@mark1russell7/stack-endurance 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -89,6 +89,17 @@ const year = yearShortfall(SAMPLE_ENDURANCE, "home", { at: "2026-12-01" });
89
89
 
90
90
  In the sample, the rice needs 2 L of water for each kg. The drinking water holds 6.667 days, and it keeps back all the water for these days. So the rice gives nothing, and the food holds 0.889 days on the cans.
91
91
 
92
+ ## The join
93
+
94
+ `joinEndurance(pieces)` joins the endurance layers of the fragments of a stack, for example one file of stores for each owner.
95
+
96
+ - Two fragments can declare one resource code. When the two records are equal, the joined layer has one record.
97
+ - The join compares the records with canonical JSON (RFC 8785). Thus the order of the keys has no effect.
98
+ - When the unit or a different field is not equal, the join has a fault. The message names the fragments and the resource code.
99
+ - The join is `joinRecords` of the core with the option `equal`.
100
+ - One key of a store, a draw, a direct use, a converter, a case or a prior in two fragments is a fault.
101
+ - The levels are one setting. Each fragment with levels gives the same list.
102
+
92
103
  ## The gate
93
104
 
94
105
  `checkEndurance(layer, stack)` gives the faults of a layer. `ENDURANCE_CODES` lists the codes. The gate finds two records with one key, and an unknown level, resource or part. It also finds a value out of range, a bad date, an empty converter and a bad survival curve. Converters that make a resource from itself are a cycle, and the gate refuses them. A draw with no way to get its need is a warning, and a cut with no curve is a warning.
package/build/add-on.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as checkEndurance, t as joinEndurance } from "./join-BiG5NScO.js";
1
+ import { r as checkEndurance, t as joinEndurance } from "./join-D5n6U49k.js";
2
2
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
3
3
  import { parseEndurance } from "./schema.js";
4
4
  // src/add-on.ts
package/build/index.d.ts CHANGED
@@ -296,7 +296,10 @@ export declare function hasEnduranceError(faults: readonly EnduranceFault[]): bo
296
296
  *
297
297
  * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.
298
298
  * - The records of each list are in the order of the fragments.
299
- * - One key in two or more fragments is a fault, also when the records are equal. The key of a direct use is its resource and its need.
299
+ * - Two resources with one code in two fragments join into one resource when their records are equal. A different field is a fault.
300
+ * - A code that one fragment has two times stays in the joined layer. The gate `checkEndurance` finds it.
301
+ * - One key of each other list in two or more fragments is a fault, also when the records are equal.
302
+ * - The key of a direct use is its resource and its need.
300
303
  *
301
304
  * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.
302
305
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/endurance.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAOiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;wBAOK,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAoB/E,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;;;;;;;;;;;;;wBAiKxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;wBCpO9E,WAAW,OAAO,UAAU;;;;;;wBAoB5B,SAAS,OAAO,UAAU,cAAc;;;;;;;;;;iBAqBvC,yBAAyB,KAAK,gCAAgC,KAAK;;WAEzE;;iBAGM,yBAAyB;;WAE/B;;;;;;wBAqBK,iBAAiB,OAAO,UAAU;;wBAWlC,WAAW,OAAO;;wBAKlB,SAAS,OAAO;;;;;;;;;;;;;;;;wBAoDhB,UAAU,iBAAiB,YAAY,QAAQ,sCAAsC;;;;;;;;wBAiBrF,YAAY,iBAAiB,aAAa;;;;;qBAU7C;;;;;wBAMG,aAAa,eAAe,QAAQ;;;;;;;;;;wBA8BpC,UAAU,iBAAiB,YAAY,mDAAmD;;qBAiB7F;;;;;;qBAO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;;;;;;wBC5KnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCd5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
- import { a as hasEnduranceError, c as drawDemand, d as giftResource, f as storeAmounts, i as curveFault, l as enduranceOf, n as ENDURANCE_CODES, o as caseDraws, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed } from "./join-BiG5NScO.js";
2
+ import { a as hasEnduranceError, c as drawDemand, d as giftResource, f as storeAmounts, i as curveFault, l as enduranceOf, n as ENDURANCE_CODES, o as caseDraws, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed } from "./join-D5n6U49k.js";
3
3
  import { DEFAULT_MAX_SETS, STACK_SCHEMA, neededParts, stopSets } from "@mark1russell7/system-stack";
4
4
  import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
5
5
  // src/stops.ts
@@ -1,6 +1,7 @@
1
1
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
2
  import { curveFault, curveFault as curveFault$1, dayNumber, joinRecords, joinSetting, stopped } from "@mark1russell7/system-stack";
3
3
  import { stronglyConnectedComponents } from "@mark1russell7/collections/graph";
4
+ import { canonicalJson } from "@mark1russell7/rigor-generators";
4
5
  // src/fit.ts
5
6
  /** The relative tolerance of a take and of a fit. */
6
7
  const TOLERANCE = 1e-13;
@@ -500,7 +501,10 @@ function hasEnduranceError(faults) {
500
501
  *
501
502
  * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.
502
503
  * - The records of each list are in the order of the fragments.
503
- * - One key in two or more fragments is a fault, also when the records are equal. The key of a direct use is its resource and its need.
504
+ * - Two resources with one code in two fragments join into one resource when their records are equal. A different field is a fault.
505
+ * - A code that one fragment has two times stays in the joined layer. The gate `checkEndurance` finds it.
506
+ * - One key of each other list in two or more fragments is a fault, also when the records are equal.
507
+ * - The key of a direct use is its resource and its need.
504
508
  *
505
509
  * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.
506
510
  *
@@ -509,7 +513,7 @@ function hasEnduranceError(faults) {
509
513
  */
510
514
  function joinEndurance(pieces) {
511
515
  const levels = joinSetting(pieces, (layer) => layer.levels.length > 0 ? layer.levels.join("\n") : void 0, "levels");
512
- const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, "resource");
516
+ const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, "resource", { equal: (first, other) => canonicalJson(first) === canonicalJson(other) });
513
517
  const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, "store");
514
518
  const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, "draw");
515
519
  const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, "direct use");
@@ -548,4 +552,4 @@ function joinEndurance(pieces) {
548
552
  }
549
553
  export { hasEnduranceError as a, drawDemand as c, giftResource as d, storeAmounts as f, curveFault as i, enduranceOf as l, ENDURANCE_CODES as n, caseDraws as o, checkEndurance as r, caseStopped as s, joinEndurance as t, giftNeed as u };
550
554
 
551
- //# sourceMappingURL=join-BiG5NScO.js.map
555
+ //# sourceMappingURL=join-D5n6U49k.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"join-BiG5NScO.js","names":["curveFault"],"sources":["../src/fit.ts","../src/endurance.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["/** The relative tolerance of a take and of a fit. */\nexport const TOLERANCE = 1e-13;\n\n/** One try of a fit: the amount that the stores could not give, out of the amount wanted, and the value of the try. */\nexport interface Try<T> {\n readonly short: number;\n readonly need: number;\n readonly value: T;\n}\n\n/** The result of a fit: the largest amount with no shortfall, and the value of its try. The value is `undefined` when only 0 fits. */\nexport interface Fit<T> {\n readonly x: number;\n readonly value: T | undefined;\n}\n\n/**\n * The count of the tries of `largestFit`, for the tests of the cost. It is not in the public API, and it does not change a result.\n * It is the one side effect of `largestFit` and of the queries that use it.\n */\nexport const fitTries = { count: 0 };\n\n/**\n * This function gives the largest `x` in `[0, most]` at which `attempt` has no shortfall, to the relative tolerance `TOLERANCE`.\n *\n * - A try fits when its shortfall is not more than `TOLERANCE` times its need.\n * - The shortfall must not decrease when `x` increases. A take of a chain of converters gives a shortfall that is linear in parts.\n * - The first try is `most`. After it, each step tries the zero of the line through the last two tries that do not fit.\n * With one try that does not fit, the step tries `x` times the part of the need that the stores gave.\n * - When a step does not halve the interval, the next step is a bisection. Thus a fit takes at most approximately twice the steps of a bisection.\n * - A step on the lower end tries a point just above it, so a correct estimate ends the fit in one more try.\n * - An estimate that fits with a shortfall above 0 is in the band of the tolerance above the zero, so the fit ends there.\n * A bisection step or a probe at the lower end can fit with a shortfall of rounding below the zero. The fit does not end there.\n *\n * @param most - The upper limit of `x`\n * @param attempt - The try at an amount. It must not change its input\n * @returns The largest amount that fits, and the value of its try\n */\nexport function largestFit<T>(most: number, attempt: (x: number) => Try<T>): Fit<T> {\n const fits = (tried: Try<T>): boolean => tried.short <= TOLERANCE * tried.need;\n fitTries.count += 1;\n const first = attempt(most);\n if (fits(first)) return { x: most, value: first.value };\n let low = 0;\n let best: T | undefined;\n let high = most;\n let highShort = first.short;\n let highNeed = first.need;\n let before: { readonly x: number; readonly short: number } | undefined;\n let bisect = false;\n for (let step = 0; step < 400 && high - low > 4 * TOLERANCE * high; step += 1) {\n const width = high - low;\n let x: number;\n if (bisect) x = (low + high) / 2;\n else if (before !== undefined && before.short > highShort) x = high - (highShort * (before.x - high)) / (before.short - highShort);\n else x = high * (1 - highShort / highNeed);\n // Only a secant or ratio estimate through tries that do not fit lands at or above the zero of a convex shortfall.\n const estimate = !bisect && x < high;\n if (!(x < high)) x = (low + high) / 2;\n const floor = low + 2 * TOLERANCE * high;\n const clamped = !(x > floor);\n if (clamped) x = floor;\n fitTries.count += 1;\n const tried = attempt(x);\n if (fits(tried)) {\n low = x;\n best = tried.value;\n // An estimate that fits with a shortfall is in the band of the tolerance above the zero, so the fit ends.\n if (tried.short > 0 && estimate && !clamped) break;\n } else {\n before = { x: high, short: highShort };\n high = x;\n highShort = tried.short;\n highNeed = tried.need;\n }\n bisect = !bisect && high - low > width / 2;\n }\n return { x: low, value: best };\n}\n","import { dayNumber, stopped, type Stack } from \"@mark1russell7/system-stack\";\nimport { largestFit, type Try } from \"./fit.ts\";\nimport type { CaseCuts, Converter, DirectUse, Draw, Endurance, EnduranceLayer, IsoDate } from \"./layer.ts\";\n\n// The endurance query: the days that each draw holds when a case stops its supply.\n\n/** The options of the queries of a case. */\nexport interface CaseOptions {\n /** The date of the query. A store whose due date is on this date or before it gives nothing. */\n readonly at: IsoDate;\n /** The base stack. With it, a cut also stops each part that cannot work without a cut part (`stopped` of the core). */\n readonly stack?: Stack | undefined;\n /** The `id` of more parts that are down, with the cuts of the case. */\n readonly down?: readonly string[] | undefined;\n}\n\n/**\n * This function gives the `id` of each part that does not work in a case: the cut parts and the parts of `down`.\n * With a stack, it also gives each part that stops.\n */\nexport function caseStopped(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): Set<string> {\n const down = [...caseCuts.cuts.map((cut) => cut.part), ...(options.down ?? [])];\n const out = new Set(down);\n if (options.stack !== undefined) for (const id of stopped(options.stack, down)) out.add(id);\n return out;\n}\n\n/** This function gives the day number of a date, or throws a `RangeError` for a date that is not `YYYY-MM-DD`. */\nfunction dayOf(date: IsoDate): number {\n const day = dayNumber(date);\n if (day === undefined) throw new RangeError(`The date \"${date}\" is not a date YYYY-MM-DD.`);\n return day;\n}\n\n/**\n * This function gives the amount of each resource in the stores at a date, by the code of the resource.\n *\n * - A store gives nothing on its due date and after it.\n * - A store gives nothing when its part is in `stoppedParts`.\n */\nexport function storeAmounts(layer: EnduranceLayer, at: IsoDate, stoppedParts: ReadonlySet<string> = new Set()): Map<string, number> {\n const today = dayOf(at);\n const out = new Map<string, number>();\n for (const store of layer.stores) {\n if (store.due !== undefined && today >= dayOf(store.due)) continue;\n if (store.part !== undefined && stoppedParts.has(store.part)) continue;\n out.set(store.resource, (out.get(store.resource) ?? 0) + store.amount);\n }\n return out;\n}\n\n/** This function gives the amount of a need for each day in a case: the rate of the draw times the factor of the case. */\nexport function drawDemand(draw: Draw, caseCuts: CaseCuts): number {\n return draw.perDay * (caseCuts.factors?.[draw.need] ?? 1);\n}\n\n/**\n * This function gives the draws that take from the stores in a case: each draw whose supply stops, with a demand more than 0.\n * The sequence is by the level (the order of `levels`), then by the code of the need.\n */\nexport function caseDraws(layer: EnduranceLayer, caseCuts: CaseCuts, stoppedParts: ReadonlySet<string>): Draw[] {\n const rank = (level: string): number => {\n const index = layer.levels.indexOf(level);\n return index < 0 ? layer.levels.length : index;\n };\n return layer.draws\n .filter((draw) => stoppedParts.has(draw.supply) && drawDemand(draw, caseCuts) > 0)\n .sort((a, b) => rank(a.level) - rank(b.level) || (a.need < b.need ? -1 : a.need > b.need ? 1 : 0));\n}\n\n/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */\nexport function giftNeed(converter: Converter): string | undefined {\n return \"need\" in converter.gives ? converter.gives.need : undefined;\n}\n\n/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */\nexport function giftResource(converter: Converter): string | undefined {\n return \"resource\" in converter.gives ? converter.gives.resource : undefined;\n}\n\n/** This function gives the amount of each resource that one run of a converter takes. Two lines of one resource add. */\nfunction inputsOf(converter: Converter): Map<string, number> {\n const out = new Map<string, number>();\n for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);\n return out;\n}\n\n/** This function tells if a converter can run in a case. Its device works, it takes a resource, and it gives an amount more than 0. */\nfunction canRun(converter: Converter, stoppedParts: ReadonlySet<string>): boolean {\n return converter.gives.amount > 0 && inputsOf(converter).size > 0 && (converter.device === undefined || !stoppedParts.has(converter.device));\n}\n\n/** The converters of a case that make each resource, in the order of the layer, by the code of the resource. */\ntype Makers = ReadonlyMap<string, readonly Converter[]>;\n\nfunction makersOf(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): Makers {\n const out = new Map<string, Converter[]>();\n for (const converter of layer.converters ?? []) {\n const resource = giftResource(converter);\n if (resource === undefined || !canRun(converter, stoppedParts)) continue;\n out.set(resource, [...(out.get(resource) ?? []), converter]);\n }\n return out;\n}\n\n/** The ways to get one need in a case: its direct uses, then the converters that give it, in the order of the layer. `makers` make the resources. */\ninterface Ways {\n readonly direct: readonly DirectUse[];\n readonly converters: readonly Converter[];\n readonly makers: Makers;\n}\n\nfunction waysOf(layer: EnduranceLayer, need: string, stoppedParts: ReadonlySet<string>, makers: Makers): Ways {\n return {\n direct: (layer.direct ?? []).filter((use) => use.need === need && use.amount > 0),\n converters: (layer.converters ?? []).filter((converter) => giftNeed(converter) === need && canRun(converter, stoppedParts)),\n makers,\n };\n}\n\n// A chain: the resources on the path of a take. A maker does not take a resource of its own path, so a cycle of the layer stops there.\nconst NO_PATH: ReadonlySet<string> = new Set();\n\n/**\n * This function gives the most of a resource that `left` gives: its stock, and the runs of each maker.\n * It is an upper limit. When two inputs come from one resource, the true amount can be less.\n */\nfunction mostResource(left: ReadonlyMap<string, number>, makers: Makers, resource: string, path: ReadonlySet<string>): number {\n let total = left.get(resource) ?? 0;\n if (path.has(resource)) return total;\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) total += mostRuns(left, makers, maker, next) * maker.gives.amount;\n return total;\n}\n\n/** This function gives the most runs of a converter that `left` gives. It is an upper limit, as for `mostResource`. */\nfunction mostRuns(left: ReadonlyMap<string, number>, makers: Makers, converter: Converter, path: ReadonlySet<string>): number {\n let runs = Infinity;\n for (const [resource, each] of inputsOf(converter)) runs = Math.min(runs, mostResource(left, makers, resource, path) / each);\n return Number.isFinite(runs) ? runs : 0;\n}\n\n/**\n * This function takes an amount of a resource from `left`: the stock first, then the makers in the order of the layer.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction takeResource(left: Map<string, number>, makers: Makers, resource: string, amount: number, path: ReadonlySet<string>): number {\n const has = left.get(resource) ?? 0;\n const got = Math.min(amount, has);\n left.set(resource, has - got);\n let rest = amount - got;\n if (rest <= 0 || path.has(resource)) return Math.max(0, rest);\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) {\n if (rest <= 0) break;\n rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/**\n * This function runs a converter up to `wanted` times with the resources of `left`, and it gives the count of runs.\n * It changes `left`. When two inputs come from one resource, `largestFit` finds the runs that the resources give.\n */\nfunction run(left: Map<string, number>, makers: Makers, converter: Converter, wanted: number, path: ReadonlySet<string>): number {\n const inputs = inputsOf(converter);\n const most = Math.min(wanted, mostRuns(left, makers, converter, path));\n if (!(most > 0)) return 0;\n const attempt = (runs: number): Try<Map<string, number>> => {\n const copy = new Map(left);\n let need = 0;\n let short = 0;\n for (const [resource, each] of inputs) {\n need += runs * each;\n short += takeResource(copy, makers, resource, runs * each, path);\n }\n return { short, need, value: copy };\n };\n const { x: runs, value: best } = largestFit(most, attempt);\n if (best === undefined) return 0;\n for (const [resource, amount] of best) left.set(resource, amount);\n return runs;\n}\n\n/**\n * This function takes an amount of a need from the resources in `left`: the direct uses first, then the converters.\n * A direct use or a converter takes each resource from its stock first, then from its makers.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction take(left: Map<string, number>, ways: Ways, amount: number): number {\n let rest = amount;\n for (const use of ways.direct) {\n if (rest <= 0) break;\n const wanted = rest / use.amount;\n rest -= (wanted - takeResource(left, ways.makers, use.resource, wanted, NO_PATH)) * use.amount;\n }\n for (const converter of ways.converters) {\n if (rest <= 0) break;\n rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/** This function gives each resource that a need can use: the inputs of its ways, and the inputs of their makers, through each chain. */\nfunction inputClosure(ways: Ways): Set<string> {\n const out = new Set<string>();\n const queue = [...ways.direct.map((use) => use.resource), ...ways.converters.flatMap((converter) => [...inputsOf(converter).keys()])];\n for (let resource = queue.shift(); resource !== undefined; resource = queue.shift()) {\n if (out.has(resource)) continue;\n out.add(resource);\n for (const maker of ways.makers.get(resource) ?? []) queue.push(...inputsOf(maker).keys());\n }\n return out;\n}\n\n/** The relative tolerance of a used-up resource. */\nconst USED_UP = 1e-9;\n\n/**\n * This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.\n *\n * - A draw takes from the stores only when the case stops its supply part. Each other draw holds without end, and the result leaves it out.\n * - The demand of a draw for each day is its rate times the factor of the case.\n * - The draws take the resources in the order of their level, then of their codes. A draw takes from its direct uses first, then from its converters.\n * - The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.\n * - Each higher draw keeps back its own days times its demand. Thus the takes of all the draws are not more than the stores at any time.\n * - The take order is a rule, not the best share: the direct uses in the order of the list, then the converters. The days are the days of this order.\n * - A converter whose device stops gives nothing. A store whose part stops gives nothing.\n * - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.\n *\n * The function is pure, but for an internal count of the tries of its fits for the tests. It throws a `RangeError` for a date that is not `YYYY-MM-DD`. The gate `checkEndurance` examines the layer before.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, and the stack or the parts that are also down\n * @returns The endurance of each draw whose supply stops\n */\nexport function enduranceOf(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions): Endurance {\n const stoppedParts = caseStopped(caseCuts, options);\n const start = storeAmounts(layer, options.at, stoppedParts);\n const makers = makersOf(layer, stoppedParts);\n const stocked = new Set(layer.stores.map((store) => store.resource));\n const done: { readonly ways: Ways; readonly demand: number; readonly days: number }[] = [];\n const needs: Record<string, { days: number; binding: string[]; takes: Record<string, number> }> = {};\n for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {\n const ways = waysOf(layer, draw.need, stoppedParts, makers);\n const demand = drawDemand(draw, caseCuts);\n const before = new Map(start);\n for (const higher of done) take(before, higher.ways, higher.days * higher.demand);\n const after = (days: number): { left: Map<string, number>; short: number } => {\n const left = new Map(before);\n return { left, short: take(left, ways, days * demand) };\n };\n // The upper limit: the days that the draw holds when it takes all the stores itself. `largestFit` finds the days below it.\n const fit = largestFit(capacity(start, ways) / demand, (days) => {\n const tried = after(days);\n return { short: tried.short, need: days * demand, value: tried.left };\n });\n const low = fit.x;\n const left = fit.value ?? after(low).left;\n const binding = [...inputClosure(ways)]\n .filter((resource) => !makers.has(resource) || stocked.has(resource))\n .filter((resource) => mostResource(left, makers, resource, NO_PATH) <= USED_UP * Math.max(1, start.get(resource) ?? 0))\n .sort();\n const takes: Record<string, number> = {};\n for (const [resource, amount] of before) {\n const taken = amount - (left.get(resource) ?? 0);\n if (taken > 0) takes[resource] = taken;\n }\n needs[draw.need] = { days: low, binding, takes };\n done.push({ ways, demand, days: low });\n }\n return { case: caseCuts.case, at: options.at, needs };\n}\n\n/**\n * This function gives an upper limit of a need that the stores give with no other draw, through each chain.\n * A converter that takes nothing gives nothing: the gate refuses it.\n */\nfunction capacity(start: ReadonlyMap<string, number>, ways: Ways): number {\n let total = 0;\n for (const use of ways.direct) total += mostResource(start, ways.makers, use.resource, NO_PATH) * use.amount;\n for (const converter of ways.converters) total += mostRuns(start, ways.makers, converter, NO_PATH) * converter.gives.amount;\n return total;\n}\n","import { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { curveFault, dayNumber, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { giftNeed, giftResource } from \"./endurance.ts\";\nimport type { Converter, EnduranceLayer } from \"./layer.ts\";\n\n// The gate of an endurance layer: the meaning of a layer with a correct form, for its base stack.\n\n/**\n * These are the codes of the gate. Each code is an error, except `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.\n *\n * - `endurance-twice`: two or more records of one list have one key. A key is a level, a resource, a store, a need, a converter or a case.\n * The key of a prior is its case and its place. A converter takes each resource on one line, and a case cuts each part one time.\n * - `endurance-level-unknown`: the level of a draw is not a level of the layer.\n * - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.\n * - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.\n * - `endurance-range`: an amount, a rate, a count or a factor is not a finite number of 0 or more. Or a reach is not from 0 to 1.\n * - `endurance-date`: a date is not a date `YYYY-MM-DD`.\n * - `endurance-converter-empty`: a converter takes nothing, or it gives an amount of 0.\n * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.\n * Or its days do not increase, or its chance increases.\n * - `endurance-prior-case`: a prior names a case that the layer does not have.\n * - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.\n * - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.\n * - `endurance-cut-no-curve` (warning): a cut has no curve of its duration. The draws whose stop it can be part of are no read in the shortfall.\n */\nexport const ENDURANCE_CODES: readonly [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n] = [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n];\n\n/** A code of `ENDURANCE_CODES`. */\nexport type EnduranceCode = (typeof ENDURANCE_CODES)[number];\n\n/** A fault of the gate of an endurance layer. */\nexport interface EnduranceFault extends Fault {\n readonly code: EnduranceCode;\n}\n\nexport { curveFault } from \"@mark1russell7/system-stack\";\n\n/**\n * This function gives each fault of an endurance layer. With a base stack, it also examines the `id` of each part. A list with no error tells that the gate passes.\n *\n * The faults are in the order of the layer. The function is pure.\n *\n * @param layer - The endurance layer\n * @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.\n * @returns The faults\n */\nexport function checkEndurance(layer: EnduranceLayer, stack?: Stack): EnduranceFault[] {\n const faults: EnduranceFault[] = [];\n const add = (level: EnduranceFault[\"level\"], code: EnduranceCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const once = (what: string, keys: readonly string[]): void => {\n const seen = new Set<string>();\n for (const key of keys) {\n if (seen.has(key)) add(\"error\", \"endurance-twice\", key, `Two or more ${what} have the key \"${key}\".`);\n seen.add(key);\n }\n };\n const range = (at: string, what: string, value: number): void => {\n if (!(Number.isFinite(value) && value >= 0)) add(\"error\", \"endurance-range\", at, `The ${what} of \"${at}\" is ${String(value)}. It must be a finite number of 0 or more.`);\n };\n const date = (at: string, value: string): void => {\n if (dayNumber(value) === undefined) add(\"error\", \"endurance-date\", at, `The date \"${value}\" of \"${at}\" is not a date YYYY-MM-DD.`);\n };\n const parts = stack === undefined ? undefined : new Set(stack.parts.map((part) => part.id));\n const part = (at: string, what: string, id: string | undefined): void => {\n if (parts !== undefined && id !== undefined && !parts.has(id)) add(\"error\", \"endurance-part-unknown\", at, `The ${what} \"${id}\" of \"${at}\" is not a part of the stack.`);\n };\n const resources = new Set(layer.resources.map((resource) => resource.code));\n const resource = (at: string, code: string): void => {\n if (!resources.has(code)) add(\"error\", \"endurance-resource-unknown\", at, `The resource \"${code}\" of \"${at}\" is not a resource of the layer.`);\n };\n const direct = layer.direct ?? [];\n const converters = layer.converters ?? [];\n const cases = layer.cases ?? [];\n const priors = layer.priors ?? [];\n\n once(\"levels\", layer.levels);\n once(\"resources\", layer.resources.map((item) => item.code));\n once(\"stores\", layer.stores.map((store) => store.id));\n once(\"draws\", layer.draws.map((draw) => draw.need));\n once(\"converters\", converters.map((converter) => converter.id));\n once(\"cases\", cases.map((item) => item.case));\n once(\"priors\", priors.map((prior) => `${prior.case}@${prior.place}`));\n\n for (const store of layer.stores) {\n resource(store.id, store.resource);\n range(store.id, \"amount\", store.amount);\n if (store.due !== undefined) date(store.id, store.due);\n part(store.id, \"part\", store.part);\n }\n const levels = new Set(layer.levels);\n for (const draw of layer.draws) {\n if (!levels.has(draw.level)) add(\"error\", \"endurance-level-unknown\", draw.need, `The level \"${draw.level}\" of the draw \"${draw.need}\" is not a level of the layer.`);\n range(draw.need, \"rate\", draw.perDay);\n if (draw.users !== undefined) range(draw.need, \"count of users\", draw.users);\n part(draw.need, \"supply\", draw.supply);\n const ways = direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need);\n if (!ways) add(\"warning\", \"endurance-no-way\", draw.need, `The draw \"${draw.need}\" has no direct use and no converter. It holds 0 days when its supply stops.`);\n }\n for (const use of direct) {\n const at = `${use.resource}>${use.need}`;\n resource(at, use.resource);\n range(at, \"amount\", use.amount);\n }\n for (const converter of converters) {\n once(`resources of the converter \"${converter.id}\"`, converter.takes.map((input) => input.resource));\n for (const input of converter.takes) {\n resource(converter.id, input.resource);\n range(converter.id, \"amount\", input.amount);\n }\n range(converter.id, \"amount\", converter.gives.amount);\n const made = giftResource(converter);\n if (made !== undefined) resource(converter.id, made);\n if (!converter.takes.some((input) => input.amount > 0) || converter.gives.amount === 0) add(\"error\", \"endurance-converter-empty\", converter.id, `The converter \"${converter.id}\" takes nothing, or it gives nothing.`);\n part(converter.id, \"device\", converter.device);\n }\n const caseCodes = new Set(cases.map((item) => item.case));\n for (const item of cases) {\n once(`cuts of the case \"${item.case}\"`, item.cuts.map((cut) => cut.part));\n for (const cut of item.cuts) {\n const at = `${item.case}/${cut.part}`;\n part(at, \"cut\", cut.part);\n if (cut.duration === undefined) {\n add(\"warning\", \"endurance-cut-no-curve\", at, `The cut \"${at}\" has no curve of its duration, so the draws that it can stop are no read.`);\n continue;\n }\n const fault = curveFault(cut.duration);\n if (fault !== undefined) add(\"error\", \"endurance-curve\", at, `The duration of the cut \"${at}\": ${fault}`);\n }\n for (const [need, factor] of Object.entries(item.factors ?? {})) range(`${item.case}/${need}`, \"factor\", factor);\n if (item.leadSeconds !== undefined) range(item.case, \"lead time\", item.leadSeconds);\n }\n for (const cycle of resourceCycles(converters)) {\n const [first = \"\"] = cycle;\n const names = cycle.map((code) => `\"${code}\"`).join(\", \");\n const message = cycle.length === 1 ? `A converter makes the resource ${names} from itself.` : `Converters make the resources ${names} from each other.`;\n add(\"error\", \"endurance-cycle\", first, `${message} A chain of converters cannot end.`);\n }\n for (const prior of priors) {\n const at = `${prior.case}@${prior.place}`;\n if (!caseCodes.has(prior.case)) add(\"error\", \"endurance-prior-case\", at, `The prior \"${at}\" names the case \"${prior.case}\", which the layer does not have.`);\n range(at, \"count of events in one year\", prior.perYear);\n if (!(prior.reach >= 0 && prior.reach <= 1)) add(\"error\", \"endurance-range\", at, `The reach of \"${at}\" is ${String(prior.reach)}. It must be from 0 to 1.`);\n date(at, prior.asOf);\n }\n return faults;\n}\n\n/** This function gives each cycle of resources: a resource is made from a resource that a converter makes from it. Each cycle is a list of codes. */\nfunction resourceCycles(converters: readonly Converter[]): string[][] {\n const from = new Map<string, Set<string>>();\n for (const converter of converters) {\n const made = giftResource(converter);\n if (made === undefined) continue;\n const inputs = from.get(made) ?? new Set<string>();\n for (const input of converter.takes) if (input.amount > 0) inputs.add(input.resource);\n from.set(made, inputs);\n }\n const successors = (code: string): Iterable<string> => from.get(code) ?? [];\n return stronglyConnectedComponents(from.keys(), successors).filter((component) => {\n const [only = \"\"] = component;\n return component.length > 1 || (from.get(only)?.has(only) ?? false);\n });\n}\n\n/** This function tells if a list of faults has an error. */\nexport function hasEnduranceError(faults: readonly EnduranceFault[]): boolean {\n return faults.some((fault) => fault.level === \"error\");\n}\n","import { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The join of the endurance layers of the fragments of a stack, for example one file of stores for each owner.\n\n/**\n * This function joins the endurance layers of the fragments of a stack into one layer.\n *\n * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.\n * - The records of each list are in the order of the fragments.\n * - One key in two or more fragments is a fault, also when the records are equal. The key of a direct use is its resource and its need.\n *\n * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinEndurance(pieces: readonly LayerPiece<EnduranceLayer>[]): LayerParse<EnduranceLayer> {\n const levels = joinSetting(pieces, (layer) => (layer.levels.length > 0 ? layer.levels.join(\"\\n\") : undefined), \"levels\");\n const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, \"resource\");\n const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, \"store\");\n const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, \"draw\");\n const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, \"direct use\");\n const converters = joinRecords(pieces, (layer) => layer.converters, (item) => item.id, \"converter\");\n const cases = joinRecords(pieces, (layer) => layer.cases, (item) => item.case, \"case\");\n const priors = joinRecords(pieces, (layer) => layer.priors, (item) => `${item.case}@${item.place}`, \"prior\");\n const errors = [levels, resources, stores, draws, direct, converters, cases, priors].flatMap((join) => join.errors);\n if (errors.length > 0) return { ok: false, errors };\n const has = (key: \"direct\" | \"converters\" | \"cases\" | \"priors\"): boolean => pieces.some((piece) => piece.layer[key] !== undefined);\n return {\n ok: true,\n layer: {\n schema: ENDURANCE_SCHEMA,\n levels: levels.value === undefined ? [] : levels.value.split(\"\\n\"),\n resources: resources.items,\n stores: stores.items,\n draws: draws.items,\n ...(has(\"direct\") ? { direct: direct.items } : {}),\n ...(has(\"converters\") ? { converters: converters.items } : {}),\n ...(has(\"cases\") ? { cases: cases.items } : {}),\n ...(has(\"priors\") ? { priors: priors.items } : {}),\n },\n };\n}\n"],"mappings":";;;;;AACA,MAAa,YAAY;;;;;AAmBzB,MAAa,WAAW,E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UAAU,MAAM,MAAM,SAAS,KAAA,CAAS;CACjI,OAAO;EACL,IAAI;EACJ,OAAO;GACL,QAAQ;GACR,QAAQ,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,OAAO,MAAM,MAAM,IAAI;GACjE,WAAW,UAAU;GACrB,QAAQ,OAAO;GACf,OAAO,MAAM;GACb,GAAI,IAAI,QAAQ,IAAI,EAAE,QAAQ,OAAO,MAAM,IAAI,CAAC;GAChD,GAAI,IAAI,YAAY,IAAI,EAAE,YAAY,WAAW,MAAM,IAAI,CAAC;GAC5D,GAAI,IAAI,OAAO,IAAI,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;GAC7C,GAAI,IAAI,QAAQ,IAAI,EAAE,QAAQ,OAAO,MAAM,IAAI,CAAC;EAClD;CACF;AACF"}
1
+ {"version":3,"file":"join-D5n6U49k.js","names":["curveFault"],"sources":["../src/fit.ts","../src/endurance.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["/** The relative tolerance of a take and of a fit. */\nexport const TOLERANCE = 1e-13;\n\n/** One try of a fit: the amount that the stores could not give, out of the amount wanted, and the value of the try. */\nexport interface Try<T> {\n readonly short: number;\n readonly need: number;\n readonly value: T;\n}\n\n/** The result of a fit: the largest amount with no shortfall, and the value of its try. The value is `undefined` when only 0 fits. */\nexport interface Fit<T> {\n readonly x: number;\n readonly value: T | undefined;\n}\n\n/**\n * The count of the tries of `largestFit`, for the tests of the cost. It is not in the public API, and it does not change a result.\n * It is the one side effect of `largestFit` and of the queries that use it.\n */\nexport const fitTries = { count: 0 };\n\n/**\n * This function gives the largest `x` in `[0, most]` at which `attempt` has no shortfall, to the relative tolerance `TOLERANCE`.\n *\n * - A try fits when its shortfall is not more than `TOLERANCE` times its need.\n * - The shortfall must not decrease when `x` increases. A take of a chain of converters gives a shortfall that is linear in parts.\n * - The first try is `most`. After it, each step tries the zero of the line through the last two tries that do not fit.\n * With one try that does not fit, the step tries `x` times the part of the need that the stores gave.\n * - When a step does not halve the interval, the next step is a bisection. Thus a fit takes at most approximately twice the steps of a bisection.\n * - A step on the lower end tries a point just above it, so a correct estimate ends the fit in one more try.\n * - An estimate that fits with a shortfall above 0 is in the band of the tolerance above the zero, so the fit ends there.\n * A bisection step or a probe at the lower end can fit with a shortfall of rounding below the zero. The fit does not end there.\n *\n * @param most - The upper limit of `x`\n * @param attempt - The try at an amount. It must not change its input\n * @returns The largest amount that fits, and the value of its try\n */\nexport function largestFit<T>(most: number, attempt: (x: number) => Try<T>): Fit<T> {\n const fits = (tried: Try<T>): boolean => tried.short <= TOLERANCE * tried.need;\n fitTries.count += 1;\n const first = attempt(most);\n if (fits(first)) return { x: most, value: first.value };\n let low = 0;\n let best: T | undefined;\n let high = most;\n let highShort = first.short;\n let highNeed = first.need;\n let before: { readonly x: number; readonly short: number } | undefined;\n let bisect = false;\n for (let step = 0; step < 400 && high - low > 4 * TOLERANCE * high; step += 1) {\n const width = high - low;\n let x: number;\n if (bisect) x = (low + high) / 2;\n else if (before !== undefined && before.short > highShort) x = high - (highShort * (before.x - high)) / (before.short - highShort);\n else x = high * (1 - highShort / highNeed);\n // Only a secant or ratio estimate through tries that do not fit lands at or above the zero of a convex shortfall.\n const estimate = !bisect && x < high;\n if (!(x < high)) x = (low + high) / 2;\n const floor = low + 2 * TOLERANCE * high;\n const clamped = !(x > floor);\n if (clamped) x = floor;\n fitTries.count += 1;\n const tried = attempt(x);\n if (fits(tried)) {\n low = x;\n best = tried.value;\n // An estimate that fits with a shortfall is in the band of the tolerance above the zero, so the fit ends.\n if (tried.short > 0 && estimate && !clamped) break;\n } else {\n before = { x: high, short: highShort };\n high = x;\n highShort = tried.short;\n highNeed = tried.need;\n }\n bisect = !bisect && high - low > width / 2;\n }\n return { x: low, value: best };\n}\n","import { dayNumber, stopped, type Stack } from \"@mark1russell7/system-stack\";\nimport { largestFit, type Try } from \"./fit.ts\";\nimport type { CaseCuts, Converter, DirectUse, Draw, Endurance, EnduranceLayer, IsoDate } from \"./layer.ts\";\n\n// The endurance query: the days that each draw holds when a case stops its supply.\n\n/** The options of the queries of a case. */\nexport interface CaseOptions {\n /** The date of the query. A store whose due date is on this date or before it gives nothing. */\n readonly at: IsoDate;\n /** The base stack. With it, a cut also stops each part that cannot work without a cut part (`stopped` of the core). */\n readonly stack?: Stack | undefined;\n /** The `id` of more parts that are down, with the cuts of the case. */\n readonly down?: readonly string[] | undefined;\n}\n\n/**\n * This function gives the `id` of each part that does not work in a case: the cut parts and the parts of `down`.\n * With a stack, it also gives each part that stops.\n */\nexport function caseStopped(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): Set<string> {\n const down = [...caseCuts.cuts.map((cut) => cut.part), ...(options.down ?? [])];\n const out = new Set(down);\n if (options.stack !== undefined) for (const id of stopped(options.stack, down)) out.add(id);\n return out;\n}\n\n/** This function gives the day number of a date, or throws a `RangeError` for a date that is not `YYYY-MM-DD`. */\nfunction dayOf(date: IsoDate): number {\n const day = dayNumber(date);\n if (day === undefined) throw new RangeError(`The date \"${date}\" is not a date YYYY-MM-DD.`);\n return day;\n}\n\n/**\n * This function gives the amount of each resource in the stores at a date, by the code of the resource.\n *\n * - A store gives nothing on its due date and after it.\n * - A store gives nothing when its part is in `stoppedParts`.\n */\nexport function storeAmounts(layer: EnduranceLayer, at: IsoDate, stoppedParts: ReadonlySet<string> = new Set()): Map<string, number> {\n const today = dayOf(at);\n const out = new Map<string, number>();\n for (const store of layer.stores) {\n if (store.due !== undefined && today >= dayOf(store.due)) continue;\n if (store.part !== undefined && stoppedParts.has(store.part)) continue;\n out.set(store.resource, (out.get(store.resource) ?? 0) + store.amount);\n }\n return out;\n}\n\n/** This function gives the amount of a need for each day in a case: the rate of the draw times the factor of the case. */\nexport function drawDemand(draw: Draw, caseCuts: CaseCuts): number {\n return draw.perDay * (caseCuts.factors?.[draw.need] ?? 1);\n}\n\n/**\n * This function gives the draws that take from the stores in a case: each draw whose supply stops, with a demand more than 0.\n * The sequence is by the level (the order of `levels`), then by the code of the need.\n */\nexport function caseDraws(layer: EnduranceLayer, caseCuts: CaseCuts, stoppedParts: ReadonlySet<string>): Draw[] {\n const rank = (level: string): number => {\n const index = layer.levels.indexOf(level);\n return index < 0 ? layer.levels.length : index;\n };\n return layer.draws\n .filter((draw) => stoppedParts.has(draw.supply) && drawDemand(draw, caseCuts) > 0)\n .sort((a, b) => rank(a.level) - rank(b.level) || (a.need < b.need ? -1 : a.need > b.need ? 1 : 0));\n}\n\n/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */\nexport function giftNeed(converter: Converter): string | undefined {\n return \"need\" in converter.gives ? converter.gives.need : undefined;\n}\n\n/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */\nexport function giftResource(converter: Converter): string | undefined {\n return \"resource\" in converter.gives ? converter.gives.resource : undefined;\n}\n\n/** This function gives the amount of each resource that one run of a converter takes. Two lines of one resource add. */\nfunction inputsOf(converter: Converter): Map<string, number> {\n const out = new Map<string, number>();\n for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);\n return out;\n}\n\n/** This function tells if a converter can run in a case. Its device works, it takes a resource, and it gives an amount more than 0. */\nfunction canRun(converter: Converter, stoppedParts: ReadonlySet<string>): boolean {\n return converter.gives.amount > 0 && inputsOf(converter).size > 0 && (converter.device === undefined || !stoppedParts.has(converter.device));\n}\n\n/** The converters of a case that make each resource, in the order of the layer, by the code of the resource. */\ntype Makers = ReadonlyMap<string, readonly Converter[]>;\n\nfunction makersOf(layer: EnduranceLayer, stoppedParts: ReadonlySet<string>): Makers {\n const out = new Map<string, Converter[]>();\n for (const converter of layer.converters ?? []) {\n const resource = giftResource(converter);\n if (resource === undefined || !canRun(converter, stoppedParts)) continue;\n out.set(resource, [...(out.get(resource) ?? []), converter]);\n }\n return out;\n}\n\n/** The ways to get one need in a case: its direct uses, then the converters that give it, in the order of the layer. `makers` make the resources. */\ninterface Ways {\n readonly direct: readonly DirectUse[];\n readonly converters: readonly Converter[];\n readonly makers: Makers;\n}\n\nfunction waysOf(layer: EnduranceLayer, need: string, stoppedParts: ReadonlySet<string>, makers: Makers): Ways {\n return {\n direct: (layer.direct ?? []).filter((use) => use.need === need && use.amount > 0),\n converters: (layer.converters ?? []).filter((converter) => giftNeed(converter) === need && canRun(converter, stoppedParts)),\n makers,\n };\n}\n\n// A chain: the resources on the path of a take. A maker does not take a resource of its own path, so a cycle of the layer stops there.\nconst NO_PATH: ReadonlySet<string> = new Set();\n\n/**\n * This function gives the most of a resource that `left` gives: its stock, and the runs of each maker.\n * It is an upper limit. When two inputs come from one resource, the true amount can be less.\n */\nfunction mostResource(left: ReadonlyMap<string, number>, makers: Makers, resource: string, path: ReadonlySet<string>): number {\n let total = left.get(resource) ?? 0;\n if (path.has(resource)) return total;\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) total += mostRuns(left, makers, maker, next) * maker.gives.amount;\n return total;\n}\n\n/** This function gives the most runs of a converter that `left` gives. It is an upper limit, as for `mostResource`. */\nfunction mostRuns(left: ReadonlyMap<string, number>, makers: Makers, converter: Converter, path: ReadonlySet<string>): number {\n let runs = Infinity;\n for (const [resource, each] of inputsOf(converter)) runs = Math.min(runs, mostResource(left, makers, resource, path) / each);\n return Number.isFinite(runs) ? runs : 0;\n}\n\n/**\n * This function takes an amount of a resource from `left`: the stock first, then the makers in the order of the layer.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction takeResource(left: Map<string, number>, makers: Makers, resource: string, amount: number, path: ReadonlySet<string>): number {\n const has = left.get(resource) ?? 0;\n const got = Math.min(amount, has);\n left.set(resource, has - got);\n let rest = amount - got;\n if (rest <= 0 || path.has(resource)) return Math.max(0, rest);\n const next = new Set(path).add(resource);\n for (const maker of makers.get(resource) ?? []) {\n if (rest <= 0) break;\n rest -= run(left, makers, maker, rest / maker.gives.amount, next) * maker.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/**\n * This function runs a converter up to `wanted` times with the resources of `left`, and it gives the count of runs.\n * It changes `left`. When two inputs come from one resource, `largestFit` finds the runs that the resources give.\n */\nfunction run(left: Map<string, number>, makers: Makers, converter: Converter, wanted: number, path: ReadonlySet<string>): number {\n const inputs = inputsOf(converter);\n const most = Math.min(wanted, mostRuns(left, makers, converter, path));\n if (!(most > 0)) return 0;\n const attempt = (runs: number): Try<Map<string, number>> => {\n const copy = new Map(left);\n let need = 0;\n let short = 0;\n for (const [resource, each] of inputs) {\n need += runs * each;\n short += takeResource(copy, makers, resource, runs * each, path);\n }\n return { short, need, value: copy };\n };\n const { x: runs, value: best } = largestFit(most, attempt);\n if (best === undefined) return 0;\n for (const [resource, amount] of best) left.set(resource, amount);\n return runs;\n}\n\n/**\n * This function takes an amount of a need from the resources in `left`: the direct uses first, then the converters.\n * A direct use or a converter takes each resource from its stock first, then from its makers.\n * It changes `left`, and it gives the amount that it could not take.\n */\nfunction take(left: Map<string, number>, ways: Ways, amount: number): number {\n let rest = amount;\n for (const use of ways.direct) {\n if (rest <= 0) break;\n const wanted = rest / use.amount;\n rest -= (wanted - takeResource(left, ways.makers, use.resource, wanted, NO_PATH)) * use.amount;\n }\n for (const converter of ways.converters) {\n if (rest <= 0) break;\n rest -= run(left, ways.makers, converter, rest / converter.gives.amount, NO_PATH) * converter.gives.amount;\n }\n return Math.max(0, rest);\n}\n\n/** This function gives each resource that a need can use: the inputs of its ways, and the inputs of their makers, through each chain. */\nfunction inputClosure(ways: Ways): Set<string> {\n const out = new Set<string>();\n const queue = [...ways.direct.map((use) => use.resource), ...ways.converters.flatMap((converter) => [...inputsOf(converter).keys()])];\n for (let resource = queue.shift(); resource !== undefined; resource = queue.shift()) {\n if (out.has(resource)) continue;\n out.add(resource);\n for (const maker of ways.makers.get(resource) ?? []) queue.push(...inputsOf(maker).keys());\n }\n return out;\n}\n\n/** The relative tolerance of a used-up resource. */\nconst USED_UP = 1e-9;\n\n/**\n * This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.\n *\n * - A draw takes from the stores only when the case stops its supply part. Each other draw holds without end, and the result leaves it out.\n * - The demand of a draw for each day is its rate times the factor of the case.\n * - The draws take the resources in the order of their level, then of their codes. A draw takes from its direct uses first, then from its converters.\n * - The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.\n * - Each higher draw keeps back its own days times its demand. Thus the takes of all the draws are not more than the stores at any time.\n * - The take order is a rule, not the best share: the direct uses in the order of the list, then the converters. The days are the days of this order.\n * - A converter whose device stops gives nothing. A store whose part stops gives nothing.\n * - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.\n *\n * The function is pure, but for an internal count of the tries of its fits for the tests. It throws a `RangeError` for a date that is not `YYYY-MM-DD`. The gate `checkEndurance` examines the layer before.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param options - The date, and the stack or the parts that are also down\n * @returns The endurance of each draw whose supply stops\n */\nexport function enduranceOf(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions): Endurance {\n const stoppedParts = caseStopped(caseCuts, options);\n const start = storeAmounts(layer, options.at, stoppedParts);\n const makers = makersOf(layer, stoppedParts);\n const stocked = new Set(layer.stores.map((store) => store.resource));\n const done: { readonly ways: Ways; readonly demand: number; readonly days: number }[] = [];\n const needs: Record<string, { days: number; binding: string[]; takes: Record<string, number> }> = {};\n for (const draw of caseDraws(layer, caseCuts, stoppedParts)) {\n const ways = waysOf(layer, draw.need, stoppedParts, makers);\n const demand = drawDemand(draw, caseCuts);\n const before = new Map(start);\n for (const higher of done) take(before, higher.ways, higher.days * higher.demand);\n const after = (days: number): { left: Map<string, number>; short: number } => {\n const left = new Map(before);\n return { left, short: take(left, ways, days * demand) };\n };\n // The upper limit: the days that the draw holds when it takes all the stores itself. `largestFit` finds the days below it.\n const fit = largestFit(capacity(start, ways) / demand, (days) => {\n const tried = after(days);\n return { short: tried.short, need: days * demand, value: tried.left };\n });\n const low = fit.x;\n const left = fit.value ?? after(low).left;\n const binding = [...inputClosure(ways)]\n .filter((resource) => !makers.has(resource) || stocked.has(resource))\n .filter((resource) => mostResource(left, makers, resource, NO_PATH) <= USED_UP * Math.max(1, start.get(resource) ?? 0))\n .sort();\n const takes: Record<string, number> = {};\n for (const [resource, amount] of before) {\n const taken = amount - (left.get(resource) ?? 0);\n if (taken > 0) takes[resource] = taken;\n }\n needs[draw.need] = { days: low, binding, takes };\n done.push({ ways, demand, days: low });\n }\n return { case: caseCuts.case, at: options.at, needs };\n}\n\n/**\n * This function gives an upper limit of a need that the stores give with no other draw, through each chain.\n * A converter that takes nothing gives nothing: the gate refuses it.\n */\nfunction capacity(start: ReadonlyMap<string, number>, ways: Ways): number {\n let total = 0;\n for (const use of ways.direct) total += mostResource(start, ways.makers, use.resource, NO_PATH) * use.amount;\n for (const converter of ways.converters) total += mostRuns(start, ways.makers, converter, NO_PATH) * converter.gives.amount;\n return total;\n}\n","import { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { curveFault, dayNumber, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { giftNeed, giftResource } from \"./endurance.ts\";\nimport type { Converter, EnduranceLayer } from \"./layer.ts\";\n\n// The gate of an endurance layer: the meaning of a layer with a correct form, for its base stack.\n\n/**\n * These are the codes of the gate. Each code is an error, except `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.\n *\n * - `endurance-twice`: two or more records of one list have one key. A key is a level, a resource, a store, a need, a converter or a case.\n * The key of a prior is its case and its place. A converter takes each resource on one line, and a case cuts each part one time.\n * - `endurance-level-unknown`: the level of a draw is not a level of the layer.\n * - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.\n * - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.\n * - `endurance-range`: an amount, a rate, a count or a factor is not a finite number of 0 or more. Or a reach is not from 0 to 1.\n * - `endurance-date`: a date is not a date `YYYY-MM-DD`.\n * - `endurance-converter-empty`: a converter takes nothing, or it gives an amount of 0.\n * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.\n * Or its days do not increase, or its chance increases.\n * - `endurance-prior-case`: a prior names a case that the layer does not have.\n * - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.\n * - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.\n * - `endurance-cut-no-curve` (warning): a cut has no curve of its duration. The draws whose stop it can be part of are no read in the shortfall.\n */\nexport const ENDURANCE_CODES: readonly [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n] = [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n];\n\n/** A code of `ENDURANCE_CODES`. */\nexport type EnduranceCode = (typeof ENDURANCE_CODES)[number];\n\n/** A fault of the gate of an endurance layer. */\nexport interface EnduranceFault extends Fault {\n readonly code: EnduranceCode;\n}\n\nexport { curveFault } from \"@mark1russell7/system-stack\";\n\n/**\n * This function gives each fault of an endurance layer. With a base stack, it also examines the `id` of each part. A list with no error tells that the gate passes.\n *\n * The faults are in the order of the layer. The function is pure.\n *\n * @param layer - The endurance layer\n * @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.\n * @returns The faults\n */\nexport function checkEndurance(layer: EnduranceLayer, stack?: Stack): EnduranceFault[] {\n const faults: EnduranceFault[] = [];\n const add = (level: EnduranceFault[\"level\"], code: EnduranceCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const once = (what: string, keys: readonly string[]): void => {\n const seen = new Set<string>();\n for (const key of keys) {\n if (seen.has(key)) add(\"error\", \"endurance-twice\", key, `Two or more ${what} have the key \"${key}\".`);\n seen.add(key);\n }\n };\n const range = (at: string, what: string, value: number): void => {\n if (!(Number.isFinite(value) && value >= 0)) add(\"error\", \"endurance-range\", at, `The ${what} of \"${at}\" is ${String(value)}. It must be a finite number of 0 or more.`);\n };\n const date = (at: string, value: string): void => {\n if (dayNumber(value) === undefined) add(\"error\", \"endurance-date\", at, `The date \"${value}\" of \"${at}\" is not a date YYYY-MM-DD.`);\n };\n const parts = stack === undefined ? undefined : new Set(stack.parts.map((part) => part.id));\n const part = (at: string, what: string, id: string | undefined): void => {\n if (parts !== undefined && id !== undefined && !parts.has(id)) add(\"error\", \"endurance-part-unknown\", at, `The ${what} \"${id}\" of \"${at}\" is not a part of the stack.`);\n };\n const resources = new Set(layer.resources.map((resource) => resource.code));\n const resource = (at: string, code: string): void => {\n if (!resources.has(code)) add(\"error\", \"endurance-resource-unknown\", at, `The resource \"${code}\" of \"${at}\" is not a resource of the layer.`);\n };\n const direct = layer.direct ?? [];\n const converters = layer.converters ?? [];\n const cases = layer.cases ?? [];\n const priors = layer.priors ?? [];\n\n once(\"levels\", layer.levels);\n once(\"resources\", layer.resources.map((item) => item.code));\n once(\"stores\", layer.stores.map((store) => store.id));\n once(\"draws\", layer.draws.map((draw) => draw.need));\n once(\"converters\", converters.map((converter) => converter.id));\n once(\"cases\", cases.map((item) => item.case));\n once(\"priors\", priors.map((prior) => `${prior.case}@${prior.place}`));\n\n for (const store of layer.stores) {\n resource(store.id, store.resource);\n range(store.id, \"amount\", store.amount);\n if (store.due !== undefined) date(store.id, store.due);\n part(store.id, \"part\", store.part);\n }\n const levels = new Set(layer.levels);\n for (const draw of layer.draws) {\n if (!levels.has(draw.level)) add(\"error\", \"endurance-level-unknown\", draw.need, `The level \"${draw.level}\" of the draw \"${draw.need}\" is not a level of the layer.`);\n range(draw.need, \"rate\", draw.perDay);\n if (draw.users !== undefined) range(draw.need, \"count of users\", draw.users);\n part(draw.need, \"supply\", draw.supply);\n const ways = direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need);\n if (!ways) add(\"warning\", \"endurance-no-way\", draw.need, `The draw \"${draw.need}\" has no direct use and no converter. It holds 0 days when its supply stops.`);\n }\n for (const use of direct) {\n const at = `${use.resource}>${use.need}`;\n resource(at, use.resource);\n range(at, \"amount\", use.amount);\n }\n for (const converter of converters) {\n once(`resources of the converter \"${converter.id}\"`, converter.takes.map((input) => input.resource));\n for (const input of converter.takes) {\n resource(converter.id, input.resource);\n range(converter.id, \"amount\", input.amount);\n }\n range(converter.id, \"amount\", converter.gives.amount);\n const made = giftResource(converter);\n if (made !== undefined) resource(converter.id, made);\n if (!converter.takes.some((input) => input.amount > 0) || converter.gives.amount === 0) add(\"error\", \"endurance-converter-empty\", converter.id, `The converter \"${converter.id}\" takes nothing, or it gives nothing.`);\n part(converter.id, \"device\", converter.device);\n }\n const caseCodes = new Set(cases.map((item) => item.case));\n for (const item of cases) {\n once(`cuts of the case \"${item.case}\"`, item.cuts.map((cut) => cut.part));\n for (const cut of item.cuts) {\n const at = `${item.case}/${cut.part}`;\n part(at, \"cut\", cut.part);\n if (cut.duration === undefined) {\n add(\"warning\", \"endurance-cut-no-curve\", at, `The cut \"${at}\" has no curve of its duration, so the draws that it can stop are no read.`);\n continue;\n }\n const fault = curveFault(cut.duration);\n if (fault !== undefined) add(\"error\", \"endurance-curve\", at, `The duration of the cut \"${at}\": ${fault}`);\n }\n for (const [need, factor] of Object.entries(item.factors ?? {})) range(`${item.case}/${need}`, \"factor\", factor);\n if (item.leadSeconds !== undefined) range(item.case, \"lead time\", item.leadSeconds);\n }\n for (const cycle of resourceCycles(converters)) {\n const [first = \"\"] = cycle;\n const names = cycle.map((code) => `\"${code}\"`).join(\", \");\n const message = cycle.length === 1 ? `A converter makes the resource ${names} from itself.` : `Converters make the resources ${names} from each other.`;\n add(\"error\", \"endurance-cycle\", first, `${message} A chain of converters cannot end.`);\n }\n for (const prior of priors) {\n const at = `${prior.case}@${prior.place}`;\n if (!caseCodes.has(prior.case)) add(\"error\", \"endurance-prior-case\", at, `The prior \"${at}\" names the case \"${prior.case}\", which the layer does not have.`);\n range(at, \"count of events in one year\", prior.perYear);\n if (!(prior.reach >= 0 && prior.reach <= 1)) add(\"error\", \"endurance-range\", at, `The reach of \"${at}\" is ${String(prior.reach)}. It must be from 0 to 1.`);\n date(at, prior.asOf);\n }\n return faults;\n}\n\n/** This function gives each cycle of resources: a resource is made from a resource that a converter makes from it. Each cycle is a list of codes. */\nfunction resourceCycles(converters: readonly Converter[]): string[][] {\n const from = new Map<string, Set<string>>();\n for (const converter of converters) {\n const made = giftResource(converter);\n if (made === undefined) continue;\n const inputs = from.get(made) ?? new Set<string>();\n for (const input of converter.takes) if (input.amount > 0) inputs.add(input.resource);\n from.set(made, inputs);\n }\n const successors = (code: string): Iterable<string> => from.get(code) ?? [];\n return stronglyConnectedComponents(from.keys(), successors).filter((component) => {\n const [only = \"\"] = component;\n return component.length > 1 || (from.get(only)?.has(only) ?? false);\n });\n}\n\n/** This function tells if a list of faults has an error. */\nexport function hasEnduranceError(faults: readonly EnduranceFault[]): boolean {\n return faults.some((fault) => fault.level === \"error\");\n}\n","import { canonicalJson } from \"@mark1russell7/rigor-generators\";\nimport { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The join of the endurance layers of the fragments of a stack, for example one file of stores for each owner.\n\n/**\n * This function joins the endurance layers of the fragments of a stack into one layer.\n *\n * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.\n * - The records of each list are in the order of the fragments.\n * - Two resources with one code in two fragments join into one resource when their records are equal. A different field is a fault.\n * - A code that one fragment has two times stays in the joined layer. The gate `checkEndurance` finds it.\n * - One key of each other list in two or more fragments is a fault, also when the records are equal.\n * - The key of a direct use is its resource and its need.\n *\n * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinEndurance(pieces: readonly LayerPiece<EnduranceLayer>[]): LayerParse<EnduranceLayer> {\n const levels = joinSetting(pieces, (layer) => (layer.levels.length > 0 ? layer.levels.join(\"\\n\") : undefined), \"levels\");\n // Two fragments can declare one resource, for example `water.stored` in `L`. Canonical JSON (RFC 8785) compares the records,\n // so the order of the keys has no effect.\n const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, \"resource\", { equal: (first, other) => canonicalJson(first) === canonicalJson(other) });\n const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, \"store\");\n const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, \"draw\");\n const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, \"direct use\");\n const converters = joinRecords(pieces, (layer) => layer.converters, (item) => item.id, \"converter\");\n const cases = joinRecords(pieces, (layer) => layer.cases, (item) => item.case, \"case\");\n const priors = joinRecords(pieces, (layer) => layer.priors, (item) => `${item.case}@${item.place}`, \"prior\");\n const errors = [levels, resources, stores, draws, direct, converters, cases, priors].flatMap((join) => join.errors);\n if (errors.length > 0) return { ok: false, errors };\n const has = (key: \"direct\" | \"converters\" | \"cases\" | \"priors\"): boolean => pieces.some((piece) => piece.layer[key] !== undefined);\n return {\n ok: true,\n layer: {\n schema: ENDURANCE_SCHEMA,\n levels: levels.value === undefined ? [] : levels.value.split(\"\\n\"),\n resources: resources.items,\n stores: stores.items,\n draws: draws.items,\n ...(has(\"direct\") ? { direct: direct.items } : {}),\n ...(has(\"converters\") ? { converters: converters.items } : {}),\n ...(has(\"cases\") ? { cases: cases.items } : {}),\n ...(has(\"priors\") ? { priors: priors.items } : {}),\n },\n };\n}\n"],"mappings":";;;;;;AACA,MAAa,YAAY;;;;;AAmBzB,MAAa,WAAW,EAAE,OAAO,EAAE;;;;;;;;;;;;;;;;;AAkBnC,SAAgB,WAAc,MAAc,SAAwC;C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M,UAAU,MAAM,MAAM,SAAS,KAAA,CAAS;CACjI,OAAO;EACL,IAAI;EACJ,OAAO;GACL,QAAQ;GACR,QAAQ,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,OAAO,MAAM,MAAM,IAAI;GACjE,WAAW,UAAU;GACrB,QAAQ,OAAO;GACf,OAAO,MAAM;GACb,GAAI,IAAI,QAAQ,IAAI,EAAE,QAAQ,OAAO,MAAM,IAAI,CAAC;GAChD,GAAI,IAAI,YAAY,IAAI,EAAE,YAAY,WAAW,MAAM,IAAI,CAAC;GAC5D,GAAI,IAAI,OAAO,IAAI,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;GAC7C,GAAI,IAAI,QAAQ,IAAI,EAAE,QAAQ,OAAO,MAAM,IAAI,CAAC;EAClD;CACF;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/stack-endurance",
4
- "version": "0.6.0",
4
+ "version": "0.6.2",
5
5
  "description": "Stores, draws and converters of a system stack: the days that each draw holds when a case cuts its supply, and the shortfall of each level in one year. An add-on of system-stack.",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -50,13 +50,13 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@mark1russell7/collections": "^0.11.2",
53
- "@mark1russell7/system-stack": "0.1.8",
53
+ "@mark1russell7/rigor-generators": "^0.2.0",
54
+ "@mark1russell7/system-stack": "0.1.9",
54
55
  "zod": "^4.6.7"
55
56
  },
56
57
  "devDependencies": {
57
58
  "@mark1russell7/cue": "^2.0.0",
58
59
  "@mark1russell7/rigor-bench": "^0.3.2",
59
- "@mark1russell7/rigor-generators": "^0.2.0",
60
60
  "@types/node": "^26.6.5",
61
61
  "@vitest/coverage-v8": "^5.0.3",
62
62
  "fast-check": "^4.10.2",