@starci/eslint-canon-be 3.0.7 → 3.0.9
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 +13 -1
- package/README.md +13 -7
- package/ambient-id.mjs +90 -0
- package/cli.mjs +181 -0
- package/comments.mjs +18 -21
- package/config-owner.mjs +20 -4
- package/connections.mjs +12 -12
- package/cookies.mjs +106 -0
- package/cqrs.mjs +22 -26
- package/data-access.mjs +9 -28
- package/default-deny.mjs +2 -1
- package/e2e-flow.mjs +4 -4
- package/event-bus.mjs +237 -0
- package/feature-thin.mjs +237 -0
- package/idempotency.mjs +3 -1
- package/index.mjs +22 -1
- package/infra-owner.mjs +1 -1
- package/injection.mjs +67 -22
- package/input-bounds.mjs +2 -1
- package/jobs.mjs +214 -0
- package/lib/ast.mjs +7 -0
- package/lib/config.mjs +1 -1
- package/lib/db-writes.mjs +1 -1
- package/lib/doors.mjs +81 -0
- package/lib/edition.mjs +45 -0
- package/lib/entity-writes.mjs +35 -0
- package/lib/hfs.mjs +3 -3
- package/lib/path.mjs +0 -6
- package/lib/persistence.mjs +11 -18
- package/lib/ports.mjs +5 -2
- package/lib/specifier.mjs +27 -0
- package/lib/transactions.mjs +37 -0
- package/lib/transport-slots.mjs +8 -3
- package/lib/unit-spec.mjs +63 -2
- package/module-layering.mjs +3 -24
- package/module-shape.mjs +2 -2
- package/naming.mjs +2 -2
- package/package.json +5 -3
- package/project-graph.mjs +8 -5
- package/projections.mjs +117 -0
- package/query-safety.mjs +1 -1
- package/realtime.mjs +181 -0
- package/runtime/engine/config.mjs +494 -0
- package/runtime/engine/invalid-config.mjs +15 -0
- package/runtime/engine/orca-config.mjs +27 -0
- package/runtime/engine/runtime-root.mjs +5 -0
- package/runtime/engine/yaml.mjs +3 -3
- package/runtime/knowledge/hfs/canon-pins.yaml +163 -32
- package/runtime/knowledge/hfs/rules.yaml +2059 -0
- package/runtime/knowledge/hfs/slots.yaml +915 -123
- package/runtime/knowledge/patterns/fe/folder.yaml +133 -27
- package/runtime/knowledge/sonar-gate.yaml +53 -19
- package/runtime/modules/models/registry.yaml +591 -0
- package/runtime/modules/models/runtimes.yaml +701 -0
- package/runtime/packages/hfs/templates/app/package-scripts/package.json +3 -10
- package/runtime/scripts/api/git/config-get.mjs +10 -0
- package/runtime/scripts/api/git/lib.mjs +17 -27
- package/runtime/scripts/api/git/ls-files.mjs +6 -0
- package/runtime/scripts/api/git/recorded-lines.mjs +19 -0
- package/runtime/scripts/api/git/remote.mjs +5 -0
- package/runtime/scripts/api/git/rev-parse-query.mjs +5 -0
- package/runtime/scripts/{lib/hfs-allows.mjs → hfs/allows.mjs} +3 -3
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +220 -0
- package/runtime/scripts/{checks → hfs}/architecture/backend.mjs +17 -24
- package/runtime/scripts/{checks → hfs}/architecture/background-unowned.mjs +16 -34
- package/runtime/scripts/{checks → hfs}/architecture/client-reaches-server.mjs +3 -1
- package/runtime/scripts/{checks → hfs}/architecture/clones.mjs +4 -4
- package/runtime/scripts/{checks → hfs}/architecture/config.mjs +11 -8
- package/runtime/scripts/{checks → hfs}/architecture/connection-map.mjs +21 -9
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +88 -0
- package/runtime/scripts/hfs/architecture/context-map.mjs +237 -0
- package/runtime/scripts/hfs/architecture/context-owner.mjs +82 -0
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -0
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +60 -0
- package/runtime/scripts/{checks → hfs}/architecture/contract-fixture-guard.mjs +5 -11
- package/runtime/scripts/{checks → hfs}/architecture/contracts.mjs +33 -162
- package/runtime/scripts/{checks → hfs}/architecture/dead-exports.mjs +58 -29
- package/runtime/scripts/{checks → hfs}/architecture/doc-language.mjs +1 -1
- package/runtime/scripts/{checks → hfs}/architecture/entrypoint.mjs +2 -1
- package/runtime/scripts/{checks → hfs}/architecture/fe-slot-allows.mjs +4 -4
- package/runtime/scripts/{checks → hfs}/architecture/feature-shape.mjs +6 -3
- package/runtime/scripts/{checks → hfs}/architecture/framework-pinned.mjs +1 -1
- package/runtime/scripts/{checks → hfs}/architecture/frontend.mjs +17 -43
- package/runtime/scripts/{checks → hfs}/architecture/hfs-graph.mjs +1 -1
- package/runtime/scripts/{checks → hfs}/architecture/hfs.mjs +27 -42
- package/runtime/scripts/{checks → hfs}/architecture/i18n-keys.mjs +1 -1
- package/runtime/scripts/{checks → hfs}/architecture/index.mjs +17 -4
- package/runtime/scripts/{checks → hfs}/architecture/machine-ast.mjs +44 -11
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +27 -0
- package/runtime/scripts/{checks → hfs}/architecture/module-per-transport.mjs +30 -6
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +96 -0
- package/runtime/scripts/{checks → hfs}/architecture/next-data.mjs +40 -168
- package/runtime/scripts/{checks → hfs}/architecture/owners.mjs +35 -15
- package/runtime/scripts/{checks → hfs}/architecture/register-once.mjs +2 -1
- package/runtime/scripts/{checks → hfs}/architecture/registration.mjs +23 -81
- package/runtime/scripts/{checks → hfs}/architecture/required-files.mjs +21 -13
- package/runtime/scripts/{checks → hfs}/architecture/schema-owner.mjs +17 -114
- package/runtime/scripts/hfs/architecture/server-action.mjs +24 -0
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +16 -0
- package/runtime/scripts/{checks → hfs}/architecture/source-names.mjs +27 -147
- package/runtime/scripts/{checks → hfs}/architecture/sql-owner.mjs +59 -18
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +64 -0
- package/runtime/scripts/hfs/architecture/supabase-ast.mjs +111 -0
- package/runtime/scripts/hfs/architecture/supabase-be.mjs +131 -0
- package/runtime/scripts/hfs/architecture/supabase-tables.mjs +42 -0
- package/runtime/scripts/hfs/architecture/supabase.mjs +434 -0
- package/runtime/scripts/{checks → hfs}/architecture/surface.mjs +10 -4
- package/runtime/scripts/{checks → hfs}/architecture/test-world-files.mjs +11 -21
- package/runtime/scripts/{checks → hfs}/architecture/tiers.mjs +47 -5
- package/runtime/scripts/{checks → hfs}/architecture/transport-owner.mjs +3 -3
- package/runtime/scripts/{checks → hfs}/architecture/typescript.mjs +13 -27
- package/runtime/scripts/hfs/declaration-shape.mjs +62 -0
- package/runtime/scripts/hfs/declaration-slots.mjs +75 -0
- package/runtime/scripts/hfs/edition-slots.mjs +66 -0
- package/runtime/scripts/hfs/manifest-shape.mjs +247 -0
- package/runtime/scripts/hfs/param-names.mjs +18 -0
- package/runtime/scripts/{lib/hfs-path-findings.mjs → hfs/path-findings.mjs} +7 -7
- package/runtime/scripts/{lib → hfs}/project-graph.mjs +0 -0
- package/runtime/scripts/{lib → hfs}/project-rule.mjs +3 -3
- package/runtime/scripts/{lib → hfs}/repo-identity.mjs +9 -6
- package/runtime/scripts/hfs/rule-params-shape.mjs +50 -0
- package/runtime/scripts/{lib/hfs-rules → hfs/rules}/fe-no-tests.mjs +6 -5
- package/runtime/scripts/{lib/hfs-rules → hfs/rules}/read.mjs +1 -1
- package/runtime/scripts/{lib/hfs-rules → hfs/rules}/secrets.mjs +4 -4
- package/runtime/scripts/{lib/hfs-rules → hfs/rules}/spec-placement.mjs +1 -1
- package/runtime/scripts/{lib/hfs-slots.mjs → hfs/slots.mjs} +114 -150
- package/runtime/scripts/hfs/test-world-slot.mjs +6 -0
- package/runtime/scripts/{checks → hfs}/typescript-programs.mjs +0 -5
- package/runtime/scripts/{lib/hfs-view.mjs → hfs/view.mjs} +6 -5
- package/runtime/scripts/lib/dockerfile.mjs +124 -0
- package/runtime/scripts/lib/git.mjs +36 -0
- package/runtime/scripts/lib/i18n.mjs +86 -0
- package/runtime/scripts/lib/json.mjs +13 -3
- package/runtime/scripts/lib/language.mjs +26 -7
- package/runtime/scripts/lib/line-count.mjs +9 -0
- package/runtime/scripts/lib/list.mjs +20 -0
- package/runtime/scripts/lib/path-key.mjs +59 -2
- package/runtime/scripts/lib/read-text.mjs +34 -0
- package/runtime/scripts/lib/regex.mjs +4 -0
- package/runtime/scripts/lib/secret-patterns.mjs +4 -3
- package/runtime/scripts/lib/sops-envelope.mjs +58 -0
- package/runtime/scripts/lib/stack-services.mjs +7 -31
- package/runtime/scripts/lib/ts-ast.mjs +35 -0
- package/runtime/scripts/{checks/common.mjs → lib/walk.mjs} +5 -15
- package/schema-authority.mjs +14 -12
- package/service-deps.mjs +7 -13
- package/service-isolation.mjs +72 -0
- package/size-budget.mjs +3 -2
- package/test-world.mjs +5 -4
- package/testing.mjs +27 -24
- package/transport.mjs +12 -9
- package/unit-spec.mjs +1 -1
- package/user-copy.mjs +5 -4
- package/webhooks.mjs +173 -0
- package/runtime/scripts/api/sops/decrypt.mjs +0 -16
- package/runtime/scripts/lib/recorded-lines.mjs +0 -27
- package/runtime/scripts/lib/test-secrets.mjs +0 -116
- /package/runtime/scripts/{checks → hfs}/architecture/config-unread.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/constructor-deps.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/cross-app-duplicate.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/default-deny.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/error-codes.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/error-masked.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/hooks-are-hooks.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/injection-token-exported.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/package-shape.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/reachability.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/route-files-thin.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/sql-tokens.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/symbols.mjs +0 -0
- /package/runtime/scripts/{checks → hfs}/architecture/unit-spec-providers.mjs +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The lint surface: which architecture-machine findings an ESLint rule judges instead of `
|
|
2
|
+
* The lint surface: which architecture-machine findings an ESLint rule judges instead of `starci app check`.
|
|
3
3
|
* Single source of truth. Each enforcer id is the rules.yaml enforcer; `codes` are the exact violation.ruleId strings its
|
|
4
4
|
* check file emits on source files. plugins: 'be' = back-end profile repos, 'fe' = front-end profile, graph checks run for both.
|
|
5
5
|
*/
|
|
@@ -24,6 +24,7 @@ export const LINT_ENFORCERS = Object.freeze([
|
|
|
24
24
|
enforcer('tier-direction', BOTH, ['BE_TIER_DIRECTION', 'FE_TIER_DIRECTION'], 'An import goes only to a tier the slot matrix allows.'),
|
|
25
25
|
enforcer('owner-cycle', BOTH, ['ARCH_OWNER_CYCLE'], 'Owners never import each other in a cycle.'),
|
|
26
26
|
enforcer('feature-imports-feature', BE, ['BE_FEATURE_IMPORTS_FEATURE'], 'A feature never imports another feature.'),
|
|
27
|
+
enforcer('kind-isolation', BE, ['BE_KIND_ISOLATION'], 'A feature of one trigger kind never imports a feature of another kind; the kinds meet through the event bus.'),
|
|
27
28
|
enforcer('app-isolation', FE, ['FE_APP_ISOLATION'], 'An app never imports another app.'),
|
|
28
29
|
enforcer('feature-layout', BE, ['BE_FEATURE_LAYOUT_INVALID'], 'A feature file sits in the folder its role names.'),
|
|
29
30
|
enforcer('application-never-imports-transport', BE, ['BE_APPLICATION_IMPORTS_TRANSPORT', 'BE_APPLICATION_TRANSPORT_FRAMEWORK'], 'Application code never imports transport code, directly or through a chain.'),
|
|
@@ -33,6 +34,11 @@ export const LINT_ENFORCERS = Object.freeze([
|
|
|
33
34
|
enforcer('app-composition-only', BE, ['BE_APP_COMPOSITION_ONLY', 'BE_APP_BUSINESS_ROLE'], 'An app only composes modules and holds no business role.'),
|
|
34
35
|
enforcer('entrypoint-only-in-apps', BE, ['BE_ENTRYPOINT_ONLY_IN_APPS'], 'NestFactory and bootstrap live only in an app main file.'),
|
|
35
36
|
enforcer('schema-owner', BE, ['BE_SCHEMA_OWNER'], 'Each entity array is registered by one owner across all apps.'),
|
|
37
|
+
enforcer('sql-returning', BE, ['BE_SQL_RETURNING_SHAPE'], 'An UPDATE or DELETE with RETURNING is wrapped in a CTE SELECT, because EntityManager.query returns it as [rows, count].'),
|
|
38
|
+
enforcer('context-owner', BE, ['BE_CONTEXT_OWNER'], 'An app composes only the contexts (connections) it owns; the migration apps compose all of them.'),
|
|
39
|
+
enforcer('context-coupling', BE, ['BE_CONTEXT_COUPLING'], 'Contexts are never coupled by a relation, a foreign key or an import; only by events.'),
|
|
40
|
+
enforcer('context-transaction', BE, ['BE_CONTEXT_TRANSACTION'], 'One transaction touches one context connection.'),
|
|
41
|
+
enforcer('context-platform-tables', BE, ['BE_CONTEXT_PLATFORM_TABLES'], 'A per-connection platform capability registers its tables on every connection that uses it.'),
|
|
36
42
|
enforcer('error-code-unique', BE, ['BE_ERROR_HOME'], 'An error code is declared once in the repository.'),
|
|
37
43
|
enforcer('error-masked', BE, ['BE_ERROR_MASKED'], 'Every app wires the error filter that masks internal errors.'),
|
|
38
44
|
enforcer('default-deny-app-guard', BE, ['BE_DEFAULT_DENY'], 'Every app registers the default-deny guard before any other guard.'),
|
|
@@ -60,7 +66,7 @@ export const LINT_ENFORCERS = Object.freeze([
|
|
|
60
66
|
enforcer('component-purity', FE, ['FE_COMPONENT_WORLD_OWNERSHIP', 'FE_WORLD_OWNER_RENDER_BOUNDARY', 'FE_CONNECTED_BLOCK_RENDER_PAIR', 'FE_PURE_REACHES_DATA', 'FE_PURE_WORLD_HOOK', 'FE_PURE_WORLD_IMPORT'], 'A pure component reaches no data or world state; its connected entry owns them.'),
|
|
61
67
|
enforcer('grammar-entry', FE, ['ARCH_GRAMMAR_CONTRACT_INVALID', 'ARCH_GRAMMAR_EXPORT_BYPASS'], 'Vendor grammar is reached only through its owner entry.'),
|
|
62
68
|
enforcer('i18n-keys', FE, ['FE_I18N_KEYS'], 'Translation keys read by source and keys held by catalogs agree both ways.'),
|
|
63
|
-
// The per-path judgements of the slot manifest (scripts/
|
|
69
|
+
// The per-path judgements of the slot manifest (scripts/hfs/path-findings.mjs), on a tracked TypeScript file.
|
|
64
70
|
enforcer('slot-undeclared', BOTH, ['HFS_SLOT_UNDECLARED', 'HFS_SLOT_AMBIGUOUS', 'HFS_SLOT_NOT_ENABLED'], 'A TypeScript file is owned by exactly one slot of the repository.', { origin: 'repo' }),
|
|
65
71
|
enforcer('source-suffix', BE, ['BE_SOURCE_FORM'], 'A source file name is index.ts, main.ts, a migration or <kebab-name>.<suffix>.ts with a suffix of the closed list.', { origin: 'repo' }),
|
|
66
72
|
enforcer('spec-placement', BE, ['BE_SPEC_PLACEMENT'], 'A spec file lives in one of the four test layers and nowhere else.', { origin: 'repo' }),
|
|
@@ -74,7 +80,7 @@ export const LINT_CODES = new Set(LINT_ENFORCERS.flatMap(e => e.codes));
|
|
|
74
80
|
export const TS_SOURCE = /\.(?:[cm]?tsx?)$/;
|
|
75
81
|
|
|
76
82
|
/** True when a finding sits on an existing TypeScript file of the repository: the only findings an editor can show on a line. */
|
|
77
|
-
|
|
83
|
+
function attachesToSource(repositoryRoot, violation) {
|
|
78
84
|
const file = violation?.path;
|
|
79
85
|
if (typeof file !== 'string' || !TS_SOURCE.test(file)) return false;
|
|
80
86
|
return fs.existsSync(path.join(repositoryRoot, ...file.split('/')));
|
|
@@ -87,5 +93,5 @@ export const codeOf = (finding) => finding?.ruleId ?? finding?.code;
|
|
|
87
93
|
export const belongsTo = (enforcer, finding) => enforcer.codes.includes(codeOf(finding))
|
|
88
94
|
&& (finding.origin ?? 'machine') === (enforcer.origin ?? 'machine') && (enforcer.via === undefined || finding.check === enforcer.via);
|
|
89
95
|
|
|
90
|
-
/** True when some lint rule owns the finding and it sits on an existing TypeScript file: it is an ESLint report, not a `
|
|
96
|
+
/** True when some lint rule owns the finding and it sits on an existing TypeScript file: it is an ESLint report, not a `starci app check` finding. */
|
|
91
97
|
export const onLintSurface = (repositoryRoot, finding) => LINT_ENFORCERS.some(enforcer => belongsTo(enforcer, finding)) && attachesToSource(repositoryRoot, finding);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { allowsFile } from '
|
|
3
|
-
import { locateDeclaration } from '
|
|
1
|
+
import { checkerScope } from './required-files.mjs';
|
|
2
|
+
import { allowsFile } from '../allows.mjs';
|
|
3
|
+
import { locateDeclaration } from '../slots.mjs';
|
|
4
4
|
import { DEFAULT_ENVIRONMENT, STACKS_DIRECTORY, STATEFUL_KINDS, namesOfService, readStack } from '../../lib/stack-services.mjs';
|
|
5
|
+
import { unwrapEach } from './ast-walks.mjs';
|
|
6
|
+
import { nameText, sourceLocation } from '../../lib/ts-ast.mjs';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* R47 `test-world-files` (BE_TEST_TOPOLOGY). Judgements over the test world, read through slots, the repository's own
|
|
@@ -40,18 +42,9 @@ const NAMED_FORM = `export const { useTestWorld, useSandbox } = ${DEFINE}({ ...
|
|
|
40
42
|
const defaultEnvironment = DEFAULT_ENVIRONMENT;
|
|
41
43
|
const KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
42
44
|
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
let current = node;
|
|
46
|
-
while (current && (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression?.(current))) current = current.expression;
|
|
47
|
-
return current;
|
|
48
|
-
};
|
|
49
|
-
const propertyOf = (ts, literal, key) => literal.properties.find(property => ts.isPropertyAssignment(property) && nameOf(ts, property.name) === key)?.initializer ?? null;
|
|
45
|
+
const unwrap = (ts, node) => unwrapEach(ts, node, [ts.isParenthesizedExpression, ts.isAsExpression, ts.isSatisfiesExpression]);
|
|
46
|
+
const propertyOf = (ts, literal, key) => literal.properties.find(property => ts.isPropertyAssignment(property) && nameText(ts, property.name) === key)?.initializer ?? null;
|
|
50
47
|
const isExported = (ts, statement) => (statement.modifiers ?? []).some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
51
|
-
const positionOf = (sourceFile, node) => {
|
|
52
|
-
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
53
|
-
return { line: position.line + 1, column: position.character + 1 };
|
|
54
|
-
};
|
|
55
48
|
|
|
56
49
|
/** The object literal of `defineTestWorld(<object literal>)`, or null. */
|
|
57
50
|
function defineLiteral(ts, expression) {
|
|
@@ -89,7 +82,7 @@ function fakeEntriesOf(ts, sourceFile, literal) {
|
|
|
89
82
|
const value = node ? unwrap(ts, node) : null;
|
|
90
83
|
if (!value || !ts.isObjectLiteralExpression(value)) return [];
|
|
91
84
|
return value.properties
|
|
92
|
-
.map(property => ({ name:
|
|
85
|
+
.map(property => ({ name: nameText(ts, property.name), ...sourceLocation(sourceFile, property) }))
|
|
93
86
|
.filter(entry => entry.name);
|
|
94
87
|
}
|
|
95
88
|
|
|
@@ -107,21 +100,18 @@ function fakedByOf(ts, sourceFile, literal) {
|
|
|
107
100
|
if (!fake) continue;
|
|
108
101
|
const reason = propertyOf(ts, body, 'reason');
|
|
109
102
|
entries.push({
|
|
110
|
-
service:
|
|
103
|
+
service: nameText(ts, property.name),
|
|
111
104
|
fake: ts.isStringLiteralLike(fake) ? fake.text : '',
|
|
112
105
|
reason: reason && ts.isStringLiteralLike(reason) ? reason.text.trim() : '',
|
|
113
|
-
...
|
|
106
|
+
...sourceLocation(sourceFile, property),
|
|
114
107
|
});
|
|
115
108
|
}
|
|
116
109
|
return entries;
|
|
117
110
|
}
|
|
118
111
|
|
|
119
112
|
export function checkTestWorldFiles(input) {
|
|
120
|
-
const { config, graph,
|
|
121
|
-
const ts = context.ts;
|
|
122
|
-
const resolver = graph.resolver;
|
|
113
|
+
const { config, graph, ts, resolver, tree } = checkerScope(input);
|
|
123
114
|
const { suffixes } = resolver.ruleParams();
|
|
124
|
-
const tree = treeOf(config.root);
|
|
125
115
|
const violations = [];
|
|
126
116
|
const fakeProviders = new Map();
|
|
127
117
|
let worldRoot = null;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import { isServerActionModule } from './server-action.mjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* HFS checks 1 and 2 (knowledge/hfs/slots.yaml `tiers`):
|
|
3
5
|
* 1. the tier direction matrix: every import, re-export and type-only import between two owners must go from a tier to
|
|
4
6
|
* a tier its `mayImport` lists (BE_TIER_DIRECTION / FE_TIER_DIRECTION); a backend feature importing another feature
|
|
5
|
-
* is the one direction with its own code (BE_FEATURE_IMPORTS_FEATURE, R28), never BE_TIER_DIRECTION,
|
|
7
|
+
* is the one direction with its own code (BE_FEATURE_IMPORTS_FEATURE, R28), never BE_TIER_DIRECTION, and a feature of one trigger
|
|
8
|
+
* kind (slot field `trigger`: api, webhooks, realtime, saga, reactors, jobs, cli) importing a feature of another is
|
|
9
|
+
* BE_KIND_ISOLATION, whose fix is the event bus,
|
|
6
10
|
* an app never imports another app (FE_APP_ISOLATION), and a component layer imports only the layers after it;
|
|
7
11
|
* 2. owner cycles: a strongly connected component of the owner graph, type-only imports included (ARCH_OWNER_CYCLE),
|
|
8
12
|
* reported with the cycle path and the import that closes each hop.
|
|
9
13
|
* Importing inside one owner is always allowed; the public-entry rule stays with owners.mjs (ARCH_OWNER_EXPORT_BYPASS).
|
|
10
14
|
*/
|
|
11
|
-
export const TIER_RULE_IDS = ['BE_TIER_DIRECTION', 'BE_FEATURE_IMPORTS_FEATURE', 'FE_TIER_DIRECTION', 'FE_APP_ISOLATION', 'ARCH_OWNER_CYCLE'];
|
|
15
|
+
export const TIER_RULE_IDS = ['BE_TIER_DIRECTION', 'BE_FEATURE_IMPORTS_FEATURE', 'BE_KIND_ISOLATION', 'FE_TIER_DIRECTION', 'FE_APP_ISOLATION', 'ARCH_OWNER_CYCLE'];
|
|
12
16
|
|
|
13
17
|
const REASON_TEXT = {
|
|
14
18
|
tierDirection: ({ fromTier, toTier, mayImport }) => `a ${fromTier} may import only ${mayImport.join(', ') || 'nothing'}; it imports a ${toTier}`,
|
|
@@ -70,6 +74,27 @@ function cycleThrough(adjacency, members, origin) {
|
|
|
70
74
|
return [origin, origin];
|
|
71
75
|
}
|
|
72
76
|
|
|
77
|
+
/** The trigger kind (slot field `trigger`) of the owner that holds `file`, or null when its owner's slot names none. */
|
|
78
|
+
const triggerOf = (resolver, file) => {
|
|
79
|
+
const owner = resolver.ownerOf(file);
|
|
80
|
+
return owner ? (resolver.slot(owner.slot)?.trigger ?? null) : null;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** The db Server Action an edge targets, or null. */
|
|
84
|
+
const serverActionTarget = (graph, edge) => {
|
|
85
|
+
if (graph.profile !== 'fe') return null;
|
|
86
|
+
const to = graph.resolver.classifyPath(edge.to);
|
|
87
|
+
return to.slot === 'fe.modules.db' && /^write-[^/]+\.ts$/u.test(edge.to.split('/').at(-1))
|
|
88
|
+
&& isServerActionModule(null, graph.files.get(edge.to).sourceFile) ? to : null;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** A connected block may call a db writer directly when that writer is a file-level Next Server Action. */
|
|
92
|
+
const blockCallsServerAction = (graph, edge) => {
|
|
93
|
+
if (!serverActionTarget(graph, edge)) return false;
|
|
94
|
+
const from = graph.resolver.classifyPath(edge.from);
|
|
95
|
+
return from.slot === 'fe.components' && from.kind === 'blocks' && from.role === 'entry';
|
|
96
|
+
};
|
|
97
|
+
|
|
73
98
|
export function checkTiers(graph) {
|
|
74
99
|
const { resolver, profile } = graph;
|
|
75
100
|
const violations = [];
|
|
@@ -81,15 +106,32 @@ export function checkTiers(graph) {
|
|
|
81
106
|
const verdict = resolver.importAllowed(edge.from, edge.to);
|
|
82
107
|
if (verdict.reason === 'unowned' || verdict.reason?.startsWith('slot')) { unclassified += 1; continue; }
|
|
83
108
|
edgesChecked += 1;
|
|
84
|
-
|
|
109
|
+
const actionTarget = serverActionTarget(graph, edge);
|
|
110
|
+
if ((verdict.allowed || verdict.reason === 'notPublicEntry') && actionTarget && graph.unit(edge.from) !== graph.unit(edge.to) && !blockCallsServerAction(graph, edge)) {
|
|
111
|
+
counts.tierDirection += 1;
|
|
112
|
+
violations.push({
|
|
113
|
+
ruleId: tierRule,
|
|
114
|
+
path: edge.from, line: edge.line, column: edge.column,
|
|
115
|
+
specifier: edge.specifier, resolvedPath: edge.to, typeOnly: !edge.runtime,
|
|
116
|
+
fromTier: resolver.tierOf(edge.from), toTier: resolver.tierOf(edge.to),
|
|
117
|
+
message: `${edge.from} -> ${edge.to}: a db Server Action is called directly only by a connected block entry; hooks and other tiers use their declared data path${edge.runtime ? '' : ' (type-only imports count)'}.`,
|
|
118
|
+
});
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (verdict.allowed || (verdict.reason === 'tierDirection' && blockCallsServerAction(graph, edge)) || !REASON_TEXT[verdict.reason]) continue;
|
|
85
122
|
counts[verdict.reason] += 1;
|
|
86
123
|
const featureToFeature = profile === 'be' && verdict.reason === 'tierDirection' && verdict.fromTier === 'feature' && verdict.toTier === 'feature';
|
|
124
|
+
const fromKind = featureToFeature ? triggerOf(resolver, edge.from) : null;
|
|
125
|
+
const toKind = featureToFeature ? triggerOf(resolver, edge.to) : null;
|
|
126
|
+
const crossKind = fromKind !== null && toKind !== null && fromKind !== toKind;
|
|
87
127
|
violations.push({
|
|
88
|
-
ruleId: verdict.reason === 'crossApp' ? 'FE_APP_ISOLATION' : featureToFeature ? 'BE_FEATURE_IMPORTS_FEATURE' : tierRule,
|
|
128
|
+
ruleId: verdict.reason === 'crossApp' ? 'FE_APP_ISOLATION' : crossKind ? 'BE_KIND_ISOLATION' : featureToFeature ? 'BE_FEATURE_IMPORTS_FEATURE' : tierRule,
|
|
89
129
|
path: edge.from, line: edge.line, column: edge.column,
|
|
90
130
|
specifier: edge.specifier, resolvedPath: edge.to, typeOnly: !edge.runtime,
|
|
91
131
|
fromTier: verdict.fromTier ?? null, toTier: verdict.toTier ?? null,
|
|
92
|
-
message:
|
|
132
|
+
message: crossKind
|
|
133
|
+
? `${edge.from} -> ${edge.to}: a ${fromKind} feature imports a ${toKind} feature; no kind imports another, every cross-kind call is an event published with eventBus.publish(event, tx) from a domain service${edge.runtime ? '' : ' (type-only imports count)'}.`
|
|
134
|
+
: `${edge.from} -> ${edge.to}: ${REASON_TEXT[verdict.reason](verdict)}${edge.runtime ? '' : ' (type-only imports count)'}.`,
|
|
93
135
|
});
|
|
94
136
|
}
|
|
95
137
|
|
|
@@ -6,7 +6,8 @@ import { machineKit } from './machine-ast.mjs';
|
|
|
6
6
|
* `client-fetch-has-signal`. ESLint judges one file at a time by the spelling of a call; the machine judges the repository by
|
|
7
7
|
* what the checker resolves. A repository has exactly ONE transport client and ONE Outcome union, both named by slot (never
|
|
8
8
|
* by a path spelled here): the api package's (`fe.package.api.client`, `fe.package.api.outcome`) when the repository shares
|
|
9
|
-
* it, or the only app's (`fe.transport.client`, `fe.transport.outcome`) when the repository declares exactly one app.
|
|
9
|
+
* it, or the only app's (`fe.transport.client`, `fe.transport.outcome`) when the repository declares exactly one app. The
|
|
10
|
+
* Outcome homes are the slots the manifest marks `outcomeHome` (the lite edition adds `fe.modules.db.outcome`), not a list kept here.
|
|
10
11
|
*
|
|
11
12
|
* - two or more clients, or two or more Outcome unions, in the repository (two apps each keeping one, or a package one plus
|
|
12
13
|
* an app one) are findings on every copy;
|
|
@@ -30,7 +31,6 @@ const APP_CLIENT_SLOT = 'fe.transport.client';
|
|
|
30
31
|
const APP_OUTCOME_SLOT = 'fe.transport.outcome';
|
|
31
32
|
const PACKAGE_API_SLOT = 'fe.package.api';
|
|
32
33
|
const CLIENT_SLOTS = new Set([APP_CLIENT_SLOT, 'fe.package.api.client']);
|
|
33
|
-
const OUTCOME_SLOTS = new Set([APP_OUTCOME_SLOT, 'fe.package.api.outcome']);
|
|
34
34
|
const NO_CLIENT = "the repository has no transport client. Create the one client (packages/<family>-api/src/client.ts, or the only app's modules/api/client.ts) and call it.";
|
|
35
35
|
|
|
36
36
|
export function checkTransportOwner(input) {
|
|
@@ -60,7 +60,7 @@ export function checkTransportOwner(input) {
|
|
|
60
60
|
|
|
61
61
|
const files = [...graph.files.values()].filter(file => file.slot && file.tier !== 'e2e');
|
|
62
62
|
const clients = files.filter(file => CLIENT_SLOTS.has(file.slot));
|
|
63
|
-
const outcomes = files.filter(file =>
|
|
63
|
+
const outcomes = files.filter(file => resolver.slot(file.slot)?.outcomeHome === true);
|
|
64
64
|
const clientRels = new Set(clients.map(file => file.rel));
|
|
65
65
|
const list = items => items.map(item => item.rel).join(', ');
|
|
66
66
|
const owned = clients.length ? `the repository has one transport (${list(clients)}). Call the client and take its Outcome.` : NO_CLIENT;
|
|
@@ -2,31 +2,23 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { canonical, isInside, slash } from './config.mjs';
|
|
5
|
+
import { crossesSide } from './side-boundary.mjs';
|
|
5
6
|
import { sameOrUnder } from '../../lib/path-key.mjs';
|
|
6
7
|
import { createTypeScriptProgram, readTypeScriptProject, resolveTypeScriptModule, sharedInProgramRun, typeScriptProjectReferencePath } from '../typescript-programs.mjs';
|
|
7
8
|
import { readJsonFile } from '../../lib/json.mjs';
|
|
8
|
-
import {
|
|
9
|
+
import { sourceLocation } from '../../lib/ts-ast.mjs';
|
|
10
|
+
import { locateDeclaration } from '../slots.mjs';
|
|
9
11
|
|
|
10
12
|
const CODE_EXTENSIONS = /\.(?:[cm]?[jt]sx?)$/i;
|
|
11
13
|
const TEST_FILE = /(?:^|[.-])(?:spec|test)\.[cm]?[jt]sx?$/i;
|
|
12
14
|
const ASSET_EXTENSION = /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|avif|ico|woff2?|ttf|eot|ya?ml|json)$/i;
|
|
13
15
|
// Framework build output a tsconfig may include (Next writes `.next/types/**/*.ts` back into tsconfig.json on
|
|
14
16
|
// every build) is compiled for type resolution but is never source: it is gitignored, regenerated, and no
|
|
15
|
-
// canon or architecture rule applies to it (
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
// canon or architecture rule applies to it (inc-ffe60c49f502).
|
|
18
|
+
const GENERATED_SEGMENTS = new Set(['.next', '.turbo', '.vercel', '.output', '.nuxt', '.svelte-kit', '.expo', '.docusaurus', '.swc', '.cache']);
|
|
19
|
+
function isGeneratedPath(root, fileName) {
|
|
18
20
|
return slash(path.relative(root, fileName)).split('/').slice(0, -1).some(segment => GENERATED_SEGMENTS.has(segment));
|
|
19
21
|
}
|
|
20
|
-
// A `<tool>.config.*` or `<tool>.setup.*` module at the root of a project (beside a package manifest or a tsconfig.json:
|
|
21
|
-
// next.config.ts and postcss.config.mjs of an app, which has no package.json of its own) is build tooling a broad `**/*.ts`
|
|
22
|
-
// include pulls in; a `*.config.ts` inside a source tree (src/config/database.config.ts) has neither beside it and stays source.
|
|
23
|
-
// The architecture program still reads tooling modules (a profile may declare one as source); the lint (hfs lint) judges one only
|
|
24
|
-
// through the repository's own eslint.config.
|
|
25
|
-
const TOOLING_MODULE = /^[^/]+\.(?:config|setup)\.[cm]?[jt]sx?$/i;
|
|
26
|
-
export function isToolingModule(fileName) {
|
|
27
|
-
return TOOLING_MODULE.test(path.basename(fileName)) && ['package.json', 'tsconfig.json'].some((manifest) => fs.existsSync(path.join(path.dirname(fileName), manifest)));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
22
|
function diagnosticMessage(ts, diagnostic) {
|
|
31
23
|
return ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
|
32
24
|
}
|
|
@@ -53,7 +45,7 @@ function compilerError(ts, root, diagnostic, project, ruleId = 'ARCH_TSCONFIG_IN
|
|
|
53
45
|
* Load TypeScript through the target package boundary, never through StarCi's own dependency graph. A side folder of an app has no
|
|
54
46
|
* package.json of its own: the app root's one manifest is the boundary its TypeScript is installed under.
|
|
55
47
|
*/
|
|
56
|
-
|
|
48
|
+
function loadTargetTypeScript(repositoryRoot) {
|
|
57
49
|
const packageFile = path.join(locateDeclaration(repositoryRoot).appRoot, 'package.json');
|
|
58
50
|
if (!fs.existsSync(packageFile)) throw Error('ARCH_TYPESCRIPT_MISSING: target package.json is required to resolve target-installed TypeScript.');
|
|
59
51
|
const targetRequire = createRequire(packageFile);
|
|
@@ -98,7 +90,7 @@ function runtimeImport(ts, node) {
|
|
|
98
90
|
return true;
|
|
99
91
|
}
|
|
100
92
|
|
|
101
|
-
function isUnshadowedCommonJsRequire(ts, checker, expression) {
|
|
93
|
+
export function isUnshadowedCommonJsRequire(ts, checker, expression) {
|
|
102
94
|
if (!ts.isIdentifier(expression) || expression.text !== 'require') return false;
|
|
103
95
|
const symbol = checker?.getSymbolAtLocation(expression);
|
|
104
96
|
if (!symbol) return true;
|
|
@@ -113,7 +105,7 @@ function isUnshadowedCommonJsRequire(ts, checker, expression) {
|
|
|
113
105
|
* existing directory and a data-asset extension tail qualify; code never does, since a context of code would
|
|
114
106
|
* be an import graph nobody wrote down. Returns the specifiers, or null when the import stays unproven.
|
|
115
107
|
*/
|
|
116
|
-
|
|
108
|
+
function assetContextSpecifiers(ts, sourceFile, argument) {
|
|
117
109
|
if (!argument || !ts.isTemplateExpression(argument)) return null;
|
|
118
110
|
const head = argument.head.text;
|
|
119
111
|
const spans = argument.templateSpans;
|
|
@@ -168,11 +160,6 @@ function moduleReferences(ts, sourceFile, checker) {
|
|
|
168
160
|
return { found, unproven };
|
|
169
161
|
}
|
|
170
162
|
|
|
171
|
-
function sourceLocation(sourceFile, node) {
|
|
172
|
-
const point = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
173
|
-
return { line: point.line + 1, column: point.character + 1 };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
163
|
function isProductionSource(root, sourceFile) {
|
|
177
164
|
return isInside(root, sourceFile.fileName)
|
|
178
165
|
&& CODE_EXTENSIONS.test(sourceFile.fileName)
|
|
@@ -210,7 +197,7 @@ function exportPatternCapture(pattern, request) {
|
|
|
210
197
|
return request.startsWith(before) && request.endsWith(after) ? request.slice(before.length, request.length - after.length) : null;
|
|
211
198
|
}
|
|
212
199
|
|
|
213
|
-
function exportTargetStrings(value) {
|
|
200
|
+
export function exportTargetStrings(value) {
|
|
214
201
|
if (typeof value === 'string') return [value];
|
|
215
202
|
if (Array.isArray(value)) return value.flatMap(exportTargetStrings);
|
|
216
203
|
if (value && typeof value === 'object' && !Object.keys(value).some(key => key.startsWith('.'))) return Object.values(value).flatMap(exportTargetStrings);
|
|
@@ -497,9 +484,7 @@ function typeScriptContext(config, loaded, paths) {
|
|
|
497
484
|
|| (config.repository && isInside(config.repository, actualTarget) && !slash(actualTarget).includes('/node_modules/'));
|
|
498
485
|
// A side of an app (config.root is be/ or fe/) imports nothing of the app outside itself: the root holds no source, the other
|
|
499
486
|
// side is another program, and a declared read (sides.fe.reads, be/contracts/) is codegen input, never an import.
|
|
500
|
-
|
|
501
|
-
&& isInside(config.packageRoot, actualTarget) && !isInside(config.root, actualTarget) && !slash(actualTarget).includes('/node_modules/');
|
|
502
|
-
if (internal && crossesSide) {
|
|
487
|
+
if (internal && crossesSide(config, actualTarget)) {
|
|
503
488
|
errors.push({
|
|
504
489
|
ruleId: 'ARCH_INTERNAL_IMPORT_OUTSIDE',
|
|
505
490
|
project: project.relative,
|
|
@@ -581,6 +566,8 @@ export function unwrapExpression(ts, expression) {
|
|
|
581
566
|
return expression;
|
|
582
567
|
}
|
|
583
568
|
|
|
569
|
+
/* ---- the AST walks every architecture checker shares ---- */
|
|
570
|
+
|
|
584
571
|
/** The names of `expected` an import or re-export statement binds (all of them for a namespace or star form). */
|
|
585
572
|
export function referencedExports(ts, statement, expected) {
|
|
586
573
|
if (ts.isImportDeclaration(statement)) {
|
|
@@ -595,4 +582,3 @@ export function referencedExports(ts, statement, expected) {
|
|
|
595
582
|
return [...expected];
|
|
596
583
|
}
|
|
597
584
|
|
|
598
|
-
export { isUnshadowedCommonJsRequire, sourceLocation };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// declaration-shape.mjs - the dependency-free hfs.json shape validation used by the HFS slot loader. Semantic checks
|
|
2
|
+
// against a loaded manifest remain in slots.mjs; this module mirrors modules/schemas/hfs-repo.schema.yaml only.
|
|
3
|
+
import { isPlainObject } from '../../engine/plain-object.mjs';
|
|
4
|
+
import { APP_KIND, connectionShapeProblems, NAME, RUNTIME_KIND, SLOT_ID } from './manifest-shape.mjs';
|
|
5
|
+
import { kindShapeProblems, patternShapeProblems } from './declaration-slots.mjs';
|
|
6
|
+
|
|
7
|
+
/** Shape problems of the optional hfs.json `supabase` block whose auth posture DB_CONFIG_POLICY checks. */
|
|
8
|
+
function supabaseBlockProblems(block) {
|
|
9
|
+
if (block === undefined) return [];
|
|
10
|
+
if (!isPlainObject(block)) return ['supabase must be an object'];
|
|
11
|
+
const bad = [];
|
|
12
|
+
for (const key of Object.keys(block)) if (!['enableSignup', 'jwtExpiry', 'siteUrl', 'redirectUrls', 'forceRls'].includes(key)) bad.push(`supabase has unknown key ${key}`);
|
|
13
|
+
if (block.enableSignup !== undefined && typeof block.enableSignup !== 'boolean') bad.push('supabase.enableSignup must be true or false');
|
|
14
|
+
if (block.jwtExpiry !== undefined && !(Number.isInteger(block.jwtExpiry) && block.jwtExpiry > 0 && block.jwtExpiry <= 3600)) bad.push('supabase.jwtExpiry must be an integer of seconds, 3600 at most');
|
|
15
|
+
if (block.siteUrl !== undefined && (typeof block.siteUrl !== 'string' || !block.siteUrl.trim())) bad.push('supabase.siteUrl must be a URL string');
|
|
16
|
+
for (const key of ['redirectUrls', 'forceRls']) if (block[key] !== undefined && !(Array.isArray(block[key]) && block[key].every((value) => typeof value === 'string' && value.trim()))) bad.push(`supabase.${key} must be a list of strings`);
|
|
17
|
+
return bad;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Shape problems of a parsed hfs.json, in the words of modules/schemas/hfs-repo.schema.yaml. */
|
|
21
|
+
export function declarationShapeProblems(declaration, profiles) {
|
|
22
|
+
const bad = [];
|
|
23
|
+
if (!isPlainObject(declaration)) return ['hfs.json is not an object'];
|
|
24
|
+
if (!(Number.isInteger(declaration.hfs) && declaration.hfs >= 1)) bad.push('hfs must be the pinned manifest major (an integer, 1 or more)');
|
|
25
|
+
if (!NAME.test(String(declaration.project))) bad.push('project must be a project name');
|
|
26
|
+
if (declaration.kind === RUNTIME_KIND) {
|
|
27
|
+
for (const key of Object.keys(declaration)) if (!['hfs', 'kind', 'project'].includes(key)) bad.push(`unknown key ${key} (a runtime declaration is {hfs, kind, project})`);
|
|
28
|
+
return bad;
|
|
29
|
+
}
|
|
30
|
+
for (const key of Object.keys(declaration)) if (!['hfs', 'kind', 'project', 'edition', 'supabase', 'sides', 'browser'].includes(key)) bad.push(`unknown key ${key}`);
|
|
31
|
+
bad.push(...supabaseBlockProblems(declaration.supabase));
|
|
32
|
+
if (declaration.browser !== undefined && declaration.browser !== true) bad.push('browser is `true` when the app has a browser journey (slot app.browser), and is left out otherwise');
|
|
33
|
+
if (declaration.kind !== APP_KIND) bad.push(`kind must be ${APP_KIND} (a product is one app repository with a be and an fe side) or ${RUNTIME_KIND} (the StarCi runtime repository)`);
|
|
34
|
+
if (!isPlainObject(declaration.sides) || Object.keys(declaration.sides).sort().join() !== profiles.join()) { bad.push('sides must declare exactly be and fe'); return bad; }
|
|
35
|
+
const names = new Map();
|
|
36
|
+
for (const side of profiles) {
|
|
37
|
+
const value = declaration.sides[side];
|
|
38
|
+
const at = `sides.${side}`;
|
|
39
|
+
if (!isPlainObject(value)) { bad.push(`${at} must be an object`); continue; }
|
|
40
|
+
for (const key of Object.keys(value)) if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads'].includes(key)) bad.push(`${at} has unknown key ${key}`);
|
|
41
|
+
if (!Array.isArray(value.apps) || !value.apps.length) bad.push(`${at}.apps must list every ${side}/apps/<name> with its kind`);
|
|
42
|
+
else value.apps.forEach((app, index) => {
|
|
43
|
+
if (!isPlainObject(app) || !NAME.test(String(app.name)) || !NAME.test(String(app.kind)) || Object.keys(app).some((key) => key !== 'name' && key !== 'kind')) bad.push(`${at}.apps[${index}] must be {name, kind}`);
|
|
44
|
+
else if (names.has(app.name)) bad.push(`app ${app.name} is declared twice (${names.get(app.name)} and ${side})`);
|
|
45
|
+
else names.set(app.name, side);
|
|
46
|
+
});
|
|
47
|
+
if (value.optionalSlots !== undefined && (!Array.isArray(value.optionalSlots) || !value.optionalSlots.every((slot) => SLOT_ID.test(String(slot))) || new Set(value.optionalSlots).size !== value.optionalSlots.length)) bad.push(`${at}.optionalSlots must be a unique list of slot ids`);
|
|
48
|
+
bad.push(...patternShapeProblems(value, at, NAME), ...kindShapeProblems(value, at, NAME));
|
|
49
|
+
if (value.reads !== undefined && (!Array.isArray(value.reads) || !value.reads.every((read) => typeof read === 'string' && read.length > 0) || new Set(value.reads).size !== value.reads.length)) bad.push(`${at}.reads must be a unique list of paths`);
|
|
50
|
+
if (value.connections !== undefined) {
|
|
51
|
+
if (side !== 'be') { bad.push('connections belong to the be side'); continue; }
|
|
52
|
+
const list = Array.isArray(value.connections) ? value.connections : null;
|
|
53
|
+
const shape = connectionShapeProblems(list, value.apps);
|
|
54
|
+
if (shape.length) bad.push(...shape);
|
|
55
|
+
else {
|
|
56
|
+
if (new Set(list.map((connection) => connection.name)).size !== list.length) bad.push('connections names must be unique');
|
|
57
|
+
for (const a of list) for (const b of list) if (a !== b && `${b.envPrefix}_`.startsWith(`${a.envPrefix}_`)) bad.push(`connections ${a.name} and ${b.name} share env keys (${a.envPrefix}_ covers ${b.envPrefix}_)`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return bad;
|
|
62
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// declaration-slots.mjs - how an app declaration (hfs.json) switches on the opt-in slots of a side: by name (`optionalSlots`), by app kind
|
|
2
|
+
// (a slot with `appKind`) and by declared pattern (a slot with `pattern: <name>` is enabled by `sides.<side>.patterns: [<name>]`, one
|
|
3
|
+
// mechanism for every pattern: saga, event-bus, fenced-job, ...). slots.mjs asks this file to judge a side's lists and to say whether a
|
|
4
|
+
// slot is enabled for a repository.
|
|
5
|
+
|
|
6
|
+
/** The problems of a side's `optionalSlots` and `patterns` against the manifest. */
|
|
7
|
+
export function optionalSlotProblems(manifest, side, s) {
|
|
8
|
+
const bad = [];
|
|
9
|
+
for (const id of s.optionalSlots ?? []) {
|
|
10
|
+
const slot = manifest.slots.find((candidate) => candidate.id === id);
|
|
11
|
+
if (!slot || !slot.profiles.includes(side)) bad.push(`sides.${side}.optionalSlots names ${id}, which is not a ${side} slot`);
|
|
12
|
+
else if (slot.presence !== 'opt-in') bad.push(`sides.${side}.optionalSlots names ${id}, which is ${slot.presence}, not opt-in`);
|
|
13
|
+
else if (slot.appKind !== undefined) bad.push(`sides.${side}.optionalSlots names ${id}; an app of kind ${slot.appKind} enables it`);
|
|
14
|
+
}
|
|
15
|
+
for (const name of s.patterns ?? []) {
|
|
16
|
+
if (!manifest.slots.some((slot) => slot.profiles.includes(side) && slot.pattern === name)) bad.push(`sides.${side}.patterns names ${name}, which no ${side} slot declares as its pattern`);
|
|
17
|
+
}
|
|
18
|
+
if (s.kinds !== undefined && side !== 'be') bad.push(`sides.${side}.kinds belongs to the be side`);
|
|
19
|
+
for (const kind of s.kinds ?? []) {
|
|
20
|
+
if (!(manifest.triggerKinds ?? []).includes(kind)) bad.push(`sides.${side}.kinds names ${kind}, which is not one of triggerKinds (${(manifest.triggerKinds ?? []).join(', ')})`);
|
|
21
|
+
}
|
|
22
|
+
return bad;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The problems of the shape of a side's `patterns` list (a unique list of pattern names). */
|
|
26
|
+
export function patternShapeProblems(s, at, namePattern) {
|
|
27
|
+
const list = s.patterns;
|
|
28
|
+
if (list === undefined) return [];
|
|
29
|
+
return Array.isArray(list) && list.every((value) => namePattern.test(String(value))) && new Set(list).size === list.length ? [] : [`${at}.patterns must be a unique list of pattern names`];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The problems of the shape of a side's `kinds` list (a unique list of trigger kind names). */
|
|
33
|
+
export function kindShapeProblems(s, at, namePattern) {
|
|
34
|
+
const list = s.kinds;
|
|
35
|
+
if (list === undefined) return [];
|
|
36
|
+
return Array.isArray(list) && list.every((value) => namePattern.test(String(value))) && new Set(list).size === list.length ? [] : [`${at}.kinds must be a unique list of trigger kind names`];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The problems of `ruleParams.be.kindPatterns` (trigger kind -> patterns) and `ruleParams.be.addKinds` (starci app add noun -> {topic, variable, patterns, trigger?, needs?, also?, defaults?, wire?}). */
|
|
40
|
+
export function kindParamProblems(be, triggerKinds) {
|
|
41
|
+
const kebab = /^[a-z][a-z0-9-]*$/;
|
|
42
|
+
const names = (list) => Array.isArray(list) && list.every((value) => kebab.test(String(value))) && new Set(list).size === list.length;
|
|
43
|
+
const bad = [];
|
|
44
|
+
const patterns = be.kindPatterns;
|
|
45
|
+
if (patterns === null || typeof patterns !== 'object' || Array.isArray(patterns) || !Object.entries(patterns).every(([kind, list]) => (triggerKinds ?? []).includes(kind) && names(list))) bad.push('ruleParams.be.kindPatterns must map a trigger kind to a unique list of pattern names');
|
|
46
|
+
const nouns = be.addKinds;
|
|
47
|
+
const nounOk = (spec) => spec !== null && typeof spec === 'object' && kebab.test(String(spec.topic)) && kebab.test(String(spec.variable)) && names(spec.patterns) && (spec.trigger === undefined || kebab.test(String(spec.trigger))) && (spec.needs === undefined || names(spec.needs)) && (spec.also === undefined || names(spec.also)) && (spec.defaults === undefined || (typeof spec.defaults === 'object' && !Array.isArray(spec.defaults))) && (spec.wire === undefined || (spec.wire !== null && typeof spec.wire === 'object' && ['file', 'import', 'symbol'].every((key) => typeof spec.wire[key] === 'string' && spec.wire[key] !== '')));
|
|
48
|
+
if (nouns === null || typeof nouns !== 'object' || Array.isArray(nouns) || !Object.entries(nouns).every(([noun, spec]) => kebab.test(noun) && nounOk(spec))) bad.push('ruleParams.be.addKinds must map a noun to {topic, variable, patterns, trigger?, needs?, also?, defaults?}');
|
|
49
|
+
return bad;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The problems of `ruleParams.be.patternScenarios`: a pattern name to a non-empty list of unique kebab-case scenario ids. */
|
|
53
|
+
export function scenarioProblem(scenarios) {
|
|
54
|
+
const kebab = /^[a-z][a-z0-9-]*$/;
|
|
55
|
+
const ok = scenarios !== null && typeof scenarios === 'object' && !Array.isArray(scenarios) && Object.entries(scenarios).every(([name, list]) => kebab.test(name) && Array.isArray(list) && list.length > 0 && list.every((id) => kebab.test(String(id))) && new Set(list).size === list.length);
|
|
56
|
+
return ok ? [] : ['ruleParams.be.patternScenarios must map a pattern name to a non-empty list of unique kebab-case scenario ids'];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The problems of the `trigger` of a slot against the manifest's `triggerKinds`: a known kind, on a feature-tier slot only. */
|
|
60
|
+
export function triggerProblems(slot, triggerKinds) {
|
|
61
|
+
if (slot.trigger === undefined) return [];
|
|
62
|
+
const bad = [];
|
|
63
|
+
if (!(triggerKinds ?? []).includes(slot.trigger)) bad.push(`slot ${slot.id}: trigger ${slot.trigger} is not one of triggerKinds`);
|
|
64
|
+
if (slot.tier !== 'feature') bad.push(`slot ${slot.id}: a trigger belongs to a feature-tier slot`);
|
|
65
|
+
return bad;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Whether an opt-in slot is enabled for the repository: by its app kind, by a connection's provider, by name in optionalSlots, or by its declared pattern. */
|
|
69
|
+
export function declaredSlotEnabled(slot, repo) {
|
|
70
|
+
if (slot.appKind !== undefined) return repo.apps.some((app) => app.kind === slot.appKind);
|
|
71
|
+
// A provider declared on any connection (be owns them all today) enables the provider slots of every profile: repo.providers
|
|
72
|
+
// is the app-wide union the declaration resolver computed; a hand-built repo falls back to its own connections.
|
|
73
|
+
if (slot.provider !== undefined) return (repo.providers ?? (repo.connections ?? []).map((connection) => connection.provider)).includes(slot.provider);
|
|
74
|
+
return repo.optionalSlots.includes(slot.id) || (slot.pattern !== undefined && (repo.patterns ?? []).includes(slot.pattern));
|
|
75
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// edition.mjs - the one edition filter shared by the HFS slot resolver, declaration validation, rule catalog and
|
|
2
|
+
// edition-specific rule parameters. Full is the default; lite changes data views, never the checks that consume them.
|
|
3
|
+
import { isPlainObject } from '../../engine/plain-object.mjs';
|
|
4
|
+
import { EDITIONS } from './manifest-shape.mjs';
|
|
5
|
+
|
|
6
|
+
/** The presence of `slot` under edition lite for `profile`: `litePresence`, else the slot's own presence. */
|
|
7
|
+
export function litePresenceOf(slot, profile) {
|
|
8
|
+
const lp = slot.litePresence;
|
|
9
|
+
if (lp === undefined) return slot.presence;
|
|
10
|
+
return isPlainObject(lp) ? (lp[profile] ?? slot.presence) : lp;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Whether `slot` exists under `edition` of `manifest` (default: the manifest's own editions). */
|
|
14
|
+
export function slotInEdition(manifest, slot, edition) {
|
|
15
|
+
return (slot.editions ?? manifest.editions ?? EDITIONS).includes(edition);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The slot as `edition` sees it: lite overlays its data, presence and tracking while forbidding every test world. */
|
|
19
|
+
export function effectiveSlot(slot, profile, edition) {
|
|
20
|
+
if (edition !== 'lite') return slot;
|
|
21
|
+
const { lite, litePresence, ...base } = slot;
|
|
22
|
+
const presence = litePresenceOf(slot, profile);
|
|
23
|
+
const tracked = presence === 'forbidden' ? 'external' : (slot.tracked === 'external' ? 'tracked' : slot.tracked);
|
|
24
|
+
return { ...base, ...(lite ?? {}), presence, tracked, tests: 'none' };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The template group starci app sync renders `slot` from under `edition`: `liteManagedBy` (else `managedBy`) in lite, `managedBy` otherwise; undefined when unmanaged. */
|
|
28
|
+
export function managedGroupOf(slot, edition) {
|
|
29
|
+
return edition === 'lite' ? (slot.liteManagedBy ?? slot.managedBy) : slot.managedBy;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The declared edition and the vocabulary against which it is validated. */
|
|
33
|
+
export function declarationEdition(manifest, declaration) {
|
|
34
|
+
const edition = declaration.edition === undefined ? 'full' : declaration.edition;
|
|
35
|
+
const known = manifest.editions ?? EDITIONS;
|
|
36
|
+
return { edition, known, valid: known.includes(edition) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Problems of an optional rule-catalog `editions` list, in the catalog schema's words. */
|
|
40
|
+
export function ruleEditionProblems(rule, label) {
|
|
41
|
+
if (rule.editions === undefined) return [];
|
|
42
|
+
const bad = [];
|
|
43
|
+
if (!Array.isArray(rule.editions) || !rule.editions.length) return [`${label}.editions must be a non-empty list`];
|
|
44
|
+
for (const value of rule.editions) if (!EDITIONS.includes(value)) bad.push(`${label}.editions has ${JSON.stringify(value)}, not one of ${EDITIONS.join(', ')}`);
|
|
45
|
+
if (new Set(rule.editions).size !== rule.editions.length) bad.push(`${label}.editions repeats a value`);
|
|
46
|
+
return bad;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Whether a catalogued rule owner judges its finding under `edition`; uncatalogued codes always remain judged. */
|
|
50
|
+
export function judgedInEdition(owner, edition = 'full') {
|
|
51
|
+
return !owner?.editions || owner.editions.includes(edition);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Whether the enforcer `kind:id` of the catalog `rules` runs under `edition`: every rule listing it is judged there, and the enforcer row's own `editions` (a rule with several enforcers where only one is full-only) agrees. A lint rule no rule lists runs everywhere. */
|
|
55
|
+
export function enforcerJudgedInEdition(rules, kind, id, edition = 'full') {
|
|
56
|
+
const owners = rules.filter((rule) => rule.enforcers.some((enforcer) => enforcer.kind === kind && enforcer.id === id));
|
|
57
|
+
return owners.every((rule) => judgedInEdition(rule, edition) && rule.enforcers.filter((enforcer) => enforcer.kind === kind && enforcer.id === id).every((enforcer) => judgedInEdition(enforcer, edition)));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A frozen copy of one profile's parameters, with its lite overrides applied only in the lite edition. */
|
|
61
|
+
export function editionRuleParams(params, edition) {
|
|
62
|
+
const { lite, ...base } = params;
|
|
63
|
+
const merged = edition === 'lite' && lite ? { ...base, ...lite } : base;
|
|
64
|
+
const deepFreeze = (value) => { if (value && typeof value === 'object') Object.values(value).forEach(deepFreeze); return Object.freeze(value); };
|
|
65
|
+
return deepFreeze(structuredClone(merged));
|
|
66
|
+
}
|