@liveblocks/node 3.8.1 → 3.9.0

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
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node";
6
- var PKG_VERSION = "3.8.1";
6
+ var PKG_VERSION = "3.9.0";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // src/client.ts
@@ -337,20 +337,6 @@ var Liveblocks = class {
337
337
  });
338
338
  return res;
339
339
  }
340
- async #put(path, json, options) {
341
- const url3 = _core.urljoin.call(void 0, this.#baseUrl, path);
342
- const headers = {
343
- Authorization: `Bearer ${this.#secret}`,
344
- "Content-Type": "application/json"
345
- };
346
- const fetch = await fetchPolyfill();
347
- return await fetch(url3, {
348
- method: "PUT",
349
- headers,
350
- body: JSON.stringify(json),
351
- signal: _optionalChain([options, 'optionalAccess', _2 => _2.signal])
352
- });
353
- }
354
340
  async #putBinary(path, body, params, options) {
355
341
  const url3 = _core.urljoin.call(void 0, this.#baseUrl, path, params);
356
342
  const headers = {
@@ -362,7 +348,7 @@ var Liveblocks = class {
362
348
  method: "PUT",
363
349
  headers,
364
350
  body,
365
- signal: _optionalChain([options, 'optionalAccess', _3 => _3.signal])
351
+ signal: _optionalChain([options, 'optionalAccess', _2 => _2.signal])
366
352
  });
367
353
  }
368
354
  async #delete(path, params, options) {
@@ -374,7 +360,7 @@ var Liveblocks = class {
374
360
  const res = await fetch(url3, {
375
361
  method: "DELETE",
376
362
  headers,
377
- signal: _optionalChain([options, 'optionalAccess', _4 => _4.signal])
363
+ signal: _optionalChain([options, 'optionalAccess', _3 => _3.signal])
378
364
  });
379
365
  return res;
380
366
  }
@@ -387,7 +373,7 @@ var Liveblocks = class {
387
373
  const res = await fetch(url3, {
388
374
  method: "GET",
389
375
  headers,
390
- signal: _optionalChain([options, 'optionalAccess', _5 => _5.signal])
376
+ signal: _optionalChain([options, 'optionalAccess', _4 => _4.signal])
391
377
  });
392
378
  return res;
393
379
  }
@@ -417,8 +403,8 @@ var Liveblocks = class {
417
403
  return new Session(
418
404
  this.#post.bind(this),
419
405
  userId,
420
- _optionalChain([options, 'optionalAccess', _6 => _6.userInfo]),
421
- _optionalChain([options, 'optionalAccess', _7 => _7.tenantId])
406
+ _optionalChain([options, 'optionalAccess', _5 => _5.userInfo]),
407
+ _optionalChain([options, 'optionalAccess', _6 => _6.tenantId])
422
408
  );
423
409
  }
424
410
  /**
@@ -463,7 +449,7 @@ var Liveblocks = class {
463
449
  userId,
464
450
  groupIds,
465
451
  tenantId,
466
- userInfo: _optionalChain([options, 'optionalAccess', _8 => _8.userInfo])
452
+ userInfo: _optionalChain([options, 'optionalAccess', _7 => _7.userInfo])
467
453
  };
468
454
  try {
469
455
  const resp = await this.#post(path, body);
@@ -539,7 +525,7 @@ var Liveblocks = class {
539
525
  */
540
526
  async *iterRooms(criteria, options) {
541
527
  const { signal } = _nullishCoalesce(options, () => ( {}));
542
- const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.pageSize]), () => ( 40)), 20);
528
+ const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _8 => _8.pageSize]), () => ( 40)), 20);
543
529
  let cursor = void 0;
544
530
  while (true) {
545
531
  const { nextCursor, data } = await this.getRooms(
@@ -575,7 +561,7 @@ var Liveblocks = class {
575
561
  tenantId
576
562
  } = params;
577
563
  const res = await this.#post(
578
- _optionalChain([options, 'optionalAccess', _10 => _10.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
564
+ _optionalChain([options, 'optionalAccess', _9 => _9.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
579
565
  {
580
566
  id: roomId,
581
567
  defaultAccesses,
@@ -870,152 +856,6 @@ var Liveblocks = class {
870
856
  }
871
857
  return res.arrayBuffer();
872
858
  }
873
- /* -------------------------------------------------------------------------------------------------
874
- * Schema Validation
875
- * -----------------------------------------------------------------------------------------------*/
876
- /**
877
- * Creates a new schema which can be referenced later to enforce a room’s Storage data structure.
878
- * @param name The name used to reference the schema. Must be a non-empty string with less than 65 characters and only contain lowercase letters, numbers and dashes
879
- * @param body The exact allowed shape of data in the room. It is a multi-line string written in the [Liveblocks schema syntax](https://liveblocks.io/docs/platform/schema-validation/syntax).
880
- * @param options.signal (optional) An abort signal to cancel the request.
881
- * @returns The created schema.
882
- */
883
- async createSchema(name, body, options) {
884
- const res = await this.#post(_core.url`/v2/schemas`, { name, body }, options);
885
- if (!res.ok) {
886
- throw await LiveblocksError.from(res);
887
- }
888
- const data = await res.json();
889
- const createdAt = new Date(data.createdAt);
890
- const updatedAt = new Date(data.updatedAt);
891
- return {
892
- ...data,
893
- createdAt,
894
- updatedAt
895
- };
896
- }
897
- /**
898
- * Returns a schema by its id.
899
- * @param schemaId Id of the schema - this is the combination of the schema name and version of the schema to update. For example, `my-schema@1`.
900
- * @param options.signal (optional) An abort signal to cancel the request.
901
- * @returns The schema with the given id.
902
- */
903
- async getSchema(schemaId, options) {
904
- const res = await this.#get(
905
- _core.url`/v2/schemas/${schemaId}`,
906
- void 0,
907
- options
908
- );
909
- if (!res.ok) {
910
- throw await LiveblocksError.from(res);
911
- }
912
- const data = await res.json();
913
- const createdAt = new Date(data.createdAt);
914
- const updatedAt = new Date(data.updatedAt);
915
- return {
916
- ...data,
917
- createdAt,
918
- updatedAt
919
- };
920
- }
921
- /**
922
- * Updates the body for the schema. A schema can only be updated if it is not used by any room.
923
- * @param schemaId Id of the schema - this is the combination of the schema name and version of the schema to update. For example, `my-schema@1`.
924
- * @param body The exact allowed shape of data in the room. It is a multi-line string written in the [Liveblocks schema syntax](https://liveblocks.io/docs/platform/schema-validation/syntax).
925
- * @param options.signal (optional) An abort signal to cancel the request.
926
- * @returns The updated schema. The version of the schema will be incremented.
927
- */
928
- async updateSchema(schemaId, body, options) {
929
- const res = await this.#put(
930
- _core.url`/v2/schemas/${schemaId}`,
931
- { body },
932
- options
933
- );
934
- if (!res.ok) {
935
- throw await LiveblocksError.from(res);
936
- }
937
- const data = await res.json();
938
- const createdAt = new Date(data.createdAt);
939
- const updatedAt = new Date(data.updatedAt);
940
- return {
941
- ...data,
942
- createdAt,
943
- updatedAt
944
- };
945
- }
946
- /**
947
- * Deletes a schema by its id. A schema can only be deleted if it is not used by any room.
948
- * @param schemaId Id of the schema - this is the combination of the schema name and version of the schema to update. For example, `my-schema@1`.
949
- * @param options.signal (optional) An abort signal to cancel the request.
950
- */
951
- async deleteSchema(schemaId, options) {
952
- const res = await this.#delete(
953
- _core.url`/v2/schemas/${schemaId}`,
954
- void 0,
955
- options
956
- );
957
- if (!res.ok) {
958
- throw await LiveblocksError.from(res);
959
- }
960
- }
961
- /**
962
- * Returns the schema attached to a room.
963
- * @param roomId The id of the room to get the schema from.
964
- * @param options.signal (optional) An abort signal to cancel the request.
965
- * @returns
966
- */
967
- async getSchemaByRoomId(roomId, options) {
968
- const res = await this.#get(
969
- _core.url`/v2/rooms/${roomId}/schema`,
970
- void 0,
971
- options
972
- );
973
- if (!res.ok) {
974
- throw await LiveblocksError.from(res);
975
- }
976
- const data = await res.json();
977
- const createdAt = new Date(data.createdAt);
978
- const updatedAt = new Date(data.updatedAt);
979
- return {
980
- ...data,
981
- createdAt,
982
- updatedAt
983
- };
984
- }
985
- /**
986
- * Attaches a schema to a room, and instantly enables runtime schema validation for the room.
987
- * If the current contents of the room’s Storage do not match the schema, attaching will fail and the error message will give details on why the schema failed to attach.
988
- * @param roomId The id of the room to attach the schema to.
989
- * @param schemaId Id of the schema - this is the combination of the schema name and version of the schema to update. For example, `my-schema@1`.
990
- * @param options.signal (optional) An abort signal to cancel the request.
991
- * @returns The schema id as JSON.
992
- */
993
- async attachSchemaToRoom(roomId, schemaId, options) {
994
- const res = await this.#post(
995
- _core.url`/v2/rooms/${roomId}/schema`,
996
- { schema: schemaId },
997
- options
998
- );
999
- if (!res.ok) {
1000
- throw await LiveblocksError.from(res);
1001
- }
1002
- return await res.json();
1003
- }
1004
- /**
1005
- * Detaches a schema from a room, and disables runtime schema validation for the room.
1006
- * @param roomId The id of the room to detach the schema from.
1007
- * @param options.signal (optional) An abort signal to cancel the request.
1008
- */
1009
- async detachSchemaFromRoom(roomId, options) {
1010
- const res = await this.#delete(
1011
- _core.url`/v2/rooms/${roomId}/schema`,
1012
- void 0,
1013
- options
1014
- );
1015
- if (!res.ok) {
1016
- throw await LiveblocksError.from(res);
1017
- }
1018
- }
1019
859
  /* -------------------------------------------------------------------------------------------------
1020
860
  * Comments
1021
861
  * -----------------------------------------------------------------------------------------------*/
@@ -1156,7 +996,7 @@ var Liveblocks = class {
1156
996
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
1157
997
  {
1158
998
  ...data,
1159
- createdAt: _optionalChain([data, 'access', _11 => _11.createdAt, 'optionalAccess', _12 => _12.toISOString, 'call', _13 => _13()])
999
+ createdAt: _optionalChain([data, 'access', _10 => _10.createdAt, 'optionalAccess', _11 => _11.toISOString, 'call', _12 => _12()])
1160
1000
  },
1161
1001
  options
1162
1002
  );
@@ -1179,7 +1019,7 @@ var Liveblocks = class {
1179
1019
  const { roomId, threadId, commentId, data } = params;
1180
1020
  const res = await this.#post(
1181
1021
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
1182
- { ...data, editedAt: _optionalChain([data, 'access', _14 => _14.editedAt, 'optionalAccess', _15 => _15.toISOString, 'call', _16 => _16()]) },
1022
+ { ...data, editedAt: _optionalChain([data, 'access', _13 => _13.editedAt, 'optionalAccess', _14 => _14.toISOString, 'call', _15 => _15()]) },
1183
1023
  options
1184
1024
  );
1185
1025
  if (!res.ok) {
@@ -1224,7 +1064,7 @@ var Liveblocks = class {
1224
1064
  ...data,
1225
1065
  comment: {
1226
1066
  ...data.comment,
1227
- createdAt: _optionalChain([data, 'access', _17 => _17.comment, 'access', _18 => _18.createdAt, 'optionalAccess', _19 => _19.toISOString, 'call', _20 => _20()])
1067
+ createdAt: _optionalChain([data, 'access', _16 => _16.comment, 'access', _17 => _17.createdAt, 'optionalAccess', _18 => _18.toISOString, 'call', _19 => _19()])
1228
1068
  }
1229
1069
  },
1230
1070
  options
@@ -1347,7 +1187,7 @@ var Liveblocks = class {
1347
1187
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
1348
1188
  {
1349
1189
  ...data,
1350
- updatedAt: _optionalChain([data, 'access', _21 => _21.updatedAt, 'optionalAccess', _22 => _22.toISOString, 'call', _23 => _23()])
1190
+ updatedAt: _optionalChain([data, 'access', _20 => _20.updatedAt, 'optionalAccess', _21 => _21.toISOString, 'call', _22 => _22()])
1351
1191
  },
1352
1192
  options
1353
1193
  );
@@ -1373,7 +1213,7 @@ var Liveblocks = class {
1373
1213
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
1374
1214
  {
1375
1215
  ...data,
1376
- createdAt: _optionalChain([data, 'access', _24 => _24.createdAt, 'optionalAccess', _25 => _25.toISOString, 'call', _26 => _26()])
1216
+ createdAt: _optionalChain([data, 'access', _23 => _23.createdAt, 'optionalAccess', _24 => _24.toISOString, 'call', _25 => _25()])
1377
1217
  },
1378
1218
  options
1379
1219
  );
@@ -1399,7 +1239,7 @@ var Liveblocks = class {
1399
1239
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
1400
1240
  {
1401
1241
  ...data,
1402
- removedAt: _optionalChain([data, 'access', _27 => _27.removedAt, 'optionalAccess', _28 => _28.toISOString, 'call', _29 => _29()])
1242
+ removedAt: _optionalChain([data, 'access', _26 => _26.removedAt, 'optionalAccess', _27 => _27.toISOString, 'call', _28 => _28()])
1403
1243
  },
1404
1244
  options
1405
1245
  );
@@ -1475,7 +1315,7 @@ var Liveblocks = class {
1475
1315
  */
1476
1316
  async *iterInboxNotifications(criteria, options) {
1477
1317
  const { signal } = _nullishCoalesce(options, () => ( {}));
1478
- const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _30 => _30.pageSize]), () => ( 50)), 10);
1318
+ const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _29 => _29.pageSize]), () => ( 50)), 10);
1479
1319
  let cursor = void 0;
1480
1320
  while (true) {
1481
1321
  const { nextCursor, data } = await this.getInboxNotifications(
@@ -1799,7 +1639,7 @@ var Liveblocks = class {
1799
1639
  async getGroups(params, options) {
1800
1640
  const res = await this.#get(
1801
1641
  _core.url`/v2/groups`,
1802
- { startingAfter: _optionalChain([params, 'optionalAccess', _31 => _31.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _32 => _32.limit]) },
1642
+ { startingAfter: _optionalChain([params, 'optionalAccess', _30 => _30.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _31 => _31.limit]) },
1803
1643
  options
1804
1644
  );
1805
1645
  if (!res.ok) {
@@ -1861,7 +1701,7 @@ var Liveblocks = class {
1861
1701
  async massMutateStorage(criteria, callback, massOptions) {
1862
1702
  const concurrency = _core.checkBounds.call(void 0,
1863
1703
  "concurrency",
1864
- _nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _33 => _33.concurrency]), () => ( 8)),
1704
+ _nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _32 => _32.concurrency]), () => ( 8)),
1865
1705
  1,
1866
1706
  20
1867
1707
  );
@@ -1877,7 +1717,7 @@ var Liveblocks = class {
1877
1717
  }
1878
1718
  async #_mutateOneRoom(roomId, room, callback, options) {
1879
1719
  const debounceInterval = 200;
1880
- const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _34 => _34.signal]));
1720
+ const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _33 => _33.signal]));
1881
1721
  let opsBuffer = [];
1882
1722
  let outstandingFlush$ = void 0;
1883
1723
  let lastFlush = performance.now();
@@ -1943,7 +1783,7 @@ var Liveblocks = class {
1943
1783
  const res = await this.#post(
1944
1784
  _core.url`/v2/rooms/${roomId}/send-message`,
1945
1785
  { messages },
1946
- { signal: _optionalChain([options, 'optionalAccess', _35 => _35.signal]) }
1786
+ { signal: _optionalChain([options, 'optionalAccess', _34 => _34.signal]) }
1947
1787
  );
1948
1788
  if (!res.ok) {
1949
1789
  throw await LiveblocksError.from(res);
@@ -2080,7 +1920,7 @@ var Liveblocks = class {
2080
1920
  "Content-Type": params.file.type,
2081
1921
  "Content-Length": String(params.file.size)
2082
1922
  },
2083
- signal: _optionalChain([options, 'optionalAccess', _36 => _36.signal])
1923
+ signal: _optionalChain([options, 'optionalAccess', _35 => _35.signal])
2084
1924
  }
2085
1925
  );
2086
1926
  if (!res.ok) {