@fluidgrids/workflows 0.0.0-stage → 2026.1027.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/LICENSE +9 -0
- package/README.md +187 -2
- package/dist/assemble-BJo9TECS.d.cts +569 -0
- package/dist/assemble-DMOuaxRI.d.ts +569 -0
- package/dist/chunk-265J2FCH.cjs +33 -0
- package/dist/chunk-27HASETB.cjs +250 -0
- package/dist/chunk-4DPEGDPW.js +74 -0
- package/dist/chunk-5LUIDMF4.js +42 -0
- package/dist/chunk-AU3YW7FZ.cjs +279 -0
- package/dist/chunk-BWSLWF2E.js +722 -0
- package/dist/chunk-BYJ7QTLY.cjs +76 -0
- package/dist/chunk-G4UEPUGO.cjs +46 -0
- package/dist/chunk-GO34UHSY.js +95 -0
- package/dist/chunk-IZQNUNSU.cjs +931 -0
- package/dist/chunk-KUTMY2IO.cjs +745 -0
- package/dist/chunk-LMX35GNQ.js +893 -0
- package/dist/chunk-LRM6JXJA.cjs +181 -0
- package/dist/chunk-LSKSBVL4.cjs +102 -0
- package/dist/chunk-LUXCXFOE.cjs +269 -0
- package/dist/chunk-PL73GJR4.js +174 -0
- package/dist/chunk-REV7ZOA4.js +170 -0
- package/dist/chunk-RRQ5HOBF.cjs +185 -0
- package/dist/chunk-S34NJE3A.js +262 -0
- package/dist/chunk-SRQRLWOS.js +31 -0
- package/dist/chunk-SS4LT2IP.js +268 -0
- package/dist/chunk-X4HKU3MX.js +244 -0
- package/dist/codegen/index.cjs +18 -0
- package/dist/codegen/index.d.cts +15 -0
- package/dist/codegen/index.d.ts +15 -0
- package/dist/codegen/index.js +5 -0
- package/dist/expressions-DhHaqyar.d.cts +62 -0
- package/dist/expressions-DhHaqyar.d.ts +62 -0
- package/dist/hash-CZkTXPCX.d.cts +15 -0
- package/dist/hash-CZkTXPCX.d.ts +15 -0
- package/dist/index.cjs +117 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +4 -0
- package/dist/ir/index.cjs +1244 -0
- package/dist/ir/index.d.cts +828 -0
- package/dist/ir/index.d.ts +828 -0
- package/dist/ir/index.js +1120 -0
- package/dist/lower-DcOY8ux0.d.cts +49 -0
- package/dist/lower-Dw5grNrI.d.ts +49 -0
- package/dist/manifest-Bp9ZJlav.d.ts +60 -0
- package/dist/manifest-Duf-gHdO.d.cts +60 -0
- package/dist/node-evaluator-2GTUZVPK.cjs +17 -0
- package/dist/node-evaluator-RMYEWCXZ.js +8 -0
- package/dist/quickjs/index.cjs +92 -0
- package/dist/quickjs/index.d.cts +18 -0
- package/dist/quickjs/index.d.ts +18 -0
- package/dist/quickjs/index.js +90 -0
- package/dist/roundtrip/index.cjs +1375 -0
- package/dist/roundtrip/index.d.cts +287 -0
- package/dist/roundtrip/index.d.ts +287 -0
- package/dist/roundtrip/index.js +1328 -0
- package/dist/types-Dr2Fn1Ax.d.cts +225 -0
- package/dist/types-Dr2Fn1Ax.d.ts +225 -0
- package/package.json +117 -4
- package/schema/ir-v2.schema.json +655 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import { S as SourceFile } from './hash-CZkTXPCX.cjs';
|
|
3
|
+
import { W as WorkflowDefinition } from './types-Dr2Fn1Ax.cjs';
|
|
4
|
+
import { h as ConnectionResolver } from './assemble-BJo9TECS.cjs';
|
|
5
|
+
|
|
6
|
+
/** The esbuild API surface lower() uses (`esbuild` or `esbuild-wasm`, version 0.28.2). */
|
|
7
|
+
type EsbuildApi = Pick<typeof esbuild, 'build' | 'transform'>;
|
|
8
|
+
/** Runs a bundle and returns the string value of its `__fluidgrids` export. */
|
|
9
|
+
interface Evaluator {
|
|
10
|
+
/** `esm`: the bundle as built; `iife`: a script assigning the exports to `__fluidgridsBundle`. */
|
|
11
|
+
readonly format: 'esm' | 'iife';
|
|
12
|
+
evaluate(code: string): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
declare const EVALUATION_GLOBAL = "__fluidgridsBundle";
|
|
15
|
+
declare const ESBUILD_VERSION = "0.28.2";
|
|
16
|
+
declare class LowerError extends Error {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
interface LowerOptions {
|
|
20
|
+
/** Modules to evaluate. Default: every `.ts` file outside `.fluidgrids/`, except tests and declarations. */
|
|
21
|
+
entries?: readonly string[];
|
|
22
|
+
esbuild?: EsbuildApi;
|
|
23
|
+
evaluator?: Evaluator;
|
|
24
|
+
connections?: ConnectionResolver;
|
|
25
|
+
/** Largest JSON the evaluation may return. Default 16 MiB. */
|
|
26
|
+
maxOutputBytes?: number;
|
|
27
|
+
}
|
|
28
|
+
interface LoweredWorkflow {
|
|
29
|
+
key: string;
|
|
30
|
+
module: string;
|
|
31
|
+
exportName: string;
|
|
32
|
+
definition: WorkflowDefinition;
|
|
33
|
+
}
|
|
34
|
+
interface LowerResult {
|
|
35
|
+
/** `sha256:<hex>` of the bundle. */
|
|
36
|
+
buildId: string;
|
|
37
|
+
bundle: string;
|
|
38
|
+
/** `sha256:<hex>` of the source files. */
|
|
39
|
+
sourceHash: string;
|
|
40
|
+
workflows: LoweredWorkflow[];
|
|
41
|
+
}
|
|
42
|
+
/** The default entry modules: workflow sources, not generated clients, tests or declarations. */
|
|
43
|
+
declare function defaultEntries(paths: readonly string[]): string[];
|
|
44
|
+
/** Bundle a project. Exported so services can compute `buildId` without evaluating. */
|
|
45
|
+
declare function bundleProject(files: ReadonlyMap<string, string>, entries: readonly string[], esbuild: EsbuildApi): Promise<string>;
|
|
46
|
+
/** Lower tier-1 sources to IR v2. */
|
|
47
|
+
declare function lower(files: readonly SourceFile[] | Readonly<Record<string, string>>, options?: LowerOptions): Promise<LowerResult>;
|
|
48
|
+
|
|
49
|
+
export { type Evaluator as E, LowerError as L, type EsbuildApi as a, ESBUILD_VERSION as b, EVALUATION_GLOBAL as c, type LowerOptions as d, type LowerResult as e, type LoweredWorkflow as f, bundleProject as g, defaultEntries as h, lower as l };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import { S as SourceFile } from './hash-CZkTXPCX.js';
|
|
3
|
+
import { W as WorkflowDefinition } from './types-Dr2Fn1Ax.js';
|
|
4
|
+
import { h as ConnectionResolver } from './assemble-DMOuaxRI.js';
|
|
5
|
+
|
|
6
|
+
/** The esbuild API surface lower() uses (`esbuild` or `esbuild-wasm`, version 0.28.2). */
|
|
7
|
+
type EsbuildApi = Pick<typeof esbuild, 'build' | 'transform'>;
|
|
8
|
+
/** Runs a bundle and returns the string value of its `__fluidgrids` export. */
|
|
9
|
+
interface Evaluator {
|
|
10
|
+
/** `esm`: the bundle as built; `iife`: a script assigning the exports to `__fluidgridsBundle`. */
|
|
11
|
+
readonly format: 'esm' | 'iife';
|
|
12
|
+
evaluate(code: string): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
declare const EVALUATION_GLOBAL = "__fluidgridsBundle";
|
|
15
|
+
declare const ESBUILD_VERSION = "0.28.2";
|
|
16
|
+
declare class LowerError extends Error {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
interface LowerOptions {
|
|
20
|
+
/** Modules to evaluate. Default: every `.ts` file outside `.fluidgrids/`, except tests and declarations. */
|
|
21
|
+
entries?: readonly string[];
|
|
22
|
+
esbuild?: EsbuildApi;
|
|
23
|
+
evaluator?: Evaluator;
|
|
24
|
+
connections?: ConnectionResolver;
|
|
25
|
+
/** Largest JSON the evaluation may return. Default 16 MiB. */
|
|
26
|
+
maxOutputBytes?: number;
|
|
27
|
+
}
|
|
28
|
+
interface LoweredWorkflow {
|
|
29
|
+
key: string;
|
|
30
|
+
module: string;
|
|
31
|
+
exportName: string;
|
|
32
|
+
definition: WorkflowDefinition;
|
|
33
|
+
}
|
|
34
|
+
interface LowerResult {
|
|
35
|
+
/** `sha256:<hex>` of the bundle. */
|
|
36
|
+
buildId: string;
|
|
37
|
+
bundle: string;
|
|
38
|
+
/** `sha256:<hex>` of the source files. */
|
|
39
|
+
sourceHash: string;
|
|
40
|
+
workflows: LoweredWorkflow[];
|
|
41
|
+
}
|
|
42
|
+
/** The default entry modules: workflow sources, not generated clients, tests or declarations. */
|
|
43
|
+
declare function defaultEntries(paths: readonly string[]): string[];
|
|
44
|
+
/** Bundle a project. Exported so services can compute `buildId` without evaluating. */
|
|
45
|
+
declare function bundleProject(files: ReadonlyMap<string, string>, entries: readonly string[], esbuild: EsbuildApi): Promise<string>;
|
|
46
|
+
/** Lower tier-1 sources to IR v2. */
|
|
47
|
+
declare function lower(files: readonly SourceFile[] | Readonly<Record<string, string>>, options?: LowerOptions): Promise<LowerResult>;
|
|
48
|
+
|
|
49
|
+
export { type Evaluator as E, LowerError as L, type EsbuildApi as a, ESBUILD_VERSION as b, EVALUATION_GLOBAL as c, type LowerOptions as d, type LowerResult as e, type LoweredWorkflow as f, bundleProject as g, defaultEntries as h, lower as l };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { a as JsonObject } from './types-Dr2Fn1Ax.js';
|
|
2
|
+
|
|
3
|
+
/** One input or output field. Output fields may also be a bare type name. */
|
|
4
|
+
interface ManifestField {
|
|
5
|
+
type?: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
description?: string;
|
|
8
|
+
default?: unknown;
|
|
9
|
+
items?: unknown;
|
|
10
|
+
options?: unknown[];
|
|
11
|
+
enum?: unknown[];
|
|
12
|
+
properties?: Record<string, unknown>;
|
|
13
|
+
format?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
interface ManifestOperation {
|
|
17
|
+
name: string;
|
|
18
|
+
type?: string;
|
|
19
|
+
role?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
input_fields?: Record<string, ManifestField>;
|
|
22
|
+
output_fields?: Record<string, ManifestField | string>;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** A handle a node card renders (static list or derived from node state). */
|
|
26
|
+
type ManifestHandles = Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
label?: string;
|
|
29
|
+
}> | {
|
|
30
|
+
fromStateRecord: string;
|
|
31
|
+
extra?: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
interface NodeManifest {
|
|
36
|
+
nodeType: string;
|
|
37
|
+
nodeVersion?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
kind?: string[];
|
|
40
|
+
operations: ManifestOperation[] | {
|
|
41
|
+
operations: ManifestOperation[];
|
|
42
|
+
outputHandles?: ManifestHandles;
|
|
43
|
+
inputHandles?: ManifestHandles;
|
|
44
|
+
};
|
|
45
|
+
outputHandles?: ManifestHandles;
|
|
46
|
+
inputHandles?: ManifestHandles;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/** The operations of a manifest, whichever form the registry returned. */
|
|
50
|
+
declare function operationsOf(manifest: NodeManifest): ManifestOperation[];
|
|
51
|
+
/** True when the operation starts a workflow. */
|
|
52
|
+
declare function isTriggerOperation(operation: ManifestOperation): boolean;
|
|
53
|
+
/** A JSON Schema for one manifest field. */
|
|
54
|
+
declare function fieldSchema(value: ManifestField | string | unknown): JsonObject;
|
|
55
|
+
/** A JSON Schema object for a set of fields (`input_fields` / `output_fields`). */
|
|
56
|
+
declare function fieldsSchema(fields: Record<string, ManifestField | string> | undefined): JsonObject;
|
|
57
|
+
/** Find the manifest of a node type (the highest version when several are given). */
|
|
58
|
+
declare function findManifest(manifests: readonly NodeManifest[], nodeType: string): NodeManifest | undefined;
|
|
59
|
+
|
|
60
|
+
export { type ManifestField as M, type NodeManifest as N, type ManifestHandles as a, type ManifestOperation as b, fieldsSchema as c, findManifest as d, fieldSchema as f, isTriggerOperation as i, operationsOf as o };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { a as JsonObject } from './types-Dr2Fn1Ax.cjs';
|
|
2
|
+
|
|
3
|
+
/** One input or output field. Output fields may also be a bare type name. */
|
|
4
|
+
interface ManifestField {
|
|
5
|
+
type?: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
description?: string;
|
|
8
|
+
default?: unknown;
|
|
9
|
+
items?: unknown;
|
|
10
|
+
options?: unknown[];
|
|
11
|
+
enum?: unknown[];
|
|
12
|
+
properties?: Record<string, unknown>;
|
|
13
|
+
format?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
interface ManifestOperation {
|
|
17
|
+
name: string;
|
|
18
|
+
type?: string;
|
|
19
|
+
role?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
input_fields?: Record<string, ManifestField>;
|
|
22
|
+
output_fields?: Record<string, ManifestField | string>;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** A handle a node card renders (static list or derived from node state). */
|
|
26
|
+
type ManifestHandles = Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
label?: string;
|
|
29
|
+
}> | {
|
|
30
|
+
fromStateRecord: string;
|
|
31
|
+
extra?: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
interface NodeManifest {
|
|
36
|
+
nodeType: string;
|
|
37
|
+
nodeVersion?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
kind?: string[];
|
|
40
|
+
operations: ManifestOperation[] | {
|
|
41
|
+
operations: ManifestOperation[];
|
|
42
|
+
outputHandles?: ManifestHandles;
|
|
43
|
+
inputHandles?: ManifestHandles;
|
|
44
|
+
};
|
|
45
|
+
outputHandles?: ManifestHandles;
|
|
46
|
+
inputHandles?: ManifestHandles;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/** The operations of a manifest, whichever form the registry returned. */
|
|
50
|
+
declare function operationsOf(manifest: NodeManifest): ManifestOperation[];
|
|
51
|
+
/** True when the operation starts a workflow. */
|
|
52
|
+
declare function isTriggerOperation(operation: ManifestOperation): boolean;
|
|
53
|
+
/** A JSON Schema for one manifest field. */
|
|
54
|
+
declare function fieldSchema(value: ManifestField | string | unknown): JsonObject;
|
|
55
|
+
/** A JSON Schema object for a set of fields (`input_fields` / `output_fields`). */
|
|
56
|
+
declare function fieldsSchema(fields: Record<string, ManifestField | string> | undefined): JsonObject;
|
|
57
|
+
/** Find the manifest of a node type (the highest version when several are given). */
|
|
58
|
+
declare function findManifest(manifests: readonly NodeManifest[], nodeType: string): NodeManifest | undefined;
|
|
59
|
+
|
|
60
|
+
export { type ManifestField as M, type NodeManifest as N, type ManifestHandles as a, type ManifestOperation as b, fieldsSchema as c, findManifest as d, fieldSchema as f, isTriggerOperation as i, operationsOf as o };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk265J2FCH_cjs = require('./chunk-265J2FCH.cjs');
|
|
4
|
+
require('./chunk-LUXCXFOE.cjs');
|
|
5
|
+
require('./chunk-KUTMY2IO.cjs');
|
|
6
|
+
require('./chunk-AU3YW7FZ.cjs');
|
|
7
|
+
require('./chunk-G4UEPUGO.cjs');
|
|
8
|
+
require('./chunk-RRQ5HOBF.cjs');
|
|
9
|
+
require('./chunk-27HASETB.cjs');
|
|
10
|
+
require('./chunk-LRM6JXJA.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Object.defineProperty(exports, "createNodeVmEvaluator", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return chunk265J2FCH_cjs.createNodeVmEvaluator; }
|
|
17
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createNodeVmEvaluator } from './chunk-SRQRLWOS.js';
|
|
2
|
+
import './chunk-S34NJE3A.js';
|
|
3
|
+
import './chunk-BWSLWF2E.js';
|
|
4
|
+
import './chunk-SS4LT2IP.js';
|
|
5
|
+
import './chunk-5LUIDMF4.js';
|
|
6
|
+
import './chunk-PL73GJR4.js';
|
|
7
|
+
import './chunk-X4HKU3MX.js';
|
|
8
|
+
import './chunk-REV7ZOA4.js';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLUXCXFOE_cjs = require('../chunk-LUXCXFOE.cjs');
|
|
4
|
+
require('../chunk-KUTMY2IO.cjs');
|
|
5
|
+
require('../chunk-AU3YW7FZ.cjs');
|
|
6
|
+
require('../chunk-G4UEPUGO.cjs');
|
|
7
|
+
require('../chunk-RRQ5HOBF.cjs');
|
|
8
|
+
require('../chunk-27HASETB.cjs');
|
|
9
|
+
require('../chunk-LRM6JXJA.cjs');
|
|
10
|
+
var quickjsEmscripten = require('quickjs-emscripten');
|
|
11
|
+
|
|
12
|
+
var WASM_PAGE_BYTES = 64 * 1024;
|
|
13
|
+
var ENGINE_HEADROOM_BYTES = 32 * 1024 * 1024;
|
|
14
|
+
var INITIAL_ENGINE_BYTES = 16 * 1024 * 1024;
|
|
15
|
+
function errorMessage(ctx, handle) {
|
|
16
|
+
const dumped = ctx.dump(handle);
|
|
17
|
+
if (typeof dumped === "object" && dumped !== null && "message" in dumped)
|
|
18
|
+
return String(dumped.message);
|
|
19
|
+
return String(dumped);
|
|
20
|
+
}
|
|
21
|
+
function createQuickJSEvaluator(options = {}) {
|
|
22
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
23
|
+
const memoryLimitBytes = options.memoryLimitBytes ?? 64 * 1024 * 1024;
|
|
24
|
+
const maxStackSizeBytes = options.maxStackSizeBytes ?? 1024 * 1024;
|
|
25
|
+
return {
|
|
26
|
+
format: "esm",
|
|
27
|
+
async evaluate(code) {
|
|
28
|
+
const maximum = Math.ceil((memoryLimitBytes + ENGINE_HEADROOM_BYTES) / WASM_PAGE_BYTES);
|
|
29
|
+
const initial = Math.min(maximum, INITIAL_ENGINE_BYTES / WASM_PAGE_BYTES);
|
|
30
|
+
const engine = await quickjsEmscripten.newQuickJSWASMModuleFromVariant(
|
|
31
|
+
quickjsEmscripten.newVariant(quickjsEmscripten.RELEASE_SYNC, { wasmMemory: new WebAssembly.Memory({ initial, maximum }) })
|
|
32
|
+
);
|
|
33
|
+
const runtime = engine.newRuntime();
|
|
34
|
+
const deadline = Date.now() + timeoutMs;
|
|
35
|
+
runtime.setMemoryLimit(memoryLimitBytes);
|
|
36
|
+
runtime.setMaxStackSize(maxStackSizeBytes);
|
|
37
|
+
runtime.setInterruptHandler(quickjsEmscripten.shouldInterruptAfterDeadline(deadline));
|
|
38
|
+
const ctx = runtime.newContext();
|
|
39
|
+
const handles = [];
|
|
40
|
+
try {
|
|
41
|
+
const result = ctx.evalCode(code, "workflow-bundle.mjs", { type: "module" });
|
|
42
|
+
if (result.error) {
|
|
43
|
+
const message = errorMessage(ctx, result.error);
|
|
44
|
+
result.error.dispose();
|
|
45
|
+
throw new chunkLUXCXFOE_cjs.LowerError(`Evaluating the workflow code failed: ${message}`);
|
|
46
|
+
}
|
|
47
|
+
let namespace = result.value;
|
|
48
|
+
handles.push(namespace);
|
|
49
|
+
const state = ctx.getPromiseState(namespace);
|
|
50
|
+
if (!(state.type === "fulfilled" && state.notAPromise === true)) {
|
|
51
|
+
if (state.type === "fulfilled") state.value.dispose();
|
|
52
|
+
else if (state.type === "rejected") state.error.dispose();
|
|
53
|
+
while (runtime.hasPendingJob()) {
|
|
54
|
+
if (Date.now() > deadline)
|
|
55
|
+
throw new chunkLUXCXFOE_cjs.LowerError("Evaluating the workflow code timed out");
|
|
56
|
+
const jobs = runtime.executePendingJobs();
|
|
57
|
+
if (jobs.error) {
|
|
58
|
+
const message = errorMessage(ctx, jobs.error);
|
|
59
|
+
jobs.error.dispose();
|
|
60
|
+
throw new chunkLUXCXFOE_cjs.LowerError(`Evaluating the workflow code failed: ${message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const settled = ctx.getPromiseState(namespace);
|
|
64
|
+
if (settled.type === "rejected") {
|
|
65
|
+
const message = errorMessage(ctx, settled.error);
|
|
66
|
+
settled.error.dispose();
|
|
67
|
+
throw new chunkLUXCXFOE_cjs.LowerError(`Evaluating the workflow code failed: ${message}`);
|
|
68
|
+
}
|
|
69
|
+
if (settled.type === "pending")
|
|
70
|
+
throw new chunkLUXCXFOE_cjs.LowerError("The workflow module never finished evaluating");
|
|
71
|
+
namespace = settled.value;
|
|
72
|
+
handles.push(namespace);
|
|
73
|
+
}
|
|
74
|
+
const exported = ctx.getProp(namespace, "__fluidgrids");
|
|
75
|
+
handles.push(exported);
|
|
76
|
+
if (ctx.typeof(exported) !== "string")
|
|
77
|
+
throw new chunkLUXCXFOE_cjs.LowerError("The bundle did not export a workflow collection");
|
|
78
|
+
return ctx.getString(exported);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof chunkLUXCXFOE_cjs.LowerError) throw error;
|
|
81
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
82
|
+
throw new chunkLUXCXFOE_cjs.LowerError(`Evaluating the workflow code failed: ${message}`);
|
|
83
|
+
} finally {
|
|
84
|
+
for (const handle of handles.reverse()) if (handle.alive) handle.dispose();
|
|
85
|
+
ctx.dispose();
|
|
86
|
+
runtime.dispose();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
exports.createQuickJSEvaluator = createQuickJSEvaluator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { E as Evaluator } from '../lower-DcOY8ux0.cjs';
|
|
2
|
+
import 'esbuild';
|
|
3
|
+
import '../hash-CZkTXPCX.cjs';
|
|
4
|
+
import '../types-Dr2Fn1Ax.cjs';
|
|
5
|
+
import '../assemble-BJo9TECS.cjs';
|
|
6
|
+
|
|
7
|
+
interface QuickJSEvaluatorOptions {
|
|
8
|
+
/** Wall-clock budget. Default 5000 ms. */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
/** Runtime heap cap. Default 64 MiB. */
|
|
11
|
+
memoryLimitBytes?: number;
|
|
12
|
+
/** Native stack cap. Default 1 MiB. */
|
|
13
|
+
maxStackSizeBytes?: number;
|
|
14
|
+
}
|
|
15
|
+
/** An {@link Evaluator} backed by a bounded QuickJS engine. */
|
|
16
|
+
declare function createQuickJSEvaluator(options?: QuickJSEvaluatorOptions): Evaluator;
|
|
17
|
+
|
|
18
|
+
export { type QuickJSEvaluatorOptions, createQuickJSEvaluator };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { E as Evaluator } from '../lower-Dw5grNrI.js';
|
|
2
|
+
import 'esbuild';
|
|
3
|
+
import '../hash-CZkTXPCX.js';
|
|
4
|
+
import '../types-Dr2Fn1Ax.js';
|
|
5
|
+
import '../assemble-DMOuaxRI.js';
|
|
6
|
+
|
|
7
|
+
interface QuickJSEvaluatorOptions {
|
|
8
|
+
/** Wall-clock budget. Default 5000 ms. */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
/** Runtime heap cap. Default 64 MiB. */
|
|
11
|
+
memoryLimitBytes?: number;
|
|
12
|
+
/** Native stack cap. Default 1 MiB. */
|
|
13
|
+
maxStackSizeBytes?: number;
|
|
14
|
+
}
|
|
15
|
+
/** An {@link Evaluator} backed by a bounded QuickJS engine. */
|
|
16
|
+
declare function createQuickJSEvaluator(options?: QuickJSEvaluatorOptions): Evaluator;
|
|
17
|
+
|
|
18
|
+
export { type QuickJSEvaluatorOptions, createQuickJSEvaluator };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { LowerError } from '../chunk-S34NJE3A.js';
|
|
2
|
+
import '../chunk-BWSLWF2E.js';
|
|
3
|
+
import '../chunk-SS4LT2IP.js';
|
|
4
|
+
import '../chunk-5LUIDMF4.js';
|
|
5
|
+
import '../chunk-PL73GJR4.js';
|
|
6
|
+
import '../chunk-X4HKU3MX.js';
|
|
7
|
+
import '../chunk-REV7ZOA4.js';
|
|
8
|
+
import { newQuickJSWASMModuleFromVariant, newVariant, RELEASE_SYNC, shouldInterruptAfterDeadline } from 'quickjs-emscripten';
|
|
9
|
+
|
|
10
|
+
var WASM_PAGE_BYTES = 64 * 1024;
|
|
11
|
+
var ENGINE_HEADROOM_BYTES = 32 * 1024 * 1024;
|
|
12
|
+
var INITIAL_ENGINE_BYTES = 16 * 1024 * 1024;
|
|
13
|
+
function errorMessage(ctx, handle) {
|
|
14
|
+
const dumped = ctx.dump(handle);
|
|
15
|
+
if (typeof dumped === "object" && dumped !== null && "message" in dumped)
|
|
16
|
+
return String(dumped.message);
|
|
17
|
+
return String(dumped);
|
|
18
|
+
}
|
|
19
|
+
function createQuickJSEvaluator(options = {}) {
|
|
20
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
21
|
+
const memoryLimitBytes = options.memoryLimitBytes ?? 64 * 1024 * 1024;
|
|
22
|
+
const maxStackSizeBytes = options.maxStackSizeBytes ?? 1024 * 1024;
|
|
23
|
+
return {
|
|
24
|
+
format: "esm",
|
|
25
|
+
async evaluate(code) {
|
|
26
|
+
const maximum = Math.ceil((memoryLimitBytes + ENGINE_HEADROOM_BYTES) / WASM_PAGE_BYTES);
|
|
27
|
+
const initial = Math.min(maximum, INITIAL_ENGINE_BYTES / WASM_PAGE_BYTES);
|
|
28
|
+
const engine = await newQuickJSWASMModuleFromVariant(
|
|
29
|
+
newVariant(RELEASE_SYNC, { wasmMemory: new WebAssembly.Memory({ initial, maximum }) })
|
|
30
|
+
);
|
|
31
|
+
const runtime = engine.newRuntime();
|
|
32
|
+
const deadline = Date.now() + timeoutMs;
|
|
33
|
+
runtime.setMemoryLimit(memoryLimitBytes);
|
|
34
|
+
runtime.setMaxStackSize(maxStackSizeBytes);
|
|
35
|
+
runtime.setInterruptHandler(shouldInterruptAfterDeadline(deadline));
|
|
36
|
+
const ctx = runtime.newContext();
|
|
37
|
+
const handles = [];
|
|
38
|
+
try {
|
|
39
|
+
const result = ctx.evalCode(code, "workflow-bundle.mjs", { type: "module" });
|
|
40
|
+
if (result.error) {
|
|
41
|
+
const message = errorMessage(ctx, result.error);
|
|
42
|
+
result.error.dispose();
|
|
43
|
+
throw new LowerError(`Evaluating the workflow code failed: ${message}`);
|
|
44
|
+
}
|
|
45
|
+
let namespace = result.value;
|
|
46
|
+
handles.push(namespace);
|
|
47
|
+
const state = ctx.getPromiseState(namespace);
|
|
48
|
+
if (!(state.type === "fulfilled" && state.notAPromise === true)) {
|
|
49
|
+
if (state.type === "fulfilled") state.value.dispose();
|
|
50
|
+
else if (state.type === "rejected") state.error.dispose();
|
|
51
|
+
while (runtime.hasPendingJob()) {
|
|
52
|
+
if (Date.now() > deadline)
|
|
53
|
+
throw new LowerError("Evaluating the workflow code timed out");
|
|
54
|
+
const jobs = runtime.executePendingJobs();
|
|
55
|
+
if (jobs.error) {
|
|
56
|
+
const message = errorMessage(ctx, jobs.error);
|
|
57
|
+
jobs.error.dispose();
|
|
58
|
+
throw new LowerError(`Evaluating the workflow code failed: ${message}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const settled = ctx.getPromiseState(namespace);
|
|
62
|
+
if (settled.type === "rejected") {
|
|
63
|
+
const message = errorMessage(ctx, settled.error);
|
|
64
|
+
settled.error.dispose();
|
|
65
|
+
throw new LowerError(`Evaluating the workflow code failed: ${message}`);
|
|
66
|
+
}
|
|
67
|
+
if (settled.type === "pending")
|
|
68
|
+
throw new LowerError("The workflow module never finished evaluating");
|
|
69
|
+
namespace = settled.value;
|
|
70
|
+
handles.push(namespace);
|
|
71
|
+
}
|
|
72
|
+
const exported = ctx.getProp(namespace, "__fluidgrids");
|
|
73
|
+
handles.push(exported);
|
|
74
|
+
if (ctx.typeof(exported) !== "string")
|
|
75
|
+
throw new LowerError("The bundle did not export a workflow collection");
|
|
76
|
+
return ctx.getString(exported);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof LowerError) throw error;
|
|
79
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
80
|
+
throw new LowerError(`Evaluating the workflow code failed: ${message}`);
|
|
81
|
+
} finally {
|
|
82
|
+
for (const handle of handles.reverse()) if (handle.alive) handle.dispose();
|
|
83
|
+
ctx.dispose();
|
|
84
|
+
runtime.dispose();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { createQuickJSEvaluator };
|