@mark1russell7/guidebook-plans 0.1.3 → 0.1.5
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 +73 -1
- package/build/index.d.ts +165 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +258 -4
- package/build/index.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +4 -2
- package/src/master.ts +387 -0
- package/src/steps.ts +26 -4
package/README.md
CHANGED
|
@@ -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,76 @@ 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`. With `card: true`, it also sends the reader to the card of the event. |
|
|
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, and the tab is not in `used`. |
|
|
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
|
+
|
|
162
|
+
## The master graph
|
|
163
|
+
|
|
164
|
+
The master graph `MasterGraph` is the one value that a printed binder and an app read. Its schema is `GRAPH_SCHEMA`, `"guidebook-graph/1"`. A reader refuses a graph with another value.
|
|
165
|
+
|
|
166
|
+
| Field | Value |
|
|
167
|
+
| --- | --- |
|
|
168
|
+
| `schema` | The name and the major version of the schema. |
|
|
169
|
+
| `start`, `catalog` | The id of the tab of the chart, and the id of the tab of the hazard catalog. |
|
|
170
|
+
| `societies` | The states of society, in the sequence of the sections of each tab. |
|
|
171
|
+
| `nodes`, `tabs` | The nodes and the tabs of the chart. The edges come from `masterChartOf`, so no second list can disagree. |
|
|
172
|
+
| `hazards` | The rows of the hazard catalog. Each row has a case `key`, a `title`, its `signals`, its `entry` node and its `card`: the ids of the steps unique to the case. |
|
|
173
|
+
|
|
174
|
+
The graph holds ids. A reader gets the steps and the sources from their own exports. The ids of the nodes, the tabs and the steps are stable. A change of an id is a new major version of the schema.
|
|
175
|
+
|
|
176
|
+
The graph gate `checkMasterGraph` applies the chart gate. It also gives these codes:
|
|
177
|
+
|
|
178
|
+
| Code | When |
|
|
179
|
+
| --- | --- |
|
|
180
|
+
| `bad-schema` | The schema is not `GRAPH_SCHEMA`. |
|
|
181
|
+
| `unknown-start`, `unknown-catalog` | The start tab or the catalog tab is not a tab. |
|
|
182
|
+
| `unknown-hazard`, `duplicate-hazard`, `missing-hazard` | A row names an unknown case, two rows have one case, or a case of `cases` has no row. |
|
|
183
|
+
| `unknown-signal`, `unknown-entry` | A row names no signal, a node that is not a signal, or an unknown entry. |
|
|
184
|
+
| `unknown-card-step` | A card names a step that is not a step of its case. |
|
|
185
|
+
| `no-route` | No path from the entry of a row goes to a tab with keys. |
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { checkMasterGraph } from "@mark1russell7/guidebook-plans";
|
|
189
|
+
|
|
190
|
+
const gate = checkMasterGraph(graph, library, sources, { on: keys, cover: hazards, cases, maxNodes: 20, maxEnds: 13 });
|
|
191
|
+
```
|
|
192
|
+
|
|
121
193
|
## Limits
|
|
122
194
|
|
|
123
195
|
- 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,155 @@ 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
|
+
/** The end also shows the card of the hazard of the reader, if the reader came with one. */
|
|
92
|
+
readonly card?: true;
|
|
93
|
+
}
|
|
94
|
+
/** A node of the master chart. */
|
|
95
|
+
type ChartNode = SignalNode | QuestionNode | GotoNode;
|
|
96
|
+
/** The codes of the findings of the chart gate. */
|
|
97
|
+
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", "bad-schema", "unknown-start", "unknown-catalog", "unknown-hazard", "duplicate-hazard", "missing-hazard", "unknown-signal", "unknown-entry", "unknown-card-step", "no-route"];
|
|
98
|
+
/** A code of a finding of the chart gate. */
|
|
99
|
+
type MasterFindingCode = (typeof MASTER_FINDING_CODES)[number];
|
|
100
|
+
/** A finding of the chart gate. */
|
|
101
|
+
type MasterFinding = Finding<MasterFindingCode, "chart">;
|
|
102
|
+
/** The options of the chart gate. */
|
|
103
|
+
interface MasterGateOptions {
|
|
104
|
+
/** The known keys: the cases, the cuts and the needs. */
|
|
105
|
+
readonly on: readonly string[];
|
|
106
|
+
/** The keys that a tab of the chart must hold. No `cover` means no key. */
|
|
107
|
+
readonly cover?: readonly string[];
|
|
108
|
+
/** The most questions on a path from a signal to a tab. The default is 3. */
|
|
109
|
+
readonly maxQuestions?: number;
|
|
110
|
+
/** The most nodes that the print of the chart can hold. No `maxNodes` means no limit. */
|
|
111
|
+
readonly maxNodes?: number;
|
|
112
|
+
/** The most ends (nodes of the kind `goto`) that the print of the chart can hold. No `maxEnds` means no limit. */
|
|
113
|
+
readonly maxEnds?: number;
|
|
114
|
+
/** The ids of the tabs that a reader reaches by another way than an end, for example the catalog through the cards. */
|
|
115
|
+
readonly used?: readonly string[];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* This function applies the chart gate.
|
|
119
|
+
* Each node is known and reached, and each path ends at a known tab after a few questions.
|
|
120
|
+
* Each tab with keys has steps. Each key of `cover` is in a tab that the chart reaches.
|
|
121
|
+
*/
|
|
122
|
+
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>;
|
|
123
|
+
/** An edge of the master chart, for a renderer. */
|
|
124
|
+
interface ChartEdge {
|
|
125
|
+
readonly from: string;
|
|
126
|
+
readonly to: string;
|
|
127
|
+
/** The words of the answer. A signal edge has no label. */
|
|
128
|
+
readonly label?: string;
|
|
129
|
+
}
|
|
130
|
+
/** A node of the master chart with its layer: the most edges from a signal to the node. */
|
|
131
|
+
interface PlacedNode {
|
|
132
|
+
readonly node: ChartNode;
|
|
133
|
+
readonly layer: number;
|
|
134
|
+
}
|
|
135
|
+
/** The master chart, for a renderer: the nodes by layer, the edges and the tabs that the chart reaches. */
|
|
136
|
+
interface MasterChart<P extends string = Phase> {
|
|
137
|
+
readonly nodes: readonly PlacedNode[];
|
|
138
|
+
readonly edges: readonly ChartEdge[];
|
|
139
|
+
readonly tabs: readonly Tab<P>[];
|
|
140
|
+
}
|
|
141
|
+
/** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */
|
|
142
|
+
export declare function masterChartOf<P extends string>(nodes: readonly ChartNode[], tabs: readonly Tab<P>[]): MasterChart<P>;
|
|
143
|
+
/** The name and the major version of the schema of the master graph. A reader refuses a graph with another value. */
|
|
144
|
+
export declare const GRAPH_SCHEMA = "guidebook-graph/1";
|
|
145
|
+
/** A row of the hazard catalog: an index into the graph, with the facts that are unique to the hazard. */
|
|
146
|
+
interface HazardRow {
|
|
147
|
+
/** The key of the case. */
|
|
148
|
+
readonly key: string;
|
|
149
|
+
readonly title: string;
|
|
150
|
+
/** The ids of the signal nodes that the hazard gives. */
|
|
151
|
+
readonly signals: readonly string[];
|
|
152
|
+
/** The id of the node where a reader with this hazard joins the graph. */
|
|
153
|
+
readonly entry: string;
|
|
154
|
+
/** The ids of the steps of the case that are unique to it: its card. */
|
|
155
|
+
readonly card: readonly string[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The master graph: one value that a printed binder and an app read.
|
|
159
|
+
* The edges come from the nodes with `masterChartOf`, so no second list can disagree with them.
|
|
160
|
+
*/
|
|
161
|
+
interface MasterGraph<P extends string = Phase> {
|
|
162
|
+
readonly schema: typeof GRAPH_SCHEMA;
|
|
163
|
+
/** The id of the tab of the chart itself, the entry of the binder. */
|
|
164
|
+
readonly start: string;
|
|
165
|
+
/** The id of the tab of the hazard catalog. An end with `card` shows the card from it. */
|
|
166
|
+
readonly catalog: string;
|
|
167
|
+
/** The states of society, in the sequence of the sections of each tab. */
|
|
168
|
+
readonly societies: readonly Society[];
|
|
169
|
+
readonly nodes: readonly ChartNode[];
|
|
170
|
+
readonly tabs: readonly Tab<P>[];
|
|
171
|
+
readonly hazards: readonly HazardRow[];
|
|
172
|
+
}
|
|
173
|
+
/** The options of the graph gate: the options of the chart gate and the cases that the catalog must index. */
|
|
174
|
+
interface GraphGateOptions extends MasterGateOptions {
|
|
175
|
+
/** The keys of the cases. Each case has one row of the catalog. */
|
|
176
|
+
readonly cases: readonly string[];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* This function applies the graph gate: the chart gate, and the gate of the hazard rows.
|
|
180
|
+
*
|
|
181
|
+
* The start tab and the catalog tab are tabs. The start tab needs no path. An end with `card` uses the catalog tab.
|
|
182
|
+
* Each case has one row. Each row names known signals, a known entry and steps of its case.
|
|
183
|
+
* Each entry reaches an end whose tab has keys.
|
|
184
|
+
*/
|
|
185
|
+
export declare function checkMasterGraph<P extends string>(graph: MasterGraph<P>, steps: readonly Step<P>[], sources: readonly Source[], options: GraphGateOptions): GateResult<MasterFinding>;
|
|
37
186
|
/**
|
|
38
187
|
* One action of a plan. A step belongs to a key and to a phase.
|
|
39
188
|
* 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 +205,15 @@ interface Step<P extends string = Phase> {
|
|
|
56
205
|
readonly uses?: readonly string[];
|
|
57
206
|
/** The order of the step in its phase, from 1. */
|
|
58
207
|
readonly order: number;
|
|
59
|
-
/** The sources of the step.
|
|
208
|
+
/** The sources of the step. A step with no `reasoning` has one or more. */
|
|
60
209
|
readonly sources: readonly SourceId[];
|
|
210
|
+
/**
|
|
211
|
+
* The reasoning of a strategy step from first principles, for a step that no source tells.
|
|
212
|
+
* A step with a number in its text (a dose, a time or a safety limit) still cites a source.
|
|
213
|
+
*/
|
|
214
|
+
readonly reasoning?: string;
|
|
215
|
+
/** The states of society that the step is for. No `society` means each state. */
|
|
216
|
+
readonly society?: readonly Society[];
|
|
61
217
|
}
|
|
62
218
|
/** A marked gap: a key and a phase that have no step on purpose, with the reason. */
|
|
63
219
|
interface Gap<P extends string = Phase> {
|
|
@@ -73,15 +229,20 @@ interface Cell<P extends string = Phase> {
|
|
|
73
229
|
readonly steps: readonly Step<P>[];
|
|
74
230
|
readonly gap?: Gap<P>;
|
|
75
231
|
}
|
|
232
|
+
/** The options of the steps query. */
|
|
233
|
+
interface StepsForOptions {
|
|
234
|
+
/** Only the steps for this state of society. A step with no `society` is for each state. */
|
|
235
|
+
readonly society?: Society;
|
|
236
|
+
}
|
|
76
237
|
/**
|
|
77
238
|
* This function gives the steps whose `on` is in `on` and whose phase is in `phases`.
|
|
78
239
|
* The sequence is by `on`, then by `phases`, then by `order`. A step that matches two entries of `on` comes one time.
|
|
79
240
|
*/
|
|
80
|
-
export declare function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[]): readonly Step<P>[];
|
|
241
|
+
export declare function stepsFor<P extends string>(library: readonly Step<P>[], on: readonly string[], phases: readonly P[], options?: StepsForOptions): readonly Step<P>[];
|
|
81
242
|
/** This function gives the matrix of a library: one row for each key of `on`, with one cell for each phase of `phases`. */
|
|
82
243
|
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
244
|
/** 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"];
|
|
245
|
+
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
246
|
/** A code of a finding of the step gate. */
|
|
86
247
|
type StepFindingCode = (typeof STEP_FINDING_CODES)[number];
|
|
87
248
|
/** A finding of the step gate. */
|
|
@@ -190,5 +351,5 @@ interface ChartQuestion<P extends string = Phase> {
|
|
|
190
351
|
}
|
|
191
352
|
/** 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
353
|
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 };
|
|
354
|
+
export type { Cell, ChartAnswer, ChartEdge, ChartNode, ChartQuestion, CoverageFinding, CoverageFindingCode, CoverageOptions, Gap, GotoNode, GraphGateOptions, HazardRow, KeyCoverage, Ladder, MasterChart, MasterFinding, MasterFindingCode, MasterGateOptions, MasterGraph, Phase, PlacedNode, QuestionNode, Rule, RuleFinding, RuleFindingCode, RuleGateOptions, RuleKind, RuleTarget, SignalNode, Society, Step, StepFinding, StepFindingCode, StepGateOptions, StepsForOptions, Tab };
|
|
194
355
|
//# 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":"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"}
|
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,251 @@ 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
|
+
"bad-schema",
|
|
405
|
+
"unknown-start",
|
|
406
|
+
"unknown-catalog",
|
|
407
|
+
"unknown-hazard",
|
|
408
|
+
"duplicate-hazard",
|
|
409
|
+
"missing-hazard",
|
|
410
|
+
"unknown-signal",
|
|
411
|
+
"unknown-entry",
|
|
412
|
+
"unknown-card-step",
|
|
413
|
+
"no-route"
|
|
414
|
+
];
|
|
415
|
+
/** The ids of the nodes that come after a node. */
|
|
416
|
+
function nextOf(node) {
|
|
417
|
+
if (node.kind === "signal") return [node.next];
|
|
418
|
+
if (node.kind === "question") return node.answers.map((answer) => answer.next);
|
|
419
|
+
return [];
|
|
420
|
+
}
|
|
421
|
+
/** The nodes in a cycle. A chart with a cycle has no end on that path. */
|
|
422
|
+
function cycleNodes(nodes, byId) {
|
|
423
|
+
const next = (id) => {
|
|
424
|
+
const node = byId.get(id);
|
|
425
|
+
return node === void 0 ? [] : nextOf(node).filter((to) => byId.has(to));
|
|
426
|
+
};
|
|
427
|
+
const out = /* @__PURE__ */ new Set();
|
|
428
|
+
for (const group of stronglyConnectedComponents(nodes.map((node) => node.id), next)) {
|
|
429
|
+
const [first] = group;
|
|
430
|
+
if (group.length > 1 || first !== void 0 && next(first).includes(first)) for (const id of group) out.add(id);
|
|
431
|
+
}
|
|
432
|
+
return out;
|
|
433
|
+
}
|
|
434
|
+
/** The most questions from each node to an end, on a chart with no cycle. */
|
|
435
|
+
function questionsToEnd(byId, skip) {
|
|
436
|
+
const memo = /* @__PURE__ */ new Map();
|
|
437
|
+
const walk = (id) => {
|
|
438
|
+
const known = memo.get(id);
|
|
439
|
+
if (known !== void 0) return known;
|
|
440
|
+
const node = byId.get(id);
|
|
441
|
+
if (node === void 0 || skip.has(id)) return 0;
|
|
442
|
+
const rest = Math.max(0, ...nextOf(node).map(walk));
|
|
443
|
+
const value = (node.kind === "question" ? 1 : 0) + rest;
|
|
444
|
+
memo.set(id, value);
|
|
445
|
+
return value;
|
|
446
|
+
};
|
|
447
|
+
for (const id of byId.keys()) walk(id);
|
|
448
|
+
return memo;
|
|
449
|
+
}
|
|
450
|
+
/** The ids of the nodes that a signal reaches. */
|
|
451
|
+
function reached(nodes, byId) {
|
|
452
|
+
const seen = /* @__PURE__ */ new Set();
|
|
453
|
+
const stack = nodes.filter((node) => node.kind === "signal").map((node) => node.id);
|
|
454
|
+
for (let id = stack.pop(); id !== void 0; id = stack.pop()) {
|
|
455
|
+
if (seen.has(id)) continue;
|
|
456
|
+
seen.add(id);
|
|
457
|
+
const node = byId.get(id);
|
|
458
|
+
if (node !== void 0) stack.push(...nextOf(node));
|
|
459
|
+
}
|
|
460
|
+
return seen;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* This function applies the chart gate.
|
|
464
|
+
* Each node is known and reached, and each path ends at a known tab after a few questions.
|
|
465
|
+
* Each tab with keys has steps. Each key of `cover` is in a tab that the chart reaches.
|
|
466
|
+
*/
|
|
467
|
+
function checkMasterChart(nodes, tabs, steps, sources, options) {
|
|
468
|
+
const out = [];
|
|
469
|
+
const error = (code, id, message) => {
|
|
470
|
+
out.push({
|
|
471
|
+
level: "error",
|
|
472
|
+
code,
|
|
473
|
+
record: "chart",
|
|
474
|
+
id,
|
|
475
|
+
message
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
const byId = /* @__PURE__ */ new Map();
|
|
479
|
+
for (const node of nodes) {
|
|
480
|
+
if (byId.has(node.id)) error("duplicate-id", node.id, `Two nodes have the id "${node.id}".`);
|
|
481
|
+
byId.set(node.id, node);
|
|
482
|
+
}
|
|
483
|
+
const tabById = /* @__PURE__ */ new Map();
|
|
484
|
+
for (const tab of tabs) {
|
|
485
|
+
if (tabById.has(tab.id)) error("duplicate-id", tab.id, `Two tabs have the id "${tab.id}".`);
|
|
486
|
+
tabById.set(tab.id, tab);
|
|
487
|
+
}
|
|
488
|
+
const known = new Set(options.on);
|
|
489
|
+
const sourceIds = new Set(sources.map((source) => source.id));
|
|
490
|
+
for (const node of nodes) {
|
|
491
|
+
for (const to of nextOf(node)) if (!byId.has(to)) error("unknown-node", node.id, `The node goes to the unknown node "${to}".`);
|
|
492
|
+
if (node.kind === "question" && node.answers.length < 2) error("few-answers", node.id, "The question has fewer than 2 answers.");
|
|
493
|
+
if (node.kind === "goto" && !tabById.has(node.tab)) error("unknown-tab", node.id, `The node goes to the unknown tab "${node.tab}".`);
|
|
494
|
+
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.");
|
|
495
|
+
for (const id of node.sources ?? []) if (!sourceIds.has(id)) error("unknown-source", node.id, `The node cites the unknown source "${id}".`);
|
|
496
|
+
}
|
|
497
|
+
if (!nodes.some((node) => node.kind === "signal")) error("no-signal", "chart", "The chart has no signal, so a reader cannot start.");
|
|
498
|
+
const seen = reached(nodes, byId);
|
|
499
|
+
for (const node of nodes) if (!seen.has(node.id)) error("unreachable", node.id, "No signal reaches the node.");
|
|
500
|
+
const cycle = cycleNodes(nodes, byId);
|
|
501
|
+
for (const id of cycle) error("cycle", id, "The node is in a cycle, so its path has no end.");
|
|
502
|
+
const limit = options.maxQuestions ?? 3;
|
|
503
|
+
const depth = questionsToEnd(byId, cycle);
|
|
504
|
+
for (const node of nodes) {
|
|
505
|
+
const value = depth.get(node.id) ?? 0;
|
|
506
|
+
if (node.kind === "signal" && value > limit) error("too-deep", node.id, `A path from the signal has ${value} questions. The limit is ${limit}.`);
|
|
507
|
+
}
|
|
508
|
+
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}.`);
|
|
509
|
+
const ends = nodes.filter((node) => node.kind === "goto").length;
|
|
510
|
+
if (options.maxEnds !== void 0 && ends > options.maxEnds) error("too-many-ends", "chart", `The chart has ${ends} ends. The limit is ${options.maxEnds}.`);
|
|
511
|
+
const used = /* @__PURE__ */ new Set([...options.used ?? [], ...nodes.filter((node) => seen.has(node.id)).flatMap((node) => node.kind === "goto" ? [node.tab] : [])]);
|
|
512
|
+
for (const tab of tabs) {
|
|
513
|
+
for (const key of tab.keys) if (!known.has(key)) error("unknown-key", tab.id, `The tab names the unknown key "${key}".`);
|
|
514
|
+
const keys = new Set(tab.keys);
|
|
515
|
+
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.");
|
|
516
|
+
if (!used.has(tab.id)) error("unused-tab", tab.id, "No path of the chart goes to the tab.");
|
|
517
|
+
}
|
|
518
|
+
const held = new Set([...used].flatMap((id) => tabById.get(id)?.keys ?? []));
|
|
519
|
+
for (const key of options.cover ?? []) if (!held.has(key)) error("uncovered-key", key, `No tab of the chart holds the key "${key}".`);
|
|
520
|
+
return resultOf(out);
|
|
521
|
+
}
|
|
522
|
+
/** This function gives the master chart for a renderer. It gives no layer to a node in a cycle. Apply the chart gate first. */
|
|
523
|
+
function masterChartOf(nodes, tabs) {
|
|
524
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
525
|
+
const cycle = cycleNodes(nodes, byId);
|
|
526
|
+
const edges = nodes.flatMap((node) => {
|
|
527
|
+
if (node.kind === "signal") return [{
|
|
528
|
+
from: node.id,
|
|
529
|
+
to: node.next
|
|
530
|
+
}];
|
|
531
|
+
if (node.kind === "question") return node.answers.map((answer) => ({
|
|
532
|
+
from: node.id,
|
|
533
|
+
to: answer.next,
|
|
534
|
+
label: answer.label
|
|
535
|
+
}));
|
|
536
|
+
return [];
|
|
537
|
+
});
|
|
538
|
+
const layer = /* @__PURE__ */ new Map();
|
|
539
|
+
const into = /* @__PURE__ */ new Map();
|
|
540
|
+
for (const edge of edges) into.set(edge.to, [...into.get(edge.to) ?? [], edge.from]);
|
|
541
|
+
const layerOf = (id) => {
|
|
542
|
+
const known = layer.get(id);
|
|
543
|
+
if (known !== void 0) return known;
|
|
544
|
+
const before = (into.get(id) ?? []).filter((from) => byId.has(from) && !cycle.has(from));
|
|
545
|
+
const value = before.length === 0 ? 0 : 1 + Math.max(...before.map(layerOf));
|
|
546
|
+
layer.set(id, value);
|
|
547
|
+
return value;
|
|
548
|
+
};
|
|
549
|
+
const placed = nodes.filter((node) => !cycle.has(node.id)).map((node) => ({
|
|
550
|
+
node,
|
|
551
|
+
layer: layerOf(node.id)
|
|
552
|
+
}));
|
|
553
|
+
placed.sort((a, b) => a.layer - b.layer);
|
|
554
|
+
const tabIds = new Set(nodes.flatMap((node) => node.kind === "goto" ? [node.tab] : []));
|
|
555
|
+
return {
|
|
556
|
+
nodes: placed,
|
|
557
|
+
edges,
|
|
558
|
+
tabs: tabs.filter((tab) => tabIds.has(tab.id))
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
/** The name and the major version of the schema of the master graph. A reader refuses a graph with another value. */
|
|
562
|
+
const GRAPH_SCHEMA = "guidebook-graph/1";
|
|
563
|
+
/**
|
|
564
|
+
* This function applies the graph gate: the chart gate, and the gate of the hazard rows.
|
|
565
|
+
*
|
|
566
|
+
* The start tab and the catalog tab are tabs. The start tab needs no path. An end with `card` uses the catalog tab.
|
|
567
|
+
* Each case has one row. Each row names known signals, a known entry and steps of its case.
|
|
568
|
+
* Each entry reaches an end whose tab has keys.
|
|
569
|
+
*/
|
|
570
|
+
function checkMasterGraph(graph, steps, sources, options) {
|
|
571
|
+
const out = [];
|
|
572
|
+
const error = (code, id, message) => {
|
|
573
|
+
out.push({
|
|
574
|
+
level: "error",
|
|
575
|
+
code,
|
|
576
|
+
record: "chart",
|
|
577
|
+
id,
|
|
578
|
+
message
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
if (graph.schema !== "guidebook-graph/1") error("bad-schema", "graph", `The schema is "${String(graph.schema)}", not "${GRAPH_SCHEMA}".`);
|
|
582
|
+
const tabIds = new Set(graph.tabs.map((tab) => tab.id));
|
|
583
|
+
if (!tabIds.has(graph.start)) error("unknown-start", graph.start, `The start tab "${graph.start}" is not a tab.`);
|
|
584
|
+
if (!tabIds.has(graph.catalog)) error("unknown-catalog", graph.catalog, `The catalog tab "${graph.catalog}" is not a tab.`);
|
|
585
|
+
const withCards = graph.nodes.some((node) => node.kind === "goto" && node.card === true);
|
|
586
|
+
const chartTabs = graph.tabs.filter((tab) => tab.id !== graph.start);
|
|
587
|
+
const chart = checkMasterChart(graph.nodes, chartTabs, steps, sources, {
|
|
588
|
+
...options,
|
|
589
|
+
used: [...options.used ?? [], ...withCards ? [graph.catalog] : []]
|
|
590
|
+
});
|
|
591
|
+
out.push(...chart.findings);
|
|
592
|
+
const byId = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
593
|
+
const stepById = new Map(steps.map((step) => [step.id, step]));
|
|
594
|
+
const tabById = new Map(graph.tabs.map((tab) => [tab.id, tab]));
|
|
595
|
+
const cases = new Set(options.cases);
|
|
596
|
+
const rows = /* @__PURE__ */ new Set();
|
|
597
|
+
const routes = (id, seen = /* @__PURE__ */ new Set()) => {
|
|
598
|
+
if (seen.has(id)) return false;
|
|
599
|
+
seen.add(id);
|
|
600
|
+
const node = byId.get(id);
|
|
601
|
+
if (node === void 0) return false;
|
|
602
|
+
if (node.kind === "goto") return (tabById.get(node.tab)?.keys.length ?? 0) > 0;
|
|
603
|
+
return nextOf(node).some((to) => routes(to, seen));
|
|
604
|
+
};
|
|
605
|
+
for (const row of graph.hazards) {
|
|
606
|
+
if (rows.has(row.key)) error("duplicate-hazard", row.key, `Two rows of the catalog have the key "${row.key}".`);
|
|
607
|
+
rows.add(row.key);
|
|
608
|
+
if (!cases.has(row.key)) error("unknown-hazard", row.key, `The row names the unknown case "${row.key}".`);
|
|
609
|
+
if (row.signals.length === 0) error("unknown-signal", row.key, "The row names no signal.");
|
|
610
|
+
for (const id of row.signals) if (byId.get(id)?.kind !== "signal") error("unknown-signal", row.key, `The row names "${id}", which is not a signal node.`);
|
|
611
|
+
if (!byId.has(row.entry)) error("unknown-entry", row.key, `The row names the unknown entry "${row.entry}".`);
|
|
612
|
+
else if (!routes(row.entry)) error("no-route", row.key, "No path from the entry of the row goes to a tab with keys.");
|
|
613
|
+
for (const id of row.card) if (stepById.get(id)?.on !== row.key) error("unknown-card-step", row.key, `The card names "${id}", which is not a step of the case.`);
|
|
614
|
+
}
|
|
615
|
+
for (const key of options.cases) if (!rows.has(key)) error("missing-hazard", key, `The catalog has no row for the case "${key}".`);
|
|
616
|
+
return resultOf(out);
|
|
617
|
+
}
|
|
618
|
+
export { COVERAGE_FINDING_CODES, GRAPH_SCHEMA, 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, checkMasterGraph, checkRules, checkSteps, coverageOf, masterChartOf, phaseIn, phaseOf, phasesOf, planMatrix, stepsFor, unitsOf };
|
|
365
619
|
|
|
366
620
|
//# sourceMappingURL=index.js.map
|