@starci/eslint-canon-be 3.8.20 → 3.9.2
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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/runtime/bundle.json +192 -0
- package/runtime/engine/by-code-unit.mjs +6 -6
- package/runtime/engine/model-config.mjs +98 -76
- package/runtime/engine/orca-config.mjs +22 -17
- package/runtime/engine/release-config.mjs +22 -18
- package/runtime/engine/removed-vocabulary.mjs +21 -20
- package/runtime/engine/resources-config.mjs +42 -35
- package/runtime/engine/runtime-root.mjs +11 -13
- package/runtime/engine/secrets.mjs +170 -102
- package/runtime/engine/sonar-config.mjs +16 -13
- package/runtime/engine/temp-root.mjs +3 -9
- package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
- package/runtime/knowledge/hfs/rules.yaml +6 -6
- package/runtime/knowledge/hfs/slots.yaml +2 -2
- package/runtime/knowledge/sonar-gate.yaml +1 -1
- package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
- package/runtime/scripts/api/git/cat-file.mjs +0 -1
- package/runtime/scripts/api/git/config-get.mjs +1 -2
- package/runtime/scripts/api/git/diff.mjs +0 -1
- package/runtime/scripts/api/git/lib.mjs +32 -32
- package/runtime/scripts/api/git/ls-files.mjs +0 -1
- package/runtime/scripts/api/git/ls-tree.mjs +0 -1
- package/runtime/scripts/api/git/merge-base.mjs +2 -3
- package/runtime/scripts/api/git/remote.mjs +0 -1
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
- package/runtime/scripts/api/git/show.mjs +0 -1
- package/runtime/scripts/hfs/allows.mjs +37 -38
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
- package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
- package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
- package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
- package/runtime/scripts/hfs/architecture/config.mjs +302 -268
- package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
- package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
- package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
- package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
- package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
- package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
- package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
- package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
- package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
- package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
- package/runtime/scripts/hfs/architecture/index.mjs +272 -272
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
- package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
- package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
- package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
- package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
- package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
- package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
- package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
- package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
- package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
- package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
- package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
- package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
- package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
- package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
- package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
- package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
- package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
- package/runtime/scripts/hfs/edition-slots.mjs +43 -40
- package/runtime/scripts/hfs/linear-text.mjs +20 -20
- package/runtime/scripts/hfs/param-names.mjs +6 -11
- package/runtime/scripts/hfs/path-findings.mjs +120 -100
- package/runtime/scripts/hfs/repo-identity.mjs +55 -42
- package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
- package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
- package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
- package/runtime/scripts/hfs/rules/read.mjs +19 -15
- package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
- package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
- package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
- package/runtime/scripts/hfs/slot-classify.mjs +42 -38
- package/runtime/scripts/hfs/slot-errors.mjs +8 -7
- package/runtime/scripts/hfs/slot-imports.mjs +70 -63
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
- package/runtime/scripts/hfs/slot-match.mjs +122 -111
- package/runtime/scripts/hfs/slot-path.mjs +0 -2
- package/runtime/scripts/hfs/slot-required.mjs +65 -59
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
- package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
- package/runtime/scripts/hfs/slots.mjs +175 -152
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
- package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
- package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
- package/runtime/scripts/hfs/view.mjs +38 -40
- package/runtime/scripts/lib/dockerfile.mjs +131 -114
- package/runtime/scripts/lib/env.mjs +3 -6
- package/runtime/scripts/lib/event-contract.mjs +73 -78
- package/runtime/scripts/lib/git.mjs +15 -16
- package/runtime/scripts/lib/glob.mjs +23 -14
- package/runtime/scripts/lib/grammar-lint.mjs +33 -37
- package/runtime/scripts/lib/i18n.mjs +32 -35
- package/runtime/scripts/lib/in-order.mjs +57 -38
- package/runtime/scripts/lib/json-clone.mjs +45 -36
- package/runtime/scripts/lib/json.mjs +26 -14
- package/runtime/scripts/lib/language.mjs +133 -129
- package/runtime/scripts/lib/list.mjs +9 -14
- package/runtime/scripts/lib/mutation-fence.mjs +10 -5
- package/runtime/scripts/lib/path-key.mjs +53 -38
- package/runtime/scripts/lib/read-text.mjs +30 -17
- package/runtime/scripts/lib/regex.mjs +1 -2
- package/runtime/scripts/lib/same-text.mjs +0 -1
- package/runtime/scripts/lib/sops-envelope.mjs +148 -120
- package/runtime/scripts/lib/stack-services.mjs +128 -129
- package/runtime/scripts/lib/ts-analysis.mjs +28 -26
- package/runtime/scripts/lib/ts-ast.mjs +36 -42
- package/runtime/scripts/lib/walk.mjs +33 -27
- package/runtime/scripts/lib/yaml-cached.mjs +4 -4
|
@@ -5,10 +5,8 @@
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { allowsFile } from './allows.mjs';
|
|
7
7
|
import { openHfs } from './slots.mjs';
|
|
8
|
-
|
|
9
8
|
const posix = (p) => String(p).replaceAll('\\', '/');
|
|
10
9
|
const isAbsoluteAny = (text) => path.isAbsolute(text) || /^[A-Za-z]:\//.test(text);
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* The view rules read, over an opened resolver.
|
|
14
12
|
*
|
|
@@ -17,44 +15,45 @@ const isAbsoluteAny = (text) => path.isAbsolute(text) || /^[A-Za-z]:\//.test(tex
|
|
|
17
15
|
* @returns {object} The frozen view: profile, apps, connections, patterns, ruleParams, relative, classify, slotOf, tierOf, ownerOf, slot.
|
|
18
16
|
*/
|
|
19
17
|
function hfsView(opened, repoRoot) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
18
|
+
const rel = (file) => {
|
|
19
|
+
const text = posix(file);
|
|
20
|
+
if (!isAbsoluteAny(text))
|
|
21
|
+
return text.replace(/^\.\//, '');
|
|
22
|
+
return posix(path.relative(repoRoot, file));
|
|
23
|
+
};
|
|
24
|
+
const slotCache = new Map();
|
|
25
|
+
const classify = (file) => {
|
|
26
|
+
const key = rel(file);
|
|
27
|
+
if (!slotCache.has(key))
|
|
28
|
+
slotCache.set(key, opened.classifyPath(key));
|
|
29
|
+
return slotCache.get(key);
|
|
30
|
+
};
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
repoRoot,
|
|
33
|
+
profile: opened.repo.profile,
|
|
34
|
+
side: opened.repo.side ?? null,
|
|
35
|
+
edition: opened.repo.edition ?? 'full',
|
|
36
|
+
...(opened.repo.grammar === undefined ? {} : { grammar: opened.repo.grammar }),
|
|
37
|
+
apps: opened.repo.apps,
|
|
38
|
+
connections: opened.repo.connections,
|
|
39
|
+
patterns: Object.freeze([...(opened.repo.patterns ?? [])]),
|
|
40
|
+
ruleParams: opened.ruleParams(),
|
|
41
|
+
/** The repository-relative, forward-slash form of a linted filename. */
|
|
42
|
+
relative: rel,
|
|
43
|
+
/** The classification of a file: `{ slot, tier, owner?, bindings? ... }` or a no-slot status. */
|
|
44
|
+
classify,
|
|
45
|
+
/** The slot id that owns a file, or null when no slot does. */
|
|
46
|
+
slotOf: (file) => classify(file).slot ?? null,
|
|
47
|
+
/** The tier of a file, or null. */
|
|
48
|
+
tierOf: (file) => opened.tierOf(rel(file)) ?? null,
|
|
49
|
+
/** The owner root of a file, or null. */
|
|
50
|
+
ownerOf: (file) => opened.ownerOf(rel(file))?.root ?? null,
|
|
51
|
+
/** What the slot that owns a file says about it: `{ slot, root, relative, allowed, entry?, forbiddenBy?, allows }`, or null when the slot names no `allows`. */
|
|
52
|
+
allows: (file) => allowsFile(opened, rel(file)),
|
|
53
|
+
/** A slot definition by id. */
|
|
54
|
+
slot: (id) => opened.slot(id),
|
|
55
|
+
});
|
|
56
56
|
}
|
|
57
|
-
|
|
58
57
|
/**
|
|
59
58
|
* The view of the app folder on disk at `repoRoot`, against the manifest under `runtimeRoot`: a side folder (be/, fe/) finds the
|
|
60
59
|
* app-root hfs.json one level up and gets that side's view, so every linted file below it is judged by its own side's slots.
|
|
@@ -63,7 +62,6 @@ function hfsView(opened, repoRoot) {
|
|
|
63
62
|
* @returns {object} The frozen view.
|
|
64
63
|
*/
|
|
65
64
|
export const openHfsView = ({ runtimeRoot, repoRoot }) => hfsView(openHfs({ root: runtimeRoot, repoRoot }), repoRoot);
|
|
66
|
-
|
|
67
65
|
/**
|
|
68
66
|
* The view of one side of an in-memory app declaration (rule tests): no file is read except the manifest.
|
|
69
67
|
*
|
|
@@ -2,146 +2,163 @@
|
|
|
2
2
|
// one statement per logical line (a trailing backslash continues it, comment lines inside a continuation are dropped), the
|
|
3
3
|
// instruction keyword is the first word, the stages open at each FROM. Parser directives (`# syntax=`, `# escape=`) and
|
|
4
4
|
// comments are kept apart from the instructions. Here-documents are not part of the subset the canon uses and are read as text.
|
|
5
|
-
|
|
6
5
|
/** Split a shell-form or exec-form argument string into its words (quotes group a word and are removed). */
|
|
7
6
|
export function words(text) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const out = [];
|
|
8
|
+
let current = '';
|
|
9
|
+
let quote = null;
|
|
10
|
+
let started = false;
|
|
11
|
+
for (const char of text) {
|
|
12
|
+
if (quote) {
|
|
13
|
+
if (char === quote)
|
|
14
|
+
quote = null;
|
|
15
|
+
else
|
|
16
|
+
current += char;
|
|
17
|
+
}
|
|
18
|
+
else if (char === '"' || char === "'") {
|
|
19
|
+
quote = char;
|
|
20
|
+
started = true;
|
|
21
|
+
}
|
|
22
|
+
else if (char === ' ' || char === '\t' || char === '\n') {
|
|
23
|
+
if (started || current)
|
|
24
|
+
out.push(current);
|
|
25
|
+
current = '';
|
|
26
|
+
started = false;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
current += char;
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
if (started || current)
|
|
33
|
+
out.push(current);
|
|
34
|
+
return out;
|
|
29
35
|
}
|
|
30
|
-
|
|
31
36
|
/** The exec-form array of an instruction's argument text (`["node", "x.js"]`), or null when it is not a JSON array of strings. */
|
|
32
37
|
export function execForm(text) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const trimmed = text.trim();
|
|
39
|
+
if (!trimmed.startsWith('['))
|
|
40
|
+
return null;
|
|
41
|
+
try {
|
|
42
|
+
const value = JSON.parse(trimmed);
|
|
43
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : null;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
|
-
|
|
43
49
|
/** The commands of a shell-form RUN body: the text split at `&&`, `||`, `;` and `|` outside quotes, each as its words. */
|
|
44
50
|
export function shellCommands(body) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
const commands = [];
|
|
52
|
+
let current = '';
|
|
53
|
+
let quote = null;
|
|
54
|
+
const flush = () => {
|
|
55
|
+
const parts = words(current);
|
|
56
|
+
if (parts.length)
|
|
57
|
+
commands.push(parts);
|
|
58
|
+
current = '';
|
|
59
|
+
};
|
|
60
|
+
for (let i = 0; i < body.length; i += 1) {
|
|
61
|
+
const char = body.charAt(i);
|
|
62
|
+
if (quote) {
|
|
63
|
+
current += char;
|
|
64
|
+
if (char === quote)
|
|
65
|
+
quote = null;
|
|
66
|
+
}
|
|
67
|
+
else if (char === '"' || char === "'") {
|
|
68
|
+
quote = char;
|
|
69
|
+
current += char;
|
|
70
|
+
}
|
|
71
|
+
else if (isCommandSeparator(body, i, char)) {
|
|
72
|
+
i += commandSeparatorAdvance(body, i, char);
|
|
73
|
+
flush();
|
|
74
|
+
}
|
|
75
|
+
else if (char === '\\' && body[i + 1] === '\n') {
|
|
76
|
+
i += 1;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
current += char;
|
|
80
|
+
}
|
|
68
81
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return commands;
|
|
82
|
+
flush();
|
|
83
|
+
return commands;
|
|
72
84
|
}
|
|
73
|
-
|
|
74
85
|
const isCommandSeparator = (body, index, char) => char === ';' || char === '|' || (char === '&' && body[index + 1] === '&');
|
|
75
86
|
const commandSeparatorAdvance = (body, index, char) => char !== ';' && body[index + 1] === char ? 1 : 0;
|
|
76
|
-
|
|
77
87
|
/**
|
|
78
88
|
* Parse a Dockerfile: { instructions: [{ keyword, text, line, stage }], stages: [{ index, name, image, line, instructions }],
|
|
79
89
|
* comments: [{ text, line }], preamble: [instruction before the first FROM (ARG)] }. `keyword` is upper-case; `text` is the
|
|
80
90
|
* argument text of the logical line; `stage` is the index of the stage the instruction belongs to (-1 before the first FROM).
|
|
81
91
|
*/
|
|
82
92
|
export function parseDockerfile(source) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
const lines = String(source).replaceAll('\r\n', '\n').split('\n');
|
|
94
|
+
const { instructions, comments } = parseInstructions(lines);
|
|
95
|
+
const stages = [];
|
|
96
|
+
const preamble = [];
|
|
97
|
+
for (const instruction of instructions) {
|
|
98
|
+
if (instruction.keyword === 'FROM') {
|
|
99
|
+
const parts = words(instruction.text).filter((part) => !part.startsWith('--'));
|
|
100
|
+
const asAt = parts.findIndex((part, index) => index > 0 && part.toUpperCase() === 'AS');
|
|
101
|
+
stages.push({ index: stages.length, name: asAt > 0 ? parts[asAt + 1] ?? null : null, image: parts[0] ?? '', line: instruction.line, instructions: [] });
|
|
102
|
+
}
|
|
103
|
+
instruction.stage = stages.length - 1;
|
|
104
|
+
if (stages.length)
|
|
105
|
+
stages.at(-1).instructions.push(instruction);
|
|
106
|
+
else
|
|
107
|
+
preamble.push(instruction);
|
|
92
108
|
}
|
|
93
|
-
|
|
94
|
-
if (stages.length) stages.at(-1).instructions.push(instruction);
|
|
95
|
-
else preamble.push(instruction);
|
|
96
|
-
}
|
|
97
|
-
return { instructions, stages, comments, preamble };
|
|
109
|
+
return { instructions, stages, comments, preamble };
|
|
98
110
|
}
|
|
99
|
-
|
|
100
111
|
function parseInstructions(lines) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
const instructions = [];
|
|
113
|
+
const comments = [];
|
|
114
|
+
const state = { escape: '\\', directives: true };
|
|
115
|
+
let i = 0;
|
|
116
|
+
while (i < lines.length) {
|
|
117
|
+
const parsed = parseInstructionLine(lines, i, state);
|
|
118
|
+
if (parsed.comment)
|
|
119
|
+
comments.push(parsed.comment);
|
|
120
|
+
if (parsed.instruction)
|
|
121
|
+
instructions.push(parsed.instruction);
|
|
122
|
+
i = parsed.nextLine + 1;
|
|
123
|
+
}
|
|
124
|
+
return { instructions, comments };
|
|
112
125
|
}
|
|
113
|
-
|
|
114
126
|
function parseInstructionLine(lines, index, state) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
const trimmed = lines[index].trim();
|
|
128
|
+
if (trimmed === '') {
|
|
129
|
+
state.directives = false;
|
|
130
|
+
return { nextLine: index };
|
|
131
|
+
}
|
|
132
|
+
if (trimmed.startsWith('#'))
|
|
133
|
+
return parseCommentLine(trimmed, index, state);
|
|
134
|
+
state.directives = false;
|
|
135
|
+
const { logical, nextLine } = logicalInstructionOf(lines, index, state.escape);
|
|
136
|
+
const split = logical.search(/\s/);
|
|
137
|
+
const keyword = (split < 0 ? logical : logical.slice(0, split)).toUpperCase();
|
|
138
|
+
return { nextLine, instruction: { keyword, text: split < 0 ? '' : logical.slice(split).trim(), line: index + 1, stage: -1 } };
|
|
123
139
|
}
|
|
124
|
-
|
|
125
140
|
function parseCommentLine(trimmed, index, state) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
141
|
+
const body = trimmed.slice(1).trim();
|
|
142
|
+
const directive = state.directives ? /^(syntax|escape|check)\s*=\s*(\S+)$/i.exec(body) : null;
|
|
143
|
+
if (directive) {
|
|
144
|
+
if (directive[1].toLowerCase() === 'escape')
|
|
145
|
+
state.escape = directive[2];
|
|
146
|
+
return { nextLine: index };
|
|
147
|
+
}
|
|
148
|
+
state.directives = false;
|
|
149
|
+
return { nextLine: index, comment: { text: body, line: index + 1 } };
|
|
134
150
|
}
|
|
135
|
-
|
|
136
151
|
function logicalInstructionOf(lines, index, escape) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
let logical = lines[index].trim();
|
|
153
|
+
let nextLine = index;
|
|
154
|
+
while (logical.endsWith(escape) && nextLine + 1 < lines.length) {
|
|
155
|
+
logical = logical.slice(0, -1).trimEnd();
|
|
156
|
+
nextLine += 1;
|
|
157
|
+
while (nextLine < lines.length && lines[nextLine].trim().startsWith('#'))
|
|
158
|
+
nextLine += 1;
|
|
159
|
+
if (nextLine >= lines.length)
|
|
160
|
+
break;
|
|
161
|
+
logical = `${logical} ${lines[nextLine].trim()}`;
|
|
162
|
+
}
|
|
163
|
+
return { logical, nextLine };
|
|
147
164
|
}
|
|
@@ -2,20 +2,17 @@
|
|
|
2
2
|
// modules/schemas/env.yaml catalogues every variable with its purpose and kind. Production code reads a variable here
|
|
3
3
|
// (readEnv) or takes an injected `env` parameter; it never reads `process.env.NAME` itself. The test runner is observed
|
|
4
4
|
// in exactly one place, isSpecRun: code that must not touch the host's real state during a spec asks it.
|
|
5
|
-
|
|
6
5
|
/** The value of the environment variable `name` in `env` (default: the process environment), or undefined. */
|
|
7
6
|
export const readEnv = (name, env = process.env) => env[name];
|
|
8
|
-
|
|
9
7
|
/** True when `env` (default: the process environment) belongs to a spec run (`node --test` marks its children with NODE_TEST_CONTEXT). */
|
|
10
8
|
export const isSpecRun = (env = process.env) => Boolean(env.NODE_TEST_CONTEXT);
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* The environment for a child that is itself a test runner: `env` without the mark of an enclosing spec run. A `node --test` that inherits NODE_TEST_CONTEXT believes it is a
|
|
14
11
|
* subtest of that run: it reports to its parent and exits 0 whatever its tests did, so a verb that runs specs as a child (the package clean-test, the scaffold e2e, the release cut)
|
|
15
12
|
* would pass red specs from inside a test process. The runner marks the spec files it starts itself, so isSpecRun stays true inside them.
|
|
16
13
|
*/
|
|
17
14
|
export function withoutTestRunner(env = process.env) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const rest = { ...env };
|
|
16
|
+
delete rest.NODE_TEST_CONTEXT;
|
|
17
|
+
return rest;
|
|
21
18
|
}
|
|
@@ -1,107 +1,102 @@
|
|
|
1
|
-
// event-contract.mjs - the async contract between the services of one product (R166 HFS_EVENT_CONTRACT).
|
|
2
|
-
// The one source of the contract is the typed event classes of a service, `be/src/modules/events/<service>/<event>.event.ts`:
|
|
3
|
-
// export interface OrderPlacedPayload { readonly orderId: string; readonly totalMinorUnits: number }
|
|
4
|
-
// export class OrderPlacedEvent extends BaseEvent {
|
|
5
|
-
// static readonly eventName = "order.placed"; static readonly version = 1
|
|
6
|
-
// static readonly compensates = "order.placed" // only an event that reports the failure of a step
|
|
7
|
-
// static create(payload: OrderPlacedPayload): OrderPlacedEvent { ... }
|
|
8
|
-
// }
|
|
9
|
-
// `starci app emit` writes `be/contracts/<service>/events.json` from them (name, version, compensates, and the payload fields of the
|
|
10
|
-
// interface `create` takes); `starci app check` compares the committed file with the same reader. Nothing is executed: both walk the TypeScript
|
|
11
|
-
// syntax tree. The functions take the `ts` module the caller loaded (the repository's own, else the runtime's); this file imports only the code-unit comparator.
|
|
12
1
|
import { byCodeUnit } from './list.mjs';
|
|
13
|
-
|
|
14
2
|
const EVENT_CONTRACT_SCHEMA = 'starci/event-contract@1';
|
|
15
3
|
const FIELD_TYPE = /^(?:string|number|boolean|string\[\]|number\[\])\??$/;
|
|
16
|
-
|
|
17
4
|
const hasStatic = (ts, member) => member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword) === true;
|
|
18
|
-
|
|
19
5
|
/** The literal of a `static readonly <name> = <literal>` member: `{ text }` for a string, `{ number }` for an integer, or null. */
|
|
20
6
|
function staticLiteral(ts, member) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
7
|
+
if (!ts.isPropertyDeclaration(member) || !hasStatic(ts, member) || !ts.isIdentifier(member.name) || member.initializer === undefined)
|
|
8
|
+
return null;
|
|
9
|
+
let value = member.initializer;
|
|
10
|
+
while (ts.isAsExpression(value) || ts.isParenthesizedExpression(value))
|
|
11
|
+
value = value.expression;
|
|
12
|
+
if (ts.isStringLiteralLike(value))
|
|
13
|
+
return { name: member.name.text, text: value.text };
|
|
14
|
+
if (ts.isNumericLiteral(value) && Number.isInteger(Number(value.text)))
|
|
15
|
+
return { name: member.name.text, number: Number(value.text) };
|
|
16
|
+
return null;
|
|
27
17
|
}
|
|
28
|
-
|
|
29
18
|
/** The text of a type node when it is one of the wire field types (`string`, `number`, `boolean`, `string[]`, `number[]`), else null. */
|
|
30
19
|
function fieldType(ts, node) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
if (node.kind === ts.SyntaxKind.StringKeyword)
|
|
21
|
+
return 'string';
|
|
22
|
+
if (node.kind === ts.SyntaxKind.NumberKeyword)
|
|
23
|
+
return 'number';
|
|
24
|
+
if (node.kind === ts.SyntaxKind.BooleanKeyword)
|
|
25
|
+
return 'boolean';
|
|
26
|
+
if (ts.isArrayTypeNode(node)) {
|
|
27
|
+
const element = fieldType(ts, node.elementType);
|
|
28
|
+
return element === 'string' || element === 'number' ? `${element}[]` : null;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
function appendPayloadMember(ts, member, typeName, problems, where, payload) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
if (!ts.isPropertySignature(member) || !ts.isIdentifier(member.name) || member.type === undefined) {
|
|
34
|
+
problems.push(`${where}: the payload ${typeName} holds a member that is not \`name: type\``);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const type = fieldType(ts, member.type);
|
|
38
|
+
let written = null;
|
|
39
|
+
if (type !== null)
|
|
40
|
+
written = `${type}${member.questionToken ? '?' : ''}`;
|
|
41
|
+
if (written === null || !FIELD_TYPE.test(written))
|
|
42
|
+
problems.push(`${where}: payload field ${member.name.text} must be string, number, boolean, string[] or number[]`);
|
|
43
|
+
else
|
|
44
|
+
payload[member.name.text] = written;
|
|
51
45
|
}
|
|
52
|
-
|
|
53
46
|
/** The payload fields of the interface or type literal named `typeName` in the file: `{ <field>: <type> }`, optional fields with a `?`. */
|
|
54
47
|
function payloadOf(ts, sourceFile, typeName, problems, where) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
let members = null;
|
|
49
|
+
for (const statement of sourceFile.statements) {
|
|
50
|
+
if (ts.isInterfaceDeclaration(statement) && statement.name.text === typeName)
|
|
51
|
+
members = statement.members;
|
|
52
|
+
if (ts.isTypeAliasDeclaration(statement) && statement.name.text === typeName && ts.isTypeLiteralNode(statement.type))
|
|
53
|
+
members = statement.type.members;
|
|
54
|
+
}
|
|
55
|
+
if (members === null) {
|
|
56
|
+
problems.push(`${where}: the payload type ${typeName} is not an interface or type literal of the file`);
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
const payload = {};
|
|
60
|
+
for (const member of members)
|
|
61
|
+
appendPayloadMember(ts, member, typeName, problems, where, payload);
|
|
62
|
+
return payload;
|
|
67
63
|
}
|
|
68
|
-
|
|
69
64
|
/**
|
|
70
65
|
* The event classes of one source text: `{ events: [{ className, name, version, compensates, payload }], problems: [text] }`. A class is an event
|
|
71
66
|
* when it declares `static readonly eventName`; `version` is required, `create(payload: <Interface>)` names the payload.
|
|
72
67
|
*/
|
|
73
68
|
export function readEventClasses(ts, text, file = 'event.ts') {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
69
|
+
const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
70
|
+
const events = [];
|
|
71
|
+
const problems = [];
|
|
72
|
+
for (const statement of sourceFile.statements) {
|
|
73
|
+
if (!ts.isClassDeclaration(statement) || statement.name === undefined)
|
|
74
|
+
continue;
|
|
75
|
+
const literals = statement.members.map((member) => staticLiteral(ts, member)).filter((literal) => literal !== null);
|
|
76
|
+
const name = literals.find((literal) => literal.name === 'eventName')?.text;
|
|
77
|
+
if (name === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
const className = statement.name.text;
|
|
80
|
+
const version = literals.find((literal) => literal.name === 'version')?.number;
|
|
81
|
+
const compensates = literals.find((literal) => literal.name === 'compensates')?.text;
|
|
82
|
+
if (version === undefined || version < 1)
|
|
83
|
+
problems.push(`${className} needs \`static readonly version\` as a positive integer`);
|
|
84
|
+
const create = statement.members.find((member) => ts.isMethodDeclaration(member) && hasStatic(ts, member) && ts.isIdentifier(member.name) && member.name.text === 'create');
|
|
85
|
+
const parameter = create?.parameters[0]?.type;
|
|
86
|
+
if (parameter === undefined || !ts.isTypeReferenceNode(parameter) || !ts.isIdentifier(parameter.typeName)) {
|
|
87
|
+
problems.push(`${className} needs \`static create(payload: <Interface>)\` naming its payload interface`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
events.push({ className, name, version: version ?? 0, ...(compensates === undefined ? {} : { compensates }), payload: payloadOf(ts, sourceFile, parameter.typeName.text, problems, className) });
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
return { events, problems };
|
|
92
|
+
return { events, problems };
|
|
95
93
|
}
|
|
96
|
-
|
|
97
94
|
/** The sorted object: keys in code-point order, recursively (what the snapshot prints). */
|
|
98
95
|
const sorted = (value) => (value !== null && typeof value === 'object' && !Array.isArray(value) ? Object.fromEntries(Object.keys(value).sort(byCodeUnit).map((key) => [key, sorted(value[key])])) : value);
|
|
99
|
-
|
|
100
96
|
/** The text of the snapshot of a service from its event classes: 2-space JSON, sorted keys, one final newline. */
|
|
101
97
|
export function snapshotText(service, events) {
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
const table = Object.fromEntries(events.map(({ name, version, compensates, payload }) => [name, { version, payload, ...(compensates === undefined ? {} : { compensates }) }]));
|
|
99
|
+
return `${JSON.stringify(sorted({ schema: EVENT_CONTRACT_SCHEMA, service, events: table }), null, 2)}\n`;
|
|
104
100
|
}
|
|
105
|
-
|
|
106
101
|
/** The snapshot's text with line endings folded, for comparing a committed file to a fresh one. */
|
|
107
102
|
export const folded = (text) => text.replaceAll('\r\n', '\n');
|