@telorun/templating 0.21.0 → 0.22.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/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +2 -0
- package/dist/cel/catalog.d.ts +2 -0
- package/dist/cel/catalog.d.ts.map +1 -1
- package/dist/cel/catalog.js +14 -0
- package/dist/cel/compile.d.ts.map +1 -1
- package/dist/cel/compile.js +27 -0
- package/dist/cel/environment.d.ts.map +1 -1
- package/dist/cel/environment.js +1 -0
- package/dist/engine.d.ts +3 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engines/include.d.ts +3 -0
- package/dist/engines/include.d.ts.map +1 -1
- package/dist/engines/include.js +36 -14
- package/dist/engines/module-path.d.ts +17 -0
- package/dist/engines/module-path.d.ts.map +1 -0
- package/dist/engines/module-path.js +33 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/sentinel.d.ts +12 -0
- package/dist/sentinel.d.ts.map +1 -1
- package/dist/sentinel.js +16 -0
- package/package.json +2 -2
- package/src/builtins.ts +2 -0
- package/src/cel/catalog.ts +17 -0
- package/src/cel/compile.ts +27 -0
- package/src/cel/environment.ts +1 -0
- package/src/engine.ts +3 -0
- package/src/engines/include.ts +57 -14
- package/src/engines/module-path.ts +39 -0
- package/src/index.ts +5 -0
- package/src/sentinel.ts +21 -0
package/dist/builtins.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builtins.d.ts","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;gEAKgE;AAChE,eAAO,MAAM,cAAc,EAAE,SAAS,gBAAgB,EAQrD,CAAC;AAEF,wBAAgB,qBAAqB,IAAI,wBAAwB,CAMhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAEtF;AAID;;;oBAGoB;AACpB,wBAAgB,eAAe,IAAI,wBAAwB,CAK1D"}
|
package/dist/builtins.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { celEngine } from "./engines/cel.js";
|
|
2
2
|
import { includeBytesEngine, includeTextEngine } from "./engines/include.js";
|
|
3
3
|
import { literalEngine } from "./engines/literal.js";
|
|
4
|
+
import { modulePathEngine } from "./engines/module-path.js";
|
|
4
5
|
import { refEngine } from "./engines/ref.js";
|
|
5
6
|
import { sqlEngine } from "./engines/sql.js";
|
|
6
7
|
import { TemplatingEngineRegistry } from "./registry.js";
|
|
@@ -15,6 +16,7 @@ export const builtinEngines = [
|
|
|
15
16
|
includeBytesEngine,
|
|
16
17
|
includeTextEngine,
|
|
17
18
|
literalEngine,
|
|
19
|
+
modulePathEngine,
|
|
18
20
|
refEngine,
|
|
19
21
|
sqlEngine,
|
|
20
22
|
];
|
package/dist/cel/catalog.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface CelHandlers {
|
|
|
11
11
|
base64Encode: (s: string) => string;
|
|
12
12
|
base64Decode: (s: string) => string;
|
|
13
13
|
json: (value: unknown) => string;
|
|
14
|
+
/** Join a relative path onto a base with the HOST's path rules. */
|
|
15
|
+
joinPath: (base: string, relative: string) => string;
|
|
14
16
|
}
|
|
15
17
|
export type CelFunctionCategory = "conversion" | "time" | "uuid" | "string" | "math" | "collection" | "json" | "encoding" | "hashing" | "formatting" | "null";
|
|
16
18
|
/** One entry in the CEL standard library — the single source of truth that both
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../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og.js
CHANGED
|
@@ -784,6 +784,20 @@ export const CEL_FUNCTIONS = [
|
|
|
784
784
|
hostBacked: false,
|
|
785
785
|
build: () => (s) => JSON.parse(s),
|
|
786
786
|
},
|
|
787
|
+
// Paths. The one way to extend a host path: `variables.dataDir.joinPath('reports')`
|
|
788
|
+
// keeps it a `Telo.HostPath` (the analyzer types that overload), where `+`
|
|
789
|
+
// would make it a plain string. Host-backed because what a separator IS
|
|
790
|
+
// belongs to the machine running it.
|
|
791
|
+
{
|
|
792
|
+
name: "joinPath",
|
|
793
|
+
signature: "string.joinPath(string): string",
|
|
794
|
+
register: ["string.joinPath(string): string"],
|
|
795
|
+
category: "string",
|
|
796
|
+
summary: "Join a relative path onto a path with the host's separator (`\\` on Windows). On a host path it yields a host path; an absolute argument is refused.",
|
|
797
|
+
deterministic: true,
|
|
798
|
+
hostBacked: true,
|
|
799
|
+
build: (h) => (base, relative) => h.joinPath(base, relative),
|
|
800
|
+
},
|
|
787
801
|
// Encoding
|
|
788
802
|
{
|
|
789
803
|
name: "base64Encode",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/cel/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAW,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKjE,eAAO,MAAM,cAAc,QAA8B,CAAC;AAC1D,eAAO,MAAM,oBAAoB,QAAqC,CAAC;AAoCvE;;;;;;;;+BAQ+B;AAC/B,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,WAAW,EAChB,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,aAAa,CAYf;AAED;;;;+DAI+D;AAC/D,wBAAgB,aAAa,CAC3B,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,EAChB,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAChC,OAAO,CAqCT;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAsB5C"}
|
package/dist/cel/compile.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isCompiledValue } from "@telorun/sdk";
|
|
2
2
|
import { extractAccessChains } from "./analyze.js";
|
|
3
|
+
import { CEL_FUNCTIONS } from "./catalog.js";
|
|
3
4
|
import { resolveModuleCalls } from "./module-call.js";
|
|
4
5
|
export const TEMPLATE_REGEX = /\$\{\{\s*([^}]+?)\s*\}\}/g;
|
|
5
6
|
export const EXACT_TEMPLATE_REGEX = /^\s*\$\{\{\s*([^}]+?)\s*\}\}\s*$/;
|
|
@@ -15,6 +16,27 @@ function rootRefs(ast) {
|
|
|
15
16
|
}
|
|
16
17
|
return [...roots];
|
|
17
18
|
}
|
|
19
|
+
const NON_DETERMINISTIC = new Set(CEL_FUNCTIONS.filter((f) => !f.deterministic).map((f) => f.name));
|
|
20
|
+
/** True when the expression calls a catalog function whose result differs per
|
|
21
|
+
* call (`uuidv4()`, `nowMillis()`), so evaluating it once and reusing the value
|
|
22
|
+
* would change what it means. */
|
|
23
|
+
function callsNonDeterministic(root) {
|
|
24
|
+
const visit = (node) => {
|
|
25
|
+
if (Array.isArray(node))
|
|
26
|
+
return node.some(visit);
|
|
27
|
+
if (!node || typeof node !== "object" || !("op" in node))
|
|
28
|
+
return false;
|
|
29
|
+
const n = node;
|
|
30
|
+
if ((n.op === "call" || n.op === "rcall") && Array.isArray(n.args)) {
|
|
31
|
+
const name = n.args[0];
|
|
32
|
+
if (typeof name === "string" && NON_DETERMINISTIC.has(name))
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const args = n.args;
|
|
36
|
+
return Array.isArray(args) ? args.some(visit) : visit(args);
|
|
37
|
+
};
|
|
38
|
+
return visit(root);
|
|
39
|
+
}
|
|
18
40
|
/** Compile a single CEL expression (no `${{ }}` wrapping) into a CompiledValue.
|
|
19
41
|
* Throws on syntax errors. Used by the `!cel` engine where the entire tagged
|
|
20
42
|
* scalar is treated as one expression.
|
|
@@ -33,6 +55,7 @@ export function compileExpression(expr, env, moduleNames) {
|
|
|
33
55
|
source: expr,
|
|
34
56
|
refs: rootRefs(ast),
|
|
35
57
|
calls,
|
|
58
|
+
...(callsNonDeterministic(ast) ? { volatile: true } : {}),
|
|
36
59
|
call: (ctx) => fn(ctx),
|
|
37
60
|
};
|
|
38
61
|
}
|
|
@@ -60,6 +83,7 @@ export function compileString(s, env, moduleNames) {
|
|
|
60
83
|
parts.push(s.slice(last));
|
|
61
84
|
const refs = new Set();
|
|
62
85
|
const calls = new Set();
|
|
86
|
+
let volatile = false;
|
|
63
87
|
for (const p of parts) {
|
|
64
88
|
if (typeof p === "string")
|
|
65
89
|
continue;
|
|
@@ -69,6 +93,8 @@ export function compileString(s, env, moduleNames) {
|
|
|
69
93
|
if (p.calls)
|
|
70
94
|
for (const c of p.calls)
|
|
71
95
|
calls.add(c);
|
|
96
|
+
if (p.volatile)
|
|
97
|
+
volatile = true;
|
|
72
98
|
}
|
|
73
99
|
return {
|
|
74
100
|
__compiled: true,
|
|
@@ -76,6 +102,7 @@ export function compileString(s, env, moduleNames) {
|
|
|
76
102
|
parts,
|
|
77
103
|
refs: [...refs],
|
|
78
104
|
calls: [...calls],
|
|
105
|
+
...(volatile ? { volatile: true } : {}),
|
|
79
106
|
call: (ctx) => parts.map((p) => (typeof p === "string" ? p : String(p.call(ctx) ?? ""))).join(""),
|
|
80
107
|
};
|
|
81
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/cel/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAG/D,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/cel/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAG/D,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAuBhD;;;;;;;;;;;;;;;yDAeyD;AACzD;;;;;wBAKwB;AACxB,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAyB5D;AAYD;;;;;yCAKyC;AACzC,wBAAgB,mBAAmB,IAAI,UAAU,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAC,CAE5F;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAcpF"}
|
package/dist/cel/environment.js
CHANGED
|
@@ -16,6 +16,7 @@ const STUB_HANDLERS = {
|
|
|
16
16
|
base64Encode: stub("base64Encode"),
|
|
17
17
|
base64Decode: stub("base64Decode"),
|
|
18
18
|
json: stub("json"),
|
|
19
|
+
joinPath: stub("joinPath"),
|
|
19
20
|
};
|
|
20
21
|
/** Build a CEL `Environment` with Telo's stdlib. Every function comes from the
|
|
21
22
|
* single-source catalog (`CEL_FUNCTIONS`), so registration and the documented
|
package/dist/engine.d.ts
CHANGED
|
@@ -172,6 +172,9 @@ export interface AnalyzeResult {
|
|
|
172
172
|
* costs no consumer a signature change. */
|
|
173
173
|
export interface EngineFileClaim {
|
|
174
174
|
readonly path: string;
|
|
175
|
+
/** The path may name a directory, which then claims every file beneath it.
|
|
176
|
+
* Whether it does is a question for whoever holds the directory. */
|
|
177
|
+
readonly directory?: boolean;
|
|
175
178
|
}
|
|
176
179
|
/** Per-property templating engine. Matches a YAML tag (`!<name>`); the kernel
|
|
177
180
|
* and analyzer dispatch through the registry rather than knowing about
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;wEAEwE;AACxE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC5C;AAED;;;;;;;;;eASe;AACf,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACvD;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAEjC;;;2DAGuD;IACvD,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAE3C;;qEAEiE;IACjE,QAAQ,CAAC,cAAc,CAAC,EAAE,sBA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CAiBuC;IACvC,YAAY,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C"}
|
|
@@ -17,6 +17,9 @@ export interface NormalizedIncludePath {
|
|
|
17
17
|
* the module happens to sit on disk.
|
|
18
18
|
*/
|
|
19
19
|
export declare function normalizeIncludePath(source: string): NormalizedIncludePath;
|
|
20
|
+
/** Normalize a `!module-path` source — a file or a directory that ships inside
|
|
21
|
+
* the module — by the same pure-string rules as an include path. */
|
|
22
|
+
export declare function normalizeModulePath(source: string): NormalizedIncludePath;
|
|
20
23
|
/** Embeds a file's contents as a UTF-8 string. */
|
|
21
24
|
export declare const includeTextEngine: TemplatingEngine;
|
|
22
25
|
/** Embeds a file's contents as raw bytes — the shape every `Telo.Bytes` slot
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"include.d.ts","sourceRoot":"","sources":["../../src/engines/include.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAaxF,MAAM,WAAW,qBAAqB;IACpC;kEAC8D;IAC9D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,
|
|
1
|
+
{"version":3,"file":"include.d.ts","sourceRoot":"","sources":["../../src/engines/include.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAaxF,MAAM,WAAW,qBAAqB;IACpC;kEAC8D;IAC9D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,CAE1E;AAED;qEACqE;AACrE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,CAEzE;AA2JD,kDAAkD;AAClD,eAAO,MAAM,iBAAiB,EAAE,gBAE9B,CAAC;AAEH;;;;YAIY;AACZ,eAAO,MAAM,kBAAkB,EAAE,gBAE/B,CAAC"}
|
package/dist/engines/include.js
CHANGED
|
@@ -19,30 +19,51 @@ const URI_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
|
19
19
|
* the module happens to sit on disk.
|
|
20
20
|
*/
|
|
21
21
|
export function normalizeIncludePath(source) {
|
|
22
|
+
return normalizeRootRelativePath(source, INCLUDE_PATH_GRAMMAR);
|
|
23
|
+
}
|
|
24
|
+
/** Normalize a `!module-path` source — a file or a directory that ships inside
|
|
25
|
+
* the module — by the same pure-string rules as an include path. */
|
|
26
|
+
export function normalizeModulePath(source) {
|
|
27
|
+
return normalizeRootRelativePath(source, MODULE_PATH_GRAMMAR);
|
|
28
|
+
}
|
|
29
|
+
const INCLUDE_PATH_GRAMMAR = {
|
|
30
|
+
invalid: "INCLUDE_PATH_INVALID",
|
|
31
|
+
escapes: "INCLUDE_PATH_ESCAPES_MODULE",
|
|
32
|
+
noun: "An include path",
|
|
33
|
+
names: "exactly one file",
|
|
34
|
+
elsewhere: "To read a file at runtime from somewhere else, use Fs.File.",
|
|
35
|
+
};
|
|
36
|
+
const MODULE_PATH_GRAMMAR = {
|
|
37
|
+
invalid: "MODULE_PATH_INVALID",
|
|
38
|
+
escapes: "MODULE_PATH_ESCAPES_MODULE",
|
|
39
|
+
noun: "A module path",
|
|
40
|
+
names: "one file or directory",
|
|
41
|
+
elsewhere: "A location on the host is a Telo.HostPath value, read from a variable.",
|
|
42
|
+
};
|
|
43
|
+
function normalizeRootRelativePath(source, grammar) {
|
|
22
44
|
const raw = source.trim();
|
|
23
45
|
if (raw === "") {
|
|
24
46
|
return {
|
|
25
47
|
diagnostic: {
|
|
26
|
-
code:
|
|
27
|
-
message: "the path is empty — name a
|
|
48
|
+
code: grammar.invalid,
|
|
49
|
+
message: "the path is empty — name a location relative to the module root.",
|
|
28
50
|
},
|
|
29
51
|
};
|
|
30
52
|
}
|
|
31
53
|
if (URI_SCHEME.test(raw)) {
|
|
32
54
|
return {
|
|
33
55
|
diagnostic: {
|
|
34
|
-
code:
|
|
35
|
-
message: `'${raw}' names a location outside the module.
|
|
36
|
-
`inside the module artifact, written relative to the module root.
|
|
37
|
-
`runtime from somewhere else, use Fs.File.`,
|
|
56
|
+
code: grammar.invalid,
|
|
57
|
+
message: `'${raw}' names a location outside the module. ${grammar.noun} names what ships ` +
|
|
58
|
+
`inside the module artifact, written relative to the module root. ${grammar.elsewhere}`,
|
|
38
59
|
},
|
|
39
60
|
};
|
|
40
61
|
}
|
|
41
62
|
if (GLOB_CHARS.test(raw)) {
|
|
42
63
|
return {
|
|
43
64
|
diagnostic: {
|
|
44
|
-
code:
|
|
45
|
-
message: `'${raw}' looks like a pattern.
|
|
65
|
+
code: grammar.invalid,
|
|
66
|
+
message: `'${raw}' looks like a pattern. ${grammar.noun} names ${grammar.names}, because ` +
|
|
46
67
|
`publish places each claimed file into a layer by name.`,
|
|
47
68
|
},
|
|
48
69
|
};
|
|
@@ -50,8 +71,8 @@ export function normalizeIncludePath(source) {
|
|
|
50
71
|
if (raw.startsWith("/") || raw.startsWith("\\")) {
|
|
51
72
|
return {
|
|
52
73
|
diagnostic: {
|
|
53
|
-
code:
|
|
54
|
-
message: `'${raw}' is an absolute path.
|
|
74
|
+
code: grammar.escapes,
|
|
75
|
+
message: `'${raw}' is an absolute path. ${grammar.noun} is written relative to the module ` +
|
|
55
76
|
`root, so the same manifest resolves identically from a checkout and from a ` +
|
|
56
77
|
`published artifact.`,
|
|
57
78
|
},
|
|
@@ -71,8 +92,8 @@ export function normalizeIncludePath(source) {
|
|
|
71
92
|
if (out.length === 0) {
|
|
72
93
|
return {
|
|
73
94
|
diagnostic: {
|
|
74
|
-
code:
|
|
75
|
-
message: `'${raw}' points above the module root.
|
|
95
|
+
code: grammar.escapes,
|
|
96
|
+
message: `'${raw}' points above the module root. ${grammar.noun} may only name what is ` +
|
|
76
97
|
`inside the module, since that is the only thing its artifact can carry.`,
|
|
77
98
|
},
|
|
78
99
|
};
|
|
@@ -82,8 +103,9 @@ export function normalizeIncludePath(source) {
|
|
|
82
103
|
if (out.length === 0) {
|
|
83
104
|
return {
|
|
84
105
|
diagnostic: {
|
|
85
|
-
code:
|
|
86
|
-
message: `'${raw}' resolves to the module root, not
|
|
106
|
+
code: grammar.invalid,
|
|
107
|
+
message: `'${raw}' resolves to the module root itself, which is not ${grammar.names} of it — ` +
|
|
108
|
+
`name what inside it you mean.`,
|
|
87
109
|
},
|
|
88
110
|
};
|
|
89
111
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TemplatingEngine } from "../engine.js";
|
|
2
|
+
/**
|
|
3
|
+
* The `!module-path` engine — a file or directory that ships inside the module,
|
|
4
|
+
* named by its LOCATION: at resource creation the kernel resolves it to the
|
|
5
|
+
* absolute path where the module's files are on disk (a checkout, or the
|
|
6
|
+
* materialized assets layer of a published artifact).
|
|
7
|
+
*
|
|
8
|
+
* The include engines' posture throughout: `compile` is identity on the marker,
|
|
9
|
+
* the path is a literal checked as a pure string, and `fileClaims` hands the
|
|
10
|
+
* path to publish and packaging so neither recognises the tag. A computed path
|
|
11
|
+
* is unrepresentable on purpose — what ships has a name known at publish time.
|
|
12
|
+
*
|
|
13
|
+
* It produces a `Telo.HostPath`: once resolved it is an absolute host path,
|
|
14
|
+
* which is what any slot declaring that type holds.
|
|
15
|
+
*/
|
|
16
|
+
export declare const modulePathEngine: TemplatingEngine;
|
|
17
|
+
//# sourceMappingURL=module-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-path.d.ts","sourceRoot":"","sources":["../../src/engines/module-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAItE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAoB9B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MODULE_PATH_ENGINE, makeTaggedSentinel } from "../sentinel.js";
|
|
2
|
+
import { normalizeModulePath } from "./include.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `!module-path` engine — a file or directory that ships inside the module,
|
|
5
|
+
* named by its LOCATION: at resource creation the kernel resolves it to the
|
|
6
|
+
* absolute path where the module's files are on disk (a checkout, or the
|
|
7
|
+
* materialized assets layer of a published artifact).
|
|
8
|
+
*
|
|
9
|
+
* The include engines' posture throughout: `compile` is identity on the marker,
|
|
10
|
+
* the path is a literal checked as a pure string, and `fileClaims` hands the
|
|
11
|
+
* path to publish and packaging so neither recognises the tag. A computed path
|
|
12
|
+
* is unrepresentable on purpose — what ships has a name known at publish time.
|
|
13
|
+
*
|
|
14
|
+
* It produces a `Telo.HostPath`: once resolved it is an absolute host path,
|
|
15
|
+
* which is what any slot declaring that type holds.
|
|
16
|
+
*/
|
|
17
|
+
export const modulePathEngine = {
|
|
18
|
+
name: MODULE_PATH_ENGINE,
|
|
19
|
+
compile(source) {
|
|
20
|
+
return makeTaggedSentinel(MODULE_PATH_ENGINE, source);
|
|
21
|
+
},
|
|
22
|
+
producedType() {
|
|
23
|
+
return { type: "string", "x-telo-type": "Telo.HostPath" };
|
|
24
|
+
},
|
|
25
|
+
analyze(source) {
|
|
26
|
+
const { diagnostic } = normalizeModulePath(source);
|
|
27
|
+
return { diagnostics: diagnostic ? [diagnostic] : [], calls: [] };
|
|
28
|
+
},
|
|
29
|
+
fileClaims(source) {
|
|
30
|
+
const { path } = normalizeModulePath(source);
|
|
31
|
+
return path ? [{ path, directory: true }] : [];
|
|
32
|
+
},
|
|
33
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,13 +6,14 @@ export { auditCalls, explainUnresolved, functionIndex, type CallAudit, type Modu
|
|
|
6
6
|
export { MODULE_CALL_DISPATCH_KEY, moduleCallOf, resolveModuleCalls, type ModuleCallDispatch, type ModuleCallTypeResolver, } from "./cel/module-call.js";
|
|
7
7
|
export { walkCelExpressions, type CelSurface } from "./cel/walk.js";
|
|
8
8
|
export { celEngine } from "./engines/cel.js";
|
|
9
|
-
export { includeBytesEngine, includeTextEngine, normalizeIncludePath, type NormalizedIncludePath, } from "./engines/include.js";
|
|
9
|
+
export { includeBytesEngine, includeTextEngine, normalizeIncludePath, normalizeModulePath, type NormalizedIncludePath, } from "./engines/include.js";
|
|
10
10
|
export { literalEngine } from "./engines/literal.js";
|
|
11
|
+
export { modulePathEngine } from "./engines/module-path.js";
|
|
11
12
|
export { refEngine } from "./engines/ref.js";
|
|
12
13
|
export { sqlEngine, isParameterizedSql, type ParameterizedSql } from "./engines/sql.js";
|
|
13
14
|
export { TemplatingEngineRegistry } from "./registry.js";
|
|
14
15
|
export { builtinEngines, createDefaultRegistry, defaultRegistry, producedTypeOf, } from "./builtins.js";
|
|
15
16
|
export type { AnalyzeEnv, AnalyzeResult, CallArgument, CallSite, CompileEnv, DiagnosticFix, EngineDiagnostic, EngineFileClaim, TemplatingEngine, } from "./engine.js";
|
|
16
|
-
export { CEL_ENGINE, INCLUDE_BYTES_ENGINE, INCLUDE_ENGINE_NAMES, INCLUDE_TEXT_ENGINE, isIncludeSentinel, isRefSentinel, isTaggedSentinel, makeTaggedSentinel, plainChainOf, type TaggedSentinel, } from "./sentinel.js";
|
|
17
|
+
export { CEL_ENGINE, INCLUDE_BYTES_ENGINE, INCLUDE_ENGINE_NAMES, INCLUDE_TEXT_ENGINE, isIncludeSentinel, isModulePathSentinel, isRefSentinel, isTaggedSentinel, makeTaggedSentinel, MODULE_FILE_ENGINE_NAMES, MODULE_PATH_ENGINE, plainChainOf, type TaggedSentinel, } from "./sentinel.js";
|
|
17
18
|
export { buildCustomTags, defaultCustomTags } from "./yaml-tags.js";
|
|
18
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,EACd,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,11 +11,12 @@ export { auditCalls, explainUnresolved, functionIndex, } from "./cel/diagnose.js
|
|
|
11
11
|
export { MODULE_CALL_DISPATCH_KEY, moduleCallOf, resolveModuleCalls, } from "./cel/module-call.js";
|
|
12
12
|
export { walkCelExpressions } from "./cel/walk.js";
|
|
13
13
|
export { celEngine } from "./engines/cel.js";
|
|
14
|
-
export { includeBytesEngine, includeTextEngine, normalizeIncludePath, } from "./engines/include.js";
|
|
14
|
+
export { includeBytesEngine, includeTextEngine, normalizeIncludePath, normalizeModulePath, } from "./engines/include.js";
|
|
15
15
|
export { literalEngine } from "./engines/literal.js";
|
|
16
|
+
export { modulePathEngine } from "./engines/module-path.js";
|
|
16
17
|
export { refEngine } from "./engines/ref.js";
|
|
17
18
|
export { sqlEngine, isParameterizedSql } from "./engines/sql.js";
|
|
18
19
|
export { TemplatingEngineRegistry } from "./registry.js";
|
|
19
20
|
export { builtinEngines, createDefaultRegistry, defaultRegistry, producedTypeOf, } from "./builtins.js";
|
|
20
|
-
export { CEL_ENGINE, INCLUDE_BYTES_ENGINE, INCLUDE_ENGINE_NAMES, INCLUDE_TEXT_ENGINE, isIncludeSentinel, isRefSentinel, isTaggedSentinel, makeTaggedSentinel, plainChainOf, } from "./sentinel.js";
|
|
21
|
+
export { CEL_ENGINE, INCLUDE_BYTES_ENGINE, INCLUDE_ENGINE_NAMES, INCLUDE_TEXT_ENGINE, isIncludeSentinel, isModulePathSentinel, isRefSentinel, isTaggedSentinel, makeTaggedSentinel, MODULE_FILE_ENGINE_NAMES, MODULE_PATH_ENGINE, plainChainOf, } from "./sentinel.js";
|
|
21
22
|
export { buildCustomTags, defaultCustomTags } from "./yaml-tags.js";
|
package/dist/sentinel.d.ts
CHANGED
|
@@ -28,6 +28,9 @@ export declare const CEL_ENGINE = "cel";
|
|
|
28
28
|
* themselves agree on one spelling. */
|
|
29
29
|
export declare const INCLUDE_TEXT_ENGINE = "include-text";
|
|
30
30
|
export declare const INCLUDE_BYTES_ENGINE = "include-bytes";
|
|
31
|
+
/** Engine name of the tag naming a file or directory that ships with the
|
|
32
|
+
* module, by its location rather than its contents. */
|
|
33
|
+
export declare const MODULE_PATH_ENGINE = "module-path";
|
|
31
34
|
/**
|
|
32
35
|
* The dotted chain a value names, or undefined.
|
|
33
36
|
*
|
|
@@ -56,4 +59,13 @@ export declare const INCLUDE_ENGINE_NAMES: ReadonlySet<string>;
|
|
|
56
59
|
export declare function isIncludeSentinel(v: unknown): v is TaggedSentinel & {
|
|
57
60
|
engine: typeof INCLUDE_TEXT_ENGINE | typeof INCLUDE_BYTES_ENGINE;
|
|
58
61
|
};
|
|
62
|
+
/** True when `v` is an unresolved `!module-path` sentinel. Resolved at resource
|
|
63
|
+
* creation beside the embeds, for the same reason: naming a module file must
|
|
64
|
+
* not pull the payload at manifest load. */
|
|
65
|
+
export declare function isModulePathSentinel(v: unknown): v is TaggedSentinel & {
|
|
66
|
+
engine: typeof MODULE_PATH_ENGINE;
|
|
67
|
+
};
|
|
68
|
+
/** Every tag that names a module file, for a check that holds for all of them
|
|
69
|
+
* (a tag on a document nothing instantiates is read by nothing). */
|
|
70
|
+
export declare const MODULE_FILE_ENGINE_NAMES: ReadonlySet<string>;
|
|
59
71
|
//# sourceMappingURL=sentinel.d.ts.map
|
package/dist/sentinel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentinel.d.ts","sourceRoot":"","sources":["../src/sentinel.ts"],"names":[],"mappings":"AAAA;;;;;YAKY;AACZ,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,CAQhE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAEjF;AAED;;;;4CAI4C;AAC5C,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,CAEjF;AAED;;gDAEgD;AAChD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,gBAAgB,CAAC;AAEhD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAa/D;AAED;mEACmE;AACnE,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAGnD,CAAC;AAEH;;;;;;;qCAOqC;AACrC,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,OAAO,mBAAmB,GAAG,OAAO,oBAAoB,CAAA;CAAE,CAI5F;AAED;;6CAE6C;AAC7C,wBAAgB,oBAAoB,CAClC,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,OAAO,kBAAkB,CAAA;CAAE,CAE7D;AAED;qEACqE;AACrE,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAIvD,CAAC"}
|
package/dist/sentinel.js
CHANGED
|
@@ -25,6 +25,9 @@ export const CEL_ENGINE = "cel";
|
|
|
25
25
|
* themselves agree on one spelling. */
|
|
26
26
|
export const INCLUDE_TEXT_ENGINE = "include-text";
|
|
27
27
|
export const INCLUDE_BYTES_ENGINE = "include-bytes";
|
|
28
|
+
/** Engine name of the tag naming a file or directory that ships with the
|
|
29
|
+
* module, by its location rather than its contents. */
|
|
30
|
+
export const MODULE_PATH_ENGINE = "module-path";
|
|
28
31
|
/**
|
|
29
32
|
* The dotted chain a value names, or undefined.
|
|
30
33
|
*
|
|
@@ -70,3 +73,16 @@ export const INCLUDE_ENGINE_NAMES = new Set([
|
|
|
70
73
|
export function isIncludeSentinel(v) {
|
|
71
74
|
return (isTaggedSentinel(v) && (v.engine === INCLUDE_TEXT_ENGINE || v.engine === INCLUDE_BYTES_ENGINE));
|
|
72
75
|
}
|
|
76
|
+
/** True when `v` is an unresolved `!module-path` sentinel. Resolved at resource
|
|
77
|
+
* creation beside the embeds, for the same reason: naming a module file must
|
|
78
|
+
* not pull the payload at manifest load. */
|
|
79
|
+
export function isModulePathSentinel(v) {
|
|
80
|
+
return isTaggedSentinel(v) && v.engine === MODULE_PATH_ENGINE;
|
|
81
|
+
}
|
|
82
|
+
/** Every tag that names a module file, for a check that holds for all of them
|
|
83
|
+
* (a tag on a document nothing instantiates is read by nothing). */
|
|
84
|
+
export const MODULE_FILE_ENGINE_NAMES = new Set([
|
|
85
|
+
INCLUDE_TEXT_ENGINE,
|
|
86
|
+
INCLUDE_BYTES_ENGINE,
|
|
87
|
+
MODULE_PATH_ENGINE,
|
|
88
|
+
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/templating",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Telo Templating - Engine registry and shared CEL core for Telo manifests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telo",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@types/node": "^20.0.0",
|
|
47
47
|
"typescript": "^5.0.0",
|
|
48
48
|
"vitest": "^2.1.8",
|
|
49
|
-
"@telorun/sdk": "0.
|
|
49
|
+
"@telorun/sdk": "0.98.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@telorun/sdk": "*"
|
package/src/builtins.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { celEngine } from "./engines/cel.js";
|
|
2
2
|
import { includeBytesEngine, includeTextEngine } from "./engines/include.js";
|
|
3
3
|
import { literalEngine } from "./engines/literal.js";
|
|
4
|
+
import { modulePathEngine } from "./engines/module-path.js";
|
|
4
5
|
import { refEngine } from "./engines/ref.js";
|
|
5
6
|
import { sqlEngine } from "./engines/sql.js";
|
|
6
7
|
import { TemplatingEngineRegistry } from "./registry.js";
|
|
@@ -17,6 +18,7 @@ export const builtinEngines: readonly TemplatingEngine[] = [
|
|
|
17
18
|
includeBytesEngine,
|
|
18
19
|
includeTextEngine,
|
|
19
20
|
literalEngine,
|
|
21
|
+
modulePathEngine,
|
|
20
22
|
refEngine,
|
|
21
23
|
sqlEngine,
|
|
22
24
|
];
|
package/src/cel/catalog.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface CelHandlers {
|
|
|
15
15
|
base64Encode: (s: string) => string;
|
|
16
16
|
base64Decode: (s: string) => string;
|
|
17
17
|
json: (value: unknown) => string;
|
|
18
|
+
/** Join a relative path onto a base with the HOST's path rules. */
|
|
19
|
+
joinPath: (base: string, relative: string) => string;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/** RE2 regex engine for the CEL `regex*` functions — `re2js`, a pure-JS port of
|
|
@@ -898,6 +900,21 @@ export const CEL_FUNCTIONS: readonly CelFunctionDoc[] = [
|
|
|
898
900
|
hostBacked: false,
|
|
899
901
|
build: () => (s: string) => JSON.parse(s),
|
|
900
902
|
},
|
|
903
|
+
// Paths. The one way to extend a host path: `variables.dataDir.joinPath('reports')`
|
|
904
|
+
// keeps it a `Telo.HostPath` (the analyzer types that overload), where `+`
|
|
905
|
+
// would make it a plain string. Host-backed because what a separator IS
|
|
906
|
+
// belongs to the machine running it.
|
|
907
|
+
{
|
|
908
|
+
name: "joinPath",
|
|
909
|
+
signature: "string.joinPath(string): string",
|
|
910
|
+
register: ["string.joinPath(string): string"],
|
|
911
|
+
category: "string",
|
|
912
|
+
summary:
|
|
913
|
+
"Join a relative path onto a path with the host's separator (`\\` on Windows). On a host path it yields a host path; an absolute argument is refused.",
|
|
914
|
+
deterministic: true,
|
|
915
|
+
hostBacked: true,
|
|
916
|
+
build: (h) => (base: string, relative: string) => h.joinPath(base, relative),
|
|
917
|
+
},
|
|
901
918
|
// Encoding
|
|
902
919
|
{
|
|
903
920
|
name: "base64Encode",
|
package/src/cel/compile.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isCompiledValue, type CompiledValue } from "@telorun/sdk";
|
|
2
2
|
import type { ASTNode, Environment } from "@marcbachmann/cel-js";
|
|
3
3
|
import { extractAccessChains } from "./analyze.js";
|
|
4
|
+
import { CEL_FUNCTIONS } from "./catalog.js";
|
|
4
5
|
import { resolveModuleCalls } from "./module-call.js";
|
|
5
6
|
|
|
6
7
|
export const TEMPLATE_REGEX = /\$\{\{\s*([^}]+?)\s*\}\}/g;
|
|
@@ -18,6 +19,28 @@ function rootRefs(ast: ASTNode): readonly string[] {
|
|
|
18
19
|
return [...roots];
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
const NON_DETERMINISTIC = new Set(
|
|
23
|
+
CEL_FUNCTIONS.filter((f) => !f.deterministic).map((f) => f.name),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
/** True when the expression calls a catalog function whose result differs per
|
|
27
|
+
* call (`uuidv4()`, `nowMillis()`), so evaluating it once and reusing the value
|
|
28
|
+
* would change what it means. */
|
|
29
|
+
function callsNonDeterministic(root: ASTNode): boolean {
|
|
30
|
+
const visit = (node: unknown): boolean => {
|
|
31
|
+
if (Array.isArray(node)) return node.some(visit);
|
|
32
|
+
if (!node || typeof node !== "object" || !("op" in node)) return false;
|
|
33
|
+
const n = node as ASTNode;
|
|
34
|
+
if ((n.op === "call" || n.op === "rcall") && Array.isArray(n.args)) {
|
|
35
|
+
const name = (n.args as unknown[])[0];
|
|
36
|
+
if (typeof name === "string" && NON_DETERMINISTIC.has(name)) return true;
|
|
37
|
+
}
|
|
38
|
+
const args = n.args as unknown;
|
|
39
|
+
return Array.isArray(args) ? args.some(visit) : visit(args);
|
|
40
|
+
};
|
|
41
|
+
return visit(root);
|
|
42
|
+
}
|
|
43
|
+
|
|
21
44
|
/** Compile a single CEL expression (no `${{ }}` wrapping) into a CompiledValue.
|
|
22
45
|
* Throws on syntax errors. Used by the `!cel` engine where the entire tagged
|
|
23
46
|
* scalar is treated as one expression.
|
|
@@ -40,6 +63,7 @@ export function compileExpression(
|
|
|
40
63
|
source: expr,
|
|
41
64
|
refs: rootRefs(ast),
|
|
42
65
|
calls,
|
|
66
|
+
...(callsNonDeterministic(ast) ? { volatile: true as const } : {}),
|
|
43
67
|
call: (ctx: Record<string, unknown>) => fn(ctx),
|
|
44
68
|
};
|
|
45
69
|
}
|
|
@@ -72,10 +96,12 @@ export function compileString(
|
|
|
72
96
|
|
|
73
97
|
const refs = new Set<string>();
|
|
74
98
|
const calls = new Set<string>();
|
|
99
|
+
let volatile = false;
|
|
75
100
|
for (const p of parts) {
|
|
76
101
|
if (typeof p === "string") continue;
|
|
77
102
|
if (p.refs) for (const r of p.refs) refs.add(r);
|
|
78
103
|
if (p.calls) for (const c of p.calls) calls.add(c);
|
|
104
|
+
if (p.volatile) volatile = true;
|
|
79
105
|
}
|
|
80
106
|
|
|
81
107
|
return {
|
|
@@ -84,6 +110,7 @@ export function compileString(
|
|
|
84
110
|
parts,
|
|
85
111
|
refs: [...refs],
|
|
86
112
|
calls: [...calls],
|
|
113
|
+
...(volatile ? { volatile: true as const } : {}),
|
|
87
114
|
call: (ctx: Record<string, unknown>) =>
|
|
88
115
|
parts.map((p) => (typeof p === "string" ? p : String(p.call(ctx) ?? ""))).join(""),
|
|
89
116
|
} satisfies CompiledValue;
|
package/src/cel/environment.ts
CHANGED
package/src/engine.ts
CHANGED
|
@@ -185,6 +185,9 @@ export interface AnalyzeResult {
|
|
|
185
185
|
* costs no consumer a signature change. */
|
|
186
186
|
export interface EngineFileClaim {
|
|
187
187
|
readonly path: string;
|
|
188
|
+
/** The path may name a directory, which then claims every file beneath it.
|
|
189
|
+
* Whether it does is a question for whoever holds the directory. */
|
|
190
|
+
readonly directory?: boolean;
|
|
188
191
|
}
|
|
189
192
|
|
|
190
193
|
/** Per-property templating engine. Matches a YAML tag (`!<name>`); the kernel
|
package/src/engines/include.ts
CHANGED
|
@@ -30,32 +30,73 @@ export interface NormalizedIncludePath {
|
|
|
30
30
|
* the module happens to sit on disk.
|
|
31
31
|
*/
|
|
32
32
|
export function normalizeIncludePath(source: string): NormalizedIncludePath {
|
|
33
|
+
return normalizeRootRelativePath(source, INCLUDE_PATH_GRAMMAR);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Normalize a `!module-path` source — a file or a directory that ships inside
|
|
37
|
+
* the module — by the same pure-string rules as an include path. */
|
|
38
|
+
export function normalizeModulePath(source: string): NormalizedIncludePath {
|
|
39
|
+
return normalizeRootRelativePath(source, MODULE_PATH_GRAMMAR);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What differs between the tags that name a module-root-relative location:
|
|
43
|
+
* their diagnostic codes and how a message names what the path must be. */
|
|
44
|
+
interface RootRelativeGrammar {
|
|
45
|
+
readonly invalid: string;
|
|
46
|
+
readonly escapes: string;
|
|
47
|
+
/** "An include path" / "A module path". */
|
|
48
|
+
readonly noun: string;
|
|
49
|
+
/** What one such path names, for the refusal of a pattern. */
|
|
50
|
+
readonly names: string;
|
|
51
|
+
/** Where a location outside the module is written instead. */
|
|
52
|
+
readonly elsewhere: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const INCLUDE_PATH_GRAMMAR: RootRelativeGrammar = {
|
|
56
|
+
invalid: "INCLUDE_PATH_INVALID",
|
|
57
|
+
escapes: "INCLUDE_PATH_ESCAPES_MODULE",
|
|
58
|
+
noun: "An include path",
|
|
59
|
+
names: "exactly one file",
|
|
60
|
+
elsewhere: "To read a file at runtime from somewhere else, use Fs.File.",
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const MODULE_PATH_GRAMMAR: RootRelativeGrammar = {
|
|
64
|
+
invalid: "MODULE_PATH_INVALID",
|
|
65
|
+
escapes: "MODULE_PATH_ESCAPES_MODULE",
|
|
66
|
+
noun: "A module path",
|
|
67
|
+
names: "one file or directory",
|
|
68
|
+
elsewhere: "A location on the host is a Telo.HostPath value, read from a variable.",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function normalizeRootRelativePath(
|
|
72
|
+
source: string,
|
|
73
|
+
grammar: RootRelativeGrammar,
|
|
74
|
+
): NormalizedIncludePath {
|
|
33
75
|
const raw = source.trim();
|
|
34
76
|
if (raw === "") {
|
|
35
77
|
return {
|
|
36
78
|
diagnostic: {
|
|
37
|
-
code:
|
|
38
|
-
message: "the path is empty — name a
|
|
79
|
+
code: grammar.invalid,
|
|
80
|
+
message: "the path is empty — name a location relative to the module root.",
|
|
39
81
|
},
|
|
40
82
|
};
|
|
41
83
|
}
|
|
42
84
|
if (URI_SCHEME.test(raw)) {
|
|
43
85
|
return {
|
|
44
86
|
diagnostic: {
|
|
45
|
-
code:
|
|
87
|
+
code: grammar.invalid,
|
|
46
88
|
message:
|
|
47
|
-
`'${raw}' names a location outside the module.
|
|
48
|
-
`inside the module artifact, written relative to the module root.
|
|
49
|
-
`runtime from somewhere else, use Fs.File.`,
|
|
89
|
+
`'${raw}' names a location outside the module. ${grammar.noun} names what ships ` +
|
|
90
|
+
`inside the module artifact, written relative to the module root. ${grammar.elsewhere}`,
|
|
50
91
|
},
|
|
51
92
|
};
|
|
52
93
|
}
|
|
53
94
|
if (GLOB_CHARS.test(raw)) {
|
|
54
95
|
return {
|
|
55
96
|
diagnostic: {
|
|
56
|
-
code:
|
|
97
|
+
code: grammar.invalid,
|
|
57
98
|
message:
|
|
58
|
-
`'${raw}' looks like a pattern.
|
|
99
|
+
`'${raw}' looks like a pattern. ${grammar.noun} names ${grammar.names}, because ` +
|
|
59
100
|
`publish places each claimed file into a layer by name.`,
|
|
60
101
|
},
|
|
61
102
|
};
|
|
@@ -63,9 +104,9 @@ export function normalizeIncludePath(source: string): NormalizedIncludePath {
|
|
|
63
104
|
if (raw.startsWith("/") || raw.startsWith("\\")) {
|
|
64
105
|
return {
|
|
65
106
|
diagnostic: {
|
|
66
|
-
code:
|
|
107
|
+
code: grammar.escapes,
|
|
67
108
|
message:
|
|
68
|
-
`'${raw}' is an absolute path.
|
|
109
|
+
`'${raw}' is an absolute path. ${grammar.noun} is written relative to the module ` +
|
|
69
110
|
`root, so the same manifest resolves identically from a checkout and from a ` +
|
|
70
111
|
`published artifact.`,
|
|
71
112
|
},
|
|
@@ -85,9 +126,9 @@ export function normalizeIncludePath(source: string): NormalizedIncludePath {
|
|
|
85
126
|
if (out.length === 0) {
|
|
86
127
|
return {
|
|
87
128
|
diagnostic: {
|
|
88
|
-
code:
|
|
129
|
+
code: grammar.escapes,
|
|
89
130
|
message:
|
|
90
|
-
`'${raw}' points above the module root.
|
|
131
|
+
`'${raw}' points above the module root. ${grammar.noun} may only name what is ` +
|
|
91
132
|
`inside the module, since that is the only thing its artifact can carry.`,
|
|
92
133
|
},
|
|
93
134
|
};
|
|
@@ -97,8 +138,10 @@ export function normalizeIncludePath(source: string): NormalizedIncludePath {
|
|
|
97
138
|
if (out.length === 0) {
|
|
98
139
|
return {
|
|
99
140
|
diagnostic: {
|
|
100
|
-
code:
|
|
101
|
-
message:
|
|
141
|
+
code: grammar.invalid,
|
|
142
|
+
message:
|
|
143
|
+
`'${raw}' resolves to the module root itself, which is not ${grammar.names} of it — ` +
|
|
144
|
+
`name what inside it you mean.`,
|
|
102
145
|
},
|
|
103
146
|
};
|
|
104
147
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { EngineFileClaim, TemplatingEngine } from "../engine.js";
|
|
2
|
+
import { MODULE_PATH_ENGINE, makeTaggedSentinel } from "../sentinel.js";
|
|
3
|
+
import { normalizeModulePath } from "./include.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The `!module-path` engine — a file or directory that ships inside the module,
|
|
7
|
+
* named by its LOCATION: at resource creation the kernel resolves it to the
|
|
8
|
+
* absolute path where the module's files are on disk (a checkout, or the
|
|
9
|
+
* materialized assets layer of a published artifact).
|
|
10
|
+
*
|
|
11
|
+
* The include engines' posture throughout: `compile` is identity on the marker,
|
|
12
|
+
* the path is a literal checked as a pure string, and `fileClaims` hands the
|
|
13
|
+
* path to publish and packaging so neither recognises the tag. A computed path
|
|
14
|
+
* is unrepresentable on purpose — what ships has a name known at publish time.
|
|
15
|
+
*
|
|
16
|
+
* It produces a `Telo.HostPath`: once resolved it is an absolute host path,
|
|
17
|
+
* which is what any slot declaring that type holds.
|
|
18
|
+
*/
|
|
19
|
+
export const modulePathEngine: TemplatingEngine = {
|
|
20
|
+
name: MODULE_PATH_ENGINE,
|
|
21
|
+
|
|
22
|
+
compile(source) {
|
|
23
|
+
return makeTaggedSentinel(MODULE_PATH_ENGINE, source);
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
producedType() {
|
|
27
|
+
return { type: "string", "x-telo-type": "Telo.HostPath" };
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
analyze(source) {
|
|
31
|
+
const { diagnostic } = normalizeModulePath(source);
|
|
32
|
+
return { diagnostics: diagnostic ? [diagnostic] : [], calls: [] };
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
fileClaims(source): readonly EngineFileClaim[] {
|
|
36
|
+
const { path } = normalizeModulePath(source);
|
|
37
|
+
return path ? [{ path, directory: true }] : [];
|
|
38
|
+
},
|
|
39
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -50,9 +50,11 @@ export {
|
|
|
50
50
|
includeBytesEngine,
|
|
51
51
|
includeTextEngine,
|
|
52
52
|
normalizeIncludePath,
|
|
53
|
+
normalizeModulePath,
|
|
53
54
|
type NormalizedIncludePath,
|
|
54
55
|
} from "./engines/include.js";
|
|
55
56
|
export { literalEngine } from "./engines/literal.js";
|
|
57
|
+
export { modulePathEngine } from "./engines/module-path.js";
|
|
56
58
|
export { refEngine } from "./engines/ref.js";
|
|
57
59
|
export { sqlEngine, isParameterizedSql, type ParameterizedSql } from "./engines/sql.js";
|
|
58
60
|
|
|
@@ -81,9 +83,12 @@ export {
|
|
|
81
83
|
INCLUDE_ENGINE_NAMES,
|
|
82
84
|
INCLUDE_TEXT_ENGINE,
|
|
83
85
|
isIncludeSentinel,
|
|
86
|
+
isModulePathSentinel,
|
|
84
87
|
isRefSentinel,
|
|
85
88
|
isTaggedSentinel,
|
|
86
89
|
makeTaggedSentinel,
|
|
90
|
+
MODULE_FILE_ENGINE_NAMES,
|
|
91
|
+
MODULE_PATH_ENGINE,
|
|
87
92
|
plainChainOf,
|
|
88
93
|
type TaggedSentinel,
|
|
89
94
|
} from "./sentinel.js";
|
package/src/sentinel.ts
CHANGED
|
@@ -44,6 +44,10 @@ export const CEL_ENGINE = "cel";
|
|
|
44
44
|
export const INCLUDE_TEXT_ENGINE = "include-text";
|
|
45
45
|
export const INCLUDE_BYTES_ENGINE = "include-bytes";
|
|
46
46
|
|
|
47
|
+
/** Engine name of the tag naming a file or directory that ships with the
|
|
48
|
+
* module, by its location rather than its contents. */
|
|
49
|
+
export const MODULE_PATH_ENGINE = "module-path";
|
|
50
|
+
|
|
47
51
|
/**
|
|
48
52
|
* The dotted chain a value names, or undefined.
|
|
49
53
|
*
|
|
@@ -94,3 +98,20 @@ export function isIncludeSentinel(
|
|
|
94
98
|
isTaggedSentinel(v) && (v.engine === INCLUDE_TEXT_ENGINE || v.engine === INCLUDE_BYTES_ENGINE)
|
|
95
99
|
);
|
|
96
100
|
}
|
|
101
|
+
|
|
102
|
+
/** True when `v` is an unresolved `!module-path` sentinel. Resolved at resource
|
|
103
|
+
* creation beside the embeds, for the same reason: naming a module file must
|
|
104
|
+
* not pull the payload at manifest load. */
|
|
105
|
+
export function isModulePathSentinel(
|
|
106
|
+
v: unknown,
|
|
107
|
+
): v is TaggedSentinel & { engine: typeof MODULE_PATH_ENGINE } {
|
|
108
|
+
return isTaggedSentinel(v) && v.engine === MODULE_PATH_ENGINE;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Every tag that names a module file, for a check that holds for all of them
|
|
112
|
+
* (a tag on a document nothing instantiates is read by nothing). */
|
|
113
|
+
export const MODULE_FILE_ENGINE_NAMES: ReadonlySet<string> = new Set([
|
|
114
|
+
INCLUDE_TEXT_ENGINE,
|
|
115
|
+
INCLUDE_BYTES_ENGINE,
|
|
116
|
+
MODULE_PATH_ENGINE,
|
|
117
|
+
]);
|