@chartcoach/catalog 0.1.7 → 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 (72) hide show
  1. package/README.md +324 -38
  2. package/dist/duckdb-wasm.d.ts +8 -0
  3. package/dist/duckdb-wasm.js +22 -0
  4. package/dist/duckdb.d.ts +8 -0
  5. package/dist/duckdb.js +9 -0
  6. package/dist/index-cache-Cx1gIK6N.js +280 -0
  7. package/dist/index.d.ts +40 -8
  8. package/dist/index.js +22 -7
  9. package/dist/json-CBWjz9b4.js +29 -0
  10. package/dist/model-De0MF-zg.d.ts +255 -0
  11. package/dist/node.d.ts +15 -0
  12. package/dist/node.js +218 -0
  13. package/dist/open-Nnzkr_bE.d.ts +15 -0
  14. package/dist/open-Uu3-r8kp.js +1244 -0
  15. package/dist/registration-CgQGMUIH.d.ts +6 -0
  16. package/dist/registration-DXhS7vgr.js +41 -0
  17. package/dist/tables-DcgKnXwF.js +389 -0
  18. package/package.json +47 -18
  19. package/src/catalog/artifacts.ts +309 -100
  20. package/src/catalog/description.ts +198 -0
  21. package/src/catalog/errors.ts +26 -1
  22. package/src/catalog/identity.ts +69 -0
  23. package/src/catalog/json.ts +32 -0
  24. package/src/catalog/labels.ts +8 -6
  25. package/src/catalog/manifest.ts +81 -20
  26. package/src/catalog/markdown.ts +2 -2
  27. package/src/catalog/model.ts +222 -37
  28. package/src/catalog/open.ts +428 -0
  29. package/src/catalog/parquet.ts +164 -0
  30. package/src/catalog/profile-layout.ts +86 -0
  31. package/src/catalog/profile.ts +345 -0
  32. package/src/catalog/query.ts +125 -0
  33. package/src/catalog/read.ts +101 -0
  34. package/src/catalog/references.ts +336 -0
  35. package/src/catalog/registration.ts +74 -0
  36. package/src/catalog/tables.ts +250 -0
  37. package/src/catalog/wire.ts +38 -65
  38. package/src/duckdb-wasm.ts +33 -0
  39. package/src/duckdb.ts +18 -0
  40. package/src/index.ts +51 -20
  41. package/src/node/index-cache.ts +432 -0
  42. package/src/node.ts +347 -0
  43. package/dist/catalog/artifacts.d.ts +0 -28
  44. package/dist/catalog/artifacts.d.ts.map +0 -1
  45. package/dist/catalog/artifacts.js +0 -89
  46. package/dist/catalog/chartcoach-defaults.d.ts +0 -17
  47. package/dist/catalog/chartcoach-defaults.d.ts.map +0 -1
  48. package/dist/catalog/chartcoach-defaults.js +0 -8
  49. package/dist/catalog/errors.d.ts +0 -4
  50. package/dist/catalog/errors.d.ts.map +0 -1
  51. package/dist/catalog/errors.js +0 -6
  52. package/dist/catalog/labels.d.ts +0 -9
  53. package/dist/catalog/labels.d.ts.map +0 -1
  54. package/dist/catalog/labels.js +0 -23
  55. package/dist/catalog/load-parquet-core.d.ts +0 -15
  56. package/dist/catalog/load-parquet-core.d.ts.map +0 -1
  57. package/dist/catalog/load-parquet-core.js +0 -45
  58. package/dist/catalog/manifest.d.ts +0 -15
  59. package/dist/catalog/manifest.d.ts.map +0 -1
  60. package/dist/catalog/manifest.js +0 -143
  61. package/dist/catalog/markdown.d.ts +0 -3
  62. package/dist/catalog/markdown.d.ts.map +0 -1
  63. package/dist/catalog/markdown.js +0 -13
  64. package/dist/catalog/model.d.ts +0 -33
  65. package/dist/catalog/model.d.ts.map +0 -1
  66. package/dist/catalog/model.js +0 -67
  67. package/dist/catalog/wire.d.ts +0 -18
  68. package/dist/catalog/wire.d.ts.map +0 -1
  69. package/dist/catalog/wire.js +0 -78
  70. package/dist/index.d.ts.map +0 -1
  71. package/src/catalog/chartcoach-defaults.ts +0 -17
  72. package/src/catalog/load-parquet-core.ts +0 -78
package/README.md CHANGED
@@ -1,67 +1,353 @@
1
1
  # @chartcoach/catalog
2
2
 
3
- JavaScript models and parsers for chartcoach catalog artifacts.
3
+ `@chartcoach/catalog` fetches a selected or exact Guideline Catalog release,
4
+ verifies its files, and returns immutable `Guideline` values for querying,
5
+ reading, and citation.
4
6
 
5
- Read the package docs at [docs.chartcoach.dev/javascript](https://docs.chartcoach.dev/javascript).
6
- Read about the cataloging scheme at [docs.chartcoach.dev/catalog](https://docs.chartcoach.dev/catalog).
7
+ chartcoach is alpha software. `openCatalog` requires a browser or server
8
+ runtime with `fetch`, Web Crypto, `AbortSignal.timeout`, and `AbortSignal.any`.
9
+ Node.js consumers require Node 22.19 or later.
10
+ `loadCatalog` verifies release files that the application already holds.
11
+ `loadCatalogData` parses descriptor-free bundle data.
7
12
 
8
- Install the package from an application root:
13
+ ## Query and read guidance
9
14
 
10
15
  ```bash
11
16
  npm install @chartcoach/catalog
12
17
  ```
13
18
 
14
19
  ```ts
15
- import { DEFAULT_CATALOG, loadCatalog } from "@chartcoach/catalog"
20
+ import { openCatalog } from "@chartcoach/catalog";
16
21
 
17
- const entries = await (await fetch(DEFAULT_CATALOG.entriesUrl)).arrayBuffer()
18
- const manifestText = await (await fetch(DEFAULT_CATALOG.manifestUrl)).text()
22
+ const catalog = await openCatalog();
23
+ const candidates = catalog.query({ contains: "direct labels", limit: 5 });
24
+ const ids = candidates.map(({ id }) => id);
25
+ const records = catalog.read({ ids, sourceDetail: "minimal" });
26
+ const citations = catalog.cite({ ids });
27
+ const info = await catalog.describe();
19
28
 
20
- const catalog = await loadCatalog({ entries, manifestText })
21
- const guideline = catalog.require("compare-percentages-with-bars-not-pies")
29
+ console.log(records[0]?.title);
22
30
  ```
23
31
 
24
- `@chartcoach/catalog` accepts bytes that the caller already acquired. Use
25
- `fetch`, `fs.readFile`, `Bun.file`, `Deno.readFile`, or a test fixture to read
26
- the artifacts, then pass `entries` and optional manifest data to `loadCatalog`.
32
+ ```text
33
+ Directly label colored series instead of relying on a color key
34
+ ```
35
+
36
+ `query`, `read`, and `cite` run synchronously over the loaded `Catalog`.
37
+ `describe` is asynchronous because it computes SHA-256 digests and can fetch
38
+ selected profile metadata.
39
+
40
+ Reference parsing and APA citations use [RefKit](https://peter-gy.github.io/refkit/).
41
+ The module initializes its WebAssembly engine during import. Browser builds must
42
+ serve RefKit's bundled `.wasm` asset at its module-relative URL. A restrictive
43
+ [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)
44
+ must allow `'wasm-unsafe-eval'` in `script-src` and the asset origin in `connect-src`.
45
+
46
+ `contains` matches a contiguous phrase in the ID, title, or description,
47
+ ignoring case and normalizing whitespace, hyphens, and underscores. For empty
48
+ matches, shorten the phrase or follow [Find guidelines](https://docs.chartcoach.dev/querying)
49
+ to query section text with the application's data engine.
50
+
51
+ ## Choose a release URL
52
+
53
+ `openCatalog(location, { fetch, signal })` accepts an absolute HTTP or HTTPS URL:
54
+
55
+ | Location | Behavior |
56
+ | -------------- | --------------------------------------------- |
57
+ | `catalog.json` | Follows the currently selected public release |
58
+ | `release.json` | Keeps one release digest across calls |
59
+ | Omitted | Opens the official selected catalog |
60
+
61
+ The loader verifies the release digest, then checks the byte count and SHA-256
62
+ hash of `MANIFEST.md` and `entries.parquet` before parsing them. Pass a custom
63
+ `fetch` implementation when the runtime does not use `globalThis.fetch`. Pass
64
+ an `AbortSignal` to cancel descriptor and artifact requests.
65
+ The returned catalog exposes the verified descriptor as `catalog.release` and
66
+ its sanitized exact `release.json` URL as `catalog.releaseUrl`.
67
+
68
+ ## Load files your app already has
69
+
70
+ `loadCatalogData` accepts Parquet bytes and manifest text:
27
71
 
28
72
  ```ts
29
- import { readFile } from "node:fs/promises"
30
- import { loadCatalog } from "@chartcoach/catalog"
73
+ import { readFile } from "node:fs/promises";
74
+ import { loadCatalogData } from "@chartcoach/catalog";
31
75
 
76
+ const catalog = await loadCatalogData({
77
+ entries: await readFile("dist/catalog/entries.parquet"),
78
+ manifestText: await readFile("dist/catalog/MANIFEST.md", "utf8"),
79
+ });
80
+ ```
81
+
82
+ `loadCatalogData` validates the manifest vocabulary and guideline fields.
83
+ Release integrity remains caller-owned because this input contains no
84
+ `release.json`.
85
+
86
+ Use `loadCatalog` when the application already has a parsed release and the
87
+ files listed by its descriptor:
88
+
89
+ ```ts
90
+ import { readFile } from "node:fs/promises";
91
+ import { pathToFileURL } from "node:url";
92
+ import { loadCatalog, parseCatalogRelease } from "@chartcoach/catalog";
93
+
94
+ const releasePath = "dist/release/release.json";
95
+ const release = parseCatalogRelease(JSON.parse(await readFile(releasePath, "utf8")));
32
96
  const catalog = await loadCatalog({
33
- entries: await readFile("entries.parquet"),
34
- manifestText: await readFile("MANIFEST.md", "utf8"),
35
- })
97
+ release,
98
+ releaseUrl: pathToFileURL(releasePath),
99
+ entries: await readFile("dist/release/entries.parquet"),
100
+ manifest: await readFile("dist/release/MANIFEST.md"),
101
+ });
102
+ ```
103
+
104
+ `loadCatalog` verifies the release digest and both core files before returning
105
+ a catalog with its exact release URL. Each core file is capped at 64 MiB.
106
+
107
+ ## Catalog methods
108
+
109
+ | Method | Result |
110
+ | -------------------------------------- | -------------------------------------------------------------------------------- |
111
+ | `query(options?)` | Compact guideline entry candidates. The default limit is 50. |
112
+ | `read({ ids, roles?, sourceDetail? })` | Guideline entry records with ordered sections and parsed sources. |
113
+ | `cite({ ids, urlTemplate? })` | Guideline links, formatted guideline citations, and structured source citations. |
114
+ | `table(name)` | Cached, immutable rows for a canonical catalog table. |
115
+ | `describe({ profile?, signal? })` | Catalog identity, table schemas and counts, vocabulary, and profile information. |
116
+ | `get(id)` | A `Guideline` or `undefined`. |
117
+ | `require(id)` | A `Guideline` or a `CatalogError` with code `"lookup"`. |
118
+
119
+ `catalog.guidelines`, iteration, `catalog.length`, `catalog.labels()`,
120
+ `catalog.sectionRoles()`, `catalog.release`, `catalog.releaseUrl`, and
121
+ `toMarkdown(guideline)` support direct application composition.
122
+
123
+ JavaScript option names use camel case. Shared JSON result fields use snake
124
+ case, including `source_title`, `reference_id`, and `release_digest`.
125
+
126
+ ## Query canonical tables
127
+
128
+ `catalog.table(name)` exposes the same six relations as Python: `guidelines`,
129
+ `sections`, `guideline_labels`, `references`, `guideline_references`, and
130
+ `guideline_sources`. Rows and nested values are immutable. Unknown names raise
131
+ `CatalogError` with code `"lookup"`. `describe().tables` supplies names, row counts,
132
+ and logical column types, including for empty tables.
133
+
134
+ ```ts
135
+ const sources = catalog.table("guideline_sources");
136
+ console.log(sources[0]?.authors);
137
+ console.log((await catalog.describe()).tables);
138
+ ```
139
+
140
+ For native SQL, install [DuckDB's Node.js client](https://duckdb.org/docs/stable/clients/node_neo/overview)
141
+ alongside the catalog package:
142
+
143
+ ```bash
144
+ npm install @chartcoach/catalog @duckdb/node-api
145
+ ```
146
+
147
+ ```ts
148
+ import { DuckDBInstance } from "@duckdb/node-api";
149
+ import { registerCatalog } from "@chartcoach/catalog/duckdb";
150
+
151
+ const db = await DuckDBInstance.create(":memory:");
152
+ const connection = await db.connect();
153
+ try {
154
+ await registerCatalog(connection, catalog);
155
+ const result = await connection.runAndReadAll(
156
+ 'SELECT source_type, count(*) FROM "references" GROUP BY source_type',
157
+ );
158
+ console.log(result.getRowsJson());
159
+ } finally {
160
+ connection.closeSync();
161
+ db.closeSync();
162
+ }
163
+ ```
164
+
165
+ `registerCatalog(connection, catalog, { ids? })` creates or replaces the six
166
+ catalog tables and returns the same connection. The caller owns configuration,
167
+ transactions, and closing. Omit `ids` for the full catalog. An empty array creates
168
+ six empty typed tables. Selected IDs retain all their linked source records.
169
+ Unknown IDs and invalid references fail before table replacement.
170
+
171
+ ## Query in the browser with DuckDB-WASM
172
+
173
+ The optional `@chartcoach/catalog/duckdb-wasm` adapter registers the same six
174
+ tables in a caller-owned [DuckDB-WASM](https://duckdb.org/docs/stable/clients/wasm/overview)
175
+ connection. DuckDB-WASM runs SQL in a browser worker. With a loaded `catalog` and
176
+ an `AsyncDuckDBConnection` named `connection`:
177
+
178
+ ```ts
179
+ import { registerCatalog } from "@chartcoach/catalog/duckdb-wasm";
180
+
181
+ await registerCatalog(connection, catalog, { ids });
182
+ const result = await connection.query('SELECT * FROM "references"');
183
+ console.log(result.toArray());
184
+ ```
185
+
186
+ Install `@duckdb/duckdb-wasm` alongside this package. The adapter accepts the same
187
+ `{ ids? }` option as the Node adapter and preserves caller-owned connections and
188
+ transactions. It releases its temporary in-memory files after registration.
189
+ The caller owns worker creation and database shutdown.
190
+
191
+ Catalog artifacts can also be read directly by DuckDB. Use the verified bytes
192
+ already retained by a release-backed catalog:
193
+
194
+ ```ts
195
+ await connection.bindings.registerFileBuffer(
196
+ "entries.parquet",
197
+ await catalog.artifact("entries.parquet"),
198
+ );
199
+ const rows = await connection.query(
200
+ "SELECT id, title FROM read_parquet('entries.parquet') LIMIT 5",
201
+ );
202
+ console.log(rows.toArray());
203
+ await connection.bindings.dropFile("entries.parquet");
204
+ ```
205
+
206
+ Use DuckDB's EH bundle in a browser with WebAssembly exception handling, and serve
207
+ its worker and WASM assets through your application. Its
208
+ first JSON query loads a version-matched extension from `extensions.duckdb.org`
209
+ unless you configure another extension repository. Your Content Security Policy
210
+ must permit WASM compilation, workers, and that extension origin. The
211
+ [chat app](../../apps/chat) demonstrates same-origin assets, verified HTTPS
212
+ Parquet loading, and linked filters with Mosaic.
213
+
214
+ ## Inspect a profile
215
+
216
+ ```ts
217
+ const info = await catalog.describe();
218
+ const profile = info.profiles[0];
219
+
220
+ if (profile !== undefined) {
221
+ const controller = new AbortController();
222
+ const details = await catalog.describe({ profile, signal: controller.signal });
223
+ console.log(details.profile?.distance_metric, details.profile?.dimensions);
224
+ }
36
225
  ```
37
226
 
38
- Parse release metadata when code needs artifact URLs:
227
+ `describe({ profile })` verifies `profile.json` against the release byte count,
228
+ SHA-256 hash, 64 KiB limit, catalog entries digest, and manifest digest. It
229
+ keeps the index unopened and caches verified metadata per `Catalog` instance.
230
+ Each call has its own cancellation signal.
231
+
232
+ `ProfileInfo` contains the profile and document schema versions, embedding
233
+ binding, dimensions, `distance_metric`, `python_requirements`, LanceDB version,
234
+ and projection metadata.
235
+
236
+ Catalogs created with `loadCatalog` retain the release descriptor and profile
237
+ names from caller-held bytes. Use `openCatalog` to fetch profile metadata over
238
+ HTTP.
239
+
240
+ `Guideline` values, operation results, their nested arrays, and manifest
241
+ definitions are frozen. Pass changed record objects to a new `Catalog`. Use
242
+ `loadCatalogData` after writing changed rows to `entries.parquet`.
243
+
244
+ `CatalogError` exposes `code`, `details`, and `hints`. Its codes use the shared
245
+ Python and JavaScript error vocabulary.
246
+
247
+ ## Compose verified artifacts
39
248
 
40
249
  ```ts
41
- import {
42
- catalogArtifact,
43
- catalogArtifactUrl,
44
- parseCatalogReleaseMetadata,
45
- } from "@chartcoach/catalog"
46
-
47
- const metadata = parseCatalogReleaseMetadata(await response.json())
48
- const entriesUrl = catalogArtifactUrl(
49
- metadataUrl,
50
- catalogArtifact(metadata, "entries"),
51
- )
52
-
53
- const entries = await (await fetch(entriesUrl)).arrayBuffer()
250
+ const entries = await catalog.artifact("entries.parquet");
251
+ const paths = Object.keys(catalog.release?.artifacts ?? {});
54
252
  ```
55
253
 
56
- Run package checks from the repository root:
254
+ `artifact(path, { signal? })` returns a caller-owned `Uint8Array` after checking
255
+ its byte count and SHA-256 hash. The release inventory lists optional files
256
+ such as `profiles/<profile>/documents.parquet` and
257
+ `profiles/<profile>/projection.parquet`. Pass Parquet bytes to your data library.
258
+ Core bytes and small metadata are reused in memory.
259
+ `loadCatalog` makes its supplied core bytes available through the same method.
260
+
261
+ `openCatalog` accepts an optional `cache` with asynchronous `get(sha256, bytes)` and
262
+ `put(sha256, bytes)` methods. Cached bytes are verified before reuse. A custom
263
+ `fetch` can resolve other URI schemes, including S3, using the caller's storage
264
+ client and credentials. Return a standard `Response` and forward its request
265
+ signal to the client.
266
+
267
+ ## Open local files and cache releases in Node.js
268
+
269
+ ```ts
270
+ import { openCatalog, artifactPath } from "@chartcoach/catalog/node";
271
+
272
+ const catalog = await openCatalog("./dist/release");
273
+ const entriesPath = await artifactPath(catalog, "entries.parquet");
274
+ ```
275
+
276
+ The Node entry point accepts local bundles, release directories, deployed
277
+ roots, descriptor paths, and remote descriptor URLs. It caches verified bytes
278
+ in the per-user platform cache directory, sharing the `chartcoach` cache layout
279
+ with Python. `cacheDirectory` overrides that location.
280
+ `artifactPath(catalog, path, { signal? })` streams a missing artifact to disk and
281
+ returns a verified local path for native DuckDB, Arrow, or other file readers.
282
+ It verifies an existing file before reuse. Each artifact is capped at 1 GiB,
283
+ and core files at 64 MiB.
284
+
285
+ Opening `catalog.json` refreshes the selection. A digest-addressed
286
+ `release.json` URL can reopen offline after its descriptor and core files have
287
+ been cached. Optional files become available offline after they are requested.
288
+
289
+ Use the browser entry point in browser applications. Node filesystem imports
290
+ are confined to `@chartcoach/catalog/node`.
291
+
292
+ ## Open a native search index
293
+
294
+ Install [LanceDB](https://lancedb.github.io/lancedb/js/), the application's
295
+ vector and full-text database client:
57
296
 
58
297
  ```bash
59
- pnpm --dir packages/catalog-javascript lint
60
- pnpm --dir packages/catalog-javascript typecheck
61
- pnpm --dir packages/catalog-javascript test
62
- pnpm --dir packages/catalog-javascript build
298
+ npm install @lancedb/lancedb
63
299
  ```
64
300
 
65
- ## License
301
+ Open a release built with an index profile. This example uses `./dist/release`:
302
+
303
+ ```ts
304
+ import { connect } from "@lancedb/lancedb";
305
+ import { openCatalog, indexPath } from "@chartcoach/catalog/node";
306
+
307
+ const catalog = await openCatalog("./dist/release");
308
+ const [profile] = (await catalog.describe()).profiles;
309
+ if (!profile) throw new Error("Choose a catalog release with an index profile.");
310
+
311
+ const db = await connect(await indexPath(catalog, profile));
312
+ const table = await db.openTable("documents");
313
+ try {
314
+ await table.checkout(await table.version());
315
+ const matches = await table.query().fullTextSearch("direct labels").limit(5).toArray();
316
+ const ids = [...new Set(matches.map((row) => row.parent_id))];
317
+ console.log(catalog.read({ ids }));
318
+ } finally {
319
+ table.close();
320
+ db.close();
321
+ }
322
+ ```
323
+
324
+ `indexPath(catalog, profile, { directory?, signal? })` verifies the profile and
325
+ archive, then returns an extracted database directory containing `documents.lance`.
326
+ The default extraction is a read-only generation in the catalog's cache directory
327
+ on POSIX systems. Repeated calls reuse a completed generation. Pin the native
328
+ table with `checkout` before querying shared cached data.
329
+
330
+ Pass a new `directory` for a writable, caller-owned extraction. This option is
331
+ required on Windows. Existing directories are rejected. The caller owns cleanup.
332
+ Extraction rejects unsafe paths, links, colliding names, and oversized archives.
333
+ Cancellation rejects the operation and cleans its incomplete extraction.
334
+
335
+ Use `table.vectorSearch(vector)` for application-supplied query embeddings and
336
+ `table.query().fullTextSearch(text)` for provider-free search. String-based
337
+ embedding search requires the application to configure a compatible LanceDB
338
+ embedding function. A stored Python embedding binding is not a JavaScript
339
+ provider registration.
340
+
341
+ `parseProfileMetadata(value)` validates and freezes `profile.json`. Profiles use
342
+ flat lowercase IDs such as `minilm-normalized` and contain `profile.json` plus
343
+ `index.tar.gz`. A release may also contain `documents.parquet` and
344
+ `projection.parquet` exports. The package exports `EntryCandidate`,
345
+ `GuidelineEntryRecord`, `ProfileInfo`, constructor and loader inputs, operation
346
+ options, manifest types, release types, and profile metadata types.
347
+
348
+ | Page | Details |
349
+ | ---------------------------------------------------- | ------------------------------------------------------------ |
350
+ | [JavaScript](https://docs.chartcoach.dev/javascript) | Release loading, catalog methods, and Markdown serialization |
351
+ | [Catalog data](https://docs.chartcoach.dev/catalog) | Guideline fields and published file layouts |
66
352
 
67
- Apache-2.0. See [LICENSE](../../LICENSE).
353
+ Licensed under Apache-2.0.
@@ -0,0 +1,8 @@
1
+ import { n as Catalog } from "./model-De0MF-zg.js";
2
+ import { t as RegisterCatalogOptions } from "./registration-CgQGMUIH.js";
3
+ import { AsyncDuckDBConnection } from "@duckdb/duckdb-wasm";
4
+ //#region src/duckdb-wasm.d.ts
5
+ /** Create or replace canonical catalog tables in a caller-owned DuckDB-WASM connection. */
6
+ declare function registerCatalog(connection: AsyncDuckDBConnection, catalog: Catalog, options?: RegisterCatalogOptions): Promise<AsyncDuckDBConnection>;
7
+ //#endregion
8
+ export { type RegisterCatalogOptions, registerCatalog };
@@ -0,0 +1,22 @@
1
+ import { t as registrationPlan } from "./registration-DXhS7vgr.js";
2
+ //#region src/duckdb-wasm.ts
3
+ /** Create or replace canonical catalog tables in a caller-owned DuckDB-WASM connection. */
4
+ async function registerCatalog(connection, catalog, options = {}) {
5
+ for (const { sql, rows } of registrationPlan(catalog, options, "file")) {
6
+ const file = `chartcoach-${crypto.randomUUID()}.json`;
7
+ await connection.bindings.registerFileBuffer(file, new TextEncoder().encode(rows));
8
+ try {
9
+ const statement = await connection.prepare(sql);
10
+ try {
11
+ await statement.query(file);
12
+ } finally {
13
+ await statement.close();
14
+ }
15
+ } finally {
16
+ await connection.bindings.dropFile(file);
17
+ }
18
+ }
19
+ return connection;
20
+ }
21
+ //#endregion
22
+ export { registerCatalog };
@@ -0,0 +1,8 @@
1
+ import { n as Catalog } from "./model-De0MF-zg.js";
2
+ import { t as RegisterCatalogOptions } from "./registration-CgQGMUIH.js";
3
+ import { DuckDBConnection } from "@duckdb/node-api";
4
+ //#region src/duckdb.d.ts
5
+ /** Create or replace canonical catalog tables in a caller-owned DuckDB connection. */
6
+ declare function registerCatalog(connection: DuckDBConnection, catalog: Catalog, options?: RegisterCatalogOptions): Promise<DuckDBConnection>;
7
+ //#endregion
8
+ export { type RegisterCatalogOptions, registerCatalog };
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 };