@pluv/platform-cloudflare 0.36.0 → 0.37.0

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-cloudflare@0.36.0 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
2
+ > @pluv/platform-cloudflare@0.37.0 build /home/runner/work/pluv/pluv/packages/platform-cloudflare
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
- ESM dist/index.mjs 12.12 KB
12
- ESM ⚡️ Build success in 54ms
13
- CJS dist/index.js 13.22 KB
14
- CJS ⚡️ Build success in 55ms
11
+ ESM dist/index.mjs 12.36 KB
12
+ ESM ⚡️ Build success in 85ms
13
+ CJS dist/index.js 13.49 KB
14
+ CJS ⚡️ Build success in 85ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 847ms
17
- DTS dist/index.d.mts 5.33 KB
18
- DTS dist/index.d.ts 5.33 KB
16
+ DTS ⚡️ Build success in 1129ms
17
+ DTS dist/index.d.mts 6.61 KB
18
+ DTS dist/index.d.ts 6.61 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,66 @@
1
1
  # @pluv/platform-cloudflare
2
2
 
3
+ ## 0.37.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5165be0: **BREAKING**
8
+
9
+ Updated the `platformCloudflare` function to return an entire `createIO` input object. Now `createIO` must be called with `platformCloudflare`'s return value as an input.
10
+
11
+ ```ts
12
+ // Before
13
+
14
+ import { createIO } from "@pluv/io";
15
+ import { platformCloudflare } from "@pluv/platform-cloudflare";
16
+
17
+ export const io = createIO({
18
+ authorize: {
19
+ // ...
20
+ },
21
+ context: {
22
+ // ...
23
+ },
24
+ platform: platformCloudflare<Env, Meta>({
25
+ // ...
26
+ }),
27
+ // ...
28
+ });
29
+
30
+ // After
31
+
32
+ import { createIO } from "@pluv/io";
33
+ import { infer, platformCloudflare } from "@pluv/platform-cloudflare";
34
+
35
+ // Types must now be inferred like so, due to TypeScript limitations around partial inferences
36
+ // Note that this types variable is defined outside of the `createIO` function
37
+ const types = infer((i) => ({
38
+ env: i<Env>,
39
+ meta: i<Meta>,
40
+ }));
41
+ export const io = createIO(
42
+ platformCloudflare({
43
+ authorize: {
44
+ // ...
45
+ },
46
+ context: {
47
+ // ...
48
+ },
49
+ // Optional: Pass inferred types here
50
+ types,
51
+ // ...
52
+ }),
53
+ );
54
+ ```
55
+
56
+ ### Patch Changes
57
+
58
+ - 9b74abb: Improved type inference when calling `PluvIO.server` to not include options that are always undefined (i.e. are not allowed by the specified platform).
59
+ - Updated dependencies [9b74abb]
60
+ - @pluv/io@0.37.0
61
+ - @pluv/persistence-cloudflare-transactional-storage@0.37.0
62
+ - @pluv/types@0.37.0
63
+
3
64
  ## 0.36.0
4
65
 
5
66
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPlatformConfig, ConvertWebSocketConfig, PluvServer, InferInitContextType } from '@pluv/io';
1
+ import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPlatformConfig, ConvertWebSocketConfig, PluvServer, InferInitContextType, CreateIOParams, PluvIOAuthorize, PluvContext } from '@pluv/io';
2
2
  import { JsonObject, Json, MaybePromise, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, Maybe, Id } from '@pluv/types';
3
3
 
4
4
  type CloudflareWebSocketConfig = AbstractWebSocketConfig;
@@ -43,6 +43,7 @@ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta ex
43
43
  onUserConnected: true;
44
44
  onUserDisconnected: true;
45
45
  };
46
+ router: true;
46
47
  }> {
47
48
  readonly _config: {
48
49
  authorize: {
@@ -58,6 +59,7 @@ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta ex
58
59
  onUserConnected: true;
59
60
  onUserDisconnected: true;
60
61
  };
62
+ router: true;
61
63
  };
62
64
  readonly _name = "platformCloudflare";
63
65
  constructor(config: CloudflarePlatformConfig<TEnv, TMeta>);
@@ -99,6 +101,19 @@ interface CreatePluvHandlerResult<TEnv extends Record<string, any> = {}> {
99
101
  type InferCloudflarePluvHandlerEnv<TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>> = TPluvServer extends PluvServer<CloudflarePlatform<infer IEnv>, any, any, any> ? IEnv : {};
100
102
  declare const createPluvHandler: <TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer, Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>) => CreatePluvHandlerResult<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>;
101
103
 
102
- declare const platformCloudflare: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(config?: CloudflarePlatformConfig<TEnv, TMeta>) => CloudflarePlatform<TEnv, TMeta>;
104
+ declare const identity: <T extends unknown>(x: T) => T;
103
105
 
104
- export { type AuthorizeFunction, type AuthorizeFunctionContext, CloudflarePlatform, type CloudflarePlatformConfig, type CreatePluvHandlerConfig, type CreatePluvHandlerResult, type PluvHandlerFetch, createPluvHandler, platformCloudflare };
106
+ type InferCallback<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> = (i: typeof identity) => {
107
+ env?: (io: TEnv) => TEnv;
108
+ meta?: (io: TMeta) => TMeta;
109
+ };
110
+ declare const infer: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(callback: InferCallback<TEnv, TMeta>) => InferCallback<TEnv, TMeta>;
111
+
112
+ type PlatformCloudflareCreateIOParams<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null> = Id<CloudflarePlatformConfig<TEnv, TMeta> & Omit<CreateIOParams<CloudflarePlatform<TEnv, TMeta>, TContext, TUser>, "authorize" | "context" | "platform"> & {
113
+ authorize?: PluvIOAuthorize<CloudflarePlatform<TEnv, TMeta>, TUser, InferInitContextType<CloudflarePlatform<TEnv, TMeta>>>;
114
+ context?: PluvContext<CloudflarePlatform<TEnv, TMeta>, TContext>;
115
+ types?: InferCallback<TEnv, TMeta>;
116
+ }>;
117
+ declare const platformCloudflare: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null>(config?: PlatformCloudflareCreateIOParams<TEnv, TMeta, TContext, TUser>) => CreateIOParams<CloudflarePlatform<TEnv, TMeta>, TContext, TUser>;
118
+
119
+ export { type AuthorizeFunction, type AuthorizeFunctionContext, CloudflarePlatform, type CloudflarePlatformConfig, type CreatePluvHandlerConfig, type CreatePluvHandlerResult, type InferCallback, type PlatformCloudflareCreateIOParams, type PluvHandlerFetch, createPluvHandler, infer, platformCloudflare };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPlatformConfig, ConvertWebSocketConfig, PluvServer, InferInitContextType } from '@pluv/io';
1
+ import { AbstractWebSocket, WebSocketSerializedState, AbstractWebSocketConfig, AbstractEventMap, AbstractListener, AbstractPlatform, WebSocketRegistrationMode, AbstractPlatformConfig, ConvertWebSocketConfig, PluvServer, InferInitContextType, CreateIOParams, PluvIOAuthorize, PluvContext } from '@pluv/io';
2
2
  import { JsonObject, Json, MaybePromise, InferIOAuthorizeUser, InferIOAuthorize, BaseUser, Maybe, Id } from '@pluv/types';
3
3
 
4
4
  type CloudflareWebSocketConfig = AbstractWebSocketConfig;
@@ -43,6 +43,7 @@ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta ex
43
43
  onUserConnected: true;
44
44
  onUserDisconnected: true;
45
45
  };
46
+ router: true;
46
47
  }> {
47
48
  readonly _config: {
48
49
  authorize: {
@@ -58,6 +59,7 @@ declare class CloudflarePlatform<TEnv extends Record<string, any> = {}, TMeta ex
58
59
  onUserConnected: true;
59
60
  onUserDisconnected: true;
60
61
  };
62
+ router: true;
61
63
  };
62
64
  readonly _name = "platformCloudflare";
63
65
  constructor(config: CloudflarePlatformConfig<TEnv, TMeta>);
@@ -99,6 +101,19 @@ interface CreatePluvHandlerResult<TEnv extends Record<string, any> = {}> {
99
101
  type InferCloudflarePluvHandlerEnv<TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>> = TPluvServer extends PluvServer<CloudflarePlatform<infer IEnv>, any, any, any> ? IEnv : {};
100
102
  declare const createPluvHandler: <TPluvServer extends PluvServer<CloudflarePlatform, any, any, any>>(config: CreatePluvHandlerConfig<TPluvServer, Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>) => CreatePluvHandlerResult<Id<InferCloudflarePluvHandlerEnv<TPluvServer>>>;
101
103
 
102
- declare const platformCloudflare: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(config?: CloudflarePlatformConfig<TEnv, TMeta>) => CloudflarePlatform<TEnv, TMeta>;
104
+ declare const identity: <T extends unknown>(x: T) => T;
103
105
 
104
- export { type AuthorizeFunction, type AuthorizeFunctionContext, CloudflarePlatform, type CloudflarePlatformConfig, type CreatePluvHandlerConfig, type CreatePluvHandlerResult, type PluvHandlerFetch, createPluvHandler, platformCloudflare };
106
+ type InferCallback<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> = (i: typeof identity) => {
107
+ env?: (io: TEnv) => TEnv;
108
+ meta?: (io: TMeta) => TMeta;
109
+ };
110
+ declare const infer: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(callback: InferCallback<TEnv, TMeta>) => InferCallback<TEnv, TMeta>;
111
+
112
+ type PlatformCloudflareCreateIOParams<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null> = Id<CloudflarePlatformConfig<TEnv, TMeta> & Omit<CreateIOParams<CloudflarePlatform<TEnv, TMeta>, TContext, TUser>, "authorize" | "context" | "platform"> & {
113
+ authorize?: PluvIOAuthorize<CloudflarePlatform<TEnv, TMeta>, TUser, InferInitContextType<CloudflarePlatform<TEnv, TMeta>>>;
114
+ context?: PluvContext<CloudflarePlatform<TEnv, TMeta>, TContext>;
115
+ types?: InferCallback<TEnv, TMeta>;
116
+ }>;
117
+ declare const platformCloudflare: <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}, TContext extends Record<string, any> = {}, TUser extends BaseUser | null = null>(config?: PlatformCloudflareCreateIOParams<TEnv, TMeta, TContext, TUser>) => CreateIOParams<CloudflarePlatform<TEnv, TMeta>, TContext, TUser>;
118
+
119
+ export { type AuthorizeFunction, type AuthorizeFunctionContext, CloudflarePlatform, type CloudflarePlatformConfig, type CreatePluvHandlerConfig, type CreatePluvHandlerResult, type InferCallback, type PlatformCloudflareCreateIOParams, type PluvHandlerFetch, createPluvHandler, infer, platformCloudflare };
package/dist/index.js CHANGED
@@ -58,6 +58,7 @@ var __async = (__this, __arguments, generator) => {
58
58
  var index_exports = {};
59
59
  __export(index_exports, {
60
60
  createPluvHandler: () => createPluvHandler,
61
+ infer: () => infer,
61
62
  platformCloudflare: () => platformCloudflare
62
63
  });
63
64
  module.exports = __toCommonJS(index_exports);
@@ -183,6 +184,9 @@ var createPluvHandler = (config) => {
183
184
  return { fetch: handlerFetch, DurableObject, handler };
184
185
  };
185
186
 
187
+ // src/infer.ts
188
+ var infer = (callback) => callback;
189
+
186
190
  // src/CloudflarePlatform.ts
187
191
  var import_io2 = require("@pluv/io");
188
192
  var import_persistence_cloudflare_transactional_storage = require("@pluv/persistence-cloudflare-transactional-storage");
@@ -258,7 +262,7 @@ var DEFAULT_REGISTRATION_MODE = "detached";
258
262
  var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPlatform {
259
263
  constructor(config) {
260
264
  var _a;
261
- super(__spreadValues(__spreadValues({}, config), config.context && config.mode === "detached" ? { persistence: new import_persistence_cloudflare_transactional_storage.PersistenceCloudflareTransactionalStorage(config.context) } : {}));
265
+ super(__spreadValues(__spreadValues({}, config), config.roomContext && config.mode === "detached" ? { persistence: new import_persistence_cloudflare_transactional_storage.PersistenceCloudflareTransactionalStorage(config.roomContext) } : {}));
262
266
  this._name = "platformCloudflare";
263
267
  this._config = {
264
268
  authorize: {
@@ -273,7 +277,8 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
273
277
  onStorageUpdated: true,
274
278
  onUserConnected: true,
275
279
  onUserDisconnected: true
276
- }
280
+ },
281
+ router: true
277
282
  };
278
283
  const detachedState = this._getDetachedState();
279
284
  if (!detachedState) return;
@@ -322,15 +327,15 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
322
327
  }
323
328
  initialize(config) {
324
329
  var _a;
325
- const context = (_a = config.context) != null ? _a : __spreadValues({}, this._roomContext);
326
- if (!context.env || !context.state) {
327
- throw new Error("Could not derive platform context");
330
+ const roomContext = (_a = config.roomContext) != null ? _a : __spreadValues({}, this._roomContext);
331
+ if (!roomContext.env || !roomContext.state) {
332
+ throw new Error("Could not derive platform roomContext");
328
333
  }
329
334
  return new _CloudflarePlatform({
330
- context: {
331
- env: context.env,
332
- meta: context.meta,
333
- state: context.state
335
+ roomContext: {
336
+ env: roomContext.env,
337
+ meta: roomContext.meta,
338
+ state: roomContext.state
334
339
  },
335
340
  mode: this._config.registrationMode,
336
341
  persistence: this.persistence,
@@ -359,10 +364,18 @@ var CloudflarePlatform = class _CloudflarePlatform extends import_io2.AbstractPl
359
364
 
360
365
  // src/platformCloudflare.ts
361
366
  var platformCloudflare = (config = {}) => {
362
- return new CloudflarePlatform(config);
367
+ const { authorize, context, crdt, debug } = config;
368
+ return {
369
+ authorize,
370
+ context,
371
+ crdt,
372
+ debug,
373
+ platform: new CloudflarePlatform(config)
374
+ };
363
375
  };
364
376
  // Annotate the CommonJS export names for ESM import in node:
365
377
  0 && (module.exports = {
366
378
  createPluvHandler,
379
+ infer,
367
380
  platformCloudflare
368
381
  });
package/dist/index.mjs CHANGED
@@ -159,6 +159,9 @@ var createPluvHandler = (config) => {
159
159
  return { fetch: handlerFetch, DurableObject, handler };
160
160
  };
161
161
 
162
+ // src/infer.ts
163
+ var infer = (callback) => callback;
164
+
162
165
  // src/CloudflarePlatform.ts
163
166
  import { AbstractPlatform } from "@pluv/io";
164
167
  import { PersistenceCloudflareTransactionalStorage } from "@pluv/persistence-cloudflare-transactional-storage";
@@ -234,7 +237,7 @@ var DEFAULT_REGISTRATION_MODE = "detached";
234
237
  var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
235
238
  constructor(config) {
236
239
  var _a;
237
- super(__spreadValues(__spreadValues({}, config), config.context && config.mode === "detached" ? { persistence: new PersistenceCloudflareTransactionalStorage(config.context) } : {}));
240
+ super(__spreadValues(__spreadValues({}, config), config.roomContext && config.mode === "detached" ? { persistence: new PersistenceCloudflareTransactionalStorage(config.roomContext) } : {}));
238
241
  this._name = "platformCloudflare";
239
242
  this._config = {
240
243
  authorize: {
@@ -249,7 +252,8 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
249
252
  onStorageUpdated: true,
250
253
  onUserConnected: true,
251
254
  onUserDisconnected: true
252
- }
255
+ },
256
+ router: true
253
257
  };
254
258
  const detachedState = this._getDetachedState();
255
259
  if (!detachedState) return;
@@ -298,15 +302,15 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
298
302
  }
299
303
  initialize(config) {
300
304
  var _a;
301
- const context = (_a = config.context) != null ? _a : __spreadValues({}, this._roomContext);
302
- if (!context.env || !context.state) {
303
- throw new Error("Could not derive platform context");
305
+ const roomContext = (_a = config.roomContext) != null ? _a : __spreadValues({}, this._roomContext);
306
+ if (!roomContext.env || !roomContext.state) {
307
+ throw new Error("Could not derive platform roomContext");
304
308
  }
305
309
  return new _CloudflarePlatform({
306
- context: {
307
- env: context.env,
308
- meta: context.meta,
309
- state: context.state
310
+ roomContext: {
311
+ env: roomContext.env,
312
+ meta: roomContext.meta,
313
+ state: roomContext.state
310
314
  },
311
315
  mode: this._config.registrationMode,
312
316
  persistence: this.persistence,
@@ -335,9 +339,17 @@ var CloudflarePlatform = class _CloudflarePlatform extends AbstractPlatform {
335
339
 
336
340
  // src/platformCloudflare.ts
337
341
  var platformCloudflare = (config = {}) => {
338
- return new CloudflarePlatform(config);
342
+ const { authorize, context, crdt, debug } = config;
343
+ return {
344
+ authorize,
345
+ context,
346
+ crdt,
347
+ debug,
348
+ platform: new CloudflarePlatform(config)
349
+ };
339
350
  };
340
351
  export {
341
352
  createPluvHandler,
353
+ infer,
342
354
  platformCloudflare
343
355
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/platform-cloudflare",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
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.36.0",
22
- "@pluv/persistence-cloudflare-transactional-storage": "^0.36.0",
23
- "@pluv/types": "^0.36.0"
21
+ "@pluv/io": "^0.37.0",
22
+ "@pluv/types": "^0.37.0",
23
+ "@pluv/persistence-cloudflare-transactional-storage": "^0.37.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@cloudflare/workers-types": "^4.20250224.0",
27
27
  "eslint": "^8.57.1",
28
28
  "tsup": "^8.4.0",
29
- "typescript": "^5.7.3",
30
- "@pluv/tsconfig": "^0.36.0",
31
- "eslint-config-pluv": "^0.36.0"
29
+ "typescript": "^5.8.2",
30
+ "@pluv/tsconfig": "^0.37.0",
31
+ "eslint-config-pluv": "^0.37.0"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -41,6 +41,7 @@ export class CloudflarePlatform<
41
41
  onUserConnected: true;
42
42
  onUserDisconnected: true;
43
43
  };
44
+ router: true;
44
45
  }
45
46
  > {
46
47
  public readonly _config;
@@ -49,8 +50,8 @@ export class CloudflarePlatform<
49
50
  constructor(config: CloudflarePlatformConfig<TEnv, TMeta>) {
50
51
  super({
51
52
  ...config,
52
- ...(config.context && config.mode === "detached"
53
- ? { persistence: new PersistenceCloudflareTransactionalStorage(config.context) }
53
+ ...(config.roomContext && config.mode === "detached"
54
+ ? { persistence: new PersistenceCloudflareTransactionalStorage(config.roomContext) }
54
55
  : {}),
55
56
  });
56
57
 
@@ -68,6 +69,7 @@ export class CloudflarePlatform<
68
69
  onUserConnected: true as const,
69
70
  onUserDisconnected: true as const,
70
71
  },
72
+ router: true as const,
71
73
  };
72
74
 
73
75
  const detachedState = this._getDetachedState();
@@ -131,17 +133,17 @@ export class CloudflarePlatform<
131
133
  }
132
134
 
133
135
  public initialize(config: AbstractPlatformConfig<CloudflarePlatformRoomContext<TEnv, TMeta>>): this {
134
- const context = config.context ?? { ...this._roomContext };
136
+ const roomContext = config.roomContext ?? { ...this._roomContext };
135
137
 
136
- if (!context.env || !context.state) {
137
- throw new Error("Could not derive platform context");
138
+ if (!roomContext.env || !roomContext.state) {
139
+ throw new Error("Could not derive platform roomContext");
138
140
  }
139
141
 
140
142
  return new CloudflarePlatform<TEnv, TMeta>({
141
- context: {
142
- env: context.env,
143
- meta: context.meta,
144
- state: context.state,
143
+ roomContext: {
144
+ env: roomContext.env,
145
+ meta: roomContext.meta,
146
+ state: roomContext.state,
145
147
  } as CloudflarePlatformRoomContext<TEnv, TMeta>,
146
148
  mode: this._config.registrationMode,
147
149
  persistence: this.persistence,
package/src/index.ts CHANGED
@@ -7,4 +7,7 @@ export type {
7
7
  CreatePluvHandlerResult,
8
8
  PluvHandlerFetch,
9
9
  } from "./createPluvHandler";
10
+ export { infer } from "./infer";
11
+ export type { InferCallback } from "./infer";
10
12
  export { platformCloudflare } from "./platformCloudflare";
13
+ export type { PlatformCloudflareCreateIOParams } from "./platformCloudflare";
package/src/infer.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { Json } from "@pluv/types";
2
+ import type { identity } from "./utils";
3
+
4
+ export type InferCallback<TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}> = (
5
+ i: typeof identity,
6
+ ) => {
7
+ env?: (io: TEnv) => TEnv;
8
+ meta?: (io: TMeta) => TMeta;
9
+ };
10
+
11
+ export const infer = <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(
12
+ callback: InferCallback<TEnv, TMeta>,
13
+ ) => callback;
@@ -1,9 +1,42 @@
1
- import type { Json } from "@pluv/types";
1
+ import type { CreateIOParams, InferInitContextType, PluvContext, PluvIOAuthorize } from "@pluv/io";
2
+ import type { BaseUser, Id, Json } from "@pluv/types";
2
3
  import type { CloudflarePlatformConfig } from "./CloudflarePlatform";
3
4
  import { CloudflarePlatform } from "./CloudflarePlatform";
5
+ import type { InferCallback } from "./infer";
4
6
 
5
- export const platformCloudflare = <TEnv extends Record<string, any> = {}, TMeta extends Record<string, Json> = {}>(
6
- config: CloudflarePlatformConfig<TEnv, TMeta> = {},
7
- ): CloudflarePlatform<TEnv, TMeta> => {
8
- return new CloudflarePlatform<TEnv, TMeta>(config);
7
+ export type PlatformCloudflareCreateIOParams<
8
+ TEnv extends Record<string, any> = {},
9
+ TMeta extends Record<string, Json> = {},
10
+ TContext extends Record<string, any> = {},
11
+ TUser extends BaseUser | null = null,
12
+ > = Id<
13
+ CloudflarePlatformConfig<TEnv, TMeta> &
14
+ Omit<CreateIOParams<CloudflarePlatform<TEnv, TMeta>, TContext, TUser>, "authorize" | "context" | "platform"> & {
15
+ authorize?: PluvIOAuthorize<
16
+ CloudflarePlatform<TEnv, TMeta>,
17
+ TUser,
18
+ InferInitContextType<CloudflarePlatform<TEnv, TMeta>>
19
+ >;
20
+ context?: PluvContext<CloudflarePlatform<TEnv, TMeta>, TContext>;
21
+ types?: InferCallback<TEnv, TMeta>;
22
+ }
23
+ >;
24
+
25
+ export const platformCloudflare = <
26
+ TEnv extends Record<string, any> = {},
27
+ TMeta extends Record<string, Json> = {},
28
+ TContext extends Record<string, any> = {},
29
+ TUser extends BaseUser | null = null,
30
+ >(
31
+ config: PlatformCloudflareCreateIOParams<TEnv, TMeta, TContext, TUser> = {},
32
+ ): CreateIOParams<CloudflarePlatform<TEnv, TMeta>, TContext, TUser> => {
33
+ const { authorize, context, crdt, debug } = config;
34
+
35
+ return {
36
+ authorize,
37
+ context,
38
+ crdt,
39
+ debug,
40
+ platform: new CloudflarePlatform<TEnv, TMeta>(config),
41
+ };
9
42
  };
@@ -0,0 +1 @@
1
+ export const identity = <T extends unknown>(x: T): T => x;
@@ -0,0 +1 @@
1
+ export { identity } from "./identity";