@mark1russell7/guidebook-library 0.0.0-stage → 0.1.0
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 +110 -2
- package/build/index.d.ts +310 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +534 -0
- package/build/index.js.map +1 -0
- package/package.json +68 -3
- package/src/check.ts +105 -0
- package/src/copies.ts +141 -0
- package/src/date.ts +10 -0
- package/src/index.ts +13 -0
- package/src/kiwix.ts +214 -0
- package/src/placement.ts +174 -0
- package/src/records.ts +61 -0
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,111 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mark1russell7/guidebook-library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The library add-on of the guidebook. It holds a catalog of offline bundles and the copies of each bundle on media. It tells which copies are missing or old.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @mark1russell7/guidebook-library
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The add-on names no topic. The bundles, the levels, the media and the places are input data of the caller.
|
|
10
|
+
|
|
11
|
+
## The records
|
|
12
|
+
|
|
13
|
+
| Record | What it holds |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `Bundle` | One offline file, for example a Kiwix ZIM file: its `id`, `title`, `bytes`, `license`, `level` and `source`, and an optional `version`, `sha256` and `url` |
|
|
16
|
+
| `Copy` | A copy of a bundle on one medium: the `bundle`, the `medium`, its `kind`, its `place`, the date `checked` of the last read, and an optional `version` and `sha256` |
|
|
17
|
+
| `CopyRule` | The copies that a level needs: the count of `copies`, of `kinds` of media and of `places`, and the days `everyDays` between two checks |
|
|
18
|
+
|
|
19
|
+
The kinds of media are `flash`, `ssd`, `hdd`, `optical` and `paper`.
|
|
20
|
+
|
|
21
|
+
## The catalog gate
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { checkCatalog, checkCopies } from "@mark1russell7/guidebook-library";
|
|
25
|
+
|
|
26
|
+
const findings = checkCatalog(bundles, { sources, rules, commercial: false });
|
|
27
|
+
const copyFindings = checkCopies(copies, bundles, { at: "2026-11-21" });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`checkCatalog` uses `permits(license, "bundle")` of the core. A bundle with a license that refuses an offline copy gets the error `use-refused`.
|
|
31
|
+
|
|
32
|
+
| Code | When |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `duplicate-id` | Two bundles have the same `id`. |
|
|
35
|
+
| `empty-title` | A bundle has no title. |
|
|
36
|
+
| `bad-bytes` | The size is not a whole number of 1 or more. |
|
|
37
|
+
| `bad-sha256` | The hash is not 64 lower-case hexadecimal digits. |
|
|
38
|
+
| `bad-url` | The address does not start with `https:` or `http:`. |
|
|
39
|
+
| `unknown-license` | The core does not know the license. |
|
|
40
|
+
| `use-refused` | The license does not permit an offline copy. |
|
|
41
|
+
| `missing-source` | The `source` is not in the sources. |
|
|
42
|
+
| `unknown-level` | No copy rule has the level of the bundle. |
|
|
43
|
+
|
|
44
|
+
`checkCopies` gives the codes `duplicate-copy`, `missing-bundle`, `bad-kind`, `bad-sha256`, `bad-date` and `checked-in-future`.
|
|
45
|
+
|
|
46
|
+
## The state of the copies
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { checksDue, copyStates } from "@mark1russell7/guidebook-library";
|
|
50
|
+
|
|
51
|
+
const { states, findings } = copyStates(bundles, copies, rules, { at: "2026-11-21" });
|
|
52
|
+
const next = checksDue(bundles, copies, rules, { at: "2026-11-21", withinDays: 30 });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Each copy has one status:
|
|
56
|
+
|
|
57
|
+
| Status | When | Does it count? |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| `good` | The last check is within the days of the rule, and the hash agrees. | yes |
|
|
60
|
+
| `old` | As `good`, but the copy holds an earlier release. | yes |
|
|
61
|
+
| `due` | The last check is older than the days of the rule. | no |
|
|
62
|
+
| `bad` | The hash does not agree with the hash of the same release. | no |
|
|
63
|
+
|
|
64
|
+
A bundle with too few good copies, kinds or places gets an error: `few-copies`, `few-kinds` or `few-places`. A bundle with no rule gets the error `no-rule`. A copy with the status `due`, `bad` or `old` gets a warning: `check-due`, `bad-hash` or `old-version`.
|
|
65
|
+
|
|
66
|
+
`checksDue` gives the last good date of each copy, the first due first. `bytesOf(bundles, ids)` gives the bytes that one medium needs for a list of bundles.
|
|
67
|
+
|
|
68
|
+
## The Kiwix catalog
|
|
69
|
+
|
|
70
|
+
Kiwix gives offline copies of open sites as ZIM files. Its OPDS feed lists each release, and the `.meta4` file of a release gives its exact size and its SHA-256. The functions are pure: the caller fetches the files, for example with `polite-crawler/api`.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { checkReleases, kiwixFeedUrl, parseKiwixFeed, parseMeta4, withRelease } from "@mark1russell7/guidebook-library";
|
|
74
|
+
|
|
75
|
+
const entries = parseKiwixFeed(await read(kiwixFeedUrl({ lang: "eng" })));
|
|
76
|
+
const findings = checkReleases(bundles, entries, { at: "2026-11-21" });
|
|
77
|
+
const next = withRelease(bundle, entry, parseMeta4(await read(entry.meta4)));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The feed rounds each size up to whole KiB. Thus a bundle takes its `bytes` from `parseMeta4`, not from the feed.
|
|
81
|
+
|
|
82
|
+
| Code | Level | When |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| `not-in-feed` | error | The feed has no file of the bundle. |
|
|
85
|
+
| `old-release` | error | The feed has a newer release, and the bundle is older than `maxAgeDays` (365 by default). |
|
|
86
|
+
| `newer-release` | warning | The feed has a newer release. |
|
|
87
|
+
| `no-hash` | warning | The bundle has no SHA-256. |
|
|
88
|
+
| `not-kiwix` | warning | The address of the bundle is not a ZIM release. |
|
|
89
|
+
|
|
90
|
+
The decoder of character references comes from `@mark1russell7/text`.
|
|
91
|
+
|
|
92
|
+
## Where the copies go
|
|
93
|
+
|
|
94
|
+
The plan of the copies of a level is a query of `@mark1russell7/stack-placement`. Nobody picks a place or a medium by hand.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { bytesOf, copiesLayer, planCopies } from "@mark1russell7/guidebook-library";
|
|
98
|
+
|
|
99
|
+
const query = copiesLayer({ rule, bytes: bytesOf(bundles, ids), offers, places, currency: "USD" });
|
|
100
|
+
const plan = planCopies(query, rule, { today: "2026-11-21" });
|
|
101
|
+
plan.front.map((row) => [row.choice, row.cost, row.chance]);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- Each slot is one copy. The rule gives `rule.copies` slots, and `extra` gives the optional slots after them (1 by default).
|
|
105
|
+
- Each candidate is one medium offer at one place. An offer with less capacity than `bytes` is not a candidate.
|
|
106
|
+
- Each place and each kind of medium is a shared fragment. Thus two copies at one place share the loss of that place.
|
|
107
|
+
- The chance is the chance that one copy or more can be read at the end of one period `rule.everyDays`. `keepChance` scales each yearly loss to that period.
|
|
108
|
+
- The cost is the cost of a month: `price / (lifeYears × 12)` for each copy, plus the `monthly` cost of each place.
|
|
109
|
+
- A plan with fewer places or fewer kinds than the rule gets the break `measure`. Thus it is not on the front.
|
|
110
|
+
|
|
111
|
+
The offers, the places and their rates of loss are input data of the caller. Each rate has its source.
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { Finding, IsoDate, License, Source, SourceId, UseContext } from "@mark1russell7/guidebook";
|
|
2
|
+
import { PlacementLayer, PlacementPlan } from "@mark1russell7/stack-placement";
|
|
3
|
+
import { Stack } from "@mark1russell7/system-stack";
|
|
4
|
+
/** The kinds of media that hold a copy. */
|
|
5
|
+
export declare const MEDIUM_KINDS: readonly ["flash", "ssd", "hdd", "optical", "paper"];
|
|
6
|
+
/** A kind of medium. */
|
|
7
|
+
type MediumKind = (typeof MEDIUM_KINDS)[number];
|
|
8
|
+
/**
|
|
9
|
+
* An offline bundle: one file that holds a full source, for example a Kiwix ZIM file.
|
|
10
|
+
* The `level` names a rule of the caller, so the add-on names no topic.
|
|
11
|
+
*/
|
|
12
|
+
interface Bundle {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly title: string;
|
|
15
|
+
/** The size of the file in bytes. */
|
|
16
|
+
readonly bytes: number;
|
|
17
|
+
readonly license: License;
|
|
18
|
+
/** The level of the most important content of the bundle. A copy rule of the caller gives the copies of each level. */
|
|
19
|
+
readonly level: string;
|
|
20
|
+
/** The `id` of the source of the bundle in the sources of the core. */
|
|
21
|
+
readonly source: SourceId;
|
|
22
|
+
/** The release of the file, for example `2026-10`. */
|
|
23
|
+
readonly version?: string;
|
|
24
|
+
/** The SHA-256 of the file, as 64 lower-case hexadecimal digits. */
|
|
25
|
+
readonly sha256?: string;
|
|
26
|
+
/** The address of the file, with `https:` or `http:`. */
|
|
27
|
+
readonly url?: string;
|
|
28
|
+
}
|
|
29
|
+
/** A copy of a bundle on one medium. Where each copy goes is a query of the caller, for example of `stack-placement`. */
|
|
30
|
+
interface Copy {
|
|
31
|
+
/** The `id` of the bundle. */
|
|
32
|
+
readonly bundle: string;
|
|
33
|
+
/** The `id` of the medium, for example the label on a drive. */
|
|
34
|
+
readonly medium: string;
|
|
35
|
+
readonly kind: MediumKind;
|
|
36
|
+
/** The `id` of the place of the medium. The places are input data of the caller. */
|
|
37
|
+
readonly place: string;
|
|
38
|
+
/** The date of the last read of the full copy against its hash. */
|
|
39
|
+
readonly checked: IsoDate;
|
|
40
|
+
/** The release of the bundle on the medium. */
|
|
41
|
+
readonly version?: string;
|
|
42
|
+
/** The SHA-256 that the last check read from the copy. */
|
|
43
|
+
readonly sha256?: string;
|
|
44
|
+
}
|
|
45
|
+
/** The copies that a level needs. */
|
|
46
|
+
interface CopyRule {
|
|
47
|
+
readonly level: string;
|
|
48
|
+
/** The smallest count of good copies. */
|
|
49
|
+
readonly copies: number;
|
|
50
|
+
/** The smallest count of different kinds of media among the good copies. */
|
|
51
|
+
readonly kinds: number;
|
|
52
|
+
/** The smallest count of different places among the good copies. */
|
|
53
|
+
readonly places: number;
|
|
54
|
+
/** A copy is good for this number of days after its last check. */
|
|
55
|
+
readonly everyDays: number;
|
|
56
|
+
}
|
|
57
|
+
/** The codes of the findings of the catalog gate. */
|
|
58
|
+
export declare const LIBRARY_CODES: readonly ["duplicate-id", "empty-title", "bad-bytes", "bad-sha256", "bad-url", "unknown-license", "missing-source", "unknown-level", "use-refused", "missing-bundle", "bad-kind", "bad-date", "checked-in-future", "duplicate-copy"];
|
|
59
|
+
/** A code of a finding of the catalog gate. */
|
|
60
|
+
type LibraryCode = (typeof LIBRARY_CODES)[number];
|
|
61
|
+
/** A finding of the catalog gate, on a bundle or on a copy. */
|
|
62
|
+
type LibraryFinding = Finding<LibraryCode, "bundle" | "copy">;
|
|
63
|
+
/** The options of the catalog gate. */
|
|
64
|
+
interface CatalogOptions extends UseContext {
|
|
65
|
+
/** The sources of the core. With them, a bundle must name a known source. */
|
|
66
|
+
readonly sources?: readonly Source[];
|
|
67
|
+
/** The copy rules. With them, a bundle must name the level of a rule. */
|
|
68
|
+
readonly rules?: readonly CopyRule[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* This function gives the findings of the bundles of a catalog.
|
|
72
|
+
* A bundle must have a unique id, a title, a whole positive size and a license that permits a bundle.
|
|
73
|
+
* Its hash and its address must be correct when it has them.
|
|
74
|
+
*/
|
|
75
|
+
export declare function checkCatalog(bundles: readonly Bundle[], options?: CatalogOptions): readonly LibraryFinding[];
|
|
76
|
+
/** The options of the check of the copies. */
|
|
77
|
+
interface CopiesOptions {
|
|
78
|
+
/** The date of the check. With it, a copy with a later check date is an error. */
|
|
79
|
+
readonly at?: string;
|
|
80
|
+
}
|
|
81
|
+
/** This function gives the findings of the copies: an unknown bundle or kind, a bad date, and two records of one copy. */
|
|
82
|
+
export declare function checkCopies(copies: readonly Copy[], bundles: readonly Bundle[], options?: CopiesOptions): readonly LibraryFinding[];
|
|
83
|
+
/** The codes of the copy gaps. */
|
|
84
|
+
export declare const GAP_CODES: readonly ["few-copies", "few-kinds", "few-places", "no-rule", "check-due", "bad-hash", "old-version"];
|
|
85
|
+
/** A code of a copy gap. */
|
|
86
|
+
type GapCode = (typeof GAP_CODES)[number];
|
|
87
|
+
/** A copy gap: an error on a bundle with too few good copies, or a warning on one copy. */
|
|
88
|
+
type GapFinding = Finding<GapCode, "bundle" | "copy">;
|
|
89
|
+
/**
|
|
90
|
+
* The status of one copy at a date.
|
|
91
|
+
* - `good`: the copy had a check within the days of its rule, and its hash agrees with the bundle.
|
|
92
|
+
* - `old`: as `good`, but the copy holds an earlier release of the bundle. It counts as a good copy.
|
|
93
|
+
* - `due`: the last check is older than the days of the rule. The copy does not count until a new check.
|
|
94
|
+
* - `bad`: the hash of the copy does not agree with the hash of the same release. Replace the copy.
|
|
95
|
+
*/
|
|
96
|
+
type CopyStatus = "good" | "old" | "due" | "bad";
|
|
97
|
+
/** The state of the copies of one bundle. */
|
|
98
|
+
interface CopyState {
|
|
99
|
+
readonly bundle: string;
|
|
100
|
+
readonly level: string;
|
|
101
|
+
/** The rule of the level, or `undefined` when no rule has the level. */
|
|
102
|
+
readonly rule: CopyRule | undefined;
|
|
103
|
+
readonly copies: readonly {
|
|
104
|
+
readonly copy: Copy;
|
|
105
|
+
readonly status: CopyStatus;
|
|
106
|
+
}[];
|
|
107
|
+
/** The count of good copies (the status `good` or `old`). */
|
|
108
|
+
readonly good: number;
|
|
109
|
+
/** The different kinds of media of the good copies. */
|
|
110
|
+
readonly kinds: readonly MediumKind[];
|
|
111
|
+
/** The different places of the good copies. */
|
|
112
|
+
readonly places: readonly string[];
|
|
113
|
+
/** This field is true when the good copies obey the rule. */
|
|
114
|
+
readonly ok: boolean;
|
|
115
|
+
}
|
|
116
|
+
/** The result of `copyStates`. */
|
|
117
|
+
interface CopyStates {
|
|
118
|
+
readonly states: readonly CopyState[];
|
|
119
|
+
readonly findings: readonly GapFinding[];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* This function gives the state of the copies of each bundle at the date `at`, and the gaps.
|
|
123
|
+
* A bundle with fewer good copies, kinds or places than the rule of its level gets an error.
|
|
124
|
+
* A copy with a check that is due, a bad hash or an earlier release gets a warning.
|
|
125
|
+
*/
|
|
126
|
+
export declare function copyStates(bundles: readonly Bundle[], copies: readonly Copy[], rules: readonly CopyRule[], options: {
|
|
127
|
+
readonly at: IsoDate;
|
|
128
|
+
}): CopyStates;
|
|
129
|
+
/** A check of a copy that a schedule gives to a person or a job. */
|
|
130
|
+
interface DueCheck {
|
|
131
|
+
readonly bundle: string;
|
|
132
|
+
readonly medium: string;
|
|
133
|
+
readonly place: string;
|
|
134
|
+
/** The last date on which the copy is good with no new check. */
|
|
135
|
+
readonly due: IsoDate;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* This function gives the check of each copy whose due date is on or before `at` plus `withinDays`, the first due first.
|
|
139
|
+
* A copy of a bundle with no rule, or of an unknown bundle, gets no check.
|
|
140
|
+
*/
|
|
141
|
+
export declare function checksDue(bundles: readonly Bundle[], copies: readonly Copy[], rules: readonly CopyRule[], options: {
|
|
142
|
+
readonly at: IsoDate;
|
|
143
|
+
readonly withinDays?: number;
|
|
144
|
+
}): readonly DueCheck[];
|
|
145
|
+
/** This function gives the bytes that are necessary on one medium for each bundle of a list. */
|
|
146
|
+
export declare function bytesOf(bundles: readonly Bundle[], ids: readonly string[]): number;
|
|
147
|
+
/** The address of the OPDS catalog of Kiwix. */
|
|
148
|
+
export declare const KIWIX_CATALOG = "https://opds.library.kiwix.org/catalog/v2";
|
|
149
|
+
/** One ZIM file of the OPDS feed of Kiwix. */
|
|
150
|
+
interface KiwixEntry {
|
|
151
|
+
/** The key of the file: its name with its flavour, for example `wikipedia_en_medicine_nopic`. */
|
|
152
|
+
readonly key: string;
|
|
153
|
+
readonly name: string;
|
|
154
|
+
/** The flavour of the file, for example `nopic`, or an empty text. */
|
|
155
|
+
readonly flavour: string;
|
|
156
|
+
readonly title: string;
|
|
157
|
+
/** The release of the file, `YYYY-MM`. */
|
|
158
|
+
readonly release: string;
|
|
159
|
+
/** The date of the release. */
|
|
160
|
+
readonly issued: IsoDate;
|
|
161
|
+
/** The address of the `.meta4` file of the release. */
|
|
162
|
+
readonly meta4: string;
|
|
163
|
+
/** The size that the feed gives. The feed rounds it up to whole KiB, so `parseMeta4` gives the exact size. */
|
|
164
|
+
readonly approxBytes: number;
|
|
165
|
+
}
|
|
166
|
+
/** The facts of one file in a `.meta4` file. */
|
|
167
|
+
interface Meta4 {
|
|
168
|
+
/** The name of the file, for example `wikipedia_en_medicine_nopic_2026-10.zim`. */
|
|
169
|
+
readonly file: string;
|
|
170
|
+
/** The exact size of the file in bytes. */
|
|
171
|
+
readonly bytes: number;
|
|
172
|
+
/** The SHA-256 of the file, as 64 lower-case hexadecimal digits. */
|
|
173
|
+
readonly sha256: string;
|
|
174
|
+
}
|
|
175
|
+
/** The options of `kiwixFeedUrl`. */
|
|
176
|
+
interface FeedQuery {
|
|
177
|
+
/** The ISO 639-3 code of the language, for example `eng`. */
|
|
178
|
+
readonly lang?: string;
|
|
179
|
+
/** The name of a file, for example `wikipedia_en_medicine`. */
|
|
180
|
+
readonly name?: string;
|
|
181
|
+
/** The largest count of entries. The default is 2000. */
|
|
182
|
+
readonly count?: number;
|
|
183
|
+
/** The address of the catalog. The default is `KIWIX_CATALOG`. */
|
|
184
|
+
readonly catalog?: string;
|
|
185
|
+
}
|
|
186
|
+
/** This function gives the address of the OPDS feed of the entries that agree with the query. */
|
|
187
|
+
export declare function kiwixFeedUrl(query?: FeedQuery): string;
|
|
188
|
+
/** This function gives the key and the release of a ZIM file from its name or its address, or `undefined` for another file. */
|
|
189
|
+
export declare function kiwixKeyOf(fileOrUrl: string): {
|
|
190
|
+
readonly key: string;
|
|
191
|
+
readonly release: string;
|
|
192
|
+
} | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* This function gives the entries of an OPDS feed of Kiwix.
|
|
195
|
+
* An entry with no open-access link to a `.meta4` file of a ZIM release is not in the result.
|
|
196
|
+
*/
|
|
197
|
+
export declare function parseKiwixFeed(xml: string): readonly KiwixEntry[];
|
|
198
|
+
/** This function gives the file, the exact size and the SHA-256 of the first file of a `.meta4` file. It throws a `RangeError` when one is missing. */
|
|
199
|
+
export declare function parseMeta4(xml: string): Meta4;
|
|
200
|
+
/** This function gives the newest release of each key of the entries. */
|
|
201
|
+
export declare function latestReleases(entries: readonly KiwixEntry[]): ReadonlyMap<string, KiwixEntry>;
|
|
202
|
+
/** The address of the ZIM file of a `.meta4` address: the same address with no `.meta4`. */
|
|
203
|
+
export declare function zimUrlOf(meta4: string): string;
|
|
204
|
+
/**
|
|
205
|
+
* This function gives the bundle with the release of the entry: its version, its exact size, its SHA-256 and its address.
|
|
206
|
+
* It throws a `RangeError` when the `.meta4` file is for a different file.
|
|
207
|
+
*/
|
|
208
|
+
export declare function withRelease(bundle: Bundle, entry: KiwixEntry, meta4: Meta4): Bundle;
|
|
209
|
+
/** The codes of the release gate. */
|
|
210
|
+
export declare const RELEASE_CODES: readonly ["not-kiwix", "not-in-feed", "newer-release", "old-release", "no-hash"];
|
|
211
|
+
/** A code of the release gate. */
|
|
212
|
+
type ReleaseCode = (typeof RELEASE_CODES)[number];
|
|
213
|
+
/** A finding of the release gate. */
|
|
214
|
+
type ReleaseFinding = Finding<ReleaseCode, "bundle">;
|
|
215
|
+
/** The options of `checkReleases`. */
|
|
216
|
+
interface ReleaseOptions {
|
|
217
|
+
/** The date of the read of the feed. */
|
|
218
|
+
readonly at: IsoDate;
|
|
219
|
+
/** A newer release is an error when the release of the bundle is older than this count of days. The default is 365. */
|
|
220
|
+
readonly maxAgeDays?: number;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* This function compares each bundle with a Kiwix address to the newest release of the feed.
|
|
224
|
+
* - The feed has no file of the key: the error `not-in-feed`.
|
|
225
|
+
* - The feed has a newer release: the warning `newer-release`, or the error `old-release` when the bundle is older than `maxAgeDays`.
|
|
226
|
+
* - The bundle has no SHA-256: the warning `no-hash`.
|
|
227
|
+
* - A bundle with an address that is not a ZIM release gets the warning `not-kiwix`.
|
|
228
|
+
*/
|
|
229
|
+
export declare function checkReleases(bundles: readonly Bundle[], entries: readonly KiwixEntry[], options: ReleaseOptions): readonly ReleaseFinding[];
|
|
230
|
+
/** A medium that a copy can go on, with its price and its rate of loss. The offers are input data of the caller. */
|
|
231
|
+
interface MediumOffer {
|
|
232
|
+
readonly id: string;
|
|
233
|
+
readonly kind: MediumKind;
|
|
234
|
+
/** The capacity of one medium in bytes. */
|
|
235
|
+
readonly bytes: number;
|
|
236
|
+
/** The price of one medium, in the currency of the plan. */
|
|
237
|
+
readonly price: number;
|
|
238
|
+
/** The years of use of one medium. The cost of a month is `price / (lifeYears × 12)`. */
|
|
239
|
+
readonly lifeYears: number;
|
|
240
|
+
/** The chance from 0 to 1 that a copy on the medium cannot be read after one year, for example an annual failure rate. */
|
|
241
|
+
readonly yearlyLoss: number;
|
|
242
|
+
/** The source of `yearlyLoss`. */
|
|
243
|
+
readonly source: string;
|
|
244
|
+
}
|
|
245
|
+
/** A place that holds copies, with its rate of loss. The places are input data of the caller. */
|
|
246
|
+
interface CopyPlace {
|
|
247
|
+
readonly id: string;
|
|
248
|
+
/** The chance from 0 to 1 that the place loses all its copies in one year, for example by fire, flood or theft. */
|
|
249
|
+
readonly yearlyLoss: number;
|
|
250
|
+
/** The source of `yearlyLoss`. */
|
|
251
|
+
readonly source: string;
|
|
252
|
+
/** The cost of a month of the place, for example the rent of a box. The default is 0. */
|
|
253
|
+
readonly monthly?: number;
|
|
254
|
+
}
|
|
255
|
+
/** A shared cause of loss of all the copies on one kind of medium, for example a format that no reader can read. */
|
|
256
|
+
interface KindLoss {
|
|
257
|
+
readonly kind: MediumKind;
|
|
258
|
+
readonly yearlyLoss: number;
|
|
259
|
+
readonly source: string;
|
|
260
|
+
}
|
|
261
|
+
/** The input of `copiesLayer`. */
|
|
262
|
+
interface CopiesInput {
|
|
263
|
+
/** The copy rule of the level. The slots, the counts of kinds and places, and the period of the chance come from it. */
|
|
264
|
+
readonly rule: CopyRule;
|
|
265
|
+
/** The bytes of the bundles of the level, for example from `bytesOf`. An offer with less capacity is not a candidate. */
|
|
266
|
+
readonly bytes: number;
|
|
267
|
+
readonly offers: readonly MediumOffer[];
|
|
268
|
+
readonly places: readonly CopyPlace[];
|
|
269
|
+
/** The shared losses of the kinds. A kind with no record has no shared loss. */
|
|
270
|
+
readonly kindLosses?: readonly KindLoss[];
|
|
271
|
+
/** The count of optional slots after the `rule.copies` slots. The default is 1. */
|
|
272
|
+
readonly extra?: number;
|
|
273
|
+
/** The currency of the prices. */
|
|
274
|
+
readonly currency: string;
|
|
275
|
+
/** The largest cost of a month, and the smallest chance. */
|
|
276
|
+
readonly limits?: {
|
|
277
|
+
readonly cost?: number;
|
|
278
|
+
readonly chance?: number;
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/** The layer and the base stack of a plan of copies. */
|
|
282
|
+
interface CopiesQuery {
|
|
283
|
+
readonly layer: PlacementLayer;
|
|
284
|
+
readonly base: Stack;
|
|
285
|
+
}
|
|
286
|
+
/** The part of a placed stack that works when one copy of the level or more can be read. */
|
|
287
|
+
export declare const libraryPartOf: (level: string) => string;
|
|
288
|
+
/** This function gives the chance that a thing with a yearly loss still works after `days` days. */
|
|
289
|
+
export declare function keepChance(yearlyLoss: number, days: number): number;
|
|
290
|
+
/**
|
|
291
|
+
* This function gives the placement layer and the base stack of the copies of one level.
|
|
292
|
+
* The chance of a choice is the chance that one copy or more can be read after one period `rule.everyDays`. A check then repairs each loss.
|
|
293
|
+
* It throws a `RangeError` when no offer can hold the bytes, or when the input has no place.
|
|
294
|
+
*/
|
|
295
|
+
export declare function copiesLayer(input: CopiesInput): CopiesQuery;
|
|
296
|
+
/** The options of `planCopies`. */
|
|
297
|
+
interface PlanCopiesOptions {
|
|
298
|
+
/** The date of the plan, for the risk add-on. */
|
|
299
|
+
readonly today: string;
|
|
300
|
+
/** The count of evaluations of a seeded search of a large space. */
|
|
301
|
+
readonly evaluations?: number;
|
|
302
|
+
readonly seed?: number | string;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* This function gives the front of the plans of copies. No other plan is better on the cost of a month and on the chance.
|
|
306
|
+
* A plan with fewer places or fewer kinds than the rule gets the break `measure`, so it is not on the front.
|
|
307
|
+
*/
|
|
308
|
+
export declare function planCopies(query: CopiesQuery, rule: CopyRule, options: PlanCopiesOptions): PlacementPlan;
|
|
309
|
+
export type { Bundle, CatalogOptions, CopiesInput, CopiesOptions, CopiesQuery, Copy, CopyPlace, CopyRule, CopyState, CopyStates, CopyStatus, DueCheck, FeedQuery, GapCode, GapFinding, KindLoss, KiwixEntry, LibraryCode, LibraryFinding, MediumKind, MediumOffer, Meta4, PlanCopiesOptions, ReleaseCode, ReleaseFinding, ReleaseOptions };
|
|
310
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/records.ts","../src/check.ts","../src/copies.ts","../src/kiwix.ts","../src/placement.ts"],"mappings":";;;;qBAKa;;KAGD,qBAAqB;;;;;UAMhB;WACN;WACA;;WAEA;WACA,SAAS;;WAET;;WAEA,QAAQ;;WAER;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;WACA,MAAM;;WAEN;;WAEA,SAAS;;WAET;;WAEA;;;UAIM;WACN;;WAEA;;WAEA;;WAEA;;WAEA;;;qBCnDE;;KAkBD,sBAAsB;;KAGtB,iBAAiB,QAAQ;;UAGpB,uBAAuB;;WAE7B,mBAAmB;;WAEnB,iBAAiB;;;;;;;wBAcZ,aAAa,kBAAkB,UAAU,UAAS,0BAA+B;;UA2BhF;;WAEN;;;wBAIK,YAAY,iBAAiB,QAAQ,kBAAkB,UAAU,UAAS,yBAA8B;;qBC3E3G;;KAGD,kBAAkB;;KAGlB,aAAa,QAAQ;;;;;;;;KASrB;;UAGK;WACN;WACA;;WAEA,MAAM;WACN;aAA4B,MAAM;aAAe,QAAQ;;;WAEzD;;WAEA,gBAAgB;;WAEhB;;WAEA;;;UAIM;WACN,iBAAiB;WACjB,mBAAmB;;;;;;;wBAiBd,WAAW,kBAAkB,UAAU,iBAAiB,QAAQ,gBAAgB,YAAY;WAAoB,IAAI;IAAY;;UAyC/H;WACN;WACA;WACA;;WAEA,KAAK;;;;;;wBAOA,UAAU,kBAAkB,UAAU,iBAAiB,QAAQ,gBAAgB,YAAY;WAAoB,IAAI;WAAkB;aAAiC;;wBAgBtK,QAAQ,kBAAkB,UAAU;;qBC1HvC;;UAGI;;WAEN;WACA;;WAEA;WACA;;WAEA;;WAEA,QAAQ;;WAER;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;;wBAIK,aAAa,QAAO;;wBAYpB,WAAW;WAA+B;WAAsB;;;;;;wBAiChE,eAAe,uBAAuB;;wBAwBtC,WAAW,cAAc;;wBAezB,eAAe,kBAAkB,eAAe,oBAAoB;;wBAUpE,SAAS;;;;;wBAQT,YAAY,QAAQ,QAAQ,OAAO,YAAY,OAAO,QAAQ;;qBASjE;;KAGD,sBAAsB;;KAGtB,iBAAiB,QAAQ;;UAGpB;;WAEN,IAAI;;WAEJ;;;;;;;;;wBAUK,cAAc,kBAAkB,UAAU,kBAAkB,cAAc,SAAS,0BAA0B;;UC5K5G;WACN;WACA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;WACN;;WAEA;;WAEA;;WAEA;;;UAIM;WACN,MAAM;WACN;WACA;;;UAIM;;WAEN,MAAM;;WAEN;WACA,iBAAiB;WACjB,iBAAiB;;WAEjB,sBAAsB;;WAEtB;;WAEA;;WAEA;aAAoB;aAAwB;;;;UAItC;WACN,OAAO;WACP,MAAM;;;qBAIJ,gBAAiB;;wBAMd,WAAW,oBAAoB;;;;;;wBAgB/B,YAAY,OAAO,cAAc;;UAkDhC;;WAEN;;WAEA;WACA;;;;;;wBAOK,WAAW,OAAO,aAAa,MAAM,UAAU,SAAS,oBAAoB"}
|