@chartcoach/catalog 0.1.6 → 0.2.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 (73) hide show
  1. package/LICENSE +201 -21
  2. package/README.md +324 -38
  3. package/dist/duckdb-wasm.d.ts +8 -0
  4. package/dist/duckdb-wasm.js +22 -0
  5. package/dist/duckdb.d.ts +8 -0
  6. package/dist/duckdb.js +9 -0
  7. package/dist/index-cache-Cx1gIK6N.js +280 -0
  8. package/dist/index.d.ts +40 -8
  9. package/dist/index.js +22 -7
  10. package/dist/json-CBWjz9b4.js +29 -0
  11. package/dist/model-De0MF-zg.d.ts +255 -0
  12. package/dist/node.d.ts +15 -0
  13. package/dist/node.js +218 -0
  14. package/dist/open-Nnzkr_bE.d.ts +15 -0
  15. package/dist/open-Uu3-r8kp.js +1244 -0
  16. package/dist/registration-CgQGMUIH.d.ts +6 -0
  17. package/dist/registration-DXhS7vgr.js +41 -0
  18. package/dist/tables-DcgKnXwF.js +389 -0
  19. package/package.json +48 -19
  20. package/src/catalog/artifacts.ts +309 -100
  21. package/src/catalog/description.ts +198 -0
  22. package/src/catalog/errors.ts +26 -1
  23. package/src/catalog/identity.ts +69 -0
  24. package/src/catalog/json.ts +32 -0
  25. package/src/catalog/labels.ts +8 -6
  26. package/src/catalog/manifest.ts +81 -20
  27. package/src/catalog/markdown.ts +2 -2
  28. package/src/catalog/model.ts +222 -37
  29. package/src/catalog/open.ts +428 -0
  30. package/src/catalog/parquet.ts +164 -0
  31. package/src/catalog/profile-layout.ts +86 -0
  32. package/src/catalog/profile.ts +345 -0
  33. package/src/catalog/query.ts +125 -0
  34. package/src/catalog/read.ts +101 -0
  35. package/src/catalog/references.ts +336 -0
  36. package/src/catalog/registration.ts +74 -0
  37. package/src/catalog/tables.ts +250 -0
  38. package/src/catalog/wire.ts +38 -65
  39. package/src/duckdb-wasm.ts +33 -0
  40. package/src/duckdb.ts +18 -0
  41. package/src/index.ts +51 -20
  42. package/src/node/index-cache.ts +432 -0
  43. package/src/node.ts +347 -0
  44. package/dist/catalog/artifacts.d.ts +0 -28
  45. package/dist/catalog/artifacts.d.ts.map +0 -1
  46. package/dist/catalog/artifacts.js +0 -89
  47. package/dist/catalog/chartcoach-defaults.d.ts +0 -17
  48. package/dist/catalog/chartcoach-defaults.d.ts.map +0 -1
  49. package/dist/catalog/chartcoach-defaults.js +0 -8
  50. package/dist/catalog/errors.d.ts +0 -4
  51. package/dist/catalog/errors.d.ts.map +0 -1
  52. package/dist/catalog/errors.js +0 -6
  53. package/dist/catalog/labels.d.ts +0 -9
  54. package/dist/catalog/labels.d.ts.map +0 -1
  55. package/dist/catalog/labels.js +0 -23
  56. package/dist/catalog/load-parquet-core.d.ts +0 -15
  57. package/dist/catalog/load-parquet-core.d.ts.map +0 -1
  58. package/dist/catalog/load-parquet-core.js +0 -45
  59. package/dist/catalog/manifest.d.ts +0 -15
  60. package/dist/catalog/manifest.d.ts.map +0 -1
  61. package/dist/catalog/manifest.js +0 -143
  62. package/dist/catalog/markdown.d.ts +0 -3
  63. package/dist/catalog/markdown.d.ts.map +0 -1
  64. package/dist/catalog/markdown.js +0 -13
  65. package/dist/catalog/model.d.ts +0 -33
  66. package/dist/catalog/model.d.ts.map +0 -1
  67. package/dist/catalog/model.js +0 -67
  68. package/dist/catalog/wire.d.ts +0 -18
  69. package/dist/catalog/wire.d.ts.map +0 -1
  70. package/dist/catalog/wire.js +0 -78
  71. package/dist/index.d.ts.map +0 -1
  72. package/src/catalog/chartcoach-defaults.ts +0 -17
  73. package/src/catalog/load-parquet-core.ts +0 -78
package/dist/duckdb.js ADDED
@@ -0,0 +1,9 @@
1
+ import { t as registrationPlan } from "./registration-DXhS7vgr.js";
2
+ //#region src/duckdb.ts
3
+ /** Create or replace canonical catalog tables in a caller-owned DuckDB connection. */
4
+ async function registerCatalog(connection, catalog, options = {}) {
5
+ for (const { sql, rows } of registrationPlan(catalog, options, "parameter")) await connection.run(sql, [rows]);
6
+ return connection;
7
+ }
8
+ //#endregion
9
+ export { registerCatalog };
@@ -0,0 +1,280 @@
1
+ import { a as CatalogError, i as parseJson, n as isJsonObject, r as isJsonString } from "./json-CBWjz9b4.js";
2
+ import { randomUUID } from "node:crypto";
3
+ import { createReadStream, createWriteStream } from "node:fs";
4
+ import { chmod, lstat, mkdir, readFile, readdir, realpath, rename, rm, writeFile } from "node:fs/promises";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { Transform, Writable } from "node:stream";
7
+ import { pipeline } from "node:stream/promises";
8
+ import { createGunzip } from "node:zlib";
9
+ import { Parser } from "tar";
10
+ //#region src/node/index-cache.ts
11
+ const pending = /* @__PURE__ */ new Map();
12
+ async function extractIndex(options) {
13
+ if (options.directory !== void 0) {
14
+ const target = resolve(options.directory);
15
+ const archive = await options.archive();
16
+ await mkdir(dirname(target), { recursive: true });
17
+ return unpack(archive, target, options.signal);
18
+ }
19
+ if (process.platform === "win32") throw new CatalogError("Protected shared index extraction is unavailable on this platform.", {
20
+ code: "unavailable_capability",
21
+ hints: ["Pass a new caller-owned directory to indexPath(...)."]
22
+ });
23
+ await mkdir(options.cacheDirectory, { recursive: true });
24
+ const cache = await realpath(options.cacheDirectory);
25
+ const root = join(cache, "indexes-v2", options.digest);
26
+ const previous = pending.get(root) ?? Promise.resolve("");
27
+ let active = false;
28
+ const operation = (async () => {
29
+ await previous.catch(() => "");
30
+ active = true;
31
+ options.signal?.throwIfAborted();
32
+ return cachedIndex(root, options);
33
+ })();
34
+ pending.set(root, operation);
35
+ const settled = () => {
36
+ if (pending.get(root) === operation) pending.delete(root);
37
+ };
38
+ operation.then(settled, settled);
39
+ return wait(operation, () => active, options.signal);
40
+ }
41
+ async function cachedIndex(root, options) {
42
+ await safeDirectory(dirname(root));
43
+ await safeDirectory(root);
44
+ const generations = join(root, "generations");
45
+ await safeDirectory(generations);
46
+ const current = await currentGeneration(root, options.digest, options.signal);
47
+ if (current) return current;
48
+ const archive = await options.archive();
49
+ const generation = randomUUID().replaceAll("-", "");
50
+ const staged = join(root, `.${generation}.tmp`);
51
+ const published = join(generations, generation);
52
+ const pointer = join(root, `.current.${generation}.tmp`);
53
+ let committed = false;
54
+ try {
55
+ await unpack(archive, staged, options.signal);
56
+ await writeFile(join(staged, ".complete"), options.digest, { flag: "wx" });
57
+ options.signal?.throwIfAborted();
58
+ await rename(staged, published);
59
+ await seal(published, options.signal);
60
+ await writeFile(pointer, JSON.stringify({
61
+ digest: options.digest,
62
+ generation
63
+ }), { flag: "wx" });
64
+ options.signal?.throwIfAborted();
65
+ await rename(pointer, join(root, "current.json"));
66
+ committed = true;
67
+ return published;
68
+ } finally {
69
+ await rm(pointer, { force: true });
70
+ await discard(staged);
71
+ if (!committed) await discard(published);
72
+ }
73
+ }
74
+ async function currentGeneration(root, digest, signal) {
75
+ try {
76
+ const pointer = join(root, "current.json");
77
+ const status = await lstat(pointer);
78
+ if (!status.isFile() || status.size > 1024) return void 0;
79
+ const value = parseJson(await readFile(pointer, "utf8"));
80
+ if (!isJsonObject(value)) return void 0;
81
+ if (value.digest !== digest || !isJsonString(value.generation) || !/^[a-f0-9]{32}$/.test(value.generation)) return void 0;
82
+ const target = join(root, "generations", value.generation);
83
+ if (!await validTree(target, signal)) return void 0;
84
+ const marker = join(target, ".complete");
85
+ const markerStatus = await lstat(marker);
86
+ if (!markerStatus.isFile() || markerStatus.size !== digest.length || await readFile(marker, "utf8") !== digest) return void 0;
87
+ if (!(await lstat(join(target, "documents.lance"))).isDirectory()) return void 0;
88
+ return target;
89
+ } catch (error) {
90
+ signal?.throwIfAborted();
91
+ if (error instanceof SyntaxError || error instanceof Error && isMissing(error)) return void 0;
92
+ throw error;
93
+ }
94
+ }
95
+ async function validTree(root, signal) {
96
+ let count = 0;
97
+ const visit = async (path) => {
98
+ signal?.throwIfAborted();
99
+ const status = await lstat(path);
100
+ if (++count > 100002 || (status.mode & 146) !== 0) return false;
101
+ if (status.isFile()) return true;
102
+ if (!status.isDirectory()) return false;
103
+ for (const name of await readdir(path)) if (!await visit(join(path, name))) return false;
104
+ return true;
105
+ };
106
+ return (await lstat(root)).isDirectory() && visit(root);
107
+ }
108
+ async function unpack(archive, target, signal) {
109
+ signal?.throwIfAborted();
110
+ try {
111
+ await mkdir(target);
112
+ } catch (error) {
113
+ if (error instanceof Error && "code" in error && error.code === "EEXIST") throw new CatalogError("Index directory already exists. Pass a new directory.");
114
+ throw error;
115
+ }
116
+ const members = /* @__PURE__ */ new Map();
117
+ let count = 0;
118
+ let total = 0;
119
+ let expanded = 0;
120
+ let ended = false;
121
+ const cancellation = new AbortController();
122
+ const extractionSignal = signal ? AbortSignal.any([signal, cancellation.signal]) : cancellation.signal;
123
+ const jobs = [];
124
+ const extractor = new Parser({
125
+ strict: true,
126
+ maxMetaEntrySize: 1048576,
127
+ maxDecompressionRatio: 0,
128
+ brotli: false,
129
+ zstd: false,
130
+ onReadEntry(entry) {
131
+ const job = writeEntry(entry);
132
+ jobs.push(job);
133
+ job.catch((error) => cancellation.abort(error));
134
+ }
135
+ });
136
+ async function writeEntry(entry) {
137
+ extractionSignal.throwIfAborted();
138
+ const directory = entry.type === "Directory";
139
+ if (!directory && entry.type !== "File") throw integrity("Index archive must contain regular files and directories.");
140
+ if (++count > 1e5) throw integrity("Index archive contains too many members.");
141
+ if (!Number.isSafeInteger(entry.size) || entry.size < 0 || entry.size > 2 * 1024 ** 3) throw integrity("Index archive member exceeds the 2 GiB limit.");
142
+ total += entry.size;
143
+ if (total > 8 * 1024 ** 3) throw integrity("Index archive expands beyond the 8 GiB limit.");
144
+ const parts = portablePath(entry.path, directory);
145
+ for (let length = 1; length <= parts.length; length += 1) {
146
+ const name = parts.slice(0, length).join("/");
147
+ const key = name.normalize("NFKC").toUpperCase();
148
+ const previous = members.get(key);
149
+ const leaf = length === parts.length;
150
+ if (previous && (previous.path !== name || !previous.directory || leaf && (!directory || previous.explicit))) throw integrity("Index archive members collide.");
151
+ if (!previous && members.size >= 1e5) throw integrity("Index archive contains too many filesystem entries.");
152
+ members.set(key, {
153
+ path: name,
154
+ directory: !leaf || directory,
155
+ explicit: leaf || previous?.explicit === true
156
+ });
157
+ }
158
+ const output = join(target, ...parts);
159
+ if (directory) {
160
+ await mkdir(output, {
161
+ recursive: true,
162
+ mode: 448
163
+ });
164
+ entry.resume();
165
+ } else {
166
+ await mkdir(dirname(output), {
167
+ recursive: true,
168
+ mode: 448
169
+ });
170
+ await pipeline(entry, createWriteStream(output, {
171
+ flags: "wx",
172
+ mode: 384
173
+ }), { signal: extractionSignal });
174
+ }
175
+ }
176
+ const destination = new Writable({
177
+ write(chunk, _encoding, callback) {
178
+ if (ended) {
179
+ callback();
180
+ return;
181
+ }
182
+ try {
183
+ if (extractor.write(chunk)) callback();
184
+ else extractor.once("drain", callback);
185
+ } catch (error) {
186
+ callback(error instanceof Error ? error : new Error(String(error)));
187
+ }
188
+ },
189
+ final(callback) {
190
+ extractor.once("end", callback);
191
+ try {
192
+ extractor.end();
193
+ } catch (error) {
194
+ callback(error instanceof Error ? error : new Error(String(error)));
195
+ }
196
+ }
197
+ });
198
+ extractor.on("eof", () => {
199
+ ended = true;
200
+ });
201
+ extractor.on("error", (error) => destination.destroy(error));
202
+ extractor.on("ignoredEntry", () => destination.destroy(integrity("Index archive contains an unsupported or oversized member.")));
203
+ const limit = new Transform({ transform(chunk, _encoding, callback) {
204
+ expanded += chunk.length;
205
+ callback(expanded > 8 * 1024 ** 3 + 1024e5 ? integrity("Index archive decompression exceeds the size limit.") : null, chunk);
206
+ } });
207
+ try {
208
+ await pipeline(createReadStream(archive), createGunzip(), limit, destination, { signal: extractionSignal });
209
+ await Promise.all(jobs);
210
+ if (!(await lstat(join(target, "documents.lance"))).isDirectory()) throw integrity("Index archive must contain the documents LanceDB table.");
211
+ signal?.throwIfAborted();
212
+ return target;
213
+ } catch (error) {
214
+ cancellation.abort(error);
215
+ await Promise.allSettled(jobs);
216
+ await discard(target);
217
+ signal?.throwIfAborted();
218
+ if (cancellation.signal.reason instanceof CatalogError) throw cancellation.signal.reason;
219
+ if (error instanceof CatalogError) throw error;
220
+ throw integrity("Index archive could not be extracted as a complete LanceDB database.");
221
+ }
222
+ }
223
+ function portablePath(path, directory) {
224
+ const normalized = directory && path.endsWith("/") ? path.slice(0, -1) : path;
225
+ const parts = normalized.split("/");
226
+ if (Buffer.byteLength(normalized) > 4096 || parts.length > 64 || parts.some((part) => !part || Buffer.byteLength(part) > 255 || part === "." || part === ".." || /[\p{Cc}\\:<>"|?*]/u.test(part) || /[. ]$/.test(part) || /^(?:CON|PRN|AUX|NUL|CONIN\$|CONOUT\$|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(part.normalize("NFKC"))) || parts[0]?.normalize("NFKC").toUpperCase() === ".COMPLETE") throw integrity("Index archive contains an unsafe path.");
227
+ return parts;
228
+ }
229
+ async function safeDirectory(path) {
230
+ try {
231
+ await mkdir(path);
232
+ } catch (error) {
233
+ if (!(error instanceof Error && "code" in error && error.code === "EEXIST")) throw error;
234
+ }
235
+ if (!(await lstat(path)).isDirectory()) throw integrity("Index cache path must be a directory, not a link.");
236
+ }
237
+ async function seal(root, signal) {
238
+ signal?.throwIfAborted();
239
+ if ((await lstat(root)).isDirectory()) {
240
+ for (const name of await readdir(root)) await seal(join(root, name), signal);
241
+ await chmod(root, 365);
242
+ } else await chmod(root, 292);
243
+ }
244
+ async function discard(root) {
245
+ try {
246
+ if ((await lstat(root)).isDirectory()) {
247
+ await chmod(root, 448);
248
+ for (const name of await readdir(root)) await discard(join(root, name));
249
+ }
250
+ await rm(root, {
251
+ recursive: true,
252
+ force: true
253
+ });
254
+ } catch (error) {
255
+ if (!(error instanceof Error && isMissing(error))) throw error;
256
+ }
257
+ }
258
+ function isMissing(error) {
259
+ return "code" in error && error.code === "ENOENT";
260
+ }
261
+ function integrity(message) {
262
+ return new CatalogError(message, { code: "integrity" });
263
+ }
264
+ async function wait(operation, active, signal) {
265
+ if (!signal) return operation;
266
+ signal.throwIfAborted();
267
+ let abort = () => {};
268
+ try {
269
+ return await Promise.race([operation, new Promise((_resolve, reject) => {
270
+ abort = () => {
271
+ if (!active()) reject(signal.reason);
272
+ };
273
+ signal.addEventListener("abort", abort, { once: true });
274
+ })]);
275
+ } finally {
276
+ signal.removeEventListener("abort", abort);
277
+ }
278
+ }
279
+ //#endregion
280
+ export { extractIndex };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,40 @@
1
- export { Catalog, type CatalogOptions, type Guideline, type GuidelineSection, } from "./catalog/model.js";
2
- export { CatalogError } from "./catalog/errors.js";
3
- export { CHARTCOACH_DEFAULTS, DEFAULT_CATALOG, catalogArtifact, catalogArtifactUrl, parseCatalogReleaseMetadata, type ArtifactDescriptor, type ArtifactKind, type CatalogReleaseMetadata, type ChartCoachDefaults, } from "./catalog/artifacts.js";
4
- export { loadCatalog, type AsyncBuffer, type CatalogBytes, type LoadCatalogInput, type ParquetBytes, } from "./catalog/load-parquet-core.js";
5
- export { type CatalogManifest, type ManifestDefinition, parseCatalogManifest, } from "./catalog/manifest.js";
6
- export { parseLabel, type CatalogLabel } from "./catalog/labels.js";
7
- export { toMarkdown } from "./catalog/markdown.js";
8
- //# sourceMappingURL=index.d.ts.map
1
+ import { A as parseProfileMetadata, C as CatalogRelease, D as EmbeddingBinding, E as DistanceMetric, F as JsonValue, M as ManifestDefinition, N as parseCatalogManifest, O as ProfileMetadata, P as JsonObject, S as TableName, T as parseCatalogRelease, _ as DescribeOptions, a as GuidelineSection, b as TableColumnInfo, c as SourceDetail, d as CiteOptions, f as FullSourceRecord, g as CatalogInfo, h as QueryOptions, i as GuidelineInput, j as CatalogManifest, k as ProjectionMetadata, l as CitationRecord, m as EntryCandidate, n as Catalog, o as GuidelineEntryRecord, p as MinimalSourceRecord, r as Guideline, s as ReadOptions, t as ArtifactOptions, u as CitationSource, v as ProfileInfo, w as ReleaseArtifact, x as TableInfo, y as CatalogTables } from "./model-De0MF-zg.js";
2
+ import { i as openCatalog, n as FetchLike, r as OpenCatalogOptions, t as ArtifactCache } from "./open-Nnzkr_bE.js";
3
+ //#region src/catalog/errors.d.ts
4
+ type CatalogErrorCode = "lookup" | "invalid_input" | "integrity" | "unavailable_capability" | "incompatible_profile" | "embedding_failure" | "operation_failed" | "response_too_large";
5
+ type CatalogErrorOptions = Readonly<{
6
+ code?: CatalogErrorCode;
7
+ details?: JsonObject;
8
+ hints?: readonly string[];
9
+ }>;
10
+ declare class CatalogError extends Error {
11
+ readonly code: CatalogErrorCode;
12
+ readonly details: Readonly<JsonObject>;
13
+ readonly hints: readonly string[];
14
+ constructor(message: string, options?: CatalogErrorOptions);
15
+ }
16
+ //#endregion
17
+ //#region src/catalog/parquet.d.ts
18
+ type AsyncBuffer = {
19
+ byteLength: number;
20
+ slice(start: number, end?: number): ArrayBuffer | Promise<ArrayBuffer>;
21
+ };
22
+ type ParquetBytes = ArrayBuffer | ArrayBufferView;
23
+ type CatalogBytes = ParquetBytes | AsyncBuffer;
24
+ type LoadCatalogDataInput = {
25
+ entries: CatalogBytes;
26
+ manifestText: string;
27
+ };
28
+ type LoadCatalogInput = {
29
+ entries: ParquetBytes;
30
+ manifest: ParquetBytes;
31
+ release: CatalogRelease;
32
+ releaseUrl: string | URL;
33
+ };
34
+ declare function loadCatalog(input: LoadCatalogInput): Promise<Catalog>;
35
+ declare function loadCatalogData(input: LoadCatalogDataInput): Promise<Catalog>;
36
+ //#endregion
37
+ //#region src/catalog/markdown.d.ts
38
+ declare function toMarkdown(guideline: Pick<Guideline, "id" | "title" | "description" | "labels" | "body">): string;
39
+ //#endregion
40
+ export { type ArtifactCache, type ArtifactOptions, Catalog, CatalogError, type CatalogErrorCode, type CatalogErrorOptions, type CatalogInfo, type CatalogManifest, type CatalogRelease, type CatalogTables, type CitationRecord, type CitationSource, type CiteOptions, type DescribeOptions, type DistanceMetric, type EmbeddingBinding, type EntryCandidate, type FetchLike, type FullSourceRecord, type Guideline, type GuidelineEntryRecord, type GuidelineInput, type GuidelineSection, type JsonObject, type JsonValue, type LoadCatalogDataInput, type LoadCatalogInput, type ManifestDefinition, type MinimalSourceRecord, type OpenCatalogOptions, type ProfileInfo, type ProfileMetadata, type ProjectionMetadata, type QueryOptions, type ReadOptions, type ReleaseArtifact, type SourceDetail, type TableColumnInfo, type TableInfo, type TableName, loadCatalog, loadCatalogData, openCatalog, parseCatalogManifest, parseCatalogRelease, parseProfileMetadata, toMarkdown };
package/dist/index.js CHANGED
@@ -1,7 +1,22 @@
1
- export { Catalog, } from "./catalog/model.js";
2
- export { CatalogError } from "./catalog/errors.js";
3
- export { CHARTCOACH_DEFAULTS, DEFAULT_CATALOG, catalogArtifact, catalogArtifactUrl, parseCatalogReleaseMetadata, } from "./catalog/artifacts.js";
4
- export { loadCatalog, } from "./catalog/load-parquet-core.js";
5
- export { parseCatalogManifest, } from "./catalog/manifest.js";
6
- export { parseLabel } from "./catalog/labels.js";
7
- export { toMarkdown } from "./catalog/markdown.js";
1
+ import { a as CatalogError } from "./json-CBWjz9b4.js";
2
+ import { a as Catalog, i as loadCatalogData, l as parseCatalogManifest, n as parseProfileMetadata, r as loadCatalog, s as parseCatalogRelease, t as openCatalog } from "./open-Uu3-r8kp.js";
3
+ import { stringify } from "yaml";
4
+ //#region src/catalog/markdown.ts
5
+ function toMarkdown(guideline) {
6
+ const frontmatter = {
7
+ id: guideline.id,
8
+ title: guideline.title,
9
+ description: guideline.description,
10
+ labels: [...guideline.labels]
11
+ };
12
+ return [
13
+ "---",
14
+ stringify(frontmatter, { sortMapEntries: false }).trim(),
15
+ "---",
16
+ "",
17
+ guideline.body.trim(),
18
+ ""
19
+ ].join("\n");
20
+ }
21
+ //#endregion
22
+ export { Catalog, CatalogError, loadCatalog, loadCatalogData, openCatalog, parseCatalogManifest, parseCatalogRelease, parseProfileMetadata, toMarkdown };
@@ -0,0 +1,29 @@
1
+ //#region src/catalog/errors.ts
2
+ var CatalogError = class extends Error {
3
+ code;
4
+ details;
5
+ hints;
6
+ constructor(message, options = {}) {
7
+ super(message);
8
+ this.name = "CatalogError";
9
+ this.code = options.code ?? "invalid_input";
10
+ this.details = Object.freeze({ ...options.details });
11
+ this.hints = Object.freeze([...options.hints ?? []]);
12
+ }
13
+ };
14
+ //#endregion
15
+ //#region src/catalog/json.ts
16
+ function parseJson(text) {
17
+ return JSON.parse(text);
18
+ }
19
+ function isJsonObject(value) {
20
+ return value !== null && value !== void 0 && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
21
+ }
22
+ function isJsonNumber(value) {
23
+ return Object.prototype.toString.call(value) === "[object Number]" && value === value?.valueOf() && Number.isFinite(value);
24
+ }
25
+ function isJsonString(value) {
26
+ return Object.prototype.toString.call(value) === "[object String]" && value === value?.valueOf();
27
+ }
28
+ //#endregion
29
+ export { CatalogError as a, parseJson as i, isJsonObject as n, isJsonString as r, isJsonNumber as t };
@@ -0,0 +1,255 @@
1
+ //#region src/catalog/json.d.ts
2
+ type JsonScalar = boolean | null | number | string;
3
+ interface JsonObject {
4
+ [key: string]: JsonValue;
5
+ }
6
+ type JsonValue = JsonScalar | JsonObject | readonly JsonValue[];
7
+ //#endregion
8
+ //#region src/catalog/manifest.d.ts
9
+ type ManifestDefinition = {
10
+ readonly name: string;
11
+ readonly description: string;
12
+ readonly examples: readonly string[];
13
+ };
14
+ type CatalogManifest = {
15
+ readonly markdown: string;
16
+ readonly sectionRoles: Readonly<Record<string, ManifestDefinition>>;
17
+ readonly labelFamilies: Readonly<Record<string, ManifestDefinition>>;
18
+ };
19
+ declare function parseCatalogManifest(markdown: string): CatalogManifest;
20
+ //#endregion
21
+ //#region src/catalog/profile.d.ts
22
+ type DistanceMetric = "cosine" | "l2" | "dot";
23
+ type EmbeddingBinding = Readonly<{
24
+ name: string;
25
+ model: Readonly<JsonObject>;
26
+ source_column: "text";
27
+ vector_column: "vector";
28
+ }>;
29
+ type ProjectionMetadata = Readonly<{
30
+ algorithm: "empty" | "linear" | "umap";
31
+ options: Readonly<JsonObject>;
32
+ }>;
33
+ type ProfileMetadata = Readonly<{
34
+ schema_version: 1;
35
+ documents_version: 1;
36
+ entries_digest: string;
37
+ manifest_digest: string;
38
+ embedding_functions: readonly [EmbeddingBinding];
39
+ dimensions: number;
40
+ distance_metric: DistanceMetric;
41
+ python_requirements: Readonly<Record<string, string>>;
42
+ lancedb_version: string;
43
+ projection: ProjectionMetadata | null;
44
+ }>;
45
+ declare function parseProfileMetadata(value: JsonValue): ProfileMetadata;
46
+ //#endregion
47
+ //#region src/catalog/artifacts.d.ts
48
+ type ReleaseArtifact = Readonly<{
49
+ sha256: string;
50
+ bytes: number;
51
+ }>;
52
+ type CatalogRelease = Readonly<{
53
+ schema_version: 1;
54
+ digest: string;
55
+ artifacts: Readonly<Record<string, ReleaseArtifact>>;
56
+ }>;
57
+ declare function parseCatalogRelease(value: JsonValue): CatalogRelease;
58
+ //#endregion
59
+ //#region src/catalog/tables.d.ts
60
+ type ReferenceRow = Readonly<{
61
+ id: string;
62
+ source_type: string | null;
63
+ authors: readonly string[];
64
+ authors_text: string | null;
65
+ year: string | null;
66
+ title: string | null;
67
+ journal: string | null;
68
+ booktitle: string | null;
69
+ publisher: string | null;
70
+ url: string | null;
71
+ doi: string | null;
72
+ bibtex: string;
73
+ }>;
74
+ type GuidelineReferenceRow = Readonly<{
75
+ guideline_id: string;
76
+ reference_id: string;
77
+ }>;
78
+ type CatalogTables = Readonly<{
79
+ guidelines: readonly Omit<Guideline, "references">[];
80
+ sections: readonly Readonly<GuidelineSection & {
81
+ guideline_id: string;
82
+ }>[];
83
+ guideline_labels: readonly Readonly<{
84
+ guideline_id: string;
85
+ label: string;
86
+ family: string;
87
+ category: string;
88
+ modifier: string | null;
89
+ }>[];
90
+ references: readonly ReferenceRow[];
91
+ guideline_references: readonly GuidelineReferenceRow[];
92
+ guideline_sources: readonly Readonly<Omit<ReferenceRow, "id" | "title"> & GuidelineReferenceRow & {
93
+ source_title: string | null;
94
+ }>[];
95
+ }>;
96
+ type TableName = keyof CatalogTables;
97
+ type TableColumnInfo = Readonly<{
98
+ name: string;
99
+ type: "String" | "List(String)" | "List(Struct({'role': String, 'title': String, 'content': String}))";
100
+ }>;
101
+ type TableInfo = Readonly<{
102
+ name: TableName;
103
+ rows: number;
104
+ columns: readonly TableColumnInfo[];
105
+ }>;
106
+ //#endregion
107
+ //#region src/catalog/description.d.ts
108
+ type DescribeOptions = Readonly<{
109
+ profile?: string;
110
+ signal?: AbortSignal;
111
+ }>;
112
+ type ProfileInfo = Readonly<{
113
+ name: string;
114
+ profile_schema_version: 1;
115
+ documents_version: 1;
116
+ embedding_functions: ProfileMetadata["embedding_functions"];
117
+ dimensions: number;
118
+ distance_metric: ProfileMetadata["distance_metric"];
119
+ python_requirements: ProfileMetadata["python_requirements"];
120
+ lancedb_version: string;
121
+ projection: ProfileMetadata["projection"];
122
+ }>;
123
+ type CatalogInfo = Readonly<{
124
+ resolved_location: string | null;
125
+ release_digest: string | null;
126
+ entries_digest: string;
127
+ manifest_digest: string;
128
+ tables: readonly TableInfo[];
129
+ section_roles: readonly ManifestDefinition[];
130
+ label_families: readonly ManifestDefinition[];
131
+ profiles: readonly string[];
132
+ profile: ProfileInfo | null;
133
+ }>;
134
+ //#endregion
135
+ //#region src/catalog/query.d.ts
136
+ type QueryOptions = Readonly<{
137
+ ids?: readonly string[];
138
+ labels?: readonly string[];
139
+ labelPrefixes?: readonly string[];
140
+ contains?: string;
141
+ limit?: number;
142
+ }>;
143
+ type EntryCandidate = Readonly<{
144
+ id: string;
145
+ title: string;
146
+ description: string;
147
+ labels: readonly string[];
148
+ }>;
149
+ //#endregion
150
+ //#region src/catalog/references.d.ts
151
+ type MinimalSourceRecord = Readonly<{
152
+ reference_id: string;
153
+ authors_text: string | null;
154
+ year: string | null;
155
+ source_title: string | null;
156
+ doi: string | null;
157
+ url: string | null;
158
+ }>;
159
+ type FullSourceRecord = Readonly<{
160
+ guideline_id: string;
161
+ reference_id: string;
162
+ source_type: string | null;
163
+ authors: readonly string[];
164
+ authors_text: string | null;
165
+ year: string | null;
166
+ source_title: string | null;
167
+ journal: string | null;
168
+ booktitle: string | null;
169
+ publisher: string | null;
170
+ url: string | null;
171
+ doi: string | null;
172
+ }>;
173
+ type CitationSource = Readonly<{
174
+ reference_id: string;
175
+ source_type: string | null;
176
+ authors_text: string | null;
177
+ year: string | null;
178
+ source_title: string | null;
179
+ journal: string | null;
180
+ booktitle: string | null;
181
+ publisher: string | null;
182
+ doi: string | null;
183
+ url: string | null;
184
+ citation: string;
185
+ }>;
186
+ type CiteOptions = Readonly<{
187
+ ids: readonly string[];
188
+ urlTemplate?: string;
189
+ }>;
190
+ type CitationRecord = Readonly<{
191
+ id: string;
192
+ title: string;
193
+ url: string;
194
+ guideline_citation: string;
195
+ sources: readonly CitationSource[];
196
+ }>;
197
+ //#endregion
198
+ //#region src/catalog/read.d.ts
199
+ type SourceDetail = "none" | "minimal" | "full";
200
+ type ReadOptions = Readonly<{
201
+ ids: readonly string[];
202
+ roles?: readonly string[];
203
+ sourceDetail?: SourceDetail;
204
+ }>;
205
+ type GuidelineEntryRecord = Readonly<{
206
+ id: string;
207
+ title: string;
208
+ description: string;
209
+ labels: readonly string[];
210
+ sections: readonly GuidelineSection[];
211
+ sources: readonly (MinimalSourceRecord | FullSourceRecord)[];
212
+ references?: readonly string[];
213
+ }>;
214
+ //#endregion
215
+ //#region src/catalog/model.d.ts
216
+ type GuidelineSection = Readonly<{
217
+ role: string;
218
+ title: string;
219
+ content: string;
220
+ }>;
221
+ type Guideline = Readonly<{
222
+ id: string;
223
+ title: string;
224
+ description: string;
225
+ labels: readonly string[];
226
+ body: string;
227
+ sections: readonly GuidelineSection[];
228
+ references: readonly string[];
229
+ }>;
230
+ type GuidelineInput = Omit<Guideline, "body">;
231
+ type ArtifactOptions = Readonly<{
232
+ signal?: AbortSignal;
233
+ }>;
234
+ declare class Catalog implements Iterable<Guideline> {
235
+ readonly guidelines: readonly Guideline[];
236
+ readonly manifest: CatalogManifest;
237
+ private readonly byId;
238
+ constructor(guidelines: Iterable<GuidelineInput>, manifest: CatalogManifest);
239
+ get release(): CatalogRelease | undefined;
240
+ get releaseUrl(): string | undefined;
241
+ get length(): number;
242
+ artifact(path: string, options?: ArtifactOptions): Promise<Uint8Array>;
243
+ get(id: string): Guideline | undefined;
244
+ require(id: string): Guideline;
245
+ query(options?: QueryOptions): readonly EntryCandidate[];
246
+ read(options: ReadOptions): readonly GuidelineEntryRecord[];
247
+ cite(options: CiteOptions): readonly CitationRecord[];
248
+ table<Name extends TableName>(name: Name): CatalogTables[Name];
249
+ labels(): string[];
250
+ sectionRoles(): string[];
251
+ describe(options?: DescribeOptions): Promise<CatalogInfo>;
252
+ [Symbol.iterator](): IterableIterator<Guideline>;
253
+ }
254
+ //#endregion
255
+ export { parseProfileMetadata as A, CatalogRelease as C, EmbeddingBinding as D, DistanceMetric as E, JsonValue as F, ManifestDefinition as M, parseCatalogManifest as N, ProfileMetadata as O, JsonObject as P, TableName as S, parseCatalogRelease as T, DescribeOptions as _, GuidelineSection as a, TableColumnInfo as b, SourceDetail as c, CiteOptions as d, FullSourceRecord as f, CatalogInfo as g, QueryOptions as h, GuidelineInput as i, CatalogManifest as j, ProjectionMetadata as k, CitationRecord as l, EntryCandidate as m, Catalog as n, GuidelineEntryRecord as o, MinimalSourceRecord as p, Guideline as r, ReadOptions as s, ArtifactOptions as t, CitationSource as u, ProfileInfo as v, ReleaseArtifact as w, TableInfo as x, CatalogTables as y };
package/dist/node.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { n as Catalog, t as ArtifactOptions } from "./model-De0MF-zg.js";
2
+ import { r as OpenCatalogOptions } from "./open-Nnzkr_bE.js";
3
+ //#region src/node.d.ts
4
+ type NodeOpenCatalogOptions = OpenCatalogOptions & {
5
+ cacheDirectory?: string;
6
+ };
7
+ type IndexPathOptions = ArtifactOptions & {
8
+ directory?: string;
9
+ };
10
+ /** Return a verified profile's extracted database directory for native LanceDB clients. */
11
+ declare function indexPath(catalog: Catalog, profile: string, options?: IndexPathOptions): Promise<string>;
12
+ declare function openCatalog(location?: string | URL, options?: NodeOpenCatalogOptions): Promise<Catalog>;
13
+ declare function artifactPath(catalog: Catalog, path: string, options?: ArtifactOptions): Promise<string>;
14
+ //#endregion
15
+ export { IndexPathOptions, NodeOpenCatalogOptions, artifactPath, indexPath, openCatalog };