devframe 0.0.0 → 0.1.17
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/LICENSE.md +21 -0
- package/README.md +62 -0
- package/dist/_shared-Bxa2_kq7.mjs +20 -0
- package/dist/adapters/build.d.mts +37 -0
- package/dist/adapters/build.mjs +68 -0
- package/dist/adapters/cli.d.mts +35 -0
- package/dist/adapters/cli.mjs +357 -0
- package/dist/adapters/embedded.d.mts +19 -0
- package/dist/adapters/embedded.mjs +15 -0
- package/dist/adapters/kit.d.mts +23 -0
- package/dist/adapters/kit.mjs +16 -0
- package/dist/adapters/mcp.d.mts +39 -0
- package/dist/adapters/mcp.mjs +278 -0
- package/dist/adapters/vite.d.mts +32 -0
- package/dist/adapters/vite.mjs +31 -0
- package/dist/client/index.d.mts +228 -0
- package/dist/client/index.mjs +2 -0
- package/dist/client-CsR1_h3o.mjs +1569 -0
- package/dist/constants.d.mts +20 -0
- package/dist/constants.mjs +34 -0
- package/dist/context-xQo1FcxX.mjs +6827 -0
- package/dist/define-CW9gLnyG.mjs +11 -0
- package/dist/devtool-CHT-4_OU.d.mts +1233 -0
- package/dist/helpers/nuxt/index.d.mts +46 -0
- package/dist/helpers/nuxt/index.mjs +58 -0
- package/dist/helpers/nuxt/runtime/plugin.client.d.mts +8 -0
- package/dist/helpers/nuxt/runtime/plugin.client.mjs +12 -0
- package/dist/human-id-CHS0s28X.mjs +844 -0
- package/dist/immer-DEqg5kOd.mjs +894 -0
- package/dist/index-Cei8vVcd.d.mts +140 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +2 -0
- package/dist/main-BJD9t8dk.mjs +601 -0
- package/dist/node/index.d.mts +393 -0
- package/dist/node/index.mjs +69 -0
- package/dist/open-BMO2_-wC.mjs +533 -0
- package/dist/recipes/open-helpers.d.mts +108 -0
- package/dist/recipes/open-helpers.mjs +69 -0
- package/dist/rpc/client.d.mts +9 -0
- package/dist/rpc/client.mjs +13 -0
- package/dist/rpc/index.d.mts +3 -0
- package/dist/rpc/index.mjs +4 -0
- package/dist/rpc/server.d.mts +8 -0
- package/dist/rpc/server.mjs +10 -0
- package/dist/rpc/transports/ws-client.d.mts +2 -0
- package/dist/rpc/transports/ws-client.mjs +58 -0
- package/dist/rpc/transports/ws-server.d.mts +2 -0
- package/dist/rpc/transports/ws-server.mjs +73 -0
- package/dist/rpc-hbRk8qtt.mjs +456 -0
- package/dist/serialization-CWcWE7x7.mjs +112 -0
- package/dist/server-DkJ2-s0Y.mjs +49 -0
- package/dist/src-DIKqQIjp.mjs +85 -0
- package/dist/static-dump-DwFfj4U_.mjs +97 -0
- package/dist/transports-4bqw6Fqg.mjs +15 -0
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.mjs +6 -0
- package/dist/types-BkyzI9r4.d.mts +273 -0
- package/dist/utils/events.d.mts +9 -0
- package/dist/utils/events.mjs +40 -0
- package/dist/utils/human-id.d.mts +10 -0
- package/dist/utils/human-id.mjs +3 -0
- package/dist/utils/nanoid.d.mts +4 -0
- package/dist/utils/nanoid.mjs +10 -0
- package/dist/utils/promise.d.mts +8 -0
- package/dist/utils/promise.mjs +15 -0
- package/dist/utils/shared-state.d.mts +2 -0
- package/dist/utils/shared-state.mjs +36 -0
- package/dist/utils/state.d.mts +49 -0
- package/dist/utils/state.mjs +26 -0
- package/dist/utils/when.d.mts +2 -0
- package/dist/utils/when.mjs +424 -0
- package/dist/when-aBBXAEh5.d.mts +401 -0
- package/dist/ws-client-CDGmViwt.d.mts +26 -0
- package/dist/ws-server-Cu8tmZcF.d.mts +49 -0
- package/package.json +116 -8
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { n as defineRpcFunction } from "../define-CW9gLnyG.mjs";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
//#region src/recipes/open-helpers.ts
|
|
4
|
+
/**
|
|
5
|
+
* Prebuilt RPC action that opens a file in the user's configured editor
|
|
6
|
+
* via [`launch-editor`](https://www.npmjs.com/package/launch-editor).
|
|
7
|
+
*
|
|
8
|
+
* Registered name: `devframe:open-in-editor`.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { openInEditor } from 'devframe/recipes/open-helpers'
|
|
12
|
+
*
|
|
13
|
+
* defineDevtool({
|
|
14
|
+
* id: 'my-tool',
|
|
15
|
+
* name: 'My Tool',
|
|
16
|
+
* setup(ctx) {
|
|
17
|
+
* ctx.rpc.register(openInEditor)
|
|
18
|
+
* },
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Requires `launch-editor` to be installed by the consumer (declared as
|
|
23
|
+
* an optional peer dependency on devframe).
|
|
24
|
+
*/
|
|
25
|
+
const openInEditor = defineRpcFunction({
|
|
26
|
+
name: "devframe:open-in-editor",
|
|
27
|
+
type: "action",
|
|
28
|
+
args: [v.string()],
|
|
29
|
+
returns: v.void(),
|
|
30
|
+
async handler(filename) {
|
|
31
|
+
const mod = await import("launch-editor");
|
|
32
|
+
(mod.default ?? mod)(filename);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Prebuilt RPC action that reveals a path in the OS file explorer via
|
|
37
|
+
* [`open`](https://www.npmjs.com/package/open).
|
|
38
|
+
*
|
|
39
|
+
* Registered name: `devframe:open-in-finder`.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { openInFinder } from 'devframe/recipes/open-helpers'
|
|
43
|
+
*
|
|
44
|
+
* ctx.rpc.register(openInFinder)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
const openInFinder = defineRpcFunction({
|
|
48
|
+
name: "devframe:open-in-finder",
|
|
49
|
+
type: "action",
|
|
50
|
+
args: [v.string()],
|
|
51
|
+
returns: v.void(),
|
|
52
|
+
async handler(path) {
|
|
53
|
+
const { default: open } = await import("../open-BMO2_-wC.mjs");
|
|
54
|
+
await open(path);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Convenience array bundling both helpers so callers can register them
|
|
59
|
+
* in a single `forEach`.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { openHelpers } from 'devframe/recipes/open-helpers'
|
|
63
|
+
*
|
|
64
|
+
* openHelpers.forEach(fn => ctx.rpc.register(fn))
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
const openHelpers = [openInEditor, openInFinder];
|
|
68
|
+
//#endregion
|
|
69
|
+
export { openHelpers, openInEditor, openInFinder };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BirpcOptions, BirpcReturn, ChannelOptions } from "birpc";
|
|
2
|
+
|
|
3
|
+
//#region src/rpc/client.d.ts
|
|
4
|
+
declare function createRpcClient<ServerFunctions extends object = Record<string, never>, ClientFunctions extends object = Record<string, never>>(functions: ClientFunctions, options: {
|
|
5
|
+
channel: ChannelOptions;
|
|
6
|
+
rpcOptions?: Partial<BirpcOptions<ServerFunctions, ClientFunctions, boolean>>;
|
|
7
|
+
}): BirpcReturn<ServerFunctions, ClientFunctions, false>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { createRpcClient };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createBirpc } from "birpc";
|
|
2
|
+
//#region src/rpc/client.ts
|
|
3
|
+
function createRpcClient(functions, options) {
|
|
4
|
+
const { channel, rpcOptions = {} } = options;
|
|
5
|
+
return createBirpc(functions, {
|
|
6
|
+
...channel,
|
|
7
|
+
timeout: -1,
|
|
8
|
+
...rpcOptions,
|
|
9
|
+
proxify: false
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { createRpcClient };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { _ as RpcCacheManager, a as structuredCloneDeserialize, c as structuredCloneStringify, d as createClientFromDump, f as dumpFunctions, g as RpcFunctionsCollectorBase, h as defineRpcFunction, i as strictJsonStringify, l as getRpcHandler, m as createDefineWrapperWithContext, n as validateDefinitions, o as structuredCloneParse, p as getDefinitionsWithDumps, r as STRUCTURED_CLONE_PREFIX, s as structuredCloneSerialize, t as validateDefinition, u as getRpcResolvedSetupResult, v as RpcCacheOptions } from "../index-Cei8vVcd.mjs";
|
|
2
|
+
import { C as RpcReturnSchema, S as RpcFunctionsCollector, _ as RpcFunctionDefinitionAnyWithContext, a as RpcDefinitionsFilter, b as RpcFunctionSetupResult, c as RpcDumpClientOptions, d as RpcDumpGetter, f as RpcDumpRecord, g as RpcFunctionDefinitionAny, h as RpcFunctionDefinition, i as RpcArgsSchema, l as RpcDumpCollectionOptions, m as RpcFunctionAgentOptions, n as BirpcReturn, o as RpcDefinitionsToFunctions, p as RpcDumpStore, r as EntriesToObject, s as RpcDump, t as BirpcFn, u as RpcDumpDefinition, v as RpcFunctionDefinitionBase, w as Thenable, x as RpcFunctionType, y as RpcFunctionDefinitionToFunction } from "../types-BkyzI9r4.mjs";
|
|
3
|
+
export { BirpcFn, BirpcReturn, EntriesToObject, RpcArgsSchema, RpcCacheManager, RpcCacheOptions, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcDump, RpcDumpClientOptions, RpcDumpCollectionOptions, RpcDumpDefinition, RpcDumpGetter, RpcDumpRecord, RpcDumpStore, RpcFunctionAgentOptions, RpcFunctionDefinition, RpcFunctionDefinitionAny, RpcFunctionDefinitionAnyWithContext, RpcFunctionDefinitionBase, RpcFunctionDefinitionToFunction, RpcFunctionSetupResult, RpcFunctionType, RpcFunctionsCollector, RpcFunctionsCollectorBase, RpcReturnSchema, STRUCTURED_CLONE_PREFIX, Thenable, createClientFromDump, createDefineWrapperWithContext, defineRpcFunction, dumpFunctions, getDefinitionsWithDumps, getRpcHandler, getRpcResolvedSetupResult, strictJsonStringify, structuredCloneDeserialize, structuredCloneParse, structuredCloneSerialize, structuredCloneStringify, validateDefinition, validateDefinitions };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { a as validateDefinitions, c as getRpcResolvedSetupResult, i as validateDefinition, l as RpcCacheManager, n as dumpFunctions, o as RpcFunctionsCollectorBase, r as getDefinitionsWithDumps, s as getRpcHandler, t as createClientFromDump } from "../rpc-hbRk8qtt.mjs";
|
|
2
|
+
import { a as structuredCloneSerialize, i as structuredCloneParse, n as strictJsonStringify, o as structuredCloneStringify, r as structuredCloneDeserialize, t as STRUCTURED_CLONE_PREFIX } from "../serialization-CWcWE7x7.mjs";
|
|
3
|
+
import { n as defineRpcFunction, t as createDefineWrapperWithContext } from "../define-CW9gLnyG.mjs";
|
|
4
|
+
export { RpcCacheManager, RpcFunctionsCollectorBase, STRUCTURED_CLONE_PREFIX, createClientFromDump, createDefineWrapperWithContext, defineRpcFunction, dumpFunctions, getDefinitionsWithDumps, getRpcHandler, getRpcResolvedSetupResult, strictJsonStringify, structuredCloneDeserialize, structuredCloneParse, structuredCloneSerialize, structuredCloneStringify, validateDefinition, validateDefinitions };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BirpcGroup, EventOptions } from "birpc";
|
|
2
|
+
|
|
3
|
+
//#region src/rpc/server.d.ts
|
|
4
|
+
declare function createRpcServer<ClientFunctions extends object = Record<string, never>, ServerFunctions extends object = Record<string, never>>(functions: ServerFunctions, options?: {
|
|
5
|
+
rpcOptions?: EventOptions<ClientFunctions, ServerFunctions, false>;
|
|
6
|
+
}): BirpcGroup<ClientFunctions, ServerFunctions, false>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { createRpcServer };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createBirpcGroup } from "birpc";
|
|
2
|
+
//#region src/rpc/server.ts
|
|
3
|
+
function createRpcServer(functions, options = {}) {
|
|
4
|
+
return createBirpcGroup(functions, [], {
|
|
5
|
+
...options.rpcOptions,
|
|
6
|
+
proxify: false
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { createRpcServer };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { i as structuredCloneParse, n as strictJsonStringify, o as structuredCloneStringify } from "../../serialization-CWcWE7x7.mjs";
|
|
2
|
+
//#region src/rpc/transports/ws-client.ts
|
|
3
|
+
function NOOP() {}
|
|
4
|
+
const EMPTY_DEFS = /* @__PURE__ */ new Map();
|
|
5
|
+
/**
|
|
6
|
+
* Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
|
|
7
|
+
* Pass the result straight to `createRpcClient`'s `channel` option.
|
|
8
|
+
*/
|
|
9
|
+
function createWsRpcChannel(options) {
|
|
10
|
+
let url = options.url;
|
|
11
|
+
if (options.authToken) url = `${url}?vite_devtools_auth_token=${encodeURIComponent(options.authToken)}`;
|
|
12
|
+
const ws = new WebSocket(url);
|
|
13
|
+
const { onConnected = NOOP, onError = NOOP, onDisconnected = NOOP, definitions = EMPTY_DEFS } = options;
|
|
14
|
+
ws.addEventListener("open", (e) => {
|
|
15
|
+
onConnected(e);
|
|
16
|
+
});
|
|
17
|
+
ws.addEventListener("error", (e) => {
|
|
18
|
+
onError(e instanceof Error ? e : new Error(e.type));
|
|
19
|
+
});
|
|
20
|
+
ws.addEventListener("close", (e) => {
|
|
21
|
+
onDisconnected(e);
|
|
22
|
+
});
|
|
23
|
+
const pendingRequestMethods = /* @__PURE__ */ new Map();
|
|
24
|
+
return {
|
|
25
|
+
on: (handler) => {
|
|
26
|
+
ws.addEventListener("message", (e) => {
|
|
27
|
+
handler(e.data);
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
post: (data) => {
|
|
31
|
+
if (ws.readyState === WebSocket.OPEN) ws.send(data);
|
|
32
|
+
else {
|
|
33
|
+
function handler() {
|
|
34
|
+
ws.send(data);
|
|
35
|
+
ws.removeEventListener("open", handler);
|
|
36
|
+
}
|
|
37
|
+
ws.addEventListener("open", handler);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
serialize: (msg) => {
|
|
41
|
+
let method;
|
|
42
|
+
if (msg.t === "q") method = msg.m;
|
|
43
|
+
else {
|
|
44
|
+
method = pendingRequestMethods.get(msg.i);
|
|
45
|
+
pendingRequestMethods.delete(msg.i);
|
|
46
|
+
}
|
|
47
|
+
if (!!method && definitions.get(method)?.jsonSerializable === true) return strictJsonStringify(msg, method ?? "");
|
|
48
|
+
return `s:${structuredCloneStringify(msg)}`;
|
|
49
|
+
},
|
|
50
|
+
deserialize: (raw) => {
|
|
51
|
+
const msg = raw.startsWith("s:") ? structuredCloneParse(raw.slice(2)) : JSON.parse(raw);
|
|
52
|
+
if (msg.t === "q" && msg.i && msg.m) pendingRequestMethods.set(msg.i, msg.m);
|
|
53
|
+
return msg;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { createWsRpcChannel };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { i as structuredCloneParse, n as strictJsonStringify, o as structuredCloneStringify } from "../../serialization-CWcWE7x7.mjs";
|
|
2
|
+
import { createServer } from "node:https";
|
|
3
|
+
import { WebSocketServer } from "ws";
|
|
4
|
+
//#region src/rpc/transports/ws-server.ts
|
|
5
|
+
let sessionId = 0;
|
|
6
|
+
const EMPTY_DEFS = /* @__PURE__ */ new Map();
|
|
7
|
+
function NOOP() {}
|
|
8
|
+
/**
|
|
9
|
+
* Attach a WebSocket transport to an existing RPC group. Either pass an
|
|
10
|
+
* existing `WebSocketServer` via `wss`, or let this helper create one from
|
|
11
|
+
* `port` / `host` / `https`.
|
|
12
|
+
*/
|
|
13
|
+
function attachWsRpcTransport(rpcGroup, options = {}) {
|
|
14
|
+
const { wss: externalWss, port, host = "localhost", https, onConnected = NOOP, onDisconnected = NOOP, definitions = EMPTY_DEFS, serialize: serializeOverride, deserialize: deserializeOverride } = options;
|
|
15
|
+
let wss;
|
|
16
|
+
if (externalWss) wss = externalWss;
|
|
17
|
+
else if (https) {
|
|
18
|
+
const httpsServer = createServer(https);
|
|
19
|
+
wss = new WebSocketServer({ server: httpsServer });
|
|
20
|
+
httpsServer.listen(port, host);
|
|
21
|
+
} else wss = new WebSocketServer({
|
|
22
|
+
port,
|
|
23
|
+
host
|
|
24
|
+
});
|
|
25
|
+
wss.on("connection", (ws, req) => {
|
|
26
|
+
const meta = {
|
|
27
|
+
id: sessionId++,
|
|
28
|
+
ws,
|
|
29
|
+
subscribedStates: /* @__PURE__ */ new Set()
|
|
30
|
+
};
|
|
31
|
+
const pendingRequestMethods = /* @__PURE__ */ new Map();
|
|
32
|
+
const channel = {
|
|
33
|
+
post: (data) => {
|
|
34
|
+
ws.send(data);
|
|
35
|
+
},
|
|
36
|
+
on: (fn) => {
|
|
37
|
+
ws.on("message", (data) => {
|
|
38
|
+
fn(data.toString());
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
serialize: serializeOverride ?? ((msg) => {
|
|
42
|
+
let method;
|
|
43
|
+
if (msg.t === "q") method = msg.m;
|
|
44
|
+
else {
|
|
45
|
+
method = pendingRequestMethods.get(msg.i);
|
|
46
|
+
pendingRequestMethods.delete(msg.i);
|
|
47
|
+
}
|
|
48
|
+
if (!!method && definitions.get(method)?.jsonSerializable === true) return strictJsonStringify(msg, method ?? "");
|
|
49
|
+
return `s:${structuredCloneStringify(msg)}`;
|
|
50
|
+
}),
|
|
51
|
+
deserialize: deserializeOverride ?? ((raw) => {
|
|
52
|
+
const msg = raw.startsWith("s:") ? structuredCloneParse(raw.slice(2)) : JSON.parse(raw);
|
|
53
|
+
if (msg.t === "q" && msg.i && msg.m) pendingRequestMethods.set(msg.i, msg.m);
|
|
54
|
+
return msg;
|
|
55
|
+
}),
|
|
56
|
+
meta
|
|
57
|
+
};
|
|
58
|
+
rpcGroup.updateChannels((channels) => {
|
|
59
|
+
channels.push(channel);
|
|
60
|
+
});
|
|
61
|
+
ws.on("close", () => {
|
|
62
|
+
rpcGroup.updateChannels((channels) => {
|
|
63
|
+
const index = channels.indexOf(channel);
|
|
64
|
+
if (index >= 0) channels.splice(index, 1);
|
|
65
|
+
});
|
|
66
|
+
onDisconnected(ws, meta);
|
|
67
|
+
});
|
|
68
|
+
onConnected(ws, req, meta);
|
|
69
|
+
});
|
|
70
|
+
return { wss };
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { attachWsRpcTransport };
|