@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/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 chartcoach Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 chartcoach contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
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
- MIT. 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 };