keepset 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/entry.d.ts +55 -0
- package/dist/browser/entry.js +107 -0
- package/dist/{bundled-B1094k0B.js → bundled-OrF_TPDq.js} +19 -1
- package/dist/{categories-BbW0rFCf.d.ts → categories-BG8lRjy8.d.ts} +162 -162
- package/dist/fetch-A4VG2QuN.js +6384 -0
- package/dist/fetch-HjZj2roj.d.ts +100 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/node/fetch-dataset.d.ts +62 -108
- package/dist/node/fetch-dataset.js +41 -6387
- package/dist-cli/keepset.mjs +1 -1
- package/package.json +5 -1
- package/schemas/entry.schema.json +1 -1
- package/schemas/manifest.schema.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z as Dataset } from "../categories-BG8lRjy8.js";
|
|
2
|
+
import { a as FetchPort, c as Provenance, d as fetchDataset$1, f as fetchEntry$1, i as FetchOptions, l as RoundTripReport, n as Download, o as FetchedDataset, p as roundTripEntry$1, r as DownloadProvenance, s as FilesProvenance, t as DigestPort, u as downloadUrl } from "../fetch-HjZj2roj.js";
|
|
3
|
+
//#region src/browser/download.d.ts
|
|
4
|
+
/** How long a request may take in all, at any point of a download, before it is given up as dead. The platform `fetch` reports progress to no one, so the stall watch of the Node downloader becomes a whole-request deadline here; a healthy server of the open data portals recipes read answers well inside it. */
|
|
5
|
+
export declare const STALL_MILLISECONDS = 120000;
|
|
6
|
+
/** How many times a download is tried when its connection fails, and how long each retry waits for the one before it (the delay times the attempt number), the policy the Node downloader keeps. */
|
|
7
|
+
export declare const DOWNLOAD_ATTEMPTS = 3;
|
|
8
|
+
export declare const RETRY_DELAY_MILLISECONDS = 3000;
|
|
9
|
+
/** Options for one download: the signal that aborts it, and the deadlines only a test shortens. */
|
|
10
|
+
interface DownloadInit {
|
|
11
|
+
readonly signal?: AbortSignal;
|
|
12
|
+
readonly stallMilliseconds?: number;
|
|
13
|
+
readonly retryDelayMilliseconds?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Downloads a URL's bytes, following redirects as the platform does. See the module comment for the one difference from the Node downloader no browser can avoid.
|
|
17
|
+
* @param url - An http or https URL.
|
|
18
|
+
* @param init - The request options.
|
|
19
|
+
* @returns A Response holding the bytes the platform delivers, with the final status.
|
|
20
|
+
* @throws KeepsetError when the URL is not http or https, or the request passes its deadline; the connection's failure, after the tries, when it keeps failing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function downloadRaw(url: string, init: DownloadInit): Promise<Response>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/browser/entry.d.ts
|
|
25
|
+
export type BrowserFetchOptions = Omit<FetchOptions, "fetch" | "digest">;
|
|
26
|
+
/**
|
|
27
|
+
* Fetches a dataset of the bundled catalogue by id through the platform's downloader and digest. See `../fetch`'s `fetchEntry` for what a fetch does; see `./download` for the one way the platform's bytes can differ from Node's.
|
|
28
|
+
* @param id - The entry id.
|
|
29
|
+
* @param options - An abort signal and the clock.
|
|
30
|
+
* @returns The fetched dataset.
|
|
31
|
+
*/
|
|
32
|
+
export declare function fetchDataset(id: string, options: BrowserFetchOptions): Promise<Awaited<ReturnType<typeof fetchDataset$1>>>;
|
|
33
|
+
/**
|
|
34
|
+
* Fetches a dataset object through the platform's downloader and digest.
|
|
35
|
+
* @param dataset - A dataset from any catalogue.
|
|
36
|
+
* @param options - An abort signal and the clock.
|
|
37
|
+
* @returns The fetched dataset.
|
|
38
|
+
*/
|
|
39
|
+
export declare function fetchEntry(dataset: Dataset, options: BrowserFetchOptions): Promise<Awaited<ReturnType<typeof fetchEntry$1>>>;
|
|
40
|
+
/**
|
|
41
|
+
* Checks a dataset's crosswalk on its real data through the platform's ports.
|
|
42
|
+
* @param dataset - A dataset from any catalogue.
|
|
43
|
+
* @param options - An abort signal and the clock.
|
|
44
|
+
* @returns Whether the round trip holds.
|
|
45
|
+
*/
|
|
46
|
+
export declare function roundTripEntry(dataset: Dataset, options: BrowserFetchOptions): Promise<Awaited<ReturnType<typeof roundTripEntry$1>>>;
|
|
47
|
+
/**
|
|
48
|
+
* Runs `roundTripEntry` on a dataset of the bundled catalogue by id.
|
|
49
|
+
* @param id - The entry id.
|
|
50
|
+
* @param options - An abort signal and the clock.
|
|
51
|
+
* @returns Whether the round trip holds.
|
|
52
|
+
*/
|
|
53
|
+
export declare function roundTripDataset(id: string, options: BrowserFetchOptions): Promise<Awaited<ReturnType<typeof roundTripEntry$1>>>;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { type DigestPort, type Download, type DownloadInit, type DownloadProvenance, type FetchOptions, type FetchPort, type FetchedDataset, type FilesProvenance, type Provenance, type RoundTripReport, downloadUrl };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ft as KeepsetError } from "../bundled-OrF_TPDq.js";
|
|
2
|
+
import { i as roundTripEntry$1, n as fetchDataset$1, r as fetchEntry$1, t as downloadUrl } from "../fetch-A4VG2QuN.js";
|
|
3
|
+
//#region src/browser/download.ts
|
|
4
|
+
/** How long a request may take in all, at any point of a download, before it is given up as dead. The platform `fetch` reports progress to no one, so the stall watch of the Node downloader becomes a whole-request deadline here; a healthy server of the open data portals recipes read answers well inside it. */
|
|
5
|
+
const STALL_MILLISECONDS = 12e4;
|
|
6
|
+
/** How many times a download is tried when its connection fails, and how long each retry waits for the one before it (the delay times the attempt number), the policy the Node downloader keeps. */
|
|
7
|
+
const DOWNLOAD_ATTEMPTS = 3;
|
|
8
|
+
const RETRY_DELAY_MILLISECONDS = 3e3;
|
|
9
|
+
/**
|
|
10
|
+
* Downloads a URL's bytes, following redirects as the platform does. See the module comment for the one difference from the Node downloader no browser can avoid.
|
|
11
|
+
* @param url - An http or https URL.
|
|
12
|
+
* @param init - The request options.
|
|
13
|
+
* @returns A Response holding the bytes the platform delivers, with the final status.
|
|
14
|
+
* @throws KeepsetError when the URL is not http or https, or the request passes its deadline; the connection's failure, after the tries, when it keeps failing.
|
|
15
|
+
*/
|
|
16
|
+
async function downloadRaw(url, init) {
|
|
17
|
+
return await tryDownload(url, init, 1);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One try of a download, and the tries after it while the connection fails.
|
|
21
|
+
* @param url - The URL.
|
|
22
|
+
* @param init - The request options.
|
|
23
|
+
* @param attempt - Which try this is, from 1.
|
|
24
|
+
* @returns The response.
|
|
25
|
+
* @throws The last failure when the tries are used up, or at once for a failure that is not the connection's.
|
|
26
|
+
*/
|
|
27
|
+
async function tryDownload(url, init, attempt) {
|
|
28
|
+
const parsed = new URL(url);
|
|
29
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new KeepsetError(`${url} is not an http or https URL`);
|
|
30
|
+
const deadline = new AbortController();
|
|
31
|
+
const timer = setTimeout(() => {
|
|
32
|
+
deadline.abort(new KeepsetError(`${url} did not finish within ${String(init.stallMilliseconds ?? 12e4)} milliseconds, so the request was given up as dead`));
|
|
33
|
+
}, init.stallMilliseconds ?? 12e4);
|
|
34
|
+
const abort = () => {
|
|
35
|
+
deadline.abort(init.signal?.reason);
|
|
36
|
+
};
|
|
37
|
+
init.signal?.addEventListener("abort", abort, { once: true });
|
|
38
|
+
try {
|
|
39
|
+
return await fetch(url, {
|
|
40
|
+
signal: deadline.signal,
|
|
41
|
+
headers: { accept: "*/*" }
|
|
42
|
+
});
|
|
43
|
+
} catch (error) {
|
|
44
|
+
if (init.signal?.aborted === true) throw init.signal.reason;
|
|
45
|
+
if (attempt >= 3) throw error;
|
|
46
|
+
await new Promise((resolve) => {
|
|
47
|
+
setTimeout(resolve, (init.retryDelayMilliseconds ?? 3e3) * attempt);
|
|
48
|
+
});
|
|
49
|
+
return await tryDownload(url, init, attempt + 1);
|
|
50
|
+
} finally {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
init.signal?.removeEventListener("abort", abort);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/browser/entry.ts
|
|
57
|
+
/** The radix of one byte's two hex characters, and their count. */
|
|
58
|
+
const HEX_RADIX = 16;
|
|
59
|
+
const HEX_DIGITS = 2;
|
|
60
|
+
/** The platform's SHA-256, which SubtleCrypto answers; a copy, so the hash reads an ArrayBuffer even when the bytes arrived as a view over a SharedArrayBuffer. */
|
|
61
|
+
const digest = async (bytes) => {
|
|
62
|
+
const hashed = await crypto.subtle.digest("SHA-256", new Uint8Array(bytes));
|
|
63
|
+
return [...new Uint8Array(hashed)].map((byte) => byte.toString(HEX_RADIX).padStart(HEX_DIGITS, "0")).join("");
|
|
64
|
+
};
|
|
65
|
+
const ports = (options) => ({
|
|
66
|
+
...options,
|
|
67
|
+
fetch: downloadRaw,
|
|
68
|
+
digest
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Fetches a dataset of the bundled catalogue by id through the platform's downloader and digest. See `../fetch`'s `fetchEntry` for what a fetch does; see `./download` for the one way the platform's bytes can differ from Node's.
|
|
72
|
+
* @param id - The entry id.
|
|
73
|
+
* @param options - An abort signal and the clock.
|
|
74
|
+
* @returns The fetched dataset.
|
|
75
|
+
*/
|
|
76
|
+
async function fetchDataset(id, options) {
|
|
77
|
+
return fetchDataset$1(id, ports(options));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Fetches a dataset object through the platform's downloader and digest.
|
|
81
|
+
* @param dataset - A dataset from any catalogue.
|
|
82
|
+
* @param options - An abort signal and the clock.
|
|
83
|
+
* @returns The fetched dataset.
|
|
84
|
+
*/
|
|
85
|
+
async function fetchEntry(dataset, options) {
|
|
86
|
+
return fetchEntry$1(dataset, ports(options));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks a dataset's crosswalk on its real data through the platform's ports.
|
|
90
|
+
* @param dataset - A dataset from any catalogue.
|
|
91
|
+
* @param options - An abort signal and the clock.
|
|
92
|
+
* @returns Whether the round trip holds.
|
|
93
|
+
*/
|
|
94
|
+
async function roundTripEntry(dataset, options) {
|
|
95
|
+
return roundTripEntry$1(dataset, ports(options));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Runs `roundTripEntry` on a dataset of the bundled catalogue by id.
|
|
99
|
+
* @param id - The entry id.
|
|
100
|
+
* @param options - An abort signal and the clock.
|
|
101
|
+
* @returns Whether the round trip holds.
|
|
102
|
+
*/
|
|
103
|
+
async function roundTripDataset(id, options) {
|
|
104
|
+
return roundTripEntry$1((await import("../bundled-OrF_TPDq.js").then((n) => n.t)).getDataset(id), ports(options));
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { DOWNLOAD_ATTEMPTS, RETRY_DELAY_MILLISECONDS, STALL_MILLISECONDS, downloadRaw, downloadUrl, fetchDataset, fetchEntry, roundTripDataset, roundTripEntry };
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { CrosswalkSchema, validateCrosswalk } from "crossmap";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __exportAll = (all, no_symbols) => {
|
|
6
|
+
let target = {};
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
3
15
|
//#region src/errors.ts
|
|
4
16
|
/** The root of this package's error taxonomy: every error keepset throws is a `KeepsetError`, so callers can catch the family with one check. */
|
|
5
17
|
var KeepsetError = class extends Error {
|
|
@@ -68812,6 +68824,12 @@ var catalogue_default = {
|
|
|
68812
68824
|
};
|
|
68813
68825
|
//#endregion
|
|
68814
68826
|
//#region src/bundled.ts
|
|
68827
|
+
var bundled_exports = /* @__PURE__ */ __exportAll({
|
|
68828
|
+
getDataset: () => getDataset,
|
|
68829
|
+
getManifest: () => getManifest,
|
|
68830
|
+
listDatasets: () => listDatasets,
|
|
68831
|
+
listNamespaces: () => listNamespaces
|
|
68832
|
+
});
|
|
68815
68833
|
let bundled;
|
|
68816
68834
|
/** The catalogue shipped in this package, assembled from catalogue/ by the build and parsed on first use, so importing the package costs nothing until a query runs. */
|
|
68817
68835
|
function catalogue() {
|
|
@@ -68848,4 +68866,4 @@ function getManifest() {
|
|
|
68848
68866
|
return catalogue().manifest;
|
|
68849
68867
|
}
|
|
68850
68868
|
//#endregion
|
|
68851
|
-
export {
|
|
68869
|
+
export { listCategories as $, SnapshotSchema as A, NAME_SEPARATOR as B, IdSchema as C, RESERVED_META_KEYS as D, ParserSchema as E, parseEntry as F, countTarget as G, namesOf as H, rawSnapshotUrl as I, getCollectionTarget as J, countedKeys as K, readsCollection as L, SourceSchema as M, SubjectSchema as N, RecipeSchema as O, WaybackTimestampSchema as P, kindOf as Q, toIssues as R, HttpUrlSchema as S, NamespaceSchema as T, getOwn as U, groupsOf as V, CategoryIdSchema as W, getTarget as X, getStreamedShape as Y, isStreamable as Z, CollectionFileSchema as _, listNamespaces as a, GraphNodeSchema as at, EntrySchema as b, LineageSchema as c, ArchiveError as ct, parseManifest as d, DatasetNotFoundError as dt, TaskSchema as et, AliasSchema as f, KeepsetError as ft, CollectionArchiveSchema as g, CitationSchema as h, UnknownCategoryError as ht, listDatasets as i, GraphEdgeSchema as it, SourceRecipeSchema as j, RelativePathSchema as k, ManifestSchema as l, CatalogueSyntaxError as lt, ArchiveSchema as m, RecipeError as mt, getDataset as n, TasksV1Schema as nt, CatalogueIndexSchema as o, GraphV1Schema as ot, ArchiveMemberSchema as p, NativeParseError as pt, getCategory as q, getManifest as r, collectionOf as rt, createCatalogue as s, JsonScalarSchema as st, bundled_exports as t, TasksMetaSchema as tt, SemVerSchema as u, DatasetAmbiguousError as ut, ColumnNameSchema as v, LicenceSchema as w, FilesRecipeSchema as x, CrosswalkReferenceSchema as y, waybackUrl as z };
|