Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ably-js.iml
node_modules
npm-debug.log
.tool-versions
objects.d.mts
liveobjects.d.mts
build/
react/
typedoc/generated/
Expand Down
26 changes: 13 additions & 13 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = function (grunt) {
});
});

grunt.registerTask('build', ['webpack:all', 'build:browser', 'build:node', 'build:push', 'build:objects']);
grunt.registerTask('build', ['webpack:all', 'build:browser', 'build:node', 'build:push', 'build:liveobjects']);

grunt.registerTask('all', ['build', 'requirejs']);

Expand Down Expand Up @@ -138,14 +138,14 @@ module.exports = function (grunt) {
});
});

grunt.registerTask('build:objects:bundle', function () {
grunt.registerTask('build:liveobjects:bundle', function () {
var done = this.async();

Promise.all([
esbuild.build(esbuildConfig.objectsPluginConfig),
esbuild.build(esbuildConfig.objectsPluginEsmConfig),
esbuild.build(esbuildConfig.objectsPluginCdnConfig),
esbuild.build(esbuildConfig.minifiedObjectsPluginCdnConfig),
esbuild.build(esbuildConfig.liveObjectsPluginConfig),
esbuild.build(esbuildConfig.liveObjectsPluginEsmConfig),
esbuild.build(esbuildConfig.liveObjectsPluginCdnConfig),
esbuild.build(esbuildConfig.minifiedLiveObjectsPluginCdnConfig),
])
.then(() => {
done(true);
Expand All @@ -156,22 +156,22 @@ module.exports = function (grunt) {
});

grunt.registerTask(
'build:objects:types',
'Generate objects.d.mts from objects.d.ts by adding .js extensions to relative imports',
'build:liveobjects:types',
'Generate liveobjects.d.mts from liveobjects.d.ts by adding .js extensions to relative imports',
function () {
const dtsContent = fs.readFileSync('objects.d.ts', 'utf8');
const dtsContent = fs.readFileSync('liveobjects.d.ts', 'utf8');
const mtsContent = dtsContent.replace(/from '(\.\/[^']+)'/g, "from '$1.js'");
fs.writeFileSync('objects.d.mts', mtsContent);
grunt.log.ok('Generated objects.d.mts from objects.d.ts');
fs.writeFileSync('liveobjects.d.mts', mtsContent);
grunt.log.ok('Generated liveobjects.d.mts from liveobjects.d.ts');
},
);

grunt.registerTask('build:objects', ['build:objects:bundle', 'build:objects:types']);
grunt.registerTask('build:liveobjects', ['build:liveobjects:bundle', 'build:liveobjects:types']);

grunt.registerTask('test:webserver', 'Launch the Mocha test web server on http://localhost:3000/', [
'build:browser',
'build:push',
'build:objects',
'build:liveobjects',
'checkGitSubmodules',
'mocha:webserver',
]);
Expand Down
4 changes: 2 additions & 2 deletions ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export type Transport = 'web_socket' | 'xhr_polling' | 'comet';
* This enables TypeScript to distinguish between these otherwise empty interfaces,
* which would be structurally identical without this discriminating property.
*
* This symbol is exported from 'ably' so that the types in 'ably/objects'
* This symbol is exported from 'ably' so that the types in 'ably/liveobjects'
* (both ESM and CJS versions) share the same symbol, ensuring type compatibility.
*/
export declare const __livetype: unique symbol;
Expand Down Expand Up @@ -638,7 +638,7 @@ export interface CorePlugins {
/**
* A plugin which allows the client to use LiveObjects functionality at {@link RealtimeChannel.object}.
*/
Objects?: unknown;
LiveObjects?: unknown;
}

/**
Expand Down
38 changes: 19 additions & 19 deletions grunt/esbuild/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,35 @@ const minifiedPushPluginCdnConfig = {
minify: true,
};

const objectsPluginConfig = {
const liveObjectsPluginConfig = {
...createBaseConfig(),
entryPoints: ['src/plugins/objects/index.ts'],
plugins: [umdWrapper.default({ libraryName: 'AblyObjectsPlugin', amdNamedModule: false })],
outfile: 'build/objects.js',
entryPoints: ['src/plugins/liveobjects/index.ts'],
plugins: [umdWrapper.default({ libraryName: 'AblyLiveObjectsPlugin', amdNamedModule: false })],
outfile: 'build/liveobjects.js',
external: ['dequal'],
};

const objectsPluginEsmConfig = {
const liveObjectsPluginEsmConfig = {
...createBaseConfig(),
format: 'esm',
plugins: [],
entryPoints: ['src/plugins/objects/index.ts'],
outfile: 'build/objects.mjs',
entryPoints: ['src/plugins/liveobjects/index.ts'],
outfile: 'build/liveobjects.mjs',
external: ['dequal'],
};

const objectsPluginCdnConfig = {
const liveObjectsPluginCdnConfig = {
...createBaseConfig(),
entryPoints: ['src/plugins/objects/index.ts'],
plugins: [umdWrapper.default({ libraryName: 'AblyObjectsPlugin', amdNamedModule: false })],
outfile: 'build/objects.umd.js',
entryPoints: ['src/plugins/liveobjects/index.ts'],
plugins: [umdWrapper.default({ libraryName: 'AblyLiveObjectsPlugin', amdNamedModule: false })],
outfile: 'build/liveobjects.umd.js',
};

const minifiedObjectsPluginCdnConfig = {
const minifiedLiveObjectsPluginCdnConfig = {
...createBaseConfig(),
entryPoints: ['src/plugins/objects/index.ts'],
plugins: [umdWrapper.default({ libraryName: 'AblyObjectsPlugin', amdNamedModule: false })],
outfile: 'build/objects.umd.min.js',
entryPoints: ['src/plugins/liveobjects/index.ts'],
plugins: [umdWrapper.default({ libraryName: 'AblyLiveObjectsPlugin', amdNamedModule: false })],
outfile: 'build/liveobjects.umd.min.js',
minify: true,
};

Expand All @@ -117,8 +117,8 @@ module.exports = {
pushPluginConfig,
pushPluginCdnConfig,
minifiedPushPluginCdnConfig,
objectsPluginConfig,
objectsPluginEsmConfig,
objectsPluginCdnConfig,
minifiedObjectsPluginCdnConfig,
liveObjectsPluginConfig,
liveObjectsPluginEsmConfig,
liveObjectsPluginCdnConfig,
minifiedLiveObjectsPluginCdnConfig,
};
24 changes: 12 additions & 12 deletions objects.d.ts → liveobjects.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* You are currently viewing the Ably Objects plugin type definitions for the Ably JavaScript Client Library SDK.
* You are currently viewing the Ably LiveObjects plugin type definitions for the Ably JavaScript Client Library SDK.
*
* To get started with Objects, follow the [Quickstart Guide](https://ably.com/docs/liveobjects/quickstart/javascript) or view the [Introduction to Objects](https://ably.com/docs/liveobjects).
* To get started with LiveObjects, follow the [Quickstart Guide](https://ably.com/docs/liveobjects/quickstart/javascript) or view the [Introduction to LiveObjects](https://ably.com/docs/liveobjects).
*
* @module
*/
Expand Down Expand Up @@ -70,7 +70,7 @@ export declare interface RealtimeObject {
* Example:
*
* ```typescript
* import { LiveCounter } from 'ably/objects';
* import { LiveCounter } from 'ably/liveobjects';
*
* type MyObject = {
* myTypedCounter: LiveCounter;
Expand Down Expand Up @@ -1852,35 +1852,35 @@ export class LiveCounter {
}

/**
* The Objects plugin that provides a {@link RealtimeClient} instance with the ability to use Objects functionality.
* The LiveObjects plugin that provides a {@link RealtimeClient} instance with the ability to use LiveObjects functionality.
*
* To create a client that includes this plugin, include it in the client options that you pass to the {@link RealtimeClient.constructor}:
*
* ```javascript
* import { Realtime } from 'ably';
* import { Objects } from 'ably/objects';
* const realtime = new Realtime({ ...options, plugins: { Objects } });
* import { LiveObjects } from 'ably/liveobjects';
* const realtime = new Realtime({ ...options, plugins: { LiveObjects } });
* ```
*
* The Objects plugin can also be used with a {@link BaseRealtime} client:
* The LiveObjects plugin can also be used with a {@link BaseRealtime} client:
*
* ```javascript
* import { BaseRealtime, WebSocketTransport, FetchRequest } from 'ably/modular';
* import { Objects } from 'ably/objects';
* const realtime = new BaseRealtime({ ...options, plugins: { WebSocketTransport, FetchRequest, Objects } });
* import { LiveObjects } from 'ably/liveobjects';
* const realtime = new BaseRealtime({ ...options, plugins: { WebSocketTransport, FetchRequest, LiveObjects } });
* ```
*
* You can also import individual utilities alongside the plugin:
*
* ```javascript
* import { Objects, LiveCounter, LiveMap } from 'ably/objects';
* import { LiveObjects, LiveCounter, LiveMap } from 'ably/liveobjects';
* ```
*/
export declare const Objects: any;
export declare const LiveObjects: any;

/**
* Module augmentation to add the `object` property to `RealtimeChannel` when
* importing from 'ably/objects'. This ensures all Objects types come from
* importing from 'ably/liveobjects'. This ensures all LiveObjects types come from
* the same module (CJS or ESM), avoiding type incompatibility issues.
*/
declare module './ably' {
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@
"types": "./push.d.ts",
"import": "./build/push.js"
},
"./objects": {
"./liveobjects": {
"import": {
"types": "./objects.d.mts",
"default": "./build/objects.mjs"
"types": "./liveobjects.d.mts",
"default": "./build/liveobjects.mjs"
},
"require": {
"types": "./objects.d.ts",
"default": "./build/objects.js"
"types": "./liveobjects.d.ts",
"default": "./build/liveobjects.js"
}
}
},
"files": [
"build/**",
"ably.d.ts",
"objects.d.ts",
"objects.d.mts",
"liveobjects.d.ts",
"liveobjects.d.mts",
"modular.d.ts",
"push.d.ts",
"resources/**",
Expand Down Expand Up @@ -151,8 +151,8 @@
"start:react": "npx vite serve",
"grunt": "grunt",
"test": "npm run test:node",
"test:node": "npm run build:node && npm run build:push && npm run build:objects && mocha",
"test:grep": "npm run build:node && npm run build:push && npm run build:objects && mocha --grep",
"test:node": "npm run build:node && npm run build:push && npm run build:liveobjects && mocha",
"test:grep": "npm run build:node && npm run build:push && npm run build:liveobjects && mocha --grep",
"test:node:skip-build": "mocha",
"test:webserver": "grunt test:webserver",
"test:playwright": "node test/support/runPlaywrightTests.js",
Expand All @@ -166,7 +166,7 @@
"build:react:mjs": "tsc --project src/platform/react-hooks/tsconfig.mjs.json && cp src/platform/react-hooks/res/package.mjs.json react/mjs/package.json",
"build:react:cjs": "tsc --project src/platform/react-hooks/tsconfig.cjs.json && cp src/platform/react-hooks/res/package.cjs.json react/cjs/package.json",
"build:push": "grunt build:push",
"build:objects": "grunt build:objects",
"build:liveobjects": "grunt build:liveobjects",
"requirejs": "grunt requirejs",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
Expand Down
50 changes: 25 additions & 25 deletions scripts/moduleReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ interface PluginInfo {
external?: string[];
}

const buildablePlugins: Record<'push' | 'objects', PluginInfo> = {
const buildablePlugins: Record<'push' | 'liveobjects', PluginInfo> = {
push: { description: 'Push', path: './build/push.js', external: ['ulid'] },
objects: { description: 'Objects', path: './build/objects.js', external: ['dequal'] },
liveobjects: { description: 'LiveObjects', path: './build/liveobjects.js', external: ['dequal'] },
};

function formatBytes(bytes: number) {
Expand Down Expand Up @@ -217,8 +217,8 @@ async function calculatePushPluginSize(): Promise<Output> {
return calculatePluginSize(buildablePlugins.push);
}

async function calculateObjectsPluginSize(): Promise<Output> {
return calculatePluginSize(buildablePlugins.objects);
async function calculateLiveObjectsPluginSize(): Promise<Output> {
return calculatePluginSize(buildablePlugins.liveobjects);
}

async function calculateAndCheckMinimalUsefulRealtimeBundleSize(): Promise<Output> {
Expand Down Expand Up @@ -321,28 +321,28 @@ async function checkPushPluginFiles() {
return checkBundleFiles(pushPluginBundleInfo, allowedFiles, 100);
}

async function checkObjectsPluginFiles() {
const { path, external } = buildablePlugins.objects;
async function checkLiveObjectsPluginFiles() {
const { path, external } = buildablePlugins.liveobjects;
const pluginBundleInfo = getBundleInfo(path, undefined, external);

// These are the files that are allowed to contribute >= `threshold` bytes to the Objects bundle.
// These are the files that are allowed to contribute >= `threshold` bytes to the LiveObjects bundle.
const allowedFiles = new Set([
'src/plugins/objects/batchcontext.ts',
'src/plugins/objects/index.ts',
'src/plugins/objects/instance.ts',
'src/plugins/objects/livecounter.ts',
'src/plugins/objects/livecountervaluetype.ts',
'src/plugins/objects/livemap.ts',
'src/plugins/objects/livemapvaluetype.ts',
'src/plugins/objects/liveobject.ts',
'src/plugins/objects/objectid.ts',
'src/plugins/objects/objectmessage.ts',
'src/plugins/objects/objectspool.ts',
'src/plugins/objects/pathobject.ts',
'src/plugins/objects/pathobjectsubscriptionregister.ts',
'src/plugins/objects/realtimeobject.ts',
'src/plugins/objects/rootbatchcontext.ts',
'src/plugins/objects/syncobjectsdatapool.ts',
'src/plugins/liveobjects/batchcontext.ts',
'src/plugins/liveobjects/index.ts',
'src/plugins/liveobjects/instance.ts',
'src/plugins/liveobjects/livecounter.ts',
'src/plugins/liveobjects/livecountervaluetype.ts',
'src/plugins/liveobjects/livemap.ts',
'src/plugins/liveobjects/livemapvaluetype.ts',
'src/plugins/liveobjects/liveobject.ts',
'src/plugins/liveobjects/objectid.ts',
'src/plugins/liveobjects/objectmessage.ts',
'src/plugins/liveobjects/objectspool.ts',
'src/plugins/liveobjects/pathobject.ts',
'src/plugins/liveobjects/pathobjectsubscriptionregister.ts',
'src/plugins/liveobjects/realtimeobject.ts',
'src/plugins/liveobjects/rootbatchcontext.ts',
'src/plugins/liveobjects/syncobjectsdatapool.ts',
]);

return checkBundleFiles(pluginBundleInfo, allowedFiles, 100);
Expand Down Expand Up @@ -399,7 +399,7 @@ async function checkBundleFiles(bundleInfo: BundleInfo, allowedFiles: Set<string
calculateAndCheckExportSizes(),
calculateAndCheckFunctionSizes(),
calculatePushPluginSize(),
calculateObjectsPluginSize(),
calculateLiveObjectsPluginSize(),
])
).reduce((accum, current) => ({
tableRows: [...accum.tableRows, ...current.tableRows],
Expand All @@ -408,7 +408,7 @@ async function checkBundleFiles(bundleInfo: BundleInfo, allowedFiles: Set<string

output.errors.push(...(await checkBaseRealtimeFiles()));
output.errors.push(...(await checkPushPluginFiles()));
output.errors.push(...(await checkObjectsPluginFiles()));
output.errors.push(...(await checkLiveObjectsPluginFiles()));

const table = new Table({
style: { head: ['green'] },
Expand Down
6 changes: 3 additions & 3 deletions src/common/lib/client/baserealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { ModularPlugins, RealtimePresencePlugin } from './modularplugins';
import { TransportNames } from 'common/constants/TransportName';
import { TransportImplementations } from 'common/platform';
import Defaults from '../util/defaults';
import type * as ObjectsPlugin from 'plugins/objects';
import type * as LiveObjectsPlugin from 'plugins/liveobjects';

/**
`BaseRealtime` is an export of the tree-shakable version of the SDK, and acts as the base class for the `DefaultRealtime` class exported by the non tree-shakable version.
*/
class BaseRealtime extends BaseClient {
readonly _RealtimePresence: RealtimePresencePlugin | null;
readonly _objectsPlugin: typeof ObjectsPlugin | null;
readonly _liveObjectsPlugin: typeof LiveObjectsPlugin | null;
// Extra transport implementations available to this client, in addition to those in Platform.Transports.bundledImplementations
readonly _additionalTransportImplementations: TransportImplementations;
_channels: any;
Expand Down Expand Up @@ -60,7 +60,7 @@ class BaseRealtime extends BaseClient {

this._additionalTransportImplementations = BaseRealtime.transportImplementationsFromPlugins(this.options.plugins);
this._RealtimePresence = this.options.plugins?.RealtimePresence ?? null;
this._objectsPlugin = this.options.plugins?.Objects ?? null;
this._liveObjectsPlugin = this.options.plugins?.LiveObjects ?? null;
this.connection = new Connection(this, this.options);
this._channels = new Channels(this);
if (this.options.autoConnect !== false) this.connect();
Expand Down
4 changes: 2 additions & 2 deletions src/common/lib/client/modularplugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PresenceMessage, { WirePresenceMessage } from '../types/presencemessage';
import Annotation, { WireAnnotation } from '../types/annotation';
import { TransportCtor } from '../transport/transport';
import type * as PushPlugin from 'plugins/push';
import type * as ObjectsPlugin from 'plugins/objects';
import type * as LiveObjectsPlugin from 'plugins/liveobjects';

export interface PresenceMessagePlugin {
PresenceMessage: typeof PresenceMessage;
Expand Down Expand Up @@ -41,7 +41,7 @@ export interface ModularPlugins {
FetchRequest?: typeof fetchRequest;
MessageInteractions?: typeof FilteredSubscriptions;
Push?: typeof PushPlugin;
Objects?: typeof ObjectsPlugin; // PC5, PT2b
LiveObjects?: typeof LiveObjectsPlugin; // PC5, PT2b
}

export const allCommonModularPlugins: ModularPlugins = { Rest };
Loading
Loading