@mark1russell7/stack-risk 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,12 +59,15 @@ const layer: RiskLayer = {
59
59
  | `part` | The `id` of the part with the goal, for example a function of the system. |
60
60
  | `survives` | The count of failures of other parts that the part survives. With 1, no failure of one part stops the part. |
61
61
  | `chance` | The smallest chance that the part works, from 0 to 1. |
62
+ | `within` | The limit of time of the chance, in seconds from the event. With it, the part must also end its work in time. A goal with a limit of time needs a chance. |
62
63
 
63
64
  | Field of a chance record | What it is |
64
65
  | --- | --- |
65
66
  | `part` | The `id` of the part. |
66
67
  | `works` | The chance that the part works at a moment, when each of its needs holds. |
67
68
  | `source` | The source of the number, for example a service agreement or a measured period. |
69
+ | `wait` | The wait of the part before it starts, in seconds, for example the wait of the rank of a copy. The default is 0. |
70
+ | `delay` | The points of the distribution of the time from the end of the wait to the end of the work, when the part works. Each point is `{ within, chance }`: the chance that the time is `within` seconds or less. |
68
71
 
69
72
  | Field of an accepted risk | What it is |
70
73
  | --- | --- |
@@ -98,9 +101,11 @@ The gate examines the design: each part of the stack is in operation. A fault of
98
101
  | `goal-duplicate` | Two goals name one part. |
99
102
  | `goal-survives` | The count of a goal is not a whole number from 0. |
100
103
  | `goal-chance` | The chance of a goal is not from 0 to 1. |
104
+ | `goal-within` | The limit of time of a goal is not a time of 0 or more, or the goal has no chance. |
101
105
  | `chance-part` | A chance record names no part of the stack. |
102
106
  | `chance-duplicate` | Two chance records name one part. |
103
107
  | `chance-range` | The chance of a part is not from 0 to 1. |
108
+ | `chance-delay` | The wait of a part is not a time of 0 or more, or its delay points are not in order. |
104
109
  | `accept-part` | An accepted risk names a part with no goal. |
105
110
  | `accept-stop` | An accepted risk names no part, or a part that is not in the stack. |
106
111
  | `accept-date` | The last date of an accepted risk is not a date. |
@@ -109,7 +114,7 @@ The gate examines the design: each part of the stack is in operation. A fault of
109
114
  | `accept-old` | The acceptance of a stop set ended before the date of the check. |
110
115
  | `accept-unused` | An accepted risk names a set that is no stop set of its goal. |
111
116
  | `chance-none` | A goal has a chance, and a part of its paths has no chance record. |
112
- | `chance-low` | The chance that a part works is less than the chance of its goal. |
117
+ | `chance-low` | The chance that a part works is less than the chance of its goal. With a limit of time, the part must also end in time. |
113
118
  | `no-read` | A search passed its limit, so the gate has no result for the goal. |
114
119
 
115
120
  The gate reports only the smallest sets. When the failure of one part stops a part, each larger set with that part is not a second fault.
@@ -175,6 +180,30 @@ const chance = worksChance(SAMPLE_RISK, SAMPLE_STACK, "alert");
175
180
 
176
181
  The sample shows where work helps most. The two copies of the program and the two message services have a small importance. The reader and the phone have a large one.
177
182
 
183
+ ### The chance within a limit of time
184
+
185
+ `worksChance(layer, stack, part, { within })` gives the chance that a part works and ends its work within `within` seconds of the event.
186
+
187
+ ```ts
188
+ const layer = {
189
+ schema: "risk/1",
190
+ goals: [{ part: "send", survives: 1, chance: 0.999, within: 90 }],
191
+ chances: [
192
+ { part: "home", works: 0.98, delay: [{ within: 5, chance: 0.9 }, { within: 30, chance: 0.999 }] },
193
+ { part: "cloud", works: 0.99, wait: 60, delay: [{ within: 5, chance: 0.95 }] },
194
+ ],
195
+ } as const;
196
+ worksChance(layer, stack, "send", { within: 90 });
197
+ ```
198
+
199
+ - The chance of each part is its chance to work, times `inTimeChance(record, within)`: the chance that its wait and its delay end in time.
200
+ - Between two points of a delay, the chance is the chance of the lower point. The chance of a part does not decrease when the chance of one of its parts increases. Thus the result is a lower bound, which fits a gate.
201
+ - A part with no wait and no delay ends at once. With `within: Infinity`, each delay gives the chance of its last point.
202
+ - The time of each part is independent of the others when its needs work. A path ends when its last part ends: the delays do not add. Thus give the time of each part from the event, for example the time of a copy to send.
203
+ - Without `within`, the time has no effect, and the result is the chance at a moment.
204
+
205
+ For one copy or more, the result is equal to `sendChance` of [`@mark1russell7/algebra/availability`](https://www.npmjs.com/package/@mark1russell7/algebra). A cause of a placement is a part, and a copy is a part that needs its causes. A property test holds this equivalence.
206
+
178
207
  The paths, the stop sets and the smallest stop set are functions of the core: `pathSets`, `stopSets` and `smallestStop`.
179
208
 
180
209
  ## The read of JSON
package/build/add-on.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as RiskOptions } from "./check-CahTrDAa.js";
2
- import { a as RiskLayer } from "./layer-zvH_ueL5.js";
1
+ import { i as RiskOptions } from "./check-eWTX3RSX.js";
2
+ import { o as RiskLayer } from "./layer-D4_dWgrV.js";
3
3
  import { StackJoiner } from "@mark1russell7/system-stack";
4
4
  /**
5
5
  * This function gives the risk add-on for a check on one date.
package/build/add-on.js CHANGED
@@ -1,5 +1,5 @@
1
- import { r as checkRisk, t as joinRisk } from "./join-ClFU2WDq.js";
2
- import { t as RISK_SCHEMA } from "./layer-BLQnPkuy.js";
1
+ import { r as checkRisk, t as joinRisk } from "./join-B5LoxybX.js";
2
+ import { t as RISK_SCHEMA } from "./layer-Bkl6X1Vt.js";
3
3
  import { parseRisk } from "./schema.js";
4
4
  import { dayNumber } from "@mark1russell7/system-stack";
5
5
  // src/add-on.ts
@@ -1,7 +1,7 @@
1
- import { a as RiskLayer } from "./layer-zvH_ueL5.js";
1
+ import { o as RiskLayer } from "./layer-D4_dWgrV.js";
2
2
  import { Fault, Stack } from "@mark1russell7/system-stack";
3
3
  /** These are the codes of the faults of a risk layer. */
4
- declare const RISK_CODES: readonly ["goal-part", "goal-duplicate", "goal-survives", "goal-chance", "chance-part", "chance-duplicate", "chance-range", "accept-part", "accept-stop", "accept-date", "stopped", "stop-set", "accept-old", "accept-unused", "chance-none", "chance-low", "no-read"];
4
+ declare const RISK_CODES: readonly ["goal-part", "goal-duplicate", "goal-survives", "goal-chance", "goal-within", "chance-part", "chance-duplicate", "chance-range", "chance-delay", "accept-part", "accept-stop", "accept-date", "stopped", "stop-set", "accept-old", "accept-unused", "chance-none", "chance-low", "no-read"];
5
5
  /** A code of a fault of a risk layer. */
6
6
  type RiskCode = (typeof RISK_CODES)[number];
7
7
  /** A fault of a risk layer. Its field `at` is the `id` of the part of the record. */
@@ -28,9 +28,11 @@ interface RiskOptions {
28
28
  * - `goal-duplicate`: two goals name one part.
29
29
  * - `goal-survives`: the count of a goal is not a whole number from 0.
30
30
  * - `goal-chance`: the chance of a goal is not from 0 to 1.
31
+ * - `goal-within`: the limit of time of a goal is not a time of 0 or more, or the goal has no chance.
31
32
  * - `chance-part`: a chance record names no part of the stack.
32
33
  * - `chance-duplicate`: two chance records name one part.
33
34
  * - `chance-range`: the chance of a part is not from 0 to 1.
35
+ * - `chance-delay`: the wait of a part is not a time of 0 or more, or its delay points are not in order.
34
36
  * - `accept-part`: an accepted risk names a part with no goal.
35
37
  * - `accept-stop`: an accepted risk names no part, or a part that is not in the stack.
36
38
  * - `accept-date`: the last date of an accepted risk is not a date.
@@ -41,7 +43,8 @@ interface RiskOptions {
41
43
  * - `accept-old`: the acceptance of a stop set ended before `today`.
42
44
  * - `accept-unused`: an accepted risk names a set that is no stop set of its goal. Remove the record.
43
45
  * - `chance-none`: a goal has a chance, and a part of its paths has no chance record.
44
- * - `chance-low`: the chance that a part works is less than the chance of its goal.
46
+ * - `chance-low`: the chance that a part works is less than the chance of its goal. With a limit of time, the part
47
+ * must also end its work in time.
45
48
  * - `no-read`: a search passed its limit. The gate has no result for the goal, so it does not pass.
46
49
  *
47
50
  * The faults are in the sequence of the chance records, the accepted risks and the goals. The function is pure.
@@ -50,4 +53,4 @@ interface RiskOptions {
50
53
  */
51
54
  declare function checkRisk(layer: RiskLayer, stack: Stack, options: RiskOptions): RiskFault[];
52
55
  export { checkRisk as a, RiskOptions as i, RiskCode as n, RiskFault as r, RISK_CODES as t };
53
- //# sourceMappingURL=check-CahTrDAa.d.ts.map
56
+ //# sourceMappingURL=check-eWTX3RSX.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-eWTX3RSX.d.ts","names":[],"sources":["../src/check.ts"],"mappings":";;;cAQa;;KA2CD,mBAAmB;;UAGd,kBAAkB;WACxB,MAAM;;WAEN;;;UAIM;;WAEN;;WAEA;;WAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6CK,UAAU,OAAO,WAAW,OAAO,OAAO,SAAS,cAAc"}
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as RiskLayer, c as isChance, i as RISK_SCHEMA, n as Chance, o as chancesByPart, r as Goal, s as firstGoals, t as Accepted } from "./layer-zvH_ueL5.js";
2
- import { a as checkRisk, i as RiskOptions, n as RiskCode, r as RiskFault, t as RISK_CODES } from "./check-CahTrDAa.js";
1
+ import { a as RISK_SCHEMA, c as delayFault, d as isChance, i as Goal, l as firstGoals, n as Chance, o as RiskLayer, r as DelayPoint, s as chancesByPart, t as Accepted, u as inTimeChance } from "./layer-D4_dWgrV.js";
2
+ import { a as checkRisk, i as RiskOptions, n as RiskCode, r as RiskFault, t as RISK_CODES } from "./check-eWTX3RSX.js";
3
3
  import { LayerParse, LayerPiece, PathOptions, Stack } from "@mark1russell7/system-stack";
4
4
  /**
5
5
  * The state of the goal of one part, with the parts that are down at this time.
@@ -36,6 +36,12 @@ export declare function goalStates(layer: RiskLayer, stack: Stack, options?: Pat
36
36
  export interface ChanceOptions extends PathOptions {
37
37
  /** The largest count of steps of the calculation. The default is 1000000. */
38
38
  readonly maxSteps?: number | undefined;
39
+ /**
40
+ * The limit of time in seconds from the event, from 0. With it, a part works only when it also ends its work within
41
+ * the limit. `inTimeChance` gives that chance from the wait and the delay of its record. `Infinity` uses the last
42
+ * point of each delay. Without it, the time has no effect.
43
+ */
44
+ readonly within?: number | undefined;
39
45
  }
40
46
  /** The importance of one part for the chance that a different part works. */
41
47
  export interface PartImportance {
@@ -69,11 +75,15 @@ export type WorksChance = {
69
75
  * - A shared cause of failure is thus a part of the stack: a provider, an account or a power feed. Do not put it in a number.
70
76
  * - The value is exact: `pathSetReliability` of `@mark1russell7/collections/graph` counts a shared part one time.
71
77
  * - A part that does not work with the parts of `down` has the chance 0.
78
+ * - With `within`, the chance of each part is the chance that it works and ends in time. The time of each part is
79
+ * independent of the others when its needs work. A path ends when its last part ends: the delays do not add. Thus
80
+ * give the wait and the delay of each part as its time from the event, for example the time of a copy to send.
72
81
  * - The sequence of the parts of the stack does not change the value or an importance, to the last digit.
73
82
  *
74
83
  * The function is pure.
75
84
  *
76
- * @throws RangeError when a chance of a part of the paths is not from 0 to 1, or an option is not valid
85
+ * @throws RangeError when a chance of a part of the paths is not from 0 to 1, or an option is not valid. With
86
+ * `within`, also when the wait or the delay of a part of the paths is not valid.
77
87
  */
78
88
  export declare function worksChance(layer: RiskLayer, stack: Stack, part: string, options?: ChanceOptions): WorksChance;
79
89
  /**
@@ -99,5 +109,5 @@ export declare const SAMPLE_TODAY = "2026-11-16";
99
109
  * The failure of the reader alone stops the alert too, and a record accepts that risk.
100
110
  */
101
111
  export declare const SAMPLE_RISK: RiskLayer;
102
- export { Accepted, Chance, Goal, RISK_CODES, RISK_SCHEMA, RiskCode, RiskFault, RiskLayer, RiskOptions, chancesByPart, checkRisk, firstGoals, isChance };
112
+ export { Accepted, Chance, DelayPoint, Goal, RISK_CODES, RISK_SCHEMA, RiskCode, RiskFault, RiskLayer, RiskOptions, chancesByPart, checkRisk, delayFault, firstGoals, inTimeChance, isChance };
103
113
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/states.ts","../src/chance.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;;;;;;;;;YAaY;WACG;WAAuB;WAAqB;WAAyB;WAAyB;WAAkC;;WAChI;WAAuB;;;;;;;;;;;;;wBAatB,WAAW,OAAO,WAAW,OAAO,OAAO,UAAS,cAAmB;;iBCrBtE,sBAAsB;;WAE5B;;;iBAIM;;WAEN;;WAEA;;;;;;;;;;;YAYC;WAAyB;WAAwB;WAAwB,qBAAqB;WAA2B;;WAA0C;;;;;;;;;;;;;;;;wBAqB/J,YAAY,OAAO,WAAW,OAAO,OAAO,cAAc,UAAS,gBAAqB;;;;;;;;;;;;;;;wBC/BxF,SAAS,iBAAiB,WAAW,eAAe,WAAW;;qBChBlE;;;;;;qBAOA,aAAa"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/states.ts","../src/chance.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;;;;;;;;;YAaY;WACG;WAAuB;WAAqB;WAAyB;WAAyB;WAAkC;;WAChI;WAAuB;;;;;;;;;;;;;wBAatB,WAAW,OAAO,WAAW,OAAO,OAAO,UAAS,cAAmB;;iBCrBtE,sBAAsB;;WAE5B;;;;;;WAMA;;;iBAIM;;WAEN;;WAEA;;;;;;;;;;;YAYC;WAAyB;WAAwB;WAAwB,qBAAqB;WAA2B;;WAA0C;;;;;;;;;;;;;;;;;;;;wBAyB/J,YAAY,OAAO,WAAW,OAAO,OAAO,cAAc,UAAS,gBAAqB;;;;;;;;;;;;;;;wBCzCxF,SAAS,iBAAiB,WAAW,eAAe,WAAW;;qBChBlE;;;;;;qBAOA,aAAa"}
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { i as isChance, n as chancesByPart, r as firstGoals, t as RISK_SCHEMA } from "./layer-BLQnPkuy.js";
2
- import { i as worksChance, n as RISK_CODES, r as checkRisk, t as joinRisk } from "./join-ClFU2WDq.js";
1
+ import { a as inTimeChance, i as firstGoals, n as chancesByPart, o as isChance, r as delayFault, t as RISK_SCHEMA } from "./layer-Bkl6X1Vt.js";
2
+ import { i as worksChance, n as RISK_CODES, r as checkRisk, t as joinRisk } from "./join-B5LoxybX.js";
3
3
  import { smallestStop, stopSets, works } from "@mark1russell7/system-stack";
4
4
  // src/states.ts
5
5
  /**
@@ -143,6 +143,6 @@ const SAMPLE_RISK = {
143
143
  until: "2027-06-30"
144
144
  }]
145
145
  };
146
- export { RISK_CODES, RISK_SCHEMA, SAMPLE_RISK, SAMPLE_TODAY, chancesByPart, checkRisk, firstGoals, goalStates, isChance, joinRisk, worksChance };
146
+ export { RISK_CODES, RISK_SCHEMA, SAMPLE_RISK, SAMPLE_TODAY, chancesByPart, checkRisk, delayFault, firstGoals, goalStates, inTimeChance, isChance, joinRisk, worksChance };
147
147
 
148
148
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { i as isChance, n as chancesByPart, r as firstGoals, t as RISK_SCHEMA } from "./layer-BLQnPkuy.js";
1
+ import { a as inTimeChance, i as firstGoals, n as chancesByPart, o as isChance, r as delayFault, t as RISK_SCHEMA } from "./layer-Bkl6X1Vt.js";
2
2
  import { dayNumber, joinRecords, partsById, pathSets, stopSets, works } from "@mark1russell7/system-stack";
3
3
  import { NUMBER_RING, pathSetReliability } from "@mark1russell7/collections/graph";
4
4
  // src/chance.ts
@@ -14,13 +14,19 @@ function compareTexts(a, b) {
14
14
  * - A shared cause of failure is thus a part of the stack: a provider, an account or a power feed. Do not put it in a number.
15
15
  * - The value is exact: `pathSetReliability` of `@mark1russell7/collections/graph` counts a shared part one time.
16
16
  * - A part that does not work with the parts of `down` has the chance 0.
17
+ * - With `within`, the chance of each part is the chance that it works and ends in time. The time of each part is
18
+ * independent of the others when its needs work. A path ends when its last part ends: the delays do not add. Thus
19
+ * give the wait and the delay of each part as its time from the event, for example the time of a copy to send.
17
20
  * - The sequence of the parts of the stack does not change the value or an importance, to the last digit.
18
21
  *
19
22
  * The function is pure.
20
23
  *
21
- * @throws RangeError when a chance of a part of the paths is not from 0 to 1, or an option is not valid
24
+ * @throws RangeError when a chance of a part of the paths is not from 0 to 1, or an option is not valid. With
25
+ * `within`, also when the wait or the delay of a part of the paths is not valid.
22
26
  */
23
27
  function worksChance(layer, stack, part, options = {}) {
28
+ const { within } = options;
29
+ if (within !== void 0 && !(within >= 0)) throw new RangeError(`The limit of time ${String(within)} is not a time of 0 or more.`);
24
30
  const paths = pathSets(stack, part, options);
25
31
  if (paths.kind === "budget") return paths;
26
32
  if (paths.sets.length === 0) return {
@@ -34,7 +40,14 @@ function worksChance(layer, stack, part, options = {}) {
34
40
  const fixed = [...ids].sort(compareTexts);
35
41
  const index = new Map(fixed.map((id, at) => [id, at]));
36
42
  const records = chancesByPart(layer);
37
- const chances = fixed.map((id) => records.get(id)?.works ?? 1);
43
+ const chances = fixed.map((id) => {
44
+ const record = records.get(id);
45
+ if (within === void 0 || record === void 0) return record?.works ?? 1;
46
+ if (!isChance(record.works)) throw new RangeError(`The chance ${String(record.works)} of "${id}" is not from 0 to 1.`);
47
+ const fault = delayFault(record);
48
+ if (fault !== void 0) throw new RangeError(fault);
49
+ return record.works * inTimeChance(record, within);
50
+ });
38
51
  const sets = paths.sets.map((set) => [part, ...set].map((id) => index.get(id) ?? 0));
39
52
  const result = pathSetReliability(sets, chances, NUMBER_RING, options.maxSteps === void 0 ? {} : { maxSteps: options.maxSteps });
40
53
  if (result.kind === "budget") return { kind: "budget" };
@@ -56,9 +69,11 @@ const RISK_CODES = [
56
69
  "goal-duplicate",
57
70
  "goal-survives",
58
71
  "goal-chance",
72
+ "goal-within",
59
73
  "chance-part",
60
74
  "chance-duplicate",
61
75
  "chance-range",
76
+ "chance-delay",
62
77
  "accept-part",
63
78
  "accept-stop",
64
79
  "accept-date",
@@ -87,9 +102,11 @@ function setKey(parts) {
87
102
  * - `goal-duplicate`: two goals name one part.
88
103
  * - `goal-survives`: the count of a goal is not a whole number from 0.
89
104
  * - `goal-chance`: the chance of a goal is not from 0 to 1.
105
+ * - `goal-within`: the limit of time of a goal is not a time of 0 or more, or the goal has no chance.
90
106
  * - `chance-part`: a chance record names no part of the stack.
91
107
  * - `chance-duplicate`: two chance records name one part.
92
108
  * - `chance-range`: the chance of a part is not from 0 to 1.
109
+ * - `chance-delay`: the wait of a part is not a time of 0 or more, or its delay points are not in order.
93
110
  * - `accept-part`: an accepted risk names a part with no goal.
94
111
  * - `accept-stop`: an accepted risk names no part, or a part that is not in the stack.
95
112
  * - `accept-date`: the last date of an accepted risk is not a date.
@@ -100,7 +117,8 @@ function setKey(parts) {
100
117
  * - `accept-old`: the acceptance of a stop set ended before `today`.
101
118
  * - `accept-unused`: an accepted risk names a set that is no stop set of its goal. Remove the record.
102
119
  * - `chance-none`: a goal has a chance, and a part of its paths has no chance record.
103
- * - `chance-low`: the chance that a part works is less than the chance of its goal.
120
+ * - `chance-low`: the chance that a part works is less than the chance of its goal. With a limit of time, the part
121
+ * must also end its work in time.
104
122
  * - `no-read`: a search passed its limit. The gate has no result for the goal, so it does not pass.
105
123
  *
106
124
  * The faults are in the sequence of the chance records, the accepted risks and the goals. The function is pure.
@@ -139,6 +157,11 @@ function checkRisk(layer, stack, options) {
139
157
  add("chance-range", at, `The chance ${String(chance.works)} of "${at}" is not from 0 to 1.`);
140
158
  chancesValid = false;
141
159
  }
160
+ const fault = delayFault(chance);
161
+ if (fault !== void 0) {
162
+ add("chance-delay", at, fault);
163
+ chancesValid = false;
164
+ }
142
165
  }
143
166
  const goals = new Map(firstGoals(layer).map((goal) => [goal.part, goal]));
144
167
  const accepted = [];
@@ -186,6 +209,10 @@ function checkRisk(layer, stack, options) {
186
209
  const counted = Number.isInteger(goal.survives) && goal.survives >= 0;
187
210
  if (!counted) add("goal-survives", at, `The count ${String(goal.survives)} of the goal of "${at}" is not a whole number from 0.`);
188
211
  if (goal.chance !== void 0 && !isChance(goal.chance)) add("goal-chance", at, `The chance ${String(goal.chance)} of the goal of "${at}" is not from 0 to 1.`);
212
+ const { within } = goal;
213
+ const timed = within === void 0 || within >= 0 && goal.chance !== void 0;
214
+ if (within !== void 0 && !(within >= 0)) add("goal-within", at, `The limit of time ${String(within)} of the goal of "${at}" is not a time of 0 or more.`);
215
+ else if (within !== void 0 && goal.chance === void 0) add("goal-within", at, `The goal of "${at}" has a limit of time and no chance.`);
189
216
  if (!works(stack, at)) {
190
217
  add("stopped", at, `The part "${at}" does not work, with each part of the stack in operation: one of its needs does not hold.`);
191
218
  continue;
@@ -209,11 +236,14 @@ function checkRisk(layer, stack, options) {
209
236
  }
210
237
  }
211
238
  }
212
- if (goal.chance === void 0 || !isChance(goal.chance) || !chancesValid) continue;
213
- const chance = worksChance(layer, stack, at, limits);
239
+ if (goal.chance === void 0 || !isChance(goal.chance) || !chancesValid || !timed) continue;
240
+ const chance = worksChance(layer, stack, at, within === void 0 ? limits : {
241
+ ...limits,
242
+ within
243
+ });
214
244
  if (chance.kind === "budget") add("no-read", at, `The calculation of the chance of "${at}" passed its limit. The gate has no result for this goal.`);
215
245
  else if (chance.assumed.length > 0) add("chance-none", at, `The goal of "${at}" has a chance, and these parts of its paths have no chance record: ${setText(chance.assumed)}.`, { parts: chance.assumed });
216
- else if (chance.value < goal.chance) add("chance-low", at, `The chance that "${at}" works is ${String(chance.value)}. The goal is ${String(goal.chance)}.`);
246
+ else if (chance.value < goal.chance) add("chance-low", at, `The chance that "${at}" ${within === void 0 ? "works" : `works and ends within ${String(within)} seconds`} is ${String(chance.value)}. The goal is ${String(goal.chance)}.`);
217
247
  }
218
248
  for (const entry of accepted) {
219
249
  const at = entry.record.part;
@@ -260,4 +290,4 @@ function joinRisk(pieces) {
260
290
  }
261
291
  export { worksChance as i, RISK_CODES as n, checkRisk as r, joinRisk as t };
262
292
 
263
- //# sourceMappingURL=join-ClFU2WDq.js.map
293
+ //# sourceMappingURL=join-B5LoxybX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-B5LoxybX.js","names":[],"sources":["../src/chance.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["import { NUMBER_RING, pathSetReliability } from \"@mark1russell7/collections/graph\";\nimport { pathSets, type PathOptions, type Stack } from \"@mark1russell7/system-stack\";\nimport { chancesByPart, delayFault, inTimeChance, isChance, type RiskLayer } from \"./layer.ts\";\n\n// The chance that a part works, from the chance of each part of its paths. Each part works or fails alone.\n\n/** The options of `worksChance`. */\nexport interface ChanceOptions extends PathOptions {\n /** The largest count of steps of the calculation. The default is 1000000. */\n readonly maxSteps?: number | undefined;\n /**\n * The limit of time in seconds from the event, from 0. With it, a part works only when it also ends its work within\n * the limit. `inTimeChance` gives that chance from the wait and the delay of its record. `Infinity` uses the last\n * point of each delay. Without it, the time has no effect.\n */\n readonly within?: number | undefined;\n}\n\n/** The importance of one part for the chance that a different part works. */\nexport interface PartImportance {\n /** The `id` of the part. */\n readonly part: string;\n /** The Birnbaum importance: the chance when the part works, minus the chance when the part fails. */\n readonly importance: number;\n}\n\n/**\n * The result of `worksChance`.\n *\n * - `exact`: `value` is the chance that the part works. `importance` has the part and each part of its paths, from the\n * largest importance. Parts with one importance are in the sequence of the stack, after the part itself. `assumed`\n * has the parts of the paths with no chance record, in the sequence of the stack: the calculation uses the chance 1\n * for each. The part itself is not in `assumed`. A part that cannot work has the value 0 and two empty lists.\n * - `budget`: the search of the paths or the calculation passed its limit, so the result has no value.\n */\nexport type WorksChance = { readonly kind: \"exact\"; readonly value: number; readonly importance: readonly PartImportance[]; readonly assumed: readonly string[] } | { readonly kind: \"budget\" };\n\n/** This function compares two texts by their code units. The language of the computer does not change the result. */\nfunction compareTexts(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\n/**\n * This function gives the chance that a part of a stack works.\n *\n * - The part works when each part of one of its path sets works, and the part itself works.\n * - Each part works or fails alone, with the chance of its record in the layer. A part with no record has the chance 1.\n * - A shared cause of failure is thus a part of the stack: a provider, an account or a power feed. Do not put it in a number.\n * - The value is exact: `pathSetReliability` of `@mark1russell7/collections/graph` counts a shared part one time.\n * - A part that does not work with the parts of `down` has the chance 0.\n * - With `within`, the chance of each part is the chance that it works and ends in time. The time of each part is\n * independent of the others when its needs work. A path ends when its last part ends: the delays do not add. Thus\n * give the wait and the delay of each part as its time from the event, for example the time of a copy to send.\n * - The sequence of the parts of the stack does not change the value or an importance, to the last digit.\n *\n * The function is pure.\n *\n * @throws RangeError when a chance of a part of the paths is not from 0 to 1, or an option is not valid. With\n * `within`, also when the wait or the delay of a part of the paths is not valid.\n */\nexport function worksChance(layer: RiskLayer, stack: Stack, part: string, options: ChanceOptions = {}): WorksChance {\n const { within } = options;\n if (within !== undefined && !(within >= 0)) throw new RangeError(`The limit of time ${String(within)} is not a time of 0 or more.`);\n const paths = pathSets(stack, part, options);\n if (paths.kind === \"budget\") return paths;\n if (paths.sets.length === 0) return { kind: \"exact\", value: 0, importance: [], assumed: [] };\n // The part itself is first: it is a part of each path. Then each part of the paths, in the sequence of the stack.\n const used = new Set(paths.sets.flat());\n const ids = [part, ...stack.parts.map((entry) => entry.id).filter((id, at, all) => id !== part && used.has(id) && all.indexOf(id) === at)];\n // The calculation gets the parts in one fixed order, the order of the texts of the ids.\n // Thus the sequence of the records of the stack does not change the last digits of the value.\n // The order of the path sets and of the parts of a set has no effect on the result of `pathSetReliability`.\n const fixed = [...ids].sort(compareTexts);\n const index = new Map(fixed.map((id, at) => [id, at]));\n const records = chancesByPart(layer);\n const chances = fixed.map((id) => {\n const record = records.get(id);\n if (within === undefined || record === undefined) return record?.works ?? 1;\n // The product can hide a bad chance from the check of `pathSetReliability`, so this step examines it first.\n if (!isChance(record.works)) throw new RangeError(`The chance ${String(record.works)} of \"${id}\" is not from 0 to 1.`);\n const fault = delayFault(record);\n if (fault !== undefined) throw new RangeError(fault);\n return record.works * inTimeChance(record, within);\n });\n const sets = paths.sets.map((set) => [part, ...set].map((id) => index.get(id) ?? 0));\n const result = pathSetReliability(sets, chances, NUMBER_RING, options.maxSteps === undefined ? {} : { maxSteps: options.maxSteps });\n if (result.kind === \"budget\") return { kind: \"budget\" };\n const importance = ids.map((id) => ({ part: id, importance: result.importance[index.get(id) ?? 0] ?? 0 })).sort((a, b) => b.importance - a.importance);\n return { kind: \"exact\", value: result.value, importance, assumed: ids.filter((id) => id !== part && !records.has(id)) };\n}\n","import { dayNumber, partsById, stopSets, works, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { worksChance } from \"./chance.ts\";\nimport { delayFault, firstGoals, isChance, type Accepted, type RiskLayer } from \"./layer.ts\";\n\n// The gate of the risk layer. A gate that passes tells that each goal holds: no set of parts stops a part with fewer\n// failures than its goal permits, unless a record accepts the set, and each chance is not less than its goal.\n\n/** These are the codes of the faults of a risk layer. */\nexport const RISK_CODES: readonly [\n \"goal-part\",\n \"goal-duplicate\",\n \"goal-survives\",\n \"goal-chance\",\n \"goal-within\",\n \"chance-part\",\n \"chance-duplicate\",\n \"chance-range\",\n \"chance-delay\",\n \"accept-part\",\n \"accept-stop\",\n \"accept-date\",\n \"stopped\",\n \"stop-set\",\n \"accept-old\",\n \"accept-unused\",\n \"chance-none\",\n \"chance-low\",\n \"no-read\",\n] = [\n \"goal-part\",\n \"goal-duplicate\",\n \"goal-survives\",\n \"goal-chance\",\n \"goal-within\",\n \"chance-part\",\n \"chance-duplicate\",\n \"chance-range\",\n \"chance-delay\",\n \"accept-part\",\n \"accept-stop\",\n \"accept-date\",\n \"stopped\",\n \"stop-set\",\n \"accept-old\",\n \"accept-unused\",\n \"chance-none\",\n \"chance-low\",\n \"no-read\",\n];\n\n/** A code of a fault of a risk layer. */\nexport type RiskCode = (typeof RISK_CODES)[number];\n\n/** A fault of a risk layer. Its field `at` is the `id` of the part of the record. */\nexport interface RiskFault extends Fault {\n readonly code: RiskCode;\n /** The parts of the fault: the stop set, or the parts with no chance record. */\n readonly parts?: readonly string[] | undefined;\n}\n\n/** The options of the gate. */\nexport interface RiskOptions {\n /** The date of the check, as `YYYY-MM-DD`. The gate has no clock: the caller gives the date. */\n readonly today: string;\n /** The largest count of sets in one step of a search. The default is the default of the core, 4096. */\n readonly maxSets?: number | undefined;\n /** The largest count of steps of the calculation of a chance. The default is 1000000. */\n readonly maxSteps?: number | undefined;\n}\n\n/** This function gives the text of a set of parts for a message, for example `[\"card\", \"push\"]`. */\nfunction setText(parts: readonly string[]): string {\n return `[${parts.map((id) => `\"${id}\"`).join(\", \")}]`;\n}\n\n/** This function gives one key for each set of parts. The sequence of the parts does not change the key. */\nfunction setKey(parts: readonly string[]): string {\n return JSON.stringify([...new Set(parts)].sort());\n}\n\n/**\n * This function gives each fault of a risk layer for a stack. An empty list tells that the gate passes.\n * The gate examines the design: each part of the stack is in operation. `goalStates` gives the state with parts that are down.\n *\n * The records:\n * - `goal-part`: a goal names no part of the stack.\n * - `goal-duplicate`: two goals name one part.\n * - `goal-survives`: the count of a goal is not a whole number from 0.\n * - `goal-chance`: the chance of a goal is not from 0 to 1.\n * - `goal-within`: the limit of time of a goal is not a time of 0 or more, or the goal has no chance.\n * - `chance-part`: a chance record names no part of the stack.\n * - `chance-duplicate`: two chance records name one part.\n * - `chance-range`: the chance of a part is not from 0 to 1.\n * - `chance-delay`: the wait of a part is not a time of 0 or more, or its delay points are not in order.\n * - `accept-part`: an accepted risk names a part with no goal.\n * - `accept-stop`: an accepted risk names no part, or a part that is not in the stack.\n * - `accept-date`: the last date of an accepted risk is not a date.\n *\n * The goals:\n * - `stopped`: the part of a goal does not work, with each part of the stack in operation.\n * - `stop-set`: the failure of a set of parts stops a part, and the goal is to survive a set of that size. No record accepts the set.\n * - `accept-old`: the acceptance of a stop set ended before `today`.\n * - `accept-unused`: an accepted risk names a set that is no stop set of its goal. Remove the record.\n * - `chance-none`: a goal has a chance, and a part of its paths has no chance record.\n * - `chance-low`: the chance that a part works is less than the chance of its goal. With a limit of time, the part\n * must also end its work in time.\n * - `no-read`: a search passed its limit. The gate has no result for the goal, so it does not pass.\n *\n * The faults are in the sequence of the chance records, the accepted risks and the goals. The function is pure.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `maxSets` or `maxSteps` is not valid\n */\nexport function checkRisk(layer: RiskLayer, stack: Stack, options: RiskOptions): RiskFault[] {\n const today = dayNumber(options.today);\n if (today === undefined) throw new RangeError(`The date \"${options.today}\" is not a date of the form YYYY-MM-DD.`);\n const limits = { ...(options.maxSets === undefined ? {} : { maxSets: options.maxSets }), ...(options.maxSteps === undefined ? {} : { maxSteps: options.maxSteps }) };\n const faults: RiskFault[] = [];\n const add = (code: RiskCode, at: string, message: string, more: { readonly other?: string; readonly parts?: readonly string[] } = {}): void => {\n faults.push({ level: \"error\", code, at, message, ...more });\n };\n const parts = partsById(stack);\n\n const chanceParts = new Set<string>();\n let chancesValid = true;\n for (const chance of layer.chances ?? []) {\n const at = chance.part;\n if (chanceParts.has(at)) {\n add(\"chance-duplicate\", at, `Two chance records name the part \"${at}\".`);\n continue;\n }\n chanceParts.add(at);\n if (!parts.has(at)) add(\"chance-part\", at, `A chance record names \"${at}\", which is no part of the stack.`);\n if (!isChance(chance.works)) {\n add(\"chance-range\", at, `The chance ${String(chance.works)} of \"${at}\" is not from 0 to 1.`);\n chancesValid = false;\n }\n const fault = delayFault(chance);\n if (fault !== undefined) {\n add(\"chance-delay\", at, fault);\n chancesValid = false;\n }\n }\n\n const goals = new Map(firstGoals(layer).map((goal) => [goal.part, goal]));\n // Each accepted risk with a correct form, with the key of its set. `used` tells that the set is a stop set of its goal.\n const accepted: { readonly record: Accepted; readonly key: string; readonly ended: boolean; used: boolean }[] = [];\n for (const record of layer.accepted ?? []) {\n const at = record.part;\n let valid = true;\n if (!goals.has(at)) {\n add(\"accept-part\", at, `An accepted risk names \"${at}\", which has no goal.`);\n valid = false;\n }\n if (record.stop.length === 0) {\n add(\"accept-stop\", at, `An accepted risk of \"${at}\" names no part.`);\n valid = false;\n }\n for (const id of record.stop) {\n if (parts.has(id)) continue;\n add(\"accept-stop\", at, `An accepted risk of \"${at}\" names \"${id}\", which is no part of the stack.`, { other: id });\n valid = false;\n }\n const last = record.until === undefined ? undefined : dayNumber(record.until);\n if (record.until !== undefined && last === undefined) {\n add(\"accept-date\", at, `The date \"${record.until}\" of an accepted risk of \"${at}\" is not a date of the form YYYY-MM-DD.`);\n valid = false;\n }\n if (valid) accepted.push({ record, key: setKey(record.stop), ended: last !== undefined && last < today, used: false });\n }\n\n // The goals whose stop sets the gate read. An accepted risk of a different goal gets no examination.\n const read = new Set<string>();\n const seen = new Set<string>();\n for (const goal of layer.goals) {\n const at = goal.part;\n if (seen.has(at)) {\n add(\"goal-duplicate\", at, `Two goals name the part \"${at}\".`);\n continue;\n }\n seen.add(at);\n if (!parts.has(at)) {\n add(\"goal-part\", at, `A goal names \"${at}\", which is no part of the stack.`);\n continue;\n }\n const counted = Number.isInteger(goal.survives) && goal.survives >= 0;\n if (!counted) add(\"goal-survives\", at, `The count ${String(goal.survives)} of the goal of \"${at}\" is not a whole number from 0.`);\n if (goal.chance !== undefined && !isChance(goal.chance)) add(\"goal-chance\", at, `The chance ${String(goal.chance)} of the goal of \"${at}\" is not from 0 to 1.`);\n const { within } = goal;\n const timed = within === undefined || (within >= 0 && goal.chance !== undefined);\n if (within !== undefined && !(within >= 0)) add(\"goal-within\", at, `The limit of time ${String(within)} of the goal of \"${at}\" is not a time of 0 or more.`);\n else if (within !== undefined && goal.chance === undefined) add(\"goal-within\", at, `The goal of \"${at}\" has a limit of time and no chance.`);\n if (!works(stack, at)) {\n add(\"stopped\", at, `The part \"${at}\" does not work, with each part of the stack in operation: one of its needs does not hold.`);\n continue;\n }\n if (counted) {\n const stops = stopSets(stack, at, { ...limits, size: goal.survives });\n if (stops.kind === \"budget\") add(\"no-read\", at, `The search of the stop sets of \"${at}\" passed its limit. The gate has no result for this goal.`);\n else {\n read.add(at);\n for (const set of stops.sets) {\n const key = setKey(set);\n const records = accepted.filter((entry) => entry.record.part === at && entry.key === key);\n for (const entry of records) entry.used = true;\n if (records.some((entry) => !entry.ended)) continue;\n const old = records[0];\n if (old === undefined) {\n add(\"stop-set\", at, `The failure of the set ${setText(set)} stops \"${at}\". The goal of \"${at}\" is to survive each set of ${String(goal.survives)} or fewer parts.`, { parts: set });\n } else {\n add(\"accept-old\", at, `The acceptance of the stop set ${setText(set)} of \"${at}\" ended on ${old.record.until ?? \"\"}. The failure of the set stops \"${at}\".`, { parts: set });\n }\n }\n }\n }\n if (goal.chance === undefined || !isChance(goal.chance) || !chancesValid || !timed) continue;\n const chance = worksChance(layer, stack, at, within === undefined ? limits : { ...limits, within });\n if (chance.kind === \"budget\") add(\"no-read\", at, `The calculation of the chance of \"${at}\" passed its limit. The gate has no result for this goal.`);\n else if (chance.assumed.length > 0) {\n add(\"chance-none\", at, `The goal of \"${at}\" has a chance, and these parts of its paths have no chance record: ${setText(chance.assumed)}.`, { parts: chance.assumed });\n } else if (chance.value < goal.chance) {\n const what = within === undefined ? \"works\" : `works and ends within ${String(within)} seconds`;\n add(\"chance-low\", at, `The chance that \"${at}\" ${what} is ${String(chance.value)}. The goal is ${String(goal.chance)}.`);\n }\n }\n\n for (const entry of accepted) {\n const at = entry.record.part;\n if (entry.used || !read.has(at)) continue;\n const survives = goals.get(at)?.survives ?? 0;\n add(\"accept-unused\", at, `An accepted risk of \"${at}\" names the set ${setText(entry.record.stop)}. It is no stop set of \"${at}\" of ${String(survives)} or fewer parts.`, { parts: entry.record.stop });\n }\n return faults;\n}\n","import { joinRecords, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { RISK_SCHEMA, type RiskLayer } from \"./layer.ts\";\n\n// The join of the risk layers of the fragments of a stack, for example one file of goals for each owner.\n\n/**\n * This function joins the risk layers of the fragments of a stack into one layer.\n *\n * - The goals and the chance records are in the order of the fragments. The record of a part is in one fragment.\n * - A part with a goal in two or more fragments is a fault, also when the goals are equal.\n * - A part with a chance record in two or more fragments is a fault, also when the records are equal.\n * - The accepted risks are in the order of the fragments. A fragment can accept a risk of a goal of a different fragment.\n *\n * The joined layer has the field `chances` or `accepted` when a fragment has it. The function is pure, and it\n * changes no layer. The gate `checkRisk` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinRisk(pieces: readonly LayerPiece<RiskLayer>[]): LayerParse<RiskLayer> {\n const goals = joinRecords(\n pieces,\n (layer) => layer.goals,\n (goal) => goal.part,\n \"goal of the part\",\n );\n const chances = joinRecords(\n pieces,\n (layer) => layer.chances,\n (chance) => chance.part,\n \"chance record of the part\",\n );\n const errors = [...goals.errors, ...chances.errors];\n if (errors.length > 0) return { ok: false, errors };\n const withChances = pieces.some((piece) => piece.layer.chances !== undefined);\n const withAccepted = pieces.some((piece) => piece.layer.accepted !== undefined);\n return {\n ok: true,\n layer: {\n schema: RISK_SCHEMA,\n goals: goals.items,\n ...(withChances ? { chances: chances.items } : {}),\n ...(withAccepted ? { accepted: pieces.flatMap((piece) => piece.layer.accepted ?? []) } : {}),\n },\n };\n}\n"],"mappings":";;;;;AAsCA,SAAS,aAAa,GAAW,GAAmB;CAClD,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,OAAkB,OAAc,MAAc,UAAyB,CAAC,GAAgB;CAClH,MAAM,EAAE,WAAW;CACnB,IAAI,WAAW,KAAA,KAAa,EAAE,UAAU,IAAI,MAAM,IAAI,WAAW,qBAAqB,OAAO,MAAM,EAAE,6BAA6B;CAClI,MAAM,QAAQ,SAAS,OAAO,MAAM,OAAO;CAC3C,IAAI,MAAM,SAAS,UAAU,OAAO;CACpC,IAAI,MAAM,KAAK,WAAW,GAAG,OAAO;EAAE,MAAM;EAAS,OAAO;EAAG,YAAY,CAAC;EAAG,SAAS,CAAC;CAAE;CAE3F,MAAM,OAAO,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC;CACtC,MAAM,MAAM,CAAC,MAAM,GAAG,MAAM,MAAM,KAAK,UAAU,MAAM,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI,QAAQ,OAAO,QAAQ,KAAK,IAAI,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,EAAE,CAAC;CAIzI,MAAM,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,YAAY;CACxC,MAAM,QAAQ,IAAI,IAAI,MAAM,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;CACrD,MAAM,UAAU,cAAc,KAAK;CACnC,MAAM,UAAU,MAAM,KAAK,OAAO;EAChC,MAAM,SAAS,QAAQ,IAAI,EAAE;EAC7B,IAAI,WAAW,KAAA,KAAa,WAAW,KAAA,GA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AgB,SAAS,QAAiE;CACxF,MAAM,QAAQ,YACZ,SACC,UAAU,MAAM,QAChB,SAAS,KAAK,MACf,kBACF;CACA,MAAM,UAAU,YACd,SACC,UAAU,MAAM,UAChB,WAAW,OAAO,MACnB,2BACF;CACA,MAAM,SAAS,CAAC,GAAG,MAAM,QAAQ,GAAG,QAAQ,MAAM;CAClD,IAAI,OAAO,SAAS,GAAG,OAAO;EAAE,IAAI;EAAO;CAAO;CAClD,MAAM,cAAc,OAAO,MAAM,UAAU,MAAM,MAAM,YAAY,KAAA,CAAS;CAC5E,MAAM,eAAe,OAAO,MAAM,UAAU,MAAM,MAAM,aAAa,KAAA,CAAS;CAC9E,OAAO;EACL,IAAI;EACJ,OAAO;GACL,QAAQ;GACR,OAAO,MAAM;GACb,GAAI,cAAc,EAAE,SAAS,QAAQ,MAAM,IAAI,CAAC;GAChD,GAAI,eAAe,EAAE,UAAU,OAAO,SAAS,UAAU,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC;EAC5F;CACF;AACF"}
@@ -0,0 +1,59 @@
1
+ // src/layer.ts
2
+ /** The name of the format of a risk layer. It is the key of the layer in `Stack.layers`. */
3
+ const RISK_SCHEMA = "risk/1";
4
+ /** This function gives the first goal of each part of a layer, in the sequence of the records. */
5
+ function firstGoals(layer) {
6
+ const seen = /* @__PURE__ */ new Set();
7
+ return layer.goals.filter((goal) => {
8
+ if (seen.has(goal.part)) return false;
9
+ seen.add(goal.part);
10
+ return true;
11
+ });
12
+ }
13
+ /** This function gives the chance record of each part of a layer, by the `id` of the part. The first record of a part is used. */
14
+ function chancesByPart(layer) {
15
+ const chances = /* @__PURE__ */ new Map();
16
+ for (const chance of layer.chances ?? []) if (!chances.has(chance.part)) chances.set(chance.part, chance);
17
+ return chances;
18
+ }
19
+ /** This function tells if a value is a chance: a number from 0 to 1. */
20
+ function isChance(value) {
21
+ return value >= 0 && value <= 1;
22
+ }
23
+ /**
24
+ * This function gives the chance that a part ends its work within `within` seconds of the event, when the part works.
25
+ *
26
+ * - The part waits for its `wait`, then it ends after its delay.
27
+ * - Between two points of the delay, the chance is the chance of the lower point. Thus the chance is a lower bound.
28
+ * - With no record or no points, the delay is 0. With `Infinity`, the chance is the chance of the last point.
29
+ * - Without a limit of time, the chance is 1: the time has no effect.
30
+ */
31
+ function inTimeChance(chance, within) {
32
+ if (within === void 0) return 1;
33
+ const left = within - (chance?.wait ?? 0);
34
+ if (left < 0) return 0;
35
+ const points = chance?.delay ?? [];
36
+ if (points.length === 0) return 1;
37
+ let found = 0;
38
+ for (const point of points) if (point.within <= left) found = point.chance;
39
+ return found;
40
+ }
41
+ /** This function gives the first fault of the wait and of the delay points of a chance record, or `undefined`. */
42
+ function delayFault(chance) {
43
+ const { part, wait } = chance;
44
+ if (wait !== void 0 && !(wait >= 0 && Number.isFinite(wait))) return `The wait ${String(wait)} of "${part}" is not a time of 0 or more.`;
45
+ let last = -1;
46
+ let lastChance = 0;
47
+ for (const [index, point] of (chance.delay ?? []).entries()) {
48
+ const what = `The delay point ${String(index)} of "${part}"`;
49
+ if (!(point.within >= 0 && Number.isFinite(point.within))) return `${what} has the time ${String(point.within)}, which is not a time of 0 or more.`;
50
+ if (point.within <= last) return `${what} is not after the point before it.`;
51
+ if (!isChance(point.chance)) return `${what} has the chance ${String(point.chance)}, which is not from 0 to 1.`;
52
+ if (point.chance < lastChance) return `${what} has a chance less than the chance of the point before it.`;
53
+ last = point.within;
54
+ lastChance = point.chance;
55
+ }
56
+ }
57
+ export { inTimeChance as a, firstGoals as i, chancesByPart as n, isChance as o, delayFault as r, RISK_SCHEMA as t };
58
+
59
+ //# sourceMappingURL=layer-Bkl6X1Vt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layer-Bkl6X1Vt.js","names":[],"sources":["../src/layer.ts"],"sourcesContent":["// The records of the risk add-on. They are one layer of a stack, with the key `risk/1` in `Stack.layers`.\n// A goal tells how many failures a part must survive. The answers are queries over the stack: the layer keeps no list of risks.\n\n/** The name of the format of a risk layer. It is the key of the layer in `Stack.layers`. */\nexport const RISK_SCHEMA = \"risk/1\";\n\n/** The goal of one part of the stack, for example of a function of the system. */\nexport interface Goal {\n /** The `id` of the part with the goal. */\n readonly part: string;\n /**\n * The count of failures of other parts that the part survives. It is a whole number from 0.\n * With 1, no failure of one part stops the part: it has no single point of failure.\n */\n readonly survives: number;\n /** The smallest chance that the part works, from 0 to 1. The gate then needs the chance of each part of its paths. */\n readonly chance?: number | undefined;\n /**\n * The limit of time of the chance, in seconds from the event. With it, a part works only when it also ends its work\n * within the limit. A goal with a limit of time needs a chance.\n */\n readonly within?: number | undefined;\n}\n\n/** A point of the distribution of a time: the chance that the time is `within` seconds or less. */\nexport interface DelayPoint {\n /** The time in seconds, from 0. */\n readonly within: number;\n /** The chance that the time is `within` seconds or less, from 0 to 1. */\n readonly chance: number;\n}\n\n/** The chance that one part works. */\nexport interface Chance {\n /** The `id` of the part. */\n readonly part: string;\n /** The chance that the part works at a moment, from 0 to 1, when each of its needs holds. */\n readonly works: number;\n /** The source of the number, for example the service agreement of a provider or a measured period. */\n readonly source?: string | undefined;\n /** The wait of the part before it starts, in seconds, for example the wait of the rank of a copy. The default is 0. */\n readonly wait?: number | undefined;\n /**\n * The distribution of the time from the end of the wait to the end of the work of the part, when the part works. The\n * times of the points increase, and their chances do not decrease. No points tell a time of 0.\n */\n readonly delay?: readonly DelayPoint[] | undefined;\n}\n\n/** An accepted risk: one set of parts whose failure stops a part, which the owner accepts for a reason. */\nexport interface Accepted {\n /** The `id` of the part with the goal. */\n readonly part: string;\n /** The parts of the set, in any sequence. Their failure together stops the part. */\n readonly stop: readonly string[];\n /** The reason of the owner. */\n readonly reason: string;\n /** The last date of the acceptance, as `YYYY-MM-DD`. After that date the gate fails for the set. An acceptance without it has no end. */\n readonly until?: string | undefined;\n}\n\n/** A risk layer: the goals of the parts of a stack, the chance of each part, and the accepted risks. */\nexport interface RiskLayer {\n readonly schema: typeof RISK_SCHEMA;\n readonly goals: readonly Goal[];\n readonly chances?: readonly Chance[] | undefined;\n readonly accepted?: readonly Accepted[] | undefined;\n}\n\n/** This function gives the first goal of each part of a layer, in the sequence of the records. */\nexport function firstGoals(layer: RiskLayer): readonly Goal[] {\n const seen = new Set<string>();\n return layer.goals.filter((goal) => {\n if (seen.has(goal.part)) return false;\n seen.add(goal.part);\n return true;\n });\n}\n\n/** This function gives the chance record of each part of a layer, by the `id` of the part. The first record of a part is used. */\nexport function chancesByPart(layer: RiskLayer): Map<string, Chance> {\n const chances = new Map<string, Chance>();\n for (const chance of layer.chances ?? []) if (!chances.has(chance.part)) chances.set(chance.part, chance);\n return chances;\n}\n\n/** This function tells if a value is a chance: a number from 0 to 1. */\nexport function isChance(value: number): boolean {\n return value >= 0 && value <= 1;\n}\n\n/**\n * This function gives the chance that a part ends its work within `within` seconds of the event, when the part works.\n *\n * - The part waits for its `wait`, then it ends after its delay.\n * - Between two points of the delay, the chance is the chance of the lower point. Thus the chance is a lower bound.\n * - With no record or no points, the delay is 0. With `Infinity`, the chance is the chance of the last point.\n * - Without a limit of time, the chance is 1: the time has no effect.\n */\nexport function inTimeChance(chance: Chance | undefined, within: number | undefined): number {\n if (within === undefined) return 1;\n const left = within - (chance?.wait ?? 0);\n if (left < 0) return 0;\n const points = chance?.delay ?? [];\n if (points.length === 0) return 1;\n let found = 0;\n for (const point of points) if (point.within <= left) found = point.chance;\n return found;\n}\n\n/** This function gives the first fault of the wait and of the delay points of a chance record, or `undefined`. */\nexport function delayFault(chance: Chance): string | undefined {\n const { part, wait } = chance;\n if (wait !== undefined && !(wait >= 0 && Number.isFinite(wait))) return `The wait ${String(wait)} of \"${part}\" is not a time of 0 or more.`;\n let last = -1;\n let lastChance = 0;\n for (const [index, point] of (chance.delay ?? []).entries()) {\n const what = `The delay point ${String(index)} of \"${part}\"`;\n if (!(point.within >= 0 && Number.isFinite(point.within))) return `${what} has the time ${String(point.within)}, which is not a time of 0 or more.`;\n if (point.within <= last) return `${what} is not after the point before it.`;\n if (!isChance(point.chance)) return `${what} has the chance ${String(point.chance)}, which is not from 0 to 1.`;\n if (point.chance < lastChance) return `${what} has a chance less than the chance of the point before it.`;\n last = point.within;\n lastChance = point.chance;\n }\n return undefined;\n}\n"],"mappings":";;AAIA,MAAa,cAAc;;AAkE3B,SAAgB,WAAW,OAAmC;CAC5D,MAAM,uBAAO,IAAI,IAAY;CAC7B,OAAO,MAAM,MAAM,QAAQ,SAAS;EAClC,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,OAAO;EAChC,KAAK,IAAI,KAAK,IAAI;EAClB,OAAO;CACT,CAAC;AACH;;AAGA,SAAgB,cAAc,OAAuC;CACnE,MAAM,0BAAU,IAAI,IAAoB;CACxC,KAAK,MAAM,UAAU,MAAM,WAAW,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,IAAI,GAAG,QAAQ,IAAI,OAAO,MAAM,MAAM;CACxG,OAAO;AACT;;AAGA,SAAgB,SAAS,OAAwB;CAC/C,OAAO,SAAS,KAAK,SAAS;AAChC;;;;;;;;;AAUA,SAAgB,aAAa,QAA4B,QAAoC;CAC3F,IAAI,WAAW,KAAA,GAAW,OAAO;CACjC,MAAM,OAAO,UAAU,QAAQ,QAAQ;CACvC,IAAI,OAAO,GAAG,OAAO;CACrB,MAAM,SAAS,QAAQ,SAAS,CAAC;CACjC,IAAI,OAAO,WAAW,GAAG,OAAO;CAChC,IAAI,QAAQ;CACZ,KAAK,MAAM,SAAS,QAAQ,IAAI,MAAM,UAAU,MAAM,QAAQ,MAAM;CACpE,OAAO;AACT;;AAGA,SAAgB,WAAW,QAAoC;CAC7D,MAAM,EAAE,MAAM,SAAS;CACvB,IAAI,SAAS,KAAA,KAAa,EAAE,QAAQ,KAAK,OAAO,SAAS,IAAI,IAAI,OAAO,YAAY,OAAO,IAAI,EAAE,OAAO,KAAK;CAC7G,IAAI,OAAO;CACX,IAAI,aAAa;CACjB,KAAK,MAAM,CAAC,OAAO,WAAW,OAAO,SAAS,CAAC,EAAA,CAAG,QAAQ,GAAG;EAC3D,MAAM,OAAO,mBAAmB,OAAO,KAAK,EAAE,OAAO,KAAK;EAC1D,IAAI,EAAE,MAAM,UAAU,KAAK,OAAO,SAAS,MAAM,MAAM,IAAI,OAAO,GAAG,KAAK,gBAAgB,OAAO,MAAM,MAAM,EAAE;EAC/G,IAAI,MAAM,UAAU,MAAM,OAAO,GAAG,KAAK;EACzC,IAAI,CAAC,SAAS,MAAM,MAAM,GAAG,OAAO,GAAG,KAAK,kBAAkB,OAAO,MAAM,MAAM,EAAE;EACnF,IAAI,MAAM,SAAS,YAAY,OAAO,GAAG,KAAK;EAC9C,OAAO,MAAM;EACb,aAAa,MAAM;CACrB;AAEF"}
@@ -11,6 +11,18 @@ interface Goal {
11
11
  readonly survives: number;
12
12
  /** The smallest chance that the part works, from 0 to 1. The gate then needs the chance of each part of its paths. */
13
13
  readonly chance?: number | undefined;
14
+ /**
15
+ * The limit of time of the chance, in seconds from the event. With it, a part works only when it also ends its work
16
+ * within the limit. A goal with a limit of time needs a chance.
17
+ */
18
+ readonly within?: number | undefined;
19
+ }
20
+ /** A point of the distribution of a time: the chance that the time is `within` seconds or less. */
21
+ interface DelayPoint {
22
+ /** The time in seconds, from 0. */
23
+ readonly within: number;
24
+ /** The chance that the time is `within` seconds or less, from 0 to 1. */
25
+ readonly chance: number;
14
26
  }
15
27
  /** The chance that one part works. */
16
28
  interface Chance {
@@ -20,6 +32,13 @@ interface Chance {
20
32
  readonly works: number;
21
33
  /** The source of the number, for example the service agreement of a provider or a measured period. */
22
34
  readonly source?: string | undefined;
35
+ /** The wait of the part before it starts, in seconds, for example the wait of the rank of a copy. The default is 0. */
36
+ readonly wait?: number | undefined;
37
+ /**
38
+ * The distribution of the time from the end of the wait to the end of the work of the part, when the part works. The
39
+ * times of the points increase, and their chances do not decrease. No points tell a time of 0.
40
+ */
41
+ readonly delay?: readonly DelayPoint[] | undefined;
23
42
  }
24
43
  /** An accepted risk: one set of parts whose failure stops a part, which the owner accepts for a reason. */
25
44
  interface Accepted {
@@ -45,5 +64,16 @@ declare function firstGoals(layer: RiskLayer): readonly Goal[];
45
64
  declare function chancesByPart(layer: RiskLayer): Map<string, Chance>;
46
65
  /** This function tells if a value is a chance: a number from 0 to 1. */
47
66
  declare function isChance(value: number): boolean;
48
- export { RiskLayer as a, isChance as c, RISK_SCHEMA as i, Chance as n, chancesByPart as o, Goal as r, firstGoals as s, Accepted as t };
49
- //# sourceMappingURL=layer-zvH_ueL5.d.ts.map
67
+ /**
68
+ * This function gives the chance that a part ends its work within `within` seconds of the event, when the part works.
69
+ *
70
+ * - The part waits for its `wait`, then it ends after its delay.
71
+ * - Between two points of the delay, the chance is the chance of the lower point. Thus the chance is a lower bound.
72
+ * - With no record or no points, the delay is 0. With `Infinity`, the chance is the chance of the last point.
73
+ * - Without a limit of time, the chance is 1: the time has no effect.
74
+ */
75
+ declare function inTimeChance(chance: Chance | undefined, within: number | undefined): number;
76
+ /** This function gives the first fault of the wait and of the delay points of a chance record, or `undefined`. */
77
+ declare function delayFault(chance: Chance): string | undefined;
78
+ export { RISK_SCHEMA as a, delayFault as c, isChance as d, Goal as i, firstGoals as l, Chance as n, RiskLayer as o, DelayPoint as r, chancesByPart as s, Accepted as t, inTimeChance as u };
79
+ //# sourceMappingURL=layer-D4_dWgrV.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layer-D4_dWgrV.d.ts","names":[],"sources":["../src/layer.ts"],"mappings":";cAIa;;UAGI;;WAEN;;;;;WAKA;;WAEA;;;;;WAKA;;;UAIM;;WAEN;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;;;;WAKA,iBAAiB;;;UAIX;;WAEN;;WAEA;;WAEA;;WAEA;;;UAIM;WACN,eAAe;WACf,gBAAgB;WAChB,mBAAmB;WACnB,oBAAoB;;;iBAIf,WAAW,OAAO,qBAAqB;;iBAUvC,cAAc,OAAO,YAAY,YAAY;;iBAO7C,SAAS;;;;;;;;;iBAYT,aAAa,QAAQ,oBAAoB;;iBAYzC,WAAW,QAAQ"}
package/build/schema.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as RiskLayer } from "./layer-zvH_ueL5.js";
1
+ import { o as RiskLayer } from "./layer-D4_dWgrV.js";
2
2
  import { z } from "zod";
3
3
  /**
4
4
  * The schema of a risk layer. It examines the form of the record: the fields, their types and the finite numbers.
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;qBAgCa,YAAY,EAAE,QAAQ;;YAQvB;WAAuB;WAAmB,OAAO;;WAAyB;WAAoB;;;;;;wBAM1F,UAAU,iBAAiB"}
1
+ {"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;qBAwCa,YAAY,EAAE,QAAQ;;YAQvB;WAAuB;WAAmB,OAAO;;WAAyB;WAAoB;;;;;;wBAM1F,UAAU,iBAAiB"}
package/build/schema.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RISK_SCHEMA } from "./layer-BLQnPkuy.js";
1
+ import { t as RISK_SCHEMA } from "./layer-Bkl6X1Vt.js";
2
2
  import { formErrors } from "@mark1russell7/system-stack/schema";
3
3
  import { z } from "zod";
4
4
  // src/schema.ts
@@ -6,12 +6,19 @@ const id = z.string().min(1);
6
6
  const goal = z.strictObject({
7
7
  part: id,
8
8
  survives: z.number(),
9
- chance: z.number().optional()
9
+ chance: z.number().optional(),
10
+ within: z.number().optional()
11
+ });
12
+ const point = z.strictObject({
13
+ within: z.number(),
14
+ chance: z.number()
10
15
  });
11
16
  const chance = z.strictObject({
12
17
  part: id,
13
18
  works: z.number(),
14
- source: z.string().optional()
19
+ source: z.string().optional(),
20
+ wait: z.number().optional(),
21
+ delay: z.array(point).readonly().optional()
15
22
  });
16
23
  const accepted = z.strictObject({
17
24
  part: id,
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { formErrors } from \"@mark1russell7/system-stack/schema\";\nimport { z } from \"zod\";\nimport { RISK_SCHEMA, type RiskLayer } from \"./layer.ts\";\n\n// The zod schema of a risk layer, and the read of its JSON. This module is the entry `/schema` of the package.\n// The root entry has no zod, so a page that only runs the queries gets no schema library.\n\nconst id = z.string().min(1);\n\nconst goal = z.strictObject({\n part: id,\n survives: z.number(),\n chance: z.number().optional(),\n});\n\nconst chance = z.strictObject({\n part: id,\n works: z.number(),\n source: z.string().optional(),\n});\n\nconst accepted = z.strictObject({\n part: id,\n stop: z.array(id).readonly(),\n reason: z.string().min(1),\n until: z.string().optional(),\n});\n\n/**\n * The schema of a risk layer. It examines the form of the record: the fields, their types and the finite numbers.\n * It refuses a field that the format does not have. `checkRisk` examines the meaning of a layer with a correct form.\n */\nexport const riskSchema: z.ZodType<RiskLayer> = z.strictObject({\n schema: z.literal(RISK_SCHEMA),\n goals: z.array(goal).readonly(),\n chances: z.array(chance).readonly().optional(),\n accepted: z.array(accepted).readonly().optional(),\n});\n\n/** The result of the read of a risk layer: the layer, or the faults of its form. */\nexport type RiskParse = { readonly ok: true; readonly layer: RiskLayer } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of a risk layer. It gives the layer, or the faults of its form.\n * Each fault names its place in the record, for example `goals.0.part`.\n */\nexport function parseRisk(value: unknown): RiskParse {\n const read = riskSchema.safeParse(value);\n if (read.success) return { ok: true, layer: read.data };\n return { ok: false, errors: formErrors(RISK_SCHEMA, read.error.issues) };\n}\n"],"mappings":";;;;AAOA,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAE3B,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM;CACN,UAAU,EAAE,OAAO;CACnB,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;AAC9B,CAAC;AAED,MAAM,SAAS,EAAE,aAAa;CAC5B,MAAM;CACN,OAAO,EAAE,OAAO;CAChB,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;AAC9B,CAAC;AAED,MAAM,WAAW,EAAE,aAAa;CAC9B,MAAM;CACN,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS;CAC3B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;AAC7B,CAAC;;;;;AAMD,MAAa,aAAmC,EAAE,aAAa;CAC7D,QAAQ,EAAE,QAAQ,WAAW;CAC7B,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,SAAS;CAC9B,SAAS,EAAE,MAAM,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC7C,UAAU,EAAE,MAAM,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;AAClD,CAAC;;;;;AASD,SAAgB,UAAU,OAA2B;CACnD,MAAM,OAAO,WAAW,UAAU,KAAK;CACvC,IAAI,KAAK,SAAS,OAAO;EAAE,IAAI;EAAM,OAAO,KAAK;CAAK;CACtD,OAAO;EAAE,IAAI;EAAO,QAAQ,WAAW,aAAa,KAAK,MAAM,MAAM;CAAE;AACzE"}
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { formErrors } from \"@mark1russell7/system-stack/schema\";\nimport { z } from \"zod\";\nimport { RISK_SCHEMA, type RiskLayer } from \"./layer.ts\";\n\n// The zod schema of a risk layer, and the read of its JSON. This module is the entry `/schema` of the package.\n// The root entry has no zod, so a page that only runs the queries gets no schema library.\n\nconst id = z.string().min(1);\n\nconst goal = z.strictObject({\n part: id,\n survives: z.number(),\n chance: z.number().optional(),\n within: z.number().optional(),\n});\n\nconst point = z.strictObject({\n within: z.number(),\n chance: z.number(),\n});\n\nconst chance = z.strictObject({\n part: id,\n works: z.number(),\n source: z.string().optional(),\n wait: z.number().optional(),\n delay: z.array(point).readonly().optional(),\n});\n\nconst accepted = z.strictObject({\n part: id,\n stop: z.array(id).readonly(),\n reason: z.string().min(1),\n until: z.string().optional(),\n});\n\n/**\n * The schema of a risk layer. It examines the form of the record: the fields, their types and the finite numbers.\n * It refuses a field that the format does not have. `checkRisk` examines the meaning of a layer with a correct form.\n */\nexport const riskSchema: z.ZodType<RiskLayer> = z.strictObject({\n schema: z.literal(RISK_SCHEMA),\n goals: z.array(goal).readonly(),\n chances: z.array(chance).readonly().optional(),\n accepted: z.array(accepted).readonly().optional(),\n});\n\n/** The result of the read of a risk layer: the layer, or the faults of its form. */\nexport type RiskParse = { readonly ok: true; readonly layer: RiskLayer } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of a risk layer. It gives the layer, or the faults of its form.\n * Each fault names its place in the record, for example `goals.0.part`.\n */\nexport function parseRisk(value: unknown): RiskParse {\n const read = riskSchema.safeParse(value);\n if (read.success) return { ok: true, layer: read.data };\n return { ok: false, errors: formErrors(RISK_SCHEMA, read.error.issues) };\n}\n"],"mappings":";;;;AAOA,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAE3B,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM;CACN,UAAU,EAAE,OAAO;CACnB,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;AAC9B,CAAC;AAED,MAAM,QAAQ,EAAE,aAAa;CAC3B,QAAQ,EAAE,OAAO;CACjB,QAAQ,EAAE,OAAO;AACnB,CAAC;AAED,MAAM,SAAS,EAAE,aAAa;CAC5B,MAAM;CACN,OAAO,EAAE,OAAO;CAChB,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,OAAO,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;AAC5C,CAAC;AAED,MAAM,WAAW,EAAE,aAAa;CAC9B,MAAM;CACN,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS;CAC3B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;AAC7B,CAAC;;;;;AAMD,MAAa,aAAmC,EAAE,aAAa;CAC7D,QAAQ,EAAE,QAAQ,WAAW;CAC7B,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,SAAS;CAC9B,SAAS,EAAE,MAAM,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC7C,UAAU,EAAE,MAAM,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;AAClD,CAAC;;;;;AASD,SAAgB,UAAU,OAA2B;CACnD,MAAM,OAAO,WAAW,UAAU,KAAK;CACvC,IAAI,KAAK,SAAS,OAAO;EAAE,IAAI;EAAM,OAAO,KAAK;CAAK;CACtD,OAAO;EAAE,IAAI;EAAO,QAAQ,WAAW,aAAa,KAAK,MAAM,MAAM;CAAE;AACzE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/stack-risk",
4
- "version": "0.1.3",
4
+ "version": "0.2.0",
5
5
  "description": "The risks of a system stack as queries: the parts whose failure stops a function, the failures that a function survives, the chance that it works, and a gate. An add-on of system-stack.",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -53,6 +53,7 @@
53
53
  "zod": "^4.6.7"
54
54
  },
55
55
  "devDependencies": {
56
+ "@mark1russell7/algebra": "^0.9.8",
56
57
  "@mark1russell7/cue": "^2.0.0",
57
58
  "@types/node": "^26.6.5",
58
59
  "@vitest/coverage-v8": "^5.0.3",
@@ -1 +0,0 @@
1
- {"version":3,"file":"check-CahTrDAa.d.ts","names":[],"sources":["../src/check.ts"],"mappings":";;;cAQa;;KAuCD,mBAAmB;;UAGd,kBAAkB;WACxB,MAAM;;WAEN;;;UAIM;;WAEN;;WAEA;;WAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0CK,UAAU,OAAO,WAAW,OAAO,OAAO,SAAS,cAAc"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"join-ClFU2WDq.js","names":[],"sources":["../src/chance.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["import { NUMBER_RING, pathSetReliability } from \"@mark1russell7/collections/graph\";\nimport { pathSets, type PathOptions, type Stack } from \"@mark1russell7/system-stack\";\nimport { chancesByPart, type RiskLayer } from \"./layer.ts\";\n\n// The chance that a part works, from the chance of each part of its paths. Each part works or fails alone.\n\n/** The options of `worksChance`. */\nexport interface ChanceOptions extends PathOptions {\n /** The largest count of steps of the calculation. The default is 1000000. */\n readonly maxSteps?: number | undefined;\n}\n\n/** The importance of one part for the chance that a different part works. */\nexport interface PartImportance {\n /** The `id` of the part. */\n readonly part: string;\n /** The Birnbaum importance: the chance when the part works, minus the chance when the part fails. */\n readonly importance: number;\n}\n\n/**\n * The result of `worksChance`.\n *\n * - `exact`: `value` is the chance that the part works. `importance` has the part and each part of its paths, from the\n * largest importance. Parts with one importance are in the sequence of the stack, after the part itself. `assumed`\n * has the parts of the paths with no chance record, in the sequence of the stack: the calculation uses the chance 1\n * for each. The part itself is not in `assumed`. A part that cannot work has the value 0 and two empty lists.\n * - `budget`: the search of the paths or the calculation passed its limit, so the result has no value.\n */\nexport type WorksChance = { readonly kind: \"exact\"; readonly value: number; readonly importance: readonly PartImportance[]; readonly assumed: readonly string[] } | { readonly kind: \"budget\" };\n\n/** This function compares two texts by their code units. The language of the computer does not change the result. */\nfunction compareTexts(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\n/**\n * This function gives the chance that a part of a stack works.\n *\n * - The part works when each part of one of its path sets works, and the part itself works.\n * - Each part works or fails alone, with the chance of its record in the layer. A part with no record has the chance 1.\n * - A shared cause of failure is thus a part of the stack: a provider, an account or a power feed. Do not put it in a number.\n * - The value is exact: `pathSetReliability` of `@mark1russell7/collections/graph` counts a shared part one time.\n * - A part that does not work with the parts of `down` has the chance 0.\n * - The sequence of the parts of the stack does not change the value or an importance, to the last digit.\n *\n * The function is pure.\n *\n * @throws RangeError when a chance of a part of the paths is not from 0 to 1, or an option is not valid\n */\nexport function worksChance(layer: RiskLayer, stack: Stack, part: string, options: ChanceOptions = {}): WorksChance {\n const paths = pathSets(stack, part, options);\n if (paths.kind === \"budget\") return paths;\n if (paths.sets.length === 0) return { kind: \"exact\", value: 0, importance: [], assumed: [] };\n // The part itself is first: it is a part of each path. Then each part of the paths, in the sequence of the stack.\n const used = new Set(paths.sets.flat());\n const ids = [part, ...stack.parts.map((entry) => entry.id).filter((id, at, all) => id !== part && used.has(id) && all.indexOf(id) === at)];\n // The calculation gets the parts in one fixed order, the order of the texts of the ids.\n // Thus the sequence of the records of the stack does not change the last digits of the value.\n // The order of the path sets and of the parts of a set has no effect on the result of `pathSetReliability`.\n const fixed = [...ids].sort(compareTexts);\n const index = new Map(fixed.map((id, at) => [id, at]));\n const records = chancesByPart(layer);\n const chances = fixed.map((id) => records.get(id)?.works ?? 1);\n const sets = paths.sets.map((set) => [part, ...set].map((id) => index.get(id) ?? 0));\n const result = pathSetReliability(sets, chances, NUMBER_RING, options.maxSteps === undefined ? {} : { maxSteps: options.maxSteps });\n if (result.kind === \"budget\") return { kind: \"budget\" };\n const importance = ids.map((id) => ({ part: id, importance: result.importance[index.get(id) ?? 0] ?? 0 })).sort((a, b) => b.importance - a.importance);\n return { kind: \"exact\", value: result.value, importance, assumed: ids.filter((id) => id !== part && !records.has(id)) };\n}\n","import { dayNumber, partsById, stopSets, works, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { worksChance } from \"./chance.ts\";\nimport { firstGoals, isChance, type Accepted, type RiskLayer } from \"./layer.ts\";\n\n// The gate of the risk layer. A gate that passes tells that each goal holds: no set of parts stops a part with fewer\n// failures than its goal permits, unless a record accepts the set, and each chance is not less than its goal.\n\n/** These are the codes of the faults of a risk layer. */\nexport const RISK_CODES: readonly [\n \"goal-part\",\n \"goal-duplicate\",\n \"goal-survives\",\n \"goal-chance\",\n \"chance-part\",\n \"chance-duplicate\",\n \"chance-range\",\n \"accept-part\",\n \"accept-stop\",\n \"accept-date\",\n \"stopped\",\n \"stop-set\",\n \"accept-old\",\n \"accept-unused\",\n \"chance-none\",\n \"chance-low\",\n \"no-read\",\n] = [\n \"goal-part\",\n \"goal-duplicate\",\n \"goal-survives\",\n \"goal-chance\",\n \"chance-part\",\n \"chance-duplicate\",\n \"chance-range\",\n \"accept-part\",\n \"accept-stop\",\n \"accept-date\",\n \"stopped\",\n \"stop-set\",\n \"accept-old\",\n \"accept-unused\",\n \"chance-none\",\n \"chance-low\",\n \"no-read\",\n];\n\n/** A code of a fault of a risk layer. */\nexport type RiskCode = (typeof RISK_CODES)[number];\n\n/** A fault of a risk layer. Its field `at` is the `id` of the part of the record. */\nexport interface RiskFault extends Fault {\n readonly code: RiskCode;\n /** The parts of the fault: the stop set, or the parts with no chance record. */\n readonly parts?: readonly string[] | undefined;\n}\n\n/** The options of the gate. */\nexport interface RiskOptions {\n /** The date of the check, as `YYYY-MM-DD`. The gate has no clock: the caller gives the date. */\n readonly today: string;\n /** The largest count of sets in one step of a search. The default is the default of the core, 4096. */\n readonly maxSets?: number | undefined;\n /** The largest count of steps of the calculation of a chance. The default is 1000000. */\n readonly maxSteps?: number | undefined;\n}\n\n/** This function gives the text of a set of parts for a message, for example `[\"card\", \"push\"]`. */\nfunction setText(parts: readonly string[]): string {\n return `[${parts.map((id) => `\"${id}\"`).join(\", \")}]`;\n}\n\n/** This function gives one key for each set of parts. The sequence of the parts does not change the key. */\nfunction setKey(parts: readonly string[]): string {\n return JSON.stringify([...new Set(parts)].sort());\n}\n\n/**\n * This function gives each fault of a risk layer for a stack. An empty list tells that the gate passes.\n * The gate examines the design: each part of the stack is in operation. `goalStates` gives the state with parts that are down.\n *\n * The records:\n * - `goal-part`: a goal names no part of the stack.\n * - `goal-duplicate`: two goals name one part.\n * - `goal-survives`: the count of a goal is not a whole number from 0.\n * - `goal-chance`: the chance of a goal is not from 0 to 1.\n * - `chance-part`: a chance record names no part of the stack.\n * - `chance-duplicate`: two chance records name one part.\n * - `chance-range`: the chance of a part is not from 0 to 1.\n * - `accept-part`: an accepted risk names a part with no goal.\n * - `accept-stop`: an accepted risk names no part, or a part that is not in the stack.\n * - `accept-date`: the last date of an accepted risk is not a date.\n *\n * The goals:\n * - `stopped`: the part of a goal does not work, with each part of the stack in operation.\n * - `stop-set`: the failure of a set of parts stops a part, and the goal is to survive a set of that size. No record accepts the set.\n * - `accept-old`: the acceptance of a stop set ended before `today`.\n * - `accept-unused`: an accepted risk names a set that is no stop set of its goal. Remove the record.\n * - `chance-none`: a goal has a chance, and a part of its paths has no chance record.\n * - `chance-low`: the chance that a part works is less than the chance of its goal.\n * - `no-read`: a search passed its limit. The gate has no result for the goal, so it does not pass.\n *\n * The faults are in the sequence of the chance records, the accepted risks and the goals. The function is pure.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `maxSets` or `maxSteps` is not valid\n */\nexport function checkRisk(layer: RiskLayer, stack: Stack, options: RiskOptions): RiskFault[] {\n const today = dayNumber(options.today);\n if (today === undefined) throw new RangeError(`The date \"${options.today}\" is not a date of the form YYYY-MM-DD.`);\n const limits = { ...(options.maxSets === undefined ? {} : { maxSets: options.maxSets }), ...(options.maxSteps === undefined ? {} : { maxSteps: options.maxSteps }) };\n const faults: RiskFault[] = [];\n const add = (code: RiskCode, at: string, message: string, more: { readonly other?: string; readonly parts?: readonly string[] } = {}): void => {\n faults.push({ level: \"error\", code, at, message, ...more });\n };\n const parts = partsById(stack);\n\n const chanceParts = new Set<string>();\n let chancesValid = true;\n for (const chance of layer.chances ?? []) {\n const at = chance.part;\n if (chanceParts.has(at)) {\n add(\"chance-duplicate\", at, `Two chance records name the part \"${at}\".`);\n continue;\n }\n chanceParts.add(at);\n if (!parts.has(at)) add(\"chance-part\", at, `A chance record names \"${at}\", which is no part of the stack.`);\n if (!isChance(chance.works)) {\n add(\"chance-range\", at, `The chance ${String(chance.works)} of \"${at}\" is not from 0 to 1.`);\n chancesValid = false;\n }\n }\n\n const goals = new Map(firstGoals(layer).map((goal) => [goal.part, goal]));\n // Each accepted risk with a correct form, with the key of its set. `used` tells that the set is a stop set of its goal.\n const accepted: { readonly record: Accepted; readonly key: string; readonly ended: boolean; used: boolean }[] = [];\n for (const record of layer.accepted ?? []) {\n const at = record.part;\n let valid = true;\n if (!goals.has(at)) {\n add(\"accept-part\", at, `An accepted risk names \"${at}\", which has no goal.`);\n valid = false;\n }\n if (record.stop.length === 0) {\n add(\"accept-stop\", at, `An accepted risk of \"${at}\" names no part.`);\n valid = false;\n }\n for (const id of record.stop) {\n if (parts.has(id)) continue;\n add(\"accept-stop\", at, `An accepted risk of \"${at}\" names \"${id}\", which is no part of the stack.`, { other: id });\n valid = false;\n }\n const last = record.until === undefined ? undefined : dayNumber(record.until);\n if (record.until !== undefined && last === undefined) {\n add(\"accept-date\", at, `The date \"${record.until}\" of an accepted risk of \"${at}\" is not a date of the form YYYY-MM-DD.`);\n valid = false;\n }\n if (valid) accepted.push({ record, key: setKey(record.stop), ended: last !== undefined && last < today, used: false });\n }\n\n // The goals whose stop sets the gate read. An accepted risk of a different goal gets no examination.\n const read = new Set<string>();\n const seen = new Set<string>();\n for (const goal of layer.goals) {\n const at = goal.part;\n if (seen.has(at)) {\n add(\"goal-duplicate\", at, `Two goals name the part \"${at}\".`);\n continue;\n }\n seen.add(at);\n if (!parts.has(at)) {\n add(\"goal-part\", at, `A goal names \"${at}\", which is no part of the stack.`);\n continue;\n }\n const counted = Number.isInteger(goal.survives) && goal.survives >= 0;\n if (!counted) add(\"goal-survives\", at, `The count ${String(goal.survives)} of the goal of \"${at}\" is not a whole number from 0.`);\n if (goal.chance !== undefined && !isChance(goal.chance)) add(\"goal-chance\", at, `The chance ${String(goal.chance)} of the goal of \"${at}\" is not from 0 to 1.`);\n if (!works(stack, at)) {\n add(\"stopped\", at, `The part \"${at}\" does not work, with each part of the stack in operation: one of its needs does not hold.`);\n continue;\n }\n if (counted) {\n const stops = stopSets(stack, at, { ...limits, size: goal.survives });\n if (stops.kind === \"budget\") add(\"no-read\", at, `The search of the stop sets of \"${at}\" passed its limit. The gate has no result for this goal.`);\n else {\n read.add(at);\n for (const set of stops.sets) {\n const key = setKey(set);\n const records = accepted.filter((entry) => entry.record.part === at && entry.key === key);\n for (const entry of records) entry.used = true;\n if (records.some((entry) => !entry.ended)) continue;\n const old = records[0];\n if (old === undefined) {\n add(\"stop-set\", at, `The failure of the set ${setText(set)} stops \"${at}\". The goal of \"${at}\" is to survive each set of ${String(goal.survives)} or fewer parts.`, { parts: set });\n } else {\n add(\"accept-old\", at, `The acceptance of the stop set ${setText(set)} of \"${at}\" ended on ${old.record.until ?? \"\"}. The failure of the set stops \"${at}\".`, { parts: set });\n }\n }\n }\n }\n if (goal.chance === undefined || !isChance(goal.chance) || !chancesValid) continue;\n const chance = worksChance(layer, stack, at, limits);\n if (chance.kind === \"budget\") add(\"no-read\", at, `The calculation of the chance of \"${at}\" passed its limit. The gate has no result for this goal.`);\n else if (chance.assumed.length > 0) {\n add(\"chance-none\", at, `The goal of \"${at}\" has a chance, and these parts of its paths have no chance record: ${setText(chance.assumed)}.`, { parts: chance.assumed });\n } else if (chance.value < goal.chance) {\n add(\"chance-low\", at, `The chance that \"${at}\" works is ${String(chance.value)}. The goal is ${String(goal.chance)}.`);\n }\n }\n\n for (const entry of accepted) {\n const at = entry.record.part;\n if (entry.used || !read.has(at)) continue;\n const survives = goals.get(at)?.survives ?? 0;\n add(\"accept-unused\", at, `An accepted risk of \"${at}\" names the set ${setText(entry.record.stop)}. It is no stop set of \"${at}\" of ${String(survives)} or fewer parts.`, { parts: entry.record.stop });\n }\n return faults;\n}\n","import { joinRecords, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { RISK_SCHEMA, type RiskLayer } from \"./layer.ts\";\n\n// The join of the risk layers of the fragments of a stack, for example one file of goals for each owner.\n\n/**\n * This function joins the risk layers of the fragments of a stack into one layer.\n *\n * - The goals and the chance records are in the order of the fragments. The record of a part is in one fragment.\n * - A part with a goal in two or more fragments is a fault, also when the goals are equal.\n * - A part with a chance record in two or more fragments is a fault, also when the records are equal.\n * - The accepted risks are in the order of the fragments. A fragment can accept a risk of a goal of a different fragment.\n *\n * The joined layer has the field `chances` or `accepted` when a fragment has it. The function is pure, and it\n * changes no layer. The gate `checkRisk` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinRisk(pieces: readonly LayerPiece<RiskLayer>[]): LayerParse<RiskLayer> {\n const goals = joinRecords(\n pieces,\n (layer) => layer.goals,\n (goal) => goal.part,\n \"goal of the part\",\n );\n const chances = joinRecords(\n pieces,\n (layer) => layer.chances,\n (chance) => chance.part,\n \"chance record of the part\",\n );\n const errors = [...goals.errors, ...chances.errors];\n if (errors.length > 0) return { ok: false, errors };\n const withChances = pieces.some((piece) => piece.layer.chances !== undefined);\n const withAccepted = pieces.some((piece) => piece.layer.accepted !== undefined);\n return {\n ok: true,\n layer: {\n schema: RISK_SCHEMA,\n goals: goals.items,\n ...(withChances ? { chances: chances.items } : {}),\n ...(withAccepted ? { accepted: pieces.flatMap((piece) => piece.layer.accepted ?? []) } : {}),\n },\n };\n}\n"],"mappings":";;;;;AAgCA,SAAS,aAAa,GAAW,GAAmB;CAClD,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;;;;;;;;;;;;;;;AAgBA,SAAgB,YAAY,OAAkB,OAAc,MAAc,UAAyB,CAAC,GAAgB;CAClH,MAAM,QAAQ,SAAS,OAAO,MAAM,OAAO;CAC3C,IAAI,MAAM,SAAS,UAAU,OAAO;CACpC,IAAI,MAAM,KAAK,WAAW,GAAG,OAAO;EAAE,MAAM;EAAS,OAAO;EAAG,YAAY,CAAC;EAAG,SAAS,CAAC;CAAE;CAE3F,MAAM,OAAO,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC;CACtC,MAAM,MAAM,CAAC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;CAC9E,OAAO;EACL,IAAI;EACJ,OAAO;GACL,QAAQ;GACR,OAAO,MAAM;GACb,GAAI,cAAc,EAAE,SAAS,QAAQ,MAAM,IAAI,CAAC;GAChD,GAAI,eAAe,EAAE,UAAU,OAAO,SAAS,UAAU,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC;EAC5F;CACF;AACF"}
@@ -1,25 +0,0 @@
1
- // src/layer.ts
2
- /** The name of the format of a risk layer. It is the key of the layer in `Stack.layers`. */
3
- const RISK_SCHEMA = "risk/1";
4
- /** This function gives the first goal of each part of a layer, in the sequence of the records. */
5
- function firstGoals(layer) {
6
- const seen = /* @__PURE__ */ new Set();
7
- return layer.goals.filter((goal) => {
8
- if (seen.has(goal.part)) return false;
9
- seen.add(goal.part);
10
- return true;
11
- });
12
- }
13
- /** This function gives the chance record of each part of a layer, by the `id` of the part. The first record of a part is used. */
14
- function chancesByPart(layer) {
15
- const chances = /* @__PURE__ */ new Map();
16
- for (const chance of layer.chances ?? []) if (!chances.has(chance.part)) chances.set(chance.part, chance);
17
- return chances;
18
- }
19
- /** This function tells if a value is a chance: a number from 0 to 1. */
20
- function isChance(value) {
21
- return value >= 0 && value <= 1;
22
- }
23
- export { isChance as i, chancesByPart as n, firstGoals as r, RISK_SCHEMA as t };
24
-
25
- //# sourceMappingURL=layer-BLQnPkuy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layer-BLQnPkuy.js","names":[],"sources":["../src/layer.ts"],"sourcesContent":["// The records of the risk add-on. They are one layer of a stack, with the key `risk/1` in `Stack.layers`.\n// A goal tells how many failures a part must survive. The answers are queries over the stack: the layer keeps no list of risks.\n\n/** The name of the format of a risk layer. It is the key of the layer in `Stack.layers`. */\nexport const RISK_SCHEMA = \"risk/1\";\n\n/** The goal of one part of the stack, for example of a function of the system. */\nexport interface Goal {\n /** The `id` of the part with the goal. */\n readonly part: string;\n /**\n * The count of failures of other parts that the part survives. It is a whole number from 0.\n * With 1, no failure of one part stops the part: it has no single point of failure.\n */\n readonly survives: number;\n /** The smallest chance that the part works, from 0 to 1. The gate then needs the chance of each part of its paths. */\n readonly chance?: number | undefined;\n}\n\n/** The chance that one part works. */\nexport interface Chance {\n /** The `id` of the part. */\n readonly part: string;\n /** The chance that the part works at a moment, from 0 to 1, when each of its needs holds. */\n readonly works: number;\n /** The source of the number, for example the service agreement of a provider or a measured period. */\n readonly source?: string | undefined;\n}\n\n/** An accepted risk: one set of parts whose failure stops a part, which the owner accepts for a reason. */\nexport interface Accepted {\n /** The `id` of the part with the goal. */\n readonly part: string;\n /** The parts of the set, in any sequence. Their failure together stops the part. */\n readonly stop: readonly string[];\n /** The reason of the owner. */\n readonly reason: string;\n /** The last date of the acceptance, as `YYYY-MM-DD`. After that date the gate fails for the set. An acceptance without it has no end. */\n readonly until?: string | undefined;\n}\n\n/** A risk layer: the goals of the parts of a stack, the chance of each part, and the accepted risks. */\nexport interface RiskLayer {\n readonly schema: typeof RISK_SCHEMA;\n readonly goals: readonly Goal[];\n readonly chances?: readonly Chance[] | undefined;\n readonly accepted?: readonly Accepted[] | undefined;\n}\n\n/** This function gives the first goal of each part of a layer, in the sequence of the records. */\nexport function firstGoals(layer: RiskLayer): readonly Goal[] {\n const seen = new Set<string>();\n return layer.goals.filter((goal) => {\n if (seen.has(goal.part)) return false;\n seen.add(goal.part);\n return true;\n });\n}\n\n/** This function gives the chance record of each part of a layer, by the `id` of the part. The first record of a part is used. */\nexport function chancesByPart(layer: RiskLayer): Map<string, Chance> {\n const chances = new Map<string, Chance>();\n for (const chance of layer.chances ?? []) if (!chances.has(chance.part)) chances.set(chance.part, chance);\n return chances;\n}\n\n/** This function tells if a value is a chance: a number from 0 to 1. */\nexport function isChance(value: number): boolean {\n return value >= 0 && value <= 1;\n}\n"],"mappings":";;AAIA,MAAa,cAAc;;AA8C3B,SAAgB,WAAW,OAAmC;CAC5D,MAAM,uBAAO,IAAI,IAAY;CAC7B,OAAO,MAAM,MAAM,QAAQ,SAAS;EAClC,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,OAAO;EAChC,KAAK,IAAI,KAAK,IAAI;EAClB,OAAO;CACT,CAAC;AACH;;AAGA,SAAgB,cAAc,OAAuC;CACnE,MAAM,0BAAU,IAAI,IAAoB;CACxC,KAAK,MAAM,UAAU,MAAM,WAAW,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,IAAI,GAAG,QAAQ,IAAI,OAAO,MAAM,MAAM;CACxG,OAAO;AACT;;AAGA,SAAgB,SAAS,OAAwB;CAC/C,OAAO,SAAS,KAAK,SAAS;AAChC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"layer-zvH_ueL5.d.ts","names":[],"sources":["../src/layer.ts"],"mappings":";cAIa;;UAGI;;WAEN;;;;;WAKA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;;UAIM;WACN,eAAe;WACf,gBAAgB;WAChB,mBAAmB;WACnB,oBAAoB;;;iBAIf,WAAW,OAAO,qBAAqB;;iBAUvC,cAAc,OAAO,YAAY,YAAY;;iBAO7C,SAAS"}