@liveblocks/core 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +15 -3
- package/dist/index.js +99 -46
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -686,11 +686,11 @@ declare function asArrayWithLegacyMethods<T>(arr: readonly T[]): ReadonlyArrayWi
|
|
|
686
686
|
*/
|
|
687
687
|
declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta> = {
|
|
688
688
|
/**
|
|
689
|
-
* The connection
|
|
689
|
+
* The connection ID of the User. It is unique and increment at every new connection.
|
|
690
690
|
*/
|
|
691
691
|
readonly connectionId: number;
|
|
692
692
|
/**
|
|
693
|
-
* The
|
|
693
|
+
* The ID of the User that has been set in the authentication endpoint.
|
|
694
694
|
* Useful to get additional information about the connected user.
|
|
695
695
|
*/
|
|
696
696
|
readonly id: TUserMeta["id"];
|
|
@@ -699,7 +699,7 @@ declare type User<TPresence extends JsonObject, TUserMeta extends BaseUserMeta>
|
|
|
699
699
|
*/
|
|
700
700
|
readonly info: TUserMeta["info"];
|
|
701
701
|
/**
|
|
702
|
-
* The user presence.
|
|
702
|
+
* The user’s presence data.
|
|
703
703
|
*/
|
|
704
704
|
readonly presence: TPresence;
|
|
705
705
|
/**
|
|
@@ -1052,6 +1052,17 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1052
1052
|
*/
|
|
1053
1053
|
addToHistory: boolean;
|
|
1054
1054
|
}): void;
|
|
1055
|
+
/**
|
|
1056
|
+
*
|
|
1057
|
+
* Sends Yjs document updates to liveblocks server
|
|
1058
|
+
*
|
|
1059
|
+
* @param {string} data the doc update to send to the server, base64 encoded uint8array
|
|
1060
|
+
*/
|
|
1061
|
+
updateYDoc(data: string): void;
|
|
1062
|
+
/**
|
|
1063
|
+
* Sends a request for the current document from liveblocks server
|
|
1064
|
+
*/
|
|
1065
|
+
fetchYDoc(stateVector: string): void;
|
|
1055
1066
|
/**
|
|
1056
1067
|
* Broadcasts an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
|
|
1057
1068
|
* @param {any} event the event to broadcast. Should be serializable to JSON
|
|
@@ -1109,6 +1120,7 @@ declare type Room<TPresence extends JsonObject, TStorage extends LsonObject, TUs
|
|
|
1109
1120
|
*/
|
|
1110
1121
|
readonly storageDidLoad: Observable<void>;
|
|
1111
1122
|
readonly storageStatus: Observable<StorageStatus>;
|
|
1123
|
+
readonly ydoc: Observable<string>;
|
|
1112
1124
|
};
|
|
1113
1125
|
/**
|
|
1114
1126
|
* Batches modifications made during the given function.
|
package/dist/index.js
CHANGED
|
@@ -145,7 +145,7 @@ var onMessageFromPanel = eventSource.observable;
|
|
|
145
145
|
// src/devtools/index.ts
|
|
146
146
|
var VERSION = true ? (
|
|
147
147
|
/* istanbul ignore next */
|
|
148
|
-
"1.1.
|
|
148
|
+
"1.1.2"
|
|
149
149
|
) : "dev";
|
|
150
150
|
var _devtoolsSetupHasRun = false;
|
|
151
151
|
function setupDevTools(getAllRooms) {
|
|
@@ -3973,6 +3973,19 @@ var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
|
|
|
3973
3973
|
return ServerMsgCode2;
|
|
3974
3974
|
})(ServerMsgCode || {});
|
|
3975
3975
|
|
|
3976
|
+
// src/lib/LegacyArray.ts
|
|
3977
|
+
function asArrayWithLegacyMethods(arr) {
|
|
3978
|
+
Object.defineProperty(arr, "count", {
|
|
3979
|
+
value: arr.length,
|
|
3980
|
+
enumerable: false
|
|
3981
|
+
});
|
|
3982
|
+
Object.defineProperty(arr, "toArray", {
|
|
3983
|
+
value: () => arr,
|
|
3984
|
+
enumerable: false
|
|
3985
|
+
});
|
|
3986
|
+
return freeze(arr);
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3976
3989
|
// src/refs/ImmutableRef.ts
|
|
3977
3990
|
function merge(target, patch) {
|
|
3978
3991
|
let updated = false;
|
|
@@ -4010,42 +4023,6 @@ var ImmutableRef = class {
|
|
|
4010
4023
|
}
|
|
4011
4024
|
};
|
|
4012
4025
|
|
|
4013
|
-
// src/refs/MeRef.ts
|
|
4014
|
-
var MeRef = class extends ImmutableRef {
|
|
4015
|
-
constructor(initialPresence) {
|
|
4016
|
-
super();
|
|
4017
|
-
this._me = freeze(compactObject(initialPresence));
|
|
4018
|
-
}
|
|
4019
|
-
/** @internal */
|
|
4020
|
-
_toImmutable() {
|
|
4021
|
-
return this._me;
|
|
4022
|
-
}
|
|
4023
|
-
/**
|
|
4024
|
-
* Patches the current "me" instance.
|
|
4025
|
-
*/
|
|
4026
|
-
patch(patch) {
|
|
4027
|
-
const oldMe = this._me;
|
|
4028
|
-
const newMe = merge(oldMe, patch);
|
|
4029
|
-
if (oldMe !== newMe) {
|
|
4030
|
-
this._me = freeze(newMe);
|
|
4031
|
-
this.invalidate();
|
|
4032
|
-
}
|
|
4033
|
-
}
|
|
4034
|
-
};
|
|
4035
|
-
|
|
4036
|
-
// src/lib/LegacyArray.ts
|
|
4037
|
-
function asArrayWithLegacyMethods(arr) {
|
|
4038
|
-
Object.defineProperty(arr, "count", {
|
|
4039
|
-
value: arr.length,
|
|
4040
|
-
enumerable: false
|
|
4041
|
-
});
|
|
4042
|
-
Object.defineProperty(arr, "toArray", {
|
|
4043
|
-
value: () => arr,
|
|
4044
|
-
enumerable: false
|
|
4045
|
-
});
|
|
4046
|
-
return freeze(arr);
|
|
4047
|
-
}
|
|
4048
|
-
|
|
4049
4026
|
// src/refs/OthersRef.ts
|
|
4050
4027
|
function makeUser(conn, presence) {
|
|
4051
4028
|
return freeze(compactObject(__spreadProps(__spreadValues({}, conn), { presence })));
|
|
@@ -4155,6 +4132,29 @@ var OthersRef = class extends ImmutableRef {
|
|
|
4155
4132
|
}
|
|
4156
4133
|
};
|
|
4157
4134
|
|
|
4135
|
+
// src/refs/PatchableRef.ts
|
|
4136
|
+
var PatchableRef = class extends ImmutableRef {
|
|
4137
|
+
constructor(data) {
|
|
4138
|
+
super();
|
|
4139
|
+
this._data = freeze(compactObject(data));
|
|
4140
|
+
}
|
|
4141
|
+
/** @internal */
|
|
4142
|
+
_toImmutable() {
|
|
4143
|
+
return this._data;
|
|
4144
|
+
}
|
|
4145
|
+
/**
|
|
4146
|
+
* Patches the current object.
|
|
4147
|
+
*/
|
|
4148
|
+
patch(patch) {
|
|
4149
|
+
const oldMe = this._data;
|
|
4150
|
+
const newMe = merge(oldMe, patch);
|
|
4151
|
+
if (oldMe !== newMe) {
|
|
4152
|
+
this._data = freeze(newMe);
|
|
4153
|
+
this.invalidate();
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
};
|
|
4157
|
+
|
|
4158
4158
|
// src/refs/ValueRef.ts
|
|
4159
4159
|
var ValueRef = class extends ImmutableRef {
|
|
4160
4160
|
constructor(initialValue) {
|
|
@@ -4237,7 +4237,7 @@ function createRoom(options, config) {
|
|
|
4237
4237
|
storageOperations: []
|
|
4238
4238
|
},
|
|
4239
4239
|
sessionInfo: new ValueRef(null),
|
|
4240
|
-
me: new
|
|
4240
|
+
me: new PatchableRef(initialPresence),
|
|
4241
4241
|
others: new OthersRef(),
|
|
4242
4242
|
initialStorage,
|
|
4243
4243
|
idFactory: null,
|
|
@@ -4262,9 +4262,10 @@ function createRoom(options, config) {
|
|
|
4262
4262
|
const token = (_a2 = managedSocket.token) == null ? void 0 : _a2.parsed;
|
|
4263
4263
|
if (token !== void 0 && token !== lastToken) {
|
|
4264
4264
|
context.sessionInfo.set({
|
|
4265
|
-
id: token.actor,
|
|
4266
4265
|
userInfo: token.info,
|
|
4267
4266
|
userId: token.id,
|
|
4267
|
+
// NOTE: In the future, these fields will get assigned in the connection phase
|
|
4268
|
+
actor: token.actor,
|
|
4268
4269
|
isReadOnly: isStorageReadOnly(token.scopes)
|
|
4269
4270
|
});
|
|
4270
4271
|
lastToken = token;
|
|
@@ -4316,7 +4317,7 @@ function createRoom(options, config) {
|
|
|
4316
4317
|
__spreadValues({}, context.me.current)
|
|
4317
4318
|
)
|
|
4318
4319
|
};
|
|
4319
|
-
context.idFactory = makeIdFactory(sessionInfo.
|
|
4320
|
+
context.idFactory = makeIdFactory(sessionInfo.actor);
|
|
4320
4321
|
if (_getStorage$ !== null) {
|
|
4321
4322
|
refreshStorage({ flush: false });
|
|
4322
4323
|
}
|
|
@@ -4402,7 +4403,8 @@ function createRoom(options, config) {
|
|
|
4402
4403
|
storage: makeEventSource(),
|
|
4403
4404
|
history: makeEventSource(),
|
|
4404
4405
|
storageDidLoad: makeEventSource(),
|
|
4405
|
-
storageStatus: makeEventSource()
|
|
4406
|
+
storageStatus: makeEventSource(),
|
|
4407
|
+
ydoc: makeEventSource()
|
|
4406
4408
|
};
|
|
4407
4409
|
function sendMessages(messageOrMessages) {
|
|
4408
4410
|
var _a2, _b2;
|
|
@@ -4432,7 +4434,7 @@ function createRoom(options, config) {
|
|
|
4432
4434
|
context.me,
|
|
4433
4435
|
(info, me) => {
|
|
4434
4436
|
return info !== null ? {
|
|
4435
|
-
connectionId: info.
|
|
4437
|
+
connectionId: info.actor,
|
|
4436
4438
|
id: info.userId,
|
|
4437
4439
|
info: info.userInfo,
|
|
4438
4440
|
presence: me,
|
|
@@ -4509,7 +4511,7 @@ function createRoom(options, config) {
|
|
|
4509
4511
|
function getConnectionId() {
|
|
4510
4512
|
const info = context.sessionInfo.current;
|
|
4511
4513
|
if (info) {
|
|
4512
|
-
return info.
|
|
4514
|
+
return info.actor;
|
|
4513
4515
|
}
|
|
4514
4516
|
throw new Error(
|
|
4515
4517
|
"Internal. Tried to get connection id but connection was never open"
|
|
@@ -4823,6 +4825,10 @@ function createRoom(options, config) {
|
|
|
4823
4825
|
}
|
|
4824
4826
|
break;
|
|
4825
4827
|
}
|
|
4828
|
+
case 300 /* UPDATE_YDOC */: {
|
|
4829
|
+
eventHub.ydoc.notify(message.update);
|
|
4830
|
+
break;
|
|
4831
|
+
}
|
|
4826
4832
|
case 104 /* ROOM_STATE */: {
|
|
4827
4833
|
updates.others.push(onRoomStateMessage(message));
|
|
4828
4834
|
break;
|
|
@@ -4941,6 +4947,13 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
4941
4947
|
}
|
|
4942
4948
|
return messages;
|
|
4943
4949
|
}
|
|
4950
|
+
function updateYDoc(update) {
|
|
4951
|
+
context.buffer.messages.push({
|
|
4952
|
+
type: 301 /* UPDATE_YDOC */,
|
|
4953
|
+
update
|
|
4954
|
+
});
|
|
4955
|
+
flushNowOrSoon();
|
|
4956
|
+
}
|
|
4944
4957
|
function broadcastEvent(event, options2 = {
|
|
4945
4958
|
shouldQueueEventIfNotReady: false
|
|
4946
4959
|
}) {
|
|
@@ -5000,6 +5013,13 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5000
5013
|
};
|
|
5001
5014
|
});
|
|
5002
5015
|
}
|
|
5016
|
+
function fetchYDoc(vector) {
|
|
5017
|
+
context.buffer.messages.push({
|
|
5018
|
+
type: 300 /* FETCH_YDOC */,
|
|
5019
|
+
vector
|
|
5020
|
+
});
|
|
5021
|
+
flushNowOrSoon();
|
|
5022
|
+
}
|
|
5003
5023
|
function undo() {
|
|
5004
5024
|
if (context.activeBatch) {
|
|
5005
5025
|
throw new Error("undo is not allowed during a batch");
|
|
@@ -5121,7 +5141,8 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5121
5141
|
storage: eventHub.storage.observable,
|
|
5122
5142
|
history: eventHub.history.observable,
|
|
5123
5143
|
storageDidLoad: eventHub.storageDidLoad.observable,
|
|
5124
|
-
storageStatus: eventHub.storageStatus.observable
|
|
5144
|
+
storageStatus: eventHub.storageStatus.observable,
|
|
5145
|
+
ydoc: eventHub.ydoc.observable
|
|
5125
5146
|
};
|
|
5126
5147
|
return {
|
|
5127
5148
|
/* NOTE: Exposing __internal here only to allow testing implementation details in unit tests */
|
|
@@ -5156,6 +5177,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5156
5177
|
destroy: () => managedSocket.destroy(),
|
|
5157
5178
|
// Presence
|
|
5158
5179
|
updatePresence,
|
|
5180
|
+
updateYDoc,
|
|
5159
5181
|
broadcastEvent,
|
|
5160
5182
|
// Storage
|
|
5161
5183
|
batch,
|
|
@@ -5167,6 +5189,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5167
5189
|
pause: pauseHistory,
|
|
5168
5190
|
resume: resumeHistory
|
|
5169
5191
|
},
|
|
5192
|
+
fetchYDoc,
|
|
5170
5193
|
getStorage,
|
|
5171
5194
|
getStorageSnapshot,
|
|
5172
5195
|
getStorageStatus,
|
|
@@ -5282,7 +5305,7 @@ function makeCreateSocketDelegateForRoom(liveblocksServer, WebSocketPolyfill) {
|
|
|
5282
5305
|
// @ts-ignore (__PACKAGE_VERSION__ will be injected by the build script)
|
|
5283
5306
|
true ? (
|
|
5284
5307
|
/* istanbul ignore next */
|
|
5285
|
-
"1.1.
|
|
5308
|
+
"1.1.2"
|
|
5286
5309
|
) : "dev"}`
|
|
5287
5310
|
);
|
|
5288
5311
|
};
|
|
@@ -5547,6 +5570,35 @@ function buildLiveblocksPublicAuthorizeEndpoint(options, roomId) {
|
|
|
5547
5570
|
)}/public/authorize`;
|
|
5548
5571
|
}
|
|
5549
5572
|
|
|
5573
|
+
// src/crdts/utils.ts
|
|
5574
|
+
function toPlainLson(lson) {
|
|
5575
|
+
if (lson instanceof LiveObject) {
|
|
5576
|
+
return {
|
|
5577
|
+
liveblocksType: "LiveObject",
|
|
5578
|
+
data: Object.fromEntries(
|
|
5579
|
+
Object.entries(lson.toObject()).map(([key, value]) => [
|
|
5580
|
+
key,
|
|
5581
|
+
value ? toPlainLson(value) : ""
|
|
5582
|
+
])
|
|
5583
|
+
)
|
|
5584
|
+
};
|
|
5585
|
+
} else if (lson instanceof LiveMap) {
|
|
5586
|
+
return {
|
|
5587
|
+
liveblocksType: "LiveMap",
|
|
5588
|
+
data: Object.fromEntries(
|
|
5589
|
+
[...lson].map(([key, value]) => [key, toPlainLson(value)])
|
|
5590
|
+
)
|
|
5591
|
+
};
|
|
5592
|
+
} else if (lson instanceof LiveList) {
|
|
5593
|
+
return {
|
|
5594
|
+
liveblocksType: "LiveList",
|
|
5595
|
+
data: [...lson].map((item) => toPlainLson(item))
|
|
5596
|
+
};
|
|
5597
|
+
} else {
|
|
5598
|
+
return lson;
|
|
5599
|
+
}
|
|
5600
|
+
}
|
|
5601
|
+
|
|
5550
5602
|
// src/immutable.ts
|
|
5551
5603
|
function lsonObjectToJson(obj) {
|
|
5552
5604
|
const result = {};
|
|
@@ -5935,4 +5987,5 @@ var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
|
|
|
5935
5987
|
|
|
5936
5988
|
|
|
5937
5989
|
|
|
5938
|
-
|
|
5990
|
+
|
|
5991
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asArrayWithLegacyMethods = asArrayWithLegacyMethods; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.createClient = createClient; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.errorIf = errorIf; exports.freeze = freeze; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makePosition = makePosition; exports.nn = nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.shallow = shallow; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.withTimeout = withTimeout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Shared code and foundational internals for Liveblocks",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"test:types": "tsd",
|
|
28
28
|
"test:watch": "jest --silent --verbose --color=always --watch",
|
|
29
29
|
"test:e2e": "jest --silent --verbose --color=always --config=./jest.config.e2e.js",
|
|
30
|
-
"test:deps": "depcruise src --exclude __tests__
|
|
31
|
-
"showdeps": "depcruise src --include-only '^src' --exclude='__tests__' --
|
|
32
|
-
"showdeps:high-level": "depcruise src --include-only '^src' --exclude='(^src/index.ts|shallow.ts|__tests__)' --collapse='^src/(refs|lib|compat|types|crdts|protocol)' --
|
|
30
|
+
"test:deps": "depcruise src --exclude __tests__",
|
|
31
|
+
"showdeps": "depcruise src --include-only '^src' --exclude='__tests__' --output-type dot | dot -T svg > /tmp/dependency-graph.svg && open /tmp/dependency-graph.svg",
|
|
32
|
+
"showdeps:high-level": "depcruise src --include-only '^src' --exclude='(^src/index.ts|shallow.ts|__tests__)' --collapse='^src/(refs|lib|compat|types|crdts|protocol)' --output-type dot | dot -T svg > /tmp/dependency-graph.svg && open /tmp/dependency-graph.svg"
|
|
33
33
|
},
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"devDependencies": {
|