Skip to content

Commit c1aa378

Browse files
authored
Merge pull request #2044 from ably/objects-spec-tags
Objects spec tags: ObjectMessage and sync sequence
2 parents 39e0677 + bf2aa76 commit c1aa378

11 files changed

Lines changed: 248 additions & 145 deletions

File tree

src/common/lib/client/modularplugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface ModularPlugins {
4141
FetchRequest?: typeof fetchRequest;
4242
MessageInteractions?: typeof FilteredSubscriptions;
4343
Push?: typeof PushPlugin;
44-
Objects?: typeof ObjectsPlugin;
44+
Objects?: typeof ObjectsPlugin; // PC5, PT2b
4545
}
4646

4747
export const allCommonModularPlugins: ModularPlugins = { Rest };

src/common/lib/client/realtimechannel.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ class RealtimeChannel extends EventEmitter {
149149
return this._push;
150150
}
151151

152+
/** @spec RTL27 */
152153
get objects() {
153154
if (!this._objects) {
154-
Utils.throwMissingPluginError('Objects');
155+
Utils.throwMissingPluginError('Objects'); // RTL27b
155156
}
156-
return this._objects;
157+
return this._objects; // RTL27a
157158
}
158159

159160
invalidStateError(): ErrorInfo {
@@ -613,6 +614,7 @@ class RealtimeChannel extends EventEmitter {
613614
break;
614615
}
615616

617+
// RTL1
616618
// OBJECT and OBJECT_SYNC message processing share most of the logic, so group them together
617619
case actions.OBJECT:
618620
case actions.OBJECT_SYNC: {

src/common/lib/types/protocolmessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class ProtocolMessage {
169169
/**
170170
* This will be undefined if we skipped decoding this property due to user not requesting Objects functionality — see {@link fromDeserialized}
171171
*/
172-
state?: ObjectsPlugin.ObjectMessage[];
172+
state?: ObjectsPlugin.ObjectMessage[]; // TR4r
173173
auth?: unknown;
174174
connectionDetails?: Record<string, unknown>;
175175
params?: Record<string, string>;

src/common/lib/types/protocolmessagecommon.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// constant definitions that can be imported by anyone without worrying about circular
22
// deps
33

4+
// TR2
45
export const actions = {
56
HEARTBEAT: 0,
67
ACK: 1,
@@ -31,6 +32,7 @@ Object.keys(actions).forEach(function (name) {
3132
ActionName[(actions as { [key: string]: number })[name]] = name;
3233
});
3334

35+
// TR3
3436
export const flags: { [key: string]: number } = {
3537
/* Channel attach state flags */
3638
HAS_PRESENCE: 1 << 0,

src/common/lib/util/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ export function inspectBody(body: unknown): string {
285285
* Returns the byte size of the provided data based on the spec:
286286
* - TM6a - size of the string is byte length of the string
287287
* - TM6c - size of the buffer is its size in bytes
288-
* - OD3c - size of a number is 8 bytes
289-
* - OD3d - size of a boolean is 1 byte
288+
* - OD3d - size of a number is 8 bytes
289+
* - OD3b - size of a boolean is 1 byte
290290
*/
291291
export function dataSizeBytes(data: string | number | boolean | Bufferlike): number {
292292
if (Platform.BufferUtils.isBuffer(data)) {

src/plugins/objects/livecounter.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import { ObjectMessage, ObjectOperation, ObjectOperationAction, ObjectsCounterOp
44
import { Objects } from './objects';
55

66
export interface LiveCounterData extends LiveObjectData {
7-
data: number;
7+
data: number; // RTLC3
88
}
99

1010
export interface LiveCounterUpdate extends LiveObjectUpdate {
1111
update: { amount: number };
1212
}
1313

14+
/** @spec RTLC1, RTLC2 */
1415
export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate> {
1516
/**
1617
* Returns a {@link LiveCounter} instance with a 0 value.
1718
*
1819
* @internal
20+
* @spec RTLC4
1921
*/
2022
static zeroValue(objects: Objects, objectId: string): LiveCounter {
2123
return new LiveCounter(objects, objectId);
@@ -122,9 +124,10 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
122124
};
123125
}
124126

127+
/** @spec RTLC5 */
125128
value(): number {
126-
this._objects.throwIfInvalidAccessApiConfiguration();
127-
return this._dataRef.data;
129+
this._objects.throwIfInvalidAccessApiConfiguration(); // RTLC5a, RTLC5b
130+
return this._dataRef.data; // RTLC5c
128131
}
129132

130133
/**
@@ -221,6 +224,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
221224

222225
/**
223226
* @internal
227+
* @spec RTLC6
224228
*/
225229
overrideWithObjectState(objectState: ObjectState): LiveCounterUpdate | LiveObjectUpdateNoop {
226230
if (objectState.objectId !== this.getObjectId()) {
@@ -252,7 +256,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
252256

253257
// object's site serials are still updated even if it is tombstoned, so always use the site serials received from the operation.
254258
// should default to empty map if site serials do not exist on the object state, so that any future operation may be applied to this object.
255-
this._siteTimeserials = objectState.siteTimeserials ?? {};
259+
this._siteTimeserials = objectState.siteTimeserials ?? {}; // RTLC6a
256260

257261
if (this.isTombstoned()) {
258262
// this object is tombstoned. this is a terminal state which can't be overridden. skip the rest of object state message processing
@@ -265,8 +269,9 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
265269
this.tombstone();
266270
} else {
267271
// override data for this object with data from the object state
268-
this._createOperationIsMerged = false;
269-
this._dataRef = { data: objectState.counter?.count ?? 0 };
272+
this._createOperationIsMerged = false; // RTLC6b
273+
this._dataRef = { data: objectState.counter?.count ?? 0 }; // RTLC6c
274+
// RTLC6d
270275
if (!this._client.Utils.isNil(objectState.createOp)) {
271276
this._mergeInitialDataFromCreateOperation(objectState.createOp);
272277
}
@@ -285,6 +290,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
285290
return;
286291
}
287292

293+
/** @spec RTLC4 */
288294
protected _getZeroValueData(): LiveCounterData {
289295
return { data: 0 };
290296
}
@@ -299,8 +305,8 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
299305
// note that it is intentional to SUM the incoming count from the create op.
300306
// if we got here, it means that current counter instance is missing the initial value in its data reference,
301307
// which we're going to add now.
302-
this._dataRef.data += objectOperation.counter?.count ?? 0;
303-
this._createOperationIsMerged = true;
308+
this._dataRef.data += objectOperation.counter?.count ?? 0; // RTLC6d1
309+
this._createOperationIsMerged = true; // RTLC6d2
304310

305311
return { update: { amount: objectOperation.counter?.count ?? 0 } };
306312
}

0 commit comments

Comments
 (0)