@wavehouse/chtypes 0.5.2 → 1.0.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 (195) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +34 -38
  3. package/dist/abi1/buildinfo.d.ts +40 -0
  4. package/dist/abi1/buildinfo.d.ts.map +1 -0
  5. package/dist/abi1/buildinfo.js +83 -0
  6. package/dist/abi1/buildinfo.js.map +1 -0
  7. package/dist/abi1/calls.gen.d.ts +55 -0
  8. package/dist/abi1/calls.gen.d.ts.map +1 -0
  9. package/dist/abi1/calls.gen.js +110 -0
  10. package/dist/abi1/calls.gen.js.map +1 -0
  11. package/dist/abi1/decls.gen.d.ts +115 -0
  12. package/dist/abi1/decls.gen.d.ts.map +1 -0
  13. package/dist/abi1/decls.gen.js +1613 -0
  14. package/dist/abi1/decls.gen.js.map +1 -0
  15. package/dist/abi1/errmap.gen.d.ts +18 -0
  16. package/dist/abi1/errmap.gen.d.ts.map +1 -0
  17. package/dist/abi1/errmap.gen.js +66 -0
  18. package/dist/abi1/errmap.gen.js.map +1 -0
  19. package/dist/abi1/errors.d.ts +107 -0
  20. package/dist/abi1/errors.d.ts.map +1 -0
  21. package/dist/abi1/errors.js +134 -0
  22. package/dist/abi1/errors.js.map +1 -0
  23. package/dist/abi1/handles.d.ts +31 -0
  24. package/dist/abi1/handles.d.ts.map +1 -0
  25. package/dist/abi1/handles.js +76 -0
  26. package/dist/abi1/handles.js.map +1 -0
  27. package/dist/abi1/index.d.ts +17 -0
  28. package/dist/abi1/index.d.ts.map +1 -0
  29. package/dist/abi1/index.js +17 -0
  30. package/dist/abi1/index.js.map +1 -0
  31. package/dist/abi1/libc.d.ts +54 -0
  32. package/dist/abi1/libc.d.ts.map +1 -0
  33. package/dist/abi1/libc.gen.d.ts +12 -0
  34. package/dist/abi1/libc.gen.d.ts.map +1 -0
  35. package/dist/abi1/libc.gen.js +75 -0
  36. package/dist/abi1/libc.gen.js.map +1 -0
  37. package/dist/abi1/libc.js +109 -0
  38. package/dist/abi1/libc.js.map +1 -0
  39. package/dist/abi1/loader.d.ts +99 -0
  40. package/dist/abi1/loader.d.ts.map +1 -0
  41. package/dist/abi1/loader.js +261 -0
  42. package/dist/abi1/loader.js.map +1 -0
  43. package/dist/abi1/raw.d.ts +104 -0
  44. package/dist/abi1/raw.d.ts.map +1 -0
  45. package/dist/abi1/raw.js +296 -0
  46. package/dist/abi1/raw.js.map +1 -0
  47. package/dist/abi1/strictjson.d.ts +19 -0
  48. package/dist/abi1/strictjson.d.ts.map +1 -0
  49. package/dist/abi1/strictjson.js +78 -0
  50. package/dist/abi1/strictjson.js.map +1 -0
  51. package/dist/abi1/vocab.gen.d.ts +169 -0
  52. package/dist/abi1/vocab.gen.d.ts.map +1 -0
  53. package/dist/abi1/vocab.gen.js +306 -0
  54. package/dist/abi1/vocab.gen.js.map +1 -0
  55. package/dist/cli.d.ts +25 -26
  56. package/dist/cli.d.ts.map +1 -1
  57. package/dist/cli.js +206 -218
  58. package/dist/cli.js.map +1 -1
  59. package/dist/documents.d.ts +195 -0
  60. package/dist/documents.d.ts.map +1 -0
  61. package/dist/documents.js +389 -0
  62. package/dist/documents.js.map +1 -0
  63. package/dist/env.d.ts +16 -0
  64. package/dist/env.d.ts.map +1 -0
  65. package/dist/env.js +57 -0
  66. package/dist/env.js.map +1 -0
  67. package/dist/index.d.ts +19 -24
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +17 -23
  70. package/dist/index.js.map +1 -1
  71. package/dist/json.d.ts +11 -89
  72. package/dist/json.d.ts.map +1 -1
  73. package/dist/json.js +16 -180
  74. package/dist/json.js.map +1 -1
  75. package/dist/library.d.ts +53 -309
  76. package/dist/library.d.ts.map +1 -1
  77. package/dist/library.js +77 -315
  78. package/dist/library.js.map +1 -1
  79. package/dist/ocifetch/constants.gen.d.ts +84 -0
  80. package/dist/ocifetch/constants.gen.d.ts.map +1 -0
  81. package/dist/ocifetch/constants.gen.js +92 -0
  82. package/dist/ocifetch/constants.gen.js.map +1 -0
  83. package/dist/ocifetch/dsse.d.ts +114 -0
  84. package/dist/ocifetch/dsse.d.ts.map +1 -0
  85. package/dist/ocifetch/dsse.js +331 -0
  86. package/dist/ocifetch/dsse.js.map +1 -0
  87. package/dist/ocifetch/ensure.d.ts +65 -0
  88. package/dist/ocifetch/ensure.d.ts.map +1 -0
  89. package/dist/ocifetch/ensure.js +775 -0
  90. package/dist/ocifetch/ensure.js.map +1 -0
  91. package/dist/ocifetch/errors.d.ts +92 -0
  92. package/dist/ocifetch/errors.d.ts.map +1 -0
  93. package/dist/ocifetch/errors.js +101 -0
  94. package/dist/ocifetch/errors.js.map +1 -0
  95. package/dist/ocifetch/goldens.d.ts +44 -0
  96. package/dist/ocifetch/goldens.d.ts.map +1 -0
  97. package/dist/ocifetch/goldens.js +62 -0
  98. package/dist/ocifetch/goldens.js.map +1 -0
  99. package/dist/ocifetch/http.d.ts +124 -0
  100. package/dist/ocifetch/http.d.ts.map +1 -0
  101. package/dist/ocifetch/http.js +549 -0
  102. package/dist/ocifetch/http.js.map +1 -0
  103. package/dist/ocifetch/index.d.ts +17 -0
  104. package/dist/ocifetch/index.d.ts.map +1 -0
  105. package/dist/ocifetch/index.js +14 -0
  106. package/dist/ocifetch/index.js.map +1 -0
  107. package/dist/ocifetch/layout.d.ts +126 -0
  108. package/dist/ocifetch/layout.d.ts.map +1 -0
  109. package/dist/ocifetch/layout.js +375 -0
  110. package/dist/ocifetch/layout.js.map +1 -0
  111. package/dist/ocifetch/localverify.d.ts +43 -0
  112. package/dist/ocifetch/localverify.d.ts.map +1 -0
  113. package/dist/ocifetch/localverify.js +164 -0
  114. package/dist/ocifetch/localverify.js.map +1 -0
  115. package/dist/ocifetch/lock.d.ts +39 -0
  116. package/dist/ocifetch/lock.d.ts.map +1 -0
  117. package/dist/ocifetch/lock.js +140 -0
  118. package/dist/ocifetch/lock.js.map +1 -0
  119. package/dist/ocifetch/oci.d.ts +100 -0
  120. package/dist/ocifetch/oci.d.ts.map +1 -0
  121. package/dist/ocifetch/oci.js +323 -0
  122. package/dist/ocifetch/oci.js.map +1 -0
  123. package/dist/ocifetch/referrers.d.ts +55 -0
  124. package/dist/ocifetch/referrers.d.ts.map +1 -0
  125. package/dist/ocifetch/referrers.js +132 -0
  126. package/dist/ocifetch/referrers.js.map +1 -0
  127. package/dist/ocifetch/types.d.ts +167 -0
  128. package/dist/ocifetch/types.d.ts.map +1 -0
  129. package/dist/ocifetch/types.js +88 -0
  130. package/dist/ocifetch/types.js.map +1 -0
  131. package/dist/ocifetch/unpack.d.ts +55 -0
  132. package/dist/ocifetch/unpack.d.ts.map +1 -0
  133. package/dist/ocifetch/unpack.js +205 -0
  134. package/dist/ocifetch/unpack.js.map +1 -0
  135. package/dist/registry.d.ts +38 -387
  136. package/dist/registry.d.ts.map +1 -1
  137. package/dist/registry.js +94 -819
  138. package/dist/registry.js.map +1 -1
  139. package/dist/schema.d.ts +77 -588
  140. package/dist/schema.d.ts.map +1 -1
  141. package/dist/schema.js +87 -549
  142. package/dist/schema.js.map +1 -1
  143. package/dist/settings.d.ts +27 -36
  144. package/dist/settings.d.ts.map +1 -1
  145. package/dist/settings.js +75 -25
  146. package/dist/settings.js.map +1 -1
  147. package/dist/setup.d.ts +37 -0
  148. package/dist/setup.d.ts.map +1 -0
  149. package/dist/setup.js +60 -0
  150. package/dist/setup.js.map +1 -0
  151. package/dist/tar.d.ts +27 -11
  152. package/dist/tar.d.ts.map +1 -1
  153. package/dist/tar.js +54 -32
  154. package/dist/tar.js.map +1 -1
  155. package/package.json +2 -2
  156. package/dist/discover.d.ts +0 -142
  157. package/dist/discover.d.ts.map +0 -1
  158. package/dist/discover.js +0 -288
  159. package/dist/discover.js.map +0 -1
  160. package/dist/error-codes.d.ts +0 -80
  161. package/dist/error-codes.d.ts.map +0 -1
  162. package/dist/error-codes.js +0 -139
  163. package/dist/error-codes.js.map +0 -1
  164. package/dist/errors.d.ts +0 -284
  165. package/dist/errors.d.ts.map +0 -1
  166. package/dist/errors.js +0 -321
  167. package/dist/errors.js.map +0 -1
  168. package/dist/fetch.d.ts +0 -382
  169. package/dist/fetch.d.ts.map +0 -1
  170. package/dist/fetch.js +0 -1498
  171. package/dist/fetch.js.map +0 -1
  172. package/dist/ffi.d.ts +0 -410
  173. package/dist/ffi.d.ts.map +0 -1
  174. package/dist/ffi.js +0 -1154
  175. package/dist/ffi.js.map +0 -1
  176. package/dist/format.d.ts +0 -128
  177. package/dist/format.d.ts.map +0 -1
  178. package/dist/format.js +0 -132
  179. package/dist/format.js.map +0 -1
  180. package/dist/numeric.d.ts +0 -20
  181. package/dist/numeric.d.ts.map +0 -1
  182. package/dist/numeric.js +0 -107
  183. package/dist/numeric.js.map +0 -1
  184. package/dist/paths.d.ts +0 -55
  185. package/dist/paths.d.ts.map +0 -1
  186. package/dist/paths.js +0 -87
  187. package/dist/paths.js.map +0 -1
  188. package/dist/results.d.ts +0 -495
  189. package/dist/results.d.ts.map +0 -1
  190. package/dist/results.js +0 -406
  191. package/dist/results.js.map +0 -1
  192. package/dist/transform.d.ts +0 -73
  193. package/dist/transform.d.ts.map +0 -1
  194. package/dist/transform.js +0 -533
  195. package/dist/transform.js.map +0 -1
package/dist/env.js ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The fetch layer's environment (`docs/guides/fetch-v1.md` §2 and §4): the
3
+ * variables that configure a fetch without code. `CHTYPES_ARTIFACTS_URL` and
4
+ * `CHTYPES_CACHE` are read by the fetch layer itself; the rest are read here,
5
+ * once, and an option the caller passed always wins over its variable.
6
+ *
7
+ * CHTYPES_DOWNLOAD_TOKEN `token`
8
+ * CHTYPES_TRUSTED_KEYS `trustedKeys`: comma-separated raw ed25519 keys, 64 hex characters each; REPLACES the default list
9
+ * CHTYPES_ALLOW_UNSIGNED `allowUnsigned`: `1`, `true`, `yes` or `on`
10
+ * CHTYPES_TARGET `platform`: one of the three platform keys
11
+ * CHTYPES_REGISTRY retired: one warning, otherwise ignored
12
+ */
13
+ import { usageError } from './abi1/index.js';
14
+ import { ENV_ALLOW_UNSIGNED_NAME, ENV_BASES_NAME, ENV_CACHE_NAME, ENV_RETIRED, ENV_TARGET_NAME, ENV_TOKEN_NAME, ENV_TRUSTED_KEYS_NAME, PLATFORMS, } from './ocifetch/constants.gen.js';
15
+ import { isPlatformKey, keyIdOfRawKey } from './ocifetch/index.js';
16
+ const RAW_KEY = /^[0-9a-fA-F]{64}$/;
17
+ let warnedRetired = false;
18
+ function flag(name) {
19
+ const v = process.env[name];
20
+ return v !== undefined && ['1', 'true', 'yes', 'on'].includes(v.trim().toLowerCase());
21
+ }
22
+ /** Fills each option the caller left unset from its environment variable. Pure over `process.env`, except the one retired-variable warning. */
23
+ export function withEnvironment(options) {
24
+ const out = { ...options };
25
+ for (const name of ENV_RETIRED) {
26
+ const v = process.env[name];
27
+ if (v !== undefined && v !== '' && !warnedRetired) {
28
+ warnedRetired = true;
29
+ process.emitWarning(`${name} is retired and ignored; ${ENV_BASES_NAME} and ${ENV_CACHE_NAME} replace it`, { code: 'CHTYPES_ENV_RETIRED' });
30
+ }
31
+ }
32
+ const token = process.env[ENV_TOKEN_NAME];
33
+ if (out.token === undefined && token !== undefined && token !== '')
34
+ out.token = token;
35
+ if (out.allowUnsigned === undefined && flag(ENV_ALLOW_UNSIGNED_NAME))
36
+ out.allowUnsigned = true;
37
+ const keys = process.env[ENV_TRUSTED_KEYS_NAME];
38
+ if (out.trustedKeys === undefined && keys !== undefined && keys.trim() !== '') {
39
+ const list = [];
40
+ for (const k of keys.split(',').map((x) => x.trim()).filter((x) => x !== '')) {
41
+ if (!RAW_KEY.test(k)) {
42
+ throw usageError(`${ENV_TRUSTED_KEYS_NAME}: ${JSON.stringify(k)} is not a raw ed25519 public key (64 hex characters)`);
43
+ }
44
+ list.push({ keyid: keyIdOfRawKey(k), ed25519Hex: k.toLowerCase() });
45
+ }
46
+ out.trustedKeys = list;
47
+ }
48
+ const target = process.env[ENV_TARGET_NAME];
49
+ if (out.platform === undefined && target !== undefined && target !== '') {
50
+ if (!isPlatformKey(target)) {
51
+ throw usageError(`${ENV_TARGET_NAME}: ${JSON.stringify(target)} is not a platform; use one of ${PLATFORMS.map((p) => p.key).join(', ')}`);
52
+ }
53
+ out.platform = target;
54
+ }
55
+ return out;
56
+ }
57
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,WAAW,EACX,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,SAAS,GACV,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAuB,aAAa,EAAE,aAAa,EAAmB,MAAM,qBAAqB,CAAC;AAEzG,MAAM,OAAO,GAAG,mBAAmB,CAAC;AACpC,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,SAAS,IAAI,CAAC,IAAY;IACxB,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACxF,CAAC;AAED,+IAA+I;AAC/I,MAAM,UAAU,eAAe,CAA2B,OAAU;IAClE,MAAM,GAAG,GAAiE,EAAE,GAAG,OAAO,EAAE,CAAC;IACzF,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,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AAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACtE,CAAC;QACD,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;IACzB,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC5C,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;QACxE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,MAAM,UAAU,CAAC,GAAG,eAAe,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kCAAkC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5I,CAAC;QACD,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC;IACxB,CAAC;IACD,OAAO,GAAQ,CAAC;AAClB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,29 +1,24 @@
1
1
  /**
2
- * `@wavehouse/chtypes` — ClickHouse's own type system, per version.
2
+ * `@wavehouse/chtypes`: ClickHouse's own type system, per version, over the
3
+ * ABI v1 C layer (`docs/reference/bindings-v1.md` is the contract).
3
4
  *
4
- * Registry --for(version)--> Library --compileDdl(ddl)--> Schema --rows(...)--> BatchResult
5
- * | |
6
- * validateType(expr) setEngine / setTtl row(...) --> RowResult
5
+ * setup(...) optional, once, before the first open
6
+ * Registry.open() --for(request)--> Library --compileTable(createTable)--> Schema --rows(...)--> BatchResult
7
+ * | |
8
+ * validateType(expr) row(...) --> RowResult
7
9
  *
8
- * Nothing here reimplements a coercion rule: every answer comes from ClickHouse's
9
- * own C++ (`DataTypeFactory`, `ISerialization`, `ReadHelpers`,
10
- * `evaluateMissingDefaults`, the TTL algorithms, `MergeTreeDataWriter::mergeBlock`)
11
- * vendored per release behind the frozen `chs_*` C ABI. The one derived answer is
12
- * `transformed`, and it is the reason the product exists.
10
+ * Nothing here reimplements a ClickHouse rule: every answer comes from
11
+ * ClickHouse's own C++, vendored per release behind the C ABI, and every result
12
+ * is a one-to-one decode of the document the library returned. `Registry.open`,
13
+ * `for` and `installed` are asynchronous only because the fetch layer is.
13
14
  */
14
- export { type DiscoveredColumn, parseChangedSettingsResult, parseColumnsResult, parseVersionResult, QUERY_CHANGED_SETTINGS, QUERY_SERVER_VERSION, QUERY_TABLE_COLUMNS, type ServerProfile, } from './discover.js';
15
- export { type ErrorCodeEntry, ErrorCodeTable } from './error-codes.js';
16
- export { ABI_REVISION, ArtifactCorruptError, ArtifactError, type ArtifactErrorCode, ArtifactMissingError, ArtifactPinnedError, ArtifactUnpublishedError, ArtifactUntrustedError, artifactMissingMessage, ChtypesError, CODE_ARTIFACT_CORRUPT, CODE_ARTIFACT_MISSING, CODE_ARTIFACT_PINNED, CODE_ARTIFACT_UNPUBLISHED, CODE_ARTIFACT_UNTRUSTED, CODE_SOURCE_UNREACHABLE, CODE_UNSUPPORTED, FETCH_COMMAND, FetchError, InitConflictError, RegistryError, SchemaError, SourceUnreachableError, UnsupportedError, } from './errors.js';
17
- export { compareVersions, DEFAULT_ARTIFACTS_URL, DEFAULT_LOCK_FILE, DEFAULT_RELEASE_TAG, type EnsureOptions, type EnsureResult, ensure, ensureAll, type FetchEvent, type IndexArtifact, type InstalledArtifact, keyId, type ListResult, LOCK_SCHEMA, type LockEntry, type LockFile, listArtifacts, parseSignatureFile, parseVersionSpelling, RELEASE_KEY_ID, RELEASE_PUBLIC_KEYS, type ReleaseIndex, readLock, resolvePlatform, selectAll, selectArtifact, sha256File, trustedKeys, type VersionRequest, verifyEd25519, verifyInstalled, } from './fetch.js';
18
- export { nativeStats } from './ffi.js';
19
- export { DOC_ALL, DOC_DEFAULTS, DOC_TRANSFORMS, DOC_VALUES, EXPORT_NONE, Format, formatName, } from './format.js';
20
- export { isValidUtf8, Json, type JsonKind, parseDocument, parseJsonValue, rawBytes, rawText, repairBareDenormals, } from './json.js';
21
- export { CompileMode, type CompileOptions, Library, minorOf } from './library.js';
22
- export { cacheRegistryDir, ENV_AUTOFETCH, ENV_REGISTRY, fetchDestination, hostPlatform, isPlatformKey, registrySearchPath, systemRegistryDirs, } from './paths.js';
23
- export { compareMinor, defaultRegistryDir, looksLikeRegistry, type Manifest, Registry, type RegistryOptions, type Resolution, resolveRegistryDir, } from './registry.js';
24
- export { type BatchResult, type ColumnDoc, type Computed, DefaultKind, FilterOutcome, type FilterResult, type FilterRowError, isAnswer, Outcome, type RowResult, Source, type Span, type Substitution, type Transform, type Value, Verdict, } from './results.js';
25
- export { Block, type ColumnInfo, type CompileFilterOptions, type EngineOptions, Filter, type RowOptions, type RowsOptions, Schema, } from './schema.js';
26
- export { encodeSettings, type Settings, type SettingValue } from './settings.js';
27
- export { type ExtractedEntry, extractTarGz } from './tar.js';
28
- export { isLossyReason, Reason } from './transform.js';
15
+ export { type BuildInfo, type Capabilities, type BatchOutcome, DefaultKind, DiscoverQueryParam, DocFlags, EXPORT_NONE, FilterOutcome, Format, formatChName, Outcome, Reason, reasonLossy, Source, sourceIsStored, Status, Verdict, verdictAnswered, } from './abi1/index.js';
16
+ export { ArtifactCorruptError, ArtifactError, ArtifactIncompatibleError, CallError, type CallErrorFields, ChtypesError, InternalError, isChtypesError, LoaderCorruptError, type LoaderErrorFields, SchemaError, UnsupportedError, UsageError, } from './abi1/index.js';
17
+ export { type BatchResult, type Column, type Computed, type DiscoveredColumn, type EngineCell, type Discovery, type ErrorCodeEntry, ErrorCodeTable, type FilterResult, type FilterRowError, type Framing, type Header, type RowResult, type SchemaDescription, type Span, type Transform, type Value, } from './documents.js';
18
+ export { Library, openUnverified } from './library.js';
19
+ export { ArtifactMissingError, ArtifactPinnedError, ArtifactUnpublishedError, ArtifactUntrustedError, type Resolved, SourceForbiddenError, SourceIncompatibleError, SourceUnauthorizedError, SourceUnreachableError, } from './ocifetch/index.js';
20
+ export { type FetchOptions, Registry, type RegistryOptions } from './registry.js';
21
+ export { Block, type CompileOptions, type EvalOptions, Filter, type FilterOptions, type RowOptions, type RowsOptions, Schema, } from './schema.js';
22
+ export type { BytesIn, Settings } from './settings.js';
23
+ export { setup, type SetupOptions } from './setup.js';
29
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,KAAK,gBAAgB,EACrB,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,KAAK,iBAAiB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,MAAM,EACN,SAAS,EACT,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,EACL,KAAK,UAAU,EACf,WAAW,EACX,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACnB,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GACP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,KAAK,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,aAAa,EACb,MAAM,EACN,YAAY,EACZ,OAAO,EACP,MAAM,EACN,WAAW,EACX,MAAM,EACN,cAAc,EACd,MAAM,EACN,OAAO,EACP,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,yBAAyB,EACzB,SAAS,EACT,KAAK,eAAe,EACpB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,WAAW,EACX,gBAAgB,EAChB,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,KAAK,GACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,KAAK,QAAQ,EACb,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,YAAY,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EACL,KAAK,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,MAAM,EACN,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,MAAM,GACP,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,29 +1,23 @@
1
1
  /**
2
- * `@wavehouse/chtypes` — ClickHouse's own type system, per version.
2
+ * `@wavehouse/chtypes`: ClickHouse's own type system, per version, over the
3
+ * ABI v1 C layer (`docs/reference/bindings-v1.md` is the contract).
3
4
  *
4
- * Registry --for(version)--> Library --compileDdl(ddl)--> Schema --rows(...)--> BatchResult
5
- * | |
6
- * validateType(expr) setEngine / setTtl row(...) --> RowResult
5
+ * setup(...) optional, once, before the first open
6
+ * Registry.open() --for(request)--> Library --compileTable(createTable)--> Schema --rows(...)--> BatchResult
7
+ * | |
8
+ * validateType(expr) row(...) --> RowResult
7
9
  *
8
- * Nothing here reimplements a coercion rule: every answer comes from ClickHouse's
9
- * own C++ (`DataTypeFactory`, `ISerialization`, `ReadHelpers`,
10
- * `evaluateMissingDefaults`, the TTL algorithms, `MergeTreeDataWriter::mergeBlock`)
11
- * vendored per release behind the frozen `chs_*` C ABI. The one derived answer is
12
- * `transformed`, and it is the reason the product exists.
10
+ * Nothing here reimplements a ClickHouse rule: every answer comes from
11
+ * ClickHouse's own C++, vendored per release behind the C ABI, and every result
12
+ * is a one-to-one decode of the document the library returned. `Registry.open`,
13
+ * `for` and `installed` are asynchronous only because the fetch layer is.
13
14
  */
14
- export { parseChangedSettingsResult, parseColumnsResult, parseVersionResult, QUERY_CHANGED_SETTINGS, QUERY_SERVER_VERSION, QUERY_TABLE_COLUMNS, } from './discover.js';
15
- export { ErrorCodeTable } from './error-codes.js';
16
- export { ABI_REVISION, ArtifactCorruptError, ArtifactError, ArtifactMissingError, ArtifactPinnedError, ArtifactUnpublishedError, ArtifactUntrustedError, artifactMissingMessage, ChtypesError, CODE_ARTIFACT_CORRUPT, CODE_ARTIFACT_MISSING, CODE_ARTIFACT_PINNED, CODE_ARTIFACT_UNPUBLISHED, CODE_ARTIFACT_UNTRUSTED, CODE_SOURCE_UNREACHABLE, CODE_UNSUPPORTED, FETCH_COMMAND, FetchError, InitConflictError, RegistryError, SchemaError, SourceUnreachableError, UnsupportedError, } from './errors.js';
17
- export { compareVersions, DEFAULT_ARTIFACTS_URL, DEFAULT_LOCK_FILE, DEFAULT_RELEASE_TAG, ensure, ensureAll, keyId, LOCK_SCHEMA, listArtifacts, parseSignatureFile, parseVersionSpelling, RELEASE_KEY_ID, RELEASE_PUBLIC_KEYS, readLock, resolvePlatform, selectAll, selectArtifact, sha256File, trustedKeys, verifyEd25519, verifyInstalled, } from './fetch.js';
18
- export { nativeStats } from './ffi.js';
19
- export { DOC_ALL, DOC_DEFAULTS, DOC_TRANSFORMS, DOC_VALUES, EXPORT_NONE, Format, formatName, } from './format.js';
20
- export { isValidUtf8, Json, parseDocument, parseJsonValue, rawBytes, rawText, repairBareDenormals, } from './json.js';
21
- export { CompileMode, Library, minorOf } from './library.js';
22
- export { cacheRegistryDir, ENV_AUTOFETCH, ENV_REGISTRY, fetchDestination, hostPlatform, isPlatformKey, registrySearchPath, systemRegistryDirs, } from './paths.js';
23
- export { compareMinor, defaultRegistryDir, looksLikeRegistry, Registry, resolveRegistryDir, } from './registry.js';
24
- export { DefaultKind, FilterOutcome, isAnswer, Outcome, Source, Verdict, } from './results.js';
15
+ export { DefaultKind, DiscoverQueryParam, DocFlags, EXPORT_NONE, FilterOutcome, Format, formatChName, Outcome, Reason, reasonLossy, Source, sourceIsStored, Status, Verdict, verdictAnswered, } from './abi1/index.js';
16
+ export { ArtifactCorruptError, ArtifactError, ArtifactIncompatibleError, CallError, ChtypesError, InternalError, isChtypesError, LoaderCorruptError, SchemaError, UnsupportedError, UsageError, } from './abi1/index.js';
17
+ export { ErrorCodeTable, } from './documents.js';
18
+ export { Library, openUnverified } from './library.js';
19
+ export { ArtifactMissingError, ArtifactPinnedError, ArtifactUnpublishedError, ArtifactUntrustedError, SourceForbiddenError, SourceIncompatibleError, SourceUnauthorizedError, SourceUnreachableError, } from './ocifetch/index.js';
20
+ export { Registry } from './registry.js';
25
21
  export { Block, Filter, Schema, } from './schema.js';
26
- export { encodeSettings } from './settings.js';
27
- export { extractTarGz } from './tar.js';
28
- export { isLossyReason, Reason } from './transform.js';
22
+ export { setup } from './setup.js';
29
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAEL,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,GAEpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAuB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,aAAa,EAEb,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,sBAAsB,EACtB,g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AAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAIL,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,aAAa,EACb,MAAM,EACN,YAAY,EACZ,OAAO,EACP,MAAM,EACN,WAAW,EACX,MAAM,EACN,cAAc,EACd,MAAM,EACN,OAAO,EACP,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,yBAAyB,EACzB,SAAS,EAET,YAAY,EACZ,aAAa,EACb,cAAc,EACd,kBAAkB,EAElB,WAAW,EACX,gBAAgB,EAChB,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAQL,cAAc,GAUf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EAEtB,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAqB,QAAQ,EAAwB,MAAM,eAAe,CAAC;AAClF,OAAO,EACL,KAAK,EAGL,MAAM,EAIN,MAAM,GACP,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC"}
package/dist/json.d.ts CHANGED
@@ -1,42 +1,10 @@
1
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 (the C ABI contract §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-serialization 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.
2
+ * The fetch layer's JSON plumbing: a parser over bytes whose values remember the
3
+ * exact slice they were cut from, with duplicate keys kept in source order (the
4
+ * fetch layer's own duplicate-key refusals read them). The result documents of
5
+ * the C layer no longer use it: they are decoded with the stock `JSON.parse`
6
+ * (`./documents.ts`), because the library's documents are valid RFC 8259 JSON.
7
+ * It is kept for the fetch layer's use only.
40
8
  */
41
9
  /** The six JSON kinds. `number` keeps its text; nothing is ever converted. */
42
10
  export type JsonKind = 'null' | 'bool' | 'number' | 'string' | 'array' | 'object';
@@ -60,68 +28,22 @@ export declare class Json {
60
28
  /** True when these bytes are valid UTF-8 — i.e. when their text is exact. */
61
29
  export declare function isValidUtf8(bytes: Uint8Array): boolean;
62
30
  /**
63
- * Parse a `chs_row` / `chs_rows` document: denormals repaired, every value
64
- * carrying the exact bytes the library wrote.
65
- */
66
- export declare function parseDocument(bytes: Buffer): Json;
67
- /**
68
- * Is this supplied text **one JSON value**? A spec rule rather than a language
69
- * default (docs/reference/bindings.md §detectors, measured 2026-08-17): the text is a JSON
70
- * value only if a strict parse consumes **all** of it, with whitespace being
71
- * exactly JSON's four (space, tab, LF, CR).
72
- *
73
- * Both edges cost real false transforms. A numeric *prefix* must not count —
74
- * `1.2.3.4` is not `1.2` — and U+FEFF is **not** whitespace: JS's own
75
- * `String.prototype.trim()` counts `<ZWNBSP>` as `WhiteSpace`, so a
76
- * `trim()`-then-`JSON.parse` reading took a BOM-prefixed CSV field for the
77
- * number after it and reported 12 `reformat` transforms that never happened.
78
- * Deciding over bytes with this grammar makes both impossible.
31
+ * Is this byte string **one JSON value**? It is only if a strict parse consumes
32
+ * **all** of it, with whitespace being exactly JSON's four (space, tab, LF, CR).
33
+ * A numeric *prefix* does not count (`1.2.3.4` is not `1.2`), and U+FEFF is
34
+ * **not** whitespace, though JS's own `String.prototype.trim()` counts it as one.
79
35
  *
80
- * Returns `null` when the bytes are not a single JSON value (a TSV field, a bare
81
- * CSV token, raw bytes).
36
+ * Returns `null` when the bytes are not a single JSON value.
82
37
  */
83
38
  export declare function parseJsonValue(bytes: Buffer): Json | null;
84
- /**
85
- * Quote the bare `inf` / `-inf` / `nan` tokens ClickHouse writes outside JSON
86
- * strings. Port of `quoteBareDenormals`; the stored text is preserved exactly and
87
- * only the quoting is added, so the slices this module hands out are the bytes
88
- * ClickHouse would have written.
89
- */
90
- export declare function repairBareDenormals(text: Buffer): Buffer;
91
39
  /**
92
40
  * One member of an object, by key. The **last** wins, which is what a JS object,
93
41
  * a Go map and the arbiter's own `json.loads` all do — a document field is never
94
42
  * repeated, and a stored value is read through `rawBytes`, never by key.
95
43
  */
96
44
  export declare function field(value: Json | undefined, key: string): Json | undefined;
97
- /** Is this key present at all? `"stored": null` is a value; absence is not. */
98
- export declare function hasField(value: Json | undefined, key: string): boolean;
99
45
  /** The elements of an array (or an object's values); `[]` for anything else. */
100
46
  export declare function items(value: Json | undefined): readonly Json[];
101
47
  /** A JSON string's text, decoded as UTF-8. `''` for any other kind. */
102
48
  export declare function asString(value: Json | undefined): string;
103
- /** A JSON string's **unescaped bytes** — authoritative where `asString` is not. */
104
- export declare function asBytes(value: Json | undefined): Buffer;
105
- export declare function asStringArray(value: Json | undefined): string[];
106
- export declare function asInt(value: Json | undefined): number;
107
- export declare function asBool(value: Json | undefined): boolean;
108
- /**
109
- * The exact source bytes of a value — the equivalent of holding a
110
- * `json.RawMessage`. Duplicate keys, escape spellings and 256-bit digits all
111
- * survive, because nothing is re-rendered.
112
- *
113
- * Not the same thing as `asBytes`, and the difference decides correctness: for
114
- * the string `"a\\u000Bb"` this returns all nine bytes **including the quotes and
115
- * the escape**, which is what a stored value's rendering is, while `asBytes`
116
- * returns the three bytes the escape stands for, which is what a *field of the
117
- * document* (`input`, `name`, `err`) means.
118
- */
119
- export declare function rawBytes(value: Json | undefined): Buffer;
120
- /**
121
- * `rawBytes` decoded as UTF-8, for logs, comparisons and messages. **Lossy when
122
- * the value is not valid UTF-8** — a ClickHouse `String` column holds arbitrary
123
- * bytes, `isValidUtf8(rawBytes(v))` says whether this text is exact, and
124
- * `rawBytes` is the authority.
125
- */
126
- export declare function rawText(value: Json | undefined): string;
127
49
  //# sourceMappingURL=json.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAKH,8EAA8E;AA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EAAE,UAAU,GAAG,OAAO,CAEtD;AAySD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAUzD;AASD;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAO5E;AAoBD,gFAAgF;AAChF,wBAAgB,KAAK,CAAC,KAAK,EAAE,IAAI,GAAG,SAAS,GAAG,SAAS,IAAI,EAAE,CAE9D;AAED,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,CAExD"}
package/dist/json.js CHANGED
@@ -1,45 +1,13 @@
1
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 (the C ABI contract §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-serialization 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.
2
+ * The fetch layer's JSON plumbing: a parser over bytes whose values remember the
3
+ * exact slice they were cut from, with duplicate keys kept in source order (the
4
+ * fetch layer's own duplicate-key refusals read them). The result documents of
5
+ * the C layer no longer use it: they are decoded with the stock `JSON.parse`
6
+ * (`./documents.ts`), because the library's documents are valid RFC 8259 JSON.
7
+ * It is kept for the fetch layer's use only.
40
8
  */
41
9
  import { isUtf8 } from 'node:buffer';
42
- import { ChtypesError } from './errors.js';
10
+ import { ArtifactCorruptError } from './ocifetch/errors.js';
43
11
  const EMPTY = Buffer.alloc(0);
44
12
  const NO_ITEMS = [];
45
13
  const NO_KEYS = [];
@@ -115,7 +83,7 @@ class Parser {
115
83
  this.b = b;
116
84
  }
117
85
  fail(what) {
118
- throw new ChtypesError(`chtypes: bad result document: ${what} at offset ${this.i}`);
86
+ throw new ArtifactCorruptError(`chtypes: bad result document: ${what} at offset ${this.i}`);
119
87
  }
120
88
  skipSpace() {
121
89
  while (this.i < this.b.length && isSpace(this.b[this.i]))
@@ -161,10 +129,9 @@ class Parser {
161
129
  }
162
130
  /**
163
131
  * 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 (docs/reference/bindings.md
167
- * §detectors).
132
+ * zeros. The strictness is load-bearing rather than pedantic: the fetch layer
133
+ * reads signed statements and manifests with this grammar, and a lenient reading
134
+ * would accept bytes the signature never covered.
168
135
  */
169
136
  number() {
170
137
  const start = this.i;
@@ -374,32 +341,12 @@ class Parser {
374
341
  }
375
342
  }
376
343
  /**
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 (docs/reference/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.
344
+ * Is this byte string **one JSON value**? It is only if a strict parse consumes
345
+ * **all** of it, with whitespace being exactly JSON's four (space, tab, LF, CR).
346
+ * A numeric *prefix* does not count (`1.2.3.4` is not `1.2`), and U+FEFF is
347
+ * **not** whitespace, though JS's own `String.prototype.trim()` counts it as one.
400
348
  *
401
- * Returns `null` when the bytes are not a single JSON value (a TSV field, a bare
402
- * CSV token, raw bytes).
349
+ * Returns `null` when the bytes are not a single JSON value.
403
350
  */
404
351
  export function parseJsonValue(bytes) {
405
352
  if (bytes.length === 0)
@@ -414,73 +361,6 @@ export function parseJsonValue(bytes) {
414
361
  return null;
415
362
  }
416
363
  }
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
364
  // ------------------------------------------------------------------ accessors
485
365
  //
486
366
  // Every field of a result document is optional: a rejected row's document omits
@@ -522,10 +402,6 @@ function keyIs(key, want) {
522
402
  }
523
403
  return true;
524
404
  }
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
405
  /** The elements of an array (or an object's values); `[]` for anything else. */
530
406
  export function items(value) {
531
407
  return value === undefined ? NO_ITEMS : value.items;
@@ -534,44 +410,4 @@ export function items(value) {
534
410
  export function asString(value) {
535
411
  return value !== undefined && value.kind === 'string' ? value.bytes.toString('utf8') : '';
536
412
  }
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
413
  //# sourceMappingURL=json.js.map