@pluv/client 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -57,9 +57,7 @@ var __async = (__this, __arguments, generator) => {
57
57
  // src/index.ts
58
58
  var index_exports = {};
59
59
  __export(index_exports, {
60
- AbstractRoom: () => AbstractRoom,
61
60
  AbstractStorageStore: () => AbstractStorageStore,
62
- ConnectionState: () => ConnectionState,
63
61
  MockedRoom: () => MockedRoom,
64
62
  PluvClient: () => PluvClient,
65
63
  PluvRoom: () => PluvRoom,
@@ -69,13 +67,6 @@ __export(index_exports, {
69
67
  });
70
68
  module.exports = __toCommonJS(index_exports);
71
69
 
72
- // src/AbstractRoom.ts
73
- var AbstractRoom = class {
74
- constructor(room) {
75
- this.id = room;
76
- }
77
- };
78
-
79
70
  // src/AbstractStorageStore.ts
80
71
  var AbstractStorageStore = class {
81
72
  constructor(room) {
@@ -121,6 +112,9 @@ var PluvProcedure = class _PluvProcedure {
121
112
  }
122
113
  };
123
114
 
115
+ // src/PluvRoom.ts
116
+ var import_types = require("@pluv/types");
117
+
124
118
  // src/CrdtManager.ts
125
119
  var import_crdt = require("@pluv/crdt");
126
120
  var CrdtManager = class {
@@ -554,15 +548,6 @@ var UsersManager = class {
554
548
  }
555
549
  };
556
550
 
557
- // src/enums.ts
558
- var ConnectionState = {
559
- Closed: "Closed",
560
- Connecting: "Connecting",
561
- Open: "Open",
562
- Unavailable: "Unavailable",
563
- Untouched: "Untouched"
564
- };
565
-
566
551
  // src/PluvRoom.ts
567
552
  var ADD_TO_STORAGE_STATE_DEBOUNCE_MS = 1e3;
568
553
  var HEARTBEAT_INTERVAL_MS = 1e4;
@@ -575,24 +560,8 @@ var ORIGIN_STORAGE_UPDATED = "$storageUpdated";
575
560
  var DEFAULT_PLUV_CLIENT_ADDON = (input) => ({
576
561
  storage: new StorageStore(input.room.id)
577
562
  });
578
- var PluvRoom = class extends AbstractRoom {
563
+ var PluvRoom = class {
579
564
  constructor(room, options) {
580
- const {
581
- addons = [],
582
- authEndpoint,
583
- debug = false,
584
- initialPresence,
585
- initialStorage,
586
- limits,
587
- metadata,
588
- onAuthorizationFail,
589
- presence,
590
- publicKey,
591
- reconnectTimeoutMs = RECONNECT_TIMEOUT_MS,
592
- router,
593
- wsEndpoint
594
- } = options;
595
- super(room);
596
565
  this._crdtNotifier = new CrdtNotifier();
597
566
  this._eventNotifier = new EventNotifier();
598
567
  this._intervals = {
@@ -618,7 +587,7 @@ var PluvRoom = class extends AbstractRoom {
618
587
  attempts: 0,
619
588
  count: 0,
620
589
  id: null,
621
- state: ConnectionState.Untouched
590
+ state: import_types.ConnectionState.Untouched
622
591
  },
623
592
  webSocket: null
624
593
  };
@@ -627,7 +596,7 @@ var PluvRoom = class extends AbstractRoom {
627
596
  this.broadcast = new Proxy(
628
597
  (event, data) => __async(this, null, function* () {
629
598
  if (!this._state.webSocket) return;
630
- if (this._state.connection.state !== ConnectionState.Open) return;
599
+ if (this._state.connection.state !== import_types.ConnectionState.Open) return;
631
600
  const type = event.toString();
632
601
  const procedure = this._router._defs.events[type];
633
602
  if (!(procedure == null ? void 0 : procedure.config.broadcast)) {
@@ -751,14 +720,30 @@ var PluvRoom = class extends AbstractRoom {
751
720
  DEFAULT_PLUV_CLIENT_ADDON
752
721
  );
753
722
  };
723
+ const {
724
+ addons = [],
725
+ authEndpoint,
726
+ debug = false,
727
+ initialPresence,
728
+ initialStorage,
729
+ limits,
730
+ metadata,
731
+ onAuthorizationFail,
732
+ presence,
733
+ publicKey,
734
+ reconnectTimeoutMs = RECONNECT_TIMEOUT_MS,
735
+ router,
736
+ wsEndpoint
737
+ } = options;
738
+ this.id = room;
739
+ this.metadata = metadata;
754
740
  const addon = this._getAddon(addons);
755
741
  const { storage } = __spreadValues(__spreadValues({}, DEFAULT_PLUV_CLIENT_ADDON({ room: this })), addon({ room: this }));
756
- this.metadata = metadata;
742
+ this._storageStore = storage;
757
743
  this._debug = debug;
758
744
  this._endpoints = { authEndpoint, wsEndpoint };
759
745
  this._limits = limits;
760
746
  this._reconnectTimeoutMs = reconnectTimeoutMs;
761
- this._storageStore = storage;
762
747
  if (!!publicKey) this._publicKey = publicKey;
763
748
  this._listeners = {
764
749
  onAuthorizationFail: (error) => {
@@ -786,14 +771,14 @@ var PluvRoom = class extends AbstractRoom {
786
771
  const metadata = params.metadata;
787
772
  this._setMetadata(metadata);
788
773
  const canConnect = [
789
- ConnectionState.Closed,
790
- ConnectionState.Unavailable,
791
- ConnectionState.Untouched
774
+ import_types.ConnectionState.Closed,
775
+ import_types.ConnectionState.Unavailable,
776
+ import_types.ConnectionState.Untouched
792
777
  ].some((state) => this._state.connection.state === state);
793
778
  if (!canConnect) return;
794
779
  this._clearTimeout(this._timeouts.reconnect);
795
780
  this._updateState((oldState) => {
796
- oldState.connection.state = ConnectionState.Connecting;
781
+ oldState.connection.state = import_types.ConnectionState.Connecting;
797
782
  return oldState;
798
783
  });
799
784
  yield this._storageStore.initialize();
@@ -830,7 +815,7 @@ var PluvRoom = class extends AbstractRoom {
830
815
  disconnect() {
831
816
  return __async(this, null, function* () {
832
817
  if (!this._state.webSocket) return;
833
- const canDisconnect = [ConnectionState.Connecting, ConnectionState.Open].some(
818
+ const canDisconnect = [import_types.ConnectionState.Connecting, import_types.ConnectionState.Open].some(
834
819
  (state) => this._state.connection.state === state
835
820
  );
836
821
  if (!canDisconnect) return;
@@ -839,7 +824,7 @@ var PluvRoom = class extends AbstractRoom {
839
824
  this._clearTimeout(this._timeouts.reconnect);
840
825
  this._updateState((oldState) => {
841
826
  oldState.authorization.token = null;
842
- oldState.connection.state = ConnectionState.Closed;
827
+ oldState.connection.state = import_types.ConnectionState.Closed;
843
828
  oldState.webSocket = null;
844
829
  return oldState;
845
830
  });
@@ -1185,7 +1170,8 @@ var PluvRoom = class extends AbstractRoom {
1185
1170
  }
1186
1171
  _logDebug(...data) {
1187
1172
  var _a;
1188
- if (((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
1173
+ if (typeof process === "undefined") return;
1174
+ if (((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
1189
1175
  if (this._debug) console.log(...data);
1190
1176
  }
1191
1177
  _observeCrdt() {
@@ -1213,7 +1199,7 @@ var PluvRoom = class extends AbstractRoom {
1213
1199
  const authError = error instanceof Error ? error : new Error("Authorization failed");
1214
1200
  this._listeners.onAuthorizationFail(authError);
1215
1201
  this._updateState((oldState) => {
1216
- oldState.connection.state = ConnectionState.Unavailable;
1202
+ oldState.connection.state = import_types.ConnectionState.Unavailable;
1217
1203
  return oldState;
1218
1204
  });
1219
1205
  }
@@ -1237,14 +1223,14 @@ var PluvRoom = class extends AbstractRoom {
1237
1223
  ].some((okToRetryCode) => event.code === okToRetryCode);
1238
1224
  this._updateState((oldState) => {
1239
1225
  oldState.authorization.token = null;
1240
- oldState.connection.state = shouldRetry ? ConnectionState.Unavailable : (
1226
+ oldState.connection.state = shouldRetry ? import_types.ConnectionState.Unavailable : (
1241
1227
  /**
1242
1228
  * !HACK
1243
1229
  * @description Assume these are not recoverable. We're just going to mark this
1244
1230
  * as Closed to avoid reconnect attempts.
1245
1231
  * @date April 28, 2025
1246
1232
  */
1247
- ConnectionState.Closed
1233
+ import_types.ConnectionState.Closed
1248
1234
  );
1249
1235
  oldState.webSocket = null;
1250
1236
  return oldState;
@@ -1313,10 +1299,10 @@ var PluvRoom = class extends AbstractRoom {
1313
1299
  }
1314
1300
  }
1315
1301
  _onOpen() {
1316
- if (this._state.connection.state !== ConnectionState.Connecting) return;
1302
+ if (this._state.connection.state !== import_types.ConnectionState.Connecting) return;
1317
1303
  this._logDebug("WebSocket connected");
1318
1304
  this._updateState((oldState) => {
1319
- oldState.connection.state = ConnectionState.Open;
1305
+ oldState.connection.state = import_types.ConnectionState.Open;
1320
1306
  return oldState;
1321
1307
  });
1322
1308
  this._clearInterval(this._intervals.heartbeat);
@@ -1327,16 +1313,16 @@ var PluvRoom = class extends AbstractRoom {
1327
1313
  }
1328
1314
  _onNavigatorOffline() {
1329
1315
  return __async(this, null, function* () {
1330
- if (this._state.connection.state === ConnectionState.Closed) return;
1316
+ if (this._state.connection.state === import_types.ConnectionState.Closed) return;
1331
1317
  this._updateState((oldState) => {
1332
- oldState.connection.state = ConnectionState.Unavailable;
1318
+ oldState.connection.state = import_types.ConnectionState.Unavailable;
1333
1319
  return oldState;
1334
1320
  });
1335
1321
  });
1336
1322
  }
1337
1323
  _onNavigatorOnline() {
1338
1324
  return __async(this, null, function* () {
1339
- if (this._state.connection.state !== ConnectionState.Unavailable) return;
1325
+ if (this._state.connection.state !== import_types.ConnectionState.Unavailable) return;
1340
1326
  yield this._reconnect();
1341
1327
  });
1342
1328
  }
@@ -1345,12 +1331,12 @@ var PluvRoom = class extends AbstractRoom {
1345
1331
  if (typeof document === "undefined") return;
1346
1332
  if (document.visibilityState !== "visible") return;
1347
1333
  switch (this._state.connection.state) {
1348
- case ConnectionState.Open: {
1334
+ case import_types.ConnectionState.Open: {
1349
1335
  this._clearInterval(this._intervals.heartbeat);
1350
1336
  setInterval(this._heartbeat.bind(this), HEARTBEAT_INTERVAL_MS);
1351
1337
  return;
1352
1338
  }
1353
- case ConnectionState.Unavailable: {
1339
+ case import_types.ConnectionState.Unavailable: {
1354
1340
  yield this._reconnect();
1355
1341
  return;
1356
1342
  }
@@ -1390,7 +1376,7 @@ var PluvRoom = class extends AbstractRoom {
1390
1376
  _reconnect() {
1391
1377
  return __async(this, null, function* () {
1392
1378
  this._closeWs();
1393
- if (this._state.connection.state === ConnectionState.Closed) return;
1379
+ if (this._state.connection.state === import_types.ConnectionState.Closed) return;
1394
1380
  const metadata = this._lastMetadata;
1395
1381
  const params = typeof metadata === "undefined" ? [] : [{ metadata }];
1396
1382
  yield this.connect(...params);
@@ -1445,7 +1431,7 @@ var PluvClient = class {
1445
1431
  this._publicKey = null;
1446
1432
  this._rooms = /* @__PURE__ */ new Map();
1447
1433
  this.createRoom = (room, options = {}) => {
1448
- var _a;
1434
+ var _a, _b;
1449
1435
  const oldRoom = this.getRoom(room);
1450
1436
  if (oldRoom) return oldRoom;
1451
1437
  const newRoom = new PluvRoom(room, {
@@ -1453,12 +1439,12 @@ var PluvClient = class {
1453
1439
  authEndpoint: this._authEndpoint,
1454
1440
  debug: options.debug,
1455
1441
  initialPresence: options.initialPresence,
1456
- initialStorage: this._initialStorage,
1442
+ initialStorage: (_a = options.initialStorage) != null ? _a : this._initialStorage,
1457
1443
  limits: this._limits,
1458
1444
  metadata: this.metadata,
1459
1445
  onAuthorizationFail: options.onAuthorizationFail,
1460
1446
  presence: this._presence,
1461
- publicKey: (_a = this._publicKey) != null ? _a : void 0,
1447
+ publicKey: (_b = this._publicKey) != null ? _b : void 0,
1462
1448
  reconnectTimeoutMs: options.reconnectTimeoutMs,
1463
1449
  router: options.router,
1464
1450
  wsEndpoint: this._wsEndpoint
@@ -1527,7 +1513,8 @@ var PluvClient = class {
1527
1513
  }
1528
1514
  _logDebug(...data) {
1529
1515
  var _a;
1530
- if (((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
1516
+ if (typeof process === "undefined") return;
1517
+ if (((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
1531
1518
  if (this._debug) console.log(...data);
1532
1519
  }
1533
1520
  };
@@ -1541,10 +1528,9 @@ var createClient = (options) => {
1541
1528
  var infer = (callback) => callback;
1542
1529
 
1543
1530
  // src/MockedRoom.ts
1544
- var MockedRoom = class extends AbstractRoom {
1531
+ var import_types2 = require("@pluv/types");
1532
+ var MockedRoom = class {
1545
1533
  constructor(room, options) {
1546
- const { events, initialPresence, initialStorage, limits, presence, router } = options;
1547
- super(room);
1548
1534
  this._crdtNotifier = new CrdtNotifier();
1549
1535
  this._eventNotifier = new EventNotifier();
1550
1536
  this._otherNotifier = new OtherNotifier();
@@ -1557,7 +1543,7 @@ var MockedRoom = class extends AbstractRoom {
1557
1543
  attempts: 0,
1558
1544
  count: 1,
1559
1545
  id: null,
1560
- state: ConnectionState.Untouched
1546
+ state: import_types2.ConnectionState.Untouched
1561
1547
  },
1562
1548
  webSocket: null
1563
1549
  };
@@ -1568,7 +1554,7 @@ var MockedRoom = class extends AbstractRoom {
1568
1554
  this.broadcast = new Proxy(
1569
1555
  (event, data) => __async(this, null, function* () {
1570
1556
  if (!this._state.webSocket) return;
1571
- if (this._state.connection.state !== ConnectionState.Open) return;
1557
+ if (this._state.connection.state !== import_types2.ConnectionState.Open) return;
1572
1558
  const type = event.toString();
1573
1559
  const procedure = this._router._defs.events[type];
1574
1560
  if (!(procedure == null ? void 0 : procedure.config.broadcast)) {
@@ -1670,6 +1656,8 @@ var MockedRoom = class extends AbstractRoom {
1670
1656
  this._stateNotifier.subjects["my-presence"].next(myPresence);
1671
1657
  if (!!myself) this._stateNotifier.subjects["myself"].next(myself);
1672
1658
  };
1659
+ const { events, initialPresence, initialStorage, limits, presence, router } = options;
1660
+ this.id = room;
1673
1661
  this._events = events;
1674
1662
  this._limits = __spreadValues({
1675
1663
  presenceMaxSize: MAX_PRESENCE_SIZE_BYTES
@@ -1746,9 +1734,7 @@ var register = (params) => {
1746
1734
  };
1747
1735
  // Annotate the CommonJS export names for ESM import in node:
1748
1736
  0 && (module.exports = {
1749
- AbstractRoom,
1750
1737
  AbstractStorageStore,
1751
- ConnectionState,
1752
1738
  MockedRoom,
1753
1739
  PluvClient,
1754
1740
  PluvRoom,
package/dist/index.mjs CHANGED
@@ -38,13 +38,6 @@ var __async = (__this, __arguments, generator) => {
38
38
  });
39
39
  };
40
40
 
41
- // src/AbstractRoom.ts
42
- var AbstractRoom = class {
43
- constructor(room) {
44
- this.id = room;
45
- }
46
- };
47
-
48
41
  // src/AbstractStorageStore.ts
49
42
  var AbstractStorageStore = class {
50
43
  constructor(room) {
@@ -90,6 +83,9 @@ var PluvProcedure = class _PluvProcedure {
90
83
  }
91
84
  };
92
85
 
86
+ // src/PluvRoom.ts
87
+ import { ConnectionState } from "@pluv/types";
88
+
93
89
  // src/CrdtManager.ts
94
90
  import { noop } from "@pluv/crdt";
95
91
  var CrdtManager = class {
@@ -523,15 +519,6 @@ var UsersManager = class {
523
519
  }
524
520
  };
525
521
 
526
- // src/enums.ts
527
- var ConnectionState = {
528
- Closed: "Closed",
529
- Connecting: "Connecting",
530
- Open: "Open",
531
- Unavailable: "Unavailable",
532
- Untouched: "Untouched"
533
- };
534
-
535
522
  // src/PluvRoom.ts
536
523
  var ADD_TO_STORAGE_STATE_DEBOUNCE_MS = 1e3;
537
524
  var HEARTBEAT_INTERVAL_MS = 1e4;
@@ -544,24 +531,8 @@ var ORIGIN_STORAGE_UPDATED = "$storageUpdated";
544
531
  var DEFAULT_PLUV_CLIENT_ADDON = (input) => ({
545
532
  storage: new StorageStore(input.room.id)
546
533
  });
547
- var PluvRoom = class extends AbstractRoom {
534
+ var PluvRoom = class {
548
535
  constructor(room, options) {
549
- const {
550
- addons = [],
551
- authEndpoint,
552
- debug = false,
553
- initialPresence,
554
- initialStorage,
555
- limits,
556
- metadata,
557
- onAuthorizationFail,
558
- presence,
559
- publicKey,
560
- reconnectTimeoutMs = RECONNECT_TIMEOUT_MS,
561
- router,
562
- wsEndpoint
563
- } = options;
564
- super(room);
565
536
  this._crdtNotifier = new CrdtNotifier();
566
537
  this._eventNotifier = new EventNotifier();
567
538
  this._intervals = {
@@ -720,14 +691,30 @@ var PluvRoom = class extends AbstractRoom {
720
691
  DEFAULT_PLUV_CLIENT_ADDON
721
692
  );
722
693
  };
694
+ const {
695
+ addons = [],
696
+ authEndpoint,
697
+ debug = false,
698
+ initialPresence,
699
+ initialStorage,
700
+ limits,
701
+ metadata,
702
+ onAuthorizationFail,
703
+ presence,
704
+ publicKey,
705
+ reconnectTimeoutMs = RECONNECT_TIMEOUT_MS,
706
+ router,
707
+ wsEndpoint
708
+ } = options;
709
+ this.id = room;
710
+ this.metadata = metadata;
723
711
  const addon = this._getAddon(addons);
724
712
  const { storage } = __spreadValues(__spreadValues({}, DEFAULT_PLUV_CLIENT_ADDON({ room: this })), addon({ room: this }));
725
- this.metadata = metadata;
713
+ this._storageStore = storage;
726
714
  this._debug = debug;
727
715
  this._endpoints = { authEndpoint, wsEndpoint };
728
716
  this._limits = limits;
729
717
  this._reconnectTimeoutMs = reconnectTimeoutMs;
730
- this._storageStore = storage;
731
718
  if (!!publicKey) this._publicKey = publicKey;
732
719
  this._listeners = {
733
720
  onAuthorizationFail: (error) => {
@@ -1154,7 +1141,8 @@ var PluvRoom = class extends AbstractRoom {
1154
1141
  }
1155
1142
  _logDebug(...data) {
1156
1143
  var _a;
1157
- if (((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
1144
+ if (typeof process === "undefined") return;
1145
+ if (((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
1158
1146
  if (this._debug) console.log(...data);
1159
1147
  }
1160
1148
  _observeCrdt() {
@@ -1414,7 +1402,7 @@ var PluvClient = class {
1414
1402
  this._publicKey = null;
1415
1403
  this._rooms = /* @__PURE__ */ new Map();
1416
1404
  this.createRoom = (room, options = {}) => {
1417
- var _a;
1405
+ var _a, _b;
1418
1406
  const oldRoom = this.getRoom(room);
1419
1407
  if (oldRoom) return oldRoom;
1420
1408
  const newRoom = new PluvRoom(room, {
@@ -1422,12 +1410,12 @@ var PluvClient = class {
1422
1410
  authEndpoint: this._authEndpoint,
1423
1411
  debug: options.debug,
1424
1412
  initialPresence: options.initialPresence,
1425
- initialStorage: this._initialStorage,
1413
+ initialStorage: (_a = options.initialStorage) != null ? _a : this._initialStorage,
1426
1414
  limits: this._limits,
1427
1415
  metadata: this.metadata,
1428
1416
  onAuthorizationFail: options.onAuthorizationFail,
1429
1417
  presence: this._presence,
1430
- publicKey: (_a = this._publicKey) != null ? _a : void 0,
1418
+ publicKey: (_b = this._publicKey) != null ? _b : void 0,
1431
1419
  reconnectTimeoutMs: options.reconnectTimeoutMs,
1432
1420
  router: options.router,
1433
1421
  wsEndpoint: this._wsEndpoint
@@ -1496,7 +1484,8 @@ var PluvClient = class {
1496
1484
  }
1497
1485
  _logDebug(...data) {
1498
1486
  var _a;
1499
- if (((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
1487
+ if (typeof process === "undefined") return;
1488
+ if (((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
1500
1489
  if (this._debug) console.log(...data);
1501
1490
  }
1502
1491
  };
@@ -1510,10 +1499,9 @@ var createClient = (options) => {
1510
1499
  var infer = (callback) => callback;
1511
1500
 
1512
1501
  // src/MockedRoom.ts
1513
- var MockedRoom = class extends AbstractRoom {
1502
+ import { ConnectionState as ConnectionState2 } from "@pluv/types";
1503
+ var MockedRoom = class {
1514
1504
  constructor(room, options) {
1515
- const { events, initialPresence, initialStorage, limits, presence, router } = options;
1516
- super(room);
1517
1505
  this._crdtNotifier = new CrdtNotifier();
1518
1506
  this._eventNotifier = new EventNotifier();
1519
1507
  this._otherNotifier = new OtherNotifier();
@@ -1526,7 +1514,7 @@ var MockedRoom = class extends AbstractRoom {
1526
1514
  attempts: 0,
1527
1515
  count: 1,
1528
1516
  id: null,
1529
- state: ConnectionState.Untouched
1517
+ state: ConnectionState2.Untouched
1530
1518
  },
1531
1519
  webSocket: null
1532
1520
  };
@@ -1537,7 +1525,7 @@ var MockedRoom = class extends AbstractRoom {
1537
1525
  this.broadcast = new Proxy(
1538
1526
  (event, data) => __async(this, null, function* () {
1539
1527
  if (!this._state.webSocket) return;
1540
- if (this._state.connection.state !== ConnectionState.Open) return;
1528
+ if (this._state.connection.state !== ConnectionState2.Open) return;
1541
1529
  const type = event.toString();
1542
1530
  const procedure = this._router._defs.events[type];
1543
1531
  if (!(procedure == null ? void 0 : procedure.config.broadcast)) {
@@ -1639,6 +1627,8 @@ var MockedRoom = class extends AbstractRoom {
1639
1627
  this._stateNotifier.subjects["my-presence"].next(myPresence);
1640
1628
  if (!!myself) this._stateNotifier.subjects["myself"].next(myself);
1641
1629
  };
1630
+ const { events, initialPresence, initialStorage, limits, presence, router } = options;
1631
+ this.id = room;
1642
1632
  this._events = events;
1643
1633
  this._limits = __spreadValues({
1644
1634
  presenceMaxSize: MAX_PRESENCE_SIZE_BYTES
@@ -1714,9 +1704,7 @@ var register = (params) => {
1714
1704
  };
1715
1705
  };
1716
1706
  export {
1717
- AbstractRoom,
1718
1707
  AbstractStorageStore,
1719
- ConnectionState,
1720
1708
  MockedRoom,
1721
1709
  PluvClient,
1722
1710
  PluvRoom,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/client",
3
- "version": "1.0.2",
3
+ "version": "2.0.0",
4
4
  "description": "@pluv/io frontend client",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -18,15 +18,15 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "wonka": "^6.3.5",
21
- "@pluv/crdt": "^1.0.2",
22
- "@pluv/types": "^1.0.2"
21
+ "@pluv/crdt": "^2.0.0",
22
+ "@pluv/types": "^2.0.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "eslint": "^9.25.1",
26
26
  "tsup": "^8.4.0",
27
27
  "typescript": "^5.8.3",
28
- "@pluv/tsconfig": "^1.0.2",
29
- "eslint-config-pluv": "^1.0.2"
28
+ "@pluv/tsconfig": "^2.0.0",
29
+ "eslint-config-pluv": "^2.0.0"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -1,8 +1,8 @@
1
- import type { AbstractCrdtDoc, AbstractCrdtDocFactory, CrdtType } from "@pluv/crdt";
1
+ import type { AbstractCrdtDocFactory, CrdtDocLike, CrdtType, InferStorage } from "@pluv/crdt";
2
2
  import { noop } from "@pluv/crdt";
3
3
 
4
- export type CrdtManagerOptions<TStorage extends Record<string, CrdtType<any, any>> = {}> = {
5
- initialStorage?: AbstractCrdtDocFactory<TStorage>;
4
+ export type CrdtManagerOptions<TCrdt extends AbstractCrdtDocFactory<any>> = {
5
+ initialStorage?: TCrdt;
6
6
  };
7
7
 
8
8
  interface CrdtManagerInitializeParams {
@@ -15,14 +15,14 @@ interface ApplyUpdateParams {
15
15
  update: string | readonly string[];
16
16
  }
17
17
 
18
- export class CrdtManager<TStorage extends Record<string, CrdtType<any, any>>> {
19
- public doc: AbstractCrdtDoc<TStorage>;
18
+ export class CrdtManager<TCrdt extends AbstractCrdtDocFactory<any>> {
19
+ public doc: CrdtDocLike<InferStorage<TCrdt>>;
20
20
  public initialized: boolean = false;
21
21
 
22
- private readonly _docFactory: AbstractCrdtDocFactory<TStorage>;
22
+ private readonly _docFactory: TCrdt;
23
23
 
24
- constructor(options: CrdtManagerOptions<TStorage>) {
25
- const { initialStorage = noop.doc({}) as AbstractCrdtDocFactory<TStorage> } = options;
24
+ constructor(options: CrdtManagerOptions<TCrdt>) {
25
+ const { initialStorage = noop.doc({}) as any } = options;
26
26
 
27
27
  this._docFactory = initialStorage;
28
28
  this.doc = initialStorage.getEmpty();
@@ -52,7 +52,7 @@ export class CrdtManager<TStorage extends Record<string, CrdtType<any, any>>> {
52
52
  this.doc = this._docFactory.getEmpty();
53
53
  }
54
54
 
55
- public get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey] {
55
+ public get<TKey extends keyof InferStorage<TCrdt>>(key: TKey): InferStorage<TCrdt>[TKey] {
56
56
  return this.doc.get(key);
57
57
  }
58
58
 
@@ -110,10 +110,10 @@ export class CrdtManager<TStorage extends Record<string, CrdtType<any, any>>> {
110
110
  }
111
111
 
112
112
  private _applyDocUpdates(
113
- doc: AbstractCrdtDoc<TStorage>,
113
+ doc: CrdtDocLike<InferStorage<TCrdt>>,
114
114
  updates: readonly string[],
115
115
  origin?: string,
116
- ): AbstractCrdtDoc<TStorage> {
116
+ ): CrdtDocLike<InferStorage<TCrdt>> {
117
117
  doc.transact(() => {
118
118
  doc.batchApplyEncodedState({ origin, updates });
119
119
  }, origin);
@@ -1,12 +1,13 @@
1
- import type { Id, InferIOOutput, IOEventMessage, IOLike } from "@pluv/types";
1
+ import type {
2
+ EventNotifierSubscriptionCallback,
3
+ Id,
4
+ InferIOOutput,
5
+ IOEventMessage,
6
+ IOLike,
7
+ } from "@pluv/types";
2
8
  import type { Subject } from "wonka";
3
9
  import { makeSubject, subscribe } from "wonka";
4
10
 
5
- export type EventNotifierSubscriptionCallback<
6
- TIO extends IOLike<any, any>,
7
- TEvent extends keyof InferIOOutput<TIO>,
8
- > = (value: Id<IOEventMessage<TIO, TEvent>>) => void;
9
-
10
11
  export class EventNotifier<TIO extends IOLike> {
11
12
  public subjects = new Map<
12
13
  keyof InferIOOutput<TIO>,