@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.cjs 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(() => _optionalChain([unsub, 'optionalCall', _2 => _2()]));
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 = _nullishCoalesce(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
- _optionalChain([trackedReads, 'optionalAccess', _3 => _3.add, 'call', _4 => _4(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 = _nullishCoalesce(_nullishCoalesce(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 && _optionalChain([event, 'access', _5 => _5.data, 'optionalAccess', _6 => _6.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
+ var _core = require('@liveblocks/core');
756
14
 
757
15
 
758
16
 
@@ -774,14 +32,15 @@ var jsonObjectYolo = jsonYolo.refine(
774
32
 
775
33
  // src/decoders/Op.ts
776
34
 
35
+
777
36
  var updateObjectOp = _decoders.object.call(void 0, {
778
- type: _decoders.constant.call(void 0, OpCode.UPDATE_OBJECT),
37
+ type: _decoders.constant.call(void 0, _core.OpCode.UPDATE_OBJECT),
779
38
  opId: _decoders.string,
780
39
  id: _decoders.string,
781
40
  data: jsonObjectYolo
782
41
  });
783
42
  var createObjectOp = _decoders.object.call(void 0, {
784
- type: _decoders.constant.call(void 0, OpCode.CREATE_OBJECT),
43
+ type: _decoders.constant.call(void 0, _core.OpCode.CREATE_OBJECT),
785
44
  opId: _decoders.string,
786
45
  id: _decoders.string,
787
46
  parentId: _decoders.string,
@@ -791,7 +50,7 @@ var createObjectOp = _decoders.object.call(void 0, {
791
50
  deletedId: _decoders.optional.call(void 0, _decoders.string)
792
51
  });
793
52
  var createListOp = _decoders.object.call(void 0, {
794
- type: _decoders.constant.call(void 0, OpCode.CREATE_LIST),
53
+ type: _decoders.constant.call(void 0, _core.OpCode.CREATE_LIST),
795
54
  opId: _decoders.string,
796
55
  id: _decoders.string,
797
56
  parentId: _decoders.string,
@@ -800,7 +59,7 @@ var createListOp = _decoders.object.call(void 0, {
800
59
  deletedId: _decoders.optional.call(void 0, _decoders.string)
801
60
  });
802
61
  var createMapOp = _decoders.object.call(void 0, {
803
- type: _decoders.constant.call(void 0, OpCode.CREATE_MAP),
62
+ type: _decoders.constant.call(void 0, _core.OpCode.CREATE_MAP),
804
63
  opId: _decoders.string,
805
64
  id: _decoders.string,
806
65
  parentId: _decoders.string,
@@ -809,7 +68,7 @@ var createMapOp = _decoders.object.call(void 0, {
809
68
  deletedId: _decoders.optional.call(void 0, _decoders.string)
810
69
  });
811
70
  var createRegisterOp = _decoders.object.call(void 0, {
812
- type: _decoders.constant.call(void 0, OpCode.CREATE_REGISTER),
71
+ type: _decoders.constant.call(void 0, _core.OpCode.CREATE_REGISTER),
813
72
  opId: _decoders.string,
814
73
  id: _decoders.string,
815
74
  parentId: _decoders.string,
@@ -819,31 +78,31 @@ var createRegisterOp = _decoders.object.call(void 0, {
819
78
  deletedId: _decoders.optional.call(void 0, _decoders.string)
820
79
  });
821
80
  var deleteCrdtOp = _decoders.object.call(void 0, {
822
- type: _decoders.constant.call(void 0, OpCode.DELETE_CRDT),
81
+ type: _decoders.constant.call(void 0, _core.OpCode.DELETE_CRDT),
823
82
  opId: _decoders.string,
824
83
  id: _decoders.string
825
84
  });
826
85
  var setParentKeyOp = _decoders.object.call(void 0, {
827
- type: _decoders.constant.call(void 0, OpCode.SET_PARENT_KEY),
86
+ type: _decoders.constant.call(void 0, _core.OpCode.SET_PARENT_KEY),
828
87
  opId: _decoders.string,
829
88
  id: _decoders.string,
830
89
  parentKey: _decoders.string
831
90
  });
832
91
  var deleteObjectKeyOp = _decoders.object.call(void 0, {
833
- type: _decoders.constant.call(void 0, OpCode.DELETE_OBJECT_KEY),
92
+ type: _decoders.constant.call(void 0, _core.OpCode.DELETE_OBJECT_KEY),
834
93
  opId: _decoders.string,
835
94
  id: _decoders.string,
836
95
  key: _decoders.string
837
96
  });
838
97
  var op = _decoders.taggedUnion.call(void 0, "type", {
839
- [OpCode.UPDATE_OBJECT]: updateObjectOp,
840
- [OpCode.CREATE_OBJECT]: createObjectOp,
841
- [OpCode.CREATE_LIST]: createListOp,
842
- [OpCode.CREATE_MAP]: createMapOp,
843
- [OpCode.CREATE_REGISTER]: createRegisterOp,
844
- [OpCode.DELETE_CRDT]: deleteCrdtOp,
845
- [OpCode.SET_PARENT_KEY]: setParentKeyOp,
846
- [OpCode.DELETE_OBJECT_KEY]: deleteObjectKeyOp
98
+ [_core.OpCode.UPDATE_OBJECT]: updateObjectOp,
99
+ [_core.OpCode.CREATE_OBJECT]: createObjectOp,
100
+ [_core.OpCode.CREATE_LIST]: createListOp,
101
+ [_core.OpCode.CREATE_MAP]: createMapOp,
102
+ [_core.OpCode.CREATE_REGISTER]: createRegisterOp,
103
+ [_core.OpCode.DELETE_CRDT]: deleteCrdtOp,
104
+ [_core.OpCode.SET_PARENT_KEY]: setParentKeyOp,
105
+ [_core.OpCode.DELETE_OBJECT_KEY]: deleteObjectKeyOp
847
106
  });
848
107
 
849
108
  // src/decoders/y-types.ts
@@ -853,53 +112,54 @@ var ROOT_YDOC_ID = "root";
853
112
 
854
113
  // src/decoders/ClientMsg.ts
855
114
  var updatePresenceClientMsg = _decoders.object.call(void 0, {
856
- type: _decoders.constant.call(void 0, ClientMsgCode.UPDATE_PRESENCE),
115
+ type: _decoders.constant.call(void 0, _core.ClientMsgCode.UPDATE_PRESENCE),
857
116
  data: jsonObjectYolo,
858
117
  targetActor: _decoders.optional.call(void 0, _decoders.number)
859
118
  });
860
119
  var broadcastEventClientMsg = _decoders.object.call(void 0, {
861
- type: _decoders.constant.call(void 0, ClientMsgCode.BROADCAST_EVENT),
120
+ type: _decoders.constant.call(void 0, _core.ClientMsgCode.BROADCAST_EVENT),
862
121
  event: jsonYolo
863
122
  });
864
123
  var fetchStorageClientMsg = _decoders.object.call(void 0, {
865
- type: _decoders.constant.call(void 0, ClientMsgCode.FETCH_STORAGE)
124
+ type: _decoders.constant.call(void 0, _core.ClientMsgCode.FETCH_STORAGE)
866
125
  });
867
126
  var updateStorageClientMsg = _decoders.object.call(void 0, {
868
- type: _decoders.constant.call(void 0, ClientMsgCode.UPDATE_STORAGE),
127
+ type: _decoders.constant.call(void 0, _core.ClientMsgCode.UPDATE_STORAGE),
869
128
  ops: _decoders.array.call(void 0, op)
870
129
  });
871
130
  var fetchYDocClientMsg = _decoders.object.call(void 0, {
872
- type: _decoders.constant.call(void 0, ClientMsgCode.FETCH_YDOC),
131
+ type: _decoders.constant.call(void 0, _core.ClientMsgCode.FETCH_YDOC),
873
132
  vector: _decoders.string.refineType(),
874
133
  guid: _decoders.optional.call(void 0, guidDecoder),
875
134
  // Don't specify to update the root doc
876
135
  v2: _decoders.optional.call(void 0, _decoders.boolean)
877
136
  });
878
137
  var updateYDocClientMsg = _decoders.object.call(void 0, {
879
- type: _decoders.constant.call(void 0, ClientMsgCode.UPDATE_YDOC),
138
+ type: _decoders.constant.call(void 0, _core.ClientMsgCode.UPDATE_YDOC),
880
139
  update: _decoders.string.refineType(),
881
140
  guid: _decoders.optional.call(void 0, guidDecoder),
882
141
  // Don't specify to update the root doc
883
142
  v2: _decoders.optional.call(void 0, _decoders.boolean)
884
143
  });
885
144
  var clientMsgDecoder = _decoders.taggedUnion.call(void 0, "type", {
886
- [ClientMsgCode.UPDATE_PRESENCE]: updatePresenceClientMsg,
887
- [ClientMsgCode.BROADCAST_EVENT]: broadcastEventClientMsg,
888
- [ClientMsgCode.FETCH_STORAGE]: fetchStorageClientMsg,
889
- [ClientMsgCode.UPDATE_STORAGE]: updateStorageClientMsg,
890
- [ClientMsgCode.FETCH_YDOC]: fetchYDocClientMsg,
891
- [ClientMsgCode.UPDATE_YDOC]: updateYDocClientMsg
145
+ [_core.ClientMsgCode.UPDATE_PRESENCE]: updatePresenceClientMsg,
146
+ [_core.ClientMsgCode.BROADCAST_EVENT]: broadcastEventClientMsg,
147
+ [_core.ClientMsgCode.FETCH_STORAGE]: fetchStorageClientMsg,
148
+ [_core.ClientMsgCode.UPDATE_STORAGE]: updateStorageClientMsg,
149
+ [_core.ClientMsgCode.FETCH_YDOC]: fetchYDocClientMsg,
150
+ [_core.ClientMsgCode.UPDATE_YDOC]: updateYDocClientMsg
892
151
  }).describe("Must be a valid client message");
893
152
  var transientClientMsgDecoder = _decoders.taggedUnion.call(void 0, "type", {
894
153
  // [ClientMsgCode.UPDATE_PRESENCE]: updatePresenceClientMsg,
895
154
  // [ClientMsgCode.BROADCAST_EVENT]: broadcastEventClientMsg,
896
155
  // [ClientMsgCode.FETCH_STORAGE]: fetchStorageClientMsg,
897
- [ClientMsgCode.UPDATE_STORAGE]: updateStorageClientMsg
156
+ [_core.ClientMsgCode.UPDATE_STORAGE]: updateStorageClientMsg
898
157
  // [ClientMsgCode.FETCH_YDOC]: fetchYDocClientMsg,
899
158
  // [ClientMsgCode.UPDATE_YDOC]: updateYDocClientMsg,
900
159
  }).describe("Must be a valid transient client message");
901
160
 
902
161
  // src/formats/LossyJson.ts
162
+
903
163
  function snapshotToLossyJson_eager(snapshot2) {
904
164
  try {
905
165
  return buildObject(snapshot2, "root", snapshot2.get_root().data);
@@ -909,11 +169,11 @@ function snapshotToLossyJson_eager(snapshot2) {
909
169
  }
910
170
  function buildNode(snapshot2, id) {
911
171
  const node = snapshot2.get_node(id);
912
- if (node.type === CrdtType.OBJECT) {
172
+ if (node.type === _core.CrdtType.OBJECT) {
913
173
  return buildObject(snapshot2, id, node.data);
914
- } else if (node.type === CrdtType.LIST) {
174
+ } else if (node.type === _core.CrdtType.LIST) {
915
175
  return buildList(snapshot2, id);
916
- } else if (node.type === CrdtType.MAP) {
176
+ } else if (node.type === _core.CrdtType.MAP) {
917
177
  return buildMap(snapshot2, id);
918
178
  } else {
919
179
  return node.data;
@@ -950,13 +210,13 @@ function* snapshotToLossyJson_lazy(snapshot2) {
950
210
  }
951
211
  function* emit(snapshot2, id) {
952
212
  const node = snapshot2.get_node(id);
953
- if (node.type === CrdtType.OBJECT) {
213
+ if (node.type === _core.CrdtType.OBJECT) {
954
214
  yield* emitObject(snapshot2, id, JSON.stringify(node.data).slice(1, -1));
955
- } else if (node.type === CrdtType.LIST) {
215
+ } else if (node.type === _core.CrdtType.LIST) {
956
216
  yield* emitList(snapshot2, id);
957
- } else if (node.type === CrdtType.MAP) {
217
+ } else if (node.type === _core.CrdtType.MAP) {
958
218
  yield* emitMap(snapshot2, id);
959
- } else if (node.type === CrdtType.REGISTER) {
219
+ } else if (node.type === _core.CrdtType.REGISTER) {
960
220
  yield JSON.stringify(node.data);
961
221
  }
962
222
  }
@@ -1004,12 +264,18 @@ function* snapshotToNodeStream(snapshot2) {
1004
264
  }
1005
265
 
1006
266
  // src/formats/PlainLson.ts
267
+
268
+
269
+
270
+
271
+
272
+
1007
273
  var SERVER_INIT_OP_PREFIX = "si";
1008
274
  function generateId(state) {
1009
275
  return `${SERVER_INIT_OP_PREFIX}:${state.clock++}`;
1010
276
  }
1011
277
  function isSpecialPlainLsonValue(value) {
1012
- return isJsonObject(value) && value.liveblocksType !== void 0;
278
+ return _core.isJsonObject.call(void 0, value) && value.liveblocksType !== void 0;
1013
279
  }
1014
280
  function* iterJson(key, data, parent, state) {
1015
281
  if (isSpecialPlainLsonValue(data)) {
@@ -1024,13 +290,13 @@ function* iterJson(key, data, parent, state) {
1024
290
  yield* iterMap(key, data.data, parent, state);
1025
291
  return;
1026
292
  default:
1027
- assertNever(data, "Unknown `liveblocksType` field");
293
+ _core.assertNever.call(void 0, data, "Unknown `liveblocksType` field");
1028
294
  }
1029
295
  } else {
1030
296
  yield [
1031
297
  generateId(state),
1032
298
  {
1033
- type: CrdtType.REGISTER,
299
+ type: _core.CrdtType.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: _core.CrdtType.MAP, parentId: parent[0], parentKey: key }
1045
311
  ];
1046
312
  yield mapTuple;
1047
313
  for (const [subKey, subValue] of Object.entries(map)) {
@@ -1051,16 +317,16 @@ 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: _core.CrdtType.LIST,
1055
321
  parentId: parent[0],
1056
322
  parentKey: key
1057
323
  };
1058
324
  const listTuple = [id, crdt];
1059
325
  yield listTuple;
1060
- let position = makePosition();
326
+ let position = _core.makePosition.call(void 0, );
1061
327
  for (const subValue of list) {
1062
328
  yield* iterJson(position, subValue, listTuple, state);
1063
- position = makePosition(position);
329
+ position = _core.makePosition.call(void 0, position);
1064
330
  }
1065
331
  }
1066
332
  function* iterObjectInner(key, value, parent, state) {
@@ -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: _core.CrdtType.OBJECT,
1080
346
  data,
1081
347
  parentId: parent[0],
1082
348
  parentKey: key
1083
349
  }
1084
- ] : ["root", { type: CrdtType.OBJECT, data }];
350
+ ] : ["root", { type: _core.CrdtType.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 === _core.CrdtType.OBJECT) {
1104
370
  return buildObject2(snapshot2, id, node.data);
1105
- } else if (node.type === CrdtType.LIST) {
371
+ } else if (node.type === _core.CrdtType.LIST) {
1106
372
  return buildList2(snapshot2, id);
1107
- } else if (node.type === CrdtType.MAP) {
373
+ } else if (node.type === _core.CrdtType.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 === _core.CrdtType.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 === _core.CrdtType.LIST) {
1150
416
  yield* emitList2(snapshot2, id);
1151
- } else if (node.type === CrdtType.MAP) {
417
+ } else if (node.type === _core.CrdtType.MAP) {
1152
418
  yield* emitMap2(snapshot2, id);
1153
- } else if (node.type === CrdtType.REGISTER) {
419
+ } else if (node.type === _core.CrdtType.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
+
459
+
1191
460
  // src/lib/DefaultMap.ts
1192
- var _defaultFn2;
1193
- var DefaultMap2 = class extends Map {
461
+
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 = _nullishCoalesce(_nullishCoalesce(defaultFn, () => ( __privateGet(this, _defaultFn2))), () => ( raise("DefaultMap used without a factory function")));
484
+ const fn = _nullishCoalesce(_nullishCoalesce(defaultFn, () => ( __privateGet(this, _defaultFn))), () => ( _core.raise.call(void 0, "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;
@@ -1238,7 +508,7 @@ var NestedMap = class {
1238
508
  return total;
1239
509
  }
1240
510
  count(key1) {
1241
- return _nullishCoalesce(_optionalChain([__privateGet, 'call', _7 => _7(this, _map), 'access', _8 => _8.get, 'call', _9 => _9(key1), 'optionalAccess', _10 => _10.size]), () => ( 0));
511
+ return _nullishCoalesce(_optionalChain([__privateGet, 'call', _2 => _2(this, _map), 'access', _3 => _3.get, 'call', _4 => _4(key1), 'optionalAccess', _5 => _5.size]), () => ( 0));
1242
512
  }
1243
513
  *keys() {
1244
514
  for (const [key1, nested] of __privateGet(this, _map)) {
@@ -1248,10 +518,10 @@ var NestedMap = class {
1248
518
  }
1249
519
  }
1250
520
  has(key1, key2) {
1251
- return _nullishCoalesce(_optionalChain([__privateGet, 'call', _11 => _11(this, _map), 'access', _12 => _12.get, 'call', _13 => _13(key1), 'optionalAccess', _14 => _14.has, 'call', _15 => _15(key2)]), () => ( false));
521
+ return _nullishCoalesce(_optionalChain([__privateGet, 'call', _6 => _6(this, _map), 'access', _7 => _7.get, 'call', _8 => _8(key1), 'optionalAccess', _9 => _9.has, 'call', _10 => _10(key2)]), () => ( false));
1252
522
  }
1253
523
  get(key1, key2) {
1254
- return _optionalChain([__privateGet, 'call', _16 => _16(this, _map), 'access', _17 => _17.get, 'call', _18 => _18(key1), 'optionalAccess', _19 => _19.get, 'call', _20 => _20(key2)]);
524
+ return _optionalChain([__privateGet, 'call', _11 => _11(this, _map), 'access', _12 => _12.get, 'call', _13 => _13(key1), 'optionalAccess', _14 => _14.get, 'call', _15 => _15(key2)]);
1255
525
  }
1256
526
  set(key1, key2, value) {
1257
527
  __privateGet(this, _map).getOrCreate(key1).set(key2, value);
@@ -1278,7 +548,7 @@ var NestedMap = class {
1278
548
  }
1279
549
  }
1280
550
  entriesAt(key1) {
1281
- return _nullishCoalesce(_optionalChain([__privateGet, 'call', _21 => _21(this, _map), 'access', _22 => _22.get, 'call', _23 => _23(key1), 'optionalAccess', _24 => _24.entries, 'call', _25 => _25()]), () => ( emptyIterator()));
551
+ return _nullishCoalesce(_optionalChain([__privateGet, 'call', _16 => _16(this, _map), 'access', _17 => _17.get, 'call', _18 => _18(key1), 'optionalAccess', _19 => _19.entries, 'call', _20 => _20()]), () => ( emptyIterator()));
1282
552
  }
1283
553
  *filterAt(key1, keys) {
1284
554
  const nested = __privateGet(this, _map).get(key1);
@@ -1293,10 +563,10 @@ var NestedMap = class {
1293
563
  }
1294
564
  }
1295
565
  keysAt(key1) {
1296
- return _nullishCoalesce(_optionalChain([__privateGet, 'call', _26 => _26(this, _map), 'access', _27 => _27.get, 'call', _28 => _28(key1), 'optionalAccess', _29 => _29.keys, 'call', _30 => _30()]), () => ( emptyIterator()));
566
+ return _nullishCoalesce(_optionalChain([__privateGet, 'call', _21 => _21(this, _map), 'access', _22 => _22.get, 'call', _23 => _23(key1), 'optionalAccess', _24 => _24.keys, 'call', _25 => _25()]), () => ( emptyIterator()));
1297
567
  }
1298
568
  valuesAt(key1) {
1299
- return _nullishCoalesce(_optionalChain([__privateGet, 'call', _31 => _31(this, _map), 'access', _32 => _32.get, 'call', _33 => _33(key1), 'optionalAccess', _34 => _34.values, 'call', _35 => _35()]), () => ( emptyIterator()));
569
+ return _nullishCoalesce(_optionalChain([__privateGet, 'call', _26 => _26(this, _map), 'access', _27 => _27.get, 'call', _28 => _28(key1), 'optionalAccess', _29 => _29.values, 'call', _30 => _30()]), () => ( emptyIterator()));
1300
570
  }
1301
571
  deleteAll(key1) {
1302
572
  __privateGet(this, _map).delete(key1);
@@ -1308,12 +578,12 @@ _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: _core.CrdtType.OBJECT, data: {} });
1312
582
  }
1313
583
  const entries = [];
1314
584
  const nodeStream = map;
1315
585
  for (const node of nodeStream) {
1316
- if (isRootStorageNode(node)) continue;
586
+ if (_core.isRootStorageNode.call(void 0, node)) continue;
1317
587
  const [id, crdt] = node;
1318
588
  entries.push([crdt.parentId, crdt.parentKey, id]);
1319
589
  }
@@ -1325,10 +595,10 @@ function makeInMemorySnapshot(values) {
1325
595
  revMap.set(parentId, parentKey, id);
1326
596
  }
1327
597
  function get_node(id) {
1328
- return nn(map.get(id), `Node not found: ${id}`);
598
+ return _core.nn.call(void 0, map.get(id), `Node not found: ${id}`);
1329
599
  }
1330
600
  return {
1331
- get_root: () => nn(
601
+ get_root: () => _core.nn.call(void 0,
1332
602
  map.get("root"),
1333
603
  "Root not found"
1334
604
  ),
@@ -1370,12 +640,23 @@ var protocolVersionDecoder = _decoders.enum_.call(void 0, ProtocolVersion).descr
1370
640
  );
1371
641
 
1372
642
  // src/Room.ts
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
1373
653
  var _asyncmutex = require('async-mutex');
1374
654
 
1375
655
  var _itertools = require('itertools');
1376
656
  var _nanoid = require('nanoid');
1377
657
 
1378
658
  // src/lib/Logger.ts
659
+
1379
660
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1380
661
  LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
1381
662
  LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
@@ -1385,7 +666,7 @@ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1385
666
  })(LogLevel || {});
1386
667
  function formatError(err) {
1387
668
  const prefix = `${err.name}: ${err.message}`;
1388
- return (_optionalChain([err, 'access', _36 => _36.stack, 'optionalAccess', _37 => _37.startsWith, 'call', _38 => _38(prefix)]) ? err.stack : `${prefix}
669
+ return (_optionalChain([err, 'access', _31 => _31.stack, 'optionalAccess', _32 => _32.startsWith, 'call', _33 => _33(prefix)]) ? err.stack : `${prefix}
1389
670
  ${_nullishCoalesce(err.stack, () => ( ""))}`).trimEnd();
1390
671
  }
1391
672
  var _cache;
@@ -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 _core.raise.call(void 0, "Invalid log level");
1411
692
  }
1412
693
  }
1413
694
  /** Helper for formatting an Arg */
@@ -1510,6 +791,7 @@ var Logger = class _Logger {
1510
791
  // src/plugins/InMemoryDriver.ts
1511
792
 
1512
793
 
794
+
1513
795
  // src/lib/text.ts
1514
796
  function quote(value) {
1515
797
  return value !== void 0 ? `'${value}'` : "???";
@@ -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 (_core.isRootStorageNode.call(void 0, 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 = _core.nn.call(void 0, nodes.get(nodeId));
820
+ if (node.type === _core.CrdtType.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 !== _core.CrdtType.REGISTER) {
1544
826
  queue.push(...revNodes.valuesAt(nodeId));
1545
827
  } else {
1546
828
  const parent = nodes.get(node.parentId);
1547
- if (_optionalChain([parent, 'optionalAccess', _39 => _39.type]) === CrdtType.OBJECT) {
829
+ if (_optionalChain([parent, 'optionalAccess', _34 => _34.type]) === _core.CrdtType.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 === _core.CrdtType.OBJECT && Object.prototype.hasOwnProperty.call(node.data, key) && node.data[key] !== void 0;
1564
846
  }
1565
847
  var InMemoryDriver = class {
1566
848
  constructor(options) {
@@ -1571,8 +853,8 @@ var InMemoryDriver = class {
1571
853
  this._nodes = /* @__PURE__ */ new Map();
1572
854
  this._metadb = /* @__PURE__ */ new Map();
1573
855
  this._ydb = /* @__PURE__ */ new Map();
1574
- this._nextActor = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _40 => _40.initialActor]), () => ( -1));
1575
- for (const [key, value] of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _41 => _41.initialNodes]), () => ( []))) {
856
+ this._nextActor = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _35 => _35.initialActor]), () => ( -1));
857
+ for (const [key, value] of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _36 => _36.initialNodes]), () => ( []))) {
1576
858
  this._nodes.set(key, value);
1577
859
  }
1578
860
  }
@@ -1621,13 +903,13 @@ 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: _core.CrdtType.OBJECT, data: {} });
1625
907
  }
1626
908
  const revNodes = buildReverseLookup(nodes);
1627
909
  function get_next_sibling(parentId, pos) {
1628
910
  let nextPos;
1629
911
  for (const siblingKey of revNodes.keysAt(parentId)) {
1630
- const siblingPos = asPos(siblingKey);
912
+ const siblingPos = _core.asPos.call(void 0, siblingKey);
1631
913
  if (siblingPos > pos && (nextPos === void 0 || siblingPos < nextPos)) {
1632
914
  nextPos = siblingPos;
1633
915
  }
@@ -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 === _core.CrdtType.REGISTER && parentNode.type === _core.CrdtType.OBJECT) {
1643
925
  throw new Error("Cannot add register under object");
1644
926
  }
1645
927
  const conflictingSiblingId = revNodes.get(node.parentId, node.parentKey);
@@ -1659,7 +941,7 @@ var InMemoryDriver = class {
1659
941
  }
1660
942
  async function move_sibling(id, newPos) {
1661
943
  const node = nodes.get(id);
1662
- if (_optionalChain([node, 'optionalAccess', _42 => _42.parentId]) === void 0) {
944
+ if (_optionalChain([node, 'optionalAccess', _37 => _37.parentId]) === void 0) {
1663
945
  return;
1664
946
  }
1665
947
  if (revNodes.has(node.parentId, newPos))
@@ -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 (_optionalChain([node, 'optionalAccess', _43 => _43.type]) !== CrdtType.OBJECT) {
956
+ if (_optionalChain([node, 'optionalAccess', _38 => _38.type]) !== _core.CrdtType.OBJECT) {
1675
957
  return;
1676
958
  }
1677
959
  for (const key of Object.keys(data)) {
@@ -1688,7 +970,7 @@ var InMemoryDriver = class {
1688
970
  }
1689
971
  function delete_node(id) {
1690
972
  const node = nodes.get(id);
1691
- if (_optionalChain([node, 'optionalAccess', _44 => _44.parentId]) === void 0) {
973
+ if (_optionalChain([node, 'optionalAccess', _39 => _39.parentId]) === void 0) {
1692
974
  return;
1693
975
  }
1694
976
  revNodes.delete(node.parentId, node.parentKey);
@@ -1799,6 +1081,13 @@ function makeNewInMemoryDriver(options) {
1799
1081
  }
1800
1082
 
1801
1083
  // src/Storage.ts
1084
+
1085
+
1086
+
1087
+
1088
+
1089
+
1090
+
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 _core.OpCode.CREATE_LIST:
1811
1100
  return {
1812
- type: CrdtType.LIST,
1101
+ type: _core.CrdtType.LIST,
1813
1102
  parentId: op2.parentId,
1814
1103
  parentKey: op2.parentKey
1815
1104
  };
1816
- case OpCode.CREATE_MAP:
1105
+ case _core.OpCode.CREATE_MAP:
1817
1106
  return {
1818
- type: CrdtType.MAP,
1107
+ type: _core.CrdtType.MAP,
1819
1108
  parentId: op2.parentId,
1820
1109
  parentKey: op2.parentKey
1821
1110
  };
1822
- case OpCode.CREATE_OBJECT:
1111
+ case _core.OpCode.CREATE_OBJECT:
1823
1112
  return {
1824
- type: CrdtType.OBJECT,
1113
+ type: _core.CrdtType.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 _core.OpCode.CREATE_REGISTER:
1830
1119
  return {
1831
- type: CrdtType.REGISTER,
1120
+ type: _core.CrdtType.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 _core.assertNever.call(void 0, 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 _core.OpCode.CREATE_LIST:
1181
+ case _core.OpCode.CREATE_MAP:
1182
+ case _core.OpCode.CREATE_REGISTER:
1183
+ case _core.OpCode.CREATE_OBJECT:
1895
1184
  return await this.applyCreateOp(op2);
1896
- case OpCode.UPDATE_OBJECT:
1185
+ case _core.OpCode.UPDATE_OBJECT:
1897
1186
  return await this.applyUpdateObjectOp(op2);
1898
- case OpCode.SET_PARENT_KEY:
1187
+ case _core.OpCode.SET_PARENT_KEY:
1899
1188
  return await this.applySetParentKeyOp(op2);
1900
- case OpCode.DELETE_OBJECT_KEY:
1189
+ case _core.OpCode.DELETE_OBJECT_KEY:
1901
1190
  return await this.applyDeleteObjectKeyOp(op2);
1902
- case OpCode.DELETE_CRDT:
1191
+ case _core.OpCode.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 _core.assertNever.call(void 0, 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 _core.CrdtType.OBJECT:
1212
+ if (op2.type === _core.OpCode.CREATE_REGISTER) {
1924
1213
  return ignore(op2);
1925
1214
  }
1926
- case CrdtType.MAP:
1215
+ case _core.CrdtType.MAP:
1927
1216
  await this.loadedDriver.set_child(op2.id, node, true);
1928
1217
  return accept(op2);
1929
- case CrdtType.LIST:
1218
+ case _core.CrdtType.LIST:
1930
1219
  return this.createChildAsListItem(op2, node);
1931
- case CrdtType.REGISTER:
1220
+ case _core.CrdtType.REGISTER:
1932
1221
  return ignore(op2);
1933
1222
  default:
1934
- return assertNever(parent, "Unhandled CRDT type");
1223
+ return _core.assertNever.call(void 0, 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: _core.OpCode.SET_PARENT_KEY,
1946
1235
  id: op2.id,
1947
1236
  parentKey: insertedParentKey
1948
1237
  };
@@ -1950,7 +1239,7 @@ var Storage = class {
1950
1239
  }
1951
1240
  return accept(op2);
1952
1241
  } else if (intent === "set") {
1953
- const deletedId = op2.deletedId !== void 0 && op2.deletedId !== op2.id && _optionalChain([this, 'access', _45 => _45.loadedDriver, 'access', _46 => _46.get_node, 'call', _47 => _47(op2.deletedId), 'optionalAccess', _48 => _48.parentId]) === node.parentId ? op2.deletedId : void 0;
1242
+ const deletedId = op2.deletedId !== void 0 && op2.deletedId !== op2.id && _optionalChain([this, 'access', _40 => _40.loadedDriver, 'access', _41 => _41.get_node, 'call', _42 => _42(op2.deletedId), 'optionalAccess', _43 => _43.parentId]) === node.parentId ? op2.deletedId : void 0;
1954
1243
  if (deletedId !== void 0) {
1955
1244
  await this.loadedDriver.delete_node(deletedId);
1956
1245
  }
@@ -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: _core.OpCode.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 _core.assertNever.call(void 0, 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: _core.OpCode.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, _core.asPos.call(void 0, node.parentKey));
2012
1301
  if (key !== node.parentKey) {
2013
1302
  node = { ...node, parentKey: key };
2014
1303
  }
@@ -2029,16 +1318,16 @@ var Storage = class {
2029
1318
  */
2030
1319
  async moveToPosInList(id, targetKey) {
2031
1320
  const node = this.loadedDriver.get_node(id);
2032
- if (_optionalChain([node, 'optionalAccess', _49 => _49.parentId]) === void 0) {
1321
+ if (_optionalChain([node, 'optionalAccess', _44 => _44.parentId]) === void 0) {
2033
1322
  return;
2034
1323
  }
2035
- if (_optionalChain([this, 'access', _50 => _50.loadedDriver, 'access', _51 => _51.get_node, 'call', _52 => _52(node.parentId), 'optionalAccess', _53 => _53.type]) !== CrdtType.LIST) {
1324
+ if (_optionalChain([this, 'access', _45 => _45.loadedDriver, 'access', _46 => _46.get_node, 'call', _47 => _47(node.parentId), 'optionalAccess', _48 => _48.type]) !== _core.CrdtType.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, _core.asPos.call(void 0, 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 _core.makePosition.call(void 0, currPos, nextPos);
2062
1351
  } else {
2063
- return makePosition(currPos);
1352
+ return _core.makePosition.call(void 0, currPos);
2064
1353
  }
2065
1354
  }
2066
1355
  };
2067
1356
 
2068
1357
  // src/YjsStorage.ts
1358
+
2069
1359
  var _jsbase64 = require('js-base64');
2070
1360
 
2071
1361
  var _yjs = require('yjs'); var Y = _interopRequireWildcard(_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 (0, _core.DefaultMap)(
2082
1372
  () => /* @__PURE__ */ new Set()
2083
1373
  ));
2084
1374
  __publicField(this, "initPromisesById", /* @__PURE__ */ new Map());
@@ -2284,9 +1574,9 @@ var YjsStorage = class {
2284
1574
  const docUpdateInfo = this.lastUpdatesById.get(docId);
2285
1575
  const updateSinceLastVector = Y.encodeStateAsUpdate(
2286
1576
  doc,
2287
- _optionalChain([docUpdateInfo, 'optionalAccess', _54 => _54.lastVector])
1577
+ _optionalChain([docUpdateInfo, 'optionalAccess', _49 => _49.lastVector])
2288
1578
  );
2289
- const storageKey = _nullishCoalesce(_optionalChain([docUpdateInfo, 'optionalAccess', _55 => _55.currentKey]), () => ( _nanoid.nanoid.call(void 0, )));
1579
+ const storageKey = _nullishCoalesce(_optionalChain([docUpdateInfo, 'optionalAccess', _50 => _50.currentKey]), () => ( _nanoid.nanoid.call(void 0, )));
2290
1580
  if (updateSinceLastVector.length > MAX_Y_UPDATE_SIZE) {
2291
1581
  const newKey = _nanoid.nanoid.call(void 0, );
2292
1582
  await this.driver.write_y_updates(
@@ -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
+
2373
1664
  function concatUint8Arrays(arrays) {
2374
1665
  const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
2375
1666
  const result = new Uint8Array(totalLength);
@@ -2382,7 +1673,7 @@ function concatUint8Arrays(arrays) {
2382
1673
  }
2383
1674
  function makeRoomStateMsg(actor, nonce, scopes, users, publicMeta) {
2384
1675
  return {
2385
- type: ServerMsgCode.ROOM_STATE,
1676
+ type: _core.ServerMsgCode.ROOM_STATE,
2386
1677
  actor,
2387
1678
  nonce,
2388
1679
  scopes,
@@ -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(_core.ServerMsgCode).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: _core.OpCode.DELETE_CRDT, id: "ACK", opId };
2419
1710
  }
2420
1711
  function stripOpId(op2) {
2421
1712
  const { opId: _, ...rest } = op2;
@@ -2459,7 +1750,7 @@ var BrowserSession = class {
2459
1750
  __privateSet(this, __hasNotifiedClientStorageUpdateError, false);
2460
1751
  }
2461
1752
  get lastActiveAt() {
2462
- const lastPing = _optionalChain([__privateGet, 'call', _56 => _56(this, __socket), 'access', _57 => _57.getLastPongTimestamp, 'optionalCall', _58 => _58()]);
1753
+ const lastPing = _optionalChain([__privateGet, 'call', _51 => _51(this, __socket), 'access', _52 => _52.getLastPongTimestamp, 'optionalCall', _53 => _53()]);
2463
1754
  if (lastPing && lastPing > __privateGet(this, __lastActiveAt)) {
2464
1755
  return lastPing;
2465
1756
  } else {
@@ -2551,28 +1842,28 @@ var Room = class {
2551
1842
  __publicField(this, "hooks");
2552
1843
  __privateAdd(this, __debug2);
2553
1844
  __privateAdd(this, __allowStreaming);
2554
- const driver = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _59 => _59.storage]), () => ( makeNewInMemoryDriver()));
1845
+ const driver = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _54 => _54.storage]), () => ( makeNewInMemoryDriver()));
2555
1846
  this.meta = meta;
2556
1847
  this.driver = driver;
2557
- this.logger = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _60 => _60.logger]), () => ( BLACK_HOLE));
2558
- __privateSet(this, __allowStreaming, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _61 => _61.allowStreaming]), () => ( true)));
1848
+ this.logger = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _55 => _55.logger]), () => ( BLACK_HOLE));
1849
+ __privateSet(this, __allowStreaming, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _56 => _56.allowStreaming]), () => ( true)));
2559
1850
  this.hooks = {
2560
- isClientMsgAllowed: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _62 => _62.hooks, 'optionalAccess', _63 => _63.isClientMsgAllowed]), () => ( (() => {
1851
+ isClientMsgAllowed: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _57 => _57.hooks, 'optionalAccess', _58 => _58.isClientMsgAllowed]), () => ( (() => {
2561
1852
  return {
2562
1853
  allowed: true
2563
1854
  };
2564
1855
  }))),
2565
1856
  // YYY .load() isn't called on the RoomServer yet! As soon as it does, these hooks will get called
2566
- onRoomWillLoad: _optionalChain([options, 'optionalAccess', _64 => _64.hooks, 'optionalAccess', _65 => _65.onRoomWillLoad]),
2567
- onRoomDidLoad: _optionalChain([options, 'optionalAccess', _66 => _66.hooks, 'optionalAccess', _67 => _67.onRoomDidLoad]),
2568
- onRoomWillUnload: _optionalChain([options, 'optionalAccess', _68 => _68.hooks, 'optionalAccess', _69 => _69.onRoomWillUnload]),
2569
- onRoomDidUnload: _optionalChain([options, 'optionalAccess', _70 => _70.hooks, 'optionalAccess', _71 => _71.onRoomDidUnload]),
2570
- onSessionDidStart: _optionalChain([options, 'optionalAccess', _72 => _72.hooks, 'optionalAccess', _73 => _73.onSessionDidStart]),
2571
- onSessionDidEnd: _optionalChain([options, 'optionalAccess', _74 => _74.hooks, 'optionalAccess', _75 => _75.onSessionDidEnd]),
2572
- postClientMsgStorageDidUpdate: _optionalChain([options, 'optionalAccess', _76 => _76.hooks, 'optionalAccess', _77 => _77.postClientMsgStorageDidUpdate]),
2573
- postClientMsgYdocDidUpdate: _optionalChain([options, 'optionalAccess', _78 => _78.hooks, 'optionalAccess', _79 => _79.postClientMsgYdocDidUpdate])
1857
+ onRoomWillLoad: _optionalChain([options, 'optionalAccess', _59 => _59.hooks, 'optionalAccess', _60 => _60.onRoomWillLoad]),
1858
+ onRoomDidLoad: _optionalChain([options, 'optionalAccess', _61 => _61.hooks, 'optionalAccess', _62 => _62.onRoomDidLoad]),
1859
+ onRoomWillUnload: _optionalChain([options, 'optionalAccess', _63 => _63.hooks, 'optionalAccess', _64 => _64.onRoomWillUnload]),
1860
+ onRoomDidUnload: _optionalChain([options, 'optionalAccess', _65 => _65.hooks, 'optionalAccess', _66 => _66.onRoomDidUnload]),
1861
+ onSessionDidStart: _optionalChain([options, 'optionalAccess', _67 => _67.hooks, 'optionalAccess', _68 => _68.onSessionDidStart]),
1862
+ onSessionDidEnd: _optionalChain([options, 'optionalAccess', _69 => _69.hooks, 'optionalAccess', _70 => _70.onSessionDidEnd]),
1863
+ postClientMsgStorageDidUpdate: _optionalChain([options, 'optionalAccess', _71 => _71.hooks, 'optionalAccess', _72 => _72.postClientMsgStorageDidUpdate]),
1864
+ postClientMsgYdocDidUpdate: _optionalChain([options, 'optionalAccess', _73 => _73.hooks, 'optionalAccess', _74 => _74.postClientMsgYdocDidUpdate])
2574
1865
  };
2575
- __privateSet(this, __debug2, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _80 => _80.enableDebugLogging]), () => ( false)));
1866
+ __privateSet(this, __debug2, _nullishCoalesce(_optionalChain([options, 'optionalAccess', _75 => _75.enableDebugLogging]), () => ( false)));
2576
1867
  }
2577
1868
  get loadingState() {
2578
1869
  if (this._loadData$ === null) {
@@ -2600,7 +1891,7 @@ var Room = class {
2600
1891
  }
2601
1892
  // prettier-ignore
2602
1893
  get data() {
2603
- return _nullishCoalesce(this._data, () => ( raise("Cannot use room before it's loaded")));
1894
+ return _nullishCoalesce(this._data, () => ( _core.raise.call(void 0, "Cannot use room before it's loaded")));
2604
1895
  }
2605
1896
  // prettier-ignore
2606
1897
  // ------------------------------------------------------------------------------------
@@ -2628,13 +1919,13 @@ var Room = class {
2628
1919
  * room will be reloaded from storage.
2629
1920
  */
2630
1921
  unload(ctx) {
2631
- _optionalChain([this, 'access', _81 => _81.hooks, 'access', _82 => _82.onRoomWillUnload, 'optionalCall', _83 => _83(ctx)]);
1922
+ _optionalChain([this, 'access', _76 => _76.hooks, 'access', _77 => _77.onRoomWillUnload, 'optionalCall', _78 => _78(ctx)]);
2632
1923
  if (this._data) {
2633
1924
  this.storage.unload();
2634
1925
  this.yjsStorage.unload();
2635
1926
  }
2636
1927
  this._loadData$ = null;
2637
- _optionalChain([this, 'access', _84 => _84.hooks, 'access', _85 => _85.onRoomDidUnload, 'optionalCall', _86 => _86(ctx)]);
1928
+ _optionalChain([this, 'access', _79 => _79.hooks, 'access', _80 => _80.onRoomDidUnload, 'optionalCall', _81 => _81(ctx)]);
2638
1929
  }
2639
1930
  /**
2640
1931
  * Issues a Ticket with a new/unique actor ID
@@ -2648,17 +1939,17 @@ var Room = class {
2648
1939
  * unused Ticket will simply get garbage collected.
2649
1940
  */
2650
1941
  async createTicket(options) {
2651
- const actor$ = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _87 => _87.actor]), () => ( this.getNextActor()));
1942
+ const actor$ = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _82 => _82.actor]), () => ( this.getNextActor()));
2652
1943
  const sessionKey = _nanoid.nanoid.call(void 0, );
2653
- const info = _optionalChain([options, 'optionalAccess', _88 => _88.info]);
1944
+ const info = _optionalChain([options, 'optionalAccess', _83 => _83.info]);
2654
1945
  const ticket = {
2655
- version: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _89 => _89.version]), () => ( HIGHEST_PROTOCOL_VERSION)),
1946
+ version: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _84 => _84.version]), () => ( HIGHEST_PROTOCOL_VERSION)),
2656
1947
  actor: await actor$,
2657
1948
  sessionKey,
2658
- meta: _optionalChain([options, 'optionalAccess', _90 => _90.meta]),
2659
- publicMeta: _optionalChain([options, 'optionalAccess', _91 => _91.publicMeta]),
2660
- user: _optionalChain([options, 'optionalAccess', _92 => _92.id]) ? { id: options.id, info } : { anonymousId: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _93 => _93.anonymousId]), () => ( _nanoid.nanoid.call(void 0, ))), info },
2661
- scopes: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _94 => _94.scopes]), () => ( ["room:write"]))
1949
+ meta: _optionalChain([options, 'optionalAccess', _85 => _85.meta]),
1950
+ publicMeta: _optionalChain([options, 'optionalAccess', _86 => _86.publicMeta]),
1951
+ user: _optionalChain([options, 'optionalAccess', _87 => _87.id]) ? { id: options.id, info } : { anonymousId: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _88 => _88.anonymousId]), () => ( _nanoid.nanoid.call(void 0, ))), info },
1952
+ scopes: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _89 => _89.scopes]), () => ( ["room:write"]))
2662
1953
  };
2663
1954
  if (__privateGet(this, __debug2)) {
2664
1955
  console.log(`new ticket created: ${JSON.stringify(ticket)}`);
@@ -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
+ _core.WebsocketCloseCodes.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: _core.ServerMsgCode.USER_JOINED,
2755
2046
  actor: newSession.actor,
2756
2047
  id: newSession.user.id,
2757
2048
  info: newSession.user.info,
@@ -2760,7 +2051,7 @@ var Room = class {
2760
2051
  ctx,
2761
2052
  defer
2762
2053
  );
2763
- const p$ = _optionalChain([this, 'access', _95 => _95.hooks, 'access', _96 => _96.onSessionDidStart, 'optionalCall', _97 => _97(newSession, ctx)]);
2054
+ const p$ = _optionalChain([this, 'access', _90 => _90.hooks, 'access', _91 => _91.onSessionDidStart, 'optionalCall', _92 => _92(newSession, ctx)]);
2764
2055
  if (p$) defer(p$);
2765
2056
  }
2766
2057
  /**
@@ -2782,9 +2073,9 @@ 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: _core.ServerMsgCode.USER_LEFT, actor: session.actor });
2786
2077
  }
2787
- const p$ = _optionalChain([this, 'access', _98 => _98.hooks, 'access', _99 => _99.onSessionDidEnd, 'optionalCall', _100 => _100(session, ctx)]);
2078
+ const p$ = _optionalChain([this, 'access', _93 => _93.hooks, 'access', _94 => _94.onSessionDidEnd, 'optionalCall', _95 => _95(session, ctx)]);
2788
2079
  if (p$) defer(p$);
2789
2080
  }
2790
2081
  }
@@ -2814,17 +2105,17 @@ 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 : _core.raise.call(void 0, "Unsupported message format");
2818
2109
  if (text === "ping") {
2819
2110
  await this.handlePing(key, ctx);
2820
2111
  } else {
2821
- const json = tryParseJson(text);
2112
+ const json = _core.tryParseJson.call(void 0, text);
2822
2113
  const messages = messagesDecoder.decode(json);
2823
2114
  if (!messages.ok) {
2824
2115
  const reason = process.env.NODE_ENV !== "production" ? _decoders.formatInline.call(void 0, messages.error) : "Invalid message format";
2825
2116
  this.endBrowserSession(
2826
2117
  key,
2827
- WebsocketCloseCodes.INVALID_MESSAGE_FORMAT,
2118
+ _core.WebsocketCloseCodes.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
+ _core.WebsocketCloseCodes.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
+ _core.WebsocketCloseCodes.KICKED,
2940
2231
  "Closed broken connection",
2941
2232
  ctx,
2942
2233
  defer
@@ -2959,7 +2250,7 @@ var Room = class {
2959
2250
  }
2960
2251
  // Don't ever manually call this!
2961
2252
  async _load(ctx) {
2962
- await _optionalChain([this, 'access', _101 => _101.hooks, 'access', _102 => _102.onRoomWillLoad, 'optionalCall', _103 => _103(ctx)]);
2253
+ await _optionalChain([this, 'access', _96 => _96.hooks, 'access', _97 => _97.onRoomWillLoad, 'optionalCall', _98 => _98(ctx)]);
2963
2254
  const storage = await this._loadStorage();
2964
2255
  const yjsStorage = await this._loadYjsStorage();
2965
2256
  this._data = {
@@ -2967,7 +2258,7 @@ var Room = class {
2967
2258
  storage,
2968
2259
  yjsStorage
2969
2260
  };
2970
- await _optionalChain([this, 'access', _104 => _104.hooks, 'access', _105 => _105.onRoomDidLoad, 'optionalCall', _106 => _106(ctx)]);
2261
+ await _optionalChain([this, 'access', _99 => _99.hooks, 'access', _100 => _100.onRoomDidLoad, 'optionalCall', _101 => _101(ctx)]);
2971
2262
  }
2972
2263
  /**
2973
2264
  * Returns a new, unique, actor ID.
@@ -3008,7 +2299,7 @@ var Room = class {
3008
2299
  }
3009
2300
  const sent = session.sendPong();
3010
2301
  if (sent !== 0) {
3011
- await _optionalChain([this, 'access', _107 => _107.hooks, 'access', _108 => _108.onDidPong, 'optionalCall', _109 => _109(ctx)]);
2302
+ await _optionalChain([this, 'access', _102 => _102.hooks, 'access', _103 => _103.onDidPong, 'optionalCall', _104 => _104(ctx)]);
3012
2303
  }
3013
2304
  }
3014
2305
  async _processClientMsg_withExclusiveAccess(sessionKey, messages, ctx, 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: _core.ServerMsgCode.REJECT_STORAGE_OP,
2332
+ opIds: msg.type === _core.ClientMsgCode.UPDATE_STORAGE ? msg.ops.map((op2) => op2.opId) : [],
3042
2333
  reason: isMsgAllowed.reason
3043
2334
  });
3044
2335
  session.setHasNotifiedClientStorageUpdateError();
@@ -3099,55 +2390,55 @@ 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 _core.ClientMsgCode.UPDATE_PRESENCE: {
3103
2394
  scheduleFanOut({
3104
- type: ServerMsgCode.UPDATE_PRESENCE,
2395
+ type: _core.ServerMsgCode.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 _core.ClientMsgCode.BROADCAST_EVENT: {
3112
2403
  scheduleFanOut({
3113
- type: ServerMsgCode.BROADCASTED_EVENT,
2404
+ type: _core.ServerMsgCode.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 _core.ClientMsgCode.FETCH_STORAGE: {
3120
2411
  if (session.version >= 8 /* V8 */) {
3121
2412
  if (__privateGet(this, __allowStreaming)) {
3122
2413
  const NODES_PER_CHUNK = 250;
3123
2414
  for (const chunk of _itertools.chunked.call(void 0,
3124
- nodeStreamToCompactNodes(this.storage.loadedDriver.iter_nodes()),
2415
+ _core.nodeStreamToCompactNodes.call(void 0, this.storage.loadedDriver.iter_nodes()),
3125
2416
  NODES_PER_CHUNK
3126
2417
  )) {
3127
2418
  replyImmediately({
3128
- type: ServerMsgCode.STORAGE_CHUNK,
2419
+ type: _core.ServerMsgCode.STORAGE_CHUNK,
3129
2420
  nodes: chunk
3130
2421
  });
3131
2422
  }
3132
2423
  } else {
3133
2424
  replyImmediately({
3134
- type: ServerMsgCode.STORAGE_CHUNK,
2425
+ type: _core.ServerMsgCode.STORAGE_CHUNK,
3135
2426
  nodes: Array.from(
3136
- nodeStreamToCompactNodes(this.storage.loadedDriver.iter_nodes())
2427
+ _core.nodeStreamToCompactNodes.call(void 0, this.storage.loadedDriver.iter_nodes())
3137
2428
  )
3138
2429
  });
3139
2430
  }
3140
- replyImmediately({ type: ServerMsgCode.STORAGE_STREAM_END });
2431
+ replyImmediately({ type: _core.ServerMsgCode.STORAGE_STREAM_END });
3141
2432
  } else {
3142
2433
  replyImmediately({
3143
- type: ServerMsgCode.STORAGE_STATE_V7,
2434
+ type: _core.ServerMsgCode.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: {
3150
- _optionalChain([this, 'access', _110 => _110.driver, 'access', _111 => _111.bump_storage_version, 'optionalCall', _112 => _112()]);
2440
+ case _core.ClientMsgCode.UPDATE_STORAGE: {
2441
+ _optionalChain([this, 'access', _105 => _105.driver, 'access', _106 => _106.bump_storage_version, 'optionalCall', _107 => _107()]);
3151
2442
  const result = await this.storage.applyOps(msg.ops);
3152
2443
  const opsToForward = result.flatMap(
3153
2444
  (r) => r.action === "accepted" ? [r.op] : []
@@ -3159,32 +2450,32 @@ 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 _core.assertNever.call(void 0, r, "Unhandled case");
3163
2454
  }
3164
2455
  });
3165
2456
  if (opsToForward.length > 0) {
3166
2457
  scheduleFanOut({
3167
- type: ServerMsgCode.UPDATE_STORAGE,
2458
+ type: _core.ServerMsgCode.UPDATE_STORAGE,
3168
2459
  ops: opsToForward.map(stripOpId)
3169
2460
  });
3170
2461
  scheduleReply({
3171
- type: ServerMsgCode.UPDATE_STORAGE,
2462
+ type: _core.ServerMsgCode.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: _core.ServerMsgCode.UPDATE_STORAGE,
3178
2469
  ops: opsToSendBack
3179
2470
  });
3180
2471
  }
3181
2472
  if (opsToForward.length > 0) {
3182
- const p$ = _optionalChain([this, 'access', _113 => _113.hooks, 'access', _114 => _114.postClientMsgStorageDidUpdate, 'optionalCall', _115 => _115(ctx)]);
2473
+ const p$ = _optionalChain([this, 'access', _108 => _108.hooks, 'access', _109 => _109.postClientMsgStorageDidUpdate, 'optionalCall', _110 => _110(ctx)]);
3183
2474
  if (p$) defer(p$);
3184
2475
  }
3185
2476
  break;
3186
2477
  }
3187
- case ClientMsgCode.FETCH_YDOC: {
2478
+ case _core.ClientMsgCode.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: _core.ServerMsgCode.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 _core.ClientMsgCode.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: _core.ServerMsgCode.UPDATE_YDOC,
3222
2513
  update,
3223
2514
  guid,
3224
2515
  isSync: false,
@@ -3230,14 +2521,14 @@ var Room = class {
3230
2521
  defer
3231
2522
  );
3232
2523
  if (result.isUpdated) {
3233
- const p$ = _optionalChain([this, 'access', _116 => _116.hooks, 'access', _117 => _117.postClientMsgYdocDidUpdate, 'optionalCall', _118 => _118(ctx, session)]);
2524
+ const p$ = _optionalChain([this, 'access', _111 => _111.hooks, 'access', _112 => _112.postClientMsgYdocDidUpdate, 'optionalCall', _113 => _113(ctx, session)]);
3234
2525
  if (p$) defer(p$);
3235
2526
  }
3236
2527
  break;
3237
2528
  }
3238
2529
  default: {
3239
2530
  try {
3240
- return assertNever(msg, "Unrecognized client msg");
2531
+ return _core.assertNever.call(void 0, msg, "Unrecognized client msg");
3241
2532
  } catch (e2) {
3242
2533
  }
3243
2534
  }
@@ -3281,5 +2572,5 @@ __allowStreaming = new WeakMap();
3281
2572
 
3282
2573
 
3283
2574
 
3284
- exports.BackendSession = BackendSession; exports.BrowserSession = BrowserSession; exports.ConsoleTarget = ConsoleTarget; exports.DefaultMap = DefaultMap2; exports.InMemoryDriver = InMemoryDriver; exports.LogLevel = LogLevel; exports.LogTarget = LogTarget; exports.Logger = Logger; exports.NestedMap = NestedMap; exports.ProtocolVersion = ProtocolVersion; exports.ROOT_YDOC_ID = ROOT_YDOC_ID; exports.Room = Room; exports.UniqueMap = UniqueMap; exports.ackIgnoredOp = ackIgnoredOp; exports.clientMsgDecoder = clientMsgDecoder; exports.concatUint8Arrays = concatUint8Arrays; exports.guidDecoder = guidDecoder; exports.jsonObjectYolo = jsonObjectYolo; exports.jsonYolo = jsonYolo; exports.makeInMemorySnapshot = makeInMemorySnapshot; exports.makeMetadataDB = makeMetadataDB; exports.plainLsonToNodeStream = plainLsonToNodeStream; exports.protocolVersionDecoder = protocolVersionDecoder; exports.quote = quote; exports.serializeServerMsg = serialize; exports.snapshotToLossyJson_eager = snapshotToLossyJson_eager; exports.snapshotToLossyJson_lazy = snapshotToLossyJson_lazy; exports.snapshotToNodeStream = snapshotToNodeStream; exports.snapshotToPlainLson_eager = snapshotToPlainLson_eager; exports.snapshotToPlainLson_lazy = snapshotToPlainLson_lazy; exports.test_only__Storage = Storage; exports.test_only__YjsStorage = YjsStorage; exports.transientClientMsgDecoder = transientClientMsgDecoder; exports.tryCatch = tryCatch;
2575
+ exports.BackendSession = BackendSession; exports.BrowserSession = BrowserSession; exports.ConsoleTarget = ConsoleTarget; exports.DefaultMap = DefaultMap; exports.InMemoryDriver = InMemoryDriver; exports.LogLevel = LogLevel; exports.LogTarget = LogTarget; exports.Logger = Logger; exports.NestedMap = NestedMap; exports.ProtocolVersion = ProtocolVersion; exports.ROOT_YDOC_ID = ROOT_YDOC_ID; exports.Room = Room; exports.UniqueMap = UniqueMap; exports.ackIgnoredOp = ackIgnoredOp; exports.clientMsgDecoder = clientMsgDecoder; exports.concatUint8Arrays = concatUint8Arrays; exports.guidDecoder = guidDecoder; exports.jsonObjectYolo = jsonObjectYolo; exports.jsonYolo = jsonYolo; exports.makeInMemorySnapshot = makeInMemorySnapshot; exports.makeMetadataDB = makeMetadataDB; exports.plainLsonToNodeStream = plainLsonToNodeStream; exports.protocolVersionDecoder = protocolVersionDecoder; exports.quote = quote; exports.serializeServerMsg = serialize; exports.snapshotToLossyJson_eager = snapshotToLossyJson_eager; exports.snapshotToLossyJson_lazy = snapshotToLossyJson_lazy; exports.snapshotToNodeStream = snapshotToNodeStream; exports.snapshotToPlainLson_eager = snapshotToPlainLson_eager; exports.snapshotToPlainLson_lazy = snapshotToPlainLson_lazy; exports.test_only__Storage = Storage; exports.test_only__YjsStorage = YjsStorage; exports.transientClientMsgDecoder = transientClientMsgDecoder; exports.tryCatch = tryCatch;
3285
2576
  //# sourceMappingURL=index.cjs.map