@mark1russell7/stack-needs 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +137 -2
- package/build/index.d.ts +353 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +892 -0
- package/build/index.js.map +1 -0
- package/package.json +67 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Russell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mark1russell7/stack-needs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The need rates of draws as reference data. Each rate has its source and its license. The first table is the food energy that each person needs each day.
|
|
4
|
+
|
|
5
|
+
It is an add-on of [`@mark1russell7/system-stack`](../system-stack/README.md). It makes a fragment of an endurance layer, and [`@mark1russell7/stack-endurance`](../stack-endurance/README.md) calculates with it. The data names no person and no place. The persons of a household are input data.
|
|
6
|
+
|
|
7
|
+
Each function is a plain function with no clock, no network and no file.
|
|
8
|
+
|
|
9
|
+
## The records
|
|
10
|
+
|
|
11
|
+
| Record | What it tells |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `HashedSource` | A source of `@mark1russell7/guidebook` (an id, a title, a URL, a license and the date of the check), with the SHA-256 hash of the file. |
|
|
14
|
+
| `CalorieTable` | A table of estimated calorie needs from one source, with the place of the tables in the source. |
|
|
15
|
+
| `CalorieRow` | A sex, a range of ages in months, and the need of each activity level, or one need for all levels. |
|
|
16
|
+
| `Person` | A group of persons: a sex, an age in whole months, a count and, as an option, an activity level. |
|
|
17
|
+
| `HouseholdFragment` | A fragment of an endurance layer: the resources, the stores, one draw and one direct use. It has the form of `EnduranceLayer`. |
|
|
18
|
+
|
|
19
|
+
## The rules of the data
|
|
20
|
+
|
|
21
|
+
1. Each value comes from a table of a cited source. A value with no source is not data.
|
|
22
|
+
2. An age with no row in the table gives a line with no read for that person, not an error. The total of `calorieNeed` is then a lower limit, and `read` is false.
|
|
23
|
+
3. The activity level is an explicit input. The package has no default level.
|
|
24
|
+
4. The package has no cooking converter. No cited source gives the water and the fuel to cook 1 kg of dry food.
|
|
25
|
+
|
|
26
|
+
`checkCalorieTable` is the gate of a table. It gives the findings of `checkSources` of `@mark1russell7/guidebook` for the source. It also refuses a hash that is not 64 lowercase hexadecimal digits. For the rows, it refuses two rows of one sex with ages in common, and a need that is not above 0 in `kcal/d`. The rows of each sex also cover each month with no gap, from the first row to an open last row (`needs-gap`).
|
|
27
|
+
|
|
28
|
+
The field `sha256` is not in the source of guidebook yet. It moves there later.
|
|
29
|
+
|
|
30
|
+
## A first look
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { SUPPLY_CATALOG } from "@mark1russell7/market/supplies";
|
|
34
|
+
import { enduranceOf } from "@mark1russell7/stack-endurance";
|
|
35
|
+
import { calorieNeed, DGA_CALORIES, householdFragment, type Person } from "@mark1russell7/stack-needs";
|
|
36
|
+
|
|
37
|
+
// Made-up persons: two adults of 33 years.
|
|
38
|
+
const persons: Person[] = [
|
|
39
|
+
{ sex: "male", ageMonths: 396, count: 1 },
|
|
40
|
+
{ sex: "female", ageMonths: 396, count: 1 },
|
|
41
|
+
];
|
|
42
|
+
console.log(calorieNeed(DGA_CALORIES, persons, "sedentary", 1).need); // { value: 4200, unit: "kcal" }
|
|
43
|
+
|
|
44
|
+
const food = householdFragment({
|
|
45
|
+
persons,
|
|
46
|
+
activity: "sedentary",
|
|
47
|
+
catalog: SUPPLY_CATALOG,
|
|
48
|
+
units: { "food.rice-white-1kg": 4, "food.peanut-butter-1kg": 2 },
|
|
49
|
+
level: "critical",
|
|
50
|
+
levels: ["critical"],
|
|
51
|
+
});
|
|
52
|
+
const cut = { case: "food-cut", title: "No food shops", cuts: [{ part: "food.retail", title: "No food shops", source: "example" }] };
|
|
53
|
+
if (food.layer === undefined) throw new Error(food.why);
|
|
54
|
+
console.log(enduranceOf(food.layer, cut, { at: "2026-11-22" }).needs["food.energy"]?.days); // about 2.85: the peanut butter alone
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## The join of a household and a buy list
|
|
58
|
+
|
|
59
|
+
`householdFragment` turns the persons and a buy list into a fragment of an endurance layer. The buy list is the count of units of each product of the catalog of supplies of `@mark1russell7/market`.
|
|
60
|
+
|
|
61
|
+
- The fragment has one draw `food.energy`. Its rate is the need of the persons for one day, in `kcal`. Its users are the persons.
|
|
62
|
+
- Each gift of the buy list (`giftsOf`) is one store. Examples are `food.no-cook` in `kcal`, the dry foods in `kg` and `water.stored` in `L`.
|
|
63
|
+
- A gift with no read has no store. It is in `noReads`, and `storesRead` is false. The draw does not change.
|
|
64
|
+
- The direct uses are the food uses of `uses`: each use for the need `food.energy`. The default `DIRECT_USES` gives `food.no-cook`, 1 kcal for each kcal.
|
|
65
|
+
- The resources are the resources of the stores and of the food uses. The resource of each food use is in `kcal` in the catalog, or the function throws a `RangeError`.
|
|
66
|
+
- The supply part of the draw is `supply`. Its default is the part of `NEED_SUPPLIES` for `food.energy`: `food.retail`.
|
|
67
|
+
- The result also has the food energy of each product (`buyListEnergy`). A caller gets the energy of the dry food for its converters from it.
|
|
68
|
+
|
|
69
|
+
The result has two reads. `needRead` tells if the draw has a read, and `storesRead` tells if each gift of the buy list has a read.
|
|
70
|
+
|
|
71
|
+
### A person with no row
|
|
72
|
+
|
|
73
|
+
The table has no row below 12 months. By default, a person with no row gives no layer. The result has `layer: undefined`, the persons with no row and the reason. A low rate gives too many days, and the draw has no field for a no read. A draw of 0 kcal also gives no layer: a household with no person, or each count 0.
|
|
74
|
+
|
|
75
|
+
The option `noRow: "leave-out"` leaves those persons out of the draw. The users are then the persons with a row, and `leftOut` lists the other persons. The draw then has no need of those persons. For an infant, that need is breast milk or formula, not the buy list. The days are then an upper limit for the whole household.
|
|
76
|
+
|
|
77
|
+
### The resources of the buy list and the join
|
|
78
|
+
|
|
79
|
+
The fragment has no converter. Thus, with this fragment alone, only `food.no-cook` feeds the draw. This is the worst case: no water and no fuel.
|
|
80
|
+
|
|
81
|
+
A caller adds the converters for the dry food in a different fragment, with the water and the fuel of each run. Then `joinEndurance` joins the fragments. The dry food then adds days only while the water and the fuel last.
|
|
82
|
+
|
|
83
|
+
This fragment declares the resource codes of the buy list, for example `water.stored` in `L`. A different fragment, for example the fragment of a water tank, can declare the same resource. `joinEndurance` of `@mark1russell7/stack-endurance` joins two equal records into one. A different unit is a fault of the join.
|
|
84
|
+
|
|
85
|
+
## The uses, the supply parts and the join gate
|
|
86
|
+
|
|
87
|
+
The package holds one record of each use and of each default supply part. `householdFragment` takes its food use from `DIRECT_USES`.
|
|
88
|
+
|
|
89
|
+
| Name | What it has |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `NEED_SUPPLIES` | The default reference part of each need: `hydration.drink` to `water.main`, and `food.energy` to `food.retail`. A household with a well gives a different part. |
|
|
92
|
+
| `DIRECT_USES` | `water.stored` gives `hydration.drink`, 1 L for each L. This is a definition, not a read. `food.no-cook` gives `food.energy`, 1 kcal for each kcal. |
|
|
93
|
+
| `checkJoins` | The join gate of a catalog, the direct uses and the supply parts with the reference lists. |
|
|
94
|
+
|
|
95
|
+
`checkJoins(catalog, uses, supplies, { needs, parts })` gives one finding for each break. An empty list is a pass. Each finding is an error.
|
|
96
|
+
|
|
97
|
+
A finding has the form of a finding of `@mark1russell7/guidebook`, the same form as the findings of `checkCalorieTable`. Its record is `use` or `supply`. The `id` of a `use` finding is the resource of the use. The `id` of a `supply` finding is the need.
|
|
98
|
+
|
|
99
|
+
| Code | Record | The break |
|
|
100
|
+
| --- | --- | --- |
|
|
101
|
+
| `join-use-resource` | `use` | A direct use names a resource that is not in the catalog. |
|
|
102
|
+
| `join-use-need` | `use` | A direct use names a need that is not a reference need. |
|
|
103
|
+
| `join-use-unit` | `use` | The unit of the resource of a direct use does not convert to the unit of its need. |
|
|
104
|
+
| `join-use-amount` | `use` | The amount of a direct use is not the factor from the unit of its resource to the unit of its need. |
|
|
105
|
+
| `join-supply-need` | `supply` | A supply names a need that is not a reference need. |
|
|
106
|
+
| `join-supply-part` | `supply` | A supply names a part that is not a reference part. |
|
|
107
|
+
|
|
108
|
+
A direct use is a definition. Thus its amount is the factor of the units, from `valueIn` of `@mark1russell7/quantity`. For example, a use in `gal` for a need in `L` gives 3.785411784 L for each gal. A different rate is a converter, and a converter has a cited source.
|
|
109
|
+
|
|
110
|
+
The reference lists are parameters. An add-on does not import a different add-on, thus the caller gives them. Give `NEEDS` of `@mark1russell7/alerts` and `SUPPLY_PARTS` of `@mark1russell7/stack-hazards`. A test of the package joins these real lists. It also checks that `food.energy` is a need of `NEEDS` in `kcal`.
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { NEEDS } from "@mark1russell7/alerts";
|
|
114
|
+
import { SUPPLY_CATALOG } from "@mark1russell7/market/supplies";
|
|
115
|
+
import { SUPPLY_PARTS } from "@mark1russell7/stack-hazards";
|
|
116
|
+
import { checkJoins, DIRECT_USES, NEED_SUPPLIES } from "@mark1russell7/stack-needs";
|
|
117
|
+
|
|
118
|
+
console.log(checkJoins(SUPPLY_CATALOG, DIRECT_USES, NEED_SUPPLIES, { needs: NEEDS, parts: SUPPLY_PARTS })); // []
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The gate does not examine the FoodKeeper `id` of each product. That join goes to the gate of the catalog of `@mark1russell7/market`.
|
|
122
|
+
|
|
123
|
+
## The sources
|
|
124
|
+
|
|
125
|
+
The calorie table comes from Appendix 2 of the Dietary Guidelines for Americans, 2020-2025, 9th Edition (USDA and HHS). Table A2-1 gives the ages of 12 through 23 months, on page 139. Table A2-2 gives the ages of 2 and more, on pages 140 and 141. The table has 68 rows: 34 for each sex.
|
|
126
|
+
|
|
127
|
+
The guidelines are a work of the United States federal government, in the public domain (the license `us-public-domain` of guidebook). The record of the source has the SHA-256 hash of the PDF of the check of 2026-11-22.
|
|
128
|
+
|
|
129
|
+
- A calorie of the source is a food calorie, thus 1 kcal.
|
|
130
|
+
- Table A2-1 gives one need for each age and sex of a toddler. The level does not change it.
|
|
131
|
+
- Each row of a toddler covers the months up to the next row. The table has no row below 12 months.
|
|
132
|
+
- The source gives each need for a reference height and weight. A person can need more or less.
|
|
133
|
+
|
|
134
|
+
## The entries
|
|
135
|
+
|
|
136
|
+
| Entry | What it has |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| `@mark1russell7/stack-needs` | The records, the calorie table, the gate, `calorieNeed`, `householdFragment`, the uses, the supply parts and `checkJoins`. |
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { Quantity } from "@mark1russell7/quantity";
|
|
2
|
+
import { Finding, FindingCode, GateOptions, Source } from "@mark1russell7/guidebook";
|
|
3
|
+
import { BuyListEnergy, SupplyCatalog } from "@mark1russell7/market/supplies";
|
|
4
|
+
/**
|
|
5
|
+
* A source of a table: a source of `@mark1russell7/guidebook`, with the SHA-256 hash of the file of the read.
|
|
6
|
+
* The hash has 64 lowercase hexadecimal digits. A page with no fixed file has no hash.
|
|
7
|
+
*/
|
|
8
|
+
export type HashedSource = Source & {
|
|
9
|
+
readonly sha256?: string;
|
|
10
|
+
};
|
|
11
|
+
/** The activity levels of the table, as the source names them: sedentary, moderately active and active. */
|
|
12
|
+
export declare const ACTIVITY_LEVELS: readonly ["sedentary", "moderately-active", "active"];
|
|
13
|
+
/** An activity level of the table. */
|
|
14
|
+
export type ActivityLevel = (typeof ACTIVITY_LEVELS)[number];
|
|
15
|
+
/** The sexes of the table. */
|
|
16
|
+
export declare const CALORIE_SEXES: readonly ["female", "male"];
|
|
17
|
+
/** A sex of the table. */
|
|
18
|
+
export type CalorieSex = (typeof CALORIE_SEXES)[number];
|
|
19
|
+
/**
|
|
20
|
+
* The estimated calorie need of one person of a row for each day. A row gives a need for each activity level, or one need for all levels.
|
|
21
|
+
* The table of the toddlers gives one need for each age and sex only. Each need has a unit of energy for each day, for example `{ "value": 2000, "unit": "kcal/d" }`.
|
|
22
|
+
*/
|
|
23
|
+
export type CalorieNeed = {
|
|
24
|
+
readonly levels: Readonly<Record<ActivityLevel, Quantity>>;
|
|
25
|
+
readonly each?: never;
|
|
26
|
+
} | {
|
|
27
|
+
readonly each: Quantity;
|
|
28
|
+
readonly levels?: never;
|
|
29
|
+
};
|
|
30
|
+
/** A row of a table of calorie needs: a sex, a range of ages in months, and the need. */
|
|
31
|
+
export interface CalorieRow {
|
|
32
|
+
readonly sex: CalorieSex;
|
|
33
|
+
/** The age as the source names it, for example `19-20` (years) or `21 through 23 months`. */
|
|
34
|
+
readonly age: string;
|
|
35
|
+
/** The first age of the row, in whole months. */
|
|
36
|
+
readonly from: number;
|
|
37
|
+
/** The last age of the row, in whole months. Without it, the row applies to each larger age. */
|
|
38
|
+
readonly to?: number | undefined;
|
|
39
|
+
readonly need: CalorieNeed;
|
|
40
|
+
}
|
|
41
|
+
/** A table of estimated calorie needs from one source. */
|
|
42
|
+
export interface CalorieTable {
|
|
43
|
+
/** The id, for example `dga.2020-2025:calorie-needs`. */
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly title: string;
|
|
46
|
+
readonly source: HashedSource;
|
|
47
|
+
/** The place of the tables in the source: the tables and their pages. */
|
|
48
|
+
readonly locator: string;
|
|
49
|
+
/** The rows of the table. The age ranges of the rows of one sex do not overlap. */
|
|
50
|
+
readonly rows: readonly CalorieRow[];
|
|
51
|
+
}
|
|
52
|
+
/** A group of persons of the same sex and age, and their count. */
|
|
53
|
+
export interface Person {
|
|
54
|
+
readonly sex: CalorieSex;
|
|
55
|
+
/** The age, in whole months, for example 420 for 35 years. */
|
|
56
|
+
readonly ageMonths: number;
|
|
57
|
+
readonly count: number;
|
|
58
|
+
/** The activity level of the persons. Without it, the level of the call applies. */
|
|
59
|
+
readonly level?: ActivityLevel | undefined;
|
|
60
|
+
}
|
|
61
|
+
/** The need of one person record for the days, or no read when the table has no row for the age. */
|
|
62
|
+
export type CalorieNeedLine = {
|
|
63
|
+
readonly person: Person;
|
|
64
|
+
readonly read: true;
|
|
65
|
+
readonly level: ActivityLevel;
|
|
66
|
+
readonly row: string;
|
|
67
|
+
readonly need: Quantity;
|
|
68
|
+
} | {
|
|
69
|
+
readonly person: Person;
|
|
70
|
+
readonly read: false;
|
|
71
|
+
readonly why: string;
|
|
72
|
+
};
|
|
73
|
+
/** The energy need of the persons of a household for a count of days. */
|
|
74
|
+
export interface CalorieNeedTotal {
|
|
75
|
+
/** The need of each person record, in the order of the input. */
|
|
76
|
+
readonly lines: readonly CalorieNeedLine[];
|
|
77
|
+
/** True when each line has a read. When it is false, `need` is a lower limit. */
|
|
78
|
+
readonly read: boolean;
|
|
79
|
+
/** The sum of the needs of the lines with a read, in `kcal`. */
|
|
80
|
+
readonly need: Quantity;
|
|
81
|
+
/** The count of the persons of all the records, also of the records with no read. */
|
|
82
|
+
readonly persons: number;
|
|
83
|
+
}
|
|
84
|
+
/** This function tells if a value is an activity level of the table. */
|
|
85
|
+
export declare function isActivityLevel(level: unknown): level is ActivityLevel;
|
|
86
|
+
/**
|
|
87
|
+
* This function gives the row of a table for a sex and an age in months, or `undefined` when the table has no row.
|
|
88
|
+
*
|
|
89
|
+
* @param table - The table of calorie needs
|
|
90
|
+
* @param sex - The sex
|
|
91
|
+
* @param ageMonths - The age, in whole months
|
|
92
|
+
*/
|
|
93
|
+
export declare function calorieRow(table: CalorieTable, sex: CalorieSex, ageMonths: number): CalorieRow | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* This function gives the energy need of the persons of a household for a count of days, in `kcal`.
|
|
96
|
+
* It adds the need of each person at the activity level of that person. The table finds the row of each person from the age.
|
|
97
|
+
*
|
|
98
|
+
* - An age with no row in the table gives a line with no read, for example 6 months. Then the total is a lower limit.
|
|
99
|
+
* - The table of the toddlers gives one need for each age and sex. Thus the level does not change the need of a toddler.
|
|
100
|
+
*
|
|
101
|
+
* The activity level is an explicit input. This package has no default level. The planner selects it, also for the worst case of a long power cut.
|
|
102
|
+
* In that case, work can make the level higher, for example the carry of water. The function is pure.
|
|
103
|
+
*
|
|
104
|
+
* @param table - The table of calorie needs
|
|
105
|
+
* @param persons - The person records of the household: a sex, an age in months, a count and, as an option, a level
|
|
106
|
+
* @param level - The activity level of each record with no level of its own
|
|
107
|
+
* @param days - The count of days, a finite number of 0 or more
|
|
108
|
+
* @throws RangeError when a count of persons or an age is not a whole number of 0 or more, or when the household has no person
|
|
109
|
+
* @throws RangeError when a level is not a level of the table, or when a sex is not a sex of the table
|
|
110
|
+
* @throws RangeError when the count of days is not a finite number of 0 or more
|
|
111
|
+
*/
|
|
112
|
+
export declare function calorieNeed(table: CalorieTable, persons: readonly Person[], level: ActivityLevel, days: number): CalorieNeedTotal;
|
|
113
|
+
/** The source of the calorie table: the PDF of the Dietary Guidelines for Americans, 2020-2025, 9th Edition. It is a work of the United States federal government. */
|
|
114
|
+
export declare const DGA_SOURCE: HashedSource;
|
|
115
|
+
/** The table of estimated calorie needs of the Dietary Guidelines for Americans, 2020-2025: 68 rows, 34 for each sex. */
|
|
116
|
+
export declare const DGA_CALORIES: CalorieTable;
|
|
117
|
+
/** The tables of estimated calorie needs, one record for each source. */
|
|
118
|
+
export declare const CALORIE_TABLES: readonly CalorieTable[];
|
|
119
|
+
/**
|
|
120
|
+
* These are the codes of the gate of the rows and the hash. Each code is an error. The gate of the sources of `@mark1russell7/guidebook` gives its own codes.
|
|
121
|
+
*
|
|
122
|
+
* - `needs-hash`: the hash of the source is not 64 lowercase hexadecimal digits.
|
|
123
|
+
* - `needs-row`: a row has no age or a wrong sex. Or its range of months is not a range of whole numbers of 0 or more.
|
|
124
|
+
* - `needs-overlap`: two rows of one sex have ages in common.
|
|
125
|
+
* - `needs-gap`: the rows of one sex do not cover each month with no gap, from the first row to an open last row.
|
|
126
|
+
* - `needs-value`: a need is not a finite number above 0 in a unit of energy for each day.
|
|
127
|
+
*/
|
|
128
|
+
export declare const NEEDS_CODES: readonly ["needs-hash", "needs-row", "needs-overlap", "needs-gap", "needs-value"];
|
|
129
|
+
/** A code of the gate of a table of calorie needs. */
|
|
130
|
+
export type NeedsCode = (typeof NEEDS_CODES)[number];
|
|
131
|
+
/** A finding of the gate of a table of calorie needs: a finding of the gate of the sources, or a finding of a row. */
|
|
132
|
+
export type NeedsFinding = Finding<NeedsCode | FindingCode, "source" | "unit" | "row">;
|
|
133
|
+
/**
|
|
134
|
+
* This function gives each finding of a table of calorie needs. A list with no error tells that the gate passes.
|
|
135
|
+
*
|
|
136
|
+
* - The findings of the source come from `checkSources` of `@mark1russell7/guidebook`, with the options of the call.
|
|
137
|
+
* - The form of the hash and the rows have the codes of `NEEDS_CODES`.
|
|
138
|
+
*
|
|
139
|
+
* The findings are in the order of the table. The function is pure.
|
|
140
|
+
*
|
|
141
|
+
* @param table - The table of calorie needs
|
|
142
|
+
* @param options - The options of the gate of the sources, for example the date of the gate
|
|
143
|
+
*/
|
|
144
|
+
export declare function checkCalorieTable(table: CalorieTable, options?: GateOptions): NeedsFinding[];
|
|
145
|
+
/** This function tells if a list of findings has an error. */
|
|
146
|
+
export declare function hasNeedsError(findings: readonly NeedsFinding[]): boolean;
|
|
147
|
+
/** The code of the need of the food draw: food energy, in `kcal` for each day. */
|
|
148
|
+
export declare const FOOD_NEED = "food.energy";
|
|
149
|
+
/** The code of the need of drinking water, in `L` for each day. */
|
|
150
|
+
export declare const WATER_NEED = "hydration.drink";
|
|
151
|
+
/** The resource of the food to eat with no water and no fuel, in `kcal`. It has a direct use for the food draw. */
|
|
152
|
+
export declare const NO_COOK = "food.no-cook";
|
|
153
|
+
/** The resource of the stored drinking water, in `L`. It has a direct use for the water need. */
|
|
154
|
+
export declare const STORED_WATER = "water.stored";
|
|
155
|
+
/** The direct use of a resource for a need: 1 unit of the resource gives `amount` of the need. */
|
|
156
|
+
export interface FragmentDirectUse {
|
|
157
|
+
readonly resource: string;
|
|
158
|
+
readonly need: string;
|
|
159
|
+
readonly amount: number;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The default reference part that supplies each need when no case stops it, by the code of the need.
|
|
163
|
+
* The parts are `id` values of `SUPPLY_PARTS` of `@mark1russell7/stack-hazards`. A household with a well gives a different part.
|
|
164
|
+
* The type has the exact keys. The annotation replaces `as const`, because the package has isolated declarations.
|
|
165
|
+
*/
|
|
166
|
+
export declare const NEED_SUPPLIES: {
|
|
167
|
+
readonly "hydration.drink": "water.main";
|
|
168
|
+
readonly "food.energy": "food.retail";
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* The direct uses of the resources of the buy list. Each use gives 1 unit of its need for each unit of its resource.
|
|
172
|
+
*
|
|
173
|
+
* - 1 L of stored drinking water gives 1 L of drink. This is a definition, not a read.
|
|
174
|
+
* - 1 kcal of food to eat with no water and no fuel gives 1 kcal of food energy.
|
|
175
|
+
*
|
|
176
|
+
* These records have the form of `DirectUse` of `@mark1russell7/stack-endurance`.
|
|
177
|
+
*/
|
|
178
|
+
export declare const DIRECT_USES: readonly FragmentDirectUse[];
|
|
179
|
+
/**
|
|
180
|
+
* These are the codes of the join gate. Each code is an error.
|
|
181
|
+
*
|
|
182
|
+
* - `join-use-resource`: a direct use names a resource that is not in the catalog.
|
|
183
|
+
* - `join-use-need`: a direct use names a need that is not in the reference needs.
|
|
184
|
+
* - `join-use-unit`: the unit of the resource of a direct use does not convert to the unit of its need.
|
|
185
|
+
* - `join-use-amount`: the amount of a direct use is not the factor from the unit of its resource to the unit of its need.
|
|
186
|
+
* - `join-supply-need`: a supply names a need that is not in the reference needs.
|
|
187
|
+
* - `join-supply-part`: a supply names a part that is not in the reference parts.
|
|
188
|
+
*/
|
|
189
|
+
export declare const JOIN_CODES: readonly ["join-use-resource", "join-use-need", "join-use-unit", "join-use-amount", "join-supply-need", "join-supply-part"];
|
|
190
|
+
/** A code of the join gate. */
|
|
191
|
+
export type JoinCode = (typeof JOIN_CODES)[number];
|
|
192
|
+
/**
|
|
193
|
+
* A finding of the join gate, in the form of a finding of `@mark1russell7/guidebook`. Each finding of the gate is an error.
|
|
194
|
+
* The record is `use` for a direct use, with the resource of the use as its `id`. It is `supply` for a supply, with the need as its `id`.
|
|
195
|
+
*/
|
|
196
|
+
export type JoinFinding = Finding<JoinCode, "use" | "supply">;
|
|
197
|
+
/** A reference need: its code and its unit. Each record of `NEEDS` of `@mark1russell7/alerts` has this form. */
|
|
198
|
+
export interface ReferenceNeed {
|
|
199
|
+
readonly code: string;
|
|
200
|
+
readonly unit: string;
|
|
201
|
+
}
|
|
202
|
+
/** A reference part: its `id`. Each record of `SUPPLY_PARTS` of `@mark1russell7/stack-hazards` has this form. */
|
|
203
|
+
export interface ReferencePart {
|
|
204
|
+
readonly id: string;
|
|
205
|
+
}
|
|
206
|
+
/** The reference lists of the join gate. */
|
|
207
|
+
export interface JoinReferences {
|
|
208
|
+
/** The reference needs, for example `NEEDS` of `@mark1russell7/alerts`. */
|
|
209
|
+
readonly needs: readonly ReferenceNeed[];
|
|
210
|
+
/** The reference parts, for example `SUPPLY_PARTS` of `@mark1russell7/stack-hazards`. */
|
|
211
|
+
readonly parts: readonly ReferencePart[];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* This function examines the joins of a catalog, the direct uses and the supply parts with the reference lists.
|
|
215
|
+
*
|
|
216
|
+
* - The resource of each direct use is a resource of the catalog, and its need is a reference need.
|
|
217
|
+
* - The unit of the resource of each direct use converts to the unit of its need.
|
|
218
|
+
* - The amount of each direct use is the factor of that conversion. A direct use is a definition, so a different rate is a converter with a cited source.
|
|
219
|
+
* - Each supply names a reference need and a reference part.
|
|
220
|
+
*
|
|
221
|
+
* The findings are in the order of the uses, then in the order of the supplies. The function is pure.
|
|
222
|
+
*
|
|
223
|
+
* @param catalog - The catalog of supplies of `@mark1russell7/market`
|
|
224
|
+
* @param uses - The direct uses, for example `DIRECT_USES`
|
|
225
|
+
* @param supplies - The part that supplies each need, by the code of the need, for example `NEED_SUPPLIES`
|
|
226
|
+
* @param references - The reference needs and the reference parts
|
|
227
|
+
* @returns The findings of the joins. An empty list is a pass.
|
|
228
|
+
*/
|
|
229
|
+
export declare function checkJoins(catalog: SupplyCatalog, uses: readonly FragmentDirectUse[], supplies: Readonly<Record<string, string>>, references: JoinReferences): JoinFinding[];
|
|
230
|
+
/** A resource of a store, with its unit. */
|
|
231
|
+
export interface FragmentResource {
|
|
232
|
+
readonly code: string;
|
|
233
|
+
readonly unit: string;
|
|
234
|
+
}
|
|
235
|
+
/** A store of the buy list: an amount of one resource, in its unit. */
|
|
236
|
+
export interface FragmentStore {
|
|
237
|
+
readonly id: string;
|
|
238
|
+
readonly resource: string;
|
|
239
|
+
readonly amount: number;
|
|
240
|
+
}
|
|
241
|
+
/** The food draw: the food energy of the persons of the draw for each day. */
|
|
242
|
+
export interface FragmentDraw {
|
|
243
|
+
readonly need: string;
|
|
244
|
+
readonly level: string;
|
|
245
|
+
/** The food energy of the persons of the draw for each day, in `kcal`. It is above 0. */
|
|
246
|
+
readonly perDay: number;
|
|
247
|
+
/** The count of the persons of the draw. */
|
|
248
|
+
readonly users: number;
|
|
249
|
+
readonly supply: string;
|
|
250
|
+
}
|
|
251
|
+
/** A fragment of an endurance layer, with the form of `EnduranceLayer` of `@mark1russell7/stack-endurance`. It has no converter. */
|
|
252
|
+
export interface HouseholdFragment {
|
|
253
|
+
/** The format of an endurance layer, `endurance/1`. */
|
|
254
|
+
readonly schema: "endurance/1";
|
|
255
|
+
readonly levels: readonly string[];
|
|
256
|
+
readonly resources: readonly FragmentResource[];
|
|
257
|
+
readonly stores: readonly FragmentStore[];
|
|
258
|
+
readonly draws: readonly FragmentDraw[];
|
|
259
|
+
readonly direct: readonly FragmentDirectUse[];
|
|
260
|
+
}
|
|
261
|
+
/** The action for the persons with no row in the table. The only action is `leave-out`. */
|
|
262
|
+
export type NoRowAction = "leave-out";
|
|
263
|
+
/** The inputs of the household fragment. */
|
|
264
|
+
export interface HouseholdFragmentInput {
|
|
265
|
+
/** The person records of the household. */
|
|
266
|
+
readonly persons: readonly Person[];
|
|
267
|
+
/** The activity level of each person record with no level of its own. It has no default. */
|
|
268
|
+
readonly activity: ActivityLevel;
|
|
269
|
+
/** The catalog of supplies of `@mark1russell7/market`. */
|
|
270
|
+
readonly catalog: SupplyCatalog;
|
|
271
|
+
/** The count of units of each product of the buy list, by the `id` of the product. */
|
|
272
|
+
readonly units: Readonly<Record<string, number>>;
|
|
273
|
+
/** The `id` of the part of the stack that supplies the food when no case stops it. The default is `NEED_SUPPLIES["food.energy"]`, `food.retail`. */
|
|
274
|
+
readonly supply?: string | undefined;
|
|
275
|
+
/** The direct uses. The fragment takes each use for the need `food.energy`. The default is `DIRECT_USES`. */
|
|
276
|
+
readonly uses?: readonly FragmentDirectUse[] | undefined;
|
|
277
|
+
/** The level of the food draw. It is one of the levels of the joined layer. */
|
|
278
|
+
readonly level: string;
|
|
279
|
+
/** The levels of the fragment. The default is no levels: a different fragment of the stack gives them. */
|
|
280
|
+
readonly levels?: readonly string[] | undefined;
|
|
281
|
+
/** The table of calorie needs. The default is `DGA_CALORIES`. */
|
|
282
|
+
readonly table?: CalorieTable | undefined;
|
|
283
|
+
/** The start of the `id` of each store. The default is `buy`. */
|
|
284
|
+
readonly prefix?: string | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* The action for the persons with no row in the table. Without it, a person with no row gives no layer.
|
|
287
|
+
* With `leave-out`, the draw has no need of those persons, and the result lists them.
|
|
288
|
+
*/
|
|
289
|
+
readonly noRow?: NoRowAction | undefined;
|
|
290
|
+
}
|
|
291
|
+
/** A gift of the buy list with no read. The fragment has no store for it. A no read is not 0. */
|
|
292
|
+
export interface GiftNoRead {
|
|
293
|
+
readonly product: string;
|
|
294
|
+
readonly resource: string;
|
|
295
|
+
readonly why: string;
|
|
296
|
+
}
|
|
297
|
+
/** The parts of the result that do not change with the draw. */
|
|
298
|
+
export interface HouseholdStoresResult {
|
|
299
|
+
/** The food energy of each product of the buy list. A caller gets the energy of the dry food for its converters from it. */
|
|
300
|
+
readonly energy: BuyListEnergy;
|
|
301
|
+
/** The gifts of the buy list with no read. */
|
|
302
|
+
readonly noReads: readonly GiftNoRead[];
|
|
303
|
+
/** True when each gift of the buy list has a read. When it is false, the stores are a lower limit. */
|
|
304
|
+
readonly storesRead: boolean;
|
|
305
|
+
}
|
|
306
|
+
/** The household fragment with its draw. The draw is exact for its users. */
|
|
307
|
+
export interface HouseholdFragmentRead extends HouseholdStoresResult {
|
|
308
|
+
readonly layer: HouseholdFragment;
|
|
309
|
+
/**
|
|
310
|
+
* The food energy of the household for one day, with a line for each person record. Its `read` covers the whole
|
|
311
|
+
* household. It is false when a person is left out, or when a record with count 0 has no row. The flag of the draw
|
|
312
|
+
* is `needRead`.
|
|
313
|
+
*/
|
|
314
|
+
readonly need: CalorieNeedTotal;
|
|
315
|
+
/** This field is true: the draw has a read for each of its users. */
|
|
316
|
+
readonly needRead: true;
|
|
317
|
+
/** The persons with no row that the option `leave-out` left out of the draw. With no option, the list is empty. */
|
|
318
|
+
readonly leftOut: readonly Person[];
|
|
319
|
+
}
|
|
320
|
+
/** No household fragment: the draw has no read. A low rate gives too many days, so the function gives no layer. */
|
|
321
|
+
export interface HouseholdFragmentNoRead extends HouseholdStoresResult {
|
|
322
|
+
readonly layer: undefined;
|
|
323
|
+
/** The food energy of the household for one day. It is `undefined` when the household has no person. */
|
|
324
|
+
readonly need: CalorieNeedTotal | undefined;
|
|
325
|
+
readonly needRead: false;
|
|
326
|
+
/** The persons with no row in the table. */
|
|
327
|
+
readonly noRow: readonly Person[];
|
|
328
|
+
/** The reason for no layer. */
|
|
329
|
+
readonly why: string;
|
|
330
|
+
}
|
|
331
|
+
/** The household fragment, or a no read of the draw. Both have the reads of the buy list. */
|
|
332
|
+
export type HouseholdFragmentResult = HouseholdFragmentRead | HouseholdFragmentNoRead;
|
|
333
|
+
/**
|
|
334
|
+
* This function joins a household and a buy list into a fragment of an endurance layer.
|
|
335
|
+
*
|
|
336
|
+
* - The fragment has one draw of food energy. Its rate is the need of the persons for one day, and its users are the persons.
|
|
337
|
+
* - Each gift of the buy list with a read is one store, with the `id` `<prefix>:<product>:<resource>`. A gift with no read has no store.
|
|
338
|
+
* - The direct uses are the food uses: each use of `uses` for the need `food.energy`. The default `DIRECT_USES` gives `food.no-cook`, 1 kcal for each kcal.
|
|
339
|
+
* - The resources are the resources of the stores and of the food uses, with the units of the catalog.
|
|
340
|
+
* - The supply part of the draw is `supply`. Its default is the part of `NEED_SUPPLIES` for `food.energy`.
|
|
341
|
+
* - The fragment has no converter. A caller adds converters for the dry food, with the water and the fuel of each run.
|
|
342
|
+
*
|
|
343
|
+
* A person with no row in the table gives no layer, because a low rate gives too many days.
|
|
344
|
+
* The option `noRow: "leave-out"` leaves those persons out of the draw. A draw of 0 kcal gives no layer.
|
|
345
|
+
* The function is pure.
|
|
346
|
+
*
|
|
347
|
+
* @param input - The persons, the activity level, the catalog and the buy list, the supply part and the level of the draw
|
|
348
|
+
* @returns The fragment or a no read of the draw, with the energy of the list and the gifts with no read
|
|
349
|
+
* @throws RangeError for the errors of `calorieNeed`, `giftsOf` and `buyListEnergy`, except a household with no person
|
|
350
|
+
* @throws RangeError when the catalog has no resource in `kcal` for a food use
|
|
351
|
+
*/
|
|
352
|
+
export declare function householdFragment(input: HouseholdFragmentInput): HouseholdFragmentResult;
|
|
353
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/source.ts","../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts"],"mappings":";;;;;;;YASY,eAAe;WAAoB;;;qBCDlC;;YAGD,wBAAwB;;qBAGvB;;YAGD,qBAAqB;;;;;YAMrB;WAAyB,QAAQ,SAAS,OAAO,eAAe;WAAqB;;WAA4B,MAAM;WAAmB;;;iBAGrI;WACN,KAAK;;WAEL;;WAEA;;WAEA;WACA,MAAM;;;iBAIA;;WAEN;WACA;WACA,QAAQ;;WAER;;WAEA,eAAe;;;iBAIT;WACN,KAAK;;WAEL;WACA;;WAEA,QAAQ;;;YAIP;WACG,QAAQ;WAAiB;WAAqB,OAAO;WAAwB;WAAsB,MAAM;;WACzG,QAAQ;WAAiB;WAAsB;;;iBAG7C;;WAEN,gBAAgB;;WAEhB;;WAEA,MAAM;;WAEN;;;wBASK,gBAAgB,iBAAiB,SAAS;;;;;;;;wBAW1C,WAAW,OAAO,cAAc,KAAK,YAAY,oBAAoB;;;;;;;;;;;;;;;;;;;wBAsBrE,YAAY,OAAO,cAAc,kBAAkB,UAAU,OAAO,eAAe,eAAe;;qBC1GrG,YAAY;;qBAeZ,cAAc;;qBA8Ed,yBAAyB;;;;;;;;;;qBCvFzB;;YAGD,oBAAoB;;YAGpB,eAAe,QAAQ,YAAY;;;;;;;;;;;;wBAuB/B,kBAAkB,OAAO,cAAc,UAAU,cAAc;;wBAsC/D,cAAc,mBAAmB;;qBC1EpC;;qBAGA;;qBAGA;;qBAGA;;iBAGI;WACN;WACA;WACA;;;;;;;qBAQE;WAA0B;WAA0C;;;;;;;;;;qBAapE,sBAAsB;;;;;;;;;;;qBAetB;;YAUD,mBAAmB;;;;;YAMnB,cAAc,QAAQ;;iBAajB;WACN;WACA;;;iBAIM;WACN;;;iBAIM;;WAEN,gBAAgB;;WAEhB,gBAAgB;;;;;;;;;;;;;;;;;;wBAmBX,WACd,SAAS,eACT,eAAe,qBACf,UAAU,SAAS,yBACnB,YAAY,iBACX;;iBCpHc;WACN;WACA;;;iBAIM;WACN;WACA;WACA;;;iBAIM;WACN;WACA;;WAEA;;WAEA;WACA;;;iBAIM;;WAEN;WACA;WACA,oBAAoB;WACpB,iBAAiB;WACjB,gBAAgB;WAChB,iBAAiB;;;YAIhB;;iBAGK;;WAEN,kBAAkB;;WAElB,UAAU;;WAEV,SAAS;;WAET,OAAO,SAAS;;WAEhB;;WAEA,gBAAgB;;WAEhB;;WAEA;;WAEA,QAAQ;;WAER;;;;;WAKA,QAAQ;;;iBAIF;WACN;WACA;WACA;;;iBAIM;;WAEN,QAAQ;;WAER,kBAAkB;;WAElB;;;iBAIM,8BAA8B;WACpC,OAAO;;;;;;WAMP,MAAM;;WAEN;;WAEA,kBAAkB;;;iBAIZ,gCAAgC;WACtC;;WAEA,MAAM;WACN;;WAEA,gBAAgB;;WAEhB;;;YAIC,0BAA0B,wBAAwB;;;;;;;;;;;;;;;;;;;;wBA8C9C,kBAAkB,OAAO,yBAAyB"}
|