@liveblocks/core 2.0.3 → 2.0.4-test1

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.js 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 = "2.0.3";
9
+ var PKG_VERSION = "2.0.4-test1";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -5688,10 +5688,17 @@ function createRoom(options, config) {
5688
5688
  } else {
5689
5689
  context.root = LiveObject._fromItems(message.items, pool);
5690
5690
  }
5691
+ const canWrite = _nullishCoalesce(_optionalChain([self, 'access', _138 => _138.current, 'optionalAccess', _139 => _139.canWrite]), () => ( true));
5691
5692
  const stackSizeBefore = context.undoStack.length;
5692
5693
  for (const key in context.initialStorage) {
5693
5694
  if (context.root.get(key) === void 0) {
5694
- context.root.set(key, cloneLson(context.initialStorage[key]));
5695
+ if (canWrite) {
5696
+ context.root.set(key, cloneLson(context.initialStorage[key]));
5697
+ } else {
5698
+ warn(
5699
+ `Attempted to populate missing storage key '${key}', but current user has no write access`
5700
+ );
5701
+ }
5695
5702
  }
5696
5703
  }
5697
5704
  context.undoStack.length = stackSizeBefore;
@@ -5886,7 +5893,7 @@ function createRoom(options, config) {
5886
5893
  }
5887
5894
  context.myPresence.patch(patch);
5888
5895
  if (context.activeBatch) {
5889
- if (_optionalChain([options2, 'optionalAccess', _138 => _138.addToHistory])) {
5896
+ if (_optionalChain([options2, 'optionalAccess', _140 => _140.addToHistory])) {
5890
5897
  context.activeBatch.reverseOps.unshift({
5891
5898
  type: "presence",
5892
5899
  data: oldValues
@@ -5896,7 +5903,7 @@ function createRoom(options, config) {
5896
5903
  } else {
5897
5904
  flushNowOrSoon();
5898
5905
  batchUpdates(() => {
5899
- if (_optionalChain([options2, 'optionalAccess', _139 => _139.addToHistory])) {
5906
+ if (_optionalChain([options2, 'optionalAccess', _141 => _141.addToHistory])) {
5900
5907
  addToUndoStack(
5901
5908
  [{ type: "presence", data: oldValues }],
5902
5909
  doNotBatchUpdates
@@ -6094,7 +6101,7 @@ function createRoom(options, config) {
6094
6101
  if (process.env.NODE_ENV !== "production") {
6095
6102
  const traces = /* @__PURE__ */ new Set();
6096
6103
  for (const opId of message.opIds) {
6097
- const trace = _optionalChain([context, 'access', _140 => _140.opStackTraces, 'optionalAccess', _141 => _141.get, 'call', _142 => _142(opId)]);
6104
+ const trace = _optionalChain([context, 'access', _142 => _142.opStackTraces, 'optionalAccess', _143 => _143.get, 'call', _144 => _144(opId)]);
6098
6105
  if (trace) {
6099
6106
  traces.add(trace);
6100
6107
  }
@@ -6227,7 +6234,7 @@ ${Array.from(traces).join("\n\n")}`
6227
6234
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
6228
6235
  createOrUpdateRootFromMessage(message, doNotBatchUpdates);
6229
6236
  applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
6230
- _optionalChain([_resolveStoragePromise, 'optionalCall', _143 => _143()]);
6237
+ _optionalChain([_resolveStoragePromise, 'optionalCall', _145 => _145()]);
6231
6238
  notifyStorageStatus();
6232
6239
  eventHub.storageDidLoad.notify();
6233
6240
  }
@@ -6502,7 +6509,7 @@ ${Array.from(traces).join("\n\n")}`
6502
6509
  {
6503
6510
  [kInternal]: {
6504
6511
  get presenceBuffer() {
6505
- return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _144 => _144.buffer, 'access', _145 => _145.presenceUpdates, 'optionalAccess', _146 => _146.data]), () => ( null)));
6512
+ return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _146 => _146.buffer, 'access', _147 => _147.presenceUpdates, 'optionalAccess', _148 => _148.data]), () => ( null)));
6506
6513
  },
6507
6514
  // prettier-ignore
6508
6515
  get undoStack() {
@@ -6650,7 +6657,7 @@ function makeClassicSubscribeFn(events) {
6650
6657
  }
6651
6658
  if (isLiveNode(first)) {
6652
6659
  const node = first;
6653
- if (_optionalChain([options, 'optionalAccess', _147 => _147.isDeep])) {
6660
+ if (_optionalChain([options, 'optionalAccess', _149 => _149.isDeep])) {
6654
6661
  const storageCallback = second;
6655
6662
  return subscribeToLiveStructureDeeply(node, storageCallback);
6656
6663
  } else {
@@ -7011,7 +7018,7 @@ function upsertComment(thread, comment) {
7011
7018
  );
7012
7019
  if (existingComment === void 0) {
7013
7020
  const updatedAt = new Date(
7014
- Math.max(_optionalChain([thread, 'access', _148 => _148.updatedAt, 'optionalAccess', _149 => _149.getTime, 'call', _150 => _150()]) || 0, comment.createdAt.getTime())
7021
+ Math.max(_optionalChain([thread, 'access', _150 => _150.updatedAt, 'optionalAccess', _151 => _151.getTime, 'call', _152 => _152()]) || 0, comment.createdAt.getTime())
7015
7022
  );
7016
7023
  const updatedThread = {
7017
7024
  ...thread,
@@ -7031,8 +7038,8 @@ function upsertComment(thread, comment) {
7031
7038
  ...thread,
7032
7039
  updatedAt: new Date(
7033
7040
  Math.max(
7034
- _optionalChain([thread, 'access', _151 => _151.updatedAt, 'optionalAccess', _152 => _152.getTime, 'call', _153 => _153()]) || 0,
7035
- _optionalChain([comment, 'access', _154 => _154.editedAt, 'optionalAccess', _155 => _155.getTime, 'call', _156 => _156()]) || comment.createdAt.getTime()
7041
+ _optionalChain([thread, 'access', _153 => _153.updatedAt, 'optionalAccess', _154 => _154.getTime, 'call', _155 => _155()]) || 0,
7042
+ _optionalChain([comment, 'access', _156 => _156.editedAt, 'optionalAccess', _157 => _157.getTime, 'call', _158 => _158()]) || comment.createdAt.getTime()
7036
7043
  )
7037
7044
  ),
7038
7045
  comments: updatedComments
@@ -7097,7 +7104,7 @@ function addReaction(thread, commentId, reaction) {
7097
7104
  return {
7098
7105
  ...thread,
7099
7106
  updatedAt: new Date(
7100
- Math.max(reaction.createdAt.getTime(), _optionalChain([thread, 'access', _157 => _157.updatedAt, 'optionalAccess', _158 => _158.getTime, 'call', _159 => _159()]) || 0)
7107
+ Math.max(reaction.createdAt.getTime(), _optionalChain([thread, 'access', _159 => _159.updatedAt, 'optionalAccess', _160 => _160.getTime, 'call', _161 => _161()]) || 0)
7101
7108
  ),
7102
7109
  comments: updatedComments
7103
7110
  };
@@ -7130,7 +7137,7 @@ function removeReaction(thread, commentId, emoji, userId, removedAt) {
7130
7137
  return {
7131
7138
  ...thread,
7132
7139
  updatedAt: new Date(
7133
- Math.max(removedAt.getTime(), _optionalChain([thread, 'access', _160 => _160.updatedAt, 'optionalAccess', _161 => _161.getTime, 'call', _162 => _162()]) || 0)
7140
+ Math.max(removedAt.getTime(), _optionalChain([thread, 'access', _162 => _162.updatedAt, 'optionalAccess', _163 => _163.getTime, 'call', _164 => _164()]) || 0)
7134
7141
  ),
7135
7142
  comments: updatedComments
7136
7143
  };
@@ -7241,12 +7248,12 @@ function createClient(options) {
7241
7248
  createSocket: makeCreateSocketDelegateForRoom(
7242
7249
  roomId,
7243
7250
  baseUrl,
7244
- _optionalChain([clientOptions, 'access', _163 => _163.polyfills, 'optionalAccess', _164 => _164.WebSocket])
7251
+ _optionalChain([clientOptions, 'access', _165 => _165.polyfills, 'optionalAccess', _166 => _166.WebSocket])
7245
7252
  ),
7246
7253
  authenticate: makeAuthDelegateForRoom(roomId, authManager)
7247
7254
  })),
7248
7255
  enableDebugLogging: clientOptions.enableDebugLogging,
7249
- unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _165 => _165.unstable_batchedUpdates]),
7256
+ unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _167 => _167.unstable_batchedUpdates]),
7250
7257
  baseUrl,
7251
7258
  unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP,
7252
7259
  unstable_streamData: !!clientOptions.unstable_streamData
@@ -7262,7 +7269,7 @@ function createClient(options) {
7262
7269
  const shouldConnect = _nullishCoalesce(options2.autoConnect, () => ( true));
7263
7270
  if (shouldConnect) {
7264
7271
  if (typeof atob === "undefined") {
7265
- if (_optionalChain([clientOptions, 'access', _166 => _166.polyfills, 'optionalAccess', _167 => _167.atob]) === void 0) {
7272
+ if (_optionalChain([clientOptions, 'access', _168 => _168.polyfills, 'optionalAccess', _169 => _169.atob]) === void 0) {
7266
7273
  throw new Error(
7267
7274
  "You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
7268
7275
  );
@@ -7274,7 +7281,7 @@ function createClient(options) {
7274
7281
  return leaseRoom(newRoomDetails);
7275
7282
  }
7276
7283
  function getRoom(roomId) {
7277
- const room = _optionalChain([roomsById, 'access', _168 => _168.get, 'call', _169 => _169(roomId), 'optionalAccess', _170 => _170.room]);
7284
+ const room = _optionalChain([roomsById, 'access', _170 => _170.get, 'call', _171 => _171(roomId), 'optionalAccess', _172 => _172.room]);
7278
7285
  return room ? room : null;
7279
7286
  }
7280
7287
  function logout() {
@@ -7293,7 +7300,7 @@ function createClient(options) {
7293
7300
  markInboxNotificationAsRead
7294
7301
  } = createNotificationsApi({
7295
7302
  baseUrl,
7296
- fetcher: _optionalChain([clientOptions, 'access', _171 => _171.polyfills, 'optionalAccess', _172 => _172.fetch]) || /* istanbul ignore next */
7303
+ fetcher: _optionalChain([clientOptions, 'access', _173 => _173.polyfills, 'optionalAccess', _174 => _174.fetch]) || /* istanbul ignore next */
7297
7304
  fetch,
7298
7305
  authManager,
7299
7306
  currentUserIdStore
@@ -7307,7 +7314,7 @@ function createClient(options) {
7307
7314
  const usersStore = createBatchStore(
7308
7315
  async (batchedUserIds) => {
7309
7316
  const userIds = batchedUserIds.flat();
7310
- const users = await _optionalChain([resolveUsers, 'optionalCall', _173 => _173({ userIds })]);
7317
+ const users = await _optionalChain([resolveUsers, 'optionalCall', _175 => _175({ userIds })]);
7311
7318
  warnIfNoResolveUsers();
7312
7319
  return _nullishCoalesce(users, () => ( userIds.map(() => void 0)));
7313
7320
  },
@@ -7321,7 +7328,7 @@ function createClient(options) {
7321
7328
  const roomsInfoStore = createBatchStore(
7322
7329
  async (batchedRoomIds) => {
7323
7330
  const roomIds = batchedRoomIds.flat();
7324
- const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _174 => _174({ roomIds })]);
7331
+ const roomsInfo = await _optionalChain([resolveRoomsInfo, 'optionalCall', _176 => _176({ roomIds })]);
7325
7332
  warnIfNoResolveRoomsInfo();
7326
7333
  return _nullishCoalesce(roomsInfo, () => ( roomIds.map(() => void 0)));
7327
7334
  },
@@ -7433,7 +7440,7 @@ var commentBodyElementsTypes = {
7433
7440
  mention: "inline"
7434
7441
  };
7435
7442
  function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
7436
- if (!body || !_optionalChain([body, 'optionalAccess', _175 => _175.content])) {
7443
+ if (!body || !_optionalChain([body, 'optionalAccess', _177 => _177.content])) {
7437
7444
  return;
7438
7445
  }
7439
7446
  const element = typeof elementOrVisitor === "string" ? elementOrVisitor : void 0;
@@ -7443,13 +7450,13 @@ function traverseCommentBody(body, elementOrVisitor, possiblyVisitor) {
7443
7450
  for (const block of body.content) {
7444
7451
  if (type === "all" || type === "block") {
7445
7452
  if (guard(block)) {
7446
- _optionalChain([visitor, 'optionalCall', _176 => _176(block)]);
7453
+ _optionalChain([visitor, 'optionalCall', _178 => _178(block)]);
7447
7454
  }
7448
7455
  }
7449
7456
  if (type === "all" || type === "inline") {
7450
7457
  for (const inline of block.children) {
7451
7458
  if (guard(inline)) {
7452
- _optionalChain([visitor, 'optionalCall', _177 => _177(inline)]);
7459
+ _optionalChain([visitor, 'optionalCall', _179 => _179(inline)]);
7453
7460
  }
7454
7461
  }
7455
7462
  }
@@ -7474,7 +7481,7 @@ async function resolveUsersInCommentBody(body, resolveUsers) {
7474
7481
  userIds
7475
7482
  });
7476
7483
  for (const [index, userId] of userIds.entries()) {
7477
- const user = _optionalChain([users, 'optionalAccess', _178 => _178[index]]);
7484
+ const user = _optionalChain([users, 'optionalAccess', _180 => _180[index]]);
7478
7485
  if (user) {
7479
7486
  resolvedUsers.set(userId, user);
7480
7487
  }
@@ -7597,7 +7604,7 @@ var stringifyCommentBodyPlainElements = {
7597
7604
  text: ({ element }) => element.text,
7598
7605
  link: ({ element }) => element.url,
7599
7606
  mention: ({ element, user }) => {
7600
- return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _179 => _179.name]), () => ( element.id))}`;
7607
+ return `@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _181 => _181.name]), () => ( element.id))}`;
7601
7608
  }
7602
7609
  };
7603
7610
  var stringifyCommentBodyHtmlElements = {
@@ -7627,7 +7634,7 @@ var stringifyCommentBodyHtmlElements = {
7627
7634
  return html`<a href="${href}" target="_blank" rel="noopener noreferrer">${element.url}</a>`;
7628
7635
  },
7629
7636
  mention: ({ element, user }) => {
7630
- return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _180 => _180.name]), () => ( element.id))}</span>`;
7637
+ return html`<span data-mention>@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _182 => _182.name]), () => ( element.id))}</span>`;
7631
7638
  }
7632
7639
  };
7633
7640
  var stringifyCommentBodyMarkdownElements = {
@@ -7657,19 +7664,19 @@ var stringifyCommentBodyMarkdownElements = {
7657
7664
  return markdown`[${element.url}](${href})`;
7658
7665
  },
7659
7666
  mention: ({ element, user }) => {
7660
- return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _181 => _181.name]), () => ( element.id))}`;
7667
+ return markdown`@${_nullishCoalesce(_optionalChain([user, 'optionalAccess', _183 => _183.name]), () => ( element.id))}`;
7661
7668
  }
7662
7669
  };
7663
7670
  async function stringifyCommentBody(body, options) {
7664
- const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _182 => _182.format]), () => ( "plain"));
7665
- const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _183 => _183.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
7671
+ const format = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _184 => _184.format]), () => ( "plain"));
7672
+ const separator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _185 => _185.separator]), () => ( (format === "markdown" ? "\n\n" : "\n")));
7666
7673
  const elements = {
7667
7674
  ...format === "html" ? stringifyCommentBodyHtmlElements : format === "markdown" ? stringifyCommentBodyMarkdownElements : stringifyCommentBodyPlainElements,
7668
- ..._optionalChain([options, 'optionalAccess', _184 => _184.elements])
7675
+ ..._optionalChain([options, 'optionalAccess', _186 => _186.elements])
7669
7676
  };
7670
7677
  const resolvedUsers = await resolveUsersInCommentBody(
7671
7678
  body,
7672
- _optionalChain([options, 'optionalAccess', _185 => _185.resolveUsers])
7679
+ _optionalChain([options, 'optionalAccess', _187 => _187.resolveUsers])
7673
7680
  );
7674
7681
  const blocks = body.content.flatMap((block, blockIndex) => {
7675
7682
  switch (block.type) {
@@ -7944,12 +7951,12 @@ function legacy_patchImmutableNode(state, path, update) {
7944
7951
  }
7945
7952
  const newState = Object.assign({}, state);
7946
7953
  for (const key in update.updates) {
7947
- if (_optionalChain([update, 'access', _186 => _186.updates, 'access', _187 => _187[key], 'optionalAccess', _188 => _188.type]) === "update") {
7954
+ if (_optionalChain([update, 'access', _188 => _188.updates, 'access', _189 => _189[key], 'optionalAccess', _190 => _190.type]) === "update") {
7948
7955
  const val = update.node.get(key);
7949
7956
  if (val !== void 0) {
7950
7957
  newState[key] = lsonToJson(val);
7951
7958
  }
7952
- } else if (_optionalChain([update, 'access', _189 => _189.updates, 'access', _190 => _190[key], 'optionalAccess', _191 => _191.type]) === "delete") {
7959
+ } else if (_optionalChain([update, 'access', _191 => _191.updates, 'access', _192 => _192[key], 'optionalAccess', _193 => _193.type]) === "delete") {
7953
7960
  delete newState[key];
7954
7961
  }
7955
7962
  }
@@ -8010,12 +8017,12 @@ function legacy_patchImmutableNode(state, path, update) {
8010
8017
  }
8011
8018
  const newState = Object.assign({}, state);
8012
8019
  for (const key in update.updates) {
8013
- if (_optionalChain([update, 'access', _192 => _192.updates, 'access', _193 => _193[key], 'optionalAccess', _194 => _194.type]) === "update") {
8020
+ if (_optionalChain([update, 'access', _194 => _194.updates, 'access', _195 => _195[key], 'optionalAccess', _196 => _196.type]) === "update") {
8014
8021
  const value = update.node.get(key);
8015
8022
  if (value !== void 0) {
8016
8023
  newState[key] = lsonToJson(value);
8017
8024
  }
8018
- } else if (_optionalChain([update, 'access', _195 => _195.updates, 'access', _196 => _196[key], 'optionalAccess', _197 => _197.type]) === "delete") {
8025
+ } else if (_optionalChain([update, 'access', _197 => _197.updates, 'access', _198 => _198[key], 'optionalAccess', _199 => _199.type]) === "delete") {
8019
8026
  delete newState[key];
8020
8027
  }
8021
8028
  }