@liveblocks/server 1.4.1 → 1.4.2-pre2
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 +115 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -13
- package/dist/index.d.ts +63 -13
- package/dist/index.js +90 -36
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -129,7 +129,9 @@ var feedMetadataRecordForCreate = _decoders.record.call(void 0,
|
|
|
129
129
|
(value) => Object.keys(value).length <= MAX_METADATA_COUNT,
|
|
130
130
|
`Must be at most ${MAX_METADATA_COUNT} items`
|
|
131
131
|
);
|
|
132
|
-
var optionalFeedMetadataDecoder = _decoders.optional.call(void 0,
|
|
132
|
+
var optionalFeedMetadataDecoder = _decoders.optional.call(void 0,
|
|
133
|
+
feedMetadataRecordForCreate
|
|
134
|
+
);
|
|
133
135
|
var feedMetadataUpdateDecoder = _decoders.record.call(void 0,
|
|
134
136
|
feedMetadataIdDecoder,
|
|
135
137
|
feedMetadataNullableValueDecoder
|
|
@@ -156,6 +158,14 @@ var jsonObjectYolo = jsonYolo.refine(
|
|
|
156
158
|
// src/decoders/Op.ts
|
|
157
159
|
|
|
158
160
|
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
var intent = _decoders.oneOf.call(void 0, ["set", "push"]);
|
|
159
169
|
var updateObjectOp = _decoders.object.call(void 0, {
|
|
160
170
|
type: _decoders.constant.call(void 0, _core.OpCode.UPDATE_OBJECT),
|
|
161
171
|
opId: _decoders.string,
|
|
@@ -169,7 +179,7 @@ var createObjectOp = _decoders.object.call(void 0, {
|
|
|
169
179
|
parentId: _decoders.string,
|
|
170
180
|
parentKey: _decoders.string,
|
|
171
181
|
data: jsonObjectYolo,
|
|
172
|
-
intent: _decoders.optional.call(void 0,
|
|
182
|
+
intent: _decoders.optional.call(void 0, intent),
|
|
173
183
|
deletedId: _decoders.optional.call(void 0, _decoders.string)
|
|
174
184
|
});
|
|
175
185
|
var createListOp = _decoders.object.call(void 0, {
|
|
@@ -178,7 +188,7 @@ var createListOp = _decoders.object.call(void 0, {
|
|
|
178
188
|
id: _decoders.string,
|
|
179
189
|
parentId: _decoders.string,
|
|
180
190
|
parentKey: _decoders.string,
|
|
181
|
-
intent: _decoders.optional.call(void 0,
|
|
191
|
+
intent: _decoders.optional.call(void 0, intent),
|
|
182
192
|
deletedId: _decoders.optional.call(void 0, _decoders.string)
|
|
183
193
|
});
|
|
184
194
|
var createMapOp = _decoders.object.call(void 0, {
|
|
@@ -187,7 +197,7 @@ var createMapOp = _decoders.object.call(void 0, {
|
|
|
187
197
|
id: _decoders.string,
|
|
188
198
|
parentId: _decoders.string,
|
|
189
199
|
parentKey: _decoders.string,
|
|
190
|
-
intent: _decoders.optional.call(void 0,
|
|
200
|
+
intent: _decoders.optional.call(void 0, intent),
|
|
191
201
|
deletedId: _decoders.optional.call(void 0, _decoders.string)
|
|
192
202
|
});
|
|
193
203
|
var createRegisterOp = _decoders.object.call(void 0, {
|
|
@@ -197,7 +207,7 @@ var createRegisterOp = _decoders.object.call(void 0, {
|
|
|
197
207
|
parentId: _decoders.string,
|
|
198
208
|
parentKey: _decoders.string,
|
|
199
209
|
data: jsonYolo,
|
|
200
|
-
intent: _decoders.optional.call(void 0,
|
|
210
|
+
intent: _decoders.optional.call(void 0, intent),
|
|
201
211
|
deletedId: _decoders.optional.call(void 0, _decoders.string)
|
|
202
212
|
});
|
|
203
213
|
var deleteCrdtOp = _decoders.object.call(void 0, {
|
|
@@ -826,7 +836,6 @@ function makeMetadataDB(driver) {
|
|
|
826
836
|
|
|
827
837
|
|
|
828
838
|
|
|
829
|
-
|
|
830
839
|
var _asyncmutex = require('async-mutex');
|
|
831
840
|
|
|
832
841
|
var _itertools = require('itertools');
|
|
@@ -967,6 +976,12 @@ var Logger = class _Logger {
|
|
|
967
976
|
|
|
968
977
|
|
|
969
978
|
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
970
985
|
// src/lib/text.ts
|
|
971
986
|
function quote(value) {
|
|
972
987
|
return value !== void 0 ? `'${value}'` : "???";
|
|
@@ -1287,6 +1302,16 @@ var InMemoryDriver = class {
|
|
|
1287
1302
|
}
|
|
1288
1303
|
return nextPos;
|
|
1289
1304
|
}
|
|
1305
|
+
function get_last_sibling(parentId) {
|
|
1306
|
+
let lastPos;
|
|
1307
|
+
for (const siblingKey of revNodes.keysAt(parentId)) {
|
|
1308
|
+
const siblingPos = _core.asPos.call(void 0, siblingKey);
|
|
1309
|
+
if (lastPos === void 0 || siblingPos > lastPos) {
|
|
1310
|
+
lastPos = siblingPos;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
return lastPos;
|
|
1314
|
+
}
|
|
1290
1315
|
async function set_child(id, node, allowOverwrite = false) {
|
|
1291
1316
|
const parentNode = nodes.get(node.parentId);
|
|
1292
1317
|
if (parentNode === void 0) {
|
|
@@ -1374,6 +1399,17 @@ var InMemoryDriver = class {
|
|
|
1374
1399
|
* Yield all nodes as [id, node] pairs. Must always include the root node.
|
|
1375
1400
|
*/
|
|
1376
1401
|
iter_nodes: () => nodes,
|
|
1402
|
+
/**
|
|
1403
|
+
* Yield each node as a pre-built CompactNode JSON tuple string.
|
|
1404
|
+
*
|
|
1405
|
+
* This implementation IS the canonical reference for the invariant:
|
|
1406
|
+
* iter_nodes_optimized` ≡ `nodeStreamToCompactNodes(iter_nodes())
|
|
1407
|
+
*/
|
|
1408
|
+
*iter_nodes_optimized() {
|
|
1409
|
+
for (const compact of _core.nodeStreamToCompactNodes.call(void 0, nodes)) {
|
|
1410
|
+
yield JSON.stringify(compact);
|
|
1411
|
+
}
|
|
1412
|
+
},
|
|
1377
1413
|
/**
|
|
1378
1414
|
* Return true iff a node with the given id exists. Must return true for "root".
|
|
1379
1415
|
*/
|
|
@@ -1395,6 +1431,11 @@ var InMemoryDriver = class {
|
|
|
1395
1431
|
* does not have to exist already. Positions compare lexicographically.
|
|
1396
1432
|
*/
|
|
1397
1433
|
get_next_sibling,
|
|
1434
|
+
/**
|
|
1435
|
+
* Return the position of the last (rightmost) child under parentId, or
|
|
1436
|
+
* undefined if the node has no children.
|
|
1437
|
+
*/
|
|
1438
|
+
get_last_sibling,
|
|
1398
1439
|
/**
|
|
1399
1440
|
* Insert a child node with the given id.
|
|
1400
1441
|
*
|
|
@@ -1600,8 +1641,8 @@ var Storage = class {
|
|
|
1600
1641
|
}
|
|
1601
1642
|
async createChildAsListItem(op2, node) {
|
|
1602
1643
|
let fix;
|
|
1603
|
-
const
|
|
1604
|
-
if (
|
|
1644
|
+
const intent2 = _nullishCoalesce(op2.intent, () => ( "insert"));
|
|
1645
|
+
if (intent2 === "insert") {
|
|
1605
1646
|
const insertedParentKey = await this.insertIntoList(op2.id, node);
|
|
1606
1647
|
if (insertedParentKey !== node.parentKey) {
|
|
1607
1648
|
op2 = { ...op2, parentKey: insertedParentKey };
|
|
@@ -1613,7 +1654,7 @@ var Storage = class {
|
|
|
1613
1654
|
return accept(op2, fix);
|
|
1614
1655
|
}
|
|
1615
1656
|
return accept(op2);
|
|
1616
|
-
} else if (
|
|
1657
|
+
} else if (intent2 === "set") {
|
|
1617
1658
|
const deletedId = op2.deletedId !== void 0 && op2.deletedId !== op2.id && _optionalChain([this, 'access', _47 => _47.loadedDriver, 'access', _48 => _48.get_node, 'call', _49 => _49(op2.deletedId), 'optionalAccess', _50 => _50.parentId]) === node.parentId ? op2.deletedId : void 0;
|
|
1618
1659
|
if (deletedId !== void 0) {
|
|
1619
1660
|
await this.loadedDriver.delete_node(deletedId);
|
|
@@ -1630,8 +1671,26 @@ var Storage = class {
|
|
|
1630
1671
|
}
|
|
1631
1672
|
await this.loadedDriver.set_child(op2.id, node, true);
|
|
1632
1673
|
return accept(op2, fix);
|
|
1674
|
+
} else if (intent2 === "push") {
|
|
1675
|
+
const lastPos = this.loadedDriver.get_last_sibling(node.parentId);
|
|
1676
|
+
const guessedKey = _core.asPos.call(void 0, node.parentKey);
|
|
1677
|
+
const pushedKey = lastPos === void 0 || guessedKey > lastPos ? guessedKey : _core.makePosition.call(void 0, lastPos);
|
|
1678
|
+
await this.loadedDriver.set_child(op2.id, {
|
|
1679
|
+
...node,
|
|
1680
|
+
parentKey: pushedKey
|
|
1681
|
+
});
|
|
1682
|
+
if (pushedKey !== node.parentKey) {
|
|
1683
|
+
op2 = { ...op2, parentKey: pushedKey };
|
|
1684
|
+
fix = {
|
|
1685
|
+
type: _core.OpCode.SET_PARENT_KEY,
|
|
1686
|
+
id: op2.id,
|
|
1687
|
+
parentKey: pushedKey
|
|
1688
|
+
};
|
|
1689
|
+
return accept(op2, fix);
|
|
1690
|
+
}
|
|
1691
|
+
return accept(op2);
|
|
1633
1692
|
} else {
|
|
1634
|
-
return _core.assertNever.call(void 0,
|
|
1693
|
+
return _core.assertNever.call(void 0, intent2, "Invalid intent");
|
|
1635
1694
|
}
|
|
1636
1695
|
}
|
|
1637
1696
|
async applyDeleteObjectKeyOp(op2) {
|
|
@@ -2035,6 +2094,7 @@ function isLeasedSessionExpired(leasedSession) {
|
|
|
2035
2094
|
}
|
|
2036
2095
|
|
|
2037
2096
|
// src/Room.ts
|
|
2097
|
+
var MB = 1024 * 1024;
|
|
2038
2098
|
var messagesDecoder = _decoders.array.call(void 0, clientMsgDecoder);
|
|
2039
2099
|
var ServerMsgCode2 = { ..._core.ServerMsgCode, ...FeedMsgCode };
|
|
2040
2100
|
var HIGHEST_PROTOCOL_VERSION = Math.max(
|
|
@@ -2048,6 +2108,11 @@ var SERVER_MSG_CODE_NAMES = Object.fromEntries(
|
|
|
2048
2108
|
var BLACK_HOLE = new Logger([
|
|
2049
2109
|
/* No targets, i.e. black hole logger */
|
|
2050
2110
|
]);
|
|
2111
|
+
function groupNodesForWebSocketMessages(input) {
|
|
2112
|
+
const MAX_SIZE = 16 * MB;
|
|
2113
|
+
const idealSize = (chunkIndex) => chunkIndex < 3 ? 1 * MB : Math.min(8, chunkIndex - 1) * MB;
|
|
2114
|
+
return _itertools.chunkedByCost.call(void 0, input, (tup) => tup.length, MAX_SIZE, idealSize);
|
|
2115
|
+
}
|
|
2051
2116
|
function collectSideEffects() {
|
|
2052
2117
|
const deferred = [];
|
|
2053
2118
|
return {
|
|
@@ -2181,7 +2246,7 @@ var BackendSession = class extends BrowserSession {
|
|
|
2181
2246
|
super(ticket, socket, debug);
|
|
2182
2247
|
}
|
|
2183
2248
|
};
|
|
2184
|
-
var __debug2
|
|
2249
|
+
var __debug2;
|
|
2185
2250
|
var Room = class {
|
|
2186
2251
|
constructor(meta, options) {
|
|
2187
2252
|
// ^^^^^^^^^^ User-defined Room Metadata, Session Metadata, and Client Metadata
|
|
@@ -2203,29 +2268,27 @@ var Room = class {
|
|
|
2203
2268
|
__publicField(this, "sessions", new UniqueMap((s) => s.actor));
|
|
2204
2269
|
__publicField(this, "hooks");
|
|
2205
2270
|
__privateAdd(this, __debug2);
|
|
2206
|
-
__privateAdd(this, __allowStreaming);
|
|
2207
2271
|
const driver = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _61 => _61.storage]), () => ( makeNewInMemoryDriver()));
|
|
2208
2272
|
this.meta = meta;
|
|
2209
2273
|
this.driver = driver;
|
|
2210
2274
|
this.logger = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _62 => _62.logger]), () => ( BLACK_HOLE));
|
|
2211
|
-
__privateSet(this, __allowStreaming, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _63 => _63.allowStreaming]), () => ( true)));
|
|
2212
2275
|
this.hooks = {
|
|
2213
|
-
isClientMsgAllowed: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2276
|
+
isClientMsgAllowed: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _63 => _63.hooks, 'optionalAccess', _64 => _64.isClientMsgAllowed]), () => ( (() => {
|
|
2214
2277
|
return {
|
|
2215
2278
|
allowed: true
|
|
2216
2279
|
};
|
|
2217
2280
|
}))),
|
|
2218
2281
|
// YYY .load() isn't called on the RoomServer yet! As soon as it does, these hooks will get called
|
|
2219
|
-
onRoomWillLoad: _optionalChain([options, 'optionalAccess',
|
|
2220
|
-
onRoomDidLoad: _optionalChain([options, 'optionalAccess',
|
|
2221
|
-
onRoomWillUnload: _optionalChain([options, 'optionalAccess',
|
|
2222
|
-
onRoomDidUnload: _optionalChain([options, 'optionalAccess',
|
|
2223
|
-
onSessionDidStart: _optionalChain([options, 'optionalAccess',
|
|
2224
|
-
onSessionDidEnd: _optionalChain([options, 'optionalAccess',
|
|
2225
|
-
postClientMsgStorageDidUpdate: _optionalChain([options, 'optionalAccess',
|
|
2226
|
-
postClientMsgYdocDidUpdate: _optionalChain([options, 'optionalAccess',
|
|
2282
|
+
onRoomWillLoad: _optionalChain([options, 'optionalAccess', _65 => _65.hooks, 'optionalAccess', _66 => _66.onRoomWillLoad]),
|
|
2283
|
+
onRoomDidLoad: _optionalChain([options, 'optionalAccess', _67 => _67.hooks, 'optionalAccess', _68 => _68.onRoomDidLoad]),
|
|
2284
|
+
onRoomWillUnload: _optionalChain([options, 'optionalAccess', _69 => _69.hooks, 'optionalAccess', _70 => _70.onRoomWillUnload]),
|
|
2285
|
+
onRoomDidUnload: _optionalChain([options, 'optionalAccess', _71 => _71.hooks, 'optionalAccess', _72 => _72.onRoomDidUnload]),
|
|
2286
|
+
onSessionDidStart: _optionalChain([options, 'optionalAccess', _73 => _73.hooks, 'optionalAccess', _74 => _74.onSessionDidStart]),
|
|
2287
|
+
onSessionDidEnd: _optionalChain([options, 'optionalAccess', _75 => _75.hooks, 'optionalAccess', _76 => _76.onSessionDidEnd]),
|
|
2288
|
+
postClientMsgStorageDidUpdate: _optionalChain([options, 'optionalAccess', _77 => _77.hooks, 'optionalAccess', _78 => _78.postClientMsgStorageDidUpdate]),
|
|
2289
|
+
postClientMsgYdocDidUpdate: _optionalChain([options, 'optionalAccess', _79 => _79.hooks, 'optionalAccess', _80 => _80.postClientMsgYdocDidUpdate])
|
|
2227
2290
|
};
|
|
2228
|
-
__privateSet(this, __debug2, _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2291
|
+
__privateSet(this, __debug2, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _81 => _81.enableDebugLogging]), () => ( false)));
|
|
2229
2292
|
}
|
|
2230
2293
|
get loadingState() {
|
|
2231
2294
|
if (this._loadData$ === null) {
|
|
@@ -2299,13 +2362,13 @@ var Room = class {
|
|
|
2299
2362
|
* room will be reloaded from storage.
|
|
2300
2363
|
*/
|
|
2301
2364
|
unload(ctx) {
|
|
2302
|
-
_optionalChain([this, 'access',
|
|
2365
|
+
_optionalChain([this, 'access', _82 => _82.hooks, 'access', _83 => _83.onRoomWillUnload, 'optionalCall', _84 => _84(ctx)]);
|
|
2303
2366
|
if (this._data) {
|
|
2304
2367
|
this.storage.unload();
|
|
2305
2368
|
this.yjsStorage.unload();
|
|
2306
2369
|
}
|
|
2307
2370
|
this._loadData$ = null;
|
|
2308
|
-
_optionalChain([this, 'access',
|
|
2371
|
+
_optionalChain([this, 'access', _85 => _85.hooks, 'access', _86 => _86.onRoomDidUnload, 'optionalCall', _87 => _87(ctx)]);
|
|
2309
2372
|
}
|
|
2310
2373
|
/**
|
|
2311
2374
|
* Issues a Ticket with a new/unique actor ID
|
|
@@ -2319,17 +2382,17 @@ var Room = class {
|
|
|
2319
2382
|
* unused Ticket will simply get garbage collected.
|
|
2320
2383
|
*/
|
|
2321
2384
|
async createTicket(options) {
|
|
2322
|
-
const actor$ = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2385
|
+
const actor$ = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _88 => _88.actor]), () => ( this.getNextActor()));
|
|
2323
2386
|
const sessionKey = _nanoid.nanoid.call(void 0, );
|
|
2324
|
-
const info = _optionalChain([options, 'optionalAccess',
|
|
2387
|
+
const info = _optionalChain([options, 'optionalAccess', _89 => _89.info]);
|
|
2325
2388
|
const ticket = {
|
|
2326
|
-
version: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2389
|
+
version: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _90 => _90.version]), () => ( HIGHEST_PROTOCOL_VERSION)),
|
|
2327
2390
|
actor: await actor$,
|
|
2328
2391
|
sessionKey,
|
|
2329
|
-
meta: _optionalChain([options, 'optionalAccess',
|
|
2330
|
-
publicMeta: _optionalChain([options, 'optionalAccess',
|
|
2331
|
-
user: _optionalChain([options, 'optionalAccess',
|
|
2332
|
-
scopes: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2392
|
+
meta: _optionalChain([options, 'optionalAccess', _91 => _91.meta]),
|
|
2393
|
+
publicMeta: _optionalChain([options, 'optionalAccess', _92 => _92.publicMeta]),
|
|
2394
|
+
user: _optionalChain([options, 'optionalAccess', _93 => _93.id]) ? { id: options.id, info } : { anonymousId: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _94 => _94.anonymousId]), () => ( _nanoid.nanoid.call(void 0, ))), info },
|
|
2395
|
+
scopes: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _95 => _95.scopes]), () => ( ["room:write"]))
|
|
2333
2396
|
};
|
|
2334
2397
|
if (__privateGet(this, __debug2)) {
|
|
2335
2398
|
console.log(`new ticket created: ${JSON.stringify(ticket)}`);
|
|
@@ -2463,7 +2526,7 @@ var Room = class {
|
|
|
2463
2526
|
ctx,
|
|
2464
2527
|
defer
|
|
2465
2528
|
);
|
|
2466
|
-
const p$ = _optionalChain([this, 'access',
|
|
2529
|
+
const p$ = _optionalChain([this, 'access', _96 => _96.hooks, 'access', _97 => _97.onSessionDidStart, 'optionalCall', _98 => _98(newSession, ctx)]);
|
|
2467
2530
|
if (p$) defer(p$);
|
|
2468
2531
|
}
|
|
2469
2532
|
/**
|
|
@@ -2487,7 +2550,7 @@ var Room = class {
|
|
|
2487
2550
|
for (const other of this.otherSessions(key)) {
|
|
2488
2551
|
other.send({ type: ServerMsgCode2.USER_LEFT, actor: session.actor });
|
|
2489
2552
|
}
|
|
2490
|
-
const p$ = _optionalChain([this, 'access',
|
|
2553
|
+
const p$ = _optionalChain([this, 'access', _99 => _99.hooks, 'access', _100 => _100.onSessionDidEnd, 'optionalCall', _101 => _101(session, ctx)]);
|
|
2491
2554
|
if (p$) defer(p$);
|
|
2492
2555
|
}
|
|
2493
2556
|
}
|
|
@@ -2518,7 +2581,7 @@ var Room = class {
|
|
|
2518
2581
|
);
|
|
2519
2582
|
}) {
|
|
2520
2583
|
const text = typeof data === "string" ? data : _core.raise.call(void 0, "Unsupported message format");
|
|
2521
|
-
_optionalChain([this, 'access',
|
|
2584
|
+
_optionalChain([this, 'access', _102 => _102.sessions, 'access', _103 => _103.get, 'call', _104 => _104(key), 'optionalAccess', _105 => _105.markActive, 'call', _106 => _106()]);
|
|
2522
2585
|
if (text === "ping") {
|
|
2523
2586
|
await this.handlePing(key, ctx);
|
|
2524
2587
|
} else {
|
|
@@ -2873,7 +2936,7 @@ var Room = class {
|
|
|
2873
2936
|
}
|
|
2874
2937
|
// Don't ever manually call this!
|
|
2875
2938
|
async _load(ctx) {
|
|
2876
|
-
await _optionalChain([this, 'access',
|
|
2939
|
+
await _optionalChain([this, 'access', _107 => _107.hooks, 'access', _108 => _108.onRoomWillLoad, 'optionalCall', _109 => _109(ctx)]);
|
|
2877
2940
|
const storage = await this._loadStorage();
|
|
2878
2941
|
const yjsStorage = await this._loadYjsStorage();
|
|
2879
2942
|
this._data = {
|
|
@@ -2881,7 +2944,7 @@ var Room = class {
|
|
|
2881
2944
|
storage,
|
|
2882
2945
|
yjsStorage
|
|
2883
2946
|
};
|
|
2884
|
-
await _optionalChain([this, 'access',
|
|
2947
|
+
await _optionalChain([this, 'access', _110 => _110.hooks, 'access', _111 => _111.onRoomDidLoad, 'optionalCall', _112 => _112(ctx)]);
|
|
2885
2948
|
}
|
|
2886
2949
|
/**
|
|
2887
2950
|
* Returns a new, unique, actor ID.
|
|
@@ -2921,7 +2984,7 @@ var Room = class {
|
|
|
2921
2984
|
}
|
|
2922
2985
|
const sent = session.sendPong();
|
|
2923
2986
|
if (sent !== 0) {
|
|
2924
|
-
await _optionalChain([this, 'access',
|
|
2987
|
+
await _optionalChain([this, 'access', _113 => _113.hooks, 'access', _114 => _114.onDidPong, 'optionalCall', _115 => _115(ctx)]);
|
|
2925
2988
|
}
|
|
2926
2989
|
}
|
|
2927
2990
|
async _processClientMsg_withExclusiveAccess(sessionKey, messages, ctx, defer) {
|
|
@@ -2973,7 +3036,13 @@ var Room = class {
|
|
|
2973
3036
|
const toReplyImmediately = [];
|
|
2974
3037
|
const toReplyAfter = [];
|
|
2975
3038
|
const replyImmediately = (msg) => {
|
|
2976
|
-
if (
|
|
3039
|
+
if (typeof msg === "string") {
|
|
3040
|
+
if (toReplyImmediately.length > 0) {
|
|
3041
|
+
session.send(toReplyImmediately);
|
|
3042
|
+
toReplyImmediately.length = 0;
|
|
3043
|
+
}
|
|
3044
|
+
session.send(msg);
|
|
3045
|
+
} else if (Array.isArray(msg)) {
|
|
2977
3046
|
for (const m of msg) {
|
|
2978
3047
|
toReplyImmediately.push(m);
|
|
2979
3048
|
}
|
|
@@ -3031,24 +3100,10 @@ var Room = class {
|
|
|
3031
3100
|
}
|
|
3032
3101
|
case _core.ClientMsgCode.FETCH_STORAGE: {
|
|
3033
3102
|
if (session.version >= 8 /* V8 */) {
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
NODES_PER_CHUNK
|
|
3039
|
-
)) {
|
|
3040
|
-
replyImmediately({
|
|
3041
|
-
type: ServerMsgCode2.STORAGE_CHUNK,
|
|
3042
|
-
nodes: chunk
|
|
3043
|
-
});
|
|
3044
|
-
}
|
|
3045
|
-
} else {
|
|
3046
|
-
replyImmediately({
|
|
3047
|
-
type: ServerMsgCode2.STORAGE_CHUNK,
|
|
3048
|
-
nodes: Array.from(
|
|
3049
|
-
_core.nodeStreamToCompactNodes.call(void 0, this.storage.loadedDriver.iter_nodes())
|
|
3050
|
-
)
|
|
3051
|
-
});
|
|
3103
|
+
const rawStream = this.storage.loadedDriver.iter_nodes_optimized();
|
|
3104
|
+
for (const chunk of groupNodesForWebSocketMessages(rawStream)) {
|
|
3105
|
+
const frame = `{"type":${ServerMsgCode2.STORAGE_CHUNK},"nodes":[${chunk.join(",")}]}`;
|
|
3106
|
+
replyImmediately(frame);
|
|
3052
3107
|
}
|
|
3053
3108
|
replyImmediately({ type: ServerMsgCode2.STORAGE_STREAM_END });
|
|
3054
3109
|
} else {
|
|
@@ -3060,7 +3115,7 @@ var Room = class {
|
|
|
3060
3115
|
break;
|
|
3061
3116
|
}
|
|
3062
3117
|
case _core.ClientMsgCode.UPDATE_STORAGE: {
|
|
3063
|
-
_optionalChain([this, 'access',
|
|
3118
|
+
_optionalChain([this, 'access', _116 => _116.driver, 'access', _117 => _117.bump_storage_version, 'optionalCall', _118 => _118()]);
|
|
3064
3119
|
const result = await this.storage.applyOps(msg.ops);
|
|
3065
3120
|
const opsToForward = result.flatMap(
|
|
3066
3121
|
(r) => r.action === "accepted" ? [r.op] : []
|
|
@@ -3093,7 +3148,7 @@ var Room = class {
|
|
|
3093
3148
|
});
|
|
3094
3149
|
}
|
|
3095
3150
|
if (opsToForward.length > 0) {
|
|
3096
|
-
const p$ = _optionalChain([this, 'access',
|
|
3151
|
+
const p$ = _optionalChain([this, 'access', _119 => _119.hooks, 'access', _120 => _120.postClientMsgStorageDidUpdate, 'optionalCall', _121 => _121(ctx)]);
|
|
3097
3152
|
if (p$) defer(p$);
|
|
3098
3153
|
}
|
|
3099
3154
|
break;
|
|
@@ -3144,7 +3199,7 @@ var Room = class {
|
|
|
3144
3199
|
defer
|
|
3145
3200
|
);
|
|
3146
3201
|
if (result.isUpdated) {
|
|
3147
|
-
const p$ = _optionalChain([this, 'access',
|
|
3202
|
+
const p$ = _optionalChain([this, 'access', _122 => _122.hooks, 'access', _123 => _123.postClientMsgYdocDidUpdate, 'optionalCall', _124 => _124(ctx, session)]);
|
|
3148
3203
|
if (p$) defer(p$);
|
|
3149
3204
|
}
|
|
3150
3205
|
break;
|
|
@@ -3327,7 +3382,6 @@ var Room = class {
|
|
|
3327
3382
|
}
|
|
3328
3383
|
};
|
|
3329
3384
|
__debug2 = new WeakMap();
|
|
3330
|
-
__allowStreaming = new WeakMap();
|
|
3331
3385
|
|
|
3332
3386
|
|
|
3333
3387
|
|