Skip to content

Commit 8f90fe9

Browse files
committed
Add 'unknown' to public ObjectOperationAction for forward compatibility with unrecognized server values
The public type previously only allowed known operation actions ('map.set', 'map.create' etc), meaning any future operation action from the server would be silently cast. Now the type explicitly includes 'unknown' so consumers can handle unrecognized values.
1 parent 2d93846 commit 8f90fe9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

liveobjects.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,10 @@ declare namespace ObjectOperationActions {
19311931
* Object operation action for clearing a map object.
19321932
*/
19331933
type MAP_CLEAR = 'map.clear';
1934+
/**
1935+
* Unrecognized object operation action received from the server.
1936+
*/
1937+
type UNKNOWN = 'unknown';
19341938
}
19351939

19361940
/**
@@ -1943,7 +1947,8 @@ export type ObjectOperationAction =
19431947
| ObjectOperationActions.COUNTER_CREATE
19441948
| ObjectOperationActions.COUNTER_INC
19451949
| ObjectOperationActions.OBJECT_DELETE
1946-
| ObjectOperationActions.MAP_CLEAR;
1950+
| ObjectOperationActions.MAP_CLEAR
1951+
| ObjectOperationActions.UNKNOWN;
19471952

19481953
/**
19491954
* The namespace containing the different types of map object semantics.

src/plugins/liveobjects/objectmessage.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const operationActions: ObjectsApi.ObjectOperationAction[] = [
2727
'map.clear',
2828
];
2929

30+
export function decodeObjectOperationAction(action: ObjectOperationAction): ObjectsApi.ObjectOperationAction {
31+
return operationActions[action] || 'unknown';
32+
}
33+
3034
/** @spec OMP2 */
3135
export enum ObjectsMapSemantics {
3236
LWW = 0,
@@ -617,7 +621,7 @@ function toUserFacingObjectOperation(operation: ObjectOperation<ObjectData>): Ob
617621
}
618622

619623
return {
620-
action: operationActions[operation.action] || 'unknown',
624+
action: decodeObjectOperationAction(operation.action),
621625
objectId: operation.objectId,
622626
mapCreate,
623627
mapSet,

0 commit comments

Comments
 (0)