@hailstails/hone 2.0.0-pre.4 → 2.0.0-pre.6

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 (135) hide show
  1. package/ADOPTING.md +10 -19
  2. package/CHANGELOG.md +46 -0
  3. package/MIGRATING.md +25 -14
  4. package/README.md +3 -4
  5. package/chunks/chunk-2U5EKYGS.js +14348 -0
  6. package/chunks/{chunk-FPIP7JEC.js → chunk-4AJQHZ7I.js} +1 -1
  7. package/chunks/chunk-4PHKVNM3.js +2377 -0
  8. package/chunks/{chunk-CXM5KBZX.js → chunk-6LTJRJOE.js} +1 -1
  9. package/chunks/{chunk-PVSC4SE3.js → chunk-BISP2JOL.js} +4 -6
  10. package/chunks/{chunk-BRANVR7K.js → chunk-FRE5IA3C.js} +1 -1
  11. package/chunks/{chunk-E4D5WDRX.js → chunk-GMLT3MHO.js} +252 -254
  12. package/chunks/chunk-M4VSJ27S.js +139 -0
  13. package/chunks/{chunk-YGMO5Z6U.js → chunk-P2VHWLK4.js} +182 -193
  14. package/chunks/{chunk-LD766VWU.js → chunk-U6W65ZOF.js} +31 -2
  15. package/chunks/{chunk-BKQ3K766.js → chunk-WPEOCLTP.js} +39 -33
  16. package/chunks/{chunk-A3RL4O5V.js → chunk-XNIXPQQ5.js} +35 -2
  17. package/docs/extending.md +2 -2
  18. package/methods/lenses/function-first.md +2 -2
  19. package/package.json +1 -1
  20. package/rules/README.md +5 -3
  21. package/rules/SPIRIT.md +1 -1
  22. package/rules/numbers.md +4 -4
  23. package/rules/principles/no-leak-across-a-boundary.md +1 -1
  24. package/rules/principles.md +1 -1
  25. package/rules/record-kinds/authorised-location.md +1 -1
  26. package/rules/records.md +11 -19
  27. package/rules/rules.md +5 -5
  28. package/rules/sources.md +6 -7
  29. package/rules/typescript/checks.md +55 -387
  30. package/rules/typescript/recipes/adapter-per-outside-party.md +10 -5
  31. package/rules/typescript/recipes/assert-to-narrow.md +114 -4
  32. package/rules/typescript/recipes/closure-factory.md +5 -5
  33. package/rules/typescript/recipes/companion-test-file.md +5 -3
  34. package/rules/typescript/recipes/composed-orchestrator.md +6 -4
  35. package/rules/typescript/recipes/composition-root.md +5 -3
  36. package/rules/typescript/recipes/{bounded-context-generic.md → constrained-context-generic.md} +6 -4
  37. package/rules/typescript/recipes/copy-never-write-in.md +6 -4
  38. package/rules/typescript/recipes/declared-not-bundled.md +5 -3
  39. package/rules/typescript/recipes/dependency-record.md +5 -3
  40. package/rules/typescript/recipes/domain-vocabulary-list.md +5 -3
  41. package/rules/typescript/recipes/entity-module.md +8 -5
  42. package/rules/typescript/recipes/exact-pins-and-a-lock-file.md +5 -3
  43. package/rules/typescript/recipes/extension-outside-the-vendored-code.md +5 -3
  44. package/rules/typescript/recipes/failure-asserted-as-a-value.md +44 -4
  45. package/rules/typescript/recipes/failure-mapping-at-the-adapter.md +8 -5
  46. package/rules/typescript/recipes/fix-the-declaration-not-the-value.md +5 -3
  47. package/rules/typescript/recipes/functional-iteration.md +8 -3
  48. package/rules/typescript/recipes/guard-clauses.md +5 -3
  49. package/rules/typescript/recipes/integration-test-owns-its-scratch.md +5 -3
  50. package/rules/typescript/recipes/integration-test-suffix.md +5 -3
  51. package/rules/typescript/recipes/it-each-over-typed-rows.md +117 -0
  52. package/rules/typescript/recipes/map-out-at-the-adapter.md +36 -4
  53. package/rules/typescript/recipes/meaning-in-names-not-comments.md +5 -5
  54. package/rules/typescript/recipes/named-exported-type.md +5 -3
  55. package/rules/typescript/recipes/narrow-ports.md +5 -3
  56. package/rules/typescript/recipes/one-argument-object.md +8 -3
  57. package/rules/typescript/recipes/{port-in-the-domain.md → port-in-a-module-of-its-own.md} +7 -5
  58. package/rules/typescript/recipes/ports-in-the-argument.md +5 -3
  59. package/rules/typescript/recipes/repo-scripts-only.md +5 -3
  60. package/rules/typescript/recipes/result-union.md +5 -5
  61. package/rules/typescript/recipes/screaming-folders.md +5 -5
  62. package/rules/typescript/recipes/shared-strict-base-config.md +5 -5
  63. package/rules/typescript/recipes/stub-with-vi-fn.md +130 -0
  64. package/rules/typescript/recipes/tagged-union-and-exhaustive-switch.md +5 -3
  65. package/rules/typescript/recipes/whole-words.md +5 -3
  66. package/rules/typescript/recipes/whole-written-out-expectation.md +284 -4
  67. package/rules/typescript/recipes/world-values-through-a-port.md +5 -3
  68. package/rules/typescript/recipes/zod-at-the-producers-adapter.md +8 -3
  69. package/rules/typescript/recipes.md +567 -21
  70. package/rules/typescript/symptoms/ambient-randomness.md +1 -1
  71. package/rules/typescript/symptoms/answer-set-in-a-hook.md +1 -1
  72. package/rules/typescript/symptoms/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site.md +1 -1
  73. package/rules/typescript/symptoms/{assertion-outside-a-test.md → assertion-outside-a-test-body.md} +1 -1
  74. package/rules/typescript/symptoms/branch-in-a-test/test-body.md +10 -184
  75. package/rules/typescript/symptoms/branch-in-a-test.md +11 -1
  76. package/rules/typescript/symptoms/claimed-type/non-null-assertions.md +1 -1
  77. package/rules/typescript/symptoms/{code-or-prose-read-as-text.md → code-or-prose-read-as-text-in-a-test.md} +2 -2
  78. package/rules/typescript/symptoms/computed-value-in-a-test/test-body.md +26 -117
  79. package/rules/typescript/symptoms/computed-value-in-a-test.md +1 -1
  80. package/rules/typescript/symptoms/date-used-directly.md +1 -1
  81. package/rules/typescript/symptoms/default-for-a-required-value.md +1 -1
  82. package/rules/typescript/symptoms/double-with-a-body/logic-in-a-passed-function.md +1 -18
  83. package/rules/typescript/symptoms/double-with-a-body.md +1 -1
  84. package/rules/typescript/symptoms/{export-from-a-test-file.md → export-from-a-test.md} +1 -1
  85. package/rules/typescript/symptoms/failure-shaped-as-success.md +1 -1
  86. package/rules/typescript/symptoms/inherited-environment-in-a-subprocess/git-spawn-environment.md +1 -1
  87. package/rules/typescript/symptoms/inner-layer-imports-outer.md +1 -1
  88. package/rules/typescript/symptoms/library-class-built-in-place.md +1 -1
  89. package/rules/typescript/symptoms/loop-keyword/loop-statement.md +1 -1
  90. package/rules/typescript/symptoms/outside-import-past-a-boundary/import-or-require.md +1 -0
  91. package/rules/typescript/symptoms/outside-import-past-a-boundary.md +5 -4
  92. package/rules/typescript/symptoms/outside-type-in-a-signature.md +2 -2
  93. package/rules/typescript/symptoms/{port-outside-the-domain.md → port-beside-its-adapter.md} +2 -2
  94. package/rules/typescript/symptoms/port-named-for-a-mechanism.md +1 -1
  95. package/rules/typescript/symptoms/process-global-used-in-place.md +1 -1
  96. package/rules/typescript/symptoms/rebinding/test-body.md +1 -18
  97. package/rules/typescript/symptoms/rebinding.md +11 -1
  98. package/rules/typescript/symptoms/schema-past-its-adapter.md +2 -2
  99. package/rules/typescript/symptoms/text-past-its-reader/test-body.md +2 -17
  100. package/rules/typescript/symptoms/text-past-its-reader.md +1 -1
  101. package/rules/typescript/symptoms/throw-or-catch-in-a-test/try-block.md +1 -25
  102. package/rules/typescript/symptoms/type-declared-in-a-test/test-type-declaration.md +1 -1
  103. package/rules/typescript/symptoms/unasserted-call.md +1 -1
  104. package/rules/typescript/symptoms.md +35 -35
  105. package/src/application/conformance/conformance-testing-types.d.ts +2 -0
  106. package/src/domain/language-layer/authored-item-types.d.ts +21 -5
  107. package/src/domain/runner/runner-result-types.d.ts +1 -2
  108. package/src/eslint-plugin.js +40 -38
  109. package/src/hone.js +15 -13638
  110. package/src/infrastructure/disciplines-file/version-one-names.json +4 -5
  111. package/src/infrastructure/engines/eslint/runner/runner.js +56 -70
  112. package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/assertion-site.js +1 -1
  113. package/src/infrastructure/engines/walker/branch-in-a-test/test-body/test-body-logic.js +39 -65
  114. package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/raw-read.js +1 -1
  115. package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/test-file-export.js +1 -1
  116. package/src/infrastructure/engines/walker/runner/runner.js +10 -10
  117. package/src/infrastructure/engines/walker/strictness-weakened/strict/compiler-overrides.js +3 -3
  118. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.examples.json +15 -3
  119. package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.js +118 -4
  120. package/src/measure-engines.process.js +80 -0
  121. package/src/testing.d.ts +1 -0
  122. package/src/testing.js +111 -26
  123. package/chunks/chunk-7FVSZ2VL.js +0 -1304
  124. package/chunks/chunk-BIDD2YWP.js +0 -398
  125. package/rules/record-kinds/boundary-record.md +0 -9
  126. package/rules/typescript/recipes/iteach-over-typed-rows.md +0 -18
  127. package/rules/typescript/recipes/stub-with-vifn.md +0 -20
  128. /package/rules/typescript/symptoms/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read.md +0 -0
  129. /package/rules/typescript/symptoms/{export-from-a-test-file → export-from-a-test}/test-file-export.md +0 -0
  130. /package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/assertion-site.examples.json +0 -0
  131. /package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/piece.json +0 -0
  132. /package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/piece.json +0 -0
  133. /package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/raw-read.examples.json +0 -0
  134. /package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/piece.json +0 -0
  135. /package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/test-file-export.examples.json +0 -0
@@ -1,1304 +0,0 @@
1
- import {
2
- checksOf,
3
- everyOk
4
- } from "./chunk-LD766VWU.js";
5
- import {
6
- readNamedPiece
7
- } from "./chunk-FPIP7JEC.js";
8
- import {
9
- clauseAddressSchema
10
- } from "./chunk-BRANVR7K.js";
11
- import {
12
- CATALOGUE_NAME,
13
- CHECK_ADDRESS_SEPARATOR,
14
- absolutePathSchema,
15
- anchorKindSchema,
16
- checkAddressOfNames,
17
- checkAddressTextOf,
18
- checkNamesOf,
19
- clauseAddressText,
20
- engineIdSchema,
21
- isCatalogueName,
22
- parsedJson,
23
- readVersionOneJson,
24
- sameClauseAddress
25
- } from "./chunk-BKQ3K766.js";
26
-
27
- // src/domain/language-layer/symptom-catalogue-location.ts
28
- var SYMPTOM_CATALOGUE_SEGMENTS = ["rules"];
29
-
30
- // src/domain/language-layer/catalogue-binding.ts
31
- var boundCheckOf = (request) => ({
32
- check: request.check,
33
- engines: request.bindings.get(checkAddressTextOf(request)) ?? []
34
- });
35
- var checkOf = (bound) => ({ ...bound.check, engines: bound.engines });
36
- var catalogueBoundTo = (request) => {
37
- const bound = request.content.checks.map(
38
- (check) => boundCheckOf({ check, bindings: request.bindings })
39
- );
40
- const unrun = bound.filter((each) => each.engines.length === 0).map((each) => checkAddressTextOf({ check: each.check }));
41
- return unrun.length > 0 ? { outcome: "failed", error: `no piece runs the clause of ${unrun.join(", ")}` } : { outcome: "ok", value: { ...request.content, checks: bound.map(checkOf) } };
42
- };
43
- var holdingBoundTo = (request) => {
44
- if (request.holding.held === "none") {
45
- return { outcome: "ok", value: request.holding };
46
- }
47
- const catalogue = catalogueBoundTo({
48
- content: request.holding.content,
49
- bindings: request.bindings
50
- });
51
- return catalogue.outcome === "failed" ? catalogue : { outcome: "ok", value: { held: "catalogue", catalogue: catalogue.value } };
52
- };
53
-
54
- // src/infrastructure/engines/engine-registry.ts
55
- var ENGINE_REGISTRY = [{ name: "walker" }, { name: "eslint" }];
56
-
57
- // src/infrastructure/engines/piece-engines.ts
58
- var allBound = (bounds) => {
59
- const failure = bounds.find((bound) => bound.outcome === "failed");
60
- return failure ?? {
61
- outcome: "ok",
62
- value: bounds.flatMap((bound) => bound.outcome === "ok" ? bound.value : [])
63
- };
64
- };
65
- var bindingsByAddress = (bindings) => {
66
- const byAddress = /* @__PURE__ */ new Map();
67
- bindings.forEach(({ address, engine }) => {
68
- const engines = byAddress.get(address) ?? [];
69
- if (!engines.some(({ name }) => name === engine.name)) {
70
- byAddress.set(address, [...engines, engine]);
71
- }
72
- });
73
- return byAddress;
74
- };
75
- var namedBindingOf = (request) => {
76
- const address = checkAddressTextOf(request);
77
- const names = checkNamesOf({ text: address });
78
- if (names === void 0) {
79
- return { outcome: "ok", value: [] };
80
- }
81
- const piece = readNamedPiece({ ...request.source, ...names, mechanism: request.engine.name });
82
- if (piece.outcome === "ok") {
83
- return { outcome: "ok", value: [{ address, engine: request.engine }] };
84
- }
85
- return piece.error.kind === "piece-missing" ? { outcome: "ok", value: [] } : piece;
86
- };
87
- var readEngineBindings = (source, checks) => {
88
- const bound = allBound(
89
- ENGINE_REGISTRY.flatMap(
90
- (engine) => checks.map((check) => namedBindingOf({ source, engine, check }))
91
- )
92
- );
93
- return bound.outcome === "failed" ? bound : { outcome: "ok", value: bindingsByAddress(bound.value) };
94
- };
95
- var createEngineBindingsRepository = (options) => ({
96
- read: (request) => readEngineBindings(options, request.checks)
97
- });
98
-
99
- // src/infrastructure/disciplines-file/version-one-names.ts
100
- import { z as z2 } from "zod";
101
-
102
- // src/infrastructure/content-files/symptom-catalogues/symptom-catalogue-wire.ts
103
- import { z } from "zod";
104
- var SUPPORTED_VERSION = 1;
105
- var NOT_A_CATALOGUE_NAME = "is not a lower-case hyphenated name";
106
- var catalogueNameSchema = z.string().regex(new RegExp(`^${CATALOGUE_NAME}$`), { error: NOT_A_CATALOGUE_NAME });
107
- var textSchema = z.string().min(1);
108
- var standingSchema = z.enum(["accepted", "proposed"]);
109
- var recordKindNameSchema = z.enum([
110
- "authorised-location",
111
- "deviation",
112
- "debt",
113
- "boundary-record",
114
- "dependency-record"
115
- ]);
116
- var pointedWireSchema = z.union([
117
- z.strictObject({ rule: catalogueNameSchema }),
118
- z.strictObject({ principle: catalogueNameSchema })
119
- ]);
120
- var caseWireSchema = z.strictObject({
121
- name: catalogueNameSchema,
122
- title: textSchema,
123
- standing: standingSchema,
124
- owes: z.array(pointedWireSchema).min(1)
125
- });
126
- var correctUseWireSchema = z.strictObject({
127
- situation: textSchema,
128
- kind: recordKindNameSchema,
129
- at: textSchema.optional()
130
- });
131
- var seenBySchema = z.enum([
132
- "syntax",
133
- "types",
134
- "graph",
135
- "app",
136
- "files",
137
- "history",
138
- "person"
139
- ]);
140
- var reportsSchema = z.enum(["seen", "seen-to-breach"]);
141
- var symptomWireSchema = z.strictObject({
142
- name: catalogueNameSchema,
143
- title: textSchema,
144
- group: textSchema,
145
- seen: textSchema,
146
- mayIndicate: z.array(
147
- z.strictObject({
148
- case: catalogueNameSchema,
149
- situation: textSchema.optional(),
150
- quote: textSchema.optional(),
151
- points: z.array(pointedWireSchema).min(1)
152
- })
153
- ).min(1),
154
- breachUsuallySits: textSchema,
155
- seenBy: z.array(seenBySchema).min(1),
156
- reports: reportsSchema.optional(),
157
- recipes: z.array(catalogueNameSchema),
158
- correctUses: z.array(correctUseWireSchema),
159
- howItIsSeen: textSchema.optional(),
160
- breachACheckCouldName: textSchema.optional(),
161
- toNameTheBreach: textSchema.optional()
162
- });
163
- var sightWireSchema = z.discriminatedUnion("kind", [
164
- z.strictObject({ kind: z.literal("one-symptom"), symptom: catalogueNameSchema }),
165
- z.strictObject({
166
- kind: z.literal("symptom-by-form"),
167
- forms: z.array(z.strictObject({ section: textSchema, symptom: catalogueNameSchema })).min(1)
168
- }),
169
- z.strictObject({
170
- kind: z.literal("method"),
171
- recipe: catalogueNameSchema,
172
- outcomeSeenBy: z.array(catalogueNameSchema).min(1)
173
- }),
174
- z.strictObject({ kind: z.literal("outside-the-cases") })
175
- ]);
176
- var recordKindWireSchema = z.strictObject({
177
- name: recordKindNameSchema,
178
- title: textSchema,
179
- phrase: textSchema,
180
- todaysFormat: z.enum(["authorised-location", "file-carve-out", "none-yet"])
181
- });
182
- var checkWireSchema = z.strictObject({
183
- symptom: catalogueNameSchema,
184
- name: catalogueNameSchema,
185
- clause: clauseAddressSchema.optional(),
186
- flagsBeyondTheSymptom: textSchema.optional(),
187
- misses: textSchema.optional(),
188
- settingsTracedTo: textSchema.optional()
189
- });
190
- var catalogueFileSchema = z.strictObject({
191
- version: z.literal(SUPPORTED_VERSION),
192
- principles: z.array(z.strictObject({ name: catalogueNameSchema, title: textSchema })),
193
- rules: z.array(
194
- z.strictObject({
195
- name: catalogueNameSchema,
196
- title: textSchema,
197
- principle: catalogueNameSchema,
198
- standing: standingSchema
199
- })
200
- ),
201
- cases: z.array(caseWireSchema),
202
- recipes: z.array(
203
- z.strictObject({
204
- name: catalogueNameSchema,
205
- title: textSchema,
206
- serves: pointedWireSchema,
207
- standing: standingSchema,
208
- reason: z.strictObject({ text: textSchema, standing: standingSchema })
209
- })
210
- ),
211
- recordKinds: z.array(recordKindWireSchema),
212
- engines: z.array(z.strictObject({ name: engineIdSchema })),
213
- symptoms: z.array(symptomWireSchema),
214
- clauses: z.array(z.strictObject({ clause: clauseAddressSchema, sight: sightWireSchema })),
215
- checks: z.array(checkWireSchema),
216
- namedBans: z.array(z.strictObject({ outsideDependency: textSchema }))
217
- });
218
- var resolved = (found) => ({ outcome: "ok", value: found });
219
- var faultsOf = (resolution) => resolution.outcome === "failed" ? resolution.error : [];
220
- var allResolved = (resolutions) => {
221
- const faults = resolutions.flatMap(faultsOf);
222
- return faults.length > 0 ? { outcome: "failed", error: faults } : resolved(
223
- resolutions.flatMap(
224
- (resolution) => resolution.outcome === "ok" ? [resolution.value] : []
225
- )
226
- );
227
- };
228
- var mapped = (request) => request.resolution.outcome === "failed" ? request.resolution : resolved(request.to(request.resolution.value));
229
- var entryNamed = (request) => {
230
- const entry = request.entries.find((candidate) => candidate.name === request.name);
231
- return entry === void 0 ? { outcome: "failed", error: [request.refusal] } : resolved(entry);
232
- };
233
- var notHeldRefusal = (request) => `${request.listing} names ${request.name}, which the catalogue does not hold`;
234
- var heldEntryNamed = (request) => entryNamed({ ...request, refusal: notHeldRefusal(request) });
235
- var principleOf = (wire) => ({ name: wire.name, title: wire.title });
236
- var recipeOf = (request) => ({
237
- ruleSet: request.ruleSet,
238
- name: request.wire.name,
239
- title: request.wire.title,
240
- standing: request.wire.standing,
241
- reason: { text: request.wire.reason.text, standing: request.wire.reason.standing }
242
- });
243
- var recordKindOf = (wire) => ({
244
- name: wire.name,
245
- title: wire.title,
246
- phrase: wire.phrase,
247
- todaysFormat: wire.todaysFormat
248
- });
249
- var engineOf = (wire) => ({ name: wire.name });
250
- var namedBanOf = (wire) => ({
251
- outsideDependency: wire.outsideDependency
252
- });
253
- var ruleOf = (request) => mapped({
254
- resolution: heldEntryNamed({
255
- listing: "rules",
256
- entries: request.principles,
257
- name: request.wire.principle
258
- }),
259
- to: (principle) => ({
260
- name: request.wire.name,
261
- title: request.wire.title,
262
- principle,
263
- standing: request.wire.standing
264
- })
265
- });
266
- var pointedOf = (request) => "rule" in request.point ? mapped({
267
- resolution: heldEntryNamed({
268
- listing: request.listing,
269
- entries: request.pointable.rules,
270
- name: request.point.rule
271
- }),
272
- to: (rule) => ({ kind: "rule", rule })
273
- }) : mapped({
274
- resolution: heldEntryNamed({
275
- listing: request.listing,
276
- entries: request.pointable.principles,
277
- name: request.point.principle
278
- }),
279
- to: (principle) => ({ kind: "principle", principle })
280
- });
281
- var caseOf = (request) => mapped({
282
- resolution: allResolved(
283
- request.wire.owes.map(
284
- (point) => pointedOf({ listing: "cases", point, pointable: request.pointable })
285
- )
286
- ),
287
- to: (owes) => ({
288
- name: request.wire.name,
289
- title: request.wire.title,
290
- standing: request.wire.standing,
291
- owes
292
- })
293
- });
294
- var requiredRecordKindFaultsOf = (recordKinds) => ["debt", "authorised-location"].flatMap(
295
- (name) => recordKinds.some((kind) => kind.name === name) ? [] : [`recordKinds holds no ${name}, which every symptom takes`]
296
- );
297
- var pointableOf = (request) => {
298
- const principles = request.file.principles.map(principleOf);
299
- return mapped({
300
- resolution: allResolved(request.file.rules.map((wire) => ruleOf({ wire, principles }))),
301
- to: (rules) => ({ principles, rules })
302
- });
303
- };
304
- var recordKindsOf = (request) => {
305
- const own = request.file.recordKinds.map(recordKindOf);
306
- return [
307
- ...request.inheritedRecordKinds.filter(
308
- (inherited) => !own.some((kind) => kind.name === inherited.name)
309
- ),
310
- ...own
311
- ];
312
- };
313
- var definitionsOf = (request) => {
314
- const pointable = pointableOf(request);
315
- if (pointable.outcome === "failed") {
316
- return pointable;
317
- }
318
- const recordKinds = recordKindsOf(request);
319
- const cases = allResolved(
320
- request.file.cases.map((wire) => caseOf({ wire, pointable: pointable.value }))
321
- );
322
- const recordKindFaults = requiredRecordKindFaultsOf(recordKinds);
323
- const served = allResolved(
324
- request.file.recipes.map(
325
- (wire) => pointedOf({ listing: "recipes", point: wire.serves, pointable: pointable.value })
326
- )
327
- );
328
- return cases.outcome === "failed" || recordKindFaults.length > 0 || served.outcome === "failed" ? {
329
- outcome: "failed",
330
- error: [...faultsOf(cases), ...recordKindFaults, ...faultsOf(served)]
331
- } : resolved({
332
- ...pointable.value,
333
- cases: cases.value,
334
- recipes: request.file.recipes.map((wire) => recipeOf({ wire, ruleSet: request.ruleSet })),
335
- recordKinds,
336
- engines: request.file.engines.map(engineOf)
337
- });
338
- };
339
- var indicationOf = (request) => {
340
- const indicated = heldEntryNamed({
341
- listing: "symptoms",
342
- entries: request.definitions.cases,
343
- name: request.indication.case
344
- });
345
- const points = allResolved(
346
- request.indication.points.map(
347
- (point) => pointedOf({ listing: "symptoms", point, pointable: request.definitions })
348
- )
349
- );
350
- return indicated.outcome === "failed" || points.outcome === "failed" ? { outcome: "failed", error: [...faultsOf(indicated), ...faultsOf(points)] } : resolved(
351
- request.indication.situation === void 0 ? { case: indicated.value, points: points.value } : {
352
- case: indicated.value,
353
- situation: request.indication.situation,
354
- points: points.value
355
- }
356
- );
357
- };
358
- var correctUseOf = (request) => mapped({
359
- resolution: heldEntryNamed({
360
- listing: "symptoms",
361
- entries: request.definitions.recordKinds,
362
- name: request.use.kind
363
- }),
364
- to: (kind) => request.use.at === void 0 ? { situation: request.use.situation, kind } : { situation: request.use.situation, kind, at: request.use.at }
365
- });
366
- var symptomOf = (request) => {
367
- const { wire, definitions } = request;
368
- const mayIndicate = allResolved(
369
- wire.mayIndicate.map((indication) => indicationOf({ indication, definitions }))
370
- );
371
- const recipes = allResolved(
372
- wire.recipes.map(
373
- (name) => heldEntryNamed({ listing: "symptoms", entries: definitions.recipes, name })
374
- )
375
- );
376
- const correctUses = allResolved(
377
- wire.correctUses.map((use) => correctUseOf({ use, definitions }))
378
- );
379
- if (mayIndicate.outcome === "failed" || recipes.outcome === "failed" || correctUses.outcome === "failed") {
380
- return {
381
- outcome: "failed",
382
- error: [...faultsOf(mayIndicate), ...faultsOf(recipes), ...faultsOf(correctUses)]
383
- };
384
- }
385
- return resolved({
386
- ruleSet: request.ruleSet,
387
- name: wire.name,
388
- title: wire.title,
389
- seen: wire.seen,
390
- mayIndicate: mayIndicate.value,
391
- breachUsuallySits: wire.breachUsuallySits,
392
- recipes: recipes.value,
393
- correctUses: correctUses.value
394
- });
395
- };
396
- var sightedSymptomOf = (request) => heldEntryNamed({ listing: "clauses", entries: request.symptoms, name: request.name });
397
- var methodSightOf = (request) => {
398
- const recipe = heldEntryNamed({
399
- listing: "clauses",
400
- entries: request.recipes,
401
- name: request.sight.recipe
402
- });
403
- const outcomeSeenBy = allResolved(
404
- request.sight.outcomeSeenBy.map((name) => sightedSymptomOf({ ...request, name }))
405
- );
406
- return recipe.outcome === "failed" || outcomeSeenBy.outcome === "failed" ? { outcome: "failed", error: [...faultsOf(recipe), ...faultsOf(outcomeSeenBy)] } : resolved({ kind: "method", recipe: recipe.value, outcomeSeenBy: outcomeSeenBy.value });
407
- };
408
- var sightOf = (request) => {
409
- const { sight } = request;
410
- switch (sight.kind) {
411
- case "one-symptom":
412
- return mapped({
413
- resolution: sightedSymptomOf({ ...request, name: sight.symptom }),
414
- to: (symptom) => ({ kind: "one-symptom", symptom })
415
- });
416
- case "symptom-by-form":
417
- return mapped({
418
- resolution: allResolved(
419
- sight.forms.map(
420
- (form) => mapped({
421
- resolution: sightedSymptomOf({ ...request, name: form.symptom }),
422
- to: (symptom) => ({ section: form.section, symptom })
423
- })
424
- )
425
- ),
426
- to: (forms) => ({ kind: "symptom-by-form", forms })
427
- });
428
- case "method":
429
- return methodSightOf({ ...request, sight });
430
- case "outside-the-cases":
431
- return resolved({ kind: "outside-the-cases" });
432
- }
433
- };
434
- var clauseOf = (request) => mapped({
435
- resolution: sightOf({ ...request, sight: request.wire.sight }),
436
- to: (sight) => ({ clause: request.wire.clause, sight })
437
- });
438
- var sightedSymptomsOf = (request) => {
439
- switch (request.sight.kind) {
440
- case "one-symptom":
441
- return [request.sight.symptom];
442
- case "symptom-by-form":
443
- return request.sight.forms.map((form) => form.symptom);
444
- case "method":
445
- case "outside-the-cases":
446
- return [];
447
- }
448
- };
449
- var sightedNamesOf = (request) => [
450
- ...new Set(sightedSymptomsOf({ sight: request.clause.sight }).map((symptom) => symptom.name))
451
- ];
452
- var formsOf = (request) => request.clause.sight.kind === "symptom-by-form" ? request.clause.sight.forms.filter((form) => form.symptom.name === request.symptom.name).map((form) => form.section) : [];
453
- var checkedClauseOf = (request) => {
454
- const clause = request.clauses.find(
455
- (candidate) => sameClauseAddress({ left: candidate.clause, right: request.address }) === "same"
456
- );
457
- return clause === void 0 ? {
458
- outcome: "failed",
459
- error: [
460
- notHeldRefusal({
461
- listing: "checks",
462
- name: clauseAddressText({ address: request.address })
463
- })
464
- ]
465
- } : resolved(clause);
466
- };
467
- var sightedCheckOf = (request) => sightedNamesOf({ clause: request.clause }).includes(request.symptom.name) ? resolved({
468
- name: request.wire.name,
469
- symptom: request.symptom,
470
- clause: request.clause.clause,
471
- forms: formsOf({ clause: request.clause, symptom: request.symptom })
472
- }) : {
473
- outcome: "failed",
474
- error: [
475
- `checks names ${request.symptom.name}#${request.wire.name} on ${clauseAddressText({ address: request.clause.clause })}, which does not see ${request.symptom.name}`
476
- ]
477
- };
478
- var checkOf2 = (request) => {
479
- const { wire } = request;
480
- const symptom = heldEntryNamed({
481
- listing: "checks",
482
- entries: request.symptoms,
483
- name: wire.symptom
484
- });
485
- if (wire.clause === void 0) {
486
- return symptom.outcome === "failed" ? symptom : resolved({ name: wire.name, symptom: symptom.value, forms: [] });
487
- }
488
- const clause = checkedClauseOf({ ...request, address: wire.clause });
489
- return symptom.outcome === "failed" || clause.outcome === "failed" ? { outcome: "failed", error: [...faultsOf(symptom), ...faultsOf(clause)] } : sightedCheckOf({ wire, symptom: symptom.value, clause: clause.value });
490
- };
491
- var uncheckedSightingsOf = (request) => {
492
- const checked = checksOf({ catalogue: request, clause: request.clause.clause });
493
- return checked.length === 0 ? [] : sightedNamesOf(request).filter((name) => !checked.some((check) => check.symptom.name === name)).map(
494
- (name) => `${clauseAddressText({ address: request.clause.clause })} sees ${name}, which no check names`
495
- );
496
- };
497
- var resolvedChecksOf = (request) => {
498
- const checks = allResolved(request.wires.map((wire) => checkOf2({ ...request, wire })));
499
- if (checks.outcome === "failed") {
500
- return checks;
501
- }
502
- const unchecked = request.clauses.flatMap(
503
- (clause) => uncheckedSightingsOf({ clause, checks: checks.value })
504
- );
505
- return unchecked.length > 0 ? { outcome: "failed", error: unchecked } : checks;
506
- };
507
- var catalogueOf = (request) => {
508
- const definitions = definitionsOf(request);
509
- if (definitions.outcome === "failed") {
510
- return definitions;
511
- }
512
- const symptoms = allResolved(
513
- request.file.symptoms.map(
514
- (wire) => symptomOf({ wire, definitions: definitions.value, ruleSet: request.ruleSet })
515
- )
516
- );
517
- if (symptoms.outcome === "failed") {
518
- return symptoms;
519
- }
520
- const sighting = { symptoms: symptoms.value, recipes: definitions.value.recipes };
521
- const clauses = allResolved(request.file.clauses.map((wire) => clauseOf({ ...sighting, wire })));
522
- if (clauses.outcome === "failed") {
523
- return clauses;
524
- }
525
- return mapped({
526
- resolution: resolvedChecksOf({
527
- symptoms: symptoms.value,
528
- clauses: clauses.value,
529
- wires: request.file.checks
530
- }),
531
- to: (checks) => ({
532
- ...definitions.value,
533
- symptoms: symptoms.value,
534
- clauses: clauses.value,
535
- checks,
536
- namedBans: request.file.namedBans.map(namedBanOf)
537
- })
538
- });
539
- };
540
- var repeatsIn = (request) => request.names.filter((name, index) => request.names.indexOf(name) !== index).map((name) => `${request.listing} holds ${name} more than once`);
541
- var formSectionRepeatsOf = (request) => request.file.clauses.flatMap(
542
- ({ clause, sight }) => sight.kind === "symptom-by-form" ? repeatsIn({
543
- listing: `the forms of ${clauseAddressText({ address: clause })}`,
544
- names: sight.forms.map((form) => form.section)
545
- }) : []
546
- );
547
- var indicatedCaseRepeatsOf = (request) => request.file.symptoms.flatMap(
548
- (symptom) => repeatsIn({
549
- listing: `the cases of ${symptom.name}`,
550
- names: symptom.mayIndicate.map(
551
- (indication) => indication.situation === void 0 ? indication.case : `${indication.case}: ${indication.situation}`
552
- )
553
- })
554
- );
555
- var checkedClauseRepeatsOf = (request) => [...new Set(request.file.checks.map((check) => check.symptom))].flatMap(
556
- (symptom) => repeatsIn({
557
- listing: `the checks of ${symptom}`,
558
- names: request.file.checks.filter((check) => check.symptom === symptom).map(
559
- (check) => check.clause === void 0 ? `${check.symptom}#${check.name}` : clauseAddressText({ address: check.clause })
560
- )
561
- })
562
- );
563
- var repeatedNamesOf = (request) => [
564
- ...repeatsIn({
565
- listing: "principles",
566
- names: request.file.principles.map((principle) => principle.name)
567
- }),
568
- ...repeatsIn({ listing: "rules", names: request.file.rules.map((rule) => rule.name) }),
569
- ...repeatsIn({ listing: "cases", names: request.file.cases.map((entry) => entry.name) }),
570
- ...repeatsIn({ listing: "recipes", names: request.file.recipes.map((recipe) => recipe.name) }),
571
- ...repeatsIn({
572
- listing: "recordKinds",
573
- names: request.file.recordKinds.map((kind) => kind.name)
574
- }),
575
- ...repeatsIn({ listing: "engines", names: request.file.engines.map((engine) => engine.name) }),
576
- ...repeatsIn({
577
- listing: "symptoms",
578
- names: request.file.symptoms.map((symptom) => symptom.name)
579
- }),
580
- ...repeatsIn({
581
- listing: "clauses",
582
- names: request.file.clauses.map(({ clause }) => clauseAddressText({ address: clause }))
583
- }),
584
- ...repeatsIn({
585
- listing: "checks",
586
- names: request.file.checks.map((check) => `${check.symptom}#${check.name}`)
587
- }),
588
- ...checkedClauseRepeatsOf(request),
589
- ...formSectionRepeatsOf(request),
590
- ...indicatedCaseRepeatsOf(request)
591
- ];
592
- var checkedCatalogueFileSchema = catalogueFileSchema.superRefine((file, context) => {
593
- repeatedNamesOf({ file }).forEach((message) => {
594
- context.addIssue({ code: "custom", message });
595
- });
596
- });
597
- var refusalText = (request) => request.faults.map((fault) => `\u2716 ${fault}`).join("\n");
598
- var catalogueContentFromFile = (request) => {
599
- const repeats = repeatedNamesOf({ file: request.file });
600
- if (repeats.length > 0) {
601
- return { outcome: "failed", error: refusalText({ faults: repeats }) };
602
- }
603
- const catalogue = catalogueOf(request);
604
- return catalogue.outcome === "failed" ? { outcome: "failed", error: refusalText({ faults: catalogue.error }) } : catalogue;
605
- };
606
-
607
- // src/infrastructure/disciplines-file/version-one-names.ts
608
- var VERSION_ONE_NAMES_SEGMENTS = [
609
- "src",
610
- "infrastructure",
611
- "disciplines-file",
612
- "version-one-names.json"
613
- ];
614
- var formatOfTodaySchema = recordKindWireSchema.shape.todaysFormat.exclude(["none-yet"]);
615
- var checkAddressSchema = z2.string().regex(new RegExp(`^${CATALOGUE_NAME}#${CATALOGUE_NAME}$`), {
616
- error: "is not a check address of the form <symptom>#<check>"
617
- });
618
- var versionOneNamesSchema = z2.strictObject({
619
- version: z2.literal(1),
620
- clauses: z2.array(
621
- z2.strictObject({
622
- clause: clauseAddressSchema,
623
- sight: z2.union([sightWireSchema, z2.literal("piece-forms")]),
624
- checks: z2.array(checkAddressSchema),
625
- anchor: anchorKindSchema.optional(),
626
- review: z2.string().min(1).optional()
627
- })
628
- ),
629
- recordKinds: z2.partialRecord(recordKindNameSchema, formatOfTodaySchema)
630
- }).superRefine((file, context) => {
631
- const checks = file.clauses.flatMap((entry) => entry.checks);
632
- [...new Set(checks.filter((check, index) => checks.indexOf(check) !== index))].forEach(
633
- (check) => {
634
- context.addIssue({ code: "custom", message: `${check} is named by more than one clause` });
635
- }
636
- );
637
- file.clauses.filter((entry) => entry.anchor === void 0 === entry.checks.length > 0).forEach((entry) => {
638
- context.addIssue({
639
- code: "custom",
640
- message: `${clauseAddressText({ address: entry.clause })} needs an anchor exactly when it names a check`
641
- });
642
- });
643
- });
644
- var NO_VERSION_ONE_NAMES = {
645
- clauses: [],
646
- claimsPieceForms: [],
647
- namedClauses: [],
648
- clauseOfCheck: /* @__PURE__ */ new Map(),
649
- formatsOfToday: {}
650
- };
651
- var addressedCheckOf = (address) => {
652
- const mark = address.indexOf(CHECK_ADDRESS_SEPARATOR);
653
- return { name: address.slice(mark + 1), symptom: { name: address.slice(0, mark) } };
654
- };
655
- var namedClauseOf = (entry) => entry.anchor === void 0 ? { clause: entry.clause, kind: "judgement" } : {
656
- clause: entry.clause,
657
- kind: "mechanical",
658
- anchor: entry.anchor,
659
- checks: entry.checks.map(addressedCheckOf)
660
- };
661
- var namesOf = (file) => ({
662
- clauses: file.clauses.flatMap(
663
- ({ clause, sight }) => sight === "piece-forms" ? [] : [{ clause, sight }]
664
- ),
665
- claimsPieceForms: file.clauses.flatMap(
666
- ({ clause, sight }) => sight === "piece-forms" ? [clause] : []
667
- ),
668
- namedClauses: file.clauses.map(namedClauseOf),
669
- clauseOfCheck: new Map(
670
- file.clauses.flatMap(
671
- ({ clause, checks }) => checks.map((check) => [check, clause])
672
- )
673
- ),
674
- formatsOfToday: file.recordKinds
675
- });
676
- var checksNamedFor = (request) => request.names.namedClauses.flatMap((named2) => {
677
- if (named2.kind !== "mechanical" || sameClauseAddress({ left: named2.clause, right: request.clause }) === "different") {
678
- return [];
679
- }
680
- return named2.checks.flatMap((check) => {
681
- const names = checkNamesOf({ text: checkAddressTextOf({ check }) });
682
- return names === void 0 ? [] : [names];
683
- });
684
- });
685
- var versionOneNamesOf = (request) => {
686
- const parsed = versionOneNamesSchema.safeParse(request.document);
687
- return parsed.success ? { outcome: "ok", value: namesOf(parsed.data) } : { outcome: "failed", error: z2.prettifyError(parsed.error) };
688
- };
689
- var readVersionOneNames = (request) => {
690
- const document = readVersionOneJson(request);
691
- if (document.outcome === "failed") {
692
- return document;
693
- }
694
- const names = versionOneNamesOf({ document: document.value });
695
- return names.outcome === "failed" ? {
696
- outcome: "failed",
697
- error: { kind: "file-malformed", path: request.path, detail: names.error }
698
- } : names;
699
- };
700
-
701
- // src/infrastructure/content-files/item-folders/item-document.ts
702
- var ofKind = (kind) => (placed2) => placed2.item.kind === kind;
703
- var allAssembled = (assembled) => {
704
- const failure = assembled.find((each) => each.outcome === "failed");
705
- return failure?.outcome === "failed" ? failure : {
706
- outcome: "ok",
707
- value: assembled.flatMap((each) => each.outcome === "ok" ? [each.value] : [])
708
- };
709
- };
710
- var recordKindOf2 = (request) => {
711
- const { placed: placed2 } = request;
712
- const name = recordKindNameSchema.safeParse(placed2.name);
713
- return name.success ? {
714
- outcome: "ok",
715
- value: {
716
- name: name.data,
717
- title: placed2.title,
718
- ...placed2.item.facts,
719
- todaysFormat: request.formatsOfToday[name.data] ?? "none-yet"
720
- }
721
- } : { outcome: "failed", error: `${placed2.name} is not the name of a record kind` };
722
- };
723
- var ruleOf2 = (placed2) => ({
724
- name: placed2.name,
725
- title: placed2.title,
726
- principle: placed2.item.facts.principle,
727
- standing: placed2.item.facts.standing
728
- });
729
- var checkOf3 = (request) => {
730
- const symptom = request.placed.within ?? "";
731
- const name = request.placed.name;
732
- const clause = request.clauseOfCheck.get(`${symptom}#${name}`);
733
- return {
734
- symptom,
735
- name,
736
- ...clause === void 0 ? {} : { clause },
737
- ...request.placed.item.facts
738
- };
739
- };
740
- var unheldChecksOf = (request) => {
741
- const held = new Set(request.checks.map((check) => `${check.symptom}#${check.name}`));
742
- return [...request.clauseOfCheck.keys()].filter((address) => !held.has(address));
743
- };
744
- var catalogueFileOf = (request) => {
745
- const { items, beside } = request;
746
- const recordKinds = allAssembled(
747
- items.filter(ofKind("record-kind")).map((placed2) => recordKindOf2({ placed: placed2, formatsOfToday: beside.formatsOfToday }))
748
- );
749
- if (recordKinds.outcome === "failed") {
750
- return recordKinds;
751
- }
752
- const checks = items.filter(ofKind("check")).map((placed2) => checkOf3({ placed: placed2, clauseOfCheck: beside.clauseOfCheck }));
753
- const [unheld] = unheldChecksOf({ checks, clauseOfCheck: beside.clauseOfCheck });
754
- if (unheld !== void 0) {
755
- return { outcome: "failed", error: `the version 1 names give ${unheld}, which no item holds` };
756
- }
757
- const rules = items.filter(ofKind("rule"));
758
- return {
759
- outcome: "ok",
760
- value: {
761
- version: SUPPORTED_VERSION,
762
- principles: items.filter(ofKind("principle")).map((placed2) => ({ name: placed2.name, title: placed2.title })),
763
- rules: rules.map(ruleOf2),
764
- cases: items.filter(ofKind("case")).map((placed2) => ({ name: placed2.name, title: placed2.title, ...placed2.item.facts })),
765
- recipes: items.filter(ofKind("recipe")).map((placed2) => ({ name: placed2.name, title: placed2.title, ...placed2.item.facts })),
766
- recordKinds: recordKinds.value,
767
- engines: beside.engines,
768
- symptoms: items.filter(ofKind("symptom")).map((placed2) => ({ name: placed2.name, title: placed2.title, ...placed2.item.facts })),
769
- clauses: beside.clauses,
770
- checks,
771
- namedBans: rules.flatMap((placed2) => placed2.item.facts.namedBans ?? []).map((outsideDependency) => ({ outsideDependency }))
772
- }
773
- };
774
- };
775
-
776
- // src/infrastructure/content-files/item-folders/item-facts.ts
777
- import { z as z3 } from "zod";
778
- var OMITTED_NAME_AND_TITLE = { name: true, title: true };
779
- var reviewLensSchema = z3.enum([
780
- "clean-architecture",
781
- "decomposition",
782
- "di-discipline",
783
- "errors-as-data",
784
- "function-first",
785
- "naming",
786
- "test-discipline",
787
- "type-soundness",
788
- "zod-boundary"
789
- ]);
790
- var reviewLensesSchema = z3.array(reviewLensSchema).min(1).optional();
791
- var principleFactsSchema = catalogueFileSchema.shape.principles.element.omit(OMITTED_NAME_AND_TITLE).extend({ lenses: reviewLensesSchema });
792
- var ruleFactsSchema = catalogueFileSchema.shape.rules.element.omit(OMITTED_NAME_AND_TITLE).extend({ namedBans: z3.array(z3.string().min(1)).min(1).optional(), lenses: reviewLensesSchema });
793
- var caseFactsSchema = caseWireSchema.omit(OMITTED_NAME_AND_TITLE);
794
- var recipeFactsSchema = catalogueFileSchema.shape.recipes.element.omit(OMITTED_NAME_AND_TITLE);
795
- var recordKindFactsSchema = recordKindWireSchema.omit({
796
- ...OMITTED_NAME_AND_TITLE,
797
- todaysFormat: true
798
- });
799
- var symptomFactsSchema = symptomWireSchema.omit(OMITTED_NAME_AND_TITLE);
800
- var checkFactsSchema = checkWireSchema.omit({ symptom: true, name: true, clause: true });
801
- var itemOf = (request) => request.result.success ? { outcome: "ok", value: request.toItem(request.result.data) } : { outcome: "failed", error: z3.prettifyError(request.result.error) };
802
- var itemFactsOf = (request) => {
803
- const { facts } = request;
804
- switch (request.kind) {
805
- case "principle":
806
- return itemOf({
807
- result: principleFactsSchema.safeParse(facts),
808
- toItem: (parsed) => ({ kind: "principle", facts: parsed })
809
- });
810
- case "rule":
811
- return itemOf({
812
- result: ruleFactsSchema.safeParse(facts),
813
- toItem: (parsed) => ({ kind: "rule", facts: parsed })
814
- });
815
- case "case":
816
- return itemOf({
817
- result: caseFactsSchema.safeParse(facts),
818
- toItem: (parsed) => ({ kind: "case", facts: parsed })
819
- });
820
- case "recipe":
821
- return itemOf({
822
- result: recipeFactsSchema.safeParse(facts),
823
- toItem: (parsed) => ({ kind: "recipe", facts: parsed })
824
- });
825
- case "record-kind":
826
- return itemOf({
827
- result: recordKindFactsSchema.safeParse(facts),
828
- toItem: (parsed) => ({ kind: "record-kind", facts: parsed })
829
- });
830
- case "symptom":
831
- return itemOf({
832
- result: symptomFactsSchema.safeParse(facts),
833
- toItem: (parsed) => ({ kind: "symptom", facts: parsed })
834
- });
835
- case "check":
836
- return itemOf({
837
- result: checkFactsSchema.safeParse(facts),
838
- toItem: (parsed) => ({ kind: "check", facts: parsed })
839
- });
840
- }
841
- };
842
-
843
- // src/infrastructure/content-files/item-folders/item-identity.ts
844
- var ITEM_EXTENSION = ".md";
845
- var LIST_PAGE_FILE = "README.md";
846
- var SEGMENT_SEPARATOR = "/";
847
- var ROOT_KIND_FOLDERS = /* @__PURE__ */ new Map([
848
- ["principles", "principle"],
849
- ["rules", "rule"],
850
- ["cases", "case"],
851
- ["record-kinds", "record-kind"]
852
- ]);
853
- var LANGUAGE_KIND_FOLDERS = /* @__PURE__ */ new Map([
854
- ["symptoms", "symptom"],
855
- ["recipes", "recipe"]
856
- ]);
857
- var CHECKS_UNDER = "symptoms";
858
- var NOT_A_NAME = "is not a lower-case hyphenated name";
859
- var placed = (identity) => ({ outcome: "ok", value: identity });
860
- var refused = (refusal) => ({ outcome: "failed", error: { refusal } });
861
- var nameRefusalOf = (request) => {
862
- switch (request.kind) {
863
- case "record-kind":
864
- return recordKindNameSchema.safeParse(request.name).success ? void 0 : `${request.name} is not the name of a record kind`;
865
- case "principle":
866
- case "rule":
867
- case "case":
868
- case "recipe":
869
- case "symptom":
870
- case "check":
871
- return isCatalogueName(request.name) ? void 0 : `${request.name} ${NOT_A_NAME}`;
872
- }
873
- };
874
- var named = (request) => {
875
- const refusal = nameRefusalOf(request);
876
- return refusal === void 0 ? placed(request) : refused(refusal);
877
- };
878
- var checkOf4 = (request) => isCatalogueName(request.symptom) ? named({ kind: "check", name: request.stem, within: request.symptom }) : refused(`${request.symptom} ${NOT_A_NAME}, and a check sits in the folder of its symptom`);
879
- var placementOfFolders = (request) => {
880
- const [first, second, third] = request.folders;
881
- const rootKind = first === void 0 ? void 0 : ROOT_KIND_FOLDERS.get(first);
882
- const languageKind = second === void 0 ? void 0 : LANGUAGE_KIND_FOLDERS.get(second);
883
- if (request.folders.length === 1 && rootKind !== void 0) {
884
- return named({ kind: rootKind, name: request.stem, within: void 0 });
885
- }
886
- if (request.folders.length === 2 && languageKind !== void 0) {
887
- return named({ kind: languageKind, name: request.stem, within: void 0 });
888
- }
889
- if (request.folders.length === 3 && second === CHECKS_UNDER && third !== void 0) {
890
- return checkOf4({ stem: request.stem, symptom: third });
891
- }
892
- return refused("sits where no kind of item is kept");
893
- };
894
- var segmentsOf = (request) => request.path.split(SEGMENT_SEPARATOR);
895
- var fileOf = (request) => segmentsOf(request).at(-1) ?? "";
896
- var folderPlaceOf = (request) => {
897
- const [first, second] = request.folders;
898
- const underRootKind = first !== void 0 && ROOT_KIND_FOLDERS.has(first);
899
- const underLanguageKind = second !== void 0 && LANGUAGE_KIND_FOLDERS.has(second);
900
- return underRootKind || underLanguageKind ? "under-a-kind-folder" : "elsewhere";
901
- };
902
- var fileRoleOf = (request) => {
903
- const file = fileOf(request);
904
- return file !== LIST_PAGE_FILE && file.endsWith(ITEM_EXTENSION) && folderPlaceOf({ folders: segmentsOf(request).slice(0, -1) }) === "under-a-kind-folder" ? "item" : "other";
905
- };
906
- var identityOf = (request) => placementOfFolders({
907
- folders: segmentsOf(request).slice(0, -1),
908
- stem: fileOf(request).slice(0, -ITEM_EXTENSION.length)
909
- });
910
-
911
- // src/infrastructure/content-files/item-folders/item-listing.ts
912
- var PATH_SEPARATOR = "/";
913
- var byCodePoint = (left, right) => left < right ? -1 : left > right ? 1 : 0;
914
- var folderAt = (request) => {
915
- const joined = request.path.join({ segments: [request.root, ...request.within] });
916
- const folder = absolutePathSchema.safeParse(joined);
917
- return folder.success ? { outcome: "ok", value: folder.data } : {
918
- outcome: "failed",
919
- error: {
920
- kind: "directory-unreadable",
921
- path: request.root,
922
- detail: `${joined} is not an absolute path`
923
- }
924
- };
925
- };
926
- var joinedLists = (lists) => {
927
- const failure = lists.find((list) => list.outcome === "failed");
928
- return failure ?? {
929
- outcome: "ok",
930
- value: lists.flatMap((list) => list.outcome === "ok" ? list.value : [])
931
- };
932
- };
933
- var listedEntry = (request) => request.entry.kind === "directory" ? listedWithin({ ...request, within: [...request.within, request.entry.name] }) : { outcome: "ok", value: [[...request.within, request.entry.name].join(PATH_SEPARATOR)] };
934
- var listedWithin = (request) => {
935
- const folder = folderAt(request);
936
- if (folder.outcome === "failed") {
937
- return folder;
938
- }
939
- const entries = request.directory.list({ path: folder.value });
940
- return entries.outcome === "failed" ? entries : joinedLists(entries.value.map((entry) => listedEntry({ ...request, entry })));
941
- };
942
- var filesUnder = (request) => {
943
- const listed = listedWithin({ ...request, within: [] });
944
- return listed.outcome === "failed" ? listed : { outcome: "ok", value: [...listed.value].sort(byCodePoint) };
945
- };
946
-
947
- // src/infrastructure/content-files/item-folders/item-text.ts
948
- var TITLE_LINE = /^# (?<title>\S.*)$/;
949
- var FENCE_LINE = /^```(?<language>[A-Za-z0-9_-]*)\s*$/;
950
- var FACTS_LANGUAGE = "json";
951
- var LINE_BREAK = /\r?\n/;
952
- var scanned = (scan, numbered) => {
953
- const fence = FENCE_LINE.exec(numbered.line);
954
- if (scan.open === void 0) {
955
- return fence === null ? scan : { open: { language: fence.groups?.language ?? "", lines: [] }, closed: scan.closed };
956
- }
957
- return fence === null ? {
958
- open: { language: scan.open.language, lines: [...scan.open.lines, numbered.line] },
959
- closed: scan.closed
960
- } : { open: void 0, closed: [...scan.closed, { ...scan.open, closedAt: numbered.index }] };
961
- };
962
- var titleOf = (request) => {
963
- const first = request.lines.find((line) => line.trim().length > 0);
964
- const title = first === void 0 ? void 0 : TITLE_LINE.exec(first)?.groups?.title;
965
- return title === void 0 ? { outcome: "failed", error: "does not start with a title line, # <title>" } : { outcome: "ok", value: title.trim() };
966
- };
967
- var factsFenceOf = (request) => {
968
- const scan = request.lines.map((line, index) => ({ line, index })).reduce(scanned, { open: void 0, closed: [] });
969
- if (scan.open !== void 0) {
970
- return { outcome: "failed", error: "has a fenced block that is never closed" };
971
- }
972
- const [only, ...others] = scan.closed.filter((fence) => fence.language === FACTS_LANGUAGE);
973
- if (only === void 0) {
974
- return { outcome: "failed", error: "holds no fenced json block of facts" };
975
- }
976
- return others.length > 0 ? { outcome: "failed", error: "holds more than one fenced json block; the facts are one block" } : { outcome: "ok", value: only };
977
- };
978
- var itemTextOf = (request) => {
979
- const lines = request.text.split(LINE_BREAK);
980
- const title = titleOf({ lines });
981
- if (title.outcome === "failed") {
982
- return title;
983
- }
984
- const fence = factsFenceOf({ lines });
985
- if (fence.outcome === "failed") {
986
- return fence;
987
- }
988
- const facts = parsedJson({ text: fence.value.lines.join("\n") });
989
- const prose = lines.slice(fence.value.closedAt + 1).join("\n").trim();
990
- return facts.outcome === "failed" ? { outcome: "failed", error: `has facts that are not JSON: ${facts.error}` } : { outcome: "ok", value: { title: title.value, facts: facts.value, prose } };
991
- };
992
- var FACTS_INDENT = 2;
993
- var itemTextFrom = (request) => `# ${request.title}
994
-
995
- \`\`\`${FACTS_LANGUAGE}
996
- ${JSON.stringify(request.facts, null, FACTS_INDENT)}
997
- \`\`\`
998
- `;
999
-
1000
- // src/infrastructure/content-files/item-folders/read-item-folder-catalogue.ts
1001
- var malformed = (request) => ({
1002
- kind: "file-malformed",
1003
- path: request.path,
1004
- detail: request.detail
1005
- });
1006
- var placedItemAt = (request) => {
1007
- const path = request.path.join({ segments: [request.root, request.file] });
1008
- const identity = identityOf({ path: request.file });
1009
- if (identity.outcome === "failed") {
1010
- return { outcome: "failed", error: malformed({ path, detail: identity.error.refusal }) };
1011
- }
1012
- const text = request.fileText.read({ path });
1013
- if (text.outcome === "failed") {
1014
- return {
1015
- outcome: "failed",
1016
- error: { kind: "file-unreadable", path, detail: text.error.detail }
1017
- };
1018
- }
1019
- const read = itemTextOf({ text: text.value });
1020
- if (read.outcome === "failed") {
1021
- return { outcome: "failed", error: malformed({ path, detail: read.error }) };
1022
- }
1023
- const facts = itemFactsOf({ kind: identity.value.kind, facts: read.value.facts });
1024
- return facts.outcome === "failed" ? { outcome: "failed", error: malformed({ path, detail: facts.error }) } : {
1025
- outcome: "ok",
1026
- value: {
1027
- name: identity.value.name,
1028
- ...request.symptomSourcePrefix === void 0 || identity.value.kind !== "symptom" ? {} : { sourceFile: `${request.symptomSourcePrefix}/${request.file}` },
1029
- within: identity.value.within,
1030
- title: read.value.title,
1031
- item: facts.value
1032
- }
1033
- };
1034
- };
1035
- var placedItemsOf = (request) => {
1036
- const reads = request.files.filter((file) => fileRoleOf({ path: file }) === "item").map((file) => placedItemAt({ ...request, file }));
1037
- const failure = reads.find((each) => each.outcome === "failed");
1038
- return failure?.outcome === "failed" ? failure : {
1039
- outcome: "ok",
1040
- value: reads.flatMap((each) => each.outcome === "ok" ? [each.value] : [])
1041
- };
1042
- };
1043
- var holdingOf = (request) => {
1044
- const file = catalogueFileOf({ items: request.items, beside: request.beside });
1045
- const content = file.outcome === "failed" ? file : catalogueContentFromFile({
1046
- file: file.value,
1047
- ruleSet: request.ruleSet,
1048
- inheritedRecordKinds: request.inheritedRecordKinds
1049
- });
1050
- if (content.outcome === "failed") {
1051
- return { outcome: "failed", error: malformed({ path: request.root, detail: content.error }) };
1052
- }
1053
- const sourceFiles = /* @__PURE__ */ new Map();
1054
- for (const { name, sourceFile } of request.items) {
1055
- if (sourceFile !== void 0) sourceFiles.set(name, sourceFile);
1056
- }
1057
- if (sourceFiles.size === 0) {
1058
- return { outcome: "ok", value: { held: "catalogue", content: content.value } };
1059
- }
1060
- const symptoms = content.value.symptoms.map((symptom) => ({
1061
- ...symptom,
1062
- sourceFile: sourceFiles.get(symptom.name)
1063
- }));
1064
- const byName = new Map(symptoms.map((symptom) => [symptom.name, symptom]));
1065
- const checks = content.value.checks.map((check) => ({
1066
- ...check,
1067
- symptom: byName.get(check.symptom.name) ?? check.symptom
1068
- }));
1069
- return {
1070
- outcome: "ok",
1071
- value: { held: "catalogue", content: { ...content.value, symptoms, checks } }
1072
- };
1073
- };
1074
- var readItemFolderCatalogue = (request) => {
1075
- const files = filesUnder(request);
1076
- if (files.outcome === "failed") {
1077
- return {
1078
- outcome: "failed",
1079
- error: { kind: "file-unreadable", path: files.error.path, detail: files.error.detail }
1080
- };
1081
- }
1082
- const items = placedItemsOf({ ...request, files: files.value });
1083
- if (items.outcome === "failed") {
1084
- return items;
1085
- }
1086
- return items.value.length === 0 ? { outcome: "ok", value: { held: "none" } } : holdingOf({ ...request, items: items.value });
1087
- };
1088
- var createItemFolderCatalogueRepository = (options) => ({
1089
- read: (_request) => readItemFolderCatalogue(options)
1090
- });
1091
-
1092
- // src/infrastructure/content-files/rule-sets/installed-pieces.ts
1093
- var installedNamesPathOf = (request) => request.path.join({ segments: [request.installRoot, ...VERSION_ONE_NAMES_SEGMENTS] });
1094
- var readInstalledNames = (request) => readVersionOneNames({ fileText: request.fileText, path: installedNamesPathOf(request) });
1095
- var installedPieceOf = (request) => {
1096
- const location = { ...request, ruleSetRoot: request.installRoot };
1097
- const piece = readNamedPiece(location);
1098
- if (piece.outcome === "failed") {
1099
- return piece.error.kind === "piece-missing" ? { outcome: "ok", value: void 0 } : piece;
1100
- }
1101
- return {
1102
- outcome: "ok",
1103
- value: {
1104
- mechanism: request.mechanism,
1105
- examplesPath: piece.value.examplesPath,
1106
- piece: piece.value
1107
- }
1108
- };
1109
- };
1110
- var firstPieceFrom = (request) => {
1111
- const [check, ...remaining] = request.checks;
1112
- if (check === void 0) {
1113
- return { outcome: "ok", value: void 0 };
1114
- }
1115
- const held = installedPieceOf({ ...request, ...check });
1116
- return held.outcome === "failed" || held.value !== void 0 ? held : firstPieceFrom({ ...request, checks: remaining });
1117
- };
1118
- var firstInstalledPieceFor = (request) => firstPieceFrom({ ...request, checks: checksNamedFor(request) });
1119
- var installedPiecesFor = (request) => {
1120
- const held = everyOk({
1121
- entries: request.mechanisms,
1122
- resolve: (mechanism) => firstInstalledPieceFor({ ...request, mechanism })
1123
- });
1124
- return held.outcome === "failed" ? held : { outcome: "ok", value: held.value.filter((piece) => piece !== void 0) };
1125
- };
1126
- var catalogueClausesOf = (request) => {
1127
- const forms = everyOk({
1128
- entries: request.names.claimsPieceForms,
1129
- resolve: (clause) => {
1130
- const first = firstInstalledPieceFor({ ...request, clause, mechanism: "walker" });
1131
- if (first.outcome === "failed") {
1132
- return first;
1133
- }
1134
- const forms2 = Object.entries(first.value?.piece.forms ?? {});
1135
- if (first.value === void 0 || forms2.length === 0) {
1136
- return {
1137
- outcome: "failed",
1138
- error: {
1139
- kind: "rule-set-invalid",
1140
- path: installedNamesPathOf(request),
1141
- detail: `no piece declares the forms of ${clauseAddressText({ address: clause })}`
1142
- }
1143
- };
1144
- }
1145
- const names = new Set(
1146
- checksNamedFor({ names: request.names, clause }).map(checkAddressOfNames)
1147
- );
1148
- const unknown = forms2.find(([, check]) => !names.has(checkAddressOfNames(check)));
1149
- if (unknown !== void 0) {
1150
- const [section, check] = unknown;
1151
- return {
1152
- outcome: "failed",
1153
- error: {
1154
- kind: "file-malformed",
1155
- path: first.value.piece.declarationPath,
1156
- detail: `form ${section} names unregistered check ${checkAddressOfNames(check)}`
1157
- }
1158
- };
1159
- }
1160
- return {
1161
- outcome: "ok",
1162
- value: {
1163
- clause,
1164
- sight: {
1165
- kind: "symptom-by-form",
1166
- forms: forms2.map(([section, { symptom }]) => ({ section, symptom }))
1167
- }
1168
- }
1169
- };
1170
- }
1171
- });
1172
- return forms.outcome === "failed" ? forms : { outcome: "ok", value: [...request.names.clauses, ...forms.value] };
1173
- };
1174
-
1175
- // src/infrastructure/content-files/symptom-catalogues/read-symptom-catalogue.ts
1176
- var namesOfRuleSet = (request) => request.upgradeNames !== void 0 ? { outcome: "ok", value: request.upgradeNames } : request.ruleSetRoot === request.installRoot ? readVersionOneNames({
1177
- fileText: request.fileText,
1178
- path: request.path.join({
1179
- segments: [request.installRoot, ...VERSION_ONE_NAMES_SEGMENTS]
1180
- })
1181
- }) : { outcome: "ok", value: NO_VERSION_ONE_NAMES };
1182
- var VERSION_ONE_RULE_FILE = "discipline.json";
1183
- var versionOneRuleFilesOf = (request) => {
1184
- const entries = request.directory.list({ path: request.itemRoot });
1185
- if (entries.outcome === "failed") {
1186
- return {
1187
- outcome: "failed",
1188
- error: { kind: "file-unreadable", path: entries.error.path, detail: entries.error.detail }
1189
- };
1190
- }
1191
- return {
1192
- outcome: "ok",
1193
- value: entries.value.flatMap((entry) => {
1194
- const path = request.path.join({
1195
- segments: [request.itemRoot, entry.name, VERSION_ONE_RULE_FILE]
1196
- });
1197
- return entry.kind === "directory" && request.fileText.exists({ path }) === "present" ? [path] : [];
1198
- })
1199
- };
1200
- };
1201
- var refusedWhenVersionOne = (request) => {
1202
- if (request.holding.held === "catalogue") {
1203
- return { outcome: "ok", value: request.holding };
1204
- }
1205
- const files = versionOneRuleFilesOf(request);
1206
- if (files.outcome === "failed") {
1207
- return files;
1208
- }
1209
- return files.value.length > 0 ? { outcome: "failed", error: { kind: "rule-set-not-upgraded", path: request.ruleSetRoot } } : { outcome: "ok", value: request.holding };
1210
- };
1211
- var readSymptomCatalogue = (request) => {
1212
- const itemRoot = request.path.join({
1213
- segments: [request.ruleSetRoot, ...SYMPTOM_CATALOGUE_SEGMENTS]
1214
- });
1215
- const root = absolutePathSchema.safeParse(itemRoot);
1216
- if (!root.success) {
1217
- return {
1218
- outcome: "failed",
1219
- error: { kind: "file-unreadable", path: itemRoot, detail: "is not an absolute path" }
1220
- };
1221
- }
1222
- const names = namesOfRuleSet(request);
1223
- if (names.outcome === "failed") {
1224
- return names;
1225
- }
1226
- const clauses = catalogueClausesOf({
1227
- ...request,
1228
- installRoot: request.ruleSetRoot,
1229
- names: names.value
1230
- });
1231
- if (clauses.outcome === "failed") {
1232
- return clauses;
1233
- }
1234
- if (request.fileText.exists({ path: root.data }) === "absent") {
1235
- return { outcome: "ok", value: { held: "none" } };
1236
- }
1237
- const beside = {
1238
- engines: ENGINE_REGISTRY,
1239
- clauses: clauses.value,
1240
- clauseOfCheck: names.value.clauseOfCheck,
1241
- formatsOfToday: names.value.formatsOfToday
1242
- };
1243
- const holding = createItemFolderCatalogueRepository({
1244
- fileText: request.fileText,
1245
- directory: request.directory,
1246
- path: request.path,
1247
- root: root.data,
1248
- ruleSet: request.ruleSet,
1249
- beside,
1250
- inheritedRecordKinds: request.inheritedRecordKinds,
1251
- symptomSourcePrefix: request.ruleSetRoot === request.installRoot ? void 0 : SYMPTOM_CATALOGUE_SEGMENTS.join("/")
1252
- }).read({});
1253
- return holding.outcome === "failed" ? holding : refusedWhenVersionOne({ ...request, itemRoot: root.data, holding: holding.value });
1254
- };
1255
- var createSymptomCatalogueRepository = (options) => ({
1256
- read: (_request) => readSymptomCatalogue(options)
1257
- });
1258
-
1259
- // src/infrastructure/content-files/symptom-catalogues/bound-catalogue.ts
1260
- var readBoundCatalogue = (source) => {
1261
- const holding = createSymptomCatalogueRepository(source).read({});
1262
- if (holding.outcome === "failed") {
1263
- return holding;
1264
- }
1265
- const checks = holding.value.held === "catalogue" ? holding.value.content.checks : [];
1266
- const bindings = createEngineBindingsRepository(source).read({ checks });
1267
- if (bindings.outcome === "failed") {
1268
- return bindings;
1269
- }
1270
- const bound = holdingBoundTo({ holding: holding.value, bindings: bindings.value });
1271
- return bound.outcome === "failed" ? {
1272
- outcome: "failed",
1273
- error: {
1274
- kind: "file-malformed",
1275
- path: source.path.join({ segments: [source.ruleSetRoot, ...SYMPTOM_CATALOGUE_SEGMENTS] }),
1276
- detail: bound.error
1277
- }
1278
- } : bound;
1279
- };
1280
- var createBoundCatalogueOf = (options) => {
1281
- const boundCatalogueOf = (request) => readBoundCatalogue({ ...request, directory: options.directory });
1282
- return boundCatalogueOf;
1283
- };
1284
-
1285
- export {
1286
- SYMPTOM_CATALOGUE_SEGMENTS,
1287
- ENGINE_REGISTRY,
1288
- catalogueNameSchema,
1289
- caseWireSchema,
1290
- symptomWireSchema,
1291
- catalogueFileSchema,
1292
- VERSION_ONE_NAMES_SEGMENTS,
1293
- NO_VERSION_ONE_NAMES,
1294
- versionOneNamesOf,
1295
- readVersionOneNames,
1296
- itemTextFrom,
1297
- installedNamesPathOf,
1298
- readInstalledNames,
1299
- firstInstalledPieceFor,
1300
- installedPiecesFor,
1301
- versionOneRuleFilesOf,
1302
- readBoundCatalogue,
1303
- createBoundCatalogueOf
1304
- };