@mark1russell7/stack-spend 0.1.5 → 0.1.7
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 +15 -4
- package/build/add-on.d.ts +2 -2
- package/build/add-on.js +1 -1
- package/build/{check-CpHvgGvh.d.ts → check-Dh9mPQSu.d.ts} +4 -3
- package/build/check-Dh9mPQSu.d.ts.map +1 -0
- package/build/index.d.ts +6 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -3
- package/build/index.js.map +1 -1
- package/build/{join-BsjQ9eKd.js → join-98opeDSl.js} +12 -4
- package/build/join-98opeDSl.js.map +1 -0
- package/build/{layer-BYSJfC_1.d.ts → layer-Dm7OM6CQ.d.ts} +14 -2
- package/build/layer-Dm7OM6CQ.d.ts.map +1 -0
- package/build/reads-BNyUIVaY.js.map +1 -1
- package/build/schema.d.ts +1 -1
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +6 -1
- package/build/schema.js.map +1 -1
- package/package.json +2 -2
- package/build/check-CpHvgGvh.d.ts.map +0 -1
- package/build/join-BsjQ9eKd.js.map +0 -1
- package/build/layer-BYSJfC_1.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -134,7 +134,7 @@ checkSpend(SAMPLE_SPEND, SAMPLE_STACK, { today: SAMPLE_TODAY }).map((fault) => `
|
|
|
134
134
|
| `limit-recharge` | error | A prepaid balance gets money automatically. |
|
|
135
135
|
| `limit-stop` | error | A stop by code does not name the part of the stack that stops the use. |
|
|
136
136
|
| `limit-wanted` | error | A wanted limit is not in force. |
|
|
137
|
-
| `end-date` | error | The date of the end of a plan is not a date. |
|
|
137
|
+
| `end-date` | error | The date of the end of a plan is not a date. The date of its decision is not a date, or it is after `today`. |
|
|
138
138
|
| `end-past` | error | The plan ended before the date of the check. The record gives the cost before the end. |
|
|
139
139
|
| `end-soon` | warning | The plan ends in `endDays` days, or fewer. |
|
|
140
140
|
| `end-open` | error | The cost after the end of a plan grows with the use, and it has no hard limit. |
|
|
@@ -152,10 +152,12 @@ A trial, a free credit or a term ends on a date. The field `ends` of a cost reco
|
|
|
152
152
|
| --- | --- |
|
|
153
153
|
| `date` | The last day of the plan, as `YYYY-MM-DD`. |
|
|
154
154
|
| `next` | The cost after the end: its `plan`, its `billing`, its `price` and its `limits`. A service that stops has none. |
|
|
155
|
+
| `decided` | The decision of the owner that the result after the end is wanted: its `date` and the person in `by`. |
|
|
155
156
|
|
|
156
157
|
- With no `next`, the provider stops the service after the date, and it takes no money. The part does not work after the date.
|
|
157
158
|
- With a `next`, the service continues after the date, with the cost of `next`.
|
|
158
159
|
- The rule holds for the cost of `next` too: a `metered` cost must have a hard limit.
|
|
160
|
+
- With a `decided`, the end gives no step to the owner. A cost after the end with no hard limit stays a fault.
|
|
159
161
|
|
|
160
162
|
`SAMPLE_ENDS` of the package is a layer for `SAMPLE_STACK` with two plans that end:
|
|
161
163
|
|
|
@@ -197,6 +199,15 @@ The free credit of the call account ends with no plan after it. The provider tak
|
|
|
197
199
|
- The warning starts `endDays` days before the last day of the plan. The default is `END_DAYS`, 30 days.
|
|
198
200
|
- After the last day, the fault is `end-past`: the record gives the old plan. The owner reads the account again.
|
|
199
201
|
- A plan that ends later than the days of warning gives no fault. The fault `end-open` does not wait for the days of warning.
|
|
202
|
+
- The warning tells the decision of the owner, when the record has one. The fault `end-date` finds a decision with a date that is not valid.
|
|
203
|
+
|
|
204
|
+
The owner of the call account decides that the stop is wanted. The record keeps the decision:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
const decided = { part: "call-account", plan: "A free credit", billing: "free", ends: { date: "2026-11-30", decided: { date: "2026-11-12", by: "The owner" } }, proof };
|
|
208
|
+
// The warning: 'The plan of "call-account" ends on 2026-11-30, in 14 days. Then the provider stops the service. The owner decided this on 2026-11-12.'
|
|
209
|
+
// `ownerSteps` gives no step for this end, and `planEnds` gives `decided: true` for it.
|
|
210
|
+
```
|
|
200
211
|
- The faults `price`, `amount` and `limit-stop` examine the cost of `next` too.
|
|
201
212
|
|
|
202
213
|
### The parts that stop
|
|
@@ -209,8 +220,8 @@ import { SAMPLE_STACK } from "@mark1russell7/system-stack";
|
|
|
209
220
|
|
|
210
221
|
planEnds(SAMPLE_ENDS, { today: SAMPLE_TODAY });
|
|
211
222
|
// => [
|
|
212
|
-
// { part: "call-account", date: "2026-11-30", days: 14, stops: true },
|
|
213
|
-
// { part: "cloud-account", date: "2026-12-01", days: 15, stops: false },
|
|
223
|
+
// { part: "call-account", date: "2026-11-30", days: 14, stops: true, decided: false },
|
|
224
|
+
// { part: "cloud-account", date: "2026-12-01", days: 15, stops: false, decided: false },
|
|
214
225
|
// ]
|
|
215
226
|
|
|
216
227
|
endStops(SAMPLE_ENDS, SAMPLE_STACK, { today: SAMPLE_TODAY });
|
|
@@ -274,7 +285,7 @@ ownerSteps(SAMPLE_SPEND, SAMPLE_STACK, { today: SAMPLE_TODAY });
|
|
|
274
285
|
| --- | --- |
|
|
275
286
|
| `limit-wanted` | Set the wanted limit in the account. A wanted stop by code is the work of a programmer, so it gives no step. |
|
|
276
287
|
| `limit-recharge` | Stop the automatic recharge of the balance. |
|
|
277
|
-
| `end-soon` | Decide before the date. A service with no plan after the end stops, and the cost of each other service changes. |
|
|
288
|
+
| `end-soon` | Decide before the date. A service with no plan after the end stops, and the cost of each other service changes. An end with a `decided` gives no step. |
|
|
278
289
|
| `end-open` | Set a hard limit for the cost after the end, or stop the service before the date. Then `end-soon` gives no second step. |
|
|
279
290
|
| `end-past`, `proof-none`, `proof-old` | Read the plan and the limits in the account, and give them with the date of the read. |
|
|
280
291
|
|
package/build/add-on.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as SpendOptions } from "./check-
|
|
2
|
-
import {
|
|
1
|
+
import { i as SpendOptions } from "./check-Dh9mPQSu.js";
|
|
2
|
+
import { p as SpendLayer } from "./layer-Dm7OM6CQ.js";
|
|
3
3
|
import { StackJoiner } from "@mark1russell7/system-stack";
|
|
4
4
|
/**
|
|
5
5
|
* This function gives the spend add-on for a check on one date.
|
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-98opeDSl.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";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as SpendLayer } from "./layer-Dm7OM6CQ.js";
|
|
2
2
|
import { Fault, Stack, dayNumber } from "@mark1russell7/system-stack";
|
|
3
3
|
/** These are the codes of the faults of a spend layer. */
|
|
4
4
|
declare const SPEND_CODES: readonly ["service-part", "service-duplicate", "part-no-service", "price", "amount", "limit-none", "limit-alert", "limit-recharge", "limit-stop", "limit-wanted", "end-date", "end-past", "end-soon", "end-open", "proof-none", "proof-date", "proof-old"];
|
|
@@ -31,9 +31,10 @@ interface SpendOptions {
|
|
|
31
31
|
* - `limit-wanted`: a wanted limit is not in force.
|
|
32
32
|
*
|
|
33
33
|
* The end of a plan:
|
|
34
|
-
* - `end-date`: the date of an end is not a date.
|
|
34
|
+
* - `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`.
|
|
35
35
|
* - `end-past`: the plan ended before `today`. The record gives the cost before the end, so it is not correct.
|
|
36
36
|
* - `end-soon`: the plan ends in `endDays` days, or fewer. This fault is a warning: it does not stop the gate.
|
|
37
|
+
* Its message tells the decision of the owner, when the record has one.
|
|
37
38
|
* - `end-open`: the cost after the end grows with the use, and it has no hard limit.
|
|
38
39
|
*
|
|
39
40
|
* The proofs:
|
|
@@ -48,4 +49,4 @@ interface SpendOptions {
|
|
|
48
49
|
*/
|
|
49
50
|
declare function checkSpend(layer: SpendLayer, stack: Stack, options: SpendOptions): SpendFault[];
|
|
50
51
|
export { checkSpend as a, SpendOptions as i, SpendCode as n, dayNumber as o, SpendFault as r, SPEND_CODES as t };
|
|
51
|
-
//# sourceMappingURL=check-
|
|
52
|
+
//# sourceMappingURL=check-Dh9mPQSu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-Dh9mPQSu.d.ts","names":[],"sources":["../src/check.ts"],"mappings":";;;cAOa;;KAuCD,oBAAoB;;UAGf,mBAAmB;WACzB,MAAM;;;UAIA;;WAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmDK,WAAW,OAAO,YAAY,OAAO,OAAO,SAAS,eAAe"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as checkSpend, i as SpendOptions, n as SpendCode, o as dayNumber, r as SpendFault, t as SPEND_CODES } from "./check-
|
|
1
|
+
import { a as LIMIT_KINDS, c as NextPlan, d as SPEND_SCHEMA, f as Service, i as EndDecision, l as PlanEnd, n as Billing, o as Limit, p as SpendLayer, r as END_DAYS, s as LimitKind, t as BILLINGS, u as Proof } from "./layer-Dm7OM6CQ.js";
|
|
2
|
+
import { a as checkSpend, i as SpendOptions, n as SpendCode, o as dayNumber, r as SpendFault, t as SPEND_CODES } from "./check-Dh9mPQSu.js";
|
|
3
3
|
import { a as UseSource, i as UseRead, n as USE_SOURCES, r as UseOptions, t as USE_LEVELS } from "./reads-HuHaDiHO.js";
|
|
4
4
|
import { Axis, Expr, Result, Space } from "@mark1russell7/vex";
|
|
5
5
|
import { Fault, LayerParse, LayerPiece, Stack } from "@mark1russell7/system-stack";
|
|
@@ -121,6 +121,8 @@ export interface PlanEndState {
|
|
|
121
121
|
readonly days: number;
|
|
122
122
|
/** This field tells if the provider stops the service after the date: the record gives no plan after the end. */
|
|
123
123
|
readonly stops: boolean;
|
|
124
|
+
/** This field tells if the record has the decision of the owner about the end. An end with no decision is work of the owner. */
|
|
125
|
+
readonly decided: boolean;
|
|
124
126
|
}
|
|
125
127
|
/**
|
|
126
128
|
* This function gives the end of the plan of each service that has one, with the nearest date first.
|
|
@@ -200,6 +202,7 @@ export interface OwnerStep {
|
|
|
200
202
|
* - `limit-wanted`: set the wanted limit in the account. A wanted stop by code is the work of a programmer, so it gives no step.
|
|
201
203
|
* - `limit-recharge`: stop the automatic recharge of the balance.
|
|
202
204
|
* - `end-soon`: decide before the date. A service with no plan after the end stops, and the cost of each other service changes.
|
|
205
|
+
* An end with a decision (`ends.decided`) gives no step.
|
|
203
206
|
* - `end-open`: set a hard limit for the cost after the end, or stop the service before the date. Then `end-soon` gives no second step.
|
|
204
207
|
* - `end-past`, `proof-none` and `proof-old`: read the plan and the limits in the account, and give them with the date.
|
|
205
208
|
*
|
|
@@ -329,5 +332,5 @@ export declare const SAMPLE_ENDS: SpendLayer;
|
|
|
329
332
|
* The provider of the call account shows more than the stack counted, and the used amount is at 50 percent of the hard limit, or more.
|
|
330
333
|
*/
|
|
331
334
|
export declare const SAMPLE_READS: readonly UseRead[];
|
|
332
|
-
export { BILLINGS, Billing, END_DAYS, LIMIT_KINDS, Limit, LimitKind, NextPlan, PlanEnd, Proof, SPEND_CODES, SPEND_SCHEMA, Service, SpendCode, SpendFault, SpendLayer, SpendOptions, USE_LEVELS, USE_SOURCES, UseOptions, UseRead, UseSource, checkSpend, dayNumber };
|
|
335
|
+
export { BILLINGS, Billing, END_DAYS, EndDecision, LIMIT_KINDS, Limit, LimitKind, NextPlan, PlanEnd, Proof, SPEND_CODES, SPEND_SCHEMA, Service, SpendCode, SpendFault, SpendLayer, SpendOptions, USE_LEVELS, USE_SOURCES, UseOptions, UseRead, UseSource, checkSpend, dayNumber };
|
|
333
336
|
//# sourceMappingURL=index.d.ts.map
|
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;;qBCvFf;;wBAKG,WAAW;;;;;wBAUX,QAAQ;;wBAgBR,cAAc,OAAO,sBAAsB;;;;;;;;;;;;wBAoB3C,WAAW,OAAO,aAAa;;;;;wBAmC/B,gBAAgB,SAAS,MAAM,MAAM,OAAO,eAAe;;;;;wBAQ3D,aAAa,SAAS,MAAM,MAAM,OAAO,eAAe;;iBAKvD;;WAEN;WACA,SAAS;;WAET;;WAEA;;;;;WAKA;;;wBAIK,cAAc,OAAO,aAAa;;iBAiBjC;;WAEN;;WAEA;;;;;;wBAOK,WAAW,OAAO,aAAa;;iBC/I9B;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;;;;;;;wBAaK,SAAS,OAAO,YAAY,SAAS,eAAe;;iBAenD,mBAAmB;;;;;WAKzB;;;iBAIM;;WAEN;;WAEA;;;;;;;;;;;;;;wBAeK,SAAS,OAAO,YAAY,OAAO,OAAO,SAAS,aAAa;;;;;;;;;;;;;;;;;
|
|
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;;qBCvFf;;wBAKG,WAAW;;;;;wBAUX,QAAQ;;wBAgBR,cAAc,OAAO,sBAAsB;;;;;;;;;;;;wBAoB3C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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-98opeDSl.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
|
|
@@ -25,7 +25,8 @@ function planEnds(layer, options) {
|
|
|
25
25
|
part: service.part,
|
|
26
26
|
date: service.ends.date,
|
|
27
27
|
days: end - today,
|
|
28
|
-
stops: service.ends.next === void 0
|
|
28
|
+
stops: service.ends.next === void 0,
|
|
29
|
+
decided: service.ends.decided !== void 0
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
return ends.sort((first, second) => first.days - second.days);
|
|
@@ -79,6 +80,7 @@ function endText(ends) {
|
|
|
79
80
|
* - `limit-wanted`: set the wanted limit in the account. A wanted stop by code is the work of a programmer, so it gives no step.
|
|
80
81
|
* - `limit-recharge`: stop the automatic recharge of the balance.
|
|
81
82
|
* - `end-soon`: decide before the date. A service with no plan after the end stops, and the cost of each other service changes.
|
|
83
|
+
* An end with a decision (`ends.decided`) gives no step.
|
|
82
84
|
* - `end-open`: set a hard limit for the cost after the end, or stop the service before the date. Then `end-soon` gives no second step.
|
|
83
85
|
* - `end-past`, `proof-none` and `proof-old`: read the plan and the limits in the account, and give them with the date.
|
|
84
86
|
*
|
|
@@ -97,7 +99,7 @@ function ownerSteps(layer, stack, options) {
|
|
|
97
99
|
const service = services.get(fault.at);
|
|
98
100
|
if (code === void 0 || service === void 0) continue;
|
|
99
101
|
if (code === "limit-wanted" && service.wanted?.kind === "code") continue;
|
|
100
|
-
if (code === "end-soon" && open.has(fault.at)) continue;
|
|
102
|
+
if (code === "end-soon" && (open.has(fault.at) || service.ends?.decided !== void 0)) continue;
|
|
101
103
|
let text = "Read the plan and the limits in the account, and give them with the date of the read.";
|
|
102
104
|
if (code === "limit-recharge") text = "Stop the automatic recharge of the prepaid balance.";
|
|
103
105
|
if (code === "limit-wanted" && service.wanted !== void 0) text = wantedText(service.wanted, layer.currency);
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["dayNumber","dayNumber"],"sources":["../src/ends.ts","../src/steps.ts","../src/use-plan.ts","../src/use.ts","../src/use-check.ts","../src/sample.ts"],"sourcesContent":["import { dayNumber, stopped, type Stack } from \"@mark1russell7/system-stack\";\nimport type { SpendOptions } from \"./check.ts\";\nimport { END_DAYS, type SpendLayer } from \"./layer.ts\";\nimport { firstServices } from \"./states.ts\";\n\n// The ends of the plans of a layer, as queries. The gate `checkSpend` gives the faults of an end, and these\n// functions give the dates and the parts of the stack that stop.\n\n/** The end of the plan of one service, from the date of a check. */\nexport interface PlanEndState {\n /** The `id` of the part of the service. */\n readonly part: string;\n /** The last day of the plan, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The count of days from the date of the check to the last day. A plan that ended gives a count below 0. */\n readonly days: number;\n /** This field tells if the provider stops the service after the date: the record gives no plan after the end. */\n readonly stops: boolean;\n}\n\n/**\n * This function gives the end of the plan of each service that has one, with the nearest date first.\n *\n * - Two ends on one date are in the sequence of the records. The first record of a part is used.\n * - A record whose date is not a date is not in the result. The gate gives the fault `end-date` for it.\n *\n * The function is pure. It has no clock: the caller gives the date.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`\n */\nexport function planEnds(layer: SpendLayer, options: SpendOptions): PlanEndState[] {\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 ends: PlanEndState[] = [];\n for (const service of firstServices(layer)) {\n if (service.ends === undefined) continue;\n const end = dayNumber(service.ends.date);\n if (end === undefined) continue;\n ends.push({ part: service.part, date: service.ends.date, days: end - today, stops: service.ends.next === undefined });\n }\n // The sort of an array is stable, so two ends on one date keep the sequence of the records.\n return ends.sort((first, second) => first.days - second.days);\n}\n\n/** The options of `endStops`. */\nexport interface EndOptions extends SpendOptions {\n /**\n * The largest count of days from `today` to the last day of a plan, for a plan to be in the result.\n * The default is the `endDays` of the layer, or `END_DAYS`. Thus the default result agrees with the fault `end-soon` of the gate.\n */\n readonly days?: number | undefined;\n}\n\n/** The parts of a stack that stop at the ends of the plans of a layer. */\nexport interface EndStops {\n /** The `id` of the part of each service that its provider stops, with the nearest date first. */\n readonly ended: readonly string[];\n /** The `id` of each part of the stack that stops when the parts of `ended` do not work, in the order of the parts. */\n readonly stopped: readonly string[];\n}\n\n/**\n * This function gives the parts of a stack that stop when the plans that end in `days` days, or fewer, come to their end.\n *\n * - A plan that ended before `today` is in the result too.\n * - A service with a plan after the end does not stop: its cost changes.\n * - `stopped` comes from the needs of the stack: `stopped` of the core, with the parts of `ended` down.\n *\n * For the parts that stop with one service, use `stopped` of the core with the `id` of its part.\n * The function is pure.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`\n */\nexport function endStops(layer: SpendLayer, stack: Stack, options: EndOptions): EndStops {\n const days = options.days ?? layer.endDays ?? END_DAYS;\n const ended = planEnds(layer, options)\n .filter((end) => end.stops && end.days <= days)\n .map((end) => end.part);\n return { ended, stopped: stopped(stack, ended) };\n}\n","import { partsById, type Stack } from \"@mark1russell7/system-stack\";\nimport { checkSpend, type SpendOptions } from \"./check.ts\";\nimport type { Limit, PlanEnd, SpendLayer } from \"./layer.ts\";\n\n// The work of the owner of the accounts, from the faults of the gate. A program cannot change these settings.\n\n/** These are the codes of the faults that the owner of an account corrects in the account of the service. */\nexport const OWNER_CODES: readonly [\"limit-wanted\", \"limit-recharge\", \"end-past\", \"end-soon\", \"end-open\", \"proof-none\", \"proof-old\"] = [\n \"limit-wanted\",\n \"limit-recharge\",\n \"end-past\",\n \"end-soon\",\n \"end-open\",\n \"proof-none\",\n \"proof-old\",\n];\n\n/** A code of a fault that the owner of an account corrects. */\nexport type OwnerCode = (typeof OWNER_CODES)[number];\n\n/** One piece of work of the owner of an account. */\nexport interface OwnerStep {\n /** The `id` of the part of the service. */\n readonly part: string;\n /** The name of the part, or its `id`. */\n readonly name: string;\n readonly code: OwnerCode;\n /** The work, in one sentence. */\n readonly text: string;\n /** The steps in the account of the service, from the record. */\n readonly steps: readonly string[];\n}\n\n/** This function gives the sentence for a wanted limit that the owner sets in the account. */\nfunction wantedText(limit: Limit, currency: string): string {\n const amount = `${String(limit.amount)} ${currency}`;\n if (limit.kind === \"provider\") return `Set a hard limit of ${amount} for a month.`;\n if (limit.kind === \"prepaid\") return `Keep a prepaid balance of ${amount} at most, with no automatic recharge.`;\n return `Set an alert at ${amount} for a month.`;\n}\n\n/** This function gives the sentence for a plan that ends soon. */\nfunction endText(ends: PlanEnd): string {\n if (ends.next === undefined) return `Decide before ${ends.date} if the service continues. With no change, the provider stops it after that date.`;\n return `Stop the service before ${ends.date} if the cost after that date is not wanted.`;\n}\n\n/**\n * This function gives the work of the owner of the accounts, in the sequence of the records.\n *\n * - `limit-wanted`: set the wanted limit in the account. A wanted stop by code is the work of a programmer, so it gives no step.\n * - `limit-recharge`: stop the automatic recharge of the balance.\n * - `end-soon`: decide before the date. A service with no plan after the end stops, and the cost of each other service changes.\n * - `end-open`: set a hard limit for the cost after the end, or stop the service before the date. Then `end-soon` gives no second step.\n * - `end-past`, `proof-none` and `proof-old`: read the plan and the limits in the account, and give them with the date.\n *\n * Each other fault of the gate is a fault of the records, which their writer corrects.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`\n */\nexport function ownerSteps(layer: SpendLayer, stack: Stack, options: SpendOptions): OwnerStep[] {\n const parts = partsById(stack);\n const services = new Map(layer.services.map((service) => [service.part, service] as const).reverse());\n const steps: OwnerStep[] = [];\n const faults = checkSpend(layer, stack, options);\n const open = new Set(faults.filter((fault) => fault.code === \"end-open\").map((fault) => fault.at));\n for (const fault of faults) {\n const code = OWNER_CODES.find((item) => item === fault.code);\n const service = services.get(fault.at);\n if (code === undefined || service === undefined) continue;\n if (code === \"limit-wanted\" && service.wanted?.kind === \"code\") continue;\n if (code === \"end-soon\" && open.has(fault.at)) continue;\n let text = \"Read the plan and the limits in the account, and give them with the date of the read.\";\n if (code === \"limit-recharge\") text = \"Stop the automatic recharge of the prepaid balance.\";\n if (code === \"limit-wanted\" && service.wanted !== undefined) text = wantedText(service.wanted, layer.currency);\n if (code === \"end-soon\" && service.ends !== undefined) text = endText(service.ends);\n if (code === \"end-open\" && service.ends !== undefined) text = `Set a hard limit for the cost after ${service.ends.date}, or stop the service before that date.`;\n steps.push({ part: fault.at, name: parts.get(fault.at)?.name ?? fault.at, code, text, steps: service.steps ?? [] });\n }\n return steps;\n}\n","import { dayNumber } from \"@mark1russell7/system-stack\";\nimport type { SpendLayer } from \"./layer.ts\";\nimport { USE_LEVELS, type UseOptions, type UseRead } from \"./reads.ts\";\n\n// The examination of the options and of each read. This module is internal: no entry exports it.\n// `useSpace` and `checkUse` use it, so the tree and the gate agree on the reads with a fault.\n\n/** These are the codes of the faults of one read. */\nexport const READ_CODES: readonly [\"read-part\", \"read-amount\", \"read-date\"] = [\"read-part\", \"read-amount\", \"read-date\"];\n\n/** A code of a fault of one read. */\nexport type ReadCode = (typeof READ_CODES)[number];\n\n/** The options with their defaults, and the fault of each read. */\nexport interface UsePlan {\n /** The number of the day of the check. */\n readonly today: number;\n /** The month of the check, as `YYYY-MM`. */\n readonly month: string;\n readonly levels: readonly number[];\n readonly readDays: number | undefined;\n /** The fault of each read, in the sequence of the reads. A read with no fault has `undefined`. */\n readonly codes: readonly (ReadCode | undefined)[];\n /** The age of each read in days, in the sequence of the reads. A read with a fault of its date has `undefined`. */\n readonly ages: readonly (number | undefined)[];\n}\n\n/** This function gives the month of a date `YYYY-MM-DD`, as `YYYY-MM`. */\nexport function monthOf(date: string): string {\n return date.slice(0, 7);\n}\n\n/**\n * This function examines the options and each read.\n *\n * - `read-part`: the read names a part with no cost record.\n * - `read-amount`: the amount is less than 0 or not finite.\n * - `read-date`: the date is not a date, or it is after the date of the check.\n *\n * A read has one code at most: the first fault of this list.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid\n */\nexport function usePlan(layer: SpendLayer, reads: readonly UseRead[], options: UseOptions): UsePlan {\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 levels = options.levels ?? USE_LEVELS;\n for (const level of levels) {\n if (!Number.isFinite(level) || level <= 0) throw new RangeError(`The level ${String(level)} is not a finite number above 0.`);\n }\n const readDays = options.readDays;\n if (readDays !== undefined && (!Number.isFinite(readDays) || readDays < 0)) throw new RangeError(`The largest age ${String(readDays)} of a read is less than 0 or not finite.`);\n const parts = new Set(layer.services.map((service) => service.part));\n const days = reads.map((read) => dayNumber(read.date));\n const ages = days.map((day) => (day === undefined || day > today ? undefined : today - day));\n const codes = reads.map((read, index): ReadCode | undefined => {\n if (!parts.has(read.part)) return \"read-part\";\n if (!Number.isFinite(read.amount) || read.amount < 0) return \"read-amount\";\n return ages[index] === undefined ? \"read-date\" : undefined;\n });\n return { today, month: monthOf(options.today), levels, readDays, codes, ages };\n}\n","import { app, axes, each, let_, lit, parent, ref, space, v, type Axis, type Expr, type Space } from \"@mark1russell7/vex\";\nimport type { Billing, SpendLayer } from \"./layer.ts\";\nimport type { UseOptions, UseRead, UseSource } from \"./reads.ts\";\nimport { evaluateService, firstServices, LAYER_KEY, serviceKey, serviceStates } from \"./states.ts\";\nimport { monthOf, usePlan } from \"./use-plan.ts\";\nimport { booleanOf, numberOf } from \"./values.ts\";\n\n// The used amount of each service in a month, from the reads. The rule: the used amount is the larger of the count of\n// the stack and the amount of the provider. Each formula is a Vex program on the tree that `useSpace` makes.\n\n/** This test tells if a read node is of the month of the layer node. The program evaluates at a read. */\nconst IN_MONTH: Expr = app(\"eq\", ref(\"month\"), ref(\"month\", [parent, parent]));\n\n/** The reads of a service in the month of the check. */\nexport const MONTH_READS: Axis = axes.where(axes.children, IN_MONTH);\n\n/** This function gives the amount of each read of one source, for a service in the month of the check. */\nfunction amountsOf(source: UseSource): Expr {\n return each(axes.where(MONTH_READS, app(\"eq\", ref(\"source\"), lit(source))), ref(\"amount\"));\n}\n\n/** The largest amount that a part of the stack counted for a service in the month. With no such read, it gives `#N/A`. */\nexport const COUNT_USED: Expr = app(\"max\", amountsOf(\"count\"));\n\n/** The largest amount that the provider showed for a service in the month. With no such read, it gives `#N/A`. */\nexport const PROVIDER_USED: Expr = app(\"max\", amountsOf(\"provider\"));\n\n/**\n * The used amount of a service in the month: the larger of the count of the stack and the amount of the provider.\n * It is the largest amount of the reads of the month, because the cost of a month does not go down.\n * With no read of the month, it gives `#N/A`.\n */\nexport const USED: Expr = app(\"max\", each(MONTH_READS, ref(\"amount\")));\n\n/** The used share of the hard limit of a service: the used amount divided by the limit. With no read or no limit, it gives an error value. */\nexport const USE_SHARE: Expr = app(\"divide\", USED, ref(\"limit\"));\n\n/** This test tells if the used amount of a service is more than its hard limit. Such a limit did not hold. */\nexport const USE_OVER: Expr = app(\"gt\", USED, ref(\"limit\"));\n\n/**\n * The tolerance of the comparison of a share with a level. A share reaches a level when it is the level less this\n * tolerance, or more. Thus the rounding of a division does not hide a level: 2.4 of 3 reaches the level 0.8.\n */\nexport const LEVEL_TOLERANCE = 1e-9;\n\n/**\n * The largest level that the used share of a service reached. A share below each level gives 0.\n * With no read or no limit, it gives `#N/A`. The levels are in the field `levels` of the layer node.\n */\nexport const USE_LEVEL: Expr = let_(\n { share: app(\"add\", USE_SHARE, lit(LEVEL_TOLERANCE)) },\n app(\"max\", each(axes.list(ref(\"levels\", [parent])), app(\"if\", app(\"lte\", v(\"level\"), v(\"share\")), v(\"level\"), lit(0)), undefined, [\"level\"])),\n);\n\n/** The age of the newest read of a service in the month, in days. With no read of the month, it gives `#N/A`. */\nexport const READ_AGE: Expr = app(\"min\", each(MONTH_READS, ref(\"age\")));\n\n/**\n * This function gives the tree of the reads of a layer, as a space of Vex.\n *\n * - The layer is the root, with the key `LAYER_KEY`. Its fields are `month` (the month of the check) and `levels`.\n * - A service is a child of the layer. Its fields are `billing` and `limit`: its hard limit, from `serviceStates`.\n * - A read is a child of its service. Its fields are `source`, `amount`, `month` and `age`: the days from its date to the check.\n *\n * A read with a fault is not in the tree, and `checkUse` tells the fault. The first record of a part is used.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid\n */\nexport function useSpace(layer: SpendLayer, reads: readonly UseRead[], options: UseOptions): Space {\n const plan = usePlan(layer, reads, options);\n const limits = new Map(serviceStates(layer).map((state) => [state.part, state.hardLimit] as const));\n const records: Record<string, Readonly<Record<string, unknown>>> = { [LAYER_KEY]: { kind: \"layer\", month: plan.month, levels: [...plan.levels] } };\n const parents: Record<string, string | null> = { [LAYER_KEY]: null };\n for (const service of firstServices(layer)) {\n const key = serviceKey(service.part);\n const limit = limits.get(service.part);\n records[key] = { kind: \"service\", billing: service.billing, ...(limit === undefined ? {} : { limit }) };\n parents[key] = LAYER_KEY;\n }\n reads.forEach((read, index) => {\n if (plan.codes[index] !== undefined) return;\n const key = `read:${String(index)}`;\n records[key] = { kind: \"read\", source: read.source, amount: read.amount, month: monthOf(read.date), age: plan.ages[index] };\n parents[key] = serviceKey(read.part);\n });\n return space.tree(records, parents);\n}\n\n/** The state of the used amount of one service in the month of the check. A field with no known value is absent. */\nexport interface UseState {\n /** The `id` of the part of the service. */\n readonly part: string;\n readonly billing: Billing;\n /** The largest amount that a part of the stack counted in the month. */\n readonly count?: number | undefined;\n /** The largest amount that the provider showed in the month. */\n readonly provider?: number | undefined;\n /** The used amount of the month: the larger of `count` and `provider`. A service with no read of the month has none. */\n readonly used?: number | undefined;\n /** The hard limit of the service for a month. */\n readonly limit?: number | undefined;\n /** The used share of the hard limit: `used` divided by `limit`. */\n readonly share?: number | undefined;\n /** The largest level that the share reached. A share below each level has none. */\n readonly level?: number | undefined;\n /** This field tells if the used amount is more than the hard limit. */\n readonly over?: boolean | undefined;\n /** The age of the newest read of the month, in days. */\n readonly age?: number | undefined;\n}\n\n/** This function gives a record without the fields that have no value. */\nfunction known<Fields extends Record<string, unknown>>(fields: Fields): Partial<Fields> {\n return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined)) as Partial<Fields>;\n}\n\n/**\n * This function gives the state of the used amount of each service of a layer, in the sequence of the services.\n * The month is the month of `today`: a read of a different month does not count.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid\n */\nexport function useStates(layer: SpendLayer, reads: readonly UseRead[], options: UseOptions): UseState[] {\n const tree = useSpace(layer, reads, options);\n return firstServices(layer).map((service) => {\n const number = (program: Expr): number | undefined => numberOf(evaluateService(program, tree, service.part));\n const level = number(USE_LEVEL);\n return {\n part: service.part,\n billing: service.billing,\n ...known({\n count: number(COUNT_USED),\n provider: number(PROVIDER_USED),\n used: number(USED),\n limit: number(ref(\"limit\")),\n share: number(USE_SHARE),\n level: level === 0 ? undefined : level,\n over: booleanOf(evaluateService(USE_OVER, tree, service.part)),\n age: number(READ_AGE),\n }),\n };\n });\n}\n","import type { Fault, FaultLevel } from \"@mark1russell7/system-stack\";\nimport type { SpendLayer } from \"./layer.ts\";\nimport type { UseOptions, UseRead } from \"./reads.ts\";\nimport { usePlan } from \"./use-plan.ts\";\nimport { useStates } from \"./use.ts\";\n\n// The gate of the used amounts. It tells when a limit did not hold, and it gives a warning at each level of a limit.\n\n/** These are the codes of the faults of the used amounts of a layer. */\nexport const USE_CODES: readonly [\"read-part\", \"read-amount\", \"read-date\", \"use-billing\", \"use-over\", \"use-level\", \"use-count\", \"use-none\", \"use-old\"] = [\n \"read-part\",\n \"read-amount\",\n \"read-date\",\n \"use-billing\",\n \"use-over\",\n \"use-level\",\n \"use-count\",\n \"use-none\",\n \"use-old\",\n];\n\n/** A code of a fault of the used amounts of a layer. */\nexport type UseCode = (typeof USE_CODES)[number];\n\n/** A fault of the used amounts of a layer. Its field `at` is the `id` of the part. */\nexport interface UseFault extends Fault {\n readonly code: UseCode;\n}\n\n/** This function gives a share as a text in percent, for example `80` for 0.8. */\nfunction percent(share: number): string {\n return String(Number((share * 100).toFixed(6)));\n}\n\n/**\n * This function gives each fault of the used amounts of a layer. A list with no error tells that the gate passes.\n *\n * The reads, as errors:\n * - `read-part`: a read names a part with no cost record.\n * - `read-amount`: the amount of a read is less than 0 or not finite.\n * - `read-date`: the date of a read is not a date, or it is after `today`.\n *\n * The services, as errors:\n * - `use-billing`: a read shows a cost of the use of a `free` or `fixed` service. The cost record is not correct.\n * - `use-over`: the used amount of a `metered` service is more than its hard limit. The limit did not hold.\n *\n * The services, as warnings:\n * - `use-level`: the used amount of a `metered` service reached a level of its hard limit.\n * - `use-count`: the provider shows more than the stack counted. The count does not have all the use.\n * - `use-none`: a `metered` service has no read of the month, so its used amount is not known.\n * - `use-old`: the newest read of a `metered` service is older than `readDays`.\n *\n * A read with a fault does not count. The faults are in the sequence of the reads, then of the services. The function is pure.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid\n */\nexport function checkUse(layer: SpendLayer, reads: readonly UseRead[], options: UseOptions): UseFault[] {\n const plan = usePlan(layer, reads, options);\n const faults: UseFault[] = [];\n const add = (level: FaultLevel, code: UseCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const money = (amount: number): string => `${String(amount)} ${layer.currency}`;\n reads.forEach((read, index) => {\n const code = plan.codes[index];\n if (code === \"read-part\") add(\"error\", code, read.part, `A read names \"${read.part}\", which has no cost record.`);\n if (code === \"read-amount\") add(\"error\", code, read.part, `The amount ${String(read.amount)} of a read of \"${read.part}\" is less than 0 or not finite.`);\n if (code === \"read-date\") add(\"error\", code, read.part, `The date \"${read.date}\" of a read of \"${read.part}\" is not a date of the form YYYY-MM-DD, or it is after the date of the check, ${options.today}.`);\n });\n for (const state of useStates(layer, reads, options)) {\n const at = state.part;\n if (state.billing !== \"metered\") {\n if (state.used !== undefined && state.used > 0) {\n add(\"error\", \"use-billing\", at, `The service \"${at}\" has the billing \"${state.billing}\", and a read shows a cost of ${money(state.used)} for its use in the month ${plan.month}.`);\n }\n continue;\n }\n if (state.used === undefined) {\n add(\"warning\", \"use-none\", at, `No read gives the used amount of \"${at}\" in the month ${plan.month}.`);\n continue;\n }\n if (state.over === true && state.limit !== undefined) {\n add(\"error\", \"use-over\", at, `The used amount of \"${at}\" in the month ${plan.month} is ${money(state.used)}. Its hard limit is ${money(state.limit)}, so the limit did not hold.`);\n } else if (state.level !== undefined && state.limit !== undefined) {\n add(\"warning\", \"use-level\", at, `The used amount of \"${at}\" in the month ${plan.month} is ${money(state.used)}: ${percent(state.level)} percent of its hard limit of ${money(state.limit)}, or more.`);\n }\n if (state.count !== undefined && state.provider !== undefined && state.provider > state.count) {\n add(\"warning\", \"use-count\", at, `The provider shows ${money(state.provider)} for \"${at}\" in the month ${plan.month}, and the stack counted ${money(state.count)}. The count does not have all the use.`);\n }\n if (plan.readDays !== undefined && state.age !== undefined && state.age > plan.readDays) {\n add(\"warning\", \"use-old\", at, `The age of the newest read of \"${at}\" is ${String(state.age)}, in days. The largest age is ${String(plan.readDays)}.`);\n }\n }\n return faults;\n}\n","import { SPEND_SCHEMA, type SpendLayer } from \"./layer.ts\";\nimport type { UseRead } from \"./reads.ts\";\n\n/** The date of the check of the sample. With it, the gate gives the faults that the README shows. */\nexport const SAMPLE_TODAY = \"2026-11-16\";\n\n/**\n * A sample spend layer for `SAMPLE_STACK` of the core. Each name and each amount is an example.\n * It has two faults: the only limit of the cloud account is an alert, and the balance of the call account gets money automatically.\n */\nexport const SAMPLE_SPEND: SpendLayer = {\n schema: SPEND_SCHEMA,\n currency: \"USD\",\n kinds: [\"account\"],\n proofDays: 90,\n services: [\n {\n part: \"cloud-account\",\n plan: \"A free allowance, then a price for the use\",\n billing: \"metered\",\n limits: [{ kind: \"alert\", amount: 5 }],\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The billing page of the account\" },\n },\n {\n part: \"push-account\",\n plan: \"A license that was paid one time\",\n billing: \"fixed\",\n price: 0,\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The license page of the account\" },\n },\n {\n part: \"call-account\",\n plan: \"A price for each call\",\n billing: \"metered\",\n limits: [\n { kind: \"prepaid\", amount: 20, recharge: true },\n { kind: \"code\", amount: 10, stop: \"program-home\" },\n ],\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The billing page of the account\" },\n steps: [\"Open the billing page of the account.\", \"Stop the automatic recharge.\", \"Save the change.\"],\n },\n ],\n};\n\n/**\n * A sample spend layer for `SAMPLE_STACK` of the core, with two plans that end. Each name, each date and each amount is an example.\n *\n * - The free trial of the cloud account ends. After the end, the cost grows with the use, and its only limit is an alert.\n * - The free credit of the call account ends. The record gives no plan after the end, so the provider stops the service.\n *\n * With the date `SAMPLE_TODAY`, the two ends are in the 30 days of warning.\n */\nexport const SAMPLE_ENDS: SpendLayer = {\n schema: SPEND_SCHEMA,\n currency: \"USD\",\n kinds: [\"account\"],\n proofDays: 90,\n services: [\n {\n part: \"cloud-account\",\n plan: \"A free trial\",\n billing: \"free\",\n ends: { date: \"2026-12-01\", next: { plan: \"A price for the use\", billing: \"metered\", limits: [{ kind: \"alert\", amount: 5 }] } },\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The billing page of the account\" },\n },\n {\n part: \"push-account\",\n plan: \"A license that was paid one time\",\n billing: \"fixed\",\n price: 0,\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The license page of the account\" },\n },\n {\n part: \"call-account\",\n plan: \"A free credit, with no payment method\",\n billing: \"free\",\n ends: { date: \"2026-11-30\" },\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The billing page of the account\" },\n },\n ],\n};\n\n/**\n * Sample reads of the used amounts of `SAMPLE_SPEND`, for the date `SAMPLE_TODAY`. Each amount is an example.\n * The provider of the call account shows more than the stack counted, and the used amount is at 50 percent of the hard limit, or more.\n */\nexport const SAMPLE_READS: readonly UseRead[] = [\n { part: \"cloud-account\", source: \"provider\", amount: 0, date: \"2026-11-15\" },\n { part: \"call-account\", source: \"count\", amount: 4, date: \"2026-11-16\" },\n { part: \"call-account\", source: \"provider\", amount: 5.2, date: \"2026-11-16\" },\n];\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,SAAgB,SAAS,OAAmB,SAAuC;CACjF,MAAM,QAAQA,YAAU,QAAQ,KAAK;CACrC,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,WAAW,aAAa,QAAQ,MAAM,wCAAwC;CACjH,MAAM,OAAuB,CAAC;CAC9B,KAAK,MAAM,WAAW,cAAc,KAAK,GAAG;EAC1C,IAAI,QAAQ,SAAS,KAAA,GAAW;EAChC,MAAM,MAAMA,YAAU,QAAQ,KAAK,IAAI;EACvC,IAAI,QAAQ,KAAA,GAAW;EACvB,KAAK,KAAK;G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AAa,cAA0B;CACrC,QAAQ;CACR,UAAU;CACV,OAAO,CAAC,SAAS;CACjB,WAAW;CACX,UAAU;EACR;GACE,MAAM;GACN,MAAM;GACN,SAAS;GACT,MAAM;IAAE,MAAM;IAAc,MAAM;KAAE,MAAM;KAAuB,SAAS;KAAW,QAAQ,CAAC;MAAE,MAAM;MAAS,QAAQ;KAAE,CAAC;IAAE;GAAE;GAC9H,OAAO;IAAE,MAAM;IAAc,IAAI;IAAa,QAAQ;GAAkC;EAC1F;EACA;GACE,MAAM;GACN,MAAM;GACN,SAAS;GACT,OAAO;GACP,OAAO;IAAE,MAAM;IAAc,IAAI;IAAa,QAAQ;GAAkC;EAC1F;EACA;GACE,MAAM;GACN,MAAM;GACN,SAAS;GACT,MAAM,EAAE,MAAM,aAAa;GAC3B,OAAO;IAAE,MAAM;IAAc,IAAI;IAAa,QAAQ;GAAkC;EAC1F;CACF;AACF;;;;;AAMA,MAAa,eAAmC;CAC9C;EAAE,MAAM;EAAiB,QAAQ;EAAY,QAAQ;EAAG,MAAM;CAAa;CAC3E;EAAE,MAAM;EAAgB,QAAQ;EAAS,QAAQ;EAAG,MAAM;CAAa;CACvE;EAAE,MAAM;EAAgB,QAAQ;EAAY,QAAQ;EAAK,MAAM;CAAa;AAC9E"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["dayNumber","dayNumber"],"sources":["../src/ends.ts","../src/steps.ts","../src/use-plan.ts","../src/use.ts","../src/use-check.ts","../src/sample.ts"],"sourcesContent":["import { dayNumber, stopped, type Stack } from \"@mark1russell7/system-stack\";\nimport type { SpendOptions } from \"./check.ts\";\nimport { END_DAYS, type SpendLayer } from \"./layer.ts\";\nimport { firstServices } from \"./states.ts\";\n\n// The ends of the plans of a layer, as queries. The gate `checkSpend` gives the faults of an end, and these\n// functions give the dates and the parts of the stack that stop.\n\n/** The end of the plan of one service, from the date of a check. */\nexport interface PlanEndState {\n /** The `id` of the part of the service. */\n readonly part: string;\n /** The last day of the plan, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The count of days from the date of the check to the last day. A plan that ended gives a count below 0. */\n readonly days: number;\n /** This field tells if the provider stops the service after the date: the record gives no plan after the end. */\n readonly stops: boolean;\n /** This field tells if the record has the decision of the owner about the end. An end with no decision is work of the owner. */\n readonly decided: boolean;\n}\n\n/**\n * This function gives the end of the plan of each service that has one, with the nearest date first.\n *\n * - Two ends on one date are in the sequence of the records. The first record of a part is used.\n * - A record whose date is not a date is not in the result. The gate gives the fault `end-date` for it.\n *\n * The function is pure. It has no clock: the caller gives the date.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`\n */\nexport function planEnds(layer: SpendLayer, options: SpendOptions): PlanEndState[] {\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 ends: PlanEndState[] = [];\n for (const service of firstServices(layer)) {\n if (service.ends === undefined) continue;\n const end = dayNumber(service.ends.date);\n if (end === undefined) continue;\n ends.push({ part: service.part, date: service.ends.date, days: end - today, stops: service.ends.next === undefined, decided: service.ends.decided !== undefined });\n }\n // The sort of an array is stable, so two ends on one date keep the sequence of the records.\n return ends.sort((first, second) => first.days - second.days);\n}\n\n/** The options of `endStops`. */\nexport interface EndOptions extends SpendOptions {\n /**\n * The largest count of days from `today` to the last day of a plan, for a plan to be in the result.\n * The default is the `endDays` of the layer, or `END_DAYS`. Thus the default result agrees with the fault `end-soon` of the gate.\n */\n readonly days?: number | undefined;\n}\n\n/** The parts of a stack that stop at the ends of the plans of a layer. */\nexport interface EndStops {\n /** The `id` of the part of each service that its provider stops, with the nearest date first. */\n readonly ended: readonly string[];\n /** The `id` of each part of the stack that stops when the parts of `ended` do not work, in the order of the parts. */\n readonly stopped: readonly string[];\n}\n\n/**\n * This function gives the parts of a stack that stop when the plans that end in `days` days, or fewer, come to their end.\n *\n * - A plan that ended before `today` is in the result too.\n * - A service with a plan after the end does not stop: its cost changes.\n * - `stopped` comes from the needs of the stack: `stopped` of the core, with the parts of `ended` down.\n *\n * For the parts that stop with one service, use `stopped` of the core with the `id` of its part.\n * The function is pure.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`\n */\nexport function endStops(layer: SpendLayer, stack: Stack, options: EndOptions): EndStops {\n const days = options.days ?? layer.endDays ?? END_DAYS;\n const ended = planEnds(layer, options)\n .filter((end) => end.stops && end.days <= days)\n .map((end) => end.part);\n return { ended, stopped: stopped(stack, ended) };\n}\n","import { partsById, type Stack } from \"@mark1russell7/system-stack\";\nimport { checkSpend, type SpendOptions } from \"./check.ts\";\nimport type { Limit, PlanEnd, SpendLayer } from \"./layer.ts\";\n\n// The work of the owner of the accounts, from the faults of the gate. A program cannot change these settings.\n\n/** These are the codes of the faults that the owner of an account corrects in the account of the service. */\nexport const OWNER_CODES: readonly [\"limit-wanted\", \"limit-recharge\", \"end-past\", \"end-soon\", \"end-open\", \"proof-none\", \"proof-old\"] = [\n \"limit-wanted\",\n \"limit-recharge\",\n \"end-past\",\n \"end-soon\",\n \"end-open\",\n \"proof-none\",\n \"proof-old\",\n];\n\n/** A code of a fault that the owner of an account corrects. */\nexport type OwnerCode = (typeof OWNER_CODES)[number];\n\n/** One piece of work of the owner of an account. */\nexport interface OwnerStep {\n /** The `id` of the part of the service. */\n readonly part: string;\n /** The name of the part, or its `id`. */\n readonly name: string;\n readonly code: OwnerCode;\n /** The work, in one sentence. */\n readonly text: string;\n /** The steps in the account of the service, from the record. */\n readonly steps: readonly string[];\n}\n\n/** This function gives the sentence for a wanted limit that the owner sets in the account. */\nfunction wantedText(limit: Limit, currency: string): string {\n const amount = `${String(limit.amount)} ${currency}`;\n if (limit.kind === \"provider\") return `Set a hard limit of ${amount} for a month.`;\n if (limit.kind === \"prepaid\") return `Keep a prepaid balance of ${amount} at most, with no automatic recharge.`;\n return `Set an alert at ${amount} for a month.`;\n}\n\n/** This function gives the sentence for a plan that ends soon. */\nfunction endText(ends: PlanEnd): string {\n if (ends.next === undefined) return `Decide before ${ends.date} if the service continues. With no change, the provider stops it after that date.`;\n return `Stop the service before ${ends.date} if the cost after that date is not wanted.`;\n}\n\n/**\n * This function gives the work of the owner of the accounts, in the sequence of the records.\n *\n * - `limit-wanted`: set the wanted limit in the account. A wanted stop by code is the work of a programmer, so it gives no step.\n * - `limit-recharge`: stop the automatic recharge of the balance.\n * - `end-soon`: decide before the date. A service with no plan after the end stops, and the cost of each other service changes.\n * An end with a decision (`ends.decided`) gives no step.\n * - `end-open`: set a hard limit for the cost after the end, or stop the service before the date. Then `end-soon` gives no second step.\n * - `end-past`, `proof-none` and `proof-old`: read the plan and the limits in the account, and give them with the date.\n *\n * Each other fault of the gate is a fault of the records, which their writer corrects.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`\n */\nexport function ownerSteps(layer: SpendLayer, stack: Stack, options: SpendOptions): OwnerStep[] {\n const parts = partsById(stack);\n const services = new Map(layer.services.map((service) => [service.part, service] as const).reverse());\n const steps: OwnerStep[] = [];\n const faults = checkSpend(layer, stack, options);\n const open = new Set(faults.filter((fault) => fault.code === \"end-open\").map((fault) => fault.at));\n for (const fault of faults) {\n const code = OWNER_CODES.find((item) => item === fault.code);\n const service = services.get(fault.at);\n if (code === undefined || service === undefined) continue;\n if (code === \"limit-wanted\" && service.wanted?.kind === \"code\") continue;\n if (code === \"end-soon\" && (open.has(fault.at) || service.ends?.decided !== undefined)) continue;\n let text = \"Read the plan and the limits in the account, and give them with the date of the read.\";\n if (code === \"limit-recharge\") text = \"Stop the automatic recharge of the prepaid balance.\";\n if (code === \"limit-wanted\" && service.wanted !== undefined) text = wantedText(service.wanted, layer.currency);\n if (code === \"end-soon\" && service.ends !== undefined) text = endText(service.ends);\n if (code === \"end-open\" && service.ends !== undefined) text = `Set a hard limit for the cost after ${service.ends.date}, or stop the service before that date.`;\n steps.push({ part: fault.at, name: parts.get(fault.at)?.name ?? fault.at, code, text, steps: service.steps ?? [] });\n }\n return steps;\n}\n","import { dayNumber } from \"@mark1russell7/system-stack\";\nimport type { SpendLayer } from \"./layer.ts\";\nimport { USE_LEVELS, type UseOptions, type UseRead } from \"./reads.ts\";\n\n// The examination of the options and of each read. This module is internal: no entry exports it.\n// `useSpace` and `checkUse` use it, so the tree and the gate agree on the reads with a fault.\n\n/** These are the codes of the faults of one read. */\nexport const READ_CODES: readonly [\"read-part\", \"read-amount\", \"read-date\"] = [\"read-part\", \"read-amount\", \"read-date\"];\n\n/** A code of a fault of one read. */\nexport type ReadCode = (typeof READ_CODES)[number];\n\n/** The options with their defaults, and the fault of each read. */\nexport interface UsePlan {\n /** The number of the day of the check. */\n readonly today: number;\n /** The month of the check, as `YYYY-MM`. */\n readonly month: string;\n readonly levels: readonly number[];\n readonly readDays: number | undefined;\n /** The fault of each read, in the sequence of the reads. A read with no fault has `undefined`. */\n readonly codes: readonly (ReadCode | undefined)[];\n /** The age of each read in days, in the sequence of the reads. A read with a fault of its date has `undefined`. */\n readonly ages: readonly (number | undefined)[];\n}\n\n/** This function gives the month of a date `YYYY-MM-DD`, as `YYYY-MM`. */\nexport function monthOf(date: string): string {\n return date.slice(0, 7);\n}\n\n/**\n * This function examines the options and each read.\n *\n * - `read-part`: the read names a part with no cost record.\n * - `read-amount`: the amount is less than 0 or not finite.\n * - `read-date`: the date is not a date, or it is after the date of the check.\n *\n * A read has one code at most: the first fault of this list.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid\n */\nexport function usePlan(layer: SpendLayer, reads: readonly UseRead[], options: UseOptions): UsePlan {\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 levels = options.levels ?? USE_LEVELS;\n for (const level of levels) {\n if (!Number.isFinite(level) || level <= 0) throw new RangeError(`The level ${String(level)} is not a finite number above 0.`);\n }\n const readDays = options.readDays;\n if (readDays !== undefined && (!Number.isFinite(readDays) || readDays < 0)) throw new RangeError(`The largest age ${String(readDays)} of a read is less than 0 or not finite.`);\n const parts = new Set(layer.services.map((service) => service.part));\n const days = reads.map((read) => dayNumber(read.date));\n const ages = days.map((day) => (day === undefined || day > today ? undefined : today - day));\n const codes = reads.map((read, index): ReadCode | undefined => {\n if (!parts.has(read.part)) return \"read-part\";\n if (!Number.isFinite(read.amount) || read.amount < 0) return \"read-amount\";\n return ages[index] === undefined ? \"read-date\" : undefined;\n });\n return { today, month: monthOf(options.today), levels, readDays, codes, ages };\n}\n","import { app, axes, each, let_, lit, parent, ref, space, v, type Axis, type Expr, type Space } from \"@mark1russell7/vex\";\nimport type { Billing, SpendLayer } from \"./layer.ts\";\nimport type { UseOptions, UseRead, UseSource } from \"./reads.ts\";\nimport { evaluateService, firstServices, LAYER_KEY, serviceKey, serviceStates } from \"./states.ts\";\nimport { monthOf, usePlan } from \"./use-plan.ts\";\nimport { booleanOf, numberOf } from \"./values.ts\";\n\n// The used amount of each service in a month, from the reads. The rule: the used amount is the larger of the count of\n// the stack and the amount of the provider. Each formula is a Vex program on the tree that `useSpace` makes.\n\n/** This test tells if a read node is of the month of the layer node. The program evaluates at a read. */\nconst IN_MONTH: Expr = app(\"eq\", ref(\"month\"), ref(\"month\", [parent, parent]));\n\n/** The reads of a service in the month of the check. */\nexport const MONTH_READS: Axis = axes.where(axes.children, IN_MONTH);\n\n/** This function gives the amount of each read of one source, for a service in the month of the check. */\nfunction amountsOf(source: UseSource): Expr {\n return each(axes.where(MONTH_READS, app(\"eq\", ref(\"source\"), lit(source))), ref(\"amount\"));\n}\n\n/** The largest amount that a part of the stack counted for a service in the month. With no such read, it gives `#N/A`. */\nexport const COUNT_USED: Expr = app(\"max\", amountsOf(\"count\"));\n\n/** The largest amount that the provider showed for a service in the month. With no such read, it gives `#N/A`. */\nexport const PROVIDER_USED: Expr = app(\"max\", amountsOf(\"provider\"));\n\n/**\n * The used amount of a service in the month: the larger of the count of the stack and the amount of the provider.\n * It is the largest amount of the reads of the month, because the cost of a month does not go down.\n * With no read of the month, it gives `#N/A`.\n */\nexport const USED: Expr = app(\"max\", each(MONTH_READS, ref(\"amount\")));\n\n/** The used share of the hard limit of a service: the used amount divided by the limit. With no read or no limit, it gives an error value. */\nexport const USE_SHARE: Expr = app(\"divide\", USED, ref(\"limit\"));\n\n/** This test tells if the used amount of a service is more than its hard limit. Such a limit did not hold. */\nexport const USE_OVER: Expr = app(\"gt\", USED, ref(\"limit\"));\n\n/**\n * The tolerance of the comparison of a share with a level. A share reaches a level when it is the level less this\n * tolerance, or more. Thus the rounding of a division does not hide a level: 2.4 of 3 reaches the level 0.8.\n */\nexport const LEVEL_TOLERANCE = 1e-9;\n\n/**\n * The largest level that the used share of a service reached. A share below each level gives 0.\n * With no read or no limit, it gives `#N/A`. The levels are in the field `levels` of the layer node.\n */\nexport const USE_LEVEL: Expr = let_(\n { share: app(\"add\", USE_SHARE, lit(LEVEL_TOLERANCE)) },\n app(\"max\", each(axes.list(ref(\"levels\", [parent])), app(\"if\", app(\"lte\", v(\"level\"), v(\"share\")), v(\"level\"), lit(0)), undefined, [\"level\"])),\n);\n\n/** The age of the newest read of a service in the month, in days. With no read of the month, it gives `#N/A`. */\nexport const READ_AGE: Expr = app(\"min\", each(MONTH_READS, ref(\"age\")));\n\n/**\n * This function gives the tree of the reads of a layer, as a space of Vex.\n *\n * - The layer is the root, with the key `LAYER_KEY`. Its fields are `month` (the month of the check) and `levels`.\n * - A service is a child of the layer. Its fields are `billing` and `limit`: its hard limit, from `serviceStates`.\n * - A read is a child of its service. Its fields are `source`, `amount`, `month` and `age`: the days from its date to the check.\n *\n * A read with a fault is not in the tree, and `checkUse` tells the fault. The first record of a part is used.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid\n */\nexport function useSpace(layer: SpendLayer, reads: readonly UseRead[], options: UseOptions): Space {\n const plan = usePlan(layer, reads, options);\n const limits = new Map(serviceStates(layer).map((state) => [state.part, state.hardLimit] as const));\n const records: Record<string, Readonly<Record<string, unknown>>> = { [LAYER_KEY]: { kind: \"layer\", month: plan.month, levels: [...plan.levels] } };\n const parents: Record<string, string | null> = { [LAYER_KEY]: null };\n for (const service of firstServices(layer)) {\n const key = serviceKey(service.part);\n const limit = limits.get(service.part);\n records[key] = { kind: \"service\", billing: service.billing, ...(limit === undefined ? {} : { limit }) };\n parents[key] = LAYER_KEY;\n }\n reads.forEach((read, index) => {\n if (plan.codes[index] !== undefined) return;\n const key = `read:${String(index)}`;\n records[key] = { kind: \"read\", source: read.source, amount: read.amount, month: monthOf(read.date), age: plan.ages[index] };\n parents[key] = serviceKey(read.part);\n });\n return space.tree(records, parents);\n}\n\n/** The state of the used amount of one service in the month of the check. A field with no known value is absent. */\nexport interface UseState {\n /** The `id` of the part of the service. */\n readonly part: string;\n readonly billing: Billing;\n /** The largest amount that a part of the stack counted in the month. */\n readonly count?: number | undefined;\n /** The largest amount that the provider showed in the month. */\n readonly provider?: number | undefined;\n /** The used amount of the month: the larger of `count` and `provider`. A service with no read of the month has none. */\n readonly used?: number | undefined;\n /** The hard limit of the service for a month. */\n readonly limit?: number | undefined;\n /** The used share of the hard limit: `used` divided by `limit`. */\n readonly share?: number | undefined;\n /** The largest level that the share reached. A share below each level has none. */\n readonly level?: number | undefined;\n /** This field tells if the used amount is more than the hard limit. */\n readonly over?: boolean | undefined;\n /** The age of the newest read of the month, in days. */\n readonly age?: number | undefined;\n}\n\n/** This function gives a record without the fields that have no value. */\nfunction known<Fields extends Record<string, unknown>>(fields: Fields): Partial<Fields> {\n return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined)) as Partial<Fields>;\n}\n\n/**\n * This function gives the state of the used amount of each service of a layer, in the sequence of the services.\n * The month is the month of `today`: a read of a different month does not count.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid\n */\nexport function useStates(layer: SpendLayer, reads: readonly UseRead[], options: UseOptions): UseState[] {\n const tree = useSpace(layer, reads, options);\n return firstServices(layer).map((service) => {\n const number = (program: Expr): number | undefined => numberOf(evaluateService(program, tree, service.part));\n const level = number(USE_LEVEL);\n return {\n part: service.part,\n billing: service.billing,\n ...known({\n count: number(COUNT_USED),\n provider: number(PROVIDER_USED),\n used: number(USED),\n limit: number(ref(\"limit\")),\n share: number(USE_SHARE),\n level: level === 0 ? undefined : level,\n over: booleanOf(evaluateService(USE_OVER, tree, service.part)),\n age: number(READ_AGE),\n }),\n };\n });\n}\n","import type { Fault, FaultLevel } from \"@mark1russell7/system-stack\";\nimport type { SpendLayer } from \"./layer.ts\";\nimport type { UseOptions, UseRead } from \"./reads.ts\";\nimport { usePlan } from \"./use-plan.ts\";\nimport { useStates } from \"./use.ts\";\n\n// The gate of the used amounts. It tells when a limit did not hold, and it gives a warning at each level of a limit.\n\n/** These are the codes of the faults of the used amounts of a layer. */\nexport const USE_CODES: readonly [\"read-part\", \"read-amount\", \"read-date\", \"use-billing\", \"use-over\", \"use-level\", \"use-count\", \"use-none\", \"use-old\"] = [\n \"read-part\",\n \"read-amount\",\n \"read-date\",\n \"use-billing\",\n \"use-over\",\n \"use-level\",\n \"use-count\",\n \"use-none\",\n \"use-old\",\n];\n\n/** A code of a fault of the used amounts of a layer. */\nexport type UseCode = (typeof USE_CODES)[number];\n\n/** A fault of the used amounts of a layer. Its field `at` is the `id` of the part. */\nexport interface UseFault extends Fault {\n readonly code: UseCode;\n}\n\n/** This function gives a share as a text in percent, for example `80` for 0.8. */\nfunction percent(share: number): string {\n return String(Number((share * 100).toFixed(6)));\n}\n\n/**\n * This function gives each fault of the used amounts of a layer. A list with no error tells that the gate passes.\n *\n * The reads, as errors:\n * - `read-part`: a read names a part with no cost record.\n * - `read-amount`: the amount of a read is less than 0 or not finite.\n * - `read-date`: the date of a read is not a date, or it is after `today`.\n *\n * The services, as errors:\n * - `use-billing`: a read shows a cost of the use of a `free` or `fixed` service. The cost record is not correct.\n * - `use-over`: the used amount of a `metered` service is more than its hard limit. The limit did not hold.\n *\n * The services, as warnings:\n * - `use-level`: the used amount of a `metered` service reached a level of its hard limit.\n * - `use-count`: the provider shows more than the stack counted. The count does not have all the use.\n * - `use-none`: a `metered` service has no read of the month, so its used amount is not known.\n * - `use-old`: the newest read of a `metered` service is older than `readDays`.\n *\n * A read with a fault does not count. The faults are in the sequence of the reads, then of the services. The function is pure.\n *\n * @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid\n */\nexport function checkUse(layer: SpendLayer, reads: readonly UseRead[], options: UseOptions): UseFault[] {\n const plan = usePlan(layer, reads, options);\n const faults: UseFault[] = [];\n const add = (level: FaultLevel, code: UseCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const money = (amount: number): string => `${String(amount)} ${layer.currency}`;\n reads.forEach((read, index) => {\n const code = plan.codes[index];\n if (code === \"read-part\") add(\"error\", code, read.part, `A read names \"${read.part}\", which has no cost record.`);\n if (code === \"read-amount\") add(\"error\", code, read.part, `The amount ${String(read.amount)} of a read of \"${read.part}\" is less than 0 or not finite.`);\n if (code === \"read-date\") add(\"error\", code, read.part, `The date \"${read.date}\" of a read of \"${read.part}\" is not a date of the form YYYY-MM-DD, or it is after the date of the check, ${options.today}.`);\n });\n for (const state of useStates(layer, reads, options)) {\n const at = state.part;\n if (state.billing !== \"metered\") {\n if (state.used !== undefined && state.used > 0) {\n add(\"error\", \"use-billing\", at, `The service \"${at}\" has the billing \"${state.billing}\", and a read shows a cost of ${money(state.used)} for its use in the month ${plan.month}.`);\n }\n continue;\n }\n if (state.used === undefined) {\n add(\"warning\", \"use-none\", at, `No read gives the used amount of \"${at}\" in the month ${plan.month}.`);\n continue;\n }\n if (state.over === true && state.limit !== undefined) {\n add(\"error\", \"use-over\", at, `The used amount of \"${at}\" in the month ${plan.month} is ${money(state.used)}. Its hard limit is ${money(state.limit)}, so the limit did not hold.`);\n } else if (state.level !== undefined && state.limit !== undefined) {\n add(\"warning\", \"use-level\", at, `The used amount of \"${at}\" in the month ${plan.month} is ${money(state.used)}: ${percent(state.level)} percent of its hard limit of ${money(state.limit)}, or more.`);\n }\n if (state.count !== undefined && state.provider !== undefined && state.provider > state.count) {\n add(\"warning\", \"use-count\", at, `The provider shows ${money(state.provider)} for \"${at}\" in the month ${plan.month}, and the stack counted ${money(state.count)}. The count does not have all the use.`);\n }\n if (plan.readDays !== undefined && state.age !== undefined && state.age > plan.readDays) {\n add(\"warning\", \"use-old\", at, `The age of the newest read of \"${at}\" is ${String(state.age)}, in days. The largest age is ${String(plan.readDays)}.`);\n }\n }\n return faults;\n}\n","import { SPEND_SCHEMA, type SpendLayer } from \"./layer.ts\";\nimport type { UseRead } from \"./reads.ts\";\n\n/** The date of the check of the sample. With it, the gate gives the faults that the README shows. */\nexport const SAMPLE_TODAY = \"2026-11-16\";\n\n/**\n * A sample spend layer for `SAMPLE_STACK` of the core. Each name and each amount is an example.\n * It has two faults: the only limit of the cloud account is an alert, and the balance of the call account gets money automatically.\n */\nexport const SAMPLE_SPEND: SpendLayer = {\n schema: SPEND_SCHEMA,\n currency: \"USD\",\n kinds: [\"account\"],\n proofDays: 90,\n services: [\n {\n part: \"cloud-account\",\n plan: \"A free allowance, then a price for the use\",\n billing: \"metered\",\n limits: [{ kind: \"alert\", amount: 5 }],\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The billing page of the account\" },\n },\n {\n part: \"push-account\",\n plan: \"A license that was paid one time\",\n billing: \"fixed\",\n price: 0,\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The license page of the account\" },\n },\n {\n part: \"call-account\",\n plan: \"A price for each call\",\n billing: \"metered\",\n limits: [\n { kind: \"prepaid\", amount: 20, recharge: true },\n { kind: \"code\", amount: 10, stop: \"program-home\" },\n ],\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The billing page of the account\" },\n steps: [\"Open the billing page of the account.\", \"Stop the automatic recharge.\", \"Save the change.\"],\n },\n ],\n};\n\n/**\n * A sample spend layer for `SAMPLE_STACK` of the core, with two plans that end. Each name, each date and each amount is an example.\n *\n * - The free trial of the cloud account ends. After the end, the cost grows with the use, and its only limit is an alert.\n * - The free credit of the call account ends. The record gives no plan after the end, so the provider stops the service.\n *\n * With the date `SAMPLE_TODAY`, the two ends are in the 30 days of warning.\n */\nexport const SAMPLE_ENDS: SpendLayer = {\n schema: SPEND_SCHEMA,\n currency: \"USD\",\n kinds: [\"account\"],\n proofDays: 90,\n services: [\n {\n part: \"cloud-account\",\n plan: \"A free trial\",\n billing: \"free\",\n ends: { date: \"2026-12-01\", next: { plan: \"A price for the use\", billing: \"metered\", limits: [{ kind: \"alert\", amount: 5 }] } },\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The billing page of the account\" },\n },\n {\n part: \"push-account\",\n plan: \"A license that was paid one time\",\n billing: \"fixed\",\n price: 0,\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The license page of the account\" },\n },\n {\n part: \"call-account\",\n plan: \"A free credit, with no payment method\",\n billing: \"free\",\n ends: { date: \"2026-11-30\" },\n proof: { date: \"2026-11-10\", by: \"The owner\", source: \"The billing page of the account\" },\n },\n ],\n};\n\n/**\n * Sample reads of the used amounts of `SAMPLE_SPEND`, for the date `SAMPLE_TODAY`. Each amount is an example.\n * The provider of the call account shows more than the stack counted, and the used amount is at 50 percent of the hard limit, or more.\n */\nexport const SAMPLE_READS: readonly UseRead[] = [\n { part: \"cloud-account\", source: \"provider\", amount: 0, date: \"2026-11-15\" },\n { part: \"call-account\", source: \"count\", amount: 4, date: \"2026-11-16\" },\n { part: \"call-account\", source: \"provider\", amount: 5.2, date: \"2026-11-16\" },\n];\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,SAAgB,SAAS,OAAmB,SAAuC;CACjF,MAAM,QAAQA,YAAU,QAAQ,KAAK;CACrC,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,WAAW,aAAa,QAAQ,MAAM,wCAAwC;CACjH,MAAM,OAAuB,CAAC;CAC9B,KAAK,MAAM,WAAW,cAAc,KAAK,GAAG;EAC1C,IAAI,QAAQ,SAAS,KAAA,GAAW;EAChC,MAAM,MAAMA,Y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AAM;GAAe,CACnD;GACA,OAAO;IAAE,MAAM;IAAc,IAAI;IAAa,QAAQ;GAAkC;GACxF,OAAO;IAAC;IAAyC;IAAgC;GAAkB;EACrG;CACF;AACF;;;;;;;;;AAUA,MAAa,cAA0B;CACrC,QAAQ;CACR,UAAU;CACV,OAAO,CAAC,SAAS;CACjB,WAAW;CACX,UAAU;EACR;GACE,MAAM;GACN,MAAM;GACN,SAAS;GACT,MAAM;IAAE,MAAM;IAAc,MAAM;KAAE,MAAM;KAAuB,SAAS;KAAW,QAAQ,CAAC;MAAE,MAAM;MAAS,QAAQ;KAAE,CAAC;IAAE;GAAE;GAC9H,OAAO;IAAE,MAAM;IAAc,IAAI;IAAa,QAAQ;GAAkC;EAC1F;EACA;GACE,MAAM;GACN,MAAM;GACN,SAAS;GACT,OAAO;GACP,OAAO;IAAE,MAAM;IAAc,IAAI;IAAa,QAAQ;GAAkC;EAC1F;EACA;GACE,MAAM;GACN,MAAM;GACN,SAAS;GACT,MAAM,EAAE,MAAM,aAAa;GAC3B,OAAO;IAAE,MAAM;IAAc,IAAI;IAAa,QAAQ;GAAkC;EAC1F;CACF;AACF;;;;;AAMA,MAAa,eAAmC;CAC9C;EAAE,MAAM;EAAiB,QAAQ;EAAY,QAAQ;EAAG,MAAM;CAAa;CAC3E;EAAE,MAAM;EAAgB,QAAQ;EAAS,QAAQ;EAAG,MAAM;CAAa;CACvE;EAAE,MAAM;EAAgB,QAAQ;EAAY,QAAQ;EAAK,MAAM;CAAa;AAC9E"}
|
|
@@ -269,9 +269,10 @@ function inDays(days) {
|
|
|
269
269
|
* - `limit-wanted`: a wanted limit is not in force.
|
|
270
270
|
*
|
|
271
271
|
* The end of a plan:
|
|
272
|
-
* - `end-date`: the date of an end is not a date.
|
|
272
|
+
* - `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`.
|
|
273
273
|
* - `end-past`: the plan ended before `today`. The record gives the cost before the end, so it is not correct.
|
|
274
274
|
* - `end-soon`: the plan ends in `endDays` days, or fewer. This fault is a warning: it does not stop the gate.
|
|
275
|
+
* Its message tells the decision of the owner, when the record has one.
|
|
275
276
|
* - `end-open`: the cost after the end grows with the use, and it has no hard limit.
|
|
276
277
|
*
|
|
277
278
|
* The proofs:
|
|
@@ -330,13 +331,20 @@ function checkSpend(layer, stack, options) {
|
|
|
330
331
|
else add("limit-none", at, `The cost of "${at}" grows with the use, and it has no limit.`);
|
|
331
332
|
}
|
|
332
333
|
if (service.ends !== void 0) {
|
|
333
|
-
const { date, next } = service.ends;
|
|
334
|
+
const { date, next, decided } = service.ends;
|
|
334
335
|
const end = dayNumber$1(date);
|
|
335
336
|
if (end === void 0) 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.`);
|
|
336
337
|
else if (end < today) add("end-past", at, `The plan of "${at}" ended on ${date}. The record gives the cost before the end.`);
|
|
337
338
|
else if (end - today <= endDays) {
|
|
338
339
|
const then = next === void 0 ? "Then the provider stops the service." : "Then the cost changes.";
|
|
339
|
-
|
|
340
|
+
const agreed = decided === void 0 ? "" : ` ${decided.by} decided this on ${decided.date}.`;
|
|
341
|
+
push("warning", "end-soon", at, `The plan of "${at}" ends on ${date}, ${inDays(end - today)}. ${then}${agreed}`);
|
|
342
|
+
}
|
|
343
|
+
if (decided !== void 0) {
|
|
344
|
+
const day = dayNumber$1(decided.date);
|
|
345
|
+
const about = `of the decision about the end of the plan of "${at}"`;
|
|
346
|
+
if (day === void 0) add("end-date", at, `The date "${decided.date}" ${about} is not a date of the form YYYY-MM-DD.`);
|
|
347
|
+
else if (day > today) add("end-date", at, `The date ${decided.date} ${about} is after the date of the check, ${options.today}.`);
|
|
340
348
|
}
|
|
341
349
|
if (next !== void 0) {
|
|
342
350
|
const when = " after the end of its plan";
|
|
@@ -410,4 +418,4 @@ function joinSpend(pieces) {
|
|
|
410
418
|
}
|
|
411
419
|
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 };
|
|
412
420
|
|
|
413
|
-
//# sourceMappingURL=join-
|
|
421
|
+
//# sourceMappingURL=join-98opeDSl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,QA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AW,UAAU;GACrB,GAAI,QAAQ,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,MAAM;GAChE,UAAU,SAAS;EACrB;CACF;AACF"}
|
|
@@ -64,6 +64,18 @@ interface PlanEnd {
|
|
|
64
64
|
readonly date: string;
|
|
65
65
|
/** The cost of the service after the end. A service that stops has none. */
|
|
66
66
|
readonly next?: NextPlan | undefined;
|
|
67
|
+
/** The decision of the owner that the result after the end is wanted: the stop, or the cost of `next`. */
|
|
68
|
+
readonly decided?: EndDecision | undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The decision of the owner about the end of a plan: the stop of the service, or the cost of its next plan, is wanted.
|
|
72
|
+
* An end with a decision gives no step to the owner. A cost with no hard limit after the end stays a fault.
|
|
73
|
+
*/
|
|
74
|
+
interface EndDecision {
|
|
75
|
+
/** The date of the decision, as `YYYY-MM-DD`. */
|
|
76
|
+
readonly date: string;
|
|
77
|
+
/** The person who decided, for example the owner of the account. */
|
|
78
|
+
readonly by: string;
|
|
67
79
|
}
|
|
68
80
|
/** The cost record of one part of the stack. */
|
|
69
81
|
interface Service {
|
|
@@ -100,5 +112,5 @@ interface SpendLayer {
|
|
|
100
112
|
readonly endDays?: number | undefined;
|
|
101
113
|
readonly services: readonly Service[];
|
|
102
114
|
}
|
|
103
|
-
export {
|
|
104
|
-
//# sourceMappingURL=layer-
|
|
115
|
+
export { LIMIT_KINDS as a, NextPlan as c, SPEND_SCHEMA as d, Service as f, EndDecision as i, PlanEnd as l, Billing as n, Limit as o, SpendLayer as p, END_DAYS as r, LimitKind as s, BILLINGS as t, Proof as u };
|
|
116
|
+
//# sourceMappingURL=layer-Dm7OM6CQ.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer-Dm7OM6CQ.d.ts","names":[],"sources":["../src/layer.ts"],"mappings":";cAIa;;;;;;;;cASA;;KAGD,kBAAkB;;;;;;;;;cAUjB;;KAGD,oBAAoB;;UAGf;WACN,MAAM;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;;;;;UAOM;;WAEN;WACA,SAAS;;WAET;;WAEA,kBAAkB;;;;;;;;UASZ;;WAEN;;WAEA,OAAO;;WAEP,UAAU;;;;;;UAOJ;;WAEN;;WAEA;;;UAIM;;WAEN;;WAEA;WACA,SAAS;;WAET;;WAEA,kBAAkB;;WAElB,SAAS;;WAET,OAAO;;WAEP,QAAQ;;WAER;;;cAIE;;UAGI;WACN,eAAe;;WAEf;;WAEA;;WAEA;;WAEA;WACA,mBAAmB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reads-BNyUIVaY.js","names":[],"sources":["../src/layer.ts","../src/reads.ts"],"sourcesContent":["// The records of the spend add-on. They are one layer of a stack, with the key `spend/1` in `Stack.layers`.\n// Each record gives the cost of one part: its plan, its price and the limits of its cost in a month.\n\n/** The name of the format of a spend layer. It is the key of the layer in `Stack.layers`. */\nexport const SPEND_SCHEMA = \"spend/1\";\n\n/**\n * These are the kinds of billing of a service.\n *\n * - `free`: the provider cannot take money. The account has no payment method, or the plan has no paid use.\n * - `fixed`: the price of a month is fixed, and the use does not change it. A price that was paid one time is a fixed price of 0.\n * - `metered`: the cost grows with the use. A free allowance with a payment method on the account is `metered`.\n */\nexport const BILLINGS: readonly [\"free\", \"fixed\", \"metered\"] = [\"free\", \"fixed\", \"metered\"];\n\n/** A kind of billing of a service. */\nexport type Billing = (typeof BILLINGS)[number];\n\n/**\n * These are the kinds of limit of the cost of a month.\n *\n * - `provider`: a hard limit of the provider. The provider stops the service at the amount.\n * - `prepaid`: a prepaid balance. The provider stops the service when the balance is empty.\n * - `code`: a stop by code. A part of the stack counts the cost and stops the use at the amount.\n * - `alert`: a message at the amount. An alert stops nothing, so it is not a hard limit.\n */\nexport const LIMIT_KINDS: readonly [\"provider\", \"prepaid\", \"code\", \"alert\"] = [\"provider\", \"prepaid\", \"code\", \"alert\"];\n\n/** A kind of limit of the cost of a month. */\nexport type LimitKind = (typeof LIMIT_KINDS)[number];\n\n/** A limit of the cost of a service in a month. */\nexport interface Limit {\n readonly kind: LimitKind;\n /** The amount of the limit for a month, in the currency of the layer. For `prepaid`, it is the largest balance. */\n readonly amount: number;\n /** For `prepaid`: the provider adds money to the balance automatically. Such a balance is not a hard limit. */\n readonly recharge?: boolean | undefined;\n /** For `code`: the `id` of the part of the stack that stops the use. */\n readonly stop?: string | undefined;\n}\n\n/** The proof of a record: who read the settings of the service, and on which date. */\nexport interface Proof {\n /** The date of the read, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The reader of the settings, for example the owner of the account or the name of a program. */\n readonly by: string;\n /** The source of the read, for example the name of a page of the account. */\n readonly source?: string | undefined;\n}\n\n/**\n * The cost of a service after the end of its plan. It has the fields of a cost record that give a cost.\n * The gate examines it with the rules of a cost record: a cost that grows with the use must have a hard limit.\n */\nexport interface NextPlan {\n /** The name of the plan after the end. */\n readonly plan?: string | undefined;\n readonly billing: Billing;\n /** The fixed price of a month after the end, in the currency of the layer. A `fixed` plan must have one. */\n readonly price?: number | undefined;\n /** The limits that are in force after the end. A `metered` plan must have one hard limit, or more. */\n readonly limits?: readonly Limit[] | undefined;\n}\n\n/**\n * The end of the plan of a service: a trial, a free credit or a term that ends on a date.\n *\n * - With no `next`, the provider stops the service after the date, and it takes no money. The part does not work after the date.\n * - With a `next`, the service continues after the date, with the cost of `next`.\n */\nexport interface PlanEnd {\n /** The last day of the plan, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The cost of the service after the end. A service that stops has none. */\n readonly next?: NextPlan | undefined;\n}\n\n/** The cost record of one part of the stack. */\nexport interface Service {\n /** The `id` of the part of the stack with the cost. */\n readonly part: string;\n /** The name of the plan of the service. */\n readonly plan?: string | undefined;\n readonly billing: Billing;\n /** The fixed price of a month, in the currency of the layer. A `fixed` service must have one. */\n readonly price?: number | undefined;\n /** The limits that are in force. A `metered` service must have one hard limit, or more. */\n readonly limits?: readonly Limit[] | undefined;\n /** A limit that is not in force: the owner must set it. The gate fails until it is in `limits`. */\n readonly wanted?: Limit | undefined;\n /** The end of the plan, for a plan that ends on a date. The fields `billing`, `price` and `limits` give the cost before the end. */\n readonly ends?: PlanEnd | undefined;\n /** The proof of the record. Each record must have one, and a proof becomes too old. */\n readonly proof?: Proof | undefined;\n /** The steps of the owner in the account of the service, to set or to read a limit. */\n readonly steps?: readonly string[] | undefined;\n}\n\n/** The default count of days before the end of a plan from which the gate gives a warning. */\nexport const END_DAYS = 30;\n\n/** A spend layer: the cost records of the parts of a stack. */\nexport interface SpendLayer {\n readonly schema: typeof SPEND_SCHEMA;\n /** The currency of each amount of the layer, as a code of ISO 4217, for example `USD`. */\n readonly currency: string;\n /** The kinds of the parts that can have a cost. Each part of one of these kinds must have a record. */\n readonly kinds: readonly string[];\n /** The largest age of a proof, in days. */\n readonly proofDays: number;\n /** The count of days before the end of a plan from which the gate gives a warning. The default is `END_DAYS`. */\n readonly endDays?: number | undefined;\n readonly services: readonly Service[];\n}\n","// The reads of the used amount of a service. A read is live data: a program makes it, and it is no record of the layer.\n// The functions of `use.ts` and of `use-check.ts` take a list of reads.\n\n/**\n * These are the sources of a read.\n *\n * - `count`: a part of the stack counted the use, and it gives the cost of that use.\n * - `provider`: the provider of the service shows the cost of the use, for example on a usage page or in a usage API.\n */\nexport const USE_SOURCES: readonly [\"count\", \"provider\"] = [\"count\", \"provider\"];\n\n/** A source of a read. */\nexport type UseSource = (typeof USE_SOURCES)[number];\n\n/**\n * A read of the cost of the use of one service.\n *\n * The amount is the cost of the use from the start of a month until the read. It is the part of the cost that grows\n * with the use: the fixed price of a plan is not in it.\n */\nexport interface UseRead {\n /** The `id` of the part of the service. */\n readonly part: string;\n readonly source: UseSource;\n /** The cost of the use from the start of the month until the read, in the currency of the layer. */\n readonly amount: number;\n /** The date of the read, as `YYYY-MM-DD`. The month of this date is the month of the amount. */\n readonly date: string;\n}\n\n/** These are the default levels of the used share of a hard limit: 50, 80 and 100 percent. */\nexport const USE_LEVELS: readonly number[] = [0.5, 0.8, 1];\n\n/** The options of the functions of the used amount. */\nexport interface UseOptions {\n /** The date of the check, as `YYYY-MM-DD`. Its month is the month of the used amounts. The functions have no clock. */\n readonly today: string;\n /** The levels: shares of the hard limit, each one above 0. The default is `USE_LEVELS`. */\n readonly levels?: readonly number[] | undefined;\n /** The largest age of the newest read of a service, in days. With no value, the gate examines no age. */\n readonly readDays?: number | undefined;\n}\n"],"mappings":";;AAIA,MAAa,eAAe;;;;;;;;AAS5B,MAAa,WAAkD;CAAC;CAAQ;CAAS;AAAS;;;;;;;;;AAa1F,MAAa,cAAiE;CAAC;CAAY;CAAW;CAAQ;AAAO;;
|
|
1
|
+
{"version":3,"file":"reads-BNyUIVaY.js","names":[],"sources":["../src/layer.ts","../src/reads.ts"],"sourcesContent":["// The records of the spend add-on. They are one layer of a stack, with the key `spend/1` in `Stack.layers`.\n// Each record gives the cost of one part: its plan, its price and the limits of its cost in a month.\n\n/** The name of the format of a spend layer. It is the key of the layer in `Stack.layers`. */\nexport const SPEND_SCHEMA = \"spend/1\";\n\n/**\n * These are the kinds of billing of a service.\n *\n * - `free`: the provider cannot take money. The account has no payment method, or the plan has no paid use.\n * - `fixed`: the price of a month is fixed, and the use does not change it. A price that was paid one time is a fixed price of 0.\n * - `metered`: the cost grows with the use. A free allowance with a payment method on the account is `metered`.\n */\nexport const BILLINGS: readonly [\"free\", \"fixed\", \"metered\"] = [\"free\", \"fixed\", \"metered\"];\n\n/** A kind of billing of a service. */\nexport type Billing = (typeof BILLINGS)[number];\n\n/**\n * These are the kinds of limit of the cost of a month.\n *\n * - `provider`: a hard limit of the provider. The provider stops the service at the amount.\n * - `prepaid`: a prepaid balance. The provider stops the service when the balance is empty.\n * - `code`: a stop by code. A part of the stack counts the cost and stops the use at the amount.\n * - `alert`: a message at the amount. An alert stops nothing, so it is not a hard limit.\n */\nexport const LIMIT_KINDS: readonly [\"provider\", \"prepaid\", \"code\", \"alert\"] = [\"provider\", \"prepaid\", \"code\", \"alert\"];\n\n/** A kind of limit of the cost of a month. */\nexport type LimitKind = (typeof LIMIT_KINDS)[number];\n\n/** A limit of the cost of a service in a month. */\nexport interface Limit {\n readonly kind: LimitKind;\n /** The amount of the limit for a month, in the currency of the layer. For `prepaid`, it is the largest balance. */\n readonly amount: number;\n /** For `prepaid`: the provider adds money to the balance automatically. Such a balance is not a hard limit. */\n readonly recharge?: boolean | undefined;\n /** For `code`: the `id` of the part of the stack that stops the use. */\n readonly stop?: string | undefined;\n}\n\n/** The proof of a record: who read the settings of the service, and on which date. */\nexport interface Proof {\n /** The date of the read, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The reader of the settings, for example the owner of the account or the name of a program. */\n readonly by: string;\n /** The source of the read, for example the name of a page of the account. */\n readonly source?: string | undefined;\n}\n\n/**\n * The cost of a service after the end of its plan. It has the fields of a cost record that give a cost.\n * The gate examines it with the rules of a cost record: a cost that grows with the use must have a hard limit.\n */\nexport interface NextPlan {\n /** The name of the plan after the end. */\n readonly plan?: string | undefined;\n readonly billing: Billing;\n /** The fixed price of a month after the end, in the currency of the layer. A `fixed` plan must have one. */\n readonly price?: number | undefined;\n /** The limits that are in force after the end. A `metered` plan must have one hard limit, or more. */\n readonly limits?: readonly Limit[] | undefined;\n}\n\n/**\n * The end of the plan of a service: a trial, a free credit or a term that ends on a date.\n *\n * - With no `next`, the provider stops the service after the date, and it takes no money. The part does not work after the date.\n * - With a `next`, the service continues after the date, with the cost of `next`.\n */\nexport interface PlanEnd {\n /** The last day of the plan, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The cost of the service after the end. A service that stops has none. */\n readonly next?: NextPlan | undefined;\n /** The decision of the owner that the result after the end is wanted: the stop, or the cost of `next`. */\n readonly decided?: EndDecision | undefined;\n}\n\n/**\n * The decision of the owner about the end of a plan: the stop of the service, or the cost of its next plan, is wanted.\n * An end with a decision gives no step to the owner. A cost with no hard limit after the end stays a fault.\n */\nexport interface EndDecision {\n /** The date of the decision, as `YYYY-MM-DD`. */\n readonly date: string;\n /** The person who decided, for example the owner of the account. */\n readonly by: string;\n}\n\n/** The cost record of one part of the stack. */\nexport interface Service {\n /** The `id` of the part of the stack with the cost. */\n readonly part: string;\n /** The name of the plan of the service. */\n readonly plan?: string | undefined;\n readonly billing: Billing;\n /** The fixed price of a month, in the currency of the layer. A `fixed` service must have one. */\n readonly price?: number | undefined;\n /** The limits that are in force. A `metered` service must have one hard limit, or more. */\n readonly limits?: readonly Limit[] | undefined;\n /** A limit that is not in force: the owner must set it. The gate fails until it is in `limits`. */\n readonly wanted?: Limit | undefined;\n /** The end of the plan, for a plan that ends on a date. The fields `billing`, `price` and `limits` give the cost before the end. */\n readonly ends?: PlanEnd | undefined;\n /** The proof of the record. Each record must have one, and a proof becomes too old. */\n readonly proof?: Proof | undefined;\n /** The steps of the owner in the account of the service, to set or to read a limit. */\n readonly steps?: readonly string[] | undefined;\n}\n\n/** The default count of days before the end of a plan from which the gate gives a warning. */\nexport const END_DAYS = 30;\n\n/** A spend layer: the cost records of the parts of a stack. */\nexport interface SpendLayer {\n readonly schema: typeof SPEND_SCHEMA;\n /** The currency of each amount of the layer, as a code of ISO 4217, for example `USD`. */\n readonly currency: string;\n /** The kinds of the parts that can have a cost. Each part of one of these kinds must have a record. */\n readonly kinds: readonly string[];\n /** The largest age of a proof, in days. */\n readonly proofDays: number;\n /** The count of days before the end of a plan from which the gate gives a warning. The default is `END_DAYS`. */\n readonly endDays?: number | undefined;\n readonly services: readonly Service[];\n}\n","// The reads of the used amount of a service. A read is live data: a program makes it, and it is no record of the layer.\n// The functions of `use.ts` and of `use-check.ts` take a list of reads.\n\n/**\n * These are the sources of a read.\n *\n * - `count`: a part of the stack counted the use, and it gives the cost of that use.\n * - `provider`: the provider of the service shows the cost of the use, for example on a usage page or in a usage API.\n */\nexport const USE_SOURCES: readonly [\"count\", \"provider\"] = [\"count\", \"provider\"];\n\n/** A source of a read. */\nexport type UseSource = (typeof USE_SOURCES)[number];\n\n/**\n * A read of the cost of the use of one service.\n *\n * The amount is the cost of the use from the start of a month until the read. It is the part of the cost that grows\n * with the use: the fixed price of a plan is not in it.\n */\nexport interface UseRead {\n /** The `id` of the part of the service. */\n readonly part: string;\n readonly source: UseSource;\n /** The cost of the use from the start of the month until the read, in the currency of the layer. */\n readonly amount: number;\n /** The date of the read, as `YYYY-MM-DD`. The month of this date is the month of the amount. */\n readonly date: string;\n}\n\n/** These are the default levels of the used share of a hard limit: 50, 80 and 100 percent. */\nexport const USE_LEVELS: readonly number[] = [0.5, 0.8, 1];\n\n/** The options of the functions of the used amount. */\nexport interface UseOptions {\n /** The date of the check, as `YYYY-MM-DD`. Its month is the month of the used amounts. The functions have no clock. */\n readonly today: string;\n /** The levels: shares of the hard limit, each one above 0. The default is `USE_LEVELS`. */\n readonly levels?: readonly number[] | undefined;\n /** The largest age of the newest read of a service, in days. With no value, the gate examines no age. */\n readonly readDays?: number | undefined;\n}\n"],"mappings":";;AAIA,MAAa,eAAe;;;;;;;;AAS5B,MAAa,WAAkD;CAAC;CAAQ;CAAS;AAAS;;;;;;;;;AAa1F,MAAa,cAAiE;CAAC;CAAY;CAAW;CAAQ;AAAO;;AAwFrH,MAAa,WAAW;;;;;;;;ACzGxB,MAAa,cAA8C,CAAC,SAAS,UAAU;;AAsB/E,MAAa,aAAgC;CAAC;CAAK;CAAK;AAAC"}
|
package/build/schema.d.ts
CHANGED
package/build/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;;qBAyDa,aAAa,EAAE,QAAQ;;YAUxB;WAAwB;WAAmB,OAAO;;WAA0B;WAAoB;;;;;;wBAM5F,WAAW,iBAAiB;;;;;qBAoB/B,aAAa,EAAE,iBAAiB;;YAGjC;WAAwB;WAAmB,gBAAgB;;WAAyB;WAAoB;;;;;;wBAMpG,WAAW,iBAAiB"}
|
package/build/schema.js
CHANGED
|
@@ -20,9 +20,14 @@ const next = z.strictObject({
|
|
|
20
20
|
price: z.number().optional(),
|
|
21
21
|
limits: z.array(limit).readonly().optional()
|
|
22
22
|
});
|
|
23
|
+
const decided = z.strictObject({
|
|
24
|
+
date: z.string(),
|
|
25
|
+
by: z.string().min(1)
|
|
26
|
+
});
|
|
23
27
|
const ends = z.strictObject({
|
|
24
28
|
date: z.string(),
|
|
25
|
-
next: next.optional()
|
|
29
|
+
next: next.optional(),
|
|
30
|
+
decided: decided.optional()
|
|
26
31
|
});
|
|
27
32
|
const service = z.strictObject({
|
|
28
33
|
part: id,
|
package/build/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { formErrors } from \"@mark1russell7/system-stack/schema\";\nimport { z } from \"zod\";\nimport { BILLINGS, LIMIT_KINDS, SPEND_SCHEMA, type SpendLayer } from \"./layer.ts\";\nimport { USE_SOURCES, type UseRead } from \"./reads.ts\";\n\n// The zod schema of a spend layer, and the read of its JSON. This module is the entry `/schema` of the package.\n// The root entry has no zod, so a page that only evaluates the cost math gets no schema library.\n\nconst id = z.string().min(1);\n\nconst limit = z.strictObject({\n kind: z.enum([...LIMIT_KINDS]),\n amount: z.number(),\n recharge: z.boolean().optional(),\n stop: id.optional(),\n});\n\nconst proof = z.strictObject({\n date: z.string(),\n by: z.string().min(1),\n source: z.string().optional(),\n});\n\nconst next = z.strictObject({\n plan: z.string().optional(),\n billing: z.enum([...BILLINGS]),\n price: z.number().optional(),\n limits: z.array(limit).readonly().optional(),\n});\n\nconst ends = z.strictObject({\n date: z.string(),\n next: next.optional(),\n});\n\nconst service = z.strictObject({\n part: id,\n plan: z.string().optional(),\n billing: z.enum([...BILLINGS]),\n price: z.number().optional(),\n limits: z.array(limit).readonly().optional(),\n wanted: limit.optional(),\n ends: ends.optional(),\n proof: proof.optional(),\n steps: z.array(z.string()).readonly().optional(),\n});\n\n/**\n * The schema of a spend layer. It examines the form of the record: the fields, their types and the finite numbers.\n * It refuses a field that the format does not have. `checkSpend` examines the meaning of a layer with a correct form.\n */\nexport const spendSchema: z.ZodType<SpendLayer> = z.strictObject({\n schema: z.literal(SPEND_SCHEMA),\n currency: z.string().regex(/^[A-Z]{3}$/, \"The currency is a code of three capital letters.\"),\n kinds: z.array(z.string().min(1)).readonly(),\n proofDays: z.number().positive(),\n endDays: z.number().nonnegative().optional(),\n services: z.array(service).readonly(),\n});\n\n/** The result of the read of a spend layer: the layer, or the faults of its form. */\nexport type SpendParse = { readonly ok: true; readonly layer: SpendLayer } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of a spend layer. It gives the layer, or the faults of its form.\n * Each fault names its place in the record, for example `services.0.part`.\n */\nexport function parseSpend(value: unknown): SpendParse {\n const read = spendSchema.safeParse(value);\n if (read.success) return { ok: true, layer: read.data };\n return { ok: false, errors: formErrors(SPEND_SCHEMA, read.error.issues) };\n}\n\nconst read = z.strictObject({\n part: id,\n source: z.enum([...USE_SOURCES]),\n amount: z.number(),\n date: z.string(),\n});\n\n/** The name of a list of reads in a fault of its form. */\nconst READS_NAME = `${SPEND_SCHEMA} reads`;\n\n/**\n * The schema of a list of reads of the used amounts. It examines the form of each read: the fields, their types and the finite numbers.\n * `checkUse` examines the meaning of the reads with a correct form.\n */\nexport const readsSchema: z.ZodType<readonly UseRead[]> = z.array(read).readonly();\n\n/** The result of the read of a list of reads: the reads, or the faults of their form. */\nexport type ReadsParse = { readonly ok: true; readonly reads: readonly UseRead[] } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of a list of reads of the used amounts. It gives the reads, or the faults of their form.\n * Each fault names its place in the list, for example `0.amount`.\n */\nexport function parseReads(value: unknown): ReadsParse {\n const result = readsSchema.safeParse(value);\n if (result.success) return { ok: true, reads: result.data };\n return { ok: false, errors: formErrors(READS_NAME, result.error.issues) };\n}\n"],"mappings":";;;;AAQA,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAE3B,MAAM,QAAQ,EAAE,aAAa;CAC3B,MAAM,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC;CAC7B,QAAQ,EAAE,OAAO;CACjB,UAAU,EAAE,QAAQ,CAAC,CAAC,SAAS;CAC/B,MAAM,GAAG,SAAS;AACpB,CAAC;AAED,MAAM,QAAQ,EAAE,aAAa;CAC3B,MAAM,EAAE,OAAO;CACf,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACpB,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;AAC9B,CAAC;AAED,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,SAAS,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC;CAC7B,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,QAAQ,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;AAC7C,CAAC;AAED,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM,EAAE,OAAO;CACf,MAAM,KAAK,SAAS;
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { formErrors } from \"@mark1russell7/system-stack/schema\";\nimport { z } from \"zod\";\nimport { BILLINGS, LIMIT_KINDS, SPEND_SCHEMA, type SpendLayer } from \"./layer.ts\";\nimport { USE_SOURCES, type UseRead } from \"./reads.ts\";\n\n// The zod schema of a spend layer, and the read of its JSON. This module is the entry `/schema` of the package.\n// The root entry has no zod, so a page that only evaluates the cost math gets no schema library.\n\nconst id = z.string().min(1);\n\nconst limit = z.strictObject({\n kind: z.enum([...LIMIT_KINDS]),\n amount: z.number(),\n recharge: z.boolean().optional(),\n stop: id.optional(),\n});\n\nconst proof = z.strictObject({\n date: z.string(),\n by: z.string().min(1),\n source: z.string().optional(),\n});\n\nconst next = z.strictObject({\n plan: z.string().optional(),\n billing: z.enum([...BILLINGS]),\n price: z.number().optional(),\n limits: z.array(limit).readonly().optional(),\n});\n\nconst decided = z.strictObject({\n date: z.string(),\n by: z.string().min(1),\n});\n\nconst ends = z.strictObject({\n date: z.string(),\n next: next.optional(),\n decided: decided.optional(),\n});\n\nconst service = z.strictObject({\n part: id,\n plan: z.string().optional(),\n billing: z.enum([...BILLINGS]),\n price: z.number().optional(),\n limits: z.array(limit).readonly().optional(),\n wanted: limit.optional(),\n ends: ends.optional(),\n proof: proof.optional(),\n steps: z.array(z.string()).readonly().optional(),\n});\n\n/**\n * The schema of a spend layer. It examines the form of the record: the fields, their types and the finite numbers.\n * It refuses a field that the format does not have. `checkSpend` examines the meaning of a layer with a correct form.\n */\nexport const spendSchema: z.ZodType<SpendLayer> = z.strictObject({\n schema: z.literal(SPEND_SCHEMA),\n currency: z.string().regex(/^[A-Z]{3}$/, \"The currency is a code of three capital letters.\"),\n kinds: z.array(z.string().min(1)).readonly(),\n proofDays: z.number().positive(),\n endDays: z.number().nonnegative().optional(),\n services: z.array(service).readonly(),\n});\n\n/** The result of the read of a spend layer: the layer, or the faults of its form. */\nexport type SpendParse = { readonly ok: true; readonly layer: SpendLayer } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of a spend layer. It gives the layer, or the faults of its form.\n * Each fault names its place in the record, for example `services.0.part`.\n */\nexport function parseSpend(value: unknown): SpendParse {\n const read = spendSchema.safeParse(value);\n if (read.success) return { ok: true, layer: read.data };\n return { ok: false, errors: formErrors(SPEND_SCHEMA, read.error.issues) };\n}\n\nconst read = z.strictObject({\n part: id,\n source: z.enum([...USE_SOURCES]),\n amount: z.number(),\n date: z.string(),\n});\n\n/** The name of a list of reads in a fault of its form. */\nconst READS_NAME = `${SPEND_SCHEMA} reads`;\n\n/**\n * The schema of a list of reads of the used amounts. It examines the form of each read: the fields, their types and the finite numbers.\n * `checkUse` examines the meaning of the reads with a correct form.\n */\nexport const readsSchema: z.ZodType<readonly UseRead[]> = z.array(read).readonly();\n\n/** The result of the read of a list of reads: the reads, or the faults of their form. */\nexport type ReadsParse = { readonly ok: true; readonly reads: readonly UseRead[] } | { readonly ok: false; readonly errors: readonly string[] };\n\n/**\n * This function reads the JSON of a list of reads of the used amounts. It gives the reads, or the faults of their form.\n * Each fault names its place in the list, for example `0.amount`.\n */\nexport function parseReads(value: unknown): ReadsParse {\n const result = readsSchema.safeParse(value);\n if (result.success) return { ok: true, reads: result.data };\n return { ok: false, errors: formErrors(READS_NAME, result.error.issues) };\n}\n"],"mappings":";;;;AAQA,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAE3B,MAAM,QAAQ,EAAE,aAAa;CAC3B,MAAM,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC;CAC7B,QAAQ,EAAE,OAAO;CACjB,UAAU,EAAE,QAAQ,CAAC,CAAC,SAAS;CAC/B,MAAM,GAAG,SAAS;AACpB,CAAC;AAED,MAAM,QAAQ,EAAE,aAAa;CAC3B,MAAM,EAAE,OAAO;CACf,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACpB,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;AAC9B,CAAC;AAED,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,SAAS,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC;CAC7B,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,QAAQ,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;AAC7C,CAAC;AAED,MAAM,UAAU,EAAE,aAAa;CAC7B,MAAM,EAAE,OAAO;CACf,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AACtB,CAAC;AAED,MAAM,OAAO,EAAE,aAAa;CAC1B,MAAM,EAAE,OAAO;CACf,MAAM,KAAK,SAAS;C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MnC,MAAa,cAA6C,EAAE,MAAM,IAAI,CAAC,CAAC,SAAS;;;;;AASjF,SAAgB,WAAW,OAA4B;CACrD,MAAM,SAAS,YAAY,UAAU,KAAK;CAC1C,IAAI,OAAO,SAAS,OAAO;EAAE,IAAI;EAAM,OAAO,OAAO;CAAK;CAC1D,OAAO;EAAE,IAAI;EAAO,QAAQ,WAAW,YAAY,OAAO,MAAM,MAAM;CAAE;AAC1E"}
|
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.7",
|
|
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": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"build"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@mark1russell7/system-stack": "0.1.
|
|
52
|
+
"@mark1russell7/system-stack": "0.1.5",
|
|
53
53
|
"@mark1russell7/vex": "^0.19.1",
|
|
54
54
|
"@mark1russell7/vex-domains": "^0.19.1",
|
|
55
55
|
"zod": "^4.6.7"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-CpHvgGvh.d.ts","names":[],"sources":["../src/check.ts"],"mappings":";;;cAOa;;KAuCD,oBAAoB;;UAGf,mBAAmB;WACzB,MAAM;;;UAIA;;WAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkDK,WAAW,OAAO,YAAY,OAAO,OAAO,SAAS,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"join-BsjQ9eKd.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.\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 * - `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 } = 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 push(\"warning\", \"end-soon\", at, `The plan of \"${at}\" ends on ${date}, ${inDays(end - today)}. ${then}`);\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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