@starci/eslint-grammar-offset-pop 0.22.0 → 0.23.1
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 +8 -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,77 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { braceVariants, globExpression } from '../lib/glob.mjs';
|
|
3
|
-
import { declaredLogicOf } from './manifest-shape.mjs';
|
|
4
|
-
/**
|
|
5
|
-
* What a slot's `requires`, `allows` and `forbids` entries (knowledge/hfs/slots.yaml) say about a file, read through the
|
|
6
|
-
* resolver of scripts/hfs/slots.mjs. The machine checks that judge "this folder holds only what its slot allows"
|
|
7
|
-
* (feature-shape, fe-slot-allows) and the front-end lint rules (through `hfs.allows(file)` of scripts/hfs/view.mjs) read it here so no check keeps a path list.
|
|
8
|
-
*
|
|
9
|
-
* An entry is a name relative to the slot instance root: `<var>` is the instance's bound variable when the slot binds it
|
|
10
|
-
* (`<feature>`, `<capability>`) and one path segment of any text otherwise (`<action>`), `*` and `?` stay inside a segment,
|
|
11
|
-
* `{a,b}` alternates, a trailing `/` names a directory and everything below it. A slot also admits, unlisted, the unit spec beside each
|
|
12
|
-
* measured file it names (isMeasuredSpec): a file it declares in `logic`, or a named file of a logic role.
|
|
13
|
-
*/
|
|
14
|
-
const VAR = /<([A-Za-z][A-Za-z0-9-]*)>/g;
|
|
15
|
-
const SPEC = /\.spec\.ts$/;
|
|
16
|
-
/**
|
|
17
|
-
* Whether `relative` is the unit spec `<stem>.spec.ts` of a measured file beside it that the slot names: a file the slot declares in
|
|
18
|
-
* `logic`, or a `requires`/`allows` file of a logic role (ruleParams.be.logicRoles), in a slot whose coverage is required and whose tests
|
|
19
|
-
* are unit-beside. The slot admits that spec without listing it, as unit-test-colocated (R47) accepts it.
|
|
20
|
-
*/
|
|
21
|
-
function isMeasuredSpec(resolver, classified, slot, relative, named) {
|
|
22
|
-
if (!SPEC.test(relative) || slot.coverage !== 'required' || slot.tests !== 'unit-beside')
|
|
23
|
-
return false;
|
|
24
|
-
const subject = relative.replace(SPEC, '.ts');
|
|
25
|
-
if (declaredLogicOf(slot).includes(subject))
|
|
26
|
-
return true;
|
|
27
|
-
const role = /\.([a-z0-9-]+)\.ts$/.exec(subject)?.[1];
|
|
28
|
-
// An app resolver keeps no rule parameters of its own: a path on a side reads that side's.
|
|
29
|
-
const params = classified.side ? resolver.sides?.[classified.side]?.ruleParams() : resolver.ruleParams?.();
|
|
30
|
-
return (params?.logicRoles ?? []).includes(role) && named.some((matcher) => matcher.expression.test(subject));
|
|
31
|
-
}
|
|
32
|
-
function matchersOf(entries, bindings) {
|
|
33
|
-
return (entries ?? []).flatMap((entry) => {
|
|
34
|
-
const directory = entry.endsWith('/');
|
|
35
|
-
const body = directory ? entry.slice(0, -1) : entry;
|
|
36
|
-
const filled = body.replace(VAR, (_whole, name) => bindings[name] ?? '*');
|
|
37
|
-
return braceVariants(filled).map((variant) => ({ entry, directory, expression: globExpression(directory ? `${variant}/**` : variant) }));
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/** The path of `file` below the instance root of the slot that owns it. */
|
|
41
|
-
export function relativeToRoot(file, root) {
|
|
42
|
-
return root && file.startsWith(`${root}/`) ? file.slice(root.length + 1) : path.posix.basename(file);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Whether the slot that owns `file` names it in `requires` or `allows` (and does not forbid it); null when no enabled slot
|
|
46
|
-
* owns it. Unlike allowsFile it judges a slot that lists only `requires` too, so a folder closed by its slot (an app's
|
|
47
|
-
* src/) is read from the slot and never from a check's own list.
|
|
48
|
-
*/
|
|
49
|
-
export function slotAdmitsFile(resolver, file) {
|
|
50
|
-
const classified = resolver.classifyPath(file);
|
|
51
|
-
if (classified.status === 'no-slot' || classified.status === 'ambiguous' || !classified.slot)
|
|
52
|
-
return null;
|
|
53
|
-
const slot = resolver.slot(classified.slot);
|
|
54
|
-
const relative = relativeToRoot(classified.path, classified.root);
|
|
55
|
-
const named = matchersOf([...(slot.requires ?? []), ...(slot.allows ?? [])], classified.bindings);
|
|
56
|
-
const hit = named.some(matcher => matcher.expression.test(relative)) || isMeasuredSpec(resolver, classified, slot, relative, named);
|
|
57
|
-
const forbidden = matchersOf(slot.forbids, classified.bindings).some(matcher => matcher.expression.test(relative) || matcher.expression.test(`${relative}/`));
|
|
58
|
-
return hit && !forbidden;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* {slot, root, relative, allowed, entry?, forbiddenBy?} for a repository-relative file, or null when no enabled slot owns
|
|
62
|
-
* it or the slot names no `allows`. `allowed` is true when the relative path matches a `requires` or `allows` entry.
|
|
63
|
-
*/
|
|
64
|
-
export function allowsFile(resolver, file) {
|
|
65
|
-
const classified = resolver.classifyPath(file);
|
|
66
|
-
if (classified.status === 'no-slot' || classified.status === 'ambiguous' || !classified.slot)
|
|
67
|
-
return null;
|
|
68
|
-
const slot = resolver.slot(classified.slot);
|
|
69
|
-
if (!slot?.allows?.length)
|
|
70
|
-
return null;
|
|
71
|
-
const relative = relativeToRoot(classified.path, classified.root);
|
|
72
|
-
const named = matchersOf([...(slot.requires ?? []), ...slot.allows], classified.bindings);
|
|
73
|
-
const hit = named.find(matcher => matcher.expression.test(relative));
|
|
74
|
-
const spec = !hit && isMeasuredSpec(resolver, classified, slot, relative, named);
|
|
75
|
-
const forbidden = matchersOf(slot.forbids, classified.bindings).find(matcher => matcher.expression.test(relative) || matcher.expression.test(`${relative}/`));
|
|
76
|
-
return { slot: slot.id, root: classified.root, relative, allowed: (Boolean(hit) || spec) && !forbidden, entry: hit?.entry, forbiddenBy: forbidden?.entry, allows: slot.allows };
|
|
77
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// root-packages.mjs - the workspace packages of an app ROOT (packages/<name>: the agent SDK, a block library, a module package, the managed packages/modules).
|
|
2
|
-
// They lie outside both side folders and belong to no side; both sides import them by package name, through their package entry points
|
|
3
|
-
// (the `exports` of the manifest), so the import graph reads them as first-party packages and the back-end canon never reads them as
|
|
4
|
-
// a third-party library. The app root's one package.json lists them in `workspaces`; the patterns that start with a side folder
|
|
5
|
-
// (`fe/apps/*`) are that side's own workspaces and are not read here.
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import { readJsonFile as readJson } from '../../lib/json.mjs';
|
|
9
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
10
|
-
import { isInside } from '../../lib/walk.mjs';
|
|
11
|
-
import { slash } from '../../lib/path-key.mjs';
|
|
12
|
-
/** The slots whose directories at the app root are first-party packages of the app (agent SDK, module packages, the managed registry). */
|
|
13
|
-
export const ROOT_PACKAGE_SLOTS = new Set(['app.packages', 'app.module-registry']);
|
|
14
|
-
const SIDE_PREFIX = /^(?:be|fe)\//;
|
|
15
|
-
/** A workspace pattern this reader expands (a literal path, or `*` as a whole segment); the others are judged by the workspace rules. */
|
|
16
|
-
const expandablePattern = (written) => !path.isAbsolute(written) && written.split('/').every(segment => segment !== '..' && (!segment.includes('*') || segment === '*'));
|
|
17
|
-
function expandSegment(base, segment) {
|
|
18
|
-
if (segment !== '*')
|
|
19
|
-
return [path.join(base, segment)];
|
|
20
|
-
if (!fs.existsSync(base) || !fs.lstatSync(base).isDirectory())
|
|
21
|
-
return [];
|
|
22
|
-
return fs.readdirSync(base, { withFileTypes: true }).filter(item => item.isDirectory()).sort((a, b) => byCodeUnit(a.name, b.name)).map(item => path.join(base, item.name));
|
|
23
|
-
}
|
|
24
|
-
/** A package folder with a regular package.json (a link is not one). */
|
|
25
|
-
export function packageDirectory(absolute) {
|
|
26
|
-
try {
|
|
27
|
-
if (!fs.lstatSync(absolute).isDirectory())
|
|
28
|
-
return false;
|
|
29
|
-
const manifest = fs.lstatSync(path.join(absolute, 'package.json'));
|
|
30
|
-
return manifest.isFile() && !manifest.isSymbolicLink();
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/** The folders the `workspaces` of the app root's package.json name that no side owns, as absolute paths in code-unit order. */
|
|
37
|
-
export function rootWorkspaceDirectories(packageRoot) {
|
|
38
|
-
const manifest = readJson(path.join(packageRoot, 'package.json'));
|
|
39
|
-
const declared = manifest?.workspaces;
|
|
40
|
-
const patterns = Array.isArray(declared) ? declared : declared?.packages;
|
|
41
|
-
const found = new Set();
|
|
42
|
-
for (const pattern of Array.isArray(patterns) ? patterns : []) {
|
|
43
|
-
if (typeof pattern !== 'string' || !pattern.trim())
|
|
44
|
-
continue;
|
|
45
|
-
const written = slash(pattern.trim()).replace(/^\.\//, '');
|
|
46
|
-
if (SIDE_PREFIX.test(written) || !expandablePattern(written))
|
|
47
|
-
continue;
|
|
48
|
-
let bases = [packageRoot];
|
|
49
|
-
for (const segment of written.split('/'))
|
|
50
|
-
bases = bases.flatMap(base => expandSegment(base, segment));
|
|
51
|
-
for (const base of bases)
|
|
52
|
-
found.add(path.resolve(base));
|
|
53
|
-
}
|
|
54
|
-
return [...found].sort(byCodeUnit);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* The record of one package folder of the app root, or null when it is no named package inside the app root.
|
|
58
|
-
* `canonical` is the file-identity function of the caller (the real path), so a record agrees with the files the graph reads.
|
|
59
|
-
*/
|
|
60
|
-
export function rootPackageRecord(packageRoot, directory, canonical) {
|
|
61
|
-
if (!packageDirectory(directory) || !isInside(packageRoot, directory))
|
|
62
|
-
return null;
|
|
63
|
-
const manifest = readJson(path.join(directory, 'package.json'));
|
|
64
|
-
const name = manifest?.['name'];
|
|
65
|
-
if (manifest === null || typeof name !== 'string' || !name)
|
|
66
|
-
return null;
|
|
67
|
-
return { root: canonical(directory), relative: slash(path.relative(packageRoot, directory)), name, exports: manifest['exports'], manifest, workspace: true, app: false };
|
|
68
|
-
}
|
|
69
|
-
/** The names of the workspace packages of the app root: what the back-end canon must not read as third-party libraries. */
|
|
70
|
-
export function rootPackageNames(packageRoot) {
|
|
71
|
-
const names = new Set();
|
|
72
|
-
for (const directory of rootWorkspaceDirectories(packageRoot)) {
|
|
73
|
-
const record = rootPackageRecord(packageRoot, directory, (file) => file);
|
|
74
|
-
if (record !== null)
|
|
75
|
-
names.add(record.name);
|
|
76
|
-
}
|
|
77
|
-
return names;
|
|
78
|
-
}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { isPlainObject } from '../../engine/plain-object.mjs';
|
|
2
|
-
import { APP_KIND, connectionShapeProblems, NAME, PACKAGE_NAME, RUNTIME_KIND, SLOT_ID } from './manifest-shape.mjs';
|
|
3
|
-
import { dbFunctionsOk, sqlPassThroughOk } from './rule-params-shape.mjs';
|
|
4
|
-
import { kindShapeProblems, patternShapeProblems } from './declaration-slots.mjs';
|
|
5
|
-
import { byCodeUnit } from '../lib/list.mjs';
|
|
6
|
-
/** Shape problems of the optional hfs.json `db` block of a lite app: the environment variable naming its database, its image, forced RLS and its application role. */
|
|
7
|
-
const isStringList = (value) => Array.isArray(value) && value.every((entry) => typeof entry === 'string' && entry.trim());
|
|
8
|
-
/** One owner ruling on a migration's destructive DDL: the exact file, the exact objects, the reason and the date the owner ruled it. */
|
|
9
|
-
const isDestructiveRuling = (ruling) => isPlainObject(ruling)
|
|
10
|
-
&& typeof ruling.migration === 'string' && /^db\/migrations\/\d{14}_[a-z0-9_-]+\.sql$/.test(ruling.migration)
|
|
11
|
-
&& isStringList(ruling.objects) && ruling.objects.length > 0
|
|
12
|
-
&& typeof ruling.reason === 'string' && ruling.reason.trim() !== ''
|
|
13
|
-
&& typeof ruling.date === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(ruling.date)
|
|
14
|
-
&& Object.keys(ruling).every((key) => ['migration', 'objects', 'reason', 'date'].includes(key));
|
|
15
|
-
function dbBlockProblems(block) {
|
|
16
|
-
if (block === undefined)
|
|
17
|
-
return [];
|
|
18
|
-
if (!isPlainObject(block))
|
|
19
|
-
return ['db must be an object'];
|
|
20
|
-
const bad = [];
|
|
21
|
-
for (const key of Object.keys(block))
|
|
22
|
-
if (!['urlEnv', 'image', 'forceRls', 'forceRlsExemptions', 'appRole', 'destructiveRulings'].includes(key))
|
|
23
|
-
bad.push(`db has unknown key ${key}`);
|
|
24
|
-
if (block.urlEnv !== undefined && (typeof block.urlEnv !== 'string' || !/^[A-Z][A-Z0-9_]*$/.test(block.urlEnv)))
|
|
25
|
-
bad.push('db.urlEnv must name an UPPER_CASE environment variable');
|
|
26
|
-
if (block.image !== undefined && (typeof block.image !== 'string' || !/@sha256:[0-9a-f]{64}$/.test(block.image)))
|
|
27
|
-
bad.push('db.image must be a digest-pinned image reference');
|
|
28
|
-
if (block.forceRls !== undefined && !isStringList(block.forceRls))
|
|
29
|
-
bad.push('db.forceRls must be a list of strings');
|
|
30
|
-
if (block.appRole !== undefined && (typeof block.appRole !== 'string' || !/^[a-z][a-z0-9_]*$/.test(block.appRole)))
|
|
31
|
-
bad.push('db.appRole must name a role');
|
|
32
|
-
if (block.forceRlsExemptions !== undefined && !Array.isArray(block.forceRlsExemptions))
|
|
33
|
-
bad.push('db.forceRlsExemptions must be a list of { table, reason }');
|
|
34
|
-
if (block.destructiveRulings !== undefined && !(Array.isArray(block.destructiveRulings) && block.destructiveRulings.every(isDestructiveRuling)))
|
|
35
|
-
bad.push('db.destructiveRulings must be a list of { migration, objects, reason, date } naming one db/migrations file, the objects it destroys, why and the date the owner ruled it (YYYY-MM-DD)');
|
|
36
|
-
return bad;
|
|
37
|
-
}
|
|
38
|
-
function appShapeProblems(apps, at, side, names) {
|
|
39
|
-
const bad = [];
|
|
40
|
-
if (!Array.isArray(apps) || !apps.length) {
|
|
41
|
-
bad.push(`${at}.apps must list every ${side}/apps/<name> with its kind`);
|
|
42
|
-
return bad;
|
|
43
|
-
}
|
|
44
|
-
apps.forEach((app, index) => {
|
|
45
|
-
if (!isPlainObject(app) || !NAME.test(String(app.name)) || !NAME.test(String(app.kind)) || Object.keys(app).some((key) => key !== 'name' && key !== 'kind'))
|
|
46
|
-
bad.push(`${at}.apps[${index}] must be {name, kind}`);
|
|
47
|
-
else if (names.has(app.name))
|
|
48
|
-
bad.push(`app ${app.name} is declared twice (${names.get(app.name)} and ${side})`);
|
|
49
|
-
else
|
|
50
|
-
names.set(app.name, side);
|
|
51
|
-
});
|
|
52
|
-
return bad;
|
|
53
|
-
}
|
|
54
|
-
function connectionProblems(side, value) {
|
|
55
|
-
const bad = [];
|
|
56
|
-
if (side !== 'be') {
|
|
57
|
-
bad.push('connections belong to the be side');
|
|
58
|
-
return bad;
|
|
59
|
-
}
|
|
60
|
-
const list = Array.isArray(value.connections) ? value.connections : null;
|
|
61
|
-
const shape = connectionShapeProblems(list, value.apps);
|
|
62
|
-
if (shape.length) {
|
|
63
|
-
bad.push(...shape);
|
|
64
|
-
return bad;
|
|
65
|
-
}
|
|
66
|
-
if (new Set(list.map((connection) => connection.name)).size !== list.length)
|
|
67
|
-
bad.push('connections names must be unique');
|
|
68
|
-
for (const a of list)
|
|
69
|
-
for (const b of list)
|
|
70
|
-
if (a !== b && `${b.envPrefix}_`.startsWith(`${a.envPrefix}_`))
|
|
71
|
-
bad.push(`connections ${a.name} and ${b.name} share env keys (${a.envPrefix}_ covers ${b.envPrefix}_)`);
|
|
72
|
-
return bad;
|
|
73
|
-
}
|
|
74
|
-
/** Whether a declared list is present but not a list of distinct entries that all satisfy `valid`. */
|
|
75
|
-
const isBadUniqueList = (list, valid) => list !== undefined && (!Array.isArray(list) || !list.every((entry) => valid(entry)) || new Set(list).size !== list.length);
|
|
76
|
-
function validExtraPackage(entry) {
|
|
77
|
-
return isPlainObject(entry) && Object.keys(entry).every(key => key === 'name' || key === 'reason')
|
|
78
|
-
&& typeof entry.name === 'string' && entry.name.length <= 214 && PACKAGE_NAME.test(entry.name)
|
|
79
|
-
&& typeof entry.reason === 'string' && entry.reason.trim().length > 0;
|
|
80
|
-
}
|
|
81
|
-
function extraPackageProblems(side, entries) {
|
|
82
|
-
if (entries === undefined)
|
|
83
|
-
return [];
|
|
84
|
-
if (side !== 'fe')
|
|
85
|
-
return ['extraPackages belong to the fe side'];
|
|
86
|
-
if (!Array.isArray(entries) || !entries.every(validExtraPackage))
|
|
87
|
-
return ['sides.fe.extraPackages must be a list of {name, reason} with a package name and a nonempty reason'];
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
function grammarProblems(side, grammar) {
|
|
91
|
-
if (grammar === undefined)
|
|
92
|
-
return [];
|
|
93
|
-
if (side !== 'fe')
|
|
94
|
-
return ['grammar belongs to the fe side'];
|
|
95
|
-
return typeof grammar === 'string' && NAME.test(grammar) ? [] : ['sides.fe.grammar must name a Grammar family'];
|
|
96
|
-
}
|
|
97
|
-
function declarationSideProblems(side, value, names) {
|
|
98
|
-
const bad = [];
|
|
99
|
-
const at = `sides.${side}`;
|
|
100
|
-
if (!isPlainObject(value))
|
|
101
|
-
return [`${at} must be an object`];
|
|
102
|
-
for (const key of Object.keys(value))
|
|
103
|
-
if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads', 'extraPackages', 'grammar', 'backing', 'dbFunctions', 'sqlPassThrough'].includes(key))
|
|
104
|
-
bad.push(`${at} has unknown key ${key}`);
|
|
105
|
-
if (value.dbFunctions !== undefined && (side !== 'be' || !dbFunctionsOk(value.dbFunctions, { bare: true })))
|
|
106
|
-
bad.push(`${at}.dbFunctions belongs to the be side and lists {name, reason} database functions, each schema-qualified (schema.name, never pg_catalog) or a bare pg built-in of the canon's list, with unique names`);
|
|
107
|
-
if (value.sqlPassThrough !== undefined && (side !== 'be' || !sqlPassThroughOk(value.sqlPassThrough)))
|
|
108
|
-
bad.push(`${at}.sqlPassThrough belongs to the be side and lists {file, reason} files relative to the side folder, forward slashes, unique, each with the reason its SQL text is not the app's own`);
|
|
109
|
-
bad.push(...appShapeProblems(value.apps, at, side, names));
|
|
110
|
-
if (isBadUniqueList(value.optionalSlots, (slot) => SLOT_ID.test(String(slot))))
|
|
111
|
-
bad.push(`${at}.optionalSlots must be a unique list of slot ids`);
|
|
112
|
-
if (value.backing !== undefined && side !== 'be')
|
|
113
|
-
bad.push('backing belongs to the be side');
|
|
114
|
-
else if (isBadUniqueList(value.backing, (name) => NAME.test(String(name))))
|
|
115
|
-
bad.push(`${at}.backing must be a unique list of backing service names`);
|
|
116
|
-
bad.push(...patternShapeProblems(value, at, NAME), ...kindShapeProblems(value, at, NAME));
|
|
117
|
-
if (isBadUniqueList(value.reads, (read) => typeof read === 'string' && read.length > 0))
|
|
118
|
-
bad.push(`${at}.reads must be a unique list of paths`);
|
|
119
|
-
if (value.connections !== undefined)
|
|
120
|
-
bad.push(...connectionProblems(side, value));
|
|
121
|
-
bad.push(...extraPackageProblems(side, value.extraPackages), ...grammarProblems(side, value.grammar));
|
|
122
|
-
return bad;
|
|
123
|
-
}
|
|
124
|
-
/** Product vocabulary is a declaration, never a switch for a rule. */
|
|
125
|
-
function lexiconBlockProblems(lexicon) {
|
|
126
|
-
if (lexicon === undefined)
|
|
127
|
-
return [];
|
|
128
|
-
if (!isPlainObject(lexicon))
|
|
129
|
-
return ['lexicon must be an object'];
|
|
130
|
-
const bad = [];
|
|
131
|
-
for (const key of Object.keys(lexicon))
|
|
132
|
-
if (key !== 'removed')
|
|
133
|
-
bad.push(`lexicon has unknown key ${key}`);
|
|
134
|
-
if (isBadUniqueList(lexicon.removed, (word) => typeof word === 'string' && word.trim().length > 0))
|
|
135
|
-
bad.push('lexicon.removed must be a unique list of nonempty words');
|
|
136
|
-
return bad;
|
|
137
|
-
}
|
|
138
|
-
/** Front-end error reporting remains optional in both editions. */
|
|
139
|
-
function observeBlockProblems(observe) {
|
|
140
|
-
if (observe === undefined)
|
|
141
|
-
return [];
|
|
142
|
-
if (!isPlainObject(observe))
|
|
143
|
-
return ['observe must be an object'];
|
|
144
|
-
const bad = [];
|
|
145
|
-
for (const key of Object.keys(observe))
|
|
146
|
-
if (key !== 'reporter')
|
|
147
|
-
bad.push(`observe has unknown key ${key}`);
|
|
148
|
-
if (observe.reporter !== undefined && (typeof observe.reporter !== 'string' || !observe.reporter.trim()))
|
|
149
|
-
bad.push('observe.reporter must name the optional error reporter');
|
|
150
|
-
return bad;
|
|
151
|
-
}
|
|
152
|
-
const DECLARATION_KEYS = new Set(['hfs', 'kind', 'project', 'edition', 'db', 'sides', 'browser', 'modules', 'lexicon', 'observe', 'rulePacks']);
|
|
153
|
-
/** A rule pack hfs.json names (PROJECT-LINT-3): an npm package name, each once. */
|
|
154
|
-
const RULE_PACK_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u;
|
|
155
|
-
const RUNTIME_DECLARATION_KEYS = new Set(['hfs', 'kind', 'project']);
|
|
156
|
-
function productDeclarationProblems(declaration, profiles) {
|
|
157
|
-
const bad = [];
|
|
158
|
-
for (const key of Object.keys(declaration))
|
|
159
|
-
if (!DECLARATION_KEYS.has(key))
|
|
160
|
-
bad.push(`unknown key ${key}`);
|
|
161
|
-
bad.push(...dbBlockProblems(declaration.db), ...lexiconBlockProblems(declaration.lexicon), ...observeBlockProblems(declaration.observe));
|
|
162
|
-
if (declaration.browser !== undefined && declaration.browser !== true)
|
|
163
|
-
bad.push('browser is `true` when the app has a browser journey (slot app.browser), and is left out otherwise');
|
|
164
|
-
if (declaration.rulePacks !== undefined && (!Array.isArray(declaration.rulePacks) || declaration.rulePacks.length === 0 || declaration.rulePacks.some((name) => typeof name !== 'string' || !RULE_PACK_NAME.test(name)) || new Set(declaration.rulePacks).size !== declaration.rulePacks.length))
|
|
165
|
-
bad.push('rulePacks is a non-empty list of the installed rule pack packages the app adds its laws with, each once (PROJECT-LINT-3)');
|
|
166
|
-
if (declaration.modules !== undefined && declaration.modules !== 'data')
|
|
167
|
-
bad.push('modules is `"data"` when the app keeps its modules as data (seeds, no rendered registry package), and is left out otherwise');
|
|
168
|
-
if (declaration.kind !== APP_KIND)
|
|
169
|
-
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)`);
|
|
170
|
-
if (!isPlainObject(declaration.sides) || Object.keys(declaration.sides).sort(byCodeUnit).join() !== profiles.join()) {
|
|
171
|
-
bad.push('sides must declare exactly be and fe');
|
|
172
|
-
return bad;
|
|
173
|
-
}
|
|
174
|
-
const names = new Map();
|
|
175
|
-
for (const side of profiles)
|
|
176
|
-
bad.push(...declarationSideProblems(side, declaration.sides[side], names));
|
|
177
|
-
return bad;
|
|
178
|
-
}
|
|
179
|
-
/** Shape problems of a parsed hfs.json, in the words of modules/schemas/hfs-repo.schema.yaml. */
|
|
180
|
-
export function declarationShapeProblems(declaration, profiles) {
|
|
181
|
-
const bad = [];
|
|
182
|
-
if (!isPlainObject(declaration))
|
|
183
|
-
return ['hfs.json is not an object'];
|
|
184
|
-
if (!(Number.isInteger(declaration.hfs) && declaration.hfs >= 1))
|
|
185
|
-
bad.push('hfs must be the pinned manifest major (an integer, 1 or more)');
|
|
186
|
-
if (!NAME.test(String(declaration.project)))
|
|
187
|
-
bad.push('project must be a project name');
|
|
188
|
-
if (declaration.kind === RUNTIME_KIND) {
|
|
189
|
-
for (const key of Object.keys(declaration))
|
|
190
|
-
if (!RUNTIME_DECLARATION_KEYS.has(key))
|
|
191
|
-
bad.push(`unknown key ${key} (a runtime declaration is {hfs, kind, project})`);
|
|
192
|
-
return bad;
|
|
193
|
-
}
|
|
194
|
-
bad.push(...productDeclarationProblems(declaration, profiles));
|
|
195
|
-
return bad;
|
|
196
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { judgedInEdition } from './edition-slots.mjs';
|
|
2
|
-
/** The problems of a side's `optionalSlots` and `patterns` against the manifest. */
|
|
3
|
-
export function optionalSlotProblems(manifest, side, s) {
|
|
4
|
-
const bad = [];
|
|
5
|
-
for (const id of s.optionalSlots ?? []) {
|
|
6
|
-
const slot = manifest.slots.find((candidate) => candidate.id === id);
|
|
7
|
-
if (!slot?.profiles.includes(side))
|
|
8
|
-
bad.push(`sides.${side}.optionalSlots names ${id}, which is not a ${side} slot`);
|
|
9
|
-
else if (slot.presence !== 'opt-in')
|
|
10
|
-
bad.push(`sides.${side}.optionalSlots names ${id}, which is ${slot.presence}, not opt-in`);
|
|
11
|
-
else if (slot.appKind !== undefined)
|
|
12
|
-
bad.push(`sides.${side}.optionalSlots names ${id}; an app of kind ${slot.appKind} enables it`);
|
|
13
|
-
}
|
|
14
|
-
for (const name of s.patterns ?? []) {
|
|
15
|
-
const ownsSlot = manifest.slots.some((slot) => slot.profiles.includes(side) && slot.pattern === name);
|
|
16
|
-
const ownsProof = Object.hasOwn(manifest.ruleParams?.[side]?.patternScenarios ?? {}, name);
|
|
17
|
-
if (!ownsSlot && !ownsProof)
|
|
18
|
-
bad.push(`sides.${side}.patterns names ${name}, which neither a ${side} slot nor its proof scenario catalog declares`);
|
|
19
|
-
}
|
|
20
|
-
if (s.kinds !== undefined && side !== 'be')
|
|
21
|
-
bad.push(`sides.${side}.kinds belongs to the be side`);
|
|
22
|
-
for (const kind of s.kinds ?? []) {
|
|
23
|
-
if (!(manifest.triggerKinds ?? []).includes(kind))
|
|
24
|
-
bad.push(`sides.${side}.kinds names ${kind}, which is not one of triggerKinds (${(manifest.triggerKinds ?? []).join(', ')})`);
|
|
25
|
-
}
|
|
26
|
-
return bad;
|
|
27
|
-
}
|
|
28
|
-
/** The problems of a side's `backing` list: every name is admitted by ruleParams.be.backing in this edition. */
|
|
29
|
-
export function backingProblems(manifest, side, s, edition = 'full') {
|
|
30
|
-
const services = Object.entries(manifest.ruleParams?.be?.backing ?? {})
|
|
31
|
-
.filter(([, entry]) => judgedInEdition(entry, edition)).map(([name]) => name);
|
|
32
|
-
return (s.backing ?? []).filter((name) => !services.includes(name))
|
|
33
|
-
.map((name) => `sides.${side}.backing names ${name}, which is not admitted in edition ${edition} by ruleParams.be.backing (${services.join(', ')})`);
|
|
34
|
-
}
|
|
35
|
-
/** The problems of the shape of a side's `patterns` list (a unique list of pattern names). */
|
|
36
|
-
export function patternShapeProblems(s, at, namePattern) {
|
|
37
|
-
const list = s.patterns;
|
|
38
|
-
if (list === undefined)
|
|
39
|
-
return [];
|
|
40
|
-
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`];
|
|
41
|
-
}
|
|
42
|
-
/** The problems of the shape of a side's `kinds` list (a unique list of trigger kind names). */
|
|
43
|
-
export function kindShapeProblems(s, at, namePattern) {
|
|
44
|
-
const list = s.kinds;
|
|
45
|
-
if (list === undefined)
|
|
46
|
-
return [];
|
|
47
|
-
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`];
|
|
48
|
-
}
|
|
49
|
-
/** 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?}). */
|
|
50
|
-
export function kindParamProblems(be, triggerKinds) {
|
|
51
|
-
const kebab = /^[a-z][a-z0-9-]*$/;
|
|
52
|
-
const names = (list) => Array.isArray(list) && list.every((value) => kebab.test(String(value))) && new Set(list).size === list.length;
|
|
53
|
-
const bad = [];
|
|
54
|
-
const patterns = be.kindPatterns;
|
|
55
|
-
if (patterns === null || typeof patterns !== 'object' || Array.isArray(patterns) || !Object.entries(patterns).every(([kind, list]) => (triggerKinds ?? []).includes(kind) && names(list)))
|
|
56
|
-
bad.push('ruleParams.be.kindPatterns must map a trigger kind to a unique list of pattern names');
|
|
57
|
-
const nouns = be.addKinds;
|
|
58
|
-
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] !== '')));
|
|
59
|
-
if (nouns === null || typeof nouns !== 'object' || Array.isArray(nouns) || !Object.entries(nouns).every(([noun, spec]) => kebab.test(noun) && nounOk(spec)))
|
|
60
|
-
bad.push('ruleParams.be.addKinds must map a noun to {topic, variable, patterns, trigger?, needs?, also?, defaults?}');
|
|
61
|
-
return bad;
|
|
62
|
-
}
|
|
63
|
-
/** The problems of `ruleParams.be.patternScenarios`: a pattern name to a non-empty list of unique kebab-case scenario ids. */
|
|
64
|
-
export function scenarioProblem(scenarios) {
|
|
65
|
-
const kebab = /^[a-z][a-z0-9-]*$/;
|
|
66
|
-
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);
|
|
67
|
-
return ok ? [] : ['ruleParams.be.patternScenarios must map a pattern name to a non-empty list of unique kebab-case scenario ids'];
|
|
68
|
-
}
|
|
69
|
-
/** The problems of the `trigger` of a slot against the manifest's `triggerKinds`: a known kind, on a feature-tier slot only. */
|
|
70
|
-
export function triggerProblems(slot, triggerKinds) {
|
|
71
|
-
if (slot.trigger === undefined)
|
|
72
|
-
return [];
|
|
73
|
-
const bad = [];
|
|
74
|
-
if (!(triggerKinds ?? []).includes(slot.trigger))
|
|
75
|
-
bad.push(`slot ${slot.id}: trigger ${slot.trigger} is not one of triggerKinds`);
|
|
76
|
-
if (slot.tier !== 'feature')
|
|
77
|
-
bad.push(`slot ${slot.id}: a trigger belongs to a feature-tier slot`);
|
|
78
|
-
return bad;
|
|
79
|
-
}
|
|
80
|
-
/** 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. */
|
|
81
|
-
export function declaredSlotEnabled(slot, repo) {
|
|
82
|
-
if (slot.appKind !== undefined)
|
|
83
|
-
return repo.apps.some((app) => app.kind === slot.appKind);
|
|
84
|
-
// A provider declared on any connection (be owns them all today) enables the provider slots of every profile: repo.providers
|
|
85
|
-
// is the app-wide union the declaration resolver computed; a hand-built repo falls back to its own connections.
|
|
86
|
-
if (slot.provider !== undefined)
|
|
87
|
-
return (repo.providers ?? (repo.connections ?? []).map((connection) => connection.provider)).includes(slot.provider);
|
|
88
|
-
return repo.optionalSlots.includes(slot.id) || (slot.pattern !== undefined && (repo.patterns ?? []).includes(slot.pattern));
|
|
89
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
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
|
-
// Lite uses provider adapters and declares Docker Swarm production infrastructure (owner:lite-production-swarm, ruling:R212/case-4).
|
|
4
|
-
// Its overlays exclude the e2e world, and every slot keeps its own `tests`.
|
|
5
|
-
import { isPlainObject } from '../../engine/plain-object.mjs';
|
|
6
|
-
import { EDITIONS } from './manifest-shape.mjs';
|
|
7
|
-
/** The presence of `slot` under edition lite for `profile`: `litePresence`, else the slot's own presence. */
|
|
8
|
-
export function litePresenceOf(slot, profile) {
|
|
9
|
-
const lp = slot.litePresence;
|
|
10
|
-
if (lp === undefined)
|
|
11
|
-
return slot.presence;
|
|
12
|
-
return isPlainObject(lp) ? (lp[profile] ?? slot.presence) : lp;
|
|
13
|
-
}
|
|
14
|
-
/** Whether `slot` exists under `edition` of `manifest` (default: the manifest's own editions). */
|
|
15
|
-
export function slotInEdition(manifest, slot, edition) {
|
|
16
|
-
return (slot.editions ?? manifest.editions ?? EDITIONS).includes(edition);
|
|
17
|
-
}
|
|
18
|
-
/** The slot as `edition` sees it: lite overlays its data, presence and tracking; `tests` stays the slot's own (lite keeps the unit specs). */
|
|
19
|
-
export function effectiveSlot(slot, profile, edition) {
|
|
20
|
-
if (edition !== 'lite')
|
|
21
|
-
return slot;
|
|
22
|
-
const { lite, litePresence, ...base } = slot;
|
|
23
|
-
const presence = litePresenceOf(slot, profile);
|
|
24
|
-
let tracked = slot.tracked;
|
|
25
|
-
if (presence === 'forbidden')
|
|
26
|
-
tracked = 'external';
|
|
27
|
-
else if (tracked === 'external')
|
|
28
|
-
tracked = 'tracked';
|
|
29
|
-
return { ...base, ...lite, presence, tracked };
|
|
30
|
-
}
|
|
31
|
-
/** The template group starci app sync renders `slot` from under `edition`: `liteManagedBy` (else `managedBy`) in lite, `managedBy` otherwise; undefined when unmanaged. */
|
|
32
|
-
export function managedGroupOf(slot, edition) {
|
|
33
|
-
return edition === 'lite' ? (slot.liteManagedBy ?? slot.managedBy) : slot.managedBy;
|
|
34
|
-
}
|
|
35
|
-
/** The declared edition and the vocabulary against which it is validated. */
|
|
36
|
-
export function declarationEdition(manifest, declaration) {
|
|
37
|
-
const edition = declaration.edition === undefined ? 'full' : declaration.edition;
|
|
38
|
-
const known = manifest.editions ?? EDITIONS;
|
|
39
|
-
return { edition, known, valid: known.includes(edition) };
|
|
40
|
-
}
|
|
41
|
-
/** Problems of an optional rule-catalog `editions` list, in the catalog schema's words. */
|
|
42
|
-
export function ruleEditionProblems(rule, label) {
|
|
43
|
-
if (rule.editions === undefined)
|
|
44
|
-
return [];
|
|
45
|
-
const bad = [];
|
|
46
|
-
if (!Array.isArray(rule.editions) || !rule.editions.length)
|
|
47
|
-
return [`${label}.editions must be a non-empty list`];
|
|
48
|
-
for (const value of rule.editions)
|
|
49
|
-
if (!EDITIONS.includes(value))
|
|
50
|
-
bad.push(`${label}.editions has ${JSON.stringify(value)}, not one of ${EDITIONS.join(', ')}`);
|
|
51
|
-
if (new Set(rule.editions).size !== rule.editions.length)
|
|
52
|
-
bad.push(`${label}.editions repeats a value`);
|
|
53
|
-
return bad;
|
|
54
|
-
}
|
|
55
|
-
/** Whether a catalogued rule owner judges its finding under `edition`; uncatalogued codes always remain judged. */
|
|
56
|
-
export function judgedInEdition(owner, edition = 'full') {
|
|
57
|
-
return !owner?.editions || owner.editions.includes(edition);
|
|
58
|
-
}
|
|
59
|
-
/** 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. */
|
|
60
|
-
export function enforcerJudgedInEdition(rules, kind, id, edition = 'full') {
|
|
61
|
-
const owners = rules.filter((rule) => rule.enforcers.some((enforcer) => enforcer.kind === kind && enforcer.id === id));
|
|
62
|
-
return owners.every((rule) => judgedInEdition(rule, edition) && rule.enforcers.filter((enforcer) => enforcer.kind === kind && enforcer.id === id).every((enforcer) => judgedInEdition(enforcer, edition)));
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* A frozen copy of one profile's parameters, with its lite overrides applied only in the lite edition. A lite key whose base
|
|
66
|
-
* value and override are both maps merges one level deep (lite.infraOwners restates only the specifiers whose owner changes);
|
|
67
|
-
* any other value replaces the base.
|
|
68
|
-
*/
|
|
69
|
-
export function editionRuleParams(params, edition) {
|
|
70
|
-
const { lite, ...base } = params;
|
|
71
|
-
const merged = edition === 'lite' && lite ? { ...base } : base;
|
|
72
|
-
if (edition === 'lite' && lite) {
|
|
73
|
-
for (const [key, value] of Object.entries(lite))
|
|
74
|
-
merged[key] = isPlainObject(value) && isPlainObject(base[key]) ? { ...base[key], ...value } : value;
|
|
75
|
-
}
|
|
76
|
-
const deepFreeze = (value) => { if (value && typeof value === 'object') {
|
|
77
|
-
Object.values(value).forEach(deepFreeze);
|
|
78
|
-
} return Object.freeze(value); };
|
|
79
|
-
return deepFreeze(structuredClone(merged));
|
|
80
|
-
}
|