@powerlines/engine 0.15.19 → 0.15.21
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/api/build.cjs +1 -1
- package/dist/api/build.d.mts +2 -2
- package/dist/api/build.mjs +1 -1
- package/dist/api/build.mjs.map +1 -1
- package/dist/api/clean.d.mts +2 -2
- package/dist/api/clean.mjs.map +1 -1
- package/dist/api/create.d.mts +2 -2
- package/dist/api/create.mjs.map +1 -1
- package/dist/api/deploy.d.mts +2 -2
- package/dist/api/deploy.mjs.map +1 -1
- package/dist/api/docs.d.mts +2 -2
- package/dist/api/docs.mjs.map +1 -1
- package/dist/api/lint.d.mts +2 -2
- package/dist/api/lint.mjs.map +1 -1
- package/dist/api/prepare.cjs +2 -2
- package/dist/api/prepare.d.mts +2 -2
- package/dist/api/prepare.mjs +2 -2
- package/dist/api/prepare.mjs.map +1 -1
- package/dist/api/test.d.mts +2 -2
- package/dist/api/test.mjs.map +1 -1
- package/dist/api/types.cjs +2 -2
- package/dist/api/types.d.mts +2 -2
- package/dist/api/types.mjs +2 -2
- package/dist/api/types.mjs.map +1 -1
- package/dist/{api-Cdw4v0W4.d.mts → api-B2dWvRMM.d.mts} +10 -7
- package/dist/api-B2dWvRMM.d.mts.map +1 -0
- package/dist/{api-6w4hZL6n.d.cts → api-DgxYwNuZ.d.cts} +8 -5
- package/dist/api-DgxYwNuZ.d.cts.map +1 -0
- package/dist/{execution-host.cjs → api.cjs} +1 -1
- package/dist/{execution-host.d.mts → api.d.cts} +3 -3
- package/dist/api.d.cts.map +1 -0
- package/dist/{execution-host.d.cts → api.d.mts} +3 -3
- package/dist/api.d.mts.map +1 -0
- package/dist/{execution-host.mjs → api.mjs} +2 -2
- package/dist/api.mjs.map +1 -0
- package/dist/{config-BNe23XHx.d.mts → config-C9AD-erz.d.mts} +1 -1
- package/dist/config-C9AD-erz.d.mts.map +1 -0
- package/dist/config-D6xUniHh.d.cts.map +1 -1
- package/dist/context/engine-context.cjs +6 -4
- package/dist/context/engine-context.d.cts +1 -1
- package/dist/context/engine-context.d.mts +1 -1
- package/dist/context/engine-context.mjs +6 -4
- package/dist/context/engine-context.mjs.map +1 -1
- package/dist/context/index.d.cts +1 -1
- package/dist/context/index.d.mts +1 -1
- package/dist/{context-DzgsMSWr.d.mts → context-S3XH2DWP.d.mts} +2 -2
- package/dist/context-S3XH2DWP.d.mts.map +1 -0
- package/dist/context-epL7NPvL.d.cts.map +1 -1
- package/dist/engine-Ct0OGdyp.mjs +571 -0
- package/dist/engine-Ct0OGdyp.mjs.map +1 -0
- package/dist/{engine-context-DEotmVzB.d.mts → engine-context-Cc93ql_I.d.mts} +5 -6
- package/dist/engine-context-Cc93ql_I.d.mts.map +1 -0
- package/dist/{engine-context-Dw8odBCo.d.cts → engine-context-lrWc13AH.d.cts} +2 -3
- package/dist/engine-context-lrWc13AH.d.cts.map +1 -0
- package/dist/engine-ntih8wNh.cjs +590 -0
- package/dist/engine.cjs +4 -265
- package/dist/engine.d.cts +3 -3
- package/dist/engine.d.cts.map +1 -1
- package/dist/engine.d.mts +5 -5
- package/dist/engine.d.mts.map +1 -1
- package/dist/engine.mjs +2 -262
- package/dist/helpers/create-execution-host.cjs +10 -3
- package/dist/helpers/create-execution-host.d.cts +20 -2
- package/dist/helpers/create-execution-host.d.cts.map +1 -0
- package/dist/helpers/create-execution-host.d.mts +20 -2
- package/dist/helpers/create-execution-host.d.mts.map +1 -0
- package/dist/helpers/create-execution-host.mjs +10 -3
- package/dist/helpers/create-execution-host.mjs.map +1 -1
- package/dist/helpers/finalize.d.cts +12 -2
- package/dist/helpers/finalize.d.cts.map +1 -0
- package/dist/helpers/finalize.d.mts +12 -2
- package/dist/helpers/finalize.d.mts.map +1 -0
- package/dist/helpers/finalize.mjs.map +1 -1
- package/dist/helpers/index.cjs +4 -2
- package/dist/helpers/index.d.cts +5 -5
- package/dist/helpers/index.d.mts +5 -5
- package/dist/helpers/index.mjs +2 -2
- package/dist/helpers/rpc.cjs +2 -2
- package/dist/helpers/rpc.d.cts +7 -2
- package/dist/helpers/rpc.d.cts.map +1 -0
- package/dist/helpers/rpc.d.mts +7 -2
- package/dist/helpers/rpc.d.mts.map +1 -0
- package/dist/helpers/rpc.mjs +2 -2
- package/dist/helpers/rpc.mjs.map +1 -1
- package/dist/helpers/stream.cjs +120 -0
- package/dist/helpers/stream.d.cts +45 -0
- package/dist/helpers/stream.d.cts.map +1 -0
- package/dist/helpers/stream.d.mts +45 -0
- package/dist/helpers/stream.d.mts.map +1 -0
- package/dist/helpers/stream.mjs +117 -0
- package/dist/helpers/stream.mjs.map +1 -0
- package/dist/index.cjs +2 -11
- package/dist/index.d.cts +3 -7
- package/dist/index.d.mts +5 -9
- package/dist/index.mjs +2 -7
- package/package.json +10 -12
- package/dist/api-6w4hZL6n.d.cts.map +0 -1
- package/dist/api-Cdw4v0W4.d.mts.map +0 -1
- package/dist/config-BNe23XHx.d.mts.map +0 -1
- package/dist/context-DzgsMSWr.d.mts.map +0 -1
- package/dist/create-execution-host-CdpuL_YG.d.mts +0 -20
- package/dist/create-execution-host-CdpuL_YG.d.mts.map +0 -1
- package/dist/create-execution-host-DbOCE5bd.d.cts +0 -20
- package/dist/create-execution-host-DbOCE5bd.d.cts.map +0 -1
- package/dist/engine-context-DEotmVzB.d.mts.map +0 -1
- package/dist/engine-context-Dw8odBCo.d.cts.map +0 -1
- package/dist/engine.mjs.map +0 -1
- package/dist/execution-host-worker-D7LinO52.d.cts +0 -70
- package/dist/execution-host-worker-D7LinO52.d.cts.map +0 -1
- package/dist/execution-host-worker-zpQqaW_W.d.mts +0 -70
- package/dist/execution-host-worker-zpQqaW_W.d.mts.map +0 -1
- package/dist/execution-host.d.cts.map +0 -1
- package/dist/execution-host.d.mts.map +0 -1
- package/dist/execution-host.mjs.map +0 -1
- package/dist/finalize-CW0cO75l.d.cts +0 -12
- package/dist/finalize-CW0cO75l.d.cts.map +0 -1
- package/dist/finalize-DeSY1r74.d.mts +0 -12
- package/dist/finalize-DeSY1r74.d.mts.map +0 -1
- package/dist/helpers/execution-host-worker.cjs +0 -327
- package/dist/helpers/execution-host-worker.d.cts +0 -2
- package/dist/helpers/execution-host-worker.d.mts +0 -2
- package/dist/helpers/execution-host-worker.mjs +0 -326
- package/dist/helpers/execution-host-worker.mjs.map +0 -1
- package/dist/rpc-BsFxzyAK.d.cts +0 -7
- package/dist/rpc-BsFxzyAK.d.cts.map +0 -1
- package/dist/rpc-xwbFMMNu.d.mts +0 -7
- package/dist/rpc-xwbFMMNu.d.mts.map +0 -1
- /package/dist/{index-D_TYgLX3.d.cts → index-DDRpa5CJ.d.cts} +0 -0
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { r as EngineResolvedConfig } from "../config-C9AD-erz.mjs";
|
|
2
|
+
import { r as EngineSystemContext } from "../context-S3XH2DWP.mjs";
|
|
3
|
+
import { r as ExecutionHostParams } from "../api-B2dWvRMM.mjs";
|
|
4
|
+
import { ExecutionContext, InlineConfig } from "@powerlines/core";
|
|
5
|
+
import { DeepPartial, MaybePromise } from "@stryke/types/base";
|
|
6
|
+
|
|
7
|
+
//#region src/helpers/create-execution-host.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Creates an execution host with the provided methods. Each method will be wrapped to create an execution context and handle errors appropriately.
|
|
10
|
+
*
|
|
11
|
+
* @param methods - An object where keys are method names and values are functions that take an execution context and return a promise.
|
|
12
|
+
* @param inlineConfig - An optional partial inline configuration object that will be merged with the context's options when creating the execution context for each method.
|
|
13
|
+
* @returns An object with the same keys as the input methods, but each function is wrapped to create an execution context and handle errors.
|
|
14
|
+
*/
|
|
15
|
+
declare function createExecutionHost<TContext extends ExecutionContext<EngineResolvedConfig, EngineSystemContext> = ExecutionContext<EngineResolvedConfig, EngineSystemContext>>(methods: Record<string, (context: TContext) => Promise<void>>, inlineConfig?: DeepPartial<InlineConfig> | ((prev: InlineConfig) => MaybePromise<InlineConfig>)): {
|
|
16
|
+
[k: string]: (params: ExecutionHostParams) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createExecutionHost };
|
|
20
|
+
//# sourceMappingURL=create-execution-host.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-execution-host.d.mts","names":[],"sources":["../../src/helpers/create-execution-host.ts"],"mappings":";;;;;;;;;AA8CA;;;;;iBAAgB,mBAAA,kBACG,gBAAA,CAAiB,oBAAA,EAAsB,mBAAA,IACtD,gBAAA,CAAiB,oBAAA,EAAsB,mBAAA,EAAA,CAEzC,OAAA,EAAS,MAAA,UAAgB,OAAA,EAAS,QAAA,KAAa,OAAA,SAC/C,YAAA,GACI,WAAA,CAAY,YAAA,MACV,IAAA,EAAM,YAAA,KAAiB,YAAA,CAAa,YAAA;EAAA,sBAKvB,mBAAA,KAAmB,OAAA;AAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createRpcClient } from "./rpc.mjs";
|
|
2
|
+
import { MessagePortDuplex } from "./stream.mjs";
|
|
2
3
|
import { consoleLogger } from "@powerlines/core/plugin-utils";
|
|
3
|
-
import { uuid } from "@stryke/unique-id/uuid";
|
|
4
|
-
import { isFunction } from "@stryke/type-checks/is-function";
|
|
5
4
|
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
6
5
|
import { PowerlinesExecutionContext } from "@powerlines/core/context/execution-context";
|
|
7
6
|
import { resolvePluginConfig } from "@powerlines/core/lib/context-helpers";
|
|
8
7
|
import { titleCase } from "@stryke/string-format/title-case";
|
|
8
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
9
|
+
import { uuid } from "@stryke/unique-id/uuid";
|
|
9
10
|
import { defu } from "defu";
|
|
10
11
|
|
|
11
12
|
//#region src/helpers/create-execution-host.ts
|
|
@@ -18,7 +19,13 @@ import { defu } from "defu";
|
|
|
18
19
|
*/
|
|
19
20
|
function createExecutionHost(methods, inlineConfig = {}) {
|
|
20
21
|
return Object.fromEntries(Object.entries(methods).map(([method, fn]) => [method, async (params) => {
|
|
21
|
-
const { options } = params;
|
|
22
|
+
const { options, port } = params;
|
|
23
|
+
const duplex = new MessagePortDuplex(port);
|
|
24
|
+
duplex.setEncoding("utf8");
|
|
25
|
+
duplex.on("data", (chunk) => duplex.write(chunk.toUpperCase()));
|
|
26
|
+
duplex.on("end", () => {
|
|
27
|
+
duplex.end();
|
|
28
|
+
});
|
|
22
29
|
let rpc;
|
|
23
30
|
if (options.baseURL && options.connection) rpc = createRpcClient(options);
|
|
24
31
|
else throw new Error(`Execution RPC client could not be created - Missing ${!options.baseURL ? `baseURL${options.connection ? ` and connection information` : ""}` : "connection"} or connection information.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-execution-host.mjs","names":[],"sources":["../../src/helpers/create-execution-host.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n ExecutionContext,\n InlineConfig,\n LogFnMeta\n} from \"@powerlines/core\";\nimport { PowerlinesExecutionContext } from \"@powerlines/core/context/execution-context\";\nimport { resolvePluginConfig } from \"@powerlines/core/lib/context-helpers\";\nimport { consoleLogger } from \"@powerlines/core/plugin-utils\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type { DeepPartial, MaybePromise } from \"@stryke/types/base\";\nimport { uuid } from \"@stryke/unique-id/uuid\";\nimport { defu } from \"defu\";\nimport type { RpcClient } from \"../types\";\nimport type { ExecutionHostParams } from \"../types/api\";\nimport type { EngineResolvedConfig } from \"../types/config\";\nimport type { EngineSystemContext } from \"../types/context\";\nimport { createRpcClient } from \"./rpc\";\n\n/**\n * Creates an execution host with the provided methods. Each method will be wrapped to create an execution context and handle errors appropriately.\n *\n * @param methods - An object where keys are method names and values are functions that take an execution context and return a promise.\n * @param inlineConfig - An optional partial inline configuration object that will be merged with the context's options when creating the execution context for each method.\n * @returns An object with the same keys as the input methods, but each function is wrapped to create an execution context and handle errors.\n */\nexport function createExecutionHost<\n TContext extends ExecutionContext<EngineResolvedConfig, EngineSystemContext> =\n ExecutionContext<EngineResolvedConfig, EngineSystemContext>\n>(\n methods: Record<string, (context: TContext) => Promise<void>>,\n inlineConfig:\n | DeepPartial<InlineConfig>\n | ((prev: InlineConfig) => MaybePromise<InlineConfig>) = {}\n) {\n return Object.fromEntries(\n Object.entries(methods).map(([method, fn]) => [\n method,\n async (params: ExecutionHostParams) => {\n const { options } = params;\n\n let rpc!: RpcClient;\n if (options.baseURL && options.connection) {\n rpc = createRpcClient(options);\n } else {\n throw new Error(\n `Execution RPC client could not be created - Missing ${\n !options.baseURL\n ? `baseURL${options.connection ? ` and connection information` : \"\"}`\n : \"connection\"\n } or connection information.`\n );\n }\n\n const logFn = (meta: LogFnMeta, message: string) => {\n consoleLogger(meta, message);\n if (rpc) {\n void rpc.callEvent(\"powerlines:log\", {\n meta: {\n category: \"general\",\n ...options,\n ...(isSetObject(meta) ? meta : { type: meta }),\n logId: uuid(),\n timestamp: Date.now()\n },\n message\n });\n }\n };\n\n const context = (await PowerlinesExecutionContext.from<\n EngineResolvedConfig,\n EngineSystemContext\n >(\n { ...options, logFn },\n isFunction(inlineConfig)\n ? await Promise.resolve(inlineConfig(params.inlineConfig ?? {}))\n : (defu(inlineConfig, params.inlineConfig ?? {}) as InlineConfig),\n {\n rpc\n }\n )) as TContext;\n\n context.logger.info(\n `Starting ${\n titleCase(options.framework?.name) || \"Powerlines\"\n } - ${titleCase(method)} execution (${options.executionId})`\n );\n\n await resolvePluginConfig<EngineResolvedConfig, EngineSystemContext>(\n context\n );\n await fn(context);\n }\n ])\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-execution-host.mjs","names":[],"sources":["../../src/helpers/create-execution-host.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n ExecutionContext,\n InlineConfig,\n LogFnMeta\n} from \"@powerlines/core\";\nimport { PowerlinesExecutionContext } from \"@powerlines/core/context/execution-context\";\nimport { resolvePluginConfig } from \"@powerlines/core/lib/context-helpers\";\nimport { consoleLogger } from \"@powerlines/core/plugin-utils\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type { DeepPartial, MaybePromise } from \"@stryke/types/base\";\nimport { uuid } from \"@stryke/unique-id/uuid\";\nimport { defu } from \"defu\";\nimport type { RpcClient } from \"../types\";\nimport type { ExecutionHostParams } from \"../types/api\";\nimport type { EngineResolvedConfig } from \"../types/config\";\nimport type { EngineSystemContext } from \"../types/context\";\nimport { createRpcClient } from \"./rpc\";\nimport { MessagePortDuplex } from \"./stream\";\n\n/**\n * Creates an execution host with the provided methods. Each method will be wrapped to create an execution context and handle errors appropriately.\n *\n * @param methods - An object where keys are method names and values are functions that take an execution context and return a promise.\n * @param inlineConfig - An optional partial inline configuration object that will be merged with the context's options when creating the execution context for each method.\n * @returns An object with the same keys as the input methods, but each function is wrapped to create an execution context and handle errors.\n */\nexport function createExecutionHost<\n TContext extends ExecutionContext<EngineResolvedConfig, EngineSystemContext> =\n ExecutionContext<EngineResolvedConfig, EngineSystemContext>\n>(\n methods: Record<string, (context: TContext) => Promise<void>>,\n inlineConfig:\n | DeepPartial<InlineConfig>\n | ((prev: InlineConfig) => MaybePromise<InlineConfig>) = {}\n) {\n return Object.fromEntries(\n Object.entries(methods).map(([method, fn]) => [\n method,\n async (params: ExecutionHostParams) => {\n const { options, port } = params;\n\n const duplex = new MessagePortDuplex(port);\n duplex.setEncoding(\"utf8\");\n duplex.on(\"data\", (chunk: string) => duplex.write(chunk.toUpperCase()));\n duplex.on(\"end\", () => {\n duplex.end();\n });\n\n let rpc!: RpcClient;\n if (options.baseURL && options.connection) {\n rpc = createRpcClient(options);\n } else {\n throw new Error(\n `Execution RPC client could not be created - Missing ${\n !options.baseURL\n ? `baseURL${options.connection ? ` and connection information` : \"\"}`\n : \"connection\"\n } or connection information.`\n );\n }\n\n const logFn = (meta: LogFnMeta, message: string) => {\n consoleLogger(meta, message);\n if (rpc) {\n void rpc.callEvent(\"powerlines:log\", {\n meta: {\n category: \"general\",\n ...options,\n ...(isSetObject(meta) ? meta : { type: meta }),\n logId: uuid(),\n timestamp: Date.now()\n },\n message\n });\n }\n };\n\n const context = (await PowerlinesExecutionContext.from<\n EngineResolvedConfig,\n EngineSystemContext\n >(\n { ...options, logFn },\n isFunction(inlineConfig)\n ? await Promise.resolve(inlineConfig(params.inlineConfig ?? {}))\n : (defu(inlineConfig, params.inlineConfig ?? {}) as InlineConfig),\n {\n rpc\n }\n )) as TContext;\n\n context.logger.info(\n `Starting ${\n titleCase(options.framework?.name) || \"Powerlines\"\n } - ${titleCase(method)} execution (${options.executionId})`\n );\n\n await resolvePluginConfig<EngineResolvedConfig, EngineSystemContext>(\n context\n );\n await fn(context);\n }\n ])\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8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
2
|
-
|
|
1
|
+
import { ExecutionContext, ResolvedConfig } from "@powerlines/core";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/finalize.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Finalize the execution context by disposing resources and cleaning up.
|
|
6
|
+
*
|
|
7
|
+
* @param context - The execution context to finalize
|
|
8
|
+
*/
|
|
9
|
+
declare function finalize<TResolvedConfig extends ResolvedConfig = ResolvedConfig>(context: ExecutionContext<TResolvedConfig>): Promise<void>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { finalize };
|
|
12
|
+
//# sourceMappingURL=finalize.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalize.d.cts","names":[],"sources":["../../src/helpers/finalize.ts"],"mappings":";;;;;AA+BA;;;iBAAsB,QAAA,yBACI,cAAA,GAAiB,cAAA,CAAA,CACzC,OAAA,EAAS,gBAAA,CAAiB,eAAA,IAAgB,OAAA"}
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ExecutionContext, ResolvedConfig } from "@powerlines/core";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/finalize.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Finalize the execution context by disposing resources and cleaning up.
|
|
6
|
+
*
|
|
7
|
+
* @param context - The execution context to finalize
|
|
8
|
+
*/
|
|
9
|
+
declare function finalize<TResolvedConfig extends ResolvedConfig = ResolvedConfig>(context: ExecutionContext<TResolvedConfig>): Promise<void>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { finalize };
|
|
12
|
+
//# sourceMappingURL=finalize.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalize.d.mts","names":[],"sources":["../../src/helpers/finalize.ts"],"mappings":";;;;;AA+BA;;;iBAAsB,QAAA,yBACI,cAAA,GAAiB,cAAA,CAAA,CACzC,OAAA,EAAS,gBAAA,CAAiB,eAAA,IAAgB,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finalize.mjs","names":[],"sources":["../../src/helpers/finalize.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ExecutionContext, ResolvedConfig } from \"@powerlines/core\";\nimport { executeEnvironments } from \"@powerlines/core/lib/environment\";\nimport { callHook } from \"@powerlines/core/lib/hooks\";\nimport { removeDirectory } from \"@stryke/fs/helpers\";\nimport { listFiles } from \"@stryke/fs/list-files\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { existsSync } from \"node:fs\";\n\n/**\n * Finalize the execution context by disposing resources and cleaning up.\n *\n * @param context - The execution context to finalize\n */\nexport async function finalize<\n TResolvedConfig extends ResolvedConfig = ResolvedConfig\n>(context: ExecutionContext<TResolvedConfig>) {\n const timer = context.timer(\"Finalization\");\n\n await executeEnvironments(context, async env => {\n await callHook(context, \"finalize\", { environment: env });\n await env.fs.dispose();\n\n if (\n existsSync(env.cachePath) &&\n !(await listFiles(joinPaths(env.cachePath, \"**/*\")))?.length\n ) {\n await removeDirectory(env.cachePath);\n }\n });\n\n timer();\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,eAAsB,SAEpB,SAA4C;CAC5C,MAAM,QAAQ,QAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"finalize.mjs","names":[],"sources":["../../src/helpers/finalize.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { ExecutionContext, ResolvedConfig } from \"@powerlines/core\";\nimport { executeEnvironments } from \"@powerlines/core/lib/environment\";\nimport { callHook } from \"@powerlines/core/lib/hooks\";\nimport { removeDirectory } from \"@stryke/fs/helpers\";\nimport { listFiles } from \"@stryke/fs/list-files\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { existsSync } from \"node:fs\";\n\n/**\n * Finalize the execution context by disposing resources and cleaning up.\n *\n * @param context - The execution context to finalize\n */\nexport async function finalize<\n TResolvedConfig extends ResolvedConfig = ResolvedConfig\n>(context: ExecutionContext<TResolvedConfig>) {\n const timer = context.timer(\"Finalization\");\n\n await executeEnvironments(context, async env => {\n await callHook(context, \"finalize\", { environment: env });\n await env.fs.dispose();\n\n if (\n existsSync(env.cachePath) &&\n !(await listFiles(joinPaths(env.cachePath, \"**/*\")))?.length\n ) {\n await removeDirectory(env.cachePath);\n }\n });\n\n timer();\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,eAAsB,SAEpB,SAA4C;CAC5C,MAAM,QAAQ,QAAQ,MAAM,cAAc;CAE1C,MAAM,oBAAoB,SAAS,OAAM,QAAO;EAC9C,MAAM,SAAS,SAAS,YAAY,EAAE,aAAa,IAAI,CAAC;EACxD,MAAM,IAAI,GAAG,QAAQ;EAErB,IACE,WAAW,IAAI,SAAS,KACxB,EAAE,MAAM,UAAU,UAAU,IAAI,WAAW,MAAM,CAAC,IAAI,QAEtD,MAAM,gBAAgB,IAAI,SAAS;CAEvC,CAAC;CAED,MAAM;AACR"}
|
package/dist/helpers/index.cjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_helpers_execution_host_worker = require('./execution-host-worker.cjs');
|
|
3
2
|
const require_helpers_rpc = require('./rpc.cjs');
|
|
3
|
+
const require_helpers_stream = require('./stream.cjs');
|
|
4
4
|
const require_helpers_create_execution_host = require('./create-execution-host.cjs');
|
|
5
5
|
const require_helpers_finalize = require('./finalize.cjs');
|
|
6
6
|
|
|
7
|
-
exports.
|
|
7
|
+
exports.MessagePortDuplex = require_helpers_stream.MessagePortDuplex;
|
|
8
|
+
exports.MessagePortReadable = require_helpers_stream.MessagePortReadable;
|
|
9
|
+
exports.MessagePortWritable = require_helpers_stream.MessagePortWritable;
|
|
8
10
|
exports.createExecutionHost = require_helpers_create_execution_host.createExecutionHost;
|
|
9
11
|
exports.createRpcClient = require_helpers_rpc.createRpcClient;
|
|
10
12
|
exports.finalize = require_helpers_finalize.finalize;
|
package/dist/helpers/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
1
|
+
import { createExecutionHost } from "./create-execution-host.cjs";
|
|
2
|
+
import { finalize } from "./finalize.cjs";
|
|
3
|
+
import { createRpcClient } from "./rpc.cjs";
|
|
4
|
+
import { MessagePortDuplex, MessagePortDuplexOptions, MessagePortReadable, MessagePortWritable } from "./stream.cjs";
|
|
5
|
+
export { MessagePortDuplex, MessagePortDuplexOptions, MessagePortReadable, MessagePortWritable, createExecutionHost, createRpcClient, finalize };
|
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
1
|
+
import { createExecutionHost } from "./create-execution-host.mjs";
|
|
2
|
+
import { finalize } from "./finalize.mjs";
|
|
3
|
+
import { createRpcClient } from "./rpc.mjs";
|
|
4
|
+
import { MessagePortDuplex, MessagePortDuplexOptions, MessagePortReadable, MessagePortWritable } from "./stream.mjs";
|
|
5
|
+
export { MessagePortDuplex, MessagePortDuplexOptions, MessagePortReadable, MessagePortWritable, createExecutionHost, createRpcClient, finalize };
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExecutionHostWorker } from "./execution-host-worker.mjs";
|
|
2
1
|
import { createRpcClient } from "./rpc.mjs";
|
|
2
|
+
import { MessagePortDuplex, MessagePortReadable, MessagePortWritable } from "./stream.mjs";
|
|
3
3
|
import { createExecutionHost } from "./create-execution-host.mjs";
|
|
4
4
|
import { finalize } from "./finalize.mjs";
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { MessagePortDuplex, MessagePortReadable, MessagePortWritable, createExecutionHost, createRpcClient, finalize };
|
package/dist/helpers/rpc.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_chunk = require('../chunk-C0xms8kb.cjs');
|
|
3
|
-
let
|
|
3
|
+
let _powerlines_core_lib_events = require("@powerlines/core/lib/events");
|
|
4
4
|
let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
5
5
|
let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
|
|
6
|
-
let _powerlines_core_lib_events = require("@powerlines/core/lib/events");
|
|
7
6
|
let _stryke_url = require("@stryke/url");
|
|
8
7
|
let devframe_client = require("devframe/client");
|
|
9
8
|
let devframe_rpc = require("devframe/rpc");
|
|
@@ -11,6 +10,7 @@ let devframe_rpc_client = require("devframe/rpc/client");
|
|
|
11
10
|
let devframe_rpc_transports_ws_client = require("devframe/rpc/transports/ws-client");
|
|
12
11
|
let devframe_utils_promise = require("devframe/utils/promise");
|
|
13
12
|
let human_id = require("human-id");
|
|
13
|
+
let node_events = require("node:events");
|
|
14
14
|
|
|
15
15
|
//#region src/helpers/rpc.ts
|
|
16
16
|
function createWsRpcClientMode(baseURL, connectionMeta, events, clientRpc, authToken = (0, human_id.humanId)({
|
package/dist/helpers/rpc.d.cts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { i as RpcClientOptions, u as RpcClient } from "../config-D6xUniHh.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/rpc.d.ts
|
|
4
|
+
declare function createRpcClient(options: RpcClientOptions): RpcClient;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createRpcClient };
|
|
7
|
+
//# sourceMappingURL=rpc.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.cts","names":[],"sources":["../../src/helpers/rpc.ts"],"mappings":";;;iBA0LgB,eAAA,CAAgB,OAAA,EAAS,gBAAA,GAAgB,SAAA"}
|
package/dist/helpers/rpc.d.mts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { i as RpcClientOptions, u as RpcClient } from "../config-C9AD-erz.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/rpc.d.ts
|
|
4
|
+
declare function createRpcClient(options: RpcClientOptions): RpcClient;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createRpcClient };
|
|
7
|
+
//# sourceMappingURL=rpc.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.mts","names":[],"sources":["../../src/helpers/rpc.ts"],"mappings":";;;iBA0LgB,eAAA,CAAgB,OAAA,EAAS,gBAAA,GAAgB,SAAA"}
|
package/dist/helpers/rpc.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createEventEmitter } from "@powerlines/core/lib/events";
|
|
2
2
|
import { isNumber } from "@stryke/type-checks/is-number";
|
|
3
3
|
import { isSet } from "@stryke/type-checks/is-set";
|
|
4
|
-
import { createEventEmitter } from "@powerlines/core/lib/events";
|
|
5
4
|
import { StormURL } from "@stryke/url";
|
|
6
5
|
import { createRpcStreamingClientHost } from "devframe/client";
|
|
7
6
|
import { RpcCacheManager, RpcFunctionsCollectorBase } from "devframe/rpc";
|
|
@@ -9,6 +8,7 @@ import { createRpcClient as createRpcClient$1 } from "devframe/rpc/client";
|
|
|
9
8
|
import { createWsRpcChannel } from "devframe/rpc/transports/ws-client";
|
|
10
9
|
import { promiseWithResolver } from "devframe/utils/promise";
|
|
11
10
|
import { humanId } from "human-id";
|
|
11
|
+
import { EventEmitter } from "node:events";
|
|
12
12
|
|
|
13
13
|
//#region src/helpers/rpc.ts
|
|
14
14
|
function createWsRpcClientMode(baseURL, connectionMeta, events, clientRpc, authToken = humanId({
|
package/dist/helpers/rpc.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.mjs","names":["createDevframeRpcClient"],"sources":["../../src/helpers/rpc.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { createEventEmitter } from \"@powerlines/core/lib/events\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { StormURL } from \"@stryke/url\";\nimport { BirpcOptions } from \"birpc\";\nimport {\n createRpcStreamingClientHost,\n DevToolsClientRpcHost,\n DevToolsRpcClientMode,\n RpcClientEvents\n} from \"devframe/client\";\nimport { RpcCacheManager, RpcFunctionsCollectorBase } from \"devframe/rpc\";\nimport { createRpcClient as createDevframeRpcClient } from \"devframe/rpc/client\";\nimport {\n createWsRpcChannel,\n WsRpcChannelOptions\n} from \"devframe/rpc/transports/ws-client\";\nimport {\n ConnectionMeta,\n EventEmitter as DevFrameEventEmitter\n} from \"devframe/types\";\nimport { promiseWithResolver } from \"devframe/utils/promise\";\nimport { humanId } from \"human-id\";\nimport { EventEmitter } from \"node:events\";\nimport { RpcClientOptions } from \"../types/config\";\nimport {\n RpcClient,\n RpcClientFunctions,\n RpcContext,\n RpcServerFunctions\n} from \"../types/rpc\";\n\nfunction createWsRpcClientMode(\n baseURL: StormURL,\n connectionMeta: ConnectionMeta,\n events: DevFrameEventEmitter<RpcClientEvents>,\n clientRpc: DevToolsClientRpcHost,\n authToken: string = humanId({ separator: \"-\", capitalize: false }),\n rpcOptions: Partial<\n BirpcOptions<RpcServerFunctions, RpcClientFunctions, boolean>\n > = {},\n wsOptions: Partial<WsRpcChannelOptions> = {}\n): DevToolsRpcClientMode {\n let isTrusted = false;\n const trustedPromise = promiseWithResolver<boolean>();\n const url =\n isNumber(connectionMeta.websocket) ||\n (isSet(connectionMeta.websocket) &&\n `${+connectionMeta.websocket}` === `${connectionMeta.websocket}`)\n ? `${baseURL.protocol.replace(\"http\", \"ws\")}//${baseURL.hostname}:${connectionMeta.websocket}`\n : (connectionMeta.websocket as string);\n\n // Build a minimal `defs` map from the connection meta so the per-call\n // wire serializer dispatches outgoing requests with the correct\n // encoding (JSON for `jsonSerializable: true` methods; structured-\n // clone for the rest).\n const definitions = new Map<string, { jsonSerializable: true }>();\n for (const name of connectionMeta.jsonSerializableMethods ?? [])\n definitions.set(name, { jsonSerializable: true });\n\n const serverRpc = createDevframeRpcClient<\n RpcServerFunctions,\n RpcClientFunctions\n >(clientRpc.functions, {\n channel: createWsRpcChannel({\n url,\n authToken,\n definitions,\n ...wsOptions\n }),\n rpcOptions\n });\n\n // Handle server-initiated auth revocation\n clientRpc.register({\n name: \"devframe:auth:revoked\",\n type: \"event\",\n handler: () => {\n isTrusted = false;\n events.emit(\"rpc:is-trusted:updated\", false);\n }\n });\n\n let currentAuthToken = authToken;\n\n async function requestTrustWithToken(token: string) {\n currentAuthToken = token;\n\n // const info = parseUA(navigator.userAgent);\n // const ua = [\n // \"powerlines\",\n // \"1.0\",\n // \"|\",\n // info.os.name,\n // info.os.version,\n // info.device.type\n // ]\n // .filter(i => i)\n // .join(\" \");\n\n // const result = await serverRpc.$call(\"vite:anonymous:auth\", {\n // authToken: token,\n // ua,\n // origin: baseURL.origin\n // });\n\n // isTrusted = result.isTrusted;\n // trustedPromise.resolve(isTrusted);\n // events.emit(\"rpc:is-trusted:updated\", isTrusted);\n // return result.isTrusted;\n\n return true;\n }\n\n async function requestTrust() {\n if (isTrusted) return true;\n return requestTrustWithToken(currentAuthToken);\n }\n\n async function ensureTrusted(timeout = 60_000): Promise<boolean> {\n if (isTrusted) trustedPromise.resolve(true);\n\n if (timeout <= 0) return trustedPromise.promise;\n\n let clear = () => {};\n await Promise.race([\n trustedPromise.promise.then(clear),\n new Promise((resolve, reject) => {\n const id = setTimeout(() => {\n reject(new Error(\"Timeout waiting for rpc to be trusted\"));\n }, timeout);\n clear = () => clearTimeout(id);\n })\n ]);\n\n return isTrusted;\n }\n\n return {\n get isTrusted() {\n return isTrusted;\n },\n requestTrust,\n requestTrustWithToken,\n ensureTrusted,\n call: (...args: any): any => {\n return serverRpc.$call(\n // @ts-expect-error casting\n ...args\n );\n },\n callEvent: (...args: any): any => {\n return serverRpc.$callEvent(\n // @ts-expect-error casting\n ...args\n );\n },\n callOptional: (...args: any): any => {\n return serverRpc.$callOptional(\n // @ts-expect-error casting\n ...args\n );\n }\n };\n}\n\nconst CONNECTION_AUTH_TOKEN_KEY = \"__DEVTOOLS_CONNECTION_AUTH_TOKEN__\";\n\nexport function createRpcClient(options: RpcClientOptions) {\n const baseURL = new StormURL(options.baseURL);\n\n const cacheManager = new RpcCacheManager({\n functions: [],\n ...(typeof options.cacheOptions === \"object\" ? options.cacheOptions : {})\n });\n const context: RpcContext = {\n rpc: undefined!\n };\n\n const clientRpc: DevToolsClientRpcHost = new RpcFunctionsCollectorBase<\n RpcClientFunctions,\n RpcContext\n >(context);\n\n EventEmitter.setMaxListeners(100);\n const events = createEventEmitter<RpcClientEvents>();\n\n const mode = createWsRpcClientMode(\n baseURL,\n options.connection,\n events,\n clientRpc,\n undefined,\n {\n ...options.rpcOptions,\n async onRequest(req, next, resolve) {\n await options.rpcOptions?.onRequest?.call(this, req, next, resolve);\n if (options.cacheOptions && cacheManager?.validate(req.m)) {\n const cached = cacheManager.cached(req.m, req.a);\n if (cached) {\n return resolve(cached);\n } else {\n const res = await next(req);\n cacheManager?.apply(req, res);\n }\n } else {\n await next(req);\n }\n }\n },\n options.wsOptions\n );\n\n const rpc: RpcClient = {\n events,\n get isTrusted() {\n return mode.isTrusted;\n },\n connectionMeta: options.connection,\n ensureTrusted: mode.ensureTrusted,\n requestTrust: mode.requestTrust,\n requestTrustWithToken: async (token: string) => {\n // Update stored token for future reconnections\n localStorage.setItem(CONNECTION_AUTH_TOKEN_KEY, token);\n (globalThis as any)[CONNECTION_AUTH_TOKEN_KEY] = token;\n return mode.requestTrustWithToken(token);\n },\n call: mode.call,\n callEvent: mode.callEvent,\n callOptional: mode.callOptional,\n client: clientRpc,\n sharedState: undefined!,\n streaming: undefined!,\n cacheManager\n };\n\n // rpc.sharedState = createRpcSharedStateClientHost(rpc);\n rpc.streaming = createRpcStreamingClientHost(rpc);\n\n // @ts-expect-error assign to readonly property\n context.rpc = rpc;\n void mode.requestTrust();\n\n // Listen for auth updates from other tabs (e.g., auth URL page)\n try {\n const bc = new BroadcastChannel(\"vite-devtools-auth\");\n bc.onmessage = event => {\n if (event.data?.type === \"auth-update\" && event.data.authToken) {\n void rpc.requestTrustWithToken(event.data.authToken);\n }\n };\n } catch {\n // BroadcastChannel is not supported in all environments, so we can safely ignore errors here\n }\n\n return rpc;\n}\n"],"mappings":";;;;;;;;;;;;;AAkDA,SAAS,sBACP,SACA,g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AACjD,UAAO,KAAK,sBAAsB,MAAM;;EAE1C,MAAM,KAAK;EACX,WAAW,KAAK;EAChB,cAAc,KAAK;EACnB,QAAQ;EACR,aAAa;EACb,WAAW;EACX;EACD;AAGD,KAAI,YAAY,6BAA6B,IAAI;AAGjD,SAAQ,MAAM;AACd,CAAK,KAAK,cAAc;AAGxB,KAAI;EACF,MAAM,KAAK,IAAI,iBAAiB,qBAAqB;AACrD,KAAG,aAAY,UAAS;AACtB,OAAI,MAAM,MAAM,SAAS,iBAAiB,MAAM,KAAK,UACnD,CAAK,IAAI,sBAAsB,MAAM,KAAK,UAAU;;SAGlD;AAIR,QAAO"}
|
|
1
|
+
{"version":3,"file":"rpc.mjs","names":["createDevframeRpcClient"],"sources":["../../src/helpers/rpc.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { createEventEmitter } from \"@powerlines/core/lib/events\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { StormURL } from \"@stryke/url\";\nimport { BirpcOptions } from \"birpc\";\nimport {\n createRpcStreamingClientHost,\n DevToolsClientRpcHost,\n DevToolsRpcClientMode,\n RpcClientEvents\n} from \"devframe/client\";\nimport { RpcCacheManager, RpcFunctionsCollectorBase } from \"devframe/rpc\";\nimport { createRpcClient as createDevframeRpcClient } from \"devframe/rpc/client\";\nimport {\n createWsRpcChannel,\n WsRpcChannelOptions\n} from \"devframe/rpc/transports/ws-client\";\nimport {\n ConnectionMeta,\n EventEmitter as DevFrameEventEmitter\n} from \"devframe/types\";\nimport { promiseWithResolver } from \"devframe/utils/promise\";\nimport { humanId } from \"human-id\";\nimport { EventEmitter } from \"node:events\";\nimport { RpcClientOptions } from \"../types/config\";\nimport {\n RpcClient,\n RpcClientFunctions,\n RpcContext,\n RpcServerFunctions\n} from \"../types/rpc\";\n\nfunction createWsRpcClientMode(\n baseURL: StormURL,\n connectionMeta: ConnectionMeta,\n events: DevFrameEventEmitter<RpcClientEvents>,\n clientRpc: DevToolsClientRpcHost,\n authToken: string = humanId({ separator: \"-\", capitalize: false }),\n rpcOptions: Partial<\n BirpcOptions<RpcServerFunctions, RpcClientFunctions, boolean>\n > = {},\n wsOptions: Partial<WsRpcChannelOptions> = {}\n): DevToolsRpcClientMode {\n let isTrusted = false;\n const trustedPromise = promiseWithResolver<boolean>();\n const url =\n isNumber(connectionMeta.websocket) ||\n (isSet(connectionMeta.websocket) &&\n `${+connectionMeta.websocket}` === `${connectionMeta.websocket}`)\n ? `${baseURL.protocol.replace(\"http\", \"ws\")}//${baseURL.hostname}:${connectionMeta.websocket}`\n : (connectionMeta.websocket as string);\n\n // Build a minimal `defs` map from the connection meta so the per-call\n // wire serializer dispatches outgoing requests with the correct\n // encoding (JSON for `jsonSerializable: true` methods; structured-\n // clone for the rest).\n const definitions = new Map<string, { jsonSerializable: true }>();\n for (const name of connectionMeta.jsonSerializableMethods ?? [])\n definitions.set(name, { jsonSerializable: true });\n\n const serverRpc = createDevframeRpcClient<\n RpcServerFunctions,\n RpcClientFunctions\n >(clientRpc.functions, {\n channel: createWsRpcChannel({\n url,\n authToken,\n definitions,\n ...wsOptions\n }),\n rpcOptions\n });\n\n // Handle server-initiated auth revocation\n clientRpc.register({\n name: \"devframe:auth:revoked\",\n type: \"event\",\n handler: () => {\n isTrusted = false;\n events.emit(\"rpc:is-trusted:updated\", false);\n }\n });\n\n let currentAuthToken = authToken;\n\n async function requestTrustWithToken(token: string) {\n currentAuthToken = token;\n\n // const info = parseUA(navigator.userAgent);\n // const ua = [\n // \"powerlines\",\n // \"1.0\",\n // \"|\",\n // info.os.name,\n // info.os.version,\n // info.device.type\n // ]\n // .filter(i => i)\n // .join(\" \");\n\n // const result = await serverRpc.$call(\"vite:anonymous:auth\", {\n // authToken: token,\n // ua,\n // origin: baseURL.origin\n // });\n\n // isTrusted = result.isTrusted;\n // trustedPromise.resolve(isTrusted);\n // events.emit(\"rpc:is-trusted:updated\", isTrusted);\n // return result.isTrusted;\n\n return true;\n }\n\n async function requestTrust() {\n if (isTrusted) return true;\n return requestTrustWithToken(currentAuthToken);\n }\n\n async function ensureTrusted(timeout = 60_000): Promise<boolean> {\n if (isTrusted) trustedPromise.resolve(true);\n\n if (timeout <= 0) return trustedPromise.promise;\n\n let clear = () => {};\n await Promise.race([\n trustedPromise.promise.then(clear),\n new Promise((resolve, reject) => {\n const id = setTimeout(() => {\n reject(new Error(\"Timeout waiting for rpc to be trusted\"));\n }, timeout);\n clear = () => clearTimeout(id);\n })\n ]);\n\n return isTrusted;\n }\n\n return {\n get isTrusted() {\n return isTrusted;\n },\n requestTrust,\n requestTrustWithToken,\n ensureTrusted,\n call: (...args: any): any => {\n return serverRpc.$call(\n // @ts-expect-error casting\n ...args\n );\n },\n callEvent: (...args: any): any => {\n return serverRpc.$callEvent(\n // @ts-expect-error casting\n ...args\n );\n },\n callOptional: (...args: any): any => {\n return serverRpc.$callOptional(\n // @ts-expect-error casting\n ...args\n );\n }\n };\n}\n\nconst CONNECTION_AUTH_TOKEN_KEY = \"__DEVTOOLS_CONNECTION_AUTH_TOKEN__\";\n\nexport function createRpcClient(options: RpcClientOptions) {\n const baseURL = new StormURL(options.baseURL);\n\n const cacheManager = new RpcCacheManager({\n functions: [],\n ...(typeof options.cacheOptions === \"object\" ? options.cacheOptions : {})\n });\n const context: RpcContext = {\n rpc: undefined!\n };\n\n const clientRpc: DevToolsClientRpcHost = new RpcFunctionsCollectorBase<\n RpcClientFunctions,\n RpcContext\n >(context);\n\n EventEmitter.setMaxListeners(100);\n const events = createEventEmitter<RpcClientEvents>();\n\n const mode = createWsRpcClientMode(\n baseURL,\n options.connection,\n events,\n clientRpc,\n undefined,\n {\n ...options.rpcOptions,\n async onRequest(req, next, resolve) {\n await options.rpcOptions?.onRequest?.call(this, req, next, resolve);\n if (options.cacheOptions && cacheManager?.validate(req.m)) {\n const cached = cacheManager.cached(req.m, req.a);\n if (cached) {\n return resolve(cached);\n } else {\n const res = await next(req);\n cacheManager?.apply(req, res);\n }\n } else {\n await next(req);\n }\n }\n },\n options.wsOptions\n );\n\n const rpc: RpcClient = {\n events,\n get isTrusted() {\n return mode.isTrusted;\n },\n connectionMeta: options.connection,\n ensureTrusted: mode.ensureTrusted,\n requestTrust: mode.requestTrust,\n requestTrustWithToken: async (token: string) => {\n // Update stored token for future reconnections\n localStorage.setItem(CONNECTION_AUTH_TOKEN_KEY, token);\n (globalThis as any)[CONNECTION_AUTH_TOKEN_KEY] = token;\n return mode.requestTrustWithToken(token);\n },\n call: mode.call,\n callEvent: mode.callEvent,\n callOptional: mode.callOptional,\n client: clientRpc,\n sharedState: undefined!,\n streaming: undefined!,\n cacheManager\n };\n\n // rpc.sharedState = createRpcSharedStateClientHost(rpc);\n rpc.streaming = createRpcStreamingClientHost(rpc);\n\n // @ts-expect-error assign to readonly property\n context.rpc = rpc;\n void mode.requestTrust();\n\n // Listen for auth updates from other tabs (e.g., auth URL page)\n try {\n const bc = new BroadcastChannel(\"vite-devtools-auth\");\n bc.onmessage = event => {\n if (event.data?.type === \"auth-update\" && event.data.authToken) {\n void rpc.requestTrustWithToken(event.data.authToken);\n }\n };\n } catch {\n // BroadcastChannel is not supported in all environments, so we can safely ignore errors here\n }\n\n return rpc;\n}\n"],"mappings":";;;;;;;;;;;;;AAkDA,SAAS,sBACP,SACA,gBACA,QACA,WACA,YAAoB,QAAQ;CAAE,WAAW;CAAK,YAAY;AAAM,CAAC,GACjE,aAEI,CAAC,GACL,YAA0C,CAAC,GACpB;CACvB,IAAI,YAAY;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cAAc,KAAK;EACnB,QAAQ;EACR,aAAa;EACb,WAAW;EACX;CACF;CAGA,IAAI,YAAY,6BAA6B,GAAG;CAGhD,QAAQ,MAAM;CACd,AAAK,KAAK,aAAa;CAGvB,IAAI;EACF,MAAM,KAAK,IAAI,iBAAiB,oBAAoB;EACpD,GAAG,aAAY,UAAS;GACtB,IAAI,MAAM,MAAM,SAAS,iBAAiB,MAAM,KAAK,WACnD,AAAK,IAAI,sBAAsB,MAAM,KAAK,SAAS;EAEvD;CACF,QAAQ,CAER;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_chunk = require('../chunk-C0xms8kb.cjs');
|
|
3
|
+
let node_stream = require("node:stream");
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/stream.ts
|
|
6
|
+
const kPort = Symbol("kPort");
|
|
7
|
+
function toTransferable(chunk) {
|
|
8
|
+
if (ArrayBuffer.isView(chunk)) return chunk.buffer instanceof ArrayBuffer ? chunk.buffer : void 0;
|
|
9
|
+
if (chunk instanceof ArrayBuffer) return chunk;
|
|
10
|
+
}
|
|
11
|
+
var MessagePortWritable = class extends node_stream.Writable {
|
|
12
|
+
[kPort];
|
|
13
|
+
constructor(port, options) {
|
|
14
|
+
super(options);
|
|
15
|
+
this[kPort] = port;
|
|
16
|
+
}
|
|
17
|
+
_write(chunk, _encoding, callback) {
|
|
18
|
+
const transfer = toTransferable(chunk);
|
|
19
|
+
this[kPort].postMessage(chunk, transfer ? [transfer] : []);
|
|
20
|
+
callback();
|
|
21
|
+
}
|
|
22
|
+
_writev(data, callback) {
|
|
23
|
+
const chunks = data.map((entry) => entry.chunk);
|
|
24
|
+
const transfers = data.map((entry) => toTransferable(entry.chunk)).filter((value) => Boolean(value));
|
|
25
|
+
this[kPort].postMessage(chunks, transfers);
|
|
26
|
+
callback();
|
|
27
|
+
}
|
|
28
|
+
_final(callback) {
|
|
29
|
+
this[kPort].postMessage(null);
|
|
30
|
+
callback();
|
|
31
|
+
}
|
|
32
|
+
_destroy(error, callback) {
|
|
33
|
+
this[kPort].close(() => callback(error));
|
|
34
|
+
}
|
|
35
|
+
unref() {
|
|
36
|
+
this[kPort].unref();
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
ref() {
|
|
40
|
+
this[kPort].ref();
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var MessagePortReadable = class extends node_stream.Readable {
|
|
45
|
+
[kPort];
|
|
46
|
+
constructor(port, options) {
|
|
47
|
+
super(options);
|
|
48
|
+
this[kPort] = port;
|
|
49
|
+
port.onmessage = ({ data }) => {
|
|
50
|
+
this.push(data);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
_read(_size) {
|
|
54
|
+
this[kPort].start();
|
|
55
|
+
}
|
|
56
|
+
_destroy(error, callback) {
|
|
57
|
+
this[kPort].close(() => {
|
|
58
|
+
this[kPort].onmessage = null;
|
|
59
|
+
callback(error);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
unref() {
|
|
63
|
+
this[kPort].unref();
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
ref() {
|
|
67
|
+
this[kPort].ref();
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var MessagePortDuplex = class extends node_stream.Duplex {
|
|
72
|
+
[kPort];
|
|
73
|
+
_activityAbortHandler;
|
|
74
|
+
constructor(port, options) {
|
|
75
|
+
super(options);
|
|
76
|
+
this[kPort] = port;
|
|
77
|
+
this._activityAbortHandler = options?.onActivityAbort;
|
|
78
|
+
port.onmessage = ({ data }) => {
|
|
79
|
+
this.push(data);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
_read(_size) {
|
|
83
|
+
this[kPort].start();
|
|
84
|
+
}
|
|
85
|
+
_write(chunk, _encoding, callback) {
|
|
86
|
+
if (this._activityAbortHandler) this._activityAbortHandler();
|
|
87
|
+
const transfer = toTransferable(chunk);
|
|
88
|
+
this[kPort].postMessage(chunk, transfer ? [transfer] : []);
|
|
89
|
+
callback();
|
|
90
|
+
}
|
|
91
|
+
_writev(data, callback) {
|
|
92
|
+
const chunks = data.map((entry) => entry.chunk);
|
|
93
|
+
const transfers = data.map((entry) => toTransferable(entry.chunk)).filter((value) => Boolean(value));
|
|
94
|
+
this[kPort].postMessage(chunks, transfers);
|
|
95
|
+
callback();
|
|
96
|
+
}
|
|
97
|
+
_final(callback) {
|
|
98
|
+
this[kPort].postMessage(null);
|
|
99
|
+
callback();
|
|
100
|
+
}
|
|
101
|
+
_destroy(error, callback) {
|
|
102
|
+
this[kPort].close(() => {
|
|
103
|
+
this[kPort].onmessage = null;
|
|
104
|
+
callback(error);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
unref() {
|
|
108
|
+
this[kPort].unref();
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
ref() {
|
|
112
|
+
this[kPort].ref();
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
exports.MessagePortDuplex = MessagePortDuplex;
|
|
119
|
+
exports.MessagePortReadable = MessagePortReadable;
|
|
120
|
+
exports.MessagePortWritable = MessagePortWritable;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Duplex, DuplexOptions, Readable, ReadableOptions, Writable, WritableOptions } from "node:stream";
|
|
2
|
+
import { MessagePort } from "node:worker_threads";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers/stream.d.ts
|
|
5
|
+
declare const kPort: unique symbol;
|
|
6
|
+
interface WritevChunk {
|
|
7
|
+
chunk: unknown;
|
|
8
|
+
encoding: BufferEncoding;
|
|
9
|
+
}
|
|
10
|
+
declare class MessagePortWritable extends Writable {
|
|
11
|
+
private [kPort];
|
|
12
|
+
constructor(port: MessagePort, options?: WritableOptions);
|
|
13
|
+
_write(chunk: unknown, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
14
|
+
_writev(data: WritevChunk[], callback: (error?: Error | null) => void): void;
|
|
15
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
16
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
17
|
+
unref(): this;
|
|
18
|
+
ref(): this;
|
|
19
|
+
}
|
|
20
|
+
declare class MessagePortReadable extends Readable {
|
|
21
|
+
private [kPort];
|
|
22
|
+
constructor(port: MessagePort, options?: ReadableOptions);
|
|
23
|
+
_read(_size: number): void;
|
|
24
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
25
|
+
unref(): this;
|
|
26
|
+
ref(): this;
|
|
27
|
+
}
|
|
28
|
+
interface MessagePortDuplexOptions extends DuplexOptions {
|
|
29
|
+
onActivityAbort?: () => void;
|
|
30
|
+
}
|
|
31
|
+
declare class MessagePortDuplex extends Duplex {
|
|
32
|
+
private [kPort];
|
|
33
|
+
private _activityAbortHandler?;
|
|
34
|
+
constructor(port: MessagePort, options?: MessagePortDuplexOptions);
|
|
35
|
+
_read(_size: number): void;
|
|
36
|
+
_write(chunk: unknown, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
37
|
+
_writev(data: WritevChunk[], callback: (error?: Error | null) => void): void;
|
|
38
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
39
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
40
|
+
unref(): this;
|
|
41
|
+
ref(): this;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { MessagePortDuplex, MessagePortDuplexOptions, MessagePortReadable, MessagePortWritable };
|
|
45
|
+
//# sourceMappingURL=stream.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.cts","names":[],"sources":["../../src/helpers/stream.ts"],"mappings":";;;;cA0BM,KAAA;AAAA,UAMI,WAAA;EACR,KAAA;EACA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|
+
import { Duplex, DuplexOptions, Readable, ReadableOptions, Writable, WritableOptions } from "node:stream";
|
|
2
|
+
import { MessagePort } from "node:worker_threads";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers/stream.d.ts
|
|
5
|
+
declare const kPort: unique symbol;
|
|
6
|
+
interface WritevChunk {
|
|
7
|
+
chunk: unknown;
|
|
8
|
+
encoding: BufferEncoding;
|
|
9
|
+
}
|
|
10
|
+
declare class MessagePortWritable extends Writable {
|
|
11
|
+
private [kPort];
|
|
12
|
+
constructor(port: MessagePort, options?: WritableOptions);
|
|
13
|
+
_write(chunk: unknown, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
14
|
+
_writev(data: WritevChunk[], callback: (error?: Error | null) => void): void;
|
|
15
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
16
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
17
|
+
unref(): this;
|
|
18
|
+
ref(): this;
|
|
19
|
+
}
|
|
20
|
+
declare class MessagePortReadable extends Readable {
|
|
21
|
+
private [kPort];
|
|
22
|
+
constructor(port: MessagePort, options?: ReadableOptions);
|
|
23
|
+
_read(_size: number): void;
|
|
24
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
25
|
+
unref(): this;
|
|
26
|
+
ref(): this;
|
|
27
|
+
}
|
|
28
|
+
interface MessagePortDuplexOptions extends DuplexOptions {
|
|
29
|
+
onActivityAbort?: () => void;
|
|
30
|
+
}
|
|
31
|
+
declare class MessagePortDuplex extends Duplex {
|
|
32
|
+
private [kPort];
|
|
33
|
+
private _activityAbortHandler?;
|
|
34
|
+
constructor(port: MessagePort, options?: MessagePortDuplexOptions);
|
|
35
|
+
_read(_size: number): void;
|
|
36
|
+
_write(chunk: unknown, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
37
|
+
_writev(data: WritevChunk[], callback: (error?: Error | null) => void): void;
|
|
38
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
39
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
40
|
+
unref(): this;
|
|
41
|
+
ref(): this;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { MessagePortDuplex, MessagePortDuplexOptions, MessagePortReadable, MessagePortWritable };
|
|
45
|
+
//# sourceMappingURL=stream.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.mts","names":[],"sources":["../../src/helpers/stream.ts"],"mappings":";;;;cA0BM,KAAA;AAAA,UAMI,WAAA;EACR,KAAA;EACA,QAAA,EAAU,cAAc;AAAA;AAAA,cAeb,mBAAA,SAA4B,QAAA;EAAA,SAC9B,KAAA;cAEU,IAAA,EAAM,WAAA,EAAa,OAAA,GAAU,eAAA;EAKhC,MAAA,CACd,KAAA,WACA,SAAA,EAAW,cAAA,EACX,QAAA,GAAW,KAAA,GAAQ,KAAA;EAOL,OAAA,CACd,IAAA,EAAM,WAAA,IACN,QAAA,GAAW,KAAA,GAAQ,KAAA;EAWL,MAAA,CAAO,QAAA,GAAW,KAAA,GAAQ,KAAA;EAK1B,QAAA,CACd,KAAA,EAAO,KAAA,SACP,QAAA,GAAW,KAAA,GAAQ,KAAA;EAKd,KAAA,CAAA;EAKA,GAAA,CAAA;AAAA;AAAA,cAMI,mBAAA,SAA4B,QAAA;EAAA,SAC9B,KAAA;cAEU,IAAA,EAAM,WAAA,EAAa,OAAA,GAAU,eAAA;EAQhC,KAAA,CAAM,KAAA;EAIN,QAAA,CACd,KAAA,EAAO,KAAA,SACP,QAAA,GAAW,KAAA,GAAQ,KAAA;EAQd,KAAA,CAAA;EAKA,GAAA,CAAA;AAAA;AAAA,UAMQ,wBAAA,SAAiC,aAAa;EAC7D,eAAe;AAAA;AAAA,cAGJ,iBAAA,SAA0B,MAAA;EAAA,SAC5B,KAAA;EAAA,QAED,qBAAA;cAEW,IAAA,EAAM,WAAA,EAAa,OAAA,GAAU,wBAAA;EAUhC,KAAA,CAAM,K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