@telorun/templating 0.6.0 → 0.7.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/README.md +2 -2
- package/dist/cel/catalog.d.ts +4 -2
- package/dist/cel/catalog.d.ts.map +1 -1
- package/dist/cel/catalog.js +2 -4
- package/dist/cel/environment.d.ts +7 -0
- package/dist/cel/environment.d.ts.map +1 -1
- package/dist/cel/environment.js +40 -3
- package/package.json +3 -3
- package/src/cel/catalog.ts +6 -6
- package/src/cel/environment.ts +38 -3
package/README.md
CHANGED
|
@@ -55,8 +55,8 @@ metadata:
|
|
|
55
55
|
A complete feedback collection REST API — no code, pure YAML.
|
|
56
56
|
Persists entries to SQLite and serves them over HTTP.
|
|
57
57
|
imports:
|
|
58
|
-
Http: std/http-server@0.
|
|
59
|
-
Sql: std/sql@0.
|
|
58
|
+
Http: std/http-server@0.9.0
|
|
59
|
+
Sql: std/sql@0.8.0
|
|
60
60
|
targets:
|
|
61
61
|
- Migrations
|
|
62
62
|
- Server
|
package/dist/cel/catalog.d.ts
CHANGED
|
@@ -24,8 +24,10 @@ export interface CelFunctionDoc {
|
|
|
24
24
|
* optional args even though cel-js itself has no optional syntax. */
|
|
25
25
|
readonly signature: string;
|
|
26
26
|
/** Actual cel-js signatures to register — one per arity for an overloaded
|
|
27
|
-
* function.
|
|
28
|
-
*
|
|
27
|
+
* function. When omitted, `deriveSignatures(signature)` is used: if the
|
|
28
|
+
* signature contains `type?`-marked optional params (e.g. `fn(string?): T`),
|
|
29
|
+
* it auto-expands to one registration per arity. Set `register` explicitly
|
|
30
|
+
* only when the auto-derivation is insufficient. */
|
|
29
31
|
readonly register?: readonly string[];
|
|
30
32
|
readonly category: CelFunctionCategory;
|
|
31
33
|
readonly summary: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/cel/catalog.ts"],"names":[],"mappings":"AAEA;;;0DAG0D;AAC1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ist/cel/catalog.js
CHANGED
|
@@ -359,8 +359,7 @@ export const CEL_FUNCTIONS = [
|
|
|
359
359
|
// (default "UTC"); epoch values are absolute and take none.
|
|
360
360
|
{
|
|
361
361
|
name: "nowIso",
|
|
362
|
-
signature: "nowIso(
|
|
363
|
-
register: ["nowIso(): string", "nowIso(string): string"],
|
|
362
|
+
signature: "nowIso(string?): string",
|
|
364
363
|
category: "time",
|
|
365
364
|
summary: "Current time as ISO-8601; UTC by default, or in the given IANA timezone.",
|
|
366
365
|
deterministic: false,
|
|
@@ -369,8 +368,7 @@ export const CEL_FUNCTIONS = [
|
|
|
369
368
|
},
|
|
370
369
|
{
|
|
371
370
|
name: "today",
|
|
372
|
-
signature: "today(
|
|
373
|
-
register: ["today(): string", "today(string): string"],
|
|
371
|
+
signature: "today(string?): string",
|
|
374
372
|
category: "time",
|
|
375
373
|
summary: "Current calendar date (YYYY-MM-DD); UTC by default, or in the given IANA timezone.",
|
|
376
374
|
deterministic: false,
|
|
@@ -17,5 +17,12 @@ export type { CelHandlers } from "./catalog.js";
|
|
|
17
17
|
* no fields, so terminal access (passing the value through CEL) succeeds but
|
|
18
18
|
* member access raises a CEL error at runtime — matching the analyzer's
|
|
19
19
|
* static check on `x-telo-stream`-marked properties. */
|
|
20
|
+
/** Expand a documented signature that may contain `type?`-marked optional
|
|
21
|
+
* parameters into one cel-js registration signature per arity. For example,
|
|
22
|
+
* `"nowIso(string?): string"` produces `["nowIso(): string",
|
|
23
|
+
* "nowIso(string): string"]`. Required parameters must precede optional ones.
|
|
24
|
+
* Returns `[signature]` unchanged when no `?` is present or the signature
|
|
25
|
+
* cannot be parsed. */
|
|
26
|
+
export declare function deriveSignatures(signature: string): string[];
|
|
20
27
|
export declare function buildCelEnvironment(handlers?: Partial<CelHandlers>): Environment;
|
|
21
28
|
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -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;AAE/D,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAoBhD;;;;;;;;;;;;;;;yDAeyD;AACzD,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,
|
|
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;AAE/D,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAoBhD;;;;;;;;;;;;;;;yDAeyD;AACzD;;;;;wBAKwB;AACxB,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAyB5D;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAcpF"}
|
package/dist/cel/environment.js
CHANGED
|
@@ -31,14 +31,51 @@ const STUB_HANDLERS = {
|
|
|
31
31
|
* no fields, so terminal access (passing the value through CEL) succeeds but
|
|
32
32
|
* member access raises a CEL error at runtime — matching the analyzer's
|
|
33
33
|
* static check on `x-telo-stream`-marked properties. */
|
|
34
|
+
/** Expand a documented signature that may contain `type?`-marked optional
|
|
35
|
+
* parameters into one cel-js registration signature per arity. For example,
|
|
36
|
+
* `"nowIso(string?): string"` produces `["nowIso(): string",
|
|
37
|
+
* "nowIso(string): string"]`. Required parameters must precede optional ones.
|
|
38
|
+
* Returns `[signature]` unchanged when no `?` is present or the signature
|
|
39
|
+
* cannot be parsed. */
|
|
40
|
+
export function deriveSignatures(signature) {
|
|
41
|
+
const m = signature.match(/^(\w+)\((.*?)\):\s*(.+)$/);
|
|
42
|
+
if (!m)
|
|
43
|
+
return [signature];
|
|
44
|
+
const name = m[1];
|
|
45
|
+
const paramsStr = m[2].trim();
|
|
46
|
+
const returnType = m[3].trim();
|
|
47
|
+
if (!paramsStr.includes("?"))
|
|
48
|
+
return [signature];
|
|
49
|
+
const params = paramsStr.split(",").map((p) => p.trim());
|
|
50
|
+
const required = [];
|
|
51
|
+
const optional = [];
|
|
52
|
+
for (const p of params) {
|
|
53
|
+
if (p.endsWith("?")) {
|
|
54
|
+
optional.push(p.slice(0, -1));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
if (optional.length > 0)
|
|
58
|
+
return [signature];
|
|
59
|
+
required.push(p);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (optional.length === 0)
|
|
63
|
+
return [signature];
|
|
64
|
+
return Array.from({ length: optional.length + 1 }, (_, i) => {
|
|
65
|
+
const allParams = [...required, ...optional.slice(0, i)];
|
|
66
|
+
return `${name}(${allParams.join(", ")}): ${returnType}`;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
34
69
|
export function buildCelEnvironment(handlers = {}) {
|
|
35
70
|
const h = { ...STUB_HANDLERS, ...handlers };
|
|
36
71
|
let env = new Environment({ unlistedVariablesAreDyn: true, enableOptionalTypes: true });
|
|
37
72
|
for (const fn of CEL_FUNCTIONS) {
|
|
38
73
|
const impl = fn.build(h);
|
|
39
|
-
// `register` lists one cel-js signature per arity (overloaded functions)
|
|
40
|
-
//
|
|
41
|
-
|
|
74
|
+
// `register` lists one cel-js signature per arity (overloaded functions).
|
|
75
|
+
// When absent, `deriveSignatures` expands `type?` optional-param notation
|
|
76
|
+
// into one registration per arity — so `nowIso(string?): string` registers
|
|
77
|
+
// both `nowIso(): string` and `nowIso(string): string` automatically.
|
|
78
|
+
for (const sig of fn.register ?? deriveSignatures(fn.signature)) {
|
|
42
79
|
env = env.registerFunction(sig, impl);
|
|
43
80
|
}
|
|
44
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/templating",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Telo Templating - Engine registry and shared CEL core for Telo manifests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"telo",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"src/**"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@marcbachmann/cel-js": "^7.
|
|
38
|
+
"@marcbachmann/cel-js": "^7.6.1",
|
|
39
39
|
"uuid": "^10.0.0",
|
|
40
40
|
"yaml": "^2.8.3"
|
|
41
41
|
},
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@types/uuid": "^10.0.0",
|
|
45
45
|
"typescript": "^5.0.0",
|
|
46
46
|
"vitest": "^2.1.8",
|
|
47
|
-
"@telorun/sdk": "0.
|
|
47
|
+
"@telorun/sdk": "0.23.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@telorun/sdk": "*"
|
package/src/cel/catalog.ts
CHANGED
|
@@ -38,8 +38,10 @@ export interface CelFunctionDoc {
|
|
|
38
38
|
* optional args even though cel-js itself has no optional syntax. */
|
|
39
39
|
readonly signature: string;
|
|
40
40
|
/** Actual cel-js signatures to register — one per arity for an overloaded
|
|
41
|
-
* function.
|
|
42
|
-
*
|
|
41
|
+
* function. When omitted, `deriveSignatures(signature)` is used: if the
|
|
42
|
+
* signature contains `type?`-marked optional params (e.g. `fn(string?): T`),
|
|
43
|
+
* it auto-expands to one registration per arity. Set `register` explicitly
|
|
44
|
+
* only when the auto-derivation is insufficient. */
|
|
43
45
|
readonly register?: readonly string[];
|
|
44
46
|
readonly category: CelFunctionCategory;
|
|
45
47
|
readonly summary: string;
|
|
@@ -423,8 +425,7 @@ export const CEL_FUNCTIONS: readonly CelFunctionDoc[] = [
|
|
|
423
425
|
// (default "UTC"); epoch values are absolute and take none.
|
|
424
426
|
{
|
|
425
427
|
name: "nowIso",
|
|
426
|
-
signature: "nowIso(
|
|
427
|
-
register: ["nowIso(): string", "nowIso(string): string"],
|
|
428
|
+
signature: "nowIso(string?): string",
|
|
428
429
|
category: "time",
|
|
429
430
|
summary: "Current time as ISO-8601; UTC by default, or in the given IANA timezone.",
|
|
430
431
|
deterministic: false,
|
|
@@ -433,8 +434,7 @@ export const CEL_FUNCTIONS: readonly CelFunctionDoc[] = [
|
|
|
433
434
|
},
|
|
434
435
|
{
|
|
435
436
|
name: "today",
|
|
436
|
-
signature: "today(
|
|
437
|
-
register: ["today(): string", "today(string): string"],
|
|
437
|
+
signature: "today(string?): string",
|
|
438
438
|
category: "time",
|
|
439
439
|
summary: "Current calendar date (YYYY-MM-DD); UTC by default, or in the given IANA timezone.",
|
|
440
440
|
deterministic: false,
|
package/src/cel/environment.ts
CHANGED
|
@@ -38,14 +38,49 @@ const STUB_HANDLERS: CelHandlers = {
|
|
|
38
38
|
* no fields, so terminal access (passing the value through CEL) succeeds but
|
|
39
39
|
* member access raises a CEL error at runtime — matching the analyzer's
|
|
40
40
|
* static check on `x-telo-stream`-marked properties. */
|
|
41
|
+
/** Expand a documented signature that may contain `type?`-marked optional
|
|
42
|
+
* parameters into one cel-js registration signature per arity. For example,
|
|
43
|
+
* `"nowIso(string?): string"` produces `["nowIso(): string",
|
|
44
|
+
* "nowIso(string): string"]`. Required parameters must precede optional ones.
|
|
45
|
+
* Returns `[signature]` unchanged when no `?` is present or the signature
|
|
46
|
+
* cannot be parsed. */
|
|
47
|
+
export function deriveSignatures(signature: string): string[] {
|
|
48
|
+
const m = signature.match(/^(\w+)\((.*?)\):\s*(.+)$/);
|
|
49
|
+
if (!m) return [signature];
|
|
50
|
+
const name = m[1]!;
|
|
51
|
+
const paramsStr = m[2]!.trim();
|
|
52
|
+
const returnType = m[3]!.trim();
|
|
53
|
+
if (!paramsStr.includes("?")) return [signature];
|
|
54
|
+
|
|
55
|
+
const params = paramsStr.split(",").map((p) => p.trim());
|
|
56
|
+
const required: string[] = [];
|
|
57
|
+
const optional: string[] = [];
|
|
58
|
+
for (const p of params) {
|
|
59
|
+
if (p.endsWith("?")) {
|
|
60
|
+
optional.push(p.slice(0, -1));
|
|
61
|
+
} else {
|
|
62
|
+
if (optional.length > 0) return [signature];
|
|
63
|
+
required.push(p);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (optional.length === 0) return [signature];
|
|
67
|
+
|
|
68
|
+
return Array.from({ length: optional.length + 1 }, (_, i) => {
|
|
69
|
+
const allParams = [...required, ...optional.slice(0, i)];
|
|
70
|
+
return `${name}(${allParams.join(", ")}): ${returnType}`;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
41
74
|
export function buildCelEnvironment(handlers: Partial<CelHandlers> = {}): Environment {
|
|
42
75
|
const h: CelHandlers = { ...STUB_HANDLERS, ...handlers };
|
|
43
76
|
let env = new Environment({ unlistedVariablesAreDyn: true, enableOptionalTypes: true });
|
|
44
77
|
for (const fn of CEL_FUNCTIONS) {
|
|
45
78
|
const impl = fn.build(h);
|
|
46
|
-
// `register` lists one cel-js signature per arity (overloaded functions)
|
|
47
|
-
//
|
|
48
|
-
|
|
79
|
+
// `register` lists one cel-js signature per arity (overloaded functions).
|
|
80
|
+
// When absent, `deriveSignatures` expands `type?` optional-param notation
|
|
81
|
+
// into one registration per arity — so `nowIso(string?): string` registers
|
|
82
|
+
// both `nowIso(): string` and `nowIso(string): string` automatically.
|
|
83
|
+
for (const sig of fn.register ?? deriveSignatures(fn.signature)) {
|
|
49
84
|
env = env.registerFunction(sig, impl);
|
|
50
85
|
}
|
|
51
86
|
}
|