devframe 0.1.16 → 0.1.18

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.
Files changed (54) hide show
  1. package/dist/adapters/build.d.mts +1 -1
  2. package/dist/adapters/build.mjs +13 -6
  3. package/dist/adapters/cli.d.mts +1 -1
  4. package/dist/adapters/cli.mjs +6 -6
  5. package/dist/adapters/embedded.d.mts +1 -1
  6. package/dist/adapters/kit.d.mts +1 -1
  7. package/dist/adapters/mcp.d.mts +1 -1
  8. package/dist/adapters/mcp.mjs +2 -2
  9. package/dist/adapters/vite.d.mts +1 -1
  10. package/dist/adapters/vite.mjs +1 -1
  11. package/dist/client/index.d.mts +5 -4
  12. package/dist/client/index.mjs +1 -1
  13. package/dist/{client-4WrEozlH.mjs → client-CsR1_h3o.mjs} +14 -6
  14. package/dist/constants.d.mts +1 -1
  15. package/dist/{context-BrePWeyd.mjs → context-xQo1FcxX.mjs} +107 -56
  16. package/dist/{devtool-OJ3QW0ns.d.mts → devtool-CHT-4_OU.d.mts} +156 -48
  17. package/dist/helpers/nuxt/runtime/plugin.client.mjs +1 -1
  18. package/dist/index-Cei8vVcd.d.mts +140 -0
  19. package/dist/index.d.mts +4 -4
  20. package/dist/index.mjs +1 -1
  21. package/dist/node/index.d.mts +38 -10
  22. package/dist/node/index.mjs +4 -4
  23. package/dist/recipes/open-helpers.d.mts +5 -1
  24. package/dist/recipes/open-helpers.mjs +2 -2
  25. package/dist/rpc/index.d.mts +3 -2
  26. package/dist/rpc/index.mjs +4 -3
  27. package/dist/rpc/transports/ws-client.d.mts +1 -1
  28. package/dist/rpc/transports/ws-client.mjs +19 -4
  29. package/dist/rpc/transports/ws-server.d.mts +1 -1
  30. package/dist/rpc/transports/ws-server.mjs +19 -4
  31. package/dist/{rpc-9FNa3Inb.mjs → rpc-hbRk8qtt.mjs} +15 -33
  32. package/dist/serialization-CWcWE7x7.mjs +112 -0
  33. package/dist/{src-BoIqXRc9.mjs → src-DIKqQIjp.mjs} +1 -1
  34. package/dist/{static-dump-CQUC1aIW.mjs → static-dump-DwFfj4U_.mjs} +21 -6
  35. package/dist/types/index.d.mts +4 -4
  36. package/dist/{index-DvKDO5H8.d.mts → types-BkyzI9r4.d.mts} +35 -95
  37. package/dist/utils/events.d.mts +1 -1
  38. package/dist/utils/shared-state.d.mts +1 -1
  39. package/dist/utils/shared-state.mjs +1 -1
  40. package/dist/utils/state.d.mts +1 -1
  41. package/dist/utils/state.mjs +1 -1
  42. package/dist/utils/when.d.mts +1 -1
  43. package/dist/ws-client-CDGmViwt.d.mts +26 -0
  44. package/dist/{ws-server--IuUAaGi.d.mts → ws-server-Cu8tmZcF.d.mts} +12 -0
  45. package/package.json +1 -1
  46. package/dist/ws-client-CklfxUHE.d.mts +0 -17
  47. /package/dist/{_shared-CU6dE-VX.mjs → _shared-Bxa2_kq7.mjs} +0 -0
  48. /package/dist/{define-Bb4zh-Dc.mjs → define-CW9gLnyG.mjs} +0 -0
  49. /package/dist/{immer-HjMAm3b6.mjs → immer-DEqg5kOd.mjs} +0 -0
  50. /package/dist/{main-DpINGndA.mjs → main-BJD9t8dk.mjs} +0 -0
  51. /package/dist/{open-BtOOEldu.mjs → open-BMO2_-wC.mjs} +0 -0
  52. /package/dist/{server-DrBxa6ZV.mjs → server-DkJ2-s0Y.mjs} +0 -0
  53. /package/dist/{transports-BPUzHhI2.mjs → transports-4bqw6Fqg.mjs} +0 -0
  54. /package/dist/{when-CGLewRtm.d.mts → when-aBBXAEh5.d.mts} +0 -0
@@ -1,29 +1,6 @@
1
1
  import { GenericSchema, InferInput } from "valibot";
2
2
  import { BirpcFn, BirpcReturn as BirpcReturn$1 } from "birpc";
3
3
 
4
- //#region src/rpc/cache.d.ts
5
- interface RpcCacheOptions {
6
- functions: string[];
7
- keySerializer?: (args: unknown[]) => string;
8
- }
9
- /**
10
- * @experimental API is expected to change.
11
- */
12
- declare class RpcCacheManager {
13
- private cacheMap;
14
- private options;
15
- private keySerializer;
16
- constructor(options: RpcCacheOptions);
17
- updateOptions(options: Partial<RpcCacheOptions>): void;
18
- cached<T>(m: string, a: unknown[]): T | undefined;
19
- apply(req: {
20
- m: string;
21
- a: unknown[];
22
- }, res: unknown): void;
23
- validate(m: string): boolean;
24
- clear(fn?: string): void;
25
- }
26
- //#endregion
27
4
  //#region src/rpc/utils.d.ts
28
5
  /** Infers TypeScript tuple type from Valibot schema array */
29
6
  type InferArgsType<S extends RpcArgsSchema | undefined> = S extends readonly [] ? [] : S extends readonly [infer H, ...infer T] ? H extends GenericSchema ? T extends readonly GenericSchema[] ? [InferInput<H>, ...InferArgsType<T>] : never : never : never;
@@ -158,6 +135,20 @@ interface RpcFunctionDefinitionBase {
158
135
  name: string;
159
136
  /** Function type (static, action, event, or query) */
160
137
  type?: RpcFunctionType;
138
+ /**
139
+ * Declares whether this function's args/return are JSON-serializable
140
+ * — i.e. no `Map`, `Set`, `Date`, `BigInt`, class instances, circular
141
+ * references, `undefined` leaves, `Symbol`, or `Function` values.
142
+ *
143
+ * - `true` — args and return are encoded with strict `JSON.stringify`
144
+ * on the wire and on disk. Misshapen values throw `DF0019` at the
145
+ * sender, surfacing the bug *during the offending call* rather than
146
+ * silently coercing to `{}` later. Required for `agent` exposure.
147
+ * - `false` (default) — payloads use `structured-clone-es`, which
148
+ * round-trips Maps/Sets/cycles. Functions in this mode cannot be
149
+ * exposed via the `agent` field — registration throws `DF0018`.
150
+ */
151
+ jsonSerializable?: boolean;
161
152
  }
162
153
  /**
163
154
  * Dump store containing pre-computed results.
@@ -199,6 +190,16 @@ type RpcFunctionDefinition<NAME extends string, TYPE extends RpcFunctionType = '
199
190
  cacheable?: boolean; /** Valibot schema array for validating function arguments */
200
191
  args?: AS; /** Valibot schema for validating function return value */
201
192
  returns?: RS;
193
+ /**
194
+ * Declares whether this function's args/return are JSON-serializable
195
+ * (no Map/Set/Date/BigInt/cycles/class instances/undefined/Symbol/Function).
196
+ *
197
+ * - `true` — wire and dump use strict `JSON.stringify`; misshapen
198
+ * values throw `DF0019` at the call site. Required for `agent`.
199
+ * - `false` (default) — `structured-clone-es` round-trips fancy
200
+ * types. Cannot be `agent`-exposed (registration throws `DF0018`).
201
+ */
202
+ jsonSerializable?: boolean;
202
203
  /**
203
204
  * Expose this function to agents (e.g. via the MCP adapter).
204
205
  * When omitted, the function is not agent-exposed (default-deny).
@@ -226,6 +227,16 @@ type RpcFunctionDefinition<NAME extends string, TYPE extends RpcFunctionType = '
226
227
  cacheable?: boolean; /** Valibot schema array for validating function arguments */
227
228
  args: AS; /** Valibot schema for validating function return value */
228
229
  returns: RS;
230
+ /**
231
+ * Declares whether this function's args/return are JSON-serializable
232
+ * (no Map/Set/Date/BigInt/cycles/class instances/undefined/Symbol/Function).
233
+ *
234
+ * - `true` — wire and dump use strict `JSON.stringify`; misshapen
235
+ * values throw `DF0019` at the call site. Required for `agent`.
236
+ * - `false` (default) — `structured-clone-es` round-trips fancy
237
+ * types. Cannot be `agent`-exposed (registration throws `DF0018`).
238
+ */
239
+ jsonSerializable?: boolean;
229
240
  /**
230
241
  * Expose this function to agents (e.g. via the MCP adapter).
231
242
  * When omitted, the function is not agent-exposed (default-deny).
@@ -259,75 +270,4 @@ type RpcDefinitionsFilter<T extends readonly RpcFunctionDefinitionAny[], Type ex
259
270
  type: Type;
260
271
  } ? T[K] : never };
261
272
  //#endregion
262
- //#region src/rpc/collector.d.ts
263
- declare class RpcFunctionsCollectorBase<LocalFunctions extends Record<string, any>, SetupContext> implements RpcFunctionsCollector<LocalFunctions, SetupContext> {
264
- readonly context: SetupContext;
265
- readonly definitions: Map<string, RpcFunctionDefinition<string, any, any, any, any, any, SetupContext>>;
266
- readonly functions: LocalFunctions;
267
- private readonly _onChanged;
268
- constructor(context: SetupContext);
269
- register(fn: RpcFunctionDefinition<string, any, any, any, any, any, SetupContext>, force?: boolean): void;
270
- update(fn: RpcFunctionDefinition<string, any, any, any, any, any, SetupContext>, force?: boolean): void;
271
- onChanged(fn: (id?: string) => void): () => void;
272
- getHandler<T extends keyof LocalFunctions>(name: T): Promise<LocalFunctions[T]>;
273
- getSchema<T extends keyof LocalFunctions>(name: T): {
274
- args: RpcArgsSchema | undefined;
275
- returns: RpcReturnSchema | undefined;
276
- };
277
- has(name: string): boolean;
278
- get(name: string): RpcFunctionDefinition<string, any, any, any, any, any, SetupContext> | undefined;
279
- list(): string[];
280
- }
281
- //#endregion
282
- //#region src/rpc/define.d.ts
283
- declare function defineRpcFunction<NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[], RETURN = void, const AS extends RpcArgsSchema | undefined = undefined, const RS extends RpcReturnSchema | undefined = undefined>(definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, AS, RS>): RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, AS, RS>;
284
- declare function createDefineWrapperWithContext<CONTEXT>(): <NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[], RETURN = void, const AS extends RpcArgsSchema | undefined = undefined, const RS extends RpcReturnSchema | undefined = undefined>(definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, AS, RS, CONTEXT>) => RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, AS, RS, CONTEXT>;
285
- //#endregion
286
- //#region src/rpc/dumps.d.ts
287
- /**
288
- * Collects pre-computed dumps by executing functions with their defined input combinations.
289
- * Static functions without dump config automatically get `{ inputs: [[]] }`.
290
- *
291
- * @example
292
- * ```ts
293
- * const store = await dumpFunctions([greet], context, { concurrency: 10 })
294
- * ```
295
- */
296
- declare function dumpFunctions<T extends readonly RpcFunctionDefinitionAny[]>(definitions: T, context?: any, options?: RpcDumpCollectionOptions): Promise<RpcDumpStore<RpcDefinitionsToFunctions<T>>>;
297
- /**
298
- * Creates a client that serves pre-computed results from a dump store.
299
- * Uses argument hashing to match calls to stored records.
300
- *
301
- * @example
302
- * ```ts
303
- * const client = createClientFromDump(store)
304
- * await client.greet('Alice')
305
- * ```
306
- */
307
- declare function createClientFromDump<T extends Record<string, any>>(store: RpcDumpStore<T>, options?: RpcDumpClientOptions): BirpcReturn$1<T>;
308
- /**
309
- * Filters function definitions to only those with dump definitions.
310
- * Note: Only checks the definition itself, not setup results.
311
- */
312
- declare function getDefinitionsWithDumps<T extends readonly RpcFunctionDefinitionAny[]>(definitions: T): RpcFunctionDefinitionAny[];
313
- //#endregion
314
- //#region src/rpc/handler.d.ts
315
- declare function getRpcResolvedSetupResult<NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[], RETURN = void, CONTEXT = undefined>(definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, any, any, CONTEXT>, context: CONTEXT): Promise<RpcFunctionSetupResult<ARGS, RETURN>>;
316
- declare function getRpcHandler<NAME extends string, TYPE extends RpcFunctionType, ARGS extends any[], RETURN = void, CONTEXT = undefined>(definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN, any, any, CONTEXT>, context: CONTEXT): Promise<(...args: ARGS) => RETURN>;
317
- //#endregion
318
- //#region src/rpc/validation.d.ts
319
- /**
320
- * Validates RPC function definitions.
321
- * Action and event functions cannot have dumps (side effects should not be cached).
322
- *
323
- * @throws {Error} If an action or event function has a dump configuration
324
- */
325
- declare function validateDefinitions(definitions: readonly RpcFunctionDefinitionAny[]): void;
326
- /**
327
- * Validates a single RPC function definition.
328
- *
329
- * @throws {Error} If an action or event function has a dump configuration
330
- */
331
- declare function validateDefinition(definition: RpcFunctionDefinitionAny): void;
332
- //#endregion
333
- export { RpcFunctionSetupResult as A, RpcDumpStore as C, RpcFunctionDefinitionAnyWithContext as D, RpcFunctionDefinitionAny as E, RpcCacheManager as F, RpcCacheOptions as I, RpcFunctionsCollector as M, RpcReturnSchema as N, RpcFunctionDefinitionBase as O, Thenable as P, RpcDumpRecord as S, RpcFunctionDefinition as T, RpcDump as _, createClientFromDump as a, RpcDumpDefinition as b, createDefineWrapperWithContext as c, BirpcFn as d, BirpcReturn$1 as f, RpcDefinitionsToFunctions as g, RpcDefinitionsFilter as h, getRpcResolvedSetupResult as i, RpcFunctionType as j, RpcFunctionDefinitionToFunction as k, defineRpcFunction as l, RpcArgsSchema as m, validateDefinitions as n, dumpFunctions as o, EntriesToObject as p, getRpcHandler as r, getDefinitionsWithDumps as s, validateDefinition as t, RpcFunctionsCollectorBase as u, RpcDumpClientOptions as v, RpcFunctionAgentOptions as w, RpcDumpGetter as x, RpcDumpCollectionOptions as y };
273
+ export { RpcReturnSchema as C, RpcFunctionsCollector as S, RpcFunctionDefinitionAnyWithContext as _, RpcDefinitionsFilter as a, RpcFunctionSetupResult as b, RpcDumpClientOptions as c, RpcDumpGetter as d, RpcDumpRecord as f, RpcFunctionDefinitionAny as g, RpcFunctionDefinition as h, RpcArgsSchema as i, RpcDumpCollectionOptions as l, RpcFunctionAgentOptions as m, BirpcReturn$1 as n, RpcDefinitionsToFunctions as o, RpcDumpStore as p, EntriesToObject as r, RpcDump as s, BirpcFn as t, RpcDumpDefinition as u, RpcFunctionDefinitionBase as v, Thenable as w, RpcFunctionType as x, RpcFunctionDefinitionToFunction as y };
@@ -1,4 +1,4 @@
1
- import { Vt as EventsMap, zt as EventEmitter } from "../devtool-OJ3QW0ns.mjs";
1
+ import { $t as EventsMap, Zt as EventEmitter } from "../devtool-CHT-4_OU.mjs";
2
2
 
3
3
  //#region src/utils/events.d.ts
4
4
  /**
@@ -1,2 +1,2 @@
1
- import { C as ImmutableSet, D as createSharedState, E as SharedStateOptions, S as ImmutableObject, T as SharedStateEvents, b as ImmutableArray, k as Patch, w as SharedState, x as ImmutableMap, y as Immutable } from "../devtool-OJ3QW0ns.mjs";
1
+ import { C as ImmutableSet, D as createSharedState, E as SharedStateOptions, S as ImmutableObject, T as SharedStateEvents, b as ImmutableArray, k as Patch, w as SharedState, x as ImmutableMap, y as Immutable } from "../devtool-CHT-4_OU.mjs";
2
2
  export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, Patch as SharedStatePatch, createSharedState };
@@ -1,5 +1,5 @@
1
1
  import { createEventEmitter } from "./events.mjs";
2
- import { i as produceWithPatches, n as enablePatches, r as produce, t as applyPatches } from "../immer-HjMAm3b6.mjs";
2
+ import { i as produceWithPatches, n as enablePatches, r as produce, t as applyPatches } from "../immer-DEqg5kOd.mjs";
3
3
  import { nanoid } from "./nanoid.mjs";
4
4
  //#region src/utils/shared-state.ts
5
5
  function createSharedState(options) {
@@ -1,4 +1,4 @@
1
- import { O as Objectish, k as Patch, zt as EventEmitter } from "../devtool-OJ3QW0ns.mjs";
1
+ import { O as Objectish, Zt as EventEmitter, k as Patch } from "../devtool-CHT-4_OU.mjs";
2
2
 
3
3
  //#region src/utils/state.d.ts
4
4
  type ImmutablePrimitive = undefined | null | boolean | string | number | Function;
@@ -1,5 +1,5 @@
1
1
  import { createEventEmitter } from "./events.mjs";
2
- import { i as produceWithPatches, r as produce, t as applyPatches } from "../immer-HjMAm3b6.mjs";
2
+ import { i as produceWithPatches, r as produce, t as applyPatches } from "../immer-DEqg5kOd.mjs";
3
3
  //#region src/utils/state.ts
4
4
  function createSharedState(options) {
5
5
  const { enablePatches = false } = options;
@@ -1,2 +1,2 @@
1
- import { i as resolveContextValue, n as WhenExpression, r as evaluateWhen, t as WhenContext } from "../when-CGLewRtm.mjs";
1
+ import { i as resolveContextValue, n as WhenExpression, r as evaluateWhen, t as WhenContext } from "../when-aBBXAEh5.mjs";
2
2
  export { WhenContext, WhenExpression, evaluateWhen, resolveContextValue };
@@ -0,0 +1,26 @@
1
+ import { g as RpcFunctionDefinitionAny } from "./types-BkyzI9r4.mjs";
2
+ import { ChannelOptions } from "birpc";
3
+
4
+ //#region src/rpc/transports/ws-client.d.ts
5
+ interface WsRpcChannelOptions {
6
+ url: string;
7
+ onConnected?: (e: Event) => void;
8
+ onError?: (e: Error) => void;
9
+ onDisconnected?: (e: CloseEvent) => void;
10
+ authToken?: string;
11
+ /**
12
+ * RPC function definitions (or just the `jsonSerializable` flag per
13
+ * method) used to dispatch the per-call wire serializer. Pass an
14
+ * empty / partial map on clients that don't have the full registry —
15
+ * encoding falls back to structured-clone (the safer superset) and
16
+ * decoding still routes correctly via the wire prefix.
17
+ */
18
+ definitions?: ReadonlyMap<string, Pick<RpcFunctionDefinitionAny, 'jsonSerializable'>>;
19
+ }
20
+ /**
21
+ * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
22
+ * Pass the result straight to `createRpcClient`'s `channel` option.
23
+ */
24
+ declare function createWsRpcChannel(options: WsRpcChannelOptions): ChannelOptions;
25
+ //#endregion
26
+ export { createWsRpcChannel as n, WsRpcChannelOptions as t };
@@ -1,3 +1,4 @@
1
+ import { g as RpcFunctionDefinitionAny } from "./types-BkyzI9r4.mjs";
1
2
  import { BirpcGroup, ChannelOptions } from "birpc";
2
3
  import { ServerOptions } from "node:https";
3
4
  import { WebSocket, WebSocketServer } from "ws";
@@ -20,9 +21,20 @@ interface WsRpcTransportOptions {
20
21
  host?: string;
21
22
  /** When set, a new https.Server is created and the WebSocketServer is attached to it. */
22
23
  https?: ServerOptions;
24
+ /**
25
+ * RPC function definitions, used by the per-call wire serializer to
26
+ * dispatch between strict-JSON and structured-clone encoding based
27
+ * on each function's `jsonSerializable` flag.
28
+ *
29
+ * When omitted, all messages fall back to structured-clone — safe but
30
+ * loses dev-time validation for `jsonSerializable: true` declarations.
31
+ */
32
+ definitions?: ReadonlyMap<string, Pick<RpcFunctionDefinitionAny, 'jsonSerializable'>>;
23
33
  onConnected?: (ws: WebSocket, req: IncomingMessage, meta: DevToolsNodeRpcSessionMeta) => void;
24
34
  onDisconnected?: (ws: WebSocket, meta: DevToolsNodeRpcSessionMeta) => void;
35
+ /** Override the default per-call serializer. Most callers should leave this unset. */
25
36
  serialize?: ChannelOptions['serialize'];
37
+ /** Override the default per-call deserializer. Most callers should leave this unset. */
26
38
  deserialize?: ChannelOptions['deserialize'];
27
39
  }
28
40
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "devframe",
3
3
  "type": "module",
4
- "version": "0.1.16",
4
+ "version": "0.1.18",
5
5
  "description": "Framework for building generic DevTools",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -1,17 +0,0 @@
1
- import { ChannelOptions } from "birpc";
2
-
3
- //#region src/rpc/transports/ws-client.d.ts
4
- interface WsRpcChannelOptions {
5
- url: string;
6
- onConnected?: (e: Event) => void;
7
- onError?: (e: Error) => void;
8
- onDisconnected?: (e: CloseEvent) => void;
9
- authToken?: string;
10
- }
11
- /**
12
- * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
13
- * Pass the result straight to `createRpcClient`'s `channel` option.
14
- */
15
- declare function createWsRpcChannel(options: WsRpcChannelOptions): ChannelOptions;
16
- //#endregion
17
- export { createWsRpcChannel as n, WsRpcChannelOptions as t };
File without changes
File without changes
File without changes