devframe 0.1.21 → 0.2.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/README.md +40 -18
- package/dist/{_shared-iZy45oG3.mjs → _shared-BrKv3CYt.mjs} +5 -5
- package/dist/adapters/build.d.mts +5 -5
- package/dist/adapters/build.mjs +13 -12
- package/dist/adapters/cli.d.mts +4 -4
- package/dist/adapters/cli.mjs +5 -5
- package/dist/adapters/dev.d.mts +21 -12
- package/dist/adapters/dev.mjs +1 -1
- package/dist/adapters/embedded.d.mts +5 -5
- package/dist/adapters/embedded.mjs +2 -2
- package/dist/adapters/mcp.d.mts +3 -3
- package/dist/adapters/mcp.mjs +5 -5
- package/dist/chunk-e9Ob2GDo.mjs +26 -0
- package/dist/client/index.d.mts +8 -5
- package/dist/client/index.mjs +12 -12
- package/dist/colors-DS7k8ljB.mjs +123 -0
- package/dist/{context-BJ4r2SmR.mjs → context-BBi2IQDm.mjs} +19 -37
- package/dist/{context-internal-saIAfNVw.d.mts → context-DRa0wGsC.d.mts} +2 -2
- package/dist/{dev-CdAy400a.mjs → dev-CewNNE2R.mjs} +24 -28
- package/dist/{devtool-CNvLs2_Y.d.mts → devframe-R5Ex5K5L.d.mts} +41 -66
- package/dist/{diagnostics-DxPnRoXO.mjs → diagnostics-Cg9ycFIM.mjs} +7 -2
- package/dist/hash-CIBte1yS.mjs +263 -0
- package/dist/helpers/vite.d.mts +65 -0
- package/dist/helpers/vite.mjs +94 -0
- package/dist/{human-id-BLoGo_e5.mjs → human-id-adtUWQLr.mjs} +12 -3
- package/dist/{index-CuLRIMto.d.mts → index-DB2Ie0Or.d.mts} +2 -3
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +2 -5
- package/dist/launch-editor-CX_n_0SS.mjs +581 -0
- package/dist/node/auth.d.mts +44 -0
- package/dist/node/auth.mjs +55 -0
- package/dist/node/index.d.mts +13 -55
- package/dist/node/index.mjs +6 -62
- package/dist/node/internal.d.mts +16 -0
- package/dist/node/internal.mjs +50 -0
- package/dist/{open-Dede_w9r.mjs → open-B2ah1IKK.mjs} +38 -24
- package/dist/recipes/open-helpers.d.mts +4 -9
- package/dist/recipes/open-helpers.mjs +7 -12
- package/dist/revoke-DIMz1r7-.mjs +35 -0
- package/dist/rpc/index.d.mts +3 -3
- package/dist/rpc/index.mjs +4 -4
- package/dist/rpc/transports/ws-client.d.mts +1 -1
- package/dist/rpc/transports/ws-client.mjs +2 -1
- package/dist/rpc/transports/ws-server.d.mts +1 -1
- package/dist/rpc/transports/ws-server.mjs +2 -1
- package/dist/{rpc-INbWfHoX.mjs → rpc-DAzoVCR0.mjs} +5 -4
- package/dist/{serialization-DwKi05Pn.mjs → serialization-CwO31axa.mjs} +1 -2
- package/dist/{server-CBsxXIH5.mjs → server-DOk4grlJ.mjs} +4 -4
- package/dist/{server-BAqOajx_.d.mts → server-DzKz023G.d.mts} +8 -7
- package/dist/shared-state-q9-1EOSX.mjs +928 -0
- package/dist/{static-dump-D5VH8Iqk.mjs → static-dump-C67bCuse.mjs} +1 -1
- package/dist/{context-internal-Dx_NoSv1.mjs → storage-CNvfBGQ5.mjs} +5 -87
- package/dist/structured-clone-CD2l4fI3.mjs +221 -0
- package/dist/types/index.d.mts +4 -4
- package/dist/types/index.mjs +3 -3
- package/dist/utils/colors.d.mts +28 -0
- package/dist/utils/colors.mjs +2 -0
- package/dist/utils/events.d.mts +1 -1
- package/dist/utils/hash.d.mts +7 -0
- package/dist/utils/hash.mjs +2 -0
- package/dist/utils/human-id.d.mts +6 -8
- package/dist/utils/human-id.mjs +1 -2
- package/dist/utils/launch-editor.d.mts +13 -0
- package/dist/utils/launch-editor.mjs +2 -0
- package/dist/utils/open.d.mts +16 -0
- package/dist/utils/open.mjs +2 -0
- package/dist/utils/serve-static.d.mts +40 -0
- package/dist/utils/serve-static.mjs +173 -0
- package/dist/utils/shared-state.d.mts +1 -1
- package/dist/utils/shared-state.mjs +1 -35
- package/dist/utils/streaming-channel.d.mts +1 -1
- package/dist/utils/structured-clone.d.mts +21 -0
- package/dist/utils/structured-clone.mjs +2 -0
- package/dist/utils/when.d.mts +33 -50
- package/dist/utils/when.mjs +21 -3
- package/dist/{ws-client-CjPuPFbA.d.mts → ws-client-Bavoya6-.d.mts} +1 -1
- package/dist/{ws-server-C7LnhOHi.d.mts → ws-server-DjvlwLuM.d.mts} +1 -1
- package/package.json +38 -18
- package/skills/devframe/SKILL.md +64 -39
- package/skills/devframe/templates/{counter-devtool.ts → counter-devframe.ts} +4 -4
- package/skills/devframe/templates/{spa-devtool.ts → spa-devframe.ts} +5 -5
- package/skills/devframe/templates/vite-client.ts +2 -2
- package/dist/adapters/vite.d.mts +0 -33
- package/dist/adapters/vite.mjs +0 -32
- package/dist/internal/index.d.mts +0 -16
- package/dist/internal/index.mjs +0 -3
- package/dist/utils/state.d.mts +0 -50
- package/dist/utils/state.mjs +0 -26
- package/dist/{define-Bb4zh-Dc.mjs → define-CW9gLnyG.mjs} +0 -0
- package/dist/{host-h3-9jeHcltx.mjs → host-h3-Dz8YnFgu.mjs} +1 -1
- /package/dist/{transports-DSV5_5QM.mjs → transports-BnCs4rj9.mjs} +0 -0
- /package/dist/{types-C5OVe4AC.d.mts → types-4rdUEi2R.d.mts} +0 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { createReadStream } from "node:fs";
|
|
2
|
+
import { extname, join, normalize, resolve, sep } from "pathe";
|
|
3
|
+
import { defineHandler, withBase } from "h3";
|
|
4
|
+
import { stat } from "node:fs/promises";
|
|
5
|
+
import { Readable } from "node:stream";
|
|
6
|
+
import { lookup } from "mrmime";
|
|
7
|
+
//#region src/utils/serve-static.ts
|
|
8
|
+
const HTML_EXTENSIONS = [".html", ".htm"];
|
|
9
|
+
async function statFile(abs) {
|
|
10
|
+
try {
|
|
11
|
+
const s = await stat(abs);
|
|
12
|
+
if (!s.isFile()) return null;
|
|
13
|
+
return {
|
|
14
|
+
abs,
|
|
15
|
+
size: s.size,
|
|
16
|
+
mtime: s.mtime
|
|
17
|
+
};
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function resolveTarget(absDir, urlPath, indexNames, single) {
|
|
23
|
+
let cleaned;
|
|
24
|
+
try {
|
|
25
|
+
cleaned = decodeURIComponent(urlPath || "/");
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
cleaned = cleaned.replace(/[?#].*$/, "");
|
|
30
|
+
if (cleaned.endsWith("/")) cleaned = cleaned.slice(0, -1);
|
|
31
|
+
if (cleaned.startsWith("/")) cleaned = cleaned.slice(1);
|
|
32
|
+
const abs = normalize(join(absDir, cleaned));
|
|
33
|
+
if (abs !== absDir && !abs.startsWith(absDir + sep)) return null;
|
|
34
|
+
const direct = await statFile(abs);
|
|
35
|
+
if (direct) return direct;
|
|
36
|
+
try {
|
|
37
|
+
if ((await stat(abs)).isDirectory()) for (const name of indexNames) {
|
|
38
|
+
const candidate = await statFile(join(abs, name));
|
|
39
|
+
if (candidate) return candidate;
|
|
40
|
+
}
|
|
41
|
+
} catch {}
|
|
42
|
+
if (!extname(cleaned)) for (const ext of HTML_EXTENSIONS) {
|
|
43
|
+
const candidate = await statFile(abs + ext);
|
|
44
|
+
if (candidate) return candidate;
|
|
45
|
+
}
|
|
46
|
+
const fallbackIndex = indexNames[0];
|
|
47
|
+
if (single && fallbackIndex && !/\.[a-z0-9]+$/i.test(cleaned)) {
|
|
48
|
+
const indexFile = await statFile(join(absDir, fallbackIndex));
|
|
49
|
+
if (indexFile) return indexFile;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function contentTypeFor(abs) {
|
|
54
|
+
const type = lookup(abs);
|
|
55
|
+
if (!type) return "application/octet-stream";
|
|
56
|
+
if (type === "text/html") return "text/html; charset=utf-8";
|
|
57
|
+
return type;
|
|
58
|
+
}
|
|
59
|
+
function staticHeadersFor(file) {
|
|
60
|
+
return {
|
|
61
|
+
"Content-Type": contentTypeFor(file.abs),
|
|
62
|
+
"Content-Length": String(file.size),
|
|
63
|
+
"Last-Modified": file.mtime.toUTCString(),
|
|
64
|
+
"Cache-Control": "no-store"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function applyStaticHeadersToNode(res, file) {
|
|
68
|
+
for (const [k, v] of Object.entries(staticHeadersFor(file))) res.setHeader(k, v);
|
|
69
|
+
}
|
|
70
|
+
function normalizeOptions(options) {
|
|
71
|
+
return {
|
|
72
|
+
indexNames: options?.indexNames ?? ["index.html"],
|
|
73
|
+
single: options?.single ?? true
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* h3 event handler that serves files from `dir` with SPA fallback.
|
|
78
|
+
*
|
|
79
|
+
* Drop-in replacement for `fromNodeMiddleware(sirv(dir, { dev: true, single: true }))`
|
|
80
|
+
* when the surrounding server is an h3 app — no `Cache-Control` beyond
|
|
81
|
+
* `no-store`, `Content-Type` resolved via `mrmime`, and a miss with no
|
|
82
|
+
* file extension falls back to `<dir>/index.html` so client-side routing
|
|
83
|
+
* works.
|
|
84
|
+
*/
|
|
85
|
+
function serveStaticHandler(dir, options) {
|
|
86
|
+
const absDir = resolve(dir);
|
|
87
|
+
const opts = normalizeOptions(options);
|
|
88
|
+
return defineHandler(async (event) => {
|
|
89
|
+
const method = event.req.method;
|
|
90
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
91
|
+
event.res.status = 405;
|
|
92
|
+
event.res.headers.set("Allow", "GET, HEAD");
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
const file = await resolveTarget(absDir, event.url.pathname, opts.indexNames, opts.single);
|
|
96
|
+
if (!file) {
|
|
97
|
+
event.res.status = 404;
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
for (const [k, v] of Object.entries(staticHeadersFor(file))) event.res.headers.set(k, v);
|
|
101
|
+
if (method === "HEAD") return "";
|
|
102
|
+
return Readable.toWeb(createReadStream(file.abs));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Mount {@link serveStaticHandler} on an h3 app at `base`, handling the
|
|
107
|
+
* route pattern and prefix-stripping required by h3 v2.
|
|
108
|
+
*
|
|
109
|
+
* h3 v2's `app.use(base, handler)` only matches the exact `base` path and
|
|
110
|
+
* does not strip the prefix from `event.url.pathname`. Static serving
|
|
111
|
+
* needs both subpath matching (`/base/**`) and the URL stripped so the
|
|
112
|
+
* file resolver sees paths relative to `dir` — this helper bundles both.
|
|
113
|
+
*/
|
|
114
|
+
function mountStaticHandler(app, base, dir, options) {
|
|
115
|
+
const trimmed = base.replace(/\/$/, "");
|
|
116
|
+
const handler = serveStaticHandler(dir, options);
|
|
117
|
+
if (trimmed === "") {
|
|
118
|
+
app.use("/**", handler);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
app.use(`${trimmed}/**`, withBase(trimmed, handler));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Connect/Express-style Node middleware variant of {@link serveStaticHandler}.
|
|
125
|
+
*
|
|
126
|
+
* Use when mounting onto `viteServer.middlewares.use(base, …)` or any other
|
|
127
|
+
* Connect stack — avoids forcing the host package to depend on h3 just to
|
|
128
|
+
* adapt an event handler back into Node middleware.
|
|
129
|
+
*/
|
|
130
|
+
function serveStaticNodeMiddleware(dir, options) {
|
|
131
|
+
const absDir = resolve(dir);
|
|
132
|
+
const opts = normalizeOptions(options);
|
|
133
|
+
return (req, res, next) => {
|
|
134
|
+
(async () => {
|
|
135
|
+
const method = req.method;
|
|
136
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
137
|
+
if (next) {
|
|
138
|
+
next();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
res.statusCode = 405;
|
|
142
|
+
res.setHeader("Allow", "GET, HEAD");
|
|
143
|
+
res.end();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const file = await resolveTarget(absDir, req.url ?? "/", opts.indexNames, opts.single);
|
|
147
|
+
if (!file) {
|
|
148
|
+
if (next) {
|
|
149
|
+
next();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
res.statusCode = 404;
|
|
153
|
+
res.end();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
applyStaticHeadersToNode(res, file);
|
|
157
|
+
if (method === "HEAD") {
|
|
158
|
+
res.end();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
createReadStream(file.abs).pipe(res);
|
|
162
|
+
})().catch((err) => {
|
|
163
|
+
if (next) {
|
|
164
|
+
next(err instanceof Error ? err : new Error(String(err)));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
res.statusCode = 500;
|
|
168
|
+
res.end();
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { mountStaticHandler, serveStaticHandler, serveStaticNodeMiddleware };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as ImmutableArray, F as SharedStateEvents, I as SharedStateOptions, L as SharedStatePatch, M as ImmutableObject, N as ImmutableSet, P as SharedState, R as createSharedState, j as ImmutableMap, k as Immutable } from "../
|
|
1
|
+
import { A as ImmutableArray, F as SharedStateEvents, I as SharedStateOptions, L as SharedStatePatch, M as ImmutableObject, N as ImmutableSet, P as SharedState, R as createSharedState, j as ImmutableMap, k as Immutable } from "../devframe-R5Ex5K5L.mjs";
|
|
2
2
|
export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, SharedStatePatch, createSharedState };
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { nanoid } from "./nanoid.mjs";
|
|
3
|
-
import { applyPatches, enablePatches, produce, produceWithPatches } from "immer";
|
|
4
|
-
//#region src/utils/shared-state.ts
|
|
5
|
-
function createSharedState(options) {
|
|
6
|
-
const { enablePatches: enablePatches$1 = false } = options;
|
|
7
|
-
const events = createEventEmitter();
|
|
8
|
-
let state = options.initialValue;
|
|
9
|
-
const syncIds = /* @__PURE__ */ new Set();
|
|
10
|
-
return {
|
|
11
|
-
on: events.on,
|
|
12
|
-
value: () => state,
|
|
13
|
-
patch: (patches, syncId = nanoid()) => {
|
|
14
|
-
if (syncIds.has(syncId)) return;
|
|
15
|
-
enablePatches();
|
|
16
|
-
state = applyPatches(state, patches);
|
|
17
|
-
syncIds.add(syncId);
|
|
18
|
-
events.emit("updated", state, void 0, syncId);
|
|
19
|
-
},
|
|
20
|
-
mutate: (fn, syncId = nanoid()) => {
|
|
21
|
-
if (syncIds.has(syncId)) return;
|
|
22
|
-
syncIds.add(syncId);
|
|
23
|
-
if (enablePatches$1) {
|
|
24
|
-
const [newState, patches] = produceWithPatches(state, fn);
|
|
25
|
-
state = newState;
|
|
26
|
-
events.emit("updated", state, patches, syncId);
|
|
27
|
-
} else {
|
|
28
|
-
state = produce(state, fn);
|
|
29
|
-
events.emit("updated", state, void 0, syncId);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
syncIds
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
1
|
+
import { t as createSharedState } from "../shared-state-q9-1EOSX.mjs";
|
|
36
2
|
export { createSharedState };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as StreamErrorPayload, D as createStreamReader, E as StreamSinkEvents, O as createStreamSink, S as CreateStreamSinkOptions, T as StreamSink, b as BufferedChunk, w as StreamReader, x as CreateStreamReaderOptions } from "../
|
|
1
|
+
import { C as StreamErrorPayload, D as createStreamReader, E as StreamSinkEvents, O as createStreamSink, S as CreateStreamSinkOptions, T as StreamSink, b as BufferedChunk, w as StreamReader, x as CreateStreamReaderOptions } from "../devframe-R5Ex5K5L.mjs";
|
|
2
2
|
export { BufferedChunk, CreateStreamReaderOptions, CreateStreamSinkOptions, StreamErrorPayload, StreamReader, StreamSink, StreamSinkEvents, createStreamReader, createStreamSink };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/utils/structured-clone.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Serialize a structured-cloneable value (`Map`, `Set`, `Date`, `BigInt`,
|
|
4
|
+
* cycles, class instances, …) into a JSON-safe records array.
|
|
5
|
+
*/
|
|
6
|
+
declare function structuredCloneSerialize(value: unknown): unknown[];
|
|
7
|
+
/**
|
|
8
|
+
* Inverse of {@link structuredCloneSerialize}.
|
|
9
|
+
*/
|
|
10
|
+
declare function structuredCloneDeserialize<T = unknown>(value: unknown[]): T;
|
|
11
|
+
/**
|
|
12
|
+
* Serialize a structured-cloneable value to a single string. Equivalent
|
|
13
|
+
* to `JSON.stringify(structuredCloneSerialize(value))`.
|
|
14
|
+
*/
|
|
15
|
+
declare function structuredCloneStringify(value: unknown): string;
|
|
16
|
+
/**
|
|
17
|
+
* Inverse of {@link structuredCloneStringify}.
|
|
18
|
+
*/
|
|
19
|
+
declare function structuredCloneParse<T = unknown>(value: string): T;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { structuredCloneDeserialize, structuredCloneParse, structuredCloneSerialize, structuredCloneStringify };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { i as structuredCloneStringify, n as structuredCloneParse, r as structuredCloneSerialize, t as structuredCloneDeserialize } from "../structured-clone-CD2l4fI3.mjs";
|
|
2
|
+
export { structuredCloneDeserialize, structuredCloneParse, structuredCloneSerialize, structuredCloneStringify };
|
package/dist/utils/when.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region ../../node_modules/.pnpm/whenexpr@0.1.2/node_modules/whenexpr/dist/index.d.mts
|
|
2
2
|
//#region src/paths.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Union of valid context paths for `T` — both flat keys (`keyof T`) and
|
|
@@ -325,50 +325,8 @@ type ValidateExpression<S extends string, T> = string extends S ? S : Tokenize<S
|
|
|
325
325
|
* defineCommand({ name: 'x', title: 'X', when: 'typo' })
|
|
326
326
|
* // ^^^^^ type error
|
|
327
327
|
*/
|
|
328
|
-
type WhenExpression<T, S extends string> = S & ValidateExpression<S, T>; //#endregion
|
|
328
|
+
type WhenExpression$1<T, S extends string> = S & ValidateExpression<S, T>; //#endregion
|
|
329
329
|
//#region src/index.d.ts
|
|
330
|
-
interface EvaluateOptions {
|
|
331
|
-
/**
|
|
332
|
-
* If `true`, throw when the expression references a context key that does
|
|
333
|
-
* not exist. Defaults to `false`, where unknown keys evaluate to `undefined`.
|
|
334
|
-
*/
|
|
335
|
-
strict?: boolean;
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Evaluate a when-clause expression string against a context object.
|
|
339
|
-
* Equivalent to `evaluate(parse(expression), ctx, options)`.
|
|
340
|
-
*
|
|
341
|
-
* Supports a JS-expression subset:
|
|
342
|
-
* - Literals: booleans, numbers, strings (quoted with `"` or `'`)
|
|
343
|
-
* - Identifiers: bare keys, including namespaced (`vite.mode`, `vite:buildMode`)
|
|
344
|
-
* - Logical: `&&`, `||`, `!`
|
|
345
|
-
* - Equality: `==`, `!=` (string comparison, bare identifier RHS treated as string),
|
|
346
|
-
* `===`, `!==` (JS strict equality with full expression RHS)
|
|
347
|
-
* - Relational: `<`, `<=`, `>`, `>=`
|
|
348
|
-
* - Arithmetic: `+`, `-`, `*`, `/`, `%`, unary `-` / `+`
|
|
349
|
-
* - Grouping: `(` … `)`
|
|
350
|
-
*
|
|
351
|
-
* When `ctx` has a specific type with known keys, the expression string is
|
|
352
|
-
* **statically validated** — unknown context keys and syntax errors surface
|
|
353
|
-
* as TypeScript errors at the call site. Pass `ctx` typed as
|
|
354
|
-
* `Record<string, unknown>`, or the expression as `string`, to opt out of
|
|
355
|
-
* static checking (e.g. for dynamic expressions).
|
|
356
|
-
*
|
|
357
|
-
* With `{ strict: true }`, referencing an unknown context key at runtime
|
|
358
|
-
* throws. Short-circuit evaluation still applies — keys not reached are not
|
|
359
|
-
* checked.
|
|
360
|
-
*/
|
|
361
|
-
declare function evaluateWhen<T extends object, const E extends string>(expression: E & ValidateExpression<E, T>, ctx: T, options?: EvaluateOptions): boolean;
|
|
362
|
-
/**
|
|
363
|
-
* Resolve a context value by key. Supports namespaced keys with `.` or `:` separators.
|
|
364
|
-
*
|
|
365
|
-
* Lookup order:
|
|
366
|
-
* 1. Exact match — `ctx['plugin.mode']` or `ctx['plugin:mode']`
|
|
367
|
-
* 2. Nested path — e.g. `plugin.mode` falls back to `ctx.plugin?.mode`
|
|
368
|
-
*
|
|
369
|
-
* Returns `undefined` for unknown keys.
|
|
370
|
-
*/
|
|
371
|
-
declare function resolveContextValue<T extends Record<string, unknown>>(key: string, ctx: T): unknown; //#endregion
|
|
372
330
|
//#endregion
|
|
373
331
|
//#region src/utils/when.d.ts
|
|
374
332
|
/**
|
|
@@ -383,11 +341,9 @@ declare function resolveContextValue<T extends Record<string, unknown>>(key: str
|
|
|
383
341
|
* Plugins can add namespaced variables using dot or colon separators:
|
|
384
342
|
* - `vite.mode`, `vite:mode` — stored as `{ 'vite.mode': 'development' }` or nested `{ vite: { mode: 'development' } }`
|
|
385
343
|
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* (`===`/`!==`), relational (`<`/`<=`/`>`/`>=`), arithmetic (`+ - * / %`), and
|
|
390
|
-
* number/string literals are supported.
|
|
344
|
+
* Supported operators: `!`, `==`, `!=`, `===`, `!==`, `<`, `<=`, `>`, `>=`,
|
|
345
|
+
* `&&`, `||`, `+`, `-`, `*`, `/`, `%`. Parentheses, number and string literals
|
|
346
|
+
* are also supported.
|
|
391
347
|
*/
|
|
392
348
|
interface WhenContext {
|
|
393
349
|
clientType: 'embedded' | 'standalone';
|
|
@@ -397,5 +353,32 @@ interface WhenContext {
|
|
|
397
353
|
/** Allow custom context variables from plugins */
|
|
398
354
|
[key: string]: unknown;
|
|
399
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* A statically-validated `when` expression string. Used inside `define*`
|
|
358
|
+
* helpers to surface unknown context keys and syntax errors as TypeScript
|
|
359
|
+
* errors at the call site.
|
|
360
|
+
*/
|
|
361
|
+
type WhenExpression<T, S extends string> = WhenExpression$1<T, S>;
|
|
362
|
+
/** Options for `evaluateWhen`. */
|
|
363
|
+
interface EvaluateWhenOptions {
|
|
364
|
+
/**
|
|
365
|
+
* Throw when the expression references a context key that does not exist.
|
|
366
|
+
*
|
|
367
|
+
* @default false
|
|
368
|
+
*/
|
|
369
|
+
strict?: boolean;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Evaluate a when-clause expression string against a context object.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* evaluateWhen('dockOpen && clientType == embedded', ctx)
|
|
376
|
+
*/
|
|
377
|
+
declare function evaluateWhen<T extends object, const E extends string>(expression: E & WhenExpression$1<T, E>, context: T, options?: EvaluateWhenOptions): boolean;
|
|
378
|
+
/**
|
|
379
|
+
* Resolve a context value by key. Supports namespaced keys with `.` or `:`
|
|
380
|
+
* separators. Returns `undefined` for unknown keys.
|
|
381
|
+
*/
|
|
382
|
+
declare function resolveContextValue<T extends Record<string, unknown>>(key: string, context: T): unknown;
|
|
400
383
|
//#endregion
|
|
401
|
-
export { WhenContext, type WhenExpression, evaluateWhen, resolveContextValue };
|
|
384
|
+
export { EvaluateWhenOptions, WhenContext, type WhenExpression, evaluateWhen, resolveContextValue };
|
package/dist/utils/when.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region ../../node_modules/.pnpm/whenexpr@0.1.2/node_modules/whenexpr/dist/index.mjs
|
|
2
2
|
const OPS = [
|
|
3
3
|
"===",
|
|
4
4
|
"!==",
|
|
@@ -369,7 +369,7 @@ function runBinary(node, ctx, strict) {
|
|
|
369
369
|
* throws. Short-circuit evaluation still applies — keys not reached are not
|
|
370
370
|
* checked.
|
|
371
371
|
*/
|
|
372
|
-
function evaluateWhen(expression, ctx, options) {
|
|
372
|
+
function evaluateWhen$1(expression, ctx, options) {
|
|
373
373
|
return evaluate(parse(expression), ctx, options);
|
|
374
374
|
}
|
|
375
375
|
/**
|
|
@@ -381,7 +381,7 @@ function evaluateWhen(expression, ctx, options) {
|
|
|
381
381
|
*
|
|
382
382
|
* Returns `undefined` for unknown keys.
|
|
383
383
|
*/
|
|
384
|
-
function resolveContextValue(key, ctx) {
|
|
384
|
+
function resolveContextValue$1(key, ctx) {
|
|
385
385
|
return resolve(key, ctx).value;
|
|
386
386
|
}
|
|
387
387
|
function lookup(key, ctx, strict) {
|
|
@@ -421,4 +421,22 @@ function resolve(key, ctx) {
|
|
|
421
421
|
};
|
|
422
422
|
}
|
|
423
423
|
//#endregion
|
|
424
|
+
//#region src/utils/when.ts
|
|
425
|
+
/**
|
|
426
|
+
* Evaluate a when-clause expression string against a context object.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* evaluateWhen('dockOpen && clientType == embedded', ctx)
|
|
430
|
+
*/
|
|
431
|
+
function evaluateWhen(expression, context, options) {
|
|
432
|
+
return evaluateWhen$1(expression, context, options);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Resolve a context value by key. Supports namespaced keys with `.` or `:`
|
|
436
|
+
* separators. Returns `undefined` for unknown keys.
|
|
437
|
+
*/
|
|
438
|
+
function resolveContextValue(key, context) {
|
|
439
|
+
return resolveContextValue$1(key, context);
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
424
442
|
export { evaluateWhen, resolveContextValue };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as RpcFunctionDefinitionAny } from "./types-
|
|
1
|
+
import { g as RpcFunctionDefinitionAny } from "./types-4rdUEi2R.mjs";
|
|
2
2
|
import { BirpcGroup, ChannelOptions } from "birpc";
|
|
3
3
|
import { ServerOptions } from "node:https";
|
|
4
4
|
import { WebSocket, WebSocketServer } from "ws";
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devframe",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "Framework for building generic DevTools",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://github.com/
|
|
8
|
+
"homepage": "https://github.com/devframes/devframe#readme",
|
|
9
9
|
"repository": {
|
|
10
|
-
"directory": "
|
|
10
|
+
"directory": "packages/devframe",
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/
|
|
12
|
+
"url": "git+https://github.com/devframes/devframe.git"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://github.com/
|
|
14
|
+
"bugs": "https://github.com/devframes/devframe/issues",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"devtools",
|
|
17
17
|
"rpc",
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
"./adapters/dev": "./dist/adapters/dev.mjs",
|
|
26
26
|
"./adapters/embedded": "./dist/adapters/embedded.mjs",
|
|
27
27
|
"./adapters/mcp": "./dist/adapters/mcp.mjs",
|
|
28
|
-
"./adapters/vite": "./dist/adapters/vite.mjs",
|
|
29
28
|
"./client": "./dist/client/index.mjs",
|
|
30
29
|
"./constants": "./dist/constants.mjs",
|
|
31
|
-
"./
|
|
30
|
+
"./helpers/vite": "./dist/helpers/vite.mjs",
|
|
32
31
|
"./node": "./dist/node/index.mjs",
|
|
32
|
+
"./node/auth": "./dist/node/auth.mjs",
|
|
33
|
+
"./node/internal": "./dist/node/internal.mjs",
|
|
33
34
|
"./recipes/open-helpers": "./dist/recipes/open-helpers.mjs",
|
|
34
35
|
"./rpc": "./dist/rpc/index.mjs",
|
|
35
36
|
"./rpc/client": "./dist/rpc/client.mjs",
|
|
@@ -37,13 +38,18 @@
|
|
|
37
38
|
"./rpc/transports/ws-client": "./dist/rpc/transports/ws-client.mjs",
|
|
38
39
|
"./rpc/transports/ws-server": "./dist/rpc/transports/ws-server.mjs",
|
|
39
40
|
"./types": "./dist/types/index.mjs",
|
|
41
|
+
"./utils/colors": "./dist/utils/colors.mjs",
|
|
40
42
|
"./utils/events": "./dist/utils/events.mjs",
|
|
43
|
+
"./utils/hash": "./dist/utils/hash.mjs",
|
|
41
44
|
"./utils/human-id": "./dist/utils/human-id.mjs",
|
|
45
|
+
"./utils/launch-editor": "./dist/utils/launch-editor.mjs",
|
|
42
46
|
"./utils/nanoid": "./dist/utils/nanoid.mjs",
|
|
47
|
+
"./utils/open": "./dist/utils/open.mjs",
|
|
43
48
|
"./utils/promise": "./dist/utils/promise.mjs",
|
|
49
|
+
"./utils/serve-static": "./dist/utils/serve-static.mjs",
|
|
44
50
|
"./utils/shared-state": "./dist/utils/shared-state.mjs",
|
|
45
|
-
"./utils/state": "./dist/utils/state.mjs",
|
|
46
51
|
"./utils/streaming-channel": "./dist/utils/streaming-channel.mjs",
|
|
52
|
+
"./utils/structured-clone": "./dist/utils/structured-clone.mjs",
|
|
47
53
|
"./utils/when": "./dist/utils/when.mjs",
|
|
48
54
|
"./package.json": "./package.json"
|
|
49
55
|
},
|
|
@@ -62,43 +68,57 @@
|
|
|
62
68
|
},
|
|
63
69
|
"dependencies": {
|
|
64
70
|
"@valibot/to-json-schema": "^1.7.0",
|
|
65
|
-
"ansis": "^4.2.0",
|
|
66
71
|
"birpc": "^4.0.0",
|
|
67
72
|
"cac": "^7.0.0",
|
|
68
|
-
"h3": "
|
|
69
|
-
"immer": "^11.1.7",
|
|
70
|
-
"launch-editor": "^2.13.2",
|
|
73
|
+
"h3": "2.0.1-rc.22",
|
|
71
74
|
"logs-sdk": "^0.0.6",
|
|
72
|
-
"
|
|
75
|
+
"mrmime": "^2.0.1",
|
|
73
76
|
"pathe": "^2.0.3",
|
|
74
|
-
"sirv": "^3.0.2",
|
|
75
|
-
"structured-clone-es": "^2.0.0",
|
|
76
77
|
"valibot": "^1.4.0",
|
|
77
78
|
"ws": "^8.20.0"
|
|
78
79
|
},
|
|
79
80
|
"devDependencies": {
|
|
80
81
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
82
|
+
"ansis": "^4.3.0",
|
|
83
|
+
"get-port-please": "^3.2.0",
|
|
84
|
+
"human-id": "^4.1.3",
|
|
85
|
+
"immer": "^11.1.8",
|
|
81
86
|
"launch-editor": "^2.13.2",
|
|
82
|
-
"
|
|
87
|
+
"mlly": "^1.8.2",
|
|
88
|
+
"obug": "^2.1.1",
|
|
89
|
+
"ohash": "^2.0.11",
|
|
90
|
+
"open": "^11.0.0",
|
|
91
|
+
"p-limit": "^7.3.0",
|
|
92
|
+
"perfect-debounce": "^2.1.0",
|
|
93
|
+
"structured-clone-es": "^2.0.0",
|
|
94
|
+
"tsdown": "^0.22.0",
|
|
95
|
+
"ua-parser-modern": "^0.1.1",
|
|
83
96
|
"whenexpr": "^0.1.2"
|
|
84
97
|
},
|
|
85
98
|
"inlinedDependencies": {
|
|
99
|
+
"ansis": "4.3.0",
|
|
86
100
|
"bundle-name": "4.1.0",
|
|
87
|
-
"default-browser": "5.
|
|
101
|
+
"default-browser": "5.5.0",
|
|
88
102
|
"default-browser-id": "5.0.1",
|
|
89
103
|
"define-lazy-prop": "3.0.0",
|
|
90
104
|
"get-port-please": "3.2.0",
|
|
91
105
|
"human-id": "4.1.3",
|
|
106
|
+
"immer": "11.1.8",
|
|
92
107
|
"is-docker": "3.0.0",
|
|
93
108
|
"is-in-ssh": "1.0.0",
|
|
94
109
|
"is-inside-container": "1.0.0",
|
|
95
|
-
"is-wsl": "3.1.
|
|
110
|
+
"is-wsl": "3.1.1",
|
|
111
|
+
"launch-editor": "2.13.2",
|
|
96
112
|
"obug": "2.1.1",
|
|
113
|
+
"ohash": "2.0.11",
|
|
97
114
|
"open": "11.0.0",
|
|
98
115
|
"p-limit": "7.3.0",
|
|
99
116
|
"perfect-debounce": "2.1.0",
|
|
117
|
+
"picocolors": "1.1.1",
|
|
100
118
|
"powershell-utils": "0.1.0",
|
|
101
119
|
"run-applescript": "7.1.0",
|
|
120
|
+
"shell-quote": "1.8.3",
|
|
121
|
+
"structured-clone-es": "2.0.0",
|
|
102
122
|
"ua-parser-modern": "0.1.1",
|
|
103
123
|
"whenexpr": "0.1.2",
|
|
104
124
|
"wsl-utils": "0.3.1",
|