@pluv/platform-pluv 2.2.4 → 2.2.6

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/platform-pluv@2.2.4 build /home/runner/work/pluv/pluv/packages/platform-pluv
2
+ > @pluv/platform-pluv@2.2.6 build /home/runner/work/pluv/pluv/packages/platform-pluv
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- CJS dist/index.js 14.70 KB
12
- CJS ⚡️ Build success in 123ms
13
- ESM dist/index.mjs 12.86 KB
14
- ESM ⚡️ Build success in 123ms
11
+ ESM dist/index.mjs 12.99 KB
12
+ ESM ⚡️ Build success in 132ms
13
+ CJS dist/index.js 14.82 KB
14
+ CJS ⚡️ Build success in 132ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 6713ms
17
- DTS dist/index.d.mts 3.72 KB
18
- DTS dist/index.d.ts 3.72 KB
16
+ DTS ⚡️ Build success in 6531ms
17
+ DTS dist/index.d.mts 3.79 KB
18
+ DTS dist/index.d.ts 3.79 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @pluv/platform-pluv
2
2
 
3
+ ## 2.2.6
4
+
5
+ ### Patch Changes
6
+
7
+ - d5837ce: Fixed the context in `platformPluv` being declared immediately, instead of when the event listeners ran (causing errors in Cloudflare Workers).
8
+ - @pluv/crdt@2.2.6
9
+ - @pluv/io@2.2.6
10
+ - @pluv/types@2.2.6
11
+
12
+ ## 2.2.5
13
+
14
+ ### Patch Changes
15
+
16
+ - @pluv/crdt@2.2.5
17
+ - @pluv/io@2.2.5
18
+ - @pluv/types@2.2.5
19
+
3
20
  ## 2.2.4
4
21
 
5
22
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
1
+ import { PluvContext, BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType } from '@pluv/io';
2
2
  import { MaybePromise, BaseUser as BaseUser$1, Id } from '@pluv/types';
3
3
 
4
4
  interface PluvIOEndpoints {
@@ -19,7 +19,7 @@ interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
19
19
  endpoints?: PluvIOEndpoints | (() => MaybePromise<PluvIOEndpoints>);
20
20
  };
21
21
  basePath: string;
22
- context?: TContext;
22
+ context?: PluvContext<any, TContext>;
23
23
  publicKey: PublicKey;
24
24
  secretKey: SecretKey;
25
25
  webhookSecret?: WebhookSecret;
@@ -40,6 +40,7 @@ declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser exte
40
40
  };
41
41
  router: false;
42
42
  }> {
43
+ readonly id: string;
43
44
  readonly _config: {
44
45
  authorize: {
45
46
  secret: false;
@@ -81,6 +82,7 @@ declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser exte
81
82
  setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
82
83
  validateConfig(config: any): void;
83
84
  private _webhooksRouter;
85
+ private _getContext;
84
86
  private _logDebug;
85
87
  }
86
88
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType, PluvContext } from '@pluv/io';
1
+ import { PluvContext, BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType } from '@pluv/io';
2
2
  import { MaybePromise, BaseUser as BaseUser$1, Id } from '@pluv/types';
3
3
 
4
4
  interface PluvIOEndpoints {
@@ -19,7 +19,7 @@ interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
19
19
  endpoints?: PluvIOEndpoints | (() => MaybePromise<PluvIOEndpoints>);
20
20
  };
21
21
  basePath: string;
22
- context?: TContext;
22
+ context?: PluvContext<any, TContext>;
23
23
  publicKey: PublicKey;
24
24
  secretKey: SecretKey;
25
25
  webhookSecret?: WebhookSecret;
@@ -40,6 +40,7 @@ declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser exte
40
40
  };
41
41
  router: false;
42
42
  }> {
43
+ readonly id: string;
43
44
  readonly _config: {
44
45
  authorize: {
45
46
  secret: false;
@@ -81,6 +82,7 @@ declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser exte
81
82
  setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
82
83
  validateConfig(config: any): void;
83
84
  private _webhooksRouter;
85
+ private _getContext;
84
86
  private _logDebug;
85
87
  }
86
88
 
package/dist/index.js CHANGED
@@ -219,6 +219,7 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
219
219
  constructor(params) {
220
220
  var _a, _b;
221
221
  super();
222
+ this.id = Math.random().toString();
222
223
  this._config = {
223
224
  authorize: {
224
225
  secret: false
@@ -288,7 +289,7 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
288
289
  const parsed = ZodEvent.safeParse(payload);
289
290
  if (!parsed.success) throw new HttpError("Invalid request", 400);
290
291
  const { event, data } = parsed.data;
291
- const context = this._context;
292
+ const context = this._getContext();
292
293
  switch (event) {
293
294
  case "initial-storage": {
294
295
  const room = data.room;
@@ -345,7 +346,7 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
345
346
  }));
346
347
  const { _defs, basePath, context, publicKey, secretKey, webhookSecret } = params;
347
348
  this._basePath = basePath;
348
- this._context = typeof context === "function" ? context(this._roomContext) : context;
349
+ this._context = context != null ? context : {};
349
350
  this._debug = (_a = _defs == null ? void 0 : _defs.debug) != null ? _a : false;
350
351
  this._endpoints = (_b = _defs == null ? void 0 : _defs.endpoints) != null ? _b : {
351
352
  createToken: "https://rooms.pluv.io/api/room/token"
@@ -409,6 +410,9 @@ var PluvPlatform = class extends import_io.AbstractPlatform {
409
410
  }
410
411
  };
411
412
  }
413
+ _getContext() {
414
+ return typeof this._context === "function" ? this._context(this._roomContext) : this._context;
415
+ }
412
416
  _logDebug(...args) {
413
417
  if (!this._debug) return;
414
418
  console.log("[PLATFORM PLUV]", ...args);
package/dist/index.mjs CHANGED
@@ -189,6 +189,7 @@ var PluvPlatform = class extends AbstractPlatform {
189
189
  constructor(params) {
190
190
  var _a, _b;
191
191
  super();
192
+ this.id = Math.random().toString();
192
193
  this._config = {
193
194
  authorize: {
194
195
  secret: false
@@ -258,7 +259,7 @@ var PluvPlatform = class extends AbstractPlatform {
258
259
  const parsed = ZodEvent.safeParse(payload);
259
260
  if (!parsed.success) throw new HttpError("Invalid request", 400);
260
261
  const { event, data } = parsed.data;
261
- const context = this._context;
262
+ const context = this._getContext();
262
263
  switch (event) {
263
264
  case "initial-storage": {
264
265
  const room = data.room;
@@ -315,7 +316,7 @@ var PluvPlatform = class extends AbstractPlatform {
315
316
  }));
316
317
  const { _defs, basePath, context, publicKey, secretKey, webhookSecret } = params;
317
318
  this._basePath = basePath;
318
- this._context = typeof context === "function" ? context(this._roomContext) : context;
319
+ this._context = context != null ? context : {};
319
320
  this._debug = (_a = _defs == null ? void 0 : _defs.debug) != null ? _a : false;
320
321
  this._endpoints = (_b = _defs == null ? void 0 : _defs.endpoints) != null ? _b : {
321
322
  createToken: "https://rooms.pluv.io/api/room/token"
@@ -379,6 +380,9 @@ var PluvPlatform = class extends AbstractPlatform {
379
380
  }
380
381
  };
381
382
  }
383
+ _getContext() {
384
+ return typeof this._context === "function" ? this._context(this._roomContext) : this._context;
385
+ }
382
386
  _logDebug(...args) {
383
387
  if (!this._debug) return;
384
388
  console.log("[PLATFORM PLUV]", ...args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-pluv",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "description": "@pluv/io adapter for pluv.io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -21,16 +21,16 @@
21
21
  "fast-json-stable-stringify": "^2.1.0",
22
22
  "hono": "^4.7.10",
23
23
  "zod": "^3.25.17",
24
- "@pluv/crdt": "^2.2.4",
25
- "@pluv/io": "^2.2.4",
26
- "@pluv/types": "^2.2.4"
24
+ "@pluv/crdt": "^2.2.6",
25
+ "@pluv/io": "^2.2.6",
26
+ "@pluv/types": "^2.2.6"
27
27
  },
28
28
  "devDependencies": {
29
29
  "eslint": "^9.27.0",
30
30
  "tsup": "^8.5.0",
31
31
  "typescript": "^5.8.3",
32
- "eslint-config-pluv": "^2.2.4",
33
- "@pluv/tsconfig": "^2.2.4"
32
+ "@pluv/tsconfig": "^2.2.6",
33
+ "eslint-config-pluv": "^2.2.6"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -5,6 +5,7 @@ import type {
5
5
  ConvertWebSocketConfig,
6
6
  GetInitialStorageFn,
7
7
  JWTEncodeParams,
8
+ PluvContext,
8
9
  WebSocketSerializedState,
9
10
  } from "@pluv/io";
10
11
  import { AbstractPlatform } from "@pluv/io";
@@ -33,7 +34,7 @@ export interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
33
34
  endpoints?: PluvIOEndpoints | (() => MaybePromise<PluvIOEndpoints>);
34
35
  };
35
36
  basePath: string;
36
- context?: TContext;
37
+ context?: PluvContext<any, TContext>;
37
38
  publicKey: PublicKey;
38
39
  secretKey: SecretKey;
39
40
  webhookSecret?: WebhookSecret;
@@ -63,6 +64,7 @@ export class PluvPlatform<
63
64
  router: false;
64
65
  }
65
66
  > {
67
+ public readonly id = Math.random().toString();
66
68
  public readonly _config = {
67
69
  authorize: {
68
70
  secret: false as const,
@@ -83,7 +85,7 @@ export class PluvPlatform<
83
85
 
84
86
  private readonly _app: Hono;
85
87
  private readonly _basePath: string;
86
- private readonly _context: any;
88
+ private readonly _context: PluvContext<this, TContext>;
87
89
  private readonly _debug: boolean;
88
90
  private readonly _endpoints: PluvIOEndpoints | (() => MaybePromise<PluvIOEndpoints>);
89
91
  private _getInitialStorage?: GetInitialStorageFn<{}>;
@@ -140,7 +142,7 @@ export class PluvPlatform<
140
142
  const { _defs, basePath, context, publicKey, secretKey, webhookSecret } = params;
141
143
 
142
144
  this._basePath = basePath;
143
- this._context = typeof context === "function" ? context(this._roomContext) : context;
145
+ this._context = (context ?? {}) as TContext;
144
146
  this._debug = _defs?.debug ?? false;
145
147
  this._endpoints = _defs?.endpoints ?? {
146
148
  createToken: "https://rooms.pluv.io/api/room/token",
@@ -242,7 +244,7 @@ export class PluvPlatform<
242
244
  if (!parsed.success) throw new HttpError("Invalid request", 400);
243
245
 
244
246
  const { event, data } = parsed.data;
245
- const context = this._context;
247
+ const context = this._getContext();
246
248
 
247
249
  switch (event) {
248
250
  case "initial-storage": {
@@ -310,6 +312,12 @@ export class PluvPlatform<
310
312
  }
311
313
  });
312
314
 
315
+ private _getContext(): TContext {
316
+ return typeof this._context === "function"
317
+ ? this._context(this._roomContext as any)
318
+ : this._context;
319
+ }
320
+
313
321
  private _logDebug(...args: any[]): void {
314
322
  if (!this._debug) return;
315
323