@fluidgrids/workflows 0.0.0-stage → 2026.1027.1
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 +208 -2
- package/dist/assemble-CrpUyd_3.d.ts +587 -0
- package/dist/assemble-DEf3znGD.d.cts +587 -0
- package/dist/chunk-3M34AUIY.cjs +27 -0
- package/dist/chunk-5AW745OG.js +25 -0
- package/dist/chunk-5LUIDMF4.js +42 -0
- package/dist/chunk-6AIAC2FP.cjs +185 -0
- package/dist/chunk-6BEW4QD6.js +95 -0
- package/dist/chunk-6U446SKY.js +263 -0
- package/dist/chunk-7YR7DI7B.cjs +274 -0
- package/dist/chunk-CSYBNN3V.cjs +252 -0
- package/dist/chunk-E3APHA6O.cjs +199 -0
- package/dist/chunk-EEAIM35V.js +748 -0
- package/dist/chunk-G4UEPUGO.cjs +46 -0
- package/dist/chunk-IHKXLG6I.js +246 -0
- package/dist/chunk-MBBKGD7K.js +440 -0
- package/dist/chunk-OSPTJCDI.cjs +102 -0
- package/dist/chunk-TQF7MYEN.cjs +771 -0
- package/dist/chunk-TWOYB4Y7.cjs +76 -0
- package/dist/chunk-UB2BHU2M.js +174 -0
- package/dist/chunk-UJNHTS6D.js +181 -0
- package/dist/chunk-UWQWD7BP.cjs +931 -0
- package/dist/chunk-W32BSO3M.js +74 -0
- package/dist/chunk-XBIID5DY.js +893 -0
- package/dist/chunk-Y7NWR3WH.cjs +450 -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 +1246 -0
- package/dist/ir/index.d.cts +838 -0
- package/dist/ir/index.d.ts +838 -0
- package/dist/ir/index.js +1122 -0
- package/dist/lower-CXggJTIo.d.ts +67 -0
- package/dist/lower-DAzvsJCo.d.cts +67 -0
- package/dist/manifest-Bp9ZJlav.d.ts +60 -0
- package/dist/manifest-Duf-gHdO.d.cts +60 -0
- package/dist/node-evaluator-CH3XCJND.cjs +17 -0
- package/dist/node-evaluator-TULXA3WE.js +8 -0
- package/dist/quickjs/index.cjs +46 -0
- package/dist/quickjs/index.d.cts +18 -0
- package/dist/quickjs/index.d.ts +18 -0
- package/dist/quickjs/index.js +44 -0
- package/dist/roundtrip/index.cjs +1448 -0
- package/dist/roundtrip/index.d.cts +290 -0
- package/dist/roundtrip/index.d.ts +290 -0
- package/dist/roundtrip/index.js +1397 -0
- package/dist/types-Dr2Fn1Ax.d.cts +225 -0
- package/dist/types-Dr2Fn1Ax.d.ts +225 -0
- package/package.json +143 -4
- package/schema/ir-v2.schema.json +655 -0
|
@@ -0,0 +1,67 @@
|
|
|
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-CrpUyd_3.js';
|
|
5
|
+
|
|
6
|
+
/** Why an evaluation produced no collection. */
|
|
7
|
+
type IsolateFailure = 'error' | 'timeout' | 'determinism' | 'no-collection' | 'out-of-memory' | 'crashed';
|
|
8
|
+
|
|
9
|
+
/** The esbuild API surface lower() uses (`esbuild` or `esbuild-wasm`, version 0.28.2). */
|
|
10
|
+
type EsbuildApi = Pick<typeof esbuild, 'build' | 'transform'>;
|
|
11
|
+
/** Runs a bundle and returns the string value of its `__fluidgrids` export. */
|
|
12
|
+
interface Evaluator {
|
|
13
|
+
/** `esm`: the bundle as built; `iife`: a script assigning the exports to `__fluidgridsBundle`. */
|
|
14
|
+
readonly format: 'esm' | 'iife';
|
|
15
|
+
evaluate(code: string): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
declare const EVALUATION_GLOBAL = "__fluidgridsBundle";
|
|
18
|
+
declare const ESBUILD_VERSION = "0.28.2";
|
|
19
|
+
/** Why lowering failed, when the cause is one a caller may want to tell apart. */
|
|
20
|
+
type LowerFailureReason = IsolateFailure | 'too-large';
|
|
21
|
+
declare class LowerError extends Error {
|
|
22
|
+
readonly reason?: LowerFailureReason | undefined;
|
|
23
|
+
constructor(message: string, reason?: LowerFailureReason | undefined);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The workflow code read the clock or a random source while it was defined
|
|
27
|
+
* (`Date.now()`, `new Date()`, `Math.random()`, …), which would make two builds
|
|
28
|
+
* of the same source differ.
|
|
29
|
+
*/
|
|
30
|
+
declare class DeterminismViolationError extends LowerError {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
interface LowerOptions {
|
|
34
|
+
/** Modules to evaluate. Default: every `.ts` file outside `.fluidgrids/`, except tests and declarations. */
|
|
35
|
+
entries?: readonly string[];
|
|
36
|
+
esbuild?: EsbuildApi;
|
|
37
|
+
evaluator?: Evaluator;
|
|
38
|
+
connections?: ConnectionResolver;
|
|
39
|
+
/** Largest JSON the evaluation may return. Default 16 MiB. */
|
|
40
|
+
maxOutputBytes?: number;
|
|
41
|
+
/** Largest total size of the source files, in UTF-8 bytes, checked before esbuild. Default 1 MiB. */
|
|
42
|
+
maxSourceBytes?: number;
|
|
43
|
+
/** Largest bundle, in UTF-8 bytes, checked before evaluation. Default 1.5 MiB. */
|
|
44
|
+
maxBundleBytes?: number;
|
|
45
|
+
}
|
|
46
|
+
interface LoweredWorkflow {
|
|
47
|
+
key: string;
|
|
48
|
+
module: string;
|
|
49
|
+
exportName: string;
|
|
50
|
+
definition: WorkflowDefinition;
|
|
51
|
+
}
|
|
52
|
+
interface LowerResult {
|
|
53
|
+
/** `sha256:<hex>` of the bundle. */
|
|
54
|
+
buildId: string;
|
|
55
|
+
bundle: string;
|
|
56
|
+
/** `sha256:<hex>` of the source files. */
|
|
57
|
+
sourceHash: string;
|
|
58
|
+
workflows: LoweredWorkflow[];
|
|
59
|
+
}
|
|
60
|
+
/** The default entry modules: workflow sources, not generated clients, tests or declarations. */
|
|
61
|
+
declare function defaultEntries(paths: readonly string[]): string[];
|
|
62
|
+
/** Bundle a project. Exported so services can compute `buildId` without evaluating. */
|
|
63
|
+
declare function bundleProject(files: ReadonlyMap<string, string>, entries: readonly string[], esbuild: EsbuildApi): Promise<string>;
|
|
64
|
+
/** Lower tier-1 sources to IR v2. */
|
|
65
|
+
declare function lower(files: readonly SourceFile[] | Readonly<Record<string, string>>, options?: LowerOptions): Promise<LowerResult>;
|
|
66
|
+
|
|
67
|
+
export { DeterminismViolationError as D, type Evaluator as E, LowerError as L, type EsbuildApi as a, ESBUILD_VERSION as b, EVALUATION_GLOBAL as c, type LowerFailureReason as d, type LowerOptions as e, type LowerResult as f, type LoweredWorkflow as g, bundleProject as h, defaultEntries as i, lower as l };
|
|
@@ -0,0 +1,67 @@
|
|
|
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-DEf3znGD.cjs';
|
|
5
|
+
|
|
6
|
+
/** Why an evaluation produced no collection. */
|
|
7
|
+
type IsolateFailure = 'error' | 'timeout' | 'determinism' | 'no-collection' | 'out-of-memory' | 'crashed';
|
|
8
|
+
|
|
9
|
+
/** The esbuild API surface lower() uses (`esbuild` or `esbuild-wasm`, version 0.28.2). */
|
|
10
|
+
type EsbuildApi = Pick<typeof esbuild, 'build' | 'transform'>;
|
|
11
|
+
/** Runs a bundle and returns the string value of its `__fluidgrids` export. */
|
|
12
|
+
interface Evaluator {
|
|
13
|
+
/** `esm`: the bundle as built; `iife`: a script assigning the exports to `__fluidgridsBundle`. */
|
|
14
|
+
readonly format: 'esm' | 'iife';
|
|
15
|
+
evaluate(code: string): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
declare const EVALUATION_GLOBAL = "__fluidgridsBundle";
|
|
18
|
+
declare const ESBUILD_VERSION = "0.28.2";
|
|
19
|
+
/** Why lowering failed, when the cause is one a caller may want to tell apart. */
|
|
20
|
+
type LowerFailureReason = IsolateFailure | 'too-large';
|
|
21
|
+
declare class LowerError extends Error {
|
|
22
|
+
readonly reason?: LowerFailureReason | undefined;
|
|
23
|
+
constructor(message: string, reason?: LowerFailureReason | undefined);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The workflow code read the clock or a random source while it was defined
|
|
27
|
+
* (`Date.now()`, `new Date()`, `Math.random()`, …), which would make two builds
|
|
28
|
+
* of the same source differ.
|
|
29
|
+
*/
|
|
30
|
+
declare class DeterminismViolationError extends LowerError {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
interface LowerOptions {
|
|
34
|
+
/** Modules to evaluate. Default: every `.ts` file outside `.fluidgrids/`, except tests and declarations. */
|
|
35
|
+
entries?: readonly string[];
|
|
36
|
+
esbuild?: EsbuildApi;
|
|
37
|
+
evaluator?: Evaluator;
|
|
38
|
+
connections?: ConnectionResolver;
|
|
39
|
+
/** Largest JSON the evaluation may return. Default 16 MiB. */
|
|
40
|
+
maxOutputBytes?: number;
|
|
41
|
+
/** Largest total size of the source files, in UTF-8 bytes, checked before esbuild. Default 1 MiB. */
|
|
42
|
+
maxSourceBytes?: number;
|
|
43
|
+
/** Largest bundle, in UTF-8 bytes, checked before evaluation. Default 1.5 MiB. */
|
|
44
|
+
maxBundleBytes?: number;
|
|
45
|
+
}
|
|
46
|
+
interface LoweredWorkflow {
|
|
47
|
+
key: string;
|
|
48
|
+
module: string;
|
|
49
|
+
exportName: string;
|
|
50
|
+
definition: WorkflowDefinition;
|
|
51
|
+
}
|
|
52
|
+
interface LowerResult {
|
|
53
|
+
/** `sha256:<hex>` of the bundle. */
|
|
54
|
+
buildId: string;
|
|
55
|
+
bundle: string;
|
|
56
|
+
/** `sha256:<hex>` of the source files. */
|
|
57
|
+
sourceHash: string;
|
|
58
|
+
workflows: LoweredWorkflow[];
|
|
59
|
+
}
|
|
60
|
+
/** The default entry modules: workflow sources, not generated clients, tests or declarations. */
|
|
61
|
+
declare function defaultEntries(paths: readonly string[]): string[];
|
|
62
|
+
/** Bundle a project. Exported so services can compute `buildId` without evaluating. */
|
|
63
|
+
declare function bundleProject(files: ReadonlyMap<string, string>, entries: readonly string[], esbuild: EsbuildApi): Promise<string>;
|
|
64
|
+
/** Lower tier-1 sources to IR v2. */
|
|
65
|
+
declare function lower(files: readonly SourceFile[] | Readonly<Record<string, string>>, options?: LowerOptions): Promise<LowerResult>;
|
|
66
|
+
|
|
67
|
+
export { DeterminismViolationError as D, type Evaluator as E, LowerError as L, type EsbuildApi as a, ESBUILD_VERSION as b, EVALUATION_GLOBAL as c, type LowerFailureReason as d, type LowerOptions as e, type LowerResult as f, type LoweredWorkflow as g, bundleProject as h, defaultEntries as i, 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 chunk3M34AUIY_cjs = require('./chunk-3M34AUIY.cjs');
|
|
4
|
+
require('./chunk-Y7NWR3WH.cjs');
|
|
5
|
+
require('./chunk-TQF7MYEN.cjs');
|
|
6
|
+
require('./chunk-7YR7DI7B.cjs');
|
|
7
|
+
require('./chunk-G4UEPUGO.cjs');
|
|
8
|
+
require('./chunk-6AIAC2FP.cjs');
|
|
9
|
+
require('./chunk-CSYBNN3V.cjs');
|
|
10
|
+
require('./chunk-E3APHA6O.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Object.defineProperty(exports, "createNodeVmEvaluator", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return chunk3M34AUIY_cjs.createNodeVmEvaluator; }
|
|
17
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createNodeVmEvaluator } from './chunk-5AW745OG.js';
|
|
2
|
+
import './chunk-MBBKGD7K.js';
|
|
3
|
+
import './chunk-EEAIM35V.js';
|
|
4
|
+
import './chunk-6U446SKY.js';
|
|
5
|
+
import './chunk-5LUIDMF4.js';
|
|
6
|
+
import './chunk-UB2BHU2M.js';
|
|
7
|
+
import './chunk-IHKXLG6I.js';
|
|
8
|
+
import './chunk-UJNHTS6D.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkY7NWR3WH_cjs = require('../chunk-Y7NWR3WH.cjs');
|
|
4
|
+
require('../chunk-TQF7MYEN.cjs');
|
|
5
|
+
require('../chunk-7YR7DI7B.cjs');
|
|
6
|
+
require('../chunk-G4UEPUGO.cjs');
|
|
7
|
+
require('../chunk-6AIAC2FP.cjs');
|
|
8
|
+
require('../chunk-CSYBNN3V.cjs');
|
|
9
|
+
var chunkE3APHA6O_cjs = require('../chunk-E3APHA6O.cjs');
|
|
10
|
+
var module$1 = require('module');
|
|
11
|
+
var url = require('url');
|
|
12
|
+
|
|
13
|
+
// src/generated/quickjs-worker-source.ts
|
|
14
|
+
var QUICKJS_WORKER_SOURCE = '"use strict";\n\nvar import_node_worker_threads = require("node:worker_threads");\n\nfunction isRecord(value) {\n return typeof value === "object" && value !== null && !Array.isArray(value);\n}\n\nvar DETERMINISM_VIOLATION = "DeterminismViolation";\nvar DETERMINISM_PRELUDE = `(() => {\n const NAME = ${JSON.stringify(DETERMINISM_VIOLATION)};\n const fail = (what) => {\n const error = new Error(\n what + " is not allowed in workflow code: lowering must give the same IR on every build. Read times and random values at run time instead (for example wf.now)."\n );\n error.name = NAME;\n throw error;\n };\n const lock = (target, key, value) =>\n Object.defineProperty(target, key, { value, writable: false, enumerable: false, configurable: false });\n const RealDate = Date;\n const LockedDate = function Date(...args) {\n if (new.target === undefined) return fail("Date()");\n if (args.length === 0) return fail("new Date()");\n return Reflect.construct(RealDate, args, new.target);\n };\n lock(LockedDate, "prototype", RealDate.prototype);\n lock(RealDate.prototype, "constructor", LockedDate);\n lock(LockedDate, "now", function now() { return fail("Date.now()"); });\n lock(LockedDate, "parse", RealDate.parse);\n lock(LockedDate, "UTC", RealDate.UTC);\n lock(globalThis, "Date", LockedDate);\n lock(Math, "random", function random() { return fail("Math.random()"); });\n const crypto = globalThis.crypto;\n if (crypto !== null && typeof crypto === "object") {\n for (const name of ["getRandomValues", "randomUUID"]) {\n if (typeof crypto[name] === "function") lock(crypto, name, function () { return fail("crypto." + name + "()"); });\n }\n }\n const DateTimeFormat = typeof Intl === "object" && Intl !== null ? Intl.DateTimeFormat : undefined;\n if (typeof DateTimeFormat === "function") {\n const proto = DateTimeFormat.prototype;\n const format = Object.getOwnPropertyDescriptor(proto, "format");\n if (format && typeof format.get === "function") {\n const get = format.get;\n Object.defineProperty(proto, "format", {\n get() {\n const bound = get.call(this);\n return (date) => (date === undefined ? fail("Intl.DateTimeFormat format()") : bound(date));\n },\n enumerable: false,\n configurable: false,\n });\n }\n const formatToParts = proto.formatToParts;\n if (typeof formatToParts === "function") {\n lock(proto, "formatToParts", function (date) {\n return date === undefined ? fail("Intl.DateTimeFormat formatToParts()") : formatToParts.call(this, date);\n });\n }\n }\n})();\n`;\nfunction failure(kind, message) {\n return { ok: false, failure: kind, message };\n}\nfunction failureForErrorName(name) {\n return name === DETERMINISM_VIOLATION ? "determinism" : "error";\n}\n\nfunction isQuickJSApi(value) {\n return isRecord(value) && typeof value["newQuickJSWASMModuleFromVariant"] === "function" && typeof value["newVariant"] === "function" && typeof value["shouldInterruptAfterDeadline"] === "function" && value["RELEASE_SYNC"] !== void 0;\n}\nvar WASM_PAGE_BYTES = 64 * 1024;\nvar ENGINE_HEADROOM_BYTES = 32 * 1024 * 1024;\nvar INITIAL_ENGINE_BYTES = 16 * 1024 * 1024;\nfunction describe(ctx, handle) {\n const dumped = ctx.dump(handle);\n if (isRecord(dumped)) {\n const name = typeof dumped["name"] === "string" ? dumped["name"] : "Error";\n const message = dumped["message"];\n return {\n name,\n message: typeof message === "string" ? message : message === void 0 ? JSON.stringify(dumped) : String(message)\n };\n }\n return { name: "Error", message: String(dumped) };\n}\nasync function evaluateInQuickJS(api, code, limits) {\n const maximum = Math.ceil((limits.memoryLimitBytes + ENGINE_HEADROOM_BYTES) / WASM_PAGE_BYTES);\n const initial = Math.min(maximum, INITIAL_ENGINE_BYTES / WASM_PAGE_BYTES);\n const engine = await api.newQuickJSWASMModuleFromVariant(\n api.newVariant(api.RELEASE_SYNC, { wasmMemory: new WebAssembly.Memory({ initial, maximum }) })\n );\n const runtime = engine.newRuntime();\n const deadline = Date.now() + limits.timeoutMs;\n runtime.setMemoryLimit(limits.memoryLimitBytes);\n runtime.setMaxStackSize(limits.maxStackSizeBytes);\n runtime.setInterruptHandler(api.shouldInterruptAfterDeadline(deadline));\n const ctx = runtime.newContext();\n const handles = [];\n const timedOut = () => failure("timeout", `Evaluating the workflow code timed out after ${limits.timeoutMs} ms`);\n const thrown = (handle) => {\n const { name, message } = describe(ctx, handle);\n handle.dispose();\n if (Date.now() > deadline && /interrupted/.test(message)) return timedOut();\n return failure(failureForErrorName(name), message);\n };\n try {\n const prelude = ctx.evalCode(DETERMINISM_PRELUDE, "determinism-prelude.js", { type: "global" });\n if (prelude.error) return thrown(prelude.error);\n prelude.value.dispose();\n const result = ctx.evalCode(code, "workflow-bundle.mjs", { type: "module" });\n if (result.error) return thrown(result.error);\n let namespace = result.value;\n handles.push(namespace);\n const state = ctx.getPromiseState(namespace);\n if (!(state.type === "fulfilled" && state.notAPromise === true)) {\n if (state.type === "fulfilled") state.value.dispose();\n else if (state.type === "rejected") state.error.dispose();\n while (runtime.hasPendingJob()) {\n if (Date.now() > deadline) return timedOut();\n const jobs = runtime.executePendingJobs();\n if (jobs.error) return thrown(jobs.error);\n }\n const settled = ctx.getPromiseState(namespace);\n if (settled.type === "rejected") return thrown(settled.error);\n if (settled.type === "pending")\n return failure("error", "The workflow module never finished evaluating");\n namespace = settled.value;\n handles.push(namespace);\n }\n const exported = ctx.getProp(namespace, "__fluidgrids");\n handles.push(exported);\n if (ctx.typeof(exported) !== "string")\n return failure("no-collection", "The bundle did not export a workflow collection");\n return { ok: true, value: ctx.getString(exported) };\n } catch (error) {\n return failure("error", error instanceof Error ? error.message : String(error));\n } finally {\n for (const handle of handles.reverse()) if (handle.alive) handle.dispose();\n ctx.dispose();\n runtime.dispose();\n }\n}\n\nprocess.on("unhandledRejection", () => void 0);\nasync function main(input) {\n if (!isRecord(input) || typeof input["code"] !== "string" || typeof input["moduleUrl"] !== "string" || !isRecord(input["limits"]))\n return failure("crashed", "The evaluation worker received no bundle");\n const { timeoutMs, memoryLimitBytes, maxStackSizeBytes } = input["limits"];\n if (typeof timeoutMs !== "number" || typeof memoryLimitBytes !== "number" || typeof maxStackSizeBytes !== "number")\n return failure("crashed", "The evaluation worker received no limits");\n const loaded = await import(input["moduleUrl"]);\n const api = isQuickJSApi(loaded) ? loaded : isRecord(loaded) && isQuickJSApi(loaded["default"]) ? loaded["default"] : void 0;\n if (!api) return failure("crashed", "quickjs-emscripten could not be loaded");\n return evaluateInQuickJS(api, input["code"], {\n timeoutMs,\n memoryLimitBytes,\n maxStackSizeBytes\n });\n}\nmain(import_node_worker_threads.workerData).then(\n (outcome) => import_node_worker_threads.parentPort?.postMessage(outcome),\n (error) => import_node_worker_threads.parentPort?.postMessage(\n failure("crashed", error instanceof Error ? error.message : String(error))\n )\n);\n';
|
|
15
|
+
|
|
16
|
+
// src/quickjs/index.ts
|
|
17
|
+
function quickjsModuleUrl() {
|
|
18
|
+
try {
|
|
19
|
+
return url.pathToFileURL(module$1.createRequire(chunkE3APHA6O_cjs.importMetaUrl).resolve("quickjs-emscripten")).href;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw new chunkY7NWR3WH_cjs.LowerError(
|
|
22
|
+
`quickjs-emscripten cannot be resolved: ${error instanceof Error ? error.message : String(error)}`,
|
|
23
|
+
"crashed"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function createQuickJSEvaluator(options = {}) {
|
|
28
|
+
const limits = {
|
|
29
|
+
timeoutMs: options.timeoutMs ?? 5e3,
|
|
30
|
+
memoryLimitBytes: options.memoryLimitBytes ?? 64 * 1024 * 1024,
|
|
31
|
+
maxStackSizeBytes: options.maxStackSizeBytes ?? 1024 * 1024
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
format: "esm",
|
|
35
|
+
async evaluate(code) {
|
|
36
|
+
const outcome = await chunkY7NWR3WH_cjs.runIsolateWorker({
|
|
37
|
+
source: QUICKJS_WORKER_SOURCE,
|
|
38
|
+
workerData: { code, limits, moduleUrl: quickjsModuleUrl() },
|
|
39
|
+
timeoutMs: limits.timeoutMs
|
|
40
|
+
});
|
|
41
|
+
return chunkY7NWR3WH_cjs.outcomeToCollection(outcome);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.createQuickJSEvaluator = createQuickJSEvaluator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { E as Evaluator } from '../lower-DAzvsJCo.cjs';
|
|
2
|
+
import 'esbuild';
|
|
3
|
+
import '../hash-CZkTXPCX.cjs';
|
|
4
|
+
import '../types-Dr2Fn1Ax.cjs';
|
|
5
|
+
import '../assemble-DEf3znGD.cjs';
|
|
6
|
+
|
|
7
|
+
interface QuickJSEvaluatorOptions {
|
|
8
|
+
/** Wall-clock budget, including parsing and compiling the bundle. 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 in a worker thread. */
|
|
16
|
+
declare function createQuickJSEvaluator(options?: QuickJSEvaluatorOptions): Evaluator;
|
|
17
|
+
|
|
18
|
+
export { type QuickJSEvaluatorOptions, createQuickJSEvaluator };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { E as Evaluator } from '../lower-CXggJTIo.js';
|
|
2
|
+
import 'esbuild';
|
|
3
|
+
import '../hash-CZkTXPCX.js';
|
|
4
|
+
import '../types-Dr2Fn1Ax.js';
|
|
5
|
+
import '../assemble-CrpUyd_3.js';
|
|
6
|
+
|
|
7
|
+
interface QuickJSEvaluatorOptions {
|
|
8
|
+
/** Wall-clock budget, including parsing and compiling the bundle. 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 in a worker thread. */
|
|
16
|
+
declare function createQuickJSEvaluator(options?: QuickJSEvaluatorOptions): Evaluator;
|
|
17
|
+
|
|
18
|
+
export { type QuickJSEvaluatorOptions, createQuickJSEvaluator };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { runIsolateWorker, outcomeToCollection, LowerError } from '../chunk-MBBKGD7K.js';
|
|
2
|
+
import '../chunk-EEAIM35V.js';
|
|
3
|
+
import '../chunk-6U446SKY.js';
|
|
4
|
+
import '../chunk-5LUIDMF4.js';
|
|
5
|
+
import '../chunk-UB2BHU2M.js';
|
|
6
|
+
import '../chunk-IHKXLG6I.js';
|
|
7
|
+
import '../chunk-UJNHTS6D.js';
|
|
8
|
+
import { createRequire } from 'module';
|
|
9
|
+
import { pathToFileURL } from 'url';
|
|
10
|
+
|
|
11
|
+
// src/generated/quickjs-worker-source.ts
|
|
12
|
+
var QUICKJS_WORKER_SOURCE = '"use strict";\n\nvar import_node_worker_threads = require("node:worker_threads");\n\nfunction isRecord(value) {\n return typeof value === "object" && value !== null && !Array.isArray(value);\n}\n\nvar DETERMINISM_VIOLATION = "DeterminismViolation";\nvar DETERMINISM_PRELUDE = `(() => {\n const NAME = ${JSON.stringify(DETERMINISM_VIOLATION)};\n const fail = (what) => {\n const error = new Error(\n what + " is not allowed in workflow code: lowering must give the same IR on every build. Read times and random values at run time instead (for example wf.now)."\n );\n error.name = NAME;\n throw error;\n };\n const lock = (target, key, value) =>\n Object.defineProperty(target, key, { value, writable: false, enumerable: false, configurable: false });\n const RealDate = Date;\n const LockedDate = function Date(...args) {\n if (new.target === undefined) return fail("Date()");\n if (args.length === 0) return fail("new Date()");\n return Reflect.construct(RealDate, args, new.target);\n };\n lock(LockedDate, "prototype", RealDate.prototype);\n lock(RealDate.prototype, "constructor", LockedDate);\n lock(LockedDate, "now", function now() { return fail("Date.now()"); });\n lock(LockedDate, "parse", RealDate.parse);\n lock(LockedDate, "UTC", RealDate.UTC);\n lock(globalThis, "Date", LockedDate);\n lock(Math, "random", function random() { return fail("Math.random()"); });\n const crypto = globalThis.crypto;\n if (crypto !== null && typeof crypto === "object") {\n for (const name of ["getRandomValues", "randomUUID"]) {\n if (typeof crypto[name] === "function") lock(crypto, name, function () { return fail("crypto." + name + "()"); });\n }\n }\n const DateTimeFormat = typeof Intl === "object" && Intl !== null ? Intl.DateTimeFormat : undefined;\n if (typeof DateTimeFormat === "function") {\n const proto = DateTimeFormat.prototype;\n const format = Object.getOwnPropertyDescriptor(proto, "format");\n if (format && typeof format.get === "function") {\n const get = format.get;\n Object.defineProperty(proto, "format", {\n get() {\n const bound = get.call(this);\n return (date) => (date === undefined ? fail("Intl.DateTimeFormat format()") : bound(date));\n },\n enumerable: false,\n configurable: false,\n });\n }\n const formatToParts = proto.formatToParts;\n if (typeof formatToParts === "function") {\n lock(proto, "formatToParts", function (date) {\n return date === undefined ? fail("Intl.DateTimeFormat formatToParts()") : formatToParts.call(this, date);\n });\n }\n }\n})();\n`;\nfunction failure(kind, message) {\n return { ok: false, failure: kind, message };\n}\nfunction failureForErrorName(name) {\n return name === DETERMINISM_VIOLATION ? "determinism" : "error";\n}\n\nfunction isQuickJSApi(value) {\n return isRecord(value) && typeof value["newQuickJSWASMModuleFromVariant"] === "function" && typeof value["newVariant"] === "function" && typeof value["shouldInterruptAfterDeadline"] === "function" && value["RELEASE_SYNC"] !== void 0;\n}\nvar WASM_PAGE_BYTES = 64 * 1024;\nvar ENGINE_HEADROOM_BYTES = 32 * 1024 * 1024;\nvar INITIAL_ENGINE_BYTES = 16 * 1024 * 1024;\nfunction describe(ctx, handle) {\n const dumped = ctx.dump(handle);\n if (isRecord(dumped)) {\n const name = typeof dumped["name"] === "string" ? dumped["name"] : "Error";\n const message = dumped["message"];\n return {\n name,\n message: typeof message === "string" ? message : message === void 0 ? JSON.stringify(dumped) : String(message)\n };\n }\n return { name: "Error", message: String(dumped) };\n}\nasync function evaluateInQuickJS(api, code, limits) {\n const maximum = Math.ceil((limits.memoryLimitBytes + ENGINE_HEADROOM_BYTES) / WASM_PAGE_BYTES);\n const initial = Math.min(maximum, INITIAL_ENGINE_BYTES / WASM_PAGE_BYTES);\n const engine = await api.newQuickJSWASMModuleFromVariant(\n api.newVariant(api.RELEASE_SYNC, { wasmMemory: new WebAssembly.Memory({ initial, maximum }) })\n );\n const runtime = engine.newRuntime();\n const deadline = Date.now() + limits.timeoutMs;\n runtime.setMemoryLimit(limits.memoryLimitBytes);\n runtime.setMaxStackSize(limits.maxStackSizeBytes);\n runtime.setInterruptHandler(api.shouldInterruptAfterDeadline(deadline));\n const ctx = runtime.newContext();\n const handles = [];\n const timedOut = () => failure("timeout", `Evaluating the workflow code timed out after ${limits.timeoutMs} ms`);\n const thrown = (handle) => {\n const { name, message } = describe(ctx, handle);\n handle.dispose();\n if (Date.now() > deadline && /interrupted/.test(message)) return timedOut();\n return failure(failureForErrorName(name), message);\n };\n try {\n const prelude = ctx.evalCode(DETERMINISM_PRELUDE, "determinism-prelude.js", { type: "global" });\n if (prelude.error) return thrown(prelude.error);\n prelude.value.dispose();\n const result = ctx.evalCode(code, "workflow-bundle.mjs", { type: "module" });\n if (result.error) return thrown(result.error);\n let namespace = result.value;\n handles.push(namespace);\n const state = ctx.getPromiseState(namespace);\n if (!(state.type === "fulfilled" && state.notAPromise === true)) {\n if (state.type === "fulfilled") state.value.dispose();\n else if (state.type === "rejected") state.error.dispose();\n while (runtime.hasPendingJob()) {\n if (Date.now() > deadline) return timedOut();\n const jobs = runtime.executePendingJobs();\n if (jobs.error) return thrown(jobs.error);\n }\n const settled = ctx.getPromiseState(namespace);\n if (settled.type === "rejected") return thrown(settled.error);\n if (settled.type === "pending")\n return failure("error", "The workflow module never finished evaluating");\n namespace = settled.value;\n handles.push(namespace);\n }\n const exported = ctx.getProp(namespace, "__fluidgrids");\n handles.push(exported);\n if (ctx.typeof(exported) !== "string")\n return failure("no-collection", "The bundle did not export a workflow collection");\n return { ok: true, value: ctx.getString(exported) };\n } catch (error) {\n return failure("error", error instanceof Error ? error.message : String(error));\n } finally {\n for (const handle of handles.reverse()) if (handle.alive) handle.dispose();\n ctx.dispose();\n runtime.dispose();\n }\n}\n\nprocess.on("unhandledRejection", () => void 0);\nasync function main(input) {\n if (!isRecord(input) || typeof input["code"] !== "string" || typeof input["moduleUrl"] !== "string" || !isRecord(input["limits"]))\n return failure("crashed", "The evaluation worker received no bundle");\n const { timeoutMs, memoryLimitBytes, maxStackSizeBytes } = input["limits"];\n if (typeof timeoutMs !== "number" || typeof memoryLimitBytes !== "number" || typeof maxStackSizeBytes !== "number")\n return failure("crashed", "The evaluation worker received no limits");\n const loaded = await import(input["moduleUrl"]);\n const api = isQuickJSApi(loaded) ? loaded : isRecord(loaded) && isQuickJSApi(loaded["default"]) ? loaded["default"] : void 0;\n if (!api) return failure("crashed", "quickjs-emscripten could not be loaded");\n return evaluateInQuickJS(api, input["code"], {\n timeoutMs,\n memoryLimitBytes,\n maxStackSizeBytes\n });\n}\nmain(import_node_worker_threads.workerData).then(\n (outcome) => import_node_worker_threads.parentPort?.postMessage(outcome),\n (error) => import_node_worker_threads.parentPort?.postMessage(\n failure("crashed", error instanceof Error ? error.message : String(error))\n )\n);\n';
|
|
13
|
+
|
|
14
|
+
// src/quickjs/index.ts
|
|
15
|
+
function quickjsModuleUrl() {
|
|
16
|
+
try {
|
|
17
|
+
return pathToFileURL(createRequire(import.meta.url).resolve("quickjs-emscripten")).href;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new LowerError(
|
|
20
|
+
`quickjs-emscripten cannot be resolved: ${error instanceof Error ? error.message : String(error)}`,
|
|
21
|
+
"crashed"
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function createQuickJSEvaluator(options = {}) {
|
|
26
|
+
const limits = {
|
|
27
|
+
timeoutMs: options.timeoutMs ?? 5e3,
|
|
28
|
+
memoryLimitBytes: options.memoryLimitBytes ?? 64 * 1024 * 1024,
|
|
29
|
+
maxStackSizeBytes: options.maxStackSizeBytes ?? 1024 * 1024
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
format: "esm",
|
|
33
|
+
async evaluate(code) {
|
|
34
|
+
const outcome = await runIsolateWorker({
|
|
35
|
+
source: QUICKJS_WORKER_SOURCE,
|
|
36
|
+
workerData: { code, limits, moduleUrl: quickjsModuleUrl() },
|
|
37
|
+
timeoutMs: limits.timeoutMs
|
|
38
|
+
});
|
|
39
|
+
return outcomeToCollection(outcome);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { createQuickJSEvaluator };
|