@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,326 @@
1
+ /**
2
+ * The result types and the document parsers. Field for field the same concepts
3
+ * as the reference implementation's `RowResult` / `BatchResult`
4
+ * (spec/bindings.md §Result types), in TypeScript spelling.
5
+ *
6
+ * ---------------------------------------------------------------- text vs bytes
7
+ * Every rendered value here comes in both spellings, and which one is
8
+ * authoritative is not a matter of taste:
9
+ *
10
+ * `bytes` the exact slice ClickHouse emitted — the answer. Equivalent to the
11
+ * reference's `json.RawMessage`, and the only form a `String`,
12
+ * `FixedString` or `AggregateFunction` value survives (it holds
13
+ * arbitrary bytes; base64 or `Buffer` it, never a JS string).
14
+ * `text` those bytes decoded as UTF-8, for logs, comparisons and previews.
15
+ * **Lossy exactly when the bytes are not valid UTF-8**, where a JS
16
+ * string can only hold U+FFFD. `isValidUtf8(bytes)` says so.
17
+ *
18
+ * A caller that echoes a value back into an INSERT, hashes it, or compares it
19
+ * against a real server MUST use `bytes`: reporting U+FFFD where the table holds
20
+ * `0xff` is an invented transformation, which is the one thing this product may
21
+ * never do.
22
+ */
23
+ import { type Json } from './json.js';
24
+ /**
25
+ * The verdict on a row or a batch — the error taxonomy in one string, and
26
+ * conflating any two arms is a scoring error (spec/c-abi.md §Error model):
27
+ *
28
+ * - `'accepted'` — the server would take this, possibly with silent coercions
29
+ * (read `transformed`), defaults filled and volatile DEFAULTs substituted
30
+ * (read `substituted` — the caller MUST send those columns explicitly).
31
+ * - `'rejected'` — the server itself would refuse; `errCode` is ClickHouse's
32
+ * own code (27, 117, 455, …) and `errMsg` its own message. Tell the tenant.
33
+ * - `'accepted_poisoned'` — the insert is ACCEPTED (rc = 0) but the stored
34
+ * value can never be read back (`errCode` 691). Never report it as a
35
+ * rejection.
36
+ * - `'unsupported'` — chtypes declines to answer ("a real server might well
37
+ * have accepted this; I will not guess"). NOT a rejection: fall back to the
38
+ * server. Mapping it onto either other arm manufactures an over-reject or an
39
+ * over-accept, both budgeted at zero.
40
+ * - `'skipped'` (2026-08-27) — the row was dropped under
41
+ * `input_format_allow_errors_*` and the batch continued: the server's own
42
+ * skip, itemized. `errCode`/`errMsg` carry the error the vendored reader
43
+ * caught before resyncing, verbatim; `values` is empty — the row is NOT
44
+ * stored. Only ever seen on rows inside a `BatchResult`, never as a batch
45
+ * verdict and never from `Schema#row`.
46
+ */
47
+ export type Outcome = 'accepted' | 'rejected' | 'accepted_poisoned' | 'unsupported' | 'skipped';
48
+ /**
49
+ * One coerced column value, as ClickHouse itself renders it.
50
+ *
51
+ * `bytes` is that rendering verbatim (`0`, `"2023-11-14 22:13:20"`, `[1,0,3]`,
52
+ * a blob with no valid UTF-8 in it) — the same bytes the server would emit for
53
+ * the row, which is what makes it directly comparable against a real ClickHouse.
54
+ * `text` is `bytes` as UTF-8, and it is kept as text on purpose: parsing it into
55
+ * a JS number would turn 18446744073709551615 into 18446744073709552000.
56
+ */
57
+ export interface Value {
58
+ readonly column: string;
59
+ /** ClickHouse's rendering as UTF-8 text; lossy iff `bytes` is not valid UTF-8. */
60
+ readonly text: string;
61
+ /** ClickHouse's rendering, verbatim. **Authoritative.** */
62
+ readonly bytes: Buffer;
63
+ /** True only for a genuine stored null. A poisoned column has no value at all. */
64
+ readonly isNull: boolean;
65
+ /**
66
+ * Where the value came from: `input` | `default` | `default_substituted` |
67
+ * `absent` | `skipped` | `default_volatile_unresolved` | `default_pending` |
68
+ * `default_expr_unsupported` (spec/c-abi.md §`src` values).
69
+ */
70
+ readonly source: string;
71
+ }
72
+ /** A silent change: input 256 into UInt8 stored as 0. */
73
+ export interface Transform {
74
+ readonly column: string;
75
+ readonly input: string;
76
+ readonly stored: string;
77
+ /** The supplied field, verbatim. **Authoritative** where `input` is lossy. */
78
+ readonly inputBytes: Buffer;
79
+ /** The stored rendering, verbatim. **Authoritative** where `stored` is lossy. */
80
+ readonly storedBytes: Buffer;
81
+ /** One of the stable reason strings — see `Reason`. */
82
+ readonly reason: string;
83
+ /** 0-based index of the row inside the request body. */
84
+ row: number;
85
+ /** False for reformat / default_filled / zero_filled / default_materialised. */
86
+ readonly lossy: boolean;
87
+ }
88
+ /** A volatile DEFAULT this library resolved instead of the server. */
89
+ export interface Substitution {
90
+ readonly column: string;
91
+ /** The DEFAULT as ClickHouse canonicalised it, e.g. `now()`. */
92
+ readonly expr: string;
93
+ /** The value rendered by ClickHouse's own serializer. Send it back verbatim. */
94
+ readonly text: string;
95
+ /** The same value as bytes — this is the form to put in the INSERT. */
96
+ readonly bytes: Buffer;
97
+ }
98
+ /** One MATERIALIZED column's value: stored at insert, frozen thereafter. */
99
+ export interface Computed {
100
+ readonly column: string;
101
+ readonly kind: string;
102
+ readonly text: string;
103
+ /** The stored rendering, verbatim. */
104
+ readonly bytes: Buffer;
105
+ }
106
+ /**
107
+ * The verdict on one row: what would be stored, what was silently changed, and
108
+ * which of the five outcomes it is. Returned by `Schema#row` (which never
109
+ * answers `'skipped'` — a single row has no batch to continue), and one per
110
+ * row inside `BatchResult#rows`.
111
+ */
112
+ export interface RowResult {
113
+ /** The coerced stored row, positional, excluding `skipped` columns. */
114
+ readonly values: Value[];
115
+ /** Every silent change. Not optional — it is the product. */
116
+ readonly transformed: Transform[];
117
+ /** The row verdict — see `Outcome` for the four arms and their obligations. */
118
+ readonly outcome: Outcome;
119
+ /**
120
+ * ClickHouse's own code when `rejected`; 691 when `accepted_poisoned`; 0 when
121
+ * `accepted`. NOT a reliable sentinel for `unsupported`: a row-level decline
122
+ * carries the document's code verbatim, which is 0 for e.g. a
123
+ * `DEFAULT hostName()` decline and -2 only on the clock-skew decline — key on
124
+ * `outcome`, never on this number alone (spec/bindings.md §RowResult).
125
+ */
126
+ readonly errCode: number;
127
+ /** ClickHouse's own message, `''` when none. */
128
+ readonly errMsg: string;
129
+ /** Input fields with no matching column. */
130
+ readonly unknownFields: string[];
131
+ /** Non-empty means the answer must not be scored as agreement. */
132
+ readonly unsupportedSettings: string[];
133
+ /**
134
+ * Columns whose volatile DEFAULT this library resolved from its own clock.
135
+ * THE CALLER MUST SEND EVERY ONE OF THESE AS AN EXPLICIT COLUMN in the INSERT:
136
+ * if the server evaluates the expression instead, preview and stored differ
137
+ * always at now64 resolution and sometimes at now() resolution.
138
+ */
139
+ readonly substituted: Substitution[];
140
+ /** MATERIALIZED values — durable, but not part of `SELECT *`. */
141
+ readonly computed: Computed[];
142
+ }
143
+ /**
144
+ * The verdict on a whole request body, which may hold many rows. Returned by
145
+ * `Schema#rows`. The batch is where "not stored" lives: a TTL-expired row is
146
+ * `accepted` in its own `RowResult` and reported not-stored here, through
147
+ * `transformed` and `engineRows`.
148
+ */
149
+ export interface BatchResult {
150
+ /**
151
+ * One `RowResult` per row the reader consumed, in input order — including
152
+ * (2026-08-27) rows dropped under `input_format_allow_errors_*`, which
153
+ * appear as `outcome: 'skipped'` with the server's own caught error and no
154
+ * values. Filter on the row outcome when rendering survivors; a skipped
155
+ * row is never stored.
156
+ */
157
+ readonly rows: RowResult[];
158
+ /** The batch verdict — same vocabulary and obligations as a row's. */
159
+ readonly outcome: Outcome;
160
+ /** ClickHouse's own code when the BATCH was rejected; 0 when accepted. */
161
+ readonly errCode: number;
162
+ /** ClickHouse's own message, `''` when none. */
163
+ readonly errMsg: string;
164
+ /** Rows the reader consumed, failed ones included. */
165
+ readonly rowsRead: number;
166
+ /** Rows dropped under `input_format_allow_errors_num` / `_ratio`. */
167
+ readonly rowsSkipped: number;
168
+ /**
169
+ * Every transform in the batch, each tagged with its row index — including the
170
+ * batch-level `storage_transforms` (a TTL-expired row is `accepted` per row and
171
+ * NOT STORED per batch; dropping these tells a tenant a row was stored that the
172
+ * table deletes at merge time).
173
+ */
174
+ readonly transformed: Transform[];
175
+ /**
176
+ * The stored preview AFTER the engine's insert-time merge, one exact JSON text
177
+ * per row, or null when no engine semantics applied. When present this — not
178
+ * `rows` — is the stored truth: it can be shorter (a SummingMergeTree dropping
179
+ * an all-zero row) or reordered (the block is sorted by the sorting key first).
180
+ */
181
+ readonly engineRows: string[] | null;
182
+ /** The same preview as bytes, positionally aligned with `engineRows`. */
183
+ readonly engineRowsBytes: Buffer[] | null;
184
+ /**
185
+ * The export channel (revision 3; only when `rows()` was asked for an
186
+ * `exportFormat`): the batch's accepted rows, serialized once by the
187
+ * vendored writer, copied out of the C buffer and freed before the call
188
+ * returned — no ownership crosses the FFI boundary. Three states, and the
189
+ * distinction is the ABI's own (spec/c-abi.md §Rows):
190
+ *
191
+ * `undefined` no export was requested, the export was DECLINED
192
+ * (`exportDeclined` then names the reason), or a
193
+ * call-level verdict preempted the export machinery
194
+ * entirely (the batch `outcome` is then the reason and
195
+ * `exportDeclined` stays absent).
196
+ * zero-length Buffer EMITTED-EMPTY: an accepted batch with zero accepted
197
+ * rows — distinguishable from a decline.
198
+ * bytes the exported lines; slice per `spans`.
199
+ */
200
+ readonly payload: Buffer | undefined;
201
+ /**
202
+ * Index-aligned with `rows`: `spans[i]` addresses row i's complete output
203
+ * line (terminating `\n` included) inside `payload` — each slice is itself
204
+ * a valid one-row body in the export format, a non-accepted row carries
205
+ * `{off: 0, len: 0}`, and the concatenation of all non-zero spans
206
+ * reproduces `payload` exactly (batches merge by byte concatenation).
207
+ * `undefined` when no bytes were emitted.
208
+ */
209
+ readonly spans: readonly Span[] | undefined;
210
+ /**
211
+ * The library's reason for withholding requested export bytes (a
212
+ * non-accepted batch, the full-arity guard, a serialization failure,
213
+ * `output_format_json_validate_utf8`) — `undefined` when bytes were emitted
214
+ * or no export was requested. A decline here is -2-class honesty, never a
215
+ * server verdict.
216
+ */
217
+ readonly exportDeclined: string | undefined;
218
+ }
219
+ /** One row's byte range inside an export `payload` — see `BatchResult#spans`. */
220
+ export interface Span {
221
+ readonly off: number;
222
+ readonly len: number;
223
+ }
224
+ /** One entry of the result document's `cols` array, decoded. */
225
+ export interface ColumnDoc {
226
+ readonly name: string;
227
+ readonly type: string;
228
+ readonly base: string;
229
+ readonly src: string;
230
+ readonly input: string;
231
+ readonly refType: string;
232
+ /** Exact JSON text of the stored value; "" when absent or poisoned. */
233
+ readonly stored: string;
234
+ /** Exact JSON text of the reference parse; "" when it does not apply. */
235
+ readonly ref: string;
236
+ /** The raw input field, verbatim — a supplied value can be any byte sequence. */
237
+ readonly inputBytes: Buffer;
238
+ /** The stored rendering, verbatim. **This, not `stored`, is the answer.** */
239
+ readonly storedBytes: Buffer;
240
+ /** The reference parse's rendering, verbatim. */
241
+ readonly refBytes: Buffer;
242
+ readonly nullable: boolean;
243
+ readonly poison: boolean;
244
+ readonly nullInput: boolean;
245
+ readonly dupDropped: boolean;
246
+ /**
247
+ * The C layer found this leaf numeric/temporal but had no reference-ladder
248
+ * entry (audit F4): the classifier treats a visible change as lossy, never
249
+ * `reformat`. Absent from every artifact whose build gate ran.
250
+ */
251
+ readonly refUnclassified: boolean;
252
+ /** True when `stored` is a genuine JSON null. */
253
+ readonly storedIsNull: boolean;
254
+ }
255
+ /** Turn one row document into a `RowResult`. */
256
+ export declare function rowResultOf(doc: Json): RowResult;
257
+ /**
258
+ * Turn one batch document into a `BatchResult`. `payload` is the export
259
+ * channel's copy from the FFI layer (`null` = the ABI's `{NULL, 0}` — mapped
260
+ * to `undefined`; a zero-length Buffer is emitted-empty and kept), which the
261
+ * document itself never carries.
262
+ */
263
+ export declare function batchResultOf(doc: Json, payload?: Buffer | null): BatchResult;
264
+ /**
265
+ * One row's answer from `Filter#rows`. Two of the four states are ANSWERS and
266
+ * two are NOT, and the split is load-bearing: a caller enforcing visibility
267
+ * MUST fail closed (hide the row / fail the request) on `'error'` AND
268
+ * `'decline'` — collapsing either into `'false'`-the-answer inverts
269
+ * fail-closed into fail-open under NOT, the measured leak class
270
+ * (spec/bindings.md §Revision 3).
271
+ *
272
+ * - `'true'` the predicate is non-NULL and non-zero for this row.
273
+ * - `'false'` false OR NULL — SQL's three-valued logic collapsed at the
274
+ * WHERE boundary, computed by the vendored functions.
275
+ * - `'error'` the predicate THREW on this row's values (e.g. NO_COMMON_TYPE
276
+ * 386 from `s = 257` over String). On a real server a WHERE
277
+ * that throws fails the WHOLE query. NOT an answer.
278
+ * - `'decline'` this library declines to answer for this row — unparseable
279
+ * under the schema, poisoned, or the admission envelope
280
+ * tripped. NOT an answer, and the state an unknown verdict
281
+ * character degrades to.
282
+ */
283
+ export type Verdict = 'true' | 'false' | 'error' | 'decline';
284
+ /** Whether a verdict is an ANSWER (`'true'`/`'false'`) rather than an error
285
+ * or a decline. A security-enforcing caller hides the row when this is false. */
286
+ export declare function isAnswer(v: Verdict): boolean;
287
+ /**
288
+ * The CALL-level verdict of `Filter#rows` — whether evaluation completed at
289
+ * all; per-row failures live in the verdicts, not here. An outcome spelling
290
+ * this binding does not recognise degrades to `'unsupported'`, never to
291
+ * `'rejected'` (the unknown-outcome rule, spec/bindings.md §RowResult).
292
+ */
293
+ export type FilterOutcome = 'ok' | 'rejected' | 'unsupported';
294
+ /** One `'error'` or `'decline'` row, itemized: its 0-based index and the code
295
+ * and message verbatim — ClickHouse's own for an error row, this library's
296
+ * decline otherwise. */
297
+ export interface FilterRowError {
298
+ readonly row: number;
299
+ readonly code: number;
300
+ readonly err: string;
301
+ }
302
+ /** One `Filter#rows` answer. */
303
+ export interface FilterResult {
304
+ /** The call-level verdict. On anything but `'ok'`, `verdicts` and `errors`
305
+ * are empty — a malformed body yields no partial answers. */
306
+ readonly outcome: FilterOutcome;
307
+ /** The call-level code: the server's own on `'rejected'` (an unknown
308
+ * setting's 115, a framing error, a binary decode fault); -2 on a decline. */
309
+ readonly errCode: number;
310
+ readonly errMsg: string;
311
+ /** Rows the splitter/decoder yielded. */
312
+ readonly rowsRead: number;
313
+ /** Non-empty means the answer must not be scored as agreement. */
314
+ readonly unsupportedSettings: string[];
315
+ /**
316
+ * One verdict per row, in input order, index-aligned with the rows the
317
+ * reader consumed — the itemized addressing contract holds even across
318
+ * resync tails after a bad text row.
319
+ */
320
+ readonly verdicts: Verdict[];
321
+ /** Every `'error'` and `'decline'` row, itemized. */
322
+ readonly errors: FilterRowError[];
323
+ }
324
+ /** Turn one filter document into a `FilterResult`. */
325
+ export declare function filterResultOf(doc: Json): FilterResult;
326
+ //# sourceMappingURL=results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAWL,KAAK,IAAI,EACV,MAAM,WAAW,CAAC;AAGnB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,mBAAmB,GAAG,aAAa,GAAG,SAAS,CAAC;AAIhG;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAC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WAAW,CA6DnF;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAE7D;iFACiF;AACjF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAE5C;AAED;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,UAAU,GAAG,aAAa,CAAC;AAE9D;;wBAEwB;AACxB,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,gCAAgC;AAChC,MAAM,WAAW,YAAY;IAC3B;iEAC6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC;kFAC8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,kEAAkE;IAClE,QAAQ,CAAC,mBAAmB,EAAE,MAAM,EAAE,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;CACnC;AAED,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,GAAG,EAAE,IAAI,GAAG,YAAY,CAuCtD"}
@@ -0,0 +1,235 @@
1
+ /**
2
+ * The result types and the document parsers. Field for field the same concepts
3
+ * as the reference implementation's `RowResult` / `BatchResult`
4
+ * (spec/bindings.md §Result types), in TypeScript spelling.
5
+ *
6
+ * ---------------------------------------------------------------- text vs bytes
7
+ * Every rendered value here comes in both spellings, and which one is
8
+ * authoritative is not a matter of taste:
9
+ *
10
+ * `bytes` the exact slice ClickHouse emitted — the answer. Equivalent to the
11
+ * reference's `json.RawMessage`, and the only form a `String`,
12
+ * `FixedString` or `AggregateFunction` value survives (it holds
13
+ * arbitrary bytes; base64 or `Buffer` it, never a JS string).
14
+ * `text` those bytes decoded as UTF-8, for logs, comparisons and previews.
15
+ * **Lossy exactly when the bytes are not valid UTF-8**, where a JS
16
+ * string can only hold U+FFFD. `isValidUtf8(bytes)` says so.
17
+ *
18
+ * A caller that echoes a value back into an INSERT, hashes it, or compares it
19
+ * against a real server MUST use `bytes`: reporting U+FFFD where the table holds
20
+ * `0xff` is an invented transformation, which is the one thing this product may
21
+ * never do.
22
+ */
23
+ import { asBool, asBytes, asInt, asString, asStringArray, field, hasField, items, rawBytes, rawText, } from './json.js';
24
+ import { classify, isLossyReason } from './transform.js';
25
+ const EMPTY = Buffer.alloc(0);
26
+ /**
27
+ * Map a document's outcome string. An outcome this binding does not recognise
28
+ * degrades to `unsupported`, never to `rejected` (spec/bindings.md
29
+ * §RowResult, rule added 2026-08-26): a future artifact's new verdict is an
30
+ * answer this binding cannot interpret, and `unsupported` is the arm that is
31
+ * never scored as agreement, while a default of `rejected` would manufacture
32
+ * an over-reject — the zero-budget failure — out of pure vocabulary drift.
33
+ */
34
+ function outcomeOf(s) {
35
+ switch (s) {
36
+ case 'accepted':
37
+ return 'accepted';
38
+ case 'rejected':
39
+ return 'rejected';
40
+ case 'accepted_poisoned':
41
+ return 'accepted_poisoned';
42
+ case 'unsupported':
43
+ return 'unsupported';
44
+ case 'skipped':
45
+ return 'skipped';
46
+ default:
47
+ return 'unsupported';
48
+ }
49
+ }
50
+ function columnDocOf(raw) {
51
+ const poison = asBool(field(raw, 'poison'));
52
+ const inputNode = field(raw, 'input');
53
+ const storedNode = field(raw, 'stored');
54
+ const storedIsNull = storedNode !== undefined && storedNode.kind === 'null';
55
+ const refNode = field(raw, 'ref');
56
+ // Absent, or a literal null: no reference parse applies (the reference
57
+ // implementation's `Ref()` folds both onto "").
58
+ const refPresent = refNode !== undefined && refNode.kind !== 'null';
59
+ // A JSON null in `stored` is a real stored value (a Nullable column holding
60
+ // null), not the absence of one. Only the poison case has no renderable value.
61
+ const storedPresent = storedNode !== undefined && !poison;
62
+ return {
63
+ name: asString(field(raw, 'name')),
64
+ type: asString(field(raw, 'type')),
65
+ base: asString(field(raw, 'base')),
66
+ src: asString(field(raw, 'src')),
67
+ input: asString(inputNode),
68
+ refType: asString(field(raw, 'ref_type')),
69
+ stored: storedPresent ? rawText(storedNode) : '',
70
+ ref: refPresent ? rawText(refNode) : '',
71
+ inputBytes: asBytes(inputNode),
72
+ storedBytes: storedPresent ? rawBytes(storedNode) : EMPTY,
73
+ refBytes: refPresent ? rawBytes(refNode) : EMPTY,
74
+ nullable: asBool(field(raw, 'nullable')),
75
+ poison,
76
+ nullInput: asBool(field(raw, 'null_input')),
77
+ dupDropped: asBool(field(raw, 'dup_dropped')),
78
+ refUnclassified: asBool(field(raw, 'ref_unclassified')),
79
+ storedIsNull,
80
+ };
81
+ }
82
+ /** Turn one row document into a `RowResult`. */
83
+ export function rowResultOf(doc) {
84
+ const unknownFields = asStringArray(field(doc, 'unknown_fields'));
85
+ const unsupportedSettings = asStringArray(field(doc, 'unsupported_settings'));
86
+ let outcome = outcomeOf(asString(field(doc, 'outcome')));
87
+ // A declined setting must never be scored as agreement.
88
+ if (unsupportedSettings.length > 0 && outcome !== 'rejected')
89
+ outcome = 'unsupported';
90
+ const values = [];
91
+ const transformed = [];
92
+ const substituted = [];
93
+ for (const rawCol of items(field(doc, 'cols'))) {
94
+ const c = columnDocOf(rawCol);
95
+ if (c.src === 'skipped')
96
+ continue;
97
+ values.push({
98
+ column: c.name,
99
+ text: c.stored,
100
+ bytes: c.storedBytes,
101
+ isNull: c.storedIsNull && !c.poison,
102
+ source: c.src,
103
+ });
104
+ if (c.src === 'default_substituted') {
105
+ substituted.push({ column: c.name, expr: c.input, text: c.stored, bytes: c.storedBytes });
106
+ }
107
+ transformed.push(...classify(c));
108
+ }
109
+ const computed = items(field(doc, 'computed')).map((raw) => ({
110
+ column: asString(field(raw, 'name')),
111
+ kind: asString(field(raw, 'kind')),
112
+ text: rawText(field(raw, 'stored')),
113
+ bytes: rawBytes(field(raw, 'stored')),
114
+ }));
115
+ return {
116
+ values,
117
+ transformed,
118
+ outcome,
119
+ errCode: asInt(field(doc, 'code')),
120
+ errMsg: asString(field(doc, 'err')),
121
+ unknownFields,
122
+ unsupportedSettings,
123
+ substituted,
124
+ computed,
125
+ };
126
+ }
127
+ /**
128
+ * Turn one batch document into a `BatchResult`. `payload` is the export
129
+ * channel's copy from the FFI layer (`null` = the ABI's `{NULL, 0}` — mapped
130
+ * to `undefined`; a zero-length Buffer is emitted-empty and kept), which the
131
+ * document itself never carries.
132
+ */
133
+ export function batchResultOf(doc, payload = null) {
134
+ const rows = [];
135
+ const transformed = [];
136
+ items(field(doc, 'rows')).forEach((rawRow, index) => {
137
+ const row = rowResultOf(rawRow);
138
+ for (const t of row.transformed)
139
+ t.row = index;
140
+ transformed.push(...row.transformed);
141
+ rows.push(row);
142
+ });
143
+ // storage_transforms is what the STORAGE layer did to rows the type layer
144
+ // accepted: ttl_expired (the row is not stored at all) and ttl_column_expired
145
+ // (the value was reset to the column DEFAULT). Both are lossy by construction
146
+ // and both must be folded in here.
147
+ for (const rawSt of items(field(doc, 'storage_transforms'))) {
148
+ const reason = asString(field(rawSt, 'reason'));
149
+ const stored = hasField(rawSt, 'stored') ? field(rawSt, 'stored') : undefined;
150
+ transformed.push({
151
+ column: asString(field(rawSt, 'column')),
152
+ input: '',
153
+ stored: stored === undefined ? '' : rawText(stored),
154
+ inputBytes: EMPTY,
155
+ storedBytes: rawBytes(stored),
156
+ reason,
157
+ row: asInt(field(rawSt, 'row')),
158
+ // ttl_expired and ttl_column_expired are both lossy by construction.
159
+ lossy: isLossyReason(reason),
160
+ });
161
+ }
162
+ const engineNode = field(doc, 'engine_rows');
163
+ const enginePresent = engineNode !== undefined && engineNode.kind === 'array';
164
+ const engineRowsBytes = enginePresent ? engineNode.items.map((r) => rawBytes(r)) : null;
165
+ // row_spans is present exactly when export bytes were emitted;
166
+ // export_declined exactly when an export was requested and withheld
167
+ // (spec/c-abi.md §Rows). Both absent = no export requested, or a call-level
168
+ // verdict preempted the machinery.
169
+ const spansNode = field(doc, 'row_spans');
170
+ const spans = spansNode === undefined
171
+ ? undefined
172
+ : items(spansNode).map((s) => ({ off: asInt(field(s, 'off')), len: asInt(field(s, 'len')) }));
173
+ const declinedNode = field(doc, 'export_declined');
174
+ const exportDeclined = declinedNode === undefined ? undefined : asString(declinedNode);
175
+ return {
176
+ rows,
177
+ outcome: outcomeOf(asString(field(doc, 'outcome'))),
178
+ errCode: asInt(field(doc, 'code')),
179
+ errMsg: asString(field(doc, 'err')),
180
+ rowsRead: asInt(field(doc, 'rows_read')),
181
+ rowsSkipped: asInt(field(doc, 'rows_skipped')),
182
+ transformed,
183
+ engineRows: engineRowsBytes === null ? null : engineRowsBytes.map((b) => b.toString('utf8')),
184
+ engineRowsBytes,
185
+ payload: payload ?? undefined,
186
+ spans,
187
+ exportDeclined,
188
+ };
189
+ }
190
+ /** Whether a verdict is an ANSWER (`'true'`/`'false'`) rather than an error
191
+ * or a decline. A security-enforcing caller hides the row when this is false. */
192
+ export function isAnswer(v) {
193
+ return v === 'true' || v === 'false';
194
+ }
195
+ /** Turn one filter document into a `FilterResult`. */
196
+ export function filterResultOf(doc) {
197
+ const rawOutcome = asString(field(doc, 'outcome'));
198
+ // 'unsupported', and every spelling this binding does not know, degrades to
199
+ // the decline arm — never the rejection arm.
200
+ const outcome = rawOutcome === 'ok' ? 'ok' : rawOutcome === 'rejected' ? 'rejected' : 'unsupported';
201
+ const base = {
202
+ outcome,
203
+ errCode: asInt(field(doc, 'code')),
204
+ errMsg: asString(field(doc, 'err')),
205
+ rowsRead: asInt(field(doc, 'rows_read')),
206
+ unsupportedSettings: asStringArray(field(doc, 'unsupported_settings')),
207
+ };
208
+ if (outcome !== 'ok')
209
+ return { ...base, verdicts: [], errors: [] };
210
+ const verdicts = [];
211
+ for (const ch of asString(field(doc, 'verdicts'))) {
212
+ switch (ch) {
213
+ case 't':
214
+ verdicts.push('true');
215
+ break;
216
+ case 'f':
217
+ verdicts.push('false');
218
+ break;
219
+ case 'e':
220
+ verdicts.push('error');
221
+ break;
222
+ default:
223
+ // 'd', and any character this binding does not know: decline — fail
224
+ // closed, mirroring the unknown-outcome rule.
225
+ verdicts.push('decline');
226
+ }
227
+ }
228
+ const errors = items(field(doc, 'errors')).map((e) => ({
229
+ row: asInt(field(e, 'row')),
230
+ code: asInt(field(e, 'code')),
231
+ err: asString(field(e, 'err')),
232
+ }));
233
+ return { ...base, verdicts, errors };
234
+ }
235
+ //# sourceMappingURL=results.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.js","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,MAAM,EACN,OAAO,EACP,KAAK,EACL,QAAQ,EACR,aAAa,EACb,KAAK,EACL,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,OAAO,GAER,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AA2BzD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AA0N9B;;;;;;;GAOG;AACH,SAAS,SAAS,CAAC,CAAS;IAC1B,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,UAAU;YACb,OAAO,UAAU,CAAC;QACpB,KAAK,UAAU;YACb,OAAO,UAAU,CAAC;QACpB,KAAK,mBAAmB;YACtB,OAAO,mBAAmB,CAAC;QAC7B,KAAK,aAAa;YAChB,OAAO,aAAa,CAAC;QACvB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,aAAa,CAAC;IACzB,CAAC;AACH,CAAC;AAED,SAAS,WA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