@pluv/platform-cloudflare 0.32.3 → 0.32.4
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 +8 -8
- package/CHANGELOG.md +56 -0
- package/dist/index.d.mts +13 -14
- package/dist/index.d.ts +13 -14
- package/dist/index.js +6 -2
- package/dist/index.mjs +6 -2
- package/package.json +7 -7
- package/src/CloudflarePlatform.ts +24 -9
- package/src/platformCloudflare.ts +8 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/platform-cloudflare@0.32.
|
|
2
|
+
> @pluv/platform-cloudflare@0.32.4 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m11.
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m12.
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m11.70 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 81ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m12.80 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 83ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m4.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 918ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m4.71 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.71 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @pluv/platform-cloudflare
|
|
2
2
|
|
|
3
|
+
## 0.32.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fd054db: Add support for adding metadata to context when creating a room.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createIO } from "@pluv/io";
|
|
11
|
+
|
|
12
|
+
// If using Cloudflare
|
|
13
|
+
import { platformCloudflare } from "@pluv/platform-cloudflare";
|
|
14
|
+
|
|
15
|
+
const io = createIO({
|
|
16
|
+
// ...
|
|
17
|
+
platform: platformCloudflare<CloudflareEnv, { myCustomData: string }>(),
|
|
18
|
+
context: ({
|
|
19
|
+
env,
|
|
20
|
+
state,
|
|
21
|
+
// This is now available on the context function
|
|
22
|
+
meta,
|
|
23
|
+
}) => ({ env, state, meta }),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const ioServer = io.server();
|
|
27
|
+
|
|
28
|
+
ioServer.createRoom("my-room", {
|
|
29
|
+
// ...
|
|
30
|
+
// This will now be a required property when creating a room
|
|
31
|
+
meta: { myCustomData: "hello world" },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// If using Node.js
|
|
35
|
+
import { platformNode } from "@pluv/platform-node";
|
|
36
|
+
|
|
37
|
+
const io = createIO({
|
|
38
|
+
// ...
|
|
39
|
+
platform: platformNode<{ myCustomData: string }>(),
|
|
40
|
+
context: ({
|
|
41
|
+
// This is now available on the context function
|
|
42
|
+
meta,
|
|
43
|
+
}) => ({ env, state, meta }),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const ioServer = io.server();
|
|
47
|
+
|
|
48
|
+
ioServer.createRoom("my-room", {
|
|
49
|
+
// ...
|
|
50
|
+
// This will now be a required property when creating a room
|
|
51
|
+
meta: { myCustomData: "hello world" },
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- @pluv/io@0.32.4
|
|
56
|
+
- @pluv/persistence-cloudflare-transactional-storage@0.32.4
|
|
57
|
+
- @pluv/types@0.32.4
|
|
58
|
+
|
|
3
59
|
## 0.32.3
|
|
4
60
|
|
|
5
61
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractWebSocket, WebSocketSerializedState, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPlatformConfig, WebSocketRegistrationMode, AbstractPlatform, ConvertWebSocketConfig, PluvServer, InferInitContextType } from '@pluv/io';
|
|
2
|
-
import { JsonObject, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
|
|
2
|
+
import { JsonObject, JsonPrimitive, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
|
|
3
3
|
|
|
4
4
|
type CloudflareWebSocketConfig = AbstractWebSocketConfig;
|
|
5
5
|
declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
|
|
@@ -15,31 +15,30 @@ declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
|
|
|
15
15
|
terminate(): void;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
type
|
|
18
|
+
type CloudflarePlatformRoomContext<TEnv extends Record<string, any>, TMeta extends Record<string, JsonPrimitive>> = {
|
|
19
19
|
env: TEnv;
|
|
20
20
|
state: DurableObjectState;
|
|
21
|
-
}
|
|
21
|
+
} & (keyof TMeta extends never ? {
|
|
22
|
+
meta?: undefined;
|
|
23
|
+
} : {
|
|
24
|
+
meta: TMeta;
|
|
25
|
+
});
|
|
26
|
+
type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}, TMeta extends Record<string, JsonPrimitive> = {}> = AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>> & {
|
|
22
27
|
mode?: WebSocketRegistrationMode;
|
|
23
28
|
};
|
|
24
|
-
declare class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends AbstractPlatform<CloudflareWebSocket, {
|
|
29
|
+
declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta extends Record<string, JsonPrimitive> = {}> extends AbstractPlatform<CloudflareWebSocket, {
|
|
25
30
|
env: TEnv;
|
|
26
31
|
request: Request;
|
|
27
|
-
}, {
|
|
28
|
-
env: TEnv;
|
|
29
|
-
state: DurableObjectState;
|
|
30
|
-
}> {
|
|
32
|
+
}, CloudflarePlatformRoomContext<TEnv, TMeta>> {
|
|
31
33
|
readonly _registrationMode: WebSocketRegistrationMode;
|
|
32
|
-
constructor(config
|
|
34
|
+
constructor(config: CloudflarePlatformConfig<TEnv, TMeta>);
|
|
33
35
|
acceptWebSocket(webSocket: CloudflareWebSocket): Promise<void>;
|
|
34
36
|
convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket;
|
|
35
37
|
getLastPing(webSocket: CloudflareWebSocket): number | null;
|
|
36
38
|
getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
|
|
37
39
|
getSessionId(webSocket: WebSocket): string | null;
|
|
38
40
|
getWebSockets(): readonly WebSocket[];
|
|
39
|
-
initialize(config: AbstractPlatformConfig<
|
|
40
|
-
env: TEnv;
|
|
41
|
-
state: DurableObjectState;
|
|
42
|
-
}>): this;
|
|
41
|
+
initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this;
|
|
43
42
|
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
44
43
|
randomUUID(): string;
|
|
45
44
|
setSerializedState(webSocket: CloudflareWebSocket, state: WebSocketSerializedState): void;
|
|
@@ -71,6 +70,6 @@ interface CreatePluvHandlerResult<TEnv extends Record<string, any> = {}> {
|
|
|
71
70
|
type InferCloudflarePluvHandlerEnv<TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>> = TPluvServer extends PluvServer<CloudflarePlatform<infer IEnv>, any, any, any> ? IEnv : {};
|
|
72
71
|
declare const createPluvHandler: <TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer, Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>) => CreatePluvHandlerResult<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>;
|
|
73
72
|
|
|
74
|
-
declare const platformCloudflare: <TEnv extends Record<string, any> = {}>(config?: CloudflarePlatformConfig<TEnv>) => CloudflarePlatform<TEnv>;
|
|
73
|
+
declare const platformCloudflare: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, JsonPrimitive> = {}>(config?: CloudflarePlatformConfig<TEnv, TMeta>) => CloudflarePlatform<TEnv, TMeta>;
|
|
75
74
|
|
|
76
75
|
export { type AuthorizeFunction, type AuthorizeFunctionContext, CloudflarePlatform, type CloudflarePlatformConfig, type CreatePluvHandlerConfig, type CreatePluvHandlerResult, type PluvHandlerFetch, createPluvHandler, platformCloudflare };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractWebSocket, WebSocketSerializedState, AbstractEventMap, AbstractListener, AbstractWebSocketConfig, AbstractPlatformConfig, WebSocketRegistrationMode, AbstractPlatform, ConvertWebSocketConfig, PluvServer, InferInitContextType } from '@pluv/io';
|
|
2
|
-
import { JsonObject, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
|
|
2
|
+
import { JsonObject, JsonPrimitive, MaybePromise, Maybe, InferIOAuthorizeUser, InferIOAuthorize, InferIOAuthorizeRequired, Id } from '@pluv/types';
|
|
3
3
|
|
|
4
4
|
type CloudflareWebSocketConfig = AbstractWebSocketConfig;
|
|
5
5
|
declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
|
|
@@ -15,31 +15,30 @@ declare class CloudflareWebSocket extends AbstractWebSocket<WebSocket> {
|
|
|
15
15
|
terminate(): void;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
type
|
|
18
|
+
type CloudflarePlatformRoomContext<TEnv extends Record<string, any>, TMeta extends Record<string, JsonPrimitive>> = {
|
|
19
19
|
env: TEnv;
|
|
20
20
|
state: DurableObjectState;
|
|
21
|
-
}
|
|
21
|
+
} & (keyof TMeta extends never ? {
|
|
22
|
+
meta?: undefined;
|
|
23
|
+
} : {
|
|
24
|
+
meta: TMeta;
|
|
25
|
+
});
|
|
26
|
+
type CloudflarePlatformConfig<TEnv extends Record<string, any> = {}, TMeta extends Record<string, JsonPrimitive> = {}> = AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>> & {
|
|
22
27
|
mode?: WebSocketRegistrationMode;
|
|
23
28
|
};
|
|
24
|
-
declare class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends AbstractPlatform<CloudflareWebSocket, {
|
|
29
|
+
declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta extends Record<string, JsonPrimitive> = {}> extends AbstractPlatform<CloudflareWebSocket, {
|
|
25
30
|
env: TEnv;
|
|
26
31
|
request: Request;
|
|
27
|
-
}, {
|
|
28
|
-
env: TEnv;
|
|
29
|
-
state: DurableObjectState;
|
|
30
|
-
}> {
|
|
32
|
+
}, CloudflarePlatformRoomContext<TEnv, TMeta>> {
|
|
31
33
|
readonly _registrationMode: WebSocketRegistrationMode;
|
|
32
|
-
constructor(config
|
|
34
|
+
constructor(config: CloudflarePlatformConfig<TEnv, TMeta>);
|
|
33
35
|
acceptWebSocket(webSocket: CloudflareWebSocket): Promise<void>;
|
|
34
36
|
convertWebSocket(webSocket: WebSocket, config: ConvertWebSocketConfig): CloudflareWebSocket;
|
|
35
37
|
getLastPing(webSocket: CloudflareWebSocket): number | null;
|
|
36
38
|
getSerializedState(webSocket: WebSocket): WebSocketSerializedState | null;
|
|
37
39
|
getSessionId(webSocket: WebSocket): string | null;
|
|
38
40
|
getWebSockets(): readonly WebSocket[];
|
|
39
|
-
initialize(config: AbstractPlatformConfig<
|
|
40
|
-
env: TEnv;
|
|
41
|
-
state: DurableObjectState;
|
|
42
|
-
}>): this;
|
|
41
|
+
initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this;
|
|
43
42
|
parseData(data: string | ArrayBuffer): Record<string, any>;
|
|
44
43
|
randomUUID(): string;
|
|
45
44
|
setSerializedState(webSocket: CloudflareWebSocket, state: WebSocketSerializedState): void;
|
|
@@ -71,6 +70,6 @@ interface CreatePluvHandlerResult<TEnv extends Record<string, any> = {}> {
|
|
|
71
70
|
type InferCloudflarePluvHandlerEnv<TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>> = TPluvServer extends PluvServer<CloudflarePlatform<infer IEnv>, any, any, any> ? IEnv : {};
|
|
72
71
|
declare const createPluvHandler: <TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer, Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>) => CreatePluvHandlerResult<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>;
|
|
73
72
|
|
|
74
|
-
declare const platformCloudflare: <TEnv extends Record<string, any> = {}>(config?: CloudflarePlatformConfig<TEnv>) => CloudflarePlatform<TEnv>;
|
|
73
|
+
declare const platformCloudflare: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, JsonPrimitive> = {}>(config?: CloudflarePlatformConfig<TEnv, TMeta>) => CloudflarePlatform<TEnv, TMeta>;
|
|
75
74
|
|
|
76
75
|
export { type AuthorizeFunction, type AuthorizeFunctionContext, CloudflarePlatform, type CloudflarePlatformConfig, type CreatePluvHandlerConfig, type CreatePluvHandlerResult, type PluvHandlerFetch, createPluvHandler, platformCloudflare };
|
package/dist/index.js
CHANGED
|
@@ -258,7 +258,7 @@ var DEFAULT_REGISTRATION_MODE = "detached";
|
|
|
258
258
|
|
|
259
259
|
// src/CloudflarePlatform.ts
|
|
260
260
|
var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPlatform {
|
|
261
|
-
constructor(config
|
|
261
|
+
constructor(config) {
|
|
262
262
|
var _a;
|
|
263
263
|
super(__spreadValues(__spreadValues({}, config), config.context && config.mode === "detached" ? { persistence: new import_persistence_cloudflare_transactional_storage.PersistenceCloudflareTransactionalStorage(config.context) } : {}));
|
|
264
264
|
this._registrationMode = (_a = config.mode) != null ? _a : DEFAULT_REGISTRATION_MODE;
|
|
@@ -314,7 +314,11 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
|
|
|
314
314
|
throw new Error("Could not derive platform context");
|
|
315
315
|
}
|
|
316
316
|
return new _CloudflarePlatform({
|
|
317
|
-
context: {
|
|
317
|
+
context: {
|
|
318
|
+
env: context.env,
|
|
319
|
+
meta: context.meta,
|
|
320
|
+
state: context.state
|
|
321
|
+
},
|
|
318
322
|
mode: this._registrationMode,
|
|
319
323
|
persistence: this.persistence,
|
|
320
324
|
pubSub: this.pubSub
|
package/dist/index.mjs
CHANGED
|
@@ -234,7 +234,7 @@ var DEFAULT_REGISTRATION_MODE = "detached";
|
|
|
234
234
|
|
|
235
235
|
// src/CloudflarePlatform.ts
|
|
236
236
|
var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
|
|
237
|
-
constructor(config
|
|
237
|
+
constructor(config) {
|
|
238
238
|
var _a;
|
|
239
239
|
super(__spreadValues(__spreadValues({}, config), config.context && config.mode === "detached" ? { persistence: new PersistenceCloudflareTransactionalStorage(config.context) } : {}));
|
|
240
240
|
this._registrationMode = (_a = config.mode) != null ? _a : DEFAULT_REGISTRATION_MODE;
|
|
@@ -290,7 +290,11 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
|
|
|
290
290
|
throw new Error("Could not derive platform context");
|
|
291
291
|
}
|
|
292
292
|
return new _CloudflarePlatform({
|
|
293
|
-
context: {
|
|
293
|
+
context: {
|
|
294
|
+
env: context.env,
|
|
295
|
+
meta: context.meta,
|
|
296
|
+
state: context.state
|
|
297
|
+
},
|
|
294
298
|
mode: this._registrationMode,
|
|
295
299
|
persistence: this.persistence,
|
|
296
300
|
pubSub: this.pubSub
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/platform-cloudflare",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.4",
|
|
4
4
|
"description": "@pluv/io adapter for cloudflare workers",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"path-to-regexp": "^8.2.0",
|
|
21
|
-
"@pluv/io": "^0.32.
|
|
22
|
-
"@pluv/persistence-cloudflare-transactional-storage": "^0.32.
|
|
23
|
-
"@pluv/types": "^0.32.
|
|
21
|
+
"@pluv/io": "^0.32.4",
|
|
22
|
+
"@pluv/persistence-cloudflare-transactional-storage": "^0.32.4",
|
|
23
|
+
"@pluv/types": "^0.32.4"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@cloudflare/workers-types": "^4.
|
|
26
|
+
"@cloudflare/workers-types": "^4.20241018.0",
|
|
27
27
|
"eslint": "^8.57.0",
|
|
28
28
|
"tsup": "^8.3.0",
|
|
29
29
|
"typescript": "^5.6.3",
|
|
30
|
-
"@pluv/tsconfig": "^0.32.
|
|
31
|
-
"eslint-config-pluv": "^0.32.
|
|
30
|
+
"@pluv/tsconfig": "^0.32.4",
|
|
31
|
+
"eslint-config-pluv": "^0.32.4"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AbstractPlatformConfig,
|
|
3
3
|
ConvertWebSocketConfig,
|
|
4
|
-
InferInitContextType,
|
|
5
4
|
WebSocketRegistrationMode,
|
|
6
5
|
WebSocketSerializedState,
|
|
7
6
|
} from "@pluv/io";
|
|
8
7
|
import { AbstractPlatform } from "@pluv/io";
|
|
9
8
|
import { PersistenceCloudflareTransactionalStorage } from "@pluv/persistence-cloudflare-transactional-storage";
|
|
9
|
+
import type { JsonPrimitive } from "@pluv/types";
|
|
10
10
|
import { CloudflareWebSocket } from "./CloudflareWebSocket";
|
|
11
11
|
import { DEFAULT_REGISTRATION_MODE } from "./constants";
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type CloudflarePlatformRoomContext<
|
|
14
|
+
TEnv extends Record<string, any>,
|
|
15
|
+
TMeta extends Record<string, JsonPrimitive>,
|
|
16
|
+
> = {
|
|
14
17
|
env: TEnv;
|
|
15
18
|
state: DurableObjectState;
|
|
16
|
-
}
|
|
19
|
+
} & (keyof TMeta extends never ? { meta?: undefined } : { meta: TMeta });
|
|
17
20
|
|
|
18
|
-
export
|
|
21
|
+
export type CloudflarePlatformConfig<
|
|
22
|
+
TEnv extends Record<string, any> = {},
|
|
23
|
+
TMeta extends Record<string, JsonPrimitive> = {},
|
|
24
|
+
> = AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>> & { mode?: WebSocketRegistrationMode };
|
|
25
|
+
|
|
26
|
+
export class CloudflarePlatform<
|
|
27
|
+
TEnv extends Record<string, any> = {},
|
|
28
|
+
TMeta extends Record<string, JsonPrimitive> = {},
|
|
29
|
+
> extends AbstractPlatform<
|
|
19
30
|
CloudflareWebSocket,
|
|
20
31
|
{ env: TEnv; request: Request },
|
|
21
|
-
|
|
32
|
+
CloudflarePlatformRoomContext<TEnv, TMeta>
|
|
22
33
|
> {
|
|
23
34
|
readonly _registrationMode: WebSocketRegistrationMode;
|
|
24
35
|
|
|
25
|
-
constructor(config: CloudflarePlatformConfig<TEnv>
|
|
36
|
+
constructor(config: CloudflarePlatformConfig<TEnv, TMeta>) {
|
|
26
37
|
super({
|
|
27
38
|
...config,
|
|
28
39
|
...(config.context && config.mode === "detached"
|
|
@@ -92,15 +103,19 @@ export class CloudflarePlatform<TEnv extends Record<string, any> = {}> extends A
|
|
|
92
103
|
return detachedState.getWebSockets() ?? [];
|
|
93
104
|
}
|
|
94
105
|
|
|
95
|
-
public initialize(config: AbstractPlatformConfig<
|
|
106
|
+
public initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this {
|
|
96
107
|
const context = config.context ?? { ...this._roomContext };
|
|
97
108
|
|
|
98
109
|
if (!context.env || !context.state) {
|
|
99
110
|
throw new Error("Could not derive platform context");
|
|
100
111
|
}
|
|
101
112
|
|
|
102
|
-
return new CloudflarePlatform<TEnv>({
|
|
103
|
-
context: {
|
|
113
|
+
return new CloudflarePlatform<TEnv, TMeta>({
|
|
114
|
+
context: {
|
|
115
|
+
env: context.env,
|
|
116
|
+
meta: context.meta,
|
|
117
|
+
state: context.state,
|
|
118
|
+
} as CloudflarePlatformRoomContext<TEnv, TMeta>,
|
|
104
119
|
mode: this._registrationMode,
|
|
105
120
|
persistence: this.persistence,
|
|
106
121
|
pubSub: this.pubSub,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import type { JsonPrimitive } from "@pluv/types";
|
|
1
2
|
import type { CloudflarePlatformConfig } from "./CloudflarePlatform";
|
|
2
3
|
import { CloudflarePlatform } from "./CloudflarePlatform";
|
|
3
4
|
|
|
4
|
-
export const platformCloudflare = <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const platformCloudflare = <
|
|
6
|
+
TEnv extends Record<string, any> = {},
|
|
7
|
+
TMeta extends Record<string, JsonPrimitive> = {},
|
|
8
|
+
>(
|
|
9
|
+
config: CloudflarePlatformConfig<TEnv, TMeta> = {},
|
|
10
|
+
): CloudflarePlatform<TEnv, TMeta> => {
|
|
11
|
+
return new CloudflarePlatform<TEnv, TMeta>(config);
|
|
8
12
|
};
|