@pluv/platform-pluv 3.2.2 → 4.0.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.
@@ -1,18 +1,18 @@
1
1
 
2
- > @pluv/platform-pluv@3.2.2 build /home/runner/work/pluv/pluv/packages/platform-pluv
3
- > tsup src/index.ts --format esm,cjs --dts
2
+ > @pluv/platform-pluv@4.0.1 build /home/runner/work/pluv/pluv/packages/platform-pluv
3
+ > tsdown
4
4
 
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.0
8
- CLI Target: es6
9
- ESM Build start
10
- CJS Build start
11
- ESM dist/index.mjs 15.14 KB
12
- ESM ⚡️ Build success in 105ms
13
- CJS dist/index.js 16.97 KB
14
- CJS ⚡️ Build success in 108ms
15
- DTS Build start
16
- DTS ⚡️ Build success in 6581ms
17
- DTS dist/index.d.mts 4.07 KB
18
- DTS dist/index.d.ts 4.07 KB
5
+ ℹ tsdown v0.20.0-beta.4 powered by rolldown v1.0.0-beta.60
6
+ ℹ config file: /home/runner/work/pluv/pluv/packages/platform-pluv/tsdown.config.ts
7
+ ℹ entry: src/index.ts
8
+ ℹ target: esnext
9
+ ℹ tsconfig: tsconfig.json
10
+ ℹ Build start
11
+ [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
12
+ ℹ dist/index.mjs 13.74 kB │ gzip: 3.46 kB
13
+ ℹ dist/index.mjs.map 33.93 kB │ gzip: 7.44 kB
14
+ ℹ dist/index.d.mts.map  1.86 kB │ gzip: 0.69 kB
15
+ ℹ dist/index.d.mts  4.21 kB │ gzip: 1.29 kB
16
+ ℹ 4 files, total: 53.74 kB
17
+
18
+ ✔ Build complete in 3774ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,105 @@
1
1
  # @pluv/platform-pluv
2
2
 
3
+ ## 4.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 982e068: Added http header for webhook events (`x-pluv-event`).
8
+ - @pluv/crdt@4.0.1
9
+ - @pluv/io@4.0.1
10
+ - @pluv/types@4.0.1
11
+
12
+ ## 4.0.0
13
+
14
+ ### Major Changes
15
+
16
+ - df5c39c: Update all packages to be ESM only.
17
+ - 07e2a1e: ### Breaking Changes
18
+
19
+ This release includes the following breaking changes:
20
+ 1. **Removed `onDestroy` handler** (room-level only) - replaced with `onRoomDestroyed` and `onStorageDestroyed`
21
+ 2. **Removed `onRoomDeleted` handler** (server-level) - replaced with `onRoomDestroyed` and `onStorageDestroyed`
22
+ 3. **Listeners can no longer be configured at room-level** - all listeners must be configured at server-level via `io.server()`
23
+ 4. **Event type changes** - `IORoomDestroyedEvent` no longer includes `encodedState`
24
+
25
+ #### Remove `onDestroy` and `onRoomDeleted` in favor of `onRoomDestroyed` and `onStorageDestroyed`
26
+
27
+ **BREAKING**: Two event handlers have been **removed** in favor of two separate handlers that provide better control over when storage is saved. This is a breaking change that requires code updates.
28
+
29
+ **New Handlers:**
30
+ - **`onRoomDestroyed`**: Fires whenever a room is destroyed. This event does NOT include `encodedState` to prevent accidentally saving empty or uninitialized storage data. **Available only at server-level** via `io.server()`.
31
+ - **`onStorageDestroyed`**: Only fires when the storage document is about to be destroyed after it has been initialized via `initializeSession`. This event includes `encodedState` and should be used for saving storage to your database. **Available only at server-level** via `io.server()`.
32
+
33
+ **Removed Handlers:**
34
+ - **`onDestroy`** (room-level only, via `createRoom`): **REMOVED**. Use `onRoomDestroyed` and `onStorageDestroyed` instead.
35
+ - **`onRoomDeleted`** (server-level): **REMOVED**. Use `onRoomDestroyed` and `onStorageDestroyed` instead.
36
+
37
+ **Migration Guide:**
38
+
39
+ **Old (no longer works):**
40
+
41
+ ```typescript
42
+ // Room-level onDestroy (removed)
43
+ const room = io.createRoom("room-id", {
44
+ onDestroy: async ({ encodedState, room }) => {
45
+ // This no longer works
46
+ await saveToDatabase(room, encodedState);
47
+ },
48
+ });
49
+
50
+ // Server-level onRoomDeleted (removed)
51
+ io.server({
52
+ onRoomDeleted: async ({ encodedState, room }) => {
53
+ // This no longer works
54
+ await saveToDatabase(room, encodedState);
55
+ },
56
+ });
57
+ ```
58
+
59
+ **New (recommended approach):**
60
+
61
+ ```typescript
62
+ // Server-level handlers (recommended - all listeners are now server-level)
63
+ io.server({
64
+ onRoomDestroyed: async ({ room }) => {
65
+ // Room destroyed - use for cleanup if needed
66
+ await cleanupRoom(room);
67
+ },
68
+ onStorageDestroyed: async ({ encodedState, room }) => {
69
+ // Only fires when storage was initialized via initializeSession
70
+ // Safe to save to database
71
+ await saveToDatabase(room, encodedState);
72
+ },
73
+ });
74
+
75
+ // Rooms are created without listener options
76
+ const room = io.createRoom("room-id");
77
+ ```
78
+
79
+ #### Type Changes
80
+
81
+ **BREAKING**: The following type changes may require TypeScript code updates:
82
+ - **`IORoomDestroyedEvent`** no longer includes `encodedState` (breaking change if you were accessing `encodedState` from this event)
83
+ - **`IORoomListenerEvent`** includes `encodedState: string | null` (used by `onStorageDestroyed`)
84
+ - **All listeners must be configured at the server level** via `io.server()`, not at the room level via `createRoom()` (breaking change - room-level listener configuration is no longer supported)
85
+ - **`CreateRoomOptions`** now correctly requires platform-specific room context properties (e.g., `env` and `state` for Cloudflare) when they are required by the platform, while properly handling optional properties like `meta` (breaking change - TypeScript will now correctly enforce required properties)
86
+
87
+ ### Minor Changes
88
+
89
+ - 037074e: Migrated build process from tsup to tsdown.
90
+
91
+ ### Patch Changes
92
+
93
+ - 2eb5def: Bumped dependencies.
94
+ - Updated dependencies [2eb5def]
95
+ - Updated dependencies [df5c39c]
96
+ - Updated dependencies [c142910]
97
+ - Updated dependencies [037074e]
98
+ - Updated dependencies [07e2a1e]
99
+ - @pluv/types@4.0.0
100
+ - @pluv/crdt@4.0.0
101
+ - @pluv/io@4.0.0
102
+
3
103
  ## 3.2.2
4
104
 
5
105
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,96 +1,103 @@
1
- import { CrdtLibraryType, NoopCrdtDocFactory } from '@pluv/crdt';
2
- import { PluvContext, BaseUser, AbstractPlatform, JWTEncodeParams, AbstractWebSocket, ConvertWebSocketConfig, WebSocketSerializedState, AbstractPlatformConfig, CreateIOParams, PluvIOAuthorize, InferInitContextType } from '@pluv/io';
3
- import { MaybePromise, BaseUser as BaseUser$1, Id } from '@pluv/types';
1
+ import { AbstractPlatform, AbstractPlatformConfig, AbstractWebSocket, BaseUser, ConvertWebSocketConfig, CreateIOParams, InferInitContextType, JWTEncodeParams, PluvContext, PluvIOAuthorize, WebSocketSerializedState } from "@pluv/io";
2
+ import { z } from "zod";
3
+ import { CrdtLibraryType, NoopCrdtDocFactory } from "@pluv/crdt";
4
+ import { BaseUser as BaseUser$1, Id, MaybePromise } from "@pluv/types";
4
5
 
6
+ //#region src/types.d.ts
5
7
  interface PluvIOEndpoints {
6
- createToken: string;
8
+ createToken: string;
7
9
  }
8
-
10
+ //#endregion
11
+ //#region src/PluvPlatform.d.ts
9
12
  type PublicKey = string | (() => MaybePromise<string>);
10
13
  type SecretKey = string | (() => MaybePromise<string>);
11
14
  type WebhookSecret = string | (() => MaybePromise<string>);
12
15
  interface PluvPlatformConfig<TContext extends Record<string, any> = {}> {
13
- /**
14
- * @ignore
15
- * @readonly
16
- * @deprecated Internal use only. Changes to this will never be marked as breaking.
17
- */
18
- _defs?: {
19
- debug?: boolean;
20
- endpoints?: PluvIOEndpoints | (() => MaybePromise<PluvIOEndpoints>);
21
- };
22
- basePath: string;
23
- context?: PluvContext<any, TContext>;
24
- publicKey: PublicKey;
25
- secretKey: SecretKey;
26
- webhookSecret?: WebhookSecret;
16
+ /**
17
+ * @ignore
18
+ * @readonly
19
+ * @deprecated Internal use only. Changes to this will never be marked as breaking.
20
+ */
21
+ _defs?: {
22
+ debug?: boolean;
23
+ endpoints?: PluvIOEndpoints | (() => MaybePromise<PluvIOEndpoints>);
24
+ };
25
+ basePath: string;
26
+ context?: PluvContext<any, TContext>;
27
+ publicKey: PublicKey;
28
+ secretKey: SecretKey;
29
+ webhookSecret?: WebhookSecret;
27
30
  }
28
31
  declare class PluvPlatform<TContext extends Record<string, any> = {}, TUser extends BaseUser = BaseUser> extends AbstractPlatform<any, {}, {}, {
32
+ authorize: {
33
+ secret: false;
34
+ };
35
+ handleMode: "fetch";
36
+ registrationMode: "attached";
37
+ requireAuth: true;
38
+ listeners: {
39
+ onRoomDestroyed: true;
40
+ onRoomMessage: false;
41
+ onStorageDestroyed: true;
42
+ onStorageUpdated: false;
43
+ onUserConnected: true;
44
+ onUserDisconnected: true;
45
+ };
46
+ router: false;
47
+ }> {
48
+ readonly id: string;
49
+ readonly _config: {
29
50
  authorize: {
30
- secret: false;
51
+ secret: false;
31
52
  };
32
53
  handleMode: "fetch";
33
54
  registrationMode: "attached";
34
55
  requireAuth: true;
35
56
  listeners: {
36
- onRoomDeleted: true;
37
- onRoomMessage: false;
38
- onStorageUpdated: false;
39
- onUserConnected: true;
40
- onUserDisconnected: true;
57
+ onRoomDestroyed: true;
58
+ onRoomMessage: false;
59
+ onStorageDestroyed: true;
60
+ onStorageUpdated: false;
61
+ onUserConnected: true;
62
+ onUserDisconnected: true;
41
63
  };
42
64
  router: false;
43
- }> {
44
- readonly id: string;
45
- readonly _config: {
46
- authorize: {
47
- secret: false;
48
- };
49
- handleMode: "fetch";
50
- registrationMode: "attached";
51
- requireAuth: true;
52
- listeners: {
53
- onRoomDeleted: true;
54
- onRoomMessage: false;
55
- onStorageUpdated: false;
56
- onUserConnected: true;
57
- onUserDisconnected: true;
58
- };
59
- router: false;
60
- };
61
- readonly _name = "platformPluv";
62
- private readonly _app;
63
- private readonly _basePath;
64
- private readonly _context;
65
- private readonly _debug;
66
- private readonly _endpoints;
67
- private _getInitialStorage?;
68
- private _listeners?;
69
- private readonly _publicKey;
70
- private readonly _secretKey;
71
- private readonly _webhookSecret?;
72
- _createToken: (params: JWTEncodeParams<any, any>) => Promise<string>;
73
- constructor(params: PluvPlatformConfig);
74
- acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
75
- convertWebSocket(webSocket: any, config: ConvertWebSocketConfig): AbstractWebSocket;
76
- getLastPing(webSocket: AbstractWebSocket): number | null;
77
- getSerializedState(webSocket: any): WebSocketSerializedState | null;
78
- getSessionId(webSocket: any): string | null;
79
- getWebSockets(): readonly any[];
80
- initialize(config: AbstractPlatformConfig<{}>): this;
81
- parseData(data: string | ArrayBuffer): Record<string, any>;
82
- randomUUID(): string;
83
- setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
84
- validateConfig(config: any): void;
85
- private _webhooksRouter;
86
- private _getContext;
87
- private _logDebug;
65
+ };
66
+ readonly _name = "platformPluv";
67
+ private readonly _app;
68
+ private readonly _basePath;
69
+ private readonly _context;
70
+ private readonly _debug;
71
+ private readonly _endpoints;
72
+ private _getInitialStorage?;
73
+ private _listeners?;
74
+ private readonly _publicKey;
75
+ private readonly _secretKey;
76
+ private readonly _webhookSecret?;
77
+ _createToken: (params: JWTEncodeParams<any, any>) => Promise<string>;
78
+ constructor(params: PluvPlatformConfig);
79
+ acceptWebSocket(webSocket: AbstractWebSocket): Promise<void>;
80
+ convertWebSocket(webSocket: any, config: ConvertWebSocketConfig): AbstractWebSocket;
81
+ getLastPing(webSocket: AbstractWebSocket): number | null;
82
+ getSerializedState(webSocket: any): WebSocketSerializedState | null;
83
+ getSessionId(webSocket: any): string | null;
84
+ getWebSockets(): readonly any[];
85
+ initialize(config: AbstractPlatformConfig<{}>): this;
86
+ parseData(data: string | ArrayBuffer): Record<string, any>;
87
+ randomUUID(): string;
88
+ setSerializedState(webSocket: AbstractWebSocket, state: WebSocketSerializedState): WebSocketSerializedState;
89
+ validateConfig(config: any): void;
90
+ private _webhooksRouter;
91
+ private _getContext;
92
+ private _logDebug;
88
93
  }
89
-
94
+ //#endregion
95
+ //#region src/platformPluv.d.ts
90
96
  type PlatformPluvCreateIOParams<TContext extends Record<string, any> = {}, TUser extends BaseUser$1 = BaseUser$1, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>> = Id<PluvPlatformConfig & Omit<CreateIOParams<PluvPlatform, TContext, TUser, TCrdt>, "authorize" | "context" | "limits" | "platform"> & {
91
- authorize: PluvIOAuthorize<PluvPlatform, TUser, InferInitContextType<PluvPlatform>>;
92
- context?: PluvContext<PluvPlatform, TContext>;
97
+ authorize: PluvIOAuthorize<PluvPlatform, TUser, InferInitContextType<PluvPlatform>>;
98
+ context?: PluvContext<PluvPlatform, TContext>;
93
99
  }>;
94
100
  declare const platformPluv: <TContext extends Record<string, any> = {}, TUser extends BaseUser$1 = BaseUser$1, TCrdt extends CrdtLibraryType<any> = CrdtLibraryType<NoopCrdtDocFactory>>(config: PlatformPluvCreateIOParams<TContext, TUser, TCrdt>) => CreateIOParams<PluvPlatform<TContext, TUser>, TContext, TUser, TCrdt>;
95
-
101
+ //#endregion
96
102
  export { type PlatformPluvCreateIOParams, type PluvIOEndpoints, PluvPlatform, type PublicKey, type SecretKey, type WebhookSecret, platformPluv };
103
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/PluvPlatform.ts","../src/platformPluv.ts"],"mappings":";;;;;;UAqBiB,eAAA;EACb,WAAA;AAAA;;;KCDQ,SAAA,mBAA4B,YAAA;AAAA,KAC5B,SAAA,mBAA4B,YAAA;AAAA,KAC5B,aAAA,mBAAgC,YAAA;AAAA,UAE3B,kBAAA,kBAAoC,MAAA;;;;;;EAMjD,KAAA;IACI,KAAA;IACA,SAAA,GAAY,eAAA,UAAyB,YAAA,CAAa,eAAA;EAAA;EAEtD,QAAA;EACA,OAAA,GAAU,WAAA,MAAiB,QAAA;EAC3B,SAAA,EAAW,SAAA;EACX,SAAA,EAAW,SAAA;EACX,aAAA,GAAgB,aAAA;AAAA;AAAA,cAGP,YAAA,kBACQ,MAAA,kCACH,QAAA,GAAW,QAAA,UACnB,gB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