@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
|
@@ -3,7 +3,6 @@ import path from 'node:path';
|
|
|
3
3
|
import { parseYaml } from '../../engine/yaml.mjs';
|
|
4
4
|
import { words } from './dockerfile.mjs';
|
|
5
5
|
import { asList } from './list.mjs';
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* The services of a repository's own stack definition, read from `.starcistacks/application-stacks.yaml` and the compose
|
|
9
8
|
* files of one environment (`environments.<env>.composeFiles`, `include:` followed). The R47 `test-world-files` machine check
|
|
@@ -18,175 +17,175 @@ import { asList } from './list.mjs';
|
|
|
18
17
|
export const STACKS_DIRECTORY = '.starcistacks';
|
|
19
18
|
const STACKS_FILE = 'application-stacks.yaml';
|
|
20
19
|
export const DEFAULT_ENVIRONMENT = 'dev';
|
|
21
|
-
|
|
22
20
|
/** Test-only value the `*_FILE` secret variables of a compose service become (the file variable is replaced by the plain variable of the same name). Never a real secret: the test stack listens on loopback only. */
|
|
23
21
|
const TEST_SECRET_VALUE = 'starci-test-secret';
|
|
24
|
-
|
|
25
22
|
const NOT_RUN_ROLES = new Set(['service', 'observability']);
|
|
26
23
|
const NOT_RUN_PROFILES = new Set(['app']);
|
|
27
|
-
|
|
28
24
|
/**
|
|
29
25
|
* What the reader knows about the well-known images of a stack, by the repository name of the image: how the test stack
|
|
30
26
|
* tells the service answers (`probe`), which name its fakes could hide behind (`aliases`), and its kind. An image it does not
|
|
31
27
|
* know is probed by TCP and is only matched by its own name.
|
|
32
28
|
*/
|
|
33
29
|
const KNOWN_IMAGES = Object.freeze({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
postgres: { kind: 'database', aliases: ['postgres', 'postgresql', 'pg', 'database', 'db'], probe: { exec: ['pg_isready', '-h', '127.0.0.1'] } },
|
|
31
|
+
redis: { kind: 'cache', aliases: ['redis', 'cache', 'valkey'], probe: { exec: ['redis-cli', 'ping'] } },
|
|
32
|
+
valkey: { kind: 'cache', aliases: ['redis', 'cache', 'valkey'], probe: { exec: ['valkey-cli', 'ping'] } },
|
|
33
|
+
keycloak: { kind: 'identity', aliases: ['keycloak', 'idp', 'oidc'], probe: { http: { path: '/realms/master' } } },
|
|
34
|
+
minio: { kind: 'storage', aliases: ['minio', 's3', 'storage'], probe: { http: { path: '/minio/health/live', containerPort: 9000 } } },
|
|
35
|
+
mailpit: { kind: 'mail', aliases: ['mailpit', 'mail', 'smtp', 'mailhog', 'maildev'], probe: { http: { path: '/livez', containerPort: 8025 } } },
|
|
36
|
+
mailhog: { kind: 'mail', aliases: ['mailpit', 'mail', 'smtp', 'mailhog', 'maildev'], probe: { http: { path: '/', containerPort: 8025 } } },
|
|
37
|
+
maildev: { kind: 'mail', aliases: ['mailpit', 'mail', 'smtp', 'mailhog', 'maildev'], probe: { http: { path: '/healthz', containerPort: 1080 } } },
|
|
38
|
+
toxiproxy: { kind: 'proxy', aliases: ['toxiproxy'], probe: { http: { path: '/version', containerPort: 8474 } } },
|
|
39
|
+
mysql: { kind: 'database', aliases: ['mysql', 'database', 'db'], probe: { tcp: true } },
|
|
40
|
+
mariadb: { kind: 'database', aliases: ['mariadb', 'mysql', 'database', 'db'], probe: { tcp: true } },
|
|
41
|
+
mongo: { kind: 'database', aliases: ['mongo', 'mongodb', 'database', 'db'], probe: { tcp: true } },
|
|
42
|
+
clickhouse: { kind: 'database', aliases: ['clickhouse', 'database', 'db'], probe: { tcp: true } },
|
|
43
|
+
kafka: { kind: 'queue', aliases: ['kafka', 'queue', 'broker'], probe: { tcp: true } },
|
|
44
|
+
redpanda: { kind: 'queue', aliases: ['redpanda', 'kafka', 'queue', 'broker'], probe: { tcp: true } },
|
|
45
|
+
elasticsearch: { kind: 'search', aliases: ['elasticsearch', 'elastic', 'search'], probe: { tcp: true } },
|
|
46
|
+
opensearch: { kind: 'search', aliases: ['opensearch', 'search'], probe: { tcp: true } },
|
|
51
47
|
});
|
|
52
|
-
|
|
53
48
|
/**
|
|
54
49
|
* The kinds of well-known image that hold data an app reads back. A stack service of one of these kinds (or one the stack gives
|
|
55
50
|
* a persistent volume) is stateful: it always runs real in the test world and can never be faked, even with a declared
|
|
56
51
|
* exception (BE-CONVENTION 1.16: only stateless compute that needs special hardware or an external model may be faked).
|
|
57
52
|
*/
|
|
58
53
|
export const STATEFUL_KINDS = Object.freeze(new Set(['database', 'cache', 'identity', 'storage', 'mail', 'queue', 'search']));
|
|
59
|
-
|
|
60
54
|
/** The repository name of an image reference: `quay.io/keycloak/keycloak:26.0` -> `keycloak`. */
|
|
61
|
-
export const repositoryOf = image => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
export const repositoryOf = (image) => {
|
|
56
|
+
const withoutDigest = image.split('@')[0];
|
|
57
|
+
const lastSegment = withoutDigest.split('/').at(-1) ?? withoutDigest;
|
|
58
|
+
return lastSegment.split(':')[0];
|
|
65
59
|
};
|
|
66
|
-
|
|
67
60
|
/** The repository path of an image reference without its tag: `quay.io/keycloak/keycloak:26.0` -> `quay.io/keycloak/keycloak`. */
|
|
68
|
-
const imagePathOf = image => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
const imagePathOf = (image) => {
|
|
62
|
+
const withoutDigest = image.split('@')[0];
|
|
63
|
+
const lastSlash = withoutDigest.lastIndexOf('/');
|
|
64
|
+
const colon = withoutDigest.indexOf(':', lastSlash + 1);
|
|
65
|
+
return colon === -1 ? withoutDigest : withoutDigest.slice(0, colon);
|
|
73
66
|
};
|
|
74
|
-
|
|
75
67
|
/** True when the image reference carries a tag or digest (an external image, not a placeholder of the repository's own build). */
|
|
76
|
-
const isTagged = image => image.includes('@') || image.slice(image.lastIndexOf('/') + 1).includes(':');
|
|
77
|
-
|
|
68
|
+
const isTagged = (image) => image.includes('@') || image.slice(image.lastIndexOf('/') + 1).includes(':');
|
|
78
69
|
/** A compose `environment` (map or `KEY=VALUE` list) as a plain object; a `*_FILE` variable becomes the plain variable with the test value. */
|
|
79
|
-
const environmentOf = value => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
const environmentOf = (value) => {
|
|
71
|
+
const entries = Array.isArray(value)
|
|
72
|
+
? value.map((item) => { const text = String(item); const at = text.indexOf('='); return at === -1 ? [text, ''] : [text.slice(0, at), text.slice(at + 1)]; })
|
|
73
|
+
: Object.entries((value ?? {})).map(([key, item]) => [key, item === null ? '' : String(item)]);
|
|
74
|
+
const out = {};
|
|
75
|
+
for (const [key, item] of entries) {
|
|
76
|
+
if (key.endsWith('_FILE'))
|
|
77
|
+
out[key.slice(0, -'_FILE'.length)] = TEST_SECRET_VALUE;
|
|
78
|
+
else
|
|
79
|
+
out[key] = item;
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
89
82
|
};
|
|
90
|
-
|
|
91
83
|
/** The container ports a compose `ports` list publishes: `"5432:5432"`, `"127.0.0.1:8080:80/tcp"`, `5432`, `{target: 80}`. */
|
|
92
|
-
const containerPortsOf = value => asList(value).map(entry => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
const containerPortsOf = (value) => asList(value).map((entry) => {
|
|
85
|
+
if (entry !== null && typeof entry === 'object')
|
|
86
|
+
return Number(entry.target);
|
|
87
|
+
const container = String(entry).split('/')[0].split(':').at(-1);
|
|
88
|
+
return Number(container);
|
|
96
89
|
}).filter(Number.isInteger);
|
|
97
|
-
|
|
98
90
|
/** The bind mounts of a compose `volumes` list whose source is a path (`./realm.json:/x:ro`); named volumes are ephemeral in the test stack and are skipped. */
|
|
99
91
|
const mountsOf = (value, directory) => {
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
const mounts = [];
|
|
93
|
+
for (const entry of asList(value)) {
|
|
94
|
+
if (entry !== null && typeof entry === 'object') {
|
|
95
|
+
const long = entry;
|
|
96
|
+
if (long.type === 'bind' && typeof long.source === 'string')
|
|
97
|
+
mounts.push({ host: path.resolve(directory, long.source), container: String(long.target), readOnly: long.read_only === true });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const parts = String(entry).split(':');
|
|
101
|
+
// A Windows drive letter is not a separator: a `<drive>:<path>:/y` mount keeps its drive.
|
|
102
|
+
const source = /^[A-Za-z]$/u.test(parts[0]) && parts.length > 2 ? `${parts.shift()}:${parts.shift()}` : parts.shift();
|
|
103
|
+
const target = parts.shift();
|
|
104
|
+
if (!source || !target || !(source.startsWith('.') || path.isAbsolute(source)))
|
|
105
|
+
continue;
|
|
106
|
+
mounts.push({ host: path.resolve(directory, source), container: target, readOnly: parts.includes('ro') });
|
|
107
|
+
}
|
|
108
|
+
return mounts;
|
|
109
|
+
};
|
|
110
|
+
/** True when a compose `volumes` list gives the service somewhere to keep data: a named volume, or a bind mount that is not read-only. */
|
|
111
|
+
const persistsData = (value) => asList(value).some((entry) => {
|
|
102
112
|
if (entry !== null && typeof entry === 'object') {
|
|
103
|
-
|
|
104
|
-
|
|
113
|
+
const long = entry;
|
|
114
|
+
return long.type === 'volume' || (long.type === 'bind' && long.read_only !== true);
|
|
105
115
|
}
|
|
106
116
|
const parts = String(entry).split(':');
|
|
107
|
-
// A Windows drive letter is not a separator: a `<drive>:<path>:/y` mount keeps its drive.
|
|
108
117
|
const source = /^[A-Za-z]$/u.test(parts[0]) && parts.length > 2 ? `${parts.shift()}:${parts.shift()}` : parts.shift();
|
|
109
|
-
|
|
110
|
-
if (!source
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/** True when a compose `volumes` list gives the service somewhere to keep data: a named volume, or a bind mount that is not read-only. */
|
|
117
|
-
const persistsData = value => asList(value).some(entry => {
|
|
118
|
-
if (entry !== null && typeof entry === 'object') return entry.type === 'volume' || (entry.type === 'bind' && entry.read_only !== true);
|
|
119
|
-
const parts = String(entry).split(':');
|
|
120
|
-
const source = /^[A-Za-z]$/u.test(parts[0]) && parts.length > 2 ? `${parts.shift()}:${parts.shift()}` : parts.shift();
|
|
121
|
-
parts.shift();
|
|
122
|
-
if (!source) return false;
|
|
123
|
-
const isPath = source.startsWith('.') || path.isAbsolute(source);
|
|
124
|
-
return !isPath || !parts.includes('ro');
|
|
118
|
+
parts.shift();
|
|
119
|
+
if (!source)
|
|
120
|
+
return false;
|
|
121
|
+
const isPath = source.startsWith('.') || path.isAbsolute(source);
|
|
122
|
+
return !isPath || !parts.includes('ro');
|
|
125
123
|
});
|
|
126
|
-
|
|
127
|
-
const readYaml = file => parseYaml(fs.readFileSync(file, 'utf8')) ?? {};
|
|
128
|
-
|
|
124
|
+
const readYaml = (file) => parseYaml(fs.readFileSync(file, 'utf8')) ?? {};
|
|
129
125
|
/** The compose services of `file` and of every file it includes: [{name, definition, directory}]. */
|
|
130
126
|
const composeServices = (file, seen = new Set()) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
127
|
+
const resolved = path.resolve(file);
|
|
128
|
+
if (seen.has(resolved) || !fs.existsSync(resolved))
|
|
129
|
+
return [];
|
|
130
|
+
seen.add(resolved);
|
|
131
|
+
const document = readYaml(resolved);
|
|
132
|
+
const directory = path.dirname(resolved);
|
|
133
|
+
const included = asList(document.include).flatMap(entry => {
|
|
134
|
+
const target = typeof entry === 'string' ? entry : entry?.path;
|
|
135
|
+
return typeof target === 'string' ? composeServices(path.resolve(directory, target), seen) : [];
|
|
136
|
+
});
|
|
137
|
+
const own = Object.entries(document.services ?? {}).map(([name, definition]) => ({ name, definition: definition ?? {}, directory }));
|
|
138
|
+
return [...included, ...own];
|
|
142
139
|
};
|
|
143
|
-
|
|
144
140
|
/**
|
|
145
141
|
* The stack of `environment`, or null when the repository declares none. `{ environment, directory, services, proxy }`:
|
|
146
142
|
* `services` are the services the environment declares (`name`, `image`, `repository`, `tag`, `role`, `kind`, `aliases`,
|
|
147
143
|
* `probe`, `command`, `environment`, `ports`, `mounts`, `persistent`, `runs`), `proxy` the toxiproxy service or null.
|
|
148
144
|
*/
|
|
149
145
|
export function readStack({ root, environment = DEFAULT_ENVIRONMENT }) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
146
|
+
const stacksFile = path.join(root, STACKS_DIRECTORY, STACKS_FILE);
|
|
147
|
+
if (!fs.existsSync(stacksFile))
|
|
148
|
+
return null;
|
|
149
|
+
const declaration = readYaml(stacksFile);
|
|
150
|
+
const env = declaration.environments?.[environment];
|
|
151
|
+
if (!env)
|
|
152
|
+
return null;
|
|
153
|
+
const directory = path.join(root, STACKS_DIRECTORY, environment);
|
|
154
|
+
const components = declaration.components ?? {};
|
|
155
|
+
const declared = new Map();
|
|
156
|
+
for (const composeFile of asList(env.composeFiles)) {
|
|
157
|
+
for (const { name, definition, directory: composeDirectory } of composeServices(path.join(directory, composeFile)))
|
|
158
|
+
declared.set(name, { definition, directory: composeDirectory });
|
|
159
|
+
}
|
|
160
|
+
const services = [];
|
|
161
|
+
for (const [name, { definition, directory: composeDirectory }] of declared) {
|
|
162
|
+
const image = typeof definition.image === 'string' ? definition.image : components[name]?.image;
|
|
163
|
+
if (typeof image !== 'string')
|
|
164
|
+
continue;
|
|
165
|
+
const repository = repositoryOf(image);
|
|
166
|
+
const known = KNOWN_IMAGES[repository];
|
|
167
|
+
const role = components[name]?.role ?? 'stateful';
|
|
168
|
+
const profiles = asList(definition.profiles);
|
|
169
|
+
const command = typeof definition.command === 'string' ? words(definition.command) : asList(definition.command).map(String);
|
|
170
|
+
services.push({
|
|
171
|
+
name,
|
|
172
|
+
image,
|
|
173
|
+
repository,
|
|
174
|
+
tag: isTagged(image) ? image.slice(imagePathOf(image).length + 1) : null,
|
|
175
|
+
role,
|
|
176
|
+
kind: known?.kind ?? 'other',
|
|
177
|
+
aliases: known?.aliases ?? [repository],
|
|
178
|
+
probe: known?.probe ?? { tcp: true },
|
|
179
|
+
command,
|
|
180
|
+
environment: environmentOf(definition.environment),
|
|
181
|
+
ports: containerPortsOf(definition.ports),
|
|
182
|
+
mounts: mountsOf(definition.volumes, composeDirectory),
|
|
183
|
+
persistent: persistsData(definition.volumes),
|
|
184
|
+
runs: !NOT_RUN_ROLES.has(role) && !profiles.some(profile => NOT_RUN_PROFILES.has(profile)),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const proxy = services.find(service => service.kind === 'proxy') ?? null;
|
|
188
|
+
return { environment, directory, services, proxy };
|
|
189
189
|
}
|
|
190
|
-
|
|
191
190
|
/** The names a fake of `service` could hide behind: its own name, its image repository and the aliases of a well-known image. */
|
|
192
|
-
export const namesOfService = service => [...new Set([service.name, service.repository, ...service.aliases])];
|
|
191
|
+
export const namesOfService = (service) => [...new Set([service.name, service.repository, ...service.aliases])];
|
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
/** The expression under the wrappers selected by an AST check's contract. */
|
|
2
2
|
export function unwrapExpression(ts, expression, { awaitExpressions = false, typeAssertions = true, nonNullExpressions = true, satisfiesExpressions = true } = {}) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
let current = expression;
|
|
4
|
+
while (current) {
|
|
5
|
+
const wrapper = ts.isParenthesizedExpression(current) || ts.isAsExpression(current)
|
|
6
|
+
|| (typeAssertions && ts.isTypeAssertionExpression(current)) || (nonNullExpressions && ts.isNonNullExpression(current))
|
|
7
|
+
|| (satisfiesExpressions && (ts.isSatisfiesExpression?.(current) ?? false))
|
|
8
|
+
|| (awaitExpressions && ts.isAwaitExpression(current));
|
|
9
|
+
if (!wrapper)
|
|
10
|
+
break;
|
|
11
|
+
current = current.expression;
|
|
12
|
+
}
|
|
13
|
+
return current;
|
|
12
14
|
}
|
|
13
|
-
|
|
14
15
|
/** Local name -> imported name and module; callers select their existing module key and literal policy. */
|
|
15
16
|
export function importsOf(ts, sourceFile, { moduleKey = 'module', stringLiteralsOnly = false } = {}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
const imports = new Map();
|
|
18
|
+
for (const statement of sourceFile.statements) {
|
|
19
|
+
if (!ts.isImportDeclaration(statement) || (stringLiteralsOnly && !ts.isStringLiteralLike(statement.moduleSpecifier)))
|
|
20
|
+
continue;
|
|
21
|
+
const bindings = statement.importClause?.namedBindings;
|
|
22
|
+
if (!bindings || !ts.isNamedImports(bindings))
|
|
23
|
+
continue;
|
|
24
|
+
for (const binding of bindings.elements)
|
|
25
|
+
imports.set(binding.name.text, { name: (binding.propertyName ?? binding.name).text, [moduleKey]: statement.moduleSpecifier.text });
|
|
26
|
+
}
|
|
27
|
+
return imports;
|
|
24
28
|
}
|
|
25
|
-
|
|
26
29
|
/** Catalog values unwrap parentheses, `as`, and `satisfies`, preserving assertions and non-null nodes. */
|
|
27
30
|
export const unwrapCatalogExpression = (ts, node) => unwrapExpression(ts, node, { typeAssertions: false, nonNullExpressions: false });
|
|
28
|
-
|
|
29
31
|
/** Bind this file in isolation: the compiler resolves lexical names, but imports and library files are never loaded. */
|
|
30
32
|
export function lexicalChecker(ts, source) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const options = { noLib: true, noResolve: true, allowJs: true };
|
|
34
|
+
const host = ts.createCompilerHost(options);
|
|
35
|
+
host.getSourceFile = (file) => file === source.fileName ? source : undefined;
|
|
36
|
+
host.fileExists = () => false;
|
|
37
|
+
host.readFile = () => undefined;
|
|
38
|
+
return ts.createProgram([source.fileName], options, host).getTypeChecker();
|
|
37
39
|
}
|
|
@@ -1,69 +1,63 @@
|
|
|
1
|
-
// ts-ast.mjs — the small reads the hfs checks share over TypeScript's own AST: a node's name or
|
|
2
|
-
// literal text, a node's 1-based position, a named property's initializer text. `ts` is the caller's
|
|
3
|
-
// already-resolved compiler (see package-at.mjs loadTypescript); nothing here resolves a package.
|
|
4
|
-
|
|
5
1
|
/** Whether the single-bit `flag` (a ts.NodeFlags member) is set in `flags`: the bit read as arithmetic, no bitwise operator in the condition. */
|
|
6
2
|
export const hasFlag = (flags, flag) => Math.floor(flags / flag) % 2 === 1;
|
|
7
|
-
|
|
8
3
|
/** Whether any bit of `mask` (a ts flag or an OR of flags) is set in `flags` (absent flags read as none): an explicit comparison of the masked value. */
|
|
9
4
|
export const hasAnyFlag = (flags, mask) => ((flags ?? 0) & mask) !== 0;
|
|
10
|
-
|
|
11
5
|
/** Whether the variable `declaration` belongs to a `const` list: the TypeScript node-flag test, an explicit comparison of the masked flags. */
|
|
12
6
|
export const isConstVariable = (ts, declaration) => (ts.getCombinedNodeFlags(declaration.parent) & ts.NodeFlags.Const) !== 0;
|
|
13
|
-
|
|
14
7
|
/** Text of a string-literal-like node or an enabled identifier/numeric name; null for other expressions. */
|
|
15
8
|
export function nameText(ts, node, { identifiers = true, numbers = false } = {}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
if (!node)
|
|
10
|
+
return null;
|
|
11
|
+
if (ts.isStringLiteralLike(node) || (identifiers && ts.isIdentifier(node)) || (numbers && ts.isNumericLiteral(node)))
|
|
12
|
+
return node.text;
|
|
13
|
+
return null;
|
|
19
14
|
}
|
|
20
|
-
|
|
21
15
|
/** A statically selected property name, including string-literal element access; null for computed selections. */
|
|
22
16
|
export function accessName(ts, node) {
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
if (ts.isPropertyAccessExpression(node))
|
|
18
|
+
return node.name.text;
|
|
19
|
+
return ts.isElementAccessExpression(node) ? literalText(ts, node.argumentExpression) : null;
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
/** The text of a string-literal-like `node` (a string literal or a no-substitution template), or null. */
|
|
28
22
|
export const literalText = (ts, node) => (node && ts.isStringLiteralLike(node) ? node.text : null);
|
|
29
|
-
|
|
30
23
|
/** The 1-based {line, column} of `node` in `sourceFile`. */
|
|
31
24
|
export const sourceLocation = (sourceFile, node) => {
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
26
|
+
return { line: position.line + 1, column: position.character + 1 };
|
|
34
27
|
};
|
|
35
|
-
|
|
36
28
|
/**
|
|
37
29
|
* The `.text` of `key`'s property initializer in `text` (parsed as `file`): a property assignment
|
|
38
30
|
* inside an object literal, or — `declaration: true` — a class property declaration. `kind` is
|
|
39
31
|
* 'string' (a string-literal-like initializer) or 'identifier'. The last match wins; null when none.
|
|
40
32
|
*/
|
|
41
33
|
export function propertyText(ts, text, { file = 'source.ts', key, declaration = false, kind = 'string' } = {}) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
35
|
+
let value = null;
|
|
36
|
+
const visit = (node) => {
|
|
37
|
+
const prop = declaration
|
|
38
|
+
? (ts.isPropertyDeclaration(node) ? node : undefined)
|
|
39
|
+
: (ts.isPropertyAssignment(node) ? node : undefined);
|
|
40
|
+
if (prop?.name && ts.isIdentifier(prop.name) && prop.name.text === key && prop.initializer) {
|
|
41
|
+
const initializer = prop.initializer;
|
|
42
|
+
if (kind === 'identifier' ? ts.isIdentifier(initializer) : ts.isStringLiteralLike(initializer))
|
|
43
|
+
value = initializer.text;
|
|
44
|
+
}
|
|
45
|
+
ts.forEachChild(node, visit);
|
|
46
|
+
};
|
|
47
|
+
visit(source);
|
|
48
|
+
return value;
|
|
54
49
|
}
|
|
55
|
-
|
|
56
50
|
/** Initializers of every identifier-named variable, grouped in traversal order across the source's scopes. */
|
|
57
51
|
export function variableInitializerGroups(ts, source) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
const groups = new Map();
|
|
53
|
+
const collect = (node) => {
|
|
54
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
|
|
55
|
+
const initializers = groups.get(node.name.text) ?? [];
|
|
56
|
+
initializers.push(node.initializer);
|
|
57
|
+
groups.set(node.name.text, initializers);
|
|
58
|
+
}
|
|
59
|
+
ts.forEachChild(node, collect);
|
|
60
|
+
};
|
|
61
|
+
collect(source);
|
|
62
|
+
return groups;
|
|
69
63
|
}
|
|
@@ -1,39 +1,45 @@
|
|
|
1
1
|
// walk.mjs - filesystem walking helpers: isInside (containment) and walkFiles (depth-first file listing).
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
|
|
5
4
|
/** Whether `target` is `root` itself or inside it (filesystem paths, either separator). `includeSelf: false` excludes `target === root`. */
|
|
6
5
|
export function isInside(root, target, { includeSelf = true } = {}) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const relative = path.relative(root, target);
|
|
7
|
+
if (relative === '')
|
|
8
|
+
return includeSelf;
|
|
9
|
+
return !relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Every entry under `dir` that is not a directory, depth-first; `filter` sees the entry name and full
|
|
13
13
|
* path. `sorted` sorts each directory's entries by name (default: readdir order). `exclude`
|
|
14
14
|
* applies to files and directories before descent; `maxDepth` counts from the starting dir.
|
|
15
15
|
*/
|
|
16
|
-
export function walkFiles(dir, {filter = () => true, sorted = false, exclude = () => false,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
export function walkFiles(dir, { filter = () => true, sorted = false, exclude = () => false, maxDepth = Infinity, ignoreReadErrors = false } = {}) {
|
|
17
|
+
const out = [];
|
|
18
|
+
const visit = (current, depth) => {
|
|
19
|
+
if (depth > maxDepth)
|
|
20
|
+
return;
|
|
21
|
+
let entries;
|
|
22
|
+
try {
|
|
23
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (ignoreReadErrors) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
if (sorted)
|
|
32
|
+
entries = entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
const full = path.join(current, entry.name);
|
|
35
|
+
if (exclude(entry.name, full, entry))
|
|
36
|
+
continue;
|
|
37
|
+
if (entry.isDirectory())
|
|
38
|
+
visit(full, depth + 1);
|
|
39
|
+
else if (filter(entry.name, full))
|
|
40
|
+
out.push(full);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
visit(dir, 0);
|
|
44
|
+
return out;
|
|
39
45
|
}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
// bytes do not change between those asks, so the parse (the dominant cost of a load) is keyed by the text itself; each caller gets its own copy of the
|
|
5
5
|
// parsed document, so nothing a caller does to it reaches the next one. A changed file is a different text and parses again.
|
|
6
6
|
import { parseYaml } from '../../engine/yaml.mjs';
|
|
7
|
-
|
|
8
7
|
const parsed = new Map();
|
|
9
|
-
|
|
10
8
|
/** The parsed document of `text`: parsed on the first ask for this text, a structured copy afterwards. Throws what parseYaml throws, every time. */
|
|
9
|
+
// reason: the parsed YAML document is an unvalidated input boundary; each caller narrows what it reads.
|
|
11
10
|
export function parseYamlCached(text) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (!parsed.has(text))
|
|
12
|
+
parsed.set(text, parseYaml(text));
|
|
13
|
+
return structuredClone(parsed.get(text));
|
|
14
14
|
}
|