@mark1russell7/stack-spend 0.1.11 → 0.1.12
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 +18 -0
- package/build/add-on.js +1 -1
- package/build/index.d.ts +20 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/{join-98opeDSl.js → join-C8cQEqSG.js} +26 -8
- package/build/join-C8cQEqSG.js.map +1 -0
- package/package.json +1 -1
- package/build/join-98opeDSl.js.map +0 -1
package/README.md
CHANGED
|
@@ -264,6 +264,24 @@ monthTotal(SAMPLE_SPEND);
|
|
|
264
264
|
|
|
265
265
|
The cost of the layer has a bound only when `open` is empty. Then `bounded` is that bound.
|
|
266
266
|
|
|
267
|
+
### The limits when parts are down
|
|
268
|
+
|
|
269
|
+
A stop by code holds only while its part `stop` works. The option of `serviceStates`, `monthTotal` and `spendSpace` gives the stack and the parts that do not work at this time. Then a stop by code whose part does not work is not in force.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
import { monthTotal, SAMPLE_SPEND } from "@mark1russell7/stack-spend";
|
|
273
|
+
import { SAMPLE_STACK } from "@mark1russell7/system-stack";
|
|
274
|
+
|
|
275
|
+
monthTotal(SAMPLE_SPEND, { stack: SAMPLE_STACK, down: ["home-power"] });
|
|
276
|
+
// => { bounded: 0, open: ["cloud-account", "call-account"] }
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
With the power of the home down, the alert program at home does not work, so it cannot stop the calls. The prepaid balance gets money automatically, so the cost of the call account has no bound. The alert still works through the copy in the cloud.
|
|
280
|
+
|
|
281
|
+
- The part `stop` does not work when it is in `down`, or when one of its needs does not hold. `working` of the core gives the answer.
|
|
282
|
+
- A stop by code with no part `stop`, or with a part that is not in the stack, is not in force.
|
|
283
|
+
- The other kinds of limit do not change.
|
|
284
|
+
|
|
267
285
|
## The steps of the owner
|
|
268
286
|
|
|
269
287
|
A program cannot change the settings of an account. `ownerSteps(layer, stack, { today })` gives the work of the owner of the accounts, from the faults of the gate.
|
package/build/add-on.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as checkSpend, t as joinSpend } from "./join-
|
|
1
|
+
import { r as checkSpend, t as joinSpend } from "./join-C8cQEqSG.js";
|
|
2
2
|
import { o as SPEND_SCHEMA } from "./reads-BNyUIVaY.js";
|
|
3
3
|
import { parseSpend } from "./schema.js";
|
|
4
4
|
import { dayNumber } from "@mark1russell7/system-stack";
|
package/build/index.d.ts
CHANGED
|
@@ -58,6 +58,16 @@ export declare function serviceKey(part: string): string;
|
|
|
58
58
|
* The key is the text `next:` and the `id` of the part of the service.
|
|
59
59
|
*/
|
|
60
60
|
export declare function nextKey(part: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* The parts that do not work at this time, for the limits of a layer. A stop by code holds only while its part `stop` works.
|
|
63
|
+
* Thus with these options, a stop by code whose part does not work is not in force.
|
|
64
|
+
*/
|
|
65
|
+
export interface DownOptions {
|
|
66
|
+
/** This field is the stack of the layer. */
|
|
67
|
+
readonly stack: Stack;
|
|
68
|
+
/** This field has the parts of the stack that do not work, for example from the monitors of the system. */
|
|
69
|
+
readonly down: Iterable<string>;
|
|
70
|
+
}
|
|
61
71
|
/** This function gives the first record of each part of a layer, in the sequence of the records. */
|
|
62
72
|
export declare function firstServices(layer: SpendLayer): readonly Service[];
|
|
63
73
|
/**
|
|
@@ -70,8 +80,10 @@ export declare function firstServices(layer: SpendLayer): readonly Service[];
|
|
|
70
80
|
* - A limit of the plan after the end is a child of that `next` node.
|
|
71
81
|
*
|
|
72
82
|
* A wanted limit is not in the tree, because it is not in force. The first record of a part is used.
|
|
83
|
+
* With `options`, a stop by code whose part `stop` does not work is not in the tree either. The key of a limit keeps
|
|
84
|
+
* the position of the limit in its record.
|
|
73
85
|
*/
|
|
74
|
-
export declare function spendSpace(layer: SpendLayer): Space;
|
|
86
|
+
export declare function spendSpace(layer: SpendLayer, options?: DownOptions): Space;
|
|
75
87
|
/**
|
|
76
88
|
* This function evaluates a program of `formulas.ts` at a service of a tree. It gives the value, or the error value.
|
|
77
89
|
* `tree` is the result of `spendSpace`, and `part` is the `id` of the part of the service.
|
|
@@ -97,8 +109,11 @@ export interface ServiceState {
|
|
|
97
109
|
*/
|
|
98
110
|
readonly monthMax?: number | undefined;
|
|
99
111
|
}
|
|
100
|
-
/**
|
|
101
|
-
|
|
112
|
+
/**
|
|
113
|
+
* This function gives the state of the cost of each service of a layer, in the sequence of the services.
|
|
114
|
+
* With `options`, a stop by code whose part `stop` does not work is not in force.
|
|
115
|
+
*/
|
|
116
|
+
export declare function serviceStates(layer: SpendLayer, options?: DownOptions): ServiceState[];
|
|
102
117
|
/** The largest cost of a layer in a month. */
|
|
103
118
|
export interface MonthTotal {
|
|
104
119
|
/** The sum of the largest costs of the services that have a bound, in the currency of the layer. */
|
|
@@ -109,8 +124,9 @@ export interface MonthTotal {
|
|
|
109
124
|
/**
|
|
110
125
|
* This function gives the largest cost of a layer in a month.
|
|
111
126
|
* The cost of the layer has a bound only when `open` is empty. Then `bounded` is that bound.
|
|
127
|
+
* With `options`, a stop by code whose part `stop` does not work is not in force.
|
|
112
128
|
*/
|
|
113
|
-
export declare function monthTotal(layer: SpendLayer): MonthTotal;
|
|
129
|
+
export declare function monthTotal(layer: SpendLayer, options?: DownOptions): MonthTotal;
|
|
114
130
|
/** The end of the plan of one service, from the date of a check. */
|
|
115
131
|
export interface PlanEndState {
|
|
116
132
|
/** The `id` of the part of the service. */
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/formulas.ts","../src/states.ts","../src/ends.ts","../src/join.ts","../src/steps.ts","../src/use.ts","../src/use-check.ts","../src/sample.ts"],"mappings":";;;;;;;;;;;;;qBAaa;;YAGD,mBAAmB;;;;;qBAmBlB,SAAS;;qBAMT,aAAa;;qBAMb,YAAY;;;;;qBAMZ,YAAY;;;;;;;;qBAcZ,UAAU;;qBAGV,YAAY;;;;;;;qBAcZ,WAAW;;qBASX,eAAe;;qBAGf,eAAe;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/formulas.ts","../src/states.ts","../src/ends.ts","../src/join.ts","../src/steps.ts","../src/use.ts","../src/use-check.ts","../src/sample.ts"],"mappings":";;;;;;;;;;;;;qBAaa;;YAGD,mBAAmB;;;;;qBAmBlB,SAAS;;qBAMT,aAAa;;qBAMb,YAAY;;;;;qBAMZ,YAAY;;;;;;;;qBAcZ,UAAU;;qBAGV,YAAY;;;;;;;qBAcZ,WAAW;;qBASX,eAAe;;qBAGf,eAAe;;qBCtFf;;wBAKG,WAAW;;;;;wBAUX,QAAQ;;;;;iBAmBP;;WAEN,OAAO;;WAEP,MAAM;;;wBAcD,cAAc,OAAO,sBAAsB;;;;;;;;;;;;;;wBAsB3C,WAAW,OAAO,YAAY,UAAU,cAAc;;;;;wBAsCtD,gBAAgB,SAAS,MAAM,MAAM,OAAO,eAAe;;;;;wBAQ3D,aAAa,SAAS,MAAM,MAAM,OAAO,eAAe;;iBAKvD;;WAEN;WACA,SAAS;;WAET;;WAEA;;;;;WAKA;;;;;;wBAOK,cAAc,OAAO,YAAY,UAAU,cAAc;;iBAiBxD;;WAEN;;WAEA;;;;;;;wBAQK,WAAW,OAAO,YAAY,UAAU,cAAc;;iBC9KrD;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;;;;;;wBAaK,SAAS,OAAO,YAAY,SAAS,eAAe;;iBAenD,mBAAmB;;;;;WAKzB;;;iBAIM;;WAEN;;WAEA;;;;;;;;;;;;;;wBAeK,SAAS,OAAO,YAAY,OAAO,OAAO,SAAS,aAAa;;;;;;;;;;;;;;;;;wBCtDhE,UAAU,iBAAiB,WAAW,gBAAgB,WAAW;;qBCdpE;;YAWD,oBAAoB;;iBAGf;;WAEN;;WAEA;WACA,MAAM;;WAEN;;WAEA;;;;;;;;;;;;;;;;wBA+BK,WAAW,OAAO,YAAY,OAAO,OAAO,SAAS,eAAe;;qBC/CvE,aAAa;;qBAQb,YAAY;;qBAGZ,eAAe;;;;;;qBAOf,MAAM;;qBAGN,WAAW;;qBAGX,UAAU;;;;;qBAMV;;;;;qBAMA,WAAW;;qBAMX,UAAU;;;;;;;;;;;;wBAaP,SAAS,OAAO,YAAY,gBAAgB,WAAW,SAAS,aAAa;;iBAqB5E;;WAEN;WACA,SAAS;;WAET;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;;wBAcK,UAAU,OAAO,YAAY,gBAAgB,WAAW,SAAS,aAAa;;qBClHjF;;YAaD,kBAAkB;;iBAGb,iBAAiB;WACvB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;wBA8BD,SAAS,OAAO,YAAY,gBAAgB,WAAW,SAAS,aAAa;;qBCpDhF;;;;;qBAMA,cAAc;;;;;;;;;qBA0Cd,aAAa;;;;;qBAkCb,uBAAuB"}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as LIMIT_KINDS, i as END_DAYS, n as USE_SOURCES, o as SPEND_SCHEMA, r as BILLINGS, t as USE_LEVELS } from "./reads-BNyUIVaY.js";
|
|
2
|
-
import { C as NODE_KINDS, S as NEXT_PLANS, T as PLAN_MAX, _ as HARD_COUNT, a as LAYER_KEY, b as IS_HARD, c as firstServices, d as serviceKey, f as serviceStates, g as BOUNDED_TOTAL, h as numberOf, i as dayNumber, l as monthTotal, m as booleanOf, n as SPEND_CODES, o as evaluateNext, p as spendSpace, r as checkSpend, s as evaluateService, t as joinSpend, u as nextKey, v as HARD_LIMIT, w as OPEN_SERVICES, x as MONTH_MAX, y as HARD_LIMITS } from "./join-
|
|
2
|
+
import { C as NODE_KINDS, S as NEXT_PLANS, T as PLAN_MAX, _ as HARD_COUNT, a as LAYER_KEY, b as IS_HARD, c as firstServices, d as serviceKey, f as serviceStates, g as BOUNDED_TOTAL, h as numberOf, i as dayNumber, l as monthTotal, m as booleanOf, n as SPEND_CODES, o as evaluateNext, p as spendSpace, r as checkSpend, s as evaluateService, t as joinSpend, u as nextKey, v as HARD_LIMIT, w as OPEN_SERVICES, x as MONTH_MAX, y as HARD_LIMITS } from "./join-C8cQEqSG.js";
|
|
3
3
|
import { app, axes, each, let_, lit, parent, ref, space, v } from "@mark1russell7/vex";
|
|
4
4
|
import { dayNumber as dayNumber$1, partsById, stopped } from "@mark1russell7/system-stack";
|
|
5
5
|
// src/ends.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { o as SPEND_SCHEMA } from "./reads-BNyUIVaY.js";
|
|
2
2
|
import { app, axes, each, evaluate, lit, ref, space } from "@mark1russell7/vex";
|
|
3
3
|
import { BoolDomain, NumDomain, TextDomain } from "@mark1russell7/vex-domains";
|
|
4
|
-
import { dayNumber, dayNumber as dayNumber$1, joinRecords, joinSetting, partsById } from "@mark1russell7/system-stack";
|
|
4
|
+
import { dayNumber, dayNumber as dayNumber$1, joinRecords, joinSetting, partsById, working } from "@mark1russell7/system-stack";
|
|
5
5
|
// src/formulas.ts
|
|
6
6
|
/**
|
|
7
7
|
* These are the kinds of the nodes of the spend tree.
|
|
@@ -113,6 +113,15 @@ function limitRecord(limit) {
|
|
|
113
113
|
...limit.stop === void 0 ? {} : { stop: limit.stop }
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* This function gives a test that tells if a limit is in force. Without options, each limit is in force.
|
|
118
|
+
* With options, a stop by code is in force only when its part `stop` works. A stop by code with no part `stop` is not in force.
|
|
119
|
+
*/
|
|
120
|
+
function inForce(options) {
|
|
121
|
+
if (options === void 0) return () => true;
|
|
122
|
+
const up = working(options.stack, options.down);
|
|
123
|
+
return (limit) => limit.kind !== "code" || limit.stop !== void 0 && up.has(limit.stop);
|
|
124
|
+
}
|
|
116
125
|
/** This function gives the first record of each part of a layer, in the sequence of the records. */
|
|
117
126
|
function firstServices(layer) {
|
|
118
127
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -132,8 +141,11 @@ function firstServices(layer) {
|
|
|
132
141
|
* - A limit of the plan after the end is a child of that `next` node.
|
|
133
142
|
*
|
|
134
143
|
* A wanted limit is not in the tree, because it is not in force. The first record of a part is used.
|
|
144
|
+
* With `options`, a stop by code whose part `stop` does not work is not in the tree either. The key of a limit keeps
|
|
145
|
+
* the position of the limit in its record.
|
|
135
146
|
*/
|
|
136
|
-
function spendSpace(layer) {
|
|
147
|
+
function spendSpace(layer, options) {
|
|
148
|
+
const held = inForce(options);
|
|
137
149
|
const records = { [LAYER_KEY]: { kind: "layer" } };
|
|
138
150
|
const parents = { [LAYER_KEY]: null };
|
|
139
151
|
for (const service of firstServices(layer)) {
|
|
@@ -145,6 +157,7 @@ function spendSpace(layer) {
|
|
|
145
157
|
};
|
|
146
158
|
parents[key] = LAYER_KEY;
|
|
147
159
|
(service.limits ?? []).forEach((limit, index) => {
|
|
160
|
+
if (!held(limit)) return;
|
|
148
161
|
const child = `limit:${service.part}:${String(index)}`;
|
|
149
162
|
records[child] = limitRecord(limit);
|
|
150
163
|
parents[child] = key;
|
|
@@ -159,6 +172,7 @@ function spendSpace(layer) {
|
|
|
159
172
|
};
|
|
160
173
|
parents[after] = key;
|
|
161
174
|
(next.limits ?? []).forEach((limit, index) => {
|
|
175
|
+
if (!held(limit)) return;
|
|
162
176
|
const child = `next-limit:${service.part}:${String(index)}`;
|
|
163
177
|
records[child] = limitRecord(limit);
|
|
164
178
|
parents[child] = after;
|
|
@@ -192,9 +206,12 @@ function evaluateService(program, tree, part) {
|
|
|
192
206
|
function evaluateNext(program, tree, part) {
|
|
193
207
|
return run(program, tree, nextKey(part));
|
|
194
208
|
}
|
|
195
|
-
/**
|
|
196
|
-
function
|
|
197
|
-
|
|
209
|
+
/**
|
|
210
|
+
* This function gives the state of the cost of each service of a layer, in the sequence of the services.
|
|
211
|
+
* With `options`, a stop by code whose part `stop` does not work is not in force.
|
|
212
|
+
*/
|
|
213
|
+
function serviceStates(layer, options) {
|
|
214
|
+
const tree = spendSpace(layer, options);
|
|
198
215
|
return firstServices(layer).map((service) => {
|
|
199
216
|
const hardLimit = numberOf(evaluateService(HARD_LIMIT, tree, service.part));
|
|
200
217
|
const nextLimit = service.ends?.next === void 0 ? void 0 : numberOf(evaluateNext(HARD_LIMIT, tree, service.part));
|
|
@@ -211,9 +228,10 @@ function serviceStates(layer) {
|
|
|
211
228
|
/**
|
|
212
229
|
* This function gives the largest cost of a layer in a month.
|
|
213
230
|
* The cost of the layer has a bound only when `open` is empty. Then `bounded` is that bound.
|
|
231
|
+
* With `options`, a stop by code whose part `stop` does not work is not in force.
|
|
214
232
|
*/
|
|
215
|
-
function monthTotal(layer) {
|
|
216
|
-
const tree = spendSpace(layer);
|
|
233
|
+
function monthTotal(layer, options) {
|
|
234
|
+
const tree = spendSpace(layer, options);
|
|
217
235
|
const keys = run(OPEN_SERVICES, tree, LAYER_KEY);
|
|
218
236
|
const open = keys.ok && Array.isArray(keys.value) ? keys.value.filter((key) => typeof key === "string").map((key) => key.slice(8)) : [];
|
|
219
237
|
return {
|
|
@@ -418,4 +436,4 @@ function joinSpend(pieces) {
|
|
|
418
436
|
}
|
|
419
437
|
export { NODE_KINDS as C, NEXT_PLANS as S, PLAN_MAX as T, HARD_COUNT as _, LAYER_KEY as a, IS_HARD as b, firstServices as c, serviceKey as d, serviceStates as f, BOUNDED_TOTAL as g, numberOf as h, dayNumber as i, monthTotal as l, booleanOf as m, SPEND_CODES as n, evaluateNext as o, spendSpace as p, checkSpend as r, evaluateService as s, joinSpend as t, nextKey as u, HARD_LIMIT as v, OPEN_SERVICES as w, MONTH_MAX as x, HARD_LIMITS as y };
|
|
420
438
|
|
|
421
|
-
//# sourceMappingURL=join-
|
|
439
|
+
//# sourceMappingURL=join-C8cQEqSG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-C8cQEqSG.js","names":["dayNumber"],"sources":["../src/formulas.ts","../src/values.ts","../src/states.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["import { app, axes, each, lit, ref, type Axis, type Expr } from \"@mark1russell7/vex\";\n\n// The cost math, as Vex programs. A program is data: `explain` of Vex shows each step, and a host can keep it as JSON.\n// The programs evaluate on the tree that `spendSpace` makes from a layer.\n\n/**\n * These are the kinds of the nodes of the spend tree.\n *\n * - `layer`: the root.\n * - `service`: a child of the layer. It gives the cost of a service, or the cost before the end of its plan.\n * - `limit`: a child of a service or of a `next` node.\n * - `next`: a child of a service. It gives the cost after the end of the plan.\n */\nexport const NODE_KINDS: readonly [\"layer\", \"service\", \"limit\", \"next\"] = [\"layer\", \"service\", \"limit\", \"next\"];\n\n/** A kind of node of the spend tree. */\nexport type NodeKind = (typeof NODE_KINDS)[number];\n\n/** This function gives the test of the kind of a node. */\nfunction isKind(kind: NodeKind): Expr {\n return app(\"eq\", ref(\"kind\"), lit(kind));\n}\n\n/** This function gives the test of the field `limit` of a limit node: the kind of the limit. */\nfunction isLimit(kind: string): Expr {\n return app(\"eq\", ref(\"limit\"), lit(kind));\n}\n\n/** This test tells if the balance of a prepaid limit gets money automatically. A limit without the field gives false. */\nconst RECHARGES: Expr = app(\"ifError\", ref(\"recharge\"), lit(false));\n\n/**\n * This test tells if a limit node is a hard limit: the service stops at its amount.\n * A hard limit is a limit of the provider, a stop by code, or a prepaid balance with no automatic recharge.\n */\nexport const IS_HARD: Expr = app(\"or\", app(\"or\", isLimit(\"provider\"), isLimit(\"code\")), app(\"and\", isLimit(\"prepaid\"), app(\"not\", RECHARGES)));\n\n/** The limits of a plan: the limit nodes among the children of a service node or of a `next` node. */\nconst LIMITS: Axis = axes.where(axes.children, isKind(\"limit\"));\n\n/** The hard limits of a plan: its limit nodes that pass `IS_HARD`. */\nexport const HARD_LIMITS: Axis = axes.where(LIMITS, IS_HARD);\n\n/** The amount of each hard limit of a plan. */\nconst HARD_AMOUNTS: Expr = each(HARD_LIMITS, ref(\"amount\"));\n\n/** The count of the hard limits of a plan. */\nexport const HARD_COUNT: Expr = app(\"count\", HARD_AMOUNTS);\n\n/**\n * The hard limit of a plan for a month: the smallest amount of its hard limits.\n * A plan with no hard limit gives `#N/A`. The program evaluates at a service node or at a `next` node.\n */\nexport const HARD_LIMIT: Expr = app(\"min\", HARD_AMOUNTS);\n\n/** This function gives the test of the billing of a plan. */\nfunction isBilling(billing: string): Expr {\n return app(\"eq\", ref(\"billing\"), lit(billing));\n}\n\n/**\n * The largest cost of one plan in a month. The program evaluates at a service node or at a `next` node.\n *\n * - `free`: 0.\n * - `fixed`: the price. A plan with no price gives `#N/A`.\n * - `metered`: the price, or 0, plus the hard limit. A plan with no hard limit gives `#N/A`: its cost has no bound.\n */\nexport const PLAN_MAX: Expr = app(\"if\", isBilling(\"free\"), lit(0), app(\"if\", isBilling(\"fixed\"), ref(\"price\"), app(\"add\", app(\"ifError\", ref(\"price\"), lit(0)), HARD_LIMIT)));\n\n/** The plan of a service after the end of its plan: the `next` node among the children of the service. A service has one at most. */\nexport const NEXT_PLANS: Axis = axes.where(axes.children, isKind(\"next\"));\n\n/** The count of the `next` nodes of a service: 0 or 1. The items are the literal 1, so a plan with no bound has a count too. */\nconst NEXT_COUNT: Expr = app(\"count\", each(NEXT_PLANS, lit(1)));\n\n/** The largest cost of a month after the end of the plan. A cost with no bound gives `#N/A`. */\nconst NEXT_MAX: Expr = app(\"nth\", each(NEXT_PLANS, PLAN_MAX), lit(0));\n\n/**\n * The largest cost of a service in a month, before the end of its plan or after it.\n *\n * - A service with no plan after an end gives `PLAN_MAX`.\n * - A service with a plan after an end gives the larger of the two costs. When one of the two has no bound, the result is `#N/A`.\n */\nexport const MONTH_MAX: Expr = app(\"if\", app(\"eq\", NEXT_COUNT, lit(0)), PLAN_MAX, app(\"max\", PLAN_MAX, NEXT_MAX));\n\n/** This test tells if the cost of a service in a month has a bound. */\nconst HAS_MAX: Expr = app(\"ifError\", app(\"eq\", MONTH_MAX, MONTH_MAX), lit(false));\n\n/** The largest cost of each service of the layer in a month. The program evaluates at the layer node. */\nconst MONTH_MAXES: Expr = each(axes.children, MONTH_MAX);\n\n/** The sum of the largest costs of the services that have a bound. The program evaluates at the layer node. */\nexport const BOUNDED_TOTAL: Expr = app(\"sum\", MONTH_MAXES);\n\n/** The keys of the services whose cost in a month has no bound. The program evaluates at the layer node. */\nexport const OPEN_SERVICES: Expr = app(\"keys\", each(axes.where(axes.children, app(\"not\", HAS_MAX)), ref(\"kind\")));\n","import type { Result } from \"@mark1russell7/vex\";\n\n// The read of the result of a program. This module is internal: no entry exports it.\n\n/** This function gives the number of a result, or `undefined` for an error value. */\nexport function numberOf(result: Result<unknown>): number | undefined {\n return result.ok && typeof result.value === \"number\" ? result.value : undefined;\n}\n\n/** This function gives the boolean of a result, or `undefined` for an error value. */\nexport function booleanOf(result: Result<unknown>): boolean | undefined {\n return result.ok && typeof result.value === \"boolean\" ? result.value : undefined;\n}\n","import { evaluate, space, type Expr, type Result, type Space } from \"@mark1russell7/vex\";\nimport { BoolDomain, NumDomain, TextDomain } from \"@mark1russell7/vex-domains\";\nimport { working, type Stack } from \"@mark1russell7/system-stack\";\nimport { BOUNDED_TOTAL, HARD_LIMIT, MONTH_MAX, OPEN_SERVICES } from \"./formulas.ts\";\nimport type { Billing, Limit, Service, SpendLayer } from \"./layer.ts\";\nimport { numberOf } from \"./values.ts\";\n\n// The state of the cost of each service of a layer. The layer becomes a tree, and the programs of `formulas.ts` evaluate on it.\n\n/** The key of the layer node: the root of the spend tree. */\nexport const LAYER_KEY = \"layer\";\n\nconst SERVICE_PREFIX = \"service:\";\n\n/** This function gives the key of the node of a service: the text `service:` and the `id` of its part. */\nexport function serviceKey(part: string): string {\n return `${SERVICE_PREFIX}${part}`;\n}\n\nconst NEXT_PREFIX = \"next:\";\n\n/**\n * This function gives the key of the node of the plan after the end of the plan of a service.\n * The key is the text `next:` and the `id` of the part of the service.\n */\nexport function nextKey(part: string): string {\n return `${NEXT_PREFIX}${part}`;\n}\n\n/** This function gives the record of a limit node. */\nfunction limitRecord(limit: Limit): Readonly<Record<string, unknown>> {\n return {\n kind: \"limit\",\n limit: limit.kind,\n amount: limit.amount,\n ...(limit.recharge === undefined ? {} : { recharge: limit.recharge }),\n ...(limit.stop === undefined ? {} : { stop: limit.stop }),\n };\n}\n\n/**\n * The parts that do not work at this time, for the limits of a layer. A stop by code holds only while its part `stop` works.\n * Thus with these options, a stop by code whose part does not work is not in force.\n */\nexport interface DownOptions {\n /** This field is the stack of the layer. */\n readonly stack: Stack;\n /** This field has the parts of the stack that do not work, for example from the monitors of the system. */\n readonly down: Iterable<string>;\n}\n\n/**\n * This function gives a test that tells if a limit is in force. Without options, each limit is in force.\n * With options, a stop by code is in force only when its part `stop` works. A stop by code with no part `stop` is not in force.\n */\nfunction inForce(options: DownOptions | undefined): (limit: Limit) => boolean {\n if (options === undefined) return () => true;\n const up = working(options.stack, options.down);\n return (limit) => limit.kind !== \"code\" || (limit.stop !== undefined && up.has(limit.stop));\n}\n\n/** This function gives the first record of each part of a layer, in the sequence of the records. */\nexport function firstServices(layer: SpendLayer): readonly Service[] {\n const seen = new Set<string>();\n return layer.services.filter((service) => {\n if (seen.has(service.part)) return false;\n seen.add(service.part);\n return true;\n });\n}\n\n/**\n * This function gives the tree of a layer, as a space of Vex.\n *\n * - The layer is the root, with the key `LAYER_KEY`.\n * - A service is a child of the layer. Its fields are `billing` and `price`.\n * - A limit in force is a child of its service. Its fields are `limit` (its kind), `amount`, `recharge` and `stop`.\n * - The plan after the end of a plan is a child of its service, with the kind `next` and the key of `nextKey`. Its fields are `billing` and `price`.\n * - A limit of the plan after the end is a child of that `next` node.\n *\n * A wanted limit is not in the tree, because it is not in force. The first record of a part is used.\n * With `options`, a stop by code whose part `stop` does not work is not in the tree either. The key of a limit keeps\n * the position of the limit in its record.\n */\nexport function spendSpace(layer: SpendLayer, options?: DownOptions): Space {\n const held = inForce(options);\n const records: Record<string, Readonly<Record<string, unknown>>> = { [LAYER_KEY]: { kind: \"layer\" } };\n const parents: Record<string, string | null> = { [LAYER_KEY]: null };\n for (const service of firstServices(layer)) {\n const key = serviceKey(service.part);\n records[key] = { kind: \"service\", billing: service.billing, ...(service.price === undefined ? {} : { price: service.price }) };\n parents[key] = LAYER_KEY;\n (service.limits ?? []).forEach((limit, index) => {\n if (!held(limit)) return;\n const child = `limit:${service.part}:${String(index)}`;\n records[child] = limitRecord(limit);\n parents[child] = key;\n });\n const next = service.ends?.next;\n if (next === undefined) continue;\n const after = nextKey(service.part);\n records[after] = { kind: \"next\", billing: next.billing, ...(next.price === undefined ? {} : { price: next.price }) };\n parents[after] = key;\n (next.limits ?? []).forEach((limit, index) => {\n if (!held(limit)) return;\n const child = `next-limit:${service.part}:${String(index)}`;\n records[child] = limitRecord(limit);\n parents[child] = after;\n });\n }\n return space.tree(records, parents);\n}\n\n/** This function evaluates a program of `formulas.ts` at a node of a tree. It gives the value, or the error value. */\nfunction run(program: Expr, tree: Space, origin: string): Result<unknown> {\n return evaluate(program, { space: tree, origin, domains: [NumDomain, BoolDomain, TextDomain] });\n}\n\n/**\n * This function evaluates a program of `formulas.ts` at a service of a tree. It gives the value, or the error value.\n * `tree` is the result of `spendSpace`, and `part` is the `id` of the part of the service.\n */\nexport function evaluateService(program: Expr, tree: Space, part: string): Result<unknown> {\n return run(program, tree, serviceKey(part));\n}\n\n/**\n * This function evaluates a program of `formulas.ts` at the plan of a service after the end of its plan.\n * A service with no plan after an end gives an error value. `tree` is the result of `spendSpace`.\n */\nexport function evaluateNext(program: Expr, tree: Space, part: string): Result<unknown> {\n return run(program, tree, nextKey(part));\n}\n\n/** The state of the cost of one service of a layer. */\nexport interface ServiceState {\n /** The `id` of the part of the service. */\n readonly part: string;\n readonly billing: Billing;\n /** The hard limit of the service for a month: the smallest amount of its hard limits. A service with no hard limit has none. */\n readonly hardLimit?: number | undefined;\n /** The hard limit for a month after the end of the plan. A service has none with no plan after an end, or with no hard limit in that plan. */\n readonly nextLimit?: number | undefined;\n /**\n * The largest cost of the service in a month, before the end of its plan or after it.\n * A service has none when one of these costs has no bound.\n */\n readonly monthMax?: number | undefined;\n}\n\n/**\n * This function gives the state of the cost of each service of a layer, in the sequence of the services.\n * With `options`, a stop by code whose part `stop` does not work is not in force.\n */\nexport function serviceStates(layer: SpendLayer, options?: DownOptions): ServiceState[] {\n const tree = spendSpace(layer, options);\n return firstServices(layer).map((service) => {\n const hardLimit = numberOf(evaluateService(HARD_LIMIT, tree, service.part));\n const nextLimit = service.ends?.next === undefined ? undefined : numberOf(evaluateNext(HARD_LIMIT, tree, service.part));\n const monthMax = numberOf(evaluateService(MONTH_MAX, tree, service.part));\n return {\n part: service.part,\n billing: service.billing,\n ...(hardLimit === undefined ? {} : { hardLimit }),\n ...(nextLimit === undefined ? {} : { nextLimit }),\n ...(monthMax === undefined ? {} : { monthMax }),\n };\n });\n}\n\n/** The largest cost of a layer in a month. */\nexport interface MonthTotal {\n /** The sum of the largest costs of the services that have a bound, in the currency of the layer. */\n readonly bounded: number;\n /** The `id` of the part of each service whose cost has no bound. With one or more, the cost of the layer has no bound. */\n readonly open: readonly string[];\n}\n\n/**\n * This function gives the largest cost of a layer in a month.\n * The cost of the layer has a bound only when `open` is empty. Then `bounded` is that bound.\n * With `options`, a stop by code whose part `stop` does not work is not in force.\n */\nexport function monthTotal(layer: SpendLayer, options?: DownOptions): MonthTotal {\n const tree = spendSpace(layer, options);\n const keys = run(OPEN_SERVICES, tree, LAYER_KEY);\n const open = keys.ok && Array.isArray(keys.value) ? keys.value.filter((key): key is string => typeof key === \"string\").map((key) => key.slice(SERVICE_PREFIX.length)) : [];\n return { bounded: numberOf(run(BOUNDED_TOTAL, tree, LAYER_KEY)) ?? 0, open };\n}\n","import { dayNumber, partsById, type Fault, type FaultLevel, type Stack } from \"@mark1russell7/system-stack\";\nimport { END_DAYS, type Limit, type SpendLayer } from \"./layer.ts\";\nimport { serviceStates } from \"./states.ts\";\n\n// The gate of the spend layer. A gate that passes tells that the cost of each part has a hard limit, with a fresh proof.\n\n/** These are the codes of the faults of a spend layer. */\nexport const SPEND_CODES: readonly [\n \"service-part\",\n \"service-duplicate\",\n \"part-no-service\",\n \"price\",\n \"amount\",\n \"limit-none\",\n \"limit-alert\",\n \"limit-recharge\",\n \"limit-stop\",\n \"limit-wanted\",\n \"end-date\",\n \"end-past\",\n \"end-soon\",\n \"end-open\",\n \"proof-none\",\n \"proof-date\",\n \"proof-old\",\n] = [\n \"service-part\",\n \"service-duplicate\",\n \"part-no-service\",\n \"price\",\n \"amount\",\n \"limit-none\",\n \"limit-alert\",\n \"limit-recharge\",\n \"limit-stop\",\n \"limit-wanted\",\n \"end-date\",\n \"end-past\",\n \"end-soon\",\n \"end-open\",\n \"proof-none\",\n \"proof-date\",\n \"proof-old\",\n];\n\n/** A code of a fault of a spend layer. */\nexport type SpendCode = (typeof SPEND_CODES)[number];\n\n/** A fault of a spend layer. Its field `at` is the `id` of the part. */\nexport interface SpendFault extends Fault {\n readonly code: SpendCode;\n}\n\n/** The options of the gate. */\nexport interface SpendOptions {\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}\n\n// The function `dayNumber` is in the core since 0.1.1. This entry keeps the name.\nexport { dayNumber } from \"@mark1russell7/system-stack\";\n\n/** This function tells if a value is a finite number, 0 or more. */\nfunction isZeroOrMore(value: number): boolean {\n return Number.isFinite(value) && value >= 0;\n}\n\n/** This function gives the words for a count of days from the date of the check. */\nfunction inDays(days: number): string {\n if (days === 0) return \"on the date of the check\";\n return days === 1 ? \"in 1 day\" : `in ${String(days)} days`;\n}\n\n/**\n * This function gives each fault of a spend layer for a stack. A list with no error tells that the gate passes.\n *\n * The records:\n * - `service-part`: a record names no part of the stack.\n * - `service-duplicate`: two records name one part.\n * - `part-no-service`: a part of a kind of `kinds` has no record.\n * - `price`: a price is less than 0 or not finite, or a `fixed` plan has no price.\n * - `amount`: the amount of a limit is less than 0 or not finite.\n *\n * The limits:\n * - `limit-none`: the cost of a `metered` service has no limit.\n * - `limit-alert`: the only limits of a `metered` service are alerts. An alert stops nothing.\n * - `limit-recharge`: a prepaid balance gets money automatically, so it is no limit.\n * - `limit-stop`: a stop by code does not name the part of the stack that stops the use.\n * - `limit-wanted`: a wanted limit is not in force.\n *\n * The end of a plan:\n * - `end-date`: the date of an end is not a date. The date of its decision is not a date, or it is after `today`.\n * - `end-past`: the plan ended before `today`. The record gives the cost before the end, so it is not correct.\n * - `end-soon`: the plan ends in `endDays` days, or fewer. This fault is a warning: it does not stop the gate.\n * Its message tells the decision of the owner, when the record has one.\n * - `end-open`: the cost after the end grows with the use, and it has no hard limit.\n *\n * The proofs:\n * - `proof-none`: a record has no proof.\n * - `proof-date`: the date of a proof is not a date, or it is after `today`.\n * - `proof-old`: a proof is older than `proofDays`.\n *\n * The faults `price`, `amount` and `limit-stop` examine the plan after an end too.\n * The faults are in the sequence of the records, then of the parts with no record. The function is pure.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`\n */\nexport function checkSpend(layer: SpendLayer, stack: Stack, options: SpendOptions): SpendFault[] {\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 faults: SpendFault[] = [];\n const push = (level: FaultLevel, code: SpendCode, at: string, message: string, other?: string): void => {\n faults.push({ level, code, at, message, ...(other === undefined ? {} : { other }) });\n };\n const add = (code: SpendCode, at: string, message: string, other?: string): void => {\n push(\"error\", code, at, message, other);\n };\n const parts = partsById(stack);\n // The faults of one limit. `when` is empty, or it tells that the limit is of the plan after an end.\n const examine = (limit: Limit, at: string, when: string): void => {\n if (!isZeroOrMore(limit.amount)) add(\"amount\", at, `The amount ${String(limit.amount)} of a limit of \"${at}\"${when} is less than 0 or not finite.`);\n if (limit.kind !== \"code\") return;\n if (limit.stop === undefined) add(\"limit-stop\", at, `A stop by code of \"${at}\"${when} does not name the part that stops the use.`);\n else if (!parts.has(limit.stop)) add(\"limit-stop\", at, `A stop by code of \"${at}\"${when} names \"${limit.stop}\", which is no part of the stack.`, limit.stop);\n };\n const states = new Map(serviceStates(layer).map((state) => [state.part, state]));\n const endDays = layer.endDays ?? END_DAYS;\n const seen = new Set<string>();\n for (const service of layer.services) {\n const at = service.part;\n if (seen.has(at)) {\n add(\"service-duplicate\", at, `Two cost records name the part \"${at}\".`);\n continue;\n }\n seen.add(at);\n if (!parts.has(at)) add(\"service-part\", at, `A cost record names \"${at}\", which is no part of the stack.`);\n if (service.price !== undefined && !isZeroOrMore(service.price)) add(\"price\", at, `The price ${String(service.price)} of \"${at}\" is less than 0 or not finite.`);\n if (service.billing === \"fixed\" && service.price === undefined) add(\"price\", at, `The service \"${at}\" has a fixed price, and its record gives no price.`);\n const limits: readonly Limit[] = service.limits ?? [];\n for (const limit of [...limits, ...(service.wanted === undefined ? [] : [service.wanted])]) examine(limit, at, \"\");\n const recharges = limits.some((limit) => limit.kind === \"prepaid\" && limit.recharge === true);\n if (recharges) add(\"limit-recharge\", at, `The prepaid balance of \"${at}\" gets money automatically, so it does not limit the cost.`);\n if (service.wanted !== undefined) {\n add(\"limit-wanted\", at, `The wanted limit of \"${at}\" (${service.wanted.kind}, ${String(service.wanted.amount)} ${layer.currency} for a month) is not in force.`);\n } else if (service.billing === \"metered\" && states.get(at)?.hardLimit === undefined && !recharges) {\n if (limits.some((limit) => limit.kind === \"alert\")) add(\"limit-alert\", at, `The cost of \"${at}\" grows with the use, and its only limit is an alert. An alert stops nothing.`);\n else add(\"limit-none\", at, `The cost of \"${at}\" grows with the use, and it has no limit.`);\n }\n if (service.ends !== undefined) {\n const { date, next, decided } = service.ends;\n const end = dayNumber(date);\n if (end === undefined) add(\"end-date\", at, `The date \"${date}\" of the end of the plan of \"${at}\" is not a date of the form YYYY-MM-DD.`);\n else if (end < today) add(\"end-past\", at, `The plan of \"${at}\" ended on ${date}. The record gives the cost before the end.`);\n else if (end - today <= endDays) {\n const then = next === undefined ? \"Then the provider stops the service.\" : \"Then the cost changes.\";\n const agreed = decided === undefined ? \"\" : ` ${decided.by} decided this on ${decided.date}.`;\n push(\"warning\", \"end-soon\", at, `The plan of \"${at}\" ends on ${date}, ${inDays(end - today)}. ${then}${agreed}`);\n }\n if (decided !== undefined) {\n const day = dayNumber(decided.date);\n const about = `of the decision about the end of the plan of \"${at}\"`;\n if (day === undefined) add(\"end-date\", at, `The date \"${decided.date}\" ${about} is not a date of the form YYYY-MM-DD.`);\n else if (day > today) add(\"end-date\", at, `The date ${decided.date} ${about} is after the date of the check, ${options.today}.`);\n }\n if (next !== undefined) {\n const when = \" after the end of its plan\";\n if (next.price !== undefined && !isZeroOrMore(next.price)) add(\"price\", at, `The price ${String(next.price)} of \"${at}\"${when} is less than 0 or not finite.`);\n if (next.billing === \"fixed\" && next.price === undefined) add(\"price\", at, `The service \"${at}\" has a fixed price${when}, and its record gives no price.`);\n for (const limit of next.limits ?? []) examine(limit, at, when);\n if (next.billing === \"metered\" && states.get(at)?.nextLimit === undefined) {\n add(\"end-open\", at, `The plan of \"${at}\" ends on ${date}. After the end, the cost grows with the use, and it has no hard limit.`);\n }\n }\n }\n if (service.proof === undefined) {\n add(\"proof-none\", at, `The cost record of \"${at}\" has no proof.`);\n continue;\n }\n const day = dayNumber(service.proof.date);\n if (day === undefined) add(\"proof-date\", at, `The date \"${service.proof.date}\" of the proof of \"${at}\" is not a date of the form YYYY-MM-DD.`);\n else if (day > today) add(\"proof-date\", at, `The date ${service.proof.date} of the proof of \"${at}\" is after the date of the check, ${options.today}.`);\n else if (today - day > layer.proofDays) {\n add(\"proof-old\", at, `The proof of \"${at}\" is ${String(today - day)} days old. The largest age is ${String(layer.proofDays)} days.`);\n }\n }\n const kinds = new Set(layer.kinds);\n for (const part of stack.parts) {\n if (kinds.has(part.kind) && !seen.has(part.id)) add(\"part-no-service\", part.id, `The part \"${part.id}\" has the kind \"${part.kind}\", and it has no cost record.`);\n }\n return faults;\n}\n","import { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { SPEND_SCHEMA, type SpendLayer } from \"./layer.ts\";\n\n// The join of the spend layers of the fragments of a stack, for example one file of cost records for each owner.\n\n/**\n * This function joins the spend layers of the fragments of a stack into one layer.\n *\n * - The cost records are in the order of the fragments. The record of a part is in one fragment.\n * - A part with a record in two or more fragments is a fault, also when the records are equal.\n * - The layer has one currency and one largest age of a proof. A fragment with a different value is a fault.\n * - The count of days of warning before the end of a plan is one value too. A fragment with no value takes the value of the others.\n * - The kinds are the kinds of each fragment, one time each, in the order of the fragments.\n *\n * The kinds of the joined layer hold for each part of the joined stack. Thus a kind of one fragment needs a cost\n * record also for the parts of that kind in the other fragments. The function is pure, and it changes no layer.\n * The gate `checkSpend` 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. An empty list of layers is a fault.\n */\nexport function joinSpend(pieces: readonly LayerPiece<SpendLayer>[]): LayerParse<SpendLayer> {\n const currency = joinSetting(pieces, (layer) => layer.currency, \"currency\");\n const proofDays = joinSetting(pieces, (layer) => layer.proofDays, \"largest age of a proof in days\");\n const endDays = joinSetting(pieces, (layer) => layer.endDays, \"count of days of warning before the end of a plan\");\n const services = joinRecords(\n pieces,\n (layer) => layer.services,\n (service) => service.part,\n \"cost record of the part\",\n );\n if (currency.value === undefined || proofDays.value === undefined) return { ok: false, errors: [\"The join of spend layers got no layer.\"] };\n const errors = [...currency.errors, ...proofDays.errors, ...endDays.errors, ...services.errors];\n if (errors.length > 0) return { ok: false, errors };\n const kinds = [...new Set(pieces.flatMap((piece) => piece.layer.kinds))];\n return {\n ok: true,\n layer: {\n schema: SPEND_SCHEMA,\n currency: currency.value,\n kinds,\n proofDays: proofDays.value,\n ...(endDays.value === undefined ? {} : { endDays: endDays.value }),\n services: services.items,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,aAA6D;CAAC;CAAS;CAAW;CAAS;AAAM;;AAM9G,SAAS,OAAO,MAAsB;CACpC,OAAO,IAAI,MAAM,IAAI,MAAM,G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E,MAAM,YAAY,YAAY,SAAS,UAAU,MAAM,WAAW,gCAAgC;CAClG,MAAM,UAAU,YAAY,SAAS,UAAU,MAAM,SAAS,mDAAmD;CACjH,MAAM,WAAW,YACf,SACC,UAAU,MAAM,WAChB,YAAY,QAAQ,MACrB,yBACF;CACA,IAAI,SAAS,UAAU,KAAA,KAAa,UAAU,UAAU,KAAA,GAAW,OAAO;EAAE,IAAI;EAAO,QAAQ,CAAC,wCAAwC;CAAE;CAC1I,MAAM,SAAS;EAAC,GAAG,SAAS;EAAQ,GAAG,UAAU;EAAQ,GAAG,QAAQ;EAAQ,GAAG,SAAS;CAAM;CAC9F,IAAI,OAAO,SAAS,GAAG,OAAO;EAAE,IAAI;EAAO;CAAO;CAClD,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,OAAO,SAAS,UAAU,MAAM,MAAM,KAAK,CAAC,CAAC;CACvE,OAAO;EACL,IAAI;EACJ,OAAO;GACL,QAAQ;GACR,UAAU,SAAS;GACnB;GACA,WAAW,UAAU;GACrB,GAAI,QAAQ,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,MAAM;GAChE,UAAU,SAAS;EACrB;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/stack-spend",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.12",
|
|
5
5
|
"description": "The cost of each part of a system stack as data: plans, prices and hard monthly limits, a gate, and the largest cost of a month as Vex programs. An add-on of system-stack.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"join-98opeDSl.js","names":["dayNumber"],"sources":["../src/formulas.ts","../src/values.ts","../src/states.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["import { app, axes, each, lit, ref, type Axis, type Expr } from \"@mark1russell7/vex\";\n\n// The cost math, as Vex programs. A program is data: `explain` of Vex shows each step, and a host can keep it as JSON.\n// The programs evaluate on the tree that `spendSpace` makes from a layer.\n\n/**\n * These are the kinds of the nodes of the spend tree.\n *\n * - `layer`: the root.\n * - `service`: a child of the layer. It gives the cost of a service, or the cost before the end of its plan.\n * - `limit`: a child of a service or of a `next` node.\n * - `next`: a child of a service. It gives the cost after the end of the plan.\n */\nexport const NODE_KINDS: readonly [\"layer\", \"service\", \"limit\", \"next\"] = [\"layer\", \"service\", \"limit\", \"next\"];\n\n/** A kind of node of the spend tree. */\nexport type NodeKind = (typeof NODE_KINDS)[number];\n\n/** This function gives the test of the kind of a node. */\nfunction isKind(kind: NodeKind): Expr {\n return app(\"eq\", ref(\"kind\"), lit(kind));\n}\n\n/** This function gives the test of the field `limit` of a limit node: the kind of the limit. */\nfunction isLimit(kind: string): Expr {\n return app(\"eq\", ref(\"limit\"), lit(kind));\n}\n\n/** This test tells if the balance of a prepaid limit gets money automatically. A limit without the field gives false. */\nconst RECHARGES: Expr = app(\"ifError\", ref(\"recharge\"), lit(false));\n\n/**\n * This test tells if a limit node is a hard limit: the service stops at its amount.\n * A hard limit is a limit of the provider, a stop by code, or a prepaid balance with no automatic recharge.\n */\nexport const IS_HARD: Expr = app(\"or\", app(\"or\", isLimit(\"provider\"), isLimit(\"code\")), app(\"and\", isLimit(\"prepaid\"), app(\"not\", RECHARGES)));\n\n/** The limits of a plan: the limit nodes among the children of a service node or of a `next` node. */\nconst LIMITS: Axis = axes.where(axes.children, isKind(\"limit\"));\n\n/** The hard limits of a plan: its limit nodes that pass `IS_HARD`. */\nexport const HARD_LIMITS: Axis = axes.where(LIMITS, IS_HARD);\n\n/** The amount of each hard limit of a plan. */\nconst HARD_AMOUNTS: Expr = each(HARD_LIMITS, ref(\"amount\"));\n\n/** The count of the hard limits of a plan. */\nexport const HARD_COUNT: Expr = app(\"count\", HARD_AMOUNTS);\n\n/**\n * The hard limit of a plan for a month: the smallest amount of its hard limits.\n * A plan with no hard limit gives `#N/A`. The program evaluates at a service node or at a `next` node.\n */\nexport const HARD_LIMIT: Expr = app(\"min\", HARD_AMOUNTS);\n\n/** This function gives the test of the billing of a plan. */\nfunction isBilling(billing: string): Expr {\n return app(\"eq\", ref(\"billing\"), lit(billing));\n}\n\n/**\n * The largest cost of one plan in a month. The program evaluates at a service node or at a `next` node.\n *\n * - `free`: 0.\n * - `fixed`: the price. A plan with no price gives `#N/A`.\n * - `metered`: the price, or 0, plus the hard limit. A plan with no hard limit gives `#N/A`: its cost has no bound.\n */\nexport const PLAN_MAX: Expr = app(\"if\", isBilling(\"free\"), lit(0), app(\"if\", isBilling(\"fixed\"), ref(\"price\"), app(\"add\", app(\"ifError\", ref(\"price\"), lit(0)), HARD_LIMIT)));\n\n/** The plan of a service after the end of its plan: the `next` node among the children of the service. A service has one at most. */\nexport const NEXT_PLANS: Axis = axes.where(axes.children, isKind(\"next\"));\n\n/** The count of the `next` nodes of a service: 0 or 1. The items are the literal 1, so a plan with no bound has a count too. */\nconst NEXT_COUNT: Expr = app(\"count\", each(NEXT_PLANS, lit(1)));\n\n/** The largest cost of a month after the end of the plan. A cost with no bound gives `#N/A`. */\nconst NEXT_MAX: Expr = app(\"nth\", each(NEXT_PLANS, PLAN_MAX), lit(0));\n\n/**\n * The largest cost of a service in a month, before the end of its plan or after it.\n *\n * - A service with no plan after an end gives `PLAN_MAX`.\n * - A service with a plan after an end gives the larger of the two costs. When one of the two has no bound, the result is `#N/A`.\n */\nexport const MONTH_MAX: Expr = app(\"if\", app(\"eq\", NEXT_COUNT, lit(0)), PLAN_MAX, app(\"max\", PLAN_MAX, NEXT_MAX));\n\n/** This test tells if the cost of a service in a month has a bound. */\nconst HAS_MAX: Expr = app(\"ifError\", app(\"eq\", MONTH_MAX, MONTH_MAX), lit(false));\n\n/** The largest cost of each service of the layer in a month. The program evaluates at the layer node. */\nconst MONTH_MAXES: Expr = each(axes.children, MONTH_MAX);\n\n/** The sum of the largest costs of the services that have a bound. The program evaluates at the layer node. */\nexport const BOUNDED_TOTAL: Expr = app(\"sum\", MONTH_MAXES);\n\n/** The keys of the services whose cost in a month has no bound. The program evaluates at the layer node. */\nexport const OPEN_SERVICES: Expr = app(\"keys\", each(axes.where(axes.children, app(\"not\", HAS_MAX)), ref(\"kind\")));\n","import type { Result } from \"@mark1russell7/vex\";\n\n// The read of the result of a program. This module is internal: no entry exports it.\n\n/** This function gives the number of a result, or `undefined` for an error value. */\nexport function numberOf(result: Result<unknown>): number | undefined {\n return result.ok && typeof result.value === \"number\" ? result.value : undefined;\n}\n\n/** This function gives the boolean of a result, or `undefined` for an error value. */\nexport function booleanOf(result: Result<unknown>): boolean | undefined {\n return result.ok && typeof result.value === \"boolean\" ? result.value : undefined;\n}\n","import { evaluate, space, type Expr, type Result, type Space } from \"@mark1russell7/vex\";\nimport { BoolDomain, NumDomain, TextDomain } from \"@mark1russell7/vex-domains\";\nimport { BOUNDED_TOTAL, HARD_LIMIT, MONTH_MAX, OPEN_SERVICES } from \"./formulas.ts\";\nimport type { Billing, Limit, Service, SpendLayer } from \"./layer.ts\";\nimport { numberOf } from \"./values.ts\";\n\n// The state of the cost of each service of a layer. The layer becomes a tree, and the programs of `formulas.ts` evaluate on it.\n\n/** The key of the layer node: the root of the spend tree. */\nexport const LAYER_KEY = \"layer\";\n\nconst SERVICE_PREFIX = \"service:\";\n\n/** This function gives the key of the node of a service: the text `service:` and the `id` of its part. */\nexport function serviceKey(part: string): string {\n return `${SERVICE_PREFIX}${part}`;\n}\n\nconst NEXT_PREFIX = \"next:\";\n\n/**\n * This function gives the key of the node of the plan after the end of the plan of a service.\n * The key is the text `next:` and the `id` of the part of the service.\n */\nexport function nextKey(part: string): string {\n return `${NEXT_PREFIX}${part}`;\n}\n\n/** This function gives the record of a limit node. */\nfunction limitRecord(limit: Limit): Readonly<Record<string, unknown>> {\n return {\n kind: \"limit\",\n limit: limit.kind,\n amount: limit.amount,\n ...(limit.recharge === undefined ? {} : { recharge: limit.recharge }),\n ...(limit.stop === undefined ? {} : { stop: limit.stop }),\n };\n}\n\n/** This function gives the first record of each part of a layer, in the sequence of the records. */\nexport function firstServices(layer: SpendLayer): readonly Service[] {\n const seen = new Set<string>();\n return layer.services.filter((service) => {\n if (seen.has(service.part)) return false;\n seen.add(service.part);\n return true;\n });\n}\n\n/**\n * This function gives the tree of a layer, as a space of Vex.\n *\n * - The layer is the root, with the key `LAYER_KEY`.\n * - A service is a child of the layer. Its fields are `billing` and `price`.\n * - A limit in force is a child of its service. Its fields are `limit` (its kind), `amount`, `recharge` and `stop`.\n * - The plan after the end of a plan is a child of its service, with the kind `next` and the key of `nextKey`. Its fields are `billing` and `price`.\n * - A limit of the plan after the end is a child of that `next` node.\n *\n * A wanted limit is not in the tree, because it is not in force. The first record of a part is used.\n */\nexport function spendSpace(layer: SpendLayer): Space {\n const records: Record<string, Readonly<Record<string, unknown>>> = { [LAYER_KEY]: { kind: \"layer\" } };\n const parents: Record<string, string | null> = { [LAYER_KEY]: null };\n for (const service of firstServices(layer)) {\n const key = serviceKey(service.part);\n records[key] = { kind: \"service\", billing: service.billing, ...(service.price === undefined ? {} : { price: service.price }) };\n parents[key] = LAYER_KEY;\n (service.limits ?? []).forEach((limit, index) => {\n const child = `limit:${service.part}:${String(index)}`;\n records[child] = limitRecord(limit);\n parents[child] = key;\n });\n const next = service.ends?.next;\n if (next === undefined) continue;\n const after = nextKey(service.part);\n records[after] = { kind: \"next\", billing: next.billing, ...(next.price === undefined ? {} : { price: next.price }) };\n parents[after] = key;\n (next.limits ?? []).forEach((limit, index) => {\n const child = `next-limit:${service.part}:${String(index)}`;\n records[child] = limitRecord(limit);\n parents[child] = after;\n });\n }\n return space.tree(records, parents);\n}\n\n/** This function evaluates a program of `formulas.ts` at a node of a tree. It gives the value, or the error value. */\nfunction run(program: Expr, tree: Space, origin: string): Result<unknown> {\n return evaluate(program, { space: tree, origin, domains: [NumDomain, BoolDomain, TextDomain] });\n}\n\n/**\n * This function evaluates a program of `formulas.ts` at a service of a tree. It gives the value, or the error value.\n * `tree` is the result of `spendSpace`, and `part` is the `id` of the part of the service.\n */\nexport function evaluateService(program: Expr, tree: Space, part: string): Result<unknown> {\n return run(program, tree, serviceKey(part));\n}\n\n/**\n * This function evaluates a program of `formulas.ts` at the plan of a service after the end of its plan.\n * A service with no plan after an end gives an error value. `tree` is the result of `spendSpace`.\n */\nexport function evaluateNext(program: Expr, tree: Space, part: string): Result<unknown> {\n return run(program, tree, nextKey(part));\n}\n\n/** The state of the cost of one service of a layer. */\nexport interface ServiceState {\n /** The `id` of the part of the service. */\n readonly part: string;\n readonly billing: Billing;\n /** The hard limit of the service for a month: the smallest amount of its hard limits. A service with no hard limit has none. */\n readonly hardLimit?: number | undefined;\n /** The hard limit for a month after the end of the plan. A service has none with no plan after an end, or with no hard limit in that plan. */\n readonly nextLimit?: number | undefined;\n /**\n * The largest cost of the service in a month, before the end of its plan or after it.\n * A service has none when one of these costs has no bound.\n */\n readonly monthMax?: number | undefined;\n}\n\n/** This function gives the state of the cost of each service of a layer, in the sequence of the services. */\nexport function serviceStates(layer: SpendLayer): ServiceState[] {\n const tree = spendSpace(layer);\n return firstServices(layer).map((service) => {\n const hardLimit = numberOf(evaluateService(HARD_LIMIT, tree, service.part));\n const nextLimit = service.ends?.next === undefined ? undefined : numberOf(evaluateNext(HARD_LIMIT, tree, service.part));\n const monthMax = numberOf(evaluateService(MONTH_MAX, tree, service.part));\n return {\n part: service.part,\n billing: service.billing,\n ...(hardLimit === undefined ? {} : { hardLimit }),\n ...(nextLimit === undefined ? {} : { nextLimit }),\n ...(monthMax === undefined ? {} : { monthMax }),\n };\n });\n}\n\n/** The largest cost of a layer in a month. */\nexport interface MonthTotal {\n /** The sum of the largest costs of the services that have a bound, in the currency of the layer. */\n readonly bounded: number;\n /** The `id` of the part of each service whose cost has no bound. With one or more, the cost of the layer has no bound. */\n readonly open: readonly string[];\n}\n\n/**\n * This function gives the largest cost of a layer in a month.\n * The cost of the layer has a bound only when `open` is empty. Then `bounded` is that bound.\n */\nexport function monthTotal(layer: SpendLayer): MonthTotal {\n const tree = spendSpace(layer);\n const keys = run(OPEN_SERVICES, tree, LAYER_KEY);\n const open = keys.ok && Array.isArray(keys.value) ? keys.value.filter((key): key is string => typeof key === \"string\").map((key) => key.slice(SERVICE_PREFIX.length)) : [];\n return { bounded: numberOf(run(BOUNDED_TOTAL, tree, LAYER_KEY)) ?? 0, open };\n}\n","import { dayNumber, partsById, type Fault, type FaultLevel, type Stack } from \"@mark1russell7/system-stack\";\nimport { END_DAYS, type Limit, type SpendLayer } from \"./layer.ts\";\nimport { serviceStates } from \"./states.ts\";\n\n// The gate of the spend layer. A gate that passes tells that the cost of each part has a hard limit, with a fresh proof.\n\n/** These are the codes of the faults of a spend layer. */\nexport const SPEND_CODES: readonly [\n \"service-part\",\n \"service-duplicate\",\n \"part-no-service\",\n \"price\",\n \"amount\",\n \"limit-none\",\n \"limit-alert\",\n \"limit-recharge\",\n \"limit-stop\",\n \"limit-wanted\",\n \"end-date\",\n \"end-past\",\n \"end-soon\",\n \"end-open\",\n \"proof-none\",\n \"proof-date\",\n \"proof-old\",\n] = [\n \"service-part\",\n \"service-duplicate\",\n \"part-no-service\",\n \"price\",\n \"amount\",\n \"limit-none\",\n \"limit-alert\",\n \"limit-recharge\",\n \"limit-stop\",\n \"limit-wanted\",\n \"end-date\",\n \"end-past\",\n \"end-soon\",\n \"end-open\",\n \"proof-none\",\n \"proof-date\",\n \"proof-old\",\n];\n\n/** A code of a fault of a spend layer. */\nexport type SpendCode = (typeof SPEND_CODES)[number];\n\n/** A fault of a spend layer. Its field `at` is the `id` of the part. */\nexport interface SpendFault extends Fault {\n readonly code: SpendCode;\n}\n\n/** The options of the gate. */\nexport interface SpendOptions {\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}\n\n// The function `dayNumber` is in the core since 0.1.1. This entry keeps the name.\nexport { dayNumber } from \"@mark1russell7/system-stack\";\n\n/** This function tells if a value is a finite number, 0 or more. */\nfunction isZeroOrMore(value: number): boolean {\n return Number.isFinite(value) && value >= 0;\n}\n\n/** This function gives the words for a count of days from the date of the check. */\nfunction inDays(days: number): string {\n if (days === 0) return \"on the date of the check\";\n return days === 1 ? \"in 1 day\" : `in ${String(days)} days`;\n}\n\n/**\n * This function gives each fault of a spend layer for a stack. A list with no error tells that the gate passes.\n *\n * The records:\n * - `service-part`: a record names no part of the stack.\n * - `service-duplicate`: two records name one part.\n * - `part-no-service`: a part of a kind of `kinds` has no record.\n * - `price`: a price is less than 0 or not finite, or a `fixed` plan has no price.\n * - `amount`: the amount of a limit is less than 0 or not finite.\n *\n * The limits:\n * - `limit-none`: the cost of a `metered` service has no limit.\n * - `limit-alert`: the only limits of a `metered` service are alerts. An alert stops nothing.\n * - `limit-recharge`: a prepaid balance gets money automatically, so it is no limit.\n * - `limit-stop`: a stop by code does not name the part of the stack that stops the use.\n * - `limit-wanted`: a wanted limit is not in force.\n *\n * The end of a plan:\n * - `end-date`: the date of an end is not a date. The date of its decision is not a date, or it is after `today`.\n * - `end-past`: the plan ended before `today`. The record gives the cost before the end, so it is not correct.\n * - `end-soon`: the plan ends in `endDays` days, or fewer. This fault is a warning: it does not stop the gate.\n * Its message tells the decision of the owner, when the record has one.\n * - `end-open`: the cost after the end grows with the use, and it has no hard limit.\n *\n * The proofs:\n * - `proof-none`: a record has no proof.\n * - `proof-date`: the date of a proof is not a date, or it is after `today`.\n * - `proof-old`: a proof is older than `proofDays`.\n *\n * The faults `price`, `amount` and `limit-stop` examine the plan after an end too.\n * The faults are in the sequence of the records, then of the parts with no record. The function is pure.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`\n */\nexport function checkSpend(layer: SpendLayer, stack: Stack, options: SpendOptions): SpendFault[] {\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 faults: SpendFault[] = [];\n const push = (level: FaultLevel, code: SpendCode, at: string, message: string, other?: string): void => {\n faults.push({ level, code, at, message, ...(other === undefined ? {} : { other }) });\n };\n const add = (code: SpendCode, at: string, message: string, other?: string): void => {\n push(\"error\", code, at, message, other);\n };\n const parts = partsById(stack);\n // The faults of one limit. `when` is empty, or it tells that the limit is of the plan after an end.\n const examine = (limit: Limit, at: string, when: string): void => {\n if (!isZeroOrMore(limit.amount)) add(\"amount\", at, `The amount ${String(limit.amount)} of a limit of \"${at}\"${when} is less than 0 or not finite.`);\n if (limit.kind !== \"code\") return;\n if (limit.stop === undefined) add(\"limit-stop\", at, `A stop by code of \"${at}\"${when} does not name the part that stops the use.`);\n else if (!parts.has(limit.stop)) add(\"limit-stop\", at, `A stop by code of \"${at}\"${when} names \"${limit.stop}\", which is no part of the stack.`, limit.stop);\n };\n const states = new Map(serviceStates(layer).map((state) => [state.part, state]));\n const endDays = layer.endDays ?? END_DAYS;\n const seen = new Set<string>();\n for (const service of layer.services) {\n const at = service.part;\n if (seen.has(at)) {\n add(\"service-duplicate\", at, `Two cost records name the part \"${at}\".`);\n continue;\n }\n seen.add(at);\n if (!parts.has(at)) add(\"service-part\", at, `A cost record names \"${at}\", which is no part of the stack.`);\n if (service.price !== undefined && !isZeroOrMore(service.price)) add(\"price\", at, `The price ${String(service.price)} of \"${at}\" is less than 0 or not finite.`);\n if (service.billing === \"fixed\" && service.price === undefined) add(\"price\", at, `The service \"${at}\" has a fixed price, and its record gives no price.`);\n const limits: readonly Limit[] = service.limits ?? [];\n for (const limit of [...limits, ...(service.wanted === undefined ? [] : [service.wanted])]) examine(limit, at, \"\");\n const recharges = limits.some((limit) => limit.kind === \"prepaid\" && limit.recharge === true);\n if (recharges) add(\"limit-recharge\", at, `The prepaid balance of \"${at}\" gets money automatically, so it does not limit the cost.`);\n if (service.wanted !== undefined) {\n add(\"limit-wanted\", at, `The wanted limit of \"${at}\" (${service.wanted.kind}, ${String(service.wanted.amount)} ${layer.currency} for a month) is not in force.`);\n } else if (service.billing === \"metered\" && states.get(at)?.hardLimit === undefined && !recharges) {\n if (limits.some((limit) => limit.kind === \"alert\")) add(\"limit-alert\", at, `The cost of \"${at}\" grows with the use, and its only limit is an alert. An alert stops nothing.`);\n else add(\"limit-none\", at, `The cost of \"${at}\" grows with the use, and it has no limit.`);\n }\n if (service.ends !== undefined) {\n const { date, next, decided } = service.ends;\n const end = dayNumber(date);\n if (end === undefined) add(\"end-date\", at, `The date \"${date}\" of the end of the plan of \"${at}\" is not a date of the form YYYY-MM-DD.`);\n else if (end < today) add(\"end-past\", at, `The plan of \"${at}\" ended on ${date}. The record gives the cost before the end.`);\n else if (end - today <= endDays) {\n const then = next === undefined ? \"Then the provider stops the service.\" : \"Then the cost changes.\";\n const agreed = decided === undefined ? \"\" : ` ${decided.by} decided this on ${decided.date}.`;\n push(\"warning\", \"end-soon\", at, `The plan of \"${at}\" ends on ${date}, ${inDays(end - today)}. ${then}${agreed}`);\n }\n if (decided !== undefined) {\n const day = dayNumber(decided.date);\n const about = `of the decision about the end of the plan of \"${at}\"`;\n if (day === undefined) add(\"end-date\", at, `The date \"${decided.date}\" ${about} is not a date of the form YYYY-MM-DD.`);\n else if (day > today) add(\"end-date\", at, `The date ${decided.date} ${about} is after the date of the check, ${options.today}.`);\n }\n if (next !== undefined) {\n const when = \" after the end of its plan\";\n if (next.price !== undefined && !isZeroOrMore(next.price)) add(\"price\", at, `The price ${String(next.price)} of \"${at}\"${when} is less than 0 or not finite.`);\n if (next.billing === \"fixed\" && next.price === undefined) add(\"price\", at, `The service \"${at}\" has a fixed price${when}, and its record gives no price.`);\n for (const limit of next.limits ?? []) examine(limit, at, when);\n if (next.billing === \"metered\" && states.get(at)?.nextLimit === undefined) {\n add(\"end-open\", at, `The plan of \"${at}\" ends on ${date}. After the end, the cost grows with the use, and it has no hard limit.`);\n }\n }\n }\n if (service.proof === undefined) {\n add(\"proof-none\", at, `The cost record of \"${at}\" has no proof.`);\n continue;\n }\n const day = dayNumber(service.proof.date);\n if (day === undefined) add(\"proof-date\", at, `The date \"${service.proof.date}\" of the proof of \"${at}\" is not a date of the form YYYY-MM-DD.`);\n else if (day > today) add(\"proof-date\", at, `The date ${service.proof.date} of the proof of \"${at}\" is after the date of the check, ${options.today}.`);\n else if (today - day > layer.proofDays) {\n add(\"proof-old\", at, `The proof of \"${at}\" is ${String(today - day)} days old. The largest age is ${String(layer.proofDays)} days.`);\n }\n }\n const kinds = new Set(layer.kinds);\n for (const part of stack.parts) {\n if (kinds.has(part.kind) && !seen.has(part.id)) add(\"part-no-service\", part.id, `The part \"${part.id}\" has the kind \"${part.kind}\", and it has no cost record.`);\n }\n return faults;\n}\n","import { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { SPEND_SCHEMA, type SpendLayer } from \"./layer.ts\";\n\n// The join of the spend layers of the fragments of a stack, for example one file of cost records for each owner.\n\n/**\n * This function joins the spend layers of the fragments of a stack into one layer.\n *\n * - The cost records are in the order of the fragments. The record of a part is in one fragment.\n * - A part with a record in two or more fragments is a fault, also when the records are equal.\n * - The layer has one currency and one largest age of a proof. A fragment with a different value is a fault.\n * - The count of days of warning before the end of a plan is one value too. A fragment with no value takes the value of the others.\n * - The kinds are the kinds of each fragment, one time each, in the order of the fragments.\n *\n * The kinds of the joined layer hold for each part of the joined stack. Thus a kind of one fragment needs a cost\n * record also for the parts of that kind in the other fragments. The function is pure, and it changes no layer.\n * The gate `checkSpend` 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. An empty list of layers is a fault.\n */\nexport function joinSpend(pieces: readonly LayerPiece<SpendLayer>[]): LayerParse<SpendLayer> {\n const currency = joinSetting(pieces, (layer) => layer.currency, \"currency\");\n const proofDays = joinSetting(pieces, (layer) => layer.proofDays, \"largest age of a proof in days\");\n const endDays = joinSetting(pieces, (layer) => layer.endDays, \"count of days of warning before the end of a plan\");\n const services = joinRecords(\n pieces,\n (layer) => layer.services,\n (service) => service.part,\n \"cost record of the part\",\n );\n if (currency.value === undefined || proofDays.value === undefined) return { ok: false, errors: [\"The join of spend layers got no layer.\"] };\n const errors = [...currency.errors, ...proofDays.errors, ...endDays.errors, ...services.errors];\n if (errors.length > 0) return { ok: false, errors };\n const kinds = [...new Set(pieces.flatMap((piece) => piece.layer.kinds))];\n return {\n ok: true,\n layer: {\n schema: SPEND_SCHEMA,\n currency: currency.value,\n kinds,\n proofDays: proofDays.value,\n ...(endDays.value === undefined ? {} : { endDays: endDays.value }),\n services: services.items,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,aAA6D;CAAC;CAAS;CAAW;CAAS;AAAM;;AAM9G,SAAS,OAAO,MAAsB;CACpC,OAAO,IAAI,MAAM,IAAI,MAAM,GAAG,IAAI,IAAI,CAAC;AACzC;;AAGA,SAAS,QAAQ,MAAoB;CACnC,OAAO,IAAI,MAAM,IAAI,OAAO,GAAG,IAAI,IAAI,CAAC;AAC1C;;AAGA,MAAM,YAAkB,IAAI,WAAW,IAAI,UAAU,GAAG,IAAI,KAAK,CAAC;;;;;AAMlE,MAAa,UAAgB,IAAI,MAAM,IAAI,MAAM,QAAQ,UAAU,GAAG,QAAQ,MAAM,CAAC,GAAG,IAAI,OAAO,QAAQ,SAAS,GAAG,IAAI,OAAO,SAAS,CAAC,CAAC;;AAG7I,MAAM,SAAe,KAAK,MAAM,KAAK,UAAU,OAAO,OAAO,CAAC;;AAG9D,MAAa,cAAoB,KAAK,MAAM,QAAQ,OAAO;;AAG3D,MAAM,eAAqB,KAAK,aAAa,IAAI,QAAQ,CAAC;;AAG1D,MAAa,aAAmB,IAAI,SAAS,YAAY;;;;;AAMzD,MAAa,aAAmB,IAAI,OAAO,YAAY;;AAGvD,SAAS,UAAU,SAAuB;CACxC,OAAO,IAAI,MAAM,IAAI,SAAS,GAAG,IAAI,OAAO,CAAC;AAC/C;;;;;;;;AASA,MAAa,WAAiB,IAAI,MAAM,UAAU,MAAM,GAAG,IAAI,CAA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