@liveblocks/server 1.6.0 → 1.6.1

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 CHANGED
@@ -1563,6 +1563,13 @@ function accept(op2, fix) {
1563
1563
  function ignore(ignoredOp) {
1564
1564
  return { action: "ignored", ignoredOpId: ignoredOp.opId };
1565
1565
  }
1566
+ function rectify(op2, parentKey) {
1567
+ return {
1568
+ action: "rectified",
1569
+ ackOp: { ...op2, parentKey },
1570
+ fix: { type: _core.OpCode.SET_PARENT_KEY, id: op2.id, parentKey }
1571
+ };
1572
+ }
1566
1573
  function nodeFromCreateChildOp(op2) {
1567
1574
  switch (op2.type) {
1568
1575
  case _core.OpCode.CREATE_LIST:
@@ -1652,6 +1659,12 @@ var Storage = class {
1652
1659
  }
1653
1660
  applyCreateOp(op2) {
1654
1661
  if (this.driver.has_node(op2.id)) {
1662
+ if (op2.intent === "push") {
1663
+ const stored = this.driver.get_node(op2.id);
1664
+ if (_optionalChain([stored, 'optionalAccess', _47 => _47.parentId]) !== void 0 && _optionalChain([this, 'access', _48 => _48.driver, 'access', _49 => _49.get_node, 'call', _50 => _50(stored.parentId), 'optionalAccess', _51 => _51.type]) === _core.CrdtType.LIST) {
1665
+ return rectify(op2, stored.parentKey);
1666
+ }
1667
+ }
1655
1668
  return ignore(op2);
1656
1669
  }
1657
1670
  const node = nodeFromCreateChildOp(op2);
@@ -1685,7 +1698,7 @@ var Storage = class {
1685
1698
  return this.acceptAndFix(op2, node, this.appendToList(op2.id, node));
1686
1699
  } else if (intent2 === "set") {
1687
1700
  let fix;
1688
- const deletedId = op2.deletedId !== void 0 && op2.deletedId !== op2.id && _optionalChain([this, 'access', _47 => _47.driver, 'access', _48 => _48.get_node, 'call', _49 => _49(op2.deletedId), 'optionalAccess', _50 => _50.parentId]) === node.parentId ? op2.deletedId : void 0;
1701
+ const deletedId = op2.deletedId !== void 0 && op2.deletedId !== op2.id && _optionalChain([this, 'access', _52 => _52.driver, 'access', _53 => _53.get_node, 'call', _54 => _54(op2.deletedId), 'optionalAccess', _55 => _55.parentId]) === node.parentId ? op2.deletedId : void 0;
1689
1702
  if (deletedId !== void 0) {
1690
1703
  this.driver.delete_node(deletedId);
1691
1704
  }
@@ -1798,10 +1811,10 @@ var Storage = class {
1798
1811
  */
1799
1812
  moveToPosInList(id, targetKey) {
1800
1813
  const node = this.driver.get_node(id);
1801
- if (_optionalChain([node, 'optionalAccess', _51 => _51.parentId]) === void 0) {
1814
+ if (_optionalChain([node, 'optionalAccess', _56 => _56.parentId]) === void 0) {
1802
1815
  return;
1803
1816
  }
1804
- if (_optionalChain([this, 'access', _52 => _52.driver, 'access', _53 => _53.get_node, 'call', _54 => _54(node.parentId), 'optionalAccess', _55 => _55.type]) !== _core.CrdtType.LIST) {
1817
+ if (_optionalChain([this, 'access', _57 => _57.driver, 'access', _58 => _58.get_node, 'call', _59 => _59(node.parentId), 'optionalAccess', _60 => _60.type]) !== _core.CrdtType.LIST) {
1805
1818
  return;
1806
1819
  }
1807
1820
  if (node.parentKey === targetKey) {
@@ -2212,13 +2225,13 @@ var BrowserSession = class {
2212
2225
  this.publicMeta = ticket.publicMeta;
2213
2226
  __privateSet(this, __socket, socket);
2214
2227
  __privateSet(this, __debug, debug);
2215
- const now = _nullishCoalesce(_optionalChain([createdAt, 'optionalAccess', _56 => _56.getTime, 'call', _57 => _57()]), () => ( Date.now()));
2228
+ const now = _nullishCoalesce(_optionalChain([createdAt, 'optionalAccess', _61 => _61.getTime, 'call', _62 => _62()]), () => ( Date.now()));
2216
2229
  this.createdAt = now;
2217
2230
  __privateSet(this, __lastActiveAt, now);
2218
2231
  __privateSet(this, __hasNotifiedClientStorageUpdateError, false);
2219
2232
  }
2220
2233
  get lastActiveAt() {
2221
- const lastPing = _optionalChain([__privateGet, 'call', _58 => _58(this, __socket), 'access', _59 => _59.getLastPongTimestamp, 'optionalCall', _60 => _60()]);
2234
+ const lastPing = _optionalChain([__privateGet, 'call', _63 => _63(this, __socket), 'access', _64 => _64.getLastPongTimestamp, 'optionalCall', _65 => _65()]);
2222
2235
  if (lastPing && lastPing.getTime() > __privateGet(this, __lastActiveAt)) {
2223
2236
  return lastPing.getTime();
2224
2237
  } else {
@@ -2319,25 +2332,25 @@ var Room = class {
2319
2332
  __publicField(this, "sessions", new UniqueMap((s) => s.actor));
2320
2333
  __publicField(this, "hooks");
2321
2334
  __privateAdd(this, __debug2);
2322
- const driver = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _61 => _61.storage]), () => ( makeNewInMemoryDriver()));
2335
+ const driver = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _66 => _66.storage]), () => ( makeNewInMemoryDriver()));
2323
2336
  this.meta = meta;
2324
2337
  this.driver = driver;
2325
2338
  this._storage = new Storage(this.driver);
2326
2339
  this._yjsStorage = new YjsStorage(this.driver);
2327
- __privateSet(this, _logger, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _62 => _62.logger]), () => ( BLACK_HOLE)));
2340
+ __privateSet(this, _logger, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _67 => _67.logger]), () => ( BLACK_HOLE)));
2328
2341
  this.hooks = {
2329
- isClientMsgAllowed: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _63 => _63.hooks, 'optionalAccess', _64 => _64.isClientMsgAllowed]), () => ( (() => {
2342
+ isClientMsgAllowed: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.hooks, 'optionalAccess', _69 => _69.isClientMsgAllowed]), () => ( (() => {
2330
2343
  return {
2331
2344
  allowed: true
2332
2345
  };
2333
2346
  }))),
2334
- onRoomWillUnload: _optionalChain([options, 'optionalAccess', _65 => _65.hooks, 'optionalAccess', _66 => _66.onRoomWillUnload]),
2335
- onSessionDidStart: _optionalChain([options, 'optionalAccess', _67 => _67.hooks, 'optionalAccess', _68 => _68.onSessionDidStart]),
2336
- onSessionDidEnd: _optionalChain([options, 'optionalAccess', _69 => _69.hooks, 'optionalAccess', _70 => _70.onSessionDidEnd]),
2337
- postClientMsgStorageDidUpdate: _optionalChain([options, 'optionalAccess', _71 => _71.hooks, 'optionalAccess', _72 => _72.postClientMsgStorageDidUpdate]),
2338
- postClientMsgYdocDidUpdate: _optionalChain([options, 'optionalAccess', _73 => _73.hooks, 'optionalAccess', _74 => _74.postClientMsgYdocDidUpdate])
2347
+ onRoomWillUnload: _optionalChain([options, 'optionalAccess', _70 => _70.hooks, 'optionalAccess', _71 => _71.onRoomWillUnload]),
2348
+ onSessionDidStart: _optionalChain([options, 'optionalAccess', _72 => _72.hooks, 'optionalAccess', _73 => _73.onSessionDidStart]),
2349
+ onSessionDidEnd: _optionalChain([options, 'optionalAccess', _74 => _74.hooks, 'optionalAccess', _75 => _75.onSessionDidEnd]),
2350
+ postClientMsgStorageDidUpdate: _optionalChain([options, 'optionalAccess', _76 => _76.hooks, 'optionalAccess', _77 => _77.postClientMsgStorageDidUpdate]),
2351
+ postClientMsgYdocDidUpdate: _optionalChain([options, 'optionalAccess', _78 => _78.hooks, 'optionalAccess', _79 => _79.postClientMsgYdocDidUpdate])
2339
2352
  };
2340
- __privateSet(this, __debug2, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _75 => _75.enableDebugLogging]), () => ( false)));
2353
+ __privateSet(this, __debug2, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _80 => _80.enableDebugLogging]), () => ( false)));
2341
2354
  }
2342
2355
  get storage() {
2343
2356
  return this._storage;
@@ -2383,7 +2396,7 @@ var Room = class {
2383
2396
  * is used, fresh instances will lazily be created.
2384
2397
  */
2385
2398
  unload(ctx) {
2386
- _optionalChain([this, 'access', _76 => _76.hooks, 'access', _77 => _77.onRoomWillUnload, 'optionalCall', _78 => _78(ctx)]);
2399
+ _optionalChain([this, 'access', _81 => _81.hooks, 'access', _82 => _82.onRoomWillUnload, 'optionalCall', _83 => _83(ctx)]);
2387
2400
  this.driver.reinitialize();
2388
2401
  this._storage = new Storage(this.driver);
2389
2402
  this._yjsStorage = new YjsStorage(this.driver);
@@ -2400,17 +2413,17 @@ var Room = class {
2400
2413
  * unused Ticket will simply get garbage collected.
2401
2414
  */
2402
2415
  createTicket(options) {
2403
- const actor = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _79 => _79.actor]), () => ( this.getNextActor()));
2416
+ const actor = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _84 => _84.actor]), () => ( this.getNextActor()));
2404
2417
  const sessionKey = _nanoid.nanoid.call(void 0, );
2405
- const info = _optionalChain([options, 'optionalAccess', _80 => _80.info]);
2418
+ const info = _optionalChain([options, 'optionalAccess', _85 => _85.info]);
2406
2419
  const ticket = {
2407
- version: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _81 => _81.version]), () => ( HIGHEST_PROTOCOL_VERSION)),
2420
+ version: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _86 => _86.version]), () => ( HIGHEST_PROTOCOL_VERSION)),
2408
2421
  actor,
2409
2422
  sessionKey,
2410
- meta: _optionalChain([options, 'optionalAccess', _82 => _82.meta]),
2411
- publicMeta: _optionalChain([options, 'optionalAccess', _83 => _83.publicMeta]),
2412
- user: _optionalChain([options, 'optionalAccess', _84 => _84.id]) ? { id: options.id, info } : { anonymousId: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _85 => _85.anonymousId]), () => ( _nanoid.nanoid.call(void 0, ))), info },
2413
- scopes: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _86 => _86.scopes]), () => ( ["room:write"]))
2423
+ meta: _optionalChain([options, 'optionalAccess', _87 => _87.meta]),
2424
+ publicMeta: _optionalChain([options, 'optionalAccess', _88 => _88.publicMeta]),
2425
+ user: _optionalChain([options, 'optionalAccess', _89 => _89.id]) ? { id: options.id, info } : { anonymousId: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _90 => _90.anonymousId]), () => ( _nanoid.nanoid.call(void 0, ))), info },
2426
+ scopes: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _91 => _91.scopes]), () => ( ["room:write"]))
2414
2427
  };
2415
2428
  if (__privateGet(this, __debug2)) {
2416
2429
  console.log(`new ticket created: ${JSON.stringify(ticket)}`);
@@ -2541,7 +2554,7 @@ var Room = class {
2541
2554
  ctx,
2542
2555
  defer
2543
2556
  );
2544
- const p$ = _optionalChain([this, 'access', _87 => _87.hooks, 'access', _88 => _88.onSessionDidStart, 'optionalCall', _89 => _89(newSession, ctx)]);
2557
+ const p$ = _optionalChain([this, 'access', _92 => _92.hooks, 'access', _93 => _93.onSessionDidStart, 'optionalCall', _94 => _94(newSession, ctx)]);
2545
2558
  if (p$) defer(p$);
2546
2559
  }
2547
2560
  /**
@@ -2565,7 +2578,7 @@ var Room = class {
2565
2578
  for (const other of this.otherSessions(key)) {
2566
2579
  other.send({ type: ServerMsgCode2.USER_LEFT, actor: session.actor });
2567
2580
  }
2568
- const p$ = _optionalChain([this, 'access', _90 => _90.hooks, 'access', _91 => _91.onSessionDidEnd, 'optionalCall', _92 => _92(session, ctx)]);
2581
+ const p$ = _optionalChain([this, 'access', _95 => _95.hooks, 'access', _96 => _96.onSessionDidEnd, 'optionalCall', _97 => _97(session, ctx)]);
2569
2582
  if (p$) defer(p$);
2570
2583
  }
2571
2584
  }
@@ -2596,7 +2609,7 @@ var Room = class {
2596
2609
  );
2597
2610
  }) {
2598
2611
  const text = typeof data === "string" ? data : _core.raise.call(void 0, "Unsupported message format");
2599
- _optionalChain([this, 'access', _93 => _93.sessions, 'access', _94 => _94.get, 'call', _95 => _95(key), 'optionalAccess', _96 => _96.markActive, 'call', _97 => _97()]);
2612
+ _optionalChain([this, 'access', _98 => _98.sessions, 'access', _99 => _99.get, 'call', _100 => _100(key), 'optionalAccess', _101 => _101.markActive, 'call', _102 => _102()]);
2600
2613
  if (text === "ping") {
2601
2614
  await this.handlePing(key, ctx);
2602
2615
  } else {
@@ -2973,7 +2986,7 @@ var Room = class {
2973
2986
  }
2974
2987
  const sent = session.sendPong();
2975
2988
  if (sent !== 0) {
2976
- await _optionalChain([this, 'access', _98 => _98.hooks, 'access', _99 => _99.onDidPong, 'optionalCall', _100 => _100(ctx)]);
2989
+ await _optionalChain([this, 'access', _103 => _103.hooks, 'access', _104 => _104.onDidPong, 'optionalCall', _105 => _105(ctx)]);
2977
2990
  }
2978
2991
  }
2979
2992
  _processClientMsg_withExclusiveAccess(sessionKey, messages, ctx, defer) {
@@ -3104,22 +3117,26 @@ var Room = class {
3104
3117
  break;
3105
3118
  }
3106
3119
  case _core.ClientMsgCode.UPDATE_STORAGE: {
3107
- _optionalChain([this, 'access', _101 => _101.driver, 'access', _102 => _102.bump_storage_version, 'optionalCall', _103 => _103()]);
3120
+ _optionalChain([this, 'access', _106 => _106.driver, 'access', _107 => _107.bump_storage_version, 'optionalCall', _108 => _108()]);
3108
3121
  const result = this.storage.applyOps(msg.ops);
3109
3122
  const opsToForward = result.flatMap(
3110
3123
  (r) => r.action === "accepted" ? [r.op] : []
3111
3124
  );
3112
- const opsToSendBack = result.flatMap((r) => {
3113
- switch (r.action) {
3114
- case "ignored":
3115
- return r.ignoredOpId !== void 0 ? [ackIgnoredOp(r.ignoredOpId)] : [];
3116
- case "accepted":
3117
- return r.fix !== void 0 ? [r.fix] : [];
3118
- // istanbul ignore next
3119
- default:
3120
- return _core.assertNever.call(void 0, r, "Unhandled case");
3125
+ const opsToSendBack = result.flatMap(
3126
+ (r) => {
3127
+ switch (r.action) {
3128
+ case "ignored":
3129
+ return r.ignoredOpId !== void 0 ? [ackIgnoredOp(r.ignoredOpId)] : [];
3130
+ case "rectified":
3131
+ return [r.ackOp, r.fix];
3132
+ case "accepted":
3133
+ return r.fix !== void 0 ? [r.fix] : [];
3134
+ // istanbul ignore next
3135
+ default:
3136
+ return _core.assertNever.call(void 0, r, "Unhandled case");
3137
+ }
3121
3138
  }
3122
- });
3139
+ );
3123
3140
  if (opsToForward.length > 0) {
3124
3141
  scheduleFanOut({
3125
3142
  type: ServerMsgCode2.UPDATE_STORAGE,
@@ -3137,7 +3154,7 @@ var Room = class {
3137
3154
  });
3138
3155
  }
3139
3156
  if (opsToForward.length > 0) {
3140
- const p$ = _optionalChain([this, 'access', _104 => _104.hooks, 'access', _105 => _105.postClientMsgStorageDidUpdate, 'optionalCall', _106 => _106(ctx)]);
3157
+ const p$ = _optionalChain([this, 'access', _109 => _109.hooks, 'access', _110 => _110.postClientMsgStorageDidUpdate, 'optionalCall', _111 => _111(ctx)]);
3141
3158
  if (p$) defer(p$);
3142
3159
  }
3143
3160
  break;
@@ -3194,7 +3211,7 @@ var Room = class {
3194
3211
  defer
3195
3212
  );
3196
3213
  if (result.isUpdated) {
3197
- const p$ = _optionalChain([this, 'access', _107 => _107.hooks, 'access', _108 => _108.postClientMsgYdocDidUpdate, 'optionalCall', _109 => _109(ctx, session)]);
3214
+ const p$ = _optionalChain([this, 'access', _112 => _112.hooks, 'access', _113 => _113.postClientMsgYdocDidUpdate, 'optionalCall', _114 => _114(ctx, session)]);
3198
3215
  if (p$) defer(p$);
3199
3216
  }
3200
3217
  break;