@clickhouse/client 1.23.0-head.dbc2960.1 → 1.23.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 (79) hide show
  1. package/CHANGELOG.md +1342 -0
  2. package/README.md +18 -6
  3. package/dist/version.d.ts +1 -1
  4. package/dist/version.js +1 -1
  5. package/dist/version.js.map +1 -1
  6. package/package.json +7 -6
  7. package/skills/AGENTS.md +8 -0
  8. package/skills/clickhouse-js-node-rowbinary/AGENTS.md +44 -0
  9. package/skills/clickhouse-js-node-rowbinary/CHANGELOG.md +49 -0
  10. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/README.md +78 -14
  11. package/skills/clickhouse-js-node-rowbinary/SKILL.md +111 -0
  12. package/skills/{clickhouse-js-node-rowbinary-parser/SKILL.md → clickhouse-js-node-rowbinary/reader.md} +51 -131
  13. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/carts.ts +9 -5
  14. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/events.ts +5 -5
  15. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/iot.ts +4 -4
  16. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/ledger.ts +3 -3
  17. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/logs.ts +4 -4
  18. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/observability.ts +9 -10
  19. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/orders.ts +10 -9
  20. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/profiles.ts +5 -5
  21. package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/src/examples/telemetry.ts +6 -6
  22. package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/compile.ts +18 -8
  23. package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/dynamic.ts +12 -8
  24. package/skills/clickhouse-js-node-rowbinary/src/readers/enums.ts +40 -0
  25. package/skills/clickhouse-js-node-rowbinary/src/writers/aggregateFunction.ts +18 -0
  26. package/skills/clickhouse-js-node-rowbinary/src/writers/bool.ts +10 -0
  27. package/skills/clickhouse-js-node-rowbinary/src/writers/composite.ts +140 -0
  28. package/skills/clickhouse-js-node-rowbinary/src/writers/core.ts +92 -0
  29. package/skills/clickhouse-js-node-rowbinary/src/writers/datetime.ts +123 -0
  30. package/skills/clickhouse-js-node-rowbinary/src/writers/decimals.ts +51 -0
  31. package/skills/clickhouse-js-node-rowbinary/src/writers/enums.ts +18 -0
  32. package/skills/clickhouse-js-node-rowbinary/src/writers/floats.ts +40 -0
  33. package/skills/clickhouse-js-node-rowbinary/src/writers/geo.ts +125 -0
  34. package/skills/clickhouse-js-node-rowbinary/src/writers/integers.ts +90 -0
  35. package/skills/clickhouse-js-node-rowbinary/src/writers/interval.ts +11 -0
  36. package/skills/clickhouse-js-node-rowbinary/src/writers/ip.ts +121 -0
  37. package/skills/clickhouse-js-node-rowbinary/src/writers/lowCardinality.ts +12 -0
  38. package/skills/clickhouse-js-node-rowbinary/src/writers/nested.ts +17 -0
  39. package/skills/clickhouse-js-node-rowbinary/src/writers/nothing.ts +21 -0
  40. package/skills/clickhouse-js-node-rowbinary/src/writers/rows.ts +144 -0
  41. package/skills/clickhouse-js-node-rowbinary/src/writers/simpleAggregateFunction.ts +12 -0
  42. package/skills/clickhouse-js-node-rowbinary/src/writers/strings.ts +77 -0
  43. package/skills/clickhouse-js-node-rowbinary/src/writers/time.ts +54 -0
  44. package/skills/clickhouse-js-node-rowbinary/src/writers/uuid.ts +60 -0
  45. package/skills/clickhouse-js-node-rowbinary/src/writers/varint.ts +64 -0
  46. package/skills/clickhouse-js-node-rowbinary/src/writers/writer.ts +101 -0
  47. package/skills/clickhouse-js-node-rowbinary/writer.md +96 -0
  48. package/skills/clickhouse-js-node-rowbinary-parser/src/enums.ts +0 -28
  49. /package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/EXAMPLES.md +0 -0
  50. /package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/case-studies/iot-rowbinary-vs-json.md +0 -0
  51. /package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/case-studies/ledger-rowbinary-vs-json.md +0 -0
  52. /package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/case-studies/logs-json-wins.md +0 -0
  53. /package/skills/{clickhouse-js-node-rowbinary-parser → clickhouse-js-node-rowbinary}/case-studies/wasm-vs-js.md +0 -0
  54. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/aggregateFunction.ts +0 -0
  55. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/bool.ts +0 -0
  56. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/columnar.ts +0 -0
  57. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/composite.ts +0 -0
  58. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/core.ts +0 -0
  59. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/datetime.ts +0 -0
  60. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/decimals.ts +0 -0
  61. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/floats.ts +0 -0
  62. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/geo.ts +0 -0
  63. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/header.ts +0 -0
  64. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/integers.ts +0 -0
  65. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/interval.ts +0 -0
  66. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/ip.ts +0 -0
  67. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/json.ts +0 -0
  68. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/lowCardinality.ts +0 -0
  69. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/nested.ts +0 -0
  70. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/nothing.ts +0 -0
  71. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/reader.ts +0 -0
  72. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/rowBinaryWithNamesAndTypes.ts +0 -0
  73. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/rows.ts +0 -0
  74. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/simpleAggregateFunction.ts +0 -0
  75. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/stream.ts +0 -0
  76. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/strings.ts +0 -0
  77. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/time.ts +0 -0
  78. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/uuid.ts +0 -0
  79. /package/skills/{clickhouse-js-node-rowbinary-parser/src → clickhouse-js-node-rowbinary/src/readers}/varint.ts +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,1342 @@
1
+ # 1.23.0
2
+
3
+ ## Migration Notes
4
+
5
+ - Node.js 26.x was added to the CI matrix, and Node.js 18.x is no longer supported. The `engines.node` floor of `@clickhouse/client` (previously `>=16`) and `@clickhouse/datatype-parser` (previously `>=18.0.0`) was raised to `>=20`. Node.js 20.x, 22.x, 24.x, and 26.x are supported and exercised in CI.
6
+
7
+ - The `@clickhouse/client-common` package is deprecated. `@clickhouse/client` (Node.js) and `@clickhouse/client-web` (Web) no longer depend on it; the shared code is now bundled into each client package. Everything previously importable from `@clickhouse/client-common` should be imported from `@clickhouse/client` or `@clickhouse/client-web` instead. The `@clickhouse/client-common` package itself will no longer receive updates. ([#845])
8
+
9
+ - The `parseColumnType` function and its `SimpleColumnTypes` companion (exported from `@clickhouse/client`, `@clickhouse/client-web`, and `@clickhouse/client-common`) are deprecated and slated for removal in a future major version. They are superseded by the new standalone [`@clickhouse/datatype-parser`](https://www.npmjs.com/package/@clickhouse/datatype-parser) package (`parseDataType` plus its `Node` AST), which parses the full ClickHouse data-type grammar and emits an AST that mirrors the server's. ([#893])
10
+
11
+ ## New features
12
+
13
+ - (Node.js) Added a RowBinary reader library and agent skill under [`skills/clickhouse-js-node-rowbinary-parser`](../../skills/clickhouse-js-node-rowbinary-parser). It ships type-specific, monomorphizable building blocks for decoding `RowBinary` / `RowBinaryWithNames` / `RowBinaryWithNamesAndTypes` streams (full-buffer and chunked), plus a skill that guides an agent to generate bespoke high-performance parsers from a query's column types. The skill is bundled into `@clickhouse/client` (registered in `agents.skills`) and is also published independently as the [`@clickhouse/rowbinary`](https://www.npmjs.com/package/@clickhouse/rowbinary) package. A matching RowBinary writer is planned. ([#864])
14
+
15
+ - Published the [`@clickhouse/datatype-parser`](https://www.npmjs.com/package/@clickhouse/datatype-parser) package: a small, dependency-free standalone parser for ClickHouse data-type strings (the kind sent in the types row of `RowBinaryWithNamesAndTypes`, e.g. `Array(Nullable(UInt64))`, `Tuple(a UInt8, b String)`, `Enum8('a' = 1)`). It is a faithful port of the server's `ParserDataType` and emits a JSON AST that is byte-identical to the server's `EXPLAIN AST json = 1` data-type subtree. It supersedes the deprecated `parseColumnType` (see Migration Notes). ([#893])
16
+
17
+ - (Node.js, `@experimental`) Added an additive `connection?: Connection<Stream.Readable>` option to `createClient` that lets a caller plug an externally-built backend `Connection`-like object in place of the default HTTP(S) factory. Only supposed to be used for testing the `chDB` integration. ([#879])
18
+
19
+ - Added `ClickHouseSettingsInterface`, a package-neutral structural counterpart to `ClickHouseSettings`, exported from `@clickhouse/client`, `@clickhouse/client-web`, and `@clickhouse/client-common`. It is identical to `ClickHouseSettings` except that its index signature omits `SettingsMap` (a class with a private member, which TypeScript compares nominally). Because each client package now bundles its own copy of the common module, their `ClickHouseSettings` types are mutually unassignable; `ClickHouseSettingsInterface` is structurally identical across all three packages and assignable into each package's `ClickHouseSettings`, so a consumer that shares a single settings-producing helper across both the Node.js and Web clients can type it against this one type without casts. Values typed as `SettingsMap` cannot be carried through it — use `ClickHouseSettings` if you need them. ([#889])
20
+
21
+ # 1.22.0
22
+
23
+ ## New features
24
+
25
+ - (Node.js) The `compression.request` / `compression.response` client options now accept an explicit codec via an object, in addition to the existing boolean: `true` keeps gzip (backwards compatible), and `{ codec: "zstd" }` selects zstd. The object form is intentionally extensible for future codecs and codec-specific options. zstd typically yields a similar-or-better ratio than gzip at noticeably lower CPU cost (gzip/DEFLATE is comparatively CPU-heavy and decompressed single-threaded by the ClickHouse server), and it uses the built-in `zlib` zstd support, so it requires **Node.js >= 22.15.0** (`@clickhouse/client` throws a clear error at client creation otherwise). Response decompression is driven by the server's actual `Content-Encoding`, so it degrades gracefully. The request object form also accepts an optional `level` (`{ codec, level }`) to set the codec-specific compression level (zlib level for gzip, zstd compression level for zstd); the response compression level is controlled by the server. Supported only by `@clickhouse/client` (Node.js); `@clickhouse/client-web` rejects the `zstd` codec at client creation.
26
+
27
+ - (Node.js) Brotli (`{ codec: "br" }`) is now supported for `compression.request` / `compression.response`, alongside gzip and zstd. Unlike zstd, Brotli is available on every supported Node.js version (no minimum-version requirement). The `compression.request` option is a per-codec discriminated union, so each codec exposes its own tuning option: a `level` for gzip/zstd, a `quality` for Brotli (`{ codec: "br", quality }`). When omitted, Brotli defaults to quality 4 for request bodies, since zlib's brotli default of 11 (max) is far too slow for a streaming insert path. Response decompression follows the server's `Content-Encoding`. Supported only by `@clickhouse/client` (Node.js).
28
+
29
+ ## Internal changes (`@clickhouse/client-common`)
30
+
31
+ > These only affect code that imports the low-level connection primitives from the deprecated `@clickhouse/client-common` package directly (e.g. a custom `Connection` implementation). The `createClient` `compression` option is unchanged and fully backwards compatible — if you only use `@clickhouse/client` or `@clickhouse/client-web`, you are not affected.
32
+
33
+ To carry the codec (and its optional compression level) instead of a bare on/off flag, the internal compression representation changed shape:
34
+
35
+ - `CompressionSettings.compress_request` / `decompress_response` are no longer `boolean`. They are now a normalized codec object or `undefined` (disabled): `{ codec: "gzip" | "zstd"; level?: number } | { codec: "br"; quality?: number }` for the request, `{ codec: "gzip" | "zstd" | "br" }` for the response (response compression options are chosen by the server). `getConnectionParams` normalizes the public request option into this form (`true` → `{ codec: "gzip" }`).
36
+ - `withCompressionHeaders` now takes `request_compression_codec` / `response_compression_codec` (a `CompressionMethod | undefined`) instead of the boolean `enable_request_compression` / `enable_response_compression`; the codec value is also the `Content-Encoding` / `Accept-Encoding` it emits.
37
+ - `withHttpSettings` now takes the response codec object (`{ codec } | undefined`) instead of a `boolean`.
38
+ - New exported types: `CompressionMethod`, `RequestCompression`, `ResponseCompression`.
39
+
40
+ Why: a single `boolean` could not express which codec to use or its level, and a separate level field on `CompressionSettings` would have mixed a codec-specific option into the shared type. Discriminating by codec keeps each codec's options on the codec it belongs to.
41
+
42
+ ## Documentation
43
+
44
+ - Added two **tracer adapter recipes** to [`docs/howto/tracing.md`](../../docs/howto/tracing.md) and [`examples/node/coding/otel_tracing.ts`](../../examples/node/coding/otel_tracing.ts), demonstrating how common OpenTelemetry auto-instrumentation options compose as thin userland wrappers around the `tracer` API instead of being baked into the client: `requireParentSpan` (skip ClickHouse spans when there is no active parent span — e.g. background health checks) and suppressing the duplicate nested HTTP spans emitted by `@opentelemetry/instrumentation-http` (via `suppressTracing` from `@opentelemetry/core`).
45
+
46
+ # 1.21.0
47
+
48
+ ## New features
49
+
50
+ - The tracer API (unreleased, introduced in [#776]) now follows the [OpenTelemetry database semantic conventions](https://opentelemetry.io/docs/specs/semconv/db/sql/) and matches the attribute vocabulary of the Rust client ([clickhouse-rs](https://github.com/ClickHouse/clickhouse-rs)); see [`docs/howto/tracing.md`](../../docs/howto/tracing.md) for the documentation. In particular ([#828]):
51
+ - Spans now carry `db.system.name` (instead of `db.system`), `server.address` + `server.port` (instead of a combined `host:port`), `clickhouse.request.query_id` / `clickhouse.request.session_id` (instead of `clickhouse.query_id` / `clickhouse.session_id`), `clickhouse.response.format` on `query` and `clickhouse.request.format` on `insert` (instead of `clickhouse.format`), and `db.operation.name` + `db.collection.name` on `insert` (instead of `clickhouse.table`).
52
+ - The span status is left unset on success (per the OTEL spec recommendation for client spans, previously set to `OK`); on failure, the span gets the `error.type` attribute (the error class name) and, for server-side errors, `clickhouse.error.code` (the numeric ClickHouse error code).
53
+ - Spans record response-side attributes: `db.response.status_code` (HTTP status) and, when the `X-ClickHouse-Summary` header is available, `clickhouse.summary.*` counters (`read_rows`, `written_rows`, etc.).
54
+ - `query()` now emits two spans: `clickhouse.query` covers the HTTP request lifetime and ends as soon as the response headers are received; a child `clickhouse.query.stream` span is handed to the `ResultSet` and tracks the stream consumption, ending when the response is fully read, closed, or fails - with the final `clickhouse.response.decoded_bytes` and (for row-streaming) `db.response.returned_rows` metrics. This separation makes it easy to distinguish the original request duration from a stream that may never end (e.g. tailing a live table).
55
+ - Fixed a span leak in the Web `ResultSet.stream()` path: if the underlying fetch response stream was aborted (e.g. due to a network error), the `clickhouse.query.stream` span was never ended. The TransformStream now handles both source-stream aborts and consumer-side cancellations via a `cancel` callback.
56
+ - The `insert` span records `clickhouse.request.sent_rows` for array-based inserts.
57
+
58
+ - Added a `use_multipart_params_auto` client option (default: `false`). When enabled, `query()` automatically sends `query_params` as `multipart/form-data` body parts (the same mechanism as `use_multipart_params`) once their URL-encoded length exceeds 4096 characters, avoiding HTTP 414/400 errors from HTTP intermediaries (nginx, AWS ALB, CloudFront) caused by over-long URLs - for example, a large `IN` list or a high-dimensional vector embedding. Smaller parameter payloads remain in the URL query string, so existing behavior is unchanged unless the threshold is crossed. `use_multipart_params: true` still forces multipart for all queries regardless of size. This does not change the server's per-value size limit, which is governed by `http_max_field_value_size`. Supported on both `@clickhouse/client` and `@clickhouse/client-web`, and overridable per request via `use_multipart_params_auto` on `query()`. Ported from [clickhouse-connect#789](https://github.com/ClickHouse/clickhouse-connect/pull/789). ([#827])
59
+
60
+ ```ts
61
+ const client = createClient({ use_multipart_params_auto: true });
62
+
63
+ await client.query({
64
+ query: "SELECT * FROM events WHERE id IN {ids:Array(UInt64)}",
65
+ // Sent in the URL when small, auto-promoted to the multipart body when large
66
+ query_params: { ids: veryLargeArrayOfIds },
67
+ });
68
+ ```
69
+
70
+ - Added a `use_multipart_params` client option (default: `false`). When enabled, `query()` sends `query_params` as `multipart/form-data` body parts (with the SQL moved into a `query` part) instead of URL query-string entries, avoiding HTTP 400 errors caused by over-long URLs when parameters contain large arrays (25K+ values). All other URL search params (database, query_id, settings, session_id, role) remain in the URL. Supported on both `@clickhouse/client` and `@clickhouse/client-web`, and overridable per request via `use_multipart_params` on `query()`. ([#825])
71
+
72
+ ```ts
73
+ const client = createClient({ use_multipart_params: true });
74
+
75
+ await client.query({
76
+ query: "SELECT * FROM events WHERE id IN {ids:Array(UInt64)}",
77
+ query_params: { ids: veryLargeArrayOfIds },
78
+ // Per-request override is also supported:
79
+ // use_multipart_params: false,
80
+ });
81
+ ```
82
+
83
+ [#776]: https://github.com/ClickHouse/clickhouse-js/pull/776
84
+ [#825]: https://github.com/ClickHouse/clickhouse-js/pull/825
85
+ [#827]: https://github.com/ClickHouse/clickhouse-js/pull/827
86
+ [#828]: https://github.com/ClickHouse/clickhouse-js/pull/828
87
+ [#845]: https://github.com/ClickHouse/clickhouse-js/pull/845
88
+ [#864]: https://github.com/ClickHouse/clickhouse-js/pull/864
89
+ [#889]: https://github.com/ClickHouse/clickhouse-js/pull/889
90
+ [#893]: https://github.com/ClickHouse/clickhouse-js/pull/893
91
+
92
+ ## Bug Fixes
93
+
94
+ - The client now checks the `X-ClickHouse-Exception-Code` response header to detect server errors even when the HTTP status code indicates success. In some scenarios (for example, when an exception occurs while streaming the response progress in headers, or with certain proxy setups), ClickHouse responds with HTTP 200 but sets the `X-ClickHouse-Exception-Code` header. Previously, such responses were treated as successful, and the exception text could surface as malformed response data; now the request is rejected with a parsed `ClickHouseError` (with the proper `code` and `type`), consistent with non-2xx error responses. This applies to both the Node.js and Web clients. ([#554], supersedes [#350], related issue: [#332])
95
+
96
+ [#554]: https://github.com/ClickHouse/clickhouse-js/pull/554
97
+ [#350]: https://github.com/ClickHouse/clickhouse-js/pull/350
98
+ [#332]: https://github.com/ClickHouse/clickhouse-js/issues/332
99
+
100
+ # 1.20.0
101
+
102
+ ## New Features
103
+
104
+ - Added an optional **tracer API** that the user can pass through the client config (`tracer`) and that gets called around key lifecycle operations (`query`, `command`, `exec`, `insert`, `ping`). The `ClickHouseTracer` interface is a structural subset of the OpenTelemetry `Tracer`/`Span` APIs, so a raw OTEL tracer (`trace.getTracer(...)`) can be passed to the client as-is - but the client itself ships no tracing dependency. Each operation runs inside `tracer.startActiveSpan(...)`, so auto-instrumented child spans nest under the ClickHouse operation spans; for OpenTelemetry, this requires the `AsyncLocalStorageContextManager` to be registered (the default in the OpenTelemetry Node.js SDK). Tracer exceptions are NOT caught, so a broken tracer will break client operations. See [`docs/howto/tracing.md`](../../docs/howto/tracing.md) for the full surface description, and [`examples/node/coding/otel_tracing.ts`](../../examples/node/coding/otel_tracing.ts) for a runnable Node.js example. ([#776])
105
+
106
+ ```ts
107
+ import { createClient } from "@clickhouse/client";
108
+ import { trace } from "@opentelemetry/api";
109
+
110
+ // a raw OpenTelemetry tracer is structurally compatible - no adapter needed
111
+ const client = createClient({
112
+ url: "http://localhost:8123",
113
+ tracer: trace.getTracer("@clickhouse/client"),
114
+ });
115
+ ```
116
+
117
+ ## Migration Notes
118
+
119
+ - TypeScript: `ClickHouseLogLevel` is now exported as a literal numeric union type (`0 | 1 | 2 | 3 | 4 | 127`) instead of a TypeScript `enum` type. If you were assigning arbitrary `number` values to `ClickHouseLogLevel`, you may need to narrow/cast those values during migration.
120
+
121
+ ## Improvements
122
+
123
+ - Added TypeScript typings for the remaining HTTP-specific ClickHouse settings, so they are now suggested by autocomplete when used in `clickhouse_settings`: `buffer_size`, `compress`, `decompress`, `quota_key`, and `stacktrace` (in addition to the existing `wait_end_of_query`, `default_format`, `session_timeout`, and `session_check`).
124
+
125
+ ```ts
126
+ await client.query({
127
+ query: "SELECT 1",
128
+ clickhouse_settings: {
129
+ // Buffer the entire response on the server before sending it to the client
130
+ wait_end_of_query: 1,
131
+ buffer_size: "1048576",
132
+ },
133
+ });
134
+ ```
135
+
136
+ ## Bug Fixes
137
+
138
+ - (Node.js only) Fixed a race condition in `ResultSet.json()` and `ResultSet.stream()` on `JSONEachRow` (and other streamable) result sets where calling `json()` on a fast/small response could throw `Stream has been already consumed` if the underlying stream ended between internal `readableEnded` checks. The consumption guard has been hardened: the stream is now shielded through a single `consume()` path that marks the result set as consumed in the appropriate branches, after format validation, so a successful `json()` call no longer races against the stream finishing. ([#603])
139
+
140
+ [#603]: https://github.com/ClickHouse/clickhouse-js/pull/603
141
+
142
+ # 1.19.0
143
+
144
+ ## Improvements
145
+
146
+ - Re-exported the `ResponseHeaders` type from `@clickhouse/client` and `@clickhouse/client-web`. Previously this type was only available from `@clickhouse/client-common`; it is now part of the public re-export surface of both flavored packages, alongside the other commonly used types. This is part of an ongoing effort to make `@clickhouse/client-common` an internal-only package so downstream consumers can depend solely on `@clickhouse/client` or `@clickhouse/client-web`. ([#758])
147
+
148
+ [#758]: https://github.com/ClickHouse/clickhouse-js/pull/758
149
+ [#776]: https://github.com/ClickHouse/clickhouse-js/pull/776
150
+
151
+ ## Bug Fixes
152
+
153
+ - **Enum type parsing now correctly unescapes backslash escape sequences in enum names.** Previously, `parseEnumType` returned enum names with raw escape sequences (e.g., `f\'` instead of `f'`). Now it properly decodes escape sequences including `\'` (single quote), `\\` (backslash), `\n` (newline), `\t` (tab), and `\r` (carriage return). This matches the behavior of ClickHouse string literals and ensures consistency with how the client encodes strings when sending data to the server. If you were relying on the previous incorrect behavior where backslash escape sequences were preserved in enum names, you will need to update your code to handle properly unescaped values.
154
+
155
+ Example:
156
+
157
+ ```ts
158
+ // Before (incorrect):
159
+ parseEnumType({
160
+ columnType: "Enum8('f\\'' = 1)",
161
+ sourceType: "Enum8('f\\'' = 1)",
162
+ });
163
+ // returned: { values: { 1: "f\\'" } } // with backslash
164
+
165
+ // After (correct):
166
+ parseEnumType({
167
+ columnType: "Enum8('f\\'' = 1)",
168
+ sourceType: "Enum8('f\\'' = 1)",
169
+ });
170
+ // returns: { values: { 1: "f'" } } // unescaped
171
+ ```
172
+
173
+ # 1.18.5
174
+
175
+ ## Improvements
176
+
177
+ - (Node.js only) Added `max_response_headers_size` client option that forwards the [`maxHeaderSize`](https://nodejs.org/api/http.html#httprequesturl-options-callback) option to the underlying `http(s).request` call. This raises the per-request limit on the total size of HTTP response headers received from the server (Node.js default is ~16 KB). It is most useful when running long-running queries with `send_progress_in_http_headers` enabled — the `X-ClickHouse-Progress` headers accumulate over the lifetime of the request and can exceed the default limit, causing the request to fail with `HPE_HEADER_OVERFLOW`. Setting this option avoids the need to use the global `--max-http-header-size` Node.js CLI flag or the `NODE_OPTIONS` environment variable. Has no effect for the Web client (which uses `fetch`) and no effect when a custom `http_agent` is configured with a request implementation that does not honor the option.
178
+
179
+ ```ts
180
+ const client = createClient({
181
+ request_timeout: 400_000,
182
+ max_response_headers_size: 1024 * 1024, // accept up to 1 MiB of response headers
183
+ clickhouse_settings: {
184
+ send_progress_in_http_headers: 1,
185
+ http_headers_progress_interval_ms: "110000",
186
+ },
187
+ });
188
+ ```
189
+
190
+ - The `@clickhouse/client` npm package now ships embedded AI-agent skills, `clickhouse-js-node-coding` and `clickhouse-js-node-troubleshooting`, under `node_modules/@clickhouse/client/skills/`. These skills are also declared in the `agents.skills` field of the package manifest for discovery tools that scan `node_modules`. This allows agentic coding tools to load focused, Node-client-specific coding and troubleshooting guidance without any additional setup. ([#682])
191
+
192
+ [#682]: https://github.com/ClickHouse/clickhouse-js/pull/682
193
+
194
+ # 1.18.4
195
+
196
+ A release-infrastructure-only version bump (no user-facing changes). See 1.18.5 for the next release with user-facing improvements.
197
+
198
+ # 1.18.3
199
+
200
+ ## Improvements
201
+
202
+ - Added `keep_alive.eagerly_destroy_stale_sockets` option (Node.js only, default: `false`). When enabled, sockets that have been idle for longer than `idle_socket_ttl` are destroyed immediately before each request, rather than waiting for the idle timeout to fire. This helps reclaim stale sockets during event loop delays, where the timeout callback may not run on time.
203
+
204
+ ```ts
205
+ const client = createClient({
206
+ keep_alive: {
207
+ enabled: true,
208
+ idle_socket_ttl: 2500,
209
+ eagerly_destroy_stale_sockets: true,
210
+ },
211
+ });
212
+ ```
213
+
214
+ - Added auto-detection and warning when `request_timeout` is high (> 60 seconds) but progress headers are not configured. Long-running queries may fail with socket hang-up errors if they exceed the load balancer idle timeout. The client now warns users to enable `send_progress_in_http_headers` and `http_headers_progress_interval_ms` settings to prevent such issues.
215
+
216
+ ```ts
217
+ // This will now trigger a warning
218
+ const client = createClient({
219
+ request_timeout: 120_000, // 120 seconds
220
+ // send_progress_in_http_headers is not configured
221
+ });
222
+
223
+ // ✓ Properly configured to avoid load balancer timeouts
224
+ const client = createClient({
225
+ request_timeout: 400_000,
226
+ clickhouse_settings: {
227
+ send_progress_in_http_headers: 1,
228
+ http_headers_progress_interval_ms: "110000", // ~10s below LB timeout
229
+ },
230
+ });
231
+ ```
232
+
233
+ # 1.18.2
234
+
235
+ ## Improvements
236
+
237
+ - Added a helping `WARN` level log message with a suggestion to check the `keep_alive` configuration if the client receives an `ECONNRESET` error from the server, which can happen when the server closes idle connections after a certain timeout, and the client tries to reuse such a connection from the pool. This can be especially helpful for new users who might not be aware of this aspect of HTTP connection management. The log message is only emitted if the `keep_alive` option is enabled in the client configuration, and it includes the server's keep-alive timeout value (if available) to assist with troubleshooting. ([#597](https://github.com/ClickHouse/clickhouse-js/pull/597))
238
+
239
+ How to reproduce the issue that triggers the log message:
240
+
241
+ ```ts
242
+ const client = createClient({
243
+ // ...
244
+ keep_alive: {
245
+ enabled: true,
246
+ // ❌ DON'T SET THIS VALUE SO HIGH IN PRODUCTION
247
+ idle_socket_ttl: 1_000_000,
248
+ },
249
+ log: {
250
+ level: ClickHouseLogLevel.WARN, // to see the warning logs
251
+ },
252
+ });
253
+
254
+ for (let i = 0; i < 1000; i++) {
255
+ await client.ping({
256
+ // To use a regular query instead of the /ping endpoint
257
+ // which might be configured differently on the server side
258
+ // and have different timeout settings.
259
+ select: true,
260
+ });
261
+
262
+ // Wait long enough to let the server close the idle connection,
263
+ // but not too long to let the client remove it from the pool,
264
+ // in other words try to hit the scenario when the race condition
265
+ // happens between the server closing the connection and the client
266
+ // trying to reuse it.
267
+ await sleep(SERVER_KEEP_ALIVE_TIMEOUT_MS - 100);
268
+ }
269
+ ```
270
+
271
+ Example log message:
272
+
273
+ ```json
274
+ {
275
+ "message": "Ping: idle socket TTL is greater than server keep-alive timeout, try setting idle socket TTL to a value lower than the server keep-alive timeout to prevent unexpected connection resets, see https://github.com/ClickHouse/clickhouse-js/blob/main/docs/howto/keep_alive_timeout.md for more details.",
276
+ "args": {
277
+ "operation": "Ping",
278
+ "connection_id": "8dc1c9bd-7895-49b1-8a95-276470151c65",
279
+ "query_id": "beee95af-2e83-4dcb-8e1e-045bd61f4985",
280
+ "request_id": "8dc1c9bd-7895-49b1-8a95-276470151c65:2",
281
+ "socket_id": "8dc1c9bd-7895-49b1-8a95-276470151c65:1",
282
+ "server_keep_alive_timeout_ms": 10000,
283
+ "idle_socket_ttl": 15000
284
+ },
285
+ "module": "HTTP Adapter"
286
+ }
287
+ ```
288
+
289
+ # 1.18.1
290
+
291
+ ## Improvements
292
+
293
+ - Setting `log.level` default value to `ClickHouseLogLevel.WARN` instead of `ClickHouseLogLevel.OFF` to provide better visibility into potential issues without overwhelming users with too much information by default.
294
+
295
+ ```ts
296
+ const client = createClient({
297
+ // ...
298
+ log: {
299
+ level: ClickHouseLogLevel.WARN, // default is now ClickHouseLogLevel.WARN instead of ClickHouseLogLevel.OFF
300
+ },
301
+ });
302
+ ```
303
+
304
+ - Logging is now lazy, which means that the log messages will only be constructed if the log level is appropriate for the message. This can improve performance in cases where constructing the log message is expensive, and the log level is set to ignore such messages. See `ClickHouseLogLevel` enum for the complete list of log levels. ([#520])
305
+
306
+ ```ts
307
+ const client = createClient({
308
+ // ...
309
+ log: {
310
+ level: ClickHouseLogLevel.TRACE, // to log everything available down to the network level events
311
+ },
312
+ });
313
+ ```
314
+
315
+ - Enhanced the logging of the HTTP request / socket lifecycle with additional trace messages and context such as Connection ID (UUID) and Request ID and Socket ID that embed the connection ID for ease of tracing the logs of a particular request across the connection lifecycle. To enable such logs, set the `log.level` config option to `ClickHouseLogLevel.TRACE`. ([#567])
316
+
317
+ ```console
318
+ [2026-02-25T09:19:13.511Z][TRACE][@clickhouse/client][Connection] Insert: received 'close' event, 'free' listener removed
319
+ Arguments: {
320
+ operation: 'Insert',
321
+ connection_id: 'da3c9796-5dc5-46ef-83b0-ed1f4422094c',
322
+ query_id: '9dfda627-39a2-41a6-9fc9-8f8716574826',
323
+ request_id: 'da3c9796-5dc5-46ef-83b0-ed1f4422094c:3',
324
+ socket_id: 'da3c9796-5dc5-46ef-83b0-ed1f4422094c:2',
325
+ event: 'close'
326
+ }
327
+ [2026-02-25T09:19:13.502Z][TRACE][@clickhouse/client][Connection] Query: reusing socket
328
+ Arguments: {
329
+ operation: 'Query',
330
+ connection_id: 'da3c9796-5dc5-46ef-83b0-ed1f4422094c',
331
+ query_id: 'ad0127e8-b1c7-4ed6-9681-c0162f7a0ea9',
332
+ request_id: 'da3c9796-5dc5-46ef-83b0-ed1f4422094c:4',
333
+ socket_id: 'da3c9796-5dc5-46ef-83b0-ed1f4422094c:2',
334
+ usage_count: 1
335
+ }
336
+ ```
337
+
338
+ - A step towards structured logging: the client now passes rich context to the logger `args` parameter (e.g. `connection_id`, `query_id`, `request_id`, `socket_id`). ([#576])
339
+
340
+ ## Deprecated API
341
+
342
+ - The `drainStream` utility function is now deprecated, as the client will handle draining the stream internally when needed. Use `client.command()` instead, which will handle draining the stream internally when needed. ([#578])
343
+
344
+ - The `sleep` utility function is now deprecated, as it is not intended to be used outside of the client implementation. Use `setTimeout` directly or a more full-featured utility library if you need additional features like cancellation or timers management. ([#578])
345
+
346
+ [#520]: https://github.com/ClickHouse/clickhouse-js/pull/520
347
+ [#567]: https://github.com/ClickHouse/clickhouse-js/pull/567
348
+ [#576]: https://github.com/ClickHouse/clickhouse-js/pull/576
349
+ [#578]: https://github.com/ClickHouse/clickhouse-js/pull/578
350
+
351
+ # 1.18.0
352
+
353
+ A beta version. See 1.18.1 for the stable release.
354
+
355
+ # 1.17.0
356
+
357
+ ## New features
358
+
359
+ - Added `http_status_code` to query, insert, and exec commands ([#525], [Kinzeng])
360
+ - Fixed `ignore_error_response` not getting passed when using `command` ([#536], [Kinzeng])
361
+
362
+ [#525]: https://github.com/ClickHouse/clickhouse-js/pull/525
363
+ [#536]: https://github.com/ClickHouse/clickhouse-js/pull/536
364
+
365
+ # 1.16.0
366
+
367
+ ## New features
368
+
369
+ - Added support for the new [Disposable API] (a.k.a the `using` keyword) (#500)
370
+
371
+ [Disposable API]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using
372
+
373
+ ```ts
374
+ async function main() {
375
+ using resultSet = await client.query(…);
376
+
377
+ // some code that can throw
378
+ // but thanks to `using` the resultSet will still get disposed
379
+
380
+ // resultSet is also automatically disposed here by calling [Symbol.dispose]
381
+ }
382
+ ```
383
+
384
+ Without the new `using` keyword it is required to wrap the code that might leak expensive resources like sockets and big buffers in ` try / finally`
385
+
386
+ ```ts
387
+ async function main() {
388
+ let client
389
+ try {
390
+ client = await createClient(…);
391
+ // some code that can throw
392
+ } finally {
393
+ if (client) {
394
+ await client.close()
395
+ }
396
+ }
397
+ }
398
+ ```
399
+
400
+ # 1.15.0
401
+
402
+ ## New features
403
+
404
+ - Added support for [BigInt] values in query parameters. ([#487], @dalechyn)
405
+
406
+ [#487]: https://github.com/ClickHouse/clickhouse-js/pull/487
407
+ [BigInt]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt
408
+
409
+ # 1.14.0
410
+
411
+ ## New features
412
+
413
+ - It is now possible to specify custom `parse` and `stringify` functions that will be used instead of the standard `JSON.parse` and `JSON.stringify` methods for JSON serialization/deserialization when working with `JSON*` family formats. See `ClickHouseClientConfigOptions.json`, and a new [custom_json_handling] example for more details. ([#481], [looskie])
414
+ - (Node.js only) Added an `ignore_error_response` param to `ClickHouseClient.exec`, which allows callers to manually handle request errors on the application side. ([#483], [Kinzeng])
415
+
416
+ [#481]: https://github.com/ClickHouse/clickhouse-js/pull/481
417
+ [#483]: https://github.com/ClickHouse/clickhouse-js/pull/483
418
+ [looskie]: https://github.com/looskie
419
+ [Kinzeng]: https://github.com/Kinzeng
420
+ [custom_json_handling]: https://github.com/ClickHouse/clickhouse-js/blob/1.14.0/examples/custom_json_handling.ts
421
+
422
+ # 1.13.0
423
+
424
+ ## New features
425
+
426
+ - Server-side exceptions that occur in the middle of the HTTP stream are now handled correctly. This requires [ClickHouse 25.11+](https://github.com/ClickHouse/ClickHouse/pull/88818). Previous ClickHouse versions are unaffected by this change. ([#478])
427
+
428
+ ## Improvements
429
+
430
+ - `TupleParam` constructor now accepts a readonly array to permit more usages. ([#465], [Malien])
431
+
432
+ ## Bug fixes
433
+
434
+ - Fixed boolean value formatting in query parameters. Boolean values within `Array`, `Tuple`, and `Map` types are now correctly formatted as `TRUE`/`FALSE` instead of `1`/`0` to ensure proper type compatibility with ClickHouse. ([#475], [baseballyama])
435
+
436
+ [#465]: https://github.com/ClickHouse/clickhouse-js/pull/465
437
+ [#475]: https://github.com/ClickHouse/clickhouse-js/pull/475
438
+ [#478]: https://github.com/ClickHouse/clickhouse-js/pull/478
439
+ [Malien]: https://github.com/Malien
440
+ [baseballyama]: https://github.com/baseballyama
441
+
442
+ # 1.12.1
443
+
444
+ ## Improvements
445
+
446
+ - Improved performance of `toSearchParams`. ([#449], [twk])
447
+
448
+ ## Other
449
+
450
+ - Added Node.js 24.x to the CI matrix. Node.js 18.x was removed from the CI due to [EOL](https://endoflife.date/nodejs).
451
+
452
+ [#449]: https://github.com/ClickHouse/clickhouse-js/pull/449
453
+ [twk]: https://github.com/twk
454
+
455
+ # 1.12.0
456
+
457
+ ## Types
458
+
459
+ - Add missing `allow_experimental_join_condition` to `ClickHouseSettings` typing. ([#430], [looskie])
460
+ - Fixed `JSONEachRowWithProgress` TypeScript flow after the breaking changes in [ClickHouse 25.1]. `RowOrProgress<T>` now has an additional variant: `SpecialEventRow<T>`. The library now additionally exports the `parseError` method, and newly added `isRow` / `isException` type guards. See the updated [JSONEachRowWithProgress example] ([#443])
461
+ - Added missing `allow_experimental_variant_type` (24.1+), `allow_experimental_dynamic_type` (24.5+), `allow_experimental_json_type` (24.8+), `enable_json_type` (25.3+), `enable_time_time64_type` (25.6+) to `ClickHouseSettings` typing. ([#445])
462
+
463
+ ## Improvements
464
+
465
+ - Add a warning on a socket closed without fully consuming the stream (e.g., when using `query` or `exec` method). ([#441])
466
+ - (Node.js only) An option to use a simple SELECT query for ping checks instead of `/ping` endpoint. See the new optional argument to the `ClickHouseClient.ping` method and `PingParams` typings. Note that the Web version always used a SELECT query by default, as the `/ping` endpoint does not support CORS, and that cannot be changed. ([#442])
467
+
468
+ ## Other
469
+
470
+ - The project now uses [Codecov] instead of SonarCloud for code coverage reports. ([#444])
471
+
472
+ [#430]: https://github.com/ClickHouse/clickhouse-js/pull/430
473
+ [#441]: https://github.com/ClickHouse/clickhouse-js/pull/441
474
+ [#442]: https://github.com/ClickHouse/clickhouse-js/pull/442
475
+ [#443]: https://github.com/ClickHouse/clickhouse-js/pull/443
476
+ [#444]: https://github.com/ClickHouse/clickhouse-js/pull/444
477
+ [#445]: https://github.com/ClickHouse/clickhouse-js/pull/445
478
+ [looskie]: https://github.com/looskie
479
+ [ClickHouse 25.1]: https://github.com/ClickHouse/ClickHouse/pull/74181
480
+ [JSONEachRowWithProgress example]: https://github.com/ClickHouse/clickhouse-js/blob/main/examples/node/select_json_each_row_with_progress.ts
481
+ [Codecov]: https://codecov.io/gh/ClickHouse/clickhouse-js
482
+
483
+ # 1.11.2 (Common, Node.js)
484
+
485
+ A minor release to allow further investigation regarding uncaught error issues with [#410].
486
+
487
+ ## Types
488
+
489
+ - Added missing `lightweight_deletes_sync` typing to `ClickHouseSettings` ([#422], [pratimapatel2008])
490
+
491
+ ## Improvements (Node.js)
492
+
493
+ - Added a new configuration option: `capture_enhanced_stack_trace`; see the JS doc in the Node.js client package. Note that it is disabled by default due to a possible performance impact. ([#427])
494
+ - Added more try-catch blocks to the Node.js connection layer. ([#427])
495
+
496
+ [#410]: https://github.com/ClickHouse/clickhouse-js/pull/410
497
+ [#422]: https://github.com/ClickHouse/clickhouse-js/pull/422
498
+ [#427]: https://github.com/ClickHouse/clickhouse-js/pull/427
499
+ [pratimapatel2008]: https://github.com/pratimapatel2008
500
+
501
+ # 1.11.1 (Common, Node.js, Web)
502
+
503
+ ## Bug fixes
504
+
505
+ - Fixed an issue with URLEncoded special characters in the URL configuration for username or password. ([#407](https://github.com/ClickHouse/clickhouse-js/issues/407))
506
+
507
+ ## Improvements
508
+
509
+ - Added support for streaming on 32-bit platforms. ([#403](https://github.com/ClickHouse/clickhouse-js/pull/403), [shevchenkonik](https://github.com/shevchenkonik))
510
+
511
+ # 1.11.0 (Common, Node.js, Web)
512
+
513
+ ## New features
514
+
515
+ - It is now possible to provide custom HTTP headers when calling the `query`/`insert`/`command`/`exec` methods using the `http_headers` option. NB: `http_headers` specified this way will override `http_headers` set on the client instance level. ([#394](https://github.com/ClickHouse/clickhouse-js/issues/374), [@DylanRJohnston](https://github.com/DylanRJohnston))
516
+ - (Web only) It is now possible to provide a custom `fetch` implementation to the client. ([#315](https://github.com/ClickHouse/clickhouse-js/issues/315), [@lucacasonato](https://github.com/lucacasonato))
517
+
518
+ # 1.10.1 (Common, Node.js, Web)
519
+
520
+ ## Bug fixes
521
+
522
+ - Fixed `NULL` parameter binding with `Tuple`, `Array`, and `Map` types. ([#374](https://github.com/ClickHouse/clickhouse-js/issues/374))
523
+
524
+ ## Improvements
525
+
526
+ - `ClickHouseSettings` typings now include `session_timeout` and `session_check` settings. ([#370](https://github.com/ClickHouse/clickhouse-js/issues/370))
527
+
528
+ # 1.10.0 (Common, Node.js, Web)
529
+
530
+ ## New features
531
+
532
+ - Added support for JWT authentication (ClickHouse Cloud feature) in both Node.js and Web API packages. JWT token can be set via `access_token` client configuration option.
533
+
534
+ ```ts
535
+ const client = createClient({
536
+ // ...
537
+ access_token: "<JWT access token>",
538
+ });
539
+ ```
540
+
541
+ Access token can also be configured via the URL params, e.g., `https://host:port?access_token=...`.
542
+
543
+ It is also possible to override the access token for a particular request (see `BaseQueryParams.auth` for more details).
544
+
545
+ NB: do not mix access token and username/password credentials in the configuration; the client will throw an error if both are set.
546
+
547
+ # 1.9.1 (Node.js only)
548
+
549
+ ## Bug fixes
550
+
551
+ - Fixed an uncaught exception that could happen in case of malformed ClickHouse response when response compression is enabled ([#363](https://github.com/ClickHouse/clickhouse-js/issues/363))
552
+
553
+ # 1.9.0 (Common, Node.js, Web)
554
+
555
+ ## New features
556
+
557
+ - Added `input_format_json_throw_on_bad_escape_sequence` to the `ClickhouseSettings` type. ([#355](https://github.com/ClickHouse/clickhouse-js/pull/355), [@emmanuel-bonin](https://github.com/emmanuel-bonin))
558
+ - The client now exports `TupleParam` wrapper class, allowing tuples to be properly used as query parameters. Added support for JS Map as a query parameter. ([#359](https://github.com/ClickHouse/clickhouse-js/pull/359))
559
+
560
+ ## Improvements
561
+
562
+ - The client will throw a more informative error if the buffered response is larger than the max allowed string length in V8, which is `2**29 - 24` bytes. ([#357](https://github.com/ClickHouse/clickhouse-js/pull/357))
563
+
564
+ # 1.8.1 (Node.js)
565
+
566
+ ## Bug fixes
567
+
568
+ - When a custom HTTP agent is used, the HTTP or HTTPS request implementation is now correctly chosen based on the URL protocol. ([#352](https://github.com/ClickHouse/clickhouse-js/issues/352))
569
+
570
+ # 1.8.0 (Common, Node.js, Web)
571
+
572
+ ## New features
573
+
574
+ - Added support for specifying roles via request query parameters. See [this example](examples/role.ts) for more details. ([@pulpdrew](https://github.com/pulpdrew), [#328](https://github.com/ClickHouse/clickhouse-js/pull/328))
575
+
576
+ # 1.7.0 (Common, Node.js, Web)
577
+
578
+ ## Bug fixes
579
+
580
+ - (Web only) Fixed an issue where streaming large datasets could provide corrupted results. See [#333](https://github.com/ClickHouse/clickhouse-js/pull/333) (PR) for more details.
581
+
582
+ ## New features
583
+
584
+ - Added `JSONEachRowWithProgress` format support, `ProgressRow` interface, and `isProgressRow` type guard. See [this Node.js example](../../examples/node/select_json_each_row_with_progress.ts) for more details. It should work similarly with the Web version.
585
+ - (Experimental) Exposed the `parseColumnType` function that takes a string representation of a ClickHouse type (e.g., `FixedString(16)`, `Nullable(Int32)`, etc.) and returns an AST-like object that represents the type. For example:
586
+
587
+ ```ts
588
+ for (const type of [
589
+ "Int32",
590
+ "Array(Nullable(String))",
591
+ `Map(Int32, DateTime64(9, 'UTC'))`,
592
+ ]) {
593
+ console.log(`##### Source ClickHouse type: ${type}`);
594
+ console.log(parseColumnType(type));
595
+ }
596
+ ```
597
+
598
+ The above code will output:
599
+
600
+ ```
601
+ ##### Source ClickHouse type: Int32
602
+ { type: 'Simple', columnType: 'Int32', sourceType: 'Int32' }
603
+ ##### Source ClickHouse type: Array(Nullable(String))
604
+ {
605
+ type: 'Array',
606
+ value: {
607
+ type: 'Nullable',
608
+ sourceType: 'Nullable(String)',
609
+ value: { type: 'Simple', columnType: 'String', sourceType: 'String' }
610
+ },
611
+ dimensions: 1,
612
+ sourceType: 'Array(Nullable(String))'
613
+ }
614
+ ##### Source ClickHouse type: Map(Int32, DateTime64(9, 'UTC'))
615
+ {
616
+ type: 'Map',
617
+ key: { type: 'Simple', columnType: 'Int32', sourceType: 'Int32' },
618
+ value: {
619
+ type: 'DateTime64',
620
+ timezone: 'UTC',
621
+ precision: 9,
622
+ sourceType: "DateTime64(9, 'UTC')"
623
+ },
624
+ sourceType: "Map(Int32, DateTime64(9, 'UTC'))"
625
+ }
626
+ ```
627
+
628
+ While the original intention was to use this function internally for `Native`/`RowBinaryWithNamesAndTypes` data formats headers parsing, it can be useful for other purposes as well (e.g., interfaces generation, or custom JSON serializers).
629
+
630
+ NB: currently unsupported source types to parse:
631
+ - Geo
632
+ - (Simple)AggregateFunction
633
+ - Nested
634
+ - Old/new experimental JSON
635
+ - Dynamic
636
+ - Variant
637
+
638
+ # 1.6.0 (Common, Node.js, Web)
639
+
640
+ ## New features
641
+
642
+ - Added optional `real_time_microseconds` field to the `ClickHouseSummary` interface (see <https://github.com/ClickHouse/ClickHouse/pull/69032>)
643
+
644
+ ## Bug fixes
645
+
646
+ - Fixed unhandled exceptions produced when calling `ResultSet.json` if the response data was not in fact a valid JSON. ([#311](https://github.com/ClickHouse/clickhouse-js/pull/311))
647
+
648
+ # 1.5.0 (Node.js)
649
+
650
+ ## New features
651
+
652
+ - It is now possible to disable the automatic decompression of the response stream with the `exec` method. See `ExecParams.decompress_response_stream` for more details. ([#298](https://github.com/ClickHouse/clickhouse-js/issues/298)).
653
+
654
+ # 1.4.1 (Node.js, Web)
655
+
656
+ ## Improvements
657
+
658
+ - `ClickHouseClient` is now exported as a value from `@clickhouse/client` and `@clickhouse/client-web` packages, allowing for better integration in dependency injection frameworks that rely on IoC (e.g., [Nest.js](https://github.com/nestjs/nest), [tsyringe](https://github.com/microsoft/tsyringe)) ([@mathieu-bour](https://github.com/mathieu-bour), [#292](https://github.com/ClickHouse/clickhouse-js/issues/292)).
659
+
660
+ ## Bug fixes
661
+
662
+ - Fixed a potential socket hang up issue that could happen under 100% CPU load ([#294](https://github.com/ClickHouse/clickhouse-js/issues/294)).
663
+
664
+ # 1.4.0 (Node.js)
665
+
666
+ ## New features
667
+
668
+ - (Node.js only) The `exec` method now accepts an optional `values` parameter, which allows you to pass the request body as a `Stream.Readable`. This can be useful in case of custom insert streaming with arbitrary ClickHouse data formats (which might not be explicitly supported and allowed by the client in the `insert` method yet). NB: in this case, you are expected to serialize the data in the stream in the required input format yourself.
669
+
670
+ # 1.3.0 (Common, Node.js, Web)
671
+
672
+ ## New features
673
+
674
+ - It is now possible to get the entire response headers object from the `query`/`insert`/`command`/`exec` methods. With `query`, you can access the `ResultSet.response_headers` property; other methods (`insert`/`command`/`exec`) return it as parts of their response objects as well.
675
+ For example:
676
+
677
+ ```ts
678
+ const rs = await client.query({
679
+ query: "SELECT * FROM system.numbers LIMIT 1",
680
+ format: "JSONEachRow",
681
+ });
682
+ console.log(rs.response_headers["content-type"]);
683
+ ```
684
+
685
+ This will print: `application/x-ndjson; charset=UTF-8`. It can be used in a similar way with the other methods.
686
+
687
+ ## Improvements
688
+
689
+ - Re-exported several constants from the `@clickhouse/client-common` package for convenience:
690
+ - `SupportedJSONFormats`
691
+ - `SupportedRawFormats`
692
+ - `StreamableFormats`
693
+ - `StreamableJSONFormats`
694
+ - `SingleDocumentJSONFormats`
695
+ - `RecordsJSONFormats`
696
+
697
+ # 1.2.0 (Node.js)
698
+
699
+ ## New features
700
+
701
+ - (Experimental) Added an option to provide a custom HTTP Agent in the client configuration via the `http_agent` option ([#283](https://github.com/ClickHouse/clickhouse-js/issues/283), related: [#278](https://github.com/ClickHouse/clickhouse-js/issues/278)). The following conditions apply if a custom HTTP Agent is provided:
702
+ - The `max_open_connections` and `tls` options will have _no effect_ and will be ignored by the client, as it is a part of the underlying HTTP Agent configuration.
703
+ - `keep_alive.enabled` will only regulate the default value of the `Connection` header (`true` -> `Connection: keep-alive`, `false` -> `Connection: close`).
704
+ - While the idle socket management will still work, it is now possible to disable it completely by setting the `keep_alive.idle_socket_ttl` value to `0`.
705
+ - (Experimental) Added a new client configuration option: `set_basic_auth_header`, which disables the `Authorization` header that is set by the client by default for every outgoing HTTP request. One of the possible scenarios when it is necessary to disable this header is when a custom HTTPS agent is used, and the server requires TLS authorization. For example:
706
+
707
+ ```ts
708
+ const agent = new https.Agent({
709
+ ca: fs.readFileSync("./ca.crt"),
710
+ });
711
+ const client = createClient({
712
+ url: "https://server.clickhouseconnect.test:8443",
713
+ http_agent: agent,
714
+ // With a custom HTTPS agent, the client won't use the default HTTPS connection implementation; the headers should be provided manually
715
+ http_headers: {
716
+ "X-ClickHouse-User": "default",
717
+ "X-ClickHouse-Key": "",
718
+ },
719
+ // Authorization header conflicts with the TLS headers; disable it.
720
+ set_basic_auth_header: false,
721
+ });
722
+ ```
723
+
724
+ NB: It is currently not possible to set the `set_basic_auth_header` option via the URL params.
725
+
726
+ If you have feedback on these experimental features, please let us know by creating [an issue](https://github.com/ClickHouse/clickhouse-js/issues) in the repository.
727
+
728
+ # 1.1.0 (Common, Node.js, Web)
729
+
730
+ ## New features
731
+
732
+ - Added an option to override the credentials for a particular `query`/`command`/`exec`/`insert` request via the `BaseQueryParams.auth` setting; when set, the credentials will be taken from there instead of the username/password provided during the client instantiation ([#278](https://github.com/ClickHouse/clickhouse-js/issues/278)).
733
+ - Added an option to override the `session_id` for a particular `query`/`command`/`exec`/`insert` request via the `BaseQueryParams.session_id` setting; when set, it will be used instead of the session id provided during the client instantiation ([@holi0317](https://github.com/Holi0317), [#271](https://github.com/ClickHouse/clickhouse-js/issues/271)).
734
+
735
+ ## Bug fixes
736
+
737
+ - Fixed the incorrect `ResponseJSON<T>.totals` TypeScript type. Now it correctly matches the shape of the data (`T`, default = `unknown`) instead of the former `Record<string, number>` definition ([#274](https://github.com/ClickHouse/clickhouse-js/issues/274)).
738
+
739
+ # 1.0.2 (Common, Node.js, Web)
740
+
741
+ ## Bug fixes
742
+
743
+ - The `command` method now drains the response stream properly, as the previous implementation could cause the `Keep-Alive` socket to close after each request.
744
+ - Removed an unnecessary error log in the `ResultSet.stream` method if the request was aborted or the result set was closed ([#263](https://github.com/ClickHouse/clickhouse-js/issues/263)).
745
+
746
+ ## Improvements
747
+
748
+ - `ResultSet.stream` logs an error via the `Logger` instance, if the stream emits an error event instead of a simple `console.error` call.
749
+ - Minor adjustments to the `DefaultLogger` log messages formatting.
750
+ - Added missing `rows_before_limit_at_least` to the ResponseJSON type ([@0237h](https://github.com/0237h), [#267](https://github.com/ClickHouse/clickhouse-js/issues/267)).
751
+
752
+ # 1.0.1 (Common, Node.js, Web)
753
+
754
+ ## Bug fixes
755
+
756
+ - Fixed the regression where the default HTTP/HTTPS port numbers (80/443) could not be used with the URL configuration ([#258](https://github.com/ClickHouse/clickhouse-js/issues/258)).
757
+
758
+ # 1.0.0 (Common, Node.js, Web)
759
+
760
+ Formal stable release milestone with a lot of improvements and some [breaking changes](#breaking-changes-in-100).
761
+
762
+ Major new features overview:
763
+
764
+ - [Advanced TypeScript support for `query` + `ResultSet`](#advanced-typescript-support-for-query--resultset)
765
+ - [URL configuration](#url-configuration)
766
+
767
+ From now on, the client will follow the [official semantic versioning](https://docs.npmjs.com/about-semantic-versioning) guidelines.
768
+
769
+ ## Deprecated API
770
+
771
+ The following configuration parameters are marked as deprecated:
772
+
773
+ - `host` configuration parameter is deprecated; use `url` instead.
774
+ - `additional_headers` configuration parameter is deprecated; use `http_headers` instead.
775
+
776
+ The client will log a warning if any of these parameters are used. However, it is still allowed to use `host` instead of `url` and `additional_headers` instead of `http_headers` for now; this deprecation is not supposed to break the existing code.
777
+
778
+ These parameters will be removed in the next major release (2.0.0).
779
+
780
+ See "New features" section for more details.
781
+
782
+ ## Breaking changes in 1.0.0
783
+
784
+ - `compression.response` is now disabled by default in the client configuration options, as it cannot be used with readonly=1 users, and it was not clear from the ClickHouse error message what exact client option was causing the failing query in this case. If you'd like to continue using response compression, you should explicitly enable it in the client configuration.
785
+ - As the client now supports parsing [URL configuration](#url-configuration), you should specify `pathname` as a separate configuration option (as it would be considered as the `database` otherwise).
786
+ - (TypeScript only) `ResultSet` and `Row` are now more strictly typed, according to the format used during the `query` call. See [this section](#advanced-typescript-support-for-query--resultset) for more details.
787
+ - (TypeScript only) Both Node.js and Web versions now uniformly export correct `ClickHouseClient` and `ClickHouseClientConfigOptions` types, specific to each implementation. Exported `ClickHouseClient` now does not have a `Stream` type parameter, as it was unintended to expose it there. NB: you should still use `createClient` factory function provided in the package.
788
+
789
+ ## New features in 1.0.0
790
+
791
+ ### Advanced TypeScript support for `query` + `ResultSet`
792
+
793
+ Client will now try its best to figure out the shape of the data based on the DataFormat literal specified to the `query` call, as well as which methods are allowed to be called on the `ResultSet`.
794
+
795
+ Live demo (see the full description below):
796
+
797
+ [Screencast](https://github.com/ClickHouse/clickhouse-js/assets/3175289/b66afcb2-3a10-4411-af59-51d2754c417e)
798
+
799
+ Complete reference:
800
+
801
+ | Format | `ResultSet.json<T>()` | `ResultSet.stream<T>()` | Stream data | `Row.json<T>()` |
802
+ | ------------------------------- | --------------------- | --------------------------- | ----------------- | --------------- |
803
+ | JSON | ResponseJSON\<T\> | never | never | never |
804
+ | JSONObjectEachRow | Record\<string, T\> | never | never | never |
805
+ | All other `JSON*EachRow` | Array\<T\> | Stream\<Array\<Row\<T\>\>\> | Array\<Row\<T\>\> | T |
806
+ | CSV/TSV/CustomSeparated/Parquet | never | Stream\<Array\<Row\<T\>\>\> | Array\<Row\<T\>\> | never |
807
+
808
+ By default, `T` (which represents `JSONType`) is still `unknown`. However, considering `JSONObjectsEachRow` example: prior to 1.0.0, you had to specify the entire type hint, including the shape of the data, manually:
809
+
810
+ ```ts
811
+ type Data = { foo: string };
812
+
813
+ const resultSet = await client.query({
814
+ query: "SELECT * FROM my_table",
815
+ format: "JSONObjectsEachRow",
816
+ });
817
+
818
+ // pre-1.0.0, `resultOld` has type Record<string, Data>
819
+ const resultOld = resultSet.json<Record<string, Data>>();
820
+ // const resultOld = resultSet.json<Data>() // incorrect! The type hint should've been `Record<string, Data>` here.
821
+
822
+ // 1.0.0, `resultNew` also has type Record<string, Data>; client inferred that it has to be a Record from the format literal.
823
+ const resultNew = resultSet.json<Data>();
824
+ ```
825
+
826
+ This is even more handy in case of streaming on the Node.js platform:
827
+
828
+ ```ts
829
+ const resultSet = await client.query({
830
+ query: "SELECT * FROM my_table",
831
+ format: "JSONEachRow",
832
+ });
833
+
834
+ // pre-1.0.0
835
+ // `streamOld` was just a regular Node.js Stream.Readable
836
+ const streamOld = resultSet.stream();
837
+ // `rows` were `any`, needed an explicit type hint
838
+ streamNew.on("data", (rows: Row[]) => {
839
+ rows.forEach((row) => {
840
+ // without an explicit type hint to `rows`, calling `forEach` and other array methods resulted in TS compiler errors
841
+ const t = row.text;
842
+ const j = row.json<Data>(); // `j` needed a type hint here, otherwise, it's `unknown`
843
+ });
844
+ });
845
+
846
+ // 1.0.0
847
+ // `streamNew` is now StreamReadable<T> (Node.js Stream.Readable with a bit more type hints);
848
+ // type hint for the further `json` calls can be added here (and removed from the `json` calls)
849
+ const streamNew = resultSet.stream<Data>();
850
+ // `rows` are inferred as an Array<Row<Data, "JSONEachRow">> instead of `any`
851
+ streamNew.on("data", (rows) => {
852
+ // `row` is inferred as Row<Data, "JSONEachRow">
853
+ rows.forEach((row) => {
854
+ // no explicit type hints required, you can use `forEach` straight away and TS compiler will be happy
855
+ const t = row.text;
856
+ const j = row.json(); // `j` will be of type Data
857
+ });
858
+ });
859
+
860
+ // async iterator now also has type hints
861
+ // similarly to the `on(data)` example above, `rows` are inferred as Array<Row<Data, "JSONEachRow">>
862
+ for await (const rows of streamNew) {
863
+ // `row` is inferred as Row<Data, "JSONEachRow">
864
+ rows.forEach((row) => {
865
+ const t = row.text;
866
+ const j = row.json(); // `j` will be of type Data
867
+ });
868
+ }
869
+ ```
870
+
871
+ Calling `ResultSet.stream` is not allowed for certain data formats, such as `JSON` and `JSONObjectsEachRow` (unlike `JSONEachRow` and the rest of `JSON*EachRow`, these formats return a single object). In these cases, the client throws an error. However, it was previously not reflected on the type level; now, calling `stream` on these formats will result in a TS compiler error. For example:
872
+
873
+ ```ts
874
+ const resultSet = await client.query("SELECT * FROM table", {
875
+ format: "JSON",
876
+ });
877
+ const stream = resultSet.stream(); // `stream` is `never`
878
+ ```
879
+
880
+ Calling `ResultSet.json` also does not make sense on `CSV` and similar "raw" formats, and the client throws. Again, now, it is typed properly:
881
+
882
+ ```ts
883
+ const resultSet = await client.query("SELECT * FROM table", {
884
+ format: "CSV",
885
+ });
886
+ // `json` is `never`; same if you stream CSV, and call `Row.json` - it will be `never`, too.
887
+ const json = resultSet.json();
888
+ ```
889
+
890
+ Currently, there is one known limitation: as the general shape of the data and the methods allowed for calling are inferred from the format literal, there might be situations where it will fail to do so, for example:
891
+
892
+ ```ts
893
+ // assuming that `queryParams` has `JSONObjectsEachRow` format inside
894
+ async function runQuery(
895
+ queryParams: QueryParams,
896
+ ): Promise<Record<string, Data>> {
897
+ const resultSet = await client.query(queryParams);
898
+ // type hint here will provide a union of all known shapes instead of a specific one
899
+ // inferred shapes: Data[] | ResponseJSON<Data> | Record<string, Data>
900
+ return resultSet.json<Data>();
901
+ }
902
+ ```
903
+
904
+ In this case, as it is _likely_ that you already know the desired format in advance (otherwise, returning a specific shape like `Record<string, Data>` would've been incorrect), consider helping the client a bit:
905
+
906
+ ```ts
907
+ async function runQuery(
908
+ queryParams: QueryParams,
909
+ ): Promise<Record<string, Data>> {
910
+ const resultSet = await client.query({
911
+ ...queryParams,
912
+ format: "JSONObjectsEachRow",
913
+ });
914
+ // TS understands that it is a Record<string, Data> now
915
+ return resultSet.json<Data>();
916
+ }
917
+ ```
918
+
919
+ If you are interested in more details, see the [related test](../../packages/client-node/__tests__/integration/node_query_format_types.test.ts) (featuring a great ESLint plugin [expect-types](https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type)) in the client package.
920
+
921
+ ### URL configuration
922
+
923
+ - Added `url` configuration parameter. It is intended to replace the deprecated `host`, which was already supposed to be passed as a valid URL.
924
+ - It is now possible to configure most of the client instance parameters with a URL. The URL format is `http[s]://[username:password@]hostname:port[/database][?param1=value1&param2=value2]`. In almost every case, the name of a particular parameter reflects its path in the config options interface, with a few exceptions. The following parameters are supported:
925
+
926
+ | Parameter | Type |
927
+ | ------------------------------------------- | ----------------------------------------------------------------- |
928
+ | `pathname` | an arbitrary string. |
929
+ | `application_id` | an arbitrary string. |
930
+ | `session_id` | an arbitrary string. |
931
+ | `request_timeout` | non-negative number. |
932
+ | `max_open_connections` | non-negative number, greater than zero. |
933
+ | `compression_request` | boolean. See below [1]. |
934
+ | `compression_response` | boolean. |
935
+ | `log_level` | allowed values: `OFF`, `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`. |
936
+ | `keep_alive_enabled` | boolean. |
937
+ | `clickhouse_setting_*` or `ch_*` | see below [2]. |
938
+ | `http_header_*` | see below [3]. |
939
+ | (Node.js only) `keep_alive_idle_socket_ttl` | non-negative number. |
940
+
941
+ [1] For booleans, valid values will be `true`/`1` and `false`/`0`.
942
+
943
+ [2] Any parameter prefixed with `clickhouse_setting_` or `ch_` will have this prefix removed and the rest added to client's `clickhouse_settings`. For example, `?ch_async_insert=1&ch_wait_for_async_insert=1` will be the same as:
944
+
945
+ ```ts
946
+ createClient({
947
+ clickhouse_settings: {
948
+ async_insert: 1,
949
+ wait_for_async_insert: 1,
950
+ },
951
+ });
952
+ ```
953
+
954
+ Note: boolean values for `clickhouse_settings` should be passed as `1`/`0` in the URL.
955
+
956
+ [3] Similar to [2], but for `http_header` configuration. For example, `?http_header_x-clickhouse-auth=foobar` will be an equivalent of:
957
+
958
+ ```ts
959
+ createClient({
960
+ http_headers: {
961
+ "x-clickhouse-auth": "foobar",
962
+ },
963
+ });
964
+ ```
965
+
966
+ **Important: URL will _always_ overwrite the hardcoded values and a warning will be logged in this case.**
967
+
968
+ Currently not supported via URL:
969
+
970
+ - `log.LoggerClass`
971
+ - (Node.js only) `tls_ca_cert`, `tls_cert`, `tls_key`.
972
+
973
+ See also: [URL configuration example](../../examples/url_configuration.ts).
974
+
975
+ ### Performance
976
+
977
+ - (Node.js only) Improved performance when decoding the entire set of rows with _streamable_ JSON formats (such as `JSONEachRow` or `JSONCompactEachRow`) by calling the `ResultSet.json()` method. NB: The actual streaming performance when consuming the `ResultSet.stream()` hasn't changed. Only the `ResultSet.json()` method used a suboptimal stream processing in some instances, and now `ResultSet.json()` just consumes the same stream transformer provided by the `ResultSet.stream()` method (see [#253](https://github.com/ClickHouse/clickhouse-js/pull/253) for more details).
978
+
979
+ ### Miscellaneous
980
+
981
+ - Added `http_headers` configuration parameter as a direct replacement for `additional_headers`. Functionally, it is the same, and the change is purely cosmetic, as we'd like to leave an option to implement TCP connection in the future open.
982
+
983
+ ## 0.3.1 (Common, Node.js, Web)
984
+
985
+ ### Bug fixes
986
+
987
+ - Fixed an issue where query parameters containing tabs or newline characters were not encoded properly.
988
+
989
+ ## 0.3.0 (Node.js only)
990
+
991
+ This release primarily focuses on improving the Keep-Alive mechanism's reliability on the client side.
992
+
993
+ ### New features
994
+
995
+ - Idle sockets timeout rework; now, the client attaches internal timers to idling sockets, and forcefully removes them from the pool if it considers that a particular socket is idling for too long. The intention of this additional sockets housekeeping is to eliminate "Socket hang-up" errors that could previously still occur on certain configurations. Now, the client does not rely on KeepAlive agent when it comes to removing the idling sockets; in most cases, the server will not close the socket before the client does.
996
+ - There is a new `keep_alive.idle_socket_ttl` configuration parameter. The default value is `2500` (milliseconds), which is considered to be safe, as [ClickHouse versions prior to 23.11 had `keep_alive_timeout` set to 3 seconds by default](https://github.com/ClickHouse/ClickHouse/commit/1685cdcb89fe110b45497c7ff27ce73cc03e82d1), and `keep_alive.idle_socket_ttl` is supposed to be slightly less than that to allow the client to remove the sockets that are about to expire before the server does so.
997
+ - Logging improvements: more internal logs on failing requests; all client methods except ping will log an error on failure now. A failed ping will log a warning, since the underlying error is returned as a part of its result. Client logging still needs to be enabled explicitly by specifying the desired `log.level` config option, as the log level is `OFF` by default. Currently, the client logs the following events, depending on the selected `log.level` value:
998
+ - `TRACE` - low-level information about the Keep-Alive sockets lifecycle.
999
+ - `DEBUG` - response information (without authorization headers and host info).
1000
+ - `INFO` - still mostly unused, will print the current log level when the client is initialized.
1001
+ - `WARN` - non-fatal errors; failed `ping` request is logged as a warning, as the underlying error is included in the returned result.
1002
+ - `ERROR` - fatal errors from `query`/`insert`/`exec`/`command` methods, such as a failed request.
1003
+
1004
+ ### Breaking changes
1005
+
1006
+ - `keep_alive.retry_on_expired_socket` and `keep_alive.socket_ttl` configuration parameters are removed.
1007
+ - The `max_open_connections` configuration parameter is now 10 by default, as we should not rely on the KeepAlive agent's defaults.
1008
+ - Fixed the default `request_timeout` configuration value (now it is correctly set to `30_000`, previously `300_000` (milliseconds)).
1009
+
1010
+ ### Bug fixes
1011
+
1012
+ - Fixed a bug with Ping that could lead to an unhandled "Socket hang-up" propagation.
1013
+ - Ensure proper `Connection` header value considering Keep-Alive settings. If Keep-Alive is disabled, its value is now forced to ["close"](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection#close).
1014
+
1015
+ ## 0.3.0-beta.1 (Node.js only)
1016
+
1017
+ See [0.3.0](#030-nodejs-only).
1018
+
1019
+ ## 0.2.10 (Common, Node.js, Web)
1020
+
1021
+ ### New features
1022
+
1023
+ - If `InsertParams.values` is an empty array, no request is sent to the server and `ClickHouseClient.insert` short-circuits itself. In this scenario, the newly added `InsertResult.executed` flag will be `false`, and `InsertResult.query_id` will be an empty string.
1024
+
1025
+ ### Bug fixes
1026
+
1027
+ - Client no longer produces `Code: 354. inflate failed: buffer error` exception if request compression is enabled and `InsertParams.values` is an empty array (see above).
1028
+
1029
+ ## 0.2.9 (Common, Node.js, Web)
1030
+
1031
+ ### New features
1032
+
1033
+ - It is now possible to set additional HTTP headers for outgoing ClickHouse requests. This might be useful if, for example, you use a reverse proxy with authorization. ([@teawithfruit](https://github.com/teawithfruit), [#224](https://github.com/ClickHouse/clickhouse-js/pull/224))
1034
+
1035
+ ```ts
1036
+ const client = createClient({
1037
+ additional_headers: {
1038
+ "X-ClickHouse-User": "clickhouse_user",
1039
+ "X-ClickHouse-Key": "clickhouse_password",
1040
+ },
1041
+ });
1042
+ ```
1043
+
1044
+ ## 0.2.8 (Common, Node.js, Web)
1045
+
1046
+ ### New features
1047
+
1048
+ - (Web only) Allow to modify Keep-Alive setting (previously always disabled).
1049
+ Keep-Alive setting **is now enabled by default** for the Web version.
1050
+
1051
+ ```ts
1052
+ import { createClient } from "@clickhouse/client-web";
1053
+ const client = createClient({ keep_alive: { enabled: true } });
1054
+ ```
1055
+
1056
+ - (Node.js & Web) It is now possible to either specify a list of columns to insert the data into or a list of excluded columns:
1057
+
1058
+ ```ts
1059
+ // Generated query: INSERT INTO mytable (message) FORMAT JSONEachRow
1060
+ await client.insert({
1061
+ table: "mytable",
1062
+ format: "JSONEachRow",
1063
+ values: [{ message: "foo" }],
1064
+ columns: ["message"],
1065
+ });
1066
+
1067
+ // Generated query: INSERT INTO mytable (* EXCEPT (message)) FORMAT JSONEachRow
1068
+ await client.insert({
1069
+ table: "mytable",
1070
+ format: "JSONEachRow",
1071
+ values: [{ id: 42 }],
1072
+ columns: { except: ["message"] },
1073
+ });
1074
+ ```
1075
+
1076
+ See also the new examples:
1077
+
1078
+ - [Including specific columns](../../examples/insert_specific_columns.ts) or [excluding certain ones instead](../../examples/insert_exclude_columns.ts)
1079
+ - [Leveraging this feature](../../examples/insert_ephemeral_columns.ts) when working with
1080
+ [ephemeral columns](https://clickhouse.com/docs/en/sql-reference/statements/create/table#ephemeral)
1081
+ ([#217](https://github.com/ClickHouse/clickhouse-js/issues/217))
1082
+
1083
+ ## 0.2.7 (Common, Node.js, Web)
1084
+
1085
+ ### New features
1086
+
1087
+ - (Node.js only) `X-ClickHouse-Summary` response header is now parsed when working with `insert`/`exec`/`command` methods.
1088
+ See the [related test](../../packages/client-node/__tests__/integration/node_summary.test.ts) for more details.
1089
+ NB: it is guaranteed to be correct only for non-streaming scenarios.
1090
+ Web version does not currently support this due to CORS limitations. ([#210](https://github.com/ClickHouse/clickhouse-js/issues/210))
1091
+
1092
+ ### Bug fixes
1093
+
1094
+ - Drain insert response stream in Web version - required to properly work with `async_insert`, especially in the Cloudflare Workers context.
1095
+
1096
+ ## 0.2.6 (Common, Node.js)
1097
+
1098
+ ### New features
1099
+
1100
+ - Added [Parquet format](https://clickhouse.com/docs/en/integrations/data-formats/parquet) streaming support.
1101
+ See the new examples:
1102
+ [insert from a file](../../examples/node/insert_file_stream_parquet.ts),
1103
+ [select into a file](../../examples/node/select_parquet_as_file.ts).
1104
+
1105
+ ## 0.2.5 (Common, Node.js, Web)
1106
+
1107
+ ### Bug fixes
1108
+
1109
+ - `pathname` segment from `host` client configuration parameter is now handled properly when making requests.
1110
+ See this [comment](https://github.com/ClickHouse/clickhouse-js/issues/164#issuecomment-1785166626) for more details.
1111
+
1112
+ ## 0.2.4 (Node.js only)
1113
+
1114
+ No changes in web/common modules.
1115
+
1116
+ ### Bug fixes
1117
+
1118
+ - (Node.js only) Fixed an issue where streaming large datasets could provide corrupted results. See [#171](https://github.com/ClickHouse/clickhouse-js/issues/171) (issue) and [#204](https://github.com/ClickHouse/clickhouse-js/pull/204) (PR) for more details.
1119
+
1120
+ ## 0.2.3 (Node.js only)
1121
+
1122
+ No changes in web/common modules.
1123
+
1124
+ ### Bug fixes
1125
+
1126
+ - (Node.js only) Fixed an issue where the underlying socket was closed every time after using `insert` with a `keep_alive` option enabled, which led to performance limitations. See [#202](https://github.com/ClickHouse/clickhouse-js/issues/202) for more details. ([@varrocs](https://github.com/varrocs))
1127
+
1128
+ ## 0.2.2 (Common, Node.js & Web)
1129
+
1130
+ ### New features
1131
+
1132
+ - Added `default_format` setting, which allows to perform `exec` calls without `FORMAT` clause.
1133
+
1134
+ ## 0.2.1 (Common, Node.js & Web)
1135
+
1136
+ ### Breaking changes
1137
+
1138
+ Date objects in query parameters are now serialized as time-zone-agnostic Unix timestamps (NNNNNNNNNN[.NNN], optionally with millisecond-precision) instead of datetime strings without time zones (YYYY-MM-DD HH:MM:SS[.MMM]). This means the server will receive the same absolute timestamp the client sent even if the client's time zone and the database server's time zone differ. Previously, if the server used one time zone and the client used another, Date objects would be encoded in the client's time zone and decoded in the server's time zone and create a mismatch.
1139
+
1140
+ For instance, if the server used UTC (GMT) and the client used PST (GMT-8), a Date object for "2023-01-01 13:00:00 **PST**" would be encoded as "2023-01-01 13:00:00.000" and decoded as "2023-01-01 13:00:00 **UTC**" (which is 2023-01-01 **05**:00:00 PST). Now, "2023-01-01 13:00:00 PST" is encoded as "1672606800000" and decoded as "2023-01-01 **21**:00:00 UTC", the same time the client sent.
1141
+
1142
+ ## 0.2.0 (web platform support)
1143
+
1144
+ Introduces web client (using native [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
1145
+ and [WebStream](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) APIs)
1146
+ without Node.js modules in the common interfaces. No polyfills are required.
1147
+
1148
+ Web client is confirmed to work with Chrome/Firefox/CloudFlare workers.
1149
+
1150
+ It is now possible to implement new custom connections on top of `@clickhouse/client-common`.
1151
+
1152
+ The client was refactored into three packages:
1153
+
1154
+ - `@clickhouse/client-common`: all possible platform-independent code, types and interfaces
1155
+ - `@clickhouse/client-web`: new web (or non-Node.js env) connection, uses native fetch.
1156
+ - `@clickhouse/client`: Node.js connection as it was before.
1157
+
1158
+ ### Node.js client breaking changes
1159
+
1160
+ - Changed `ping` method behavior: it will not throw now.
1161
+ Instead, either `{ success: true }` or `{ success: false, error: Error }` is returned.
1162
+ - Log level configuration parameter is now explicit instead of `CLICKHOUSE_LOG_LEVEL` environment variable.
1163
+ Default is `OFF`.
1164
+ - `query` return type signature changed to is `BaseResultSet<Stream.Readable>` (no functional changes)
1165
+ - `exec` return type signature changed to `ExecResult<Stream.Readable>` (no functional changes)
1166
+ - `insert<T>` params argument type changed to `InsertParams<Stream, T>` (no functional changes)
1167
+ - Experimental `schema` module is removed
1168
+
1169
+ ### Web client known limitations
1170
+
1171
+ - Streaming for select queries works, but it is disabled for inserts (on the type level as well).
1172
+ - KeepAlive is disabled and not configurable yet.
1173
+ - Request compression is disabled and configuration is ignored. Response compression works.
1174
+ - No logging support yet.
1175
+
1176
+ ## 0.1.1
1177
+
1178
+ ## New features
1179
+
1180
+ - Expired socket detection on the client side when using Keep-Alive. If a potentially expired socket is detected,
1181
+ and retry is enabled in the configuration, both socket and request will be immediately destroyed (before sending the data),
1182
+ and the client will recreate the request. See `ClickHouseClientConfigOptions.keep_alive` for more details. Disabled by default.
1183
+ - Allow disabling Keep-Alive feature entirely.
1184
+ - `TRACE` log level.
1185
+
1186
+ ## Examples
1187
+
1188
+ #### Disable Keep-Alive feature
1189
+
1190
+ ```ts
1191
+ const client = createClient({
1192
+ keep_alive: {
1193
+ enabled: false,
1194
+ },
1195
+ });
1196
+ ```
1197
+
1198
+ #### Retry on expired socket
1199
+
1200
+ ```ts
1201
+ const client = createClient({
1202
+ keep_alive: {
1203
+ enabled: true,
1204
+ // should be slightly less than the `keep_alive_timeout` setting in server's `config.xml`
1205
+ // default is 3s there, so 2500 milliseconds seems to be a safe client value in this scenario
1206
+ // another example: if your configuration has `keep_alive_timeout` set to 60s, you could put 59_000 here
1207
+ socket_ttl: 2500,
1208
+ retry_on_expired_socket: true,
1209
+ },
1210
+ });
1211
+ ```
1212
+
1213
+ ## 0.1.0
1214
+
1215
+ ## Breaking changes
1216
+
1217
+ - `connect_timeout` client setting is removed, as it was unused in the code.
1218
+
1219
+ ## New features
1220
+
1221
+ - `command` method is introduced as an alternative to `exec`.
1222
+ `command` does not expect user to consume the response stream, and it is destroyed immediately.
1223
+ Essentially, this is a shortcut to `exec` that destroys the stream under the hood.
1224
+ Consider using `command` instead of `exec` for DDLs and other custom commands which do not provide any valuable output.
1225
+
1226
+ Example:
1227
+
1228
+ ```ts
1229
+ // incorrect: stream is not consumed and not destroyed, request will be timed out eventually
1230
+ await client.exec("CREATE TABLE foo (id String) ENGINE Memory");
1231
+
1232
+ // correct: stream does not contain any information and just destroyed
1233
+ const { stream } = await client.exec(
1234
+ "CREATE TABLE foo (id String) ENGINE Memory",
1235
+ );
1236
+ stream.destroy();
1237
+
1238
+ // correct: same as exec + stream.destroy()
1239
+ await client.command("CREATE TABLE foo (id String) ENGINE Memory");
1240
+ ```
1241
+
1242
+ ### Bug fixes
1243
+
1244
+ - Fixed delays on subsequent requests after calling `insert` that happened due to unclosed stream instance when using low number of `max_open_connections`. See [#161](https://github.com/ClickHouse/clickhouse-js/issues/161) for more details.
1245
+ - Request timeouts internal logic rework (see [#168](https://github.com/ClickHouse/clickhouse-js/pull/168))
1246
+
1247
+ ## 0.0.16
1248
+
1249
+ - Fix NULL parameter binding.
1250
+ As HTTP interface expects `\N` instead of `'NULL'` string, it is now correctly handled for both `null`
1251
+ and _explicitly_ `undefined` parameters. See the [test scenarios](https://github.com/ClickHouse/clickhouse-js/blob/f1500e188600d85ddd5ee7d2a80846071c8cf23e/__tests__/integration/select_query_binding.test.ts#L273-L303) for more details.
1252
+
1253
+ ## 0.0.15
1254
+
1255
+ ### Bug fixes
1256
+
1257
+ - Fix Node.JS 19.x/20.x timeout error (@olexiyb)
1258
+
1259
+ ## 0.0.14
1260
+
1261
+ ### New features
1262
+
1263
+ - Added support for `JSONStrings`, `JSONCompact`, `JSONCompactStrings`, `JSONColumnsWithMetadata` formats (@andrewzolotukhin).
1264
+
1265
+ ## 0.0.13
1266
+
1267
+ ### New features
1268
+
1269
+ - `query_id` can be now overridden for all main client's methods: `query`, `exec`, `insert`.
1270
+
1271
+ ## 0.0.12
1272
+
1273
+ ### New features
1274
+
1275
+ - `ResultSet.query_id` contains a unique query identifier that might be useful for retrieving query metrics from `system.query_log`
1276
+ - `User-Agent` HTTP header is set according to the [language client spec](https://docs.google.com/document/d/1924Dvy79KXIhfqKpi1EBVY3133pIdoMwgCQtZ-uhEKs/edit#heading=h.ah33hoz5xei2).
1277
+ For example, for client version 0.0.12 and Node.js runtime v19.0.4 on Linux platform, it will be `clickhouse-js/0.0.12 (lv:nodejs/19.0.4; os:linux)`.
1278
+ If `ClickHouseClientConfigOptions.application` is set, it will be prepended to the generated `User-Agent`.
1279
+
1280
+ ### Breaking changes
1281
+
1282
+ - `client.insert` now returns `{ query_id: string }` instead of `void`
1283
+ - `client.exec` now returns `{ stream: Stream.Readable, query_id: string }` instead of just `Stream.Readable`
1284
+
1285
+ ## 0.0.11, 2022-12-08
1286
+
1287
+ ### Breaking changes
1288
+
1289
+ - `log.enabled` flag was removed from the client configuration.
1290
+ - Use `CLICKHOUSE_LOG_LEVEL` environment variable instead. Possible values: `OFF`, `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`.
1291
+ Currently, there are only debug messages, but we will log more in the future.
1292
+
1293
+ For more details, see PR [#110](https://github.com/ClickHouse/clickhouse-js/pull/110)
1294
+
1295
+ ## 0.0.10, 2022-11-14
1296
+
1297
+ ### New features
1298
+
1299
+ - Remove request listeners synchronously.
1300
+ [#123](https://github.com/ClickHouse/clickhouse-js/issues/123)
1301
+
1302
+ ## 0.0.9, 2022-10-25
1303
+
1304
+ ### New features
1305
+
1306
+ - Added ClickHouse session_id support.
1307
+ [#121](https://github.com/ClickHouse/clickhouse-js/pull/121)
1308
+
1309
+ ## 0.0.8, 2022-10-18
1310
+
1311
+ ### New features
1312
+
1313
+ - Added SSL/TLS support (basic and mutual).
1314
+ [#52](https://github.com/ClickHouse/clickhouse-js/issues/52)
1315
+
1316
+ ## 0.0.7, 2022-10-18
1317
+
1318
+ ### Bug fixes
1319
+
1320
+ - Allow semicolons in select clause.
1321
+ [#116](https://github.com/ClickHouse/clickhouse-js/issues/116)
1322
+
1323
+ ## 0.0.6, 2022-10-07
1324
+
1325
+ ### New features
1326
+
1327
+ - Add JSONObjectEachRow input/output and JSON input formats.
1328
+ [#113](https://github.com/ClickHouse/clickhouse-js/pull/113)
1329
+
1330
+ ## 0.0.5, 2022-10-04
1331
+
1332
+ ### Breaking changes
1333
+
1334
+ - Rows abstraction was renamed to ResultSet.
1335
+ - now, every iteration over `ResultSet.stream()` yields `Row[]` instead of a single `Row`.
1336
+ Please check out [an example](https://github.com/ClickHouse/clickhouse-js/blob/c86c31dada8f4845cd4e6843645177c99bc53a9d/examples/select_streaming_on_data.ts)
1337
+ and [this PR](https://github.com/ClickHouse/clickhouse-js/pull/109) for more details.
1338
+ These changes allowed us to significantly reduce overhead on select result set streaming.
1339
+
1340
+ ### New features
1341
+
1342
+ - [split2](https://www.npmjs.com/package/split2) is no longer a package dependency.