@pluv/io 3.1.6 → 3.1.7

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.
@@ -1,9 +1,9 @@
1
1
 
2
- > @pluv/io@3.1.6 build /home/runner/work/pluv/pluv/packages/io
2
+ > @pluv/io@3.1.7 build /home/runner/work/pluv/pluv/packages/io
3
3
  > pnpm run version && tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
 
6
- > @pluv/io@3.1.6 version /home/runner/work/pluv/pluv/packages/io
6
+ > @pluv/io@3.1.7 version /home/runner/work/pluv/pluv/packages/io
7
7
  > genversion ./src/version.generated.ts --esm
8
8
 
9
9
  CLI Building entry: src/index.ts
@@ -12,11 +12,11 @@
12
12
  CLI Target: es6
13
13
  ESM Build start
14
14
  CJS Build start
15
- CJS dist/index.js 55.16 KB
16
- CJS ⚡️ Build success in 136ms
17
- ESM dist/index.mjs 52.98 KB
18
- ESM ⚡️ Build success in 136ms
15
+ CJS dist/index.js 55.74 KB
16
+ CJS ⚡️ Build success in 106ms
17
+ ESM dist/index.mjs 53.56 KB
18
+ ESM ⚡️ Build success in 110ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 4063ms
21
- DTS dist/index.d.mts 33.98 KB
22
- DTS dist/index.d.ts 33.98 KB
20
+ DTS ⚡️ Build success in 4281ms
21
+ DTS dist/index.d.mts 34.07 KB
22
+ DTS dist/index.d.ts 34.07 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 3.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - f1d56d9: Fixed a case where in Cloudflare Durable Objects, the CRDT storage would clear upon hibernation.
8
+ - @pluv/crdt@3.1.7
9
+ - @pluv/types@3.1.7
10
+
3
11
  ## 3.1.6
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -344,6 +344,7 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
344
344
  doc: (value: any) => AbstractCrdtDocFactory<any, any>;
345
345
  };
346
346
  debug: boolean;
347
+ getInitialStorage: GetInitialStorageFn<TContext>;
347
348
  platform: TPlatform;
348
349
  roomContext: InferRoomContextType<TPlatform>;
349
350
  router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
@@ -361,6 +362,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
361
362
  private readonly _crdt;
362
363
  private readonly _debug;
363
364
  private readonly _docFactory;
365
+ private readonly _getInitialStorage;
364
366
  private readonly _listeners;
365
367
  private readonly _platform;
366
368
  private readonly _router;
package/dist/index.d.ts CHANGED
@@ -344,6 +344,7 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
344
344
  doc: (value: any) => AbstractCrdtDocFactory<any, any>;
345
345
  };
346
346
  debug: boolean;
347
+ getInitialStorage: GetInitialStorageFn<TContext>;
347
348
  platform: TPlatform;
348
349
  roomContext: InferRoomContextType<TPlatform>;
349
350
  router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
@@ -361,6 +362,7 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
361
362
  private readonly _crdt;
362
363
  private readonly _debug;
363
364
  private readonly _docFactory;
365
+ private readonly _getInitialStorage;
364
366
  private readonly _listeners;
365
367
  private readonly _platform;
366
368
  private readonly _router;
package/dist/index.js CHANGED
@@ -440,6 +440,7 @@ var IORoom = class {
440
440
  context,
441
441
  crdt = import_crdt.noop,
442
442
  debug,
443
+ getInitialStorage,
443
444
  onDestroy,
444
445
  onMessage,
445
446
  onUserConnected,
@@ -453,6 +454,7 @@ var IORoom = class {
453
454
  this._crdt = crdt;
454
455
  this._debug = debug;
455
456
  this._docFactory = crdt.doc(() => ({}));
457
+ this._getInitialStorage = getInitialStorage;
456
458
  this._router = router;
457
459
  this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { roomContext }));
458
460
  this._listeners = {
@@ -805,6 +807,18 @@ var IORoom = class {
805
807
  return __async(this, null, function* () {
806
808
  const doc = this._docFactory.getEmpty();
807
809
  const encodedState = yield this._platform.persistence.getStorageState(this.id);
810
+ if (!encodedState) {
811
+ const loadedState = yield this._getInitialStorage({
812
+ context: this._context,
813
+ room: this.id
814
+ });
815
+ const checkDoc = this._crdt.doc(() => ({})).getEmpty().applyEncodedState({ update: loadedState });
816
+ const isEmpty = checkDoc.isEmpty();
817
+ checkDoc.destroy();
818
+ if (!!loadedState && !isEmpty) {
819
+ doc.applyEncodedState({ update: loadedState }).getEncodedState();
820
+ }
821
+ }
808
822
  if (typeof encodedState === "string") doc.applyEncodedState({ update: encodedState });
809
823
  return doc;
810
824
  });
@@ -1170,7 +1184,7 @@ var IORoom = class {
1170
1184
  };
1171
1185
 
1172
1186
  // src/version.generated.ts
1173
- var version = "3.1.6";
1187
+ var version = "3.1.7";
1174
1188
 
1175
1189
  // src/PluvServer.ts
1176
1190
  var PluvServer = class {
@@ -1392,6 +1406,7 @@ var PluvServer = class {
1392
1406
  context,
1393
1407
  crdt: this._config.crdt,
1394
1408
  debug: debug != null ? debug : this._config.debug,
1409
+ getInitialStorage: this._getInitialStorage,
1395
1410
  onDestroy(event) {
1396
1411
  return __async(this, null, function* () {
1397
1412
  logDebug(`${import_kleur2.default.blue("Deleting empty room:")} ${room}`);
package/dist/index.mjs CHANGED
@@ -398,6 +398,7 @@ var IORoom = class {
398
398
  context,
399
399
  crdt = noop,
400
400
  debug,
401
+ getInitialStorage,
401
402
  onDestroy,
402
403
  onMessage,
403
404
  onUserConnected,
@@ -411,6 +412,7 @@ var IORoom = class {
411
412
  this._crdt = crdt;
412
413
  this._debug = debug;
413
414
  this._docFactory = crdt.doc(() => ({}));
415
+ this._getInitialStorage = getInitialStorage;
414
416
  this._router = router;
415
417
  this._platform = platform.initialize(__spreadProps(__spreadValues({}, !!_meta ? { _meta } : {}), { roomContext }));
416
418
  this._listeners = {
@@ -763,6 +765,18 @@ var IORoom = class {
763
765
  return __async(this, null, function* () {
764
766
  const doc = this._docFactory.getEmpty();
765
767
  const encodedState = yield this._platform.persistence.getStorageState(this.id);
768
+ if (!encodedState) {
769
+ const loadedState = yield this._getInitialStorage({
770
+ context: this._context,
771
+ room: this.id
772
+ });
773
+ const checkDoc = this._crdt.doc(() => ({})).getEmpty().applyEncodedState({ update: loadedState });
774
+ const isEmpty = checkDoc.isEmpty();
775
+ checkDoc.destroy();
776
+ if (!!loadedState && !isEmpty) {
777
+ doc.applyEncodedState({ update: loadedState }).getEncodedState();
778
+ }
779
+ }
766
780
  if (typeof encodedState === "string") doc.applyEncodedState({ update: encodedState });
767
781
  return doc;
768
782
  });
@@ -1128,7 +1142,7 @@ var IORoom = class {
1128
1142
  };
1129
1143
 
1130
1144
  // src/version.generated.ts
1131
- var version = "3.1.6";
1145
+ var version = "3.1.7";
1132
1146
 
1133
1147
  // src/PluvServer.ts
1134
1148
  var PluvServer = class {
@@ -1350,6 +1364,7 @@ var PluvServer = class {
1350
1364
  context,
1351
1365
  crdt: this._config.crdt,
1352
1366
  debug: debug != null ? debug : this._config.debug,
1367
+ getInitialStorage: this._getInitialStorage,
1353
1368
  onDestroy(event) {
1354
1369
  return __async(this, null, function* () {
1355
1370
  logDebug(`${colors2.blue("Deleting empty room:")} ${room}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "3.1.6",
3
+ "version": "3.1.7",
4
4
  "description": "@pluv/io server-side websocket manager",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -21,16 +21,16 @@
21
21
  "jose": "^5.10.0",
22
22
  "kleur": "^4.1.5",
23
23
  "wonka": "^6.3.5",
24
- "@pluv/crdt": "^3.1.6",
25
- "@pluv/types": "^3.1.6"
24
+ "@pluv/crdt": "^3.1.7",
25
+ "@pluv/types": "^3.1.7"
26
26
  },
27
27
  "devDependencies": {
28
28
  "eslint": "^9.27.0",
29
29
  "genversion": "^3.2.0",
30
30
  "tsup": "^8.5.0",
31
31
  "typescript": "^5.8.3",
32
- "@pluv/tsconfig": "^3.1.6",
33
- "eslint-config-pluv": "^3.1.6"
32
+ "@pluv/tsconfig": "^3.1.7",
33
+ "eslint-config-pluv": "^3.1.7"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
package/src/IORoom.ts CHANGED
@@ -36,6 +36,7 @@ import { GARBAGE_COLLECT_INTERVAL_MS, PING_TIMEOUT_MS } from "./constants";
36
36
  import type {
37
37
  EventResolverContext,
38
38
  EventResolverKind,
39
+ GetInitialStorageFn,
39
40
  IORoomListenerEvent,
40
41
  IORoomMessageEvent,
41
42
  IOUserConnectedEvent,
@@ -91,6 +92,7 @@ export type IORoomConfig<
91
92
  context: TContext;
92
93
  crdt?: { doc: (value: any) => AbstractCrdtDocFactory<any, any> };
93
94
  debug: boolean;
95
+ getInitialStorage: GetInitialStorageFn<TContext>;
94
96
  platform: TPlatform;
95
97
  roomContext: InferRoomContextType<TPlatform>;
96
98
  router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
@@ -136,6 +138,7 @@ export class IORoom<
136
138
  private readonly _crdt: TCrdt;
137
139
  private readonly _debug: boolean;
138
140
  private readonly _docFactory: AbstractCrdtDocFactory<any, any>;
141
+ private readonly _getInitialStorage: GetInitialStorageFn<TContext>;
139
142
  private readonly _listeners: IORoomListeners<TPlatform, TAuthorize, TContext, TEvents>;
140
143
  private readonly _platform: TPlatform;
141
144
  private readonly _router: PluvRouter<TPlatform, TAuthorize, TContext, TEvents>;
@@ -194,6 +197,7 @@ export class IORoom<
194
197
  context,
195
198
  crdt = noop,
196
199
  debug,
200
+ getInitialStorage,
197
201
  onDestroy,
198
202
  onMessage,
199
203
  onUserConnected,
@@ -209,6 +213,7 @@ export class IORoom<
209
213
  this._crdt = crdt as TCrdt;
210
214
  this._debug = debug;
211
215
  this._docFactory = crdt.doc(() => ({}));
216
+ this._getInitialStorage = getInitialStorage;
212
217
  this._router = router;
213
218
  this._platform = platform.initialize({ ...(!!_meta ? { _meta } : {}), roomContext });
214
219
 
@@ -640,6 +645,24 @@ export class IORoom<
640
645
  const doc = this._docFactory.getEmpty();
641
646
  const encodedState = await this._platform.persistence.getStorageState(this.id);
642
647
 
648
+ if (!encodedState) {
649
+ const loadedState = await this._getInitialStorage({
650
+ context: this._context,
651
+ room: this.id,
652
+ });
653
+
654
+ const checkDoc = this._crdt
655
+ .doc(() => ({}))
656
+ .getEmpty()
657
+ .applyEncodedState({ update: loadedState });
658
+ const isEmpty = checkDoc.isEmpty();
659
+ checkDoc.destroy();
660
+
661
+ if (!!loadedState && !isEmpty) {
662
+ doc.applyEncodedState({ update: loadedState }).getEncodedState();
663
+ }
664
+ }
665
+
643
666
  if (typeof encodedState === "string") doc.applyEncodedState({ update: encodedState });
644
667
 
645
668
  return doc;
package/src/PluvServer.ts CHANGED
@@ -431,6 +431,7 @@ export class PluvServer<
431
431
  context,
432
432
  crdt: this._config.crdt,
433
433
  debug: debug ?? this._config.debug,
434
+ getInitialStorage: this._getInitialStorage,
434
435
  async onDestroy(event) {
435
436
  logDebug(`${colors.blue("Deleting empty room:")} ${room}`);
436
437
 
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '3.1.6'
2
+ export const version = '3.1.7'