@mark1russell7/stack-spend 0.0.0-bootstrap.0 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +471 -1
- package/build/add-on.d.ts +16 -0
- package/build/add-on.d.ts.map +1 -0
- package/build/add-on.js +28 -0
- package/build/add-on.js.map +1 -0
- package/build/check-CpHvgGvh.d.ts +51 -0
- package/build/check-CpHvgGvh.d.ts.map +1 -0
- package/build/index.d.ts +333 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +488 -0
- package/build/index.js.map +1 -0
- package/build/join-BsjQ9eKd.js +413 -0
- package/build/join-BsjQ9eKd.js.map +1 -0
- package/build/layer-BYSJfC_1.d.ts +104 -0
- package/build/layer-BYSJfC_1.d.ts.map +1 -0
- package/build/reads-BNyUIVaY.js +48 -0
- package/build/reads-BNyUIVaY.js.map +1 -0
- package/build/reads-HuHaDiHO.d.ts +37 -0
- package/build/reads-HuHaDiHO.d.ts.map +1 -0
- package/build/schema.d.ts +40 -0
- package/build/schema.d.ts.map +1 -0
- package/build/schema.js +95 -0
- package/build/schema.js.map +1 -0
- package/package.json +72 -6
package/build/index.js
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
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-BsjQ9eKd.js";
|
|
3
|
+
import { app, axes, each, let_, lit, parent, ref, space, v } from "@mark1russell7/vex";
|
|
4
|
+
import { dayNumber as dayNumber$1, partsById, stopped } from "@mark1russell7/system-stack";
|
|
5
|
+
// src/ends.ts
|
|
6
|
+
/**
|
|
7
|
+
* This function gives the end of the plan of each service that has one, with the nearest date first.
|
|
8
|
+
*
|
|
9
|
+
* - Two ends on one date are in the sequence of the records. The first record of a part is used.
|
|
10
|
+
* - A record whose date is not a date is not in the result. The gate gives the fault `end-date` for it.
|
|
11
|
+
*
|
|
12
|
+
* The function is pure. It has no clock: the caller gives the date.
|
|
13
|
+
*
|
|
14
|
+
* @throws RangeError when `today` is not a date `YYYY-MM-DD`
|
|
15
|
+
*/
|
|
16
|
+
function planEnds(layer, options) {
|
|
17
|
+
const today = dayNumber$1(options.today);
|
|
18
|
+
if (today === void 0) throw new RangeError(`The date "${options.today}" is not a date of the form YYYY-MM-DD.`);
|
|
19
|
+
const ends = [];
|
|
20
|
+
for (const service of firstServices(layer)) {
|
|
21
|
+
if (service.ends === void 0) continue;
|
|
22
|
+
const end = dayNumber$1(service.ends.date);
|
|
23
|
+
if (end === void 0) continue;
|
|
24
|
+
ends.push({
|
|
25
|
+
part: service.part,
|
|
26
|
+
date: service.ends.date,
|
|
27
|
+
days: end - today,
|
|
28
|
+
stops: service.ends.next === void 0
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return ends.sort((first, second) => first.days - second.days);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* This function gives the parts of a stack that stop when the plans that end in `days` days, or fewer, come to their end.
|
|
35
|
+
*
|
|
36
|
+
* - A plan that ended before `today` is in the result too.
|
|
37
|
+
* - A service with a plan after the end does not stop: its cost changes.
|
|
38
|
+
* - `stopped` comes from the needs of the stack: `stopped` of the core, with the parts of `ended` down.
|
|
39
|
+
*
|
|
40
|
+
* For the parts that stop with one service, use `stopped` of the core with the `id` of its part.
|
|
41
|
+
* The function is pure.
|
|
42
|
+
*
|
|
43
|
+
* @throws RangeError when `today` is not a date `YYYY-MM-DD`
|
|
44
|
+
*/
|
|
45
|
+
function endStops(layer, stack, options) {
|
|
46
|
+
const days = options.days ?? layer.endDays ?? 30;
|
|
47
|
+
const ended = planEnds(layer, options).filter((end) => end.stops && end.days <= days).map((end) => end.part);
|
|
48
|
+
return {
|
|
49
|
+
ended,
|
|
50
|
+
stopped: stopped(stack, ended)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// src/steps.ts
|
|
54
|
+
/** These are the codes of the faults that the owner of an account corrects in the account of the service. */
|
|
55
|
+
const OWNER_CODES = [
|
|
56
|
+
"limit-wanted",
|
|
57
|
+
"limit-recharge",
|
|
58
|
+
"end-past",
|
|
59
|
+
"end-soon",
|
|
60
|
+
"end-open",
|
|
61
|
+
"proof-none",
|
|
62
|
+
"proof-old"
|
|
63
|
+
];
|
|
64
|
+
/** This function gives the sentence for a wanted limit that the owner sets in the account. */
|
|
65
|
+
function wantedText(limit, currency) {
|
|
66
|
+
const amount = `${String(limit.amount)} ${currency}`;
|
|
67
|
+
if (limit.kind === "provider") return `Set a hard limit of ${amount} for a month.`;
|
|
68
|
+
if (limit.kind === "prepaid") return `Keep a prepaid balance of ${amount} at most, with no automatic recharge.`;
|
|
69
|
+
return `Set an alert at ${amount} for a month.`;
|
|
70
|
+
}
|
|
71
|
+
/** This function gives the sentence for a plan that ends soon. */
|
|
72
|
+
function endText(ends) {
|
|
73
|
+
if (ends.next === void 0) return `Decide before ${ends.date} if the service continues. With no change, the provider stops it after that date.`;
|
|
74
|
+
return `Stop the service before ${ends.date} if the cost after that date is not wanted.`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* This function gives the work of the owner of the accounts, in the sequence of the records.
|
|
78
|
+
*
|
|
79
|
+
* - `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
|
+
* - `limit-recharge`: stop the automatic recharge of the balance.
|
|
81
|
+
* - `end-soon`: decide before the date. A service with no plan after the end stops, and the cost of each other service changes.
|
|
82
|
+
* - `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
|
+
* - `end-past`, `proof-none` and `proof-old`: read the plan and the limits in the account, and give them with the date.
|
|
84
|
+
*
|
|
85
|
+
* Each other fault of the gate is a fault of the records, which their writer corrects.
|
|
86
|
+
*
|
|
87
|
+
* @throws RangeError when `today` is not a date `YYYY-MM-DD`
|
|
88
|
+
*/
|
|
89
|
+
function ownerSteps(layer, stack, options) {
|
|
90
|
+
const parts = partsById(stack);
|
|
91
|
+
const services = new Map(layer.services.map((service) => [service.part, service]).reverse());
|
|
92
|
+
const steps = [];
|
|
93
|
+
const faults = checkSpend(layer, stack, options);
|
|
94
|
+
const open = new Set(faults.filter((fault) => fault.code === "end-open").map((fault) => fault.at));
|
|
95
|
+
for (const fault of faults) {
|
|
96
|
+
const code = OWNER_CODES.find((item) => item === fault.code);
|
|
97
|
+
const service = services.get(fault.at);
|
|
98
|
+
if (code === void 0 || service === void 0) continue;
|
|
99
|
+
if (code === "limit-wanted" && service.wanted?.kind === "code") continue;
|
|
100
|
+
if (code === "end-soon" && open.has(fault.at)) continue;
|
|
101
|
+
let text = "Read the plan and the limits in the account, and give them with the date of the read.";
|
|
102
|
+
if (code === "limit-recharge") text = "Stop the automatic recharge of the prepaid balance.";
|
|
103
|
+
if (code === "limit-wanted" && service.wanted !== void 0) text = wantedText(service.wanted, layer.currency);
|
|
104
|
+
if (code === "end-soon" && service.ends !== void 0) text = endText(service.ends);
|
|
105
|
+
if (code === "end-open" && service.ends !== void 0) text = `Set a hard limit for the cost after ${service.ends.date}, or stop the service before that date.`;
|
|
106
|
+
steps.push({
|
|
107
|
+
part: fault.at,
|
|
108
|
+
name: parts.get(fault.at)?.name ?? fault.at,
|
|
109
|
+
code,
|
|
110
|
+
text,
|
|
111
|
+
steps: service.steps ?? []
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return steps;
|
|
115
|
+
}
|
|
116
|
+
// src/use-plan.ts
|
|
117
|
+
/** This function gives the month of a date `YYYY-MM-DD`, as `YYYY-MM`. */
|
|
118
|
+
function monthOf(date) {
|
|
119
|
+
return date.slice(0, 7);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* This function examines the options and each read.
|
|
123
|
+
*
|
|
124
|
+
* - `read-part`: the read names a part with no cost record.
|
|
125
|
+
* - `read-amount`: the amount is less than 0 or not finite.
|
|
126
|
+
* - `read-date`: the date is not a date, or it is after the date of the check.
|
|
127
|
+
*
|
|
128
|
+
* A read has one code at most: the first fault of this list.
|
|
129
|
+
*
|
|
130
|
+
* @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid
|
|
131
|
+
*/
|
|
132
|
+
function usePlan(layer, reads, options) {
|
|
133
|
+
const today = dayNumber$1(options.today);
|
|
134
|
+
if (today === void 0) throw new RangeError(`The date "${options.today}" is not a date of the form YYYY-MM-DD.`);
|
|
135
|
+
const levels = options.levels ?? USE_LEVELS;
|
|
136
|
+
for (const level of levels) if (!Number.isFinite(level) || level <= 0) throw new RangeError(`The level ${String(level)} is not a finite number above 0.`);
|
|
137
|
+
const readDays = options.readDays;
|
|
138
|
+
if (readDays !== void 0 && (!Number.isFinite(readDays) || readDays < 0)) throw new RangeError(`The largest age ${String(readDays)} of a read is less than 0 or not finite.`);
|
|
139
|
+
const parts = new Set(layer.services.map((service) => service.part));
|
|
140
|
+
const ages = reads.map((read) => dayNumber$1(read.date)).map((day) => day === void 0 || day > today ? void 0 : today - day);
|
|
141
|
+
const codes = reads.map((read, index) => {
|
|
142
|
+
if (!parts.has(read.part)) return "read-part";
|
|
143
|
+
if (!Number.isFinite(read.amount) || read.amount < 0) return "read-amount";
|
|
144
|
+
return ages[index] === void 0 ? "read-date" : void 0;
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
today,
|
|
148
|
+
month: monthOf(options.today),
|
|
149
|
+
levels,
|
|
150
|
+
readDays,
|
|
151
|
+
codes,
|
|
152
|
+
ages
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
// src/use.ts
|
|
156
|
+
/** This test tells if a read node is of the month of the layer node. The program evaluates at a read. */
|
|
157
|
+
const IN_MONTH = app("eq", ref("month"), ref("month", [parent, parent]));
|
|
158
|
+
/** The reads of a service in the month of the check. */
|
|
159
|
+
const MONTH_READS = axes.where(axes.children, IN_MONTH);
|
|
160
|
+
/** This function gives the amount of each read of one source, for a service in the month of the check. */
|
|
161
|
+
function amountsOf(source) {
|
|
162
|
+
return each(axes.where(MONTH_READS, app("eq", ref("source"), lit(source))), ref("amount"));
|
|
163
|
+
}
|
|
164
|
+
/** The largest amount that a part of the stack counted for a service in the month. With no such read, it gives `#N/A`. */
|
|
165
|
+
const COUNT_USED = app("max", amountsOf("count"));
|
|
166
|
+
/** The largest amount that the provider showed for a service in the month. With no such read, it gives `#N/A`. */
|
|
167
|
+
const PROVIDER_USED = app("max", amountsOf("provider"));
|
|
168
|
+
/**
|
|
169
|
+
* The used amount of a service in the month: the larger of the count of the stack and the amount of the provider.
|
|
170
|
+
* It is the largest amount of the reads of the month, because the cost of a month does not go down.
|
|
171
|
+
* With no read of the month, it gives `#N/A`.
|
|
172
|
+
*/
|
|
173
|
+
const USED = app("max", each(MONTH_READS, ref("amount")));
|
|
174
|
+
/** 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. */
|
|
175
|
+
const USE_SHARE = app("divide", USED, ref("limit"));
|
|
176
|
+
/** This test tells if the used amount of a service is more than its hard limit. Such a limit did not hold. */
|
|
177
|
+
const USE_OVER = app("gt", USED, ref("limit"));
|
|
178
|
+
/**
|
|
179
|
+
* The tolerance of the comparison of a share with a level. A share reaches a level when it is the level less this
|
|
180
|
+
* tolerance, or more. Thus the rounding of a division does not hide a level: 2.4 of 3 reaches the level 0.8.
|
|
181
|
+
*/
|
|
182
|
+
const LEVEL_TOLERANCE = 1e-9;
|
|
183
|
+
/**
|
|
184
|
+
* The largest level that the used share of a service reached. A share below each level gives 0.
|
|
185
|
+
* With no read or no limit, it gives `#N/A`. The levels are in the field `levels` of the layer node.
|
|
186
|
+
*/
|
|
187
|
+
const USE_LEVEL = let_({ share: app("add", USE_SHARE, lit(LEVEL_TOLERANCE)) }, app("max", each(axes.list(ref("levels", [parent])), app("if", app("lte", v("level"), v("share")), v("level"), lit(0)), void 0, ["level"])));
|
|
188
|
+
/** The age of the newest read of a service in the month, in days. With no read of the month, it gives `#N/A`. */
|
|
189
|
+
const READ_AGE = app("min", each(MONTH_READS, ref("age")));
|
|
190
|
+
/**
|
|
191
|
+
* This function gives the tree of the reads of a layer, as a space of Vex.
|
|
192
|
+
*
|
|
193
|
+
* - The layer is the root, with the key `LAYER_KEY`. Its fields are `month` (the month of the check) and `levels`.
|
|
194
|
+
* - A service is a child of the layer. Its fields are `billing` and `limit`: its hard limit, from `serviceStates`.
|
|
195
|
+
* - A read is a child of its service. Its fields are `source`, `amount`, `month` and `age`: the days from its date to the check.
|
|
196
|
+
*
|
|
197
|
+
* A read with a fault is not in the tree, and `checkUse` tells the fault. The first record of a part is used.
|
|
198
|
+
*
|
|
199
|
+
* @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid
|
|
200
|
+
*/
|
|
201
|
+
function useSpace(layer, reads, options) {
|
|
202
|
+
const plan = usePlan(layer, reads, options);
|
|
203
|
+
const limits = new Map(serviceStates(layer).map((state) => [state.part, state.hardLimit]));
|
|
204
|
+
const records = { [LAYER_KEY]: {
|
|
205
|
+
kind: "layer",
|
|
206
|
+
month: plan.month,
|
|
207
|
+
levels: [...plan.levels]
|
|
208
|
+
} };
|
|
209
|
+
const parents = { [LAYER_KEY]: null };
|
|
210
|
+
for (const service of firstServices(layer)) {
|
|
211
|
+
const key = serviceKey(service.part);
|
|
212
|
+
const limit = limits.get(service.part);
|
|
213
|
+
records[key] = {
|
|
214
|
+
kind: "service",
|
|
215
|
+
billing: service.billing,
|
|
216
|
+
...limit === void 0 ? {} : { limit }
|
|
217
|
+
};
|
|
218
|
+
parents[key] = LAYER_KEY;
|
|
219
|
+
}
|
|
220
|
+
reads.forEach((read, index) => {
|
|
221
|
+
if (plan.codes[index] !== void 0) return;
|
|
222
|
+
const key = `read:${String(index)}`;
|
|
223
|
+
records[key] = {
|
|
224
|
+
kind: "read",
|
|
225
|
+
source: read.source,
|
|
226
|
+
amount: read.amount,
|
|
227
|
+
month: monthOf(read.date),
|
|
228
|
+
age: plan.ages[index]
|
|
229
|
+
};
|
|
230
|
+
parents[key] = serviceKey(read.part);
|
|
231
|
+
});
|
|
232
|
+
return space.tree(records, parents);
|
|
233
|
+
}
|
|
234
|
+
/** This function gives a record without the fields that have no value. */
|
|
235
|
+
function known(fields) {
|
|
236
|
+
return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== void 0));
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* This function gives the state of the used amount of each service of a layer, in the sequence of the services.
|
|
240
|
+
* The month is the month of `today`: a read of a different month does not count.
|
|
241
|
+
*
|
|
242
|
+
* @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid
|
|
243
|
+
*/
|
|
244
|
+
function useStates(layer, reads, options) {
|
|
245
|
+
const tree = useSpace(layer, reads, options);
|
|
246
|
+
return firstServices(layer).map((service) => {
|
|
247
|
+
const number = (program) => numberOf(evaluateService(program, tree, service.part));
|
|
248
|
+
const level = number(USE_LEVEL);
|
|
249
|
+
return {
|
|
250
|
+
part: service.part,
|
|
251
|
+
billing: service.billing,
|
|
252
|
+
...known({
|
|
253
|
+
count: number(COUNT_USED),
|
|
254
|
+
provider: number(PROVIDER_USED),
|
|
255
|
+
used: number(USED),
|
|
256
|
+
limit: number(ref("limit")),
|
|
257
|
+
share: number(USE_SHARE),
|
|
258
|
+
level: level === 0 ? void 0 : level,
|
|
259
|
+
over: booleanOf(evaluateService(USE_OVER, tree, service.part)),
|
|
260
|
+
age: number(READ_AGE)
|
|
261
|
+
})
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
// src/use-check.ts
|
|
266
|
+
/** These are the codes of the faults of the used amounts of a layer. */
|
|
267
|
+
const USE_CODES = [
|
|
268
|
+
"read-part",
|
|
269
|
+
"read-amount",
|
|
270
|
+
"read-date",
|
|
271
|
+
"use-billing",
|
|
272
|
+
"use-over",
|
|
273
|
+
"use-level",
|
|
274
|
+
"use-count",
|
|
275
|
+
"use-none",
|
|
276
|
+
"use-old"
|
|
277
|
+
];
|
|
278
|
+
/** This function gives a share as a text in percent, for example `80` for 0.8. */
|
|
279
|
+
function percent(share) {
|
|
280
|
+
return String(Number((share * 100).toFixed(6)));
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* This function gives each fault of the used amounts of a layer. A list with no error tells that the gate passes.
|
|
284
|
+
*
|
|
285
|
+
* The reads, as errors:
|
|
286
|
+
* - `read-part`: a read names a part with no cost record.
|
|
287
|
+
* - `read-amount`: the amount of a read is less than 0 or not finite.
|
|
288
|
+
* - `read-date`: the date of a read is not a date, or it is after `today`.
|
|
289
|
+
*
|
|
290
|
+
* The services, as errors:
|
|
291
|
+
* - `use-billing`: a read shows a cost of the use of a `free` or `fixed` service. The cost record is not correct.
|
|
292
|
+
* - `use-over`: the used amount of a `metered` service is more than its hard limit. The limit did not hold.
|
|
293
|
+
*
|
|
294
|
+
* The services, as warnings:
|
|
295
|
+
* - `use-level`: the used amount of a `metered` service reached a level of its hard limit.
|
|
296
|
+
* - `use-count`: the provider shows more than the stack counted. The count does not have all the use.
|
|
297
|
+
* - `use-none`: a `metered` service has no read of the month, so its used amount is not known.
|
|
298
|
+
* - `use-old`: the newest read of a `metered` service is older than `readDays`.
|
|
299
|
+
*
|
|
300
|
+
* 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.
|
|
301
|
+
*
|
|
302
|
+
* @throws RangeError when `today` is not a date `YYYY-MM-DD`, or `levels` or `readDays` is not valid
|
|
303
|
+
*/
|
|
304
|
+
function checkUse(layer, reads, options) {
|
|
305
|
+
const plan = usePlan(layer, reads, options);
|
|
306
|
+
const faults = [];
|
|
307
|
+
const add = (level, code, at, message) => {
|
|
308
|
+
faults.push({
|
|
309
|
+
level,
|
|
310
|
+
code,
|
|
311
|
+
at,
|
|
312
|
+
message
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
const money = (amount) => `${String(amount)} ${layer.currency}`;
|
|
316
|
+
reads.forEach((read, index) => {
|
|
317
|
+
const code = plan.codes[index];
|
|
318
|
+
if (code === "read-part") add("error", code, read.part, `A read names "${read.part}", which has no cost record.`);
|
|
319
|
+
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.`);
|
|
320
|
+
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}.`);
|
|
321
|
+
});
|
|
322
|
+
for (const state of useStates(layer, reads, options)) {
|
|
323
|
+
const at = state.part;
|
|
324
|
+
if (state.billing !== "metered") {
|
|
325
|
+
if (state.used !== void 0 && state.used > 0) 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}.`);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (state.used === void 0) {
|
|
329
|
+
add("warning", "use-none", at, `No read gives the used amount of "${at}" in the month ${plan.month}.`);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (state.over === true && state.limit !== void 0) 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.`);
|
|
333
|
+
else if (state.level !== void 0 && state.limit !== void 0) 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.`);
|
|
334
|
+
if (state.count !== void 0 && state.provider !== void 0 && state.provider > state.count) 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.`);
|
|
335
|
+
if (plan.readDays !== void 0 && state.age !== void 0 && state.age > plan.readDays) 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)}.`);
|
|
336
|
+
}
|
|
337
|
+
return faults;
|
|
338
|
+
}
|
|
339
|
+
// src/sample.ts
|
|
340
|
+
/** The date of the check of the sample. With it, the gate gives the faults that the README shows. */
|
|
341
|
+
const SAMPLE_TODAY = "2026-11-16";
|
|
342
|
+
/**
|
|
343
|
+
* A sample spend layer for `SAMPLE_STACK` of the core. Each name and each amount is an example.
|
|
344
|
+
* It has two faults: the only limit of the cloud account is an alert, and the balance of the call account gets money automatically.
|
|
345
|
+
*/
|
|
346
|
+
const SAMPLE_SPEND = {
|
|
347
|
+
schema: SPEND_SCHEMA,
|
|
348
|
+
currency: "USD",
|
|
349
|
+
kinds: ["account"],
|
|
350
|
+
proofDays: 90,
|
|
351
|
+
services: [
|
|
352
|
+
{
|
|
353
|
+
part: "cloud-account",
|
|
354
|
+
plan: "A free allowance, then a price for the use",
|
|
355
|
+
billing: "metered",
|
|
356
|
+
limits: [{
|
|
357
|
+
kind: "alert",
|
|
358
|
+
amount: 5
|
|
359
|
+
}],
|
|
360
|
+
proof: {
|
|
361
|
+
date: "2026-11-10",
|
|
362
|
+
by: "The owner",
|
|
363
|
+
source: "The billing page of the account"
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
part: "push-account",
|
|
368
|
+
plan: "A license that was paid one time",
|
|
369
|
+
billing: "fixed",
|
|
370
|
+
price: 0,
|
|
371
|
+
proof: {
|
|
372
|
+
date: "2026-11-10",
|
|
373
|
+
by: "The owner",
|
|
374
|
+
source: "The license page of the account"
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
part: "call-account",
|
|
379
|
+
plan: "A price for each call",
|
|
380
|
+
billing: "metered",
|
|
381
|
+
limits: [{
|
|
382
|
+
kind: "prepaid",
|
|
383
|
+
amount: 20,
|
|
384
|
+
recharge: true
|
|
385
|
+
}, {
|
|
386
|
+
kind: "code",
|
|
387
|
+
amount: 10,
|
|
388
|
+
stop: "program-home"
|
|
389
|
+
}],
|
|
390
|
+
proof: {
|
|
391
|
+
date: "2026-11-10",
|
|
392
|
+
by: "The owner",
|
|
393
|
+
source: "The billing page of the account"
|
|
394
|
+
},
|
|
395
|
+
steps: [
|
|
396
|
+
"Open the billing page of the account.",
|
|
397
|
+
"Stop the automatic recharge.",
|
|
398
|
+
"Save the change."
|
|
399
|
+
]
|
|
400
|
+
}
|
|
401
|
+
]
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* 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.
|
|
405
|
+
*
|
|
406
|
+
* - The free trial of the cloud account ends. After the end, the cost grows with the use, and its only limit is an alert.
|
|
407
|
+
* - The free credit of the call account ends. The record gives no plan after the end, so the provider stops the service.
|
|
408
|
+
*
|
|
409
|
+
* With the date `SAMPLE_TODAY`, the two ends are in the 30 days of warning.
|
|
410
|
+
*/
|
|
411
|
+
const SAMPLE_ENDS = {
|
|
412
|
+
schema: SPEND_SCHEMA,
|
|
413
|
+
currency: "USD",
|
|
414
|
+
kinds: ["account"],
|
|
415
|
+
proofDays: 90,
|
|
416
|
+
services: [
|
|
417
|
+
{
|
|
418
|
+
part: "cloud-account",
|
|
419
|
+
plan: "A free trial",
|
|
420
|
+
billing: "free",
|
|
421
|
+
ends: {
|
|
422
|
+
date: "2026-12-01",
|
|
423
|
+
next: {
|
|
424
|
+
plan: "A price for the use",
|
|
425
|
+
billing: "metered",
|
|
426
|
+
limits: [{
|
|
427
|
+
kind: "alert",
|
|
428
|
+
amount: 5
|
|
429
|
+
}]
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
proof: {
|
|
433
|
+
date: "2026-11-10",
|
|
434
|
+
by: "The owner",
|
|
435
|
+
source: "The billing page of the account"
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
part: "push-account",
|
|
440
|
+
plan: "A license that was paid one time",
|
|
441
|
+
billing: "fixed",
|
|
442
|
+
price: 0,
|
|
443
|
+
proof: {
|
|
444
|
+
date: "2026-11-10",
|
|
445
|
+
by: "The owner",
|
|
446
|
+
source: "The license page of the account"
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
part: "call-account",
|
|
451
|
+
plan: "A free credit, with no payment method",
|
|
452
|
+
billing: "free",
|
|
453
|
+
ends: { date: "2026-11-30" },
|
|
454
|
+
proof: {
|
|
455
|
+
date: "2026-11-10",
|
|
456
|
+
by: "The owner",
|
|
457
|
+
source: "The billing page of the account"
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
]
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* Sample reads of the used amounts of `SAMPLE_SPEND`, for the date `SAMPLE_TODAY`. Each amount is an example.
|
|
464
|
+
* 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.
|
|
465
|
+
*/
|
|
466
|
+
const SAMPLE_READS = [
|
|
467
|
+
{
|
|
468
|
+
part: "cloud-account",
|
|
469
|
+
source: "provider",
|
|
470
|
+
amount: 0,
|
|
471
|
+
date: "2026-11-15"
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
part: "call-account",
|
|
475
|
+
source: "count",
|
|
476
|
+
amount: 4,
|
|
477
|
+
date: "2026-11-16"
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
part: "call-account",
|
|
481
|
+
source: "provider",
|
|
482
|
+
amount: 5.2,
|
|
483
|
+
date: "2026-11-16"
|
|
484
|
+
}
|
|
485
|
+
];
|
|
486
|
+
export { BILLINGS, BOUNDED_TOTAL, COUNT_USED, END_DAYS, HARD_COUNT, HARD_LIMIT, HARD_LIMITS, IS_HARD, LAYER_KEY, LEVEL_TOLERANCE, LIMIT_KINDS, MONTH_MAX, MONTH_READS, NEXT_PLANS, NODE_KINDS, OPEN_SERVICES, OWNER_CODES, PLAN_MAX, PROVIDER_USED, READ_AGE, SAMPLE_ENDS, SAMPLE_READS, SAMPLE_SPEND, SAMPLE_TODAY, SPEND_CODES, SPEND_SCHEMA, USED, USE_CODES, USE_LEVEL, USE_LEVELS, USE_OVER, USE_SHARE, USE_SOURCES, checkSpend, checkUse, dayNumber, endStops, evaluateNext, evaluateService, firstServices, joinSpend, monthTotal, nextKey, ownerSteps, planEnds, serviceKey, serviceStates, spendSpace, useSpace, useStates };
|
|
487
|
+
|
|
488
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;GAAE,MAAM,QAAQ;GAAM,MAAM,QAAQ,KAAK;GAAM,MAAM,MAAM;GAAO,OAAO,QAAQ,KAAK,SAAS,KAAA;EAAU,CAAC;CACtH;CAEA,OAAO,KAAK,MAAM,OAAO,WAAW,MAAM,OAAO,OAAO,IAAI;AAC9D;;;;;;;;;;;;;AA+BA,SAAgB,SAAS,OAAmB,OAAc,SAA+B;CACvF,MAAM,OAAO,QAAQ,QAAQ,MAAM,WAAA;CACnC,MAAM,QAAQ,SAAS,OAAO,OAAO,CA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