@abyss-project/runtime 3.4.0 → 3.6.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.
Files changed (58) hide show
  1. package/.eslintrc.js +32 -32
  2. package/.prettierrc +5 -5
  3. package/dist/discord/discord.types.d.ts +167 -4
  4. package/dist/discord/discord.types.js +48 -1
  5. package/dist/discord/discord.types.js.map +1 -1
  6. package/dist/engine/engine-source.js +1 -1
  7. package/dist/interpreter/interpreter.js +18 -4
  8. package/dist/interpreter/interpreter.js.map +1 -1
  9. package/dist/interpreter/interpreter.types.d.ts +2 -0
  10. package/dist/interpreter/interpreter.types.js.map +1 -1
  11. package/dist/runner-protocol/execution-protocol.types.d.ts +11 -0
  12. package/dist/runner-protocol/execution-protocol.types.js +2 -1
  13. package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
  14. package/jest.config.ts +11 -11
  15. package/package.json +15 -10
  16. package/scripts/build-engine.cjs +70 -70
  17. package/src/__tests__/engine-bundle.test.ts +121 -121
  18. package/src/__tests__/surface.test.ts +5 -1
  19. package/src/access/__tests__/host-match.test.ts +24 -24
  20. package/src/access/access.types.ts +25 -25
  21. package/src/access/host-match.ts +13 -13
  22. package/src/cost/__tests__/execution-cost.test.ts +196 -196
  23. package/src/cost/execution-cost.ts +186 -186
  24. package/src/definition/__tests__/validate-definition.test.ts +354 -354
  25. package/src/definition/definition.limits.ts +9 -9
  26. package/src/definition/definition.schema.ts +172 -172
  27. package/src/definition/definition.types.ts +171 -171
  28. package/src/definition/validate-definition.ts +206 -206
  29. package/src/definition/walk-steps.ts +44 -44
  30. package/src/discord/discord.types.ts +264 -5
  31. package/src/engine/__tests__/run-in-isolate.test.ts +468 -468
  32. package/src/engine/engine-entry.ts +3 -3
  33. package/src/engine/engine-global.ts +2 -2
  34. package/src/engine/run-in-isolate.ts +404 -404
  35. package/src/errors/runtime-error-code.enum.ts +37 -37
  36. package/src/index.ts +32 -32
  37. package/src/interpreter/__tests__/interpreter.test.ts +854 -854
  38. package/src/interpreter/__tests__/log-respond-resume.test.ts +270 -223
  39. package/src/interpreter/interpreter-error.ts +12 -12
  40. package/src/interpreter/interpreter.ts +482 -461
  41. package/src/interpreter/interpreter.types.ts +202 -192
  42. package/src/interpreter/sequence-path.ts +67 -67
  43. package/src/interpreter/test-host.ts +85 -85
  44. package/src/runner-protocol/evaluation.types.ts +21 -21
  45. package/src/runner-protocol/execution-protocol.types.ts +254 -231
  46. package/src/schedule/schedule.types.ts +100 -100
  47. package/src/server/__tests__/code-runner-session.test.ts +311 -311
  48. package/src/server/code-runner-error.ts +12 -12
  49. package/src/server/code-runner-session.ts +310 -310
  50. package/src/server/index.ts +11 -11
  51. package/src/steps/__tests__/global-references.test.ts +133 -133
  52. package/src/steps/execute-step.ts +186 -186
  53. package/src/steps/global-references.ts +48 -48
  54. package/src/steps/step-access.ts +56 -56
  55. package/src/steps/step-fields.ts +87 -87
  56. package/src/steps/value-source.ts +69 -69
  57. package/tsconfig.check.json +15 -15
  58. package/tsconfig.json +35 -35
@@ -1,48 +1,48 @@
1
- import { EvaluationKind } from '../runner-protocol/evaluation.types';
2
- import type { RuntimeDefinition } from '../definition/definition.types';
3
- import { walkSteps } from '../definition/walk-steps';
4
- import { collectStepItems } from './step-fields';
5
-
6
- const PLACEHOLDER = /\{\{([\s\S]*?)\}\}/g;
7
-
8
- const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
9
-
10
- /** The JavaScript an item runs: a template only runs what is inside its placeholders. */
11
- const codeOf = (kind: EvaluationKind, source: string): string[] =>
12
- kind === EvaluationKind.TEMPLATE
13
- ? [...source.matchAll(PLACEHOLDER)].map((match) => match[1])
14
- : [source];
15
-
16
- /**
17
- * The property names a definition reads statically from the host global `globalName`
18
- * (`ExecuteMessage.globals`), as `<globalName>.<IDENT>`, `<globalName>?.<IDENT>` or
19
- * `<globalName>['<IDENT>']` (either quote), in every expression, template placeholder and CODE
20
- * source, branches included. Names come once each, in order of first appearance.
21
- *
22
- * It is a textual scan, so a string literal that spells such an access counts too: a host that
23
- * resolves the names it finds only over-resolves. A dynamic access (`secrets[name]`) cannot be
24
- * resolved ahead of time: it yields `undefined` at run time. `abyss.secrets.get(name)` is the
25
- * dynamic path.
26
- */
27
- export const collectGlobalReferences = (
28
- definition: Pick<RuntimeDefinition, 'steps'>,
29
- globalName: string,
30
- ): string[] => {
31
- const name = escapeRegExp(globalName);
32
- // Not preceded by an identifier character or a dot: `other.secrets.A` is not a read of `secrets`.
33
- const access = new RegExp(
34
- `(?<![\\w$.])${name}\\s*(?:\\??\\.\\s*([A-Za-z_$][\\w$]*)|\\[\\s*(['"])([A-Za-z_$][\\w$]*)\\2\\s*\\])`,
35
- 'g',
36
- );
37
- const found = new Set<string>();
38
- walkSteps(definition.steps, (step) => {
39
- for (const item of collectStepItems(step)) {
40
- for (const code of codeOf(item.kind, item.source)) {
41
- for (const match of code.matchAll(access)) {
42
- found.add(match[1] ?? match[3]);
43
- }
44
- }
45
- }
46
- });
47
- return [...found];
48
- };
1
+ import { EvaluationKind } from '../runner-protocol/evaluation.types';
2
+ import type { RuntimeDefinition } from '../definition/definition.types';
3
+ import { walkSteps } from '../definition/walk-steps';
4
+ import { collectStepItems } from './step-fields';
5
+
6
+ const PLACEHOLDER = /\{\{([\s\S]*?)\}\}/g;
7
+
8
+ const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
9
+
10
+ /** The JavaScript an item runs: a template only runs what is inside its placeholders. */
11
+ const codeOf = (kind: EvaluationKind, source: string): string[] =>
12
+ kind === EvaluationKind.TEMPLATE
13
+ ? [...source.matchAll(PLACEHOLDER)].map((match) => match[1])
14
+ : [source];
15
+
16
+ /**
17
+ * The property names a definition reads statically from the host global `globalName`
18
+ * (`ExecuteMessage.globals`), as `<globalName>.<IDENT>`, `<globalName>?.<IDENT>` or
19
+ * `<globalName>['<IDENT>']` (either quote), in every expression, template placeholder and CODE
20
+ * source, branches included. Names come once each, in order of first appearance.
21
+ *
22
+ * It is a textual scan, so a string literal that spells such an access counts too: a host that
23
+ * resolves the names it finds only over-resolves. A dynamic access (`secrets[name]`) cannot be
24
+ * resolved ahead of time: it yields `undefined` at run time. `abyss.secrets.get(name)` is the
25
+ * dynamic path.
26
+ */
27
+ export const collectGlobalReferences = (
28
+ definition: Pick<RuntimeDefinition, 'steps'>,
29
+ globalName: string,
30
+ ): string[] => {
31
+ const name = escapeRegExp(globalName);
32
+ // Not preceded by an identifier character or a dot: `other.secrets.A` is not a read of `secrets`.
33
+ const access = new RegExp(
34
+ `(?<![\\w$.])${name}\\s*(?:\\??\\.\\s*([A-Za-z_$][\\w$]*)|\\[\\s*(['"])([A-Za-z_$][\\w$]*)\\2\\s*\\])`,
35
+ 'g',
36
+ );
37
+ const found = new Set<string>();
38
+ walkSteps(definition.steps, (step) => {
39
+ for (const item of collectStepItems(step)) {
40
+ for (const code of codeOf(item.kind, item.source)) {
41
+ for (const match of code.matchAll(access)) {
42
+ found.add(match[1] ?? match[3]);
43
+ }
44
+ }
45
+ }
46
+ });
47
+ return [...found];
48
+ };
@@ -1,56 +1,56 @@
1
- import { AccessKind } from '../access/access.types';
2
- import type { AccessDeclaration } from '../access/access.types';
3
- import { hostMatches } from '../access/host-match';
4
-
5
- export enum AccessVerdict {
6
- ALLOWED = 'ALLOWED',
7
- NOT_DECLARED = 'NOT_DECLARED',
8
- NOT_GRANTED = 'NOT_GRANTED',
9
- }
10
-
11
- const coversHost = (accesses: AccessDeclaration[], host: string): boolean =>
12
- accesses.some(
13
- (access) =>
14
- access.kind === AccessKind.HTTP && access.hosts.some((pattern) => hostMatches(host, pattern)),
15
- );
16
-
17
- const coversAction = (accesses: AccessDeclaration[], action: string): boolean =>
18
- accesses.some((access) => access.kind === AccessKind.HOST_ACTION && access.action === action);
19
-
20
- const verdict = (declared: boolean, granted: boolean): AccessVerdict => {
21
- if (!declared) {
22
- return AccessVerdict.NOT_DECLARED;
23
- }
24
- return granted ? AccessVerdict.ALLOWED : AccessVerdict.NOT_GRANTED;
25
- };
26
-
27
- const hostOf = (url: string): string | null => {
28
- try {
29
- const parsed = new URL(url);
30
- return parsed.protocol === 'http:' || parsed.protocol === 'https:' ? parsed.hostname : null;
31
- } catch {
32
- return null;
33
- }
34
- };
35
-
36
- /**
37
- * An HTTP effect needs its url's host in a declaration AND in a grant; an unparsable url or one
38
- * whose scheme is not http(s) (`file:`, `ftp:`...) is never covered.
39
- */
40
- export const checkHttpAccess = (
41
- url: string,
42
- declared: AccessDeclaration[],
43
- granted: AccessDeclaration[],
44
- ): AccessVerdict => {
45
- const host = hostOf(url);
46
- if (host === null) {
47
- return AccessVerdict.NOT_DECLARED;
48
- }
49
- return verdict(coversHost(declared, host), coversHost(granted, host));
50
- };
51
-
52
- export const checkHostActionAccess = (
53
- action: string,
54
- declared: AccessDeclaration[],
55
- granted: AccessDeclaration[],
56
- ): AccessVerdict => verdict(coversAction(declared, action), coversAction(granted, action));
1
+ import { AccessKind } from '../access/access.types';
2
+ import type { AccessDeclaration } from '../access/access.types';
3
+ import { hostMatches } from '../access/host-match';
4
+
5
+ export enum AccessVerdict {
6
+ ALLOWED = 'ALLOWED',
7
+ NOT_DECLARED = 'NOT_DECLARED',
8
+ NOT_GRANTED = 'NOT_GRANTED',
9
+ }
10
+
11
+ const coversHost = (accesses: AccessDeclaration[], host: string): boolean =>
12
+ accesses.some(
13
+ (access) =>
14
+ access.kind === AccessKind.HTTP && access.hosts.some((pattern) => hostMatches(host, pattern)),
15
+ );
16
+
17
+ const coversAction = (accesses: AccessDeclaration[], action: string): boolean =>
18
+ accesses.some((access) => access.kind === AccessKind.HOST_ACTION && access.action === action);
19
+
20
+ const verdict = (declared: boolean, granted: boolean): AccessVerdict => {
21
+ if (!declared) {
22
+ return AccessVerdict.NOT_DECLARED;
23
+ }
24
+ return granted ? AccessVerdict.ALLOWED : AccessVerdict.NOT_GRANTED;
25
+ };
26
+
27
+ const hostOf = (url: string): string | null => {
28
+ try {
29
+ const parsed = new URL(url);
30
+ return parsed.protocol === 'http:' || parsed.protocol === 'https:' ? parsed.hostname : null;
31
+ } catch {
32
+ return null;
33
+ }
34
+ };
35
+
36
+ /**
37
+ * An HTTP effect needs its url's host in a declaration AND in a grant; an unparsable url or one
38
+ * whose scheme is not http(s) (`file:`, `ftp:`...) is never covered.
39
+ */
40
+ export const checkHttpAccess = (
41
+ url: string,
42
+ declared: AccessDeclaration[],
43
+ granted: AccessDeclaration[],
44
+ ): AccessVerdict => {
45
+ const host = hostOf(url);
46
+ if (host === null) {
47
+ return AccessVerdict.NOT_DECLARED;
48
+ }
49
+ return verdict(coversHost(declared, host), coversHost(granted, host));
50
+ };
51
+
52
+ export const checkHostActionAccess = (
53
+ action: string,
54
+ declared: AccessDeclaration[],
55
+ granted: AccessDeclaration[],
56
+ ): AccessVerdict => verdict(coversAction(declared, action), coversAction(granted, action));
@@ -1,87 +1,87 @@
1
- import { EvaluationKind } from '../runner-protocol/evaluation.types';
2
- import type { EvaluationItem } from '../runner-protocol/evaluation.types';
3
- import { StepType } from '../definition/definition.types';
4
- import type { Step, ValueSource } from '../definition/definition.types';
5
- import { collectItems, propertyPath, resolveValue } from './value-source';
6
-
7
- interface StepField {
8
- path: string;
9
- source: ValueSource;
10
- }
11
-
12
- /** Resolved top-level fields of a step, by field path (`url`, `headers.Authorization`...). */
13
- export type ResolvedFields = ReadonlyMap<string, unknown>;
14
-
15
- const recordFields = (base: string, record: Record<string, ValueSource> | undefined): StepField[] =>
16
- Object.entries(record ?? {}).map(([key, source]) => ({ path: propertyPath(base, key), source }));
17
-
18
- const optionalField = (path: string, source: ValueSource | undefined): StepField[] =>
19
- source === undefined ? [] : [{ path, source }];
20
-
21
- /** The value sources of a step, each under the path used as evaluation item id. */
22
- const stepFields = (step: Step): StepField[] => {
23
- switch (step.type) {
24
- case StepType.CONDITION:
25
- return [{ path: 'if', source: step.if }];
26
- case StepType.SWITCH:
27
- return [
28
- { path: 'value', source: step.value },
29
- ...step.cases.map((switchCase, index) => ({
30
- path: `cases[${index}].match`,
31
- source: switchCase.match,
32
- })),
33
- ];
34
- case StepType.WAIT:
35
- return [
36
- ...optionalField('durationMs', step.durationMs),
37
- ...optionalField('until', step.until),
38
- ];
39
- case StepType.SET:
40
- return [{ path: 'value', source: step.value }];
41
- case StepType.CODE:
42
- return [];
43
- case StepType.HTTP:
44
- return [
45
- { path: 'url', source: step.url },
46
- ...recordFields('headers', step.headers),
47
- ...optionalField('body', step.body),
48
- ];
49
- case StepType.HOST:
50
- return recordFields('input', step.input);
51
- case StepType.LOG:
52
- return [{ path: 'message', source: step.message }, ...optionalField('data', step.data)];
53
- case StepType.RESPOND:
54
- return [
55
- { path: 'status', source: step.status },
56
- ...recordFields('headers', step.headers),
57
- ...optionalField('body', step.body),
58
- ];
59
- case StepType.STOP:
60
- return optionalField('output', step.output);
61
- }
62
- };
63
-
64
- /** Every non-literal value of the step, to evaluate in one lot. A CODE step always has one item. */
65
- export const collectStepItems = (step: Step): EvaluationItem[] => {
66
- if (step.type === StepType.CODE) {
67
- return [{ id: 'source', kind: EvaluationKind.CODE, source: step.source }];
68
- }
69
- const items: EvaluationItem[] = [];
70
- for (const field of stepFields(step)) {
71
- collectItems(field.path, field.source, items);
72
- }
73
- return items;
74
- };
75
-
76
- /** `results` maps item ids to evaluated values; a CODE step resolves to its single `source` item. */
77
- export const resolveStepFields = (
78
- step: Step,
79
- results: ReadonlyMap<string, unknown>,
80
- ): ResolvedFields => {
81
- if (step.type === StepType.CODE) {
82
- return new Map([['source', results.get('source')]]);
83
- }
84
- return new Map(
85
- stepFields(step).map((field) => [field.path, resolveValue(field.path, field.source, results)]),
86
- );
87
- };
1
+ import { EvaluationKind } from '../runner-protocol/evaluation.types';
2
+ import type { EvaluationItem } from '../runner-protocol/evaluation.types';
3
+ import { StepType } from '../definition/definition.types';
4
+ import type { Step, ValueSource } from '../definition/definition.types';
5
+ import { collectItems, propertyPath, resolveValue } from './value-source';
6
+
7
+ interface StepField {
8
+ path: string;
9
+ source: ValueSource;
10
+ }
11
+
12
+ /** Resolved top-level fields of a step, by field path (`url`, `headers.Authorization`...). */
13
+ export type ResolvedFields = ReadonlyMap<string, unknown>;
14
+
15
+ const recordFields = (base: string, record: Record<string, ValueSource> | undefined): StepField[] =>
16
+ Object.entries(record ?? {}).map(([key, source]) => ({ path: propertyPath(base, key), source }));
17
+
18
+ const optionalField = (path: string, source: ValueSource | undefined): StepField[] =>
19
+ source === undefined ? [] : [{ path, source }];
20
+
21
+ /** The value sources of a step, each under the path used as evaluation item id. */
22
+ const stepFields = (step: Step): StepField[] => {
23
+ switch (step.type) {
24
+ case StepType.CONDITION:
25
+ return [{ path: 'if', source: step.if }];
26
+ case StepType.SWITCH:
27
+ return [
28
+ { path: 'value', source: step.value },
29
+ ...step.cases.map((switchCase, index) => ({
30
+ path: `cases[${index}].match`,
31
+ source: switchCase.match,
32
+ })),
33
+ ];
34
+ case StepType.WAIT:
35
+ return [
36
+ ...optionalField('durationMs', step.durationMs),
37
+ ...optionalField('until', step.until),
38
+ ];
39
+ case StepType.SET:
40
+ return [{ path: 'value', source: step.value }];
41
+ case StepType.CODE:
42
+ return [];
43
+ case StepType.HTTP:
44
+ return [
45
+ { path: 'url', source: step.url },
46
+ ...recordFields('headers', step.headers),
47
+ ...optionalField('body', step.body),
48
+ ];
49
+ case StepType.HOST:
50
+ return recordFields('input', step.input);
51
+ case StepType.LOG:
52
+ return [{ path: 'message', source: step.message }, ...optionalField('data', step.data)];
53
+ case StepType.RESPOND:
54
+ return [
55
+ { path: 'status', source: step.status },
56
+ ...recordFields('headers', step.headers),
57
+ ...optionalField('body', step.body),
58
+ ];
59
+ case StepType.STOP:
60
+ return optionalField('output', step.output);
61
+ }
62
+ };
63
+
64
+ /** Every non-literal value of the step, to evaluate in one lot. A CODE step always has one item. */
65
+ export const collectStepItems = (step: Step): EvaluationItem[] => {
66
+ if (step.type === StepType.CODE) {
67
+ return [{ id: 'source', kind: EvaluationKind.CODE, source: step.source }];
68
+ }
69
+ const items: EvaluationItem[] = [];
70
+ for (const field of stepFields(step)) {
71
+ collectItems(field.path, field.source, items);
72
+ }
73
+ return items;
74
+ };
75
+
76
+ /** `results` maps item ids to evaluated values; a CODE step resolves to its single `source` item. */
77
+ export const resolveStepFields = (
78
+ step: Step,
79
+ results: ReadonlyMap<string, unknown>,
80
+ ): ResolvedFields => {
81
+ if (step.type === StepType.CODE) {
82
+ return new Map([['source', results.get('source')]]);
83
+ }
84
+ return new Map(
85
+ stepFields(step).map((field) => [field.path, resolveValue(field.path, field.source, results)]),
86
+ );
87
+ };
@@ -1,69 +1,69 @@
1
- import { EvaluationKind } from '../runner-protocol/evaluation.types';
2
- import type { EvaluationItem } from '../runner-protocol/evaluation.types';
3
- import type { ExpressionValue, ValueSource } from '../definition/definition.types';
4
-
5
- const TEMPLATE_PATTERN = /\{\{[\s\S]*?\}\}/;
6
- const IDENTIFIER_KEY = /^[A-Za-z_$][\w$-]*$/;
7
-
8
- export const isExpressionValue = (value: ValueSource): value is ExpressionValue =>
9
- typeof value === 'object' &&
10
- value !== null &&
11
- !Array.isArray(value) &&
12
- Object.keys(value).length === 1 &&
13
- typeof (value as ExpressionValue).$expression === 'string';
14
-
15
- /** Field path of a property, unambiguous whatever the key: `a.b`, `a["x.y"]`. */
16
- export const propertyPath = (base: string, key: string): string =>
17
- IDENTIFIER_KEY.test(key) ? `${base}.${key}` : `${base}[${JSON.stringify(key)}]`;
18
-
19
- const indexPath = (base: string, index: number): string => `${base}[${index}]`;
20
-
21
- /** Appends one item per non-literal value found in `source`; the item id is its field path. */
22
- export const collectItems = (path: string, source: ValueSource, items: EvaluationItem[]): void => {
23
- if (typeof source === 'string') {
24
- if (TEMPLATE_PATTERN.test(source)) {
25
- items.push({ id: path, kind: EvaluationKind.TEMPLATE, source });
26
- }
27
- return;
28
- }
29
- if (source === null || typeof source !== 'object') {
30
- return;
31
- }
32
- if (isExpressionValue(source)) {
33
- items.push({ id: path, kind: EvaluationKind.EXPRESSION, source: source.$expression });
34
- return;
35
- }
36
- if (Array.isArray(source)) {
37
- source.forEach((entry, index) => collectItems(indexPath(path, index), entry, items));
38
- return;
39
- }
40
- for (const [key, entry] of Object.entries(source)) {
41
- collectItems(propertyPath(path, key), entry, items);
42
- }
43
- };
44
-
45
- /** Rebuilds `source` with every non-literal value replaced by its evaluated result. */
46
- export const resolveValue = (
47
- path: string,
48
- source: ValueSource,
49
- results: ReadonlyMap<string, unknown>,
50
- ): unknown => {
51
- if (typeof source === 'string') {
52
- return TEMPLATE_PATTERN.test(source) ? results.get(path) : source;
53
- }
54
- if (source === null || typeof source !== 'object') {
55
- return source;
56
- }
57
- if (isExpressionValue(source)) {
58
- return results.get(path);
59
- }
60
- if (Array.isArray(source)) {
61
- return source.map((entry, index) => resolveValue(indexPath(path, index), entry, results));
62
- }
63
- return Object.fromEntries(
64
- Object.entries(source).map(([key, entry]) => [
65
- key,
66
- resolveValue(propertyPath(path, key), entry, results),
67
- ]),
68
- );
69
- };
1
+ import { EvaluationKind } from '../runner-protocol/evaluation.types';
2
+ import type { EvaluationItem } from '../runner-protocol/evaluation.types';
3
+ import type { ExpressionValue, ValueSource } from '../definition/definition.types';
4
+
5
+ const TEMPLATE_PATTERN = /\{\{[\s\S]*?\}\}/;
6
+ const IDENTIFIER_KEY = /^[A-Za-z_$][\w$-]*$/;
7
+
8
+ export const isExpressionValue = (value: ValueSource): value is ExpressionValue =>
9
+ typeof value === 'object' &&
10
+ value !== null &&
11
+ !Array.isArray(value) &&
12
+ Object.keys(value).length === 1 &&
13
+ typeof (value as ExpressionValue).$expression === 'string';
14
+
15
+ /** Field path of a property, unambiguous whatever the key: `a.b`, `a["x.y"]`. */
16
+ export const propertyPath = (base: string, key: string): string =>
17
+ IDENTIFIER_KEY.test(key) ? `${base}.${key}` : `${base}[${JSON.stringify(key)}]`;
18
+
19
+ const indexPath = (base: string, index: number): string => `${base}[${index}]`;
20
+
21
+ /** Appends one item per non-literal value found in `source`; the item id is its field path. */
22
+ export const collectItems = (path: string, source: ValueSource, items: EvaluationItem[]): void => {
23
+ if (typeof source === 'string') {
24
+ if (TEMPLATE_PATTERN.test(source)) {
25
+ items.push({ id: path, kind: EvaluationKind.TEMPLATE, source });
26
+ }
27
+ return;
28
+ }
29
+ if (source === null || typeof source !== 'object') {
30
+ return;
31
+ }
32
+ if (isExpressionValue(source)) {
33
+ items.push({ id: path, kind: EvaluationKind.EXPRESSION, source: source.$expression });
34
+ return;
35
+ }
36
+ if (Array.isArray(source)) {
37
+ source.forEach((entry, index) => collectItems(indexPath(path, index), entry, items));
38
+ return;
39
+ }
40
+ for (const [key, entry] of Object.entries(source)) {
41
+ collectItems(propertyPath(path, key), entry, items);
42
+ }
43
+ };
44
+
45
+ /** Rebuilds `source` with every non-literal value replaced by its evaluated result. */
46
+ export const resolveValue = (
47
+ path: string,
48
+ source: ValueSource,
49
+ results: ReadonlyMap<string, unknown>,
50
+ ): unknown => {
51
+ if (typeof source === 'string') {
52
+ return TEMPLATE_PATTERN.test(source) ? results.get(path) : source;
53
+ }
54
+ if (source === null || typeof source !== 'object') {
55
+ return source;
56
+ }
57
+ if (isExpressionValue(source)) {
58
+ return results.get(path);
59
+ }
60
+ if (Array.isArray(source)) {
61
+ return source.map((entry, index) => resolveValue(indexPath(path, index), entry, results));
62
+ }
63
+ return Object.fromEntries(
64
+ Object.entries(source).map(([key, entry]) => [
65
+ key,
66
+ resolveValue(propertyPath(path, key), entry, results),
67
+ ]),
68
+ );
69
+ };
@@ -1,15 +1,15 @@
1
- {
2
- // Perimetre de VERIFICATION, distinct de celui du build.
3
- //
4
- // `tsconfig.json` exclut `src/**/*.spec.ts` parce qu'il sert a emettre `dist/`, ou une spec
5
- // n'a rien a faire. Mais eslint s'appuie sur ce meme fichier via `parserOptions.project` :
6
- // les cinq specs du paquet sortaient donc en « Parsing error: that TSConfig does not include
7
- // this file », mesure du 2026-09-09, et n'etaient lintees par personne.
8
- //
9
- // Ce fichier sert uniquement a eslint. Il n'emet rien et ne change pas ce que `build` produit.
10
- "extends": "./tsconfig.json",
11
- "compilerOptions": {
12
- "noEmit": true
13
- },
14
- "exclude": ["./dist/**/*"]
15
- }
1
+ {
2
+ // Perimetre de VERIFICATION, distinct de celui du build.
3
+ //
4
+ // `tsconfig.json` exclut `src/**/*.spec.ts` parce qu'il sert a emettre `dist/`, ou une spec
5
+ // n'a rien a faire. Mais eslint s'appuie sur ce meme fichier via `parserOptions.project` :
6
+ // les cinq specs du paquet sortaient donc en « Parsing error: that TSConfig does not include
7
+ // this file », mesure du 2026-09-09, et n'etaient lintees par personne.
8
+ //
9
+ // Ce fichier sert uniquement a eslint. Il n'emet rien et ne change pas ce que `build` produit.
10
+ "extends": "./tsconfig.json",
11
+ "compilerOptions": {
12
+ "noEmit": true
13
+ },
14
+ "exclude": ["./dist/**/*"]
15
+ }
package/tsconfig.json CHANGED
@@ -1,35 +1,35 @@
1
- {
2
- "compilerOptions": {
3
- "incremental": false,
4
- "target": "es2021",
5
- "lib": [
6
- "dom",
7
- "es2021"
8
- ],
9
- "module": "commonjs",
10
- "rootDir": "src",
11
- "moduleResolution": "node",
12
- "resolveJsonModule": true,
13
- "declaration": true,
14
- "sourceMap": true,
15
- "outDir": "./dist",
16
- "removeComments": true,
17
- "allowSyntheticDefaultImports": true,
18
- "esModuleInterop": true,
19
- "forceConsistentCasingInFileNames": true,
20
- "strict": true,
21
- "strictNullChecks": true,
22
- "strictFunctionTypes": true,
23
- "strictPropertyInitialization": false,
24
- "skipLibCheck": true
25
- },
26
- "include": [
27
- "./src"
28
- ],
29
- "exclude": [
30
- "./dist/**/*",
31
- "./src/**/*.spec.ts",
32
- "./src/**/*.test.ts",
33
- "./src/**/__tests__/**"
34
- ]
35
- }
1
+ {
2
+ "compilerOptions": {
3
+ "incremental": false,
4
+ "target": "es2021",
5
+ "lib": [
6
+ "dom",
7
+ "es2021"
8
+ ],
9
+ "module": "commonjs",
10
+ "rootDir": "src",
11
+ "moduleResolution": "node",
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "sourceMap": true,
15
+ "outDir": "./dist",
16
+ "removeComments": true,
17
+ "allowSyntheticDefaultImports": true,
18
+ "esModuleInterop": true,
19
+ "forceConsistentCasingInFileNames": true,
20
+ "strict": true,
21
+ "strictNullChecks": true,
22
+ "strictFunctionTypes": true,
23
+ "strictPropertyInitialization": false,
24
+ "skipLibCheck": true
25
+ },
26
+ "include": [
27
+ "./src"
28
+ ],
29
+ "exclude": [
30
+ "./dist/**/*",
31
+ "./src/**/*.spec.ts",
32
+ "./src/**/*.test.ts",
33
+ "./src/**/__tests__/**"
34
+ ]
35
+ }