@wavehouse/chtypes 0.1.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/CHANGELOG.md +24 -0
  2. package/LICENSE +202 -0
  3. package/README.md +442 -0
  4. package/dist/cli.d.ts +43 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +303 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/discover.d.ts +134 -0
  9. package/dist/discover.d.ts.map +1 -0
  10. package/dist/discover.js +291 -0
  11. package/dist/discover.js.map +1 -0
  12. package/dist/errors.d.ts +204 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +228 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/fetch.d.ts +235 -0
  17. package/dist/fetch.d.ts.map +1 -0
  18. package/dist/fetch.js +842 -0
  19. package/dist/fetch.js.map +1 -0
  20. package/dist/ffi.d.ts +346 -0
  21. package/dist/ffi.d.ts.map +1 -0
  22. package/dist/ffi.js +913 -0
  23. package/dist/ffi.js.map +1 -0
  24. package/dist/format.d.ts +104 -0
  25. package/dist/format.d.ts.map +1 -0
  26. package/dist/format.js +108 -0
  27. package/dist/format.js.map +1 -0
  28. package/dist/index.d.ts +28 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +28 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/json.d.ts +127 -0
  33. package/dist/json.d.ts.map +1 -0
  34. package/dist/json.js +577 -0
  35. package/dist/json.js.map +1 -0
  36. package/dist/library.d.ts +225 -0
  37. package/dist/library.d.ts.map +1 -0
  38. package/dist/library.js +234 -0
  39. package/dist/library.js.map +1 -0
  40. package/dist/numeric.d.ts +20 -0
  41. package/dist/numeric.d.ts.map +1 -0
  42. package/dist/numeric.js +107 -0
  43. package/dist/numeric.js.map +1 -0
  44. package/dist/paths.d.ts +47 -0
  45. package/dist/paths.d.ts.map +1 -0
  46. package/dist/paths.js +78 -0
  47. package/dist/paths.js.map +1 -0
  48. package/dist/registry.d.ts +204 -0
  49. package/dist/registry.d.ts.map +1 -0
  50. package/dist/registry.js +409 -0
  51. package/dist/registry.js.map +1 -0
  52. package/dist/results.d.ts +326 -0
  53. package/dist/results.d.ts.map +1 -0
  54. package/dist/results.js +235 -0
  55. package/dist/results.js.map +1 -0
  56. package/dist/schema.d.ts +444 -0
  57. package/dist/schema.d.ts.map +1 -0
  58. package/dist/schema.js +448 -0
  59. package/dist/schema.js.map +1 -0
  60. package/dist/settings.d.ts +43 -0
  61. package/dist/settings.d.ts.map +1 -0
  62. package/dist/settings.js +33 -0
  63. package/dist/settings.js.map +1 -0
  64. package/dist/tar.d.ts +32 -0
  65. package/dist/tar.d.ts.map +1 -0
  66. package/dist/tar.js +310 -0
  67. package/dist/tar.js.map +1 -0
  68. package/dist/transform.d.ts +73 -0
  69. package/dist/transform.d.ts.map +1 -0
  70. package/dist/transform.js +527 -0
  71. package/dist/transform.js.map +1 -0
  72. package/package.json +62 -0
package/dist/errors.js ADDED
@@ -0,0 +1,228 @@
1
+ /**
2
+ * The error model, which is three outcomes that must never be conflated
3
+ * (spec/c-abi.md §Error model):
4
+ *
5
+ * - ClickHouse rejects -> a real ClickHouse error code
6
+ * - this build refuses -> CODE_UNSUPPORTED (-2), never a ClickHouse code
7
+ * - ClickHouse accepts but the value cannot be read back -> code 691, and it
8
+ * is an ACCEPTED insert, surfaced through the row outcome rather than here.
9
+ *
10
+ * Mapping `unsupported` onto a rejection manufactures an over-reject the product
11
+ * never made; mapping it onto an acceptance manufactures an over-accept, which
12
+ * is the cardinal sin. So it gets its own sentinel on the wire and, since
13
+ * 2026-08-26, its own ERROR CLASS here — `UnsupportedError`, a peer of
14
+ * `SchemaError` rather than a subclass, so that a `catch` which handles only
15
+ * `SchemaError` cannot silently swallow a decline as a rejection.
16
+ */
17
+ /** "This build refuses to answer." Never a real ClickHouse error code. */
18
+ export const CODE_UNSUPPORTED = -2;
19
+ /**
20
+ * The chs_* ABI revision this binding was written against — `CHS_ABI_REVISION`
21
+ * in `include/chtypes.h`.
22
+ *
23
+ * This package dlopens artifacts rather than compiling against the header, so
24
+ * this is a hand-kept mirror and MUST be bumped in the same cycle the header
25
+ * is. A `Registry` refuses an artifact reporting a different nonzero revision;
26
+ * 0 means the artifact predates the probe, which is ignorance rather than
27
+ * incompatibility (spec/artifact.md §Loading).
28
+ *
29
+ * Revision 3 (2026-08-31): `chs_rows` gained `export_format` / `doc_flags` /
30
+ * `out_bytes`, and the `chs_filter_compile` / `chs_filter_free` /
31
+ * `chs_filter_rows` trio joined the surface.
32
+ *
33
+ * Revision 4 (2026-08-31, the filter phase-2 cycle): `chs_filter_compile`
34
+ * gained `params_json` (`{name:Type}` query parameters), and the block twin
35
+ * joined — `chs_block_parse` / `chs_block_free` / `chs_filter_eval`. This
36
+ * binding therefore speaks 4 and refuses revision-3 artifacts — calling the
37
+ * 5-argument `chs_filter_compile` through the 4-argument revision-3 artifact
38
+ * is undefined behaviour, which is exactly what the gate exists to prevent.
39
+ */
40
+ export const ABI_REVISION = 4;
41
+ /** Base class for everything this package throws. */
42
+ export class ChtypesError extends Error {
43
+ constructor(message, options) {
44
+ super(message, options);
45
+ this.name = new.target.name;
46
+ }
47
+ }
48
+ /** A registry could not be loaded, or a version could not be resolved. */
49
+ export class RegistryError extends ChtypesError {
50
+ }
51
+ /**
52
+ * A REFUSAL: ClickHouse itself refused a type, a column list, an engine or a
53
+ * TTL.
54
+ *
55
+ * `code` is ALWAYS a real ClickHouse error code. "This build declines to
56
+ * answer" is a DIFFERENT CLASS — `UnsupportedError` — never this one carrying
57
+ * a sentinel, so no `SchemaError` ever holds `CODE_UNSUPPORTED`
58
+ * (spec/bindings.md rule 12).
59
+ */
60
+ export class SchemaError extends ChtypesError {
61
+ code;
62
+ detail;
63
+ column;
64
+ constructor(code, detail, column) {
65
+ super(column
66
+ ? `chtypes: column ${JSON.stringify(column)}: [${code}] ${detail}`
67
+ : `chtypes: [${code}] ${detail}`);
68
+ this.code = code;
69
+ this.detail = detail;
70
+ this.column = column;
71
+ }
72
+ }
73
+ /**
74
+ * A DECLINE: "a real server might well have accepted this; I will not guess."
75
+ * Never ClickHouse rejecting anything, so it carries no `code` property at all
76
+ * — there is no code to carry.
77
+ *
78
+ * It is a PEER of `SchemaError`, deliberately NOT a subclass and deliberately
79
+ * NOT matched by `err instanceof SchemaError`. A decline that still satisfied
80
+ * "is a SchemaError" would be the sentinel problem wearing a class hierarchy:
81
+ * every `catch` that forgot the predicate would keep silently turning declines
82
+ * into rejections, which is a manufactured over-reject — data loss the product
83
+ * never made, budgeted at zero. As a peer, forgetting throws on past the
84
+ * handler, which is loud.
85
+ *
86
+ * ```ts
87
+ * try {
88
+ * schema.setEngine(engine, orderBy);
89
+ * } catch (err) {
90
+ * // validate cautiously; do NOT blame the tenant
91
+ * if (err instanceof UnsupportedError) return degradeToCarefulPath(err);
92
+ * // ClickHouse refused: err.code is its own code
93
+ * if (err instanceof SchemaError) return rejectWith(err.code, err.detail);
94
+ * throw err;
95
+ * }
96
+ * ```
97
+ *
98
+ * The MESSAGE still renders the ABI's `CODE_UNSUPPORTED` sentinel in the shape
99
+ * `SchemaError` renders its code. The sentinel is not a property of this class
100
+ * — it is the wire value the C ABI returned — but the rendering is frozen: the
101
+ * conformance driver puts this exact string on the protocol wire as an
102
+ * `unsupported` scope, and Python's `UnsupportedError` already spells it this
103
+ * way. Changing the text would move rig records without changing a verdict.
104
+ */
105
+ export class UnsupportedError extends ChtypesError {
106
+ detail;
107
+ column;
108
+ constructor(detail, column) {
109
+ super(column
110
+ ? `chtypes: column ${JSON.stringify(column)}: [${CODE_UNSUPPORTED}] ${detail}`
111
+ : `chtypes: [${CODE_UNSUPPORTED}] ${detail}`);
112
+ this.detail = detail;
113
+ this.column = column;
114
+ }
115
+ }
116
+ /**
117
+ * The ONE place an ABI error code becomes an error object, so the
118
+ * refusal/decline split cannot be decided differently in two files.
119
+ *
120
+ * The SIGN decides (spec/bindings.md rule 12, spec/c-abi.md §Error model): a
121
+ * positive code is the server's own refusal and rides through verbatim; any
122
+ * negative code is this library declining (`-2` "I will not guess", `-1` a
123
+ * guarded exception, and a binding's own missing-symbol sentinel) and becomes
124
+ * an `UnsupportedError`. Keying on the sign rather than on `=== CODE_UNSUPPORTED`
125
+ * means a negative sentinel a later era adds can never become "a SchemaError
126
+ * with a negative code", which the class's own contract forbids.
127
+ *
128
+ * Internal: not re-exported from the package index.
129
+ */
130
+ export function schemaErrorFor(code, detail, column) {
131
+ return code < 0 ? new UnsupportedError(detail, column) : new SchemaError(code, detail, column);
132
+ }
133
+ /** The command this SDK's §7 message tells a user to run. */
134
+ export const FETCH_COMMAND = 'npx @wavehouse/chtypes fetch';
135
+ /**
136
+ * The §7 message, verbatim apart from the bracketed parts:
137
+ *
138
+ * chtypes: no artifact for ClickHouse <line> (<os>-<arch>). Looked in: <dir1>, <dir2>, ….
139
+ * Install it: npx @wavehouse/chtypes fetch <line>
140
+ * or set CHTYPES_AUTOFETCH=1 to fetch on first use.
141
+ */
142
+ export function artifactMissingMessage(line, platform, lookedIn) {
143
+ return (`chtypes: no artifact for ClickHouse ${line} (${platform}). Looked in: ${lookedIn.join(', ')}.\n` +
144
+ `Install it: ${FETCH_COMMAND} ${line}\n` +
145
+ 'or set CHTYPES_AUTOFETCH=1 to fetch on first use.');
146
+ }
147
+ /**
148
+ * The one identifiable error for a missing artifact (docs/fetch.md §7):
149
+ * a `Registry` was asked for a line that no directory on its search path
150
+ * holds. `code` is `'CHTYPES_ARTIFACT_MISSING'`; the message is the
151
+ * contract's, and names every directory that was looked in and the command
152
+ * that installs the line.
153
+ *
154
+ * A subclass of `RegistryError`, so a `catch` written against `for()`'s
155
+ * documented error keeps working; the `code` is what a caller matches on.
156
+ */
157
+ export class ArtifactMissingError extends RegistryError {
158
+ code = 'CHTYPES_ARTIFACT_MISSING';
159
+ /** The minor line that was asked for, e.g. `25.8`. */
160
+ line;
161
+ /** The platform key the registry serves, e.g. `darwin-arm64`. */
162
+ platform;
163
+ /** Every directory of the search path, in order. */
164
+ lookedIn;
165
+ constructor(line, platform, lookedIn) {
166
+ super(artifactMissingMessage(line, platform, lookedIn));
167
+ this.line = line;
168
+ this.platform = platform;
169
+ this.lookedIn = [...lookedIn];
170
+ }
171
+ }
172
+ /**
173
+ * Base of the fetch-time verdicts (docs/fetch.md §3–§7). `code` is one of the
174
+ * shared codes; the subclasses exist so `instanceof` reads as well as `code`.
175
+ */
176
+ export class FetchError extends ChtypesError {
177
+ code;
178
+ constructor(code, message, options) {
179
+ super(message, options);
180
+ this.code = code;
181
+ }
182
+ }
183
+ /**
184
+ * `CHTYPES_ARTIFACT_UNTRUSTED`: the release's `SHA256SUMS.sig` is absent,
185
+ * malformed, or does not verify with any trusted key. Nothing is downloaded
186
+ * around it (§3 step 0).
187
+ */
188
+ export class ArtifactUntrustedError extends FetchError {
189
+ constructor(message, options) {
190
+ super('CHTYPES_ARTIFACT_UNTRUSTED', message, options);
191
+ }
192
+ }
193
+ /**
194
+ * `CHTYPES_ARTIFACT_CORRUPT`: any hash mismatch along the chain, a release
195
+ * that disagrees with itself (`index.json` vs `SHA256SUMS`, manifest vs
196
+ * index), or an archive that cannot be read safely.
197
+ */
198
+ export class ArtifactCorruptError extends FetchError {
199
+ constructor(message, options) {
200
+ super('CHTYPES_ARTIFACT_CORRUPT', message, options);
201
+ }
202
+ }
203
+ /**
204
+ * `CHTYPES_ARTIFACT_PINNED`: a `--frozen` lock file names a different asset
205
+ * or sha256 for this line — or none at all — and the fetch refused it (§5).
206
+ */
207
+ export class ArtifactPinnedError extends FetchError {
208
+ constructor(message, options) {
209
+ super('CHTYPES_ARTIFACT_PINNED', message, options);
210
+ }
211
+ }
212
+ /** `CHTYPES_ARTIFACT_UNPUBLISHED`: the release has nothing for this platform, line or exact patch. */
213
+ export class ArtifactUnpublishedError extends FetchError {
214
+ constructor(message, options) {
215
+ super('CHTYPES_ARTIFACT_UNPUBLISHED', message, options);
216
+ }
217
+ }
218
+ /**
219
+ * `CHTYPES_SOURCE_UNREACHABLE`: the source could not be reached or does not
220
+ * serve the release files — or `offline` forbade reaching it and the line is
221
+ * not installed and verified.
222
+ */
223
+ export class SourceUnreachableError extends FetchError {
224
+ constructor(message, options) {
225
+ super('CHTYPES_SOURCE_UNREACHABLE', message, options);
226
+ }
227
+ }
228
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,0EAA0E;AAC1E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAE9B,qDAAqD;AACrD,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,0EAA0E;AAC1E,MAAM,OAAO,aAAc,SAAQ,YAAY;CAAG;AAElD;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;IAClC,IAAI,CAAS;IACb,MAAM,CAAS;IACf,MAAM,CAAqB;IAEpC,YAAY,IAAY,EAAE,MAAc,EAAE,MAAe;QACvD,KAAK,CACH,MAAM;YACJ,CAAC,CAAC,mBAAmB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,IAAI,KAAK,MAAM,EAAE;YAClE,CAAC,CAAC,aAAa,IAAI,KAAK,MAAM,EAAE,CACnC,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB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YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,4BAA4B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;CACF"}
@@ -0,0 +1,235 @@
1
+ /**
2
+ * Fetching, verifying and installing artifacts — docs/fetch.md, the contract
3
+ * every SDK implements identically: the same source (§2), the same
4
+ * verification chain (§3), the same signature policy (§4), the same lock
5
+ * file (§5), the same function (§6) and the same codes (§7).
6
+ *
7
+ * Nothing here is a verdict but the chain. No exit code, no
8
+ * `Content-Length`, no "download finished" ever is:
9
+ *
10
+ * 0. `SHA256SUMS.sig` — ed25519 over the exact bytes of `SHA256SUMS`, with a
11
+ * trusted key. Failure stops everything; nothing is downloaded around it.
12
+ * 1. `index.json` names the asset for the line/platform and its sha256.
13
+ * 2. `SHA256SUMS` — now known-authentic — must list the same file with the
14
+ * same sha256; a disagreement is a broken release, reported, not repaired.
15
+ * 3. The tarball is hashed BEFORE it is unpacked.
16
+ * 4. `manifest.json` inside names the library and its sha256; after the
17
+ * move into `<registry>/<minor>/`, the installed library is hashed again
18
+ * in place.
19
+ *
20
+ * The install is atomic — unpack into a temporary sibling, rename into place
21
+ * — and idempotent: an installed line that hashes what the release says is
22
+ * reported as installed and nothing is downloaded.
23
+ *
24
+ * Steady state is offline: once files are in a registry directory the loader
25
+ * trusts the directory, exactly as a runtime trusts `node_modules`.
26
+ * Verification is a fetch-time policy, not a load-time gate.
27
+ */
28
+ /** The public artifacts host (docs/fetch.md §2); `CHTYPES_ARTIFACTS_URL` overrides it. */
29
+ export declare const DEFAULT_ARTIFACTS_URL = "https://artifacts.wavehouse.dev";
30
+ /** The rolling release every fetch reads by default; `tag` picks a frozen one. */
31
+ export declare const DEFAULT_RELEASE_TAG = "artifacts";
32
+ /**
33
+ * The release signing key(s) — raw 32-byte ed25519 public keys, hex
34
+ * (docs/fetch.md §4). `CHTYPES_TRUSTED_KEYS` or the `trustedKeys` option
35
+ * REPLACES this list; it is never extended silently.
36
+ */
37
+ export declare const RELEASE_PUBLIC_KEYS: readonly string[];
38
+ /** The lock-file schema this SDK writes and reads (docs/fetch.md §5). */
39
+ export declare const LOCK_SCHEMA = 1;
40
+ /** The lock file `frozen` reads when no `lock` names one (docs/fetch.md, Decisions); relative, so the working directory's. */
41
+ export declare const DEFAULT_LOCK_FILE = "chtypes.lock";
42
+ /** One row of a release's `index.json` (docs/artifacts.md §2). */
43
+ export interface IndexArtifact {
44
+ readonly os: string;
45
+ readonly arch: string;
46
+ readonly file: string;
47
+ /** sha256 of the tarball. */
48
+ readonly sha256: string;
49
+ /** size of the tarball. */
50
+ readonly bytes: number;
51
+ readonly clickhouse_version: string;
52
+ readonly clickhouse_minor: string;
53
+ readonly library: string;
54
+ readonly library_sha256: string;
55
+ }
56
+ /** A release's `index.json`, schema 1. */
57
+ export interface ReleaseIndex {
58
+ readonly schema: number;
59
+ readonly generated_at?: string;
60
+ readonly release_tag?: string;
61
+ readonly license?: string;
62
+ readonly license_url?: string;
63
+ readonly artifacts: readonly IndexArtifact[];
64
+ }
65
+ /** One pinned line in a lock file: the asset that was installed and its sha256. */
66
+ export interface LockEntry {
67
+ readonly file: string;
68
+ readonly sha256: string;
69
+ }
70
+ /** `chtypes.lock` (docs/fetch.md §5): `{"schema": 1, "artifacts": {"<os>-<arch>/<minor>": {file, sha256}}}`. */
71
+ export interface LockFile {
72
+ readonly schema: number;
73
+ readonly artifacts: Record<string, LockEntry>;
74
+ }
75
+ /** Progress, for a caller that wants to show it (the CLI prints these on stderr). */
76
+ export type FetchEvent = {
77
+ readonly type: 'status';
78
+ readonly message: string;
79
+ } | {
80
+ readonly type: 'download';
81
+ readonly file: string;
82
+ readonly received: number;
83
+ readonly total: number;
84
+ };
85
+ /** Options for `ensure`, `ensureAll`, `listArtifacts` — the §6 flags, spelled as properties. */
86
+ export interface EnsureOptions {
87
+ /** Where to install (`--dest`); default: the §1 write target (`CHTYPES_REGISTRY`, else the per-user cache). */
88
+ readonly dest?: string | undefined;
89
+ /** `<os>-<arch>` (`--platform`); default: this host (`CHTYPES_TARGET` overrides, as `scripts/fetch.sh`). */
90
+ readonly platform?: string | undefined;
91
+ /** A release tag on the artifacts host (`--tag`); default the rolling `artifacts`. Exclusive with `url`. */
92
+ readonly tag?: string | undefined;
93
+ /** Any other base (`--url`): `https://…`, `file://…`, or a plain directory. Exclusive with `tag`. */
94
+ readonly url?: string | undefined;
95
+ /** A lock file to record into (`--lock`), and to enforce with `frozen`. */
96
+ readonly lock?: string | undefined;
97
+ /** Refuse anything the lock does not pin, with `CHTYPES_ARTIFACT_PINNED` (`--frozen`). */
98
+ readonly frozen?: boolean | undefined;
99
+ /** Re-download even when the line is installed and verified (`--force`). */
100
+ readonly force?: boolean | undefined;
101
+ /** Never touch the source: installed-and-verified is fine, anything else is `CHTYPES_SOURCE_UNREACHABLE` (`--offline`). */
102
+ readonly offline?: boolean | undefined;
103
+ /** Raw ed25519 public keys, hex; REPLACES the embedded release key (as `CHTYPES_TRUSTED_KEYS` does). */
104
+ readonly trustedKeys?: readonly string[] | undefined;
105
+ /** Skip the signature (step 0) with one loud warning; never the default (as `CHTYPES_ALLOW_UNSIGNED=1`). */
106
+ readonly allowUnsigned?: boolean | undefined;
107
+ /** Progress events; silent when absent. */
108
+ readonly onProgress?: ((event: FetchEvent) => void) | undefined;
109
+ /** Aborts an in-progress download. */
110
+ readonly signal?: AbortSignal | undefined;
111
+ }
112
+ /** What `ensure` did: where the line is, what it is, and whether bytes moved. */
113
+ export interface EnsureResult {
114
+ /** The installed line directory, `<registry>/<minor>` — what `fetch` prints. */
115
+ readonly dir: string;
116
+ /** The registry directory the line lives in. */
117
+ readonly registry: string;
118
+ readonly line: string;
119
+ readonly version: string;
120
+ readonly platform: string;
121
+ /** The asset name and its sha256 — what the lock records; empty on the offline path. */
122
+ readonly file: string;
123
+ readonly sha256: string;
124
+ readonly library: string;
125
+ readonly librarySha256: string;
126
+ /** true when the tarball was downloaded and installed by this call; false when the line was already installed and verified. */
127
+ readonly installed: boolean;
128
+ /** The source that was consulted, or `offline`. */
129
+ readonly source: string;
130
+ /** Whether `SHA256SUMS` carried a signature a trusted key verified, and that key's id. */
131
+ readonly signed: boolean;
132
+ readonly keyId: string | null;
133
+ }
134
+ /** One installed line, as `verify` and `list` report it. */
135
+ export interface InstalledArtifact {
136
+ readonly line: string;
137
+ readonly dir: string;
138
+ readonly version: string;
139
+ readonly library: string;
140
+ /** The manifest's sha256; what the file hashes (only `verifyInstalled` fills it in); the verdict. */
141
+ readonly expected: string;
142
+ readonly actual: string | null;
143
+ readonly ok: boolean;
144
+ readonly problem: string | null;
145
+ }
146
+ /** What `list` shows: what is installed, and what the release offers for the platform. */
147
+ export interface ListResult {
148
+ readonly registry: string;
149
+ readonly platform: string;
150
+ readonly installed: readonly InstalledArtifact[];
151
+ /** null when offline. */
152
+ readonly offered: readonly IndexArtifact[] | null;
153
+ readonly source: string | null;
154
+ }
155
+ /** How a version was asked for: the line, and the exact patch if one was typed. */
156
+ export interface VersionRequest {
157
+ readonly spelling: string;
158
+ /** e.g. `25.8`. */
159
+ readonly line: string;
160
+ /** `25.8.28.1-lts` when a patch was typed (a hard requirement), else null. */
161
+ readonly exact: string | null;
162
+ /** The exact patch without its channel suffix, when one was typed. */
163
+ readonly bare: string | null;
164
+ }
165
+ /**
166
+ * `25.8` is a line; `25.8.28.1-lts`, `v25.8.28.1-lts` and `25.8.28.1` are an
167
+ * exact patch and a hard requirement (a release that publishes another patch
168
+ * of the line refuses it — ask for the line to take what was published).
169
+ *
170
+ * @throws {ChtypesError} when the spelling is not a ClickHouse version at all.
171
+ */
172
+ export declare function parseVersionSpelling(spelling: string): VersionRequest;
173
+ /** Numeric order over dotted versions, channel suffix ignored: 25.10 > 25.8, 25.8.30.16 > 25.8.28.1. */
174
+ export declare function compareVersions(a: string, b: string): number;
175
+ /** The key id docs/fetch.md §4 defines: the first 16 hex characters of sha256 over the raw 32-byte public key. */
176
+ export declare function keyId(rawKeyHex: string): string;
177
+ /**
178
+ * Verify an ed25519 signature over `message` with a raw public key, through
179
+ * `node:crypto` — the key wrapped as SPKI DER, the 64-byte signature as is.
180
+ * False, never a throw, for a malformed key or signature.
181
+ */
182
+ export declare function verifyEd25519(message: Uint8Array, signature: Uint8Array, rawKeyHex: string): boolean;
183
+ /**
184
+ * `SHA256SUMS.sig`: an `untrusted comment:` line, then the base64 of the
185
+ * 64-byte signature. Null when the file is not in that shape.
186
+ */
187
+ export declare function parseSignatureFile(bytes: Uint8Array): {
188
+ comment: string;
189
+ signature: Buffer;
190
+ } | null;
191
+ /**
192
+ * The keys a fetch trusts: the `trustedKeys` option, else `CHTYPES_TRUSTED_KEYS`
193
+ * (`<hex>[,<hex>…]`), else the embedded release key. Each REPLACES the one
194
+ * below it.
195
+ *
196
+ * @throws {ChtypesError} when an entry is not 64 hex characters.
197
+ */
198
+ export declare function trustedKeys(explicit?: readonly string[]): string[];
199
+ /** The one row for a request, or `CHTYPES_ARTIFACT_UNPUBLISHED` naming what the release does have. */
200
+ export declare function selectArtifact(index: ReleaseIndex, platform: string, req: VersionRequest): IndexArtifact;
201
+ /** Every line the release publishes for the platform, newest patch per line, oldest line first. */
202
+ export declare function selectAll(index: ReleaseIndex, platform: string): IndexArtifact[];
203
+ /**
204
+ * Make one ClickHouse line available in a registry directory, through the
205
+ * verification chain, and say where it is. Idempotent: installed and
206
+ * verified is a no-op that downloads nothing (`force` re-downloads).
207
+ *
208
+ * @param spelling - a line (`"25.8"`) or an exact patch (`"25.8.28.1-lts"`, a hard requirement).
209
+ * @param options - see `EnsureOptions`; every §6 flag has a property here.
210
+ * @returns where the line is and what it is — `dir` is `<registry>/<minor>`.
211
+ * @throws {ArtifactUntrustedError} `CHTYPES_ARTIFACT_UNTRUSTED` — no signature, or none a trusted key verifies.
212
+ * @throws {ArtifactCorruptError} `CHTYPES_ARTIFACT_CORRUPT` — any hash mismatch, a release that disagrees with itself.
213
+ * @throws {ArtifactPinnedError} `CHTYPES_ARTIFACT_PINNED` — `frozen` and the lock says otherwise.
214
+ * @throws {ArtifactUnpublishedError} `CHTYPES_ARTIFACT_UNPUBLISHED` — nothing for this platform/line/patch.
215
+ * @throws {SourceUnreachableError} `CHTYPES_SOURCE_UNREACHABLE` — the source cannot be reached, or `offline` and not installed.
216
+ * @throws {ChtypesError} for a spelling that is not a version, a bad platform key, or conflicting options.
217
+ */
218
+ export declare function ensure(spelling: string, options?: EnsureOptions): Promise<EnsureResult>;
219
+ /** `fetch --all`: every line the release publishes for the platform, each through `ensure`'s chain. */
220
+ export declare function ensureAll(options?: EnsureOptions): Promise<EnsureResult[]>;
221
+ /**
222
+ * `chtypes verify`: re-hash every installed line in a registry directory
223
+ * against its own manifest. A line whose manifest cannot be read is not a
224
+ * line (a scratch directory) and is skipped, as the loader skips it.
225
+ */
226
+ export declare function verifyInstalled(dest?: string, platform?: string): Promise<InstalledArtifact[]>;
227
+ /** `chtypes list`: what is installed in the registry directory, and what the release offers for the platform. */
228
+ export declare function listArtifacts(options?: EnsureOptions): Promise<ListResult>;
229
+ /** Read a lock file; null when it does not exist. */
230
+ export declare function readLock(file: string): LockFile | null;
231
+ /** The platform a fetch is for: the option, else `CHTYPES_TARGET`, else this host. */
232
+ export declare function resolvePlatform(explicit?: string): string;
233
+ /** sha256 of a file, streamed — a 300 MB library never sits in memory whole. */
234
+ export declare function sha256File(file: string): Promise<string>;
235
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAwBH,0FAA0F;AAC1F,eAAO,MAAM,qBAAqB,oCAAoC,CAAC;AACvE,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAC/C;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAEhD,CAAC;AACF,yEAAyE;AACzE,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,8HA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