zonemapdb 0.8.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -0
  3. package/dist/block-fetch.d.ts +11 -0
  4. package/dist/block-fetch.d.ts.map +1 -0
  5. package/dist/block-fetch.js +29 -0
  6. package/dist/block-fetch.js.map +1 -0
  7. package/dist/client.d.ts +3 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +584 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/errors.d.ts +40 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +24 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/fetch-file.d.ts +39 -0
  16. package/dist/fetch-file.d.ts.map +1 -0
  17. package/dist/fetch-file.js +179 -0
  18. package/dist/fetch-file.js.map +1 -0
  19. package/dist/filter.d.ts +9 -0
  20. package/dist/filter.d.ts.map +1 -0
  21. package/dist/filter.js +104 -0
  22. package/dist/filter.js.map +1 -0
  23. package/dist/index-fetch.d.ts +3 -0
  24. package/dist/index-fetch.d.ts.map +1 -0
  25. package/dist/index-fetch.js +5 -0
  26. package/dist/index-fetch.js.map +1 -0
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +5 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/manifest.d.ts +127 -0
  32. package/dist/manifest.d.ts.map +1 -0
  33. package/dist/manifest.js +86 -0
  34. package/dist/manifest.js.map +1 -0
  35. package/dist/normalize.d.ts +25 -0
  36. package/dist/normalize.d.ts.map +1 -0
  37. package/dist/normalize.js +43 -0
  38. package/dist/normalize.js.map +1 -0
  39. package/dist/secondary-index.d.ts +32 -0
  40. package/dist/secondary-index.d.ts.map +1 -0
  41. package/dist/secondary-index.js +80 -0
  42. package/dist/secondary-index.js.map +1 -0
  43. package/dist/types.d.ts +319 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +164 -0
  46. package/dist/types.js.map +1 -0
  47. package/dist/version.d.ts +9 -0
  48. package/dist/version.d.ts.map +1 -0
  49. package/dist/version.js +9 -0
  50. package/dist/version.js.map +1 -0
  51. package/dist/zonemap-fetch.d.ts +9 -0
  52. package/dist/zonemap-fetch.d.ts.map +1 -0
  53. package/dist/zonemap-fetch.js +11 -0
  54. package/dist/zonemap-fetch.js.map +1 -0
  55. package/dist/zonemap.d.ts +35 -0
  56. package/dist/zonemap.d.ts.map +1 -0
  57. package/dist/zonemap.js +139 -0
  58. package/dist/zonemap.js.map +1 -0
  59. package/package.json +53 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,GACR,gBAAgB,GAChB,kBAAkB,GAClB,SAAS,GACT,cAAc,GACd,gBAAgB,GAChB,eAAe,GACf,SAAS,CAAC;AAEd,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,sDAAsD;IACtD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,oGAAoG;IACpG,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAGlC,SAAiB,GAAG,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAiB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEjC,YAAY,IAAI,EAAE,kBAAkB,EAOnC;CACF"}
package/dist/errors.js ADDED
@@ -0,0 +1,24 @@
1
+ // The single catchable error surface (ADR-0007 §4): one exported class with a
2
+ // discriminated `code`, chosen over a subclass hierarchy — same narrowing, far
3
+ // less exported surface, no instanceof-across-bundlers fragility. Adding a code
4
+ // later is non-breaking.
5
+ /**
6
+ * The one error `findMany`/`count`/`get` ever throw for fetch/parse/limit
7
+ * failures: `catch (e) { if (e instanceof ZonemapDbError && e.code === "…") … }`.
8
+ * The triggering query object is deliberately NOT attached — a `where` can hold
9
+ * PII-ish filter values that would land in logs (ADR-0007 §8).
10
+ */
11
+ export class ZonemapDbError extends Error {
12
+ code;
13
+ constructor(init) {
14
+ super(init.message, init.cause !== undefined ? { cause: init.cause } : undefined);
15
+ this.name = "ZonemapDbError";
16
+ this.code = init.code;
17
+ // Conditionally assigned so "absent" means absent (`"url" in err` ⇔ provided).
18
+ if (init.url !== undefined)
19
+ this.url = init.url;
20
+ if (init.status !== undefined)
21
+ this.status = init.status;
22
+ }
23
+ }
24
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+EAA+E;AAC/E,gFAAgF;AAChF,yBAAyB;AAuCzB;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAqB;IAMlC,YAAY,IAAwB;QAClC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAClF,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,+EAA+E;QAC/E,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS;YAAE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QAChD,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3D,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ import { type Compression } from "./types.js";
2
+ /**
3
+ * 404 routes by WHICH file was being fetched — always known at the call site
4
+ * (ADR-0007 §6): the manifest itself → `CONFIG` (wrong basePath); any
5
+ * manifest-referenced content-hashed file → `DEPLOY_INTEGRITY` (corrupt deploy).
6
+ */
7
+ export type FetchedFileKind = "manifest" | "referenced";
8
+ /** Fetch + JSON-parse; an unparseable 2xx body is CORRUPT_DATA (ADR-0007 §5). */
9
+ export declare function fetchJson(url: string, kind: FetchedFileKind, fetchImpl: typeof fetch, signal?: AbortSignal, cache?: RequestCache): Promise<unknown>;
10
+ /** Fetch + text; a 2xx body that won't read is CORRUPT_DATA. */
11
+ export declare function fetchText(url: string, kind: FetchedFileKind, fetchImpl: typeof fetch, signal?: AbortSignal): Promise<string>;
12
+ /** The compression a served path implies. `.br` is the file suffix; `"brotli"` is the API's format name. */
13
+ export declare function compressionOfPath(url: string): Compression;
14
+ /**
15
+ * Fetch + decompress + text, for build-time-compressed files (ADR-0002 §8) — the native
16
+ * `DecompressionStream` API, no library/WASM. A 2xx body that won't decompress, or won't read once
17
+ * decompressed, is CORRUPT_DATA (same contract as `fetchText`).
18
+ *
19
+ * When the host serves the file under a matching `Content-Encoding`, the transport has already done
20
+ * the work and this returns the body as-is. That path is worth more than a mere fix: transport-level
21
+ * brotli is understood by every browser, whereas `DecompressionStream("brotli")` is not yet (Chrome
22
+ * 150 still rejects it) — so a `.br` deploy behind such a host works where a raw-bytes one cannot.
23
+ * Where the host serves raw bytes there is no fallback, which is why build-time compression stays
24
+ * opt-in.
25
+ */
26
+ export declare function fetchCompressedText(url: string, kind: FetchedFileKind, format: "gzip" | "brotli", fetchImpl: typeof fetch, signal?: AbortSignal, cache?: RequestCache): Promise<string>;
27
+ /**
28
+ * Fetch + JSON-parse a manifest-referenced file, decompressing first when the path says it was
29
+ * built gzipped (ADR-0002 §8).
30
+ *
31
+ * Index chunks and zonemap sidecars are referenced from the manifest **by full path**, so the `.gz`
32
+ * suffix is all the signal needed — no manifest flag to keep in sync, and a tree holding a mix of
33
+ * compressed and plain files still reads correctly. That matters because content-hashed filenames
34
+ * mean a rebuild replaces only the files whose contents changed.
35
+ */
36
+ export declare function fetchReferencedJson(url: string, fetchImpl: typeof fetch, signal?: AbortSignal): Promise<unknown>;
37
+ /** Parse/decode a 2xx body's CONTENT into a domain structure; failures are CORRUPT_DATA. */
38
+ export declare function parseCorruptible<T>(url: string, parse: () => T): T;
39
+ //# sourceMappingURL=fetch-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-file.d.ts","sourceRoot":"","sources":["../src/fetch-file.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,YAAY,CAAC;AA0DxD,iFAAiF;AACjF,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,eAAe,EACrB,SAAS,EAAE,OAAO,KAAK,EACvB,MAAM,CAAC,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,YAAY,GACnB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAgBD,gEAAgE;AAChE,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,eAAe,EACrB,SAAS,EAAE,OAAO,KAAK,EACvB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,4GAA4G;AAC5G,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAI1D;AAsBD;;;;;;;;;;;GAWG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,eAAe,EACrB,MAAM,EAAE,MAAM,GAAG,QAAQ,EACzB,SAAS,EAAE,OAAO,KAAK,EACvB,MAAM,CAAC,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,YAAY,GACnB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,OAAO,KAAK,EACvB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,CAAC,CAKlB;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAWlE"}
@@ -0,0 +1,179 @@
1
+ // The WHATWG-fetch → ZonemapDbError mapping (ADR-0007 §3/§5/§6), shared by every
2
+ // file the runtime fetches. The injected fetch rejects on network-level failure
3
+ // but resolves on ANY HTTP status, so a fetch counts as failed when the promise
4
+ // rejects OR resolves !response.ok. No retry/backoff/timeout here — that is the
5
+ // injected fetch's / CDN's job (§2).
6
+ import { ZonemapDbError } from "./errors.js";
7
+ import { decompressionFormat } from "./types.js";
8
+ function messageFor404(kind, url) {
9
+ return kind === "manifest"
10
+ ? `zonemapdb: no manifest.json at "${url}" (HTTP 404) — check basePath: it must point at the deployed dataset root. If the dataset was never deployed there, re-run \`zonemapdb build\` and deploy the output.`
11
+ : `zonemapdb: "${url}" referenced by the manifest returned HTTP 404 — the deploy is incomplete or corrupt, or a stale cache (a CDN, a fetch wrapper, or an old index.html / bundled client) is still serving an earlier deploy's manifest. If the deploy is complete, wait for caches to expire or hard-reload; otherwise re-run \`zonemapdb build\` and redeploy the whole output.`;
12
+ }
13
+ function messageForHtmlFallback(kind, url) {
14
+ return kind === "manifest"
15
+ ? `zonemapdb: "${url}" returned an HTML page instead of manifest.json, which is what a single-page-app fallback serves for a missing file — check basePath: it must point at the deployed dataset root.`
16
+ : `zonemapdb: "${url}" referenced by the manifest returned an HTML page, which is what a single-page-app fallback serves for a missing file — the deploy is incomplete, or a stale cache is still serving an earlier deploy's manifest. If the deploy is complete, wait for caches to expire or hard-reload; otherwise re-run \`zonemapdb build\` and redeploy the whole output.`;
17
+ }
18
+ /**
19
+ * Fetches `url`, mapping rejection / !ok to the right ZonemapDbError code. Resolves only on 2xx.
20
+ * `cache` is set only for the manifest (#32); content-hashed files leave it off so the browser's
21
+ * normal (forever-valid) caching applies, and their `init` stays exactly `{ signal }`.
22
+ */
23
+ async function fetchOk(url, kind, fetchImpl, signal, cache) {
24
+ let response;
25
+ try {
26
+ response = await fetchImpl(url, cache === undefined ? { signal } : { signal, cache });
27
+ }
28
+ catch (cause) {
29
+ throw new ZonemapDbError({
30
+ code: "NETWORK",
31
+ url,
32
+ message: `zonemapdb: fetch for "${url}" failed at the network level (${cause instanceof Error ? cause.message : String(cause)}) — possibly transient. Retry by wrapping the injected fetch, or check connectivity/CORS.`,
33
+ cause,
34
+ });
35
+ }
36
+ // A single-page-app fallback (Netlify/Vercel/Cloudflare rewrites, `serve -s`) answers a missing file
37
+ // with 200 and index.html. zonemapdb never serves HTML, so that is the missing file, and it is routed as
38
+ // the 404 it stands for. Otherwise it would surface as CORRUPT_DATA and skip the stale-manifest recovery.
39
+ const servedHtml = response.ok && (response.headers?.get("content-type") ?? "").toLowerCase().startsWith("text/html");
40
+ if (response.ok && !servedHtml)
41
+ return response;
42
+ if (response.status === 404 || servedHtml) {
43
+ throw new ZonemapDbError({
44
+ code: kind === "manifest" ? "CONFIG" : "DEPLOY_INTEGRITY",
45
+ url,
46
+ status: response.status,
47
+ message: servedHtml ? messageForHtmlFallback(kind, url) : messageFor404(kind, url),
48
+ });
49
+ }
50
+ throw new ZonemapDbError({
51
+ code: "NETWORK",
52
+ url,
53
+ status: response.status,
54
+ message: `zonemapdb: fetch for "${url}" returned HTTP ${response.status} — possibly transient. Retry by wrapping the injected fetch, or check the host/CDN.`,
55
+ });
56
+ }
57
+ /** Fetch + JSON-parse; an unparseable 2xx body is CORRUPT_DATA (ADR-0007 §5). */
58
+ export async function fetchJson(url, kind, fetchImpl, signal, cache) {
59
+ const response = await fetchOk(url, kind, fetchImpl, signal, cache);
60
+ try {
61
+ return await response.json();
62
+ }
63
+ catch (cause) {
64
+ throw new ZonemapDbError({
65
+ code: "CORRUPT_DATA",
66
+ url,
67
+ message: `zonemapdb: the body of "${url}" would not parse as JSON — the deploy is corrupt. Re-run \`zonemapdb build\` and redeploy.`,
68
+ cause,
69
+ });
70
+ }
71
+ }
72
+ /** Reads a 2xx body as text; a body that won't read is CORRUPT_DATA. */
73
+ async function readText(response, url) {
74
+ try {
75
+ return await response.text();
76
+ }
77
+ catch (cause) {
78
+ throw new ZonemapDbError({
79
+ code: "CORRUPT_DATA",
80
+ url,
81
+ message: `zonemapdb: the body of "${url}" could not be read — the deploy is corrupt. Re-run \`zonemapdb build\` and redeploy.`,
82
+ cause,
83
+ });
84
+ }
85
+ }
86
+ /** Fetch + text; a 2xx body that won't read is CORRUPT_DATA. */
87
+ export async function fetchText(url, kind, fetchImpl, signal) {
88
+ return await readText(await fetchOk(url, kind, fetchImpl, signal), url);
89
+ }
90
+ /** The compression a served path implies. `.br` is the file suffix; `"brotli"` is the API's format name. */
91
+ export function compressionOfPath(url) {
92
+ if (url.endsWith(".gz"))
93
+ return "gzip";
94
+ if (url.endsWith(".br"))
95
+ return "brotli";
96
+ return "none";
97
+ }
98
+ /** The `Content-Encoding` token a codec travels under — `br` on the wire, `"brotli"` to the API. */
99
+ const CONTENT_ENCODING_TOKEN = { gzip: "gzip", brotli: "br" };
100
+ /**
101
+ * Whether the fetch layer has ALREADY undone this file's build-time compression.
102
+ *
103
+ * Most static hosts recognise a `.gz`/`.br` suffix and answer with the matching `Content-Encoding`
104
+ * (Vite's dev server, nginx `gzip_static`, most CDNs). The browser then decodes at the transport
105
+ * layer and hands over a plain body — while leaving the header visible on the response. Decompressing
106
+ * again would fail on what is already plain text, so the header is the signal to stand down.
107
+ *
108
+ * The match must be exact: a host that re-encodes our `.br` file as gzip has undone its own encoding,
109
+ * not the build's, and the runtime still has to do its part.
110
+ */
111
+ function alreadyDecodedByTransport(response, format) {
112
+ const header = response.headers?.get("content-encoding");
113
+ if (!header)
114
+ return false;
115
+ return header.split(",").some((token) => token.trim().toLowerCase() === CONTENT_ENCODING_TOKEN[format]);
116
+ }
117
+ /**
118
+ * Fetch + decompress + text, for build-time-compressed files (ADR-0002 §8) — the native
119
+ * `DecompressionStream` API, no library/WASM. A 2xx body that won't decompress, or won't read once
120
+ * decompressed, is CORRUPT_DATA (same contract as `fetchText`).
121
+ *
122
+ * When the host serves the file under a matching `Content-Encoding`, the transport has already done
123
+ * the work and this returns the body as-is. That path is worth more than a mere fix: transport-level
124
+ * brotli is understood by every browser, whereas `DecompressionStream("brotli")` is not yet (Chrome
125
+ * 150 still rejects it) — so a `.br` deploy behind such a host works where a raw-bytes one cannot.
126
+ * Where the host serves raw bytes there is no fallback, which is why build-time compression stays
127
+ * opt-in.
128
+ */
129
+ export async function fetchCompressedText(url, kind, format, fetchImpl, signal, cache) {
130
+ const response = await fetchOk(url, kind, fetchImpl, signal, cache);
131
+ if (alreadyDecodedByTransport(response, format))
132
+ return await readText(response, url);
133
+ try {
134
+ // Cast: TypeScript's DOM lib still types CompressionFormat as gzip/deflate/deflate-raw, though
135
+ // "brotli" is in the Compression Streams spec and shipping. The runtime check that matters is the
136
+ // catch below — an engine without the format throws here and surfaces as CORRUPT_DATA.
137
+ const decompressed = response.body.pipeThrough(new DecompressionStream(format));
138
+ return await new Response(decompressed).text();
139
+ }
140
+ catch (cause) {
141
+ throw new ZonemapDbError({
142
+ code: "CORRUPT_DATA",
143
+ url,
144
+ message: `zonemapdb: the ${format} body of "${url}" could not be decompressed — the deploy is corrupt, or this browser lacks ${format} support in DecompressionStream. Re-run \`zonemapdb build\` and redeploy.`,
145
+ cause,
146
+ });
147
+ }
148
+ }
149
+ /**
150
+ * Fetch + JSON-parse a manifest-referenced file, decompressing first when the path says it was
151
+ * built gzipped (ADR-0002 §8).
152
+ *
153
+ * Index chunks and zonemap sidecars are referenced from the manifest **by full path**, so the `.gz`
154
+ * suffix is all the signal needed — no manifest flag to keep in sync, and a tree holding a mix of
155
+ * compressed and plain files still reads correctly. That matters because content-hashed filenames
156
+ * mean a rebuild replaces only the files whose contents changed.
157
+ */
158
+ export async function fetchReferencedJson(url, fetchImpl, signal) {
159
+ const format = decompressionFormat(compressionOfPath(url));
160
+ if (format === undefined)
161
+ return await fetchJson(url, "referenced", fetchImpl, signal);
162
+ const text = await fetchCompressedText(url, "referenced", format, fetchImpl, signal);
163
+ return parseCorruptible(url, () => JSON.parse(text));
164
+ }
165
+ /** Parse/decode a 2xx body's CONTENT into a domain structure; failures are CORRUPT_DATA. */
166
+ export function parseCorruptible(url, parse) {
167
+ try {
168
+ return parse();
169
+ }
170
+ catch (cause) {
171
+ throw new ZonemapDbError({
172
+ code: "CORRUPT_DATA",
173
+ url,
174
+ message: `zonemapdb: the body of "${url}" would not parse — the deploy is corrupt. Re-run \`zonemapdb build\` and redeploy.`,
175
+ cause,
176
+ });
177
+ }
178
+ }
179
+ //# sourceMappingURL=fetch-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-file.js","sourceRoot":"","sources":["../src/fetch-file.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAChF,qCAAqC;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAoB,MAAM,YAAY,CAAC;AASnE,SAAS,aAAa,CAAC,IAAqB,EAAE,GAAW;IACvD,OAAO,IAAI,KAAK,UAAU;QACxB,CAAC,CAAC,mCAAmC,GAAG,uKAAuK;QAC/M,CAAC,CAAC,eAAe,GAAG,gWAAgW,CAAC;AACzX,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAqB,EAAE,GAAW;IAChE,OAAO,IAAI,KAAK,UAAU;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;YACpB,GAAG;YACH,OAAO,EAAE,2BAA2B,GAAG,qFAAqF;YAC5H,KAAK;SACN,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Evaluates one field's operator filter against a record (T7): `isNull`/`isAbsent`/`exists`
3
+ * distinguish an explicit `null` from a genuinely missing key; every other operator
4
+ * (including `some` and the `not` rider) requires a present, non-null value.
5
+ */
6
+ export declare function matchesFieldFilter(record: Record<string, unknown>, field: string, filter: Record<string, unknown>): boolean;
7
+ /** Implicit-AND across every field in `where` (ADR-0001). */
8
+ export declare function matchesWhere(record: Record<string, unknown>, where: Record<string, Record<string, unknown>> | undefined): boolean;
9
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AA0DA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CA4B3H;AAED,6DAA6D;AAC7D,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,GACzD,OAAO,CAMT"}
package/dist/filter.js ADDED
@@ -0,0 +1,104 @@
1
+ /** Evaluates one non-null, present value against a single scalar operator (equals/in/gt/.../not). */
2
+ function matchesValueOp(value, op, opValue) {
3
+ switch (op) {
4
+ case "equals":
5
+ return value === opValue;
6
+ case "not":
7
+ return value !== opValue;
8
+ case "in":
9
+ return opValue.includes(value);
10
+ case "gt":
11
+ return value > opValue;
12
+ case "gte":
13
+ return value >= opValue;
14
+ case "lt":
15
+ return value < opValue;
16
+ case "lte":
17
+ return value <= opValue;
18
+ case "startsWith":
19
+ return value.startsWith(opValue);
20
+ case "endsWith":
21
+ return value.endsWith(opValue);
22
+ case "contains":
23
+ return value.includes(opValue);
24
+ default:
25
+ throw new Error(`zonemapdb: unsupported operator "${op}"`);
26
+ }
27
+ }
28
+ /** One element against `some`/`every`'s element filter — shorthand value ≡ `{ equals: value }`. */
29
+ function matchesElement(element, elementFilter) {
30
+ if (typeof elementFilter === "object" && elementFilter !== null) {
31
+ return Object.entries(elementFilter).every(([op, opValue]) => matchesValueOp(element, op, opValue));
32
+ }
33
+ return element === elementFilter;
34
+ }
35
+ /**
36
+ * The list operators on a multi-valued field: `some` (T7) plus ADR-0010's `hasEvery`, `every` and
37
+ * `isEmpty`. `undefined` means `op` isn't one of them.
38
+ */
39
+ function matchesListOp(values, op, opValue) {
40
+ switch (op) {
41
+ case "some":
42
+ return values.some((element) => matchesElement(element, opValue));
43
+ case "every":
44
+ // Vacuously true for [] — "every colour is W or U" holds for a colourless card.
45
+ return values.every((element) => matchesElement(element, opValue));
46
+ case "hasEvery":
47
+ return opValue.every((wanted) => values.includes(wanted));
48
+ case "isEmpty":
49
+ return (values.length === 0) === opValue;
50
+ default:
51
+ return undefined;
52
+ }
53
+ }
54
+ /**
55
+ * Evaluates one field's operator filter against a record (T7): `isNull`/`isAbsent`/`exists`
56
+ * distinguish an explicit `null` from a genuinely missing key; every other operator
57
+ * (including `some` and the `not` rider) requires a present, non-null value.
58
+ */
59
+ export function matchesFieldFilter(record, field, filter) {
60
+ const isAbsent = !(field in record);
61
+ const value = isAbsent ? undefined : record[field];
62
+ const isNull = !isAbsent && value === null;
63
+ for (const [op, opValue] of Object.entries(filter)) {
64
+ if (op === "isNull") {
65
+ if (isNull !== opValue)
66
+ return false;
67
+ continue;
68
+ }
69
+ if (op === "isAbsent") {
70
+ if (isAbsent !== opValue)
71
+ return false;
72
+ continue;
73
+ }
74
+ if (op === "exists") {
75
+ const exists = !isAbsent && !isNull;
76
+ if (exists !== opValue)
77
+ return false;
78
+ continue;
79
+ }
80
+ if (isAbsent || isNull)
81
+ return false;
82
+ if (Array.isArray(value)) {
83
+ const listMatch = matchesListOp(value, op, opValue);
84
+ if (listMatch === false)
85
+ return false;
86
+ if (listMatch === true)
87
+ continue;
88
+ }
89
+ if (!matchesValueOp(value, op, opValue))
90
+ return false;
91
+ }
92
+ return true;
93
+ }
94
+ /** Implicit-AND across every field in `where` (ADR-0001). */
95
+ export function matchesWhere(record, where) {
96
+ if (!where)
97
+ return true;
98
+ for (const [field, filter] of Object.entries(where)) {
99
+ if (!matchesFieldFilter(record, field, filter))
100
+ return false;
101
+ }
102
+ return true;
103
+ }
104
+ //# sourceMappingURL=filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,SAAS,cAAc,CAAC,KAAc,EAAE,EAAU,EAAE,OAAgB;IAClE,QAAQ,EAAE,EAAE,CAAC;QACX,KAAK,QAAQ;YACX,OAAO,KAAK,KAAK,OAAO,CAAC;QAC3B,KAAK,KAAK;YACR,OAAO,KAAK,KAAK,OAAO,CAAC;QAC3B,KAAK,IAAI;YACP,OAAQ,OAAqB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChD,KAAK,IAAI;YACP,OAAQ,KAAyB,GAAI,OAA2B,CAAC;QACnE,KAAK,KAAK;YACR,OAAQ,KAAyB,IAAK,OAA2B,CAAC;QACpE,KAAK,IAAI;YACP,OAAQ,KAAyB,GAAI,OAA2B,CAAC;QACnE,KAAK,KAAK;YACR,OAAQ,KAAyB,IAAK,OAA2B,CAAC;QACpE,KAAK,YAAY;YACf,OAAQ,KAAgB,CAAC,UAAU,CAAC,OAAiB,CAAC,CAAC;QACzD,KAAK,UAAU;YACb,OAAQ,KAAgB,CAAC,QAAQ,CAAC,OAAiB,CAAC,CAAC;QACvD,KAAK,UAAU;YACb,OAAQ,KAAgB,CAAC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U,YAAY,CAC1B,MAA+B,EAC/B,KAA0D;IAE1D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;YAAE,OAAO,KAAK,CAAC;IAC/D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { IndexChunkFile } from "./secondary-index.js";
2
+ export declare function fetchIndexChunk(basePath: string, file: string, fetchImpl: typeof fetch, signal?: AbortSignal): Promise<IndexChunkFile>;
3
+ //# sourceMappingURL=index-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-fetch.d.ts","sourceRoot":"","sources":["../src/index-fetch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,OAAO,KAAK,EACvB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,cAAc,CAAC,CAEzB"}
@@ -0,0 +1,5 @@
1
+ import { fetchReferencedJson } from "./fetch-file.js";
2
+ export async function fetchIndexChunk(basePath, file, fetchImpl, signal) {
3
+ return (await fetchReferencedJson(`${basePath}/${file}`, fetchImpl, signal));
4
+ }
5
+ //# sourceMappingURL=index-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-fetch.js","sourceRoot":"","sources":["../src/index-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGtD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,QAAgB,EAChB,IAAY,EACZ,SAAuB,EACvB,MAAoB;IAEpB,OAAO,CAAC,MAAM,mBAAmB,CAAC,GAAG,QAAQ,IAAI,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,CAAmB,CAAC;AACjG,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { createClient } from "./client.js";
2
+ export { ZonemapDbError, type ZonemapDbErrorCode } from "./errors.js";
3
+ export { normalize, type NormalizerName } from "./normalize.js";
4
+ export type { Manifest, BlockDescriptor, SchemaDescriptor, FieldSchemaEntry } from "./manifest.js";
5
+ export { assertWhereHasPruning, wherePrunes, type ClientOptions, type Collection, type CollectionMeta, type CountOptions, type CountResult, type FieldKind, type FieldMeta, type BlockOrderScanArgs, type FindManyArgs, type QueryOptions, type FindManyResult, type GenericClient, type OrderByOf, type SchemaMeta, type ValidateWhere, type WhereOf, } from "./types.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACnG,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,OAAO,GACb,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { createClient } from "./client.js";
2
+ export { ZonemapDbError } from "./errors.js";
3
+ export { normalize } from "./normalize.js";
4
+ export { assertWhereHasPruning, wherePrunes, } from "./types.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAA2B,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,SAAS,EAAuB,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EACL,qBAAqB,EACrB,WAAW,GAiBZ,MAAM,YAAY,CAAC"}
@@ -0,0 +1,127 @@
1
+ import { type Compression } from "./types.js";
2
+ export interface BlockDescriptor {
3
+ hash: string;
4
+ bytes: number;
5
+ count: number;
6
+ }
7
+ export interface FieldSchemaEntry {
8
+ kind: string;
9
+ isDate: boolean;
10
+ indexed: boolean;
11
+ /** Everything a `where` may write on this field (ADR-0013). */
12
+ operators: readonly string[];
13
+ /** The subset of `operators` that narrows which blocks a query reads; the rest are riders. */
14
+ pruning: readonly string[];
15
+ /** The key may be missing from a record (absent ≠ null). */
16
+ absent?: true;
17
+ /** The value may be `null` (null ≠ absent). */
18
+ nullable?: true;
19
+ /** Scalar leaf under an object-array — value is an array, matched existentially via `some` (T7). */
20
+ multi?: true;
21
+ /** Present (`true`) only for the user PK field (T8). */
22
+ pk?: true;
23
+ }
24
+ export interface SchemaDescriptor {
25
+ collection: string;
26
+ sortField: string;
27
+ /** Names the user PK field, if declared (T8). */
28
+ pk?: string;
29
+ fields: Record<string, FieldSchemaEntry>;
30
+ }
31
+ /** Records with a null/absent sort-field value cluster in a contiguous tail at the high end (ADR-0002 §9). */
32
+ export interface MissingZonemapInfo {
33
+ /** Ordinal of the earliest block containing any missing (null or absent) sort-field value. */
34
+ blockFrom: number;
35
+ /** Records with an explicit `null` sort-field value. */
36
+ nullCount: number;
37
+ /** Records whose sort-field key is absent entirely (not just null). */
38
+ absentCount: number;
39
+ }
40
+ /** Sort field: N+1 monotonic split-points, binary-searchable (ADR-0003 §2). */
41
+ export interface SplitPointZonemapEntry {
42
+ splitPoints: unknown[];
43
+ /** Present iff at least one record had a null/absent sort-field value (ADR-0002 §9). */
44
+ missing?: MissingZonemapInfo;
45
+ }
46
+ /** Secondary field: per-block [min,max] pairs, ordinal-aligned with `blocks[]` (ADR-0003 §2/§9). */
47
+ export interface PairZonemapEntry {
48
+ pairs: [unknown, unknown][];
49
+ truncated?: boolean;
50
+ }
51
+ /** A secondary field's zonemap moved out of root into a per-field sidecar file (ADR-0003 §3) — spilled when the root manifest would exceed the gzip budget. */
52
+ export interface SidecarZonemapEntry {
53
+ sidecar: string;
54
+ }
55
+ export type ZonemapEntry = SplitPointZonemapEntry | PairZonemapEntry | SidecarZonemapEntry;
56
+ /** One index chunk's value-range coverage — routing metadata only (ADR-0003 §9). */
57
+ export interface IndexChunkDirEntry {
58
+ from: unknown;
59
+ to: unknown;
60
+ file: string;
61
+ }
62
+ export interface IndexDescriptor {
63
+ operators: readonly string[];
64
+ chunks: IndexChunkDirEntry[];
65
+ /** Reversed-value index chunk directory — present iff `endsWith` opted in (ADR-0003 §7/§9). */
66
+ reversed?: {
67
+ chunks: IndexChunkDirEntry[];
68
+ };
69
+ /** Trigram index chunk directory — present iff `contains` opted in (ADR-0003 §7/§9). */
70
+ trigram?: {
71
+ chunks: IndexChunkDirEntry[];
72
+ };
73
+ /**
74
+ * Multi-valued fields only: ordinals of the blocks holding at least one present `[]` — what
75
+ * `isEmpty` and `every` prune on (ADR-0010 §4/§5). Missing (a pre-ADR-0010 build) means unknown.
76
+ */
77
+ emptyBlocks?: number[];
78
+ }
79
+ export interface Manifest {
80
+ formatVersion: number;
81
+ generatorVersion: string;
82
+ dataset: {
83
+ collection: string;
84
+ recordCount: number;
85
+ blockCount: number;
86
+ sortField: string;
87
+ /** Present (`true`) only when block payloads are gzipped at build time (ADR-0002 §8) — omitted otherwise. */
88
+ /**
89
+ * How every served file was pre-compressed, when the build did so (ADR-0002 §8). Absent means
90
+ * plain files. `gzip?: true` is the pre-`compression` spelling, still read so an older deploy keeps
91
+ * working against a newer client.
92
+ */
93
+ compression?: Compression;
94
+ /** @deprecated Superseded by `compression: "gzip"`. */
95
+ gzip?: true;
96
+ };
97
+ schema: SchemaDescriptor;
98
+ blocks: BlockDescriptor[];
99
+ zonemap: Record<string, ZonemapEntry>;
100
+ indexes: Record<string, IndexDescriptor>;
101
+ }
102
+ /**
103
+ * Fetches the root manifest. `gzipped` says the deploy pre-compressed it (ADR-0002 §8) — unlike index
104
+ * chunks and zonemap sidecars, whose `.gz` paths come FROM the manifest and so describe themselves,
105
+ * this is the bootstrap fetch: nothing has been read yet that could tell the client the encoding. The
106
+ * generated client carries the answer instead, stamped by the same `build` that wrote the file, so the
107
+ * two cannot drift.
108
+ *
109
+ * `cache` defaults to `"no-cache"` (#32): the manifest is the one stable-named file, and a host that
110
+ * caches everything for minutes (GitHub Pages sends `max-age=600`) would otherwise hand back the
111
+ * previous deploy's copy after a redeploy. Revalidating costs a 304 when nothing changed. The client
112
+ * passes `"reload"` when a referenced file 404s and it needs to know what the deploy says now.
113
+ */
114
+ export declare function fetchManifest(basePath: string, fetchImpl: typeof fetch, compression?: Compression, cache?: RequestCache): Promise<Manifest>;
115
+ /**
116
+ * How this deploy compressed the files the manifest points at. Reads the modern `compression` field
117
+ * and falls back to the original `gzip: true`, so a tree built before the field existed still works.
118
+ */
119
+ export declare function datasetCompression(manifest: Manifest): Compression;
120
+ /**
121
+ * Whether `manifest` points at `url` — a block, an index chunk (base, reversed or trigram) or a
122
+ * zonemap sidecar. The client asks this of a freshly fetched manifest after a referenced file 404s
123
+ * (#32): if the fresh manifest still names the file the deploy really is missing it, and if not, the
124
+ * 404 came from a stale manifest and the query is worth one retry.
125
+ */
126
+ export declare function manifestReferences(manifest: Manifest, basePath: string, url: string): boolean;
127
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AACA,OAAO,EAA0C,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAKtF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,+DAA+D;IAC/D,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,8FAA8F;IAC9F,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,4DAA4D;IAC5D,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,oGAAoG;IACpG,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,wDAAwD;IACxD,EAAE,CAAC,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC1C;AAED,8GAA8G;AAC9G,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,+EAA+E;AAC/E,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,wFAAwF;IACx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