@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
@@ -0,0 +1,225 @@
1
+ /**
2
+ * One loaded ClickHouse build. It names itself — `chs_clickhouse_version()` —
3
+ * and nothing is ever inferred from the directory or the file name.
4
+ */
5
+ import type { NativeLibrary } from './ffi.js';
6
+ import { Schema } from './schema.js';
7
+ import { type Settings } from './settings.js';
8
+ /**
9
+ * The minor line: the first two dot-separated components of the reported
10
+ * version. `25.10` is a *later* minor than `25.8`, so string comparison of minor
11
+ * lines is meaningless and must not be used for ordering.
12
+ *
13
+ * @param version - an exact patch (`"25.8.28.1-lts"`) or already a minor line.
14
+ * @returns the minor line (`"25.8"`); a string with fewer than two components
15
+ * is returned unchanged. Never throws.
16
+ */
17
+ export declare function minorOf(version: string): string;
18
+ /**
19
+ * The compile MODE — how the profile handed to `compileDdl` relates to the
20
+ * settings this build compiles under. Numeric values are part of the C ABI
21
+ * (bindings pass an int), exactly like `Format`.
22
+ */
23
+ export declare const CompileMode: {
24
+ /**
25
+ * The only defined mode: every setting the profile names takes the
26
+ * caller's value, every setting it does not name keeps the library's own
27
+ * permissive compile base. A partial profile can admit a schema the server
28
+ * might refuse, but can never fabricate a rejection. Any other value is
29
+ * refused loudly (an `UnsupportedError`), reserved for a future
30
+ * COMPLETE-profile mode.
31
+ */
32
+ readonly Declared: 0;
33
+ };
34
+ export type CompileMode = (typeof CompileMode)[keyof typeof CompileMode];
35
+ /**
36
+ * Options for `Library#compileDdl` — the DECLARED settings profile a schema is
37
+ * compiled under (spec/c-abi.md §Compile-time vs per-call settings;
38
+ * spec/bindings.md "Compile under a declared settings profile").
39
+ */
40
+ export interface CompileOptions {
41
+ /**
42
+ * The settings the deployment's server runs, fixed into the compiled schema
43
+ * exactly as a real CREATE TABLE fixes them into the table. Values are
44
+ * strings (or bigints), as everywhere on this ABI. Absent or empty is
45
+ * structurally identical to the plain compile — `chs_schema_compile` takes
46
+ * "{}" plus mode 0 either way. An unknown setting name fails the compile
47
+ * with the server's own code 115 (`chtypes_*` per-call keys included), and
48
+ * nothing is compiled.
49
+ */
50
+ readonly settings?: Settings | undefined;
51
+ /**
52
+ * `CompileMode.Declared` (0), the default and the only defined mode — see
53
+ * `CompileMode`.
54
+ */
55
+ readonly mode?: CompileMode | undefined;
56
+ }
57
+ /**
58
+ * One loaded ClickHouse build — the entry point for compiling schemas and
59
+ * canonicalising types under that release's exact semantics. Obtained from
60
+ * `Registry#for`; never constructed directly.
61
+ *
62
+ * Thread-safety: every call here is synchronous on the JS thread, so ordinary
63
+ * single-threaded Node code needs no locking. `setDefaultSettings` and
64
+ * `shutdown` mutate per-library process state and refuse loudly if called from
65
+ * inside another chtypes call (a reentrancy guard, not a lock). Two
66
+ * `worker_threads` share one dlopen'd image and one set of C globals, which no
67
+ * per-isolate guard can see — seed settings before starting workers, or
68
+ * serialise the seed yourself (spec/bindings.md §Concurrency).
69
+ */
70
+ export declare class Library {
71
+ private readonly native;
72
+ /** The exact patch this build is, e.g. "25.8.28.1-lts". */
73
+ readonly version: string;
74
+ /** The line callers and the rigs ask in, e.g. "25.8". */
75
+ readonly minor: string;
76
+ /** The shared library that was loaded. */
77
+ readonly path: string;
78
+ /**
79
+ * The chs_* ABI revision this ARTIFACT was built from, or 0 when it predates
80
+ * `chs_abi_revision`. A `Library` that exists reports either `ABI_REVISION`
81
+ * or 0 — a different nonzero revision is refused at load (spec/c-abi.md
82
+ * §ABI identity).
83
+ */
84
+ readonly abiRevision: number;
85
+ /** @internal — obtained from a `Registry`. */
86
+ constructor(native: NativeLibrary);
87
+ /**
88
+ * Parse and canonicalise one type expression, e.g. `DECIMAL(18,4)` ->
89
+ * `Decimal(18, 4)`. The library's spelling is authoritative: pass it through
90
+ * verbatim and never normalise its whitespace.
91
+ *
92
+ * Note that this alone is insufficient for a schema — `x Int64 DEFAULT NULL`
93
+ * canonicalises the *column* to `Nullable(Int64)`, which only `compileDdl` sees.
94
+ *
95
+ * @param typeExpr - a ClickHouse type expression, e.g. `"Nullable(Decimal(18,4))"`.
96
+ * @returns the canonical spelling, e.g. `"Nullable(Decimal(18, 4))"`.
97
+ * @throws {SchemaError} when ClickHouse itself refuses the expression —
98
+ * `code` is its own code (`50` `Unknown data type family` for a typo) and
99
+ * the message its own text.
100
+ * @throws {UnsupportedError} when this build declines to construct the type
101
+ * (an unsafe family), or the artifact predates `chs_validate_type`.
102
+ */
103
+ validateType(typeExpr: string): string;
104
+ /**
105
+ * Compile a ClickHouse column-declaration list — not a CREATE TABLE:
106
+ * `"a UInt8, b Nullable(String) DEFAULT 'x', c DateTime MATERIALIZED now()"`.
107
+ * It is parsed by ClickHouse's own `ParserColumnDeclarationList`, so DEFAULT
108
+ * expressions are validated as real SQL. Column-level TTL clauses belong here.
109
+ *
110
+ * With `options.settings` the schema is compiled under that DECLARED profile,
111
+ * exactly as a real CREATE TABLE under those settings: `{ flatten_nested: '0' }`
112
+ * keeps `n Nested(a,b)` ONE column `n` of type `Nested(…)` where the default
113
+ * flattens it to the `n.a`/`n.b` Array columns, and every downstream shape —
114
+ * `columns`, JSONEachRow name lookup, positional arity, the RowBinary wire —
115
+ * follows the compiled shape. The profile is compile-time only and immutable
116
+ * for the schema's life; per-call settings still govern row parsing, and only
117
+ * row parsing.
118
+ *
119
+ * Absent/empty settings are structurally the plain compile: `chs_schema_compile`
120
+ * takes settings "{}" and `mode` `CompileMode.Declared` (0) either way. An
121
+ * unknown setting name fails the compile with the server's own code 115.
122
+ *
123
+ * @param ddl - a column-declaration list, e.g. `"x UInt8, s String DEFAULT 'x'"`.
124
+ * @param options - the declared settings profile and compile mode.
125
+ * @returns the compiled `Schema`. Release it with `close()` (or `using`).
126
+ * @throws {SchemaError} when the compile is REFUSED with a positive code: a
127
+ * bad type or DEFAULT carries ClickHouse's own code and message; an
128
+ * unknown setting name in `options.settings` carries the server's own 115
129
+ * (with its did-you-mean hint), and nothing is compiled; a type gate
130
+ * declared at a refusing value fails with the server's own 455/44, exactly
131
+ * as that server's CREATE; an Enum DEFAULT outside the declared domain is
132
+ * 691 (schema-level poisoning, refused on every version by design).
133
+ * @throws {UnsupportedError} when this build DECLINES rather than guesses —
134
+ * a `mode` other than `CompileMode.Declared`, or a DEFAULT it refuses to
135
+ * evaluate (server-property functions like `hostName()`, `sleep`, an
136
+ * admission-budget overrun). Validate cautiously; do not blame the tenant.
137
+ */
138
+ compileDdl(ddl: string, options?: CompileOptions): Schema;
139
+ /**
140
+ * Does this artifact export the consolidated, settings-aware
141
+ * `chs_schema_compile`? True on every artifact this repo builds — the
142
+ * symbol is one of the mandatory four. Kept for a `Registry` that may
143
+ * someday load a third-party-built artifact that lacks it, in which case
144
+ * `compileDdl` with a non-empty `settings` and `setEngine` with non-empty
145
+ * `mergeTreeSettings` throw an `UnsupportedError` instead of
146
+ * crashing.
147
+ */
148
+ hasCompileSettings(): boolean;
149
+ /**
150
+ * Seed the settings every later call starts from. ClickHouse gates several type
151
+ * families at column-creation time (`allow_suspicious_low_cardinality_types`,
152
+ * `allow_experimental_json_type`, …); those are properties of the server the
153
+ * table lives on, not of the row, so a gateway sets them once here. Anything a
154
+ * per-call settings map sets still wins.
155
+ *
156
+ * Prefer `compileDdl(ddl, { settings })` for a gate that belongs to a
157
+ * particular tenant's table: a gate declared in the compile profile binds
158
+ * where a real server binds it — once, at CREATE — and then outranks the
159
+ * per-call map for that handle (measured on live 25.10.7.6 and 26.7.3.19;
160
+ * spec/c-abi.md, "Server-level type gates"). This process-wide seed stays the
161
+ * right channel only for gateway-uniform policy.
162
+ *
163
+ * @param settings - the seed. An unknown name refuses the WHOLE payload with
164
+ * the server's own 115 and nothing is committed — a gateway can never
165
+ * believe a default profile is in force when part of it never applied.
166
+ * @throws {ChtypesError} when the payload is refused (the message carries
167
+ * the server's own text, did-you-mean hint included), when a value is a JS
168
+ * `number`, or when called from inside another chtypes call — it replaces
169
+ * process-global state the row path reads by reference, so it must never
170
+ * overlap another call on this library. In a `worker_threads` setup, seed
171
+ * BEFORE starting workers; the guard cannot see across isolates.
172
+ * @throws {UnsupportedError} when the artifact predates
173
+ * `chs_set_default_settings`.
174
+ */
175
+ setDefaultSettings(settings: Settings): void;
176
+ /**
177
+ * Diagnostic: the widened reference type this build compares against —
178
+ * `UInt8` → `Int256`, `DateTime` → `DateTime64(0, 'UTC')`. Not needed to
179
+ * function (the reference parse is already applied inside `row`/`rows` and
180
+ * reported per column); it makes transformation findings explainable.
181
+ *
182
+ * @param typeExpr - a ClickHouse type expression.
183
+ * @returns the reference type, or `''` for a type with no wider type to
184
+ * compare against (`String`, `Float64`).
185
+ * @throws {UnsupportedError} when the artifact predates `chs_reference_type`.
186
+ */
187
+ referenceType(typeExpr: string): string;
188
+ /**
189
+ * Every type family in this build's own runtime registry (139 entries on
190
+ * 25.8) — the answer to "does this build track upstream type families?"
191
+ * without a hand-maintained table. Part of the three-question introspection
192
+ * surface every SDK exposes (spec/bindings.md §Introspection).
193
+ *
194
+ * @returns the family names, one per registry entry.
195
+ * @throws {UnsupportedError} when the artifact predates
196
+ * `chs_registered_families`.
197
+ */
198
+ registeredFamilies(): string[];
199
+ /**
200
+ * The TSV audit of every registered function's volatility
201
+ * (`chs_function_flags`), VERBATIM: one function per line, six
202
+ * tab-separated fields — `name`, `deterministic`, `deterministic_in_query`,
203
+ * `server_constant`, `stateful`, `resolver_error_code`. ClickHouse's own
204
+ * answers off this build's own registry, and the input to the statelessness
205
+ * gate (`lib/tools/gen_function_flags.py`). Part of the three-question
206
+ * introspection surface every SDK exposes (spec/bindings.md
207
+ * §Introspection).
208
+ *
209
+ * @returns the audit text, verbatim.
210
+ * @throws {UnsupportedError} when the artifact predates
211
+ * `chs_function_flags`.
212
+ */
213
+ functionFlags(): string;
214
+ /**
215
+ * Join the DEFAULT evaluator's background threads. `chs_init` registers this
216
+ * with `atexit`, so an ordinary process needs no call; it is REQUIRED before
217
+ * an explicit unload, and useful in tests that must not depend on `atexit`.
218
+ * Idempotent.
219
+ *
220
+ * @throws {ChtypesError} when called from inside another chtypes call on
221
+ * this library (the same reentrancy guard as `setDefaultSettings`).
222
+ */
223
+ shutdown(): void;
224
+ }
225
+ //# sourceMappingURL=library.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9D;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW;IACtB;;;;;;;OAOG;aACH,QAAQ,EAAE,CAAC;CACH,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;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directory or the file name.
4
+ */
5
+ import { schemaErrorFor } from './errors.js';
6
+ import { Schema } from './schema.js';
7
+ import { encodeSettings } from './settings.js';
8
+ /**
9
+ * The minor line: the first two dot-separated components of the reported
10
+ * version. `25.10` is a *later* minor than `25.8`, so string comparison of minor
11
+ * lines is meaningless and must not be used for ordering.
12
+ *
13
+ * @param version - an exact patch (`"25.8.28.1-lts"`) or already a minor line.
14
+ * @returns the minor line (`"25.8"`); a string with fewer than two components
15
+ * is returned unchanged. Never throws.
16
+ */
17
+ export function minorOf(version) {
18
+ const parts = version.split('.');
19
+ if (parts.length < 2)
20
+ return version;
21
+ return `${parts[0]}.${parts[1]}`;
22
+ }
23
+ /**
24
+ * The compile MODE — how the profile handed to `compileDdl` relates to the
25
+ * settings this build compiles under. Numeric values are part of the C ABI
26
+ * (bindings pass an int), exactly like `Format`.
27
+ */
28
+ export const CompileMode = {
29
+ /**
30
+ * The only defined mode: every setting the profile names takes the
31
+ * caller's value, every setting it does not name keeps the library's own
32
+ * permissive compile base. A partial profile can admit a schema the server
33
+ * might refuse, but can never fabricate a rejection. Any other value is
34
+ * refused loudly (an `UnsupportedError`), reserved for a future
35
+ * COMPLETE-profile mode.
36
+ */
37
+ Declared: 0,
38
+ };
39
+ /**
40
+ * One loaded ClickHouse build — the entry point for compiling schemas and
41
+ * canonicalising types under that release's exact semantics. Obtained from
42
+ * `Registry#for`; never constructed directly.
43
+ *
44
+ * Thread-safety: every call here is synchronous on the JS thread, so ordinary
45
+ * single-threaded Node code needs no locking. `setDefaultSettings` and
46
+ * `shutdown` mutate per-library process state and refuse loudly if called from
47
+ * inside another chtypes call (a reentrancy guard, not a lock). Two
48
+ * `worker_threads` share one dlopen'd image and one set of C globals, which no
49
+ * per-isolate guard can see — seed settings before starting workers, or
50
+ * serialise the seed yourself (spec/bindings.md §Concurrency).
51
+ */
52
+ export class Library {
53
+ native;
54
+ /** The exact patch this build is, e.g. "25.8.28.1-lts". */
55
+ version;
56
+ /** The line callers and the rigs ask in, e.g. "25.8". */
57
+ minor;
58
+ /** The shared library that was loaded. */
59
+ path;
60
+ /**
61
+ * The chs_* ABI revision this ARTIFACT was built from, or 0 when it predates
62
+ * `chs_abi_revision`. A `Library` that exists reports either `ABI_REVISION`
63
+ * or 0 — a different nonzero revision is refused at load (spec/c-abi.md
64
+ * §ABI identity).
65
+ */
66
+ abiRevision;
67
+ /** @internal — obtained from a `Registry`. */
68
+ constructor(native) {
69
+ this.native = native;
70
+ this.version = native.version;
71
+ this.minor = minorOf(native.version);
72
+ this.path = native.path;
73
+ this.abiRevision = native.abiRevision;
74
+ }
75
+ /**
76
+ * Parse and canonicalise one type expression, e.g. `DECIMAL(18,4)` ->
77
+ * `Decimal(18, 4)`. The library's spelling is authoritative: pass it through
78
+ * verbatim and never normalise its whitespace.
79
+ *
80
+ * Note that this alone is insufficient for a schema — `x Int64 DEFAULT NULL`
81
+ * canonicalises the *column* to `Nullable(Int64)`, which only `compileDdl` sees.
82
+ *
83
+ * @param typeExpr - a ClickHouse type expression, e.g. `"Nullable(Decimal(18,4))"`.
84
+ * @returns the canonical spelling, e.g. `"Nullable(Decimal(18, 4))"`.
85
+ * @throws {SchemaError} when ClickHouse itself refuses the expression —
86
+ * `code` is its own code (`50` `Unknown data type family` for a typo) and
87
+ * the message its own text.
88
+ * @throws {UnsupportedError} when this build declines to construct the type
89
+ * (an unsafe family), or the artifact predates `chs_validate_type`.
90
+ */
91
+ validateType(typeExpr) {
92
+ const r = this.native.validateType(typeExpr);
93
+ if (!r.ok)
94
+ throw schemaErrorFor(r.code, r.message);
95
+ return r.canonical;
96
+ }
97
+ /**
98
+ * Compile a ClickHouse column-declaration list — not a CREATE TABLE:
99
+ * `"a UInt8, b Nullable(String) DEFAULT 'x', c DateTime MATERIALIZED now()"`.
100
+ * It is parsed by ClickHouse's own `ParserColumnDeclarationList`, so DEFAULT
101
+ * expressions are validated as real SQL. Column-level TTL clauses belong here.
102
+ *
103
+ * With `options.settings` the schema is compiled under that DECLARED profile,
104
+ * exactly as a real CREATE TABLE under those settings: `{ flatten_nested: '0' }`
105
+ * keeps `n Nested(a,b)` ONE column `n` of type `Nested(…)` where the default
106
+ * flattens it to the `n.a`/`n.b` Array columns, and every downstream shape —
107
+ * `columns`, JSONEachRow name lookup, positional arity, the RowBinary wire —
108
+ * follows the compiled shape. The profile is compile-time only and immutable
109
+ * for the schema's life; per-call settings still govern row parsing, and only
110
+ * row parsing.
111
+ *
112
+ * Absent/empty settings are structurally the plain compile: `chs_schema_compile`
113
+ * takes settings "{}" and `mode` `CompileMode.Declared` (0) either way. An
114
+ * unknown setting name fails the compile with the server's own code 115.
115
+ *
116
+ * @param ddl - a column-declaration list, e.g. `"x UInt8, s String DEFAULT 'x'"`.
117
+ * @param options - the declared settings profile and compile mode.
118
+ * @returns the compiled `Schema`. Release it with `close()` (or `using`).
119
+ * @throws {SchemaError} when the compile is REFUSED with a positive code: a
120
+ * bad type or DEFAULT carries ClickHouse's own code and message; an
121
+ * unknown setting name in `options.settings` carries the server's own 115
122
+ * (with its did-you-mean hint), and nothing is compiled; a type gate
123
+ * declared at a refusing value fails with the server's own 455/44, exactly
124
+ * as that server's CREATE; an Enum DEFAULT outside the declared domain is
125
+ * 691 (schema-level poisoning, refused on every version by design).
126
+ * @throws {UnsupportedError} when this build DECLINES rather than guesses —
127
+ * a `mode` other than `CompileMode.Declared`, or a DEFAULT it refuses to
128
+ * evaluate (server-property functions like `hostName()`, `sleep`, an
129
+ * admission-budget overrun). Validate cautiously; do not blame the tenant.
130
+ */
131
+ compileDdl(ddl, options) {
132
+ const settingsJson = encodeSettings(options?.settings);
133
+ const mode = options?.mode ?? CompileMode.Declared;
134
+ return new Schema(this.native, this.native.schemaCompile(ddl, settingsJson, mode), ddl);
135
+ }
136
+ /**
137
+ * Does this artifact export the consolidated, settings-aware
138
+ * `chs_schema_compile`? True on every artifact this repo builds — the
139
+ * symbol is one of the mandatory four. Kept for a `Registry` that may
140
+ * someday load a third-party-built artifact that lacks it, in which case
141
+ * `compileDdl` with a non-empty `settings` and `setEngine` with non-empty
142
+ * `mergeTreeSettings` throw an `UnsupportedError` instead of
143
+ * crashing.
144
+ */
145
+ hasCompileSettings() {
146
+ return this.native.hasCompileSettings();
147
+ }
148
+ /**
149
+ * Seed the settings every later call starts from. ClickHouse gates several type
150
+ * families at column-creation time (`allow_suspicious_low_cardinality_types`,
151
+ * `allow_experimental_json_type`, …); those are properties of the server the
152
+ * table lives on, not of the row, so a gateway sets them once here. Anything a
153
+ * per-call settings map sets still wins.
154
+ *
155
+ * Prefer `compileDdl(ddl, { settings })` for a gate that belongs to a
156
+ * particular tenant's table: a gate declared in the compile profile binds
157
+ * where a real server binds it — once, at CREATE — and then outranks the
158
+ * per-call map for that handle (measured on live 25.10.7.6 and 26.7.3.19;
159
+ * spec/c-abi.md, "Server-level type gates"). This process-wide seed stays the
160
+ * right channel only for gateway-uniform policy.
161
+ *
162
+ * @param settings - the seed. An unknown name refuses the WHOLE payload with
163
+ * the server's own 115 and nothing is committed — a gateway can never
164
+ * believe a default profile is in force when part of it never applied.
165
+ * @throws {ChtypesError} when the payload is refused (the message carries
166
+ * the server's own text, did-you-mean hint included), when a value is a JS
167
+ * `number`, or when called from inside another chtypes call — it replaces
168
+ * process-global state the row path reads by reference, so it must never
169
+ * overlap another call on this library. In a `worker_threads` setup, seed
170
+ * BEFORE starting workers; the guard cannot see across isolates.
171
+ * @throws {UnsupportedError} when the artifact predates
172
+ * `chs_set_default_settings`.
173
+ */
174
+ setDefaultSettings(settings) {
175
+ this.native.setDefaultSettings(encodeSettings(settings));
176
+ }
177
+ /**
178
+ * Diagnostic: the widened reference type this build compares against —
179
+ * `UInt8` → `Int256`, `DateTime` → `DateTime64(0, 'UTC')`. Not needed to
180
+ * function (the reference parse is already applied inside `row`/`rows` and
181
+ * reported per column); it makes transformation findings explainable.
182
+ *
183
+ * @param typeExpr - a ClickHouse type expression.
184
+ * @returns the reference type, or `''` for a type with no wider type to
185
+ * compare against (`String`, `Float64`).
186
+ * @throws {UnsupportedError} when the artifact predates `chs_reference_type`.
187
+ */
188
+ referenceType(typeExpr) {
189
+ return this.native.referenceType(typeExpr);
190
+ }
191
+ /**
192
+ * Every type family in this build's own runtime registry (139 entries on
193
+ * 25.8) — the answer to "does this build track upstream type families?"
194
+ * without a hand-maintained table. Part of the three-question introspection
195
+ * surface every SDK exposes (spec/bindings.md §Introspection).
196
+ *
197
+ * @returns the family names, one per registry entry.
198
+ * @throws {UnsupportedError} when the artifact predates
199
+ * `chs_registered_families`.
200
+ */
201
+ registeredFamilies() {
202
+ return this.native.registeredFamilies();
203
+ }
204
+ /**
205
+ * The TSV audit of every registered function's volatility
206
+ * (`chs_function_flags`), VERBATIM: one function per line, six
207
+ * tab-separated fields — `name`, `deterministic`, `deterministic_in_query`,
208
+ * `server_constant`, `stateful`, `resolver_error_code`. ClickHouse's own
209
+ * answers off this build's own registry, and the input to the statelessness
210
+ * gate (`lib/tools/gen_function_flags.py`). Part of the three-question
211
+ * introspection surface every SDK exposes (spec/bindings.md
212
+ * §Introspection).
213
+ *
214
+ * @returns the audit text, verbatim.
215
+ * @throws {UnsupportedError} when the artifact predates
216
+ * `chs_function_flags`.
217
+ */
218
+ functionFlags() {
219
+ return this.native.functionFlags();
220
+ }
221
+ /**
222
+ * Join the DEFAULT evaluator's background threads. `chs_init` registers this
223
+ * with `atexit`, so an ordinary process needs no call; it is REQUIRED before
224
+ * an explicit unload, and useful in tests that must not depend on `atexit`.
225
+ * Idempotent.
226
+ *
227
+ * @throws {ChtypesError} when called from inside another chtypes call on
228
+ * this library (the same reentrancy guard as `setDefaultSettings`).
229
+ */
230
+ shutdown() {
231
+ this.native.shutdown();
232
+ }
233
+ }
234
+ //# sourceMappingURL=library.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.js","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAA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AC,SAAS,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,UAAU,CAAC,GAAW,EAAE,OAAwB;QAC9C,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACvD,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,WAAW,CAAC,QAAQ,CAAC;QACnD,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IAC1F,CAAC;IAED;;;;;;;;OAQG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,kBAAkB,CAAC,QAAkB;QACnC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;;;;;OAUG;IACH,aAAa,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;OASG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;IACrC,CAAC;IAED;;;;;;;;OAQG;IACH,QAAQ;QACN,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Exact numeric comparison. `Decimal(76, 24)`'s extra digits, a quoted 64-bit
3
+ * integer and an `Int256` all have to compare by value and never through a
4
+ * double: `18446744073709551615` must not become `18446744073709552000`, and an
5
+ * `Int256` must not become `-5.78960446186581e+76`. The reference implementation
6
+ * uses `math/big.Rat`; this is the same comparison over `BigInt`.
7
+ */
8
+ /** Fold ClickHouse's denormal spellings onto one of "nan" / "inf" / "-inf". */
9
+ export declare function denormal(s: string): string;
10
+ export declare function parseRational(text: string): {
11
+ num: bigint;
12
+ den: bigint;
13
+ } | null;
14
+ /** Is this text a number (or a denormal token)? */
15
+ export declare function isNumericText(text: string): boolean;
16
+ /** Strip the JSON quoting ClickHouse uses for 64-bit integers and datetimes. */
17
+ export declare function trimQuotes(s: string): string;
18
+ /** Exact numeric equality of two renderings, denormals included. */
19
+ export declare function numEqual(a: string, b: string): boolean;
20
+ //# sourceMappingURL=numeric.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numeric.d.ts","sourceRoot":"","sources":["../src/numeric.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmBH,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAkB1C;AAUD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAoB/E;AAED,mDAAmD;AACnD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAInD;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,oEAAoE;AACpE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAWtD"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Exact numeric comparison. `Decimal(76, 24)`'s extra digits, a quoted 64-bit
3
+ * integer and an `Int256` all have to compare by value and never through a
4
+ * double: `18446744073709551615` must not become `18446744073709552000`, and an
5
+ * `Int256` must not become `-5.78960446186581e+76`. The reference implementation
6
+ * uses `math/big.Rat`; this is the same comparison over `BigInt`.
7
+ */
8
+ /**
9
+ * Whitespace is exactly JSON's four bytes (spec/bindings.md §detectors) — never
10
+ * `String.prototype.trim()`, whose `WhiteSpace` set includes `<ZWNBSP>`.
11
+ * `trim()` here made `<BOM>42` numeric text, and the detector then reported 12
12
+ * `reformat` transforms on CSV/TSV fields that were stored exactly as supplied.
13
+ * The reference implementation's `big.Rat.SetString` tolerates no surrounding
14
+ * whitespace at all, so this is the narrower of the two readings.
15
+ */
16
+ function trimJsonSpace(s) {
17
+ let from = 0;
18
+ let to = s.length;
19
+ const space = (c) => c === ' ' || c === '\t' || c === '\n' || c === '\r';
20
+ while (from < to && space(s[from]))
21
+ from++;
22
+ while (to > from && space(s[to - 1]))
23
+ to--;
24
+ return s.slice(from, to);
25
+ }
26
+ /** Fold ClickHouse's denormal spellings onto one of "nan" / "inf" / "-inf". */
27
+ export function denormal(s) {
28
+ switch (trimJsonSpace(s).toLowerCase()) {
29
+ case 'nan':
30
+ case '__nan__':
31
+ case '-nan':
32
+ return 'nan';
33
+ case 'inf':
34
+ case 'infinity':
35
+ case '__inf__':
36
+ case '+inf':
37
+ return 'inf';
38
+ case '-inf':
39
+ case '-infinity':
40
+ case '__-inf__':
41
+ return '-inf';
42
+ default:
43
+ return '';
44
+ }
45
+ }
46
+ /**
47
+ * A decimal (optionally exponential) literal as an exact rational, or null when
48
+ * the text is not a number. The exponent is bounded: a gateway parses
49
+ * tenant-supplied text, and 1e1000000000 must not become a 10^9-digit integer.
50
+ */
51
+ const MAX_ABS_EXPONENT = 100_000;
52
+ const DECIMAL = /^([+-]?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/;
53
+ export function parseRational(text) {
54
+ const s = trimJsonSpace(text);
55
+ if (s === '')
56
+ return null;
57
+ const m = DECIMAL.exec(s);
58
+ if (m === null)
59
+ return null;
60
+ const sign = m[1] ?? '';
61
+ const int = m[2] ?? '';
62
+ const frac = m[3] ?? '';
63
+ const expText = m[4];
64
+ if (int === '' && frac === '')
65
+ return null;
66
+ const exp = expText === undefined ? 0 : Number(expText);
67
+ if (!Number.isSafeInteger(exp) || Math.abs(exp) > MAX_ABS_EXPONENT)
68
+ return null;
69
+ let num = BigInt((int === '' ? '0' : int) + frac);
70
+ let den = 10n ** BigInt(frac.length);
71
+ if (exp > 0)
72
+ num *= 10n ** BigInt(exp);
73
+ else if (exp < 0)
74
+ den *= 10n ** BigInt(-exp);
75
+ if (sign === '-')
76
+ num = -num;
77
+ return { num, den };
78
+ }
79
+ /** Is this text a number (or a denormal token)? */
80
+ export function isNumericText(text) {
81
+ if (text === '')
82
+ return false;
83
+ if (denormal(text) !== '')
84
+ return true;
85
+ return parseRational(text) !== null;
86
+ }
87
+ /** Strip the JSON quoting ClickHouse uses for 64-bit integers and datetimes. */
88
+ export function trimQuotes(s) {
89
+ return s.replace(/^"+|"+$/g, '');
90
+ }
91
+ /** Exact numeric equality of two renderings, denormals included. */
92
+ export function numEqual(a, b) {
93
+ const x = trimQuotes(a);
94
+ const y = trimQuotes(b);
95
+ if (x === y)
96
+ return true;
97
+ const dx = denormal(x);
98
+ const dy = denormal(y);
99
+ if (dx !== '' || dy !== '')
100
+ return dx === dy;
101
+ const ra = parseRational(x);
102
+ const rb = parseRational(y);
103
+ if (ra === null || rb === null)
104
+ return false;
105
+ return ra.num * rb.den === rb.num * ra.den;
106
+ }
107
+ //# sourceMappingURL=numeric.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numeric.js","sourceRoot":"","sources":["../src/numeric.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,SAAS,aAAa,CAAC,CAAS;IAC9B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC;IAClB,MAAM,KAAK,GAAG,CAAC,CAAS,EAAW,EAAE,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,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I,CAAC;IACvC,OAAO,aAAa,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;AACtC,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvB,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC7C,MAAM,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Where artifacts are looked for and where a fetch writes — the §1 search
3
+ * path of docs/fetch.md, spelled once so the loader (`Registry`), the fetch
4
+ * (`ensure`) and the CLI (`chtypes where`) cannot disagree about it.
5
+ *
6
+ * The search path, in order, first directory that holds the requested line
7
+ * wins:
8
+ *
9
+ * 1. a path given explicitly to the registry constructor
10
+ * 2. `CHTYPES_REGISTRY`
11
+ * 3. `${XDG_CACHE_HOME:-~/.cache}/chtypes/artifacts/<os>-<arch>` — the
12
+ * per-user cache, where fetch installs
13
+ * 4. `/usr/local/share/chtypes/artifacts/<os>-<arch>`, then
14
+ * `/opt/chtypes/artifacts/<os>-<arch>` — system locations, reserved
15
+ *
16
+ * A fetch WRITES to the first of (1), (2), (3) that is set; never to (4).
17
+ */
18
+ /**
19
+ * This host's platform key, `<os>-<arch>` in the artifact spellings
20
+ * (`linux`/`darwin`, `arm64`/`amd64`), e.g. `darwin-arm64`.
21
+ */
22
+ export declare function hostPlatform(): string;
23
+ /** True for the four platform keys a release can carry. */
24
+ export declare function isPlatformKey(key: string): boolean;
25
+ /** `${XDG_CACHE_HOME:-~/.cache}/chtypes` — the root every chtypes cache lives under. */
26
+ export declare function cacheRoot(): string;
27
+ /** The per-user artifact cache for one platform — search-path slot (3). */
28
+ export declare function cacheRegistryDir(platform?: string): string;
29
+ /** The reserved system locations — search-path slot (4), never written by fetch. */
30
+ export declare function systemRegistryDirs(platform?: string): string[];
31
+ /**
32
+ * The §1 search path for one platform: every candidate directory, in order,
33
+ * whether or not it exists. `explicit` is slot (1); `CHTYPES_REGISTRY` is
34
+ * slot (2) when set. Duplicates collapse to their first position.
35
+ */
36
+ export declare function registrySearchPath(explicit?: string, platform?: string): string[];
37
+ /**
38
+ * Where a fetch writes: the first of (1) `explicit`, (2) `CHTYPES_REGISTRY`,
39
+ * (3) the per-user cache that is set — never a system location.
40
+ *
41
+ * `CHTYPES_REGISTRY` names THIS host's registry, so it is only a destination
42
+ * for this host's own platform; artifacts fetched for another platform (a
43
+ * container's `linux-arm64` from a Mac) land in the cache keyed by that
44
+ * platform unless `explicit` says otherwise.
45
+ */
46
+ export declare function fetchDestination(explicit?: string, platform?: string): string;
47
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAGrC;AAED,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wFAAwF;AACxF,wBAAgB,SAAS,IAAI,MAAM,CAIlC;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,QAAQ,GAAE,MAAuB,GAAG,MAAM,CAE1E;AAED,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,QAAQ,GAAE,MAAuB,GAAG,MAAM,EAAE,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAuB,GAAG,MAAM,EAAE,CAOjG;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAuB,GAAG,MAAM,CAK7F"}