@mark1russell7/stack-endurance 0.0.0-bootstrap.0 → 0.3.1
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/LICENSE +21 -0
- package/README.md +86 -1
- package/build/add-on.d.ts +12 -0
- package/build/add-on.d.ts.map +1 -0
- package/build/add-on.js +23 -0
- package/build/add-on.js.map +1 -0
- package/build/index.d.ts +258 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +529 -0
- package/build/index.js.map +1 -0
- package/build/join-D7KyUpGf.js +557 -0
- package/build/join-D7KyUpGf.js.map +1 -0
- package/build/layer-DzGZC5XH.d.ts +143 -0
- package/build/layer-DzGZC5XH.d.ts.map +1 -0
- package/build/layer-a3Fr70Uh.js +6 -0
- package/build/layer-a3Fr70Uh.js.map +1 -0
- package/build/schema.d.ts +21 -0
- package/build/schema.d.ts.map +1 -0
- package/build/schema.js +99 -0
- package/build/schema.js.map +1 -0
- package/package.json +71 -6
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/** The name of the format of an endurance layer. It is the key of the layer in `Stack.layers`. */
|
|
2
|
+
declare const ENDURANCE_SCHEMA = "endurance/1";
|
|
3
|
+
/** A date as `YYYY-MM-DD`. */
|
|
4
|
+
type IsoDate = string;
|
|
5
|
+
/** A resource of a store, with its unit, for example `L`, `kg` or `Wh`. */
|
|
6
|
+
interface Resource {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly unit: string;
|
|
9
|
+
}
|
|
10
|
+
/** A store: an amount of one resource. */
|
|
11
|
+
interface Store {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/** The `code` of the resource. */
|
|
14
|
+
readonly resource: string;
|
|
15
|
+
/** The amount, in the unit of the resource. */
|
|
16
|
+
readonly amount: number;
|
|
17
|
+
/** The due date. On this date and after it, the store gives nothing. A store with no due date does not expire. */
|
|
18
|
+
readonly due?: IsoDate | undefined;
|
|
19
|
+
/** The `id` of the part of the stack that holds the store. When the part stops, the store gives nothing. */
|
|
20
|
+
readonly part?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A draw: a need that a load takes each day from its supply.
|
|
24
|
+
* Examples are the power of a rack and the drinking water of a building.
|
|
25
|
+
* When the supply part stops, the draw takes the need from the stores.
|
|
26
|
+
*/
|
|
27
|
+
interface Draw {
|
|
28
|
+
/** The code of the need. One draw has each code. */
|
|
29
|
+
readonly need: string;
|
|
30
|
+
/** The level of the draw. It is one of the `levels` of the layer. */
|
|
31
|
+
readonly level: string;
|
|
32
|
+
/** The amount of the need for each day. */
|
|
33
|
+
readonly perDay: number;
|
|
34
|
+
/** The count of the users of the draw, for example the persons or the machines. The shortfall counts each user. The default is 1. */
|
|
35
|
+
readonly users?: number | undefined;
|
|
36
|
+
/** The `id` of the part of the stack that supplies the need when no case stops it. */
|
|
37
|
+
readonly supply: string;
|
|
38
|
+
}
|
|
39
|
+
/** The direct use of a resource for a need: 1 unit of the resource gives `amount` of the need. */
|
|
40
|
+
interface DirectUse {
|
|
41
|
+
readonly resource: string;
|
|
42
|
+
readonly need: string;
|
|
43
|
+
readonly amount: number;
|
|
44
|
+
}
|
|
45
|
+
/** The gift of one run of a converter: an amount of a need, or an amount of a resource, in its unit. */
|
|
46
|
+
type Gift = {
|
|
47
|
+
readonly need: string;
|
|
48
|
+
readonly resource?: never;
|
|
49
|
+
readonly amount: number;
|
|
50
|
+
} | {
|
|
51
|
+
readonly resource: string;
|
|
52
|
+
readonly need?: never;
|
|
53
|
+
readonly amount: number;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A converter: a device or an action that changes resources into a need or into a resource.
|
|
57
|
+
* Example: a stove cooks 1 kg of dry rice with 2 L of water and 0.05 kg of fuel, and gives 3600 kcal.
|
|
58
|
+
* Example: a generator changes 1 L of fuel into 3000 Wh of the battery. Then a direct use of the battery can take that energy.
|
|
59
|
+
*/
|
|
60
|
+
interface Converter {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
/** The `id` of the device in the stack. The converter stops when the device stops. */
|
|
63
|
+
readonly device?: string | undefined;
|
|
64
|
+
/** The resources that one run takes. */
|
|
65
|
+
readonly takes: readonly {
|
|
66
|
+
readonly resource: string;
|
|
67
|
+
readonly amount: number;
|
|
68
|
+
}[];
|
|
69
|
+
/** The need or the resource that one run gives, and its amount. A chain of converters cannot make a resource from itself. */
|
|
70
|
+
readonly gives: Gift;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The chance that a cut lasts more than a time: a list of points `[days, chance]`, from `[0, 1]` down to a chance of 0.
|
|
74
|
+
* The days increase, and the chance does not increase. Between two points the chance is linear. This is a survival curve.
|
|
75
|
+
*/
|
|
76
|
+
type Survival = readonly (readonly [days: number, chance: number])[];
|
|
77
|
+
/** A cut of a case: a part that the case stops, and the curve of the duration of the stop. */
|
|
78
|
+
interface Cut {
|
|
79
|
+
/** The `id` of the part of the stack. */
|
|
80
|
+
readonly part: string;
|
|
81
|
+
/** The printed name of the cut, for example "Power outage". */
|
|
82
|
+
readonly title: string;
|
|
83
|
+
readonly duration: Survival;
|
|
84
|
+
/** The source of the curve. */
|
|
85
|
+
readonly source: string;
|
|
86
|
+
}
|
|
87
|
+
/** A case: an event that cuts some parts at the same time, and the change that it makes to the draws. */
|
|
88
|
+
interface CaseCuts {
|
|
89
|
+
/** The code of the case. */
|
|
90
|
+
readonly case: string;
|
|
91
|
+
/** The printed name of the case, for example "Winter storm". */
|
|
92
|
+
readonly title: string;
|
|
93
|
+
readonly cuts: readonly Cut[];
|
|
94
|
+
/** A factor on the amount of a need for each day, by the code of the need. Example: 1.5 for water in a heat wave. The default is 1. */
|
|
95
|
+
readonly factors?: Readonly<Record<string, number>> | undefined;
|
|
96
|
+
/** The usual time from the warning to the start, in seconds. A case with no warning has no lead time. */
|
|
97
|
+
readonly leadSeconds?: number | undefined;
|
|
98
|
+
}
|
|
99
|
+
/** The yearly prior of one case at one place. */
|
|
100
|
+
interface Prior {
|
|
101
|
+
readonly case: string;
|
|
102
|
+
readonly place: string;
|
|
103
|
+
/** The events in one year in the area (`lambda`), 0 or more. */
|
|
104
|
+
readonly perYear: number;
|
|
105
|
+
/** The share of the events of the area that reach the place (`q`), from 0 to 1. */
|
|
106
|
+
readonly reach: number;
|
|
107
|
+
readonly source: string;
|
|
108
|
+
/** The date of the data of the source. */
|
|
109
|
+
readonly asOf: IsoDate;
|
|
110
|
+
}
|
|
111
|
+
/** The days that one draw holds, and the resources that are used up at that time. */
|
|
112
|
+
interface DrawEndurance {
|
|
113
|
+
readonly days: number;
|
|
114
|
+
/**
|
|
115
|
+
* The inputs of the draw that are used up at `days`, through each chain of converters, in the order of their codes. A higher draw can use up an input first.
|
|
116
|
+
* A resource that only converters make, with no store of the layer, is not in the list.
|
|
117
|
+
*/
|
|
118
|
+
readonly binding: readonly string[];
|
|
119
|
+
/** The amount of each resource that the draw takes in its days, by the code of the resource. A resource with no take is not in the record. */
|
|
120
|
+
readonly takes: Readonly<Record<string, number>>;
|
|
121
|
+
}
|
|
122
|
+
/** The days that each draw holds when a case stops its supply. A draw whose supply works is not in `needs`. */
|
|
123
|
+
interface Endurance {
|
|
124
|
+
readonly case: string;
|
|
125
|
+
readonly at: IsoDate;
|
|
126
|
+
/** The result of each draw, by the code of its need. */
|
|
127
|
+
readonly needs: Readonly<Record<string, DrawEndurance>>;
|
|
128
|
+
}
|
|
129
|
+
/** An endurance layer: the levels, the resources, the stores, the draws, the uses and the converters, the cases and their priors. */
|
|
130
|
+
interface EnduranceLayer {
|
|
131
|
+
readonly schema: typeof ENDURANCE_SCHEMA;
|
|
132
|
+
/** The levels of the draws, the most important first, for example `["critical", "normal"]`. A higher level takes the resources first. */
|
|
133
|
+
readonly levels: readonly string[];
|
|
134
|
+
readonly resources: readonly Resource[];
|
|
135
|
+
readonly stores: readonly Store[];
|
|
136
|
+
readonly draws: readonly Draw[];
|
|
137
|
+
readonly direct?: readonly DirectUse[] | undefined;
|
|
138
|
+
readonly converters?: readonly Converter[] | undefined;
|
|
139
|
+
readonly cases?: readonly CaseCuts[] | undefined;
|
|
140
|
+
readonly priors?: readonly Prior[] | undefined;
|
|
141
|
+
}
|
|
142
|
+
export { Draw as a, Endurance as c, IsoDate as d, Prior as f, Survival as h, DirectUse as i, EnduranceLayer as l, Store as m, Converter as n, DrawEndurance as o, Resource as p, Cut as r, ENDURANCE_SCHEMA as s, CaseCuts as t, Gift as u };
|
|
143
|
+
//# sourceMappingURL=layer-DzGZC5XH.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-DzGZC5XH.d.ts","names":[],"sources":["../src/layer.ts"],"mappings":";cAMa;;KAGD;;UAGK;WACN;WACA;;;UAIM;WACN;;WAEA;;WAEA;;WAEA,MAAM;;WAEN;;;;;;;UAQM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;WACN;WACA;WACA;;;KAIC;WAAkB;WAAuB;WAA2B;;WAA8B;WAA2B;WAAuB;;;;;;;UAO/I;WACN;;WAEA;;WAEA;aAA2B;aAA2B;;;WAEtD,OAAO;;;;;;KAON,+BAA+B,cAAc;;UAGxC;;WAEN;;WAEA;WACA,UAAU;;WAEV;;;UAIM;;WAEN;;WAEA;WACA,eAAe;;WAEf,UAAU,SAAS;;WAEnB;;;UAIM;WACN;WACA;;WAEA;;WAEA;WACA;;WAEA,MAAM;;;UAIA;WACN;;;;;WAKA;;WAEA,OAAO,SAAS;;;UAIV;WACN;WACA,IAAI;;WAEJ,OAAO,SAAS,eAAe;;;UAIzB;WACN,eAAe;;WAEf;WACA,oBAAoB;WACpB,iBAAiB;WACjB,gBAAgB;WAChB,kBAAkB;WAClB,sBAAsB;WACtB,iBAAiB;WACjB,kBAAkB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-a3Fr70Uh.js","names":[],"sources":["../src/layer.ts"],"sourcesContent":["// The records of the endurance add-on. They are one layer of a stack, with the key `endurance/1` in `Stack.layers`.\n// A store holds an amount of a resource. A draw takes a need each day. A converter changes resources into a need.\n// A case cuts some parts for a time. The queries give the days that each draw holds, and the days that it does not get its need.\n// The add-on names no topic: the resources, the needs and the levels are data. The unit of time is the day.\n\n/** The name of the format of an endurance layer. It is the key of the layer in `Stack.layers`. */\nexport const ENDURANCE_SCHEMA = \"endurance/1\";\n\n/** A date as `YYYY-MM-DD`. */\nexport type IsoDate = string;\n\n/** A resource of a store, with its unit, for example `L`, `kg` or `Wh`. */\nexport interface Resource {\n readonly code: string;\n readonly unit: string;\n}\n\n/** A store: an amount of one resource. */\nexport interface Store {\n readonly id: string;\n /** The `code` of the resource. */\n readonly resource: string;\n /** The amount, in the unit of the resource. */\n readonly amount: number;\n /** The due date. On this date and after it, the store gives nothing. A store with no due date does not expire. */\n readonly due?: IsoDate | undefined;\n /** The `id` of the part of the stack that holds the store. When the part stops, the store gives nothing. */\n readonly part?: string | undefined;\n}\n\n/**\n * A draw: a need that a load takes each day from its supply.\n * Examples are the power of a rack and the drinking water of a building.\n * When the supply part stops, the draw takes the need from the stores.\n */\nexport interface Draw {\n /** The code of the need. One draw has each code. */\n readonly need: string;\n /** The level of the draw. It is one of the `levels` of the layer. */\n readonly level: string;\n /** The amount of the need for each day. */\n readonly perDay: number;\n /** The count of the users of the draw, for example the persons or the machines. The shortfall counts each user. The default is 1. */\n readonly users?: number | undefined;\n /** The `id` of the part of the stack that supplies the need when no case stops it. */\n readonly supply: string;\n}\n\n/** The direct use of a resource for a need: 1 unit of the resource gives `amount` of the need. */\nexport interface DirectUse {\n readonly resource: string;\n readonly need: string;\n readonly amount: number;\n}\n\n/** The gift of one run of a converter: an amount of a need, or an amount of a resource, in its unit. */\nexport type Gift = { readonly need: string; readonly resource?: never; readonly amount: number } | { readonly resource: string; readonly need?: never; readonly amount: number };\n\n/**\n * A converter: a device or an action that changes resources into a need or into a resource.\n * Example: a stove cooks 1 kg of dry rice with 2 L of water and 0.05 kg of fuel, and gives 3600 kcal.\n * Example: a generator changes 1 L of fuel into 3000 Wh of the battery. Then a direct use of the battery can take that energy.\n */\nexport interface Converter {\n readonly id: string;\n /** The `id` of the device in the stack. The converter stops when the device stops. */\n readonly device?: string | undefined;\n /** The resources that one run takes. */\n readonly takes: readonly { readonly resource: string; readonly amount: number }[];\n /** The need or the resource that one run gives, and its amount. A chain of converters cannot make a resource from itself. */\n readonly gives: Gift;\n}\n\n/**\n * The chance that a cut lasts more than a time: a list of points `[days, chance]`, from `[0, 1]` down to a chance of 0.\n * The days increase, and the chance does not increase. Between two points the chance is linear. This is a survival curve.\n */\nexport type Survival = readonly (readonly [days: number, chance: number])[];\n\n/** A cut of a case: a part that the case stops, and the curve of the duration of the stop. */\nexport interface Cut {\n /** The `id` of the part of the stack. */\n readonly part: string;\n /** The printed name of the cut, for example \"Power outage\". */\n readonly title: string;\n readonly duration: Survival;\n /** The source of the curve. */\n readonly source: string;\n}\n\n/** A case: an event that cuts some parts at the same time, and the change that it makes to the draws. */\nexport interface CaseCuts {\n /** The code of the case. */\n readonly case: string;\n /** The printed name of the case, for example \"Winter storm\". */\n readonly title: string;\n readonly cuts: readonly Cut[];\n /** A factor on the amount of a need for each day, by the code of the need. Example: 1.5 for water in a heat wave. The default is 1. */\n readonly factors?: Readonly<Record<string, number>> | undefined;\n /** The usual time from the warning to the start, in seconds. A case with no warning has no lead time. */\n readonly leadSeconds?: number | undefined;\n}\n\n/** The yearly prior of one case at one place. */\nexport interface Prior {\n readonly case: string;\n readonly place: string;\n /** The events in one year in the area (`lambda`), 0 or more. */\n readonly perYear: number;\n /** The share of the events of the area that reach the place (`q`), from 0 to 1. */\n readonly reach: number;\n readonly source: string;\n /** The date of the data of the source. */\n readonly asOf: IsoDate;\n}\n\n/** The days that one draw holds, and the resources that are used up at that time. */\nexport interface DrawEndurance {\n readonly days: number;\n /**\n * The inputs of the draw that are used up at `days`, through each chain of converters, in the order of their codes. A higher draw can use up an input first.\n * A resource that only converters make, with no store of the layer, is not in the list.\n */\n readonly binding: readonly string[];\n /** The amount of each resource that the draw takes in its days, by the code of the resource. A resource with no take is not in the record. */\n readonly takes: Readonly<Record<string, number>>;\n}\n\n/** The days that each draw holds when a case stops its supply. A draw whose supply works is not in `needs`. */\nexport interface Endurance {\n readonly case: string;\n readonly at: IsoDate;\n /** The result of each draw, by the code of its need. */\n readonly needs: Readonly<Record<string, DrawEndurance>>;\n}\n\n/** An endurance layer: the levels, the resources, the stores, the draws, the uses and the converters, the cases and their priors. */\nexport interface EnduranceLayer {\n readonly schema: typeof ENDURANCE_SCHEMA;\n /** The levels of the draws, the most important first, for example `[\"critical\", \"normal\"]`. A higher level takes the resources first. */\n readonly levels: readonly string[];\n readonly resources: readonly Resource[];\n readonly stores: readonly Store[];\n readonly draws: readonly Draw[];\n readonly direct?: readonly DirectUse[] | undefined;\n readonly converters?: readonly Converter[] | undefined;\n readonly cases?: readonly CaseCuts[] | undefined;\n readonly priors?: readonly Prior[] | undefined;\n}\n"],"mappings":";;AAMA,MAAa,mBAAmB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { l as EnduranceLayer } from "./layer-DzGZC5XH.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* The schema of an endurance layer. It examines the form of the record: the fields and their types.
|
|
5
|
+
* It refuses a field that the format does not have. `checkEndurance` examines the meaning of a layer with a correct form.
|
|
6
|
+
*/
|
|
7
|
+
export declare const enduranceSchema: z.ZodType<EnduranceLayer>;
|
|
8
|
+
/** The result of the read of an endurance layer: the layer, or the faults of its form. */
|
|
9
|
+
export type EnduranceParse = {
|
|
10
|
+
readonly ok: true;
|
|
11
|
+
readonly layer: EnduranceLayer;
|
|
12
|
+
} | {
|
|
13
|
+
readonly ok: false;
|
|
14
|
+
readonly errors: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* This function reads the JSON of an endurance layer. It gives the layer, or the faults of its form.
|
|
18
|
+
* Each fault names its place in the record, for example `stores.0.amount`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseEndurance(input: unknown): EnduranceParse;
|
|
21
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;qBAmEa,iBAAiB,EAAE,QAAQ;;YAa5B;WAA4B;WAAmB,OAAO;;WAA8B;WAAoB;;;;;;wBAMpG,eAAe,iBAAiB"}
|
package/build/schema.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
|
+
import { formErrors } from "@mark1russell7/system-stack/schema";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// src/schema.ts
|
|
5
|
+
const id = z.string().min(1);
|
|
6
|
+
const amount = z.number();
|
|
7
|
+
const resource = z.strictObject({
|
|
8
|
+
code: id,
|
|
9
|
+
unit: id
|
|
10
|
+
});
|
|
11
|
+
const store = z.strictObject({
|
|
12
|
+
id,
|
|
13
|
+
resource: id,
|
|
14
|
+
amount,
|
|
15
|
+
due: id.optional(),
|
|
16
|
+
part: id.optional()
|
|
17
|
+
});
|
|
18
|
+
const draw = z.strictObject({
|
|
19
|
+
need: id,
|
|
20
|
+
level: id,
|
|
21
|
+
perDay: amount,
|
|
22
|
+
users: amount.optional(),
|
|
23
|
+
supply: id
|
|
24
|
+
});
|
|
25
|
+
const directUse = z.strictObject({
|
|
26
|
+
resource: id,
|
|
27
|
+
need: id,
|
|
28
|
+
amount
|
|
29
|
+
});
|
|
30
|
+
const converter = z.strictObject({
|
|
31
|
+
id,
|
|
32
|
+
device: id.optional(),
|
|
33
|
+
takes: z.array(z.strictObject({
|
|
34
|
+
resource: id,
|
|
35
|
+
amount
|
|
36
|
+
})).readonly(),
|
|
37
|
+
gives: z.union([z.strictObject({
|
|
38
|
+
need: id,
|
|
39
|
+
amount
|
|
40
|
+
}), z.strictObject({
|
|
41
|
+
resource: id,
|
|
42
|
+
amount
|
|
43
|
+
})])
|
|
44
|
+
});
|
|
45
|
+
const point = z.tuple([z.number(), z.number()]).readonly();
|
|
46
|
+
const cut = z.strictObject({
|
|
47
|
+
part: id,
|
|
48
|
+
title: id,
|
|
49
|
+
duration: z.array(point).readonly(),
|
|
50
|
+
source: id
|
|
51
|
+
});
|
|
52
|
+
const caseCuts = z.strictObject({
|
|
53
|
+
case: id,
|
|
54
|
+
title: id,
|
|
55
|
+
cuts: z.array(cut).readonly(),
|
|
56
|
+
factors: z.record(z.string(), amount).optional(),
|
|
57
|
+
leadSeconds: amount.optional()
|
|
58
|
+
});
|
|
59
|
+
const prior = z.strictObject({
|
|
60
|
+
case: id,
|
|
61
|
+
place: id,
|
|
62
|
+
perYear: amount,
|
|
63
|
+
reach: amount,
|
|
64
|
+
source: id,
|
|
65
|
+
asOf: id
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* The schema of an endurance layer. It examines the form of the record: the fields and their types.
|
|
69
|
+
* It refuses a field that the format does not have. `checkEndurance` examines the meaning of a layer with a correct form.
|
|
70
|
+
*/
|
|
71
|
+
const enduranceSchema = z.strictObject({
|
|
72
|
+
schema: z.literal(ENDURANCE_SCHEMA),
|
|
73
|
+
levels: z.array(id).readonly(),
|
|
74
|
+
resources: z.array(resource).readonly(),
|
|
75
|
+
stores: z.array(store).readonly(),
|
|
76
|
+
draws: z.array(draw).readonly(),
|
|
77
|
+
direct: z.array(directUse).readonly().optional(),
|
|
78
|
+
converters: z.array(converter).readonly().optional(),
|
|
79
|
+
cases: z.array(caseCuts).readonly().optional(),
|
|
80
|
+
priors: z.array(prior).readonly().optional()
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* This function reads the JSON of an endurance layer. It gives the layer, or the faults of its form.
|
|
84
|
+
* Each fault names its place in the record, for example `stores.0.amount`.
|
|
85
|
+
*/
|
|
86
|
+
function parseEndurance(input) {
|
|
87
|
+
const read = enduranceSchema.safeParse(input);
|
|
88
|
+
if (read.success) return {
|
|
89
|
+
ok: true,
|
|
90
|
+
layer: read.data
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
errors: formErrors(ENDURANCE_SCHEMA, read.error.issues)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export { enduranceSchema, parseEndurance };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +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 { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The zod schema of an endurance 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 host that only calculates gets no schema library.\n\nconst id = z.string().min(1);\nconst amount = z.number();\n\nconst resource = z.strictObject({ code: id, unit: id });\n\nconst store = z.strictObject({\n id,\n resource: id,\n amount,\n due: id.optional(),\n part: id.optional(),\n});\n\nconst draw = z.strictObject({\n need: id,\n level: id,\n perDay: amount,\n users: amount.optional(),\n supply: id,\n});\n\nconst directUse = z.strictObject({ resource: id, need: id, amount });\n\nconst converter = z.strictObject({\n id,\n device: id.optional(),\n takes: z.array(z.strictObject({ resource: id, amount })).readonly(),\n gives: z.union([z.strictObject({ need: id, amount }), z.strictObject({ resource: id, amount })]),\n});\n\nconst point = z.tuple([z.number(), z.number()]).readonly();\n\nconst cut = z.strictObject({\n part: id,\n title: id,\n duration: z.array(point).readonly(),\n source: id,\n});\n\nconst caseCuts = z.strictObject({\n case: id,\n title: id,\n cuts: z.array(cut).readonly(),\n factors: z.record(z.string(), amount).optional(),\n leadSeconds: amount.optional(),\n});\n\nconst prior = z.strictObject({\n case: id,\n place: id,\n perYear: amount,\n reach: amount,\n source: id,\n asOf: id,\n});\n\n/**\n * The schema of an endurance layer. It examines the form of the record: the fields and their types.\n * It refuses a field that the format does not have. `checkEndurance` examines the meaning of a layer with a correct form.\n */\nexport const enduranceSchema: z.ZodType<EnduranceLayer> = z.strictObject({\n schema: z.literal(ENDURANCE_SCHEMA),\n levels: z.array(id).readonly(),\n resources: z.array(resource).readonly(),\n stores: z.array(store).readonly(),\n draws: z.array(draw).readonly(),\n direct: z.array(directUse).readonly().optional(),\n converters: z.array(converter).readonly().optional(),\n cases: z.array(caseCuts).readonly().optional(),\n priors: z.array(prior).readonly().optional(),\n});\n\n/** The result of the read of an endurance layer: the layer, or the faults of its form. */\nexport type EnduranceParse = { readonly ok: true; readonly layer: EnduranceLayer } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of an endurance layer. It gives the layer, or the faults of its form.\n * Each fault names its place in the record, for example `stores.0.amount`.\n */\nexport function parseEndurance(input: unknown): EnduranceParse {\n const read = enduranceSchema.safeParse(input);\n if (read.success) return { ok: true, layer: read.data };\n return { ok: false, errors: formErrors(ENDURANCE_SCHEMA, read.error.issues) };\n}\n"],"mappings":";;;;AAOA,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAC3B,MAAM,SAAS,EAAE,OAAO;AAExB,MAAM,WAAW,EAAE,aAAa;CAAE,MAAM;CAAI,MAAM;AAAG,CAAC;AAEtD,MAAM,QAAQ,EAAE,aAAa;CAC3B;CACA,UAAU;CACV;CACA,KAAK,GAAG,SAAS;CACjB,MAAM,GAAG,SAAS;AACpB,CAAC;AAED,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM;CACN,OAAO;CACP,QAAQ;CACR,OAAO,OAAO,SAAS;CACvB,QAAQ;AACV,CAAC;AAED,MAAM,YAAY,EAAE,aAAa;CAAE,UAAU;CAAI,MAAM;CAAI;AAAO,CAAC;AAEnE,MAAM,YAAY,EAAE,aAAa;CAC/B;CACA,QAAQ,GAAG,SAAS;CACpB,OAAO,EAAE,MAAM,EAAE,aAAa;EAAE,UAAU;EAAI;CAAO,CAAC,CAAC,CAAC,CAAC,SAAS;CAClE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa;EAAE,MAAM;EAAI;CAAO,CAAC,GAAG,EAAE,aAAa;EAAE,UAAU;EAAI;CAAO,CAAC,CAAC,CAAC;AACjG,CAAC;AAED,MAAM,QAAQ,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;AAEzD,MAAM,MAAM,EAAE,aAAa;CACzB,MAAM;CACN,OAAO;CACP,UAAU,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS;CAClC,QAAQ;AACV,CAAC;AAED,MAAM,WAAW,EAAE,aAAa;CAC9B,MAAM;CACN,OAAO;CACP,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS;CAC5B,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,SAAS;CAC/C,aAAa,OAAO,SAAS;AAC/B,CAAC;AAED,MAAM,QAAQ,EAAE,aAAa;CAC3B,MAAM;CACN,OAAO;CACP,SAAS;CACT,OAAO;CACP,QAAQ;CACR,MAAM;AACR,CAAC;;;;;AAMD,MAAa,kBAA6C,EAAE,aAAa;CACvE,QAAQ,EAAE,QAAQ,gBAAgB;CAClC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS;CAC7B,WAAW,EAAE,MAAM,QAAQ,CAAC,CAAC,SAAS;CACtC,QAAQ,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS;CAChC,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,SAAS;CAC9B,QAAQ,EAAE,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC/C,YAAY,EAAE,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CACnD,OAAO,EAAE,MAAM,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC7C,QAAQ,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;AAC7C,CAAC;;;;;AASD,SAAgB,eAAe,OAAgC;CAC7D,MAAM,OAAO,gBAAgB,UAAU,KAAK;CAC5C,IAAI,KAAK,SAAS,OAAO;EAAE,IAAI;EAAM,OAAO,KAAK;CAAK;CACtD,OAAO;EAAE,IAAI;EAAO,QAAQ,WAAW,kBAAkB,KAAK,MAAM,MAAM;CAAE;AAC9E"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,78 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package",
|
|
2
3
|
"name": "@mark1russell7/stack-endurance",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
4
|
+
"version": "0.3.1",
|
|
5
|
+
"description": "Stores, draws and converters of a system stack: the days that each draw holds when a case cuts its supply, and the shortfall of each level in one year. An add-on of system-stack.",
|
|
6
|
+
"license": "MIT",
|
|
5
7
|
"repository": {
|
|
6
8
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/mark1russell7/system-stack.git"
|
|
9
|
+
"url": "git+https://github.com/mark1russell7/system-stack.git",
|
|
10
|
+
"directory": "packages/stack-endurance"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://mark1russell7.github.io/system-stack/",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/mark1russell7/system-stack/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"endurance",
|
|
18
|
+
"autonomy",
|
|
19
|
+
"shortfall",
|
|
20
|
+
"stores",
|
|
21
|
+
"converters",
|
|
22
|
+
"outage",
|
|
23
|
+
"survival-curve",
|
|
24
|
+
"gate",
|
|
25
|
+
"system-stack"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"main": "./build/index.js",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./build/index.d.ts",
|
|
33
|
+
"import": "./build/index.js",
|
|
34
|
+
"default": "./build/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./schema": {
|
|
37
|
+
"types": "./build/schema.d.ts",
|
|
38
|
+
"import": "./build/schema.js",
|
|
39
|
+
"default": "./build/schema.js"
|
|
40
|
+
},
|
|
41
|
+
"./add-on": {
|
|
42
|
+
"types": "./build/add-on.d.ts",
|
|
43
|
+
"import": "./build/add-on.js",
|
|
44
|
+
"default": "./build/add-on.js"
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"build"
|
|
50
|
+
],
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@mark1russell7/collections": "^0.11.2",
|
|
53
|
+
"@mark1russell7/system-stack": "0.1.6",
|
|
54
|
+
"zod": "^4.6.7"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@mark1russell7/cue": "^2.0.0",
|
|
58
|
+
"@types/node": "^26.6.5",
|
|
59
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
60
|
+
"fast-check": "^4.10.2",
|
|
61
|
+
"tsdown": "^0.23.1",
|
|
62
|
+
"typescript": "^7.0.2",
|
|
63
|
+
"vitest": "^5.0.3"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=22"
|
|
8
67
|
},
|
|
9
|
-
"license": "MIT",
|
|
10
68
|
"publishConfig": {
|
|
11
69
|
"access": "public"
|
|
12
|
-
}
|
|
13
|
-
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tsdown",
|
|
73
|
+
"test": "vitest run",
|
|
74
|
+
"test:watch": "vitest",
|
|
75
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json"
|
|
76
|
+
},
|
|
77
|
+
"types": "./build/index.d.ts"
|
|
78
|
+
}
|