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
536 changes: 528 additions & 8 deletions liveobjects.d.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/moduleReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ async function checkLiveObjectsPluginFiles() {
'src/plugins/liveobjects/pathobject.ts',
'src/plugins/liveobjects/pathobjectsubscriptionregister.ts',
'src/plugins/liveobjects/realtimeobject.ts',
'src/plugins/liveobjects/restobject.ts',
'src/plugins/liveobjects/rootbatchcontext.ts',
'src/plugins/liveobjects/syncobjectspool.ts',
]);
Expand Down
3 changes: 3 additions & 0 deletions src/common/lib/client/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FilteredSubscriptions } from './filteredsubscriptions';
import type { LocalDevice } from 'plugins/push/pushactivation';
import EventEmitter from '../util/eventemitter';
import { MessageEncoding } from '../types/basemessage';
import type * as LiveObjectsPlugin from 'plugins/liveobjects';

type BatchResult<T> = API.BatchResult<T>;
type BatchPublishSpec = API.BatchPublishSpec;
Expand Down Expand Up @@ -50,6 +51,7 @@ class BaseClient {
readonly _additionalHTTPRequestImplementations: HTTPRequestImplementations | null;
private readonly __FilteredSubscriptions: typeof FilteredSubscriptions | null;
readonly _Annotations: AnnotationsPlugin | null;
readonly _liveObjectsPlugin: typeof LiveObjectsPlugin | null;
readonly logger: Logger;
_device?: LocalDevice;

Expand Down Expand Up @@ -103,6 +105,7 @@ class BaseClient {
this._Crypto = options.plugins?.Crypto ?? null;
this.__FilteredSubscriptions = options.plugins?.MessageInteractions ?? null;
this._Annotations = options.plugins?.Annotations ?? null;
this._liveObjectsPlugin = options.plugins?.LiveObjects ?? null;
}

get rest(): Rest {
Expand Down
3 changes: 0 additions & 3 deletions src/common/lib/client/baserealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import { ModularPlugins, RealtimePresencePlugin } from './modularplugins';
import { TransportNames } from 'common/constants/TransportName';
import { TransportImplementations } from 'common/platform';
import Defaults from '../util/defaults';
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 _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 +58,6 @@ class BaseRealtime extends BaseClient {

this._additionalTransportImplementations = BaseRealtime.transportImplementationsFromPlugins(this.options.plugins);
this._RealtimePresence = this.options.plugins?.RealtimePresence ?? 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/realtimechannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class RealtimeChannel extends EventEmitter {
this._push = new client.options.plugins.Push.PushChannel(this);
}

if (client.options.plugins?.LiveObjects) {
this._object = new client.options.plugins.LiveObjects.RealtimeObject(this);
if (client._liveObjectsPlugin) {
this._object = new client._liveObjectsPlugin.RealtimeObject(this);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/common/lib/client/restchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RestHistoryParams } from './restchannelmixin';
import { RequestBody } from 'common/types/http';
import type { PushChannel } from 'plugins/push';
import type RestAnnotations from './restannotations';
import type { RestObject } from 'plugins/liveobjects';

const MSG_ID_ENTROPY_BYTES = 9;

Expand All @@ -42,6 +43,7 @@ class RestChannel {
}
return this._annotations;
}
private _object?: RestObject;

constructor(client: BaseRest, name: string, channelOptions?: ChannelOptions) {
Logger.logAction(client.logger, Logger.LOG_MINOR, 'RestChannel()', 'started; name = ' + name);
Expand All @@ -55,6 +57,9 @@ class RestChannel {
if (client._Annotations) {
this._annotations = new client._Annotations.RestAnnotations(this);
}
if (client._liveObjectsPlugin) {
this._object = new client._liveObjectsPlugin.RestObject(this);
}
}

get push() {
Expand All @@ -64,6 +69,13 @@ class RestChannel {
return this._push;
}

get object(): RestObject {
if (!this._object) {
Utils.throwMissingPluginError('LiveObjects');
}
return this._object;
}

get logger(): Logger {
return this.client.logger;
}
Expand Down
7 changes: 7 additions & 0 deletions src/common/types/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ export type PaginatedResultCallback<T> = StandardCallback<PaginatedResult<T>>;
* Use this to override specific property typings on an existing object type
*/
export type Modify<T, R> = Omit<T, keyof R> & R;
/**
* Collects all keys from every member of a union into a single partial object type.
* Allows uniform access to any field across a discriminated union.
*/
export type FlattenUnion<T> = {
[K in T extends unknown ? keyof T : never]?: T extends unknown ? (K extends keyof T ? T[K] : never) : never;
};
6 changes: 6 additions & 0 deletions src/plugins/liveobjects/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { LiveCounterValueType } from './livecountervaluetype';
import { LiveMapValueType } from './livemapvaluetype';
import { ObjectId } from './objectid';
import { ObjectMessage, WireObjectMessage } from './objectmessage';
import { RealtimeObject } from './realtimeobject';
import { RestObject } from './restobject';

export {
LiveCounterValueType as LiveCounter,
LiveMapValueType as LiveMap,
ObjectId,
ObjectMessage,
RealtimeObject,
RestObject,
WireObjectMessage,
};

Expand All @@ -17,7 +21,9 @@ export {
export const LiveObjects = {
LiveCounter: LiveCounterValueType,
LiveMap: LiveMapValueType,
ObjectId,
ObjectMessage,
RealtimeObject,
RestObject,
WireObjectMessage,
};
6 changes: 5 additions & 1 deletion src/plugins/liveobjects/livecountervaluetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ export class LiveCounterValueType implements LiveCounter {
}

const counterCreate = LiveCounterValueType._getCounterCreate(count); // RTO12f12
const { counterCreate: encodedCounterCreate } = encodePartialObjectOperationForWire({ counterCreate }, client);
const { counterCreate: encodedCounterCreate } = encodePartialObjectOperationForWire(
{ counterCreate },
client,
client.Utils.Format.json,
);
const initialValueJSONString = JSON.stringify(encodedCounterCreate); // RTO12f13
const nonce = client.Utils.cheapRandStr(); // RTO12f4
const msTimestamp = await client.getTimestamp(true); // RTO12f5
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/liveobjects/livemapvaluetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export class LiveMapValueType<T extends Record<string, Value> = Record<string, V
Object.entries(entries ?? {}).forEach(([key, value]) => LiveMap.validateKeyValue(realtimeObject, key, value));

const { mapCreate, nestedObjectsCreateMsgs } = await LiveMapValueType._getMapCreate(realtimeObject, entries); // RTO11f14
const { mapCreate: encodedMapCreate } = encodePartialObjectOperationForWire({ mapCreate }, client); // RTO11f15a
const { mapCreate: encodedMapCreate } = encodePartialObjectOperationForWire(
{ mapCreate },
client,
client.Utils.Format.json,
); // RTO11f15a
const initialValueJSONString = JSON.stringify(encodedMapCreate); // RTO11f15b
const nonce = client.Utils.cheapRandStr(); // RTO11f6
const msTimestamp = await client.getTimestamp(true); // RTO11f7
Expand Down
Loading
Loading