@liveblocks/core 0.19.0-beta0 → 0.19.1-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
@@ -50,15 +50,69 @@ var __async = (__this, __arguments, generator) => {
50
50
  });
51
51
  };
52
52
 
53
- // src/assert.ts
53
+ // src/lib/fancy-console.ts
54
+ var badge = "background:radial-gradient(106.94% 108.33% at -10% -5%,#ff1aa3 0,#ff881a 100%);border-radius:3px;color:#fff;padding:2px 5px;font-family:sans-serif;font-weight:600";
55
+ var bold = "font-weight:600";
56
+ function wrap(method) {
57
+ return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (message, ...args) => console[method]("%cLiveblocks", badge, message, ...args);
58
+ }
59
+ var warn = wrap("warn");
60
+ var error = wrap("error");
61
+ function wrapWithTitle(method) {
62
+ return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (title, message, ...args) => console[method](
63
+ `%cLiveblocks%c ${title}`,
64
+ badge,
65
+ bold,
66
+ message,
67
+ ...args
68
+ );
69
+ }
70
+ var errorWithTitle = wrapWithTitle("error");
71
+
72
+ // src/lib/deprecation.ts
73
+ var _emittedDeprecationWarnings = /* @__PURE__ */ new Set();
74
+ function deprecate(message, key = message) {
75
+ if (process.env.NODE_ENV !== "production") {
76
+ if (!_emittedDeprecationWarnings.has(key)) {
77
+ _emittedDeprecationWarnings.add(key);
78
+ errorWithTitle("Deprecation warning", message);
79
+ }
80
+ }
81
+ }
82
+ function deprecateIf(condition, message, key = message) {
83
+ if (process.env.NODE_ENV !== "production") {
84
+ if (condition) {
85
+ deprecate(message, key);
86
+ }
87
+ }
88
+ }
89
+ function throwUsageError(message) {
90
+ if (process.env.NODE_ENV !== "production") {
91
+ const usageError = new Error(message);
92
+ usageError.name = "Usage error";
93
+ errorWithTitle("Usage error", message);
94
+ throw usageError;
95
+ }
96
+ }
97
+ function errorIf(condition, message) {
98
+ if (process.env.NODE_ENV !== "production") {
99
+ if (condition) {
100
+ throwUsageError(message);
101
+ }
102
+ }
103
+ }
104
+
105
+ // src/lib/assert.ts
54
106
  function assertNever(_value, errmsg) {
55
107
  throw new Error(errmsg);
56
108
  }
57
109
  function assert(condition, errmsg) {
58
- if (process.env.NODE_ENV !== "production" && !condition) {
59
- const err = new Error(errmsg);
60
- err.name = "Assertion failure";
61
- throw err;
110
+ if (process.env.NODE_ENV !== "production") {
111
+ if (!condition) {
112
+ const err = new Error(errmsg);
113
+ err.name = "Assertion failure";
114
+ throw err;
115
+ }
62
116
  }
63
117
  }
64
118
  function nn(value, errmsg = "Expected value to be non-nullable") {
@@ -66,16 +120,7 @@ function nn(value, errmsg = "Expected value to be non-nullable") {
66
120
  return value;
67
121
  }
68
122
 
69
- // src/types/ClientMsg.ts
70
- var ClientMsgCode = /* @__PURE__ */ ((ClientMsgCode2) => {
71
- ClientMsgCode2[ClientMsgCode2["UPDATE_PRESENCE"] = 100] = "UPDATE_PRESENCE";
72
- ClientMsgCode2[ClientMsgCode2["BROADCAST_EVENT"] = 103] = "BROADCAST_EVENT";
73
- ClientMsgCode2[ClientMsgCode2["FETCH_STORAGE"] = 200] = "FETCH_STORAGE";
74
- ClientMsgCode2[ClientMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
75
- return ClientMsgCode2;
76
- })(ClientMsgCode || {});
77
-
78
- // src/types/Op.ts
123
+ // src/protocol/Op.ts
79
124
  var OpCode = /* @__PURE__ */ ((OpCode2) => {
80
125
  OpCode2[OpCode2["INIT"] = 0] = "INIT";
81
126
  OpCode2[OpCode2["SET_PARENT_KEY"] = 1] = "SET_PARENT_KEY";
@@ -89,50 +134,7 @@ var OpCode = /* @__PURE__ */ ((OpCode2) => {
89
134
  return OpCode2;
90
135
  })(OpCode || {});
91
136
 
92
- // src/types/SerializedCrdt.ts
93
- var CrdtType = /* @__PURE__ */ ((CrdtType2) => {
94
- CrdtType2[CrdtType2["OBJECT"] = 0] = "OBJECT";
95
- CrdtType2[CrdtType2["LIST"] = 1] = "LIST";
96
- CrdtType2[CrdtType2["MAP"] = 2] = "MAP";
97
- CrdtType2[CrdtType2["REGISTER"] = 3] = "REGISTER";
98
- return CrdtType2;
99
- })(CrdtType || {});
100
- function isRootCrdt(crdt) {
101
- return crdt.type === 0 /* OBJECT */ && !isChildCrdt(crdt);
102
- }
103
- function isChildCrdt(crdt) {
104
- return crdt.parentId !== void 0 && crdt.parentKey !== void 0;
105
- }
106
-
107
- // src/types/ServerMsg.ts
108
- var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
109
- ServerMsgCode2[ServerMsgCode2["UPDATE_PRESENCE"] = 100] = "UPDATE_PRESENCE";
110
- ServerMsgCode2[ServerMsgCode2["USER_JOINED"] = 101] = "USER_JOINED";
111
- ServerMsgCode2[ServerMsgCode2["USER_LEFT"] = 102] = "USER_LEFT";
112
- ServerMsgCode2[ServerMsgCode2["BROADCASTED_EVENT"] = 103] = "BROADCASTED_EVENT";
113
- ServerMsgCode2[ServerMsgCode2["ROOM_STATE"] = 104] = "ROOM_STATE";
114
- ServerMsgCode2[ServerMsgCode2["INITIAL_STORAGE_STATE"] = 200] = "INITIAL_STORAGE_STATE";
115
- ServerMsgCode2[ServerMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
116
- return ServerMsgCode2;
117
- })(ServerMsgCode || {});
118
-
119
- // src/types/index.ts
120
- function isRoomEventName(value) {
121
- return value === "my-presence" || value === "others" || value === "event" || value === "error" || value === "connection" || value === "history";
122
- }
123
- var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
124
- WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_ABNORMAL"] = 1006] = "CLOSE_ABNORMAL";
125
- WebsocketCloseCodes2[WebsocketCloseCodes2["INVALID_MESSAGE_FORMAT"] = 4e3] = "INVALID_MESSAGE_FORMAT";
126
- WebsocketCloseCodes2[WebsocketCloseCodes2["NOT_ALLOWED"] = 4001] = "NOT_ALLOWED";
127
- WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_SECONDS"] = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS";
128
- WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
129
- WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
130
- WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
131
- WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
132
- return WebsocketCloseCodes2;
133
- })(WebsocketCloseCodes || {});
134
-
135
- // src/AbstractCrdt.ts
137
+ // src/crdts/AbstractCrdt.ts
136
138
  function crdtAsLiveNode(value) {
137
139
  return value;
138
140
  }
@@ -270,63 +272,72 @@ var AbstractCrdt = class {
270
272
  }
271
273
  };
272
274
 
273
- // src/LiveRegister.ts
274
- var LiveRegister = class extends AbstractCrdt {
275
- constructor(data) {
276
- super();
277
- this._data = data;
278
- }
279
- get data() {
280
- return this._data;
275
+ // src/lib/utils.ts
276
+ function isPlainObject(blob) {
277
+ return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
278
+ }
279
+ function fromEntries(iterable) {
280
+ const obj = {};
281
+ for (const [key, val] of iterable) {
282
+ obj[key] = val;
281
283
  }
282
- static _deserialize([id, item], _parentToChildren, pool) {
283
- const register = new LiveRegister(item.data);
284
- register._attach(id, pool);
285
- return register;
284
+ return obj;
285
+ }
286
+ function entries(obj) {
287
+ return Object.entries(obj);
288
+ }
289
+ function tryParseJson(rawMessage) {
290
+ try {
291
+ return JSON.parse(rawMessage);
292
+ } catch (e) {
293
+ return void 0;
286
294
  }
287
- _toOps(parentId, parentKey, pool) {
288
- if (this._id === void 0) {
289
- throw new Error(
290
- "Cannot serialize register if parentId or parentKey is undefined"
291
- );
292
- }
293
- return [
294
- {
295
- type: 8 /* CREATE_REGISTER */,
296
- opId: pool == null ? void 0 : pool.generateOpId(),
297
- id: this._id,
298
- parentId,
299
- parentKey,
300
- data: this.data
301
- }
302
- ];
295
+ }
296
+ function b64decode(b64value) {
297
+ try {
298
+ const formattedValue = b64value.replace(/-/g, "+").replace(/_/g, "/");
299
+ const decodedValue = decodeURIComponent(
300
+ atob(formattedValue).split("").map(function(c) {
301
+ return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
302
+ }).join("")
303
+ );
304
+ return decodedValue;
305
+ } catch (err) {
306
+ return atob(b64value);
303
307
  }
304
- _serialize() {
305
- if (this.parent.type !== "HasParent") {
306
- throw new Error("Cannot serialize LiveRegister if parent is missing");
308
+ }
309
+ function compact(items) {
310
+ return items.filter(
311
+ (item) => item !== null && item !== void 0
312
+ );
313
+ }
314
+ function compactObject(obj) {
315
+ const newObj = __spreadValues({}, obj);
316
+ Object.keys(obj).forEach((k) => {
317
+ const key = k;
318
+ if (newObj[key] === void 0) {
319
+ delete newObj[key];
307
320
  }
308
- return {
309
- type: 3 /* REGISTER */,
310
- parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
311
- parentKey: this.parent.key,
312
- data: this.data
313
- };
314
- }
315
- _attachChild(_op) {
316
- throw new Error("Method not implemented.");
317
- }
318
- _detachChild(_crdt) {
319
- throw new Error("Method not implemented.");
320
- }
321
- _apply(op, isLocal) {
322
- return super._apply(op, isLocal);
323
- }
324
- _toImmutable() {
325
- return this._data;
326
- }
327
- };
321
+ });
322
+ return newObj;
323
+ }
328
324
 
329
- // src/position.ts
325
+ // src/protocol/SerializedCrdt.ts
326
+ var CrdtType = /* @__PURE__ */ ((CrdtType2) => {
327
+ CrdtType2[CrdtType2["OBJECT"] = 0] = "OBJECT";
328
+ CrdtType2[CrdtType2["LIST"] = 1] = "LIST";
329
+ CrdtType2[CrdtType2["MAP"] = 2] = "MAP";
330
+ CrdtType2[CrdtType2["REGISTER"] = 3] = "REGISTER";
331
+ return CrdtType2;
332
+ })(CrdtType || {});
333
+ function isRootCrdt(crdt) {
334
+ return crdt.type === 0 /* OBJECT */ && !isChildCrdt(crdt);
335
+ }
336
+ function isChildCrdt(crdt) {
337
+ return crdt.parentId !== void 0 && crdt.parentKey !== void 0;
338
+ }
339
+
340
+ // src/lib/position.ts
330
341
  var min = 32;
331
342
  var max = 126;
332
343
  function makePosition(before, after) {
@@ -430,7 +441,63 @@ function comparePosition(posA, posB) {
430
441
  );
431
442
  }
432
443
 
433
- // src/LiveList.ts
444
+ // src/crdts/LiveRegister.ts
445
+ var LiveRegister = class extends AbstractCrdt {
446
+ constructor(data) {
447
+ super();
448
+ this._data = data;
449
+ }
450
+ get data() {
451
+ return this._data;
452
+ }
453
+ static _deserialize([id, item], _parentToChildren, pool) {
454
+ const register = new LiveRegister(item.data);
455
+ register._attach(id, pool);
456
+ return register;
457
+ }
458
+ _toOps(parentId, parentKey, pool) {
459
+ if (this._id === void 0) {
460
+ throw new Error(
461
+ "Cannot serialize register if parentId or parentKey is undefined"
462
+ );
463
+ }
464
+ return [
465
+ {
466
+ type: 8 /* CREATE_REGISTER */,
467
+ opId: pool == null ? void 0 : pool.generateOpId(),
468
+ id: this._id,
469
+ parentId,
470
+ parentKey,
471
+ data: this.data
472
+ }
473
+ ];
474
+ }
475
+ _serialize() {
476
+ if (this.parent.type !== "HasParent") {
477
+ throw new Error("Cannot serialize LiveRegister if parent is missing");
478
+ }
479
+ return {
480
+ type: 3 /* REGISTER */,
481
+ parentId: nn(this.parent.node._id, "Parent node expected to have ID"),
482
+ parentKey: this.parent.key,
483
+ data: this.data
484
+ };
485
+ }
486
+ _attachChild(_op) {
487
+ throw new Error("Method not implemented.");
488
+ }
489
+ _detachChild(_crdt) {
490
+ throw new Error("Method not implemented.");
491
+ }
492
+ _apply(op, isLocal) {
493
+ return super._apply(op, isLocal);
494
+ }
495
+ _toImmutable() {
496
+ return this._data;
497
+ }
498
+ };
499
+
500
+ // src/crdts/LiveList.ts
434
501
  function compareNodePosition(itemA, itemB) {
435
502
  return comparePosition(
436
503
  itemA._getParentKeyOrThrow(),
@@ -1315,7 +1382,10 @@ function addIntentAndDeletedIdToOperation(ops, deletedId) {
1315
1382
  firstOp.deletedId = deletedId;
1316
1383
  }
1317
1384
 
1318
- // src/LiveMap.ts
1385
+ // src/lib/freeze.ts
1386
+ var freeze = process.env.NODE_ENV === "production" ? (x) => x : Object.freeze;
1387
+
1388
+ // src/crdts/LiveMap.ts
1319
1389
  var LiveMap = class extends AbstractCrdt {
1320
1390
  constructor(entries2) {
1321
1391
  super();
@@ -1589,7 +1659,7 @@ var LiveMap = class extends AbstractCrdt {
1589
1659
  }
1590
1660
  };
1591
1661
 
1592
- // src/LiveObject.ts
1662
+ // src/crdts/LiveObject.ts
1593
1663
  var LiveObject = class extends AbstractCrdt {
1594
1664
  constructor(obj = {}) {
1595
1665
  super();
@@ -2017,23 +2087,7 @@ var LiveObject = class extends AbstractCrdt {
2017
2087
  }
2018
2088
  };
2019
2089
 
2020
- // src/utils.ts
2021
- var freeze = process.env.NODE_ENV === "production" ? (x) => x : Object.freeze;
2022
- function compact(items) {
2023
- return items.filter(
2024
- (item) => item !== null && item !== void 0
2025
- );
2026
- }
2027
- function compactObject(obj) {
2028
- const newObj = __spreadValues({}, obj);
2029
- Object.keys(obj).forEach((k) => {
2030
- const key = k;
2031
- if (newObj[key] === void 0) {
2032
- delete newObj[key];
2033
- }
2034
- });
2035
- return newObj;
2036
- }
2090
+ // src/crdts/liveblocks-helpers.ts
2037
2091
  function creationOpToLiveNode(op) {
2038
2092
  return lsonToLiveNode(creationOpToLson(op));
2039
2093
  }
@@ -2246,9 +2300,6 @@ function isPlain(value) {
2246
2300
  const type = typeof value;
2247
2301
  return value === void 0 || value === null || type === "string" || type === "boolean" || type === "number" || Array.isArray(value) || isPlainObject(value);
2248
2302
  }
2249
- function isPlainObject(blob) {
2250
- return blob !== null && typeof blob === "object" && Object.prototype.toString.call(blob) === "[object Object]";
2251
- }
2252
2303
  function findNonSerializableValue(value, path = "") {
2253
2304
  if (!isPlain) {
2254
2305
  return {
@@ -2279,38 +2330,52 @@ function findNonSerializableValue(value, path = "") {
2279
2330
  }
2280
2331
  return false;
2281
2332
  }
2282
- function fromEntries(iterable) {
2283
- const obj = {};
2284
- for (const [key, val] of iterable) {
2285
- obj[key] = val;
2333
+
2334
+ // src/lib/EventSource.ts
2335
+ function makeEventSource() {
2336
+ const _onetimeObservers = /* @__PURE__ */ new Set();
2337
+ const _observers = /* @__PURE__ */ new Set();
2338
+ function subscribe(callback) {
2339
+ _observers.add(callback);
2340
+ return () => _observers.delete(callback);
2286
2341
  }
2287
- return obj;
2342
+ function subscribeOnce(callback) {
2343
+ _onetimeObservers.add(callback);
2344
+ return () => _onetimeObservers.delete(callback);
2345
+ }
2346
+ function notify(event) {
2347
+ _onetimeObservers.forEach((callback) => callback(event));
2348
+ _onetimeObservers.clear();
2349
+ _observers.forEach((callback) => callback(event));
2350
+ }
2351
+ function clear() {
2352
+ _onetimeObservers.clear();
2353
+ _observers.clear();
2354
+ }
2355
+ return {
2356
+ notify,
2357
+ subscribe,
2358
+ subscribeOnce,
2359
+ clear,
2360
+ observable: {
2361
+ subscribe,
2362
+ subscribeOnce
2363
+ }
2364
+ };
2288
2365
  }
2289
- function entries(obj) {
2290
- return Object.entries(obj);
2366
+
2367
+ // src/lib/Json.ts
2368
+ function isJsonScalar(data) {
2369
+ return data === null || typeof data === "string" || typeof data === "number" || typeof data === "boolean";
2291
2370
  }
2292
- function tryParseJson(rawMessage) {
2293
- try {
2294
- return JSON.parse(rawMessage);
2295
- } catch (e) {
2296
- return void 0;
2297
- }
2371
+ function isJsonArray(data) {
2372
+ return Array.isArray(data);
2298
2373
  }
2299
- function b64decode(b64value) {
2300
- try {
2301
- const formattedValue = b64value.replace(/-/g, "+").replace(/_/g, "/");
2302
- const decodedValue = decodeURIComponent(
2303
- atob(formattedValue).split("").map(function(c) {
2304
- return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
2305
- }).join("")
2306
- );
2307
- return decodedValue;
2308
- } catch (err) {
2309
- return atob(b64value);
2310
- }
2374
+ function isJsonObject(data) {
2375
+ return !isJsonScalar(data) && !isJsonArray(data);
2311
2376
  }
2312
2377
 
2313
- // src/AuthToken.ts
2378
+ // src/protocol/AuthToken.ts
2314
2379
  function hasJwtMeta(data) {
2315
2380
  if (!isPlainObject(data)) {
2316
2381
  return false;
@@ -2362,92 +2427,28 @@ function parseRoomAuthToken(tokenString) {
2362
2427
  }
2363
2428
  }
2364
2429
 
2365
- // src/fancy-console.ts
2366
- var badge = "background:radial-gradient(106.94% 108.33% at -10% -5%,#ff1aa3 0,#ff881a 100%);border-radius:3px;color:#fff;padding:2px 5px;font-family:sans-serif;font-weight:600";
2367
- var bold = "font-weight:600";
2368
- function wrap(method) {
2369
- return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (message, ...args) => console[method]("%cLiveblocks", badge, message, ...args);
2370
- }
2371
- var warn = wrap("warn");
2372
- var error = wrap("error");
2373
- function wrapWithTitle(method) {
2374
- return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (title, message, ...args) => console[method](
2375
- `%cLiveblocks%c ${title}`,
2376
- badge,
2377
- bold,
2378
- message,
2379
- ...args
2380
- );
2381
- }
2382
- var errorWithTitle = wrapWithTitle("error");
2383
-
2384
- // src/deprecation.ts
2385
- var _emittedDeprecationWarnings = /* @__PURE__ */ new Set();
2386
- function deprecate(message, key = message) {
2387
- if (process.env.NODE_ENV !== "production") {
2388
- if (!_emittedDeprecationWarnings.has(key)) {
2389
- _emittedDeprecationWarnings.add(key);
2390
- errorWithTitle("Deprecation warning", message);
2391
- }
2392
- }
2393
- }
2394
- function deprecateIf(condition, message, key = message) {
2395
- if (process.env.NODE_ENV !== "production") {
2396
- if (condition) {
2397
- deprecate(message, key);
2398
- }
2399
- }
2400
- }
2401
- function throwUsageError(message) {
2402
- if (process.env.NODE_ENV !== "production") {
2403
- const usageError = new Error(message);
2404
- usageError.name = "Usage error";
2405
- errorWithTitle("Usage error", message);
2406
- throw usageError;
2407
- }
2408
- }
2409
- function errorIf(condition, message) {
2410
- if (process.env.NODE_ENV !== "production") {
2411
- if (condition) {
2412
- throwUsageError(message);
2413
- }
2414
- }
2415
- }
2430
+ // src/protocol/ClientMsg.ts
2431
+ var ClientMsgCode = /* @__PURE__ */ ((ClientMsgCode2) => {
2432
+ ClientMsgCode2[ClientMsgCode2["UPDATE_PRESENCE"] = 100] = "UPDATE_PRESENCE";
2433
+ ClientMsgCode2[ClientMsgCode2["BROADCAST_EVENT"] = 103] = "BROADCAST_EVENT";
2434
+ ClientMsgCode2[ClientMsgCode2["FETCH_STORAGE"] = 200] = "FETCH_STORAGE";
2435
+ ClientMsgCode2[ClientMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
2436
+ return ClientMsgCode2;
2437
+ })(ClientMsgCode || {});
2416
2438
 
2417
- // src/EventSource.ts
2418
- function makeEventSource() {
2419
- const _onetimeObservers = /* @__PURE__ */ new Set();
2420
- const _observers = /* @__PURE__ */ new Set();
2421
- function subscribe(callback) {
2422
- _observers.add(callback);
2423
- return () => _observers.delete(callback);
2424
- }
2425
- function subscribeOnce(callback) {
2426
- _onetimeObservers.add(callback);
2427
- return () => _onetimeObservers.delete(callback);
2428
- }
2429
- function notify(event) {
2430
- _onetimeObservers.forEach((callback) => callback(event));
2431
- _onetimeObservers.clear();
2432
- _observers.forEach((callback) => callback(event));
2433
- }
2434
- function clear() {
2435
- _onetimeObservers.clear();
2436
- _observers.clear();
2437
- }
2438
- return {
2439
- notify,
2440
- subscribe,
2441
- subscribeOnce,
2442
- clear,
2443
- observable: {
2444
- subscribe,
2445
- subscribeOnce
2446
- }
2447
- };
2448
- }
2439
+ // src/protocol/ServerMsg.ts
2440
+ var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
2441
+ ServerMsgCode2[ServerMsgCode2["UPDATE_PRESENCE"] = 100] = "UPDATE_PRESENCE";
2442
+ ServerMsgCode2[ServerMsgCode2["USER_JOINED"] = 101] = "USER_JOINED";
2443
+ ServerMsgCode2[ServerMsgCode2["USER_LEFT"] = 102] = "USER_LEFT";
2444
+ ServerMsgCode2[ServerMsgCode2["BROADCASTED_EVENT"] = 103] = "BROADCASTED_EVENT";
2445
+ ServerMsgCode2[ServerMsgCode2["ROOM_STATE"] = 104] = "ROOM_STATE";
2446
+ ServerMsgCode2[ServerMsgCode2["INITIAL_STORAGE_STATE"] = 200] = "INITIAL_STORAGE_STATE";
2447
+ ServerMsgCode2[ServerMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
2448
+ return ServerMsgCode2;
2449
+ })(ServerMsgCode || {});
2449
2450
 
2450
- // src/ImmutableRef.ts
2451
+ // src/refs/ImmutableRef.ts
2451
2452
  function merge(target, patch) {
2452
2453
  let updated = false;
2453
2454
  const newValue = __spreadValues({}, target);
@@ -2484,7 +2485,7 @@ var ImmutableRef = class {
2484
2485
  }
2485
2486
  };
2486
2487
 
2487
- // src/MeRef.ts
2488
+ // src/refs/MeRef.ts
2488
2489
  var MeRef = class extends ImmutableRef {
2489
2490
  constructor(initialPresence) {
2490
2491
  super();
@@ -2503,7 +2504,7 @@ var MeRef = class extends ImmutableRef {
2503
2504
  }
2504
2505
  };
2505
2506
 
2506
- // src/LegacyArray.ts
2507
+ // src/lib/LegacyArray.ts
2507
2508
  function asArrayWithLegacyMethods(arr) {
2508
2509
  Object.defineProperty(arr, "count", {
2509
2510
  value: arr.length,
@@ -2516,7 +2517,7 @@ function asArrayWithLegacyMethods(arr) {
2516
2517
  return freeze(arr);
2517
2518
  }
2518
2519
 
2519
- // src/OthersRef.ts
2520
+ // src/refs/OthersRef.ts
2520
2521
  function makeUser(conn, presence) {
2521
2522
  return freeze(compactObject(__spreadProps(__spreadValues({}, conn), { presence })));
2522
2523
  }
@@ -2602,22 +2603,11 @@ var OthersRef = class extends ImmutableRef {
2602
2603
  }
2603
2604
  };
2604
2605
 
2605
- // src/types/Json.ts
2606
- function isJsonScalar(data) {
2607
- return data === null || typeof data === "string" || typeof data === "number" || typeof data === "boolean";
2608
- }
2609
- function isJsonArray(data) {
2610
- return Array.isArray(data);
2611
- }
2612
- function isJsonObject(data) {
2613
- return !isJsonScalar(data) && !isJsonArray(data);
2614
- }
2615
-
2616
- // src/ValueRef.ts
2606
+ // src/refs/ValueRef.ts
2617
2607
  var ValueRef = class extends ImmutableRef {
2618
2608
  constructor(initialValue) {
2619
2609
  super();
2620
- this._value = freeze(compactObject(initialValue));
2610
+ this._value = freeze(initialValue);
2621
2611
  }
2622
2612
  _toImmutable() {
2623
2613
  return this._value;
@@ -2628,8 +2618,10 @@ var ValueRef = class extends ImmutableRef {
2628
2618
  }
2629
2619
  };
2630
2620
  var DerivedRef = class extends ImmutableRef {
2631
- constructor(otherRefs, transformFn) {
2621
+ constructor(...args) {
2632
2622
  super();
2623
+ const transformFn = args.pop();
2624
+ const otherRefs = args;
2633
2625
  this._refs = otherRefs;
2634
2626
  this._refs.forEach((ref) => {
2635
2627
  ref.didInvalidate.subscribe(() => this.invalidate());
@@ -2637,11 +2629,29 @@ var DerivedRef = class extends ImmutableRef {
2637
2629
  this._transform = transformFn;
2638
2630
  }
2639
2631
  _toImmutable() {
2640
- return this._transform(this._refs[0].current, this._refs[1].current);
2632
+ return this._transform(
2633
+ ...this._refs.map((ref) => ref.current)
2634
+ );
2641
2635
  }
2642
2636
  };
2643
2637
 
2638
+ // src/types/WebsocketCloseCodes.ts
2639
+ var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
2640
+ WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_ABNORMAL"] = 1006] = "CLOSE_ABNORMAL";
2641
+ WebsocketCloseCodes2[WebsocketCloseCodes2["INVALID_MESSAGE_FORMAT"] = 4e3] = "INVALID_MESSAGE_FORMAT";
2642
+ WebsocketCloseCodes2[WebsocketCloseCodes2["NOT_ALLOWED"] = 4001] = "NOT_ALLOWED";
2643
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_SECONDS"] = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS";
2644
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
2645
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
2646
+ WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
2647
+ WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
2648
+ return WebsocketCloseCodes2;
2649
+ })(WebsocketCloseCodes || {});
2650
+
2644
2651
  // src/room.ts
2652
+ function isRoomEventName(value) {
2653
+ return value === "my-presence" || value === "others" || value === "event" || value === "error" || value === "connection" || value === "history";
2654
+ }
2645
2655
  var BACKOFF_RETRY_DELAYS = [250, 500, 1e3, 2e3, 4e3, 8e3, 1e4];
2646
2656
  var BACKOFF_RETRY_DELAYS_SLOW = [2e3, 3e4, 6e4, 3e5];
2647
2657
  var HEARTBEAT_INTERVAL = 3e4;
@@ -2752,7 +2762,8 @@ function makeStateMachine(state, config, mockedEffects) {
2752
2762
  }
2753
2763
  };
2754
2764
  const self = new DerivedRef(
2755
- [state.connection, state.me],
2765
+ state.connection,
2766
+ state.me,
2756
2767
  (conn, me) => isConnectionSelfAware(conn) ? {
2757
2768
  connectionId: conn.id,
2758
2769
  id: conn.userId,
@@ -3265,7 +3276,9 @@ function makeStateMachine(state, config, mockedEffects) {
3265
3276
  const offlineOps = new Map(state.offlineOperations);
3266
3277
  createOrUpdateRootFromMessage(message, doNotBatchUpdates);
3267
3278
  applyAndSendOfflineOps(offlineOps, doNotBatchUpdates);
3268
- _getInitialStateResolver == null ? void 0 : _getInitialStateResolver();
3279
+ if (_getInitialStateResolver !== null) {
3280
+ _getInitialStateResolver();
3281
+ }
3269
3282
  eventHub.storageDidLoad.notify();
3270
3283
  break;
3271
3284
  }
@@ -3793,7 +3806,7 @@ function prepareCreateWebSocket(liveblocksServer, WebSocketPolyfill) {
3793
3806
  const ws = WebSocketPolyfill || WebSocket;
3794
3807
  return (token) => {
3795
3808
  return new ws(
3796
- `${liveblocksServer}/?token=${token}&version=${true ? "0.19.0-beta0" : "dev"}`
3809
+ `${liveblocksServer}/?token=${token}&version=${true ? "0.19.1-test1" : "dev"}`
3797
3810
  );
3798
3811
  };
3799
3812
  }
@@ -3804,10 +3817,14 @@ function prepareAuthEndpoint(authentication, fetchPolyfill) {
3804
3817
  "To use Liveblocks client in a non-dom environment with a publicApiKey, you need to provide a fetch polyfill."
3805
3818
  );
3806
3819
  }
3807
- return (room) => fetchAuthEndpoint(fetchPolyfill || fetch, authentication.url, {
3808
- room,
3809
- publicApiKey: authentication.publicApiKey
3810
- });
3820
+ return (room) => fetchAuthEndpoint(
3821
+ fetchPolyfill || fetch,
3822
+ authentication.url,
3823
+ {
3824
+ room,
3825
+ publicApiKey: authentication.publicApiKey
3826
+ }
3827
+ );
3811
3828
  }
3812
3829
  if (authentication.type === "private") {
3813
3830
  if (typeof window === "undefined" && fetchPolyfill === void 0) {
@@ -4311,7 +4328,7 @@ function legacy_patchImmutableNode(state, path, update) {
4311
4328
  }
4312
4329
  }
4313
4330
 
4314
- // src/shallow.ts
4331
+ // src/lib/shallow.ts
4315
4332
  function shallowArray(xs, ys) {
4316
4333
  if (xs.length !== ys.length) {
4317
4334
  return false;