@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/json.js ADDED
@@ -0,0 +1,577 @@
1
+ /**
2
+ * Result-document JSON, **over bytes**, with three obligations no `JSON.parse`
3
+ * can meet.
4
+ *
5
+ * 1. **The bytes are the answer.** A ClickHouse `String`, `FixedString` or
6
+ * `AggregateFunction` value holds arbitrary bytes, and the library emits them
7
+ * into the result document verbatim (`writeJSONString` escapes the control
8
+ * bytes and passes everything else through). Decoding that document into a JS
9
+ * string replaces every invalid byte with U+FFFD, which then reads downstream
10
+ * as a silent transformation that never happened — an *invented* answer, the
11
+ * failure mode this product exists to prevent (spec/c-abi.md §Per-column
12
+ * fields: "`stored` and `ref` MUST be handled as raw bytes / raw JSON"; the
13
+ * reference implementation keeps `json.RawMessage`). So the document is parsed
14
+ * from a `Buffer`, and every value remembers the exact slice it was cut from.
15
+ *
16
+ * 2. **Numbers must keep their exact text.** ClickHouse integers go to 2^256.
17
+ * `JSON.parse` turns 18446744073709551615 into 18446744073709552000 and an
18
+ * Int256 into -5.78960446186581e+76 — a value difference no scorer can tell
19
+ * from a real coercion defect. A number is never converted here: it *is* its
20
+ * own source bytes.
21
+ *
22
+ * 3. **Duplicate keys and escape spellings survive.** ClickHouse can store a
23
+ * `Map` with a repeated key (`{"a":1,"a":2}`), and it writes the escape
24
+ * `\\u000B` where a JS re-serialisation writes `\\u000b`. `JSON.parse` collapses
25
+ * the first and loses the second, and either reports bytes the table does not
26
+ * hold.
27
+ * Object members are therefore kept as an ordered key/value list, and nothing
28
+ * is ever re-rendered: `rawBytes` hands back the library's own slice.
29
+ *
30
+ * The bare-denormal repair is the one edit made to the bytes, and it is
31
+ * required, not optional: ClickHouse's `serializeTextJSON` writes IEEE denormals
32
+ * as the bare tokens `inf`, `-inf` and `nan` unless
33
+ * `output_format_json_quote_denormals` is set. That is faithful ClickHouse
34
+ * output and it is not valid JSON — one QBit column full of infinities took an
35
+ * entire result document down and cost 18 arbiter cases at once.
36
+ * `repairBareDenormals` is the port of `quoteBareDenormals`
37
+ * (go/chtypes/chtypes.go): it quotes the token and changes nothing
38
+ * else, and it runs before any slice is cut, so the reference implementation and
39
+ * this one end up holding the same bytes.
40
+ */
41
+ import { isUtf8 } from 'node:buffer';
42
+ import { ChtypesError } from './errors.js';
43
+ const EMPTY = Buffer.alloc(0);
44
+ const NO_ITEMS = [];
45
+ const NO_KEYS = [];
46
+ /**
47
+ * One parsed JSON value that still knows the exact bytes it came from.
48
+ *
49
+ * `raw` is the equivalent of Go's `json.RawMessage` — the verbatim source slice,
50
+ * which is what any re-rendering of a stored value must use. `bytes` is a
51
+ * scalar's own value: a string's **unescaped** bytes, or a number's / literal's
52
+ * text. A container carries its members in `items` and, for an object, the
53
+ * matching unescaped `keys` — **duplicates included, in source order**.
54
+ */
55
+ export class Json {
56
+ kind;
57
+ raw;
58
+ bytes;
59
+ items;
60
+ keys;
61
+ constructor(kind, raw, bytes = EMPTY, items = NO_ITEMS, keys = NO_KEYS) {
62
+ this.kind = kind;
63
+ this.raw = raw;
64
+ this.bytes = bytes;
65
+ this.items = items;
66
+ this.keys = keys;
67
+ }
68
+ }
69
+ /** True when these bytes are valid UTF-8 — i.e. when their text is exact. */
70
+ export function isValidUtf8(bytes) {
71
+ return isUtf8(bytes);
72
+ }
73
+ // ------------------------------------------------------------------- the parser
74
+ const TAB = 0x09;
75
+ const LF = 0x0a;
76
+ const CR = 0x0d;
77
+ const SPACE = 0x20;
78
+ const QUOTE = 0x22;
79
+ const PLUS = 0x2b;
80
+ const COMMA = 0x2c;
81
+ const MINUS = 0x2d;
82
+ const DOT = 0x2e;
83
+ const SLASH = 0x2f;
84
+ const ZERO = 0x30;
85
+ const NINE = 0x39;
86
+ const COLON = 0x3a;
87
+ const UPPER_E = 0x45;
88
+ const ARRAY_OPEN = 0x5b;
89
+ const BACKSLASH = 0x5c;
90
+ const ARRAY_CLOSE = 0x5d;
91
+ const LOWER_B = 0x62;
92
+ const LOWER_E = 0x65;
93
+ const LOWER_F = 0x66;
94
+ const LOWER_N = 0x6e;
95
+ const LOWER_R = 0x72;
96
+ const LOWER_T = 0x74;
97
+ const LOWER_U = 0x75;
98
+ const OBJECT_OPEN = 0x7b;
99
+ const OBJECT_CLOSE = 0x7d;
100
+ const BACKSPACE = 0x08;
101
+ const FORM_FEED = 0x0c;
102
+ /** JSON's whitespace is exactly these four bytes — see `parseJsonValue`. */
103
+ function isSpace(c) {
104
+ return c === SPACE || c === TAB || c === LF || c === CR;
105
+ }
106
+ function isDigit(c) {
107
+ return c >= ZERO && c <= NINE;
108
+ }
109
+ /** U+FFFD, the only byte sequence this module ever substitutes. */
110
+ const REPLACEMENT = [0xef, 0xbf, 0xbd];
111
+ class Parser {
112
+ b;
113
+ i = 0;
114
+ constructor(b) {
115
+ this.b = b;
116
+ }
117
+ fail(what) {
118
+ throw new ChtypesError(`chtypes: bad result document: ${what} at offset ${this.i}`);
119
+ }
120
+ skipSpace() {
121
+ while (this.i < this.b.length && isSpace(this.b[this.i]))
122
+ this.i++;
123
+ }
124
+ atEnd() {
125
+ return this.i >= this.b.length;
126
+ }
127
+ /** Parse one value, leaving the cursor just past it. */
128
+ value() {
129
+ this.skipSpace();
130
+ if (this.atEnd())
131
+ this.fail('unexpected end of document');
132
+ const c = this.b[this.i];
133
+ switch (c) {
134
+ case OBJECT_OPEN:
135
+ return this.object();
136
+ case ARRAY_OPEN:
137
+ return this.array();
138
+ case QUOTE:
139
+ return this.string();
140
+ case LOWER_T:
141
+ return this.literal('true', 'bool');
142
+ case LOWER_F:
143
+ return this.literal('false', 'bool');
144
+ case LOWER_N:
145
+ return this.literal('null', 'null');
146
+ default:
147
+ if (c === MINUS || isDigit(c))
148
+ return this.number();
149
+ return this.fail(`unexpected byte 0x${c.toString(16)}`);
150
+ }
151
+ }
152
+ literal(word, kind) {
153
+ const start = this.i;
154
+ for (let k = 0; k < word.length; k++) {
155
+ if (this.b[this.i + k] !== word.charCodeAt(k))
156
+ this.fail(`expected ${word}`);
157
+ }
158
+ this.i += word.length;
159
+ const raw = this.b.subarray(start, this.i);
160
+ return new Json(kind, raw, raw);
161
+ }
162
+ /**
163
+ * A JSON number, strictly: no leading `+`, no bare `.5`, no `1.`, no leading
164
+ * zeros. The strictness is load-bearing rather than pedantic — `parseJsonValue`
165
+ * decides with this grammar whether a supplied CSV/TSV field *is* a JSON
166
+ * value, and a lenient reading invents transformations (spec/bindings.md
167
+ * §detectors).
168
+ */
169
+ number() {
170
+ const start = this.i;
171
+ if (this.b[this.i] === MINUS)
172
+ this.i++;
173
+ if (this.atEnd() || !isDigit(this.b[this.i]))
174
+ this.fail('expected a digit');
175
+ if (this.b[this.i] === ZERO) {
176
+ this.i++;
177
+ }
178
+ else {
179
+ while (!this.atEnd() && isDigit(this.b[this.i]))
180
+ this.i++;
181
+ }
182
+ if (this.b[this.i] === DOT) {
183
+ this.i++;
184
+ if (this.atEnd() || !isDigit(this.b[this.i]))
185
+ this.fail('expected a digit after the decimal point');
186
+ while (!this.atEnd() && isDigit(this.b[this.i]))
187
+ this.i++;
188
+ }
189
+ if (this.b[this.i] === LOWER_E || this.b[this.i] === UPPER_E) {
190
+ this.i++;
191
+ if (this.b[this.i] === PLUS || this.b[this.i] === MINUS)
192
+ this.i++;
193
+ if (this.atEnd() || !isDigit(this.b[this.i]))
194
+ this.fail('expected a digit in the exponent');
195
+ while (!this.atEnd() && isDigit(this.b[this.i]))
196
+ this.i++;
197
+ }
198
+ const raw = this.b.subarray(start, this.i);
199
+ return new Json('number', raw, raw);
200
+ }
201
+ /**
202
+ * A JSON string. Its unescaped bytes are a slice of the source when it holds no
203
+ * escape (the common case) and are assembled byte by byte when it does — never
204
+ * through a JS string, so a `String` column's invalid UTF-8 crosses intact.
205
+ */
206
+ string() {
207
+ const start = this.i;
208
+ this.i++; // the opening quote
209
+ let escaped = false;
210
+ for (;;) {
211
+ if (this.atEnd())
212
+ this.fail('unterminated string');
213
+ const c = this.b[this.i];
214
+ if (c === BACKSLASH) {
215
+ escaped = true;
216
+ this.i += 2;
217
+ continue;
218
+ }
219
+ if (c === QUOTE)
220
+ break;
221
+ // A raw control byte is not JSON, and ClickHouse escapes every one of
222
+ // them, so meeting one means this is not the document promised here.
223
+ if (c < SPACE)
224
+ this.fail(`raw control byte 0x${c.toString(16)} in a string`);
225
+ this.i++;
226
+ }
227
+ const inner = this.b.subarray(start + 1, this.i);
228
+ this.i++; // the closing quote
229
+ const raw = this.b.subarray(start, this.i);
230
+ return new Json('string', raw, escaped ? this.unescape(inner) : inner);
231
+ }
232
+ /** Resolve the escapes in a string body. Bytes in, bytes out. */
233
+ unescape(inner) {
234
+ const out = [];
235
+ for (let i = 0; i < inner.length; i++) {
236
+ const c = inner[i];
237
+ if (c !== BACKSLASH) {
238
+ out.push(c);
239
+ continue;
240
+ }
241
+ i++;
242
+ switch (inner[i]) {
243
+ case QUOTE:
244
+ out.push(QUOTE);
245
+ break;
246
+ case BACKSLASH:
247
+ out.push(BACKSLASH);
248
+ break;
249
+ // ClickHouse escapes forward slashes by default
250
+ // (output_format_json_escape_forward_slashes = 1).
251
+ case SLASH:
252
+ out.push(SLASH);
253
+ break;
254
+ case LOWER_B:
255
+ out.push(BACKSPACE);
256
+ break;
257
+ case LOWER_F:
258
+ out.push(FORM_FEED);
259
+ break;
260
+ case LOWER_N:
261
+ out.push(LF);
262
+ break;
263
+ case LOWER_R:
264
+ out.push(CR);
265
+ break;
266
+ case LOWER_T:
267
+ out.push(TAB);
268
+ break;
269
+ case LOWER_U: {
270
+ const hi = this.hex4(inner, i + 1);
271
+ i += 4;
272
+ let cp = hi;
273
+ if (hi >= 0xd800 && hi <= 0xdbff && inner[i + 1] === BACKSLASH && inner[i + 2] === LOWER_U) {
274
+ const lo = this.hex4(inner, i + 3);
275
+ if (lo >= 0xdc00 && lo <= 0xdfff) {
276
+ cp = 0x10000 + ((hi - 0xd800) << 10) + (lo - 0xdc00);
277
+ i += 6;
278
+ }
279
+ }
280
+ // A lone surrogate has no UTF-8 encoding; the reference's `unquote`
281
+ // maps it to U+FFFD, and so does this.
282
+ if (cp >= 0xd800 && cp <= 0xdfff)
283
+ out.push(...REPLACEMENT);
284
+ else
285
+ for (const byte of Buffer.from(String.fromCodePoint(cp), 'utf8'))
286
+ out.push(byte);
287
+ break;
288
+ }
289
+ default:
290
+ this.fail('unknown escape in a string');
291
+ }
292
+ }
293
+ return Buffer.from(out);
294
+ }
295
+ hex4(inner, at) {
296
+ let n = 0;
297
+ for (let k = 0; k < 4; k++) {
298
+ const c = inner[at + k];
299
+ if (c === undefined)
300
+ this.fail('truncated \\u escape');
301
+ const d = c >= 0x30 && c <= 0x39
302
+ ? c - 0x30
303
+ : c >= 0x61 && c <= 0x66
304
+ ? c - 0x61 + 10
305
+ : c >= 0x41 && c <= 0x46
306
+ ? c - 0x41 + 10
307
+ : -1;
308
+ if (d < 0)
309
+ this.fail('bad \\u escape');
310
+ n = n * 16 + d;
311
+ }
312
+ return n;
313
+ }
314
+ array() {
315
+ const start = this.i;
316
+ this.i++;
317
+ const elements = [];
318
+ this.skipSpace();
319
+ if (this.b[this.i] === ARRAY_CLOSE) {
320
+ this.i++;
321
+ return new Json('array', this.b.subarray(start, this.i), EMPTY, elements);
322
+ }
323
+ for (;;) {
324
+ elements.push(this.value());
325
+ this.skipSpace();
326
+ const c = this.b[this.i];
327
+ if (c === COMMA) {
328
+ this.i++;
329
+ continue;
330
+ }
331
+ if (c === ARRAY_CLOSE) {
332
+ this.i++;
333
+ break;
334
+ }
335
+ this.fail('expected , or ] in an array');
336
+ }
337
+ return new Json('array', this.b.subarray(start, this.i), EMPTY, elements);
338
+ }
339
+ object() {
340
+ const start = this.i;
341
+ this.i++;
342
+ const keys = [];
343
+ const values = [];
344
+ this.skipSpace();
345
+ if (this.b[this.i] === OBJECT_CLOSE) {
346
+ this.i++;
347
+ return new Json('object', this.b.subarray(start, this.i), EMPTY, values, keys);
348
+ }
349
+ for (;;) {
350
+ this.skipSpace();
351
+ if (this.b[this.i] !== QUOTE)
352
+ this.fail('expected a quoted key in an object');
353
+ // Duplicate keys are kept: ClickHouse can store a Map with a repeated key,
354
+ // and collapsing it here would report bytes the table does not hold.
355
+ keys.push(this.string().bytes);
356
+ this.skipSpace();
357
+ if (this.b[this.i] !== COLON)
358
+ this.fail('expected : after an object key');
359
+ this.i++;
360
+ values.push(this.value());
361
+ this.skipSpace();
362
+ const c = this.b[this.i];
363
+ if (c === COMMA) {
364
+ this.i++;
365
+ continue;
366
+ }
367
+ if (c === OBJECT_CLOSE) {
368
+ this.i++;
369
+ break;
370
+ }
371
+ this.fail('expected , or } in an object');
372
+ }
373
+ return new Json('object', this.b.subarray(start, this.i), EMPTY, values, keys);
374
+ }
375
+ }
376
+ /**
377
+ * Parse a `chs_row` / `chs_rows` document: denormals repaired, every value
378
+ * carrying the exact bytes the library wrote.
379
+ */
380
+ export function parseDocument(bytes) {
381
+ const p = new Parser(repairBareDenormals(bytes));
382
+ const v = p.value();
383
+ p.skipSpace();
384
+ if (!p.atEnd())
385
+ p.fail('unexpected data after the document');
386
+ return v;
387
+ }
388
+ /**
389
+ * Is this supplied text **one JSON value**? A spec rule rather than a language
390
+ * default (spec/bindings.md §detectors, measured 2026-08-17): the text is a JSON
391
+ * value only if a strict parse consumes **all** of it, with whitespace being
392
+ * exactly JSON's four (space, tab, LF, CR).
393
+ *
394
+ * Both edges cost real false transforms. A numeric *prefix* must not count —
395
+ * `1.2.3.4` is not `1.2` — and U+FEFF is **not** whitespace: JS's own
396
+ * `String.prototype.trim()` counts `<ZWNBSP>` as `WhiteSpace`, so a
397
+ * `trim()`-then-`JSON.parse` reading took a BOM-prefixed CSV field for the
398
+ * number after it and reported 12 `reformat` transforms that never happened.
399
+ * Deciding over bytes with this grammar makes both impossible.
400
+ *
401
+ * Returns `null` when the bytes are not a single JSON value (a TSV field, a bare
402
+ * CSV token, raw bytes).
403
+ */
404
+ export function parseJsonValue(bytes) {
405
+ if (bytes.length === 0)
406
+ return null;
407
+ try {
408
+ const p = new Parser(bytes);
409
+ const v = p.value();
410
+ p.skipSpace();
411
+ return p.atEnd() ? v : null;
412
+ }
413
+ catch {
414
+ return null;
415
+ }
416
+ }
417
+ /**
418
+ * Quote the bare `inf` / `-inf` / `nan` tokens ClickHouse writes outside JSON
419
+ * strings. Port of `quoteBareDenormals`; the stored text is preserved exactly and
420
+ * only the quoting is added, so the slices this module hands out are the bytes
421
+ * ClickHouse would have written.
422
+ */
423
+ export function repairBareDenormals(text) {
424
+ // Fast path: nothing that could be a bare denormal token.
425
+ if (!text.includes('inf') && !text.includes('nan'))
426
+ return text;
427
+ const startsWith = (word, at) => {
428
+ for (let k = 0; k < word.length; k++) {
429
+ if (text[at + k] !== word.charCodeAt(k))
430
+ return false;
431
+ }
432
+ return true;
433
+ };
434
+ const out = [];
435
+ let inString = false;
436
+ for (let i = 0; i < text.length; i++) {
437
+ const c = text[i];
438
+ if (inString) {
439
+ out.push(c);
440
+ if (c === BACKSLASH && i + 1 < text.length) {
441
+ i++;
442
+ out.push(text[i]);
443
+ }
444
+ else if (c === QUOTE) {
445
+ inString = false;
446
+ }
447
+ continue;
448
+ }
449
+ if (c === QUOTE) {
450
+ inString = true;
451
+ out.push(c);
452
+ continue;
453
+ }
454
+ // A value can only start right after one of these structural bytes.
455
+ if (out.length > 0) {
456
+ const prev = out[out.length - 1];
457
+ if (prev !== COLON && prev !== COMMA && prev !== ARRAY_OPEN && !isSpace(prev)) {
458
+ out.push(c);
459
+ continue;
460
+ }
461
+ }
462
+ let token = 0;
463
+ if (startsWith('-inf', i))
464
+ token = 4;
465
+ else if (startsWith('inf', i))
466
+ token = 3;
467
+ else if (startsWith('nan', i))
468
+ token = 3;
469
+ if (token > 0) {
470
+ const after = text[i + token];
471
+ if (after === undefined || after === COMMA || after === OBJECT_CLOSE || after === ARRAY_CLOSE) {
472
+ out.push(QUOTE);
473
+ for (let k = 0; k < token; k++)
474
+ out.push(text[i + k]);
475
+ out.push(QUOTE);
476
+ i += token - 1;
477
+ continue;
478
+ }
479
+ }
480
+ out.push(c);
481
+ }
482
+ return Buffer.from(out);
483
+ }
484
+ // ------------------------------------------------------------------ accessors
485
+ //
486
+ // Every field of a result document is optional: a rejected row's document omits
487
+ // `unknown_fields`, `unsupported_settings` and `computed` entirely and carries
488
+ // `"cols":[]` (spec/c-abi.md §Top-level fields). A binding must therefore treat
489
+ // each field as optional-with-a-default rather than requiring it.
490
+ /**
491
+ * One member of an object, by key. The **last** wins, which is what a JS object,
492
+ * a Go map and the arbiter's own `json.loads` all do — a document field is never
493
+ * repeated, and a stored value is read through `rawBytes`, never by key.
494
+ */
495
+ export function field(value, key) {
496
+ if (value === undefined || value.kind !== 'object')
497
+ return undefined;
498
+ let found;
499
+ for (let i = 0; i < value.keys.length; i++) {
500
+ if (keyIs(value.keys[i], key))
501
+ found = value.items[i];
502
+ }
503
+ return found;
504
+ }
505
+ /**
506
+ * Compare a raw key against a field name without allocating: this runs a dozen
507
+ * times per column and the document's own field names are ASCII. A non-ASCII
508
+ * name falls back to a real decode rather than answering wrongly.
509
+ */
510
+ function keyIs(key, want) {
511
+ for (let i = 0; i < want.length; i++) {
512
+ // One non-ASCII character and the byte length no longer matches the string
513
+ // length, so the fast path cannot answer at all.
514
+ if (want.charCodeAt(i) > 0x7f)
515
+ return key.toString('utf8') === want;
516
+ }
517
+ if (key.length !== want.length)
518
+ return false;
519
+ for (let i = 0; i < want.length; i++) {
520
+ if (key[i] !== want.charCodeAt(i))
521
+ return false;
522
+ }
523
+ return true;
524
+ }
525
+ /** Is this key present at all? `"stored": null` is a value; absence is not. */
526
+ export function hasField(value, key) {
527
+ return field(value, key) !== undefined;
528
+ }
529
+ /** The elements of an array (or an object's values); `[]` for anything else. */
530
+ export function items(value) {
531
+ return value === undefined ? NO_ITEMS : value.items;
532
+ }
533
+ /** A JSON string's text, decoded as UTF-8. `''` for any other kind. */
534
+ export function asString(value) {
535
+ return value !== undefined && value.kind === 'string' ? value.bytes.toString('utf8') : '';
536
+ }
537
+ /** A JSON string's **unescaped bytes** — authoritative where `asString` is not. */
538
+ export function asBytes(value) {
539
+ return value !== undefined && value.kind === 'string' ? value.bytes : EMPTY;
540
+ }
541
+ export function asStringArray(value) {
542
+ return items(value).map((v) => asString(v));
543
+ }
544
+ export function asInt(value) {
545
+ if (value !== undefined && value.kind === 'number') {
546
+ const n = Number(value.raw.toString('utf8'));
547
+ return Number.isFinite(n) ? n : 0;
548
+ }
549
+ return 0;
550
+ }
551
+ export function asBool(value) {
552
+ return value !== undefined && value.kind === 'bool' && value.raw[0] === LOWER_T;
553
+ }
554
+ /**
555
+ * The exact source bytes of a value — the equivalent of holding a
556
+ * `json.RawMessage`. Duplicate keys, escape spellings and 256-bit digits all
557
+ * survive, because nothing is re-rendered.
558
+ *
559
+ * Not the same thing as `asBytes`, and the difference decides correctness: for
560
+ * the string `"a\\u000Bb"` this returns all nine bytes **including the quotes and
561
+ * the escape**, which is what a stored value's rendering is, while `asBytes`
562
+ * returns the three bytes the escape stands for, which is what a *field of the
563
+ * document* (`input`, `name`, `err`) means.
564
+ */
565
+ export function rawBytes(value) {
566
+ return value === undefined ? EMPTY : value.raw;
567
+ }
568
+ /**
569
+ * `rawBytes` decoded as UTF-8, for logs, comparisons and messages. **Lossy when
570
+ * the value is not valid UTF-8** — a ClickHouse `String` column holds arbitrary
571
+ * bytes, `isValidUtf8(rawBytes(v))` says whether this text is exact, and
572
+ * `rawBytes` is the authority.
573
+ */
574
+ export function rawText(value) {
575
+ return rawBytes(value).toString('utf8');
576
+ }
577
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAK3C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9B,MAAM,QAAQ,GAAoB,EAAE,CAAC;AACrC,MAAM,OAAO,GAAsB,EAAE,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,OAAO,IAAI;IAEJ,IAAI;IACJ,GAAG;IACH,KAAK;IACL,KAAK;IACL,IAAI;IALf,YACW,IAAc,EACd,GAAW,EACX,KAAK,GAAW,KAAK,EACrB,KAAK,GAAoB,QAAQ,EACjC,IAAI,GAAsB,OAAO;oBAJjC,IAAI;mBACJ,GAAG;qBACH,KAAK;qBACL,KAAK;oBACL,IAAI;IACZ,CAAC;CACL;AAED,6EAA6E;AAC7E,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,iFAAiF;AAEjF,MAAM,GAAG,GAAG,IAAI,CAAC;AACjB,MAAM,EAAE,GAAG,IAAI,CAAC;AAChB,MAAM,EAAE,GAAG,IAAI,CAAC;AAChB,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,KAA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