@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.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -1
- package/dist/index.mjs +16 -1
- package/package.json +5 -5
- package/src/IORoom.ts +23 -0
- package/src/PluvServer.ts +1 -0
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@3.1.
|
|
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
|
+
> @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
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
[34mCLI[39m Target: es6
|
|
13
13
|
[34mESM[39m Build start
|
|
14
14
|
[34mCJS[39m Build start
|
|
15
|
-
[32mCJS[39m [1mdist/index.js [22m[32m55.
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in
|
|
17
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m55.74 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 106ms
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m53.56 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 110ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 4281ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m34.07 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m34.07 KB[39m
|
package/CHANGELOG.md
CHANGED
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.
|
|
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.
|
|
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.
|
|
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.
|
|
25
|
-
"@pluv/types": "^3.1.
|
|
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.
|
|
33
|
-
"eslint-config-pluv": "^3.1.
|
|
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
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '3.1.
|
|
2
|
+
export const version = '3.1.7'
|