@liveblocks/client
Advanced tools
Comparing version 0.17.8 to 0.17.9
@@ -1,21 +0,3 @@ | ||
import { C as ClientOptions, a as Client } from "./shared.js"; | ||
export { | ||
B as BaseUserMeta, | ||
d as BroadcastOptions, | ||
a as Client, | ||
H as History, | ||
J as Json, | ||
e as JsonObject, | ||
L as LiveList, | ||
b as LiveMap, | ||
c as LiveObject, | ||
f as LiveStructure, | ||
g as Lson, | ||
h as LsonObject, | ||
O as Others, | ||
P as Presence, | ||
R as Room, | ||
S as StorageUpdate, | ||
U as User, | ||
} from "./shared.js"; | ||
import { C as ClientOptions, a as Client } from './index-0007883d.js'; | ||
export { B as BaseUserMeta, d as BroadcastOptions, a as Client, H as History, J as Json, e as JsonObject, L as LiveList, b as LiveMap, c as LiveObject, f as LiveStructure, g as Lson, h as LsonObject, O as Others, P as Presence, R as Room, S as StorageUpdate, U as User } from './index-0007883d.js'; | ||
@@ -55,10 +37,8 @@ /** | ||
*/ | ||
declare type EnsureJson<T> = [unknown] extends [T] | ||
? T | ||
: T extends (...args: unknown[]) => unknown | ||
? T | ||
: { | ||
[K in keyof T]: EnsureJson<T[K]>; | ||
}; | ||
declare type EnsureJson<T> = [ | ||
unknown | ||
] extends [T] ? T : T extends (...args: unknown[]) => unknown ? T : { | ||
[K in keyof T]: EnsureJson<T[K]>; | ||
}; | ||
export { EnsureJson, createClient }; |
@@ -1,30 +0,14 @@ | ||
import { | ||
e as JsonObject, | ||
J as Json, | ||
B as BaseUserMeta, | ||
g as Lson, | ||
h as LsonObject, | ||
c as LiveObject, | ||
S as StorageUpdate, | ||
} from "./shared.js"; | ||
export { | ||
i as LiveNode, | ||
j as Resolve, | ||
k as RoomInitializers, | ||
W as WebsocketCloseCodes, | ||
l as isJsonArray, | ||
m as isJsonObject, | ||
n as isJsonScalar, | ||
} from "./shared.js"; | ||
import { e as JsonObject, J as Json, B as BaseUserMeta, g as Lson, h as LsonObject, c as LiveObject, S as StorageUpdate } from './index-0007883d.js'; | ||
export { i as LiveNode, j as Resolve, k as RoomInitializers, W as WebsocketCloseCodes, l as isJsonArray, m as isJsonObject, n as isJsonScalar } from './index-0007883d.js'; | ||
declare enum OpCode { | ||
INIT = 0, | ||
SET_PARENT_KEY = 1, | ||
CREATE_LIST = 2, | ||
UPDATE_OBJECT = 3, | ||
CREATE_OBJECT = 4, | ||
DELETE_CRDT = 5, | ||
DELETE_OBJECT_KEY = 6, | ||
CREATE_MAP = 7, | ||
CREATE_REGISTER = 8, | ||
INIT = 0, | ||
SET_PARENT_KEY = 1, | ||
CREATE_LIST = 2, | ||
UPDATE_OBJECT = 3, | ||
CREATE_OBJECT = 4, | ||
DELETE_CRDT = 5, | ||
DELETE_OBJECT_KEY = 6, | ||
CREATE_MAP = 7, | ||
CREATE_REGISTER = 8 | ||
} | ||
@@ -35,89 +19,80 @@ /** | ||
*/ | ||
declare type Op = | ||
| CreateOp | ||
| UpdateObjectOp | ||
| DeleteCrdtOp | ||
| SetParentKeyOp | ||
| DeleteObjectKeyOp; | ||
declare type Op = CreateOp | UpdateObjectOp | DeleteCrdtOp | SetParentKeyOp | DeleteObjectKeyOp; | ||
declare type CreateOp = CreateRootObjectOp | CreateChildOp; | ||
declare type CreateChildOp = | ||
| CreateObjectOp | ||
| CreateRegisterOp | ||
| CreateMapOp | ||
| CreateListOp; | ||
declare type CreateChildOp = CreateObjectOp | CreateRegisterOp | CreateMapOp | CreateListOp; | ||
declare type UpdateObjectOp = { | ||
opId?: string; | ||
id: string; | ||
type: OpCode.UPDATE_OBJECT; | ||
data: Partial<JsonObject>; | ||
opId?: string; | ||
id: string; | ||
type: OpCode.UPDATE_OBJECT; | ||
data: Partial<JsonObject>; | ||
}; | ||
declare type CreateObjectOp = { | ||
opId?: string; | ||
id: string; | ||
intent?: "set"; | ||
deletedId?: string; | ||
type: OpCode.CREATE_OBJECT; | ||
parentId: string; | ||
parentKey: string; | ||
data: JsonObject; | ||
opId?: string; | ||
id: string; | ||
intent?: "set"; | ||
deletedId?: string; | ||
type: OpCode.CREATE_OBJECT; | ||
parentId: string; | ||
parentKey: string; | ||
data: JsonObject; | ||
}; | ||
declare type CreateRootObjectOp = { | ||
opId?: string; | ||
id: string; | ||
type: OpCode.CREATE_OBJECT; | ||
data: JsonObject; | ||
parentId?: never; | ||
parentKey?: never; | ||
opId?: string; | ||
id: string; | ||
type: OpCode.CREATE_OBJECT; | ||
data: JsonObject; | ||
parentId?: never; | ||
parentKey?: never; | ||
}; | ||
declare type CreateListOp = { | ||
opId?: string; | ||
id: string; | ||
intent?: "set"; | ||
deletedId?: string; | ||
type: OpCode.CREATE_LIST; | ||
parentId: string; | ||
parentKey: string; | ||
opId?: string; | ||
id: string; | ||
intent?: "set"; | ||
deletedId?: string; | ||
type: OpCode.CREATE_LIST; | ||
parentId: string; | ||
parentKey: string; | ||
}; | ||
declare type CreateMapOp = { | ||
opId?: string; | ||
id: string; | ||
intent?: "set"; | ||
deletedId?: string; | ||
type: OpCode.CREATE_MAP; | ||
parentId: string; | ||
parentKey: string; | ||
opId?: string; | ||
id: string; | ||
intent?: "set"; | ||
deletedId?: string; | ||
type: OpCode.CREATE_MAP; | ||
parentId: string; | ||
parentKey: string; | ||
}; | ||
declare type CreateRegisterOp = { | ||
opId?: string; | ||
id: string; | ||
intent?: "set"; | ||
deletedId?: string; | ||
type: OpCode.CREATE_REGISTER; | ||
parentId: string; | ||
parentKey: string; | ||
data: Json; | ||
opId?: string; | ||
id: string; | ||
intent?: "set"; | ||
deletedId?: string; | ||
type: OpCode.CREATE_REGISTER; | ||
parentId: string; | ||
parentKey: string; | ||
data: Json; | ||
}; | ||
declare type DeleteCrdtOp = { | ||
opId?: string; | ||
id: string; | ||
type: OpCode.DELETE_CRDT; | ||
opId?: string; | ||
id: string; | ||
type: OpCode.DELETE_CRDT; | ||
}; | ||
declare type SetParentKeyOp = { | ||
opId?: string; | ||
id: string; | ||
type: OpCode.SET_PARENT_KEY; | ||
parentKey: string; | ||
opId?: string; | ||
id: string; | ||
type: OpCode.SET_PARENT_KEY; | ||
parentKey: string; | ||
}; | ||
declare type DeleteObjectKeyOp = { | ||
opId?: string; | ||
id: string; | ||
type: OpCode.DELETE_OBJECT_KEY; | ||
key: string; | ||
opId?: string; | ||
id: string; | ||
type: OpCode.DELETE_OBJECT_KEY; | ||
key: string; | ||
}; | ||
declare enum ClientMsgCode { | ||
UPDATE_PRESENCE = 100, | ||
BROADCAST_EVENT = 103, | ||
FETCH_STORAGE = 200, | ||
UPDATE_STORAGE = 201, | ||
UPDATE_PRESENCE = 100, | ||
BROADCAST_EVENT = 103, | ||
FETCH_STORAGE = 200, | ||
UPDATE_STORAGE = 201 | ||
} | ||
@@ -127,22 +102,39 @@ /** | ||
*/ | ||
declare type ClientMsg<TPresence extends JsonObject, TRoomEvent extends Json> = | ||
| BroadcastEventClientMsg<TRoomEvent> | ||
| UpdatePresenceClientMsg<TPresence> | ||
| UpdateStorageClientMsg | ||
| FetchStorageClientMsg; | ||
declare type ClientMsg<TPresence extends JsonObject, TRoomEvent extends Json> = BroadcastEventClientMsg<TRoomEvent> | UpdatePresenceClientMsg<TPresence> | UpdateStorageClientMsg | FetchStorageClientMsg; | ||
declare type BroadcastEventClientMsg<TRoomEvent extends Json> = { | ||
type: ClientMsgCode.BROADCAST_EVENT; | ||
event: TRoomEvent; | ||
type: ClientMsgCode.BROADCAST_EVENT; | ||
event: TRoomEvent; | ||
}; | ||
declare type UpdatePresenceClientMsg<TPresence extends JsonObject> = { | ||
type: ClientMsgCode.UPDATE_PRESENCE; | ||
data: TPresence; | ||
targetActor?: number; | ||
type: ClientMsgCode.UPDATE_PRESENCE; | ||
/** | ||
* Set this to any number to signify that this is a Full Presence™ | ||
* update, not a patch. | ||
* | ||
* The numeric value itself no longer has specific meaning. Historically, | ||
* this field was intended so that clients could ignore these broadcasted | ||
* full presence messages, but it turned out that getting a full presence | ||
* "keyframe" from time to time was useful. | ||
* | ||
* So nowadays, the presence (pun intended) of this `targetActor` field | ||
* is a backward-compatible way of expressing that the `data` contains | ||
* all presence fields, and isn't a partial "patch". | ||
*/ | ||
targetActor: number; | ||
data: TPresence; | ||
} | { | ||
type: ClientMsgCode.UPDATE_PRESENCE; | ||
/** | ||
* Absence of the `targetActor` field signifies that this is a Partial | ||
* Presence™ "patch". | ||
*/ | ||
targetActor?: undefined; | ||
data: Partial<TPresence>; | ||
}; | ||
declare type UpdateStorageClientMsg = { | ||
type: ClientMsgCode.UPDATE_STORAGE; | ||
ops: Op[]; | ||
type: ClientMsgCode.UPDATE_STORAGE; | ||
ops: Op[]; | ||
}; | ||
declare type FetchStorageClientMsg = { | ||
type: ClientMsgCode.FETCH_STORAGE; | ||
type: ClientMsgCode.FETCH_STORAGE; | ||
}; | ||
@@ -152,40 +144,36 @@ | ||
declare enum CrdtType { | ||
OBJECT = 0, | ||
LIST = 1, | ||
MAP = 2, | ||
REGISTER = 3, | ||
OBJECT = 0, | ||
LIST = 1, | ||
MAP = 2, | ||
REGISTER = 3 | ||
} | ||
declare type SerializedCrdt = SerializedRootObject | SerializedChild; | ||
declare type SerializedChild = | ||
| SerializedObject | ||
| SerializedList | ||
| SerializedMap | ||
| SerializedRegister; | ||
declare type SerializedChild = SerializedObject | SerializedList | SerializedMap | SerializedRegister; | ||
declare type SerializedRootObject = { | ||
type: CrdtType.OBJECT; | ||
data: JsonObject; | ||
parentId?: never; | ||
parentKey?: never; | ||
type: CrdtType.OBJECT; | ||
data: JsonObject; | ||
parentId?: never; | ||
parentKey?: never; | ||
}; | ||
declare type SerializedObject = { | ||
type: CrdtType.OBJECT; | ||
parentId: string; | ||
parentKey: string; | ||
data: JsonObject; | ||
type: CrdtType.OBJECT; | ||
parentId: string; | ||
parentKey: string; | ||
data: JsonObject; | ||
}; | ||
declare type SerializedList = { | ||
type: CrdtType.LIST; | ||
parentId: string; | ||
parentKey: string; | ||
type: CrdtType.LIST; | ||
parentId: string; | ||
parentKey: string; | ||
}; | ||
declare type SerializedMap = { | ||
type: CrdtType.MAP; | ||
parentId: string; | ||
parentKey: string; | ||
type: CrdtType.MAP; | ||
parentId: string; | ||
parentKey: string; | ||
}; | ||
declare type SerializedRegister = { | ||
type: CrdtType.REGISTER; | ||
parentId: string; | ||
parentKey: string; | ||
data: Json; | ||
type: CrdtType.REGISTER; | ||
parentId: string; | ||
parentKey: string; | ||
data: Json; | ||
}; | ||
@@ -198,6 +186,4 @@ declare function isRootCrdt(crdt: SerializedCrdt): crdt is SerializedRootObject; | ||
*/ | ||
declare type NodeMap = Map< | ||
string, // Node ID | ||
SerializedCrdt | ||
>; | ||
declare type NodeMap = Map<string, // Node ID | ||
SerializedCrdt>; | ||
/** | ||
@@ -207,15 +193,13 @@ * Reverse lookup table for all child nodes (= list of SerializedCrdt values) | ||
*/ | ||
declare type ParentToChildNodeMap = Map< | ||
string, // Parent's node ID | ||
IdTuple<SerializedChild>[] | ||
>; | ||
declare type ParentToChildNodeMap = Map<string, // Parent's node ID | ||
IdTuple<SerializedChild>[]>; | ||
declare enum ServerMsgCode { | ||
UPDATE_PRESENCE = 100, | ||
USER_JOINED = 101, | ||
USER_LEFT = 102, | ||
BROADCASTED_EVENT = 103, | ||
ROOM_STATE = 104, | ||
INITIAL_STORAGE_STATE = 200, | ||
UPDATE_STORAGE = 201, | ||
UPDATE_PRESENCE = 100, | ||
USER_JOINED = 101, | ||
USER_LEFT = 102, | ||
BROADCASTED_EVENT = 103, | ||
ROOM_STATE = 104, | ||
INITIAL_STORAGE_STATE = 200, | ||
UPDATE_STORAGE = 201 | ||
} | ||
@@ -225,14 +209,3 @@ /** | ||
*/ | ||
declare type ServerMsg< | ||
TPresence extends JsonObject, | ||
TUserMeta extends BaseUserMeta, | ||
TRoomEvent extends Json | ||
> = | ||
| UpdatePresenceServerMsg<TPresence> | ||
| UserJoinServerMsg<TUserMeta> | ||
| UserLeftServerMsg | ||
| BroadcastedEventServerMsg<TRoomEvent> | ||
| RoomStateServerMsg<TUserMeta> | ||
| InitialDocumentStateServerMsg | ||
| UpdateStorageServerMsg; | ||
declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg; | ||
/** | ||
@@ -250,19 +223,19 @@ * Sent by the WebSocket server and broadcasted to all clients to announce that | ||
declare type UpdatePresenceServerMsg<TPresence extends JsonObject> = { | ||
type: ServerMsgCode.UPDATE_PRESENCE; | ||
/** | ||
* The User whose Presence has changed. | ||
*/ | ||
actor: number; | ||
/** | ||
* The partial or full Presence of a User. If the `targetActor` field is set, | ||
* this will be the full Presence, otherwise it only contain the fields that | ||
* have changed since the last broadcast. | ||
*/ | ||
data: TPresence; | ||
/** | ||
* If this message was sent in response to a newly joined user, this field | ||
* indicates which client this message is for. Other existing clients may | ||
* ignore this message if this message isn't targeted for them. | ||
*/ | ||
targetActor?: number; | ||
type: ServerMsgCode.UPDATE_PRESENCE; | ||
/** | ||
* The User whose Presence has changed. | ||
*/ | ||
actor: number; | ||
/** | ||
* The partial or full Presence of a User. If the `targetActor` field is set, | ||
* this will be the full Presence, otherwise it only contain the fields that | ||
* have changed since the last broadcast. | ||
*/ | ||
data: TPresence; | ||
/** | ||
* If this message was sent in response to a newly joined user, this field | ||
* indicates which client this message is for. Other existing clients may | ||
* ignore this message if this message isn't targeted for them. | ||
*/ | ||
targetActor?: number; | ||
}; | ||
@@ -274,14 +247,14 @@ /** | ||
declare type UserJoinServerMsg<TUserMeta extends BaseUserMeta> = { | ||
type: ServerMsgCode.USER_JOINED; | ||
actor: number; | ||
/** | ||
* The id of the User that has been set in the authentication endpoint. | ||
* Useful to get additional information about the connected user. | ||
*/ | ||
id: TUserMeta["id"]; | ||
/** | ||
* Additional user information that has been set in the authentication | ||
* endpoint. | ||
*/ | ||
info: TUserMeta["info"]; | ||
type: ServerMsgCode.USER_JOINED; | ||
actor: number; | ||
/** | ||
* The id of the User that has been set in the authentication endpoint. | ||
* Useful to get additional information about the connected user. | ||
*/ | ||
id: TUserMeta["id"]; | ||
/** | ||
* Additional user information that has been set in the authentication | ||
* endpoint. | ||
*/ | ||
info: TUserMeta["info"]; | ||
}; | ||
@@ -293,4 +266,4 @@ /** | ||
declare type UserLeftServerMsg = { | ||
type: ServerMsgCode.USER_LEFT; | ||
actor: number; | ||
type: ServerMsgCode.USER_LEFT; | ||
actor: number; | ||
}; | ||
@@ -302,12 +275,12 @@ /** | ||
declare type BroadcastedEventServerMsg<TRoomEvent extends Json> = { | ||
type: ServerMsgCode.BROADCASTED_EVENT; | ||
/** | ||
* The User who broadcasted the Event. | ||
*/ | ||
actor: number; | ||
/** | ||
* The arbitrary payload of the Event. This can be any JSON value. Clients | ||
* will have to manually verify/decode this event. | ||
*/ | ||
event: TRoomEvent; | ||
type: ServerMsgCode.BROADCASTED_EVENT; | ||
/** | ||
* The User who broadcasted the Event. | ||
*/ | ||
actor: number; | ||
/** | ||
* The arbitrary payload of the Event. This can be any JSON value. Clients | ||
* will have to manually verify/decode this event. | ||
*/ | ||
event: TRoomEvent; | ||
}; | ||
@@ -320,6 +293,6 @@ /** | ||
declare type RoomStateServerMsg<TUserMeta extends BaseUserMeta> = { | ||
type: ServerMsgCode.ROOM_STATE; | ||
users: { | ||
[actor: number]: TUserMeta; | ||
}; | ||
type: ServerMsgCode.ROOM_STATE; | ||
users: { | ||
[actor: number]: TUserMeta; | ||
}; | ||
}; | ||
@@ -332,4 +305,4 @@ /** | ||
declare type InitialDocumentStateServerMsg = { | ||
type: ServerMsgCode.INITIAL_STORAGE_STATE; | ||
items: IdTuple<SerializedCrdt>[]; | ||
type: ServerMsgCode.INITIAL_STORAGE_STATE; | ||
items: IdTuple<SerializedCrdt>[]; | ||
}; | ||
@@ -344,4 +317,4 @@ /** | ||
declare type UpdateStorageServerMsg = { | ||
type: ServerMsgCode.UPDATE_STORAGE; | ||
ops: Op[]; | ||
type: ServerMsgCode.UPDATE_STORAGE; | ||
ops: Op[]; | ||
}; | ||
@@ -385,24 +358,17 @@ | ||
declare const SCOPES: readonly [ | ||
"websocket:presence", | ||
"websocket:storage", | ||
"room:read", | ||
"room:write", | ||
"rooms:read", | ||
"rooms:write" | ||
]; | ||
declare const SCOPES: readonly ["websocket:presence", "websocket:storage", "room:read", "room:write", "rooms:read", "rooms:write"]; | ||
declare type Scope = typeof SCOPES[number]; | ||
declare type AppOnlyAuthToken = { | ||
appId: string; | ||
roomId?: never; | ||
scopes: string[]; | ||
appId: string; | ||
roomId?: never; | ||
scopes: string[]; | ||
}; | ||
declare type RoomAuthToken = { | ||
appId: string; | ||
roomId: string; | ||
scopes: string[]; | ||
actor: number; | ||
maxConnectionsPerRoom?: number; | ||
id?: string; | ||
info?: Json; | ||
appId: string; | ||
roomId: string; | ||
scopes: string[]; | ||
actor: number; | ||
maxConnectionsPerRoom?: number; | ||
id?: string; | ||
info?: Json; | ||
}; | ||
@@ -430,7 +396,3 @@ declare type AuthToken = AppOnlyAuthToken | RoomAuthToken; | ||
*/ | ||
declare function deprecateIf( | ||
condition: unknown, | ||
message: string, | ||
key?: string | ||
): void; | ||
declare function deprecateIf(condition: unknown, message: string, key?: string): void; | ||
/** | ||
@@ -452,11 +414,4 @@ * Throws a deprecation error in the dev console. | ||
declare function lsonToJson(value: Lson): Json; | ||
declare function patchLiveObjectKey< | ||
O extends LsonObject, | ||
K extends keyof O, | ||
V extends Lson | ||
>(liveObject: LiveObject<O>, key: K, prev?: V, next?: V): void; | ||
declare function patchImmutableObject<S extends JsonObject>( | ||
state: S, | ||
updates: StorageUpdate[] | ||
): S; | ||
declare function patchLiveObjectKey<O extends LsonObject, K extends keyof O, V extends Lson>(liveObject: LiveObject<O>, key: K, prev?: V, next?: V): void; | ||
declare function patchImmutableObject<S extends JsonObject>(state: S, updates: StorageUpdate[]): S; | ||
@@ -467,3 +422,3 @@ declare function makePosition(before?: string, after?: string): string; | ||
declare function isPlainObject(blob: unknown): blob is { | ||
[key: string]: unknown; | ||
[key: string]: unknown; | ||
}; | ||
@@ -480,66 +435,2 @@ /** | ||
export { | ||
AppOnlyAuthToken, | ||
AuthToken, | ||
BroadcastEventClientMsg, | ||
BroadcastedEventServerMsg, | ||
ClientMsg, | ||
ClientMsgCode, | ||
CrdtType, | ||
CreateChildOp, | ||
CreateListOp, | ||
CreateMapOp, | ||
CreateObjectOp, | ||
CreateOp, | ||
CreateRegisterOp, | ||
CreateRootObjectOp, | ||
DeleteCrdtOp, | ||
DeleteObjectKeyOp, | ||
FetchStorageClientMsg, | ||
IdTuple, | ||
InitialDocumentStateServerMsg, | ||
NodeMap, | ||
Op, | ||
OpCode, | ||
ParentToChildNodeMap, | ||
RoomAuthToken, | ||
RoomStateServerMsg, | ||
Scope, | ||
SerializedChild, | ||
SerializedCrdt, | ||
SerializedList, | ||
SerializedMap, | ||
SerializedObject, | ||
SerializedRegister, | ||
SerializedRootObject, | ||
ServerMsg, | ||
ServerMsgCode, | ||
SetParentKeyOp, | ||
UpdateObjectOp, | ||
UpdatePresenceClientMsg, | ||
UpdatePresenceServerMsg, | ||
UpdateStorageClientMsg, | ||
UpdateStorageServerMsg, | ||
UserJoinServerMsg, | ||
UserLeftServerMsg, | ||
assertNever, | ||
b64decode, | ||
comparePosition, | ||
deprecate, | ||
deprecateIf, | ||
errorIf, | ||
isAppOnlyAuthToken, | ||
isAuthToken, | ||
isChildCrdt, | ||
isPlainObject, | ||
isRoomAuthToken, | ||
isRootCrdt, | ||
isScope, | ||
lsonToJson, | ||
makePosition, | ||
nn, | ||
patchImmutableObject, | ||
patchLiveObjectKey, | ||
throwUsageError, | ||
tryParseJson, | ||
}; | ||
export { AppOnlyAuthToken, AuthToken, BroadcastEventClientMsg, BroadcastedEventServerMsg, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, DeleteCrdtOp, DeleteObjectKeyOp, FetchStorageClientMsg, IdTuple, InitialDocumentStateServerMsg, NodeMap, Op, OpCode, ParentToChildNodeMap, RoomAuthToken, RoomStateServerMsg, Scope, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UserJoinServerMsg, UserLeftServerMsg, assertNever, b64decode, comparePosition, deprecate, deprecateIf, errorIf, isAppOnlyAuthToken, isAuthToken, isChildCrdt, isPlainObject, isRoomAuthToken, isRootCrdt, isScope, lsonToJson, makePosition, nn, patchImmutableObject, patchLiveObjectKey, throwUsageError, tryParseJson }; |
835
internal.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: !0 }); | ||
var Json = require("./shared.js"); | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _instanceof(left, right) { | ||
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { | ||
return !!right[Symbol.hasInstance](left); | ||
} else { | ||
return left instanceof right; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (_i == null) return; | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _s, _e; | ||
try { | ||
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){ | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally{ | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally{ | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _objectSpread(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpreadProps(target, source) { | ||
source = source != null ? source : {}; | ||
if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(n); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _optionalChain(ops) { | ||
var lastAccessLHS = undefined; | ||
var value = ops[0]; | ||
var i = 1; | ||
while(i < ops.length){ | ||
var op = ops[i]; | ||
var fn = ops[i + 1]; | ||
i += 2; | ||
if ((op === "optionalAccess" || op === "optionalCall") && value == null) { | ||
return undefined; | ||
} | ||
if (op === "access" || op === "optionalAccess") { | ||
lastAccessLHS = value; | ||
value = fn(value); | ||
} else if (op === "call" || op === "optionalCall") { | ||
var _value; | ||
value = fn(function() { | ||
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ | ||
args[_key] = arguments[_key]; | ||
} | ||
return (_value = value).call.apply(_value, [ | ||
lastAccessLHS | ||
].concat(_toConsumableArray(args))); | ||
}); | ||
lastAccessLHS = undefined; | ||
} | ||
} | ||
return value; | ||
} | ||
var _chunkQLMVHHAZjs = require("./chunk-QLMVHHAZ.js"); | ||
// src/immutable.ts | ||
function lsonObjectToJson(obj) { | ||
var result = {}; | ||
for (var key in obj) { | ||
var val = obj[key]; | ||
void 0 !== val && (result[key] = lsonToJson(val)); | ||
} | ||
return result; | ||
var result = {}; | ||
for(var key in obj){ | ||
var val = obj[key]; | ||
if (val !== void 0) { | ||
result[key] = lsonToJson(val); | ||
} | ||
} | ||
return result; | ||
} | ||
function liveObjectToJson(liveObject) { | ||
return lsonObjectToJson(liveObject.toObject()); | ||
} | ||
function liveMapToJson(map) { | ||
var result = {}; | ||
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; | ||
try { | ||
for(var _iterator = map.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
var _value = _slicedToArray(_step.value, 2), key = _value[0], value = _value[1]; | ||
result[key] = lsonToJson(value); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally{ | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally{ | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
function lsonListToJson(value) { | ||
return value.map(lsonToJson); | ||
return value.map(lsonToJson); | ||
} | ||
function liveListToJson(value) { | ||
return lsonListToJson(value.toArray()); | ||
} | ||
function lsonToJson(value) { | ||
return value instanceof Json.LiveObject | ||
? lsonObjectToJson(value.toObject()) | ||
: value instanceof Json.LiveList | ||
? (function (value) { | ||
return lsonListToJson(value.toArray()); | ||
})(value) | ||
: value instanceof Json.LiveMap | ||
? (function (map) { | ||
for ( | ||
var _step, | ||
result = {}, | ||
_iterator = Json._createForOfIteratorHelperLoose(map.entries()); | ||
!(_step = _iterator()).done; | ||
) { | ||
var _step$value = _step.value, | ||
key = _step$value[0], | ||
value = _step$value[1]; | ||
result[key] = lsonToJson(value); | ||
} | ||
return result; | ||
})(value) | ||
: value instanceof Json.LiveRegister | ||
? value.data | ||
: Array.isArray(value) | ||
? lsonListToJson(value) | ||
: Json.isPlainObject(value) | ||
? lsonObjectToJson(value) | ||
: value; | ||
if (_instanceof(value, _chunkQLMVHHAZjs.LiveObject)) { | ||
return liveObjectToJson(value); | ||
} else if (_instanceof(value, _chunkQLMVHHAZjs.LiveList)) { | ||
return liveListToJson(value); | ||
} else if (_instanceof(value, _chunkQLMVHHAZjs.LiveMap)) { | ||
return liveMapToJson(value); | ||
} else if (_instanceof(value, _chunkQLMVHHAZjs.LiveRegister)) { | ||
return value.data; | ||
} | ||
if (Array.isArray(value)) { | ||
return lsonListToJson(value); | ||
} else if (_chunkQLMVHHAZjs.isPlainObject.call(void 0, value)) { | ||
return lsonObjectToJson(value); | ||
} | ||
return value; | ||
} | ||
function deepLiveify(value) { | ||
if (Array.isArray(value)) return new Json.LiveList(value.map(deepLiveify)); | ||
if (Json.isPlainObject(value)) { | ||
var init = {}; | ||
for (var key in value) { | ||
var val = value[key]; | ||
void 0 !== val && (init[key] = deepLiveify(val)); | ||
if (Array.isArray(value)) { | ||
return new (0, _chunkQLMVHHAZjs.LiveList)(value.map(deepLiveify)); | ||
} else if (_chunkQLMVHHAZjs.isPlainObject.call(void 0, value)) { | ||
var init = {}; | ||
for(var key in value){ | ||
var val = value[key]; | ||
if (val === void 0) { | ||
continue; | ||
} | ||
init[key] = deepLiveify(val); | ||
} | ||
return new (0, _chunkQLMVHHAZjs.LiveObject)(init); | ||
} else { | ||
return value; | ||
} | ||
return new Json.LiveObject(init); | ||
} | ||
return value; | ||
} | ||
function patchLiveObjectKey(liveObject, key, prev, next) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
var nonSerializableValue = Json.findNonSerializableValue(next); | ||
if (nonSerializableValue) | ||
return void console.error( | ||
"New state path: '" + | ||
nonSerializableValue.path + | ||
"' value: '" + | ||
nonSerializableValue.value + | ||
"' is not serializable.\nOnly serializable value can be synced with Liveblocks." | ||
); | ||
} | ||
var value = liveObject.get(key); | ||
if (void 0 === next) liveObject.delete(key); | ||
else if (void 0 === value) liveObject.set(key, deepLiveify(next)); | ||
else { | ||
if (prev === next) return; | ||
Json.isLiveList(value) && Array.isArray(prev) && Array.isArray(next) | ||
? (function (liveList, prev, next) { | ||
var i = 0, | ||
prevEnd = prev.length - 1, | ||
nextEnd = next.length - 1, | ||
prevNode = prev[0], | ||
nextNode = next[0]; | ||
outer: { | ||
for (; prevNode === nextNode; ) { | ||
if (++i > prevEnd || i > nextEnd) break outer; | ||
(prevNode = prev[i]), (nextNode = next[i]); | ||
function patchLiveList(liveList, prev, next) { | ||
var i = 0; | ||
var prevEnd = prev.length - 1; | ||
var nextEnd = next.length - 1; | ||
var prevNode = prev[0]; | ||
var nextNode = next[0]; | ||
outer: { | ||
while(prevNode === nextNode){ | ||
++i; | ||
if (i > prevEnd || i > nextEnd) { | ||
break outer; | ||
} | ||
for ( | ||
prevNode = prev[prevEnd], nextNode = next[nextEnd]; | ||
prevNode === nextNode; | ||
) { | ||
if ((nextEnd--, i > --prevEnd || i > nextEnd)) break outer; | ||
(prevNode = prev[prevEnd]), (nextNode = next[nextEnd]); | ||
prevNode = prev[i]; | ||
nextNode = next[i]; | ||
} | ||
prevNode = prev[prevEnd]; | ||
nextNode = next[nextEnd]; | ||
while(prevNode === nextNode){ | ||
prevEnd--; | ||
nextEnd--; | ||
if (i > prevEnd || i > nextEnd) { | ||
break outer; | ||
} | ||
} | ||
if (i > prevEnd) { | ||
if (i <= nextEnd) | ||
for (; i <= nextEnd; ) | ||
liveList.insert(deepLiveify(next[i]), i), i++; | ||
} else if (i > nextEnd) | ||
for (var localI = i; localI <= prevEnd; ) | ||
liveList.delete(i), localI++; | ||
else { | ||
for (; i <= prevEnd && i <= nextEnd; ) { | ||
(prevNode = prev[i]), (nextNode = next[i]); | ||
var liveListNode = liveList.get(i); | ||
Json.isLiveObject(liveListNode) && | ||
Json.isPlainObject(prevNode) && | ||
Json.isPlainObject(nextNode) | ||
? patchLiveObject(liveListNode, prevNode, nextNode) | ||
: liveList.set(i, deepLiveify(nextNode)), | ||
prevNode = prev[prevEnd]; | ||
nextNode = next[nextEnd]; | ||
} | ||
} | ||
if (i > prevEnd) { | ||
if (i <= nextEnd) { | ||
while(i <= nextEnd){ | ||
liveList.insert(deepLiveify(next[i]), i); | ||
i++; | ||
} | ||
for (; i <= nextEnd; ) | ||
liveList.insert(deepLiveify(next[i]), i), i++; | ||
for (var _localI = i; _localI <= prevEnd; ) | ||
liveList.delete(i), _localI++; | ||
} | ||
})(value, prev, next) | ||
: Json.isLiveObject(value) && | ||
Json.isPlainObject(prev) && | ||
Json.isPlainObject(next) | ||
? patchLiveObject(value, prev, next) | ||
: liveObject.set(key, deepLiveify(next)); | ||
} | ||
} | ||
} else if (i > nextEnd) { | ||
var localI = i; | ||
while(localI <= prevEnd){ | ||
liveList.delete(i); | ||
localI++; | ||
} | ||
} else { | ||
while(i <= prevEnd && i <= nextEnd){ | ||
prevNode = prev[i]; | ||
nextNode = next[i]; | ||
var liveListNode = liveList.get(i); | ||
if (_chunkQLMVHHAZjs.isLiveObject.call(void 0, liveListNode) && _chunkQLMVHHAZjs.isPlainObject.call(void 0, prevNode) && _chunkQLMVHHAZjs.isPlainObject.call(void 0, nextNode)) { | ||
patchLiveObject(liveListNode, prevNode, nextNode); | ||
} else { | ||
liveList.set(i, deepLiveify(nextNode)); | ||
} | ||
i++; | ||
} | ||
while(i <= nextEnd){ | ||
liveList.insert(deepLiveify(next[i]), i); | ||
i++; | ||
} | ||
var localI1 = i; | ||
while(localI1 <= prevEnd){ | ||
liveList.delete(i); | ||
localI1++; | ||
} | ||
} | ||
} | ||
function patchLiveObjectKey(liveObject, key, prev, next) { | ||
if (process.env.NODE_ENV !== "production") { | ||
var nonSerializableValue = _chunkQLMVHHAZjs.findNonSerializableValue.call(void 0, next); | ||
if (nonSerializableValue) { | ||
console.error("New state path: '".concat(nonSerializableValue.path, "' value: '").concat(nonSerializableValue.value, "' is not serializable.\nOnly serializable value can be synced with Liveblocks.")); | ||
return; | ||
} | ||
} | ||
var value = liveObject.get(key); | ||
if (next === void 0) { | ||
liveObject.delete(key); | ||
} else if (value === void 0) { | ||
liveObject.set(key, deepLiveify(next)); | ||
} else if (prev === next) { | ||
return; | ||
} else if (_chunkQLMVHHAZjs.isLiveList.call(void 0, value) && Array.isArray(prev) && Array.isArray(next)) { | ||
patchLiveList(value, prev, next); | ||
} else if (_chunkQLMVHHAZjs.isLiveObject.call(void 0, value) && _chunkQLMVHHAZjs.isPlainObject.call(void 0, prev) && _chunkQLMVHHAZjs.isPlainObject.call(void 0, next)) { | ||
patchLiveObject(value, prev, next); | ||
} else { | ||
liveObject.set(key, deepLiveify(next)); | ||
} | ||
} | ||
function patchLiveObject(root, prev, next) { | ||
var updates = {}; | ||
for (var key in next) patchLiveObjectKey(root, key, prev[key], next[key]); | ||
for (var _key in prev) void 0 === next[_key] && root.delete(_key); | ||
Object.keys(updates).length > 0 && root.update(updates); | ||
var updates = {}; | ||
for(var key in next){ | ||
patchLiveObjectKey(root, key, prev[key], next[key]); | ||
} | ||
for(var key1 in prev){ | ||
if (next[key1] === void 0) { | ||
root.delete(key1); | ||
} | ||
} | ||
if (Object.keys(updates).length > 0) { | ||
root.update(updates); | ||
} | ||
} | ||
function getParentsPath(node) { | ||
var path = []; | ||
while(node.parent.type === "HasParent"){ | ||
if (_chunkQLMVHHAZjs.isLiveList.call(void 0, node.parent.node)) { | ||
path.push(node.parent.node._indexOfPosition(node.parent.key)); | ||
} else { | ||
path.push(node.parent.key); | ||
} | ||
node = node.parent.node; | ||
} | ||
return path; | ||
} | ||
function patchImmutableObject(state, updates) { | ||
return updates.reduce(function(state2, update) { | ||
return patchImmutableObjectWithUpdate(state2, update); | ||
}, state); | ||
} | ||
function patchImmutableObjectWithUpdate(state, update) { | ||
var path = getParentsPath(update.node); | ||
return patchImmutableNode(state, path, update); | ||
} | ||
function patchImmutableNode(state, path, update) { | ||
var pathItem = path.pop(); | ||
if (void 0 === pathItem) | ||
switch (update.type) { | ||
case "LiveObject": | ||
if (null === state || "object" != typeof state || Array.isArray(state)) | ||
throw new Error( | ||
"Internal: received update on LiveObject but state was not an object" | ||
); | ||
var newState = Object.assign({}, state); | ||
for (var key in update.updates) { | ||
var _update$updates$key, _update$updates$key2; | ||
if ( | ||
"update" === | ||
(null == (_update$updates$key = update.updates[key]) | ||
? void 0 | ||
: _update$updates$key.type) | ||
) { | ||
var val = update.node.get(key); | ||
void 0 !== val && (newState[key] = lsonToJson(val)); | ||
} else | ||
"delete" === | ||
(null == (_update$updates$key2 = update.updates[key]) | ||
? void 0 | ||
: _update$updates$key2.type) && delete newState[key]; | ||
var pathItem = path.pop(); | ||
if (pathItem === void 0) { | ||
switch(update.type){ | ||
case "LiveObject": | ||
{ | ||
var _loop = function(key) { | ||
if (_optionalChain([ | ||
update, | ||
"access", | ||
function(_) { | ||
return _.updates; | ||
}, | ||
"access", | ||
function(_2) { | ||
return _2[key]; | ||
}, | ||
"optionalAccess", | ||
function(_3) { | ||
return _3.type; | ||
} | ||
]) === "update") { | ||
var val = update.node.get(key); | ||
if (val !== void 0) { | ||
newState[key] = lsonToJson(val); | ||
} | ||
} else if (_optionalChain([ | ||
update, | ||
"access", | ||
function(_4) { | ||
return _4.updates; | ||
}, | ||
"access", | ||
function(_5) { | ||
return _5[key]; | ||
}, | ||
"optionalAccess", | ||
function(_6) { | ||
return _6.type; | ||
} | ||
]) === "delete") { | ||
delete newState[key]; | ||
} | ||
}; | ||
if (state === null || typeof state !== "object" || Array.isArray(state)) { | ||
throw new Error("Internal: received update on LiveObject but state was not an object"); | ||
} | ||
var newState = Object.assign({}, state); | ||
for(var key in update.updates)_loop(key); | ||
return newState; | ||
} | ||
case "LiveList": | ||
{ | ||
if (!Array.isArray(state)) { | ||
throw new Error("Internal: received update on LiveList but state was not an array"); | ||
} | ||
var newState1 = state.map(function(x) { | ||
return x; | ||
}); | ||
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; | ||
try { | ||
var _loop1 = function() { | ||
var listUpdate = _step.value; | ||
if (listUpdate.type === "set") { | ||
newState1 = newState1.map(function(item, index) { | ||
return index === listUpdate.index ? lsonToJson(listUpdate.item) : item; | ||
}); | ||
} else if (listUpdate.type === "insert") { | ||
if (listUpdate.index === newState1.length) { | ||
newState1.push(lsonToJson(listUpdate.item)); | ||
} else { | ||
newState1 = _toConsumableArray(newState1.slice(0, listUpdate.index)).concat([ | ||
lsonToJson(listUpdate.item) | ||
], _toConsumableArray(newState1.slice(listUpdate.index))); | ||
} | ||
} else if (listUpdate.type === "delete") { | ||
newState1.splice(listUpdate.index, 1); | ||
} else if (listUpdate.type === "move") { | ||
if (listUpdate.previousIndex > listUpdate.index) { | ||
newState1 = _toConsumableArray(newState1.slice(0, listUpdate.index)).concat([ | ||
lsonToJson(listUpdate.item) | ||
], _toConsumableArray(newState1.slice(listUpdate.index, listUpdate.previousIndex)), _toConsumableArray(newState1.slice(listUpdate.previousIndex + 1))); | ||
} else { | ||
newState1 = _toConsumableArray(newState1.slice(0, listUpdate.previousIndex)).concat(_toConsumableArray(newState1.slice(listUpdate.previousIndex + 1, listUpdate.index + 1)), [ | ||
lsonToJson(listUpdate.item) | ||
], _toConsumableArray(newState1.slice(listUpdate.index + 1))); | ||
} | ||
} | ||
}; | ||
for(var _iterator = update.updates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop1(); | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally{ | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally{ | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return newState1; | ||
} | ||
case "LiveMap": | ||
{ | ||
var _loop2 = function(key1) { | ||
if (_optionalChain([ | ||
update, | ||
"access", | ||
function(_7) { | ||
return _7.updates; | ||
}, | ||
"access", | ||
function(_8) { | ||
return _8[key1]; | ||
}, | ||
"optionalAccess", | ||
function(_9) { | ||
return _9.type; | ||
} | ||
]) === "update") { | ||
var value = update.node.get(key1); | ||
if (value !== void 0) { | ||
newState2[key1] = lsonToJson(value); | ||
} | ||
} else if (_optionalChain([ | ||
update, | ||
"access", | ||
function(_10) { | ||
return _10.updates; | ||
}, | ||
"access", | ||
function(_11) { | ||
return _11[key1]; | ||
}, | ||
"optionalAccess", | ||
function(_12) { | ||
return _12.type; | ||
} | ||
]) === "delete") { | ||
delete newState2[key1]; | ||
} | ||
}; | ||
if (state === null || typeof state !== "object" || Array.isArray(state)) { | ||
throw new Error("Internal: received update on LiveMap but state was not an object"); | ||
} | ||
var newState2 = Object.assign({}, state); | ||
for(var key1 in update.updates)_loop2(key1); | ||
return newState2; | ||
} | ||
} | ||
return newState; | ||
case "LiveList": | ||
if (!Array.isArray(state)) | ||
throw new Error( | ||
"Internal: received update on LiveList but state was not an array" | ||
); | ||
for ( | ||
var _step2, | ||
_newState = state.map(function (x) { | ||
return x; | ||
}), | ||
_loop = function () { | ||
var listUpdate = _step2.value; | ||
"set" === listUpdate.type | ||
? (_newState = _newState.map(function (item, index) { | ||
return index === listUpdate.index | ||
? lsonToJson(listUpdate.item) | ||
: item; | ||
})) | ||
: "insert" === listUpdate.type | ||
? listUpdate.index === _newState.length | ||
? _newState.push(lsonToJson(listUpdate.item)) | ||
: (_newState = [].concat( | ||
_newState.slice(0, listUpdate.index), | ||
[lsonToJson(listUpdate.item)], | ||
_newState.slice(listUpdate.index) | ||
)) | ||
: "delete" === listUpdate.type | ||
? _newState.splice(listUpdate.index, 1) | ||
: "move" === listUpdate.type && | ||
(_newState = | ||
listUpdate.previousIndex > listUpdate.index | ||
? [].concat( | ||
_newState.slice(0, listUpdate.index), | ||
[lsonToJson(listUpdate.item)], | ||
_newState.slice( | ||
listUpdate.index, | ||
listUpdate.previousIndex | ||
), | ||
_newState.slice(listUpdate.previousIndex + 1) | ||
) | ||
: [].concat( | ||
_newState.slice(0, listUpdate.previousIndex), | ||
_newState.slice( | ||
listUpdate.previousIndex + 1, | ||
listUpdate.index + 1 | ||
), | ||
[lsonToJson(listUpdate.item)], | ||
_newState.slice(listUpdate.index + 1) | ||
)); | ||
}, | ||
_iterator2 = Json._createForOfIteratorHelperLoose(update.updates); | ||
!(_step2 = _iterator2()).done; | ||
) | ||
_loop(); | ||
return _newState; | ||
case "LiveMap": | ||
if (null === state || "object" != typeof state || Array.isArray(state)) | ||
throw new Error( | ||
"Internal: received update on LiveMap but state was not an object" | ||
); | ||
var _newState2 = Object.assign({}, state); | ||
for (var _key2 in update.updates) { | ||
var _update$updates$_key, _update$updates$_key2; | ||
if ( | ||
"update" === | ||
(null == (_update$updates$_key = update.updates[_key2]) | ||
? void 0 | ||
: _update$updates$_key.type) | ||
) { | ||
var value = update.node.get(_key2); | ||
void 0 !== value && (_newState2[_key2] = lsonToJson(value)); | ||
} else | ||
"delete" === | ||
(null == (_update$updates$_key2 = update.updates[_key2]) | ||
? void 0 | ||
: _update$updates$_key2.type) && delete _newState2[_key2]; | ||
} | ||
if (Array.isArray(state)) { | ||
var newArray = _toConsumableArray(state); | ||
newArray[pathItem] = patchImmutableNode(state[pathItem], path, update); | ||
return newArray; | ||
} else if (state !== null && typeof state === "object") { | ||
var node = state[pathItem]; | ||
if (node === void 0) { | ||
return state; | ||
} else { | ||
return _objectSpreadProps(_objectSpread({}, state), _defineProperty({}, pathItem, patchImmutableNode(node, path, update))); | ||
} | ||
return _newState2; | ||
} else { | ||
return state; | ||
} | ||
if (Array.isArray(state)) { | ||
var newArray = [].concat(state); | ||
return ( | ||
(newArray[pathItem] = patchImmutableNode(state[pathItem], path, update)), | ||
newArray | ||
); | ||
} | ||
if (null !== state && "object" == typeof state) { | ||
var _extends2, | ||
node = state[pathItem]; | ||
return void 0 === node | ||
? state | ||
: Json._extends( | ||
{}, | ||
state, | ||
(((_extends2 = {})[pathItem] = patchImmutableNode( | ||
node, | ||
path, | ||
update | ||
)), | ||
_extends2) | ||
); | ||
} | ||
return state; | ||
} | ||
Object.defineProperty(exports, "ClientMsgCode", { | ||
enumerable: !0, | ||
get: function () { | ||
return Json.ClientMsgCode; | ||
}, | ||
}), | ||
Object.defineProperty(exports, "CrdtType", { | ||
enumerable: !0, | ||
get: function () { | ||
return Json.CrdtType; | ||
}, | ||
}), | ||
Object.defineProperty(exports, "OpCode", { | ||
enumerable: !0, | ||
get: function () { | ||
return Json.OpCode; | ||
}, | ||
}), | ||
Object.defineProperty(exports, "ServerMsgCode", { | ||
enumerable: !0, | ||
get: function () { | ||
return Json.ServerMsgCode; | ||
}, | ||
}), | ||
Object.defineProperty(exports, "WebsocketCloseCodes", { | ||
enumerable: !0, | ||
get: function () { | ||
return Json.WebsocketCloseCodes; | ||
}, | ||
}), | ||
(exports.assertNever = Json.assertNever), | ||
(exports.b64decode = Json.b64decode), | ||
(exports.comparePosition = Json.comparePosition), | ||
(exports.deprecate = Json.deprecate), | ||
(exports.deprecateIf = Json.deprecateIf), | ||
(exports.errorIf = Json.errorIf), | ||
(exports.isAppOnlyAuthToken = Json.isAppOnlyAuthToken), | ||
(exports.isAuthToken = Json.isAuthToken), | ||
(exports.isChildCrdt = Json.isChildCrdt), | ||
(exports.isJsonArray = Json.isJsonArray), | ||
(exports.isJsonObject = Json.isJsonObject), | ||
(exports.isJsonScalar = Json.isJsonScalar), | ||
(exports.isPlainObject = Json.isPlainObject), | ||
(exports.isRoomAuthToken = Json.isRoomAuthToken), | ||
(exports.isRootCrdt = Json.isRootCrdt), | ||
(exports.isScope = Json.isScope), | ||
(exports.makePosition = Json.makePosition), | ||
(exports.nn = Json.nn), | ||
(exports.throwUsageError = Json.throwUsageError), | ||
(exports.tryParseJson = Json.tryParseJson), | ||
(exports.lsonToJson = lsonToJson), | ||
(exports.patchImmutableObject = function (state, updates) { | ||
return updates.reduce(function (state, update) { | ||
return (function (state, update) { | ||
var path = (function (node) { | ||
for (var path = []; "HasParent" === node.parent.type; ) | ||
Json.isLiveList(node.parent.node) | ||
? path.push(node.parent.node._indexOfPosition(node.parent.key)) | ||
: path.push(node.parent.key), | ||
(node = node.parent.node); | ||
return path; | ||
})(update.node); | ||
return patchImmutableNode(state, path, update); | ||
})(state, update); | ||
}, state); | ||
}), | ||
(exports.patchLiveObjectKey = patchLiveObjectKey); | ||
exports.ClientMsgCode = _chunkQLMVHHAZjs.ClientMsgCode; | ||
exports.CrdtType = _chunkQLMVHHAZjs.CrdtType; | ||
exports.OpCode = _chunkQLMVHHAZjs.OpCode; | ||
exports.ServerMsgCode = _chunkQLMVHHAZjs.ServerMsgCode; | ||
exports.WebsocketCloseCodes = _chunkQLMVHHAZjs.WebsocketCloseCodes; | ||
exports.assertNever = _chunkQLMVHHAZjs.assertNever; | ||
exports.b64decode = _chunkQLMVHHAZjs.b64decode; | ||
exports.comparePosition = _chunkQLMVHHAZjs.comparePosition; | ||
exports.deprecate = _chunkQLMVHHAZjs.deprecate; | ||
exports.deprecateIf = _chunkQLMVHHAZjs.deprecateIf; | ||
exports.errorIf = _chunkQLMVHHAZjs.errorIf; | ||
exports.isAppOnlyAuthToken = _chunkQLMVHHAZjs.isAppOnlyAuthToken; | ||
exports.isAuthToken = _chunkQLMVHHAZjs.isAuthToken; | ||
exports.isChildCrdt = _chunkQLMVHHAZjs.isChildCrdt; | ||
exports.isJsonArray = _chunkQLMVHHAZjs.isJsonArray; | ||
exports.isJsonObject = _chunkQLMVHHAZjs.isJsonObject; | ||
exports.isJsonScalar = _chunkQLMVHHAZjs.isJsonScalar; | ||
exports.isPlainObject = _chunkQLMVHHAZjs.isPlainObject; | ||
exports.isRoomAuthToken = _chunkQLMVHHAZjs.isRoomAuthToken; | ||
exports.isRootCrdt = _chunkQLMVHHAZjs.isRootCrdt; | ||
exports.isScope = _chunkQLMVHHAZjs.isScope; | ||
exports.lsonToJson = lsonToJson; | ||
exports.makePosition = _chunkQLMVHHAZjs.makePosition; | ||
exports.nn = _chunkQLMVHHAZjs.nn; | ||
exports.patchImmutableObject = patchImmutableObject; | ||
exports.patchLiveObjectKey = patchLiveObjectKey; | ||
exports.throwUsageError = _chunkQLMVHHAZjs.throwUsageError; | ||
exports.tryParseJson = _chunkQLMVHHAZjs.tryParseJson; |
{ | ||
"name": "@liveblocks/client", | ||
"version": "0.17.8", | ||
"version": "0.17.9", | ||
"description": "A client that lets you interact with Liveblocks servers.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4
3
302321
7469
1