@procedures/compiler 0.0.0-stage → 0.3.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/CHANGELOG.md +45 -0
- package/LICENSE +21 -0
- package/README.md +254 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/checks.d.ts +24 -0
- package/dist/checks.d.ts.map +1 -0
- package/dist/checks.js +123 -0
- package/dist/checks.js.map +1 -0
- package/dist/codegen-closure.d.ts +19 -0
- package/dist/codegen-closure.d.ts.map +1 -0
- package/dist/codegen-closure.js +200 -0
- package/dist/codegen-closure.js.map +1 -0
- package/dist/codegen-text.d.ts +44 -0
- package/dist/codegen-text.d.ts.map +1 -0
- package/dist/codegen-text.js +360 -0
- package/dist/codegen-text.js.map +1 -0
- package/dist/diagnostics.d.ts +67 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +38 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/effects.d.ts +63 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/effects.js +185 -0
- package/dist/effects.js.map +1 -0
- package/dist/explain.d.ts +58 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +144 -0
- package/dist/explain.js.map +1 -0
- package/dist/facts.d.ts +66 -0
- package/dist/facts.d.ts.map +1 -0
- package/dist/facts.js +102 -0
- package/dist/facts.js.map +1 -0
- package/dist/fold.d.ts +27 -0
- package/dist/fold.d.ts.map +1 -0
- package/dist/fold.js +128 -0
- package/dist/fold.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptor.d.ts +51 -0
- package/dist/interceptor.d.ts.map +1 -0
- package/dist/interceptor.js +116 -0
- package/dist/interceptor.js.map +1 -0
- package/dist/ir.d.ts +240 -0
- package/dist/ir.d.ts.map +1 -0
- package/dist/ir.js +74 -0
- package/dist/ir.js.map +1 -0
- package/dist/mermaid.d.ts +53 -0
- package/dist/mermaid.d.ts.map +1 -0
- package/dist/mermaid.js +423 -0
- package/dist/mermaid.js.map +1 -0
- package/dist/module.d.ts +20 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +124 -0
- package/dist/module.js.map +1 -0
- package/dist/normalize.d.ts +43 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +529 -0
- package/dist/normalize.js.map +1 -0
- package/dist/openrpc.d.ts +63 -0
- package/dist/openrpc.d.ts.map +1 -0
- package/dist/openrpc.js +57 -0
- package/dist/openrpc.js.map +1 -0
- package/dist/print.d.ts +8 -0
- package/dist/print.d.ts.map +1 -0
- package/dist/print.js +148 -0
- package/dist/print.js.map +1 -0
- package/dist/procedures/program/check.d.ts +14 -0
- package/dist/procedures/program/check.d.ts.map +1 -0
- package/dist/procedures/program/check.js +30 -0
- package/dist/procedures/program/check.js.map +1 -0
- package/dist/procedures/program/compile.d.ts +14 -0
- package/dist/procedures/program/compile.d.ts.map +1 -0
- package/dist/procedures/program/compile.js +35 -0
- package/dist/procedures/program/compile.js.map +1 -0
- package/dist/procedures/program/diagram.d.ts +14 -0
- package/dist/procedures/program/diagram.d.ts.map +1 -0
- package/dist/procedures/program/diagram.js +23 -0
- package/dist/procedures/program/diagram.js.map +1 -0
- package/dist/procedures/program/effects-output.d.ts +8 -0
- package/dist/procedures/program/effects-output.d.ts.map +1 -0
- package/dist/procedures/program/effects-output.js +13 -0
- package/dist/procedures/program/effects-output.js.map +1 -0
- package/dist/procedures/program/explain.d.ts +14 -0
- package/dist/procedures/program/explain.d.ts.map +1 -0
- package/dist/procedures/program/explain.js +43 -0
- package/dist/procedures/program/explain.js.map +1 -0
- package/dist/procedures/program/index.d.ts +5 -0
- package/dist/procedures/program/index.d.ts.map +1 -0
- package/dist/procedures/program/index.js +5 -0
- package/dist/procedures/program/index.js.map +1 -0
- package/dist/procedures/sdk/index.d.ts +3 -0
- package/dist/procedures/sdk/index.d.ts.map +1 -0
- package/dist/procedures/sdk/index.js +3 -0
- package/dist/procedures/sdk/index.js.map +1 -0
- package/dist/procedures/sdk/manifest.d.ts +11 -0
- package/dist/procedures/sdk/manifest.d.ts.map +1 -0
- package/dist/procedures/sdk/manifest.js +15 -0
- package/dist/procedures/sdk/manifest.js.map +1 -0
- package/dist/procedures/sdk/openrpc.d.ts +11 -0
- package/dist/procedures/sdk/openrpc.d.ts.map +1 -0
- package/dist/procedures/sdk/openrpc.js +13 -0
- package/dist/procedures/sdk/openrpc.js.map +1 -0
- package/dist/procedures/sdk/typescript.d.ts +11 -0
- package/dist/procedures/sdk/typescript.d.ts.map +1 -0
- package/dist/procedures/sdk/typescript.js +14 -0
- package/dist/procedures/sdk/typescript.js.map +1 -0
- package/dist/program.d.ts +84 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +108 -0
- package/dist/program.js.map +1 -0
- package/dist/refs.d.ts +9 -0
- package/dist/refs.d.ts.map +1 -0
- package/dist/refs.js +9 -0
- package/dist/refs.js.map +1 -0
- package/dist/register.d.ts +6 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +8 -0
- package/dist/register.js.map +1 -0
- package/dist/runtime.d.ts +68 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +138 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.d.ts +41 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +325 -0
- package/dist/schema.js.map +1 -0
- package/dist/scopes.d.ts +25 -0
- package/dist/scopes.d.ts.map +1 -0
- package/dist/scopes.js +202 -0
- package/dist/scopes.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +157 -0
- package/dist/types.js.map +1 -0
- package/dist/typescript-sdk.d.ts +34 -0
- package/dist/typescript-sdk.d.ts.map +1 -0
- package/dist/typescript-sdk.js +231 -0
- package/dist/typescript-sdk.js.map +1 -0
- package/package.json +83 -3
- package/src/checks.ts +128 -0
- package/src/codegen-closure.ts +224 -0
- package/src/codegen-text.ts +396 -0
- package/src/diagnostics.ts +98 -0
- package/src/effects.ts +231 -0
- package/src/explain.ts +194 -0
- package/src/facts.ts +161 -0
- package/src/fold.ts +136 -0
- package/src/index.ts +35 -0
- package/src/interceptor.ts +149 -0
- package/src/ir.ts +330 -0
- package/src/mermaid.ts +460 -0
- package/src/module.ts +171 -0
- package/src/normalize.ts +694 -0
- package/src/openrpc.ts +104 -0
- package/src/print.ts +143 -0
- package/src/procedures/program/check.ts +31 -0
- package/src/procedures/program/compile.ts +36 -0
- package/src/procedures/program/diagram.ts +25 -0
- package/src/procedures/program/effects-output.ts +16 -0
- package/src/procedures/program/explain.ts +46 -0
- package/src/procedures/program/index.ts +4 -0
- package/src/procedures/sdk/index.ts +2 -0
- package/src/procedures/sdk/manifest.ts +17 -0
- package/src/procedures/sdk/openrpc.ts +16 -0
- package/src/procedures/sdk/typescript.ts +17 -0
- package/src/program.ts +181 -0
- package/src/refs.ts +9 -0
- package/src/register.ts +10 -0
- package/src/runtime.ts +188 -0
- package/src/schema.ts +318 -0
- package/src/scopes.ts +196 -0
- package/src/types.ts +318 -0
- package/src/typescript-sdk.ts +282 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../../src/procedures/sdk/manifest.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAA2D,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpJ,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAKrF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The manifest that the procedures `sdk.openrpc` and `sdk.typescript` read.
|
|
3
|
+
*/
|
|
4
|
+
import { describeRegistry, PROCEDURE_REGISTRY } from "@procedures/client/browser";
|
|
5
|
+
/**
|
|
6
|
+
* This function describes the registry of the caller, as `procedure.manifest` does. The manifest
|
|
7
|
+
* has only the procedures that the host exposes, and only one namespace when the input names it.
|
|
8
|
+
*/
|
|
9
|
+
export function manifestOf(input, ctx) {
|
|
10
|
+
return describeRegistry(ctx?.registry ?? PROCEDURE_REGISTRY, {
|
|
11
|
+
...(ctx?.expose ? { expose: ctx.expose } : {}),
|
|
12
|
+
...(input.namespace ? { include: (procedure) => procedure.path[0] === input.namespace } : {}),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../../src/procedures/sdk/manifest.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAoE,MAAM,4BAA4B,CAAC;AAGpJ;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAe,EAAE,GAAsB;IAChE,OAAO,gBAAgB,CAAC,GAAG,EAAE,QAAQ,IAAI,kBAAkB,EAAE;QAC3D,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9C,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,SAAuB,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5G,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sdk.openrpc procedure
|
|
3
|
+
*
|
|
4
|
+
* This procedure describes the procedures of the registry as an OpenRPC 1.3 document. It reads
|
|
5
|
+
* the registry of the caller and obeys the expose rule of the host, as `procedure.manifest` does.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProcedureContext } from "@procedures/client/browser";
|
|
8
|
+
import type { SdkOpenrpcInput, SdkOpenrpcOutput } from "../../types.js";
|
|
9
|
+
/** This function gives the OpenRPC document of the procedures that the host exposes. */
|
|
10
|
+
export declare function sdkOpenrpc(input: SdkOpenrpcInput, ctx?: ProcedureContext): Promise<SdkOpenrpcOutput>;
|
|
11
|
+
//# sourceMappingURL=openrpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrpc.d.ts","sourceRoot":"","sources":["../../../src/procedures/sdk/openrpc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGxE,wFAAwF;AACxF,wBAAsB,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAE1G"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sdk.openrpc procedure
|
|
3
|
+
*
|
|
4
|
+
* This procedure describes the procedures of the registry as an OpenRPC 1.3 document. It reads
|
|
5
|
+
* the registry of the caller and obeys the expose rule of the host, as `procedure.manifest` does.
|
|
6
|
+
*/
|
|
7
|
+
import { toOpenRpc } from "../../openrpc.js";
|
|
8
|
+
import { manifestOf } from "./manifest.js";
|
|
9
|
+
/** This function gives the OpenRPC document of the procedures that the host exposes. */
|
|
10
|
+
export async function sdkOpenrpc(input, ctx) {
|
|
11
|
+
return toOpenRpc(manifestOf(input, ctx));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=openrpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrpc.js","sourceRoot":"","sources":["../../../src/procedures/sdk/openrpc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAsB,EAAE,GAAsB;IAC7E,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,CAAgC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sdk.typescript procedure
|
|
3
|
+
*
|
|
4
|
+
* This procedure writes a typed TypeScript SDK for the procedures of the registry. It reads the
|
|
5
|
+
* registry of the caller and obeys the expose rule of the host, as `procedure.manifest` does.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProcedureContext } from "@procedures/client/browser";
|
|
8
|
+
import type { SdkTypescriptInput, SdkTypescriptOutput } from "../../types.js";
|
|
9
|
+
/** This function gives the source of the SDK of the procedures that the host exposes. */
|
|
10
|
+
export declare function sdkTypescript(input: SdkTypescriptInput, ctx?: ProcedureContext): Promise<SdkTypescriptOutput>;
|
|
11
|
+
//# sourceMappingURL=typescript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../src/procedures/sdk/typescript.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG9E,yFAAyF;AACzF,wBAAsB,aAAa,CAAC,KAAK,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAGnH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sdk.typescript procedure
|
|
3
|
+
*
|
|
4
|
+
* This procedure writes a typed TypeScript SDK for the procedures of the registry. It reads the
|
|
5
|
+
* registry of the caller and obeys the expose rule of the host, as `procedure.manifest` does.
|
|
6
|
+
*/
|
|
7
|
+
import { toTypeScriptSdk } from "../../typescript-sdk.js";
|
|
8
|
+
import { manifestOf } from "./manifest.js";
|
|
9
|
+
/** This function gives the source of the SDK of the procedures that the host exposes. */
|
|
10
|
+
export async function sdkTypescript(input, ctx) {
|
|
11
|
+
const manifest = manifestOf(input, ctx);
|
|
12
|
+
return { code: toTypeScriptSdk(manifest), procedures: manifest.procedures.length, registryHash: manifest.hash };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=typescript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../../src/procedures/sdk/typescript.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAyB,EAAE,GAAsB;IACnF,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxC,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;AAClH,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The functions of the compiler: `checkProgram()` and `compileProgram()`.
|
|
3
|
+
*
|
|
4
|
+
* Both read the facts of the procedures from a manifest (a browser) or from a registry (a host).
|
|
5
|
+
* They run the passes in order: normalize, scopes, effects and checks. `compileProgram()` then
|
|
6
|
+
* folds the pure calls (optional) and writes the code: the closure code and the source text.
|
|
7
|
+
*/
|
|
8
|
+
import { type Capability, type Effects, type ProcedureManifest, type ProcedurePath } from "@procedures/client/browser";
|
|
9
|
+
import type { ProgramIR } from "./ir.js";
|
|
10
|
+
import { type ProcedureFacts, type RegistryLike } from "./facts.js";
|
|
11
|
+
import { type Diagnostic } from "./diagnostics.js";
|
|
12
|
+
import { type SourceMapLine } from "./codegen-text.js";
|
|
13
|
+
import type { CompiledProgram } from "./runtime.js";
|
|
14
|
+
/** The options of `checkProgram()`. Give a manifest, a registry or facts. */
|
|
15
|
+
export interface CheckOptions {
|
|
16
|
+
/** The manifest of the host (`procedure.manifest`). A browser has only this. */
|
|
17
|
+
readonly manifest?: ProcedureManifest | undefined;
|
|
18
|
+
/** The registry of the host. It also gives the bodies of the defined procedures. */
|
|
19
|
+
readonly registry?: RegistryLike | undefined;
|
|
20
|
+
/** The facts of the procedures, when the caller made them already. */
|
|
21
|
+
readonly facts?: ProcedureFacts | undefined;
|
|
22
|
+
/** The expose rule of the host. The default exposes each procedure. */
|
|
23
|
+
readonly expose?: ((path: ProcedurePath) => boolean) | undefined;
|
|
24
|
+
/** The capability of the run. The check refuses each call that the capability refuses. */
|
|
25
|
+
readonly capability?: Capability<unknown> | undefined;
|
|
26
|
+
/** `exec` (the default): the program runs as `client.exec()` runs it. `body`: as the body of a defined procedure. */
|
|
27
|
+
readonly mode?: "exec" | "body" | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** The effects of each run in which no call fails. */
|
|
30
|
+
export interface MustEffects {
|
|
31
|
+
readonly reads: string[];
|
|
32
|
+
readonly writes: string[];
|
|
33
|
+
}
|
|
34
|
+
/** The result of `checkProgram()`. */
|
|
35
|
+
export interface CheckResult {
|
|
36
|
+
/** True when no diagnostic is an error. A host starts the program only then. */
|
|
37
|
+
readonly ok: boolean;
|
|
38
|
+
/** The effects that a run can have (the upper bound). An absent `reads` or `writes`: not known. */
|
|
39
|
+
readonly effects: Effects;
|
|
40
|
+
/** The effects of each run in which no call fails (the lower bound). */
|
|
41
|
+
readonly mustEffects: MustEffects;
|
|
42
|
+
/** The problems, in the order of the program. */
|
|
43
|
+
readonly diagnostics: Diagnostic[];
|
|
44
|
+
/** The hash of the manifest that the check used. */
|
|
45
|
+
readonly registryHash: string;
|
|
46
|
+
/** The IR of the program. */
|
|
47
|
+
readonly ir: ProgramIR;
|
|
48
|
+
}
|
|
49
|
+
/** The options of `compileProgram()`. */
|
|
50
|
+
export interface CompileOptions extends CheckOptions {
|
|
51
|
+
/** True: compute the pure core calls with literal inputs at compile time (the fold pass). The default is false. */
|
|
52
|
+
readonly fold?: boolean | undefined;
|
|
53
|
+
/** The language of the source text: `js` (the default) or `ts`. */
|
|
54
|
+
readonly language?: "js" | "ts" | undefined;
|
|
55
|
+
/** The import specifier of the runtime in the source text. The default is `@procedures/compiler/runtime`. */
|
|
56
|
+
readonly runtime?: string | undefined;
|
|
57
|
+
}
|
|
58
|
+
/** The result of `compileProgram()`. */
|
|
59
|
+
export interface CompileResult extends CheckResult {
|
|
60
|
+
/** The closure code: a host runs it as `run(ctx, input)`. It uses no `eval`. */
|
|
61
|
+
readonly run: CompiledProgram;
|
|
62
|
+
/** The source text: an ES module whose default export is `async (ctx, input) => output`. */
|
|
63
|
+
readonly code: string;
|
|
64
|
+
/** The body of an async function with the parameters `rt`, `ctx` and `input` (JavaScript). */
|
|
65
|
+
readonly body: string;
|
|
66
|
+
/** The lines of `code` and the pointers of their parts of the program. */
|
|
67
|
+
readonly sourceMap: SourceMapLine[];
|
|
68
|
+
/** The pointers of the calls that the fold pass computed. */
|
|
69
|
+
readonly folded: readonly string[];
|
|
70
|
+
}
|
|
71
|
+
/** The facts of the options: the facts, else the facts of the registry, else the facts of the manifest. */
|
|
72
|
+
export declare function baseFacts(options: CheckOptions): ProcedureFacts;
|
|
73
|
+
/**
|
|
74
|
+
* This function checks a program before it starts. It finds each unknown name and procedure, and
|
|
75
|
+
* each input that does not agree with its schema. It also finds each call that the capability
|
|
76
|
+
* refuses, and the effects of the whole program. No call starts.
|
|
77
|
+
*/
|
|
78
|
+
export declare function checkProgram(program: unknown, options: CheckOptions): CheckResult;
|
|
79
|
+
/**
|
|
80
|
+
* This function checks a program and writes it as a function: the closure code for a host and
|
|
81
|
+
* the source text for an export. The code makes the calls of the interpreter in the same order.
|
|
82
|
+
*/
|
|
83
|
+
export declare function compileProgram(program: unknown, options: CompileOptions): Promise<CompileResult>;
|
|
84
|
+
//# sourceMappingURL=program.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAa,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAClI,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAiD,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAKnH,OAAO,EAA8B,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAClD,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IAC7C,sEAAsE;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAC5C,uEAAuE;IACvE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,aAAa,KA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AAC;IACtB,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC;IACpC,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,2GAA2G;AAC3G,wBAAgB,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,cAAc,CAK/D;AAwDD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,GAAG,WAAW,CAGjF;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAqBtG"}
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The functions of the compiler: `checkProgram()` and `compileProgram()`.
|
|
3
|
+
*
|
|
4
|
+
* Both read the facts of the procedures from a manifest (a browser) or from a registry (a host).
|
|
5
|
+
* They run the passes in order: normalize, scopes, effects and checks. `compileProgram()` then
|
|
6
|
+
* folds the pure calls (optional) and writes the code: the closure code and the source text.
|
|
7
|
+
*/
|
|
8
|
+
import { pathToKey } from "@procedures/client/browser";
|
|
9
|
+
import { manifestFacts, registryFacts, withDefinitions } from "./facts.js";
|
|
10
|
+
import { findDefinitions, normalize } from "./normalize.js";
|
|
11
|
+
import { resolveScopes } from "./scopes.js";
|
|
12
|
+
import { inferEffects, toEffects } from "./effects.js";
|
|
13
|
+
import { checkCalls } from "./checks.js";
|
|
14
|
+
import { hasErrors, sortDiagnostics } from "./diagnostics.js";
|
|
15
|
+
import { foldProgram } from "./fold.js";
|
|
16
|
+
import { compileClosure } from "./codegen-closure.js";
|
|
17
|
+
import { emitText } from "./codegen-text.js";
|
|
18
|
+
/** The facts of the options: the facts, else the facts of the registry, else the facts of the manifest. */
|
|
19
|
+
export function baseFacts(options) {
|
|
20
|
+
if (options.facts)
|
|
21
|
+
return options.facts;
|
|
22
|
+
if (options.registry)
|
|
23
|
+
return registryFacts(options.registry, { expose: options.expose });
|
|
24
|
+
if (options.manifest)
|
|
25
|
+
return manifestFacts(options.manifest, { expose: options.expose });
|
|
26
|
+
throw new Error("checkProgram: give a manifest, a registry or facts");
|
|
27
|
+
}
|
|
28
|
+
function analyze(program, options) {
|
|
29
|
+
const definitions = findDefinitions(program);
|
|
30
|
+
const facts = withDefinitions(baseFacts(options), definitions);
|
|
31
|
+
const diagnostics = [];
|
|
32
|
+
// The effects of a defined body: a recursive definition gives unknown effects
|
|
33
|
+
const bodies = new Map();
|
|
34
|
+
const bodyEffects = (path) => {
|
|
35
|
+
const key = pathToKey(path);
|
|
36
|
+
const cached = bodies.get(key);
|
|
37
|
+
if (cached === "pending")
|
|
38
|
+
return undefined;
|
|
39
|
+
if (cached)
|
|
40
|
+
return cached;
|
|
41
|
+
const body = facts.body(path);
|
|
42
|
+
if (body === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
bodies.set(key, "pending");
|
|
45
|
+
const { ir } = normalize(body, facts, { mode: "body" });
|
|
46
|
+
resolveScopes(ir);
|
|
47
|
+
const summary = inferEffects(ir.root, facts, bodyEffects).program;
|
|
48
|
+
bodies.set(key, summary);
|
|
49
|
+
return summary;
|
|
50
|
+
};
|
|
51
|
+
// The bodies that the program defines are a part of the program: their problems have pointers in it
|
|
52
|
+
for (const definition of definitions.values()) {
|
|
53
|
+
const body = normalize(definition.body, facts, { mode: "body", base: definition.pointer });
|
|
54
|
+
diagnostics.push(...body.diagnostics, ...resolveScopes(body.ir));
|
|
55
|
+
diagnostics.push(...checkCalls(body.ir.root, facts, inferEffects(body.ir.root, facts, bodyEffects)));
|
|
56
|
+
}
|
|
57
|
+
const result = normalize(program, facts, { mode: options.mode ?? "exec" });
|
|
58
|
+
diagnostics.push(...result.diagnostics, ...resolveScopes(result.ir));
|
|
59
|
+
const effects = inferEffects(result.ir.root, facts, bodyEffects);
|
|
60
|
+
diagnostics.push(...checkCalls(result.ir.root, facts, effects, { capability: options.capability }));
|
|
61
|
+
return { facts, ir: result.ir, diagnostics, program: effects.program };
|
|
62
|
+
}
|
|
63
|
+
function summarize(analysis, diagnostics) {
|
|
64
|
+
const sorted = sortDiagnostics(diagnostics);
|
|
65
|
+
return {
|
|
66
|
+
ok: !hasErrors(sorted),
|
|
67
|
+
effects: toEffects(analysis.program.may),
|
|
68
|
+
mustEffects: { reads: [...analysis.program.must.reads].sort(), writes: [...analysis.program.must.writes].sort() },
|
|
69
|
+
diagnostics: sorted,
|
|
70
|
+
registryHash: analysis.facts.hash,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* This function checks a program before it starts. It finds each unknown name and procedure, and
|
|
75
|
+
* each input that does not agree with its schema. It also finds each call that the capability
|
|
76
|
+
* refuses, and the effects of the whole program. No call starts.
|
|
77
|
+
*/
|
|
78
|
+
export function checkProgram(program, options) {
|
|
79
|
+
const analysis = analyze(program, options);
|
|
80
|
+
return { ...summarize(analysis, analysis.diagnostics), ir: analysis.ir };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* This function checks a program and writes it as a function: the closure code for a host and
|
|
84
|
+
* the source text for an export. The code makes the calls of the interpreter in the same order.
|
|
85
|
+
*/
|
|
86
|
+
export async function compileProgram(program, options) {
|
|
87
|
+
const analysis = analyze(program, options);
|
|
88
|
+
let ir = analysis.ir;
|
|
89
|
+
let folded = [];
|
|
90
|
+
if (options.fold) {
|
|
91
|
+
const result = await foldProgram(ir.root, analysis.facts);
|
|
92
|
+
ir = { ...ir, root: result.root };
|
|
93
|
+
folded = result.folded;
|
|
94
|
+
}
|
|
95
|
+
const rawKeys = analysis.facts.rawKeys;
|
|
96
|
+
const run = compileClosure(ir, { rawKeys });
|
|
97
|
+
const text = emitText(ir, { language: options.language, runtime: options.runtime, registryHash: analysis.facts.hash, rawKeys });
|
|
98
|
+
return {
|
|
99
|
+
...summarize(analysis, [...analysis.diagnostics, ...text.diagnostics]),
|
|
100
|
+
ir,
|
|
101
|
+
run,
|
|
102
|
+
code: text.module,
|
|
103
|
+
body: text.body,
|
|
104
|
+
sourceMap: text.sourceMap,
|
|
105
|
+
folded,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=program.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAA6E,MAAM,4BAA4B,CAAC;AAElI,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAA0C,MAAM,YAAY,CAAC;AACnH,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAsB,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAmB,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAsB,MAAM,mBAAmB,CAAC;AAiEjE,2GAA2G;AAC3G,MAAM,UAAU,SAAS,CAAC,OAAqB;IAC7C,IAAI,OAAO,CAAC,KAAK;QAAE,OAAO,OAAO,CAAC,KAAK,CAAC;IACxC,IAAI,OAAO,CAAC,QAAQ;QAAE,OAAO,aAAa,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACzF,IAAI,OAAO,CAAC,QAAQ;QAAE,OAAO,aAAa,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,CAAC;QAClC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACzB,CAAC;IACD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;IACvC,MAAM,GAAG,GAAG,cAAc,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAChI,OAAO;QACL,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;QACtE,EAAE;QACF,GAAG;QACH,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/dist/refs.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The test of a `$ref` object, as `isOutputRef()` of the client has it (the browser entry of the
|
|
3
|
+
* client does not export that function).
|
|
4
|
+
*/
|
|
5
|
+
/** True for an object with a `$ref` string (also an inherited one, as the `in` test of the client). */
|
|
6
|
+
export declare function isOutputRef(value: unknown): value is {
|
|
7
|
+
readonly $ref: string;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=refs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs.d.ts","sourceRoot":"","sources":["../src/refs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uGAAuG;AACvG,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAE9E"}
|
package/dist/refs.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The test of a `$ref` object, as `isOutputRef()` of the client has it (the browser entry of the
|
|
3
|
+
* client does not export that function).
|
|
4
|
+
*/
|
|
5
|
+
/** True for an object with a `$ref` string (also an inherited one, as the `in` test of the client). */
|
|
6
|
+
export function isOutputRef(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "string";
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=refs.js.map
|
package/dist/refs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../src/refs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uGAAuG;AACvG,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ,CAAC;AAClI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,cAAc,aAAa,CAAC"}
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Importing this file registers the procedures of @procedures/compiler in the global registry:
|
|
3
|
+
* `import "@procedures/compiler/register"`. The package root registers nothing.
|
|
4
|
+
*/
|
|
5
|
+
import { registerCompilerProcedures } from "./module.js";
|
|
6
|
+
export * from "./module.js";
|
|
7
|
+
registerCompilerProcedures();
|
|
8
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAEzD,cAAc,aAAa,CAAC;AAE5B,0BAA0B,EAAE,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime of a compiled program: the small functions that the generated code calls.
|
|
3
|
+
*
|
|
4
|
+
* Each function does one step of the interpreter of `@procedures/client` with the same result and
|
|
5
|
+
* the same error message. The closure code and the source text use the same functions, so the
|
|
6
|
+
* two forms of a program operate the same. The entry `@procedures/compiler/runtime` exports them
|
|
7
|
+
* for the source text. Importing this module registers nothing.
|
|
8
|
+
*/
|
|
9
|
+
import { type HydrationEvent, type ProcedureContext, type ProcedurePath, type RefScope } from "@procedures/client/browser";
|
|
10
|
+
/**
|
|
11
|
+
* The context that a compiled program needs: the context of a procedure handler gives it. Each
|
|
12
|
+
* call goes through `client.call`, so it keeps its admission, validation, deadline and interceptors.
|
|
13
|
+
*/
|
|
14
|
+
export interface ProgramContext {
|
|
15
|
+
readonly client: Pick<ProcedureContext["client"], "call">;
|
|
16
|
+
/** The registry of the caller: the raw-input rule of a fallback to the interpreter reads it. */
|
|
17
|
+
readonly registry?: ProcedureContext["registry"] | undefined;
|
|
18
|
+
/** The hydration observer of the program: a fallback to the interpreter gives it its events. */
|
|
19
|
+
readonly onRef?: ((event: HydrationEvent) => void) | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** A compiled program: `(ctx, input) => output`. */
|
|
22
|
+
export type CompiledProgram = (ctx: ProgramContext, input?: unknown) => Promise<unknown>;
|
|
23
|
+
/** One frame of a scope for a raw input: the names with their values, and `$last` when the frame has it. */
|
|
24
|
+
export interface RuntimeFrame {
|
|
25
|
+
readonly names: ReadonlyArray<readonly [string, unknown]>;
|
|
26
|
+
readonly last?: readonly [unknown] | undefined;
|
|
27
|
+
}
|
|
28
|
+
/** `getPath()` of the client: the own fields of a value, or undefined. */
|
|
29
|
+
export declare function get(value: unknown, fields: readonly string[]): unknown;
|
|
30
|
+
/** The error of the interpreter for a `$ref` name that no scope has. */
|
|
31
|
+
export declare function unknownName(text: string): never;
|
|
32
|
+
/** This function throws an error with the message of the interpreter. */
|
|
33
|
+
export declare function fail(message: string): never;
|
|
34
|
+
/** The input of an operand call with the parent context (`cwd`, `node`): `callOperand()` of the client. */
|
|
35
|
+
export declare function merge(input: unknown, extra: Readonly<Record<string, unknown>>): unknown;
|
|
36
|
+
/** The truth of a condition of `client.conditional`: the `value` field of an object decides. */
|
|
37
|
+
export declare function truthy(condition: unknown): boolean;
|
|
38
|
+
/** The items of `client.map` and `client.reduce`: an array, or the error of the interpreter. */
|
|
39
|
+
export declare function items(value: unknown): unknown[];
|
|
40
|
+
/** The message of an error, as the control-flow procedures read it. */
|
|
41
|
+
export declare function message(error: unknown): string;
|
|
42
|
+
/** An object from its entries: each key is an own property, also `__proto__`. */
|
|
43
|
+
export declare function object(entries: ReadonlyArray<readonly [string, unknown]>): Record<string, unknown>;
|
|
44
|
+
/** A call that waits for its runner: the call object with its hydrated input (`hydrateRef()`). */
|
|
45
|
+
export declare function deferred(source: Record<string, unknown>, input: unknown): unknown;
|
|
46
|
+
/** The scope of the interpreter for a raw input: the frames from the outermost to the innermost. */
|
|
47
|
+
export declare function scope(frames: readonly RuntimeFrame[]): RefScope | undefined;
|
|
48
|
+
/** A call through the client. */
|
|
49
|
+
export declare function call(ctx: ProgramContext, path: ProcedurePath, input: unknown): Promise<unknown>;
|
|
50
|
+
/** A call of a procedure that takes its input raw: it gets the scope of the caller (`withScope()`). */
|
|
51
|
+
export declare function callRaw(ctx: ProgramContext, path: ProcedurePath, input: unknown, frames: readonly RuntimeFrame[] | undefined): Promise<unknown>;
|
|
52
|
+
/** The result of `client.parallel`. */
|
|
53
|
+
export interface ParallelResult {
|
|
54
|
+
results: unknown[];
|
|
55
|
+
allSucceeded: boolean;
|
|
56
|
+
errors: Array<{
|
|
57
|
+
index: number;
|
|
58
|
+
error: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
/** `client.parallel`: workers take the tasks in order, with `concurrency` and `failFast`. */
|
|
62
|
+
export declare function parallel(tasks: ReadonlyArray<() => Promise<unknown>>, concurrency: number | undefined, failFast: boolean): Promise<ParallelResult>;
|
|
63
|
+
/**
|
|
64
|
+
* `client.exec(program, input)`: the fields of the input go over the fields of the input of the
|
|
65
|
+
* root call. The program changes, so the interpreter runs it.
|
|
66
|
+
*/
|
|
67
|
+
export declare function execWithInput(ctx: ProgramContext, program: unknown, input: unknown, rawKeys: readonly string[]): Promise<unknown>;
|
|
68
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAWL,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACd,MAAM,4BAA4B,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;IAC1D,gGAAgG;IAChG,QAAQ,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC;IAC7D,gGAAgG;IAChG,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAChE;AAED,oDAAoD;AACpD,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEzF,4GAA4G;AAC5G,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,C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AAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAE/F;AAED,uGAAuG;AACvG,wBAAgB,OAAO,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAE/I;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD;AAED,6FAA6F;AAC7F,wBAAsB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAyBxJ;AASD;;;GAGG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAYvI"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime of a compiled program: the small functions that the generated code calls.
|
|
3
|
+
*
|
|
4
|
+
* Each function does one step of the interpreter of `@procedures/client` with the same result and
|
|
5
|
+
* the same error message. The closure code and the source text use the same functions, so the
|
|
6
|
+
* two forms of a program operate the same. The entry `@procedures/compiler/runtime` exports them
|
|
7
|
+
* for the source text. Importing this module registers nothing.
|
|
8
|
+
*/
|
|
9
|
+
import { createRefScope, isAnyProcedureRef, isControlFlowPath, isPlainObject, normalizeRef, pathToKey, prepareRootCall, rawInputRule, withScope, } from "@procedures/client/browser";
|
|
10
|
+
/** `getPath()` of the client: the own fields of a value, or undefined. */
|
|
11
|
+
export function get(value, fields) {
|
|
12
|
+
let current = value;
|
|
13
|
+
for (const field of fields) {
|
|
14
|
+
if (current && typeof current === "object" && Object.hasOwn(current, field)) {
|
|
15
|
+
current = current[field];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return current;
|
|
22
|
+
}
|
|
23
|
+
/** The error of the interpreter for a `$ref` name that no scope has. */
|
|
24
|
+
export function unknownName(text) {
|
|
25
|
+
const name = text.split(".")[0];
|
|
26
|
+
throw new Error(`Unknown $ref name "${name}" in "${text}": no step, item or input has this name here. ` +
|
|
27
|
+
`For a literal $ref object, write { "$literal": { "$ref": ... } }.`);
|
|
28
|
+
}
|
|
29
|
+
/** This function throws an error with the message of the interpreter. */
|
|
30
|
+
export function fail(message) {
|
|
31
|
+
throw new Error(message);
|
|
32
|
+
}
|
|
33
|
+
/** The input of an operand call with the parent context (`cwd`, `node`): `callOperand()` of the client. */
|
|
34
|
+
export function merge(input, extra) {
|
|
35
|
+
if (Object.keys(extra).length === 0)
|
|
36
|
+
return input;
|
|
37
|
+
return { ...(typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}), ...extra };
|
|
38
|
+
}
|
|
39
|
+
/** The truth of a condition of `client.conditional`: the `value` field of an object decides. */
|
|
40
|
+
export function truthy(condition) {
|
|
41
|
+
if (condition && typeof condition === "object" && "value" in condition)
|
|
42
|
+
return Boolean(condition.value);
|
|
43
|
+
return Boolean(condition);
|
|
44
|
+
}
|
|
45
|
+
/** The items of `client.map` and `client.reduce`: an array, or the error of the interpreter. */
|
|
46
|
+
export function items(value) {
|
|
47
|
+
if (!Array.isArray(value))
|
|
48
|
+
throw new Error(`items must be an array, got ${value === null ? "null" : typeof value}`);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
/** The message of an error, as the control-flow procedures read it. */
|
|
52
|
+
export function message(error) {
|
|
53
|
+
return error instanceof Error ? error.message : String(error);
|
|
54
|
+
}
|
|
55
|
+
/** An object from its entries: each key is an own property, also `__proto__`. */
|
|
56
|
+
export function object(entries) {
|
|
57
|
+
return Object.fromEntries(entries);
|
|
58
|
+
}
|
|
59
|
+
/** A call that waits for its runner: the call object with its hydrated input (`hydrateRef()`). */
|
|
60
|
+
export function deferred(source, input) {
|
|
61
|
+
return input === source["input"] ? source : { ...source, input };
|
|
62
|
+
}
|
|
63
|
+
/** The scope of the interpreter for a raw input: the frames from the outermost to the innermost. */
|
|
64
|
+
export function scope(frames) {
|
|
65
|
+
let current;
|
|
66
|
+
for (const frame of frames) {
|
|
67
|
+
const next = createRefScope(current);
|
|
68
|
+
for (const [name, value] of frame.names)
|
|
69
|
+
next.outputs.set(name, value);
|
|
70
|
+
if (frame.last)
|
|
71
|
+
next.last = frame.last[0];
|
|
72
|
+
current = next;
|
|
73
|
+
}
|
|
74
|
+
return current;
|
|
75
|
+
}
|
|
76
|
+
/** A call through the client. */
|
|
77
|
+
export function call(ctx, path, input) {
|
|
78
|
+
return ctx.client.call(path, input);
|
|
79
|
+
}
|
|
80
|
+
/** A call of a procedure that takes its input raw: it gets the scope of the caller (`withScope()`). */
|
|
81
|
+
export function callRaw(ctx, path, input, frames) {
|
|
82
|
+
return ctx.client.call(path, withScope(input, frames ? scope(frames) : undefined));
|
|
83
|
+
}
|
|
84
|
+
/** `client.parallel`: workers take the tasks in order, with `concurrency` and `failFast`. */
|
|
85
|
+
export async function parallel(tasks, concurrency, failFast) {
|
|
86
|
+
const results = new Array(tasks.length);
|
|
87
|
+
const errors = [];
|
|
88
|
+
const limit = typeof concurrency === "number" && concurrency > 0 ? Math.min(concurrency, tasks.length) : tasks.length;
|
|
89
|
+
let nextIndex = 0;
|
|
90
|
+
let aborted = false;
|
|
91
|
+
const worker = async () => {
|
|
92
|
+
while (!aborted) {
|
|
93
|
+
const index = nextIndex++;
|
|
94
|
+
if (index >= tasks.length)
|
|
95
|
+
return;
|
|
96
|
+
try {
|
|
97
|
+
results[index] = await tasks[index]();
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (failFast) {
|
|
101
|
+
aborted = true;
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
errors.push({ index, error: message(error) });
|
|
105
|
+
results[index] = undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
await Promise.all(Array.from({ length: Math.max(1, limit) }, () => worker()));
|
|
110
|
+
errors.sort((a, b) => a.index - b.index);
|
|
111
|
+
return { results, allSucceeded: errors.length === 0, errors };
|
|
112
|
+
}
|
|
113
|
+
/** The raw-input rule of a fallback: the registry of the caller, or the rule of the compile time. */
|
|
114
|
+
function rawRule(ctx, rawKeys) {
|
|
115
|
+
if (ctx.registry)
|
|
116
|
+
return rawInputRule(ctx.registry);
|
|
117
|
+
const keys = new Set(rawKeys);
|
|
118
|
+
return (path) => keys.has(pathToKey(path)) || isControlFlowPath(path);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* `client.exec(program, input)`: the fields of the input go over the fields of the input of the
|
|
122
|
+
* root call. The program changes, so the interpreter runs it.
|
|
123
|
+
*/
|
|
124
|
+
export async function execWithInput(ctx, program, input, rawKeys) {
|
|
125
|
+
let ref;
|
|
126
|
+
if (isAnyProcedureRef(program)) {
|
|
127
|
+
const normalized = normalizeRef(program);
|
|
128
|
+
ref = { ...normalized, input: isPlainObject(normalized.input) && isPlainObject(input) ? { ...normalized.input, ...input } : input };
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// client.exec(path, input)
|
|
132
|
+
ref = { $proc: program, input: input ?? {} };
|
|
133
|
+
}
|
|
134
|
+
const executor = (path, value) => ctx.client.call(path, value);
|
|
135
|
+
const root = await prepareRootCall(ref, executor, { rawInput: rawRule(ctx, rawKeys), onRef: ctx.onRef });
|
|
136
|
+
return ctx.client.call(root.path, root.input);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,SAAS,EACT,eAAe,EACf,YAAY,EACZ,SAAS,GAMV,MAAM,4BAA4B,CAAC;AAuBpC,0EAA0E;AAC1E,MAAM,UAAU,GAAG,CAAC,KAAc,EAAE,MAAyB;IAC3D,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;YAC5E,OAAO,GAAI,OAAmC,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,IAAI,KAAK,CACb,sBAAsB,IAAI,SAAS,IAAI,gDAAgD;QACrF,mEAAmE,CACtE,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,IAAI,CAAC,OAAe;IAClC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,KAAK,CAAC,KAAc,EAAE,KAAwC;IAC5E,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC;QA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AG,CAAC,KAAK,EAAE,CAAC,CAAC;IACzG,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check of an input against the JSON Schema of a procedure (the manifest gives draft-07).
|
|
3
|
+
*
|
|
4
|
+
* The compiler knows only a part of an input before the run: the literals, and the keys of an
|
|
5
|
+
* object whose values are calls. This validator works on such a partial value (a shape). It
|
|
6
|
+
* reports only a definite problem: a value that the compiler knows and that the schema refuses.
|
|
7
|
+
* A part that the compiler does not know agrees with each schema.
|
|
8
|
+
*/
|
|
9
|
+
import { type IRNode, type Pointer } from "./ir.js";
|
|
10
|
+
/** A partial value: what the compiler knows of a value before the run. */
|
|
11
|
+
export type Shape = {
|
|
12
|
+
readonly kind: "known";
|
|
13
|
+
readonly value: unknown;
|
|
14
|
+
readonly pointer: Pointer;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "unknown";
|
|
17
|
+
readonly pointer: Pointer;
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: "object";
|
|
20
|
+
readonly entries: ReadonlyMap<string, Shape>;
|
|
21
|
+
readonly pointer: Pointer;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "array";
|
|
24
|
+
readonly items: readonly Shape[];
|
|
25
|
+
readonly pointer: Pointer;
|
|
26
|
+
};
|
|
27
|
+
/** The shape of the value of a node. */
|
|
28
|
+
export declare function shapeOf(node: IRNode): Shape;
|
|
29
|
+
/** The shape of an input with the parent context of control flow (`callOperand()`). */
|
|
30
|
+
export declare function withExtra(shape: Shape, extra: Readonly<Record<string, unknown>>): Shape;
|
|
31
|
+
/** One problem of an input. */
|
|
32
|
+
export interface SchemaIssue {
|
|
33
|
+
/** The pointer of the part of the program. */
|
|
34
|
+
readonly pointer: Pointer;
|
|
35
|
+
/** The path in the input: `filter.status` or `items[2]`. */
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly message: string;
|
|
38
|
+
}
|
|
39
|
+
/** This function gives the definite problems of a partial input against a JSON Schema. */
|
|
40
|
+
export declare function checkShape(shape: Shape, schema: unknown): SchemaIssue[];
|
|
41
|
+
//# sourceMappingURL=schema.d.ts.map
|