@liveblocks/core 3.14.0-pre1 → 3.14.0-pre3
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.cjs +218 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -29
- package/dist/index.d.ts +83 -29
- package/dist/index.js +217 -128
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "3.14.0-
|
|
9
|
+
var PKG_VERSION = "3.14.0-pre3";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -3143,7 +3143,12 @@ var ServerMsgCode = Object.freeze({
|
|
|
3143
3143
|
BROADCASTED_EVENT: 103,
|
|
3144
3144
|
ROOM_STATE: 104,
|
|
3145
3145
|
// For Storage
|
|
3146
|
-
|
|
3146
|
+
STORAGE_STATE_V7: 200,
|
|
3147
|
+
// Only sent in V7
|
|
3148
|
+
STORAGE_CHUNK: 210,
|
|
3149
|
+
// Used in V8+
|
|
3150
|
+
STORAGE_STREAM_END: 211,
|
|
3151
|
+
// Used in V8+
|
|
3147
3152
|
UPDATE_STORAGE: 201,
|
|
3148
3153
|
// For Yjs Docs
|
|
3149
3154
|
UPDATE_YDOC: 300,
|
|
@@ -3222,7 +3227,7 @@ var BACKOFF_DELAYS_SLOW = [2e3, 3e4, 6e4, 3e5];
|
|
|
3222
3227
|
var HEARTBEAT_INTERVAL = 3e4;
|
|
3223
3228
|
var PONG_TIMEOUT = 2e3;
|
|
3224
3229
|
var AUTH_TIMEOUT = 1e4;
|
|
3225
|
-
var SOCKET_CONNECT_TIMEOUT =
|
|
3230
|
+
var SOCKET_CONNECT_TIMEOUT = 2e4;
|
|
3226
3231
|
var StopRetrying = class extends Error {
|
|
3227
3232
|
constructor(reason) {
|
|
3228
3233
|
super(reason);
|
|
@@ -4167,41 +4172,6 @@ var TreePool = class {
|
|
|
4167
4172
|
}
|
|
4168
4173
|
};
|
|
4169
4174
|
|
|
4170
|
-
// src/protocol/AuthToken.ts
|
|
4171
|
-
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
4172
|
-
Permission2["Read"] = "room:read";
|
|
4173
|
-
Permission2["Write"] = "room:write";
|
|
4174
|
-
Permission2["PresenceWrite"] = "room:presence:write";
|
|
4175
|
-
Permission2["CommentsWrite"] = "comments:write";
|
|
4176
|
-
Permission2["CommentsRead"] = "comments:read";
|
|
4177
|
-
return Permission2;
|
|
4178
|
-
})(Permission || {});
|
|
4179
|
-
function canWriteStorage(scopes) {
|
|
4180
|
-
return scopes.includes("room:write" /* Write */);
|
|
4181
|
-
}
|
|
4182
|
-
function canComment(scopes) {
|
|
4183
|
-
return scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:write" /* Write */);
|
|
4184
|
-
}
|
|
4185
|
-
function isValidAuthTokenPayload(data) {
|
|
4186
|
-
return isPlainObject(data) && (data.k === "acc" /* ACCESS_TOKEN */ || data.k === "id" /* ID_TOKEN */ || data.k === "sec-legacy" /* SECRET_LEGACY */);
|
|
4187
|
-
}
|
|
4188
|
-
function parseAuthToken(rawTokenString) {
|
|
4189
|
-
const tokenParts = rawTokenString.split(".");
|
|
4190
|
-
if (tokenParts.length !== 3) {
|
|
4191
|
-
throw new Error("Authentication error: invalid JWT token");
|
|
4192
|
-
}
|
|
4193
|
-
const payload = tryParseJson(b64decode(tokenParts[1]));
|
|
4194
|
-
if (!(payload && isValidAuthTokenPayload(payload))) {
|
|
4195
|
-
throw new Error(
|
|
4196
|
-
"Authentication error: expected a valid token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback"
|
|
4197
|
-
);
|
|
4198
|
-
}
|
|
4199
|
-
return {
|
|
4200
|
-
raw: rawTokenString,
|
|
4201
|
-
parsed: payload
|
|
4202
|
-
};
|
|
4203
|
-
}
|
|
4204
|
-
|
|
4205
4175
|
// src/ai.ts
|
|
4206
4176
|
var DEFAULT_REQUEST_TIMEOUT = 4e3;
|
|
4207
4177
|
function defineAiTool() {
|
|
@@ -4730,8 +4700,8 @@ function createAi(config) {
|
|
|
4730
4700
|
if (authValue.type === "secret") {
|
|
4731
4701
|
const token = authValue.token.parsed;
|
|
4732
4702
|
context.staticSessionInfoSig.set({
|
|
4733
|
-
userId: token.
|
|
4734
|
-
userInfo: token.
|
|
4703
|
+
userId: token.uid,
|
|
4704
|
+
userInfo: token.ui
|
|
4735
4705
|
});
|
|
4736
4706
|
} else {
|
|
4737
4707
|
context.staticSessionInfoSig.set({
|
|
@@ -5153,6 +5123,41 @@ function createReceivingToolInvocation(invocationId, name, partialArgsText = "")
|
|
|
5153
5123
|
};
|
|
5154
5124
|
}
|
|
5155
5125
|
|
|
5126
|
+
// src/protocol/AuthToken.ts
|
|
5127
|
+
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
5128
|
+
Permission2["Read"] = "room:read";
|
|
5129
|
+
Permission2["Write"] = "room:write";
|
|
5130
|
+
Permission2["PresenceWrite"] = "room:presence:write";
|
|
5131
|
+
Permission2["CommentsWrite"] = "comments:write";
|
|
5132
|
+
Permission2["CommentsRead"] = "comments:read";
|
|
5133
|
+
return Permission2;
|
|
5134
|
+
})(Permission || {});
|
|
5135
|
+
function canWriteStorage(scopes) {
|
|
5136
|
+
return scopes.includes("room:write" /* Write */);
|
|
5137
|
+
}
|
|
5138
|
+
function canComment(scopes) {
|
|
5139
|
+
return scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:write" /* Write */);
|
|
5140
|
+
}
|
|
5141
|
+
function isValidAuthTokenPayload(data) {
|
|
5142
|
+
return isPlainObject(data) && (data.k === "acc" /* ACCESS_TOKEN */ || data.k === "id" /* ID_TOKEN */);
|
|
5143
|
+
}
|
|
5144
|
+
function parseAuthToken(rawTokenString) {
|
|
5145
|
+
const tokenParts = rawTokenString.split(".");
|
|
5146
|
+
if (tokenParts.length !== 3) {
|
|
5147
|
+
throw new Error("Authentication error: invalid JWT token");
|
|
5148
|
+
}
|
|
5149
|
+
const payload = tryParseJson(b64decode(tokenParts[1]));
|
|
5150
|
+
if (!(payload && isValidAuthTokenPayload(payload))) {
|
|
5151
|
+
throw new Error(
|
|
5152
|
+
"Authentication error: expected a valid token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback"
|
|
5153
|
+
);
|
|
5154
|
+
}
|
|
5155
|
+
return {
|
|
5156
|
+
raw: rawTokenString,
|
|
5157
|
+
parsed: payload
|
|
5158
|
+
};
|
|
5159
|
+
}
|
|
5160
|
+
|
|
5156
5161
|
// src/auth-manager.ts
|
|
5157
5162
|
var NON_RETRY_STATUS_CODES = [
|
|
5158
5163
|
400,
|
|
@@ -5287,10 +5292,8 @@ function createAuthManager(authOptions, onAuthenticate) {
|
|
|
5287
5292
|
const BUFFER = 30;
|
|
5288
5293
|
const expiresAt = Math.floor(Date.now() / 1e3) + (token.parsed.exp - token.parsed.iat) - BUFFER;
|
|
5289
5294
|
seenTokens.add(token.raw);
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
expiryTimes.push(expiresAt);
|
|
5293
|
-
}
|
|
5295
|
+
tokens.push(token);
|
|
5296
|
+
expiryTimes.push(expiresAt);
|
|
5294
5297
|
return { type: "secret", token };
|
|
5295
5298
|
} finally {
|
|
5296
5299
|
if (requestOptions.roomId) {
|
|
@@ -6212,13 +6215,82 @@ var AbstractCrdt = class {
|
|
|
6212
6215
|
}
|
|
6213
6216
|
};
|
|
6214
6217
|
|
|
6215
|
-
// src/protocol/
|
|
6218
|
+
// src/protocol/StorageNode.ts
|
|
6216
6219
|
var CrdtType = Object.freeze({
|
|
6217
6220
|
OBJECT: 0,
|
|
6218
6221
|
LIST: 1,
|
|
6219
6222
|
MAP: 2,
|
|
6220
6223
|
REGISTER: 3
|
|
6221
6224
|
});
|
|
6225
|
+
function isRootStorageNode(node) {
|
|
6226
|
+
return node[0] === "root";
|
|
6227
|
+
}
|
|
6228
|
+
function isObjectStorageNode(node) {
|
|
6229
|
+
return node[1].type === CrdtType.OBJECT;
|
|
6230
|
+
}
|
|
6231
|
+
function isListStorageNode(node) {
|
|
6232
|
+
return node[1].type === CrdtType.LIST;
|
|
6233
|
+
}
|
|
6234
|
+
function isMapStorageNode(node) {
|
|
6235
|
+
return node[1].type === CrdtType.MAP;
|
|
6236
|
+
}
|
|
6237
|
+
function isRegisterStorageNode(node) {
|
|
6238
|
+
return node[1].type === CrdtType.REGISTER;
|
|
6239
|
+
}
|
|
6240
|
+
function isCompactRootNode(node) {
|
|
6241
|
+
return node[0] === "root";
|
|
6242
|
+
}
|
|
6243
|
+
function* compactNodesToNodeStream(compactNodes) {
|
|
6244
|
+
for (const cnode of compactNodes) {
|
|
6245
|
+
if (isCompactRootNode(cnode)) {
|
|
6246
|
+
yield [cnode[0], { type: CrdtType.OBJECT, data: cnode[1] }];
|
|
6247
|
+
continue;
|
|
6248
|
+
}
|
|
6249
|
+
switch (cnode[1]) {
|
|
6250
|
+
case CrdtType.OBJECT:
|
|
6251
|
+
yield [cnode[0], { type: CrdtType.OBJECT, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
6252
|
+
break;
|
|
6253
|
+
case CrdtType.LIST:
|
|
6254
|
+
yield [cnode[0], { type: CrdtType.LIST, parentId: cnode[2], parentKey: cnode[3] }];
|
|
6255
|
+
break;
|
|
6256
|
+
case CrdtType.MAP:
|
|
6257
|
+
yield [cnode[0], { type: CrdtType.MAP, parentId: cnode[2], parentKey: cnode[3] }];
|
|
6258
|
+
break;
|
|
6259
|
+
case CrdtType.REGISTER:
|
|
6260
|
+
yield [cnode[0], { type: CrdtType.REGISTER, parentId: cnode[2], parentKey: cnode[3], data: cnode[4] }];
|
|
6261
|
+
break;
|
|
6262
|
+
default:
|
|
6263
|
+
}
|
|
6264
|
+
}
|
|
6265
|
+
}
|
|
6266
|
+
function* nodeStreamToCompactNodes(nodes) {
|
|
6267
|
+
for (const node of nodes) {
|
|
6268
|
+
if (isObjectStorageNode(node)) {
|
|
6269
|
+
if (isRootStorageNode(node)) {
|
|
6270
|
+
const id = node[0];
|
|
6271
|
+
const crdt = node[1];
|
|
6272
|
+
yield [id, crdt.data];
|
|
6273
|
+
} else {
|
|
6274
|
+
const id = node[0];
|
|
6275
|
+
const crdt = node[1];
|
|
6276
|
+
yield [id, CrdtType.OBJECT, crdt.parentId, crdt.parentKey, crdt.data];
|
|
6277
|
+
}
|
|
6278
|
+
} else if (isListStorageNode(node)) {
|
|
6279
|
+
const id = node[0];
|
|
6280
|
+
const crdt = node[1];
|
|
6281
|
+
yield [id, CrdtType.LIST, crdt.parentId, crdt.parentKey];
|
|
6282
|
+
} else if (isMapStorageNode(node)) {
|
|
6283
|
+
const id = node[0];
|
|
6284
|
+
const crdt = node[1];
|
|
6285
|
+
yield [id, CrdtType.MAP, crdt.parentId, crdt.parentKey];
|
|
6286
|
+
} else if (isRegisterStorageNode(node)) {
|
|
6287
|
+
const id = node[0];
|
|
6288
|
+
const crdt = node[1];
|
|
6289
|
+
yield [id, CrdtType.REGISTER, crdt.parentId, crdt.parentKey, crdt.data];
|
|
6290
|
+
} else {
|
|
6291
|
+
}
|
|
6292
|
+
}
|
|
6293
|
+
}
|
|
6222
6294
|
|
|
6223
6295
|
// src/crdts/LiveRegister.ts
|
|
6224
6296
|
var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
@@ -6321,15 +6393,16 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
6321
6393
|
}
|
|
6322
6394
|
}
|
|
6323
6395
|
/** @internal */
|
|
6324
|
-
static _deserialize([id], parentToChildren, pool) {
|
|
6396
|
+
static _deserialize([id, _], parentToChildren, pool) {
|
|
6325
6397
|
const list = new _LiveList([]);
|
|
6326
6398
|
list._attach(id, pool);
|
|
6327
6399
|
const children = parentToChildren.get(id);
|
|
6328
6400
|
if (children === void 0) {
|
|
6329
6401
|
return list;
|
|
6330
6402
|
}
|
|
6331
|
-
for (const
|
|
6332
|
-
const
|
|
6403
|
+
for (const node of children) {
|
|
6404
|
+
const crdt = node[1];
|
|
6405
|
+
const child = deserialize(node, parentToChildren, pool);
|
|
6333
6406
|
child._setParentLink(list, crdt.parentKey);
|
|
6334
6407
|
list._insertAndSort(child);
|
|
6335
6408
|
}
|
|
@@ -7346,8 +7419,9 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7346
7419
|
if (children === void 0) {
|
|
7347
7420
|
return map;
|
|
7348
7421
|
}
|
|
7349
|
-
for (const
|
|
7350
|
-
const
|
|
7422
|
+
for (const node of children) {
|
|
7423
|
+
const crdt = node[1];
|
|
7424
|
+
const child = deserialize(node, parentToChildren, pool);
|
|
7351
7425
|
child._setParentLink(map, crdt.parentKey);
|
|
7352
7426
|
map.#map.set(crdt.parentKey, child);
|
|
7353
7427
|
map.invalidate();
|
|
@@ -7648,9 +7722,6 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
7648
7722
|
|
|
7649
7723
|
// src/crdts/LiveObject.ts
|
|
7650
7724
|
var MAX_LIVE_OBJECT_SIZE = 128 * 1024;
|
|
7651
|
-
function isRootCrdt(id, _) {
|
|
7652
|
-
return id === "root";
|
|
7653
|
-
}
|
|
7654
7725
|
var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
7655
7726
|
#map;
|
|
7656
7727
|
/**
|
|
@@ -7677,19 +7748,19 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7677
7748
|
* @experimental
|
|
7678
7749
|
*/
|
|
7679
7750
|
static __initStatic() {this.detectLargeObjects = false}
|
|
7680
|
-
static #buildRootAndParentToChildren(
|
|
7751
|
+
static #buildRootAndParentToChildren(nodes) {
|
|
7681
7752
|
const parentToChildren = /* @__PURE__ */ new Map();
|
|
7682
7753
|
let root = null;
|
|
7683
|
-
for (const
|
|
7684
|
-
if (
|
|
7685
|
-
root =
|
|
7754
|
+
for (const node of nodes) {
|
|
7755
|
+
if (isRootStorageNode(node)) {
|
|
7756
|
+
root = node[1];
|
|
7686
7757
|
} else {
|
|
7687
|
-
const
|
|
7758
|
+
const crdt = node[1];
|
|
7688
7759
|
const children = parentToChildren.get(crdt.parentId);
|
|
7689
7760
|
if (children !== void 0) {
|
|
7690
|
-
children.push(
|
|
7761
|
+
children.push(node);
|
|
7691
7762
|
} else {
|
|
7692
|
-
parentToChildren.set(crdt.parentId, [
|
|
7763
|
+
parentToChildren.set(crdt.parentId, [node]);
|
|
7693
7764
|
}
|
|
7694
7765
|
}
|
|
7695
7766
|
}
|
|
@@ -7699,8 +7770,8 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7699
7770
|
return [root, parentToChildren];
|
|
7700
7771
|
}
|
|
7701
7772
|
/** @private Do not use this API directly */
|
|
7702
|
-
static _fromItems(
|
|
7703
|
-
const [root, parentToChildren] = _LiveObject.#buildRootAndParentToChildren(
|
|
7773
|
+
static _fromItems(nodes, pool) {
|
|
7774
|
+
const [root, parentToChildren] = _LiveObject.#buildRootAndParentToChildren(nodes);
|
|
7704
7775
|
return _LiveObject._deserialize(
|
|
7705
7776
|
["root", root],
|
|
7706
7777
|
parentToChildren,
|
|
@@ -7754,8 +7825,9 @@ var LiveObject = (_class2 = class _LiveObject extends AbstractCrdt {
|
|
|
7754
7825
|
if (children === void 0) {
|
|
7755
7826
|
return liveObj;
|
|
7756
7827
|
}
|
|
7757
|
-
for (const
|
|
7758
|
-
const child = deserializeToLson(
|
|
7828
|
+
for (const node of children) {
|
|
7829
|
+
const child = deserializeToLson(node, parentToChildren, pool);
|
|
7830
|
+
const crdt = node[1];
|
|
7759
7831
|
if (isLiveStructure(child)) {
|
|
7760
7832
|
child._setParentLink(liveObj, crdt.parentKey);
|
|
7761
7833
|
}
|
|
@@ -8242,42 +8314,30 @@ function isSameNodeOrChildOf(node, parent) {
|
|
|
8242
8314
|
}
|
|
8243
8315
|
return false;
|
|
8244
8316
|
}
|
|
8245
|
-
function deserialize(
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
}
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
case CrdtType.LIST: {
|
|
8270
|
-
return LiveList._deserialize([id, crdt], parentToChildren, pool);
|
|
8271
|
-
}
|
|
8272
|
-
case CrdtType.MAP: {
|
|
8273
|
-
return LiveMap._deserialize([id, crdt], parentToChildren, pool);
|
|
8274
|
-
}
|
|
8275
|
-
case CrdtType.REGISTER: {
|
|
8276
|
-
return crdt.data;
|
|
8277
|
-
}
|
|
8278
|
-
default: {
|
|
8279
|
-
throw new Error("Unexpected CRDT type");
|
|
8280
|
-
}
|
|
8317
|
+
function deserialize(node, parentToChildren, pool) {
|
|
8318
|
+
if (isObjectStorageNode(node)) {
|
|
8319
|
+
return LiveObject._deserialize(node, parentToChildren, pool);
|
|
8320
|
+
} else if (isListStorageNode(node)) {
|
|
8321
|
+
return LiveList._deserialize(node, parentToChildren, pool);
|
|
8322
|
+
} else if (isMapStorageNode(node)) {
|
|
8323
|
+
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
8324
|
+
} else if (isRegisterStorageNode(node)) {
|
|
8325
|
+
return LiveRegister._deserialize(node, parentToChildren, pool);
|
|
8326
|
+
} else {
|
|
8327
|
+
throw new Error("Unexpected CRDT type");
|
|
8328
|
+
}
|
|
8329
|
+
}
|
|
8330
|
+
function deserializeToLson(node, parentToChildren, pool) {
|
|
8331
|
+
if (isObjectStorageNode(node)) {
|
|
8332
|
+
return LiveObject._deserialize(node, parentToChildren, pool);
|
|
8333
|
+
} else if (isListStorageNode(node)) {
|
|
8334
|
+
return LiveList._deserialize(node, parentToChildren, pool);
|
|
8335
|
+
} else if (isMapStorageNode(node)) {
|
|
8336
|
+
return LiveMap._deserialize(node, parentToChildren, pool);
|
|
8337
|
+
} else if (isRegisterStorageNode(node)) {
|
|
8338
|
+
return node[1].data;
|
|
8339
|
+
} else {
|
|
8340
|
+
throw new Error("Unexpected CRDT type");
|
|
8281
8341
|
}
|
|
8282
8342
|
}
|
|
8283
8343
|
function isLiveStructure(value) {
|
|
@@ -8321,10 +8381,7 @@ function getTreesDiffOperations(currentItems, newItems) {
|
|
|
8321
8381
|
const ops = [];
|
|
8322
8382
|
currentItems.forEach((_, id) => {
|
|
8323
8383
|
if (!newItems.get(id)) {
|
|
8324
|
-
ops.push({
|
|
8325
|
-
type: OpCode.DELETE_CRDT,
|
|
8326
|
-
id
|
|
8327
|
-
});
|
|
8384
|
+
ops.push({ type: OpCode.DELETE_CRDT, id });
|
|
8328
8385
|
}
|
|
8329
8386
|
});
|
|
8330
8387
|
newItems.forEach((crdt, id) => {
|
|
@@ -8824,6 +8881,23 @@ function installBackgroundTabSpy() {
|
|
|
8824
8881
|
};
|
|
8825
8882
|
return [inBackgroundSince, unsub];
|
|
8826
8883
|
}
|
|
8884
|
+
function makeNodeMapBuffer() {
|
|
8885
|
+
let map = /* @__PURE__ */ new Map();
|
|
8886
|
+
return {
|
|
8887
|
+
/** Append a "page" of nodes to the current NodeMap buffer. */
|
|
8888
|
+
append(chunk2) {
|
|
8889
|
+
for (const [id, node] of chunk2) {
|
|
8890
|
+
map.set(id, node);
|
|
8891
|
+
}
|
|
8892
|
+
},
|
|
8893
|
+
/** Return the contents of the current NodeMap buffer, and create a fresh new one. */
|
|
8894
|
+
take() {
|
|
8895
|
+
const result = map;
|
|
8896
|
+
map = /* @__PURE__ */ new Map();
|
|
8897
|
+
return result;
|
|
8898
|
+
}
|
|
8899
|
+
};
|
|
8900
|
+
}
|
|
8827
8901
|
function createRoom(options, config) {
|
|
8828
8902
|
const roomId = config.roomId;
|
|
8829
8903
|
const initialPresence = options.initialPresence;
|
|
@@ -8884,6 +8958,7 @@ function createRoom(options, config) {
|
|
|
8884
8958
|
activeBatch: null,
|
|
8885
8959
|
unacknowledgedOps: /* @__PURE__ */ new Map()
|
|
8886
8960
|
};
|
|
8961
|
+
const nodeMapBuffer = makeNodeMapBuffer();
|
|
8887
8962
|
let lastTokenKey;
|
|
8888
8963
|
function onStatusDidChange(newStatus) {
|
|
8889
8964
|
const authValue = managedSocket.authValue;
|
|
@@ -8894,8 +8969,8 @@ function createRoom(options, config) {
|
|
|
8894
8969
|
if (authValue.type === "secret") {
|
|
8895
8970
|
const token = authValue.token.parsed;
|
|
8896
8971
|
context.staticSessionInfoSig.set({
|
|
8897
|
-
userId: token.
|
|
8898
|
-
userInfo: token.
|
|
8972
|
+
userId: token.uid,
|
|
8973
|
+
userInfo: token.ui
|
|
8899
8974
|
});
|
|
8900
8975
|
} else {
|
|
8901
8976
|
context.staticSessionInfoSig.set({
|
|
@@ -9165,14 +9240,14 @@ function createRoom(options, config) {
|
|
|
9165
9240
|
self,
|
|
9166
9241
|
(me) => me !== null ? userToTreeNode("Me", me) : null
|
|
9167
9242
|
);
|
|
9168
|
-
function createOrUpdateRootFromMessage(
|
|
9169
|
-
if (message.items.length === 0) {
|
|
9170
|
-
throw new Error("Internal error: cannot load storage without items");
|
|
9171
|
-
}
|
|
9243
|
+
function createOrUpdateRootFromMessage(nodes) {
|
|
9172
9244
|
if (context.root !== void 0) {
|
|
9173
|
-
updateRoot(
|
|
9245
|
+
updateRoot(nodes);
|
|
9174
9246
|
} else {
|
|
9175
|
-
context.root = LiveObject._fromItems(
|
|
9247
|
+
context.root = LiveObject._fromItems(
|
|
9248
|
+
nodes,
|
|
9249
|
+
context.pool
|
|
9250
|
+
);
|
|
9176
9251
|
}
|
|
9177
9252
|
const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _188 => _188.get, 'call', _189 => _189(), 'optionalAccess', _190 => _190.canWrite]), () => ( true));
|
|
9178
9253
|
const stackSizeBefore = context.undoStack.length;
|
|
@@ -9189,15 +9264,18 @@ function createRoom(options, config) {
|
|
|
9189
9264
|
}
|
|
9190
9265
|
context.undoStack.length = stackSizeBefore;
|
|
9191
9266
|
}
|
|
9192
|
-
function updateRoot(
|
|
9267
|
+
function updateRoot(nodes) {
|
|
9268
|
+
if (nodes.size === 0) {
|
|
9269
|
+
throw new Error("Internal error: cannot load storage without items");
|
|
9270
|
+
}
|
|
9193
9271
|
if (context.root === void 0) {
|
|
9194
9272
|
return;
|
|
9195
9273
|
}
|
|
9196
9274
|
const currentItems = /* @__PURE__ */ new Map();
|
|
9197
|
-
for (const [id,
|
|
9198
|
-
currentItems.set(id,
|
|
9275
|
+
for (const [id, crdt] of context.pool.nodes) {
|
|
9276
|
+
currentItems.set(id, crdt._serialize());
|
|
9199
9277
|
}
|
|
9200
|
-
const ops = getTreesDiffOperations(currentItems,
|
|
9278
|
+
const ops = getTreesDiffOperations(currentItems, nodes);
|
|
9201
9279
|
const result = applyRemoteOps(ops);
|
|
9202
9280
|
notify(result.updates);
|
|
9203
9281
|
}
|
|
@@ -9572,10 +9650,12 @@ function createRoom(options, config) {
|
|
|
9572
9650
|
updates.others.push(onRoomStateMessage(message));
|
|
9573
9651
|
break;
|
|
9574
9652
|
}
|
|
9575
|
-
case ServerMsgCode.
|
|
9576
|
-
|
|
9653
|
+
case ServerMsgCode.STORAGE_CHUNK:
|
|
9654
|
+
nodeMapBuffer.append(compactNodesToNodeStream(message.nodes));
|
|
9655
|
+
break;
|
|
9656
|
+
case ServerMsgCode.STORAGE_STREAM_END:
|
|
9657
|
+
processInitialStorage(nodeMapBuffer.take());
|
|
9577
9658
|
break;
|
|
9578
|
-
}
|
|
9579
9659
|
case ServerMsgCode.UPDATE_STORAGE: {
|
|
9580
9660
|
const applyResult = applyRemoteOps(message.ops);
|
|
9581
9661
|
for (const [key, value] of applyResult.updates.storageUpdates) {
|
|
@@ -9615,6 +9695,8 @@ function createRoom(options, config) {
|
|
|
9615
9695
|
eventHub.comments.notify(message);
|
|
9616
9696
|
break;
|
|
9617
9697
|
}
|
|
9698
|
+
case ServerMsgCode.STORAGE_STATE_V7:
|
|
9699
|
+
// No longer used in V8
|
|
9618
9700
|
default:
|
|
9619
9701
|
break;
|
|
9620
9702
|
}
|
|
@@ -9716,9 +9798,9 @@ function createRoom(options, config) {
|
|
|
9716
9798
|
}
|
|
9717
9799
|
let _getStorage$ = null;
|
|
9718
9800
|
let _resolveStoragePromise = null;
|
|
9719
|
-
function processInitialStorage(
|
|
9801
|
+
function processInitialStorage(nodes) {
|
|
9720
9802
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
9721
|
-
createOrUpdateRootFromMessage(
|
|
9803
|
+
createOrUpdateRootFromMessage(nodes);
|
|
9722
9804
|
applyAndSendOfflineOps(unacknowledgedOps);
|
|
9723
9805
|
_optionalChain([_resolveStoragePromise, 'optionalCall', _193 => _193()]);
|
|
9724
9806
|
notifyStorageStatus();
|
|
@@ -9726,8 +9808,10 @@ function createRoom(options, config) {
|
|
|
9726
9808
|
}
|
|
9727
9809
|
async function streamStorage() {
|
|
9728
9810
|
if (!managedSocket.authValue) return;
|
|
9729
|
-
const
|
|
9730
|
-
|
|
9811
|
+
const nodes = new Map(
|
|
9812
|
+
await httpClient.streamStorage({ roomId })
|
|
9813
|
+
);
|
|
9814
|
+
processInitialStorage(nodes);
|
|
9731
9815
|
}
|
|
9732
9816
|
function refreshStorage(options2) {
|
|
9733
9817
|
const messages = context.buffer.messages;
|
|
@@ -9735,6 +9819,7 @@ function createRoom(options, config) {
|
|
|
9735
9819
|
void streamStorage();
|
|
9736
9820
|
} else if (!messages.some((msg) => msg.type === ClientMsgCode.FETCH_STORAGE)) {
|
|
9737
9821
|
messages.push({ type: ClientMsgCode.FETCH_STORAGE });
|
|
9822
|
+
nodeMapBuffer.take();
|
|
9738
9823
|
}
|
|
9739
9824
|
if (options2.flush) {
|
|
9740
9825
|
flushNowOrSoon();
|
|
@@ -10328,7 +10413,7 @@ function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill, eng
|
|
|
10328
10413
|
}
|
|
10329
10414
|
const url2 = new URL(baseUrl);
|
|
10330
10415
|
url2.protocol = url2.protocol === "http:" ? "ws" : "wss";
|
|
10331
|
-
url2.pathname = "/
|
|
10416
|
+
url2.pathname = "/v8";
|
|
10332
10417
|
url2.searchParams.set("roomId", roomId);
|
|
10333
10418
|
if (authValue.type === "secret") {
|
|
10334
10419
|
url2.searchParams.set("tok", authValue.token.raw);
|
|
@@ -10376,8 +10461,7 @@ function createClient(options) {
|
|
|
10376
10461
|
const baseUrl = getBaseUrl(clientOptions.baseUrl);
|
|
10377
10462
|
const currentUserId = new Signal(void 0);
|
|
10378
10463
|
const authManager = createAuthManager(options, (token) => {
|
|
10379
|
-
|
|
10380
|
-
currentUserId.set(() => userId);
|
|
10464
|
+
currentUserId.set(() => token.uid);
|
|
10381
10465
|
});
|
|
10382
10466
|
const fetchPolyfill = _optionalChain([clientOptions, 'access', _209 => _209.polyfills, 'optionalAccess', _210 => _210.fetch]) || /* istanbul ignore next */
|
|
10383
10467
|
_optionalChain([globalThis, 'access', _211 => _211.fetch, 'optionalAccess', _212 => _212.bind, 'call', _213 => _213(globalThis)]);
|
|
@@ -10408,8 +10492,6 @@ function createClient(options) {
|
|
|
10408
10492
|
throw new StopRetrying(
|
|
10409
10493
|
"Cannot use AI Copilots with a public API key"
|
|
10410
10494
|
);
|
|
10411
|
-
} else if (resp.token.parsed.k === "sec-legacy" /* SECRET_LEGACY */) {
|
|
10412
|
-
throw new StopRetrying("AI Copilots requires an ID or Access token");
|
|
10413
10495
|
}
|
|
10414
10496
|
return resp;
|
|
10415
10497
|
},
|
|
@@ -11646,5 +11728,12 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
11646
11728
|
|
|
11647
11729
|
|
|
11648
11730
|
|
|
11649
|
-
|
|
11731
|
+
|
|
11732
|
+
|
|
11733
|
+
|
|
11734
|
+
|
|
11735
|
+
|
|
11736
|
+
|
|
11737
|
+
|
|
11738
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.Deque = Deque; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MENTION_CHARACTER = MENTION_CHARACTER; exports.MutableSignal = MutableSignal; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.checkBounds = checkBounds; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactNodesToNodeStream = compactNodesToNodeStream; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToGroupData = convertToGroupData; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToSubscriptionData = convertToSubscriptionData; exports.convertToThreadData = convertToThreadData; exports.convertToUserSubscriptionData = convertToUserSubscriptionData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createManagedPool = createManagedPool; exports.createNotificationSettings = createNotificationSettings; exports.createThreadId = createThreadId; exports.defineAiTool = defineAiTool; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.findLastIndex = findLastIndex; exports.freeze = freeze; exports.generateUrl = generateUrl; exports.getMentionsFromCommentBody = getMentionsFromCommentBody; exports.getSubscriptionKey = getSubscriptionKey; exports.html = html; exports.htmlSafe = htmlSafe; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isListStorageNode = isListStorageNode; exports.isLiveNode = isLiveNode; exports.isMapStorageNode = isMapStorageNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isNumberOperator = isNumberOperator; exports.isObjectStorageNode = isObjectStorageNode; exports.isPlainObject = isPlainObject; exports.isRegisterStorageNode = isRegisterStorageNode; exports.isRootStorageNode = isRootStorageNode; exports.isStartsWithOperator = isStartsWithOperator; exports.isUrl = isUrl; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeAbortController = makeAbortController; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.nodeStreamToCompactNodes = nodeStreamToCompactNodes; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchNotificationSettings = patchNotificationSettings; exports.raise = raise; exports.resolveMentionsInCommentBody = resolveMentionsInCommentBody; exports.sanitizeUrl = sanitizeUrl; exports.shallow = shallow; exports.shallow2 = shallow2; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.warnOnce = warnOnce; exports.warnOnceIf = warnOnceIf; exports.withTimeout = withTimeout;
|
|
11650
11739
|
//# sourceMappingURL=index.cjs.map
|