devframe 0.2.2 → 0.3.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.
- package/dist/adapters/build.d.mts +1 -1
- package/dist/adapters/build.mjs +5 -5
- package/dist/adapters/cli.d.mts +1 -1
- package/dist/adapters/cli.mjs +2 -2
- package/dist/adapters/dev.d.mts +2 -2
- package/dist/adapters/dev.mjs +1 -1
- package/dist/adapters/embedded.d.mts +1 -1
- package/dist/adapters/mcp.d.mts +1 -1
- package/dist/adapters/mcp.mjs +8 -7
- package/dist/client/index.d.mts +18 -4
- package/dist/client/index.mjs +321 -8
- package/dist/{context-BDpuScNZ.d.mts → context-CwjX6sCG.d.mts} +1 -1
- package/dist/{dev-CZ9ZQkuO.mjs → dev-BbmanqL7.mjs} +1 -1
- package/dist/{devframe-DAfZWnpI.d.mts → devframe-sc4cb5xr.d.mts} +48 -90
- package/dist/diagnostics-GitRGKbr.mjs +33 -0
- package/dist/diagnostics-reporter-CBBZwoMv.mjs +38 -0
- package/dist/{rpc-BlVCyk9W.mjs → dump-zMleojnD.mjs} +147 -134
- package/dist/helpers/vite.d.mts +1 -1
- package/dist/helpers/vite.mjs +6 -5
- package/dist/{host-h3-DEfOpa0j.mjs → host-h3-TTunNr_n.mjs} +284 -44
- package/dist/human-id-Dq-qgtES.mjs +803 -0
- package/dist/index-C5PmWqBf.d.mts +79 -0
- package/dist/{index-BNAsgVNz.d.mts → index-CTK6fuXs.d.mts} +31 -78
- package/dist/index-DTeZXHSi.d.mts +639 -0
- package/dist/index.d.mts +4 -4
- package/dist/node/auth.d.mts +2 -2
- package/dist/node/auth.mjs +1 -2
- package/dist/node/index.d.mts +10 -14
- package/dist/node/index.mjs +2 -2
- package/dist/node/internal.d.mts +2 -2
- package/dist/node/internal.mjs +2 -3
- package/dist/recipes/open-helpers.d.mts +1 -1
- package/dist/rpc/dump.d.mts +2 -0
- package/dist/rpc/dump.mjs +2 -0
- package/dist/rpc/index.d.mts +2 -2
- package/dist/rpc/index.mjs +128 -2
- package/dist/rpc/transports/ws-client.d.mts +25 -1
- package/dist/rpc/transports/ws-client.mjs +2 -2
- package/dist/rpc/transports/ws-server.d.mts +1 -1
- package/dist/rpc/transports/ws-server.mjs +2 -2
- package/dist/{serialization-CwO31axa.mjs → serialization-BlqLh4_J.mjs} +4 -38
- package/dist/{server-BGSrxsQb.d.mts → server-ouL4gZbu.d.mts} +1 -1
- package/dist/shared-state-CasqoUba.mjs +1019 -0
- package/dist/{shared-state-BJXkPxtf.mjs → shared-state-u0y123fi.mjs} +6 -6
- package/dist/{storage-D-jLaxDA.mjs → storage-K-OxR1xf.mjs} +5 -3
- package/dist/structured-clone-jegjz0hM.mjs +208 -0
- package/dist/types/index.d.mts +4 -4
- package/dist/utils/events.d.mts +1 -1
- package/dist/utils/hash.mjs +1 -1
- package/dist/utils/shared-state.d.mts +1 -1
- package/dist/utils/shared-state.mjs +1 -1
- package/dist/utils/streaming-channel.d.mts +1 -1
- package/dist/utils/structured-clone.mjs +1 -1
- package/dist/{ws-server-DKlqI8XP.d.mts → ws-server-DOwLJL23.d.mts} +1 -1
- package/package.json +3 -2
- package/skills/devframe/SKILL.md +1 -1
- package/dist/diagnostics-DNxVjo6X.mjs +0 -56
- package/dist/revoke-DDa7VSJa.mjs +0 -35
- package/dist/ws-client-CrLsflnY.d.mts +0 -26
- /package/dist/{hash-CIBte1yS.mjs → hash-bwOD8RgU.mjs} +0 -0
- /package/dist/{structured-clone-CD2l4fI3.mjs → structured-clone-PdCZwt7F.mjs} +0 -0
- /package/dist/{types-DmcujDa5.d.mts → types-BXL7EIDM.d.mts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as RpcFunctionsCollectorBase } from "./index-
|
|
2
|
-
import { t as DevToolsNodeRpcSessionMeta } from "./ws-server-
|
|
3
|
-
import {
|
|
1
|
+
import { S as RpcFunctionsCollectorBase } from "./index-CTK6fuXs.mjs";
|
|
2
|
+
import { t as DevToolsNodeRpcSessionMeta } from "./ws-server-DOwLJL23.mjs";
|
|
3
|
+
import { Diagnostic, DiagnosticDefinition, defineDiagnostics } from "nostics";
|
|
4
4
|
import { BirpcReturn } from "birpc";
|
|
5
5
|
import { CAC } from "cac";
|
|
6
6
|
import { GenericSchema, InferOutput } from "valibot";
|
|
@@ -289,17 +289,31 @@ interface DevToolsAgentHost {
|
|
|
289
289
|
* A diagnostics definition object built with `defineDiagnostics`. Typed as
|
|
290
290
|
* `unknown` because each integration's definition has a distinct narrow shape
|
|
291
291
|
* (e.g. specific code keys like `DF0001` / `MYP0001`), and TypeScript's mapped
|
|
292
|
-
* types don't allow assigning a narrow-keyed
|
|
293
|
-
*
|
|
294
|
-
* rebuilds the logger on `register()`.
|
|
292
|
+
* types don't allow assigning a narrow-keyed result to a generically-keyed
|
|
293
|
+
* one. The host stores them in a heterogeneous registry.
|
|
295
294
|
*/
|
|
296
|
-
type DevToolsDiagnosticsDefinition = ReturnType<typeof defineDiagnostics<any>>;
|
|
297
|
-
/** A `logs-sdk` Logger instance built with `createLogger`. */
|
|
298
|
-
type DevToolsDiagnosticsLogger = Logger<readonly any[]>;
|
|
295
|
+
type DevToolsDiagnosticsDefinition = ReturnType<typeof defineDiagnostics<any, any>>;
|
|
299
296
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
297
|
+
* The shared diagnostics lookup exposed by the host. A `Proxy` that resolves
|
|
298
|
+
* any registered code name to its `nostics` handle (with `.report()` and
|
|
299
|
+
* `.throw()` methods). Typed loosely because it spans heterogeneous
|
|
300
|
+
* definitions registered by different integrations.
|
|
301
|
+
*/
|
|
302
|
+
type DevToolsDiagnosticsLogger = Record<string, any>;
|
|
303
|
+
/**
|
|
304
|
+
* Options accepted by the host's `defineDiagnostics()` factory — mirrors
|
|
305
|
+
* `nostics`'s shape but the host pre-wires its ANSI console reporter, so
|
|
306
|
+
* plugins typically omit `reporters`.
|
|
307
|
+
*/
|
|
308
|
+
interface DevToolsDefineDiagnosticsOptions<Codes extends Record<string, DiagnosticDefinition>> {
|
|
309
|
+
docsBase?: string | ((code: keyof Codes) => string | undefined);
|
|
310
|
+
codes: Codes;
|
|
311
|
+
reporters?: ReadonlyArray<(d: Diagnostic, o?: any) => void>;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Host for structured diagnostics — a thin layer over `nostics` that lets
|
|
315
|
+
* integrations register their own coded errors/warnings into a shared
|
|
316
|
+
* registry without taking a direct dependency on `nostics`.
|
|
303
317
|
*
|
|
304
318
|
* Typical usage from a plugin's `setup(ctx)`:
|
|
305
319
|
*
|
|
@@ -307,47 +321,40 @@ type DevToolsDiagnosticsLogger = Logger<readonly any[]>;
|
|
|
307
321
|
* const myDiagnostics = ctx.diagnostics.defineDiagnostics({
|
|
308
322
|
* docsBase: 'https://example.com/errors',
|
|
309
323
|
* codes: {
|
|
310
|
-
* MYP0001: {
|
|
324
|
+
* MYP0001: { why: 'Something went wrong' },
|
|
311
325
|
* },
|
|
312
326
|
* })
|
|
313
327
|
* ctx.diagnostics.register(myDiagnostics)
|
|
314
328
|
*
|
|
315
|
-
* //
|
|
316
|
-
* ctx.diagnostics.logger.MYP0001
|
|
329
|
+
* // Through the shared lookup (loose typing):
|
|
330
|
+
* ctx.diagnostics.logger.MYP0001.throw()
|
|
317
331
|
*
|
|
318
|
-
* // Or
|
|
319
|
-
*
|
|
320
|
-
* logger.MYP0001().warn()
|
|
332
|
+
* // Or directly on the typed handle returned from `defineDiagnostics`:
|
|
333
|
+
* myDiagnostics.MYP0001.throw()
|
|
321
334
|
* ```
|
|
322
335
|
*/
|
|
323
336
|
interface DevToolsDiagnosticsHost {
|
|
324
337
|
/**
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
338
|
+
* Proxy-backed lookup of every registered diagnostic handle by code name.
|
|
339
|
+
* Resolves to a `nostics` `DiagnosticHandle` with `.report()` / `.throw()`.
|
|
340
|
+
* Loosely typed — for autocompletion, keep a reference to the typed
|
|
341
|
+
* result of `defineDiagnostics()` instead.
|
|
329
342
|
*/
|
|
330
343
|
readonly logger: DevToolsDiagnosticsLogger;
|
|
331
344
|
/**
|
|
332
|
-
* Register
|
|
333
|
-
* registration, codes from the new definition are
|
|
334
|
-
* `host.logger`.
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*/
|
|
338
|
-
register: (definitions: unknown) => void;
|
|
339
|
-
/**
|
|
340
|
-
* Re-export of `logs-sdk`'s `defineDiagnostics`. Integrations can build
|
|
341
|
-
* their own diagnostic definitions without taking a direct dependency on
|
|
342
|
-
* `logs-sdk`.
|
|
345
|
+
* Register additional diagnostic definitions with this host. After
|
|
346
|
+
* registration, codes from the new definition are reachable via
|
|
347
|
+
* `host.logger.CODE`. Plugins that want shared output formatting should
|
|
348
|
+
* build their diagnostics via `host.defineDiagnostics()` first — that
|
|
349
|
+
* factory pre-wires the host's ANSI console reporter.
|
|
343
350
|
*/
|
|
344
|
-
|
|
351
|
+
register: (definitions: Record<string, unknown>) => void;
|
|
345
352
|
/**
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
353
|
+
* Build a typed diagnostics object with the host's ANSI console reporter
|
|
354
|
+
* pre-wired. Mirrors `nostics`'s `defineDiagnostics` so integrations don't
|
|
355
|
+
* need to take a direct dependency on `nostics`.
|
|
349
356
|
*/
|
|
350
|
-
|
|
357
|
+
defineDiagnostics: <const Codes extends Record<string, DiagnosticDefinition>>(options: DevToolsDefineDiagnosticsOptions<Codes>) => ReturnType<typeof defineDiagnostics<Codes, any>>;
|
|
351
358
|
}
|
|
352
359
|
//#endregion
|
|
353
360
|
//#region src/types/host.d.ts
|
|
@@ -564,19 +571,6 @@ interface SharedState<T> {
|
|
|
564
571
|
interface SharedStateEvents<T> {
|
|
565
572
|
updated: (fullState: T, patches: SharedStatePatch[] | undefined, syncId: string) => void;
|
|
566
573
|
}
|
|
567
|
-
interface SharedStateOptions<T> {
|
|
568
|
-
/**
|
|
569
|
-
* Initial state.
|
|
570
|
-
*/
|
|
571
|
-
initialValue: T;
|
|
572
|
-
/**
|
|
573
|
-
* Enable patches.
|
|
574
|
-
*
|
|
575
|
-
* @default false
|
|
576
|
-
*/
|
|
577
|
-
enablePatches?: boolean;
|
|
578
|
-
}
|
|
579
|
-
declare function createSharedState<T extends object>(options: SharedStateOptions<T>): SharedState<T>;
|
|
580
574
|
//#endregion
|
|
581
575
|
//#region src/utils/streaming-channel.d.ts
|
|
582
576
|
/**
|
|
@@ -604,14 +598,6 @@ interface StreamSinkEvents<T> {
|
|
|
604
598
|
/** Terminal — fired exactly once per sink lifetime. */
|
|
605
599
|
end: (error?: StreamErrorPayload) => void;
|
|
606
600
|
}
|
|
607
|
-
interface CreateStreamSinkOptions {
|
|
608
|
-
id?: string;
|
|
609
|
-
/**
|
|
610
|
-
* Size of the per-stream ring buffer kept for replay-on-resubscribe.
|
|
611
|
-
* `0` (default) disables replay.
|
|
612
|
-
*/
|
|
613
|
-
replayWindow?: number;
|
|
614
|
-
}
|
|
615
601
|
/**
|
|
616
602
|
* Server-side producer handle. Two equivalent surfaces share one piece of
|
|
617
603
|
* state: the imperative `write/error/close` triple, and a `WritableStream<T>`
|
|
@@ -652,22 +638,6 @@ interface StreamSink<T> {
|
|
|
652
638
|
*/
|
|
653
639
|
readonly buffer: ReadonlyArray<BufferedChunk<T>>;
|
|
654
640
|
}
|
|
655
|
-
interface CreateStreamReaderOptions {
|
|
656
|
-
id?: string;
|
|
657
|
-
/**
|
|
658
|
-
* Maximum number of buffered chunks held client-side while the consumer
|
|
659
|
-
* isn't draining. On overflow, the oldest chunk is dropped.
|
|
660
|
-
*/
|
|
661
|
-
highWaterMark?: number;
|
|
662
|
-
/**
|
|
663
|
-
* Called when the chunk queue overflows the high-water mark. The RPC
|
|
664
|
-
* layer wires this to a coded warning; the primitive itself is
|
|
665
|
-
* RPC-agnostic.
|
|
666
|
-
*/
|
|
667
|
-
onOverflow?: (dropped: number) => void;
|
|
668
|
-
/** Called when the consumer cancels — the RPC layer sends `:cancel` upstream. */
|
|
669
|
-
onCancel?: () => void;
|
|
670
|
-
}
|
|
671
641
|
/**
|
|
672
642
|
* Client-side consumer handle. Both an `AsyncIterable<T>` (for `for await`)
|
|
673
643
|
* and exposes `readable: ReadableStream<T>` (for `pipeTo`). Pick one — they
|
|
@@ -687,18 +657,6 @@ interface StreamReader<T> extends AsyncIterable<T> {
|
|
|
687
657
|
/** @internal */
|
|
688
658
|
_end: (error?: StreamErrorPayload) => void;
|
|
689
659
|
}
|
|
690
|
-
/**
|
|
691
|
-
* Build a server-side stream sink. RPC-agnostic — the RPC host wires
|
|
692
|
-
* `events.on('chunk' | 'end')` to broadcast, and reads `buffer` to replay
|
|
693
|
-
* for late or reconnecting subscribers.
|
|
694
|
-
*/
|
|
695
|
-
declare function createStreamSink<T>(options?: CreateStreamSinkOptions): StreamSink<T>;
|
|
696
|
-
/**
|
|
697
|
-
* Build a client-side stream reader. RPC-agnostic — the RPC host calls
|
|
698
|
-
* `_push(seq, chunk)` on each incoming chunk and `_end(error?)` on the
|
|
699
|
-
* terminal frame. Consumers iterate with `for await` or pipe `readable`.
|
|
700
|
-
*/
|
|
701
|
-
declare function createStreamReader<T>(options?: CreateStreamReaderOptions): StreamReader<T>;
|
|
702
660
|
//#endregion
|
|
703
661
|
//#region src/types/rpc.d.ts
|
|
704
662
|
interface DevToolsNodeRpcSession {
|
|
@@ -898,8 +856,8 @@ interface DevToolsNodeContext {
|
|
|
898
856
|
rpc: RpcFunctionsHost;
|
|
899
857
|
views: DevToolsViewHost;
|
|
900
858
|
/**
|
|
901
|
-
* Structured diagnostics host — wraps `
|
|
902
|
-
* register their own coded errors/warnings into the shared
|
|
859
|
+
* Structured diagnostics host — wraps `nostics` and lets integrations
|
|
860
|
+
* register their own coded errors/warnings into the shared lookup.
|
|
903
861
|
*/
|
|
904
862
|
diagnostics: DevToolsDiagnosticsHost;
|
|
905
863
|
/**
|
|
@@ -1047,4 +1005,4 @@ interface DevframeDefinition {
|
|
|
1047
1005
|
}
|
|
1048
1006
|
declare function defineDevframe(d: DevframeDefinition): DevframeDefinition;
|
|
1049
1007
|
//#endregion
|
|
1050
|
-
export {
|
|
1008
|
+
export { DevToolsDiagnosticsDefinition as A, DevToolsAgentHost as B, PartialWithoutId as C, DevToolsRpcSharedStates as D, DevToolsRpcServerFunctions as E, AgentResource as F, CliFlagsSchema as G, EventEmitter as H, AgentResourceContent as I, parseCliFlags as J, InferCliFlags as K, AgentResourceInput as L, DevToolsDiagnosticsLogger as M, AgentHandle as N, DevToolsHost as O, AgentManifest as P, AgentTool as R, EntriesToObject as S, DevToolsRpcClientFunctions as T, EventUnsubscribe as U, DevToolsAgentHostEvents as V, EventsMap as W, RpcStreamingChannel as _, DevframeRuntime as a, SharedState as b, defineDevframe as c, DevToolsNodeContext as d, DevToolsNodeRpcSession as f, RpcSharedStateHost as g, RpcSharedStateGetOptions as h, DevframeDeploymentKind as i, DevToolsDiagnosticsHost as j, DevToolsDefineDiagnosticsOptions as k, ConnectionMeta as l, RpcFunctionsHost as m, DevframeCliOptions as n, DevframeSetupInfo as o, RpcBroadcastOptions as p, defineCliFlags as q, DevframeDefinition as r, DevframeSpaOptions as s, DevframeBrowserContext as t, DevToolsCapabilities as u, RpcStreamingChannelOptions as v, Thenable as w, DevToolsViewHost as x, RpcStreamingHost as y, AgentToolInput as z };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as devframeReporter } from "./diagnostics-reporter-CBBZwoMv.mjs";
|
|
2
|
+
import { defineDiagnostics } from "nostics";
|
|
3
|
+
//#region src/rpc/diagnostics.ts
|
|
4
|
+
const diagnostics = defineDiagnostics({
|
|
5
|
+
docsBase: "https://devfra.me/errors",
|
|
6
|
+
reporters: [devframeReporter],
|
|
7
|
+
codes: {
|
|
8
|
+
DF0019: {
|
|
9
|
+
why: (p) => `RPC function "${p.name}" has \`agent\` set but \`jsonSerializable\` is not \`true\` — MCP requires JSON-serializable data.`,
|
|
10
|
+
fix: "Set `jsonSerializable: true` if the payload is JSON-safe, or remove `agent` to keep it RPC-only."
|
|
11
|
+
},
|
|
12
|
+
DF0020: {
|
|
13
|
+
why: (p) => `RPC function "${p.name}" declares \`jsonSerializable: true\` but the value at "${p.path}" is a ${p.type}.`,
|
|
14
|
+
fix: "Either drop `jsonSerializable: true` (falls back to structured-clone) or change the value to a JSON-safe shape."
|
|
15
|
+
},
|
|
16
|
+
DF0021: {
|
|
17
|
+
why: (p) => `RPC function "${p.name}" is already registered`,
|
|
18
|
+
fix: "Use the `force` parameter to overwrite an existing registration."
|
|
19
|
+
},
|
|
20
|
+
DF0022: { why: (p) => `RPC function "${p.name}" is not registered. Use register() to add new functions.` },
|
|
21
|
+
DF0023: { why: (p) => `RPC function "${p.name}" is not registered` },
|
|
22
|
+
DF0024: { why: (p) => `Either handler or setup function must be provided for RPC function "${p.name}"` },
|
|
23
|
+
DF0025: { why: (p) => `Function "${p.name}" not found in dump store` },
|
|
24
|
+
DF0026: { why: (p) => `No dump match for "${p.name}" with args: ${p.args}` },
|
|
25
|
+
DF0027: { why: (p) => `Function "${p.name}" with type "${p.type}" cannot have dump configuration. Only "static" and "query" types support dumps.` },
|
|
26
|
+
DF0028: {
|
|
27
|
+
why: (p) => `Function "${p.name}" with type "${p.type}" cannot use \`snapshot: true\`. Only "query" functions support this sugar; "static" functions have equivalent default behavior already.`,
|
|
28
|
+
fix: "Remove `snapshot: true`, or change the function type to `query`."
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
//#endregion
|
|
33
|
+
export { diagnostics as t };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ansiFormatter } from "nostics/formatters/ansi";
|
|
2
|
+
//#region src/utils/colors.ts
|
|
3
|
+
function makeColor(open, close) {
|
|
4
|
+
const o = `\x1B[${open}m`;
|
|
5
|
+
const c = `\x1B[${close}m`;
|
|
6
|
+
return ((arg, ...values) => {
|
|
7
|
+
if (Array.isArray(arg) && "raw" in arg) {
|
|
8
|
+
const strings = arg;
|
|
9
|
+
let out = "";
|
|
10
|
+
for (let i = 0; i < strings.length; i++) {
|
|
11
|
+
out += strings[i];
|
|
12
|
+
if (i < values.length) out += String(values[i]);
|
|
13
|
+
}
|
|
14
|
+
return `${o}${out}${c}`;
|
|
15
|
+
}
|
|
16
|
+
return `${o}${String(arg)}${c}`;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const colors = {
|
|
20
|
+
blue: makeColor(34, 39),
|
|
21
|
+
cyan: makeColor(36, 39),
|
|
22
|
+
gray: makeColor(90, 39),
|
|
23
|
+
green: makeColor(32, 39),
|
|
24
|
+
red: makeColor(31, 39),
|
|
25
|
+
yellow: makeColor(33, 39),
|
|
26
|
+
bold: makeColor(1, 22),
|
|
27
|
+
dim: makeColor(2, 22),
|
|
28
|
+
reset: makeColor(0, 0),
|
|
29
|
+
underline: makeColor(4, 24)
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/utils/diagnostics-reporter.ts
|
|
33
|
+
const formatAnsi = ansiFormatter(colors);
|
|
34
|
+
function devframeReporter(d, { method = "warn" } = {}) {
|
|
35
|
+
console[method](formatAnsi(d));
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { colors as n, devframeReporter as t };
|
|
@@ -1,133 +1,128 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { i as logger } from "./serialization-CwO31axa.mjs";
|
|
1
|
+
import { t as diagnostics } from "./diagnostics-GitRGKbr.mjs";
|
|
3
2
|
import { DEVTOOLS_RPC_DUMP_DIRNAME } from "./constants.mjs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
//#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/shared/ohash.D__AXeF1.mjs
|
|
5
|
+
function serialize(o) {
|
|
6
|
+
return typeof o == "string" ? `'${o}'` : new c().serialize(o);
|
|
7
|
+
}
|
|
8
|
+
const c = /* @__PURE__ */ function() {
|
|
9
|
+
class o {
|
|
10
|
+
#t = /* @__PURE__ */ new Map();
|
|
11
|
+
compare(t, r) {
|
|
12
|
+
const e = typeof t, n = typeof r;
|
|
13
|
+
return e === "string" && n === "string" ? t.localeCompare(r) : e === "number" && n === "number" ? t - r : String.prototype.localeCompare.call(this.serialize(t, true), this.serialize(r, true));
|
|
14
|
+
}
|
|
15
|
+
serialize(t, r) {
|
|
16
|
+
if (t === null) return "null";
|
|
17
|
+
switch (typeof t) {
|
|
18
|
+
case "string": return r ? t : `'${t}'`;
|
|
19
|
+
case "bigint": return `${t}n`;
|
|
20
|
+
case "object": return this.$object(t);
|
|
21
|
+
case "function": return this.$function(t);
|
|
22
|
+
}
|
|
23
|
+
return String(t);
|
|
24
|
+
}
|
|
25
|
+
serializeObject(t) {
|
|
26
|
+
const r = Object.prototype.toString.call(t);
|
|
27
|
+
if (r !== "[object Object]") return this.serializeBuiltInType(r.length < 10 ? `unknown:${r}` : r.slice(8, -1), t);
|
|
28
|
+
const e = t.constructor, n = e === Object || e === void 0 ? "" : e.name;
|
|
29
|
+
if (n !== "" && globalThis[n] === e) return this.serializeBuiltInType(n, t);
|
|
30
|
+
if (typeof t.toJSON == "function") {
|
|
31
|
+
const i = t.toJSON();
|
|
32
|
+
return n + (i !== null && typeof i == "object" ? this.$object(i) : `(${this.serialize(i)})`);
|
|
33
|
+
}
|
|
34
|
+
return this.serializeObjectEntries(n, Object.entries(t));
|
|
35
|
+
}
|
|
36
|
+
serializeBuiltInType(t, r) {
|
|
37
|
+
const e = this["$" + t];
|
|
38
|
+
if (e) return e.call(this, r);
|
|
39
|
+
if (typeof r?.entries == "function") return this.serializeObjectEntries(t, r.entries());
|
|
40
|
+
throw new Error(`Cannot serialize ${t}`);
|
|
41
|
+
}
|
|
42
|
+
serializeObjectEntries(t, r) {
|
|
43
|
+
const e = Array.from(r).sort((i, a) => this.compare(i[0], a[0]));
|
|
44
|
+
let n = `${t}{`;
|
|
45
|
+
for (let i = 0; i < e.length; i++) {
|
|
46
|
+
const [a, l] = e[i];
|
|
47
|
+
n += `${this.serialize(a, true)}:${this.serialize(l)}`, i < e.length - 1 && (n += ",");
|
|
48
|
+
}
|
|
49
|
+
return n + "}";
|
|
50
|
+
}
|
|
51
|
+
$object(t) {
|
|
52
|
+
let r = this.#t.get(t);
|
|
53
|
+
return r === void 0 && (this.#t.set(t, `#${this.#t.size}`), r = this.serializeObject(t), this.#t.set(t, r)), r;
|
|
54
|
+
}
|
|
55
|
+
$function(t) {
|
|
56
|
+
const r = Function.prototype.toString.call(t);
|
|
57
|
+
return r.slice(-15) === "[native code] }" ? `${t.name || ""}()[native]` : `${t.name}(${t.length})${r.replace(/\s*\n\s*/g, "")}`;
|
|
58
|
+
}
|
|
59
|
+
$Array(t) {
|
|
60
|
+
let r = "[";
|
|
61
|
+
for (let e = 0; e < t.length; e++) r += this.serialize(t[e]), e < t.length - 1 && (r += ",");
|
|
62
|
+
return r + "]";
|
|
63
|
+
}
|
|
64
|
+
$Date(t) {
|
|
65
|
+
try {
|
|
66
|
+
return `Date(${t.toISOString()})`;
|
|
67
|
+
} catch {
|
|
68
|
+
return "Date(null)";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
$ArrayBuffer(t) {
|
|
72
|
+
return `ArrayBuffer[${new Uint8Array(t).join(",")}]`;
|
|
73
|
+
}
|
|
74
|
+
$Set(t) {
|
|
75
|
+
return `Set${this.$Array(Array.from(t).sort((r, e) => this.compare(r, e)))}`;
|
|
76
|
+
}
|
|
77
|
+
$Map(t) {
|
|
78
|
+
return this.serializeObjectEntries("Map", t.entries());
|
|
79
|
+
}
|
|
37
80
|
}
|
|
38
|
-
|
|
81
|
+
for (const s of [
|
|
82
|
+
"Error",
|
|
83
|
+
"RegExp",
|
|
84
|
+
"URL"
|
|
85
|
+
]) o.prototype["$" + s] = function(t) {
|
|
86
|
+
return `${s}(${t})`;
|
|
87
|
+
};
|
|
88
|
+
for (const s of [
|
|
89
|
+
"Int8Array",
|
|
90
|
+
"Uint8Array",
|
|
91
|
+
"Uint8ClampedArray",
|
|
92
|
+
"Int16Array",
|
|
93
|
+
"Uint16Array",
|
|
94
|
+
"Int32Array",
|
|
95
|
+
"Uint32Array",
|
|
96
|
+
"Float32Array",
|
|
97
|
+
"Float64Array"
|
|
98
|
+
]) o.prototype["$" + s] = function(t) {
|
|
99
|
+
return `${s}[${t.join(",")}]`;
|
|
100
|
+
};
|
|
101
|
+
for (const s of ["BigInt64Array", "BigUint64Array"]) o.prototype["$" + s] = function(t) {
|
|
102
|
+
return `${s}[${t.join("n,")}${t.length > 0 ? "n" : ""}]`;
|
|
103
|
+
};
|
|
104
|
+
return o;
|
|
105
|
+
}();
|
|
39
106
|
//#endregion
|
|
40
|
-
//#region
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
definition.__promise = void 0;
|
|
47
|
-
return r;
|
|
48
|
-
});
|
|
49
|
-
return definition.__resolved ??= await definition.__promise;
|
|
107
|
+
//#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/crypto/node/index.mjs
|
|
108
|
+
const e = globalThis.process?.getBuiltinModule?.("crypto")?.hash, r = "sha256", s = "base64url";
|
|
109
|
+
function digest(t) {
|
|
110
|
+
if (e) return e(r, t, s);
|
|
111
|
+
const o = createHash(r).update(t);
|
|
112
|
+
return globalThis.process?.versions?.webcontainer ? o.digest().toString(s) : o.digest(s);
|
|
50
113
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return result.handler;
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region ../../node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/index.mjs
|
|
116
|
+
function hash$1(input) {
|
|
117
|
+
return digest(serialize(input));
|
|
56
118
|
}
|
|
57
119
|
//#endregion
|
|
58
|
-
//#region src/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
constructor(context) {
|
|
65
|
-
this.context = context;
|
|
66
|
-
const definitions = this.definitions;
|
|
67
|
-
const self = this;
|
|
68
|
-
this.functions = new Proxy({}, {
|
|
69
|
-
get(_, prop) {
|
|
70
|
-
const definition = definitions.get(prop);
|
|
71
|
-
if (!definition) return void 0;
|
|
72
|
-
return getRpcHandler(definition, self.context);
|
|
73
|
-
},
|
|
74
|
-
has(_, prop) {
|
|
75
|
-
return definitions.has(prop);
|
|
76
|
-
},
|
|
77
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
78
|
-
return {
|
|
79
|
-
value: definitions.get(prop)?.handler,
|
|
80
|
-
configurable: true,
|
|
81
|
-
enumerable: true
|
|
82
|
-
};
|
|
83
|
-
},
|
|
84
|
-
ownKeys() {
|
|
85
|
-
return Array.from(definitions.keys());
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
register(fn, force = false) {
|
|
90
|
-
if (this.definitions.has(fn.name) && !force) throw logger.DF0021({ name: fn.name }).throw();
|
|
91
|
-
assertAgentJsonSerializable(fn);
|
|
92
|
-
this.definitions.set(fn.name, fn);
|
|
93
|
-
this._onChanged.forEach((cb) => cb(fn.name));
|
|
94
|
-
}
|
|
95
|
-
update(fn, force = false) {
|
|
96
|
-
if (!this.definitions.has(fn.name) && !force) throw logger.DF0022({ name: fn.name }).throw();
|
|
97
|
-
assertAgentJsonSerializable(fn);
|
|
98
|
-
this.definitions.set(fn.name, fn);
|
|
99
|
-
this._onChanged.forEach((cb) => cb(fn.name));
|
|
100
|
-
}
|
|
101
|
-
onChanged(fn) {
|
|
102
|
-
this._onChanged.push(fn);
|
|
103
|
-
return () => {
|
|
104
|
-
const index = this._onChanged.indexOf(fn);
|
|
105
|
-
if (index !== -1) this._onChanged.splice(index, 1);
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
async getHandler(name) {
|
|
109
|
-
return await getRpcHandler(this.definitions.get(name), this.context);
|
|
110
|
-
}
|
|
111
|
-
getSchema(name) {
|
|
112
|
-
const definition = this.definitions.get(name);
|
|
113
|
-
if (!definition) throw logger.DF0023({ name: String(name) }).throw();
|
|
114
|
-
return {
|
|
115
|
-
args: definition.args,
|
|
116
|
-
returns: definition.returns
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
has(name) {
|
|
120
|
-
return this.definitions.has(name);
|
|
121
|
-
}
|
|
122
|
-
get(name) {
|
|
123
|
-
return this.definitions.get(name);
|
|
124
|
-
}
|
|
125
|
-
list() {
|
|
126
|
-
return Array.from(this.definitions.keys());
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
function assertAgentJsonSerializable(fn) {
|
|
130
|
-
if (fn.agent && fn.jsonSerializable !== true) throw logger.DF0019({ name: fn.name }).throw();
|
|
120
|
+
//#region src/utils/hash.ts
|
|
121
|
+
/**
|
|
122
|
+
* Stable, deterministic hash of any structured-cloneable value.
|
|
123
|
+
*/
|
|
124
|
+
function hash(value) {
|
|
125
|
+
return hash$1(value);
|
|
131
126
|
}
|
|
132
127
|
//#endregion
|
|
133
128
|
//#region ../../node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
@@ -267,14 +262,14 @@ function validateConcurrency(concurrency) {
|
|
|
267
262
|
function validateDefinitions(definitions) {
|
|
268
263
|
for (const definition of definitions) {
|
|
269
264
|
const type = definition.type || "query";
|
|
270
|
-
if ((type === "action" || type === "event") && definition.dump) throw
|
|
265
|
+
if ((type === "action" || type === "event") && definition.dump) throw diagnostics.DF0027.throw({
|
|
271
266
|
name: definition.name,
|
|
272
267
|
type
|
|
273
|
-
})
|
|
274
|
-
if (definition.snapshot && type !== "query") throw
|
|
268
|
+
});
|
|
269
|
+
if (definition.snapshot && type !== "query") throw diagnostics.DF0028.throw({
|
|
275
270
|
name: definition.name,
|
|
276
271
|
type
|
|
277
|
-
})
|
|
272
|
+
});
|
|
278
273
|
}
|
|
279
274
|
}
|
|
280
275
|
/**
|
|
@@ -339,7 +334,7 @@ function isPlainErrorShape(value) {
|
|
|
339
334
|
return typeof value === "object" && value !== null && typeof value.message === "string" && typeof value.name === "string";
|
|
340
335
|
}
|
|
341
336
|
//#endregion
|
|
342
|
-
//#region src/rpc/dump/
|
|
337
|
+
//#region src/rpc/dump/collect.ts
|
|
343
338
|
function getDumpRecordKey(functionName, args) {
|
|
344
339
|
return `${functionName}---${hash(args)}`;
|
|
345
340
|
}
|
|
@@ -369,7 +364,7 @@ async function dumpFunctions(definitions, context, options = {}) {
|
|
|
369
364
|
if (definition.type === "event" || definition.type === "action") return;
|
|
370
365
|
const setupResult = definition.setup ? await Promise.resolve(definition.setup(context)) : {};
|
|
371
366
|
const handler = setupResult.handler || definition.handler;
|
|
372
|
-
if (!handler) throw
|
|
367
|
+
if (!handler) throw diagnostics.DF0024.throw({ name: definition.name });
|
|
373
368
|
let dump = setupResult.dump ?? definition.dump;
|
|
374
369
|
if (!dump && definition.type === "static") dump = { inputs: [[]] };
|
|
375
370
|
if (!dump && definition.snapshot) dump = async (_ctx, h) => {
|
|
@@ -454,7 +449,7 @@ function createClientFromDump(store, options = {}) {
|
|
|
454
449
|
const { onMiss } = options;
|
|
455
450
|
return new Proxy({}, {
|
|
456
451
|
get(_, functionName) {
|
|
457
|
-
if (!(functionName in store.definitions)) throw
|
|
452
|
+
if (!(functionName in store.definitions)) throw diagnostics.DF0025.throw({ name: functionName });
|
|
458
453
|
return async (...args) => {
|
|
459
454
|
const recordKey = getDumpRecordKey(functionName, args);
|
|
460
455
|
const recordOrGetter = store.records[recordKey];
|
|
@@ -472,10 +467,10 @@ function createClientFromDump(store, options = {}) {
|
|
|
472
467
|
if (fallbackRecord && typeof fallbackRecord.output === "function") return await fallbackRecord.output();
|
|
473
468
|
if (fallbackRecord) return fallbackRecord.output;
|
|
474
469
|
}
|
|
475
|
-
throw
|
|
470
|
+
throw diagnostics.DF0026.throw({
|
|
476
471
|
name: functionName,
|
|
477
472
|
args: JSON.stringify(args)
|
|
478
|
-
})
|
|
473
|
+
});
|
|
479
474
|
};
|
|
480
475
|
},
|
|
481
476
|
has(_, functionName) {
|
|
@@ -501,6 +496,24 @@ function getDefinitionsWithDumps(definitions) {
|
|
|
501
496
|
return definitions.filter((def) => def.dump !== void 0);
|
|
502
497
|
}
|
|
503
498
|
//#endregion
|
|
499
|
+
//#region src/rpc/handler.ts
|
|
500
|
+
async function getRpcResolvedSetupResult(definition, context) {
|
|
501
|
+
if (definition.__resolved) return definition.__resolved;
|
|
502
|
+
if (!definition.setup) return {};
|
|
503
|
+
definition.__promise ??= Promise.resolve(definition.setup(context)).then((r) => {
|
|
504
|
+
definition.__resolved = r;
|
|
505
|
+
definition.__promise = void 0;
|
|
506
|
+
return r;
|
|
507
|
+
});
|
|
508
|
+
return definition.__resolved ??= await definition.__promise;
|
|
509
|
+
}
|
|
510
|
+
async function getRpcHandler(definition, context) {
|
|
511
|
+
if (definition.handler) return definition.handler;
|
|
512
|
+
const result = await getRpcResolvedSetupResult(definition, context);
|
|
513
|
+
if (!result.handler) throw diagnostics.DF0024.throw({ name: definition.name });
|
|
514
|
+
return result.handler;
|
|
515
|
+
}
|
|
516
|
+
//#endregion
|
|
504
517
|
//#region src/rpc/dump/static.ts
|
|
505
518
|
function makeDumpKey(name) {
|
|
506
519
|
return encodeURIComponent(name.replaceAll(":", "~"));
|
|
@@ -578,4 +591,4 @@ async function collectStaticRpcDump(definitions, context) {
|
|
|
578
591
|
};
|
|
579
592
|
}
|
|
580
593
|
//#endregion
|
|
581
|
-
export {
|
|
594
|
+
export { dumpFunctions as a, serializeDumpError as c, hash as d, createClientFromDump as i, validateDefinition as l, getRpcHandler as n, getDefinitionsWithDumps as o, getRpcResolvedSetupResult as r, reviveDumpError as s, collectStaticRpcDump as t, validateDefinitions as u };
|
package/dist/helpers/vite.d.mts
CHANGED
package/dist/helpers/vite.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DEVTOOLS_CONNECTION_META_FILENAME } from "../constants.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { i as diagnostics } from "../shared-state-CasqoUba.mjs";
|
|
3
3
|
import { n as resolveBasePath } from "../_shared-CUFqO4kJ.mjs";
|
|
4
4
|
import { serveStaticNodeMiddleware } from "../utils/serve-static.mjs";
|
|
5
|
-
import { n as resolveDevServerPort, t as createDevServer } from "../dev-
|
|
5
|
+
import { n as resolveDevServerPort, t as createDevServer } from "../dev-BbmanqL7.mjs";
|
|
6
6
|
import { resolve } from "pathe";
|
|
7
7
|
//#region src/helpers/vite.ts
|
|
8
8
|
/**
|
|
@@ -54,10 +54,11 @@ function viteDevBridge(d, options = {}) {
|
|
|
54
54
|
openBrowser: false
|
|
55
55
|
});
|
|
56
56
|
} catch (e) {
|
|
57
|
-
|
|
57
|
+
diagnostics.DF0033.report({
|
|
58
58
|
id: d.id,
|
|
59
|
-
reason: String(e)
|
|
60
|
-
|
|
59
|
+
reason: String(e),
|
|
60
|
+
cause: e
|
|
61
|
+
}, { method: "warn" });
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
const metaPath = `${base}${DEVTOOLS_CONNECTION_META_FILENAME}`;
|