@mark1russell7/guidebook-library 0.2.1 → 0.2.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/build/index.d.ts.map +1 -1
- package/build/index.js +3 -4
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/src/check.ts +3 -4
package/build/index.d.ts.map
CHANGED
|
@@ -1 +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;;;;;;UAOM;WACN;WACA;;WAEA,QAAQ;;WAER;;;;;;UAOM;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;WACA,MAAM;;WAEN;;WAEA,SAAS;;WAET;;WAEA;;WAEA,OAAO;;WAEP,UAAU;;;UAIJ;WACN;;WAEA;;WAEA;;WAEA;;WAEA;;;qBCjFE;;KAmBD,sBAAsB;;KAGtB,iBAAiB,QAAQ;;UAGpB,uBAAuB;;WAE7B,mBAAmB;;WAEnB,iBAAiB;;;;;;;
|
|
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;;;;;;UAOM;WACN;WACA;;WAEA,QAAQ;;WAER;;;;;;UAOM;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;WACA,MAAM;;WAEN;;WAEA,SAAS;;WAET;;WAEA;;WAEA,OAAO;;WAEP,UAAU;;;UAIJ;WACN;;WAEA;;WAEA;;WAEA;;WAEA;;;qBCjFE;;KAmBD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B;;UC5K5G;WACN;WACA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA,OAAO;;;UAID;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;;;;;;wBAUd,WAAW,MAAM,YAAY;;wBAa7B,WAAW,oBAAoB;;;;;;wBAgB/B,YAAY,OAAO,cAAc;;UAkDhC;;WAEN;;WAEA;WACA;;;;;;wBAOK,WAAW,OAAO,aAAa,MAAM,UAAU,SAAS,oBAAoB"}
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DAY_MS, LICENSES, isWebAddress, permits, timeOf } from "@mark1russell7/guidebook";
|
|
1
|
+
import { DAY_MS, LICENSES, isSha256, isWebAddress, permits, timeOf } from "@mark1russell7/guidebook";
|
|
2
2
|
import { decodeReferences } from "@mark1russell7/text/references";
|
|
3
3
|
import { PLACEMENT_SCHEMA, planPlacement } from "@mark1russell7/stack-placement";
|
|
4
4
|
import { RISK_SCHEMA, worksChance } from "@mark1russell7/stack-risk";
|
|
@@ -32,7 +32,6 @@ const LIBRARY_CODES = [
|
|
|
32
32
|
"duplicate-copy",
|
|
33
33
|
"bad-life"
|
|
34
34
|
];
|
|
35
|
-
const SHA256 = /^[0-9a-f]{64}$/;
|
|
36
35
|
function isLicense(value) {
|
|
37
36
|
return typeof value === "string" && LICENSES.includes(value);
|
|
38
37
|
}
|
|
@@ -60,7 +59,7 @@ function checkCatalog(bundles, options = {}) {
|
|
|
60
59
|
seen.add(bundle.id);
|
|
61
60
|
if (bundle.title.trim() === "") error("empty-title", bundle.id, `The bundle "${bundle.id}" has no title.`);
|
|
62
61
|
if (!Number.isSafeInteger(bundle.bytes) || bundle.bytes <= 0) error("bad-bytes", bundle.id, `The bundle "${bundle.id}" has the size ${bundle.bytes}. It needs a whole number of bytes more than 0.`);
|
|
63
|
-
if (bundle.sha256 !== void 0 && !
|
|
62
|
+
if (bundle.sha256 !== void 0 && !isSha256(bundle.sha256)) error("bad-sha256", bundle.id, `The bundle "${bundle.id}" has a SHA-256 that is not 64 lower-case hexadecimal digits.`);
|
|
64
63
|
if (bundle.url !== void 0 && !isWebAddress(bundle.url)) error("bad-url", bundle.id, `The bundle "${bundle.id}" has the address "${bundle.url}". It needs an address with https: or http:.`);
|
|
65
64
|
if (!isLicense(bundle.license)) error("unknown-license", bundle.id, `The bundle "${bundle.id}" has the unknown license "${String(bundle.license)}".`);
|
|
66
65
|
else if (!permits(bundle.license, "bundle", options)) error("use-refused", bundle.id, `The license "${bundle.license}" of the bundle "${bundle.id}" does not permit an offline bundle in this guidebook.`);
|
|
@@ -114,7 +113,7 @@ function checkCopies(copies, bundles, options = {}) {
|
|
|
114
113
|
seen.add(id);
|
|
115
114
|
if (!known.has(copy.bundle)) error("missing-bundle", `The copy "${id}" names the unknown bundle "${copy.bundle}".`);
|
|
116
115
|
if (!MEDIUM_KINDS.includes(copy.kind)) error("bad-kind", `The copy "${id}" has the unknown kind "${String(copy.kind)}".`);
|
|
117
|
-
if (copy.sha256 !== void 0 && !
|
|
116
|
+
if (copy.sha256 !== void 0 && !isSha256(copy.sha256)) error("bad-sha256", `The copy "${id}" has a SHA-256 that is not 64 lower-case hexadecimal digits.`);
|
|
118
117
|
const checked = timeOf(copy.checked);
|
|
119
118
|
if (checked === void 0) error("bad-date", `The copy "${id}" has the check date "${copy.checked}". It needs a date YYYY-MM-DD.`);
|
|
120
119
|
else if (at !== void 0 && checked > at) error("checked-in-future", `The copy "${id}" has a check date after the date of the check.`);
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/records.ts","../src/check.ts","../src/date.ts","../src/copies.ts","../src/kiwix.ts","../src/placement.ts"],"sourcesContent":["// The records of the library add-on: an offline bundle, a copy of a bundle on one medium, and the copy rule of a level.\n\nimport type { IsoDate, License, SourceId } from \"@mark1russell7/guidebook\";\n\n/** The kinds of media that hold a copy. */\nexport const MEDIUM_KINDS = [\"flash\", \"ssd\", \"hdd\", \"optical\", \"paper\"] as const;\n\n/** A kind of medium. */\nexport type MediumKind = (typeof MEDIUM_KINDS)[number];\n\n/**\n * An offline bundle: one file that holds a full source, for example a Kiwix ZIM file.\n * The `level` names a rule of the caller, so the add-on names no topic.\n */\nexport interface Bundle {\n readonly id: string;\n readonly title: string;\n /** The size of the file in bytes. */\n readonly bytes: number;\n readonly license: License;\n /** The level of the most important content of the bundle. A copy rule of the caller gives the copies of each level. */\n readonly level: string;\n /** The `id` of the source of the bundle in the sources of the core. */\n readonly source: SourceId;\n /** The release of the file, for example `2026-10`. */\n readonly version?: string;\n /** The SHA-256 of the file, as 64 lower-case hexadecimal digits. */\n readonly sha256?: string;\n /** The address of the file, with `https:` or `http:`. */\n readonly url?: string;\n}\n\n/**\n * A link of the catalog: a source with no file in the catalog, for example a source whose license permits only a link.\n * A household gets its own copy from the address, for example a book that it buys from the publisher.\n */\nexport interface Link {\n readonly id: string;\n readonly title: string;\n /** The `id` of the source of the link in the sources of the core. */\n readonly source: SourceId;\n /** The address of the page, with `https:` or `http:`. */\n readonly url: string;\n}\n\n/**\n * The life of a medium at a quantile, for example the time to 5% failure of a disc.\n * A medium younger than `years` fails with a chance of `quantile` or less. Past `years`, the life gives no bound.\n */\nexport interface MediumLife {\n /** The age in years at which the fraction `quantile` of the media fails. */\n readonly years: number;\n /** The fraction from 0 to 1 of the media that fails by the age `years`, for example 0.05. */\n readonly quantile: number;\n /** The source of the life, with its conditions, for example a temperature and a humidity. */\n readonly source: string;\n}\n\n/** A copy of a bundle on one medium. Where each copy goes is a query of the caller, for example of `stack-placement`. */\nexport interface Copy {\n /** The `id` of the bundle. */\n readonly bundle: string;\n /** The `id` of the medium, for example the label on a drive. */\n readonly medium: string;\n readonly kind: MediumKind;\n /** The `id` of the place of the medium. The places are input data of the caller. */\n readonly place: string;\n /** The date of the last read of the full copy against its hash. */\n readonly checked: IsoDate;\n /** The release of the bundle on the medium. */\n readonly version?: string;\n /** The SHA-256 that the last check read from the copy. */\n readonly sha256?: string;\n /** The life of the medium. A copy older than the life does not count. */\n readonly life?: MediumLife;\n /** The date on which the medium was written. A copy with a `life` needs it, because its age comes from it. */\n readonly written?: IsoDate;\n}\n\n/** The copies that a level needs. */\nexport interface CopyRule {\n readonly level: string;\n /** The smallest count of good copies. */\n readonly copies: number;\n /** The smallest count of different kinds of media among the good copies. */\n readonly kinds: number;\n /** The smallest count of different places among the good copies. */\n readonly places: number;\n /** A copy is good for this number of days after its last check. */\n readonly everyDays: number;\n}\n","// The catalog gate: the checks of the bundles and of their copies.\n\nimport { LICENSES, isWebAddress, permits, timeOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, License, Source, UseContext } from \"@mark1russell7/guidebook\";\nimport { MEDIUM_KINDS } from \"./records.ts\";\nimport type { Bundle, Copy, CopyRule, Link } from \"./records.ts\";\n\n/** The codes of the findings of the catalog gate. */\nexport const LIBRARY_CODES = [\n \"duplicate-id\",\n \"empty-title\",\n \"bad-bytes\",\n \"bad-sha256\",\n \"bad-url\",\n \"unknown-license\",\n \"missing-source\",\n \"unknown-level\",\n \"use-refused\",\n \"missing-bundle\",\n \"bad-kind\",\n \"bad-date\",\n \"checked-in-future\",\n \"duplicate-copy\",\n \"bad-life\",\n] as const;\n\n/** A code of a finding of the catalog gate. */\nexport type LibraryCode = (typeof LIBRARY_CODES)[number];\n\n/** A finding of the catalog gate, on a bundle or on a copy. */\nexport type LibraryFinding = Finding<LibraryCode, \"bundle\" | \"copy\" | \"link\">;\n\n/** The options of the catalog gate. */\nexport interface CatalogOptions extends UseContext {\n /** The sources of the core. With them, a bundle must name a known source. */\n readonly sources?: readonly Source[];\n /** The copy rules. With them, a bundle must name the level of a rule. */\n readonly rules?: readonly CopyRule[];\n}\n\nconst SHA256 = /^[0-9a-f]{64}$/;\n\nfunction isLicense(value: unknown): value is License {\n return typeof value === \"string\" && (LICENSES as readonly string[]).includes(value);\n}\n\n/**\n * This function gives the findings of the bundles of a catalog.\n * A bundle must have a unique id, a title, a whole positive size and a license that permits a bundle.\n * Its hash and its address must be correct when it has them.\n */\nexport function checkCatalog(bundles: readonly Bundle[], options: CatalogOptions = {}): readonly LibraryFinding[] {\n const out: LibraryFinding[] = [];\n const error = (code: LibraryCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"bundle\", id, message });\n };\n const sources = options.sources === undefined ? undefined : new Set(options.sources.map((source) => source.id));\n const levels = options.rules === undefined ? undefined : new Set(options.rules.map((rule) => rule.level));\n const seen = new Set<string>();\n for (const bundle of bundles) {\n if (seen.has(bundle.id)) error(\"duplicate-id\", bundle.id, `Two bundles have the id \"${bundle.id}\".`);\n seen.add(bundle.id);\n if (bundle.title.trim() === \"\") error(\"empty-title\", bundle.id, `The bundle \"${bundle.id}\" has no title.`);\n if (!Number.isSafeInteger(bundle.bytes) || bundle.bytes <= 0) error(\"bad-bytes\", bundle.id, `The bundle \"${bundle.id}\" has the size ${bundle.bytes}. It needs a whole number of bytes more than 0.`);\n if (bundle.sha256 !== undefined && !SHA256.test(bundle.sha256)) error(\"bad-sha256\", bundle.id, `The bundle \"${bundle.id}\" has a SHA-256 that is not 64 lower-case hexadecimal digits.`);\n if (bundle.url !== undefined && !isWebAddress(bundle.url)) error(\"bad-url\", bundle.id, `The bundle \"${bundle.id}\" has the address \"${bundle.url}\". It needs an address with https: or http:.`);\n if (!isLicense(bundle.license)) {\n error(\"unknown-license\", bundle.id, `The bundle \"${bundle.id}\" has the unknown license \"${String(bundle.license)}\".`);\n } else if (!permits(bundle.license, \"bundle\", options)) {\n error(\"use-refused\", bundle.id, `The license \"${bundle.license}\" of the bundle \"${bundle.id}\" does not permit an offline bundle in this guidebook.`);\n }\n if (sources !== undefined && !sources.has(bundle.source)) error(\"missing-source\", bundle.id, `The bundle \"${bundle.id}\" names the unknown source \"${bundle.source}\".`);\n if (levels !== undefined && !levels.has(bundle.level)) error(\"unknown-level\", bundle.id, `The bundle \"${bundle.id}\" has the level \"${bundle.level}\", and no copy rule has it.`);\n }\n return out;\n}\n\n/** The options of the check of the links. */\nexport interface LinksOptions {\n /** The sources of the core. With them, a link must name a known source. */\n readonly sources?: readonly Source[];\n}\n\n/** This function gives the findings of the links of a catalog: a duplicate id, an empty title, a bad address and an unknown source. */\nexport function checkLinks(links: readonly Link[], options: LinksOptions = {}): readonly LibraryFinding[] {\n const out: LibraryFinding[] = [];\n const error = (code: LibraryCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"link\", id, message });\n };\n const sources = options.sources === undefined ? undefined : new Set(options.sources.map((source) => source.id));\n const seen = new Set<string>();\n for (const link of links) {\n if (seen.has(link.id)) error(\"duplicate-id\", link.id, `Two links have the id \"${link.id}\".`);\n seen.add(link.id);\n if (link.title.trim() === \"\") error(\"empty-title\", link.id, `The link \"${link.id}\" has no title.`);\n if (!isWebAddress(link.url)) error(\"bad-url\", link.id, `The link \"${link.id}\" has the address \"${link.url}\". It needs an address with https: or http:.`);\n if (sources !== undefined && !sources.has(link.source)) error(\"missing-source\", link.id, `The link \"${link.id}\" names the unknown source \"${link.source}\".`);\n }\n return out;\n}\n\n/** The options of the check of the copies. */\nexport interface CopiesOptions {\n /** The date of the check. With it, a copy with a later check date is an error. */\n readonly at?: string;\n}\n\n/** This function gives the findings of the copies: an unknown bundle or kind, a bad date, and two records of one copy. */\nexport function checkCopies(copies: readonly Copy[], bundles: readonly Bundle[], options: CopiesOptions = {}): readonly LibraryFinding[] {\n const out: LibraryFinding[] = [];\n const at = options.at === undefined ? undefined : timeOf(options.at);\n if (options.at !== undefined && at === undefined) throw new RangeError(`checkCopies: the date \"${options.at}\" of the check is not a date YYYY-MM-DD.`);\n const known = new Set(bundles.map((bundle) => bundle.id));\n const seen = new Set<string>();\n for (const copy of copies) {\n const id = `${copy.bundle}@${copy.medium}`;\n const error = (code: LibraryCode, message: string): void => {\n out.push({ level: \"error\", code, record: \"copy\", id, message });\n };\n if (seen.has(id)) error(\"duplicate-copy\", `Two records give the copy of \"${copy.bundle}\" on the medium \"${copy.medium}\".`);\n seen.add(id);\n if (!known.has(copy.bundle)) error(\"missing-bundle\", `The copy \"${id}\" names the unknown bundle \"${copy.bundle}\".`);\n if (!(MEDIUM_KINDS as readonly string[]).includes(copy.kind)) error(\"bad-kind\", `The copy \"${id}\" has the unknown kind \"${String(copy.kind)}\".`);\n if (copy.sha256 !== undefined && !SHA256.test(copy.sha256)) error(\"bad-sha256\", `The copy \"${id}\" has a SHA-256 that is not 64 lower-case hexadecimal digits.`);\n const checked = timeOf(copy.checked);\n if (checked === undefined) error(\"bad-date\", `The copy \"${id}\" has the check date \"${copy.checked}\". It needs a date YYYY-MM-DD.`);\n else if (at !== undefined && checked > at) error(\"checked-in-future\", `The copy \"${id}\" has a check date after the date of the check.`);\n if (copy.written !== undefined) {\n const written = timeOf(copy.written);\n if (written === undefined) error(\"bad-date\", `The copy \"${id}\" has the date of writing \"${copy.written}\". It needs a date YYYY-MM-DD.`);\n else if (at !== undefined && written > at) error(\"checked-in-future\", `The copy \"${id}\" has a date of writing after the date of the check.`);\n }\n const life = copy.life;\n if (life !== undefined && !(life.years > 0 && life.quantile >= 0 && life.quantile <= 1 && life.source.trim() !== \"\")) {\n error(\"bad-life\", `The copy \"${id}\" has a life that is not more than 0 years, a quantile out of 0 to 1, or no source.`);\n }\n }\n return out;\n}\n","// The dates of the add-on. A date is `YYYY-MM-DD` in UTC, as in the core.\n\nimport { DAY_MS, timeOf } from \"@mark1russell7/guidebook\";\n\n/** This function gives the date `YYYY-MM-DD` that is `days` after the date `date`. */\nexport function addDays(date: string, days: number): string {\n const time = timeOf(date);\n if (time === undefined) throw new RangeError(`addDays: \"${date}\" is not a date YYYY-MM-DD.`);\n return new Date(time + days * DAY_MS).toISOString().slice(0, 10);\n}\n","// The state of the copies of each bundle, against the copy rule of its level, and the checks that are due.\n\nimport { DAY_MS, timeOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, IsoDate } from \"@mark1russell7/guidebook\";\nimport { addDays } from \"./date.ts\";\nimport type { Bundle, Copy, CopyRule, MediumKind } from \"./records.ts\";\n\n/** The codes of the copy gaps. */\nexport const GAP_CODES = [\"few-copies\", \"few-kinds\", \"few-places\", \"no-rule\", \"check-due\", \"bad-hash\", \"old-version\", \"past-life\", \"no-written-date\"] as const;\n\n/** A code of a copy gap. */\nexport type GapCode = (typeof GAP_CODES)[number];\n\n/** A copy gap: an error on a bundle with too few good copies, or a warning on one copy. */\nexport type GapFinding = Finding<GapCode, \"bundle\" | \"copy\">;\n\n/**\n * The status of one copy at a date.\n * - `good`: the copy had a check within the days of its rule, and its hash agrees with the bundle.\n * - `old`: as `good`, but the copy holds an earlier release of the bundle. It counts as a good copy.\n * - `due`: the last check is older than the days of the rule. The copy does not count until a new check.\n * - `bad`: the hash of the copy does not agree with the hash of the same release. Replace the copy.\n * - `aged`: the copy has a `life`, and it is older than the life, or its `written` date is not a date. Write a new copy.\n */\nexport type CopyStatus = \"good\" | \"old\" | \"due\" | \"bad\" | \"aged\";\n\n/** The state of the copies of one bundle. */\nexport interface CopyState {\n readonly bundle: string;\n readonly level: string;\n /** The rule of the level, or `undefined` when no rule has the level. */\n readonly rule: CopyRule | undefined;\n readonly copies: readonly { readonly copy: Copy; readonly status: CopyStatus }[];\n /** The count of good copies (the status `good` or `old`). */\n readonly good: number;\n /** The different kinds of media of the good copies. */\n readonly kinds: readonly MediumKind[];\n /** The different places of the good copies. */\n readonly places: readonly string[];\n /** This field is true when the good copies obey the rule. */\n readonly ok: boolean;\n}\n\n/** The result of `copyStates`. */\nexport interface CopyStates {\n readonly states: readonly CopyState[];\n readonly findings: readonly GapFinding[];\n}\n\nfunction statusOf(copy: Copy, bundle: Bundle, rule: CopyRule | undefined, at: number): CopyStatus {\n const sameRelease = bundle.version === undefined || copy.version === undefined || bundle.version === copy.version;\n if (sameRelease && bundle.sha256 !== undefined && copy.sha256 !== undefined && bundle.sha256 !== copy.sha256) return \"bad\";\n if (copy.life !== undefined) {\n const written = copy.written === undefined ? undefined : timeOf(copy.written);\n if (written === undefined || (at - written) / DAY_MS > copy.life.years * 365.25) return \"aged\";\n }\n const checked = timeOf(copy.checked);\n if (checked === undefined) return \"due\";\n if (rule !== undefined && (at - checked) / DAY_MS > rule.everyDays) return \"due\";\n return sameRelease ? \"good\" : \"old\";\n}\n\n/**\n * This function gives the state of the copies of each bundle at the date `at`, and the gaps.\n * A bundle with fewer good copies, kinds or places than the rule of its level gets an error.\n * A copy with a check that is due, a bad hash, an earlier release or an age past its life gets a warning.\n */\nexport function copyStates(bundles: readonly Bundle[], copies: readonly Copy[], rules: readonly CopyRule[], options: { readonly at: IsoDate }): CopyStates {\n const at = timeOf(options.at);\n if (at === undefined) throw new RangeError(`copyStates: the date \"${options.at}\" is not a date YYYY-MM-DD.`);\n const ruleOf = new Map(rules.map((rule) => [rule.level, rule]));\n const byBundle = new Map<string, Copy[]>();\n for (const copy of copies) {\n const list = byBundle.get(copy.bundle) ?? [];\n list.push(copy);\n byBundle.set(copy.bundle, list);\n }\n const states: CopyState[] = [];\n const findings: GapFinding[] = [];\n for (const bundle of bundles) {\n const rule = ruleOf.get(bundle.level);\n const rated = (byBundle.get(bundle.id) ?? []).map((copy) => ({ copy, status: statusOf(copy, bundle, rule, at) }));\n const good = rated.filter((item) => item.status === \"good\" || item.status === \"old\").map((item) => item.copy);\n const kinds = [...new Set(good.map((copy) => copy.kind))];\n const places = [...new Set(good.map((copy) => copy.place))];\n const bundleError = (code: GapCode, message: string): void => {\n findings.push({ level: \"error\", code, record: \"bundle\", id: bundle.id, message });\n };\n if (rule === undefined) {\n bundleError(\"no-rule\", `The bundle \"${bundle.id}\" has the level \"${bundle.level}\", and no copy rule has it.`);\n } else {\n if (good.length < rule.copies) bundleError(\"few-copies\", `The bundle \"${bundle.id}\" has ${good.length} good copies. Its level \"${rule.level}\" needs ${rule.copies}.`);\n if (kinds.length < rule.kinds) bundleError(\"few-kinds\", `The good copies of \"${bundle.id}\" are on ${kinds.length} kinds of media. Its level \"${rule.level}\" needs ${rule.kinds}.`);\n if (places.length < rule.places) bundleError(\"few-places\", `The good copies of \"${bundle.id}\" are in ${places.length} places. Its level \"${rule.level}\" needs ${rule.places}.`);\n }\n for (const { copy, status } of rated) {\n const id = `${copy.bundle}@${copy.medium}`;\n if (status === \"due\") findings.push({ level: \"warning\", code: \"check-due\", record: \"copy\", id, message: `Read the copy \"${id}\" against its hash. Its last check was on ${copy.checked}.` });\n if (status === \"bad\") findings.push({ level: \"warning\", code: \"bad-hash\", record: \"copy\", id, message: `The copy \"${id}\" does not agree with the hash of its release. Replace it.` });\n if (status === \"aged\") {\n const life = copy.life;\n const code: GapCode = copy.written === undefined || timeOf(copy.written) === undefined ? \"no-written-date\" : \"past-life\";\n const message = code === \"past-life\"\n ? `The copy \"${id}\" was written on ${copy.written ?? \"\"}. It is older than the life of its medium, ${life?.years ?? 0} years. Write a new copy.`\n : `The copy \"${id}\" has a life and no date of writing. Add the field \"written\", or write a new copy.`;\n findings.push({ level: \"warning\", code, record: \"copy\", id, message });\n }\n if (status === \"old\") findings.push({ level: \"warning\", code: \"old-version\", record: \"copy\", id, message: `The copy \"${id}\" holds the release \"${copy.version ?? \"\"}\". The catalog has \"${bundle.version ?? \"\"}\".` });\n }\n const ok = rule !== undefined && good.length >= rule.copies && kinds.length >= rule.kinds && places.length >= rule.places;\n states.push({ bundle: bundle.id, level: bundle.level, rule, copies: rated, good: good.length, kinds, places, ok });\n }\n return { states, findings };\n}\n\n/** A check of a copy that a schedule gives to a person or a job. */\nexport interface DueCheck {\n readonly bundle: string;\n readonly medium: string;\n readonly place: string;\n /** The last date on which the copy is good with no new check. */\n readonly due: IsoDate;\n}\n\n/**\n * This function gives the check of each copy whose due date is on or before `at` plus `withinDays`, the first due first.\n * A copy of a bundle with no rule, or of an unknown bundle, gets no check.\n */\nexport function checksDue(bundles: readonly Bundle[], copies: readonly Copy[], rules: readonly CopyRule[], options: { readonly at: IsoDate; readonly withinDays?: number }): readonly DueCheck[] {\n const limit = addDays(options.at, options.withinDays ?? 0);\n const levelOf = new Map(bundles.map((bundle) => [bundle.id, bundle.level]));\n const ruleOf = new Map(rules.map((rule) => [rule.level, rule]));\n const out: DueCheck[] = [];\n for (const copy of copies) {\n const level = levelOf.get(copy.bundle);\n const rule = level === undefined ? undefined : ruleOf.get(level);\n if (rule === undefined) continue;\n const due = timeOf(copy.checked) === undefined ? options.at : addDays(copy.checked, rule.everyDays);\n if (due <= limit) out.push({ bundle: copy.bundle, medium: copy.medium, place: copy.place, due });\n }\n return out.sort((a, b) => (a.due < b.due ? -1 : a.due > b.due ? 1 : a.bundle < b.bundle ? -1 : a.bundle > b.bundle ? 1 : a.medium < b.medium ? -1 : a.medium > b.medium ? 1 : 0));\n}\n\n/** This function gives the bytes that are necessary on one medium for each bundle of a list. */\nexport function bytesOf(bundles: readonly Bundle[], ids: readonly string[]): number {\n const sizeOf = new Map(bundles.map((bundle) => [bundle.id, bundle.bytes]));\n let total = 0;\n for (const id of new Set(ids)) {\n const bytes = sizeOf.get(id);\n if (bytes === undefined) throw new RangeError(`bytesOf: the bundle \"${id}\" is not in the catalog.`);\n total += bytes;\n }\n return total;\n}\n","// The Kiwix catalog: its OPDS feed of ZIM files, the Metalink file (`.meta4`) of each release, and the release gate.\n// The functions are pure. The caller fetches the feed and the `.meta4` files, for example with `polite-crawler/api`.\n\nimport type { Finding, IsoDate } from \"@mark1russell7/guidebook\";\nimport { DAY_MS, timeOf } from \"@mark1russell7/guidebook\";\nimport { decodeReferences } from \"@mark1russell7/text/references\";\nimport type { Bundle } from \"./records.ts\";\n\n/** The address of the OPDS catalog of Kiwix. */\nexport const KIWIX_CATALOG = \"https://opds.library.kiwix.org/catalog/v2\";\n\n/** One ZIM file of the OPDS feed of Kiwix. */\nexport interface KiwixEntry {\n /** The key of the file: its name with its flavour, for example `wikipedia_en_medicine_nopic`. */\n readonly key: string;\n readonly name: string;\n /** The flavour of the file, for example `nopic`, or an empty text. */\n readonly flavour: string;\n readonly title: string;\n /** The release of the file, `YYYY-MM`. */\n readonly release: string;\n /** The date of the release. */\n readonly issued: IsoDate;\n /** The address of the `.meta4` file of the release. */\n readonly meta4: string;\n /** The size that the feed gives. The feed rounds it up to whole KiB, so `parseMeta4` gives the exact size. */\n readonly approxBytes: number;\n}\n\n/** The facts of one file in a `.meta4` file. */\nexport interface Meta4 {\n /** The name of the file, for example `wikipedia_en_medicine_nopic_2026-10.zim`. */\n readonly file: string;\n /** The exact size of the file in bytes. */\n readonly bytes: number;\n /** The SHA-256 of the file, as 64 lower-case hexadecimal digits. */\n readonly sha256: string;\n}\n\n/** The options of `kiwixFeedUrl`. */\nexport interface FeedQuery {\n /** The ISO 639-3 code of the language, for example `eng`. */\n readonly lang?: string;\n /** The name of a file, for example `wikipedia_en_medicine`. */\n readonly name?: string;\n /** The largest count of entries. The default is 2000. */\n readonly count?: number;\n /** The address of the catalog. The default is `KIWIX_CATALOG`. */\n readonly catalog?: string;\n}\n\n/** This function gives the address of the OPDS feed of the entries that agree with the query. */\nexport function kiwixFeedUrl(query: FeedQuery = {}): string {\n const params: [string, string][] = [];\n if (query.lang !== undefined) params.push([\"lang\", query.lang]);\n if (query.name !== undefined) params.push([\"name\", query.name]);\n params.push([\"count\", String(query.count ?? 2000)]);\n const search = params.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join(\"&\");\n return `${query.catalog ?? KIWIX_CATALOG}/entries?${search}`;\n}\n\nconst FILE = /^([a-z0-9._-]+?)_(\\d{4}-\\d{2})\\.zim$/u;\n\n/** This function gives the key and the release of a ZIM file from its name or its address, or `undefined` for another file. */\nexport function kiwixKeyOf(fileOrUrl: string): { readonly key: string; readonly release: string } | undefined {\n const file = fileOrUrl.split(/[?#]/u)[0]?.split(\"/\").at(-1)?.replace(/\\.meta4$/u, \"\") ?? \"\";\n const match = FILE.exec(file);\n return match === null ? undefined : { key: match[1] ?? \"\", release: match[2] ?? \"\" };\n}\n\nfunction textOf(xml: string, tag: string): string | undefined {\n const match = new RegExp(`<${tag}(?:\\\\s[^>]*)?>([^<]*)</${tag}>`, \"u\").exec(xml);\n return match === null ? undefined : decodeReferences(match[1] ?? \"\").trim();\n}\n\n/** This function gives each start tag of the element `name` in the XML, with a scan that is linear in the length of the XML. */\nfunction tagsOf(xml: string, name: string): string[] {\n const out: string[] = [];\n for (let start = xml.indexOf(`<${name}`); start >= 0; start = xml.indexOf(`<${name}`, start + 1)) {\n const end = xml.indexOf(\">\", start);\n if (end < 0) break;\n out.push(xml.slice(start, end + 1));\n }\n return out;\n}\n\nconst OPEN_ACCESS = 'rel=\"http://opds-spec.org/acquisition/open-access\"';\n\nfunction attributeOf(tag: string, name: string): string | undefined {\n const match = new RegExp(`\\\\s${name}=\"([^\"]*)\"`, \"u\").exec(tag);\n return match === null ? undefined : decodeReferences(match[1] ?? \"\");\n}\n\n/**\n * This function gives the entries of an OPDS feed of Kiwix.\n * An entry with no open-access link to a `.meta4` file of a ZIM release is not in the result.\n */\nexport function parseKiwixFeed(xml: string): readonly KiwixEntry[] {\n const out: KiwixEntry[] = [];\n for (const part of xml.split(\"<entry>\").slice(1)) {\n const entry = part.split(\"</entry>\")[0] ?? \"\";\n const link = tagsOf(entry, \"link \").find((tag) => tag.includes(OPEN_ACCESS));\n const meta4 = link === undefined ? undefined : attributeOf(link, \"href\");\n const file = meta4 === undefined ? undefined : kiwixKeyOf(meta4);\n if (link === undefined || meta4 === undefined || file === undefined) continue;\n const issued = (textOf(entry, \"dc:issued\") ?? textOf(entry, \"updated\") ?? \"\").slice(0, 10);\n out.push({\n key: file.key,\n name: textOf(entry, \"name\") ?? \"\",\n flavour: textOf(entry, \"flavour\") ?? \"\",\n title: textOf(entry, \"title\") ?? \"\",\n release: file.release,\n issued,\n meta4,\n approxBytes: Number(attributeOf(link, \"length\") ?? \"0\"),\n });\n }\n return out;\n}\n\n/** 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. */\nexport function parseMeta4(xml: string): Meta4 {\n const tag = tagsOf(xml, \"file \")[0];\n const start = tag === undefined ? -1 : xml.indexOf(tag) + tag.length;\n const end = start < 0 ? -1 : xml.indexOf(\"</file>\", start);\n const block = end < 0 ? \"\" : xml.slice(start, end);\n const file = tag === undefined ? undefined : attributeOf(tag, \"name\");\n const bytes = Number(textOf(block, \"size\") ?? Number.NaN);\n const sha256 = /<hash\\s+type=\"sha-256\"\\s*>([0-9a-fA-F]{64})<\\/hash>/u.exec(block)?.[1]?.toLowerCase();\n if (file === undefined || file === \"\" || !Number.isSafeInteger(bytes) || bytes < 1 || sha256 === undefined) {\n throw new RangeError(\"parseMeta4: the file has no file name, no size or no SHA-256.\");\n }\n return { file, bytes, sha256 };\n}\n\n/** This function gives the newest release of each key of the entries. */\nexport function latestReleases(entries: readonly KiwixEntry[]): ReadonlyMap<string, KiwixEntry> {\n const out = new Map<string, KiwixEntry>();\n for (const entry of entries) {\n const known = out.get(entry.key);\n if (known === undefined || entry.release > known.release) out.set(entry.key, entry);\n }\n return out;\n}\n\n/** The address of the ZIM file of a `.meta4` address: the same address with no `.meta4`. */\nexport function zimUrlOf(meta4: string): string {\n return meta4.replace(/\\.meta4$/u, \"\");\n}\n\n/**\n * This function gives the bundle with the release of the entry: its version, its exact size, its SHA-256 and its address.\n * It throws a `RangeError` when the `.meta4` file is for a different file.\n */\nexport function withRelease(bundle: Bundle, entry: KiwixEntry, meta4: Meta4): Bundle {\n const file = kiwixKeyOf(meta4.file);\n if (file?.key !== entry.key || file.release !== entry.release) {\n throw new RangeError(`withRelease: the .meta4 file is for \"${meta4.file}\", not for ${entry.key} ${entry.release}.`);\n }\n return { ...bundle, version: entry.release, bytes: meta4.bytes, sha256: meta4.sha256, url: zimUrlOf(entry.meta4) };\n}\n\n/** The codes of the release gate. */\nexport const RELEASE_CODES = [\"not-kiwix\", \"not-in-feed\", \"newer-release\", \"old-release\", \"no-hash\"] as const;\n\n/** A code of the release gate. */\nexport type ReleaseCode = (typeof RELEASE_CODES)[number];\n\n/** A finding of the release gate. */\nexport type ReleaseFinding = Finding<ReleaseCode, \"bundle\">;\n\n/** The options of `checkReleases`. */\nexport interface ReleaseOptions {\n /** The date of the read of the feed. */\n readonly at: IsoDate;\n /** A newer release is an error when the release of the bundle is older than this count of days. The default is 365. */\n readonly maxAgeDays?: number;\n}\n\n/**\n * This function compares each bundle with a Kiwix address to the newest release of the feed.\n * - The feed has no file of the key: the error `not-in-feed`.\n * - The feed has a newer release: the warning `newer-release`, or the error `old-release` when the bundle is older than `maxAgeDays`.\n * - The bundle has no SHA-256: the warning `no-hash`.\n * - A bundle with an address that is not a ZIM release gets the warning `not-kiwix`.\n */\nexport function checkReleases(bundles: readonly Bundle[], entries: readonly KiwixEntry[], options: ReleaseOptions): readonly ReleaseFinding[] {\n const at = timeOf(options.at);\n if (at === undefined) throw new RangeError(`checkReleases: the date \"${options.at}\" is not a date YYYY-MM-DD.`);\n const maxAgeDays = options.maxAgeDays ?? 365;\n const latest = latestReleases(entries);\n const out: ReleaseFinding[] = [];\n const add = (level: \"error\" | \"warning\", code: ReleaseCode, id: string, message: string): void => {\n out.push({ level, code, record: \"bundle\", id, message });\n };\n for (const bundle of bundles) {\n if (bundle.url === undefined) continue;\n const file = kiwixKeyOf(bundle.url);\n if (file === undefined) {\n add(\"warning\", \"not-kiwix\", bundle.id, `The bundle \"${bundle.id}\" has the address \"${bundle.url}\". It is not a ZIM release of Kiwix.`);\n continue;\n }\n const entry = latest.get(file.key);\n if (entry === undefined) {\n add(\"error\", \"not-in-feed\", bundle.id, `The Kiwix feed has no file \"${file.key}\" of the bundle \"${bundle.id}\".`);\n } else if (entry.release > file.release) {\n const released = timeOf(`${file.release}-01`);\n const old = released !== undefined && (at - released) / DAY_MS > maxAgeDays;\n add(old ? \"error\" : \"warning\", old ? \"old-release\" : \"newer-release\", bundle.id, `The bundle \"${bundle.id}\" has the release ${file.release}. The Kiwix feed has ${entry.release}.`);\n }\n if (bundle.sha256 === undefined) add(\"warning\", \"no-hash\", bundle.id, `The bundle \"${bundle.id}\" has no SHA-256. Read it from the .meta4 file of its release.`);\n }\n return out;\n}\n","// The plan of the copies of one level as a query of `@mark1russell7/stack-placement`.\n// Each slot is one copy. Each candidate is one medium offer at one place. Each place and each kind of medium is a shared\n// fragment, so two copies at one place share the loss of that place. The chance comes from `worksChance` of `stack-risk`.\n\nimport type { Candidate, ChanceReading, PlacementLayer, PlacementPlan, Shared } from \"@mark1russell7/stack-placement\";\nimport { PLACEMENT_SCHEMA, planPlacement } from \"@mark1russell7/stack-placement\";\nimport { RISK_SCHEMA, worksChance } from \"@mark1russell7/stack-risk\";\nimport type { RiskLayer } from \"@mark1russell7/stack-risk\";\nimport { riskAddOn } from \"@mark1russell7/stack-risk/add-on\";\nimport type { Part, Stack } from \"@mark1russell7/system-stack\";\nimport { readLayer } from \"@mark1russell7/system-stack\";\nimport type { CopyRule, MediumKind, MediumLife } from \"./records.ts\";\n\n/** A medium that a copy can go on, with its price and its rate of loss. The offers are input data of the caller. */\nexport interface MediumOffer {\n readonly id: string;\n readonly kind: MediumKind;\n /** The capacity of one medium in bytes. */\n readonly bytes: number;\n /** The price of one medium, in the currency of the plan. */\n readonly price: number;\n /** The years of use of one medium. The cost of a month is `price / (lifeYears × 12)`. */\n readonly lifeYears: number;\n /** The chance from 0 to 1 that a copy on the medium cannot be read after one year, for example an annual failure rate. */\n readonly yearlyLoss: number;\n /** The source of `yearlyLoss`. */\n readonly source: string;\n /**\n * The life of the medium at a quantile. A medium that ages fails more frequently when it is old, so a yearly rate is not a safe bound.\n * With a life, the chance of a copy is the smaller of the two. A plan that keeps a medium past its life gets the chance 0.\n */\n readonly life?: MediumLife;\n}\n\n/** A place that holds copies, with its rate of loss. The places are input data of the caller. */\nexport interface CopyPlace {\n readonly id: string;\n /** The chance from 0 to 1 that the place loses all its copies in one year, for example by fire, flood or theft. */\n readonly yearlyLoss: number;\n /** The source of `yearlyLoss`. */\n readonly source: string;\n /** The cost of a month of the place, for example the rent of a box. The default is 0. */\n readonly monthly?: number;\n}\n\n/** A shared cause of loss of all the copies on one kind of medium, for example a format that no reader can read. */\nexport interface KindLoss {\n readonly kind: MediumKind;\n readonly yearlyLoss: number;\n readonly source: string;\n}\n\n/** The input of `copiesLayer`. */\nexport interface CopiesInput {\n /** The copy rule of the level. The slots, the counts of kinds and places, and the period of the chance come from it. */\n readonly rule: CopyRule;\n /** The bytes of the bundles of the level, for example from `bytesOf`. An offer with less capacity is not a candidate. */\n readonly bytes: number;\n readonly offers: readonly MediumOffer[];\n readonly places: readonly CopyPlace[];\n /** The shared losses of the kinds. A kind with no record has no shared loss. */\n readonly kindLosses?: readonly KindLoss[];\n /** The count of optional slots after the `rule.copies` slots. The default is 1. */\n readonly extra?: number;\n /** The currency of the prices. */\n readonly currency: string;\n /** The largest cost of a month, and the smallest chance. */\n readonly limits?: { readonly cost?: number; readonly chance?: number };\n}\n\n/** The layer and the base stack of a plan of copies. */\nexport interface CopiesQuery {\n readonly layer: PlacementLayer;\n readonly base: Stack;\n}\n\n/** The part of a placed stack that works when one copy of the level or more can be read. */\nexport const libraryPartOf = (level: string): string => `library:${level}`;\n\nconst placePartOf = (place: string): string => `place:${place}`;\nconst kindPartOf = (kind: MediumKind): string => `medium:${kind}`;\n\n/**\n * This function gives the chance that a medium with a life still works at the end of each period, from 0 to 1.\n * The medium is replaced after `useYears`. For each period that ends by the age `life.years`, the chance is `1 - life.quantile` or more.\n * The reason: the chance of the period is S(end) / S(start), and S(end) is S(life) or more. When `useYears` is more than `life.years`, the chance is 0.\n */\nexport function lifeChance(life: MediumLife, useYears: number): number {\n if (!(life.quantile >= 0 && life.quantile <= 1) || !(life.years > 0) || !(useYears > 0)) {\n throw new RangeError(`lifeChance: the life ${life.years} years at ${life.quantile}, or the use ${useYears} years, is out of range.`);\n }\n return useYears <= life.years ? 1 - life.quantile : 0;\n}\n\nconst offerChance = (offer: MediumOffer, days: number): number => {\n const rate = keepChance(offer.yearlyLoss, days);\n return offer.life === undefined ? rate : Math.min(rate, lifeChance(offer.life, offer.lifeYears));\n};\n\n/** This function gives the chance that a thing with a yearly loss still works after `days` days. */\nexport function keepChance(yearlyLoss: number, days: number): number {\n if (!(yearlyLoss >= 0 && yearlyLoss <= 1) || !(days >= 0)) throw new RangeError(`keepChance: the loss ${yearlyLoss} or the days ${days} is out of range.`);\n return (1 - yearlyLoss) ** (days / 365);\n}\n\nconst fragment = (part: Part, works: number, source: string): Stack => ({\n schema: \"stack/1\",\n parts: [part],\n layers: { [RISK_SCHEMA]: { schema: RISK_SCHEMA, goals: [], chances: [{ part: part.id, works, source }] } satisfies RiskLayer },\n});\n\n/**\n * This function gives the placement layer and the base stack of the copies of one level.\n * 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.\n * It throws a `RangeError` when no offer can hold the bytes, or when the input has no place.\n */\nexport function copiesLayer(input: CopiesInput): CopiesQuery {\n const { rule } = input;\n const days = rule.everyDays;\n const offers = input.offers.filter((offer) => offer.bytes >= input.bytes);\n if (offers.length === 0) throw new RangeError(`copiesLayer: no offer holds the ${input.bytes} bytes of the level \"${rule.level}\".`);\n if (input.places.length === 0) throw new RangeError(`copiesLayer: the level \"${rule.level}\" has no place.`);\n const count = Math.max(1, rule.copies) + (input.extra ?? 1);\n const slotIds = Array.from({ length: count }, (_, i) => `copy-${i + 1}`);\n const kinds = [...new Set(offers.map((offer) => offer.kind))];\n const losses = new Map((input.kindLosses ?? []).map((loss) => [loss.kind, loss]));\n const shared: Shared[] = [\n ...input.places.map((place) => ({\n id: placePartOf(place.id),\n stack: fragment({ id: placePartOf(place.id), kind: \"place\", name: place.id }, keepChance(place.yearlyLoss, days), place.source),\n cost: place.monthly ?? 0,\n })),\n ...kinds.map((kind) => {\n const loss = losses.get(kind);\n const works = loss === undefined ? 1 : keepChance(loss.yearlyLoss, days);\n return { id: kindPartOf(kind), stack: fragment({ id: kindPartOf(kind), kind: \"medium\", name: kind }, works, loss?.source ?? \"No shared loss of the kind is known.\") };\n }),\n ];\n const candidatesOf = (slot: string): Candidate[] =>\n offers.flatMap((offer) =>\n input.places.map((place) => ({\n key: `${offer.id}@${place.id}`,\n cost: offer.price / (offer.lifeYears * 12),\n uses: [placePartOf(place.id), kindPartOf(offer.kind)],\n source: offer.id,\n stack: fragment({ id: slot, kind: \"copy\", needs: [placePartOf(place.id), kindPartOf(offer.kind)] }, offerChance(offer, days), offer.life === undefined ? offer.source : `${offer.source} ${offer.life.source}`),\n })),\n );\n const part = libraryPartOf(rule.level);\n const layer: PlacementLayer = {\n schema: PLACEMENT_SCHEMA,\n part,\n currency: input.currency,\n slots: slotIds.map((id, i) => ({ id, candidates: candidatesOf(id), optional: i >= rule.copies })),\n shared,\n ...(input.limits === undefined ? {} : { limits: input.limits }),\n };\n const base: Stack = {\n schema: \"stack/1\",\n parts: [{ id: part, kind: \"function\", needs: [{ any: slotIds }] }],\n layers: { [RISK_SCHEMA]: { schema: RISK_SCHEMA, goals: [], chances: [{ part, works: 1, source: \"The level works when one copy or more can be read.\" }] } satisfies RiskLayer },\n };\n return { layer, base };\n}\n\n/** The options of `planCopies`. */\nexport interface PlanCopiesOptions {\n /** The date of the plan, for the risk add-on. */\n readonly today: string;\n /** The count of evaluations of a seeded search of a large space. */\n readonly evaluations?: number;\n readonly seed?: number | string;\n}\n\n/**\n * 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.\n * A plan with fewer places or fewer kinds than the rule gets the break `measure`, so it is not on the front.\n */\nexport function planCopies(query: CopiesQuery, rule: CopyRule, options: PlanCopiesOptions): PlacementPlan {\n const risk = riskAddOn({ today: options.today });\n const chance = (stack: Stack, part: string): ChanceReading => {\n const places = stack.parts.filter((p) => p.kind === \"place\").length;\n const kinds = stack.parts.filter((p) => p.kind === \"medium\").length;\n if (places < rule.places || kinds < rule.kinds) throw new RangeError(`The plan has ${places} places and ${kinds} kinds. The rule needs ${rule.places} and ${rule.kinds}.`);\n const read = readLayer(stack, risk);\n if (read !== undefined && !read.ok) throw new RangeError(read.errors.join(\" \"));\n const works = worksChance(read?.layer ?? { schema: RISK_SCHEMA, goals: [] }, stack, part);\n return works.kind === \"exact\" ? { value: works.value, importance: works.importance, assumed: works.assumed } : { value: Number.NaN };\n };\n return planPlacement(query.layer, query.base, {\n joiners: [risk],\n chance,\n ...(options.evaluations === undefined ? {} : { evaluations: options.evaluations }),\n ...(options.seed === undefined ? {} : { seed: options.seed }),\n });\n}\n"],"mappings":";;;;;;;;AAKA,MAAa,eAAe;CAAC;CAAS;CAAO;CAAO;CAAW;AAAO;;;ACGtE,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAgBA,MAAM,SAAS;AAEf,SAAS,UAAU,OAAkC;CACnD,OAAO,OAAO,UAAU,YAAa,SAA+B,SAAS,KAAK;AACpF;;;;;;AAOA,SAAgB,aAAa,SAA4B,UAA0B,CAAC,GAA8B;CAChH,MAAM,MAAwB,CAAC;CAC/B,MAAM,SAAS,MAAmB,IAAY,YAA0B;EACtE,IAAI,KAAK;GAAE,OAAO;GAAS;GAAM,QAAQ;GAAU;GAAI;EAAQ,CAAC;CAClE;CACA,MAAM,UAAU,QAAQ,YAAY,KAAA,IAAY,KAAA,IAAY,IAAI,IAAI,QAAQ,QAAQ,KAAK,WAAW,OAAO,EAAE,CAAC;CAC9G,MAAM,SAAS,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,IAAI,IAAI,QAAQ,MAAM,KAAK,SAAS,KAAK,KAAK,CAAC;CACxG,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,KAAK,IAAI,OAAO,EAAE,GAAG,MAAM,gBAAgB,OAAO,IAAI,4BAA4B,OAAO,G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I;EACxF,OAAO,MAAM,SAAS,UAAU;GAAE,OAAO,MAAM;GAAO,YAAY,MAAM;GAAY,SAAS,MAAM;EAAQ,IAAI,EAAE,OAAO,IAAW;CACrI;CACA,OAAO,cAAc,MAAM,OAAO,MAAM,MAAM;EAC5C,SAAS,CAAC,IAAI;EACd;EACA,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;EAChF,GAAI,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,KAAK;CAC7D,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/records.ts","../src/check.ts","../src/date.ts","../src/copies.ts","../src/kiwix.ts","../src/placement.ts"],"sourcesContent":["// The records of the library add-on: an offline bundle, a copy of a bundle on one medium, and the copy rule of a level.\n\nimport type { IsoDate, License, SourceId } from \"@mark1russell7/guidebook\";\n\n/** The kinds of media that hold a copy. */\nexport const MEDIUM_KINDS = [\"flash\", \"ssd\", \"hdd\", \"optical\", \"paper\"] as const;\n\n/** A kind of medium. */\nexport type MediumKind = (typeof MEDIUM_KINDS)[number];\n\n/**\n * An offline bundle: one file that holds a full source, for example a Kiwix ZIM file.\n * The `level` names a rule of the caller, so the add-on names no topic.\n */\nexport interface Bundle {\n readonly id: string;\n readonly title: string;\n /** The size of the file in bytes. */\n readonly bytes: number;\n readonly license: License;\n /** The level of the most important content of the bundle. A copy rule of the caller gives the copies of each level. */\n readonly level: string;\n /** The `id` of the source of the bundle in the sources of the core. */\n readonly source: SourceId;\n /** The release of the file, for example `2026-10`. */\n readonly version?: string;\n /** The SHA-256 of the file, as 64 lower-case hexadecimal digits. */\n readonly sha256?: string;\n /** The address of the file, with `https:` or `http:`. */\n readonly url?: string;\n}\n\n/**\n * A link of the catalog: a source with no file in the catalog, for example a source whose license permits only a link.\n * A household gets its own copy from the address, for example a book that it buys from the publisher.\n */\nexport interface Link {\n readonly id: string;\n readonly title: string;\n /** The `id` of the source of the link in the sources of the core. */\n readonly source: SourceId;\n /** The address of the page, with `https:` or `http:`. */\n readonly url: string;\n}\n\n/**\n * The life of a medium at a quantile, for example the time to 5% failure of a disc.\n * A medium younger than `years` fails with a chance of `quantile` or less. Past `years`, the life gives no bound.\n */\nexport interface MediumLife {\n /** The age in years at which the fraction `quantile` of the media fails. */\n readonly years: number;\n /** The fraction from 0 to 1 of the media that fails by the age `years`, for example 0.05. */\n readonly quantile: number;\n /** The source of the life, with its conditions, for example a temperature and a humidity. */\n readonly source: string;\n}\n\n/** A copy of a bundle on one medium. Where each copy goes is a query of the caller, for example of `stack-placement`. */\nexport interface Copy {\n /** The `id` of the bundle. */\n readonly bundle: string;\n /** The `id` of the medium, for example the label on a drive. */\n readonly medium: string;\n readonly kind: MediumKind;\n /** The `id` of the place of the medium. The places are input data of the caller. */\n readonly place: string;\n /** The date of the last read of the full copy against its hash. */\n readonly checked: IsoDate;\n /** The release of the bundle on the medium. */\n readonly version?: string;\n /** The SHA-256 that the last check read from the copy. */\n readonly sha256?: string;\n /** The life of the medium. A copy older than the life does not count. */\n readonly life?: MediumLife;\n /** The date on which the medium was written. A copy with a `life` needs it, because its age comes from it. */\n readonly written?: IsoDate;\n}\n\n/** The copies that a level needs. */\nexport interface CopyRule {\n readonly level: string;\n /** The smallest count of good copies. */\n readonly copies: number;\n /** The smallest count of different kinds of media among the good copies. */\n readonly kinds: number;\n /** The smallest count of different places among the good copies. */\n readonly places: number;\n /** A copy is good for this number of days after its last check. */\n readonly everyDays: number;\n}\n","// The catalog gate: the checks of the bundles and of their copies.\n\nimport { LICENSES, isSha256, isWebAddress, permits, timeOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, License, Source, UseContext } from \"@mark1russell7/guidebook\";\nimport { MEDIUM_KINDS } from \"./records.ts\";\nimport type { Bundle, Copy, CopyRule, Link } from \"./records.ts\";\n\n/** The codes of the findings of the catalog gate. */\nexport const LIBRARY_CODES = [\n \"duplicate-id\",\n \"empty-title\",\n \"bad-bytes\",\n \"bad-sha256\",\n \"bad-url\",\n \"unknown-license\",\n \"missing-source\",\n \"unknown-level\",\n \"use-refused\",\n \"missing-bundle\",\n \"bad-kind\",\n \"bad-date\",\n \"checked-in-future\",\n \"duplicate-copy\",\n \"bad-life\",\n] as const;\n\n/** A code of a finding of the catalog gate. */\nexport type LibraryCode = (typeof LIBRARY_CODES)[number];\n\n/** A finding of the catalog gate, on a bundle or on a copy. */\nexport type LibraryFinding = Finding<LibraryCode, \"bundle\" | \"copy\" | \"link\">;\n\n/** The options of the catalog gate. */\nexport interface CatalogOptions extends UseContext {\n /** The sources of the core. With them, a bundle must name a known source. */\n readonly sources?: readonly Source[];\n /** The copy rules. With them, a bundle must name the level of a rule. */\n readonly rules?: readonly CopyRule[];\n}\n\n\nfunction isLicense(value: unknown): value is License {\n return typeof value === \"string\" && (LICENSES as readonly string[]).includes(value);\n}\n\n/**\n * This function gives the findings of the bundles of a catalog.\n * A bundle must have a unique id, a title, a whole positive size and a license that permits a bundle.\n * Its hash and its address must be correct when it has them.\n */\nexport function checkCatalog(bundles: readonly Bundle[], options: CatalogOptions = {}): readonly LibraryFinding[] {\n const out: LibraryFinding[] = [];\n const error = (code: LibraryCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"bundle\", id, message });\n };\n const sources = options.sources === undefined ? undefined : new Set(options.sources.map((source) => source.id));\n const levels = options.rules === undefined ? undefined : new Set(options.rules.map((rule) => rule.level));\n const seen = new Set<string>();\n for (const bundle of bundles) {\n if (seen.has(bundle.id)) error(\"duplicate-id\", bundle.id, `Two bundles have the id \"${bundle.id}\".`);\n seen.add(bundle.id);\n if (bundle.title.trim() === \"\") error(\"empty-title\", bundle.id, `The bundle \"${bundle.id}\" has no title.`);\n if (!Number.isSafeInteger(bundle.bytes) || bundle.bytes <= 0) error(\"bad-bytes\", bundle.id, `The bundle \"${bundle.id}\" has the size ${bundle.bytes}. It needs a whole number of bytes more than 0.`);\n if (bundle.sha256 !== undefined && !isSha256(bundle.sha256)) error(\"bad-sha256\", bundle.id, `The bundle \"${bundle.id}\" has a SHA-256 that is not 64 lower-case hexadecimal digits.`);\n if (bundle.url !== undefined && !isWebAddress(bundle.url)) error(\"bad-url\", bundle.id, `The bundle \"${bundle.id}\" has the address \"${bundle.url}\". It needs an address with https: or http:.`);\n if (!isLicense(bundle.license)) {\n error(\"unknown-license\", bundle.id, `The bundle \"${bundle.id}\" has the unknown license \"${String(bundle.license)}\".`);\n } else if (!permits(bundle.license, \"bundle\", options)) {\n error(\"use-refused\", bundle.id, `The license \"${bundle.license}\" of the bundle \"${bundle.id}\" does not permit an offline bundle in this guidebook.`);\n }\n if (sources !== undefined && !sources.has(bundle.source)) error(\"missing-source\", bundle.id, `The bundle \"${bundle.id}\" names the unknown source \"${bundle.source}\".`);\n if (levels !== undefined && !levels.has(bundle.level)) error(\"unknown-level\", bundle.id, `The bundle \"${bundle.id}\" has the level \"${bundle.level}\", and no copy rule has it.`);\n }\n return out;\n}\n\n/** The options of the check of the links. */\nexport interface LinksOptions {\n /** The sources of the core. With them, a link must name a known source. */\n readonly sources?: readonly Source[];\n}\n\n/** This function gives the findings of the links of a catalog: a duplicate id, an empty title, a bad address and an unknown source. */\nexport function checkLinks(links: readonly Link[], options: LinksOptions = {}): readonly LibraryFinding[] {\n const out: LibraryFinding[] = [];\n const error = (code: LibraryCode, id: string, message: string): void => {\n out.push({ level: \"error\", code, record: \"link\", id, message });\n };\n const sources = options.sources === undefined ? undefined : new Set(options.sources.map((source) => source.id));\n const seen = new Set<string>();\n for (const link of links) {\n if (seen.has(link.id)) error(\"duplicate-id\", link.id, `Two links have the id \"${link.id}\".`);\n seen.add(link.id);\n if (link.title.trim() === \"\") error(\"empty-title\", link.id, `The link \"${link.id}\" has no title.`);\n if (!isWebAddress(link.url)) error(\"bad-url\", link.id, `The link \"${link.id}\" has the address \"${link.url}\". It needs an address with https: or http:.`);\n if (sources !== undefined && !sources.has(link.source)) error(\"missing-source\", link.id, `The link \"${link.id}\" names the unknown source \"${link.source}\".`);\n }\n return out;\n}\n\n/** The options of the check of the copies. */\nexport interface CopiesOptions {\n /** The date of the check. With it, a copy with a later check date is an error. */\n readonly at?: string;\n}\n\n/** This function gives the findings of the copies: an unknown bundle or kind, a bad date, and two records of one copy. */\nexport function checkCopies(copies: readonly Copy[], bundles: readonly Bundle[], options: CopiesOptions = {}): readonly LibraryFinding[] {\n const out: LibraryFinding[] = [];\n const at = options.at === undefined ? undefined : timeOf(options.at);\n if (options.at !== undefined && at === undefined) throw new RangeError(`checkCopies: the date \"${options.at}\" of the check is not a date YYYY-MM-DD.`);\n const known = new Set(bundles.map((bundle) => bundle.id));\n const seen = new Set<string>();\n for (const copy of copies) {\n const id = `${copy.bundle}@${copy.medium}`;\n const error = (code: LibraryCode, message: string): void => {\n out.push({ level: \"error\", code, record: \"copy\", id, message });\n };\n if (seen.has(id)) error(\"duplicate-copy\", `Two records give the copy of \"${copy.bundle}\" on the medium \"${copy.medium}\".`);\n seen.add(id);\n if (!known.has(copy.bundle)) error(\"missing-bundle\", `The copy \"${id}\" names the unknown bundle \"${copy.bundle}\".`);\n if (!(MEDIUM_KINDS as readonly string[]).includes(copy.kind)) error(\"bad-kind\", `The copy \"${id}\" has the unknown kind \"${String(copy.kind)}\".`);\n if (copy.sha256 !== undefined && !isSha256(copy.sha256)) error(\"bad-sha256\", `The copy \"${id}\" has a SHA-256 that is not 64 lower-case hexadecimal digits.`);\n const checked = timeOf(copy.checked);\n if (checked === undefined) error(\"bad-date\", `The copy \"${id}\" has the check date \"${copy.checked}\". It needs a date YYYY-MM-DD.`);\n else if (at !== undefined && checked > at) error(\"checked-in-future\", `The copy \"${id}\" has a check date after the date of the check.`);\n if (copy.written !== undefined) {\n const written = timeOf(copy.written);\n if (written === undefined) error(\"bad-date\", `The copy \"${id}\" has the date of writing \"${copy.written}\". It needs a date YYYY-MM-DD.`);\n else if (at !== undefined && written > at) error(\"checked-in-future\", `The copy \"${id}\" has a date of writing after the date of the check.`);\n }\n const life = copy.life;\n if (life !== undefined && !(life.years > 0 && life.quantile >= 0 && life.quantile <= 1 && life.source.trim() !== \"\")) {\n error(\"bad-life\", `The copy \"${id}\" has a life that is not more than 0 years, a quantile out of 0 to 1, or no source.`);\n }\n }\n return out;\n}\n","// The dates of the add-on. A date is `YYYY-MM-DD` in UTC, as in the core.\n\nimport { DAY_MS, timeOf } from \"@mark1russell7/guidebook\";\n\n/** This function gives the date `YYYY-MM-DD` that is `days` after the date `date`. */\nexport function addDays(date: string, days: number): string {\n const time = timeOf(date);\n if (time === undefined) throw new RangeError(`addDays: \"${date}\" is not a date YYYY-MM-DD.`);\n return new Date(time + days * DAY_MS).toISOString().slice(0, 10);\n}\n","// The state of the copies of each bundle, against the copy rule of its level, and the checks that are due.\n\nimport { DAY_MS, timeOf } from \"@mark1russell7/guidebook\";\nimport type { Finding, IsoDate } from \"@mark1russell7/guidebook\";\nimport { addDays } from \"./date.ts\";\nimport type { Bundle, Copy, CopyRule, MediumKind } from \"./records.ts\";\n\n/** The codes of the copy gaps. */\nexport const GAP_CODES = [\"few-copies\", \"few-kinds\", \"few-places\", \"no-rule\", \"check-due\", \"bad-hash\", \"old-version\", \"past-life\", \"no-written-date\"] as const;\n\n/** A code of a copy gap. */\nexport type GapCode = (typeof GAP_CODES)[number];\n\n/** A copy gap: an error on a bundle with too few good copies, or a warning on one copy. */\nexport type GapFinding = Finding<GapCode, \"bundle\" | \"copy\">;\n\n/**\n * The status of one copy at a date.\n * - `good`: the copy had a check within the days of its rule, and its hash agrees with the bundle.\n * - `old`: as `good`, but the copy holds an earlier release of the bundle. It counts as a good copy.\n * - `due`: the last check is older than the days of the rule. The copy does not count until a new check.\n * - `bad`: the hash of the copy does not agree with the hash of the same release. Replace the copy.\n * - `aged`: the copy has a `life`, and it is older than the life, or its `written` date is not a date. Write a new copy.\n */\nexport type CopyStatus = \"good\" | \"old\" | \"due\" | \"bad\" | \"aged\";\n\n/** The state of the copies of one bundle. */\nexport interface CopyState {\n readonly bundle: string;\n readonly level: string;\n /** The rule of the level, or `undefined` when no rule has the level. */\n readonly rule: CopyRule | undefined;\n readonly copies: readonly { readonly copy: Copy; readonly status: CopyStatus }[];\n /** The count of good copies (the status `good` or `old`). */\n readonly good: number;\n /** The different kinds of media of the good copies. */\n readonly kinds: readonly MediumKind[];\n /** The different places of the good copies. */\n readonly places: readonly string[];\n /** This field is true when the good copies obey the rule. */\n readonly ok: boolean;\n}\n\n/** The result of `copyStates`. */\nexport interface CopyStates {\n readonly states: readonly CopyState[];\n readonly findings: readonly GapFinding[];\n}\n\nfunction statusOf(copy: Copy, bundle: Bundle, rule: CopyRule | undefined, at: number): CopyStatus {\n const sameRelease = bundle.version === undefined || copy.version === undefined || bundle.version === copy.version;\n if (sameRelease && bundle.sha256 !== undefined && copy.sha256 !== undefined && bundle.sha256 !== copy.sha256) return \"bad\";\n if (copy.life !== undefined) {\n const written = copy.written === undefined ? undefined : timeOf(copy.written);\n if (written === undefined || (at - written) / DAY_MS > copy.life.years * 365.25) return \"aged\";\n }\n const checked = timeOf(copy.checked);\n if (checked === undefined) return \"due\";\n if (rule !== undefined && (at - checked) / DAY_MS > rule.everyDays) return \"due\";\n return sameRelease ? \"good\" : \"old\";\n}\n\n/**\n * This function gives the state of the copies of each bundle at the date `at`, and the gaps.\n * A bundle with fewer good copies, kinds or places than the rule of its level gets an error.\n * A copy with a check that is due, a bad hash, an earlier release or an age past its life gets a warning.\n */\nexport function copyStates(bundles: readonly Bundle[], copies: readonly Copy[], rules: readonly CopyRule[], options: { readonly at: IsoDate }): CopyStates {\n const at = timeOf(options.at);\n if (at === undefined) throw new RangeError(`copyStates: the date \"${options.at}\" is not a date YYYY-MM-DD.`);\n const ruleOf = new Map(rules.map((rule) => [rule.level, rule]));\n const byBundle = new Map<string, Copy[]>();\n for (const copy of copies) {\n const list = byBundle.get(copy.bundle) ?? [];\n list.push(copy);\n byBundle.set(copy.bundle, list);\n }\n const states: CopyState[] = [];\n const findings: GapFinding[] = [];\n for (const bundle of bundles) {\n const rule = ruleOf.get(bundle.level);\n const rated = (byBundle.get(bundle.id) ?? []).map((copy) => ({ copy, status: statusOf(copy, bundle, rule, at) }));\n const good = rated.filter((item) => item.status === \"good\" || item.status === \"old\").map((item) => item.copy);\n const kinds = [...new Set(good.map((copy) => copy.kind))];\n const places = [...new Set(good.map((copy) => copy.place))];\n const bundleError = (code: GapCode, message: string): void => {\n findings.push({ level: \"error\", code, record: \"bundle\", id: bundle.id, message });\n };\n if (rule === undefined) {\n bundleError(\"no-rule\", `The bundle \"${bundle.id}\" has the level \"${bundle.level}\", and no copy rule has it.`);\n } else {\n if (good.length < rule.copies) bundleError(\"few-copies\", `The bundle \"${bundle.id}\" has ${good.length} good copies. Its level \"${rule.level}\" needs ${rule.copies}.`);\n if (kinds.length < rule.kinds) bundleError(\"few-kinds\", `The good copies of \"${bundle.id}\" are on ${kinds.length} kinds of media. Its level \"${rule.level}\" needs ${rule.kinds}.`);\n if (places.length < rule.places) bundleError(\"few-places\", `The good copies of \"${bundle.id}\" are in ${places.length} places. Its level \"${rule.level}\" needs ${rule.places}.`);\n }\n for (const { copy, status } of rated) {\n const id = `${copy.bundle}@${copy.medium}`;\n if (status === \"due\") findings.push({ level: \"warning\", code: \"check-due\", record: \"copy\", id, message: `Read the copy \"${id}\" against its hash. Its last check was on ${copy.checked}.` });\n if (status === \"bad\") findings.push({ level: \"warning\", code: \"bad-hash\", record: \"copy\", id, message: `The copy \"${id}\" does not agree with the hash of its release. Replace it.` });\n if (status === \"aged\") {\n const life = copy.life;\n const code: GapCode = copy.written === undefined || timeOf(copy.written) === undefined ? \"no-written-date\" : \"past-life\";\n const message = code === \"past-life\"\n ? `The copy \"${id}\" was written on ${copy.written ?? \"\"}. It is older than the life of its medium, ${life?.years ?? 0} years. Write a new copy.`\n : `The copy \"${id}\" has a life and no date of writing. Add the field \"written\", or write a new copy.`;\n findings.push({ level: \"warning\", code, record: \"copy\", id, message });\n }\n if (status === \"old\") findings.push({ level: \"warning\", code: \"old-version\", record: \"copy\", id, message: `The copy \"${id}\" holds the release \"${copy.version ?? \"\"}\". The catalog has \"${bundle.version ?? \"\"}\".` });\n }\n const ok = rule !== undefined && good.length >= rule.copies && kinds.length >= rule.kinds && places.length >= rule.places;\n states.push({ bundle: bundle.id, level: bundle.level, rule, copies: rated, good: good.length, kinds, places, ok });\n }\n return { states, findings };\n}\n\n/** A check of a copy that a schedule gives to a person or a job. */\nexport interface DueCheck {\n readonly bundle: string;\n readonly medium: string;\n readonly place: string;\n /** The last date on which the copy is good with no new check. */\n readonly due: IsoDate;\n}\n\n/**\n * This function gives the check of each copy whose due date is on or before `at` plus `withinDays`, the first due first.\n * A copy of a bundle with no rule, or of an unknown bundle, gets no check.\n */\nexport function checksDue(bundles: readonly Bundle[], copies: readonly Copy[], rules: readonly CopyRule[], options: { readonly at: IsoDate; readonly withinDays?: number }): readonly DueCheck[] {\n const limit = addDays(options.at, options.withinDays ?? 0);\n const levelOf = new Map(bundles.map((bundle) => [bundle.id, bundle.level]));\n const ruleOf = new Map(rules.map((rule) => [rule.level, rule]));\n const out: DueCheck[] = [];\n for (const copy of copies) {\n const level = levelOf.get(copy.bundle);\n const rule = level === undefined ? undefined : ruleOf.get(level);\n if (rule === undefined) continue;\n const due = timeOf(copy.checked) === undefined ? options.at : addDays(copy.checked, rule.everyDays);\n if (due <= limit) out.push({ bundle: copy.bundle, medium: copy.medium, place: copy.place, due });\n }\n return out.sort((a, b) => (a.due < b.due ? -1 : a.due > b.due ? 1 : a.bundle < b.bundle ? -1 : a.bundle > b.bundle ? 1 : a.medium < b.medium ? -1 : a.medium > b.medium ? 1 : 0));\n}\n\n/** This function gives the bytes that are necessary on one medium for each bundle of a list. */\nexport function bytesOf(bundles: readonly Bundle[], ids: readonly string[]): number {\n const sizeOf = new Map(bundles.map((bundle) => [bundle.id, bundle.bytes]));\n let total = 0;\n for (const id of new Set(ids)) {\n const bytes = sizeOf.get(id);\n if (bytes === undefined) throw new RangeError(`bytesOf: the bundle \"${id}\" is not in the catalog.`);\n total += bytes;\n }\n return total;\n}\n","// The Kiwix catalog: its OPDS feed of ZIM files, the Metalink file (`.meta4`) of each release, and the release gate.\n// The functions are pure. The caller fetches the feed and the `.meta4` files, for example with `polite-crawler/api`.\n\nimport type { Finding, IsoDate } from \"@mark1russell7/guidebook\";\nimport { DAY_MS, timeOf } from \"@mark1russell7/guidebook\";\nimport { decodeReferences } from \"@mark1russell7/text/references\";\nimport type { Bundle } from \"./records.ts\";\n\n/** The address of the OPDS catalog of Kiwix. */\nexport const KIWIX_CATALOG = \"https://opds.library.kiwix.org/catalog/v2\";\n\n/** One ZIM file of the OPDS feed of Kiwix. */\nexport interface KiwixEntry {\n /** The key of the file: its name with its flavour, for example `wikipedia_en_medicine_nopic`. */\n readonly key: string;\n readonly name: string;\n /** The flavour of the file, for example `nopic`, or an empty text. */\n readonly flavour: string;\n readonly title: string;\n /** The release of the file, `YYYY-MM`. */\n readonly release: string;\n /** The date of the release. */\n readonly issued: IsoDate;\n /** The address of the `.meta4` file of the release. */\n readonly meta4: string;\n /** The size that the feed gives. The feed rounds it up to whole KiB, so `parseMeta4` gives the exact size. */\n readonly approxBytes: number;\n}\n\n/** The facts of one file in a `.meta4` file. */\nexport interface Meta4 {\n /** The name of the file, for example `wikipedia_en_medicine_nopic_2026-10.zim`. */\n readonly file: string;\n /** The exact size of the file in bytes. */\n readonly bytes: number;\n /** The SHA-256 of the file, as 64 lower-case hexadecimal digits. */\n readonly sha256: string;\n}\n\n/** The options of `kiwixFeedUrl`. */\nexport interface FeedQuery {\n /** The ISO 639-3 code of the language, for example `eng`. */\n readonly lang?: string;\n /** The name of a file, for example `wikipedia_en_medicine`. */\n readonly name?: string;\n /** The largest count of entries. The default is 2000. */\n readonly count?: number;\n /** The address of the catalog. The default is `KIWIX_CATALOG`. */\n readonly catalog?: string;\n}\n\n/** This function gives the address of the OPDS feed of the entries that agree with the query. */\nexport function kiwixFeedUrl(query: FeedQuery = {}): string {\n const params: [string, string][] = [];\n if (query.lang !== undefined) params.push([\"lang\", query.lang]);\n if (query.name !== undefined) params.push([\"name\", query.name]);\n params.push([\"count\", String(query.count ?? 2000)]);\n const search = params.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join(\"&\");\n return `${query.catalog ?? KIWIX_CATALOG}/entries?${search}`;\n}\n\nconst FILE = /^([a-z0-9._-]+?)_(\\d{4}-\\d{2})\\.zim$/u;\n\n/** This function gives the key and the release of a ZIM file from its name or its address, or `undefined` for another file. */\nexport function kiwixKeyOf(fileOrUrl: string): { readonly key: string; readonly release: string } | undefined {\n const file = fileOrUrl.split(/[?#]/u)[0]?.split(\"/\").at(-1)?.replace(/\\.meta4$/u, \"\") ?? \"\";\n const match = FILE.exec(file);\n return match === null ? undefined : { key: match[1] ?? \"\", release: match[2] ?? \"\" };\n}\n\nfunction textOf(xml: string, tag: string): string | undefined {\n const match = new RegExp(`<${tag}(?:\\\\s[^>]*)?>([^<]*)</${tag}>`, \"u\").exec(xml);\n return match === null ? undefined : decodeReferences(match[1] ?? \"\").trim();\n}\n\n/** This function gives each start tag of the element `name` in the XML, with a scan that is linear in the length of the XML. */\nfunction tagsOf(xml: string, name: string): string[] {\n const out: string[] = [];\n for (let start = xml.indexOf(`<${name}`); start >= 0; start = xml.indexOf(`<${name}`, start + 1)) {\n const end = xml.indexOf(\">\", start);\n if (end < 0) break;\n out.push(xml.slice(start, end + 1));\n }\n return out;\n}\n\nconst OPEN_ACCESS = 'rel=\"http://opds-spec.org/acquisition/open-access\"';\n\nfunction attributeOf(tag: string, name: string): string | undefined {\n const match = new RegExp(`\\\\s${name}=\"([^\"]*)\"`, \"u\").exec(tag);\n return match === null ? undefined : decodeReferences(match[1] ?? \"\");\n}\n\n/**\n * This function gives the entries of an OPDS feed of Kiwix.\n * An entry with no open-access link to a `.meta4` file of a ZIM release is not in the result.\n */\nexport function parseKiwixFeed(xml: string): readonly KiwixEntry[] {\n const out: KiwixEntry[] = [];\n for (const part of xml.split(\"<entry>\").slice(1)) {\n const entry = part.split(\"</entry>\")[0] ?? \"\";\n const link = tagsOf(entry, \"link \").find((tag) => tag.includes(OPEN_ACCESS));\n const meta4 = link === undefined ? undefined : attributeOf(link, \"href\");\n const file = meta4 === undefined ? undefined : kiwixKeyOf(meta4);\n if (link === undefined || meta4 === undefined || file === undefined) continue;\n const issued = (textOf(entry, \"dc:issued\") ?? textOf(entry, \"updated\") ?? \"\").slice(0, 10);\n out.push({\n key: file.key,\n name: textOf(entry, \"name\") ?? \"\",\n flavour: textOf(entry, \"flavour\") ?? \"\",\n title: textOf(entry, \"title\") ?? \"\",\n release: file.release,\n issued,\n meta4,\n approxBytes: Number(attributeOf(link, \"length\") ?? \"0\"),\n });\n }\n return out;\n}\n\n/** 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. */\nexport function parseMeta4(xml: string): Meta4 {\n const tag = tagsOf(xml, \"file \")[0];\n const start = tag === undefined ? -1 : xml.indexOf(tag) + tag.length;\n const end = start < 0 ? -1 : xml.indexOf(\"</file>\", start);\n const block = end < 0 ? \"\" : xml.slice(start, end);\n const file = tag === undefined ? undefined : attributeOf(tag, \"name\");\n const bytes = Number(textOf(block, \"size\") ?? Number.NaN);\n const sha256 = /<hash\\s+type=\"sha-256\"\\s*>([0-9a-fA-F]{64})<\\/hash>/u.exec(block)?.[1]?.toLowerCase();\n if (file === undefined || file === \"\" || !Number.isSafeInteger(bytes) || bytes < 1 || sha256 === undefined) {\n throw new RangeError(\"parseMeta4: the file has no file name, no size or no SHA-256.\");\n }\n return { file, bytes, sha256 };\n}\n\n/** This function gives the newest release of each key of the entries. */\nexport function latestReleases(entries: readonly KiwixEntry[]): ReadonlyMap<string, KiwixEntry> {\n const out = new Map<string, KiwixEntry>();\n for (const entry of entries) {\n const known = out.get(entry.key);\n if (known === undefined || entry.release > known.release) out.set(entry.key, entry);\n }\n return out;\n}\n\n/** The address of the ZIM file of a `.meta4` address: the same address with no `.meta4`. */\nexport function zimUrlOf(meta4: string): string {\n return meta4.replace(/\\.meta4$/u, \"\");\n}\n\n/**\n * This function gives the bundle with the release of the entry: its version, its exact size, its SHA-256 and its address.\n * It throws a `RangeError` when the `.meta4` file is for a different file.\n */\nexport function withRelease(bundle: Bundle, entry: KiwixEntry, meta4: Meta4): Bundle {\n const file = kiwixKeyOf(meta4.file);\n if (file?.key !== entry.key || file.release !== entry.release) {\n throw new RangeError(`withRelease: the .meta4 file is for \"${meta4.file}\", not for ${entry.key} ${entry.release}.`);\n }\n return { ...bundle, version: entry.release, bytes: meta4.bytes, sha256: meta4.sha256, url: zimUrlOf(entry.meta4) };\n}\n\n/** The codes of the release gate. */\nexport const RELEASE_CODES = [\"not-kiwix\", \"not-in-feed\", \"newer-release\", \"old-release\", \"no-hash\"] as const;\n\n/** A code of the release gate. */\nexport type ReleaseCode = (typeof RELEASE_CODES)[number];\n\n/** A finding of the release gate. */\nexport type ReleaseFinding = Finding<ReleaseCode, \"bundle\">;\n\n/** The options of `checkReleases`. */\nexport interface ReleaseOptions {\n /** The date of the read of the feed. */\n readonly at: IsoDate;\n /** A newer release is an error when the release of the bundle is older than this count of days. The default is 365. */\n readonly maxAgeDays?: number;\n}\n\n/**\n * This function compares each bundle with a Kiwix address to the newest release of the feed.\n * - The feed has no file of the key: the error `not-in-feed`.\n * - The feed has a newer release: the warning `newer-release`, or the error `old-release` when the bundle is older than `maxAgeDays`.\n * - The bundle has no SHA-256: the warning `no-hash`.\n * - A bundle with an address that is not a ZIM release gets the warning `not-kiwix`.\n */\nexport function checkReleases(bundles: readonly Bundle[], entries: readonly KiwixEntry[], options: ReleaseOptions): readonly ReleaseFinding[] {\n const at = timeOf(options.at);\n if (at === undefined) throw new RangeError(`checkReleases: the date \"${options.at}\" is not a date YYYY-MM-DD.`);\n const maxAgeDays = options.maxAgeDays ?? 365;\n const latest = latestReleases(entries);\n const out: ReleaseFinding[] = [];\n const add = (level: \"error\" | \"warning\", code: ReleaseCode, id: string, message: string): void => {\n out.push({ level, code, record: \"bundle\", id, message });\n };\n for (const bundle of bundles) {\n if (bundle.url === undefined) continue;\n const file = kiwixKeyOf(bundle.url);\n if (file === undefined) {\n add(\"warning\", \"not-kiwix\", bundle.id, `The bundle \"${bundle.id}\" has the address \"${bundle.url}\". It is not a ZIM release of Kiwix.`);\n continue;\n }\n const entry = latest.get(file.key);\n if (entry === undefined) {\n add(\"error\", \"not-in-feed\", bundle.id, `The Kiwix feed has no file \"${file.key}\" of the bundle \"${bundle.id}\".`);\n } else if (entry.release > file.release) {\n const released = timeOf(`${file.release}-01`);\n const old = released !== undefined && (at - released) / DAY_MS > maxAgeDays;\n add(old ? \"error\" : \"warning\", old ? \"old-release\" : \"newer-release\", bundle.id, `The bundle \"${bundle.id}\" has the release ${file.release}. The Kiwix feed has ${entry.release}.`);\n }\n if (bundle.sha256 === undefined) add(\"warning\", \"no-hash\", bundle.id, `The bundle \"${bundle.id}\" has no SHA-256. Read it from the .meta4 file of its release.`);\n }\n return out;\n}\n","// The plan of the copies of one level as a query of `@mark1russell7/stack-placement`.\n// Each slot is one copy. Each candidate is one medium offer at one place. Each place and each kind of medium is a shared\n// fragment, so two copies at one place share the loss of that place. The chance comes from `worksChance` of `stack-risk`.\n\nimport type { Candidate, ChanceReading, PlacementLayer, PlacementPlan, Shared } from \"@mark1russell7/stack-placement\";\nimport { PLACEMENT_SCHEMA, planPlacement } from \"@mark1russell7/stack-placement\";\nimport { RISK_SCHEMA, worksChance } from \"@mark1russell7/stack-risk\";\nimport type { RiskLayer } from \"@mark1russell7/stack-risk\";\nimport { riskAddOn } from \"@mark1russell7/stack-risk/add-on\";\nimport type { Part, Stack } from \"@mark1russell7/system-stack\";\nimport { readLayer } from \"@mark1russell7/system-stack\";\nimport type { CopyRule, MediumKind, MediumLife } from \"./records.ts\";\n\n/** A medium that a copy can go on, with its price and its rate of loss. The offers are input data of the caller. */\nexport interface MediumOffer {\n readonly id: string;\n readonly kind: MediumKind;\n /** The capacity of one medium in bytes. */\n readonly bytes: number;\n /** The price of one medium, in the currency of the plan. */\n readonly price: number;\n /** The years of use of one medium. The cost of a month is `price / (lifeYears × 12)`. */\n readonly lifeYears: number;\n /** The chance from 0 to 1 that a copy on the medium cannot be read after one year, for example an annual failure rate. */\n readonly yearlyLoss: number;\n /** The source of `yearlyLoss`. */\n readonly source: string;\n /**\n * The life of the medium at a quantile. A medium that ages fails more frequently when it is old, so a yearly rate is not a safe bound.\n * With a life, the chance of a copy is the smaller of the two. A plan that keeps a medium past its life gets the chance 0.\n */\n readonly life?: MediumLife;\n}\n\n/** A place that holds copies, with its rate of loss. The places are input data of the caller. */\nexport interface CopyPlace {\n readonly id: string;\n /** The chance from 0 to 1 that the place loses all its copies in one year, for example by fire, flood or theft. */\n readonly yearlyLoss: number;\n /** The source of `yearlyLoss`. */\n readonly source: string;\n /** The cost of a month of the place, for example the rent of a box. The default is 0. */\n readonly monthly?: number;\n}\n\n/** A shared cause of loss of all the copies on one kind of medium, for example a format that no reader can read. */\nexport interface KindLoss {\n readonly kind: MediumKind;\n readonly yearlyLoss: number;\n readonly source: string;\n}\n\n/** The input of `copiesLayer`. */\nexport interface CopiesInput {\n /** The copy rule of the level. The slots, the counts of kinds and places, and the period of the chance come from it. */\n readonly rule: CopyRule;\n /** The bytes of the bundles of the level, for example from `bytesOf`. An offer with less capacity is not a candidate. */\n readonly bytes: number;\n readonly offers: readonly MediumOffer[];\n readonly places: readonly CopyPlace[];\n /** The shared losses of the kinds. A kind with no record has no shared loss. */\n readonly kindLosses?: readonly KindLoss[];\n /** The count of optional slots after the `rule.copies` slots. The default is 1. */\n readonly extra?: number;\n /** The currency of the prices. */\n readonly currency: string;\n /** The largest cost of a month, and the smallest chance. */\n readonly limits?: { readonly cost?: number; readonly chance?: number };\n}\n\n/** The layer and the base stack of a plan of copies. */\nexport interface CopiesQuery {\n readonly layer: PlacementLayer;\n readonly base: Stack;\n}\n\n/** The part of a placed stack that works when one copy of the level or more can be read. */\nexport const libraryPartOf = (level: string): string => `library:${level}`;\n\nconst placePartOf = (place: string): string => `place:${place}`;\nconst kindPartOf = (kind: MediumKind): string => `medium:${kind}`;\n\n/**\n * This function gives the chance that a medium with a life still works at the end of each period, from 0 to 1.\n * The medium is replaced after `useYears`. For each period that ends by the age `life.years`, the chance is `1 - life.quantile` or more.\n * The reason: the chance of the period is S(end) / S(start), and S(end) is S(life) or more. When `useYears` is more than `life.years`, the chance is 0.\n */\nexport function lifeChance(life: MediumLife, useYears: number): number {\n if (!(life.quantile >= 0 && life.quantile <= 1) || !(life.years > 0) || !(useYears > 0)) {\n throw new RangeError(`lifeChance: the life ${life.years} years at ${life.quantile}, or the use ${useYears} years, is out of range.`);\n }\n return useYears <= life.years ? 1 - life.quantile : 0;\n}\n\nconst offerChance = (offer: MediumOffer, days: number): number => {\n const rate = keepChance(offer.yearlyLoss, days);\n return offer.life === undefined ? rate : Math.min(rate, lifeChance(offer.life, offer.lifeYears));\n};\n\n/** This function gives the chance that a thing with a yearly loss still works after `days` days. */\nexport function keepChance(yearlyLoss: number, days: number): number {\n if (!(yearlyLoss >= 0 && yearlyLoss <= 1) || !(days >= 0)) throw new RangeError(`keepChance: the loss ${yearlyLoss} or the days ${days} is out of range.`);\n return (1 - yearlyLoss) ** (days / 365);\n}\n\nconst fragment = (part: Part, works: number, source: string): Stack => ({\n schema: \"stack/1\",\n parts: [part],\n layers: { [RISK_SCHEMA]: { schema: RISK_SCHEMA, goals: [], chances: [{ part: part.id, works, source }] } satisfies RiskLayer },\n});\n\n/**\n * This function gives the placement layer and the base stack of the copies of one level.\n * 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.\n * It throws a `RangeError` when no offer can hold the bytes, or when the input has no place.\n */\nexport function copiesLayer(input: CopiesInput): CopiesQuery {\n const { rule } = input;\n const days = rule.everyDays;\n const offers = input.offers.filter((offer) => offer.bytes >= input.bytes);\n if (offers.length === 0) throw new RangeError(`copiesLayer: no offer holds the ${input.bytes} bytes of the level \"${rule.level}\".`);\n if (input.places.length === 0) throw new RangeError(`copiesLayer: the level \"${rule.level}\" has no place.`);\n const count = Math.max(1, rule.copies) + (input.extra ?? 1);\n const slotIds = Array.from({ length: count }, (_, i) => `copy-${i + 1}`);\n const kinds = [...new Set(offers.map((offer) => offer.kind))];\n const losses = new Map((input.kindLosses ?? []).map((loss) => [loss.kind, loss]));\n const shared: Shared[] = [\n ...input.places.map((place) => ({\n id: placePartOf(place.id),\n stack: fragment({ id: placePartOf(place.id), kind: \"place\", name: place.id }, keepChance(place.yearlyLoss, days), place.source),\n cost: place.monthly ?? 0,\n })),\n ...kinds.map((kind) => {\n const loss = losses.get(kind);\n const works = loss === undefined ? 1 : keepChance(loss.yearlyLoss, days);\n return { id: kindPartOf(kind), stack: fragment({ id: kindPartOf(kind), kind: \"medium\", name: kind }, works, loss?.source ?? \"No shared loss of the kind is known.\") };\n }),\n ];\n const candidatesOf = (slot: string): Candidate[] =>\n offers.flatMap((offer) =>\n input.places.map((place) => ({\n key: `${offer.id}@${place.id}`,\n cost: offer.price / (offer.lifeYears * 12),\n uses: [placePartOf(place.id), kindPartOf(offer.kind)],\n source: offer.id,\n stack: fragment({ id: slot, kind: \"copy\", needs: [placePartOf(place.id), kindPartOf(offer.kind)] }, offerChance(offer, days), offer.life === undefined ? offer.source : `${offer.source} ${offer.life.source}`),\n })),\n );\n const part = libraryPartOf(rule.level);\n const layer: PlacementLayer = {\n schema: PLACEMENT_SCHEMA,\n part,\n currency: input.currency,\n slots: slotIds.map((id, i) => ({ id, candidates: candidatesOf(id), optional: i >= rule.copies })),\n shared,\n ...(input.limits === undefined ? {} : { limits: input.limits }),\n };\n const base: Stack = {\n schema: \"stack/1\",\n parts: [{ id: part, kind: \"function\", needs: [{ any: slotIds }] }],\n layers: { [RISK_SCHEMA]: { schema: RISK_SCHEMA, goals: [], chances: [{ part, works: 1, source: \"The level works when one copy or more can be read.\" }] } satisfies RiskLayer },\n };\n return { layer, base };\n}\n\n/** The options of `planCopies`. */\nexport interface PlanCopiesOptions {\n /** The date of the plan, for the risk add-on. */\n readonly today: string;\n /** The count of evaluations of a seeded search of a large space. */\n readonly evaluations?: number;\n readonly seed?: number | string;\n}\n\n/**\n * 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.\n * A plan with fewer places or fewer kinds than the rule gets the break `measure`, so it is not on the front.\n */\nexport function planCopies(query: CopiesQuery, rule: CopyRule, options: PlanCopiesOptions): PlacementPlan {\n const risk = riskAddOn({ today: options.today });\n const chance = (stack: Stack, part: string): ChanceReading => {\n const places = stack.parts.filter((p) => p.kind === \"place\").length;\n const kinds = stack.parts.filter((p) => p.kind === \"medium\").length;\n if (places < rule.places || kinds < rule.kinds) throw new RangeError(`The plan has ${places} places and ${kinds} kinds. The rule needs ${rule.places} and ${rule.kinds}.`);\n const read = readLayer(stack, risk);\n if (read !== undefined && !read.ok) throw new RangeError(read.errors.join(\" \"));\n const works = worksChance(read?.layer ?? { schema: RISK_SCHEMA, goals: [] }, stack, part);\n return works.kind === \"exact\" ? { value: works.value, importance: works.importance, assumed: works.assumed } : { value: Number.NaN };\n };\n return planPlacement(query.layer, query.base, {\n joiners: [risk],\n chance,\n ...(options.evaluations === undefined ? {} : { evaluations: options.evaluations }),\n ...(options.seed === undefined ? {} : { seed: options.seed }),\n });\n}\n"],"mappings":";;;;;;;;AAKA,MAAa,eAAe;CAAC;CAAS;CAAO;CAAO;CAAW;AAAO;;;ACGtE,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAiBA,SAAS,UAAU,OAAkC;CACnD,OAAO,OAAO,UAAU,YAAa,SAA+B,SAAS,KAAK;AACpF;;;;;;AAOA,SAAgB,aAAa,SAA4B,UAA0B,CAAC,GAA8B;CAChH,MAAM,MAAwB,CAAC;CAC/B,MAAM,SAAS,MAAmB,IAAY,YAA0B;EACtE,IAAI,KAAK;GAAE,OAAO;GAAS;GAAM,QAAQ;GAA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AS,QAAQ,CAAC,CAAC;EAC7D,IAAI,SAAS,KAAK,UAAU,QAAQ,KAAK,OAAO,MAAM,IAAI,WAAW,gBAAgB,OAAO,cAAc,MAAM,yBAAyB,KAAK,OAAO,OAAO,KAAK,MAAM,EAAE;EACzK,MAAM,OAAO,UAAU,OAAO,IAAI;EAClC,IAAI,SAAS,KAAA,KAAa,CAAC,KAAK,IAAI,MAAM,IAAI,WAAW,KAAK,OAAO,KAAK,GAAG,CAAC;EAC9E,MAAM,QAAQ,YAAY,MAAM,SAAS;GAAE,QAAQ;GAAa,OAAO,CAAC;EAAE,GAAG,OAAO,IAAI;EACxF,OAAO,MAAM,SAAS,UAAU;GAAE,OAAO,MAAM;GAAO,YAAY,MAAM;GAAY,SAAS,MAAM;EAAQ,IAAI,EAAE,OAAO,IAAW;CACrI;CACA,OAAO,cAAc,MAAM,OAAO,MAAM,MAAM;EAC5C,SAAS,CAAC,IAAI;EACd;EACA,GAAI,QAAQ,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,QAAQ,YAAY;EAChF,GAAI,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,QAAQ,KAAK;CAC7D,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/guidebook-library",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "The library add-on of the guidebook: a catalog of offline bundles (size, license, version, checksum), the copies of each bundle on media, and the gaps of the copies of each level.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"guidebook",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@mark1russell7/guidebook": "0.
|
|
51
|
+
"@mark1russell7/guidebook": "0.3.0",
|
|
52
52
|
"@mark1russell7/stack-placement": "^0.1.1",
|
|
53
53
|
"@mark1russell7/stack-risk": "^0.2.1",
|
|
54
54
|
"@mark1russell7/system-stack": "^0.1.6",
|
package/src/check.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The catalog gate: the checks of the bundles and of their copies.
|
|
2
2
|
|
|
3
|
-
import { LICENSES, isWebAddress, permits, timeOf } from "@mark1russell7/guidebook";
|
|
3
|
+
import { LICENSES, isSha256, isWebAddress, permits, timeOf } from "@mark1russell7/guidebook";
|
|
4
4
|
import type { Finding, License, Source, UseContext } from "@mark1russell7/guidebook";
|
|
5
5
|
import { MEDIUM_KINDS } from "./records.ts";
|
|
6
6
|
import type { Bundle, Copy, CopyRule, Link } from "./records.ts";
|
|
@@ -38,7 +38,6 @@ export interface CatalogOptions extends UseContext {
|
|
|
38
38
|
readonly rules?: readonly CopyRule[];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const SHA256 = /^[0-9a-f]{64}$/;
|
|
42
41
|
|
|
43
42
|
function isLicense(value: unknown): value is License {
|
|
44
43
|
return typeof value === "string" && (LICENSES as readonly string[]).includes(value);
|
|
@@ -62,7 +61,7 @@ export function checkCatalog(bundles: readonly Bundle[], options: CatalogOptions
|
|
|
62
61
|
seen.add(bundle.id);
|
|
63
62
|
if (bundle.title.trim() === "") error("empty-title", bundle.id, `The bundle "${bundle.id}" has no title.`);
|
|
64
63
|
if (!Number.isSafeInteger(bundle.bytes) || bundle.bytes <= 0) error("bad-bytes", bundle.id, `The bundle "${bundle.id}" has the size ${bundle.bytes}. It needs a whole number of bytes more than 0.`);
|
|
65
|
-
if (bundle.sha256 !== undefined && !
|
|
64
|
+
if (bundle.sha256 !== undefined && !isSha256(bundle.sha256)) error("bad-sha256", bundle.id, `The bundle "${bundle.id}" has a SHA-256 that is not 64 lower-case hexadecimal digits.`);
|
|
66
65
|
if (bundle.url !== undefined && !isWebAddress(bundle.url)) error("bad-url", bundle.id, `The bundle "${bundle.id}" has the address "${bundle.url}". It needs an address with https: or http:.`);
|
|
67
66
|
if (!isLicense(bundle.license)) {
|
|
68
67
|
error("unknown-license", bundle.id, `The bundle "${bundle.id}" has the unknown license "${String(bundle.license)}".`);
|
|
@@ -121,7 +120,7 @@ export function checkCopies(copies: readonly Copy[], bundles: readonly Bundle[],
|
|
|
121
120
|
seen.add(id);
|
|
122
121
|
if (!known.has(copy.bundle)) error("missing-bundle", `The copy "${id}" names the unknown bundle "${copy.bundle}".`);
|
|
123
122
|
if (!(MEDIUM_KINDS as readonly string[]).includes(copy.kind)) error("bad-kind", `The copy "${id}" has the unknown kind "${String(copy.kind)}".`);
|
|
124
|
-
if (copy.sha256 !== undefined && !
|
|
123
|
+
if (copy.sha256 !== undefined && !isSha256(copy.sha256)) error("bad-sha256", `The copy "${id}" has a SHA-256 that is not 64 lower-case hexadecimal digits.`);
|
|
125
124
|
const checked = timeOf(copy.checked);
|
|
126
125
|
if (checked === undefined) error("bad-date", `The copy "${id}" has the check date "${copy.checked}". It needs a date YYYY-MM-DD.`);
|
|
127
126
|
else if (at !== undefined && checked > at) error("checked-in-future", `The copy "${id}" has a check date after the date of the check.`);
|