@starci/eslint-grammar-offset-pop 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +6 -5
- package/runtime/bundle.json +2 -51
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
// slot-semantic-problems.mjs - semantic checks for the HFS slot manifest.
|
|
2
|
-
import { isPlainObject } from '../../engine/plain-object.mjs';
|
|
3
|
-
import { triggerProblems } from './declaration-slots.mjs';
|
|
4
|
-
import { litePresenceOf, slotInEdition } from './edition-slots.mjs';
|
|
5
|
-
import { manifestKind, RUNTIME_KIND, runtimeSemanticProblems, tierKindProblems } from './manifest-shape.mjs';
|
|
6
|
-
import { APP_SCOPE, isSide, PROFILES } from './slot-manifest-shape.mjs';
|
|
7
|
-
function checkAppRootSlot(slot, bad) {
|
|
8
|
-
for (const key of ['appKind', 'owner', 'layers', 'kinds', 'composedBy', 'requiredWhen', 'requiredInstances']) {
|
|
9
|
-
if (slot[key] !== undefined)
|
|
10
|
-
bad.push(`slot ${slot.id}: an app-root slot has no ${key}`);
|
|
11
|
-
}
|
|
12
|
-
if (slot.tier !== 'none')
|
|
13
|
-
bad.push(`slot ${slot.id}: an app-root slot has tier none`);
|
|
14
|
-
}
|
|
15
|
-
function checkSideSlot(slot, profile, manifest, bad) {
|
|
16
|
-
const tiers = manifest.tiers[profile];
|
|
17
|
-
if (slot.tier !== 'none' && slot.tier !== 'inherit' && !(slot.tier in tiers))
|
|
18
|
-
bad.push(`slot ${slot.id}: tier ${slot.tier} is not a ${profile} tier`);
|
|
19
|
-
if (slot.appKind !== undefined && !manifest.appKinds[profile].includes(slot.appKind))
|
|
20
|
-
bad.push(`slot ${slot.id}: app kind ${slot.appKind} is not a ${profile} kind`);
|
|
21
|
-
bad.push(...triggerProblems(slot, manifest.triggerKinds));
|
|
22
|
-
}
|
|
23
|
-
function claimSlotPatterns(slot, profile, claimed, bad, braceVariants) {
|
|
24
|
-
if (slot.appKind !== undefined)
|
|
25
|
-
return;
|
|
26
|
-
for (const variant of braceVariants(slot.path)) {
|
|
27
|
-
const key = `${profile}:${variant}`;
|
|
28
|
-
if (claimed.has(key))
|
|
29
|
-
bad.push(`slots ${claimed.get(key)} and ${slot.id} claim the same pattern ${variant} on ${profile}`);
|
|
30
|
-
else
|
|
31
|
-
claimed.set(key, slot.id);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function checkSlotProfiles(slot, manifest, claimed, bad, braceVariants) {
|
|
35
|
-
for (const profile of slot.profiles) {
|
|
36
|
-
if (profile === APP_SCOPE)
|
|
37
|
-
checkAppRootSlot(slot, bad);
|
|
38
|
-
else
|
|
39
|
-
checkSideSlot(slot, profile, manifest, bad);
|
|
40
|
-
claimSlotPatterns(slot, profile, claimed, bad, braceVariants);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function checkLitePath(slot, pathVars, varsOf, bad, braceVariants, compileVariant) {
|
|
44
|
-
if (slot.lite?.path === undefined)
|
|
45
|
-
return;
|
|
46
|
-
for (const name of varsOf(slot.lite.path))
|
|
47
|
-
if (!pathVars.has(name))
|
|
48
|
-
bad.push(`slot ${slot.id}: lite.path binds <${name}>, which the path does not`);
|
|
49
|
-
for (const variant of braceVariants(slot.lite.path)) {
|
|
50
|
-
try {
|
|
51
|
-
compileVariant(slot, variant);
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
bad.push(`slot ${slot.id}: lite.path ${variant} does not compile (${error.message})`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function checkNamedPathBindings(slot, pathVars, varsOf, bad) {
|
|
59
|
-
for (const name of Object.keys(slot.requiredInstances ?? {})) {
|
|
60
|
-
if (!pathVars.has(name))
|
|
61
|
-
bad.push(`slot ${slot.id}: requiredInstances names <${name}>, which the path does not bind`);
|
|
62
|
-
}
|
|
63
|
-
for (const file of Object.values(slot.roles ?? {})) {
|
|
64
|
-
for (const name of varsOf(file))
|
|
65
|
-
if (!pathVars.has(name))
|
|
66
|
-
bad.push(`slot ${slot.id}: roles names <${name}> in ${file}, which the path does not bind`);
|
|
67
|
-
}
|
|
68
|
-
for (const entry of slot.requires ?? []) {
|
|
69
|
-
for (const name of varsOf(entry))
|
|
70
|
-
if (!pathVars.has(name))
|
|
71
|
-
bad.push(`slot ${slot.id}: requires ${entry} uses <${name}>, which the path does not bind`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function checkSlotPatternCompilation(slot, bad, braceVariants, compileVariant) {
|
|
75
|
-
for (const variant of braceVariants(slot.path)) {
|
|
76
|
-
try {
|
|
77
|
-
compileVariant(slot, variant);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
bad.push(`slot ${slot.id}: pattern ${variant} does not compile (${error.message})`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function checkSlotComposition(slot, manifest, bad) {
|
|
85
|
-
for (const kind of slot.composedBy ?? []) {
|
|
86
|
-
if (!slot.profiles.every((profile) => manifest.appKinds[profile].includes(kind)))
|
|
87
|
-
bad.push(`slot ${slot.id}: composedBy names ${kind}, which is not an app kind of every profile of the slot`);
|
|
88
|
-
}
|
|
89
|
-
if (slot.layers !== undefined && slot.tier !== 'none' && !slot.profiles.every((profile) => manifest.tiers[profile][slot.tier]?.lowerLayerOnly))
|
|
90
|
-
bad.push(`slot ${slot.id}: layers need a lowerLayerOnly tier`);
|
|
91
|
-
}
|
|
92
|
-
function checkLiteDeclaration(slot, manifest, bad) {
|
|
93
|
-
if (!slotInEdition(manifest, slot, 'lite') && (slot.litePresence !== undefined || slot.lite !== undefined))
|
|
94
|
-
bad.push(`slot ${slot.id}: litePresence/lite on a slot lite never sees (editions)`);
|
|
95
|
-
if (isPlainObject(slot.litePresence) && slot.profiles.includes(APP_SCOPE))
|
|
96
|
-
bad.push(`slot ${slot.id}: an app-root slot takes a bare litePresence, not a per-side map`);
|
|
97
|
-
for (const profile of slot.profiles) {
|
|
98
|
-
if (litePresenceOf(slot, profile) === 'forbidden' && typeof slot.goesTo !== 'string')
|
|
99
|
-
bad.push(`slot ${slot.id}: forbidden in lite for ${profile}, so it says where the content goes (goesTo)`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function checkSlotSemantics(slot, manifest, claimed, bad, helpers) {
|
|
103
|
-
if (claimed.ids.has(slot.id))
|
|
104
|
-
bad.push(`slot id ${slot.id} appears twice`);
|
|
105
|
-
claimed.ids.add(slot.id);
|
|
106
|
-
const pathVars = new Set(helpers.varsOf(slot.path));
|
|
107
|
-
checkSlotProfiles(slot, manifest, claimed.patterns, bad, helpers.braceVariants);
|
|
108
|
-
if (slot.appKind !== undefined && !pathVars.has('app'))
|
|
109
|
-
bad.push(`slot ${slot.id}: an app-kind slot binds <app> in its path`);
|
|
110
|
-
if (slot.requiredWhen !== undefined && slot.presence !== 'required')
|
|
111
|
-
bad.push(`slot ${slot.id}: requiredWhen belongs to a required slot`);
|
|
112
|
-
checkLiteDeclaration(slot, manifest, bad);
|
|
113
|
-
checkLitePath(slot, pathVars, helpers.varsOf, bad, helpers.braceVariants, helpers.compileVariant);
|
|
114
|
-
checkNamedPathBindings(slot, pathVars, helpers.varsOf, bad);
|
|
115
|
-
checkSlotPatternCompilation(slot, bad, helpers.braceVariants, helpers.compileVariant);
|
|
116
|
-
checkSlotComposition(slot, manifest, bad);
|
|
117
|
-
}
|
|
118
|
-
/** The problem of one declared side read, or null when a slot of the side it names (or of the app root) owns the path. */
|
|
119
|
-
function sideReadProblem(manifest, side, read, braceVariants) {
|
|
120
|
-
const [owner, ...rest] = read.split('/');
|
|
121
|
-
if (owner === side)
|
|
122
|
-
return `sides.${side}.reads names ${read}, which is its own side`;
|
|
123
|
-
const ownedBySide = isSide(owner);
|
|
124
|
-
const profile = ownedBySide ? owner : APP_SCOPE;
|
|
125
|
-
const prefix = ownedBySide ? rest.join('/') : read;
|
|
126
|
-
const owned = manifest.slots.some((slot) => slot.profiles.includes(profile) && slot.presence !== 'forbidden' && braceVariants(slot.path).some((variant) => variant.startsWith(prefix)));
|
|
127
|
-
const ownerName = ownedBySide ? owner : 'app-root';
|
|
128
|
-
return owned ? null : `sides.${side}.reads names ${read}, which no ${ownerName} slot owns`;
|
|
129
|
-
}
|
|
130
|
-
function checkSideReads(manifest, bad, braceVariants) {
|
|
131
|
-
for (const side of PROFILES) {
|
|
132
|
-
for (const read of manifest.sides[side].reads) {
|
|
133
|
-
const problem = sideReadProblem(manifest, side, read, braceVariants);
|
|
134
|
-
if (problem)
|
|
135
|
-
bad.push(problem);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function checkProfileTierTargets(manifest, profile, bad) {
|
|
140
|
-
bad.push(...tierKindProblems(manifest, profile));
|
|
141
|
-
for (const [tier, def] of Object.entries(manifest.tiers[profile])) {
|
|
142
|
-
for (const target of def.mayImport) {
|
|
143
|
-
if (!(target in manifest.tiers[profile]))
|
|
144
|
-
bad.push(`tiers.${profile}.${tier}.mayImport names ${target}, which is not a ${profile} tier`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
function checkProfileAppKinds(manifest, profile, bad) {
|
|
149
|
-
for (const kind of manifest.appKinds[profile]) {
|
|
150
|
-
const owners = manifest.slots.filter((slot) => slot.profiles.includes(profile) && slot.appKind === kind);
|
|
151
|
-
if (owners.length !== 1)
|
|
152
|
-
bad.push(`${profile} app kind ${kind} must have exactly one slot (found ${owners.length})`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function checkProfileMaps(manifest, bad) {
|
|
156
|
-
for (const profile of PROFILES) {
|
|
157
|
-
checkProfileTierTargets(manifest, profile, bad);
|
|
158
|
-
checkProfileAppKinds(manifest, profile, bad);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/** The rules a JSON Schema cannot state: unique ids, tiers named and reachable, app kinds, variables, no duplicate pattern. */
|
|
162
|
-
export function manifestSemanticProblems(manifest, helpers) {
|
|
163
|
-
const bad = [];
|
|
164
|
-
const claimed = { ids: new Set(), patterns: new Map() };
|
|
165
|
-
for (const slot of manifest.slots)
|
|
166
|
-
checkSlotSemantics(slot, manifest, claimed, bad, helpers);
|
|
167
|
-
if (manifestKind(manifest) === RUNTIME_KIND)
|
|
168
|
-
return [...bad, ...runtimeSemanticProblems(manifest)];
|
|
169
|
-
checkSideReads(manifest, bad, helpers.braceVariants);
|
|
170
|
-
checkProfileMaps(manifest, bad);
|
|
171
|
-
const major = Number(manifest.version.split('.')[0]);
|
|
172
|
-
if (String(manifest.schema) !== `starci/hfs-slots@${major}`)
|
|
173
|
-
bad.push(`schema ${manifest.schema} does not carry the major of version ${manifest.version}`);
|
|
174
|
-
return bad;
|
|
175
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// slot-side-problems.mjs - declaration checks for one app side against the HFS manifest.
|
|
2
|
-
import { backingProblems, optionalSlotProblems } from './declaration-slots.mjs';
|
|
3
|
-
function sideAppKindProblems(manifest, side, apps) {
|
|
4
|
-
const bad = [];
|
|
5
|
-
for (const app of apps)
|
|
6
|
-
if (!manifest.appKinds[side].includes(app.kind))
|
|
7
|
-
bad.push(`${side} app ${app.name} has kind ${app.kind}, which is not a ${side} kind (${manifest.appKinds[side].join(', ')})`);
|
|
8
|
-
return bad;
|
|
9
|
-
}
|
|
10
|
-
function requiredAppKindProblems(manifest, side, declaration) {
|
|
11
|
-
const bad = [];
|
|
12
|
-
const connections = declaration.connections ?? [];
|
|
13
|
-
for (const slot of manifest.slots) {
|
|
14
|
-
if (slot.appKind === undefined || !slot.profiles.includes(side) || slot.presence !== 'required')
|
|
15
|
-
continue;
|
|
16
|
-
if (slot.requiredWhen === 'connections' && !connections.length)
|
|
17
|
-
continue;
|
|
18
|
-
if (!declaration.apps.some((app) => app.kind === slot.appKind))
|
|
19
|
-
bad.push(`no ${side} app of kind ${slot.appKind} is declared (${slot.id} is required${slot.requiredWhen ? ' once a connection is declared' : ''})`);
|
|
20
|
-
}
|
|
21
|
-
return bad;
|
|
22
|
-
}
|
|
23
|
-
/** Problems for one side declaration, preserving the manifest's checks and their order. */
|
|
24
|
-
export function sideProblems(manifest, side, declaration, edition = 'full') {
|
|
25
|
-
const bad = sideAppKindProblems(manifest, side, declaration.apps);
|
|
26
|
-
bad.push(...optionalSlotProblems(manifest, side, declaration), ...backingProblems(manifest, side, declaration, edition));
|
|
27
|
-
for (const read of declaration.reads ?? [])
|
|
28
|
-
if (!manifest.sides[side].reads.includes(read))
|
|
29
|
-
bad.push(`sides.${side}.reads names ${read}; ${side} may read only ${manifest.sides[side].reads.join(', ') || 'nothing of the other side'}`);
|
|
30
|
-
bad.push(...requiredAppKindProblems(manifest, side, declaration));
|
|
31
|
-
return bad;
|
|
32
|
-
}
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
// hfs-slots.mjs - the HFS slot manifest and app declaration, loaded once and asked four questions:
|
|
2
|
-
// which slot owns path P slotOf(P) / classifyPath(P) (an unknown path reports its nearest slot)
|
|
3
|
-
// is import A -> B allowed importAllowed(A, B) (tier matrix, cross-owner entry, cross-app, layers)
|
|
4
|
-
// which files are required requiredFiles(P) / requiredPaths()
|
|
5
|
-
// is this path tracked isTracked(P) / trackingOf(P); the rule catalog (knowledge/hfs/rules.yaml, modules/schemas/hfs-rules.schema.yaml) loads through loadRuleCatalog / rules().
|
|
6
|
-
// Every check and lint rule of HFS reads knowledge/hfs/slots.yaml through this module; none keeps its own path
|
|
7
|
-
// list. The manifest shape is modules/schemas/hfs-slots.schema.yaml and hfs.json is modules/schemas/hfs-repo.schema.yaml;
|
|
8
|
-
// the installed runtime carries no npm dependency, so this file re-states those shapes instead of loading ajv.
|
|
9
|
-
//
|
|
10
|
-
// A product is ONE app repository: hfs.json at the app root has kind `app` and declares its two sides, `be` and `fe`, each in
|
|
11
|
-
// the folder of that name. The resolver of the app answers for the whole tree: a root path with the slots of profile `app`,
|
|
12
|
-
// a path below a side folder with that side's resolver (profile be or fe, the side folder as its root: the side view), so
|
|
13
|
-
// every check and lint rule runs unchanged with a side folder as its repository root. Nothing crosses sides except the
|
|
14
|
-
// paths the declaration lists in `sides.<side>.reads` (a subset of the manifest's `sides.<side>.reads`).
|
|
15
|
-
//
|
|
16
|
-
// One loader, two manifest kinds. `kind: app` (the default; knowledge/hfs/slots.yaml) is the product standard above.
|
|
17
|
-
// `kind: runtime` (knowledge/hfs/runtime-slots.yaml, schema starci/runtime-slots@<major>) is the standard of the StarCi
|
|
18
|
-
// runtime repository itself: one profile `runtime`, no sides and no app kinds, slot ids runtime.<name>, the tracked value
|
|
19
|
-
// `generated` (a copy written only by the slot's `generatedBy`). A runtime repository declares itself with
|
|
20
|
-
// hfs.json {"hfs": <major>, "kind": "runtime", "project": <name>}.
|
|
21
|
-
import fs from 'node:fs';
|
|
22
|
-
import path from 'node:path';
|
|
23
|
-
import { skillRoot } from '../../engine/runtime-root.mjs';
|
|
24
|
-
import { parseYamlCached } from '../lib/yaml-cached.mjs';
|
|
25
|
-
import { braceVariants } from '../lib/glob.mjs';
|
|
26
|
-
import { APP_KIND, RUNTIME_KIND, manifestKind } from './manifest-shape.mjs';
|
|
27
|
-
import { APP_SCOPE, isSide, manifestShapeProblems, PROFILES } from './slot-manifest-shape.mjs';
|
|
28
|
-
import { manifestSemanticProblems } from './slot-semantic-problems.mjs';
|
|
29
|
-
import { classifyIn, ownerIn, slotEnabled, tierIn } from './slot-classify.mjs';
|
|
30
|
-
import { compileVariant, varsOf, variantsOf } from './slot-match.mjs';
|
|
31
|
-
import { importAllowedIn } from './slot-imports.mjs';
|
|
32
|
-
import { requiredFilesIn, requiredPathsIn } from './slot-required.mjs';
|
|
33
|
-
import { appResolver, isAppRepo } from './slot-app-view.mjs';
|
|
34
|
-
import { sideProblems } from './slot-side-problems.mjs';
|
|
35
|
-
import { declarationShapeProblems } from './declaration-shape.mjs';
|
|
36
|
-
import { declarationEdition, editionRuleParams, effectiveSlot, slotInEdition } from './edition-slots.mjs';
|
|
37
|
-
import { fail } from './slot-errors.mjs';
|
|
38
|
-
import { loadRuleCatalog } from './rule-catalog.mjs';
|
|
39
|
-
export { litePresenceOf, slotInEdition } from './edition-slots.mjs';
|
|
40
|
-
export { HfsSlotsError } from './slot-errors.mjs';
|
|
41
|
-
export { loadRuleCatalog };
|
|
42
|
-
export { rules } from './rule-catalog.mjs';
|
|
43
|
-
export { APP_SCOPE };
|
|
44
|
-
const HFS_MANIFEST_FILE = 'knowledge/hfs/slots.yaml';
|
|
45
|
-
/** The manifest of kind runtime: the standard tree of the StarCi runtime repository (judged by scripts/hfs/runtime-check.mjs). */
|
|
46
|
-
export const RUNTIME_MANIFEST_FILE = 'knowledge/hfs/runtime-slots.yaml';
|
|
47
|
-
export const HFS_DECLARATION_FILE = 'hfs.json';
|
|
48
|
-
export const SIDES = Object.freeze([...PROFILES]);
|
|
49
|
-
/**
|
|
50
|
-
* The rewriter of a side's finding messages: `(message) => message` with its paths made app-relative like the finding's own path.
|
|
51
|
-
* Every check and rule of a side judges the side folder as its root, so the paths it names (`apps/web/src/...`, `src/modules/...`,
|
|
52
|
-
* `tsconfig.json`) are side-relative. A path here is a token that starts at a word boundary with a top-level entry of the side folder
|
|
53
|
-
* (`sideRoot`, read once) and goes on with `/`, or is that entry when its name holds a dot (a file). An import specifier (`@/x`,
|
|
54
|
-
* `../x`) or a path already app-relative is left alone.
|
|
55
|
-
*/
|
|
56
|
-
export function appRelativeMessages(side, sideRoot) {
|
|
57
|
-
let entries = [];
|
|
58
|
-
try {
|
|
59
|
-
entries = fs.readdirSync(sideRoot).filter((name) => name !== 'node_modules' && !name.startsWith('.git'));
|
|
60
|
-
}
|
|
61
|
-
catch { /* no side folder: nothing to rewrite */ }
|
|
62
|
-
if (!entries.length)
|
|
63
|
-
return (message) => message;
|
|
64
|
-
const escaped = entries.sort((a, b) => b.length - a.length).map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`));
|
|
65
|
-
const token = new RegExp(`(^|[\\s'"\`(\\[{,;=<>])((?:${escaped.join('|')})(?=/|[\\s'"\`)\\]},;:!?<>]|\\.(?:\\s|$)|$))`, 'g');
|
|
66
|
-
return (message) => (typeof message === 'string' && message
|
|
67
|
-
? message.replace(token, (whole, before, entry, offset) => (message.startsWith('/', offset + whole.length) || entry.includes('.') ? `${before}${side}/${entry}` : whole))
|
|
68
|
-
: message);
|
|
69
|
-
}
|
|
70
|
-
// ------------------------------------------------------------------------------------------- manifest
|
|
71
|
-
/**
|
|
72
|
-
* The parsed and validated manifest. `text` (or `file`, or `root`) selects the source; the default is the runtime's own
|
|
73
|
-
* knowledge/hfs/slots.yaml. A manifest that fails its shape or a semantic rule is refused whole (HFS_MANIFEST_INVALID).
|
|
74
|
-
*/
|
|
75
|
-
export function loadSlotManifest({ root = skillRoot, file = path.join(root, HFS_MANIFEST_FILE), text } = {}) {
|
|
76
|
-
let doc;
|
|
77
|
-
try {
|
|
78
|
-
doc = parseYamlCached(text ?? fs.readFileSync(file, 'utf8'));
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
fail('HFS_MANIFEST_INVALID', `the slot manifest cannot be read (${String(error?.message ?? error).split('\n')[0]})`, { file });
|
|
82
|
-
}
|
|
83
|
-
const problems = manifestShapeProblems(doc);
|
|
84
|
-
if (!problems.length)
|
|
85
|
-
problems.push(...manifestSemanticProblems(doc, { varsOf, braceVariants, compileVariant }));
|
|
86
|
-
if (problems.length)
|
|
87
|
-
fail('HFS_MANIFEST_INVALID', `the slot manifest breaks its schema: ${problems.slice(0, 5).join('; ')}${problems.length > 5 ? '; and ' + (problems.length - 5) + ' more' : ''}`, { file, problems });
|
|
88
|
-
const [major, minor, patch] = doc.version.split('.').map(Number);
|
|
89
|
-
return Object.freeze({ ...doc, major, minor, patch });
|
|
90
|
-
}
|
|
91
|
-
// ------------------------------------------------------------------------------------- declaration
|
|
92
|
-
const declarationInvalid = (problems, file) => fail('HFS_DECLARATION_INVALID', `hfs.json is refused: ${problems.slice(0, 5).join('; ')}${problems.length > 5 ? '; and ' + (problems.length - 5) + ' more' : ''}`, { file, problems });
|
|
93
|
-
function runtimeDeclaration(manifest, declaration, file, side) {
|
|
94
|
-
if (side !== null)
|
|
95
|
-
fail('HFS_DECLARATION_INVALID', 'a runtime repository has no sides', { file, side });
|
|
96
|
-
return Object.freeze({
|
|
97
|
-
hfs: declaration.hfs,
|
|
98
|
-
kind: RUNTIME_KIND,
|
|
99
|
-
project: declaration.project,
|
|
100
|
-
side: null,
|
|
101
|
-
profile: RUNTIME_KIND,
|
|
102
|
-
apps: Object.freeze([]),
|
|
103
|
-
optionalSlots: Object.freeze([]),
|
|
104
|
-
connections: Object.freeze([]),
|
|
105
|
-
reads: Object.freeze([]),
|
|
106
|
-
manifestVersion: manifest.version,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
const connectionView = (c) => Object.freeze({ name: c.name, envPrefix: c.envPrefix, owner: c.owner, isolation: c.isolation, ...(c.provider !== undefined ? { provider: c.provider } : {}) });
|
|
110
|
-
/** The declaration of one side of an app, frozen: the view a check of that side folder runs under. */
|
|
111
|
-
function sideDeclaration(manifest, declaration, name, edition, providers) {
|
|
112
|
-
const s = declaration.sides[name];
|
|
113
|
-
return Object.freeze({
|
|
114
|
-
hfs: declaration.hfs,
|
|
115
|
-
kind: APP_KIND,
|
|
116
|
-
project: declaration.project,
|
|
117
|
-
edition,
|
|
118
|
-
side: name,
|
|
119
|
-
profile: name,
|
|
120
|
-
apps: Object.freeze(s.apps.map((a) => Object.freeze({ name: a.name, kind: a.kind }))),
|
|
121
|
-
optionalSlots: Object.freeze([...(s.optionalSlots ?? [])]),
|
|
122
|
-
patterns: Object.freeze([...(s.patterns ?? [])]), kinds: Object.freeze([...(s.kinds ?? [])]),
|
|
123
|
-
backing: Object.freeze([...(s.backing ?? [])]),
|
|
124
|
-
connections: Object.freeze((s.connections ?? []).map(connectionView)),
|
|
125
|
-
providers,
|
|
126
|
-
reads: Object.freeze([...(s.reads ?? [])]),
|
|
127
|
-
dbFunctions: Object.freeze((s.dbFunctions ?? []).map((entry) => Object.freeze({ ...entry }))),
|
|
128
|
-
sqlPassThrough: Object.freeze((s.sqlPassThrough ?? []).map((entry) => Object.freeze({ ...entry }))),
|
|
129
|
-
...(s.grammar === undefined ? {} : { grammar: s.grammar }),
|
|
130
|
-
...(s.extraPackages === undefined ? {} : { extraPackages: Object.freeze(s.extraPackages.map((entry) => Object.freeze({ ...entry }))) }),
|
|
131
|
-
manifestVersion: manifest.version,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/** R334: an app's bare database function name must be a pg built-in the canon lists bare (ruleParams.be.dbFunctions); any other is schema.name. */
|
|
135
|
-
function bareDbFunctionProblems(manifest, be) {
|
|
136
|
-
const builtins = new Set((manifest.ruleParams?.be?.dbFunctions ?? []).map((entry) => entry.name).filter((name) => !name.includes('.')));
|
|
137
|
-
return (be?.dbFunctions ?? []).filter((entry) => !entry.name.includes('.') && !builtins.has(entry.name))
|
|
138
|
-
.map((entry) => `sides.be.dbFunctions names ${entry.name} bare, but a bare name is only a pg built-in of the canon's list (ruleParams.be.dbFunctions); name a function of a migration schema-qualified (public.${entry.name})`);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* A declaration checked against the manifest: kind app, the pinned major the manifest's (HFS_MANIFEST_MAJOR_MISMATCH otherwise,
|
|
142
|
-
* and there is no compatibility window), and per side: app kinds of that profile, optionalSlots naming only opt-in slots of the
|
|
143
|
-
* side that no app kind implies, every required app kind declared, reads within the manifest's. Returns the app (profile app,
|
|
144
|
-
* its two sides under `sides`), or with `side` that side's view: the declaration a check of the side folder runs under.
|
|
145
|
-
*/
|
|
146
|
-
export function resolveRepoDeclaration(manifest, declaration, { file = HFS_DECLARATION_FILE, side = null } = {}) {
|
|
147
|
-
const problems = declarationShapeProblems(declaration, PROFILES);
|
|
148
|
-
if (problems.length)
|
|
149
|
-
declarationInvalid(problems, file);
|
|
150
|
-
if (declaration.kind !== manifestKind(manifest))
|
|
151
|
-
declarationInvalid([`hfs.json is of kind ${declaration.kind}, but the manifest it is judged by is of kind ${manifestKind(manifest)}`], file);
|
|
152
|
-
if (declaration.hfs !== manifest.major)
|
|
153
|
-
fail('HFS_MANIFEST_MAJOR_MISMATCH', `hfs.json pins manifest major ${declaration.hfs} but the manifest is ${manifest.version}`, { pinned: declaration.hfs, manifest: manifest.version, manifestMajor: manifest.major, file });
|
|
154
|
-
if (declaration.kind === RUNTIME_KIND)
|
|
155
|
-
return runtimeDeclaration(manifest, declaration, file, side);
|
|
156
|
-
const { edition, known, valid } = declarationEdition(manifest, declaration);
|
|
157
|
-
if (!valid)
|
|
158
|
-
fail('HFS_EDITION_INVALID', `hfs.json edition is ${JSON.stringify(declaration.edition)}; the editions this manifest knows are ${known.join(', ')} (absent means full)`, { file, edition: declaration.edition });
|
|
159
|
-
const bad = [...PROFILES.flatMap((name) => sideProblems(manifest, name, declaration.sides[name], edition)), ...bareDbFunctionProblems(manifest, declaration.sides.be)];
|
|
160
|
-
if (bad.length)
|
|
161
|
-
declarationInvalid(bad, file);
|
|
162
|
-
if (side !== null && !isSide(side))
|
|
163
|
-
fail('HFS_DECLARATION_INVALID', `${side} is not a side of an app (be, fe)`, { file, side });
|
|
164
|
-
// A provider declared on any connection enables the provider slots of every profile (a fe side declares none): each view carries the union.
|
|
165
|
-
const providers = Object.freeze([...new Set(PROFILES.flatMap((name) => (declaration.sides[name].connections ?? []).map((c) => c.provider).filter((p) => p !== undefined)))]);
|
|
166
|
-
const sides = Object.fromEntries(PROFILES.map((name) => [name, sideDeclaration(manifest, declaration, name, edition, providers)]));
|
|
167
|
-
if (side !== null)
|
|
168
|
-
return sides[side];
|
|
169
|
-
return Object.freeze({
|
|
170
|
-
hfs: declaration.hfs,
|
|
171
|
-
kind: APP_KIND,
|
|
172
|
-
project: declaration.project,
|
|
173
|
-
edition,
|
|
174
|
-
side: null,
|
|
175
|
-
profile: APP_SCOPE,
|
|
176
|
-
// The root declares no app or connection of its own (each side does); its opt-in slots are the browser journey and the managed
|
|
177
|
-
// tsconfig.json that type-checks it, both switched on by `browser: true`.
|
|
178
|
-
apps: Object.freeze([]),
|
|
179
|
-
optionalSlots: Object.freeze(declaration.browser === true ? ['app.browser', 'app.browser-config'] : []),
|
|
180
|
-
modules: declaration.modules === 'data' ? 'data' : 'packages',
|
|
181
|
-
connections: Object.freeze([]),
|
|
182
|
-
providers,
|
|
183
|
-
reads: Object.freeze([]),
|
|
184
|
-
sides: Object.freeze(sides),
|
|
185
|
-
manifestVersion: manifest.version,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* The view of a whole app (profile app, both sides) that resolveRepoDeclaration builds for an app declaration; a declaration that
|
|
190
|
-
* resolves to a view without sides (a runtime repository) is refused HFS_DECLARATION_INVALID.
|
|
191
|
-
*/
|
|
192
|
-
export function resolveAppDeclaration(manifest, declaration, { file = HFS_DECLARATION_FILE } = {}) {
|
|
193
|
-
const view = resolveRepoDeclaration(manifest, declaration, { file });
|
|
194
|
-
if (!isAppRepo(view))
|
|
195
|
-
declarationInvalid([`a ${view.kind} declaration has no sides`], file);
|
|
196
|
-
return view;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Where the declaration of `dir` lives: `dir` itself when it holds hfs.json (the app root), else its parent when `dir` is a side
|
|
200
|
-
* folder (be/ or fe/) of an app (the side view). `{ file, appRoot, side }`; side is null at the app root.
|
|
201
|
-
*/
|
|
202
|
-
export function locateDeclaration(dir) {
|
|
203
|
-
const own = path.join(dir, HFS_DECLARATION_FILE);
|
|
204
|
-
if (fs.existsSync(own))
|
|
205
|
-
return { file: own, appRoot: dir, side: null };
|
|
206
|
-
const parent = path.dirname(dir);
|
|
207
|
-
const side = path.basename(dir);
|
|
208
|
-
const up = path.join(parent, HFS_DECLARATION_FILE);
|
|
209
|
-
if (isSide(side) && fs.existsSync(up))
|
|
210
|
-
return { file: up, appRoot: parent, side };
|
|
211
|
-
return { file: own, appRoot: dir, side: null };
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* hfs.json of the app at `repoRoot` (the app itself), or of the app whose side folder `repoRoot` is (that side's view), parsed and
|
|
215
|
-
* resolved; a missing or unreadable file is a refusal, never "unavailable".
|
|
216
|
-
*/
|
|
217
|
-
export function readRepoDeclaration(manifest, repoRoot) {
|
|
218
|
-
const { file, side } = locateDeclaration(repoRoot);
|
|
219
|
-
let declaration;
|
|
220
|
-
try {
|
|
221
|
-
declaration = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
declarationInvalid([`hfs.json cannot be read (${String(error?.code ?? error?.message ?? error).split('\n')[0]})`], file);
|
|
225
|
-
}
|
|
226
|
-
return resolveRepoDeclaration(manifest, declaration, { file, side });
|
|
227
|
-
}
|
|
228
|
-
// ------------------------------------------------------------------------------------------- resolver
|
|
229
|
-
/**
|
|
230
|
-
* The four questions for one scope: the app root (profile app, root paths) or one side (profile be or fe, paths relative to the
|
|
231
|
-
* side folder). createSlotResolver composes them; nothing else calls this.
|
|
232
|
-
*/
|
|
233
|
-
function createScopeResolver(manifest, repo) {
|
|
234
|
-
const profile = repo.profile;
|
|
235
|
-
const edition = repo.edition ?? 'full';
|
|
236
|
-
const slots = manifest.slots.filter((s) => s.managedOnly !== true && s.profiles.includes(profile) && slotInEdition(manifest, s, edition)).map((s) => effectiveSlot(s, profile, edition));
|
|
237
|
-
const scope = { manifest, repo, profile, slots, byId: new Map(slots.map((s) => [s.id, s])), variants: slots.flatMap(variantsOf), appKind: new Map(repo.apps.map((a) => [a.name, a.kind])) };
|
|
238
|
-
const classifyPath = (input) => classifyIn(scope, input);
|
|
239
|
-
/** tracked | ignored | external for the slot owning `p`, or null when no slot owns it. */
|
|
240
|
-
const trackingOf = (p) => classifyPath(p).tracking ?? null;
|
|
241
|
-
return Object.freeze({
|
|
242
|
-
repo,
|
|
243
|
-
slot: (id) => scope.byId.get(id) ?? null,
|
|
244
|
-
slots: () => slots,
|
|
245
|
-
slotEnabled: (slot) => slotEnabled(scope, slot),
|
|
246
|
-
classifyPath,
|
|
247
|
-
slotOf: (p) => { const c = classifyPath(p); return c.slot ? scope.byId.get(c.slot) : null; },
|
|
248
|
-
ownerOf: (input) => ownerIn(scope, input),
|
|
249
|
-
tierOf: (input) => tierIn(scope, input),
|
|
250
|
-
importAllowed: (fromPath, toPath) => importAllowedIn(scope, fromPath, toPath),
|
|
251
|
-
requiredFiles: (input) => requiredFilesIn(scope, input),
|
|
252
|
-
requiredPaths: () => requiredPathsIn(scope),
|
|
253
|
-
trackingOf,
|
|
254
|
-
/** True only for a path a slot owns and requires to be committed. */
|
|
255
|
-
isTracked: (p) => trackingOf(p) === 'tracked',
|
|
256
|
-
// The app's own database functions and SQL pass-through files (hfs.json sides.be.dbFunctions, sides.be.sqlPassThrough) join the canon's lists (R334).
|
|
257
|
-
ruleParams: () => withDeclaredLists(ruleParams(manifest, profile, edition), repo),
|
|
258
|
-
allowedImports: (tier) => manifest.tiers[profile]?.[tier]?.mayImport ?? null,
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* The four questions for one app, or for one side of it. `repo` comes from resolveRepoDeclaration / readRepoDeclaration.
|
|
263
|
-
* Paths are relative to the root the declaration was resolved for (backslashes and a leading ./ are folded; a trailing / or a
|
|
264
|
-
* directory path is fine): a side view (repo.side set) answers for the side folder as its root, exactly as a check of that side
|
|
265
|
-
* runs; the app (profile app) answers a root path with the app-root slots and a path below be/ or fe/ with that side's view,
|
|
266
|
-
* the side prefixed back onto every path and root it returns (and `side` added). Only the declared `reads` cross sides.
|
|
267
|
-
*/
|
|
268
|
-
export function createSlotResolver(manifest, repo) {
|
|
269
|
-
if (repo.profile !== APP_SCOPE)
|
|
270
|
-
return createScopeResolver(manifest, repo);
|
|
271
|
-
// The root declares no connection of its own, yet a provider slot of the app profile is enabled by a
|
|
272
|
-
// side's connection with that provider: the root scope reads the union of the sides' connections.
|
|
273
|
-
// reason: the profile is app, so the declaration resolveRepoDeclaration built carries both sides
|
|
274
|
-
const app = repo;
|
|
275
|
-
const root = createScopeResolver(manifest, { ...repo, connections: SIDES.flatMap((side) => app.sides[side].connections) });
|
|
276
|
-
const sides = Object.fromEntries(PROFILES.map((side) => [side, createScopeResolver(manifest, app.sides[side])]));
|
|
277
|
-
return appResolver(app, root, sides);
|
|
278
|
-
}
|
|
279
|
-
/** The rule parameters with the app's declared database functions and SQL pass-through files appended to `dbFunctions` and `sqlPassThrough` (be only), the result frozen. */
|
|
280
|
-
const withDeclaredLists = (params, repo) => {
|
|
281
|
-
const functions = repo.dbFunctions ?? [];
|
|
282
|
-
const passThrough = repo.sqlPassThrough ?? [];
|
|
283
|
-
if ((params.dbFunctions === undefined && !functions.length) && (params.sqlPassThrough === undefined && !passThrough.length))
|
|
284
|
-
return params;
|
|
285
|
-
return Object.freeze({
|
|
286
|
-
...params,
|
|
287
|
-
...(params.dbFunctions === undefined && !functions.length ? {} : { dbFunctions: [...(params.dbFunctions ?? []), ...functions] }),
|
|
288
|
-
...(params.sqlPassThrough === undefined && !passThrough.length ? {} : { sqlPassThrough: [...(params.sqlPassThrough ?? []), ...passThrough] }),
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
/** The rule parameters of one profile (be: infraOwners, suffixes, bannedSuffixes and the rest over the shared ruleParams.common fileLines and duplicateBlock; fe: common alone or with its overrides; runtime: ruleParams.runtime of a runtime manifest), as a frozen deep copy. Under `edition` lite the `lite` overrides of ruleParams.<profile> merge over the base (the `lite` key itself is never returned). */
|
|
292
|
-
export function ruleParams(manifest, profile, edition = 'full') {
|
|
293
|
-
const profiles = manifestKind(manifest) === RUNTIME_KIND ? [RUNTIME_KIND] : PROFILES;
|
|
294
|
-
if (!profiles.includes(profile))
|
|
295
|
-
fail('HFS_MANIFEST_INVALID', `ruleParams has no profile ${profile}`, { profile });
|
|
296
|
-
return editionRuleParams({ ...manifest.ruleParams.common, ...manifest.ruleParams[profile] }, edition);
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* The manifest of this runtime plus the resolver for the app or side folder at `repoRoot` (a side folder gets that side's view), or
|
|
300
|
-
* for an already-parsed declaration (the app, or with `side` that side's view).
|
|
301
|
-
*/
|
|
302
|
-
export function openHfs({ root = skillRoot, repoRoot, declaration, side = null, manifest = loadSlotManifest({ root }) } = {}) {
|
|
303
|
-
const repo = declaration !== undefined ? resolveRepoDeclaration(manifest, declaration, { side }) : readRepoDeclaration(manifest, repoRoot);
|
|
304
|
-
const resolver = createSlotResolver(manifest, repo);
|
|
305
|
-
return { manifest, ...resolver, rules: () => loadRuleCatalog({ root, manifest }) };
|
|
306
|
-
}
|