@liveblocks/node 3.8.0 → 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 +29 -182
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -70
- package/dist/index.d.ts +36 -70
- package/dist/index.js +9 -162
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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.
|
|
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',
|
|
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',
|
|
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',
|
|
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',
|
|
421
|
-
_optionalChain([options, 'optionalAccess',
|
|
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',
|
|
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',
|
|
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(
|
|
@@ -567,14 +553,21 @@ var Liveblocks = class {
|
|
|
567
553
|
* @returns The created room.
|
|
568
554
|
*/
|
|
569
555
|
async createRoom(roomId, params, options) {
|
|
570
|
-
const {
|
|
556
|
+
const {
|
|
557
|
+
defaultAccesses,
|
|
558
|
+
groupsAccesses,
|
|
559
|
+
usersAccesses,
|
|
560
|
+
metadata,
|
|
561
|
+
tenantId
|
|
562
|
+
} = params;
|
|
571
563
|
const res = await this.#post(
|
|
572
|
-
_optionalChain([options, 'optionalAccess',
|
|
564
|
+
_optionalChain([options, 'optionalAccess', _9 => _9.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
|
|
573
565
|
{
|
|
574
566
|
id: roomId,
|
|
575
567
|
defaultAccesses,
|
|
576
568
|
groupsAccesses,
|
|
577
569
|
usersAccesses,
|
|
570
|
+
tenantId,
|
|
578
571
|
metadata
|
|
579
572
|
},
|
|
580
573
|
options
|
|
@@ -863,152 +856,6 @@ var Liveblocks = class {
|
|
|
863
856
|
}
|
|
864
857
|
return res.arrayBuffer();
|
|
865
858
|
}
|
|
866
|
-
/* -------------------------------------------------------------------------------------------------
|
|
867
|
-
* Schema Validation
|
|
868
|
-
* -----------------------------------------------------------------------------------------------*/
|
|
869
|
-
/**
|
|
870
|
-
* Creates a new schema which can be referenced later to enforce a room’s Storage data structure.
|
|
871
|
-
* @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
|
|
872
|
-
* @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).
|
|
873
|
-
* @param options.signal (optional) An abort signal to cancel the request.
|
|
874
|
-
* @returns The created schema.
|
|
875
|
-
*/
|
|
876
|
-
async createSchema(name, body, options) {
|
|
877
|
-
const res = await this.#post(_core.url`/v2/schemas`, { name, body }, options);
|
|
878
|
-
if (!res.ok) {
|
|
879
|
-
throw await LiveblocksError.from(res);
|
|
880
|
-
}
|
|
881
|
-
const data = await res.json();
|
|
882
|
-
const createdAt = new Date(data.createdAt);
|
|
883
|
-
const updatedAt = new Date(data.updatedAt);
|
|
884
|
-
return {
|
|
885
|
-
...data,
|
|
886
|
-
createdAt,
|
|
887
|
-
updatedAt
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
891
|
-
* Returns a schema by its id.
|
|
892
|
-
* @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`.
|
|
893
|
-
* @param options.signal (optional) An abort signal to cancel the request.
|
|
894
|
-
* @returns The schema with the given id.
|
|
895
|
-
*/
|
|
896
|
-
async getSchema(schemaId, options) {
|
|
897
|
-
const res = await this.#get(
|
|
898
|
-
_core.url`/v2/schemas/${schemaId}`,
|
|
899
|
-
void 0,
|
|
900
|
-
options
|
|
901
|
-
);
|
|
902
|
-
if (!res.ok) {
|
|
903
|
-
throw await LiveblocksError.from(res);
|
|
904
|
-
}
|
|
905
|
-
const data = await res.json();
|
|
906
|
-
const createdAt = new Date(data.createdAt);
|
|
907
|
-
const updatedAt = new Date(data.updatedAt);
|
|
908
|
-
return {
|
|
909
|
-
...data,
|
|
910
|
-
createdAt,
|
|
911
|
-
updatedAt
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* Updates the body for the schema. A schema can only be updated if it is not used by any room.
|
|
916
|
-
* @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`.
|
|
917
|
-
* @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).
|
|
918
|
-
* @param options.signal (optional) An abort signal to cancel the request.
|
|
919
|
-
* @returns The updated schema. The version of the schema will be incremented.
|
|
920
|
-
*/
|
|
921
|
-
async updateSchema(schemaId, body, options) {
|
|
922
|
-
const res = await this.#put(
|
|
923
|
-
_core.url`/v2/schemas/${schemaId}`,
|
|
924
|
-
{ body },
|
|
925
|
-
options
|
|
926
|
-
);
|
|
927
|
-
if (!res.ok) {
|
|
928
|
-
throw await LiveblocksError.from(res);
|
|
929
|
-
}
|
|
930
|
-
const data = await res.json();
|
|
931
|
-
const createdAt = new Date(data.createdAt);
|
|
932
|
-
const updatedAt = new Date(data.updatedAt);
|
|
933
|
-
return {
|
|
934
|
-
...data,
|
|
935
|
-
createdAt,
|
|
936
|
-
updatedAt
|
|
937
|
-
};
|
|
938
|
-
}
|
|
939
|
-
/**
|
|
940
|
-
* Deletes a schema by its id. A schema can only be deleted if it is not used by any room.
|
|
941
|
-
* @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`.
|
|
942
|
-
* @param options.signal (optional) An abort signal to cancel the request.
|
|
943
|
-
*/
|
|
944
|
-
async deleteSchema(schemaId, options) {
|
|
945
|
-
const res = await this.#delete(
|
|
946
|
-
_core.url`/v2/schemas/${schemaId}`,
|
|
947
|
-
void 0,
|
|
948
|
-
options
|
|
949
|
-
);
|
|
950
|
-
if (!res.ok) {
|
|
951
|
-
throw await LiveblocksError.from(res);
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
/**
|
|
955
|
-
* Returns the schema attached to a room.
|
|
956
|
-
* @param roomId The id of the room to get the schema from.
|
|
957
|
-
* @param options.signal (optional) An abort signal to cancel the request.
|
|
958
|
-
* @returns
|
|
959
|
-
*/
|
|
960
|
-
async getSchemaByRoomId(roomId, options) {
|
|
961
|
-
const res = await this.#get(
|
|
962
|
-
_core.url`/v2/rooms/${roomId}/schema`,
|
|
963
|
-
void 0,
|
|
964
|
-
options
|
|
965
|
-
);
|
|
966
|
-
if (!res.ok) {
|
|
967
|
-
throw await LiveblocksError.from(res);
|
|
968
|
-
}
|
|
969
|
-
const data = await res.json();
|
|
970
|
-
const createdAt = new Date(data.createdAt);
|
|
971
|
-
const updatedAt = new Date(data.updatedAt);
|
|
972
|
-
return {
|
|
973
|
-
...data,
|
|
974
|
-
createdAt,
|
|
975
|
-
updatedAt
|
|
976
|
-
};
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Attaches a schema to a room, and instantly enables runtime schema validation for the room.
|
|
980
|
-
* 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.
|
|
981
|
-
* @param roomId The id of the room to attach the schema to.
|
|
982
|
-
* @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`.
|
|
983
|
-
* @param options.signal (optional) An abort signal to cancel the request.
|
|
984
|
-
* @returns The schema id as JSON.
|
|
985
|
-
*/
|
|
986
|
-
async attachSchemaToRoom(roomId, schemaId, options) {
|
|
987
|
-
const res = await this.#post(
|
|
988
|
-
_core.url`/v2/rooms/${roomId}/schema`,
|
|
989
|
-
{ schema: schemaId },
|
|
990
|
-
options
|
|
991
|
-
);
|
|
992
|
-
if (!res.ok) {
|
|
993
|
-
throw await LiveblocksError.from(res);
|
|
994
|
-
}
|
|
995
|
-
return await res.json();
|
|
996
|
-
}
|
|
997
|
-
/**
|
|
998
|
-
* Detaches a schema from a room, and disables runtime schema validation for the room.
|
|
999
|
-
* @param roomId The id of the room to detach the schema from.
|
|
1000
|
-
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1001
|
-
*/
|
|
1002
|
-
async detachSchemaFromRoom(roomId, options) {
|
|
1003
|
-
const res = await this.#delete(
|
|
1004
|
-
_core.url`/v2/rooms/${roomId}/schema`,
|
|
1005
|
-
void 0,
|
|
1006
|
-
options
|
|
1007
|
-
);
|
|
1008
|
-
if (!res.ok) {
|
|
1009
|
-
throw await LiveblocksError.from(res);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
859
|
/* -------------------------------------------------------------------------------------------------
|
|
1013
860
|
* Comments
|
|
1014
861
|
* -----------------------------------------------------------------------------------------------*/
|
|
@@ -1149,7 +996,7 @@ var Liveblocks = class {
|
|
|
1149
996
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
|
|
1150
997
|
{
|
|
1151
998
|
...data,
|
|
1152
|
-
createdAt: _optionalChain([data, 'access',
|
|
999
|
+
createdAt: _optionalChain([data, 'access', _10 => _10.createdAt, 'optionalAccess', _11 => _11.toISOString, 'call', _12 => _12()])
|
|
1153
1000
|
},
|
|
1154
1001
|
options
|
|
1155
1002
|
);
|
|
@@ -1172,7 +1019,7 @@ var Liveblocks = class {
|
|
|
1172
1019
|
const { roomId, threadId, commentId, data } = params;
|
|
1173
1020
|
const res = await this.#post(
|
|
1174
1021
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
|
|
1175
|
-
{ ...data, editedAt: _optionalChain([data, 'access',
|
|
1022
|
+
{ ...data, editedAt: _optionalChain([data, 'access', _13 => _13.editedAt, 'optionalAccess', _14 => _14.toISOString, 'call', _15 => _15()]) },
|
|
1176
1023
|
options
|
|
1177
1024
|
);
|
|
1178
1025
|
if (!res.ok) {
|
|
@@ -1217,7 +1064,7 @@ var Liveblocks = class {
|
|
|
1217
1064
|
...data,
|
|
1218
1065
|
comment: {
|
|
1219
1066
|
...data.comment,
|
|
1220
|
-
createdAt: _optionalChain([data, 'access',
|
|
1067
|
+
createdAt: _optionalChain([data, 'access', _16 => _16.comment, 'access', _17 => _17.createdAt, 'optionalAccess', _18 => _18.toISOString, 'call', _19 => _19()])
|
|
1221
1068
|
}
|
|
1222
1069
|
},
|
|
1223
1070
|
options
|
|
@@ -1340,7 +1187,7 @@ var Liveblocks = class {
|
|
|
1340
1187
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
|
|
1341
1188
|
{
|
|
1342
1189
|
...data,
|
|
1343
|
-
updatedAt: _optionalChain([data, 'access',
|
|
1190
|
+
updatedAt: _optionalChain([data, 'access', _20 => _20.updatedAt, 'optionalAccess', _21 => _21.toISOString, 'call', _22 => _22()])
|
|
1344
1191
|
},
|
|
1345
1192
|
options
|
|
1346
1193
|
);
|
|
@@ -1366,7 +1213,7 @@ var Liveblocks = class {
|
|
|
1366
1213
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
|
|
1367
1214
|
{
|
|
1368
1215
|
...data,
|
|
1369
|
-
createdAt: _optionalChain([data, 'access',
|
|
1216
|
+
createdAt: _optionalChain([data, 'access', _23 => _23.createdAt, 'optionalAccess', _24 => _24.toISOString, 'call', _25 => _25()])
|
|
1370
1217
|
},
|
|
1371
1218
|
options
|
|
1372
1219
|
);
|
|
@@ -1392,7 +1239,7 @@ var Liveblocks = class {
|
|
|
1392
1239
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
|
|
1393
1240
|
{
|
|
1394
1241
|
...data,
|
|
1395
|
-
removedAt: _optionalChain([data, 'access',
|
|
1242
|
+
removedAt: _optionalChain([data, 'access', _26 => _26.removedAt, 'optionalAccess', _27 => _27.toISOString, 'call', _28 => _28()])
|
|
1396
1243
|
},
|
|
1397
1244
|
options
|
|
1398
1245
|
);
|
|
@@ -1468,7 +1315,7 @@ var Liveblocks = class {
|
|
|
1468
1315
|
*/
|
|
1469
1316
|
async *iterInboxNotifications(criteria, options) {
|
|
1470
1317
|
const { signal } = _nullishCoalesce(options, () => ( {}));
|
|
1471
|
-
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1318
|
+
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _29 => _29.pageSize]), () => ( 50)), 10);
|
|
1472
1319
|
let cursor = void 0;
|
|
1473
1320
|
while (true) {
|
|
1474
1321
|
const { nextCursor, data } = await this.getInboxNotifications(
|
|
@@ -1792,7 +1639,7 @@ var Liveblocks = class {
|
|
|
1792
1639
|
async getGroups(params, options) {
|
|
1793
1640
|
const res = await this.#get(
|
|
1794
1641
|
_core.url`/v2/groups`,
|
|
1795
|
-
{ startingAfter: _optionalChain([params, 'optionalAccess',
|
|
1642
|
+
{ startingAfter: _optionalChain([params, 'optionalAccess', _30 => _30.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _31 => _31.limit]) },
|
|
1796
1643
|
options
|
|
1797
1644
|
);
|
|
1798
1645
|
if (!res.ok) {
|
|
@@ -1854,7 +1701,7 @@ var Liveblocks = class {
|
|
|
1854
1701
|
async massMutateStorage(criteria, callback, massOptions) {
|
|
1855
1702
|
const concurrency = _core.checkBounds.call(void 0,
|
|
1856
1703
|
"concurrency",
|
|
1857
|
-
_nullishCoalesce(_optionalChain([massOptions, 'optionalAccess',
|
|
1704
|
+
_nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _32 => _32.concurrency]), () => ( 8)),
|
|
1858
1705
|
1,
|
|
1859
1706
|
20
|
|
1860
1707
|
);
|
|
@@ -1870,7 +1717,7 @@ var Liveblocks = class {
|
|
|
1870
1717
|
}
|
|
1871
1718
|
async #_mutateOneRoom(roomId, room, callback, options) {
|
|
1872
1719
|
const debounceInterval = 200;
|
|
1873
|
-
const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess',
|
|
1720
|
+
const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _33 => _33.signal]));
|
|
1874
1721
|
let opsBuffer = [];
|
|
1875
1722
|
let outstandingFlush$ = void 0;
|
|
1876
1723
|
let lastFlush = performance.now();
|
|
@@ -1936,7 +1783,7 @@ var Liveblocks = class {
|
|
|
1936
1783
|
const res = await this.#post(
|
|
1937
1784
|
_core.url`/v2/rooms/${roomId}/send-message`,
|
|
1938
1785
|
{ messages },
|
|
1939
|
-
{ signal: _optionalChain([options, 'optionalAccess',
|
|
1786
|
+
{ signal: _optionalChain([options, 'optionalAccess', _34 => _34.signal]) }
|
|
1940
1787
|
);
|
|
1941
1788
|
if (!res.ok) {
|
|
1942
1789
|
throw await LiveblocksError.from(res);
|
|
@@ -2073,7 +1920,7 @@ var Liveblocks = class {
|
|
|
2073
1920
|
"Content-Type": params.file.type,
|
|
2074
1921
|
"Content-Length": String(params.file.size)
|
|
2075
1922
|
},
|
|
2076
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
1923
|
+
signal: _optionalChain([options, 'optionalAccess', _35 => _35.signal])
|
|
2077
1924
|
}
|
|
2078
1925
|
);
|
|
2079
1926
|
if (!res.ok) {
|