@telorun/templating 0.22.0 → 0.23.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.
@@ -1 +1 @@
1
- {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/cel/walk.ts"],"names":[],"mappings":"AAGA;;;;;;;;iFAQiF;AACjF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACzE;AAID;;;;;;;;;;8EAU8E;AAC9E,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,KAAK,IAAI,GAClF,IAAI,CAyCN"}
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../src/cel/walk.ts"],"names":[],"mappings":"AAGA;;;;;;;;iFAQiF;AACjF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACzE;AAID;;;;;;;;;;8EAU8E;AAC9E,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,KAAK,IAAI,GAClF,IAAI,CA8CN"}
package/dist/cel/walk.js CHANGED
@@ -18,6 +18,8 @@ export function walkCelExpressions(value, path, cb) {
18
18
  return;
19
19
  }
20
20
  if (typeof value === "string") {
21
+ if (!value.includes(OPEN))
22
+ return;
21
23
  const matches = [...value.matchAll(TEMPLATE_REGEX)];
22
24
  for (const m of matches) {
23
25
  const expr = m[1].trim();
@@ -46,9 +48,20 @@ export function walkCelExpressions(value, path, cb) {
46
48
  }
47
49
  if (value !== null &&
48
50
  typeof value === "object" &&
49
- !value.__compiled) {
50
- for (const [k, v] of Object.entries(value)) {
51
- walkCelExpressions(v, path ? `${path}.${k}` : k, cb);
51
+ !value.__compiled &&
52
+ isPlainObject(value)) {
53
+ // `for…in` over a plain object sees exactly its own enumerable keys, without
54
+ // the array `Object.entries` allocates — this walk runs over every resource
55
+ // a context creates.
56
+ for (const k in value) {
57
+ walkCelExpressions(value[k], path ? `${path}.${k}` : k, cb);
52
58
  }
53
59
  }
54
60
  }
61
+ /** A template body forwards `self.<ref>` as the LIVE instance, whose object graph
62
+ * is cyclic and holds no authored expression — walking it overflows the stack.
63
+ * The rule the include walk and `compileWalker` follow. */
64
+ function isPlainObject(value) {
65
+ const proto = Object.getPrototypeOf(value);
66
+ return proto === Object.prototype || proto === null;
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/templating",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Telo Templating - Engine registry and shared CEL core for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
package/src/cel/walk.ts CHANGED
@@ -38,6 +38,7 @@ export function walkCelExpressions(
38
38
  return;
39
39
  }
40
40
  if (typeof value === "string") {
41
+ if (!value.includes(OPEN)) return;
41
42
  const matches = [...value.matchAll(TEMPLATE_REGEX)];
42
43
  for (const m of matches) {
43
44
  const expr = m[1]!.trim();
@@ -67,10 +68,22 @@ export function walkCelExpressions(
67
68
  if (
68
69
  value !== null &&
69
70
  typeof value === "object" &&
70
- !(value as { __compiled?: unknown }).__compiled
71
+ !(value as { __compiled?: unknown }).__compiled &&
72
+ isPlainObject(value)
71
73
  ) {
72
- for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
73
- walkCelExpressions(v, path ? `${path}.${k}` : k, cb);
74
+ // `for…in` over a plain object sees exactly its own enumerable keys, without
75
+ // the array `Object.entries` allocates — this walk runs over every resource
76
+ // a context creates.
77
+ for (const k in value) {
78
+ walkCelExpressions((value as Record<string, unknown>)[k], path ? `${path}.${k}` : k, cb);
74
79
  }
75
80
  }
76
81
  }
82
+
83
+ /** A template body forwards `self.<ref>` as the LIVE instance, whose object graph
84
+ * is cyclic and holds no authored expression — walking it overflows the stack.
85
+ * The rule the include walk and `compileWalker` follow. */
86
+ function isPlainObject(value: object): boolean {
87
+ const proto = Object.getPrototypeOf(value);
88
+ return proto === Object.prototype || proto === null;
89
+ }