@liveblocks/server 1.0.1 → 1.0.2

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
@@ -8,751 +8,9 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
8
8
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
9
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
-
13
- // ../../node_modules/@liveblocks/core/dist/index.js
14
- var __defProp2 = Object.defineProperty;
15
- var __export = (target, all) => {
16
- for (var name in all)
17
- __defProp2(target, name, { get: all[name], enumerable: true });
18
- };
19
- var PKG_NAME = "@liveblocks/core";
20
- var PKG_VERSION = "3.14.0-pre5";
21
- var PKG_FORMAT = "esm";
22
- var g = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
23
- var crossLinkedDocs = "https://liveblocks.io/docs/errors/cross-linked";
24
- var dupesDocs = "https://liveblocks.io/docs/errors/dupes";
25
- var SPACE = " ";
26
- function error(msg) {
27
- if (process.env.NODE_ENV === "production") {
28
- console.error(msg);
29
- } else {
30
- throw new Error(msg);
31
- }
32
- }
33
- function detectDupes(pkgName, pkgVersion, pkgFormat) {
34
- const pkgId = Symbol.for(pkgName);
35
- const pkgBuildInfo = pkgFormat ? `${pkgVersion || "dev"} (${pkgFormat})` : pkgVersion || "dev";
36
- if (!g[pkgId]) {
37
- g[pkgId] = pkgBuildInfo;
38
- } else if (g[pkgId] === pkgBuildInfo) {
39
- } else {
40
- const msg = [
41
- `Multiple copies of Liveblocks are being loaded in your project. This will cause issues! See ${dupesDocs + SPACE}`,
42
- "",
43
- "Conflicts:",
44
- `- ${pkgName} ${g[pkgId]} (already loaded)`,
45
- `- ${pkgName} ${pkgBuildInfo} (trying to load this now)`
46
- ].join("\n");
47
- error(msg);
48
- }
49
- if (pkgVersion && PKG_VERSION && pkgVersion !== PKG_VERSION) {
50
- error(
51
- [
52
- `Cross-linked versions of Liveblocks found, which will cause issues! See ${crossLinkedDocs + SPACE}`,
53
- "",
54
- "Conflicts:",
55
- `- ${PKG_NAME} is at ${PKG_VERSION}`,
56
- `- ${pkgName} is at ${pkgVersion}`,
57
- "",
58
- "Always upgrade all Liveblocks packages to the same version number."
59
- ].join("\n")
60
- );
61
- }
62
- }
63
- function makeEventSource() {
64
- const _observers = /* @__PURE__ */ new Set();
65
- function subscribe(callback) {
66
- _observers.add(callback);
67
- return () => _observers.delete(callback);
68
- }
69
- function subscribeOnce(callback) {
70
- const unsub = subscribe((event) => {
71
- unsub();
72
- return callback(event);
73
- });
74
- return unsub;
75
- }
76
- async function waitUntil(predicate) {
77
- let unsub;
78
- return new Promise((res) => {
79
- unsub = subscribe((event) => {
80
- if (predicate === void 0 || predicate(event)) {
81
- res(event);
82
- }
83
- });
84
- }).finally(() => unsub?.());
85
- }
86
- function notify(event) {
87
- let called = false;
88
- for (const callback of _observers) {
89
- callback(event);
90
- called = true;
91
- }
92
- return called;
93
- }
94
- function count() {
95
- return _observers.size;
96
- }
97
- return {
98
- // Private/internal control over event emission
99
- notify,
100
- subscribe,
101
- subscribeOnce,
102
- count,
103
- waitUntil,
104
- dispose() {
105
- _observers.clear();
106
- },
107
- // Publicly exposable subscription API
108
- observable: {
109
- subscribe,
110
- subscribeOnce,
111
- waitUntil
112
- }
113
- };
114
- }
115
- var freeze = process.env.NODE_ENV === "production" ? (
116
- /* istanbul ignore next */
117
- (x) => x
118
- ) : Object.freeze;
119
- function raise(msg) {
120
- throw new Error(msg);
121
- }
122
- function tryParseJson(rawMessage) {
123
- try {
124
- return JSON.parse(rawMessage);
125
- } catch (e) {
126
- return void 0;
127
- }
128
- }
129
- var kSinks = Symbol("kSinks");
130
- var kTrigger = Symbol("kTrigger");
131
- var signalsToTrigger = null;
132
- var trackedReads = null;
133
- function enqueueTrigger(signal) {
134
- if (!signalsToTrigger) raise("Expected to be in an active batch");
135
- signalsToTrigger.add(signal);
136
- }
137
- var _a, _eventSource, _b;
138
- var AbstractSignal = (_b = class {
139
- constructor(equals) {
140
- /** @internal */
141
- __publicField(this, "equals");
142
- __privateAdd(this, _eventSource);
143
- /** @internal */
144
- __publicField(this, _a);
145
- this.equals = equals ?? Object.is;
146
- __privateSet(this, _eventSource, makeEventSource());
147
- this[kSinks] = /* @__PURE__ */ new Set();
148
- this.get = this.get.bind(this);
149
- this.subscribe = this.subscribe.bind(this);
150
- this.subscribeOnce = this.subscribeOnce.bind(this);
151
- }
152
- dispose() {
153
- __privateGet(this, _eventSource).dispose();
154
- __privateSet(this, _eventSource, "(disposed)");
155
- this.equals = "(disposed)";
156
- }
157
- get hasWatchers() {
158
- if (__privateGet(this, _eventSource).count() > 0) return true;
159
- for (const sink of this[kSinks]) {
160
- if (sink.hasWatchers) {
161
- return true;
162
- }
163
- }
164
- return false;
165
- }
166
- [(_a = kSinks, kTrigger)]() {
167
- __privateGet(this, _eventSource).notify();
168
- for (const sink of this[kSinks]) {
169
- enqueueTrigger(sink);
170
- }
171
- }
172
- subscribe(callback) {
173
- if (__privateGet(this, _eventSource).count() === 0) {
174
- this.get();
175
- }
176
- return __privateGet(this, _eventSource).subscribe(callback);
177
- }
178
- subscribeOnce(callback) {
179
- const unsub = this.subscribe(() => {
180
- unsub();
181
- return callback();
182
- });
183
- return unsub;
184
- }
185
- waitUntil() {
186
- throw new Error("waitUntil not supported on Signals");
187
- }
188
- markSinksDirty() {
189
- for (const sink of this[kSinks]) {
190
- sink.markDirty();
191
- }
192
- }
193
- addSink(sink) {
194
- this[kSinks].add(sink);
195
- }
196
- removeSink(sink) {
197
- this[kSinks].delete(sink);
198
- }
199
- asReadonly() {
200
- return this;
201
- }
202
- }, _eventSource = new WeakMap(), _b);
203
- var INITIAL = Symbol();
204
- var _prevValue, _dirty, _sources, _deps, _transform, __DerivedSignal_instances, recompute_fn, _a2;
205
- var DerivedSignal = (_a2 = class extends AbstractSignal {
206
- constructor(deps, transform, equals) {
207
- super(equals);
208
- __privateAdd(this, __DerivedSignal_instances);
209
- __privateAdd(this, _prevValue);
210
- __privateAdd(this, _dirty);
211
- // When true, the value in #value may not be up-to-date and needs re-checking
212
- __privateAdd(this, _sources);
213
- __privateAdd(this, _deps);
214
- __privateAdd(this, _transform);
215
- __privateSet(this, _dirty, true);
216
- __privateSet(this, _prevValue, INITIAL);
217
- __privateSet(this, _deps, deps);
218
- __privateSet(this, _sources, /* @__PURE__ */ new Set());
219
- __privateSet(this, _transform, transform);
220
- }
221
- // prettier-ignore
222
- static from(...args) {
223
- const last = args.pop();
224
- if (typeof last !== "function")
225
- raise("Invalid .from() call, last argument expected to be a function");
226
- if (typeof args[args.length - 1] === "function") {
227
- const equals = last;
228
- const transform = args.pop();
229
- return new _a2(args, transform, equals);
230
- } else {
231
- const transform = last;
232
- return new _a2(args, transform);
233
- }
234
- }
235
- dispose() {
236
- for (const src of __privateGet(this, _sources)) {
237
- src.removeSink(this);
238
- }
239
- __privateSet(this, _prevValue, "(disposed)");
240
- __privateSet(this, _sources, "(disposed)");
241
- __privateSet(this, _deps, "(disposed)");
242
- __privateSet(this, _transform, "(disposed)");
243
- }
244
- get isDirty() {
245
- return __privateGet(this, _dirty);
246
- }
247
- markDirty() {
248
- if (!__privateGet(this, _dirty)) {
249
- __privateSet(this, _dirty, true);
250
- this.markSinksDirty();
251
- }
252
- }
253
- get() {
254
- if (__privateGet(this, _dirty)) {
255
- __privateMethod(this, __DerivedSignal_instances, recompute_fn).call(this);
256
- }
257
- trackedReads?.add(this);
258
- return __privateGet(this, _prevValue);
259
- }
260
- /**
261
- * Called by the Signal system if one or more of the dependent signals have
262
- * changed. In the case of a DerivedSignal, we'll only want to re-evaluate
263
- * the actual value if it's being watched, or any of their sinks are being
264
- * watched actively.
265
- */
266
- [kTrigger]() {
267
- if (!this.hasWatchers) {
268
- return;
269
- }
270
- const updated = __privateMethod(this, __DerivedSignal_instances, recompute_fn).call(this);
271
- if (updated) {
272
- super[kTrigger]();
273
- }
274
- }
275
- }, _prevValue = new WeakMap(), _dirty = new WeakMap(), _sources = new WeakMap(), _deps = new WeakMap(), _transform = new WeakMap(), __DerivedSignal_instances = new WeakSet(), recompute_fn = function() {
276
- const oldTrackedReads = trackedReads;
277
- let derived;
278
- trackedReads = /* @__PURE__ */ new Set();
279
- try {
280
- derived = __privateGet(this, _transform).call(this, ...__privateGet(this, _deps).map((p) => p.get()));
281
- } finally {
282
- const oldSources = __privateGet(this, _sources);
283
- __privateSet(this, _sources, /* @__PURE__ */ new Set());
284
- for (const sig of trackedReads) {
285
- __privateGet(this, _sources).add(sig);
286
- oldSources.delete(sig);
287
- }
288
- for (const oldSource of oldSources) {
289
- oldSource.removeSink(this);
290
- }
291
- for (const newSource of __privateGet(this, _sources)) {
292
- newSource.addSink(this);
293
- }
294
- trackedReads = oldTrackedReads;
295
- }
296
- __privateSet(this, _dirty, false);
297
- if (!this.equals(__privateGet(this, _prevValue), derived)) {
298
- __privateSet(this, _prevValue, derived);
299
- return true;
300
- }
301
- return false;
302
- }, _a2);
303
- function assertNever(_value, errmsg) {
304
- throw new Error(errmsg);
305
- }
306
- function assert(condition, errmsg) {
307
- if (process.env.NODE_ENV !== "production") {
308
- if (!condition) {
309
- const err = new Error(errmsg);
310
- err.name = "Assertion failure";
311
- throw err;
312
- }
313
- }
314
- }
315
- function nn(value, errmsg = "Expected value to be non-nullable") {
316
- assert(value !== null && value !== void 0, errmsg);
317
- return value;
318
- }
319
- var fancy_console_exports = {};
320
- __export(fancy_console_exports, {
321
- error: () => error2,
322
- errorWithTitle: () => errorWithTitle,
323
- warn: () => warn,
324
- warnWithTitle: () => warnWithTitle
325
- });
326
- var badge = "background:#0e0d12;border-radius:9999px;color:#fff;padding:3px 7px;font-family:sans-serif;font-weight:600;";
327
- var bold = "font-weight:600";
328
- function wrap(method) {
329
- return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
330
- /* istanbul ignore next */
331
- (message, ...args) => console[method]("%cLiveblocks", badge, message, ...args)
332
- );
333
- }
334
- var warn = wrap("warn");
335
- var error2 = wrap("error");
336
- function wrapWithTitle(method) {
337
- return typeof window === "undefined" || process.env.NODE_ENV === "test" ? console[method] : (
338
- /* istanbul ignore next */
339
- (title, message, ...args) => console[method](
340
- `%cLiveblocks%c ${title}`,
341
- badge,
342
- bold,
343
- message,
344
- ...args
345
- )
346
- );
347
- }
348
- var warnWithTitle = wrapWithTitle("warn");
349
- var errorWithTitle = wrapWithTitle("error");
350
- var _defaultFn, _a3;
351
- var DefaultMap = (_a3 = class extends Map {
352
- /**
353
- * If the default function is not provided to the constructor, it has to be
354
- * provided in each .getOrCreate() call individually.
355
- */
356
- constructor(defaultFn, entries2) {
357
- super(entries2);
358
- __privateAdd(this, _defaultFn);
359
- __privateSet(this, _defaultFn, defaultFn);
360
- }
361
- /**
362
- * Gets the value at the given key, or creates it.
363
- *
364
- * Difference from normal Map: if the key does not exist, it will be created
365
- * on the fly using the factory function, and that value will get returned
366
- * instead of `undefined`.
367
- */
368
- getOrCreate(key, defaultFn) {
369
- if (super.has(key)) {
370
- return super.get(key);
371
- } else {
372
- const fn = defaultFn ?? __privateGet(this, _defaultFn) ?? raise("DefaultMap used without a factory function");
373
- const value = fn(key);
374
- this.set(key, value);
375
- return value;
376
- }
377
- }
378
- }, _defaultFn = new WeakMap(), _a3);
379
- var ServerMsgCode = Object.freeze({
380
- // For Presence
381
- UPDATE_PRESENCE: 100,
382
- USER_JOINED: 101,
383
- USER_LEFT: 102,
384
- BROADCASTED_EVENT: 103,
385
- ROOM_STATE: 104,
386
- // For Storage
387
- STORAGE_STATE_V7: 200,
388
- // Only sent in V7
389
- STORAGE_CHUNK: 210,
390
- // Used in V8+
391
- STORAGE_STREAM_END: 211,
392
- // Used in V8+
393
- UPDATE_STORAGE: 201,
394
- // For Yjs Docs
395
- UPDATE_YDOC: 300,
396
- // For Comments
397
- THREAD_CREATED: 400,
398
- THREAD_DELETED: 407,
399
- THREAD_METADATA_UPDATED: 401,
400
- THREAD_UPDATED: 408,
401
- COMMENT_CREATED: 402,
402
- COMMENT_EDITED: 403,
403
- COMMENT_DELETED: 404,
404
- COMMENT_REACTION_ADDED: 405,
405
- COMMENT_REACTION_REMOVED: 406,
406
- COMMENT_METADATA_UPDATED: 409,
407
- // Error codes
408
- REJECT_STORAGE_OP: 299
409
- // Sent if a mutation was not allowed on the server (i.e. due to permissions, limit exceeded, etc)
410
- });
411
- var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
412
- WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_NORMAL"] = 1e3] = "CLOSE_NORMAL";
413
- WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_ABNORMAL"] = 1006] = "CLOSE_ABNORMAL";
414
- WebsocketCloseCodes2[WebsocketCloseCodes2["UNEXPECTED_CONDITION"] = 1011] = "UNEXPECTED_CONDITION";
415
- WebsocketCloseCodes2[WebsocketCloseCodes2["TRY_AGAIN_LATER"] = 1013] = "TRY_AGAIN_LATER";
416
- WebsocketCloseCodes2[WebsocketCloseCodes2["INVALID_MESSAGE_FORMAT"] = 4e3] = "INVALID_MESSAGE_FORMAT";
417
- WebsocketCloseCodes2[WebsocketCloseCodes2["NOT_ALLOWED"] = 4001] = "NOT_ALLOWED";
418
- WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_SECONDS"] = 4002] = "MAX_NUMBER_OF_MESSAGES_PER_SECONDS";
419
- WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS"] = 4003] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS";
420
- WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP"] = 4004] = "MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP";
421
- WebsocketCloseCodes2[WebsocketCloseCodes2["MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM"] = 4005] = "MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM";
422
- WebsocketCloseCodes2[WebsocketCloseCodes2["ROOM_ID_UPDATED"] = 4006] = "ROOM_ID_UPDATED";
423
- WebsocketCloseCodes2[WebsocketCloseCodes2["KICKED"] = 4100] = "KICKED";
424
- WebsocketCloseCodes2[WebsocketCloseCodes2["TOKEN_EXPIRED"] = 4109] = "TOKEN_EXPIRED";
425
- WebsocketCloseCodes2[WebsocketCloseCodes2["CLOSE_WITHOUT_RETRY"] = 4999] = "CLOSE_WITHOUT_RETRY";
426
- return WebsocketCloseCodes2;
427
- })(WebsocketCloseCodes || {});
428
- var BACKOFF_DELAYS = [250, 500, 1e3, 2e3, 4e3, 8e3, 1e4];
429
- var RESET_DELAY = BACKOFF_DELAYS[0] - 1;
430
- function log(level, message) {
431
- const logger = level === 2 ? error2 : level === 1 ? warn : (
432
- /* black hole */
433
- () => {
434
- }
435
- );
436
- return () => {
437
- logger(message);
438
- };
439
- }
440
- var logPermanentClose = log(
441
- 1,
442
- "Connection to WebSocket closed permanently. Won't retry."
443
- );
444
- var kInternal = Symbol();
445
- var EMPTY_OBJECT = Object.freeze({});
446
- var NULL_KEYWORD_CHARS = Array.from(new Set("null"));
447
- var TRUE_KEYWORD_CHARS = Array.from(new Set("true"));
448
- var FALSE_KEYWORD_CHARS = Array.from(new Set("false"));
449
- var ALL_KEYWORD_CHARS = Array.from(new Set("nulltruefalse"));
450
- var kWILDCARD = Symbol("*");
451
- var eventSource = makeEventSource();
452
- if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
453
- window.addEventListener("message", (event) => {
454
- if (event.source === window && event.data?.source === "liveblocks-devtools-panel") {
455
- eventSource.notify(event.data);
456
- } else {
457
- }
458
- });
459
- }
460
- var onMessageFromPanel = eventSource.observable;
461
- var loadedAt = Date.now();
462
- var kPlain = Symbol("notification-settings-plain");
463
- var MIN_CODE = 32;
464
- var MAX_CODE = 126;
465
- var NUM_DIGITS = MAX_CODE - MIN_CODE + 1;
466
- var ZERO = nthDigit(0);
467
- var ONE = nthDigit(1);
468
- var ZERO_NINE = ZERO + nthDigit(-1);
469
- function nthDigit(n) {
470
- const code = MIN_CODE + (n < 0 ? NUM_DIGITS + n : n);
471
- if (code < MIN_CODE || code > MAX_CODE) {
472
- throw new Error(`Invalid n value: ${n}`);
473
- }
474
- return String.fromCharCode(code);
475
- }
476
- function makePosition(x, y) {
477
- if (x !== void 0 && y !== void 0) {
478
- return between(x, y);
479
- } else if (x !== void 0) {
480
- return after(x);
481
- } else if (y !== void 0) {
482
- return before(y);
483
- } else {
484
- return ONE;
485
- }
486
- }
487
- function before(pos) {
488
- const lastIndex = pos.length - 1;
489
- for (let i = 0; i <= lastIndex; i++) {
490
- const code = pos.charCodeAt(i);
491
- if (code <= MIN_CODE) {
492
- continue;
493
- }
494
- if (i === lastIndex) {
495
- if (code === MIN_CODE + 1) {
496
- return pos.substring(0, i) + ZERO_NINE;
497
- } else {
498
- return pos.substring(0, i) + String.fromCharCode(code - 1);
499
- }
500
- } else {
501
- return pos.substring(0, i + 1);
502
- }
503
- }
504
- return ONE;
505
- }
506
- var VIEWPORT_START = 2;
507
- var VIEWPORT_STEP = 3;
508
- function after(pos) {
509
- for (let i = 0; i < pos.length; i++) {
510
- const code = pos.charCodeAt(i);
511
- if (code < MIN_CODE || code > MAX_CODE) {
512
- return pos + ONE;
513
- }
514
- }
515
- while (pos.length > 1 && pos.charCodeAt(pos.length - 1) === MIN_CODE) {
516
- pos = pos.slice(0, -1);
517
- }
518
- if (pos.length === 0 || pos === ZERO) {
519
- return ONE;
520
- }
521
- let viewport = VIEWPORT_START;
522
- if (pos.length > VIEWPORT_START) {
523
- viewport = VIEWPORT_START + Math.ceil((pos.length - VIEWPORT_START) / VIEWPORT_STEP) * VIEWPORT_STEP;
524
- }
525
- const result = incrementWithinViewport(pos, viewport);
526
- if (result !== null) {
527
- return result;
528
- }
529
- viewport += VIEWPORT_STEP;
530
- const extendedResult = incrementWithinViewport(pos, viewport);
531
- if (extendedResult !== null) {
532
- return extendedResult;
533
- }
534
- return pos + ONE;
535
- }
536
- function incrementWithinViewport(pos, viewport) {
537
- const digits = [];
538
- for (let i = 0; i < viewport; i++) {
539
- if (i < pos.length) {
540
- digits.push(pos.charCodeAt(i) - MIN_CODE);
541
- } else {
542
- digits.push(0);
543
- }
544
- }
545
- let carry = 1;
546
- for (let i = viewport - 1; i >= 0 && carry; i--) {
547
- const sum = digits[i] + carry;
548
- if (sum >= NUM_DIGITS) {
549
- digits[i] = 0;
550
- carry = 1;
551
- } else {
552
- digits[i] = sum;
553
- carry = 0;
554
- }
555
- }
556
- if (carry) {
557
- return null;
558
- }
559
- let result = "";
560
- for (const d of digits) {
561
- result += String.fromCharCode(d + MIN_CODE);
562
- }
563
- while (result.length > 1 && result.charCodeAt(result.length - 1) === MIN_CODE) {
564
- result = result.slice(0, -1);
565
- }
566
- return result;
567
- }
568
- function between(lo, hi) {
569
- if (lo < hi) {
570
- return _between(lo, hi);
571
- } else if (lo > hi) {
572
- return _between(hi, lo);
573
- } else {
574
- throw new Error("Cannot compute value between two equal positions");
575
- }
576
- }
577
- function _between(lo, hi) {
578
- let index = 0;
579
- const loLen = lo.length;
580
- const hiLen = hi.length;
581
- while (true) {
582
- const loCode = index < loLen ? lo.charCodeAt(index) : MIN_CODE;
583
- const hiCode = index < hiLen ? hi.charCodeAt(index) : MAX_CODE;
584
- if (loCode === hiCode) {
585
- index++;
586
- continue;
587
- }
588
- if (hiCode - loCode === 1) {
589
- const size = index + 1;
590
- let prefix = lo.substring(0, size);
591
- if (prefix.length < size) {
592
- prefix += ZERO.repeat(size - prefix.length);
593
- }
594
- const suffix = lo.substring(size);
595
- const nines = "";
596
- return prefix + _between(suffix, nines);
597
- } else {
598
- return takeN(lo, index) + String.fromCharCode(hiCode + loCode >> 1);
599
- }
600
- }
601
- }
602
- function takeN(pos, n) {
603
- return n < pos.length ? pos.substring(0, n) : pos + ZERO.repeat(n - pos.length);
604
- }
605
- var MIN_NON_ZERO_CODE = MIN_CODE + 1;
606
- function isPos(str) {
607
- if (str === "") {
608
- return false;
609
- }
610
- const lastIdx = str.length - 1;
611
- const last = str.charCodeAt(lastIdx);
612
- if (last < MIN_NON_ZERO_CODE || last > MAX_CODE) {
613
- return false;
614
- }
615
- for (let i = 0; i < lastIdx; i++) {
616
- const code = str.charCodeAt(i);
617
- if (code < MIN_CODE || code > MAX_CODE) {
618
- return false;
619
- }
620
- }
621
- return true;
622
- }
623
- function convertToPos(str) {
624
- const codes = [];
625
- for (let i = 0; i < str.length; i++) {
626
- const code = str.charCodeAt(i);
627
- codes.push(code < MIN_CODE ? MIN_CODE : code > MAX_CODE ? MAX_CODE : code);
628
- }
629
- while (codes.length > 0 && codes[codes.length - 1] === MIN_CODE) {
630
- codes.length--;
631
- }
632
- return codes.length > 0 ? String.fromCharCode(...codes) : (
633
- // Edge case: the str was a 0-only string, which is invalid. Default back to .1
634
- ONE
635
- );
636
- }
637
- function asPos(str) {
638
- return isPos(str) ? str : convertToPos(str);
639
- }
640
- var OpCode = Object.freeze({
641
- INIT: 0,
642
- SET_PARENT_KEY: 1,
643
- CREATE_LIST: 2,
644
- UPDATE_OBJECT: 3,
645
- CREATE_OBJECT: 4,
646
- DELETE_CRDT: 5,
647
- DELETE_OBJECT_KEY: 6,
648
- CREATE_MAP: 7,
649
- CREATE_REGISTER: 8
650
- });
651
- var NoParent = Object.freeze({ type: "NoParent" });
652
- var CrdtType = Object.freeze({
653
- OBJECT: 0,
654
- LIST: 1,
655
- MAP: 2,
656
- REGISTER: 3
657
- });
658
- function isRootStorageNode(node) {
659
- return node[0] === "root";
660
- }
661
- function isObjectStorageNode(node) {
662
- return node[1].type === CrdtType.OBJECT;
663
- }
664
- function isListStorageNode(node) {
665
- return node[1].type === CrdtType.LIST;
666
- }
667
- function isMapStorageNode(node) {
668
- return node[1].type === CrdtType.MAP;
669
- }
670
- function isRegisterStorageNode(node) {
671
- return node[1].type === CrdtType.REGISTER;
672
- }
673
- function* nodeStreamToCompactNodes(nodes) {
674
- for (const node of nodes) {
675
- if (isObjectStorageNode(node)) {
676
- if (isRootStorageNode(node)) {
677
- const id = node[0];
678
- const crdt = node[1];
679
- yield [id, crdt.data];
680
- } else {
681
- const id = node[0];
682
- const crdt = node[1];
683
- yield [id, CrdtType.OBJECT, crdt.parentId, crdt.parentKey, crdt.data];
684
- }
685
- } else if (isListStorageNode(node)) {
686
- const id = node[0];
687
- const crdt = node[1];
688
- yield [id, CrdtType.LIST, crdt.parentId, crdt.parentKey];
689
- } else if (isMapStorageNode(node)) {
690
- const id = node[0];
691
- const crdt = node[1];
692
- yield [id, CrdtType.MAP, crdt.parentId, crdt.parentKey];
693
- } else if (isRegisterStorageNode(node)) {
694
- const id = node[0];
695
- const crdt = node[1];
696
- yield [id, CrdtType.REGISTER, crdt.parentId, crdt.parentKey, crdt.data];
697
- } else {
698
- }
699
- }
700
- }
701
- var MAX_LIVE_OBJECT_SIZE = 128 * 1024;
702
- function isJsonScalar(data) {
703
- return data === null || typeof data === "string" || typeof data === "number" || typeof data === "boolean";
704
- }
705
- function isJsonArray(data) {
706
- return Array.isArray(data);
707
- }
708
- function isJsonObject(data) {
709
- return !isJsonScalar(data) && !isJsonArray(data);
710
- }
711
- var ClientMsgCode = Object.freeze({
712
- // For Presence
713
- UPDATE_PRESENCE: 100,
714
- BROADCAST_EVENT: 103,
715
- // For Storage
716
- FETCH_STORAGE: 200,
717
- UPDATE_STORAGE: 201,
718
- // For Yjs support
719
- FETCH_YDOC: 300,
720
- UPDATE_YDOC: 301
721
- });
722
- var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 512;
723
- var htmlEscapables = {
724
- "&": "&amp;",
725
- "<": "&lt;",
726
- ">": "&gt;",
727
- '"': "&quot;",
728
- "'": "&#39;"
729
- };
730
- var htmlEscapablesRegex = new RegExp(
731
- Object.keys(htmlEscapables).map((entity) => `\\${entity}`).join("|"),
732
- "g"
733
- );
734
- var markdownEscapables = {
735
- _: "\\_",
736
- "*": "\\*",
737
- "#": "\\#",
738
- "`": "\\`",
739
- "~": "\\~",
740
- "!": "\\!",
741
- "|": "\\|",
742
- "(": "\\(",
743
- ")": "\\)",
744
- "{": "\\{",
745
- "}": "\\}",
746
- "[": "\\[",
747
- "]": "\\]"
748
- };
749
- var markdownEscapablesRegex = new RegExp(
750
- Object.keys(markdownEscapables).map((entity) => `\\${entity}`).join("|"),
751
- "g"
752
- );
753
- detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
754
11
 
755
12
  // src/decoders/ClientMsg.ts
13
+ import { ClientMsgCode } from "@liveblocks/core";
756
14
  import {
757
15
  array,
758
16
  boolean,
@@ -773,6 +31,7 @@ var jsonObjectYolo = jsonYolo.refine(
773
31
  );
774
32
 
775
33
  // src/decoders/Op.ts
34
+ import { OpCode } from "@liveblocks/core";
776
35
  import { constant, object, optional, string, taggedUnion } from "decoders";
777
36
  var updateObjectOp = object({
778
37
  type: constant(OpCode.UPDATE_OBJECT),
@@ -900,6 +159,7 @@ var transientClientMsgDecoder = taggedUnion2("type", {
900
159
  }).describe("Must be a valid transient client message");
901
160
 
902
161
  // src/formats/LossyJson.ts
162
+ import { CrdtType } from "@liveblocks/core";
903
163
  function snapshotToLossyJson_eager(snapshot2) {
904
164
  try {
905
165
  return buildObject(snapshot2, "root", snapshot2.get_root().data);
@@ -1004,6 +264,12 @@ function* snapshotToNodeStream(snapshot2) {
1004
264
  }
1005
265
 
1006
266
  // src/formats/PlainLson.ts
267
+ import {
268
+ assertNever,
269
+ CrdtType as CrdtType2,
270
+ isJsonObject,
271
+ makePosition
272
+ } from "@liveblocks/core";
1007
273
  var SERVER_INIT_OP_PREFIX = "si";
1008
274
  function generateId(state) {
1009
275
  return `${SERVER_INIT_OP_PREFIX}:${state.clock++}`;
@@ -1030,7 +296,7 @@ function* iterJson(key, data, parent, state) {
1030
296
  yield [
1031
297
  generateId(state),
1032
298
  {
1033
- type: CrdtType.REGISTER,
299
+ type: CrdtType2.REGISTER,
1034
300
  data,
1035
301
  parentId: parent[0],
1036
302
  parentKey: key
@@ -1041,7 +307,7 @@ function* iterJson(key, data, parent, state) {
1041
307
  function* iterMap(key, map, parent, state) {
1042
308
  const mapTuple = [
1043
309
  generateId(state),
1044
- { type: CrdtType.MAP, parentId: parent[0], parentKey: key }
310
+ { type: CrdtType2.MAP, parentId: parent[0], parentKey: key }
1045
311
  ];
1046
312
  yield mapTuple;
1047
313
  for (const [subKey, subValue] of Object.entries(map)) {
@@ -1051,7 +317,7 @@ function* iterMap(key, map, parent, state) {
1051
317
  function* iterList(key, list, parent, state) {
1052
318
  const id = generateId(state);
1053
319
  const crdt = {
1054
- type: CrdtType.LIST,
320
+ type: CrdtType2.LIST,
1055
321
  parentId: parent[0],
1056
322
  parentKey: key
1057
323
  };
@@ -1076,12 +342,12 @@ function* iterObjectInner(key, value, parent, state) {
1076
342
  const objectTuple = parent !== null ? [
1077
343
  generateId(state),
1078
344
  {
1079
- type: CrdtType.OBJECT,
345
+ type: CrdtType2.OBJECT,
1080
346
  data,
1081
347
  parentId: parent[0],
1082
348
  parentKey: key
1083
349
  }
1084
- ] : ["root", { type: CrdtType.OBJECT, data }];
350
+ ] : ["root", { type: CrdtType2.OBJECT, data }];
1085
351
  yield objectTuple;
1086
352
  for (const [subKey, subValue] of specialChildren) {
1087
353
  yield* iterJson(subKey, subValue, objectTuple, state);
@@ -1100,11 +366,11 @@ function snapshotToPlainLson_eager(snapshot2) {
1100
366
  }
1101
367
  function buildNode2(snapshot2, id) {
1102
368
  const node = snapshot2.get_node(id);
1103
- if (node.type === CrdtType.OBJECT) {
369
+ if (node.type === CrdtType2.OBJECT) {
1104
370
  return buildObject2(snapshot2, id, node.data);
1105
- } else if (node.type === CrdtType.LIST) {
371
+ } else if (node.type === CrdtType2.LIST) {
1106
372
  return buildList2(snapshot2, id);
1107
- } else if (node.type === CrdtType.MAP) {
373
+ } else if (node.type === CrdtType2.MAP) {
1108
374
  return buildMap2(snapshot2, id);
1109
375
  } else {
1110
376
  return node.data;
@@ -1144,13 +410,13 @@ function* snapshotToPlainLson_lazy(snapshot2) {
1144
410
  }
1145
411
  function* emit2(snapshot2, id) {
1146
412
  const node = snapshot2.get_node(id);
1147
- if (node.type === CrdtType.OBJECT) {
413
+ if (node.type === CrdtType2.OBJECT) {
1148
414
  yield* emitObject2(snapshot2, id, JSON.stringify(node.data).slice(1, -1));
1149
- } else if (node.type === CrdtType.LIST) {
415
+ } else if (node.type === CrdtType2.LIST) {
1150
416
  yield* emitList2(snapshot2, id);
1151
- } else if (node.type === CrdtType.MAP) {
417
+ } else if (node.type === CrdtType2.MAP) {
1152
418
  yield* emitMap2(snapshot2, id);
1153
- } else if (node.type === CrdtType.REGISTER) {
419
+ } else if (node.type === CrdtType2.REGISTER) {
1154
420
  yield JSON.stringify(node.data);
1155
421
  }
1156
422
  }
@@ -1188,17 +454,21 @@ function* emitMap2(snapshot2, id) {
1188
454
  yield "}}";
1189
455
  }
1190
456
 
457
+ // src/makeInMemorySnapshot.ts
458
+ import { CrdtType as CrdtType3, isRootStorageNode, nn } from "@liveblocks/core";
459
+
1191
460
  // src/lib/DefaultMap.ts
1192
- var _defaultFn2;
1193
- var DefaultMap2 = class extends Map {
461
+ import { raise } from "@liveblocks/core";
462
+ var _defaultFn;
463
+ var DefaultMap = class extends Map {
1194
464
  /**
1195
465
  * If the default function is not provided to the constructor, it has to be
1196
466
  * provided in each .getOrCreate() call individually.
1197
467
  */
1198
468
  constructor(defaultFn, entries) {
1199
469
  super(entries);
1200
- __privateAdd(this, _defaultFn2);
1201
- __privateSet(this, _defaultFn2, defaultFn);
470
+ __privateAdd(this, _defaultFn);
471
+ __privateSet(this, _defaultFn, defaultFn);
1202
472
  }
1203
473
  /**
1204
474
  * Gets the value at the given key, or creates it.
@@ -1211,14 +481,14 @@ var DefaultMap2 = class extends Map {
1211
481
  if (super.has(key)) {
1212
482
  return super.get(key);
1213
483
  } else {
1214
- const fn = defaultFn ?? __privateGet(this, _defaultFn2) ?? raise("DefaultMap used without a factory function");
484
+ const fn = defaultFn ?? __privateGet(this, _defaultFn) ?? raise("DefaultMap used without a factory function");
1215
485
  const value = fn(key);
1216
486
  this.set(key, value);
1217
487
  return value;
1218
488
  }
1219
489
  }
1220
490
  };
1221
- _defaultFn2 = new WeakMap();
491
+ _defaultFn = new WeakMap();
1222
492
 
1223
493
  // src/lib/NestedMap.ts
1224
494
  function emptyIterator() {
@@ -1228,7 +498,7 @@ var _map;
1228
498
  var NestedMap = class {
1229
499
  constructor() {
1230
500
  __privateAdd(this, _map);
1231
- __privateSet(this, _map, new DefaultMap2(() => /* @__PURE__ */ new Map()));
501
+ __privateSet(this, _map, new DefaultMap(() => /* @__PURE__ */ new Map()));
1232
502
  }
1233
503
  get size() {
1234
504
  let total = 0;
@@ -1308,7 +578,7 @@ _map = new WeakMap();
1308
578
  function makeInMemorySnapshot(values) {
1309
579
  const map = new Map(values);
1310
580
  if (!map.has("root")) {
1311
- map.set("root", { type: CrdtType.OBJECT, data: {} });
581
+ map.set("root", { type: CrdtType3.OBJECT, data: {} });
1312
582
  }
1313
583
  const entries = [];
1314
584
  const nodeStream = map;
@@ -1370,12 +640,23 @@ var protocolVersionDecoder = enum_(ProtocolVersion).describe(
1370
640
  );
1371
641
 
1372
642
  // src/Room.ts
643
+ import {
644
+ assertNever as assertNever3,
645
+ ClientMsgCode as ClientMsgCode2,
646
+ nodeStreamToCompactNodes,
647
+ OpCode as OpCode3,
648
+ raise as raise3,
649
+ ServerMsgCode as ServerMsgCode2,
650
+ tryParseJson,
651
+ WebsocketCloseCodes as CloseCode
652
+ } from "@liveblocks/core";
1373
653
  import { Mutex } from "async-mutex";
1374
654
  import { array as array2, formatInline } from "decoders";
1375
655
  import { chunked } from "itertools";
1376
656
  import { nanoid as nanoid2 } from "nanoid";
1377
657
 
1378
658
  // src/lib/Logger.ts
659
+ import { raise as raise2 } from "@liveblocks/core";
1379
660
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1380
661
  LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
1381
662
  LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
@@ -1407,7 +688,7 @@ var LogTarget = class {
1407
688
  case 3 /* ERROR */:
1408
689
  return "error";
1409
690
  default:
1410
- return raise("Invalid log level");
691
+ return raise2("Invalid log level");
1411
692
  }
1412
693
  }
1413
694
  /** Helper for formatting an Arg */
@@ -1508,6 +789,7 @@ var Logger = class _Logger {
1508
789
  };
1509
790
 
1510
791
  // src/plugins/InMemoryDriver.ts
792
+ import { asPos, CrdtType as CrdtType4, isRootStorageNode as isRootStorageNode2, nn as nn2 } from "@liveblocks/core";
1511
793
  import { ifilter, imap } from "itertools";
1512
794
 
1513
795
  // src/lib/text.ts
@@ -1519,7 +801,7 @@ function quote(value) {
1519
801
  function buildRevNodes(nodeStream) {
1520
802
  const result = new NestedMap();
1521
803
  for (const node of nodeStream) {
1522
- if (isRootStorageNode(node)) continue;
804
+ if (isRootStorageNode2(node)) continue;
1523
805
  const [id, crdt] = node;
1524
806
  const existing = result.get(crdt.parentId, crdt.parentKey);
1525
807
  if (existing === void 0 || id > existing) {
@@ -1534,17 +816,17 @@ function buildReverseLookup(nodes) {
1534
816
  const reachableNodes = /* @__PURE__ */ new Set();
1535
817
  while (queue.length > 0) {
1536
818
  const nodeId = queue.pop();
1537
- const node = nn(nodes.get(nodeId));
1538
- if (node.type === CrdtType.OBJECT) {
819
+ const node = nn2(nodes.get(nodeId));
820
+ if (node.type === CrdtType4.OBJECT) {
1539
821
  for (const key of revNodes.keysAt(nodeId)) {
1540
822
  delete node.data[key];
1541
823
  }
1542
824
  }
1543
- if (node.type !== CrdtType.REGISTER) {
825
+ if (node.type !== CrdtType4.REGISTER) {
1544
826
  queue.push(...revNodes.valuesAt(nodeId));
1545
827
  } else {
1546
828
  const parent = nodes.get(node.parentId);
1547
- if (parent?.type === CrdtType.OBJECT) {
829
+ if (parent?.type === CrdtType4.OBJECT) {
1548
830
  continue;
1549
831
  }
1550
832
  }
@@ -1560,7 +842,7 @@ function buildReverseLookup(nodes) {
1560
842
  return deletedCount === 0 ? revNodes : buildRevNodes(nodes);
1561
843
  }
1562
844
  function hasStaticDataAt(node, key) {
1563
- return node.type === CrdtType.OBJECT && Object.prototype.hasOwnProperty.call(node.data, key) && node.data[key] !== void 0;
845
+ return node.type === CrdtType4.OBJECT && Object.prototype.hasOwnProperty.call(node.data, key) && node.data[key] !== void 0;
1564
846
  }
1565
847
  var InMemoryDriver = class {
1566
848
  constructor(options) {
@@ -1621,7 +903,7 @@ var InMemoryDriver = class {
1621
903
  load_nodes_api() {
1622
904
  const nodes = this._nodes;
1623
905
  if (!nodes.has("root")) {
1624
- nodes.set("root", { type: CrdtType.OBJECT, data: {} });
906
+ nodes.set("root", { type: CrdtType4.OBJECT, data: {} });
1625
907
  }
1626
908
  const revNodes = buildReverseLookup(nodes);
1627
909
  function get_next_sibling(parentId, pos) {
@@ -1639,7 +921,7 @@ var InMemoryDriver = class {
1639
921
  if (parentNode === void 0) {
1640
922
  throw new Error(`No such parent ${quote(node.parentId)}`);
1641
923
  }
1642
- if (node.type === CrdtType.REGISTER && parentNode.type === CrdtType.OBJECT) {
924
+ if (node.type === CrdtType4.REGISTER && parentNode.type === CrdtType4.OBJECT) {
1643
925
  throw new Error("Cannot add register under object");
1644
926
  }
1645
927
  const conflictingSiblingId = revNodes.get(node.parentId, node.parentKey);
@@ -1671,7 +953,7 @@ var InMemoryDriver = class {
1671
953
  }
1672
954
  async function set_object_data(id, data, allowOverwrite = false) {
1673
955
  const node = nodes.get(id);
1674
- if (node?.type !== CrdtType.OBJECT) {
956
+ if (node?.type !== CrdtType4.OBJECT) {
1675
957
  return;
1676
958
  }
1677
959
  for (const key of Object.keys(data)) {
@@ -1799,6 +1081,13 @@ function makeNewInMemoryDriver(options) {
1799
1081
  }
1800
1082
 
1801
1083
  // src/Storage.ts
1084
+ import {
1085
+ asPos as asPos2,
1086
+ assertNever as assertNever2,
1087
+ CrdtType as CrdtType5,
1088
+ makePosition as makePosition2,
1089
+ OpCode as OpCode2
1090
+ } from "@liveblocks/core";
1802
1091
  function accept(op2, fix) {
1803
1092
  return { action: "accepted", op: op2, fix };
1804
1093
  }
@@ -1807,34 +1096,34 @@ function ignore(ignoredOp) {
1807
1096
  }
1808
1097
  function nodeFromCreateChildOp(op2) {
1809
1098
  switch (op2.type) {
1810
- case OpCode.CREATE_LIST:
1099
+ case OpCode2.CREATE_LIST:
1811
1100
  return {
1812
- type: CrdtType.LIST,
1101
+ type: CrdtType5.LIST,
1813
1102
  parentId: op2.parentId,
1814
1103
  parentKey: op2.parentKey
1815
1104
  };
1816
- case OpCode.CREATE_MAP:
1105
+ case OpCode2.CREATE_MAP:
1817
1106
  return {
1818
- type: CrdtType.MAP,
1107
+ type: CrdtType5.MAP,
1819
1108
  parentId: op2.parentId,
1820
1109
  parentKey: op2.parentKey
1821
1110
  };
1822
- case OpCode.CREATE_OBJECT:
1111
+ case OpCode2.CREATE_OBJECT:
1823
1112
  return {
1824
- type: CrdtType.OBJECT,
1113
+ type: CrdtType5.OBJECT,
1825
1114
  parentId: op2.parentId,
1826
1115
  parentKey: op2.parentKey,
1827
1116
  data: op2.data
1828
1117
  };
1829
- case OpCode.CREATE_REGISTER:
1118
+ case OpCode2.CREATE_REGISTER:
1830
1119
  return {
1831
- type: CrdtType.REGISTER,
1120
+ type: CrdtType5.REGISTER,
1832
1121
  parentId: op2.parentId,
1833
1122
  parentKey: op2.parentKey,
1834
1123
  data: op2.data
1835
1124
  };
1836
1125
  default:
1837
- return assertNever(op2, "Unknown op code");
1126
+ return assertNever2(op2, "Unknown op code");
1838
1127
  }
1839
1128
  }
1840
1129
  var Storage = class {
@@ -1888,24 +1177,24 @@ var Storage = class {
1888
1177
  */
1889
1178
  async applyOp(op2) {
1890
1179
  switch (op2.type) {
1891
- case OpCode.CREATE_LIST:
1892
- case OpCode.CREATE_MAP:
1893
- case OpCode.CREATE_REGISTER:
1894
- case OpCode.CREATE_OBJECT:
1180
+ case OpCode2.CREATE_LIST:
1181
+ case OpCode2.CREATE_MAP:
1182
+ case OpCode2.CREATE_REGISTER:
1183
+ case OpCode2.CREATE_OBJECT:
1895
1184
  return await this.applyCreateOp(op2);
1896
- case OpCode.UPDATE_OBJECT:
1185
+ case OpCode2.UPDATE_OBJECT:
1897
1186
  return await this.applyUpdateObjectOp(op2);
1898
- case OpCode.SET_PARENT_KEY:
1187
+ case OpCode2.SET_PARENT_KEY:
1899
1188
  return await this.applySetParentKeyOp(op2);
1900
- case OpCode.DELETE_OBJECT_KEY:
1189
+ case OpCode2.DELETE_OBJECT_KEY:
1901
1190
  return await this.applyDeleteObjectKeyOp(op2);
1902
- case OpCode.DELETE_CRDT:
1191
+ case OpCode2.DELETE_CRDT:
1903
1192
  return await this.applyDeleteCrdtOp(op2);
1904
1193
  default:
1905
1194
  if (process.env.NODE_ENV === "production") {
1906
1195
  return ignore(op2);
1907
1196
  } else {
1908
- return assertNever(op2, "Invalid op");
1197
+ return assertNever2(op2, "Invalid op");
1909
1198
  }
1910
1199
  }
1911
1200
  }
@@ -1919,19 +1208,19 @@ var Storage = class {
1919
1208
  return ignore(op2);
1920
1209
  }
1921
1210
  switch (parent.type) {
1922
- case CrdtType.OBJECT:
1923
- if (op2.type === OpCode.CREATE_REGISTER) {
1211
+ case CrdtType5.OBJECT:
1212
+ if (op2.type === OpCode2.CREATE_REGISTER) {
1924
1213
  return ignore(op2);
1925
1214
  }
1926
- case CrdtType.MAP:
1215
+ case CrdtType5.MAP:
1927
1216
  await this.loadedDriver.set_child(op2.id, node, true);
1928
1217
  return accept(op2);
1929
- case CrdtType.LIST:
1218
+ case CrdtType5.LIST:
1930
1219
  return this.createChildAsListItem(op2, node);
1931
- case CrdtType.REGISTER:
1220
+ case CrdtType5.REGISTER:
1932
1221
  return ignore(op2);
1933
1222
  default:
1934
- return assertNever(parent, "Unhandled CRDT type");
1223
+ return assertNever2(parent, "Unhandled CRDT type");
1935
1224
  }
1936
1225
  }
1937
1226
  async createChildAsListItem(op2, node) {
@@ -1942,7 +1231,7 @@ var Storage = class {
1942
1231
  if (insertedParentKey !== node.parentKey) {
1943
1232
  op2 = { ...op2, parentKey: insertedParentKey };
1944
1233
  fix = {
1945
- type: OpCode.SET_PARENT_KEY,
1234
+ type: OpCode2.SET_PARENT_KEY,
1946
1235
  id: op2.id,
1947
1236
  parentKey: insertedParentKey
1948
1237
  };
@@ -1960,14 +1249,14 @@ var Storage = class {
1960
1249
  );
1961
1250
  if (prevItemId !== void 0 && prevItemId !== deletedId) {
1962
1251
  fix = {
1963
- type: OpCode.DELETE_CRDT,
1252
+ type: OpCode2.DELETE_CRDT,
1964
1253
  id: prevItemId
1965
1254
  };
1966
1255
  }
1967
1256
  await this.loadedDriver.set_child(op2.id, node, true);
1968
1257
  return accept(op2, fix);
1969
1258
  } else {
1970
- return assertNever(intent, "Invalid intent");
1259
+ return assertNever2(intent, "Invalid intent");
1971
1260
  }
1972
1261
  }
1973
1262
  async applyDeleteObjectKeyOp(op2) {
@@ -1990,7 +1279,7 @@ var Storage = class {
1990
1279
  if (newPosition !== op2.parentKey) {
1991
1280
  const modifiedOp = { ...op2, parentKey: newPosition };
1992
1281
  const fix = {
1993
- type: OpCode.SET_PARENT_KEY,
1282
+ type: OpCode2.SET_PARENT_KEY,
1994
1283
  id: op2.id,
1995
1284
  parentKey: newPosition
1996
1285
  };
@@ -2008,7 +1297,7 @@ var Storage = class {
2008
1297
  * Returns the key that was used for the insertion.
2009
1298
  */
2010
1299
  async insertIntoList(id, node) {
2011
- const key = this.findFreeListPosition(node.parentId, asPos(node.parentKey));
1300
+ const key = this.findFreeListPosition(node.parentId, asPos2(node.parentKey));
2012
1301
  if (key !== node.parentKey) {
2013
1302
  node = { ...node, parentKey: key };
2014
1303
  }
@@ -2032,13 +1321,13 @@ var Storage = class {
2032
1321
  if (node?.parentId === void 0) {
2033
1322
  return;
2034
1323
  }
2035
- if (this.loadedDriver.get_node(node.parentId)?.type !== CrdtType.LIST) {
1324
+ if (this.loadedDriver.get_node(node.parentId)?.type !== CrdtType5.LIST) {
2036
1325
  return;
2037
1326
  }
2038
1327
  if (node.parentKey === targetKey) {
2039
1328
  return targetKey;
2040
1329
  }
2041
- const key = this.findFreeListPosition(node.parentId, asPos(targetKey));
1330
+ const key = this.findFreeListPosition(node.parentId, asPos2(targetKey));
2042
1331
  if (key !== node.parentKey) {
2043
1332
  await this.loadedDriver.move_sibling(id, key);
2044
1333
  }
@@ -2058,14 +1347,15 @@ var Storage = class {
2058
1347
  const currPos = parentPos;
2059
1348
  const nextPos = this.loadedDriver.get_next_sibling(parentId, currPos);
2060
1349
  if (nextPos !== void 0) {
2061
- return makePosition(currPos, nextPos);
1350
+ return makePosition2(currPos, nextPos);
2062
1351
  } else {
2063
- return makePosition(currPos);
1352
+ return makePosition2(currPos);
2064
1353
  }
2065
1354
  }
2066
1355
  };
2067
1356
 
2068
1357
  // src/YjsStorage.ts
1358
+ import { DefaultMap as DefaultMap2 } from "@liveblocks/core";
2069
1359
  import { Base64 } from "js-base64";
2070
1360
  import { nanoid } from "nanoid";
2071
1361
  import * as Y from "yjs";
@@ -2078,7 +1368,7 @@ var YjsStorage = class {
2078
1368
  __publicField(this, "lastUpdatesById", /* @__PURE__ */ new Map());
2079
1369
  __publicField(this, "lastSnapshotById", /* @__PURE__ */ new Map());
2080
1370
  // Keeps track of which keys are loaded, so we can clean them up without calling `.list()`
2081
- __publicField(this, "keysById", new DefaultMap(
1371
+ __publicField(this, "keysById", new DefaultMap2(
2082
1372
  () => /* @__PURE__ */ new Set()
2083
1373
  ));
2084
1374
  __publicField(this, "initPromisesById", /* @__PURE__ */ new Map());
@@ -2324,8 +1614,8 @@ async function tryCatch(promise) {
2324
1614
  try {
2325
1615
  const data = await (typeof promise === "function" ? promise() : promise);
2326
1616
  return [data, void 0];
2327
- } catch (error3) {
2328
- return [void 0, error3];
1617
+ } catch (error) {
1618
+ return [void 0, error];
2329
1619
  }
2330
1620
  }
2331
1621
 
@@ -2370,6 +1660,7 @@ __revMap = new WeakMap();
2370
1660
  __keyFn = new WeakMap();
2371
1661
 
2372
1662
  // src/utils.ts
1663
+ import { ServerMsgCode } from "@liveblocks/core";
2373
1664
  function concatUint8Arrays(arrays) {
2374
1665
  const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
2375
1666
  const result = new Uint8Array(totalLength);
@@ -2399,7 +1690,7 @@ var HIGHEST_PROTOCOL_VERSION = Math.max(
2399
1690
  )
2400
1691
  );
2401
1692
  var SERVER_MSG_CODE_NAMES = Object.fromEntries(
2402
- Object.entries(ServerMsgCode).map(([k, v]) => [v, k])
1693
+ Object.entries(ServerMsgCode2).map(([k, v]) => [v, k])
2403
1694
  );
2404
1695
  var BLACK_HOLE = new Logger([
2405
1696
  /* No targets, i.e. black hole logger */
@@ -2415,7 +1706,7 @@ function serialize(msgs) {
2415
1706
  return JSON.stringify(msgs);
2416
1707
  }
2417
1708
  function ackIgnoredOp(opId) {
2418
- return { type: OpCode.DELETE_CRDT, id: "ACK", opId };
1709
+ return { type: OpCode3.DELETE_CRDT, id: "ACK", opId };
2419
1710
  }
2420
1711
  function stripOpId(op2) {
2421
1712
  const { opId: _, ...rest } = op2;
@@ -2600,7 +1891,7 @@ var Room = class {
2600
1891
  }
2601
1892
  // prettier-ignore
2602
1893
  get data() {
2603
- return this._data ?? raise("Cannot use room before it's loaded");
1894
+ return this._data ?? raise3("Cannot use room before it's loaded");
2604
1895
  }
2605
1896
  // prettier-ignore
2606
1897
  // ------------------------------------------------------------------------------------
@@ -2719,7 +2010,7 @@ var Room = class {
2719
2010
  while ((existing = this.sessions.lookupPrimaryKey(ticket.actor)) !== void 0) {
2720
2011
  this.endBrowserSession(
2721
2012
  existing,
2722
- WebsocketCloseCodes.KICKED,
2013
+ CloseCode.KICKED,
2723
2014
  "Closed stale connection",
2724
2015
  ctx,
2725
2016
  defer
@@ -2751,7 +2042,7 @@ var Room = class {
2751
2042
  this.sendToOthers(
2752
2043
  ticket.sessionKey,
2753
2044
  {
2754
- type: ServerMsgCode.USER_JOINED,
2045
+ type: ServerMsgCode2.USER_JOINED,
2755
2046
  actor: newSession.actor,
2756
2047
  id: newSession.user.id,
2757
2048
  info: newSession.user.info,
@@ -2782,7 +2073,7 @@ var Room = class {
2782
2073
  const deleted = sessions.delete(key);
2783
2074
  if (deleted) {
2784
2075
  for (const other of this.otherSessions(key)) {
2785
- other.send({ type: ServerMsgCode.USER_LEFT, actor: session.actor });
2076
+ other.send({ type: ServerMsgCode2.USER_LEFT, actor: session.actor });
2786
2077
  }
2787
2078
  const p$ = this.hooks.onSessionDidEnd?.(session, ctx);
2788
2079
  if (p$) defer(p$);
@@ -2814,7 +2105,7 @@ var Room = class {
2814
2105
  "One of your hook handlers returned a promise, but no side effect collector was provided. Pass a `defer` callback to handleData() to collect async side effects."
2815
2106
  );
2816
2107
  }) {
2817
- const text = typeof data === "string" ? data : raise("Unsupported message format");
2108
+ const text = typeof data === "string" ? data : raise3("Unsupported message format");
2818
2109
  if (text === "ping") {
2819
2110
  await this.handlePing(key, ctx);
2820
2111
  } else {
@@ -2824,7 +2115,7 @@ var Room = class {
2824
2115
  const reason = process.env.NODE_ENV !== "production" ? formatInline(messages.error) : "Invalid message format";
2825
2116
  this.endBrowserSession(
2826
2117
  key,
2827
- WebsocketCloseCodes.INVALID_MESSAGE_FORMAT,
2118
+ CloseCode.INVALID_MESSAGE_FORMAT,
2828
2119
  reason,
2829
2120
  ctx,
2830
2121
  defer
@@ -2914,7 +2205,7 @@ var Room = class {
2914
2205
  if (success === 0) {
2915
2206
  this.endBrowserSession(
2916
2207
  key,
2917
- WebsocketCloseCodes.KICKED,
2208
+ CloseCode.KICKED,
2918
2209
  "Closed broken connection",
2919
2210
  ctx,
2920
2211
  defer
@@ -2936,7 +2227,7 @@ var Room = class {
2936
2227
  if (success === 0) {
2937
2228
  this.endBrowserSession(
2938
2229
  key,
2939
- WebsocketCloseCodes.KICKED,
2230
+ CloseCode.KICKED,
2940
2231
  "Closed broken connection",
2941
2232
  ctx,
2942
2233
  defer
@@ -3037,8 +2328,8 @@ var Room = class {
3037
2328
  } else {
3038
2329
  if (!session.hasNotifiedClientStorageUpdateError) {
3039
2330
  toReply.push({
3040
- type: ServerMsgCode.REJECT_STORAGE_OP,
3041
- opIds: msg.type === ClientMsgCode.UPDATE_STORAGE ? msg.ops.map((op2) => op2.opId) : [],
2331
+ type: ServerMsgCode2.REJECT_STORAGE_OP,
2332
+ opIds: msg.type === ClientMsgCode2.UPDATE_STORAGE ? msg.ops.map((op2) => op2.opId) : [],
3042
2333
  reason: isMsgAllowed.reason
3043
2334
  });
3044
2335
  session.setHasNotifiedClientStorageUpdateError();
@@ -3099,24 +2390,24 @@ var Room = class {
3099
2390
  throw new Error("Handling messages requires exclusive access");
3100
2391
  }
3101
2392
  switch (msg.type) {
3102
- case ClientMsgCode.UPDATE_PRESENCE: {
2393
+ case ClientMsgCode2.UPDATE_PRESENCE: {
3103
2394
  scheduleFanOut({
3104
- type: ServerMsgCode.UPDATE_PRESENCE,
2395
+ type: ServerMsgCode2.UPDATE_PRESENCE,
3105
2396
  actor: session.actor,
3106
2397
  data: msg.data,
3107
2398
  targetActor: msg.targetActor
3108
2399
  });
3109
2400
  break;
3110
2401
  }
3111
- case ClientMsgCode.BROADCAST_EVENT: {
2402
+ case ClientMsgCode2.BROADCAST_EVENT: {
3112
2403
  scheduleFanOut({
3113
- type: ServerMsgCode.BROADCASTED_EVENT,
2404
+ type: ServerMsgCode2.BROADCASTED_EVENT,
3114
2405
  actor: session.actor,
3115
2406
  event: msg.event
3116
2407
  });
3117
2408
  break;
3118
2409
  }
3119
- case ClientMsgCode.FETCH_STORAGE: {
2410
+ case ClientMsgCode2.FETCH_STORAGE: {
3120
2411
  if (session.version >= 8 /* V8 */) {
3121
2412
  if (__privateGet(this, __allowStreaming)) {
3122
2413
  const NODES_PER_CHUNK = 250;
@@ -3125,28 +2416,28 @@ var Room = class {
3125
2416
  NODES_PER_CHUNK
3126
2417
  )) {
3127
2418
  replyImmediately({
3128
- type: ServerMsgCode.STORAGE_CHUNK,
2419
+ type: ServerMsgCode2.STORAGE_CHUNK,
3129
2420
  nodes: chunk
3130
2421
  });
3131
2422
  }
3132
2423
  } else {
3133
2424
  replyImmediately({
3134
- type: ServerMsgCode.STORAGE_CHUNK,
2425
+ type: ServerMsgCode2.STORAGE_CHUNK,
3135
2426
  nodes: Array.from(
3136
2427
  nodeStreamToCompactNodes(this.storage.loadedDriver.iter_nodes())
3137
2428
  )
3138
2429
  });
3139
2430
  }
3140
- replyImmediately({ type: ServerMsgCode.STORAGE_STREAM_END });
2431
+ replyImmediately({ type: ServerMsgCode2.STORAGE_STREAM_END });
3141
2432
  } else {
3142
2433
  replyImmediately({
3143
- type: ServerMsgCode.STORAGE_STATE_V7,
2434
+ type: ServerMsgCode2.STORAGE_STATE_V7,
3144
2435
  items: Array.from(this.storage.loadedDriver.iter_nodes())
3145
2436
  });
3146
2437
  }
3147
2438
  break;
3148
2439
  }
3149
- case ClientMsgCode.UPDATE_STORAGE: {
2440
+ case ClientMsgCode2.UPDATE_STORAGE: {
3150
2441
  this.driver.bump_storage_version?.();
3151
2442
  const result = await this.storage.applyOps(msg.ops);
3152
2443
  const opsToForward = result.flatMap(
@@ -3159,22 +2450,22 @@ var Room = class {
3159
2450
  case "accepted":
3160
2451
  return r.fix !== void 0 ? [r.fix] : [];
3161
2452
  default:
3162
- return assertNever(r, "Unhandled case");
2453
+ return assertNever3(r, "Unhandled case");
3163
2454
  }
3164
2455
  });
3165
2456
  if (opsToForward.length > 0) {
3166
2457
  scheduleFanOut({
3167
- type: ServerMsgCode.UPDATE_STORAGE,
2458
+ type: ServerMsgCode2.UPDATE_STORAGE,
3168
2459
  ops: opsToForward.map(stripOpId)
3169
2460
  });
3170
2461
  scheduleReply({
3171
- type: ServerMsgCode.UPDATE_STORAGE,
2462
+ type: ServerMsgCode2.UPDATE_STORAGE,
3172
2463
  ops: opsToForward
3173
2464
  });
3174
2465
  }
3175
2466
  if (opsToSendBack.length > 0) {
3176
2467
  replyImmediately({
3177
- type: ServerMsgCode.UPDATE_STORAGE,
2468
+ type: ServerMsgCode2.UPDATE_STORAGE,
3178
2469
  ops: opsToSendBack
3179
2470
  });
3180
2471
  }
@@ -3184,7 +2475,7 @@ var Room = class {
3184
2475
  }
3185
2476
  break;
3186
2477
  }
3187
- case ClientMsgCode.FETCH_YDOC: {
2478
+ case ClientMsgCode2.FETCH_YDOC: {
3188
2479
  const vector = msg.vector;
3189
2480
  const guid = msg.guid;
3190
2481
  const isV2 = msg.v2;
@@ -3195,7 +2486,7 @@ var Room = class {
3195
2486
  ]);
3196
2487
  if (update !== null && snapshotHash !== null) {
3197
2488
  replyImmediately({
3198
- type: ServerMsgCode.UPDATE_YDOC,
2489
+ type: ServerMsgCode2.UPDATE_YDOC,
3199
2490
  update,
3200
2491
  isSync: true,
3201
2492
  // this is no longer used by the client, instead we use the presence of stateVector
@@ -3207,18 +2498,18 @@ var Room = class {
3207
2498
  }
3208
2499
  break;
3209
2500
  }
3210
- case ClientMsgCode.UPDATE_YDOC: {
2501
+ case ClientMsgCode2.UPDATE_YDOC: {
3211
2502
  const update = msg.update;
3212
2503
  const guid = msg.guid;
3213
2504
  const isV2 = msg.v2;
3214
- const [result, error3] = await tryCatch(
2505
+ const [result, error] = await tryCatch(
3215
2506
  this.yjsStorage.addYDocUpdate(this.logger, update, guid, isV2)
3216
2507
  );
3217
- if (error3)
2508
+ if (error)
3218
2509
  break;
3219
2510
  this.sendToAll(
3220
2511
  {
3221
- type: ServerMsgCode.UPDATE_YDOC,
2512
+ type: ServerMsgCode2.UPDATE_YDOC,
3222
2513
  update,
3223
2514
  guid,
3224
2515
  isSync: false,
@@ -3237,7 +2528,7 @@ var Room = class {
3237
2528
  }
3238
2529
  default: {
3239
2530
  try {
3240
- return assertNever(msg, "Unrecognized client msg");
2531
+ return assertNever3(msg, "Unrecognized client msg");
3241
2532
  } catch {
3242
2533
  }
3243
2534
  }
@@ -3250,7 +2541,7 @@ export {
3250
2541
  BackendSession,
3251
2542
  BrowserSession,
3252
2543
  ConsoleTarget,
3253
- DefaultMap2 as DefaultMap,
2544
+ DefaultMap,
3254
2545
  InMemoryDriver,
3255
2546
  LogLevel,
3256
2547
  LogTarget,