@pluv/io 0.4.0 → 0.4.1
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 +9 -0
- package/dist/index.d.ts +5 -7
- package/dist/index.js +1 -16
- package/dist/index.mjs +1 -16
- package/package.json +4 -4
- package/src/IORoom.ts +4 -14
- package/src/PluvIO.ts +25 -10
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.4.
|
|
2
|
+
> @pluv/io@0.4.1 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
|
+
[32mCJS[39m [1mdist/index.js [22m[32m30.01 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 89ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m27.95 KB[39m
|
|
14
|
+
[32mESM[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[32m14.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 2921ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m14.84 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonObject, MaybePromise, IOEventMessage, EventRecord, InputZodLike, Id, IOLike, InferIOOutput, BaseUser, IOAuthorize, BaseIOAuthorize, InferIOInput,
|
|
1
|
+
import { JsonObject, MaybePromise, IOEventMessage, EventRecord, InputZodLike, Id, IOLike, InferIOOutput, BaseUser, IOAuthorize, BaseIOAuthorize, InferIOInput, InferIOAuthorizeUser, InferIOAuthorize, Spread, InferIOOutputBroadcast, InferIOOutputSelf, InferIOOutputSync, Maybe, BaseClientEventRecord, BaseIOEventRecord } from '@pluv/types';
|
|
2
2
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
3
3
|
import { YjsDoc } from '@pluv/crdt-yjs';
|
|
4
4
|
|
|
@@ -188,18 +188,16 @@ type IORoomConfig<TPlatform extends AbstractPlatform<any> = AbstractPlatform<any
|
|
|
188
188
|
context: TContext;
|
|
189
189
|
debug: boolean;
|
|
190
190
|
events: InferEventConfig<TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
|
|
191
|
-
initialStorage?: () => MaybePromise<Maybe<string>>;
|
|
192
191
|
platform: TPlatform;
|
|
193
192
|
};
|
|
194
193
|
interface WebsocketRegisterOptions {
|
|
195
|
-
token?: string;
|
|
194
|
+
token?: string | null;
|
|
196
195
|
}
|
|
197
196
|
declare class IORoom<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> {
|
|
198
197
|
private readonly _context;
|
|
199
198
|
private readonly _debug;
|
|
200
199
|
private readonly _platform;
|
|
201
200
|
private _doc;
|
|
202
|
-
private _initialStorage;
|
|
203
201
|
private _listeners;
|
|
204
202
|
private _sessions;
|
|
205
203
|
private _uninitialize;
|
|
@@ -228,9 +226,9 @@ declare class IORoom<TPlatform extends AbstractPlatform<any> = AbstractPlatform<
|
|
|
228
226
|
private _sendSyncMessage;
|
|
229
227
|
}
|
|
230
228
|
|
|
231
|
-
type InferIOContext<TIO extends PluvIO<any, any, any, any, any>> = TIO extends PluvIO<any, any, infer IContext, any, any> ? IContext : never;
|
|
232
|
-
type InferIOPlatform<TIO extends PluvIO<any, any, any, any>> = TIO extends PluvIO<infer IPlatform, any, any, any, any> ? IPlatform : never;
|
|
233
|
-
type InferIORoom<TIO extends PluvIO<any, any, any, any>> = TIO extends PluvIO<infer IPlatform, infer IAuthorize, infer IContext, infer IInput, infer
|
|
229
|
+
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;
|
|
230
|
+
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;
|
|
231
|
+
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;
|
|
234
232
|
interface PluvIOListeners {
|
|
235
233
|
onRoomDeleted: (room: string, encodedState: string) => void;
|
|
236
234
|
onStorageUpdated: (room: string, encodedState: string) => void;
|
package/dist/index.js
CHANGED
|
@@ -306,19 +306,10 @@ var PING_TIMEOUT_MS = 3e4;
|
|
|
306
306
|
var IORoom = class {
|
|
307
307
|
constructor(id, config) {
|
|
308
308
|
this._doc = (0, import_crdt_yjs.doc)();
|
|
309
|
-
this._initialStorage = null;
|
|
310
309
|
this._sessions = /* @__PURE__ */ new Map();
|
|
311
310
|
this._uninitialize = null;
|
|
312
311
|
this._authorize = null;
|
|
313
|
-
const {
|
|
314
|
-
authorize: authorize2,
|
|
315
|
-
context,
|
|
316
|
-
debug,
|
|
317
|
-
events,
|
|
318
|
-
initialStorage,
|
|
319
|
-
onDestroy,
|
|
320
|
-
platform
|
|
321
|
-
} = config;
|
|
312
|
+
const { authorize: authorize2, context, debug, events, onDestroy, platform } = config;
|
|
322
313
|
this._context = context;
|
|
323
314
|
this._debug = debug;
|
|
324
315
|
this._events = events;
|
|
@@ -331,8 +322,6 @@ var IORoom = class {
|
|
|
331
322
|
};
|
|
332
323
|
if (authorize2)
|
|
333
324
|
this._authorize = authorize2;
|
|
334
|
-
if (initialStorage)
|
|
335
|
-
this._initialStorage = initialStorage;
|
|
336
325
|
}
|
|
337
326
|
broadcast(event, data) {
|
|
338
327
|
const message = { type: event, data };
|
|
@@ -902,10 +891,6 @@ var PluvIO = class {
|
|
|
902
891
|
context: this._context,
|
|
903
892
|
debug: debug != null ? debug : this._debug,
|
|
904
893
|
events: this._events,
|
|
905
|
-
initialStorage: () => {
|
|
906
|
-
var _a2;
|
|
907
|
-
return (_a2 = this._initialStorage) == null ? void 0 : _a2.call(this, room);
|
|
908
|
-
},
|
|
909
894
|
onDestroy: (encodedState) => {
|
|
910
895
|
this._logDebug(
|
|
911
896
|
`${import_kleur2.default.blue("Deleting empty room:")} ${room}`
|
package/dist/index.mjs
CHANGED
|
@@ -269,19 +269,10 @@ var PING_TIMEOUT_MS = 3e4;
|
|
|
269
269
|
var IORoom = class {
|
|
270
270
|
constructor(id, config) {
|
|
271
271
|
this._doc = doc();
|
|
272
|
-
this._initialStorage = null;
|
|
273
272
|
this._sessions = /* @__PURE__ */ new Map();
|
|
274
273
|
this._uninitialize = null;
|
|
275
274
|
this._authorize = null;
|
|
276
|
-
const {
|
|
277
|
-
authorize: authorize2,
|
|
278
|
-
context,
|
|
279
|
-
debug,
|
|
280
|
-
events,
|
|
281
|
-
initialStorage,
|
|
282
|
-
onDestroy,
|
|
283
|
-
platform
|
|
284
|
-
} = config;
|
|
275
|
+
const { authorize: authorize2, context, debug, events, onDestroy, platform } = config;
|
|
285
276
|
this._context = context;
|
|
286
277
|
this._debug = debug;
|
|
287
278
|
this._events = events;
|
|
@@ -294,8 +285,6 @@ var IORoom = class {
|
|
|
294
285
|
};
|
|
295
286
|
if (authorize2)
|
|
296
287
|
this._authorize = authorize2;
|
|
297
|
-
if (initialStorage)
|
|
298
|
-
this._initialStorage = initialStorage;
|
|
299
288
|
}
|
|
300
289
|
broadcast(event, data) {
|
|
301
290
|
const message = { type: event, data };
|
|
@@ -865,10 +854,6 @@ var PluvIO = class {
|
|
|
865
854
|
context: this._context,
|
|
866
855
|
debug: debug != null ? debug : this._debug,
|
|
867
856
|
events: this._events,
|
|
868
|
-
initialStorage: () => {
|
|
869
|
-
var _a2;
|
|
870
|
-
return (_a2 = this._initialStorage) == null ? void 0 : _a2.call(this, room);
|
|
871
|
-
},
|
|
872
857
|
onDestroy: (encodedState) => {
|
|
873
858
|
this._logDebug(
|
|
874
859
|
`${colors2.blue("Deleting empty room:")} ${room}`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "@pluv/io server-side websocket manager",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"jose": "^4.14.4",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.2",
|
|
24
|
-
"@pluv/crdt-yjs": "^0.3.
|
|
24
|
+
"@pluv/crdt-yjs": "^0.3.8",
|
|
25
25
|
"@pluv/types": "^0.2.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"tsup": "^6.7.0",
|
|
32
32
|
"typescript": "^5.0.4",
|
|
33
|
-
"yjs": "^13.6.
|
|
33
|
+
"yjs": "^13.6.1",
|
|
34
34
|
"@pluv/tsconfig": "^0.1.6",
|
|
35
|
-
"eslint-config-pluv": "^0.1.
|
|
35
|
+
"eslint-config-pluv": "^0.1.12"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/IORoom.ts
CHANGED
|
@@ -64,7 +64,6 @@ export type IORoomConfig<
|
|
|
64
64
|
TOutputSelf,
|
|
65
65
|
TOutputSync
|
|
66
66
|
>;
|
|
67
|
-
initialStorage?: () => MaybePromise<Maybe<string>>;
|
|
68
67
|
platform: TPlatform;
|
|
69
68
|
};
|
|
70
69
|
|
|
@@ -74,7 +73,7 @@ interface SendMessageSender {
|
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
export interface WebsocketRegisterOptions {
|
|
77
|
-
token?: string;
|
|
76
|
+
token?: string | null;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
export class IORoom<
|
|
@@ -93,7 +92,6 @@ export class IORoom<
|
|
|
93
92
|
private readonly _platform: TPlatform;
|
|
94
93
|
|
|
95
94
|
private _doc: YjsDoc<any> = doc();
|
|
96
|
-
private _initialStorage: (() => MaybePromise<Maybe<string>>) | null = null;
|
|
97
95
|
private _listeners: IORoomListeners;
|
|
98
96
|
private _sessions = new Map<string, WebSocketSession>();
|
|
99
97
|
private _uninitialize: (() => Promise<void>) | null = null;
|
|
@@ -121,15 +119,8 @@ export class IORoom<
|
|
|
121
119
|
TOutputSync
|
|
122
120
|
>
|
|
123
121
|
) {
|
|
124
|
-
const {
|
|
125
|
-
|
|
126
|
-
context,
|
|
127
|
-
debug,
|
|
128
|
-
events,
|
|
129
|
-
initialStorage,
|
|
130
|
-
onDestroy,
|
|
131
|
-
platform,
|
|
132
|
-
} = config;
|
|
122
|
+
const { authorize, context, debug, events, onDestroy, platform } =
|
|
123
|
+
config;
|
|
133
124
|
|
|
134
125
|
this._context = context;
|
|
135
126
|
this._debug = debug;
|
|
@@ -145,7 +136,6 @@ export class IORoom<
|
|
|
145
136
|
};
|
|
146
137
|
|
|
147
138
|
if (authorize) this._authorize = authorize;
|
|
148
|
-
if (initialStorage) this._initialStorage = initialStorage;
|
|
149
139
|
}
|
|
150
140
|
|
|
151
141
|
public broadcast<TEvent extends keyof InferIOInput<this>>(
|
|
@@ -308,7 +298,7 @@ export class IORoom<
|
|
|
308
298
|
}
|
|
309
299
|
|
|
310
300
|
private async _getAuthorizedUser(
|
|
311
|
-
token: string
|
|
301
|
+
token: Maybe<string>
|
|
312
302
|
): Promise<InferIOAuthorizeUser<InferIOAuthorize<this>> | null> {
|
|
313
303
|
if (!this._authorize) return null;
|
|
314
304
|
if (!token) return null;
|
package/src/PluvIO.ts
CHANGED
|
@@ -21,21 +21,37 @@ import type { JWTEncodeParams } from "./authorize";
|
|
|
21
21
|
import { authorize } from "./authorize";
|
|
22
22
|
import type { EventConfig, InferEventConfig } from "./types";
|
|
23
23
|
|
|
24
|
-
export type InferIOContext<
|
|
25
|
-
TIO extends PluvIO<any, any,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export type
|
|
24
|
+
export type InferIOContext<
|
|
25
|
+
TIO extends PluvIO<any, any, any, any, any, any, any>
|
|
26
|
+
> = TIO extends PluvIO<any, any, infer IContext, any, any, any, any>
|
|
27
|
+
? IContext
|
|
28
|
+
: never;
|
|
29
|
+
|
|
30
|
+
export type InferIOPlatform<
|
|
31
|
+
TIO extends PluvIO<any, any, any, any, any, any, any>
|
|
32
|
+
> = TIO extends PluvIO<infer IPlatform, any, any, any, any, any, any>
|
|
33
|
+
? IPlatform
|
|
34
|
+
: never;
|
|
35
|
+
|
|
36
|
+
export type InferIORoom<TIO extends PluvIO<any, any, any, any, any, any, any>> =
|
|
31
37
|
TIO extends PluvIO<
|
|
32
38
|
infer IPlatform,
|
|
33
39
|
infer IAuthorize,
|
|
34
40
|
infer IContext,
|
|
35
41
|
infer IInput,
|
|
36
|
-
infer
|
|
42
|
+
infer IOutputBroadcast,
|
|
43
|
+
infer IOutputSelf,
|
|
44
|
+
infer IOutputSync
|
|
37
45
|
>
|
|
38
|
-
? IORoom<
|
|
46
|
+
? IORoom<
|
|
47
|
+
IPlatform,
|
|
48
|
+
IAuthorize,
|
|
49
|
+
IContext,
|
|
50
|
+
IInput,
|
|
51
|
+
IOutputBroadcast,
|
|
52
|
+
IOutputSelf,
|
|
53
|
+
IOutputSync
|
|
54
|
+
>
|
|
39
55
|
: never;
|
|
40
56
|
|
|
41
57
|
export interface PluvIORegisterOptions {
|
|
@@ -397,7 +413,6 @@ export class PluvIO<
|
|
|
397
413
|
context: this._context,
|
|
398
414
|
debug: debug ?? this._debug,
|
|
399
415
|
events: this._events,
|
|
400
|
-
initialStorage: () => this._initialStorage?.(room),
|
|
401
416
|
onDestroy: (encodedState) => {
|
|
402
417
|
this._logDebug(
|
|
403
418
|
`${colors.blue("Deleting empty room:")} ${room}`
|