@pluv/io 0.5.0 → 0.6.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +32 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +9 -7
- package/dist/index.mjs +9 -7
- package/package.json +1 -1
- package/src/PluvIO.ts +27 -18
- package/src/createIO.ts +4 -4
- package/src/index.ts +6 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.
|
|
2
|
+
> @pluv/io@0.6.0 build /home/runner/work/pluv/pluv/packages/io
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m28.98 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 93ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m31.04 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 93ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 3311ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m17.03 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2e7cbfa: Updated createIO config option `initialStorage` to be renamed to `getInitialStorage` and updated the params to use an object that includes platform parameters.
|
|
8
|
+
|
|
9
|
+
Previously:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
createIO({
|
|
13
|
+
initialStorage(room: string): Promise<string> => {
|
|
14
|
+
// ...
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Now:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
createIO({
|
|
23
|
+
platform: platformCloudflare<Env>(),
|
|
24
|
+
getInitialStorage({
|
|
25
|
+
// If you're using Cloudflare, this is the Cloudflare env parameter
|
|
26
|
+
env,
|
|
27
|
+
// The name of the room
|
|
28
|
+
room,
|
|
29
|
+
}): Promise<string> => {
|
|
30
|
+
// ...
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
3
35
|
## 0.5.0
|
|
4
36
|
|
|
5
37
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -238,6 +238,10 @@ interface AuthorizeModule {
|
|
|
238
238
|
type InferIOContext<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<any, any, infer IContext, any, any, any, any> ? IContext : never;
|
|
239
239
|
type InferIOPlatform<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<infer IPlatform, any, any, any, any, any, any> ? IPlatform : never;
|
|
240
240
|
type InferIORoom<TIO extends PluvIO<any, any, any, any, any, any, any>> = TIO extends PluvIO<infer IPlatform, infer IAuthorize, infer IContext, infer IInput, infer IOutputBroadcast, infer IOutputSelf, infer IOutputSync> ? IORoom<IPlatform, IAuthorize, IContext, IInput, IOutputBroadcast, IOutputSelf, IOutputSync> : never;
|
|
241
|
+
type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
242
|
+
room: string;
|
|
243
|
+
} & InferPlatformRoomContextType<TPlatform>;
|
|
244
|
+
type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (event: GetInitialStorageEvent<TPlatform>) => MaybePromise<Maybe<string>>;
|
|
241
245
|
interface PluvIOListeners<TPlatform extends AbstractPlatform> {
|
|
242
246
|
onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
243
247
|
onStorageUpdated: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
@@ -247,7 +251,7 @@ type PluvIOConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
247
251
|
context?: TContext;
|
|
248
252
|
debug?: boolean;
|
|
249
253
|
events?: InferEventConfig<TPlatform, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
250
|
-
|
|
254
|
+
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
251
255
|
platform: TPlatform;
|
|
252
256
|
};
|
|
253
257
|
type GetRoomOptions<TPlatform extends AbstractPlatform> = {
|
|
@@ -255,7 +259,7 @@ type GetRoomOptions<TPlatform extends AbstractPlatform> = {
|
|
|
255
259
|
} & InferPlatformRoomContextType<TPlatform>;
|
|
256
260
|
declare class PluvIO<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any>, TAuthorize extends IOAuthorize<any, any> = BaseIOAuthorize, TContext extends JsonObject = {}, TInput extends EventRecord<string, any> = {}, TOutputBroadcast extends EventRecord<string, any> = {}, TOutputSelf extends EventRecord<string, any> = {}, TOutputSync extends EventRecord<string, any> = {}> implements IOLike<TAuthorize, TInput, TOutputBroadcast, TOutputSelf, TOutputSync> {
|
|
257
261
|
private _context;
|
|
258
|
-
private
|
|
262
|
+
private _getInitialStorage;
|
|
259
263
|
private _rooms;
|
|
260
264
|
readonly _authorize: TAuthorize | null;
|
|
261
265
|
readonly _debug: boolean;
|
|
@@ -275,9 +279,9 @@ type CreateIOParams<TPlatform extends AbstractPlatform<any> = AbstractPlatform<a
|
|
|
275
279
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired>;
|
|
276
280
|
context?: TContext;
|
|
277
281
|
debug?: boolean;
|
|
278
|
-
|
|
282
|
+
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
279
283
|
platform: TPlatform;
|
|
280
284
|
};
|
|
281
285
|
declare const createIO: <TPlatform extends AbstractPlatform<any, {}, {}> = AbstractPlatform<any, {}, {}>, TContext extends JsonObject = {}, TAuthorizeUser extends BaseUser = BaseUser, TAuthorizeRequired extends boolean = false>(params: CreateIOParams<TPlatform, TContext, TAuthorizeUser, TAuthorizeRequired>) => PluvIO<TPlatform, IOAuthorize<TAuthorizeUser, TAuthorizeRequired>, TContext, BaseClientEventRecord, BaseIOEventRecord<IOAuthorize<TAuthorizeUser, TAuthorizeRequired>>, {}, {}>;
|
|
282
286
|
|
|
283
|
-
export { AbstractCloseEvent, AbstractErrorEvent, AbstractEvent, AbstractEventMap, AbstractListener, AbstractMessageEvent, AbstractPersistance, AbstractPlatform, AbstractPubSub, AbstractWebSocket, AbstractWebSocketConfig, AbstractWebSocketHandleErrorParams, AuthorizeModule, AuthorizeParams, ConvertWebSocketConfig, CreateIOParams, GetRoomOptions, IOPubSubEventMessage, IORoom, InferIORoom, InferPlatformEventContextType, InferPlatformRoomContextType, InferPlatformWebSocketType, JWT, JWTEncodeParams, PluvIO, createIO };
|
|
287
|
+
export { AbstractCloseEvent, AbstractErrorEvent, AbstractEvent, AbstractEventMap, AbstractListener, AbstractMessageEvent, AbstractPersistance, AbstractPlatform, AbstractPubSub, AbstractWebSocket, AbstractWebSocketConfig, AbstractWebSocketHandleErrorParams, AuthorizeModule, AuthorizeParams, ConvertWebSocketConfig, CreateIOParams, GetRoomOptions, IOPubSubEventMessage, IORoom, InferIORoom, InferPlatformEventContextType, InferPlatformRoomContextType, InferPlatformWebSocketType, JWT, JWTEncodeParams, PluvIO, PluvIOConfig, createIO };
|
package/dist/index.js
CHANGED
|
@@ -730,7 +730,7 @@ var IORoom = class {
|
|
|
730
730
|
var PluvIO = class {
|
|
731
731
|
constructor(options) {
|
|
732
732
|
this._context = {};
|
|
733
|
-
this.
|
|
733
|
+
this._getInitialStorage = null;
|
|
734
734
|
this._rooms = /* @__PURE__ */ new Map();
|
|
735
735
|
this._authorize = null;
|
|
736
736
|
this._events = {
|
|
@@ -770,7 +770,9 @@ var PluvIO = class {
|
|
|
770
770
|
var _a, _b;
|
|
771
771
|
const oldState = yield this._platform.persistance.getStorageState(room);
|
|
772
772
|
const updates = [
|
|
773
|
-
oldState ? null : yield (_a = this.
|
|
773
|
+
oldState ? null : yield (_a = this._getInitialStorage) == null ? void 0 : _a.call(this, __spreadProps(__spreadValues({}, context), {
|
|
774
|
+
room
|
|
775
|
+
})),
|
|
774
776
|
update
|
|
775
777
|
];
|
|
776
778
|
if (updates.some((_update) => !!_update)) {
|
|
@@ -836,7 +838,7 @@ var PluvIO = class {
|
|
|
836
838
|
context,
|
|
837
839
|
debug = false,
|
|
838
840
|
events,
|
|
839
|
-
|
|
841
|
+
getInitialStorage,
|
|
840
842
|
onRoomDeleted,
|
|
841
843
|
onStorageUpdated,
|
|
842
844
|
platform
|
|
@@ -849,8 +851,8 @@ var PluvIO = class {
|
|
|
849
851
|
this._context = context;
|
|
850
852
|
if (events)
|
|
851
853
|
this._events = events;
|
|
852
|
-
if (
|
|
853
|
-
this.
|
|
854
|
+
if (getInitialStorage)
|
|
855
|
+
this._getInitialStorage = getInitialStorage;
|
|
854
856
|
this._listeners = {
|
|
855
857
|
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
856
858
|
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event)
|
|
@@ -968,7 +970,7 @@ var createIO = (params) => {
|
|
|
968
970
|
authorize: authorize2,
|
|
969
971
|
context,
|
|
970
972
|
debug,
|
|
971
|
-
|
|
973
|
+
getInitialStorage,
|
|
972
974
|
onRoomDeleted,
|
|
973
975
|
onStorageUpdated,
|
|
974
976
|
platform
|
|
@@ -977,7 +979,7 @@ var createIO = (params) => {
|
|
|
977
979
|
authorize: authorize2,
|
|
978
980
|
context,
|
|
979
981
|
debug,
|
|
980
|
-
|
|
982
|
+
getInitialStorage,
|
|
981
983
|
onRoomDeleted,
|
|
982
984
|
onStorageUpdated,
|
|
983
985
|
platform
|
package/dist/index.mjs
CHANGED
|
@@ -693,7 +693,7 @@ var IORoom = class {
|
|
|
693
693
|
var PluvIO = class {
|
|
694
694
|
constructor(options) {
|
|
695
695
|
this._context = {};
|
|
696
|
-
this.
|
|
696
|
+
this._getInitialStorage = null;
|
|
697
697
|
this._rooms = /* @__PURE__ */ new Map();
|
|
698
698
|
this._authorize = null;
|
|
699
699
|
this._events = {
|
|
@@ -733,7 +733,9 @@ var PluvIO = class {
|
|
|
733
733
|
var _a, _b;
|
|
734
734
|
const oldState = yield this._platform.persistance.getStorageState(room);
|
|
735
735
|
const updates = [
|
|
736
|
-
oldState ? null : yield (_a = this.
|
|
736
|
+
oldState ? null : yield (_a = this._getInitialStorage) == null ? void 0 : _a.call(this, __spreadProps(__spreadValues({}, context), {
|
|
737
|
+
room
|
|
738
|
+
})),
|
|
737
739
|
update
|
|
738
740
|
];
|
|
739
741
|
if (updates.some((_update) => !!_update)) {
|
|
@@ -799,7 +801,7 @@ var PluvIO = class {
|
|
|
799
801
|
context,
|
|
800
802
|
debug = false,
|
|
801
803
|
events,
|
|
802
|
-
|
|
804
|
+
getInitialStorage,
|
|
803
805
|
onRoomDeleted,
|
|
804
806
|
onStorageUpdated,
|
|
805
807
|
platform
|
|
@@ -812,8 +814,8 @@ var PluvIO = class {
|
|
|
812
814
|
this._context = context;
|
|
813
815
|
if (events)
|
|
814
816
|
this._events = events;
|
|
815
|
-
if (
|
|
816
|
-
this.
|
|
817
|
+
if (getInitialStorage)
|
|
818
|
+
this._getInitialStorage = getInitialStorage;
|
|
817
819
|
this._listeners = {
|
|
818
820
|
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
819
821
|
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event)
|
|
@@ -931,7 +933,7 @@ var createIO = (params) => {
|
|
|
931
933
|
authorize: authorize2,
|
|
932
934
|
context,
|
|
933
935
|
debug,
|
|
934
|
-
|
|
936
|
+
getInitialStorage,
|
|
935
937
|
onRoomDeleted,
|
|
936
938
|
onStorageUpdated,
|
|
937
939
|
platform
|
|
@@ -940,7 +942,7 @@ var createIO = (params) => {
|
|
|
940
942
|
authorize: authorize2,
|
|
941
943
|
context,
|
|
942
944
|
debug,
|
|
943
|
-
|
|
945
|
+
getInitialStorage,
|
|
944
946
|
onRoomDeleted,
|
|
945
947
|
onStorageUpdated,
|
|
946
948
|
platform
|
package/package.json
CHANGED
package/src/PluvIO.ts
CHANGED
|
@@ -24,17 +24,15 @@ import type { JWTEncodeParams } from "./authorize";
|
|
|
24
24
|
import { authorize } from "./authorize";
|
|
25
25
|
import type { EventConfig, InferEventConfig } from "./types";
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
TIO extends PluvIO<any, any,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
? IPlatform
|
|
37
|
-
: never;
|
|
27
|
+
type InferIOContext<TIO extends PluvIO<any, any, any, any, any, any, any>> =
|
|
28
|
+
TIO extends PluvIO<any, any, infer IContext, any, any, any, any>
|
|
29
|
+
? IContext
|
|
30
|
+
: never;
|
|
31
|
+
|
|
32
|
+
type InferIOPlatform<TIO extends PluvIO<any, any, any, any, any, any, any>> =
|
|
33
|
+
TIO extends PluvIO<infer IPlatform, any, any, any, any, any, any>
|
|
34
|
+
? IPlatform
|
|
35
|
+
: never;
|
|
38
36
|
|
|
39
37
|
export type InferIORoom<TIO extends PluvIO<any, any, any, any, any, any, any>> =
|
|
40
38
|
TIO extends PluvIO<
|
|
@@ -57,6 +55,14 @@ export type InferIORoom<TIO extends PluvIO<any, any, any, any, any, any, any>> =
|
|
|
57
55
|
>
|
|
58
56
|
: never;
|
|
59
57
|
|
|
58
|
+
type GetInitialStorageEvent<TPlatform extends AbstractPlatform> = {
|
|
59
|
+
room: string;
|
|
60
|
+
} & InferPlatformRoomContextType<TPlatform>;
|
|
61
|
+
|
|
62
|
+
export type GetInitialStorageFn<TPlatform extends AbstractPlatform> = (
|
|
63
|
+
event: GetInitialStorageEvent<TPlatform>
|
|
64
|
+
) => MaybePromise<Maybe<string>>;
|
|
65
|
+
|
|
60
66
|
export interface PluvIOListeners<TPlatform extends AbstractPlatform> {
|
|
61
67
|
onRoomDeleted: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
62
68
|
onStorageUpdated: (event: IORoomListenerEvent<TPlatform>) => void;
|
|
@@ -82,7 +88,7 @@ export type PluvIOConfig<
|
|
|
82
88
|
TOutputSelf,
|
|
83
89
|
TOutputSync
|
|
84
90
|
>;
|
|
85
|
-
|
|
91
|
+
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
86
92
|
platform: TPlatform;
|
|
87
93
|
};
|
|
88
94
|
|
|
@@ -102,9 +108,7 @@ export class PluvIO<
|
|
|
102
108
|
IOLike<TAuthorize, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>
|
|
103
109
|
{
|
|
104
110
|
private _context: TContext = {} as TContext;
|
|
105
|
-
private
|
|
106
|
-
| ((room: string) => MaybePromise<Maybe<string>>)
|
|
107
|
-
| null = null;
|
|
111
|
+
private _getInitialStorage: GetInitialStorageFn<TPlatform> | null = null;
|
|
108
112
|
private _rooms = new Map<
|
|
109
113
|
string,
|
|
110
114
|
IORoom<
|
|
@@ -176,7 +180,12 @@ export class PluvIO<
|
|
|
176
180
|
await this._platform.persistance.getStorageState(room);
|
|
177
181
|
|
|
178
182
|
const updates: readonly Maybe<string>[] = [
|
|
179
|
-
oldState
|
|
183
|
+
oldState
|
|
184
|
+
? null
|
|
185
|
+
: await this._getInitialStorage?.({
|
|
186
|
+
...context,
|
|
187
|
+
room,
|
|
188
|
+
}),
|
|
180
189
|
update,
|
|
181
190
|
];
|
|
182
191
|
|
|
@@ -284,7 +293,7 @@ export class PluvIO<
|
|
|
284
293
|
context,
|
|
285
294
|
debug = false,
|
|
286
295
|
events,
|
|
287
|
-
|
|
296
|
+
getInitialStorage,
|
|
288
297
|
onRoomDeleted,
|
|
289
298
|
onStorageUpdated,
|
|
290
299
|
platform,
|
|
@@ -296,7 +305,7 @@ export class PluvIO<
|
|
|
296
305
|
if (authorize) this._authorize = authorize;
|
|
297
306
|
if (context) this._context = context;
|
|
298
307
|
if (events) this._events = events;
|
|
299
|
-
if (
|
|
308
|
+
if (getInitialStorage) this._getInitialStorage = getInitialStorage;
|
|
300
309
|
|
|
301
310
|
this._listeners = {
|
|
302
311
|
onRoomDeleted: (event) => onRoomDeleted?.(event),
|
package/src/createIO.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
MaybePromise,
|
|
9
9
|
} from "@pluv/types";
|
|
10
10
|
import type { AbstractPlatform } from "./AbstractPlatform";
|
|
11
|
-
import type { PluvIOListeners } from "./PluvIO";
|
|
11
|
+
import type { GetInitialStorageFn, PluvIOListeners } from "./PluvIO";
|
|
12
12
|
import { PluvIO } from "./PluvIO";
|
|
13
13
|
|
|
14
14
|
export type CreateIOParams<
|
|
@@ -20,7 +20,7 @@ export type CreateIOParams<
|
|
|
20
20
|
authorize?: IOAuthorize<TAuthorizeUser, TAuthorizeRequired>;
|
|
21
21
|
context?: TContext;
|
|
22
22
|
debug?: boolean;
|
|
23
|
-
|
|
23
|
+
getInitialStorage?: GetInitialStorageFn<TPlatform>;
|
|
24
24
|
platform: TPlatform;
|
|
25
25
|
};
|
|
26
26
|
|
|
@@ -47,7 +47,7 @@ export const createIO = <
|
|
|
47
47
|
authorize,
|
|
48
48
|
context,
|
|
49
49
|
debug,
|
|
50
|
-
|
|
50
|
+
getInitialStorage,
|
|
51
51
|
onRoomDeleted,
|
|
52
52
|
onStorageUpdated,
|
|
53
53
|
platform,
|
|
@@ -63,7 +63,7 @@ export const createIO = <
|
|
|
63
63
|
authorize,
|
|
64
64
|
context,
|
|
65
65
|
debug,
|
|
66
|
-
|
|
66
|
+
getInitialStorage,
|
|
67
67
|
onRoomDeleted,
|
|
68
68
|
onStorageUpdated,
|
|
69
69
|
platform,
|
package/src/index.ts
CHANGED
|
@@ -26,7 +26,12 @@ export type {
|
|
|
26
26
|
AbstractWebSocketHandleErrorParams,
|
|
27
27
|
} from "./AbstractWebSocket";
|
|
28
28
|
export type { IORoom } from "./IORoom";
|
|
29
|
-
export type {
|
|
29
|
+
export type {
|
|
30
|
+
GetRoomOptions,
|
|
31
|
+
InferIORoom,
|
|
32
|
+
PluvIO,
|
|
33
|
+
PluvIOConfig,
|
|
34
|
+
} from "./PluvIO";
|
|
30
35
|
export type {
|
|
31
36
|
AuthorizeModule,
|
|
32
37
|
AuthorizeParams,
|