@telorun/templating 0.110.0 → 0.112.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,17 +1,21 @@
1
- # SUSTAINABLE USE LICENSE (Fair-code)
1
+ MIT License
2
2
 
3
3
  Copyright (c) 2026 CodeNet Sp. z o.o.
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and distribute the Software for any purpose—including commercial purposes—subject to the following conditions:
6
-
7
- 1. ANTI-COMPETITION RESTRICTION: The Software may not be provided to third parties as a managed service, commercial SaaS (Software-as-a-Service), PaaS (Platform-as-a-Service), BaaS (Backend-as-a-Service), or similar offering where the primary value provided to the user is the functionality of the Software itself, without a separate commercial license from the copyright holder.
8
-
9
- 2. PERMITTED COMMERCIAL USE: You are free to use the Software to build, host, and monetize your own commercial applications, products, and services, provided such use does not violate Clause 1.
10
-
11
- 3. ATTRIBUTION: This copyright notice and license must be included in all copies or substantial portions of the Software.
12
-
13
- 4. CONTRIBUTIONS: Contributions to the Software are welcome and encouraged. By contributing, you agree that your contributions may be incorporated into the Software and distributed under this license.
14
-
15
- 5. DISCLAIMER: The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
16
-
17
- For commercial licensing, managed hosting exemptions, or enterprise inquiries, please contact <contact@codenet.pl>.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -87,7 +87,16 @@ Those manifests were taken to the next level by allowing them to run inside a st
87
87
 
88
88
  ## License
89
89
 
90
- See [LICENSE](https://github.com/telorun/telo/blob/main/LICENSE).
90
+ Two licenses, split by directory. Each MIT directory carries its own `LICENSE`; everything else falls under the root [LICENSE](https://github.com/telorun/telo/blob/main/LICENSE), the Sustainable Use License.
91
+
92
+ | MIT | Sustainable Use |
93
+ | --- | --- |
94
+ | `cel/`, `sdk/`, `templating/`, `packages/glob/`, `packages/editor-protocol/` — the expression engine, the SDK and what a controller links against | `analyzer/`, `kernel/`, `cli/` — what loads, checks and runs a manifest |
95
+ | `modules/`, `blueprints/` — the standard library | `packages/ide-support/`, `packages/language-server/`, `packages/language-host/`, `ide/` — the editor tooling |
96
+ | `starters/`, `examples/`, `docs/`, `benchmarks/` | `packages/runner-core/`, `packages/debug-wire/`, `packages/debug-ui/`, `apps/docker-runner/`, `apps/k8s-runner/` — the runners |
97
+ | `apps/hub/`, `apps/hub-web/`, `apps/plan-approval*/` | `apps/studio/`, `apps/authoring-agent/`, `pages/` and everything not listed |
98
+
99
+ No MIT package depends on a Sustainable Use one, which `pnpm run check:licenses` enforces.
91
100
 
92
101
  ## Contribution Note
93
102
 
@@ -24,6 +24,25 @@ export declare function moduleCallArgumentChains(node: CelNode): Map<CelNode, Ar
24
24
  * member that can't be resolved to a static name. Consumers that attribute
25
25
  * chains to declared names treat this as "unknown member". */
26
26
  export declare const INDEX_SEGMENT = "[*]";
27
+ /** Chain segment for "each element of the collection reached so far": what a
28
+ * comprehension's iteration variable stands for. */
29
+ export declare const EACH_SEGMENT = "[]";
30
+ /**
31
+ * What an expression READS of the values its roots name, as member chains —
32
+ * {@link extractAccessChains} with a comprehension's iteration variable followed
33
+ * instead of dropped.
34
+ *
35
+ * - A member read through the variable is a read of THAT member on each element
36
+ * of the range: `xs.all(x, x.path != "")` reads `xs.[].path`.
37
+ * - A range that is only iterated is read as a range — its own node, none of
38
+ * its elements: the chain ends in {@link EACH_SEGMENT}.
39
+ * - A bare use of the variable reads the element whole, so the range is read
40
+ * whole, as it is by any other use of the collection.
41
+ *
42
+ * A variable whose range is not a plain chain (a call's result, another macro's
43
+ * output) names nothing a root holds, and a read through it contributes nothing.
44
+ */
45
+ export declare function extractReadChains(node: CelNode): string[][];
27
46
  /** A member access on a module call's result: the call, and the members read
28
47
  * off it in order (`Billing.total(xs).amount` → `amount`). */
29
48
  export interface CallResultAccess {
@@ -1 +1 @@
1
- {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../../src/cel/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,EAAE,CAI7D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAS5F;AA8FD;;+DAE+D;AAC/D,eAAO,MAAM,aAAa,QAAQ,CAAC;AA6BnC;+DAC+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;I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,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,EAAE,CAI3D;AA4DD;+DAC+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAI3E;AA4BD,UAAU,aAAa;IACrB,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB;AA0BD;;sBAEsB;AACtB,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,MAAM,GAAG,IAAI,CAIf;AA0DD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,OAAO,EACb,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjC,aAAa,EAAE,CAIjB;AA2ED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,MAAM,GAAG,IAAI,CAwCf"}
@@ -149,6 +149,87 @@ function extractChain(node, boundVars) {
149
149
  }
150
150
  return null;
151
151
  }
152
+ /** Chain segment for "each element of the collection reached so far": what a
153
+ * comprehension's iteration variable stands for. */
154
+ export const EACH_SEGMENT = "[]";
155
+ /**
156
+ * What an expression READS of the values its roots name, as member chains —
157
+ * {@link extractAccessChains} with a comprehension's iteration variable followed
158
+ * instead of dropped.
159
+ *
160
+ * - A member read through the variable is a read of THAT member on each element
161
+ * of the range: `xs.all(x, x.path != "")` reads `xs.[].path`.
162
+ * - A range that is only iterated is read as a range — its own node, none of
163
+ * its elements: the chain ends in {@link EACH_SEGMENT}.
164
+ * - A bare use of the variable reads the element whole, so the range is read
165
+ * whole, as it is by any other use of the collection.
166
+ *
167
+ * A variable whose range is not a plain chain (a call's result, another macro's
168
+ * output) names nothing a root holds, and a read through it contributes nothing.
169
+ */
170
+ export function extractReadChains(node) {
171
+ const chains = [];
172
+ visitReads(node, chains, new Map());
173
+ return chains;
174
+ }
175
+ function readChainOf(node, bound) {
176
+ if (node.kind === "ident") {
177
+ if (!node.absolute && bound.has(node.name)) {
178
+ const range = bound.get(node.name);
179
+ return range ? [...range, EACH_SEGMENT] : null;
180
+ }
181
+ return [node.name];
182
+ }
183
+ if (node.kind === "select") {
184
+ if (node.optional)
185
+ return null;
186
+ const parent = readChainOf(node.operand, bound);
187
+ if (parent !== null)
188
+ return [...parent, node.field];
189
+ }
190
+ if (node.kind === "index") {
191
+ if (node.optional)
192
+ return null;
193
+ const parent = readChainOf(node.operand, bound);
194
+ if (parent !== null)
195
+ return [...parent, INDEX_SEGMENT];
196
+ }
197
+ return null;
198
+ }
199
+ function visitReads(node, chains, bound) {
200
+ const chain = readChainOf(node, bound);
201
+ if (chain !== null) {
202
+ // The variable itself, with no member read off it: the whole element.
203
+ chains.push(chain[chain.length - 1] === EACH_SEGMENT ? chain.slice(0, -1) : chain);
204
+ return;
205
+ }
206
+ const moduleCall = moduleCallOf(node);
207
+ if (moduleCall) {
208
+ for (const arg of moduleCall.args)
209
+ visitReads(arg, chains, bound);
210
+ return;
211
+ }
212
+ const bind = bindCall(node);
213
+ if (bind) {
214
+ visitReads(bind.init, chains, bound);
215
+ visitReads(bind.body, chains, new Map(bound).set(bind.name, null));
216
+ return;
217
+ }
218
+ const macro = comprehension(node);
219
+ if (macro) {
220
+ const range = readChainOf(macro.receiver, bound);
221
+ if (range !== null)
222
+ chains.push([...range, EACH_SEGMENT]);
223
+ else
224
+ visitReads(macro.receiver, chains, bound);
225
+ const inner = new Map(bound).set(macro.bound, range);
226
+ for (const arg of macro.scoped)
227
+ visitReads(arg, chains, inner);
228
+ return;
229
+ }
230
+ for (const child of childNodes(node))
231
+ visitReads(child, chains, bound);
232
+ }
152
233
  /**
153
234
  * Every member access whose base is a module call, longest first — the chains
154
235
  * {@link extractAccessChains} deliberately skips, since their root is a value
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions,
2
2
  export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
3
3
  export { registerValueBrands } from "./cel/value-brands.js";
4
4
  export { interpolationShape, literalFragments, readInterpolationHoles, type HoleReading, type InterpolationHole, type InterpolationShape, } from "./cel/interpolation-holes.js";
5
- export { extractAccessChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
5
+ export { EACH_SEGMENT, extractAccessChains, extractReadChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
6
6
  export { auditCalls, explainUnresolved, type CallAudit, type ModuleCallFlags, } from "./cel/diagnose.js";
7
7
  export { celNamespaceNames, MODULE_CALL_DISPATCH_KEY, moduleCallNames, moduleCallOf, type ModuleCallDispatch, type ModuleCallTypeResolver, } from "./cel/module-call.js";
8
8
  export { walkCelExpressions } from "./cel/walk.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAk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B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,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,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,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
@@ -6,7 +6,7 @@ export { buildCelEnvironment, buildCelLanguageEnvironment, celBuiltinFunctions,
6
6
  export { compileExpression, namespaceDispatchOf } from "./cel/compile.js";
7
7
  export { registerValueBrands } from "./cel/value-brands.js";
8
8
  export { interpolationShape, literalFragments, readInterpolationHoles, } from "./cel/interpolation-holes.js";
9
- export { extractAccessChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
9
+ export { EACH_SEGMENT, extractAccessChains, extractReadChains, findNullableAccessIssues, INDEX_SEGMENT, validateChainAgainstSchema, } from "./cel/analyze.js";
10
10
  export { auditCalls, explainUnresolved, } from "./cel/diagnose.js";
11
11
  // The rewrite, its reader, and the activation key the kernel binds a scope's
12
12
  // dispatch table under. The unbound message and the receiver and bound-name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/templating",
3
- "version": "0.110.0",
3
+ "version": "0.112.0",
4
4
  "description": "Telo Templating - Engine registry and shared CEL core for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -9,7 +9,7 @@
9
9
  "yaml"
10
10
  ],
11
11
  "author": "Bartosz Pasiński <bartosz.pasinski@codenet.pl>",
12
- "license": "SEE LICENSE IN LICENSE",
12
+ "license": "MIT",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/telorun/telo.git",
@@ -39,14 +39,14 @@
39
39
  "re2js": "2.8.3",
40
40
  "uuid": "14.0.1",
41
41
  "yaml": "^2.8.3",
42
- "@telorun/cel": "0.110.0"
42
+ "@telorun/cel": "0.112.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/d3-format": "^3.0.4",
46
46
  "@types/node": "^20.0.0",
47
47
  "typescript": "^5.0.0",
48
48
  "vitest": "^2.1.8",
49
- "@telorun/sdk": "0.110.0"
49
+ "@telorun/sdk": "0.112.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@telorun/sdk": "*"
@@ -167,6 +167,89 @@ function extractChain(node: CelNode, boundVars: ReadonlySet<string>): string[] |
167
167
  return null;
168
168
  }
169
169
 
170
+ /** Chain segment for "each element of the collection reached so far": what a
171
+ * comprehension's iteration variable stands for. */
172
+ export const EACH_SEGMENT = "[]";
173
+
174
+ /**
175
+ * What an expression READS of the values its roots name, as member chains —
176
+ * {@link extractAccessChains} with a comprehension's iteration variable followed
177
+ * instead of dropped.
178
+ *
179
+ * - A member read through the variable is a read of THAT member on each element
180
+ * of the range: `xs.all(x, x.path != "")` reads `xs.[].path`.
181
+ * - A range that is only iterated is read as a range — its own node, none of
182
+ * its elements: the chain ends in {@link EACH_SEGMENT}.
183
+ * - A bare use of the variable reads the element whole, so the range is read
184
+ * whole, as it is by any other use of the collection.
185
+ *
186
+ * A variable whose range is not a plain chain (a call's result, another macro's
187
+ * output) names nothing a root holds, and a read through it contributes nothing.
188
+ */
189
+ export function extractReadChains(node: CelNode): string[][] {
190
+ const chains: string[][] = [];
191
+ visitReads(node, chains, new Map());
192
+ return chains;
193
+ }
194
+
195
+ /** A bound name's range as a chain, or null where it has none. */
196
+ type BoundRanges = ReadonlyMap<string, readonly string[] | null>;
197
+
198
+ function readChainOf(node: CelNode, bound: BoundRanges): string[] | null {
199
+ if (node.kind === "ident") {
200
+ if (!node.absolute && bound.has(node.name)) {
201
+ const range = bound.get(node.name);
202
+ return range ? [...range, EACH_SEGMENT] : null;
203
+ }
204
+ return [node.name];
205
+ }
206
+ if (node.kind === "select") {
207
+ if (node.optional) return null;
208
+ const parent = readChainOf(node.operand, bound);
209
+ if (parent !== null) return [...parent, node.field];
210
+ }
211
+ if (node.kind === "index") {
212
+ if (node.optional) return null;
213
+ const parent = readChainOf(node.operand, bound);
214
+ if (parent !== null) return [...parent, INDEX_SEGMENT];
215
+ }
216
+ return null;
217
+ }
218
+
219
+ function visitReads(node: CelNode, chains: string[][], bound: BoundRanges): void {
220
+ const chain = readChainOf(node, bound);
221
+ if (chain !== null) {
222
+ // The variable itself, with no member read off it: the whole element.
223
+ chains.push(chain[chain.length - 1] === EACH_SEGMENT ? chain.slice(0, -1) : chain);
224
+ return;
225
+ }
226
+
227
+ const moduleCall = moduleCallOf(node);
228
+ if (moduleCall) {
229
+ for (const arg of moduleCall.args) visitReads(arg, chains, bound);
230
+ return;
231
+ }
232
+
233
+ const bind = bindCall(node);
234
+ if (bind) {
235
+ visitReads(bind.init, chains, bound);
236
+ visitReads(bind.body, chains, new Map(bound).set(bind.name, null));
237
+ return;
238
+ }
239
+
240
+ const macro = comprehension(node);
241
+ if (macro) {
242
+ const range = readChainOf(macro.receiver, bound);
243
+ if (range !== null) chains.push([...range, EACH_SEGMENT]);
244
+ else visitReads(macro.receiver, chains, bound);
245
+ const inner = new Map(bound).set(macro.bound, range);
246
+ for (const arg of macro.scoped) visitReads(arg, chains, inner);
247
+ return;
248
+ }
249
+
250
+ for (const child of childNodes(node)) visitReads(child, chains, bound);
251
+ }
252
+
170
253
  /** A member access on a module call's result: the call, and the members read
171
254
  * off it in order (`Billing.total(xs).amount` → `amount`). */
172
255
  export interface CallResultAccess {
package/src/index.ts CHANGED
@@ -20,7 +20,9 @@ export {
20
20
  type InterpolationShape,
21
21
  } from "./cel/interpolation-holes.js";
22
22
  export {
23
+ EACH_SEGMENT,
23
24
  extractAccessChains,
25
+ extractReadChains,
24
26
  findNullableAccessIssues,
25
27
  INDEX_SEGMENT,
26
28
  validateChainAgainstSchema,