@pluv/io 0.4.0 → 0.4.2

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,5 +1,5 @@
1
1
 
2
- > @pluv/io@0.4.0 build /home/runner/work/pluv/pluv/packages/io
2
+ > @pluv/io@0.4.2 build /home/runner/work/pluv/pluv/packages/io
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,10 +8,10 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 28.25 KB
12
- ESM ⚡️ Build success in 154ms
13
- CJS dist/index.js 30.31 KB
14
- CJS ⚡️ Build success in 155ms
11
+ CJS dist/index.js 30.12 KB
12
+ CJS ⚡️ Build success in 109ms
13
+ ESM dist/index.mjs 28.06 KB
14
+ ESM ⚡️ Build success in 112ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 4082ms
17
- DTS dist/index.d.ts 14.78 KB
16
+ DTS ⚡️ Build success in 3144ms
17
+ DTS dist/index.d.ts 14.86 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @pluv/io
2
2
 
3
+ ## 0.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 8917309: fixed PluvIO listeners onRoomDeleted and onStorageUpdated not working when additional events were added
8
+
9
+ ## 0.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - b85a232: bumped dependencies
14
+ - Updated dependencies [b85a232]
15
+ - @pluv/crdt-yjs@0.3.8
16
+ - @pluv/types@0.2.0
17
+
3
18
  ## 0.4.0
4
19
 
5
20
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JsonObject, MaybePromise, IOEventMessage, EventRecord, InputZodLike, Id, IOLike, InferIOOutput, BaseUser, IOAuthorize, BaseIOAuthorize, InferIOInput, Maybe, InferIOAuthorizeUser, InferIOAuthorize, Spread, InferIOOutputBroadcast, InferIOOutputSelf, InferIOOutputSync, BaseClientEventRecord, BaseIOEventRecord } from '@pluv/types';
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 IOutput> ? IORoom<IPlatform, IAuthorize, IContext, IInput, IOutput> : never;
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;
@@ -249,11 +247,11 @@ interface GetRoomOptions {
249
247
  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> {
250
248
  private _context;
251
249
  private _initialStorage;
252
- private _listeners;
253
250
  private _rooms;
254
251
  readonly _authorize: TAuthorize | null;
255
252
  readonly _debug: boolean;
256
253
  readonly _events: InferEventConfig<TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>;
254
+ readonly _listeners: PluvIOListeners;
257
255
  readonly _platform: TPlatform;
258
256
  constructor(options: PluvIOConfig<TPlatform, TAuthorize, TContext, TInput, TOutputBroadcast, TOutputSelf, TOutputSync>);
259
257
  createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>>): Promise<string>;
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}`
@@ -939,11 +924,14 @@ var PluvIO = class {
939
924
  const platform = first._platform;
940
925
  const events1 = first._events;
941
926
  const events2 = second._events;
927
+ const { onRoomDeleted, onStorageUpdated } = first._listeners;
942
928
  const events = Object.assign(/* @__PURE__ */ Object.create(null), events1, events2);
943
929
  return new PluvIO({
944
930
  authorize: authorize2,
945
931
  debug,
946
932
  events,
933
+ onRoomDeleted,
934
+ onStorageUpdated,
947
935
  platform
948
936
  });
949
937
  }
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}`
@@ -902,11 +887,14 @@ var PluvIO = class {
902
887
  const platform = first._platform;
903
888
  const events1 = first._events;
904
889
  const events2 = second._events;
890
+ const { onRoomDeleted, onStorageUpdated } = first._listeners;
905
891
  const events = Object.assign(/* @__PURE__ */ Object.create(null), events1, events2);
906
892
  return new PluvIO({
907
893
  authorize: authorize2,
908
894
  debug,
909
895
  events,
896
+ onRoomDeleted,
897
+ onStorageUpdated,
910
898
  platform
911
899
  });
912
900
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/io",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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.7",
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.0",
33
+ "yjs": "^13.6.1",
34
34
  "@pluv/tsconfig": "^0.1.6",
35
- "eslint-config-pluv": "^0.1.11"
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
- authorize,
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 | undefined
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<TIO extends PluvIO<any, any, any, any, any>> =
25
- TIO extends PluvIO<any, any, infer IContext, any, any> ? IContext : never;
26
-
27
- export type InferIOPlatform<TIO extends PluvIO<any, any, any, any>> =
28
- TIO extends PluvIO<infer IPlatform, any, any, any, any> ? IPlatform : never;
29
-
30
- export type InferIORoom<TIO extends PluvIO<any, any, any, any>> =
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 IOutput
42
+ infer IOutputBroadcast,
43
+ infer IOutputSelf,
44
+ infer IOutputSync
37
45
  >
38
- ? IORoom<IPlatform, IAuthorize, IContext, IInput, IOutput>
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 {
@@ -89,7 +105,6 @@ export class PluvIO<
89
105
  private _initialStorage:
90
106
  | ((room: string) => MaybePromise<Maybe<string>>)
91
107
  | null = null;
92
- private _listeners: PluvIOListeners;
93
108
  private _rooms = new Map<
94
109
  string,
95
110
  IORoom<
@@ -240,6 +255,7 @@ export class PluvIO<
240
255
  TOutputSelf,
241
256
  TOutputSync
242
257
  >;
258
+ readonly _listeners: PluvIOListeners;
243
259
  readonly _platform: TPlatform;
244
260
 
245
261
  constructor(
@@ -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}`
@@ -452,12 +467,16 @@ export class PluvIO<
452
467
  const events1 = first._events;
453
468
  const events2 = second._events;
454
469
 
470
+ const { onRoomDeleted, onStorageUpdated } = first._listeners;
471
+
455
472
  const events = Object.assign(Object.create(null), events1, events2);
456
473
 
457
474
  return new PluvIO({
458
475
  authorize,
459
476
  debug,
460
477
  events,
478
+ onRoomDeleted,
479
+ onStorageUpdated,
461
480
  platform,
462
481
  });
463
482
  }