@starci/eslint-canon-be 3.18.3 → 3.19.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.
Files changed (208) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/comments.js +1 -1
  3. package/dist/explicit-surface.js +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/jwt-alg.js +1 -1
  6. package/dist/lib/edition.d.ts +1 -1
  7. package/dist/lib/edition.js +1 -1
  8. package/dist/lib/hfs.d.ts +0 -6
  9. package/dist/lib/hfs.js +7 -5
  10. package/dist/lib/runtime-root.d.ts +6 -1
  11. package/dist/lib/runtime-root.js +8 -2
  12. package/dist/lib/subject-values.js +1 -1
  13. package/dist/module-layering.js +2 -2
  14. package/dist/project-graph.js +1 -1
  15. package/dist/third-party-owner.js +1 -1
  16. package/package.json +3 -1
  17. package/runtime/bundle.json +1 -190
  18. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  19. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  20. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  21. package/runtime/config.example.yaml +0 -194
  22. package/runtime/engine/by-code-unit.mjs +0 -12
  23. package/runtime/engine/config.mjs +0 -461
  24. package/runtime/engine/invalid-config.mjs +0 -15
  25. package/runtime/engine/model-config.mjs +0 -112
  26. package/runtime/engine/orca-config.mjs +0 -34
  27. package/runtime/engine/plain-object.mjs +0 -5
  28. package/runtime/engine/release-config.mjs +0 -32
  29. package/runtime/engine/removed-vocabulary.mjs +0 -27
  30. package/runtime/engine/resources-config.mjs +0 -59
  31. package/runtime/engine/runtime-root.mjs +0 -138
  32. package/runtime/engine/secrets.mjs +0 -202
  33. package/runtime/engine/sonar-config.mjs +0 -24
  34. package/runtime/engine/temp-root.mjs +0 -26
  35. package/runtime/engine/yaml.mjs +0 -161
  36. package/runtime/knowledge/grammars/index.yaml +0 -114
  37. package/runtime/knowledge/hfs/canon-pins.yaml +0 -716
  38. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  39. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  40. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  41. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  42. package/runtime/knowledge/sonar-gate.yaml +0 -151
  43. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  44. package/runtime/modules/models/registry.yaml +0 -221
  45. package/runtime/modules/models/runtimes.yaml +0 -556
  46. package/runtime/modules/models/tiers.yaml +0 -66
  47. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  48. package/runtime/scripts/api/git/config-get.mjs +0 -9
  49. package/runtime/scripts/api/git/diff.mjs +0 -4
  50. package/runtime/scripts/api/git/lib.mjs +0 -80
  51. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  52. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  53. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  54. package/runtime/scripts/api/git/remote.mjs +0 -4
  55. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  56. package/runtime/scripts/api/git/show.mjs +0 -5
  57. package/runtime/scripts/api/git/tag.mjs +0 -4
  58. package/runtime/scripts/hfs/allows.mjs +0 -77
  59. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  60. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  61. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  62. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  63. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  64. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  65. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  66. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  67. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  68. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  69. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  70. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  71. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  72. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  73. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  74. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  75. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  76. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  77. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  78. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  79. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  80. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  81. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  82. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  83. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  84. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  85. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  86. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  87. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  88. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  89. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  90. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  91. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  92. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  93. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  94. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  95. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  96. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  97. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  98. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  99. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  100. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  101. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  102. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  103. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  104. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  105. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  106. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  107. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  108. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  109. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  110. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  111. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  112. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  113. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  114. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  115. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  116. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  117. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  118. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  119. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  120. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  121. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  122. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  123. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  124. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  125. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  126. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  127. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  128. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  129. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  130. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  132. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  133. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  134. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  135. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  136. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  137. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  138. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  139. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  140. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  141. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  142. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  143. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  144. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  145. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  146. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  147. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  148. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  149. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  150. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  151. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  152. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  153. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  154. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  155. package/runtime/scripts/hfs/param-names.mjs +0 -13
  156. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  157. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  158. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  159. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  160. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  161. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  162. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  163. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  164. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  165. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  166. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  167. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  168. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  169. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  170. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  171. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  172. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  173. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  174. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  175. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  176. package/runtime/scripts/hfs/slots.mjs +0 -306
  177. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  178. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  179. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  180. package/runtime/scripts/hfs/view.mjs +0 -180
  181. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  182. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  183. package/runtime/scripts/lib/env.mjs +0 -18
  184. package/runtime/scripts/lib/event-contract.mjs +0 -102
  185. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  186. package/runtime/scripts/lib/git.mjs +0 -35
  187. package/runtime/scripts/lib/glob.mjs +0 -32
  188. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  189. package/runtime/scripts/lib/i18n.mjs +0 -82
  190. package/runtime/scripts/lib/in-order.mjs +0 -90
  191. package/runtime/scripts/lib/json-clone.mjs +0 -70
  192. package/runtime/scripts/lib/json.mjs +0 -44
  193. package/runtime/scripts/lib/language.mjs +0 -233
  194. package/runtime/scripts/lib/list.mjs +0 -26
  195. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  196. package/runtime/scripts/lib/package-at.mjs +0 -62
  197. package/runtime/scripts/lib/path-key.mjs +0 -124
  198. package/runtime/scripts/lib/read-text.mjs +0 -47
  199. package/runtime/scripts/lib/regex.mjs +0 -3
  200. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  201. package/runtime/scripts/lib/same-text.mjs +0 -4
  202. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  203. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  204. package/runtime/scripts/lib/stack-services.mjs +0 -191
  205. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  206. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  207. package/runtime/scripts/lib/walk.mjs +0 -45
  208. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,458 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { skillRoot } from '../../engine/runtime-root.mjs';
4
- import { parseYamlCached } from '../lib/yaml-cached.mjs';
5
- import { jsonClone } from '../lib/json-clone.mjs';
6
- import { byCodeUnit } from '../lib/list.mjs';
7
- import { isPlainObject } from '../../engine/plain-object.mjs';
8
- import { SEMVER } from './manifest-shape.mjs';
9
- import { enforcerJudgedInEdition, judgedInEdition, ruleEditionProblems } from './edition-slots.mjs';
10
- import { fail } from './slot-errors.mjs';
11
- const HFS_RULES_FILE = 'knowledge/hfs/rules.yaml';
12
- const RULE_GATES = Object.freeze(['pre-commit', 'pre-push', 'settle', 'land', 'ci', 'sonar', 'runtime']);
13
- const ENFORCER_FAMILIES = Object.freeze(['eslint-be', 'eslint-fe', 'eslint-grammar-core', 'stylelint', 'machine', 'hfs', 'work-validate', 'sonar', 'runtime']);
14
- const RULE_KINDS = Object.freeze(['codemod', 'lint', 'check', 'design']);
15
- const FINDING_CODE = /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$/;
16
- const ENFORCER_ID = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
17
- const FILE_ENFORCERS = new Set(['machine', 'hfs', 'work-validate', 'sonar', 'runtime']);
18
- /**
19
- * The enforcer kinds that run only inside the StarCi runtime repository (`starci runtime check`, `starci work`): no published package carries
20
- * them, so no package spec can hold them (owner ruling no-runtime-specs: the runtime has no specs of its own; the package clean-test and the
21
- * scaffold e2e are its tests), and no example app is a product they judge. A rule is runtime-judged when every enforcer it has is of these kinds.
22
- */
23
- export const RUNTIME_ONLY_ENFORCERS = Object.freeze(['work-validate', 'runtime']);
24
- const RULE_KEYS = new Set(['id', 'code', 'law', 'scope', 'kinds', 'gates', 'failureCodes', 'editions', 'codeEditions', 'enforcers', 'cases', 'docs', 'exemplifiedBy', 'proves', 'witness', 'editionWhy', 'amendedBy', 'templateNa']);
25
- const CASE_KEYS = new Set(['id', 'date', 'source', 'ruling', 'quote', 'supersedes', 'status', 'staleWhen', 'amendedBy']);
26
- const CASE_DATE = /^\d{4}-\d{2}-\d{2}$/;
27
- const ENFORCER_KEYS = new Set(['kind', 'id', 'status', 'at', 'editions', 'editionWhy']);
28
- const CASE_ID = /case-[1-9]\d*/;
29
- const RULING_REFERENCE = new RegExp(String.raw `(?:ruling:)?R\d{2,3}(?:/${CASE_ID.source})?`);
30
- const OWNER_REFERENCE = /owner:[a-z][a-z0-9]*(?:-[a-z0-9]+)*/;
31
- const CASE_REFERENCE = new RegExp(`^(?:${CASE_ID.source}|${RULING_REFERENCE.source}|${OWNER_REFERENCE.source})$`);
32
- const EVIDENCE_KEYS = new Set(['path', 'edition', 'editions']);
33
- const PROOF_KEYS = new Set([...EVIDENCE_KEYS, 'codes', 'fixtures']);
34
- const WITNESS_KEYS = new Set(['edition', 'base', 'mutate', 'expect']);
35
- const MUTATION_KEYS = new Set(['op', 'path', 'content']);
36
- function textProblem(value, label, bad) {
37
- if (typeof value !== 'string' || !value.trim())
38
- bad.push(`${label} must be non-empty text`);
39
- }
40
- function relativePathProblem(value, label, bad, anchor = false) {
41
- const parts = typeof value === 'string' ? value.split('#') : [];
42
- const file = parts[0];
43
- const valid = typeof value === 'string' && value.trim() === value && value.length > 0
44
- && !value.includes('\0') && !/[\r\n\\]/.test(value) && !/^(?:\/|[a-z][a-z0-9+.-]*:)/i.test(value) && !file.includes(':')
45
- && !file.split('/').some((part) => ['', '.', '..'].includes(part))
46
- && (parts.length === 1 || (anchor && parts.length === 2 && /^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(parts[1])));
47
- if (!valid)
48
- bad.push(`${label} must be a repository-relative path${anchor ? ' with an optional #anchor' : ''}`);
49
- }
50
- function unknownKeys(item, allowed, label, bad) {
51
- for (const key of Object.keys(item))
52
- if (!allowed.has(key))
53
- bad.push(`${label} has unknown key ${key}`);
54
- }
55
- function nonEmptyList(value, label, bad) {
56
- if (!Array.isArray(value) || !value.length) {
57
- bad.push(`${label} must be a non-empty list`);
58
- return false;
59
- }
60
- const normalized = value.map((value) => JSON.stringify(value, (_key, item) => isPlainObject(item) ? Object.fromEntries(Object.keys(item).sort(byCodeUnit).map((key) => [key, item[key]])) : item));
61
- if (new Set(normalized).size !== value.length)
62
- bad.push(`${label} repeats a value`);
63
- return true;
64
- }
65
- function optionalText(item, key, label, bad) {
66
- if (item[key] !== undefined)
67
- textProblem(item[key], `${label}.${key}`, bad);
68
- }
69
- function evidenceEditionProblems(item, label, bad) {
70
- if (item.edition !== undefined && !['full', 'lite'].includes(item.edition))
71
- bad.push(`${label}.edition must be full or lite`);
72
- bad.push(...ruleEditionProblems(item, label));
73
- if (item.edition !== undefined && item.editions !== undefined)
74
- bad.push(`${label} names edition or editions, not both`);
75
- }
76
- function codeListProblems(codes, label, bad) {
77
- if (!nonEmptyList(codes, label, bad))
78
- return;
79
- for (const code of codes)
80
- if (typeof code !== 'string' || !FINDING_CODE.test(code))
81
- bad.push(`${label} must contain UPPER_SNAKE finding codes`);
82
- }
83
- function evidenceMapProblems(item, key, label, bad) {
84
- unknownKeys(item, key === 'docs' ? EVIDENCE_KEYS : PROOF_KEYS, label, bad);
85
- relativePathProblem(item.path, `${label}.path`, bad, key === 'docs');
86
- evidenceEditionProblems(item, label, bad);
87
- if (item.codes !== undefined)
88
- codeListProblems(item.codes, `${label}.codes`, bad);
89
- if (item.fixtures !== undefined && nonEmptyList(item.fixtures, `${label}.fixtures`, bad))
90
- item.fixtures.forEach((value) => textProblem(value, `${label}.fixtures`, bad));
91
- }
92
- function evidenceProblems(rule, key, label, bad) {
93
- if (rule[key] === undefined || !nonEmptyList(rule[key], `${label}.${key}`, bad))
94
- return;
95
- rule[key].forEach((item, index) => {
96
- const at = `${label}.${key}[${index}]`;
97
- if (typeof item === 'string') {
98
- relativePathProblem(item, at, bad, key === 'docs');
99
- return;
100
- }
101
- if (!isPlainObject(item)) {
102
- bad.push(`${at} must be a path or a map`);
103
- return;
104
- }
105
- evidenceMapProblems(item, key, at, bad);
106
- });
107
- }
108
- function mutationProblems(item, label, bad) {
109
- if (!isPlainObject(item)) {
110
- bad.push(`${label} must be a map`);
111
- return;
112
- }
113
- unknownKeys(item, MUTATION_KEYS, label, bad);
114
- if (!['add', 'edit', 'delete'].includes(item.op))
115
- bad.push(`${label}.op must be add, edit or delete`);
116
- relativePathProblem(item.path, `${label}.path`, bad);
117
- if (['add', 'edit'].includes(item.op) && typeof item.content !== 'string')
118
- bad.push(`${label}.content must be text for add or edit`);
119
- if (item.op === 'delete' && item.content !== undefined)
120
- bad.push(`${label}.content is absent for delete`);
121
- }
122
- function witnessEntryProblems(item, label, bad) {
123
- if (!isPlainObject(item)) {
124
- bad.push(`${label} must be a map`);
125
- return;
126
- }
127
- if (Object.hasOwn(item, 'path')) {
128
- evidenceMapProblems(item, 'proves', label, bad);
129
- return;
130
- }
131
- unknownKeys(item, WITNESS_KEYS, label, bad);
132
- if (!['full', 'lite'].includes(item.edition))
133
- bad.push(`${label}.edition must be full or lite`);
134
- relativePathProblem(item.base, `${label}.base`, bad);
135
- codeListProblems(item.expect, `${label}.expect`, bad);
136
- if (nonEmptyList(item.mutate, `${label}.mutate`, bad))
137
- item.mutate.forEach((mutation, index) => mutationProblems(mutation, `${label}.mutate[${index}]`, bad));
138
- }
139
- function witnessProblems(rule, label, bad) {
140
- const value = rule.witness;
141
- if (value === undefined)
142
- return;
143
- const at = `${label}.witness`;
144
- if (!nonEmptyList(value, at, bad))
145
- return;
146
- value.forEach((item, index) => witnessEntryProblems(item, `${at}[${index}]`, bad));
147
- }
148
- function caseReferenceProblems(value, label, bad) {
149
- const values = Array.isArray(value) ? value : [value];
150
- if (!nonEmptyList(values, label, bad))
151
- return;
152
- for (const ref of values)
153
- if (typeof ref !== 'string' || !CASE_REFERENCE.test(ref))
154
- bad.push(`${label} must name case-N, R<id>[/case-N], ruling:R<id>[/case-N] or owner:<id>`);
155
- }
156
- function caseTransitionProblems(item, label, bad) {
157
- if (item.status !== undefined && !['live', 'superseded', 'amended'].includes(item.status))
158
- bad.push(`${label}.status must be live, superseded or amended`);
159
- for (const key of ['supersedes', 'amendedBy'])
160
- if (item[key] !== undefined)
161
- caseReferenceProblems(item[key], `${label}.${key}`, bad);
162
- if (item.staleWhen !== undefined && nonEmptyList(item.staleWhen, `${label}.staleWhen`, bad)) {
163
- for (const pattern of item.staleWhen) {
164
- if (typeof pattern !== 'string' || !pattern.trim()) {
165
- bad.push(`${label}.staleWhen must contain non-empty regex strings`);
166
- continue;
167
- }
168
- try {
169
- new RegExp(pattern, 'i');
170
- }
171
- catch {
172
- bad.push(`${label}.staleWhen has an invalid regex ${JSON.stringify(pattern)}`);
173
- }
174
- }
175
- }
176
- }
177
- function vocabularyProblems(catalog, key, names, bad) {
178
- if (!isPlainObject(catalog[key])) {
179
- bad.push(`${key} must be a map`);
180
- return;
181
- }
182
- if (JSON.stringify(Object.keys(catalog[key])) !== JSON.stringify(names))
183
- bad.push(`${key} must list exactly ${names.join(', ')} in that order`);
184
- for (const [name, text] of Object.entries(catalog[key])) {
185
- if (typeof text !== 'string' || !text.trim())
186
- bad.push(`${key}.${name} needs a description`);
187
- }
188
- }
189
- function checkCatalogHeader(catalog, bad) {
190
- for (const key of Object.keys(catalog)) {
191
- if (!['schema', 'version', 'gates', 'enforcerKinds', 'rules'].includes(key))
192
- bad.push(`unknown top-level key ${key}`);
193
- }
194
- const schemaOk = /^starci\/hfs-rules@\d+$/.test(String(catalog.schema));
195
- if (!schemaOk)
196
- bad.push('schema must be starci/hfs-rules@<major>');
197
- if (!SEMVER.test(String(catalog.version)))
198
- bad.push('version must be MAJOR.MINOR.PATCH');
199
- else if (schemaOk && catalog.schema.split('@')[1] !== catalog.version.split('.')[0])
200
- bad.push('the major of version must equal the number after @ in schema');
201
- vocabularyProblems(catalog, 'gates', RULE_GATES, bad);
202
- vocabularyProblems(catalog, 'enforcerKinds', ENFORCER_FAMILIES, bad);
203
- }
204
- function enumListProblems(rule, label, key, allowed, bad) {
205
- if (!Array.isArray(rule[key]) || !rule[key].length) {
206
- bad.push(`${label}.${key} must be a non-empty list`);
207
- return [];
208
- }
209
- for (const value of rule[key]) {
210
- if (!allowed.includes(value))
211
- bad.push(`${label}.${key} has ${JSON.stringify(value)}, not one of ${allowed.join(', ')}`);
212
- }
213
- if (new Set(rule[key]).size !== rule[key].length)
214
- bad.push(`${label}.${key} repeats a value`);
215
- return rule[key];
216
- }
217
- function checkRuleIdentity(rule, index, catalog, at, label, bad) {
218
- if (!/^R\d{2,3}$/.test(String(rule.id)))
219
- bad.push(`${at}.id must be R<two or three digits>`);
220
- else if (index > 0 && typeof catalog.rules[index - 1]?.id === 'string' && Number(rule.id.slice(1)) <= Number(catalog.rules[index - 1].id.slice(1)))
221
- bad.push(`${label} is out of order: ids must increase, and ${catalog.rules[index - 1].id} comes before it`);
222
- if (!FINDING_CODE.test(String(rule.code)))
223
- bad.push(`${label}.code must be an UPPER_SNAKE finding code`);
224
- }
225
- function checkRuleText(rule, label, bad) {
226
- if (typeof rule.law !== 'string' || !rule.law.trim())
227
- bad.push(`${label}.law is missing`);
228
- if (typeof rule.law === 'string' && rule.law.includes('\n'))
229
- bad.push(`${label}.law must be one line`);
230
- if (rule.scope !== undefined && rule.scope !== 'runtime')
231
- bad.push(`${label}.scope is absent or runtime`);
232
- }
233
- /** The dated owner cases of a rule: each {id case-N, date, source owner, ruling, quote?}, ids unique (an owner ruling recorded where the law lives). */
234
- function checkRuleCases(rule, label, bad) {
235
- if (rule.cases === undefined)
236
- return;
237
- if (!Array.isArray(rule.cases) || !rule.cases.length) {
238
- bad.push(`${label}.cases must be a non-empty list`);
239
- return;
240
- }
241
- const ids = new Set();
242
- rule.cases.forEach((item, index) => {
243
- const at = `${label}.cases[${index}]`;
244
- if (!isPlainObject(item)) {
245
- bad.push(`${at} is not a map`);
246
- return;
247
- }
248
- for (const key of Object.keys(item))
249
- if (!CASE_KEYS.has(key))
250
- bad.push(`${at} has unknown key ${key}`);
251
- if (typeof item.id !== 'string' || !/^case-[1-9]\d*$/.test(item.id) || ids.has(item.id))
252
- bad.push(`${at}.id must be a unique case-N`);
253
- ids.add(item.id);
254
- if (typeof item.date !== 'string' || !CASE_DATE.test(item.date))
255
- bad.push(`${at}.date must be YYYY-MM-DD`);
256
- if (item.source !== 'owner')
257
- bad.push(`${at}.source must be owner`);
258
- for (const key of ['ruling', ...(item.quote === undefined ? [] : ['quote'])])
259
- if (typeof item[key] !== 'string' || !item[key].trim())
260
- bad.push(`${at}.${key} must be text`);
261
- caseTransitionProblems(item, at, bad);
262
- });
263
- }
264
- function checkRuleGates(rule, label, gates, bad) {
265
- if (!gates.length)
266
- return;
267
- const releaseGate = gates.includes('land') || gates.includes('ci');
268
- const runtimeGate = rule.scope === 'runtime' && gates.includes('runtime');
269
- if (!releaseGate && !runtimeGate)
270
- bad.push(`${label} must run at land or ci or, for runtime scope, the runtime gate`);
271
- }
272
- function checkRuleFailureCodes(rule, label, codeOwner, bad) {
273
- if (!Array.isArray(rule.failureCodes) || !rule.failureCodes.length || !rule.failureCodes.every((code) => FINDING_CODE.test(String(code)))) {
274
- bad.push(`${label}.failureCodes must be a non-empty list of UPPER_SNAKE codes`);
275
- return;
276
- }
277
- if (rule.failureCodes[0] !== rule.code)
278
- bad.push(`${label}.failureCodes must start with the rule's own code ${rule.code}`);
279
- if (new Set(rule.failureCodes).size !== rule.failureCodes.length)
280
- bad.push(`${label}.failureCodes repeats a code`);
281
- for (const code of rule.failureCodes) {
282
- if (codeOwner.has(code) && codeOwner.get(code) !== label)
283
- bad.push(`${label} names ${code}, which ${codeOwner.get(code)} already owns`);
284
- codeOwner.set(code, label);
285
- }
286
- }
287
- function checkCodeEditions(rule, label, bad) {
288
- const value = rule.codeEditions;
289
- if (value === undefined)
290
- return;
291
- if (!isPlainObject(value) || !Object.keys(value).length) {
292
- bad.push(`${label}.codeEditions must be a non-empty map`);
293
- return;
294
- }
295
- const editions = Array.isArray(rule.editions) ? rule.editions : ['full', 'lite'];
296
- for (const [code, selected] of Object.entries(value)) {
297
- const at = `${label}.codeEditions.${code}`;
298
- if (!Array.isArray(rule.failureCodes) || !rule.failureCodes.includes(code))
299
- bad.push(`${at} must name a code owned by this rule`);
300
- enumListProblems({ editions: selected }, at, 'editions', ['full', 'lite'], bad);
301
- if (Array.isArray(selected) && selected.some((edition) => !editions.includes(edition)))
302
- bad.push(`${at} must be a subset of the rule's editions`);
303
- }
304
- }
305
- function checkEnforcerIdentity(enforcer, label, seen, bad) {
306
- if (!ENFORCER_FAMILIES.includes(enforcer.kind))
307
- bad.push(`${label}.kind must be one of ${ENFORCER_FAMILIES.join(', ')}`);
308
- if (!ENFORCER_ID.test(String(enforcer.id)))
309
- bad.push(`${label}.id must be kebab-case`);
310
- if (seen.has(`${enforcer.kind}:${enforcer.id}`))
311
- bad.push(`${label} repeats ${enforcer.kind}:${enforcer.id}`);
312
- seen.add(`${enforcer.kind}:${enforcer.id}`);
313
- }
314
- function checkEnforcerLocation(enforcer, label, bad) {
315
- if (enforcer.at !== undefined) {
316
- if (typeof enforcer.at !== 'string' || !enforcer.at.trim() || enforcer.at.startsWith('/') || enforcer.at.includes('..'))
317
- bad.push(`${label}.at must be a repository-relative path`);
318
- if (enforcer.status === 'planned')
319
- bad.push(`${label} is planned, so it has no file yet (at)`);
320
- if (!FILE_ENFORCERS.has(enforcer.kind))
321
- bad.push(`${label}.at belongs to a machine, hfs, work-validate, sonar or runtime enforcer only`);
322
- }
323
- else if (FILE_ENFORCERS.has(enforcer.kind) && enforcer.status !== 'planned')
324
- bad.push(`${label} exists, so it names the file (at) that emits its code`);
325
- }
326
- function checkEnforcer(enforcer, index, ruleLabel, seen, bad) {
327
- const label = `${ruleLabel}.enforcers[${index}]`;
328
- if (!isPlainObject(enforcer)) {
329
- bad.push(`${label} is not a map`);
330
- return;
331
- }
332
- for (const key of Object.keys(enforcer)) {
333
- if (!ENFORCER_KEYS.has(key))
334
- bad.push(`${label} has unknown key ${key}`);
335
- }
336
- bad.push(...ruleEditionProblems(enforcer, label));
337
- optionalText(enforcer, 'editionWhy', label, bad);
338
- checkEnforcerIdentity(enforcer, label, seen, bad);
339
- if (enforcer.status !== undefined && enforcer.status !== 'planned')
340
- bad.push(`${label}.status is either absent or planned`);
341
- checkEnforcerLocation(enforcer, label, bad);
342
- }
343
- function checkRuleEnforcers(rule, label, bad) {
344
- if (!Array.isArray(rule.enforcers) || !rule.enforcers.length) {
345
- bad.push(`${label}.enforcers must name at least one enforcer`);
346
- return;
347
- }
348
- const seen = new Set();
349
- rule.enforcers.forEach((enforcer, index) => checkEnforcer(enforcer, index, label, seen, bad));
350
- }
351
- function checkRule(rule, index, catalog, codeOwner, bad) {
352
- const at = `rules[${index}]`;
353
- if (!isPlainObject(rule)) {
354
- bad.push(`${at} is not a map`);
355
- return;
356
- }
357
- const label = typeof rule.id === 'string' ? rule.id : at;
358
- for (const key of Object.keys(rule)) {
359
- if (!RULE_KEYS.has(key))
360
- bad.push(`${label} has unknown key ${key}`);
361
- }
362
- checkRuleIdentity(rule, index, catalog, at, label, bad);
363
- checkRuleText(rule, label, bad);
364
- checkRuleCases(rule, label, bad);
365
- if (rule.amendedBy !== undefined)
366
- caseReferenceProblems(rule.amendedBy, `${label}.amendedBy`, bad);
367
- optionalText(rule, 'editionWhy', label, bad);
368
- optionalText(rule, 'templateNa', label, bad);
369
- for (const key of ['docs', 'exemplifiedBy', 'proves'])
370
- evidenceProblems(rule, key, label, bad);
371
- witnessProblems(rule, label, bad);
372
- enumListProblems(rule, label, 'kinds', RULE_KINDS, bad);
373
- bad.push(...ruleEditionProblems(rule, label));
374
- const gates = enumListProblems(rule, label, 'gates', RULE_GATES, bad);
375
- checkRuleGates(rule, label, gates, bad);
376
- checkRuleFailureCodes(rule, label, codeOwner, bad);
377
- checkCodeEditions(rule, label, bad);
378
- checkRuleEnforcers(rule, label, bad);
379
- if (Array.isArray(rule.gates)) {
380
- const hasSonar = rule.enforcers.some((enforcer) => isPlainObject(enforcer) && enforcer.kind === 'sonar');
381
- if (rule.gates.includes('sonar') !== hasSonar)
382
- bad.push(`${label}: the sonar gate and a sonar enforcer go together`);
383
- }
384
- }
385
- /** Shape and semantic problems of a parsed knowledge/hfs/rules.yaml, in the words of modules/schemas/hfs-rules.schema.yaml. */
386
- function ruleCatalogProblems(catalog) {
387
- const bad = [];
388
- if (!isPlainObject(catalog))
389
- return ['the rule catalog is not a map'];
390
- checkCatalogHeader(catalog, bad);
391
- if (!Array.isArray(catalog.rules) || !catalog.rules.length) {
392
- bad.push('rules must be a non-empty list');
393
- return bad;
394
- }
395
- const codeOwner = new Map();
396
- catalog.rules.forEach((rule, index) => checkRule(rule, index, catalog, codeOwner, bad));
397
- return bad;
398
- }
399
- const deepFreeze = (value) => { if (value && typeof value === 'object') {
400
- Object.values(value).forEach(deepFreeze);
401
- } return Object.freeze(value); };
402
- /**
403
- * The parsed and validated HFS rule catalog. `text` (or `file`, or `root`) selects the source; the default is the runtime's
404
- * own knowledge/hfs/rules.yaml. A catalog that breaks its shape or a semantic rule is refused whole (HFS_RULES_INVALID), and
405
- * so is one whose major differs from the slot manifest passed as `manifest` (HFS_MANIFEST_MAJOR_MISMATCH).
406
- * Answers: rule(id), byCode(code), forGate(gate), forEnforcer(kind, id), planned() and unbuilt().
407
- */
408
- export function loadRuleCatalog({ root = skillRoot, file = path.join(root, HFS_RULES_FILE), text, manifest } = {}) {
409
- let doc;
410
- try {
411
- doc = parseYamlCached(text ?? fs.readFileSync(file, 'utf8'));
412
- }
413
- catch (error) {
414
- fail('HFS_RULES_INVALID', `the rule catalog cannot be read (${String(error?.message ?? error).split('\n')[0]})`, { file });
415
- }
416
- const problems = ruleCatalogProblems(doc);
417
- if (problems.length) {
418
- fail('HFS_RULES_INVALID', `the rule catalog breaks its schema: ${problems.slice(0, 5).join('; ')}${problems.length > 5 ? '; and ' + (problems.length - 5) + ' more' : ''}`, { file, problems });
419
- }
420
- const [major, minor, patch] = doc.version.split('.').map(Number);
421
- if (manifest && manifest.major !== major)
422
- fail('HFS_MANIFEST_MAJOR_MISMATCH', `the rule catalog is major ${major} but the slot manifest is major ${manifest.major}`, { catalog: major, manifest: manifest.major });
423
- const list = deepFreeze(doc.rules.map((rule) => ({ ...rule, enforcers: rule.enforcers.map((enforcer) => ({ ...enforcer, planned: enforcer.status === 'planned' })) })));
424
- const byId = new Map(list.map((rule) => [rule.id, rule]));
425
- const byCode = new Map(list.flatMap((rule) => rule.failureCodes.map((code) => [code, rule])));
426
- return Object.freeze({
427
- version: doc.version, major, minor, patch,
428
- gates: deepFreeze(jsonClone(doc.gates)),
429
- enforcerKinds: deepFreeze(jsonClone(doc.enforcerKinds)),
430
- rules: list,
431
- /** The rule with this id (R01..), or null. */
432
- rule: (id) => byId.get(id) ?? null,
433
- /** The rule that owns this failure code (its own or a sub-check code), or null. */
434
- byCode: (code) => byCode.get(code) ?? null,
435
- /** Whether a finding code is judged under `edition`: codeEditions narrows its owner's editions; uncatalogued codes remain judged. */
436
- judgedIn: (code, edition = 'full') => {
437
- const owner = byCode.get(code);
438
- return judgedInEdition(owner, edition) && (!owner?.codeEditions?.[code] || owner.codeEditions[code].includes(edition));
439
- },
440
- enforcerJudgedIn: (kind, id, edition = 'full') => enforcerJudgedInEdition(list, kind, id, edition),
441
- /** The rules that run at a gate. */
442
- forGate: (gate) => list.filter((rule) => rule.gates.includes(gate)),
443
- /** The catalogued why code of a lint finding's rule id (`starci-be/<id>`, `starci-fe/<id>`), or undefined. */
444
- lintCode: (ruleId) => {
445
- const [plugin, id] = String(ruleId ?? '').split('/');
446
- const kind = (plugin === 'starci-be' && 'eslint-be') || (plugin === 'starci-fe' && 'eslint-fe') || (plugin === 'starci-grammar' && 'eslint-grammar-core') || null;
447
- return kind ? list.find((rule) => rule.enforcers.some((enforcer) => enforcer.kind === kind && enforcer.id === id))?.code : undefined;
448
- },
449
- /** The rules one enforcer judges, e.g. forEnforcer('eslint-be', 'error-home'). */
450
- forEnforcer: (kind, id) => list.filter((rule) => rule.enforcers.some((enforcer) => enforcer.kind === kind && enforcer.id === id)),
451
- /** Every enforcer still owed, as {rule, kind, id}. */
452
- planned: () => list.flatMap((rule) => rule.enforcers.filter((enforcer) => enforcer.planned).map((enforcer) => ({ rule: rule.id, kind: enforcer.kind, id: enforcer.id }))),
453
- /** The rules with no existing enforcer at all. */
454
- unbuilt: () => list.filter((rule) => rule.enforcers.every((enforcer) => enforcer.planned)),
455
- });
456
- }
457
- /** The rules of this runtime's catalog, frozen, in id order. */
458
- export const rules = (options) => loadRuleCatalog(options).rules;
@@ -1,103 +0,0 @@
1
- import { isPlainObject } from '../../engine/plain-object.mjs';
2
- import { paramNamesOk } from './param-names.mjs';
3
- import { kindParamProblems, scenarioProblem } from './declaration-slots.mjs';
4
- import { NAME, namedMapValid, PACKAGE_NAME, roleListProblems, SCHEMA_AUTHORITIES, unitRolesProblems } from './manifest-shape.mjs';
5
- import { byCodeUnit, nonemptyUniqueList } from '../lib/list.mjs';
6
- import { ruleEditionProblems } from './edition-slots.mjs';
7
- const PROFILES = ['be', 'fe'];
8
- const BE_OWN = ['infraOwners', 'eventBus', 'specDoubles', 'paramNames', 'suffixes', 'bannedSuffixes', 'contractShape', 'unitRoles', 'logicRoles', 'valueRoles', 'thinRoles', 'patternScenarios', 'kindPatterns', 'addKinds', 'backing'];
9
- const backingEntryOk = (entry) => isPlainObject(entry) && Object.keys(entry).every((key) => ['clients', 'images', 'patterns', 'editions'].includes(key))
10
- && nonemptyUniqueList(entry.clients, (name) => PACKAGE_NAME.test(String(name)))
11
- && Array.isArray(entry.patterns) && entry.patterns.every((name) => NAME.test(String(name))) && new Set(entry.patterns).size === entry.patterns.length
12
- && nonemptyUniqueList(entry.images, (name) => PACKAGE_NAME.test(String(name)))
13
- && ruleEditionProblems(entry, 'backing service').length === 0;
14
- const FORM_NAMES = new Set(['call', 'new', 'curried', 'object', 'primitive', 'array']);
15
- const blockOk = (v) => isPlainObject(v) && Number.isInteger(v.lines) && v.lines >= 2 && Number.isInteger(v.tokens) && v.tokens >= 1 && Object.keys(v).length === 2;
16
- const fileLinesOk = (v) => isPlainObject(v) && Number.isInteger(v.soft) && v.soft >= 1 && typeof v.hardGrowth === 'boolean' && Object.keys(v).length === 2;
17
- const SHARED_PARAMS = {
18
- fileLines: fileLinesOk,
19
- duplicateBlock: blockOk,
20
- functionLines: (v) => Number.isInteger(v) && v >= 1,
21
- featureFiles: (v) => Number.isInteger(v) && v >= 1,
22
- };
23
- const SHARED_KEYS = Object.keys(SHARED_PARAMS);
24
- const sharedParam = (key, v) => Object.hasOwn(SHARED_PARAMS, key) && SHARED_PARAMS[key](v);
25
- const sideOk = (side, own, extra = []) => own.every((k) => side[k] !== undefined) && Object.entries(side).every(([k, v]) => own.includes(k) || extra.includes(k) || sharedParam(k, v));
26
- const liteKeyOk = (lite, key, keys) => key !== 'lite' && keys.includes(key)
27
- && (!['functionLines', 'featureFiles'].includes(key) || sharedParam(key, lite[key]));
28
- const liteOk = (lite, keys) => lite === undefined || (isPlainObject(lite) && Object.keys(lite).length > 0 && Object.keys(lite).every((k) => liteKeyOk(lite, k, keys)));
29
- const memberMap = (v, allowEmpty) => isPlainObject(v) && Object.keys(v).length > 0 && Object.values(v).every((list) => Array.isArray(list) && (allowEmpty || list.length > 0) && list.every((x) => /^[A-Z][A-Za-z0-9]*$/.test(String(x))) && new Set(list).size === list.length);
30
- const roleList = (v) => nonemptyUniqueList(v, (role) => NAME.test(String(role)));
31
- const formsOk = (v) => Array.isArray(v) && v.length > 0 && v.every((x) => FORM_NAMES.has(x)) && new Set(v).size === v.length;
32
- const doubleOk = (v) => isPlainObject(v) && /^[A-Za-z][A-Za-z0-9]*$/.test(String(v.double)) && formsOk(v.forms);
33
- const regexOk = (v) => { try {
34
- return typeof v === 'string' && v.length > 0 && Boolean(new RegExp(v));
35
- }
36
- catch {
37
- return false;
38
- } };
39
- const dbExtensionsOk = (value) => Array.isArray(value) && value.every((name) => typeof name === 'string' && name.length > 0) && new Set(value).size === value.length;
40
- const DB_PARAMS = { extensions: dbExtensionsOk };
41
- const dbParamsOk = (db) => db === undefined || (isPlainObject(db) && Object.entries(db).every(([key, value]) => Object.hasOwn(DB_PARAMS, key) && DB_PARAMS[key](value)));
42
- function beSpecificProblems(be, manifest) {
43
- const bad = [];
44
- bad.push(...scenarioProblem(be.patternScenarios), ...kindParamProblems(be, manifest.triggerKinds));
45
- if (!isPlainObject(be.contractShape) || Object.keys(be.contractShape).length !== 1 || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(String(be.contractShape.helper)))
46
- bad.push('ruleParams.be.contractShape must be {helper: <identifier>}');
47
- const owners = be.infraOwners;
48
- const ownerId = /^(platform|integrations)\/[a-z][a-z0-9-]*$/;
49
- if (!isPlainObject(owners) || !Object.keys(owners).length || !Object.entries(owners).every(([key, list]) => key && Array.isArray(list) && list.every((o) => ownerId.test(String(o))) && new Set(list).size === list.length))
50
- bad.push('ruleParams.be.infraOwners must map a non-empty specifier to a list of unique platform/<capability> or integrations/<provider> owners ([] means nowhere)');
51
- const eventBus = be.eventBus;
52
- if (!isPlainObject(eventBus) || Object.keys(eventBus).sort(byCodeUnit).join() !== 'classes,imports' || !memberMap(eventBus.imports, true) || !memberMap(eventBus.classes, false))
53
- bad.push('ruleParams.be.eventBus must be {imports: {<module>: [unique PascalCase members]}, classes: {<module>: [non-empty unique PascalCase classes]}}');
54
- if (!paramNamesOk(be.paramNames))
55
- bad.push('ruleParams.be.paramNames must be a non-empty list of unique {type | typeSuffix, names, nameSuffix?} entries');
56
- if (!namedMapValid(be.backing, backingEntryOk))
57
- bad.push('ruleParams.be.backing must map a backing service name to {clients: [unique package names], patterns: [unique pattern names], images: [unique image repositories], editions?: [unique known editions]}');
58
- if (!roleList(be.suffixes))
59
- bad.push('ruleParams.be.suffixes must be a non-empty list of unique kebab-case role suffixes');
60
- if (!roleList(be.bannedSuffixes))
61
- bad.push('ruleParams.be.bannedSuffixes must be a non-empty list of unique kebab-case suffixes');
62
- else if (roleList(be.suffixes) && be.suffixes.some((x) => be.bannedSuffixes.includes(x)))
63
- bad.push('ruleParams.be.suffixes and bannedSuffixes must be disjoint');
64
- const sd = be.specDoubles;
65
- if (!isPlainObject(sd) || Object.keys(sd).sort(byCodeUnit).join() !== 'doubles,fallback,kit' || typeof sd.kit !== 'string' || !sd.kit || !Array.isArray(sd.doubles) || !sd.doubles.length || !sd.doubles.every((e) => doubleOk(e) && regexOk(e.token) && (e.from === undefined || regexOk(e.from)) && Object.keys(e).length === (e.from === undefined ? 3 : 4)) || !doubleOk(sd.fallback) || Object.keys(sd.fallback).length !== 2)
66
- bad.push('ruleParams.be.specDoubles must be {kit, doubles: [{token: regex, double, forms}], fallback: {double, forms}} with forms drawn from call, new, curried, object, primitive, array');
67
- return bad;
68
- }
69
- /** A database function name (R334): `schema.name` outside pg_catalog, or, where `bare` admits it, a pg built-in named alone. */
70
- const dbFunctionNameOk = (name, bare) => typeof name === 'string' && (/^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*$/.test(name) ? !name.startsWith('pg_catalog.') : bare && /^[a-z_][a-z0-9_]*$/.test(name));
71
- /**
72
- * True for an absent list or a list of {name, reason} database functions, names unique and schema-qualified; `bare` also admits
73
- * a bare name, which only the canon's list (ruleParams.be.dbFunctions) uses, for the pg built-ins its helpers call.
74
- */
75
- export const dbFunctionsOk = (list, { bare = false } = {}) => list === undefined || (Array.isArray(list) && list.every((entry) => isPlainObject(entry) && Object.keys(entry).sort().join() === 'name,reason' && dbFunctionNameOk(entry.name, bare) && typeof entry.reason === 'string' && entry.reason.trim().length > 0) && new Set(list.map((entry) => entry.name)).size === list.length);
76
- /**
77
- * True for an absent list or a list of {file, reason} SQL pass-through files (R334): `file` is a forward-slash path relative to the
78
- * side folder (no leading slash, no `..`), unique, and the reason names whose text the file passes through.
79
- */
80
- export const sqlPassThroughOk = (list) => list === undefined || (Array.isArray(list) && list.every((entry) => isPlainObject(entry) && Object.keys(entry).sort().join() === 'file,reason' && typeof entry.file === 'string' && /^[A-Za-z0-9_.-]+(\/[A-Za-z0-9_.-]+)*$/.test(entry.file) && !entry.file.split('/').includes('..') && typeof entry.reason === 'string' && entry.reason.trim().length > 0) && new Set(list.map((entry) => entry.file)).size === list.length);
81
- /** The shape problems of `m.ruleParams`. */
82
- export function ruleParamsProblems(m) {
83
- const bad = [];
84
- const rp = m.ruleParams;
85
- if (!isPlainObject(rp) || Object.keys(rp).some((k) => ![...PROFILES, 'common', 'db'].includes(k)) || !isPlainObject(rp.common) || !isPlainObject(rp.be) || (rp.fe !== undefined && !isPlainObject(rp.fe)))
86
- return ['ruleParams must be a map with common, be and optionally fe and db'];
87
- else {
88
- // common holds the parameters both sides share; a side may restate one of them (a valid value) as an override, nothing else.
89
- // Edition lite: a side's optional `lite` map overrides keys of the same side (never `lite` itself) when the app declares edition lite.
90
- if (!sideOk(rp.common, []) || !fileLinesOk(rp.common.fileLines) || !blockOk(rp.common.duplicateBlock))
91
- bad.push('ruleParams.common needs fileLines {soft, hardGrowth} and duplicateBlock {lines >= 2, tokens >= 1}; optional functionLines and featureFiles must be positive integers');
92
- if (!sideOk(rp.be, BE_OWN, ['schemaAuthority', 'lite', 'dbFunctions', 'sqlPassThrough']) || (rp.be.schemaAuthority !== undefined && !SCHEMA_AUTHORITIES.includes(rp.be.schemaAuthority)) || !dbFunctionsOk(rp.be.dbFunctions, { bare: true }) || !sqlPassThroughOk(rp.be.sqlPassThrough) || !liteOk(rp.be.lite, [...BE_OWN, ...SHARED_KEYS, 'schemaAuthority', 'dbFunctions', 'sqlPassThrough']))
93
- bad.push('ruleParams.be needs infraOwners, eventBus, specDoubles, paramNames, suffixes, bannedSuffixes, contractShape {helper}, unitRoles, logicRoles, thinRoles, patternScenarios, kindPatterns, addKinds and backing (shared parameters live in ruleParams.common, a side may override them); optional: schemaAuthority (' + SCHEMA_AUTHORITIES.join(' | ') + '), dbFunctions ([{name, reason}]: a pg built-in bare, every other function schema.name), sqlPassThrough ([{file, reason}]: a file whose SQL text is not written by the app) and lite (overrides of the same keys)');
94
- else
95
- bad.push(...unitRolesProblems(rp.be), ...roleListProblems(rp.be));
96
- bad.push(...beSpecificProblems(rp.be, m));
97
- if (rp.fe !== undefined && (!sideOk(rp.fe, [], ['lite']) || !liteOk(rp.fe.lite, SHARED_KEYS)))
98
- bad.push('ruleParams.fe may only restate the shared parameters of ruleParams.common, and carry a lite override of them');
99
- if (!dbParamsOk(rp.db))
100
- bad.push('ruleParams.db may contain only extensions (a list of unique non-empty extension names)');
101
- }
102
- return bad;
103
- }
@@ -1,25 +0,0 @@
1
- // Single source of database-rule finding codes and the owned db/ paths of a lite app (slot app.db).
2
- export const DB_MIGRATION_SHAPE = 'DB_MIGRATION_SHAPE';
3
- export const DB_RLS_REQUIRED = 'DB_RLS_REQUIRED';
4
- export const DB_DYNAMIC_DDL = 'DB_DYNAMIC_DDL';
5
- export const DB_POLICY_SHAPE = 'DB_POLICY_SHAPE';
6
- export const DB_DEFINER_SAFE = 'DB_DEFINER_SAFE';
7
- export const DB_STORAGE_POLICY = 'DB_STORAGE_POLICY';
8
- export const LITE_DB_MIGRATION = 'LITE_DB_MIGRATION';
9
- export const DB_BASELINE_SHAPE = 'DB_BASELINE_SHAPE';
10
- export const DB_ARCHIVE_MUTATED = 'DB_ARCHIVE_MUTATED';
11
- export const DB_PGMQ_DECLARED = 'DB_PGMQ_DECLARED';
12
- export const DB_EXTENSION_ALLOWED = 'DB_EXTENSION_ALLOWED';
13
- export const DB_MIGRATION_DESTRUCTIVE = 'DB_MIGRATION_DESTRUCTIVE';
14
- /** An owner ruling (hfs.json db.destructiveRulings) whose destroyed object is still referenced, or that names an object or migration it cannot prove. */
15
- export const DB_DESTRUCTIVE_RULING_UNPROVEN = 'DB_DESTRUCTIVE_RULING_UNPROVEN';
16
- export const HFS_SEED_PII = 'HFS_SEED_PII';
17
- export const DB_VAULT_WRITE = 'DB_VAULT_WRITE';
18
-
19
- export const DB_DIR = 'db';
20
- export const MIGRATIONS_DIR = `${DB_DIR}/migrations`;
21
- /** The migrations retired at a baseline cutover (slot app.db.migrations.archive): never applied, never judged by L02-L08. */
22
- export const MIGRATIONS_ARCHIVE_DIR = `${MIGRATIONS_DIR}/archive`;
23
- /** True for a migration `starci app db migrate` applies: a path under db/migrations/ outside the archive. */
24
- export const isActiveMigration = (file) => file.startsWith(`${MIGRATIONS_DIR}/`) && !file.startsWith(`${MIGRATIONS_ARCHIVE_DIR}/`);
25
- export const SEED_FILE = `${DB_DIR}/seed.sql`;