devframe 0.0.0 → 0.1.16
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-CU6dE-VX.mjs +20 -0
- package/dist/adapters/build.d.mts +37 -0
- package/dist/adapters/build.mjs +61 -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 +227 -0
- package/dist/client/index.mjs +2 -0
- package/dist/client-4WrEozlH.mjs +1561 -0
- package/dist/constants.d.mts +20 -0
- package/dist/constants.mjs +34 -0
- package/dist/context-BrePWeyd.mjs +6776 -0
- package/dist/define-Bb4zh-Dc.mjs +11 -0
- package/dist/devtool-OJ3QW0ns.d.mts +1125 -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-HjMAm3b6.mjs +894 -0
- package/dist/index-DvKDO5H8.d.mts +333 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +2 -0
- package/dist/main-DpINGndA.mjs +601 -0
- package/dist/node/index.d.mts +365 -0
- package/dist/node/index.mjs +69 -0
- package/dist/open-BtOOEldu.mjs +533 -0
- package/dist/recipes/open-helpers.d.mts +104 -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 +2 -0
- package/dist/rpc/index.mjs +3 -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 +43 -0
- package/dist/rpc/transports/ws-server.d.mts +2 -0
- package/dist/rpc/transports/ws-server.mjs +58 -0
- package/dist/rpc-9FNa3Inb.mjs +474 -0
- package/dist/server-DrBxa6ZV.mjs +49 -0
- package/dist/src-BoIqXRc9.mjs +85 -0
- package/dist/static-dump-CQUC1aIW.mjs +82 -0
- package/dist/transports-BPUzHhI2.mjs +15 -0
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.mjs +6 -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-CGLewRtm.d.mts +401 -0
- package/dist/ws-client-CklfxUHE.d.mts +17 -0
- package/dist/ws-server--IuUAaGi.d.mts +37 -0
- package/package.json +116 -8
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { n as defineRpcFunction } from "../define-Bb4zh-Dc.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-BtOOEldu.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,2 @@
|
|
|
1
|
+
import { A as RpcFunctionSetupResult, C as RpcDumpStore, D as RpcFunctionDefinitionAnyWithContext, E as RpcFunctionDefinitionAny, F as RpcCacheManager, I as RpcCacheOptions, M as RpcFunctionsCollector, N as RpcReturnSchema, O as RpcFunctionDefinitionBase, P as Thenable, S as RpcDumpRecord, T as RpcFunctionDefinition, _ as RpcDump, a as createClientFromDump, b as RpcDumpDefinition, c as createDefineWrapperWithContext, d as BirpcFn, f as BirpcReturn, g as RpcDefinitionsToFunctions, h as RpcDefinitionsFilter, i as getRpcResolvedSetupResult, j as RpcFunctionType, k as RpcFunctionDefinitionToFunction, l as defineRpcFunction, m as RpcArgsSchema, n as validateDefinitions, o as dumpFunctions, p as EntriesToObject, r as getRpcHandler, s as getDefinitionsWithDumps, t as validateDefinition, u as RpcFunctionsCollectorBase, v as RpcDumpClientOptions, w as RpcFunctionAgentOptions, x as RpcDumpGetter, y as RpcDumpCollectionOptions } from "../index-DvKDO5H8.mjs";
|
|
2
|
+
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, Thenable, createClientFromDump, createDefineWrapperWithContext, defineRpcFunction, dumpFunctions, getDefinitionsWithDumps, getRpcHandler, getRpcResolvedSetupResult, validateDefinition, validateDefinitions };
|
|
@@ -0,0 +1,3 @@
|
|
|
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-9FNa3Inb.mjs";
|
|
2
|
+
import { n as defineRpcFunction, t as createDefineWrapperWithContext } from "../define-Bb4zh-Dc.mjs";
|
|
3
|
+
export { RpcCacheManager, RpcFunctionsCollectorBase, createClientFromDump, createDefineWrapperWithContext, defineRpcFunction, dumpFunctions, getDefinitionsWithDumps, getRpcHandler, getRpcResolvedSetupResult, 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,43 @@
|
|
|
1
|
+
import { parse, stringify } from "structured-clone-es";
|
|
2
|
+
//#region src/rpc/transports/ws-client.ts
|
|
3
|
+
function NOOP() {}
|
|
4
|
+
/**
|
|
5
|
+
* Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
|
|
6
|
+
* Pass the result straight to `createRpcClient`'s `channel` option.
|
|
7
|
+
*/
|
|
8
|
+
function createWsRpcChannel(options) {
|
|
9
|
+
let url = options.url;
|
|
10
|
+
if (options.authToken) url = `${url}?vite_devtools_auth_token=${encodeURIComponent(options.authToken)}`;
|
|
11
|
+
const ws = new WebSocket(url);
|
|
12
|
+
const { onConnected = NOOP, onError = NOOP, onDisconnected = NOOP } = options;
|
|
13
|
+
ws.addEventListener("open", (e) => {
|
|
14
|
+
onConnected(e);
|
|
15
|
+
});
|
|
16
|
+
ws.addEventListener("error", (e) => {
|
|
17
|
+
onError(e instanceof Error ? e : new Error(e.type));
|
|
18
|
+
});
|
|
19
|
+
ws.addEventListener("close", (e) => {
|
|
20
|
+
onDisconnected(e);
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
on: (handler) => {
|
|
24
|
+
ws.addEventListener("message", (e) => {
|
|
25
|
+
handler(e.data);
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
post: (data) => {
|
|
29
|
+
if (ws.readyState === WebSocket.OPEN) ws.send(data);
|
|
30
|
+
else {
|
|
31
|
+
function handler() {
|
|
32
|
+
ws.send(data);
|
|
33
|
+
ws.removeEventListener("open", handler);
|
|
34
|
+
}
|
|
35
|
+
ws.addEventListener("open", handler);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
serialize: stringify,
|
|
39
|
+
deserialize: parse
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { createWsRpcChannel };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { parse, stringify } from "structured-clone-es";
|
|
2
|
+
import { createServer } from "node:https";
|
|
3
|
+
import { WebSocketServer } from "ws";
|
|
4
|
+
//#region src/rpc/transports/ws-server.ts
|
|
5
|
+
let sessionId = 0;
|
|
6
|
+
function NOOP() {}
|
|
7
|
+
/**
|
|
8
|
+
* Attach a WebSocket transport to an existing RPC group. Either pass an
|
|
9
|
+
* existing `WebSocketServer` via `wss`, or let this helper create one from
|
|
10
|
+
* `port` / `host` / `https`.
|
|
11
|
+
*/
|
|
12
|
+
function attachWsRpcTransport(rpcGroup, options = {}) {
|
|
13
|
+
const { wss: externalWss, port, host = "localhost", https, onConnected = NOOP, onDisconnected = NOOP, serialize = stringify, deserialize = parse } = options;
|
|
14
|
+
let wss;
|
|
15
|
+
if (externalWss) wss = externalWss;
|
|
16
|
+
else if (https) {
|
|
17
|
+
const httpsServer = createServer(https);
|
|
18
|
+
wss = new WebSocketServer({ server: httpsServer });
|
|
19
|
+
httpsServer.listen(port, host);
|
|
20
|
+
} else wss = new WebSocketServer({
|
|
21
|
+
port,
|
|
22
|
+
host
|
|
23
|
+
});
|
|
24
|
+
wss.on("connection", (ws, req) => {
|
|
25
|
+
const meta = {
|
|
26
|
+
id: sessionId++,
|
|
27
|
+
ws,
|
|
28
|
+
subscribedStates: /* @__PURE__ */ new Set()
|
|
29
|
+
};
|
|
30
|
+
const channel = {
|
|
31
|
+
post: (data) => {
|
|
32
|
+
ws.send(data);
|
|
33
|
+
},
|
|
34
|
+
on: (fn) => {
|
|
35
|
+
ws.on("message", (data) => {
|
|
36
|
+
fn(data.toString());
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
serialize,
|
|
40
|
+
deserialize,
|
|
41
|
+
meta
|
|
42
|
+
};
|
|
43
|
+
rpcGroup.updateChannels((channels) => {
|
|
44
|
+
channels.push(channel);
|
|
45
|
+
});
|
|
46
|
+
ws.on("close", () => {
|
|
47
|
+
rpcGroup.updateChannels((channels) => {
|
|
48
|
+
const index = channels.indexOf(channel);
|
|
49
|
+
if (index >= 0) channels.splice(index, 1);
|
|
50
|
+
});
|
|
51
|
+
onDisconnected(ws, meta);
|
|
52
|
+
});
|
|
53
|
+
onConnected(ws, req, meta);
|
|
54
|
+
});
|
|
55
|
+
return { wss };
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { attachWsRpcTransport };
|