@mark1russell7/guidebook-plans 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -2
- package/build/index.d.ts +118 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +191 -4
- package/build/index.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +4 -2
- package/src/master.ts +281 -0
- package/src/steps.ts +26 -4
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ Many cases stop the same service. So most steps belong to a cut, and each case t
|
|
|
50
50
|
import { PHASES, checkSteps, phaseOf, stepsFor } from "@mark1russell7/guidebook-plans";
|
|
51
51
|
|
|
52
52
|
const phase = phaseOf(2 * 86_400); // "P2"
|
|
53
|
-
const steps = stepsFor(library, ["met.winter.storm", "
|
|
53
|
+
const steps = stepsFor(library, ["met.winter.storm", "power.grid"], [phase]);
|
|
54
54
|
const result = checkSteps(library, sources, { phases: PHASES, on: keys, gaps });
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -62,7 +62,9 @@ const result = checkSteps(library, sources, { phases: PHASES, on: keys, gaps });
|
|
|
62
62
|
| --- | --- |
|
|
63
63
|
| `duplicate-id` | Two steps have the same `id`. |
|
|
64
64
|
| `empty-text` | A step has no text `do`. |
|
|
65
|
-
| `no-source` | A step cites no source
|
|
65
|
+
| `no-source` | A step cites no source and gives no `reasoning`. |
|
|
66
|
+
| `number-without-source` | A step with a `reasoning` and no source has a number in its text. A dose, a time or a safety limit needs a source. |
|
|
67
|
+
| `empty-reasoning` | A step has an empty `reasoning`. |
|
|
66
68
|
| `missing-source` | A step cites a source that is not in the list. |
|
|
67
69
|
| `use-refused` | The license of a source refuses the use. An example is an invented source outside a fixture. |
|
|
68
70
|
| `unknown-phase` | A step or a gap has a phase that is not in `phases`. |
|
|
@@ -118,6 +120,45 @@ const gate = checkRules(rules, library, sources, { on: keys });
|
|
|
118
120
|
const chart = chartOf(rules); // The questions, each with its rules in the sequence of their rank.
|
|
119
121
|
```
|
|
120
122
|
|
|
123
|
+
## Strategy steps and the state of society
|
|
124
|
+
|
|
125
|
+
A step that no source tells can give its `reasoning` from first principles instead of a source. The reasoning goes with the step into the print. A step with a number in its text still cites a source.
|
|
126
|
+
|
|
127
|
+
A step can name the states of society that it is for: `works`, `partly` or `none`. A step with no `society` is for each state. `stepsFor(library, keys, phases, { society: "none" })` gives the steps of one state.
|
|
128
|
+
|
|
129
|
+
## The master chart
|
|
130
|
+
|
|
131
|
+
The master chart is one chart for any disaster. A reader starts at a signal, answers a few questions and goes to a tab. A tab is a section of a printed plan: the steps of its keys in its phases, with an optional page budget `pages`. Each tab is for one need or one subject. The state of society is a section in each tab.
|
|
132
|
+
|
|
133
|
+
| Kind of node | Fields |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| `signal` | A thing that a reader sees or hears, and the `next` node. |
|
|
136
|
+
| `question` | A question, two or more `answers` (each with a label, the next node and an optional state of society), and its sources. |
|
|
137
|
+
| `goto` | An instruction that sends the reader to a `tab`. |
|
|
138
|
+
|
|
139
|
+
The chart gate `checkMasterChart` gives these codes:
|
|
140
|
+
|
|
141
|
+
| Code | When |
|
|
142
|
+
| --- | --- |
|
|
143
|
+
| `duplicate-id` | Two nodes or two tabs have the same `id`. |
|
|
144
|
+
| `unknown-node`, `unknown-tab`, `unknown-key` | A node goes to an unknown node or tab, or a tab names an unknown key. |
|
|
145
|
+
| `few-answers` | A question has fewer than 2 answers. |
|
|
146
|
+
| `no-signal`, `unreachable` | The chart has no signal, or no signal reaches a node. |
|
|
147
|
+
| `cycle` | A node is in a cycle, so its path has no end. |
|
|
148
|
+
| `too-deep` | A path from a signal has more questions than `maxQuestions` (default 3). |
|
|
149
|
+
| `too-many-nodes`, `too-many-ends` | The chart has more nodes than `maxNodes`, or more ends than `maxEnds`. |
|
|
150
|
+
| `tab-without-steps` | A tab with keys has no step in its keys and phases. |
|
|
151
|
+
| `unused-tab` | No path goes to a tab. |
|
|
152
|
+
| `uncovered-key` | No tab that the chart reaches holds a key of `cover`. Give the hazard codes of a catalog as `cover`, so each hazard has a route. |
|
|
153
|
+
| `no-source`, `unknown-source` | A question cites no source and gives no `reasoning`, or a node cites an unknown source. |
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { checkMasterChart, masterChartOf } from "@mark1russell7/guidebook-plans";
|
|
157
|
+
|
|
158
|
+
const gate = checkMasterChart(nodes, tabs, library, sources, { on: keys, cover: hazards, maxNodes: 20, maxEnds: 13 });
|
|
159
|
+
const chart = masterChartOf(nodes, tabs); // The nodes by layer, the edges with their labels and the tabs that the chart reaches.
|
|
160
|
+
```
|
|
161
|
+
|
|
121
162
|
## Limits
|
|
122
163
|
|
|
123
164
|
- The gate does not evaluate `when`. The planner of an app evaluates it over the live state.
|
package/build/index.d.ts
CHANGED
|
@@ -34,6 +34,108 @@ export declare function phasesOf<P extends string>(ladder: Ladder<P>): readonly
|
|
|
34
34
|
export declare function phaseIn<P extends string>(ladder: Ladder<P>, seconds: number, warned?: boolean): P;
|
|
35
35
|
/** This function gives the phase of a time on the default ladder. 5 minutes gives `P1`. */
|
|
36
36
|
export declare function phaseOf(seconds: number, warned?: boolean): Phase;
|
|
37
|
+
/** The states of society after an event, from a society that works to a society that does not work. */
|
|
38
|
+
export declare const SOCIETY_STATES: readonly ["works", "partly", "none"];
|
|
39
|
+
/** A state of society: the emergency services, the shops, the grid and the law work, work in part or do not work. */
|
|
40
|
+
type Society = (typeof SOCIETY_STATES)[number];
|
|
41
|
+
/** The words of each state of society, for a chart. */
|
|
42
|
+
export declare const SOCIETY_TITLES: Readonly<Record<Society, string>>;
|
|
43
|
+
/**
|
|
44
|
+
* A tab of a printed plan: the steps of its keys in its phases.
|
|
45
|
+
* Each state of society is a section in the tab, so a tab is for one need or one subject, not for one state.
|
|
46
|
+
*/
|
|
47
|
+
interface Tab<P extends string = Phase> {
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly title: string;
|
|
50
|
+
/** The keys of the tab: cases, cuts or needs. A tab of reference text or of a chart has no keys. */
|
|
51
|
+
readonly keys: readonly string[];
|
|
52
|
+
readonly phases: readonly P[];
|
|
53
|
+
/** The most pages that the print of the tab can use. */
|
|
54
|
+
readonly pages?: number;
|
|
55
|
+
}
|
|
56
|
+
/** An answer to a question of the chart. */
|
|
57
|
+
interface ChartAnswer {
|
|
58
|
+
/** The words of the answer, for a chart. */
|
|
59
|
+
readonly label: string;
|
|
60
|
+
/** The id of the next node. */
|
|
61
|
+
readonly next: string;
|
|
62
|
+
/** The state of society that the answer tells, if any. */
|
|
63
|
+
readonly society?: Society;
|
|
64
|
+
}
|
|
65
|
+
/** A start of the chart: a thing that a reader sees or hears. */
|
|
66
|
+
interface SignalNode {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly kind: "signal";
|
|
69
|
+
readonly text: string;
|
|
70
|
+
readonly next: string;
|
|
71
|
+
readonly sources?: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
/** A question of the chart, with two or more answers. */
|
|
74
|
+
interface QuestionNode {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly kind: "question";
|
|
77
|
+
readonly text: string;
|
|
78
|
+
readonly answers: readonly ChartAnswer[];
|
|
79
|
+
/** The ids of the sources that tell the question and its answers. */
|
|
80
|
+
readonly sources: readonly string[];
|
|
81
|
+
/** The reasoning of the question from first principles, for a question that no source tells. */
|
|
82
|
+
readonly reasoning?: string;
|
|
83
|
+
}
|
|
84
|
+
/** An end of the chart: an instruction that sends the reader to a tab. */
|
|
85
|
+
interface GotoNode {
|
|
86
|
+
readonly id: string;
|
|
87
|
+
readonly kind: "goto";
|
|
88
|
+
readonly text: string;
|
|
89
|
+
readonly tab: string;
|
|
90
|
+
readonly sources?: readonly string[];
|
|
91
|
+
}
|
|
92
|
+
/** A node of the master chart. */
|
|
93
|
+
type ChartNode = SignalNode | QuestionNode | GotoNode;
|
|
94
|
+
/** The codes of the findings of the chart gate. */
|
|
95
|
+
export declare const MASTER_FINDING_CODES: readonly ["duplicate-id", "unknown-node", "unknown-tab", "unknown-key", "few-answers", "no-signal", "unreachable", "cycle", "too-deep", "too-many-nodes", "too-many-ends", "tab-without-steps", "unused-tab", "uncovered-key", "no-source", "unknown-source"];
|
|
96
|
+
/** A code of a finding of the chart gate. */
|
|
97
|
+
type MasterFindingCode = (typeof MASTER_FINDING_CODES)[number];
|
|
98
|
+
/** A finding of the chart gate. */
|
|
99
|
+
type MasterFinding = Finding<MasterFindingCode, "chart">;
|
|
100
|
+
/** The options of the chart gate. */
|
|
101
|
+
interface MasterGateOptions {
|
|
102
|
+
/** The known keys: the cases, the cuts and the needs. */
|
|
103
|
+
readonly on: readonly string[];
|
|
104
|
+
/** The keys that a tab of the chart must hold. No `cover` means no key. */
|
|
105
|
+
readonly cover?: readonly string[];
|
|
106
|
+
/** The most questions on a path from a signal to a tab. The default is 3. */
|
|
107
|
+
readonly maxQuestions?: number;
|
|
108
|
+
/** The most nodes that the print of the chart can hold. No `maxNodes` means no limit. */
|
|
109
|
+
readonly maxNodes?: number;
|
|
110
|
+
/** The most ends (nodes of the kind `goto`) that the print of the chart can hold. No `maxEnds` means no limit. */
|
|
111
|
+
readonly maxEnds?: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* This function applies the chart gate.
|
|
115
|
+
* Each node is known and reached, and each path ends at a known tab after a few questions.
|
|
116
|
+
* Each tab with keys has steps. Each key of `cover` is in a tab that the chart reaches.
|
|
117
|
+
*/
|
|
118
|
+
export declare function checkMasterChart<P extends string>(nodes: readonly ChartNode[], tabs: readonly Tab<P>[], steps: readonly Step<P>[], sources: readonly Source[], options: MasterGateOptions): GateResult<MasterFinding>;
|
|
119
|
+
/** An edge of the master chart, for a renderer. */
|
|
120
|
+
interface ChartEdge {
|
|
121
|
+
readonly from: string;
|
|
122
|
+
readonly to: string;
|
|
123
|
+
/** The words of the answer. A signal edge has no label. */
|
|
124
|
+
readonly label?: string;
|
|
125
|
+
}
|
|
126
|
+
/** A node of the master chart with its layer: the most edges from a signal to the node. */
|
|
127
|
+
interface PlacedNode {
|
|
128
|
+
readonly node: ChartNode;
|
|
129
|
+
readonly layer: number;
|
|
130
|
+
}
|
|
131
|
+
/** The master chart, for a renderer: the nodes by layer, the edges and the tabs that the chart reaches. */
|
|
132
|
+
interface MasterChart<P extends string = Phase> {
|
|
133
|
+
readonly nodes: readonly PlacedNode[];
|
|
134
|
+
readonly edges: readonly ChartEdge[];
|
|
135
|
+
readonly tabs: readonly Tab<P>[];
|
|
136
|
+
}
|
|
137
|
+
/** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */
|
|
138
|
+
export declare function masterChartOf<P extends string>(nodes: readonly ChartNode[], tabs: readonly Tab<P>[]): MasterChart<P>;
|
|
37
139
|
/**
|
|
38
140
|
* One action of a plan. A step belongs to a key and to a phase.
|
|
39
141
|
* A key names a case (a kind of event) or a cut (a service that an event stops). A plan of a case is its own steps and the steps of its cuts.
|
|
@@ -56,8 +158,15 @@ interface Step<P extends string = Phase> {
|
|
|
56
158
|
readonly uses?: readonly string[];
|
|
57
159
|
/** The order of the step in its phase, from 1. */
|
|
58
160
|
readonly order: number;
|
|
59
|
-
/** The sources of the step.
|
|
161
|
+
/** The sources of the step. A step with no `reasoning` has one or more. */
|
|
60
162
|
readonly sources: readonly SourceId[];
|
|
163
|
+
/**
|
|
164
|
+
* The reasoning of a strategy step from first principles, for a step that no source tells.
|
|
165
|
+
* A step with a number in its text (a dose, a time or a safety limit) still cites a source.
|
|
166
|
+
*/
|
|
167
|
+
readonly reasoning?: string;
|
|
168
|
+
/** The states of society that the step is for. No `society` means each state. */
|
|
169
|
+
readonly society?: readonly Society[];
|
|
61
170
|
}
|
|
62
171
|
/** A marked gap: a key and a phase that have no step on purpose, with the reason. */
|
|
63
172
|
interface Gap<P extends string = Phase> {
|
|
@@ -73,15 +182,20 @@ interface Cell<P extends string = Phase> {
|
|
|
73
182
|
readonly steps: readonly Step<P>[];
|
|
74
183
|
readonly gap?: Gap<P>;
|
|
75
184
|
}
|
|
185
|
+
/** The options of the steps query. */
|
|
186
|
+
interface StepsForOptions {
|
|
187
|
+
/** Only the steps for this state of society. A step with no `society` is for each state. */
|
|
188
|
+
readonly society?: Society;
|
|
189
|
+
}
|
|
76
190
|
/**
|
|
77
191
|
* This function gives the steps whose `on` is in `on` and whose phase is in `phases`.
|
|
78
192
|
* The sequence is by `on`, then by `phases`, then by `order`. A step that matches two entries of `on` comes one time.
|
|
79
193
|
*/
|
|
80
|
-
export declare function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[]): readonly Step<P>[];
|
|
194
|
+
export declare function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[], options?: StepsForOptions): readonly Step<P>[];
|
|
81
195
|
/** This function gives the matrix of a library: one row for each key of `on`, with one cell for each phase of `phases`. */
|
|
82
196
|
export declare function planMatrix<P extends string>(library: readonly Step<P>[], gaps: readonly Gap<P>[], on: readonly string[], phases: readonly P[]): readonly (readonly Cell<P>[])[];
|
|
83
197
|
/** The codes of the findings of the step gate. The codes of the source gate also apply to the sources of the steps. */
|
|
84
|
-
export declare const STEP_FINDING_CODES: readonly ["duplicate-id", "empty-text", "no-source", "missing-source", "use-refused", "unknown-phase", "bad-order", "duplicate-order", "unmarked-gap", "gap-with-steps", "duplicate-gap", "empty-reason"];
|
|
198
|
+
export declare const STEP_FINDING_CODES: readonly ["duplicate-id", "empty-text", "no-source", "number-without-source", "empty-reasoning", "missing-source", "use-refused", "unknown-phase", "bad-order", "duplicate-order", "unmarked-gap", "gap-with-steps", "duplicate-gap", "empty-reason"];
|
|
85
199
|
/** A code of a finding of the step gate. */
|
|
86
200
|
type StepFindingCode = (typeof STEP_FINDING_CODES)[number];
|
|
87
201
|
/** A finding of the step gate. */
|
|
@@ -190,5 +304,5 @@ interface ChartQuestion<P extends string = Phase> {
|
|
|
190
304
|
}
|
|
191
305
|
/** This function gives the chart of a set of rules: one question for each kind that has rules, in the sequence of `RULE_KINDS`. */
|
|
192
306
|
export declare function chartOf<P extends string>(rules: readonly Rule<P>[]): readonly ChartQuestion<P>[];
|
|
193
|
-
export type { Cell, ChartQuestion, CoverageFinding, CoverageFindingCode, CoverageOptions, Gap, KeyCoverage, Ladder, Phase, Rule, RuleFinding, RuleFindingCode, RuleGateOptions, RuleKind, RuleTarget, Step, StepFinding, StepFindingCode, StepGateOptions };
|
|
307
|
+
export type { Cell, ChartAnswer, ChartEdge, ChartNode, ChartQuestion, CoverageFinding, CoverageFindingCode, CoverageOptions, Gap, GotoNode, KeyCoverage, Ladder, MasterChart, MasterFinding, MasterFindingCode, MasterGateOptions, Phase, PlacedNode, QuestionNode, Rule, RuleFinding, RuleFindingCode, RuleGateOptions, RuleKind, RuleTarget, SignalNode, Society, Step, StepFinding, StepFindingCode, StepGateOptions, StepsForOptions, Tab };
|
|
194
308
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ladder.ts","../src/steps.ts","../src/coverage.ts","../src/rules.ts"],"mappings":";;qBAWa;;UAGI,OAAO;;WAEb,OAAO;;WAEP,QAAQ;;WAER;aAA2B,OAAO;aAAY;;WAC9C,QAAQ,SAAS,OAAO;;;qBAItB;;KAGD,gBAAgB;;qBAGf;;qBAGA,cAAc,SAAS,OAAO;;qBAY9B,QAAQ,OAAO;;wBAQZ,SAAS,kBAAkB,QAAQ,OAAO,cAAc;;;;;;wBASxD,QAAQ,kBAAkB,QAAQ,OAAO,IAAI,iBAAiB,mBAAiB;;wBAU/E,QAAQ,iBAAiB,mBAAiB;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ladder.ts","../src/master.ts","../src/steps.ts","../src/coverage.ts","../src/rules.ts"],"mappings":";;qBAWa;;UAGI,OAAO;;WAEb,OAAO;;WAEP,QAAQ;;WAER;aAA2B,OAAO;aA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,gBAAgB,cAAc"}
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { checkUnits, resultOf } from "@mark1russell7/guidebook";
|
|
2
|
+
import { stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
2
3
|
// src/ladder.ts
|
|
3
4
|
const HOUR = 3600;
|
|
4
5
|
const DAY = 24 * HOUR;
|
|
@@ -88,11 +89,13 @@ const byOrder = (a, b) => a.order - b.order || a.id.localeCompare(b.id);
|
|
|
88
89
|
* This function gives the steps whose `on` is in `on` and whose phase is in `phases`.
|
|
89
90
|
* The sequence is by `on`, then by `phases`, then by `order`. A step that matches two entries of `on` comes one time.
|
|
90
91
|
*/
|
|
91
|
-
function stepsFor(library, on, phases) {
|
|
92
|
+
function stepsFor(library, on, phases, options = {}) {
|
|
93
|
+
const { society } = options;
|
|
94
|
+
const fits = (step) => society === void 0 || step.society === void 0 || step.society.includes(society);
|
|
92
95
|
const out = [];
|
|
93
96
|
const seen = /* @__PURE__ */ new Set();
|
|
94
97
|
for (const key of on) for (const phase of phases) {
|
|
95
|
-
const hits = library.filter((step) => step.on === key && step.phase === phase && !seen.has(step.id)).sort(byOrder);
|
|
98
|
+
const hits = library.filter((step) => step.on === key && step.phase === phase && !seen.has(step.id) && fits(step)).sort(byOrder);
|
|
96
99
|
for (const step of hits) {
|
|
97
100
|
seen.add(step.id);
|
|
98
101
|
out.push(step);
|
|
@@ -122,6 +125,8 @@ const STEP_FINDING_CODES = [
|
|
|
122
125
|
"duplicate-id",
|
|
123
126
|
"empty-text",
|
|
124
127
|
"no-source",
|
|
128
|
+
"number-without-source",
|
|
129
|
+
"empty-reasoning",
|
|
125
130
|
"missing-source",
|
|
126
131
|
"use-refused",
|
|
127
132
|
"unknown-phase",
|
|
@@ -164,7 +169,11 @@ function checkSteps(steps, sources, options) {
|
|
|
164
169
|
if (ids.has(step.id)) error("duplicate-id", "step", step.id, `Two steps have the id "${step.id}".`);
|
|
165
170
|
ids.add(step.id);
|
|
166
171
|
if (step.do.trim() === "") error("empty-text", "step", step.id, `The step "${step.id}" has no text.`);
|
|
167
|
-
if (step.
|
|
172
|
+
if (step.reasoning !== void 0 && step.reasoning.trim() === "") error("empty-reasoning", "step", step.id, `The step "${step.id}" has an empty reasoning.`);
|
|
173
|
+
if (step.sources.length === 0) {
|
|
174
|
+
if (step.reasoning === void 0) error("no-source", "step", step.id, `The step "${step.id}" cites no source and gives no reasoning.`);
|
|
175
|
+
else if (/[0-9]/.test(step.do)) error("number-without-source", "step", step.id, `The step "${step.id}" has a number, so it needs a source.`);
|
|
176
|
+
}
|
|
168
177
|
if (!phases.has(step.phase)) error("unknown-phase", "step", step.id, `The step "${step.id}" has the unknown phase "${step.phase}".`);
|
|
169
178
|
if (!Number.isInteger(step.order) || step.order < 1) error("bad-order", "step", step.id, `The step "${step.id}" has the order ${String(step.order)}. It needs an integer from 1.`);
|
|
170
179
|
const cell = `${step.on}\u0000${step.phase}\u0000${String(step.order)}`;
|
|
@@ -361,6 +370,184 @@ function chartOf(rules) {
|
|
|
361
370
|
}];
|
|
362
371
|
});
|
|
363
372
|
}
|
|
364
|
-
|
|
373
|
+
// src/master.ts
|
|
374
|
+
/** The states of society after an event, from a society that works to a society that does not work. */
|
|
375
|
+
const SOCIETY_STATES = [
|
|
376
|
+
"works",
|
|
377
|
+
"partly",
|
|
378
|
+
"none"
|
|
379
|
+
];
|
|
380
|
+
/** The words of each state of society, for a chart. */
|
|
381
|
+
const SOCIETY_TITLES = {
|
|
382
|
+
works: "Society works",
|
|
383
|
+
partly: "Society works in part",
|
|
384
|
+
none: "Society does not work"
|
|
385
|
+
};
|
|
386
|
+
/** The codes of the findings of the chart gate. */
|
|
387
|
+
const MASTER_FINDING_CODES = [
|
|
388
|
+
"duplicate-id",
|
|
389
|
+
"unknown-node",
|
|
390
|
+
"unknown-tab",
|
|
391
|
+
"unknown-key",
|
|
392
|
+
"few-answers",
|
|
393
|
+
"no-signal",
|
|
394
|
+
"unreachable",
|
|
395
|
+
"cycle",
|
|
396
|
+
"too-deep",
|
|
397
|
+
"too-many-nodes",
|
|
398
|
+
"too-many-ends",
|
|
399
|
+
"tab-without-steps",
|
|
400
|
+
"unused-tab",
|
|
401
|
+
"uncovered-key",
|
|
402
|
+
"no-source",
|
|
403
|
+
"unknown-source"
|
|
404
|
+
];
|
|
405
|
+
/** The ids of the nodes that come after a node. */
|
|
406
|
+
function nextOf(node) {
|
|
407
|
+
if (node.kind === "signal") return [node.next];
|
|
408
|
+
if (node.kind === "question") return node.answers.map((answer) => answer.next);
|
|
409
|
+
return [];
|
|
410
|
+
}
|
|
411
|
+
/** The nodes in a cycle. A chart with a cycle has no end on that path. */
|
|
412
|
+
function cycleNodes(nodes, byId) {
|
|
413
|
+
const next = (id) => {
|
|
414
|
+
const node = byId.get(id);
|
|
415
|
+
return node === void 0 ? [] : nextOf(node).filter((to) => byId.has(to));
|
|
416
|
+
};
|
|
417
|
+
const out = /* @__PURE__ */ new Set();
|
|
418
|
+
for (const group of stronglyConnectedComponents(nodes.map((node) => node.id), next)) {
|
|
419
|
+
const [first] = group;
|
|
420
|
+
if (group.length > 1 || first !== void 0 && next(first).includes(first)) for (const id of group) out.add(id);
|
|
421
|
+
}
|
|
422
|
+
return out;
|
|
423
|
+
}
|
|
424
|
+
/** The most questions from each node to an end, on a chart with no cycle. */
|
|
425
|
+
function questionsToEnd(byId, skip) {
|
|
426
|
+
const memo = /* @__PURE__ */ new Map();
|
|
427
|
+
const walk = (id) => {
|
|
428
|
+
const known = memo.get(id);
|
|
429
|
+
if (known !== void 0) return known;
|
|
430
|
+
const node = byId.get(id);
|
|
431
|
+
if (node === void 0 || skip.has(id)) return 0;
|
|
432
|
+
const rest = Math.max(0, ...nextOf(node).map(walk));
|
|
433
|
+
const value = (node.kind === "question" ? 1 : 0) + rest;
|
|
434
|
+
memo.set(id, value);
|
|
435
|
+
return value;
|
|
436
|
+
};
|
|
437
|
+
for (const id of byId.keys()) walk(id);
|
|
438
|
+
return memo;
|
|
439
|
+
}
|
|
440
|
+
/** The ids of the nodes that a signal reaches. */
|
|
441
|
+
function reached(nodes, byId) {
|
|
442
|
+
const seen = /* @__PURE__ */ new Set();
|
|
443
|
+
const stack = nodes.filter((node) => node.kind === "signal").map((node) => node.id);
|
|
444
|
+
for (let id = stack.pop(); id !== void 0; id = stack.pop()) {
|
|
445
|
+
if (seen.has(id)) continue;
|
|
446
|
+
seen.add(id);
|
|
447
|
+
const node = byId.get(id);
|
|
448
|
+
if (node !== void 0) stack.push(...nextOf(node));
|
|
449
|
+
}
|
|
450
|
+
return seen;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* This function applies the chart gate.
|
|
454
|
+
* Each node is known and reached, and each path ends at a known tab after a few questions.
|
|
455
|
+
* Each tab with keys has steps. Each key of `cover` is in a tab that the chart reaches.
|
|
456
|
+
*/
|
|
457
|
+
function checkMasterChart(nodes, tabs, steps, sources, options) {
|
|
458
|
+
const out = [];
|
|
459
|
+
const error = (code, id, message) => {
|
|
460
|
+
out.push({
|
|
461
|
+
level: "error",
|
|
462
|
+
code,
|
|
463
|
+
record: "chart",
|
|
464
|
+
id,
|
|
465
|
+
message
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
const byId = /* @__PURE__ */ new Map();
|
|
469
|
+
for (const node of nodes) {
|
|
470
|
+
if (byId.has(node.id)) error("duplicate-id", node.id, `Two nodes have the id "${node.id}".`);
|
|
471
|
+
byId.set(node.id, node);
|
|
472
|
+
}
|
|
473
|
+
const tabById = /* @__PURE__ */ new Map();
|
|
474
|
+
for (const tab of tabs) {
|
|
475
|
+
if (tabById.has(tab.id)) error("duplicate-id", tab.id, `Two tabs have the id "${tab.id}".`);
|
|
476
|
+
tabById.set(tab.id, tab);
|
|
477
|
+
}
|
|
478
|
+
const known = new Set(options.on);
|
|
479
|
+
const sourceIds = new Set(sources.map((source) => source.id));
|
|
480
|
+
for (const node of nodes) {
|
|
481
|
+
for (const to of nextOf(node)) if (!byId.has(to)) error("unknown-node", node.id, `The node goes to the unknown node "${to}".`);
|
|
482
|
+
if (node.kind === "question" && node.answers.length < 2) error("few-answers", node.id, "The question has fewer than 2 answers.");
|
|
483
|
+
if (node.kind === "goto" && !tabById.has(node.tab)) error("unknown-tab", node.id, `The node goes to the unknown tab "${node.tab}".`);
|
|
484
|
+
if (node.kind === "question" && node.sources.length === 0 && (node.reasoning ?? "").trim() === "") error("no-source", node.id, "The question cites no source and gives no reasoning.");
|
|
485
|
+
for (const id of node.sources ?? []) if (!sourceIds.has(id)) error("unknown-source", node.id, `The node cites the unknown source "${id}".`);
|
|
486
|
+
}
|
|
487
|
+
if (!nodes.some((node) => node.kind === "signal")) error("no-signal", "chart", "The chart has no signal, so a reader cannot start.");
|
|
488
|
+
const seen = reached(nodes, byId);
|
|
489
|
+
for (const node of nodes) if (!seen.has(node.id)) error("unreachable", node.id, "No signal reaches the node.");
|
|
490
|
+
const cycle = cycleNodes(nodes, byId);
|
|
491
|
+
for (const id of cycle) error("cycle", id, "The node is in a cycle, so its path has no end.");
|
|
492
|
+
const limit = options.maxQuestions ?? 3;
|
|
493
|
+
const depth = questionsToEnd(byId, cycle);
|
|
494
|
+
for (const node of nodes) {
|
|
495
|
+
const value = depth.get(node.id) ?? 0;
|
|
496
|
+
if (node.kind === "signal" && value > limit) error("too-deep", node.id, `A path from the signal has ${value} questions. The limit is ${limit}.`);
|
|
497
|
+
}
|
|
498
|
+
if (options.maxNodes !== void 0 && nodes.length > options.maxNodes) error("too-many-nodes", "chart", `The chart has ${nodes.length} nodes. The limit is ${options.maxNodes}.`);
|
|
499
|
+
const ends = nodes.filter((node) => node.kind === "goto").length;
|
|
500
|
+
if (options.maxEnds !== void 0 && ends > options.maxEnds) error("too-many-ends", "chart", `The chart has ${ends} ends. The limit is ${options.maxEnds}.`);
|
|
501
|
+
const used = new Set(nodes.filter((node) => seen.has(node.id)).flatMap((node) => node.kind === "goto" ? [node.tab] : []));
|
|
502
|
+
for (const tab of tabs) {
|
|
503
|
+
for (const key of tab.keys) if (!known.has(key)) error("unknown-key", tab.id, `The tab names the unknown key "${key}".`);
|
|
504
|
+
const keys = new Set(tab.keys);
|
|
505
|
+
if (keys.size > 0 && !steps.some((step) => keys.has(step.on) && tab.phases.includes(step.phase))) error("tab-without-steps", tab.id, "The tab has no step in its keys and phases.");
|
|
506
|
+
if (!used.has(tab.id)) error("unused-tab", tab.id, "No path of the chart goes to the tab.");
|
|
507
|
+
}
|
|
508
|
+
const held = new Set([...used].flatMap((id) => tabById.get(id)?.keys ?? []));
|
|
509
|
+
for (const key of options.cover ?? []) if (!held.has(key)) error("uncovered-key", key, `No tab of the chart holds the key "${key}".`);
|
|
510
|
+
return resultOf(out);
|
|
511
|
+
}
|
|
512
|
+
/** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */
|
|
513
|
+
function masterChartOf(nodes, tabs) {
|
|
514
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
515
|
+
const cycle = cycleNodes(nodes, byId);
|
|
516
|
+
const edges = nodes.flatMap((node) => {
|
|
517
|
+
if (node.kind === "signal") return [{
|
|
518
|
+
from: node.id,
|
|
519
|
+
to: node.next
|
|
520
|
+
}];
|
|
521
|
+
if (node.kind === "question") return node.answers.map((answer) => ({
|
|
522
|
+
from: node.id,
|
|
523
|
+
to: answer.next,
|
|
524
|
+
label: answer.label
|
|
525
|
+
}));
|
|
526
|
+
return [];
|
|
527
|
+
});
|
|
528
|
+
const layer = /* @__PURE__ */ new Map();
|
|
529
|
+
const into = /* @__PURE__ */ new Map();
|
|
530
|
+
for (const edge of edges) into.set(edge.to, [...into.get(edge.to) ?? [], edge.from]);
|
|
531
|
+
const layerOf = (id) => {
|
|
532
|
+
const known = layer.get(id);
|
|
533
|
+
if (known !== void 0) return known;
|
|
534
|
+
const before = (into.get(id) ?? []).filter((from) => byId.has(from) && !cycle.has(from));
|
|
535
|
+
const value = before.length === 0 ? 0 : 1 + Math.max(...before.map(layerOf));
|
|
536
|
+
layer.set(id, value);
|
|
537
|
+
return value;
|
|
538
|
+
};
|
|
539
|
+
const placed = nodes.filter((node) => !cycle.has(node.id)).map((node) => ({
|
|
540
|
+
node,
|
|
541
|
+
layer: layerOf(node.id)
|
|
542
|
+
}));
|
|
543
|
+
placed.sort((a, b) => a.layer - b.layer);
|
|
544
|
+
const tabIds = new Set(nodes.flatMap((node) => node.kind === "goto" ? [node.tab] : []));
|
|
545
|
+
return {
|
|
546
|
+
nodes: placed,
|
|
547
|
+
edges,
|
|
548
|
+
tabs: tabs.filter((tab) => tabIds.has(tab.id))
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
export { COVERAGE_FINDING_CODES, HORIZONS, LADDER, MASTER_FINDING_CODES, PHASES, PHASE_BOUNDS, PHASE_TITLES, RULE_FINDING_CODES, RULE_KINDS, RULE_KIND_TITLES, SECONDS_PER_DAY, SOCIETY_STATES, SOCIETY_TITLES, STEP_FINDING_CODES, chartOf, checkCoverage, checkMasterChart, checkRules, checkSteps, coverageOf, masterChartOf, phaseIn, phaseOf, phasesOf, planMatrix, stepsFor, unitsOf };
|
|
365
552
|
|
|
366
553
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/ladder.ts","../src/steps.ts","../src/coverage.ts","../src/rules.ts"],"sourcesContent":["// The time ladder of a plan: the phases before the start of an event, and the phases after it, each with its first second.\n\nconst MINUTE = 60;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\nconst WEEK = 7 * DAY;\n/** A month of the ladder is 30 days, and a year is 365 days. */\nconst MONTH = 30 * DAY;\nconst YEAR = 365 * DAY;\n\n/** This constant is the number of seconds in one day. */\nexport const SECONDS_PER_DAY: number = DAY;\n\n/** A ladder of phases. Each phase has a title that a print or a page shows. */\nexport interface Ladder<P extends string = string> {\n /** The phase before the start of an event, when no warning is live. */\n readonly ready: P;\n /** The phase before the start of an event, when a warning is live. */\n readonly warned: P;\n /** The phases after the start, in their sequence. Each phase starts at its second `from`. The first phase starts at 0. */\n readonly timed: readonly { readonly phase: P; readonly from: number }[];\n readonly titles: Readonly<Record<P, string>>;\n}\n\n/** The phases of the default ladder, in their sequence. */\nexport const PHASES = [\"ready\", \"warned\", \"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const;\n\n/** One phase of the default ladder. */\nexport type Phase = (typeof PHASES)[number];\n\n/** The bounds of the phases `P0` to `P5`, in seconds: 0, 5 min, 5 h, 5 d, 5 wk, 5 mo and 5 yr. */\nexport const PHASE_BOUNDS: readonly number[] = [0, 5 * MINUTE, 5 * HOUR, 5 * DAY, 5 * WEEK, 5 * MONTH, 5 * YEAR];\n\n/** The words of each phase of the default ladder. */\nexport const PHASE_TITLES: Readonly<Record<Phase, string>> = {\n ready: \"Before an event\",\n warned: \"When a warning comes\",\n P0: \"In the first 5 minutes\",\n P1: \"From 5 minutes to 5 hours\",\n P2: \"From 5 hours to 5 days\",\n P3: \"From 5 days to 5 weeks\",\n P4: \"From 5 weeks to 5 months\",\n P5: \"From 5 months to 5 years\",\n};\n\n/** The default ladder: each phase after the start is approximately 60 times longer than the phase before it. */\nexport const LADDER: Ladder<Phase> = {\n ready: \"ready\",\n warned: \"warned\",\n timed: ([\"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const).map((phase, i) => ({ phase, from: PHASE_BOUNDS[i] ?? 0 })),\n titles: PHASE_TITLES,\n};\n\n/** This function gives the phases of a ladder in their sequence: `ready`, `warned`, then the timed phases. */\nexport function phasesOf<P extends string>(ladder: Ladder<P>): readonly P[] {\n return [ladder.ready, ladder.warned, ...ladder.timed.map((step) => step.phase)];\n}\n\n/**\n * This function gives the phase of a time on a ladder, in seconds from the start of the event.\n * A negative time is before the start: it gives `warned` when a warning is live, else `ready`.\n * A time at a bound is in the later phase. A time after the start of the last phase stays in the last phase.\n */\nexport function phaseIn<P extends string>(ladder: Ladder<P>, seconds: number, warned = false): P {\n if (!Number.isFinite(seconds)) throw new RangeError(`phaseIn: the time ${String(seconds)} is not a finite number.`);\n if (seconds < 0) return warned ? ladder.warned : ladder.ready;\n let phase: P | undefined;\n for (const step of ladder.timed) if (seconds >= step.from) phase = step.phase;\n if (phase === undefined) throw new RangeError(\"phaseIn: the ladder has no timed phase that starts at 0.\");\n return phase;\n}\n\n/** This function gives the phase of a time on the default ladder. 5 minutes gives `P1`. */\nexport function phaseOf(seconds: number, warned = false): Phase {\n return phaseIn(LADDER, seconds, warned);\n}\n","// The steps of a plan, the query of the steps, the matrix of the library, and the step gate.\n\nimport { checkUnits, resultOf } from \"@mark1russell7/guidebook\";\nimport type { CitedUnit, Finding, GateResult, Source, SourceId, UseContext } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\n\n/**\n * One action of a plan. A step belongs to a key and to a phase.\n * A key names a case (a kind of event) or a cut (a service that an event stops). A plan of a case is its own steps and the steps of its cuts.\n */\nexport interface Step<P extends string = Phase> {\n readonly id: string;\n /** The key of the step: a case or a cut. */\n readonly on: string;\n readonly phase: P;\n /** The needs that the step protects. */\n readonly needs: readonly string[];\n /** An optional condition: a Vex program over the live state. No `when` means always. */\n readonly when?: string;\n /**\n * The action, as one instruction in Simplified Technical English, in the words of the guidebook.\n * When the step has a `when`, this text names the condition in words, because a print cannot examine `when`.\n */\n readonly do: string;\n /** The parts, the resources and the topics that the step uses. */\n readonly uses?: readonly string[];\n /** The order of the step in its phase, from 1. */\n readonly order: number;\n /** The sources of the step. Each step has one or more. */\n readonly sources: readonly SourceId[];\n}\n\n/** A marked gap: a key and a phase that have no step on purpose, with the reason. */\nexport interface Gap<P extends string = Phase> {\n readonly on: string;\n readonly phase: P;\n /** The reason, for example \"A house fire gives no warning.\" */\n readonly why: string;\n}\n\n/** A cell of the matrix of a library: the steps of one key in one phase, or the marked gap of the cell. */\nexport interface Cell<P extends string = Phase> {\n readonly on: string;\n readonly phase: P;\n readonly steps: readonly Step<P>[];\n readonly gap?: Gap<P>;\n}\n\nconst byOrder = <P extends string>(a: Step<P>, b: Step<P>): number => a.order - b.order || a.id.localeCompare(b.id);\n\n/**\n * This function gives the steps whose `on` is in `on` and whose phase is in `phases`.\n * The sequence is by `on`, then by `phases`, then by `order`. A step that matches two entries of `on` comes one time.\n */\nexport function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[]): readonly Step<P>[] {\n const out: Step<P>[] = [];\n const seen = new Set<string>();\n for (const key of on) {\n for (const phase of phases) {\n const hits = library.filter((step) => step.on === key && step.phase === phase && !seen.has(step.id)).sort(byOrder);\n for (const step of hits) {\n seen.add(step.id);\n out.push(step);\n }\n }\n }\n return out;\n}\n\n/** This function gives the matrix of a library: one row for each key of `on`, with one cell for each phase of `phases`. */\nexport function planMatrix<P extends string>(\n library: readonly Step<P>[],\n gaps: readonly Gap<P>[],\n on: readonly string[],\n phases: readonly P[],\n): readonly (readonly Cell<P>[])[] {\n return on.map((key) =>\n phases.map((phase) => {\n const steps = library.filter((step) => step.on === key && step.phase === phase).sort(byOrder);\n const gap = gaps.find((item) => item.on === key && item.phase === phase);\n return gap === undefined ? { on: key, phase, steps } : { on: key, phase, steps, gap };\n }),\n );\n}\n\n/** The codes of the findings of the step gate. The codes of the source gate also apply to the sources of the steps. */\nexport const STEP_FINDING_CODES = [\n \"duplicate-id\",\n \"empty-text\",\n \"no-source\",\n \"missing-source\",\n \"use-refused\",\n \"unknown-phase\",\n \"bad-order\",\n \"duplicate-order\",\n \"unmarked-gap\",\n \"gap-with-steps\",\n \"duplicate-gap\",\n \"empty-reason\",\n] as const;\n\n/** A code of a finding of the step gate. */\nexport type StepFindingCode = (typeof STEP_FINDING_CODES)[number];\n\n/** A finding of the step gate. */\nexport type StepFinding = Finding<StepFindingCode, \"step\" | \"gap\" | \"cell\">;\n\n/** The options of the step gate. */\nexport interface StepGateOptions<P extends string> extends UseContext {\n /** The phases that a step can have. */\n readonly phases: readonly P[];\n /** The keys of the matrix. With them, the gate finds each cell that has no step and no marked gap. */\n readonly on?: readonly string[];\n /** The marked gaps of the library. */\n readonly gaps?: readonly Gap<P>[];\n}\n\n/** This function gives one summary unit for each source of each step, so the source gate examines the steps. */\nexport function unitsOf<P extends string>(steps: readonly Step<P>[]): readonly CitedUnit[] {\n return steps.flatMap((step) => step.sources.map((source) => ({ id: `${step.id}@${source}`, use: \"summary\" as const, text: step.do, source })));\n}\n\n/**\n * This function applies the step gate. It examines the ids, the text, the sources, the phases and the order of each step.\n * It examines the sources with the source gate: the text of a step is a summary of each of its sources.\n * With `on`, it also finds each cell of the matrix that has no step and no marked gap.\n */\nexport function checkSteps<P extends string>(steps: readonly Step<P>[], sources: readonly Source[], options: StepGateOptions<P>): GateResult<StepFinding> {\n const out: StepFinding[] = [];\n const error = (code: StepFindingCode, record: StepFinding[\"record\"], id: string, message: string): void => {\n out.push({ level: \"error\", code, record, id, message });\n };\n const phases = new Set<string>(options.phases);\n const ids = new Set<string>();\n const orders = new Map<string, string>();\n for (const step of steps) {\n if (ids.has(step.id)) error(\"duplicate-id\", \"step\", step.id, `Two steps have the id \"${step.id}\".`);\n ids.add(step.id);\n if (step.do.trim() === \"\") error(\"empty-text\", \"step\", step.id, `The step \"${step.id}\" has no text.`);\n if (step.sources.length === 0) error(\"no-source\", \"step\", step.id, `The step \"${step.id}\" cites no source.`);\n if (!phases.has(step.phase)) error(\"unknown-phase\", \"step\", step.id, `The step \"${step.id}\" has the unknown phase \"${step.phase}\".`);\n if (!Number.isInteger(step.order) || step.order < 1) error(\"bad-order\", \"step\", step.id, `The step \"${step.id}\" has the order ${String(step.order)}. It needs an integer from 1.`);\n const cell = `${step.on}\\u0000${step.phase}\\u0000${String(step.order)}`;\n const other = orders.get(cell);\n if (other !== undefined) error(\"duplicate-order\", \"step\", step.id, `The steps \"${other}\" and \"${step.id}\" have the same order in \"${step.on}\", phase \"${step.phase}\".`);\n else orders.set(cell, step.id);\n }\n for (const finding of checkUnits(unitsOf(steps), sources, options)) {\n if (finding.code !== \"missing-source\" && finding.code !== \"use-refused\") continue;\n const id = finding.id.slice(0, finding.id.lastIndexOf(\"@\"));\n out.push({ level: finding.level, code: finding.code, record: \"step\", id, message: finding.message.replace(`unit \"${finding.id}\"`, `step \"${id}\"`) });\n }\n out.push(...checkGaps(steps, options));\n return resultOf(out);\n}\n\nfunction checkGaps<P extends string>(steps: readonly Step<P>[], options: StepGateOptions<P>): StepFinding[] {\n const out: StepFinding[] = [];\n const gaps = options.gaps ?? [];\n const seen = new Set<string>();\n for (const gap of gaps) {\n const id = `${gap.on}/${gap.phase}`;\n if (seen.has(id)) out.push({ level: \"error\", code: \"duplicate-gap\", record: \"gap\", id, message: `Two gaps mark \"${gap.on}\" in phase \"${gap.phase}\".` });\n seen.add(id);\n if (gap.why.trim() === \"\") out.push({ level: \"error\", code: \"empty-reason\", record: \"gap\", id, message: `The gap of \"${gap.on}\" in phase \"${gap.phase}\" gives no reason.` });\n const count = steps.filter((step) => step.on === gap.on && step.phase === gap.phase).length;\n if (count > 0) out.push({ level: \"error\", code: \"gap-with-steps\", record: \"gap\", id, message: `A gap marks \"${gap.on}\" in phase \"${gap.phase}\", but the cell has ${String(count)} steps.` });\n if (!options.phases.includes(gap.phase)) out.push({ level: \"error\", code: \"unknown-phase\", record: \"gap\", id, message: `The gap of \"${gap.on}\" has the unknown phase \"${gap.phase}\".` });\n }\n if (options.on === undefined) return out;\n for (const row of planMatrix(steps, gaps, options.on, options.phases)) {\n for (const cell of row) {\n const id = `${cell.on}/${cell.phase}`;\n if (cell.steps.length === 0 && cell.gap === undefined) {\n out.push({ level: \"error\", code: \"unmarked-gap\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\", and no gap marks the cell.` });\n }\n }\n }\n return out;\n}\n","// The coverage gate: each key of a catalog has steps in each phase of a set. A marked gap does not pass it.\n\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult } from \"@mark1russell7/guidebook\";\nimport { planMatrix, type Gap, type Step } from \"./steps.ts\";\n\n/** The horizons of a plan: the phases from the first 5 minutes to 5 years. The coverage gate examines them by default. */\nexport const HORIZONS = [\"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const;\n\n/** The codes of the findings of the coverage gate. */\nexport const COVERAGE_FINDING_CODES = [\"no-step\", \"marked-gap\"] as const;\n\n/** A code of a finding of the coverage gate. */\nexport type CoverageFindingCode = (typeof COVERAGE_FINDING_CODES)[number];\n\n/** A finding of the coverage gate. Its `id` is `<key>/<phase>`. */\nexport type CoverageFinding = Finding<CoverageFindingCode, \"cell\">;\n\n/** The options of the coverage gate. */\nexport interface CoverageOptions<P extends string> {\n /** The keys of the catalog. Each key needs steps in each phase. */\n readonly on: readonly string[];\n /** The phases that each key needs. */\n readonly phases: readonly P[];\n /** The marked gaps of the library. The gate shows the reason of a gap, but the gap does not pass. */\n readonly gaps?: readonly Gap<P>[];\n}\n\n/** The coverage of one key: the phases with steps and the phases with no step. */\nexport interface KeyCoverage<P extends string> {\n readonly on: string;\n readonly covered: readonly P[];\n readonly missing: readonly P[];\n}\n\n/** This function gives the coverage of each key of `on` over `phases`, in the sequence of `on`. */\nexport function coverageOf<P extends string>(steps: readonly Step<P>[], on: readonly string[], phases: readonly P[]): readonly KeyCoverage<P>[] {\n return planMatrix(steps, [], on, phases).map((row, index) => ({\n on: on[index] ?? \"\",\n covered: row.filter((cell) => cell.steps.length > 0).map((cell) => cell.phase),\n missing: row.filter((cell) => cell.steps.length === 0).map((cell) => cell.phase),\n }));\n}\n\n/**\n * This function applies the coverage gate. Each key of `on` needs one or more steps in each phase of `phases`.\n * A cell with no step is an error, also when a gap marks it: the finding `marked-gap` gives the reason of the gap.\n * Thus a key with no step shows each of its gaps, and it does not pass.\n */\nexport function checkCoverage<P extends string>(steps: readonly Step<P>[], options: CoverageOptions<P>): GateResult<CoverageFinding> {\n const out: CoverageFinding[] = [];\n for (const row of planMatrix(steps, options.gaps ?? [], options.on, options.phases)) {\n for (const cell of row) {\n if (cell.steps.length > 0) continue;\n const id = `${cell.on}/${cell.phase}`;\n out.push(\n cell.gap === undefined\n ? { level: \"error\", code: \"no-step\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\".` }\n : { level: \"error\", code: \"marked-gap\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\". The gap gives the reason: ${cell.gap.why}` },\n );\n }\n }\n return resultOf(out);\n}\n","// The decision chart: trigger rules as data. Each rule names a trigger, the keys of the trigger and a target in the steps.\n// The rule gate examines that each key is known, each target has steps and each rule cites its sources.\n\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult, Source } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Step } from \"./steps.ts\";\n\n/**\n * The kinds of rule, in the sequence of the chart.\n * The chart asks first for the place. Then it asks for an immediate danger and for the cuts.\n * Then it asks when to stay, to go or to change the plan.\n */\nexport const RULE_KINDS = [\"place\", \"reflex\", \"module\", \"stay\", \"go\", \"fallback\", \"long-plan\"] as const;\n\n/** A kind of rule. */\nexport type RuleKind = (typeof RULE_KINDS)[number];\n\n/** The words of each kind of rule, for a chart. */\nexport const RULE_KIND_TITLES: Readonly<Record<RuleKind, string>> = {\n place: \"Where am I?\",\n reflex: \"Is there an immediate danger?\",\n module: \"What is cut?\",\n stay: \"When do I stay?\",\n go: \"When do I go?\",\n fallback: \"When do I go to a fallback place?\",\n \"long-plan\": \"When do I change to the long plan?\",\n};\n\n/** The target of a rule: the steps of a key in the given phases. */\nexport interface RuleTarget<P extends string = Phase> {\n readonly on: string;\n readonly phases: readonly P[];\n}\n\n/** A trigger rule of the decision chart. */\nexport interface Rule<P extends string = Phase> {\n readonly id: string;\n readonly kind: RuleKind;\n /** The trigger, as one sentence in Simplified Technical English. A print shows it. */\n readonly when: string;\n /** The action, as one instruction. A print shows it with the target. */\n readonly then: string;\n /** The keys that the trigger names: cases, cuts or needs. */\n readonly on: readonly string[];\n /** The steps that the rule sends the reader to. A rule of the kind `place` has no target, because the places are input data. */\n readonly target?: RuleTarget<P>;\n /** The rank in its kind. A rule with a lower rank comes first. */\n readonly rank: number;\n /** The ids of the sources that tell the trigger and the action. */\n readonly sources: readonly string[];\n}\n\n/** The codes of the findings of the rule gate. */\nexport const RULE_FINDING_CODES = [\"duplicate-id\", \"unknown-key\", \"no-target\", \"target-without-steps\", \"no-source\", \"unknown-source\"] as const;\n\n/** A code of a finding of the rule gate. */\nexport type RuleFindingCode = (typeof RULE_FINDING_CODES)[number];\n\n/** A finding of the rule gate. */\nexport type RuleFinding = Finding<RuleFindingCode, \"rule\">;\n\n/** The options of the rule gate. */\nexport interface RuleGateOptions {\n /** The known keys: the cases, the cuts and the needs. */\n readonly on: readonly string[];\n}\n\n/**\n * This function applies the rule gate.\n * Each key of a rule is known. Each rule other than `place` has a target with one or more steps. Each rule cites a known source.\n */\nexport function checkRules<P extends string>(rules: readonly Rule<P>[], steps: readonly Step<P>[], sources: readonly Source[], options: RuleGateOptions): GateResult<RuleFinding> {\n const out: RuleFinding[] = [];\n const known = new Set(options.on);\n const sourceIds = new Set(sources.map((source) => source.id));\n const seen = new Set<string>();\n const error = (code: RuleFindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"rule\", id, message });\n };\n for (const rule of rules) {\n if (seen.has(rule.id)) error(\"duplicate-id\", rule.id, `Two rules have the id \"${rule.id}\".`);\n seen.add(rule.id);\n for (const key of rule.on) if (!known.has(key)) error(\"unknown-key\", rule.id, `The rule names the unknown key \"${key}\".`);\n if (rule.target === undefined) {\n if (rule.kind !== \"place\") error(\"no-target\", rule.id, `The rule of the kind \"${rule.kind}\" has no target.`);\n } else {\n const { on, phases } = rule.target;\n if (!known.has(on)) error(\"unknown-key\", rule.id, `The target names the unknown key \"${on}\".`);\n else if (!steps.some((step) => step.on === on && phases.includes(step.phase))) {\n error(\"target-without-steps\", rule.id, `The target \"${on}\" has no step in the phases ${phases.join(\", \")}.`);\n }\n }\n if (rule.sources.length === 0) error(\"no-source\", rule.id, \"The rule cites no source.\");\n for (const id of rule.sources) if (!sourceIds.has(id)) error(\"unknown-source\", rule.id, `The rule cites the unknown source \"${id}\".`);\n }\n return resultOf(out);\n}\n\n/** One question of the chart: a kind of rule and its rules in the sequence of their rank. */\nexport interface ChartQuestion<P extends string = Phase> {\n readonly kind: RuleKind;\n readonly title: string;\n readonly rules: readonly Rule<P>[];\n}\n\n/** This function gives the chart of a set of rules: one question for each kind that has rules, in the sequence of `RULE_KINDS`. */\nexport function chartOf<P extends string>(rules: readonly Rule<P>[]): readonly ChartQuestion<P>[] {\n return RULE_KINDS.flatMap((kind) => {\n const ofKind = rules.filter((rule) => rule.kind === kind).sort((a, b) => a.rank - b.rank || a.id.localeCompare(b.id));\n return ofKind.length === 0 ? [] : [{ kind, title: RULE_KIND_TITLES[kind], rules: ofKind }];\n });\n}\n"],"mappings":";;AAGA,MAAM,OAAO;AACb,MAAM,MAAM,KAAK;AACjB,MAAM,OAAO,IAAI;;AAEjB,MAAM,QAAQ,KAAK;AACnB,MAAM,OAAO,MAAM;;AAGnB,MAAa,kBAA0B;;AAcvC,MAAa,SAAS;CAAC;CAAS;CAAU;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI;;AAM5E,MAAa,eAAkC;CAAC;CAAG;CAAY,IAAI;CAAM,IAAI;CAAK,IAAI;CAAM,IAAI;CAAO,IAAI;AAAI;;AAG/G,MAAa,eAAgD;CAC3D,OAAO;CACP,QAAQ;CACR,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;;AAGA,MAAa,SAAwB;CACnC,OAAO;CACP,QAAQ;CACR,OAAQ;EAAC;EAAM;EAAM;EAAM;EAAM;EAAM;CAAI,CAAC,CAAW,KAAK,OAAO,OAAO;EAAE;EAAO,MAAM,aAAa,MAAM;CAAE,EAAE;CAChH,QAAQ;AACV;;AAGA,SAAgB,SAA2B,Q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CAChG,OAAO,WAAW,SAAS,SAAS;EAClC,MAAM,SAAS,MAAM,QAAQ,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC;EACpH,OAAO,OAAO,WAAW,IAAI,CAAC,IAAI,CAAC;GAAE;GAAM,OAAO,iBAAiB;GAAO,OAAO;EAAO,CAAC;CAC3F,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/ladder.ts","../src/steps.ts","../src/coverage.ts","../src/rules.ts","../src/master.ts"],"sourcesContent":["// The time ladder of a plan: the phases before the start of an event, and the phases after it, each with its first second.\n\nconst MINUTE = 60;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\nconst WEEK = 7 * DAY;\n/** A month of the ladder is 30 days, and a year is 365 days. */\nconst MONTH = 30 * DAY;\nconst YEAR = 365 * DAY;\n\n/** This constant is the number of seconds in one day. */\nexport const SECONDS_PER_DAY: number = DAY;\n\n/** A ladder of phases. Each phase has a title that a print or a page shows. */\nexport interface Ladder<P extends string = string> {\n /** The phase before the start of an event, when no warning is live. */\n readonly ready: P;\n /** The phase before the start of an event, when a warning is live. */\n readonly warned: P;\n /** The phases after the start, in their sequence. Each phase starts at its second `from`. The first phase starts at 0. */\n readonly timed: readonly { readonly phase: P; readonly from: number }[];\n readonly titles: Readonly<Record<P, string>>;\n}\n\n/** The phases of the default ladder, in their sequence. */\nexport const PHASES = [\"ready\", \"warned\", \"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const;\n\n/** One phase of the default ladder. */\nexport type Phase = (typeof PHASES)[number];\n\n/** The bounds of the phases `P0` to `P5`, in seconds: 0, 5 min, 5 h, 5 d, 5 wk, 5 mo and 5 yr. */\nexport const PHASE_BOUNDS: readonly number[] = [0, 5 * MINUTE, 5 * HOUR, 5 * DAY, 5 * WEEK, 5 * MONTH, 5 * YEAR];\n\n/** The words of each phase of the default ladder. */\nexport const PHASE_TITLES: Readonly<Record<Phase, string>> = {\n ready: \"Before an event\",\n warned: \"When a warning comes\",\n P0: \"In the first 5 minutes\",\n P1: \"From 5 minutes to 5 hours\",\n P2: \"From 5 hours to 5 days\",\n P3: \"From 5 days to 5 weeks\",\n P4: \"From 5 weeks to 5 months\",\n P5: \"From 5 months to 5 years\",\n};\n\n/** The default ladder: each phase after the start is approximately 60 times longer than the phase before it. */\nexport const LADDER: Ladder<Phase> = {\n ready: \"ready\",\n warned: \"warned\",\n timed: ([\"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const).map((phase, i) => ({ phase, from: PHASE_BOUNDS[i] ?? 0 })),\n titles: PHASE_TITLES,\n};\n\n/** This function gives the phases of a ladder in their sequence: `ready`, `warned`, then the timed phases. */\nexport function phasesOf<P extends string>(ladder: Ladder<P>): readonly P[] {\n return [ladder.ready, ladder.warned, ...ladder.timed.map((step) => step.phase)];\n}\n\n/**\n * This function gives the phase of a time on a ladder, in seconds from the start of the event.\n * A negative time is before the start: it gives `warned` when a warning is live, else `ready`.\n * A time at a bound is in the later phase. A time after the start of the last phase stays in the last phase.\n */\nexport function phaseIn<P extends string>(ladder: Ladder<P>, seconds: number, warned = false): P {\n if (!Number.isFinite(seconds)) throw new RangeError(`phaseIn: the time ${String(seconds)} is not a finite number.`);\n if (seconds < 0) return warned ? ladder.warned : ladder.ready;\n let phase: P | undefined;\n for (const step of ladder.timed) if (seconds >= step.from) phase = step.phase;\n if (phase === undefined) throw new RangeError(\"phaseIn: the ladder has no timed phase that starts at 0.\");\n return phase;\n}\n\n/** This function gives the phase of a time on the default ladder. 5 minutes gives `P1`. */\nexport function phaseOf(seconds: number, warned = false): Phase {\n return phaseIn(LADDER, seconds, warned);\n}\n","// The steps of a plan, the query of the steps, the matrix of the library, and the step gate.\n\nimport { checkUnits, resultOf } from \"@mark1russell7/guidebook\";\nimport type { CitedUnit, Finding, GateResult, Source, SourceId, UseContext } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Society } from \"./master.ts\";\n\n/**\n * One action of a plan. A step belongs to a key and to a phase.\n * A key names a case (a kind of event) or a cut (a service that an event stops). A plan of a case is its own steps and the steps of its cuts.\n */\nexport interface Step<P extends string = Phase> {\n readonly id: string;\n /** The key of the step: a case or a cut. */\n readonly on: string;\n readonly phase: P;\n /** The needs that the step protects. */\n readonly needs: readonly string[];\n /** An optional condition: a Vex program over the live state. No `when` means always. */\n readonly when?: string;\n /**\n * The action, as one instruction in Simplified Technical English, in the words of the guidebook.\n * When the step has a `when`, this text names the condition in words, because a print cannot examine `when`.\n */\n readonly do: string;\n /** The parts, the resources and the topics that the step uses. */\n readonly uses?: readonly string[];\n /** The order of the step in its phase, from 1. */\n readonly order: number;\n /** The sources of the step. A step with no `reasoning` has one or more. */\n readonly sources: readonly SourceId[];\n /**\n * The reasoning of a strategy step from first principles, for a step that no source tells.\n * A step with a number in its text (a dose, a time or a safety limit) still cites a source.\n */\n readonly reasoning?: string;\n /** The states of society that the step is for. No `society` means each state. */\n readonly society?: readonly Society[];\n}\n\n/** A marked gap: a key and a phase that have no step on purpose, with the reason. */\nexport interface Gap<P extends string = Phase> {\n readonly on: string;\n readonly phase: P;\n /** The reason, for example \"A house fire gives no warning.\" */\n readonly why: string;\n}\n\n/** A cell of the matrix of a library: the steps of one key in one phase, or the marked gap of the cell. */\nexport interface Cell<P extends string = Phase> {\n readonly on: string;\n readonly phase: P;\n readonly steps: readonly Step<P>[];\n readonly gap?: Gap<P>;\n}\n\nconst byOrder = <P extends string>(a: Step<P>, b: Step<P>): number => a.order - b.order || a.id.localeCompare(b.id);\n\n/** The options of the steps query. */\nexport interface StepsForOptions {\n /** Only the steps for this state of society. A step with no `society` is for each state. */\n readonly society?: Society;\n}\n\n/**\n * This function gives the steps whose `on` is in `on` and whose phase is in `phases`.\n * The sequence is by `on`, then by `phases`, then by `order`. A step that matches two entries of `on` comes one time.\n */\nexport function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[], options: StepsForOptions = {}): readonly Step<P>[] {\n const { society } = options;\n const fits = (step: Step<P>): boolean => society === undefined || step.society === undefined || step.society.includes(society);\n const out: Step<P>[] = [];\n const seen = new Set<string>();\n for (const key of on) {\n for (const phase of phases) {\n const hits = library.filter((step) => step.on === key && step.phase === phase && !seen.has(step.id) && fits(step)).sort(byOrder);\n for (const step of hits) {\n seen.add(step.id);\n out.push(step);\n }\n }\n }\n return out;\n}\n\n/** This function gives the matrix of a library: one row for each key of `on`, with one cell for each phase of `phases`. */\nexport function planMatrix<P extends string>(\n library: readonly Step<P>[],\n gaps: readonly Gap<P>[],\n on: readonly string[],\n phases: readonly P[],\n): readonly (readonly Cell<P>[])[] {\n return on.map((key) =>\n phases.map((phase) => {\n const steps = library.filter((step) => step.on === key && step.phase === phase).sort(byOrder);\n const gap = gaps.find((item) => item.on === key && item.phase === phase);\n return gap === undefined ? { on: key, phase, steps } : { on: key, phase, steps, gap };\n }),\n );\n}\n\n/** The codes of the findings of the step gate. The codes of the source gate also apply to the sources of the steps. */\nexport const STEP_FINDING_CODES = [\n \"duplicate-id\",\n \"empty-text\",\n \"no-source\",\n \"number-without-source\",\n \"empty-reasoning\",\n \"missing-source\",\n \"use-refused\",\n \"unknown-phase\",\n \"bad-order\",\n \"duplicate-order\",\n \"unmarked-gap\",\n \"gap-with-steps\",\n \"duplicate-gap\",\n \"empty-reason\",\n] as const;\n\n/** A code of a finding of the step gate. */\nexport type StepFindingCode = (typeof STEP_FINDING_CODES)[number];\n\n/** A finding of the step gate. */\nexport type StepFinding = Finding<StepFindingCode, \"step\" | \"gap\" | \"cell\">;\n\n/** The options of the step gate. */\nexport interface StepGateOptions<P extends string> extends UseContext {\n /** The phases that a step can have. */\n readonly phases: readonly P[];\n /** The keys of the matrix. With them, the gate finds each cell that has no step and no marked gap. */\n readonly on?: readonly string[];\n /** The marked gaps of the library. */\n readonly gaps?: readonly Gap<P>[];\n}\n\n/** This function gives one summary unit for each source of each step, so the source gate examines the steps. */\nexport function unitsOf<P extends string>(steps: readonly Step<P>[]): readonly CitedUnit[] {\n return steps.flatMap((step) => step.sources.map((source) => ({ id: `${step.id}@${source}`, use: \"summary\" as const, text: step.do, source })));\n}\n\n/**\n * This function applies the step gate. It examines the ids, the text, the sources, the phases and the order of each step.\n * It examines the sources with the source gate: the text of a step is a summary of each of its sources.\n * With `on`, it also finds each cell of the matrix that has no step and no marked gap.\n */\nexport function checkSteps<P extends string>(steps: readonly Step<P>[], sources: readonly Source[], options: StepGateOptions<P>): GateResult<StepFinding> {\n const out: StepFinding[] = [];\n const error = (code: StepFindingCode, record: StepFinding[\"record\"], id: string, message: string): void => {\n out.push({ level: \"error\", code, record, id, message });\n };\n const phases = new Set<string>(options.phases);\n const ids = new Set<string>();\n const orders = new Map<string, string>();\n for (const step of steps) {\n if (ids.has(step.id)) error(\"duplicate-id\", \"step\", step.id, `Two steps have the id \"${step.id}\".`);\n ids.add(step.id);\n if (step.do.trim() === \"\") error(\"empty-text\", \"step\", step.id, `The step \"${step.id}\" has no text.`);\n if (step.reasoning !== undefined && step.reasoning.trim() === \"\") error(\"empty-reasoning\", \"step\", step.id, `The step \"${step.id}\" has an empty reasoning.`);\n if (step.sources.length === 0) {\n if (step.reasoning === undefined) error(\"no-source\", \"step\", step.id, `The step \"${step.id}\" cites no source and gives no reasoning.`);\n else if (/[0-9]/.test(step.do)) error(\"number-without-source\", \"step\", step.id, `The step \"${step.id}\" has a number, so it needs a source.`);\n }\n if (!phases.has(step.phase)) error(\"unknown-phase\", \"step\", step.id, `The step \"${step.id}\" has the unknown phase \"${step.phase}\".`);\n if (!Number.isInteger(step.order) || step.order < 1) error(\"bad-order\", \"step\", step.id, `The step \"${step.id}\" has the order ${String(step.order)}. It needs an integer from 1.`);\n const cell = `${step.on}\\u0000${step.phase}\\u0000${String(step.order)}`;\n const other = orders.get(cell);\n if (other !== undefined) error(\"duplicate-order\", \"step\", step.id, `The steps \"${other}\" and \"${step.id}\" have the same order in \"${step.on}\", phase \"${step.phase}\".`);\n else orders.set(cell, step.id);\n }\n for (const finding of checkUnits(unitsOf(steps), sources, options)) {\n if (finding.code !== \"missing-source\" && finding.code !== \"use-refused\") continue;\n const id = finding.id.slice(0, finding.id.lastIndexOf(\"@\"));\n out.push({ level: finding.level, code: finding.code, record: \"step\", id, message: finding.message.replace(`unit \"${finding.id}\"`, `step \"${id}\"`) });\n }\n out.push(...checkGaps(steps, options));\n return resultOf(out);\n}\n\nfunction checkGaps<P extends string>(steps: readonly Step<P>[], options: StepGateOptions<P>): StepFinding[] {\n const out: StepFinding[] = [];\n const gaps = options.gaps ?? [];\n const seen = new Set<string>();\n for (const gap of gaps) {\n const id = `${gap.on}/${gap.phase}`;\n if (seen.has(id)) out.push({ level: \"error\", code: \"duplicate-gap\", record: \"gap\", id, message: `Two gaps mark \"${gap.on}\" in phase \"${gap.phase}\".` });\n seen.add(id);\n if (gap.why.trim() === \"\") out.push({ level: \"error\", code: \"empty-reason\", record: \"gap\", id, message: `The gap of \"${gap.on}\" in phase \"${gap.phase}\" gives no reason.` });\n const count = steps.filter((step) => step.on === gap.on && step.phase === gap.phase).length;\n if (count > 0) out.push({ level: \"error\", code: \"gap-with-steps\", record: \"gap\", id, message: `A gap marks \"${gap.on}\" in phase \"${gap.phase}\", but the cell has ${String(count)} steps.` });\n if (!options.phases.includes(gap.phase)) out.push({ level: \"error\", code: \"unknown-phase\", record: \"gap\", id, message: `The gap of \"${gap.on}\" has the unknown phase \"${gap.phase}\".` });\n }\n if (options.on === undefined) return out;\n for (const row of planMatrix(steps, gaps, options.on, options.phases)) {\n for (const cell of row) {\n const id = `${cell.on}/${cell.phase}`;\n if (cell.steps.length === 0 && cell.gap === undefined) {\n out.push({ level: \"error\", code: \"unmarked-gap\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\", and no gap marks the cell.` });\n }\n }\n }\n return out;\n}\n","// The coverage gate: each key of a catalog has steps in each phase of a set. A marked gap does not pass it.\n\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult } from \"@mark1russell7/guidebook\";\nimport { planMatrix, type Gap, type Step } from \"./steps.ts\";\n\n/** The horizons of a plan: the phases from the first 5 minutes to 5 years. The coverage gate examines them by default. */\nexport const HORIZONS = [\"P0\", \"P1\", \"P2\", \"P3\", \"P4\", \"P5\"] as const;\n\n/** The codes of the findings of the coverage gate. */\nexport const COVERAGE_FINDING_CODES = [\"no-step\", \"marked-gap\"] as const;\n\n/** A code of a finding of the coverage gate. */\nexport type CoverageFindingCode = (typeof COVERAGE_FINDING_CODES)[number];\n\n/** A finding of the coverage gate. Its `id` is `<key>/<phase>`. */\nexport type CoverageFinding = Finding<CoverageFindingCode, \"cell\">;\n\n/** The options of the coverage gate. */\nexport interface CoverageOptions<P extends string> {\n /** The keys of the catalog. Each key needs steps in each phase. */\n readonly on: readonly string[];\n /** The phases that each key needs. */\n readonly phases: readonly P[];\n /** The marked gaps of the library. The gate shows the reason of a gap, but the gap does not pass. */\n readonly gaps?: readonly Gap<P>[];\n}\n\n/** The coverage of one key: the phases with steps and the phases with no step. */\nexport interface KeyCoverage<P extends string> {\n readonly on: string;\n readonly covered: readonly P[];\n readonly missing: readonly P[];\n}\n\n/** This function gives the coverage of each key of `on` over `phases`, in the sequence of `on`. */\nexport function coverageOf<P extends string>(steps: readonly Step<P>[], on: readonly string[], phases: readonly P[]): readonly KeyCoverage<P>[] {\n return planMatrix(steps, [], on, phases).map((row, index) => ({\n on: on[index] ?? \"\",\n covered: row.filter((cell) => cell.steps.length > 0).map((cell) => cell.phase),\n missing: row.filter((cell) => cell.steps.length === 0).map((cell) => cell.phase),\n }));\n}\n\n/**\n * This function applies the coverage gate. Each key of `on` needs one or more steps in each phase of `phases`.\n * A cell with no step is an error, also when a gap marks it: the finding `marked-gap` gives the reason of the gap.\n * Thus a key with no step shows each of its gaps, and it does not pass.\n */\nexport function checkCoverage<P extends string>(steps: readonly Step<P>[], options: CoverageOptions<P>): GateResult<CoverageFinding> {\n const out: CoverageFinding[] = [];\n for (const row of planMatrix(steps, options.gaps ?? [], options.on, options.phases)) {\n for (const cell of row) {\n if (cell.steps.length > 0) continue;\n const id = `${cell.on}/${cell.phase}`;\n out.push(\n cell.gap === undefined\n ? { level: \"error\", code: \"no-step\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\".` }\n : { level: \"error\", code: \"marked-gap\", record: \"cell\", id, message: `\"${cell.on}\" has no step in phase \"${cell.phase}\". The gap gives the reason: ${cell.gap.why}` },\n );\n }\n }\n return resultOf(out);\n}\n","// The decision chart: trigger rules as data. Each rule names a trigger, the keys of the trigger and a target in the steps.\n// The rule gate examines that each key is known, each target has steps and each rule cites its sources.\n\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult, Source } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Step } from \"./steps.ts\";\n\n/**\n * The kinds of rule, in the sequence of the chart.\n * The chart asks first for the place. Then it asks for an immediate danger and for the cuts.\n * Then it asks when to stay, to go or to change the plan.\n */\nexport const RULE_KINDS = [\"place\", \"reflex\", \"module\", \"stay\", \"go\", \"fallback\", \"long-plan\"] as const;\n\n/** A kind of rule. */\nexport type RuleKind = (typeof RULE_KINDS)[number];\n\n/** The words of each kind of rule, for a chart. */\nexport const RULE_KIND_TITLES: Readonly<Record<RuleKind, string>> = {\n place: \"Where am I?\",\n reflex: \"Is there an immediate danger?\",\n module: \"What is cut?\",\n stay: \"When do I stay?\",\n go: \"When do I go?\",\n fallback: \"When do I go to a fallback place?\",\n \"long-plan\": \"When do I change to the long plan?\",\n};\n\n/** The target of a rule: the steps of a key in the given phases. */\nexport interface RuleTarget<P extends string = Phase> {\n readonly on: string;\n readonly phases: readonly P[];\n}\n\n/** A trigger rule of the decision chart. */\nexport interface Rule<P extends string = Phase> {\n readonly id: string;\n readonly kind: RuleKind;\n /** The trigger, as one sentence in Simplified Technical English. A print shows it. */\n readonly when: string;\n /** The action, as one instruction. A print shows it with the target. */\n readonly then: string;\n /** The keys that the trigger names: cases, cuts or needs. */\n readonly on: readonly string[];\n /** The steps that the rule sends the reader to. A rule of the kind `place` has no target, because the places are input data. */\n readonly target?: RuleTarget<P>;\n /** The rank in its kind. A rule with a lower rank comes first. */\n readonly rank: number;\n /** The ids of the sources that tell the trigger and the action. */\n readonly sources: readonly string[];\n}\n\n/** The codes of the findings of the rule gate. */\nexport const RULE_FINDING_CODES = [\"duplicate-id\", \"unknown-key\", \"no-target\", \"target-without-steps\", \"no-source\", \"unknown-source\"] as const;\n\n/** A code of a finding of the rule gate. */\nexport type RuleFindingCode = (typeof RULE_FINDING_CODES)[number];\n\n/** A finding of the rule gate. */\nexport type RuleFinding = Finding<RuleFindingCode, \"rule\">;\n\n/** The options of the rule gate. */\nexport interface RuleGateOptions {\n /** The known keys: the cases, the cuts and the needs. */\n readonly on: readonly string[];\n}\n\n/**\n * This function applies the rule gate.\n * Each key of a rule is known. Each rule other than `place` has a target with one or more steps. Each rule cites a known source.\n */\nexport function checkRules<P extends string>(rules: readonly Rule<P>[], steps: readonly Step<P>[], sources: readonly Source[], options: RuleGateOptions): GateResult<RuleFinding> {\n const out: RuleFinding[] = [];\n const known = new Set(options.on);\n const sourceIds = new Set(sources.map((source) => source.id));\n const seen = new Set<string>();\n const error = (code: RuleFindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"rule\", id, message });\n };\n for (const rule of rules) {\n if (seen.has(rule.id)) error(\"duplicate-id\", rule.id, `Two rules have the id \"${rule.id}\".`);\n seen.add(rule.id);\n for (const key of rule.on) if (!known.has(key)) error(\"unknown-key\", rule.id, `The rule names the unknown key \"${key}\".`);\n if (rule.target === undefined) {\n if (rule.kind !== \"place\") error(\"no-target\", rule.id, `The rule of the kind \"${rule.kind}\" has no target.`);\n } else {\n const { on, phases } = rule.target;\n if (!known.has(on)) error(\"unknown-key\", rule.id, `The target names the unknown key \"${on}\".`);\n else if (!steps.some((step) => step.on === on && phases.includes(step.phase))) {\n error(\"target-without-steps\", rule.id, `The target \"${on}\" has no step in the phases ${phases.join(\", \")}.`);\n }\n }\n if (rule.sources.length === 0) error(\"no-source\", rule.id, \"The rule cites no source.\");\n for (const id of rule.sources) if (!sourceIds.has(id)) error(\"unknown-source\", rule.id, `The rule cites the unknown source \"${id}\".`);\n }\n return resultOf(out);\n}\n\n/** One question of the chart: a kind of rule and its rules in the sequence of their rank. */\nexport interface ChartQuestion<P extends string = Phase> {\n readonly kind: RuleKind;\n readonly title: string;\n readonly rules: readonly Rule<P>[];\n}\n\n/** This function gives the chart of a set of rules: one question for each kind that has rules, in the sequence of `RULE_KINDS`. */\nexport function chartOf<P extends string>(rules: readonly Rule<P>[]): readonly ChartQuestion<P>[] {\n return RULE_KINDS.flatMap((kind) => {\n const ofKind = rules.filter((rule) => rule.kind === kind).sort((a, b) => a.rank - b.rank || a.id.localeCompare(b.id));\n return ofKind.length === 0 ? [] : [{ kind, title: RULE_KIND_TITLES[kind], rules: ofKind }];\n });\n}\n","// The master chart: one chart for any disaster, as data. A reader starts at a signal, answers a few questions and goes to a tab.\n// A tab is a section of a printed plan: a set of keys and phases. The print gives each tab its page.\n\nimport { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { resultOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, GateResult, Source } from \"@mark1russell7/guidebook\";\nimport type { Phase } from \"./ladder.ts\";\nimport type { Step } from \"./steps.ts\";\n\n/** The states of society after an event, from a society that works to a society that does not work. */\nexport const SOCIETY_STATES = [\"works\", \"partly\", \"none\"] as const;\n\n/** A state of society: the emergency services, the shops, the grid and the law work, work in part or do not work. */\nexport type Society = (typeof SOCIETY_STATES)[number];\n\n/** The words of each state of society, for a chart. */\nexport const SOCIETY_TITLES: Readonly<Record<Society, string>> = {\n works: \"Society works\",\n partly: \"Society works in part\",\n none: \"Society does not work\",\n};\n\n/**\n * A tab of a printed plan: the steps of its keys in its phases.\n * Each state of society is a section in the tab, so a tab is for one need or one subject, not for one state.\n */\nexport interface Tab<P extends string = Phase> {\n readonly id: string;\n readonly title: string;\n /** The keys of the tab: cases, cuts or needs. A tab of reference text or of a chart has no keys. */\n readonly keys: readonly string[];\n readonly phases: readonly P[];\n /** The most pages that the print of the tab can use. */\n readonly pages?: number;\n}\n\n/** An answer to a question of the chart. */\nexport interface ChartAnswer {\n /** The words of the answer, for a chart. */\n readonly label: string;\n /** The id of the next node. */\n readonly next: string;\n /** The state of society that the answer tells, if any. */\n readonly society?: Society;\n}\n\n/** A start of the chart: a thing that a reader sees or hears. */\nexport interface SignalNode {\n readonly id: string;\n readonly kind: \"signal\";\n readonly text: string;\n readonly next: string;\n readonly sources?: readonly string[];\n}\n\n/** A question of the chart, with two or more answers. */\nexport interface QuestionNode {\n readonly id: string;\n readonly kind: \"question\";\n readonly text: string;\n readonly answers: readonly ChartAnswer[];\n /** The ids of the sources that tell the question and its answers. */\n readonly sources: readonly string[];\n /** The reasoning of the question from first principles, for a question that no source tells. */\n readonly reasoning?: string;\n}\n\n/** An end of the chart: an instruction that sends the reader to a tab. */\nexport interface GotoNode {\n readonly id: string;\n readonly kind: \"goto\";\n readonly text: string;\n readonly tab: string;\n readonly sources?: readonly string[];\n}\n\n/** A node of the master chart. */\nexport type ChartNode = SignalNode | QuestionNode | GotoNode;\n\n/** The codes of the findings of the chart gate. */\nexport const MASTER_FINDING_CODES = [\n \"duplicate-id\",\n \"unknown-node\",\n \"unknown-tab\",\n \"unknown-key\",\n \"few-answers\",\n \"no-signal\",\n \"unreachable\",\n \"cycle\",\n \"too-deep\",\n \"too-many-nodes\",\n \"too-many-ends\",\n \"tab-without-steps\",\n \"unused-tab\",\n \"uncovered-key\",\n \"no-source\",\n \"unknown-source\",\n] as const;\n\n/** A code of a finding of the chart gate. */\nexport type MasterFindingCode = (typeof MASTER_FINDING_CODES)[number];\n\n/** A finding of the chart gate. */\nexport type MasterFinding = Finding<MasterFindingCode, \"chart\">;\n\n/** The options of the chart gate. */\nexport interface MasterGateOptions {\n /** The known keys: the cases, the cuts and the needs. */\n readonly on: readonly string[];\n /** The keys that a tab of the chart must hold. No `cover` means no key. */\n readonly cover?: readonly string[];\n /** The most questions on a path from a signal to a tab. The default is 3. */\n readonly maxQuestions?: number;\n /** The most nodes that the print of the chart can hold. No `maxNodes` means no limit. */\n readonly maxNodes?: number;\n /** The most ends (nodes of the kind `goto`) that the print of the chart can hold. No `maxEnds` means no limit. */\n readonly maxEnds?: number;\n}\n\n/** The ids of the nodes that come after a node. */\nfunction nextOf(node: ChartNode): readonly string[] {\n if (node.kind === \"signal\") return [node.next];\n if (node.kind === \"question\") return node.answers.map((answer) => answer.next);\n return [];\n}\n\n/** The nodes in a cycle. A chart with a cycle has no end on that path. */\nfunction cycleNodes(nodes: readonly ChartNode[], byId: ReadonlyMap<string, ChartNode>): Set<string> {\n const next = (id: string): readonly string[] => {\n const node = byId.get(id);\n return node === undefined ? [] : nextOf(node).filter((to) => byId.has(to));\n };\n const out = new Set<string>();\n for (const group of stronglyConnectedComponents(nodes.map((node) => node.id), next)) {\n const [first] = group;\n if (group.length > 1 || (first !== undefined && next(first).includes(first))) for (const id of group) out.add(id);\n }\n return out;\n}\n\n/** The most questions from each node to an end, on a chart with no cycle. */\nfunction questionsToEnd(byId: ReadonlyMap<string, ChartNode>, skip: ReadonlySet<string>): Map<string, number> {\n const memo = new Map<string, number>();\n const walk = (id: string): number => {\n const known = memo.get(id);\n if (known !== undefined) return known;\n const node = byId.get(id);\n if (node === undefined || skip.has(id)) return 0;\n const rest = Math.max(0, ...nextOf(node).map(walk));\n const value = (node.kind === \"question\" ? 1 : 0) + rest;\n memo.set(id, value);\n return value;\n };\n for (const id of byId.keys()) walk(id);\n return memo;\n}\n\n/** The ids of the nodes that a signal reaches. */\nfunction reached(nodes: readonly ChartNode[], byId: ReadonlyMap<string, ChartNode>): Set<string> {\n const seen = new Set<string>();\n const stack = nodes.filter((node) => node.kind === \"signal\").map((node) => node.id);\n for (let id = stack.pop(); id !== undefined; id = stack.pop()) {\n if (seen.has(id)) continue;\n seen.add(id);\n const node = byId.get(id);\n if (node !== undefined) stack.push(...nextOf(node));\n }\n return seen;\n}\n\n/**\n * This function applies the chart gate.\n * Each node is known and reached, and each path ends at a known tab after a few questions.\n * Each tab with keys has steps. Each key of `cover` is in a tab that the chart reaches.\n */\nexport function checkMasterChart<P extends string>(\n nodes: readonly ChartNode[],\n tabs: readonly Tab<P>[],\n steps: readonly Step<P>[],\n sources: readonly Source[],\n options: MasterGateOptions,\n): GateResult<MasterFinding> {\n const out: MasterFinding[] = [];\n const error = (code: MasterFindingCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"chart\", id, message });\n };\n const byId = new Map<string, ChartNode>();\n for (const node of nodes) {\n if (byId.has(node.id)) error(\"duplicate-id\", node.id, `Two nodes have the id \"${node.id}\".`);\n byId.set(node.id, node);\n }\n const tabById = new Map<string, Tab<P>>();\n for (const tab of tabs) {\n if (tabById.has(tab.id)) error(\"duplicate-id\", tab.id, `Two tabs have the id \"${tab.id}\".`);\n tabById.set(tab.id, tab);\n }\n const known = new Set(options.on);\n const sourceIds = new Set(sources.map((source) => source.id));\n\n for (const node of nodes) {\n for (const to of nextOf(node)) if (!byId.has(to)) error(\"unknown-node\", node.id, `The node goes to the unknown node \"${to}\".`);\n if (node.kind === \"question\" && node.answers.length < 2) error(\"few-answers\", node.id, \"The question has fewer than 2 answers.\");\n if (node.kind === \"goto\" && !tabById.has(node.tab)) error(\"unknown-tab\", node.id, `The node goes to the unknown tab \"${node.tab}\".`);\n if (node.kind === \"question\" && node.sources.length === 0 && (node.reasoning ?? \"\").trim() === \"\") error(\"no-source\", node.id, \"The question cites no source and gives no reasoning.\");\n for (const id of node.sources ?? []) if (!sourceIds.has(id)) error(\"unknown-source\", node.id, `The node cites the unknown source \"${id}\".`);\n }\n if (!nodes.some((node) => node.kind === \"signal\")) error(\"no-signal\", \"chart\", \"The chart has no signal, so a reader cannot start.\");\n\n const seen = reached(nodes, byId);\n for (const node of nodes) if (!seen.has(node.id)) error(\"unreachable\", node.id, \"No signal reaches the node.\");\n const cycle = cycleNodes(nodes, byId);\n for (const id of cycle) error(\"cycle\", id, \"The node is in a cycle, so its path has no end.\");\n const limit = options.maxQuestions ?? 3;\n const depth = questionsToEnd(byId, cycle);\n for (const node of nodes) {\n const value = depth.get(node.id) ?? 0;\n if (node.kind === \"signal\" && value > limit) error(\"too-deep\", node.id, `A path from the signal has ${value} questions. The limit is ${limit}.`);\n }\n\n if (options.maxNodes !== undefined && nodes.length > options.maxNodes) error(\"too-many-nodes\", \"chart\", `The chart has ${nodes.length} nodes. The limit is ${options.maxNodes}.`);\n const ends = nodes.filter((node) => node.kind === \"goto\").length;\n if (options.maxEnds !== undefined && ends > options.maxEnds) error(\"too-many-ends\", \"chart\", `The chart has ${ends} ends. The limit is ${options.maxEnds}.`);\n\n const used = new Set(nodes.filter((node) => seen.has(node.id)).flatMap((node) => (node.kind === \"goto\" ? [node.tab] : [])));\n for (const tab of tabs) {\n for (const key of tab.keys) if (!known.has(key)) error(\"unknown-key\", tab.id, `The tab names the unknown key \"${key}\".`);\n const keys = new Set(tab.keys);\n if (keys.size > 0 && !steps.some((step) => keys.has(step.on) && tab.phases.includes(step.phase))) error(\"tab-without-steps\", tab.id, \"The tab has no step in its keys and phases.\");\n if (!used.has(tab.id)) error(\"unused-tab\", tab.id, \"No path of the chart goes to the tab.\");\n }\n const held = new Set([...used].flatMap((id) => tabById.get(id)?.keys ?? []));\n for (const key of options.cover ?? []) if (!held.has(key)) error(\"uncovered-key\", key, `No tab of the chart holds the key \"${key}\".`);\n return resultOf(out);\n}\n\n/** An edge of the master chart, for a renderer. */\nexport interface ChartEdge {\n readonly from: string;\n readonly to: string;\n /** The words of the answer. A signal edge has no label. */\n readonly label?: string;\n}\n\n/** A node of the master chart with its layer: the most edges from a signal to the node. */\nexport interface PlacedNode {\n readonly node: ChartNode;\n readonly layer: number;\n}\n\n/** The master chart, for a renderer: the nodes by layer, the edges and the tabs that the chart reaches. */\nexport interface MasterChart<P extends string = Phase> {\n readonly nodes: readonly PlacedNode[];\n readonly edges: readonly ChartEdge[];\n readonly tabs: readonly Tab<P>[];\n}\n\n/** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */\nexport function masterChartOf<P extends string>(nodes: readonly ChartNode[], tabs: readonly Tab<P>[]): MasterChart<P> {\n const byId = new Map(nodes.map((node) => [node.id, node] as const));\n const cycle = cycleNodes(nodes, byId);\n const edges: ChartEdge[] = nodes.flatMap((node): ChartEdge[] => {\n if (node.kind === \"signal\") return [{ from: node.id, to: node.next }];\n if (node.kind === \"question\") return node.answers.map((answer) => ({ from: node.id, to: answer.next, label: answer.label }));\n return [];\n });\n const layer = new Map<string, number>();\n const into = new Map<string, string[]>();\n for (const edge of edges) into.set(edge.to, [...(into.get(edge.to) ?? []), edge.from]);\n const layerOf = (id: string): number => {\n const known = layer.get(id);\n if (known !== undefined) return known;\n const before = (into.get(id) ?? []).filter((from) => byId.has(from) && !cycle.has(from));\n const value = before.length === 0 ? 0 : 1 + Math.max(...before.map(layerOf));\n layer.set(id, value);\n return value;\n };\n const placed = nodes.filter((node) => !cycle.has(node.id)).map((node) => ({ node, layer: layerOf(node.id) }));\n placed.sort((a, b) => a.layer - b.layer);\n const tabIds = new Set(nodes.flatMap((node) => (node.kind === \"goto\" ? [node.tab] : [])));\n return { nodes: placed, edges, tabs: tabs.filter((tab) => tabIds.has(tab.id)) };\n}\n"],"mappings":";;;AAGA,MAAM,OAAO;AACb,MAAM,MAAM,KAAK;AACjB,MAAM,OAAO,IAAI;;AAEjB,MAAM,QAAQ,KAAK;AACnB,MAAM,OAAO,MAAM;;AAGnB,MAAa,kBAA0B;;AAcvC,MAAa,SAAS;CAAC;CAAS;CAAU;CAAM;CAAM;CAAM;CAAM;CAAM;AAAI;;AAM5E,MAAa,eAAkC;CAAC;CAAG;CAAY,IAAI;CAAM,IAA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,IAAI,CAAC,CAAE,CAAC;CACxF,OAAO;EAAE,OAAO;EAAQ;EAAO,MAAM,KAAK,QAAQ,QAAQ,OAAO,IAAI,IAAI,EAAE,CAAC;CAAE;AAChF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/guidebook-plans",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "The plans add-on of the guidebook: a time ladder of phases, steps keyed by a case or a cut and a phase, the steps query, the matrix of a library with its marked gaps, and the step gate.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"guidebook",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"tsdown": "^0.23.7"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
+
"@mark1russell7/collections": "^0.11.3",
|
|
56
57
|
"@mark1russell7/guidebook": "0.1.1"
|
|
57
58
|
},
|
|
58
59
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
// The plans add-on of the guidebook: the time ladder, the steps of a plan by key and phase, the matrix of a library, the step gate, the coverage gate and the
|
|
1
|
+
// The plans add-on of the guidebook: the time ladder, the steps of a plan by key and phase, the matrix of a library, the step gate, the coverage gate, the decision chart and the master chart.
|
|
2
2
|
// The add-on names no topic. A content package gives the steps of its topic.
|
|
3
3
|
|
|
4
4
|
export { LADDER, PHASES, PHASE_BOUNDS, PHASE_TITLES, SECONDS_PER_DAY, phaseIn, phaseOf, phasesOf } from "./ladder.ts";
|
|
5
5
|
export type { Ladder, Phase } from "./ladder.ts";
|
|
6
6
|
export { STEP_FINDING_CODES, checkSteps, planMatrix, stepsFor, unitsOf } from "./steps.ts";
|
|
7
|
-
export type { Cell, Gap, Step, StepFinding, StepFindingCode, StepGateOptions } from "./steps.ts";
|
|
7
|
+
export type { Cell, Gap, Step, StepFinding, StepFindingCode, StepGateOptions, StepsForOptions } from "./steps.ts";
|
|
8
8
|
export { COVERAGE_FINDING_CODES, HORIZONS, checkCoverage, coverageOf } from "./coverage.ts";
|
|
9
9
|
export type { CoverageFinding, CoverageFindingCode, CoverageOptions, KeyCoverage } from "./coverage.ts";
|
|
10
10
|
export { RULE_FINDING_CODES, RULE_KINDS, RULE_KIND_TITLES, chartOf, checkRules } from "./rules.ts";
|
|
11
11
|
export type { ChartQuestion, Rule, RuleFinding, RuleFindingCode, RuleGateOptions, RuleKind, RuleTarget } from "./rules.ts";
|
|
12
|
+
export { MASTER_FINDING_CODES, SOCIETY_STATES, SOCIETY_TITLES, checkMasterChart, masterChartOf } from "./master.ts";
|
|
13
|
+
export type { ChartAnswer, ChartEdge, ChartNode, GotoNode, MasterChart, MasterFinding, MasterFindingCode, MasterGateOptions, PlacedNode, QuestionNode, SignalNode, Society, Tab } from "./master.ts";
|
package/src/master.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// The master chart: one chart for any disaster, as data. A reader starts at a signal, answers a few questions and goes to a tab.
|
|
2
|
+
// A tab is a section of a printed plan: a set of keys and phases. The print gives each tab its page.
|
|
3
|
+
|
|
4
|
+
import { stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
5
|
+
import { resultOf } from "@mark1russell7/guidebook";
|
|
6
|
+
import type { Finding, GateResult, Source } from "@mark1russell7/guidebook";
|
|
7
|
+
import type { Phase } from "./ladder.ts";
|
|
8
|
+
import type { Step } from "./steps.ts";
|
|
9
|
+
|
|
10
|
+
/** The states of society after an event, from a society that works to a society that does not work. */
|
|
11
|
+
export const SOCIETY_STATES = ["works", "partly", "none"] as const;
|
|
12
|
+
|
|
13
|
+
/** A state of society: the emergency services, the shops, the grid and the law work, work in part or do not work. */
|
|
14
|
+
export type Society = (typeof SOCIETY_STATES)[number];
|
|
15
|
+
|
|
16
|
+
/** The words of each state of society, for a chart. */
|
|
17
|
+
export const SOCIETY_TITLES: Readonly<Record<Society, string>> = {
|
|
18
|
+
works: "Society works",
|
|
19
|
+
partly: "Society works in part",
|
|
20
|
+
none: "Society does not work",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A tab of a printed plan: the steps of its keys in its phases.
|
|
25
|
+
* Each state of society is a section in the tab, so a tab is for one need or one subject, not for one state.
|
|
26
|
+
*/
|
|
27
|
+
export interface Tab<P extends string = Phase> {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly title: string;
|
|
30
|
+
/** The keys of the tab: cases, cuts or needs. A tab of reference text or of a chart has no keys. */
|
|
31
|
+
readonly keys: readonly string[];
|
|
32
|
+
readonly phases: readonly P[];
|
|
33
|
+
/** The most pages that the print of the tab can use. */
|
|
34
|
+
readonly pages?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** An answer to a question of the chart. */
|
|
38
|
+
export interface ChartAnswer {
|
|
39
|
+
/** The words of the answer, for a chart. */
|
|
40
|
+
readonly label: string;
|
|
41
|
+
/** The id of the next node. */
|
|
42
|
+
readonly next: string;
|
|
43
|
+
/** The state of society that the answer tells, if any. */
|
|
44
|
+
readonly society?: Society;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A start of the chart: a thing that a reader sees or hears. */
|
|
48
|
+
export interface SignalNode {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly kind: "signal";
|
|
51
|
+
readonly text: string;
|
|
52
|
+
readonly next: string;
|
|
53
|
+
readonly sources?: readonly string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A question of the chart, with two or more answers. */
|
|
57
|
+
export interface QuestionNode {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly kind: "question";
|
|
60
|
+
readonly text: string;
|
|
61
|
+
readonly answers: readonly ChartAnswer[];
|
|
62
|
+
/** The ids of the sources that tell the question and its answers. */
|
|
63
|
+
readonly sources: readonly string[];
|
|
64
|
+
/** The reasoning of the question from first principles, for a question that no source tells. */
|
|
65
|
+
readonly reasoning?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** An end of the chart: an instruction that sends the reader to a tab. */
|
|
69
|
+
export interface GotoNode {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly kind: "goto";
|
|
72
|
+
readonly text: string;
|
|
73
|
+
readonly tab: string;
|
|
74
|
+
readonly sources?: readonly string[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A node of the master chart. */
|
|
78
|
+
export type ChartNode = SignalNode | QuestionNode | GotoNode;
|
|
79
|
+
|
|
80
|
+
/** The codes of the findings of the chart gate. */
|
|
81
|
+
export const MASTER_FINDING_CODES = [
|
|
82
|
+
"duplicate-id",
|
|
83
|
+
"unknown-node",
|
|
84
|
+
"unknown-tab",
|
|
85
|
+
"unknown-key",
|
|
86
|
+
"few-answers",
|
|
87
|
+
"no-signal",
|
|
88
|
+
"unreachable",
|
|
89
|
+
"cycle",
|
|
90
|
+
"too-deep",
|
|
91
|
+
"too-many-nodes",
|
|
92
|
+
"too-many-ends",
|
|
93
|
+
"tab-without-steps",
|
|
94
|
+
"unused-tab",
|
|
95
|
+
"uncovered-key",
|
|
96
|
+
"no-source",
|
|
97
|
+
"unknown-source",
|
|
98
|
+
] as const;
|
|
99
|
+
|
|
100
|
+
/** A code of a finding of the chart gate. */
|
|
101
|
+
export type MasterFindingCode = (typeof MASTER_FINDING_CODES)[number];
|
|
102
|
+
|
|
103
|
+
/** A finding of the chart gate. */
|
|
104
|
+
export type MasterFinding = Finding<MasterFindingCode, "chart">;
|
|
105
|
+
|
|
106
|
+
/** The options of the chart gate. */
|
|
107
|
+
export interface MasterGateOptions {
|
|
108
|
+
/** The known keys: the cases, the cuts and the needs. */
|
|
109
|
+
readonly on: readonly string[];
|
|
110
|
+
/** The keys that a tab of the chart must hold. No `cover` means no key. */
|
|
111
|
+
readonly cover?: readonly string[];
|
|
112
|
+
/** The most questions on a path from a signal to a tab. The default is 3. */
|
|
113
|
+
readonly maxQuestions?: number;
|
|
114
|
+
/** The most nodes that the print of the chart can hold. No `maxNodes` means no limit. */
|
|
115
|
+
readonly maxNodes?: number;
|
|
116
|
+
/** The most ends (nodes of the kind `goto`) that the print of the chart can hold. No `maxEnds` means no limit. */
|
|
117
|
+
readonly maxEnds?: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The ids of the nodes that come after a node. */
|
|
121
|
+
function nextOf(node: ChartNode): readonly string[] {
|
|
122
|
+
if (node.kind === "signal") return [node.next];
|
|
123
|
+
if (node.kind === "question") return node.answers.map((answer) => answer.next);
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The nodes in a cycle. A chart with a cycle has no end on that path. */
|
|
128
|
+
function cycleNodes(nodes: readonly ChartNode[], byId: ReadonlyMap<string, ChartNode>): Set<string> {
|
|
129
|
+
const next = (id: string): readonly string[] => {
|
|
130
|
+
const node = byId.get(id);
|
|
131
|
+
return node === undefined ? [] : nextOf(node).filter((to) => byId.has(to));
|
|
132
|
+
};
|
|
133
|
+
const out = new Set<string>();
|
|
134
|
+
for (const group of stronglyConnectedComponents(nodes.map((node) => node.id), next)) {
|
|
135
|
+
const [first] = group;
|
|
136
|
+
if (group.length > 1 || (first !== undefined && next(first).includes(first))) for (const id of group) out.add(id);
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The most questions from each node to an end, on a chart with no cycle. */
|
|
142
|
+
function questionsToEnd(byId: ReadonlyMap<string, ChartNode>, skip: ReadonlySet<string>): Map<string, number> {
|
|
143
|
+
const memo = new Map<string, number>();
|
|
144
|
+
const walk = (id: string): number => {
|
|
145
|
+
const known = memo.get(id);
|
|
146
|
+
if (known !== undefined) return known;
|
|
147
|
+
const node = byId.get(id);
|
|
148
|
+
if (node === undefined || skip.has(id)) return 0;
|
|
149
|
+
const rest = Math.max(0, ...nextOf(node).map(walk));
|
|
150
|
+
const value = (node.kind === "question" ? 1 : 0) + rest;
|
|
151
|
+
memo.set(id, value);
|
|
152
|
+
return value;
|
|
153
|
+
};
|
|
154
|
+
for (const id of byId.keys()) walk(id);
|
|
155
|
+
return memo;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The ids of the nodes that a signal reaches. */
|
|
159
|
+
function reached(nodes: readonly ChartNode[], byId: ReadonlyMap<string, ChartNode>): Set<string> {
|
|
160
|
+
const seen = new Set<string>();
|
|
161
|
+
const stack = nodes.filter((node) => node.kind === "signal").map((node) => node.id);
|
|
162
|
+
for (let id = stack.pop(); id !== undefined; id = stack.pop()) {
|
|
163
|
+
if (seen.has(id)) continue;
|
|
164
|
+
seen.add(id);
|
|
165
|
+
const node = byId.get(id);
|
|
166
|
+
if (node !== undefined) stack.push(...nextOf(node));
|
|
167
|
+
}
|
|
168
|
+
return seen;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* This function applies the chart gate.
|
|
173
|
+
* Each node is known and reached, and each path ends at a known tab after a few questions.
|
|
174
|
+
* Each tab with keys has steps. Each key of `cover` is in a tab that the chart reaches.
|
|
175
|
+
*/
|
|
176
|
+
export function checkMasterChart<P extends string>(
|
|
177
|
+
nodes: readonly ChartNode[],
|
|
178
|
+
tabs: readonly Tab<P>[],
|
|
179
|
+
steps: readonly Step<P>[],
|
|
180
|
+
sources: readonly Source[],
|
|
181
|
+
options: MasterGateOptions,
|
|
182
|
+
): GateResult<MasterFinding> {
|
|
183
|
+
const out: MasterFinding[] = [];
|
|
184
|
+
const error = (code: MasterFindingCode, id: string, message: string): void => {
|
|
185
|
+
out.push({ level: "error", code, record: "chart", id, message });
|
|
186
|
+
};
|
|
187
|
+
const byId = new Map<string, ChartNode>();
|
|
188
|
+
for (const node of nodes) {
|
|
189
|
+
if (byId.has(node.id)) error("duplicate-id", node.id, `Two nodes have the id "${node.id}".`);
|
|
190
|
+
byId.set(node.id, node);
|
|
191
|
+
}
|
|
192
|
+
const tabById = new Map<string, Tab<P>>();
|
|
193
|
+
for (const tab of tabs) {
|
|
194
|
+
if (tabById.has(tab.id)) error("duplicate-id", tab.id, `Two tabs have the id "${tab.id}".`);
|
|
195
|
+
tabById.set(tab.id, tab);
|
|
196
|
+
}
|
|
197
|
+
const known = new Set(options.on);
|
|
198
|
+
const sourceIds = new Set(sources.map((source) => source.id));
|
|
199
|
+
|
|
200
|
+
for (const node of nodes) {
|
|
201
|
+
for (const to of nextOf(node)) if (!byId.has(to)) error("unknown-node", node.id, `The node goes to the unknown node "${to}".`);
|
|
202
|
+
if (node.kind === "question" && node.answers.length < 2) error("few-answers", node.id, "The question has fewer than 2 answers.");
|
|
203
|
+
if (node.kind === "goto" && !tabById.has(node.tab)) error("unknown-tab", node.id, `The node goes to the unknown tab "${node.tab}".`);
|
|
204
|
+
if (node.kind === "question" && node.sources.length === 0 && (node.reasoning ?? "").trim() === "") error("no-source", node.id, "The question cites no source and gives no reasoning.");
|
|
205
|
+
for (const id of node.sources ?? []) if (!sourceIds.has(id)) error("unknown-source", node.id, `The node cites the unknown source "${id}".`);
|
|
206
|
+
}
|
|
207
|
+
if (!nodes.some((node) => node.kind === "signal")) error("no-signal", "chart", "The chart has no signal, so a reader cannot start.");
|
|
208
|
+
|
|
209
|
+
const seen = reached(nodes, byId);
|
|
210
|
+
for (const node of nodes) if (!seen.has(node.id)) error("unreachable", node.id, "No signal reaches the node.");
|
|
211
|
+
const cycle = cycleNodes(nodes, byId);
|
|
212
|
+
for (const id of cycle) error("cycle", id, "The node is in a cycle, so its path has no end.");
|
|
213
|
+
const limit = options.maxQuestions ?? 3;
|
|
214
|
+
const depth = questionsToEnd(byId, cycle);
|
|
215
|
+
for (const node of nodes) {
|
|
216
|
+
const value = depth.get(node.id) ?? 0;
|
|
217
|
+
if (node.kind === "signal" && value > limit) error("too-deep", node.id, `A path from the signal has ${value} questions. The limit is ${limit}.`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (options.maxNodes !== undefined && nodes.length > options.maxNodes) error("too-many-nodes", "chart", `The chart has ${nodes.length} nodes. The limit is ${options.maxNodes}.`);
|
|
221
|
+
const ends = nodes.filter((node) => node.kind === "goto").length;
|
|
222
|
+
if (options.maxEnds !== undefined && ends > options.maxEnds) error("too-many-ends", "chart", `The chart has ${ends} ends. The limit is ${options.maxEnds}.`);
|
|
223
|
+
|
|
224
|
+
const used = new Set(nodes.filter((node) => seen.has(node.id)).flatMap((node) => (node.kind === "goto" ? [node.tab] : [])));
|
|
225
|
+
for (const tab of tabs) {
|
|
226
|
+
for (const key of tab.keys) if (!known.has(key)) error("unknown-key", tab.id, `The tab names the unknown key "${key}".`);
|
|
227
|
+
const keys = new Set(tab.keys);
|
|
228
|
+
if (keys.size > 0 && !steps.some((step) => keys.has(step.on) && tab.phases.includes(step.phase))) error("tab-without-steps", tab.id, "The tab has no step in its keys and phases.");
|
|
229
|
+
if (!used.has(tab.id)) error("unused-tab", tab.id, "No path of the chart goes to the tab.");
|
|
230
|
+
}
|
|
231
|
+
const held = new Set([...used].flatMap((id) => tabById.get(id)?.keys ?? []));
|
|
232
|
+
for (const key of options.cover ?? []) if (!held.has(key)) error("uncovered-key", key, `No tab of the chart holds the key "${key}".`);
|
|
233
|
+
return resultOf(out);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** An edge of the master chart, for a renderer. */
|
|
237
|
+
export interface ChartEdge {
|
|
238
|
+
readonly from: string;
|
|
239
|
+
readonly to: string;
|
|
240
|
+
/** The words of the answer. A signal edge has no label. */
|
|
241
|
+
readonly label?: string;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** A node of the master chart with its layer: the most edges from a signal to the node. */
|
|
245
|
+
export interface PlacedNode {
|
|
246
|
+
readonly node: ChartNode;
|
|
247
|
+
readonly layer: number;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The master chart, for a renderer: the nodes by layer, the edges and the tabs that the chart reaches. */
|
|
251
|
+
export interface MasterChart<P extends string = Phase> {
|
|
252
|
+
readonly nodes: readonly PlacedNode[];
|
|
253
|
+
readonly edges: readonly ChartEdge[];
|
|
254
|
+
readonly tabs: readonly Tab<P>[];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */
|
|
258
|
+
export function masterChartOf<P extends string>(nodes: readonly ChartNode[], tabs: readonly Tab<P>[]): MasterChart<P> {
|
|
259
|
+
const byId = new Map(nodes.map((node) => [node.id, node] as const));
|
|
260
|
+
const cycle = cycleNodes(nodes, byId);
|
|
261
|
+
const edges: ChartEdge[] = nodes.flatMap((node): ChartEdge[] => {
|
|
262
|
+
if (node.kind === "signal") return [{ from: node.id, to: node.next }];
|
|
263
|
+
if (node.kind === "question") return node.answers.map((answer) => ({ from: node.id, to: answer.next, label: answer.label }));
|
|
264
|
+
return [];
|
|
265
|
+
});
|
|
266
|
+
const layer = new Map<string, number>();
|
|
267
|
+
const into = new Map<string, string[]>();
|
|
268
|
+
for (const edge of edges) into.set(edge.to, [...(into.get(edge.to) ?? []), edge.from]);
|
|
269
|
+
const layerOf = (id: string): number => {
|
|
270
|
+
const known = layer.get(id);
|
|
271
|
+
if (known !== undefined) return known;
|
|
272
|
+
const before = (into.get(id) ?? []).filter((from) => byId.has(from) && !cycle.has(from));
|
|
273
|
+
const value = before.length === 0 ? 0 : 1 + Math.max(...before.map(layerOf));
|
|
274
|
+
layer.set(id, value);
|
|
275
|
+
return value;
|
|
276
|
+
};
|
|
277
|
+
const placed = nodes.filter((node) => !cycle.has(node.id)).map((node) => ({ node, layer: layerOf(node.id) }));
|
|
278
|
+
placed.sort((a, b) => a.layer - b.layer);
|
|
279
|
+
const tabIds = new Set(nodes.flatMap((node) => (node.kind === "goto" ? [node.tab] : [])));
|
|
280
|
+
return { nodes: placed, edges, tabs: tabs.filter((tab) => tabIds.has(tab.id)) };
|
|
281
|
+
}
|
package/src/steps.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { checkUnits, resultOf } from "@mark1russell7/guidebook";
|
|
4
4
|
import type { CitedUnit, Finding, GateResult, Source, SourceId, UseContext } from "@mark1russell7/guidebook";
|
|
5
5
|
import type { Phase } from "./ladder.ts";
|
|
6
|
+
import type { Society } from "./master.ts";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* One action of a plan. A step belongs to a key and to a phase.
|
|
@@ -26,8 +27,15 @@ export interface Step<P extends string = Phase> {
|
|
|
26
27
|
readonly uses?: readonly string[];
|
|
27
28
|
/** The order of the step in its phase, from 1. */
|
|
28
29
|
readonly order: number;
|
|
29
|
-
/** The sources of the step.
|
|
30
|
+
/** The sources of the step. A step with no `reasoning` has one or more. */
|
|
30
31
|
readonly sources: readonly SourceId[];
|
|
32
|
+
/**
|
|
33
|
+
* The reasoning of a strategy step from first principles, for a step that no source tells.
|
|
34
|
+
* A step with a number in its text (a dose, a time or a safety limit) still cites a source.
|
|
35
|
+
*/
|
|
36
|
+
readonly reasoning?: string;
|
|
37
|
+
/** The states of society that the step is for. No `society` means each state. */
|
|
38
|
+
readonly society?: readonly Society[];
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
/** A marked gap: a key and a phase that have no step on purpose, with the reason. */
|
|
@@ -48,16 +56,24 @@ export interface Cell<P extends string = Phase> {
|
|
|
48
56
|
|
|
49
57
|
const byOrder = <P extends string>(a: Step<P>, b: Step<P>): number => a.order - b.order || a.id.localeCompare(b.id);
|
|
50
58
|
|
|
59
|
+
/** The options of the steps query. */
|
|
60
|
+
export interface StepsForOptions {
|
|
61
|
+
/** Only the steps for this state of society. A step with no `society` is for each state. */
|
|
62
|
+
readonly society?: Society;
|
|
63
|
+
}
|
|
64
|
+
|
|
51
65
|
/**
|
|
52
66
|
* This function gives the steps whose `on` is in `on` and whose phase is in `phases`.
|
|
53
67
|
* The sequence is by `on`, then by `phases`, then by `order`. A step that matches two entries of `on` comes one time.
|
|
54
68
|
*/
|
|
55
|
-
export function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[]): readonly Step<P>[] {
|
|
69
|
+
export function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[], options: StepsForOptions = {}): readonly Step<P>[] {
|
|
70
|
+
const { society } = options;
|
|
71
|
+
const fits = (step: Step<P>): boolean => society === undefined || step.society === undefined || step.society.includes(society);
|
|
56
72
|
const out: Step<P>[] = [];
|
|
57
73
|
const seen = new Set<string>();
|
|
58
74
|
for (const key of on) {
|
|
59
75
|
for (const phase of phases) {
|
|
60
|
-
const hits = library.filter((step) => step.on === key && step.phase === phase && !seen.has(step.id)).sort(byOrder);
|
|
76
|
+
const hits = library.filter((step) => step.on === key && step.phase === phase && !seen.has(step.id) && fits(step)).sort(byOrder);
|
|
61
77
|
for (const step of hits) {
|
|
62
78
|
seen.add(step.id);
|
|
63
79
|
out.push(step);
|
|
@@ -88,6 +104,8 @@ export const STEP_FINDING_CODES = [
|
|
|
88
104
|
"duplicate-id",
|
|
89
105
|
"empty-text",
|
|
90
106
|
"no-source",
|
|
107
|
+
"number-without-source",
|
|
108
|
+
"empty-reasoning",
|
|
91
109
|
"missing-source",
|
|
92
110
|
"use-refused",
|
|
93
111
|
"unknown-phase",
|
|
@@ -137,7 +155,11 @@ export function checkSteps<P extends string>(steps: readonly Step<P>[], sources:
|
|
|
137
155
|
if (ids.has(step.id)) error("duplicate-id", "step", step.id, `Two steps have the id "${step.id}".`);
|
|
138
156
|
ids.add(step.id);
|
|
139
157
|
if (step.do.trim() === "") error("empty-text", "step", step.id, `The step "${step.id}" has no text.`);
|
|
140
|
-
if (step.
|
|
158
|
+
if (step.reasoning !== undefined && step.reasoning.trim() === "") error("empty-reasoning", "step", step.id, `The step "${step.id}" has an empty reasoning.`);
|
|
159
|
+
if (step.sources.length === 0) {
|
|
160
|
+
if (step.reasoning === undefined) error("no-source", "step", step.id, `The step "${step.id}" cites no source and gives no reasoning.`);
|
|
161
|
+
else if (/[0-9]/.test(step.do)) error("number-without-source", "step", step.id, `The step "${step.id}" has a number, so it needs a source.`);
|
|
162
|
+
}
|
|
141
163
|
if (!phases.has(step.phase)) error("unknown-phase", "step", step.id, `The step "${step.id}" has the unknown phase "${step.phase}".`);
|
|
142
164
|
if (!Number.isInteger(step.order) || step.order < 1) error("bad-order", "step", step.id, `The step "${step.id}" has the order ${String(step.order)}. It needs an integer from 1.`);
|
|
143
165
|
const cell = `${step.on}\u0000${step.phase}\u0000${String(step.order)}`;
|