@clickhouse/client 1.22.0 → 1.23.0-head.70ad405.1
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.
- package/CHANGELOG.md +1342 -0
- package/README.md +20 -7
- package/dist/client.d.ts +2 -2
- package/dist/client.js +11 -4
- package/dist/client.js.map +1 -1
- package/dist/common/clickhouse_types.d.ts +98 -0
- package/dist/common/clickhouse_types.js +30 -0
- package/dist/common/clickhouse_types.js.map +1 -0
- package/dist/common/client.d.ts +233 -0
- package/dist/common/client.js +414 -0
- package/dist/common/client.js.map +1 -0
- package/dist/common/config.d.ts +234 -0
- package/dist/common/config.js +364 -0
- package/dist/common/config.js.map +1 -0
- package/dist/common/connection.d.ts +124 -0
- package/dist/common/connection.js +3 -0
- package/dist/common/connection.js.map +1 -0
- package/dist/common/data_formatter/format_query_params.d.ts +11 -0
- package/dist/common/data_formatter/format_query_params.js +128 -0
- package/dist/common/data_formatter/format_query_params.js.map +1 -0
- package/dist/common/data_formatter/format_query_settings.d.ts +2 -0
- package/dist/common/data_formatter/format_query_settings.js +20 -0
- package/dist/common/data_formatter/format_query_settings.js.map +1 -0
- package/dist/common/data_formatter/formatter.d.ts +41 -0
- package/dist/common/data_formatter/formatter.js +78 -0
- package/dist/common/data_formatter/formatter.js.map +1 -0
- package/dist/common/data_formatter/index.d.ts +3 -0
- package/dist/common/data_formatter/index.js +24 -0
- package/dist/common/data_formatter/index.js.map +1 -0
- package/dist/common/error/error.d.ts +20 -0
- package/dist/common/error/error.js +73 -0
- package/dist/common/error/error.js.map +1 -0
- package/dist/common/error/index.d.ts +1 -0
- package/dist/common/error/index.js +18 -0
- package/dist/common/error/index.js.map +1 -0
- package/dist/common/index.d.ts +67 -0
- package/dist/common/index.js +97 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/logger.d.ts +80 -0
- package/dist/common/logger.js +154 -0
- package/dist/common/logger.js.map +1 -0
- package/dist/common/parse/column_types.d.ts +155 -0
- package/dist/common/parse/column_types.js +594 -0
- package/dist/common/parse/column_types.js.map +1 -0
- package/dist/common/parse/index.d.ts +2 -0
- package/dist/common/parse/index.js +19 -0
- package/dist/common/parse/index.js.map +1 -0
- package/dist/common/parse/json_handling.d.ts +19 -0
- package/dist/common/parse/json_handling.js +8 -0
- package/dist/common/parse/json_handling.js.map +1 -0
- package/dist/common/result.d.ts +90 -0
- package/dist/common/result.js +3 -0
- package/dist/common/result.js.map +1 -0
- package/dist/common/settings.d.ts +2007 -0
- package/dist/common/settings.js +19 -0
- package/dist/common/settings.js.map +1 -0
- package/dist/common/tracing.d.ts +146 -0
- package/dist/common/tracing.js +76 -0
- package/dist/common/tracing.js.map +1 -0
- package/dist/common/ts_utils.d.ts +4 -0
- package/dist/common/ts_utils.js +3 -0
- package/dist/common/ts_utils.js.map +1 -0
- package/dist/common/utils/connection.d.ts +21 -0
- package/dist/common/utils/connection.js +43 -0
- package/dist/common/utils/connection.js.map +1 -0
- package/dist/common/utils/index.d.ts +5 -0
- package/dist/common/utils/index.js +22 -0
- package/dist/common/utils/index.js.map +1 -0
- package/dist/common/utils/multipart.d.ts +34 -0
- package/dist/common/utils/multipart.js +81 -0
- package/dist/common/utils/multipart.js.map +1 -0
- package/dist/common/utils/sleep.d.ts +4 -0
- package/dist/common/utils/sleep.js +12 -0
- package/dist/common/utils/sleep.js.map +1 -0
- package/dist/common/utils/stream.d.ts +15 -0
- package/dist/common/utils/stream.js +50 -0
- package/dist/common/utils/stream.js.map +1 -0
- package/dist/common/utils/url.d.ts +20 -0
- package/dist/common/utils/url.js +67 -0
- package/dist/common/utils/url.js.map +1 -0
- package/dist/common/version.d.ts +2 -0
- package/dist/common/version.js +4 -0
- package/dist/common/version.js.map +1 -0
- package/dist/config.d.ts +22 -2
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/connection/compression.d.ts +2 -2
- package/dist/connection/compression.js +4 -4
- package/dist/connection/compression.js.map +1 -1
- package/dist/connection/create_connection.d.ts +1 -1
- package/dist/connection/node_base_connection.d.ts +3 -3
- package/dist/connection/node_base_connection.js +22 -22
- package/dist/connection/node_base_connection.js.map +1 -1
- package/dist/connection/node_custom_agent_connection.js +2 -2
- package/dist/connection/node_custom_agent_connection.js.map +1 -1
- package/dist/connection/node_http_connection.js +2 -2
- package/dist/connection/node_http_connection.js.map +1 -1
- package/dist/connection/node_https_connection.d.ts +1 -1
- package/dist/connection/node_https_connection.js +3 -3
- package/dist/connection/node_https_connection.js.map +1 -1
- package/dist/connection/socket_pool.d.ts +1 -1
- package/dist/connection/socket_pool.js +30 -30
- package/dist/connection/socket_pool.js.map +1 -1
- package/dist/connection/stream.d.ts +1 -1
- package/dist/connection/stream.js +9 -9
- package/dist/connection/stream.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.js +26 -24
- package/dist/index.js.map +1 -1
- package/dist/result_set.d.ts +1 -1
- package/dist/result_set.js +10 -10
- package/dist/result_set.js.map +1 -1
- package/dist/utils/encoder.d.ts +1 -1
- package/dist/utils/encoder.js +5 -5
- package/dist/utils/encoder.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +10 -7
- package/skills/AGENTS.md +8 -0
- package/skills/clickhouse-js-node-rowbinary/AGENTS.md +44 -0
- package/skills/clickhouse-js-node-rowbinary/CHANGELOG.md +49 -0
- package/skills/clickhouse-js-node-rowbinary/EXAMPLES.md +48 -0
- package/skills/clickhouse-js-node-rowbinary/README.md +319 -0
- package/skills/clickhouse-js-node-rowbinary/SKILL.md +111 -0
- package/skills/clickhouse-js-node-rowbinary/case-studies/iot-rowbinary-vs-json.md +83 -0
- package/skills/clickhouse-js-node-rowbinary/case-studies/ledger-rowbinary-vs-json.md +103 -0
- package/skills/clickhouse-js-node-rowbinary/case-studies/logs-json-wins.md +86 -0
- package/skills/clickhouse-js-node-rowbinary/case-studies/wasm-vs-js.md +172 -0
- package/skills/clickhouse-js-node-rowbinary/reader.md +126 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/carts.ts +75 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/events.ts +51 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/iot.ts +158 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/ledger.ts +98 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/logs.ts +73 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/observability.ts +141 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/orders.ts +66 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/profiles.ts +60 -0
- package/skills/clickhouse-js-node-rowbinary/src/examples/telemetry.ts +102 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/aggregateFunction.ts +34 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/bool.ts +10 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/columnar.ts +125 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/compile.ts +328 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/composite.ts +181 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/core.ts +77 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/datetime.ts +113 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/decimals.ts +57 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/dynamic.ts +332 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/enums.ts +40 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/floats.ts +32 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/geo.ts +109 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/header.ts +29 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/integers.ts +95 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/interval.ts +54 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/ip.ts +93 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/json.ts +33 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/lowCardinality.ts +18 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/nested.ts +23 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/nothing.ts +29 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/reader.ts +68 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/rowBinaryWithNamesAndTypes.ts +155 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/rows.ts +58 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/simpleAggregateFunction.ts +20 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/stream.ts +276 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/strings.ts +55 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/time.ts +61 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/uuid.ts +153 -0
- package/skills/clickhouse-js-node-rowbinary/src/readers/varint.ts +70 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/aggregateFunction.ts +18 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/bool.ts +10 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/composite.ts +140 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/core.ts +92 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/datetime.ts +123 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/decimals.ts +51 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/enums.ts +18 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/floats.ts +40 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/geo.ts +125 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/integers.ts +90 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/interval.ts +11 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/ip.ts +121 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/lowCardinality.ts +12 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/nested.ts +17 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/nothing.ts +21 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/rows.ts +144 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/simpleAggregateFunction.ts +12 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/strings.ts +77 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/time.ts +54 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/uuid.ts +60 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/varint.ts +64 -0
- package/skills/clickhouse-js-node-rowbinary/src/writers/writer.ts +101 -0
- package/skills/clickhouse-js-node-rowbinary/writer.md +96 -0
package/dist/result_set.js
CHANGED
|
@@ -34,8 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ResultSet = void 0;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
37
|
+
const index_1 = require("./common/index");
|
|
38
|
+
const index_2 = require("./common/index");
|
|
39
39
|
const buffer_1 = require("buffer");
|
|
40
40
|
const stream_1 = __importStar(require("stream"));
|
|
41
41
|
const utils_1 = require("./utils");
|
|
@@ -71,14 +71,14 @@ class ResultSet {
|
|
|
71
71
|
this.query_id = query_id;
|
|
72
72
|
this.span = span;
|
|
73
73
|
this.jsonHandling = {
|
|
74
|
-
...
|
|
74
|
+
...index_1.defaultJSONHandling,
|
|
75
75
|
...jsonHandling,
|
|
76
76
|
};
|
|
77
77
|
// eslint-disable-next-line no-console
|
|
78
78
|
this.log_error = log_error ?? ((err) => console.error(err));
|
|
79
79
|
if (_response_headers !== undefined) {
|
|
80
80
|
this.response_headers = Object.freeze(_response_headers);
|
|
81
|
-
this.exceptionTag = _response_headers[
|
|
81
|
+
this.exceptionTag = _response_headers[index_1.EXCEPTION_TAG_HEADER_NAME];
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
consume() {
|
|
@@ -110,7 +110,7 @@ class ResultSet {
|
|
|
110
110
|
}
|
|
111
111
|
this.span.setAttributes(attributes);
|
|
112
112
|
if (err) {
|
|
113
|
-
(0,
|
|
113
|
+
(0, index_1.recordSpanError)(this.span, err);
|
|
114
114
|
}
|
|
115
115
|
this.span.end();
|
|
116
116
|
}
|
|
@@ -131,7 +131,7 @@ class ResultSet {
|
|
|
131
131
|
/** See {@link BaseResultSet.json}. */
|
|
132
132
|
async json() {
|
|
133
133
|
// JSONEachRow, etc.
|
|
134
|
-
if ((0,
|
|
134
|
+
if ((0, index_2.isStreamableJSONFamily)(this.format)) {
|
|
135
135
|
const result = [];
|
|
136
136
|
// Using the stream() instead of _stream directly to leverage the existing logic
|
|
137
137
|
// for handling incomplete chunks and exception tags.
|
|
@@ -146,7 +146,7 @@ class ResultSet {
|
|
|
146
146
|
return result;
|
|
147
147
|
}
|
|
148
148
|
// JSON, JSONObjectEachRow, etc.
|
|
149
|
-
if ((0,
|
|
149
|
+
if ((0, index_2.isNotStreamableJSONFamily)(this.format)) {
|
|
150
150
|
const stream = this.consume();
|
|
151
151
|
try {
|
|
152
152
|
const text = await (0, utils_1.getAsText)(stream);
|
|
@@ -164,7 +164,7 @@ class ResultSet {
|
|
|
164
164
|
}
|
|
165
165
|
/** See {@link BaseResultSet.stream}. */
|
|
166
166
|
stream() {
|
|
167
|
-
(0,
|
|
167
|
+
(0, index_2.validateStreamFormat)(this.format);
|
|
168
168
|
const incompleteChunks = [];
|
|
169
169
|
const logError = this.log_error;
|
|
170
170
|
const exceptionTag = this.exceptionTag;
|
|
@@ -193,8 +193,8 @@ class ResultSet {
|
|
|
193
193
|
// Check for exception in the chunk (only after 25.11)
|
|
194
194
|
if (exceptionTag !== undefined &&
|
|
195
195
|
idx >= 1 &&
|
|
196
|
-
chunk[idx - 1] ===
|
|
197
|
-
return callback((0,
|
|
196
|
+
chunk[idx - 1] === index_1.CARET_RETURN) {
|
|
197
|
+
return callback((0, index_1.extractErrorAtTheEndOfChunk)(chunk, exceptionTag));
|
|
198
198
|
}
|
|
199
199
|
if (incompleteChunks.length > 0) {
|
|
200
200
|
incompleteChunks.push(chunk.subarray(lastIdx, idx));
|
package/dist/result_set.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result_set.js","sourceRoot":"","sources":["../src/result_set.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,
|
|
1
|
+
{"version":3,"file":"result_set.js","sourceRoot":"","sources":["../src/result_set.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,0CAMwB;AACxB,0CAIwB;AACxB,mCAAgC;AAEhC,iDAA2C;AAC3C,mCAAoC;AAEpC,MAAM,OAAO,GAAG,IAAa,CAAC;AAqC9B,MAAa,SAAS;IAGJ,gBAAgB,GAAoB,EAAE,CAAC;IAEtC,YAAY,GAAuB,SAAS,CAAC;IAC7C,SAAS,CAAyB;IAClC,YAAY,CAAe;IACpC,SAAS,GAAG,KAAK,CAAC;IAC1B;;;;;OAKG;IACK,OAAO,CAAkB;IAChB,MAAM,CAAS;IAChC;;wEAEoE;IACnD,IAAI,CAA6B;IAClD,oEAAoE;IAC5D,UAAU,GAAG,CAAC,CAAC;IACvB,oDAAoD;IAC5C,SAAS,GAAG,CAAC,CAAC;IACd,iBAAiB,GAAG,KAAK,CAAC;IAC1B,aAAa,GAAG,KAAK,CAAC;IACd,QAAQ,CAAS;IAEjC,YACE,OAAwB,EACxB,MAAc,EACd,QAAgB,EAChB,SAAkC,EAClC,iBAAmC,EACnC,YAA2B,EAC3B,IAAqB;QAErB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,YAAY,GAAG;YAClB,GAAG,2BAAmB;YACtB,GAAG,YAAY;S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 +1,4 @@
|
|
|
1
|
-
import type { DataFormat, InsertValues, JSONHandling, ValuesEncoder } from "
|
|
1
|
+
import type { DataFormat, InsertValues, JSONHandling, ValuesEncoder } from "../common/index";
|
|
2
2
|
import Stream from "stream";
|
|
3
3
|
export declare class NodeValuesEncoder implements ValuesEncoder<Stream.Readable> {
|
|
4
4
|
private readonly json;
|
package/dist/utils/encoder.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.NodeValuesEncoder = void 0;
|
|
7
|
-
const
|
|
7
|
+
const index_1 = require("../common/index");
|
|
8
8
|
const stream_1 = __importDefault(require("stream"));
|
|
9
9
|
const stream_2 = require("./stream");
|
|
10
10
|
class NodeValuesEncoder {
|
|
@@ -19,17 +19,17 @@ class NodeValuesEncoder {
|
|
|
19
19
|
return values;
|
|
20
20
|
}
|
|
21
21
|
// JSON* formats streams
|
|
22
|
-
return stream_1.default.pipeline(values, (0, stream_2.mapStream)((value) => (0,
|
|
22
|
+
return stream_1.default.pipeline(values, (0, stream_2.mapStream)((value) => (0, index_1.encodeJSON)(value, format, this.json.stringify)), pipelineCb);
|
|
23
23
|
}
|
|
24
24
|
// JSON* arrays
|
|
25
25
|
if (Array.isArray(values)) {
|
|
26
26
|
return values
|
|
27
|
-
.map((value) => (0,
|
|
27
|
+
.map((value) => (0, index_1.encodeJSON)(value, format, this.json.stringify))
|
|
28
28
|
.join("");
|
|
29
29
|
}
|
|
30
30
|
// JSON & JSONObjectEachRow format input
|
|
31
31
|
if (typeof values === "object") {
|
|
32
|
-
return (0,
|
|
32
|
+
return (0, index_1.encodeJSON)(values, format, this.json.stringify);
|
|
33
33
|
}
|
|
34
34
|
throw new Error(`Cannot encode values of type ${typeof values} with ${format} format`);
|
|
35
35
|
}
|
|
@@ -41,7 +41,7 @@ class NodeValuesEncoder {
|
|
|
41
41
|
`got: ${typeof values}`);
|
|
42
42
|
}
|
|
43
43
|
if ((0, stream_2.isStream)(values)) {
|
|
44
|
-
if ((0,
|
|
44
|
+
if ((0, index_1.isSupportedRawFormat)(format)) {
|
|
45
45
|
if (values.readableObjectMode) {
|
|
46
46
|
throw new Error(`Insert for ${format} expected Readable Stream with disabled object mode.`);
|
|
47
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../src/utils/encoder.ts"],"names":[],"mappings":";;;;;;AAMA,
|
|
1
|
+
{"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../src/utils/encoder.ts"],"names":[],"mappings":";;;;;;AAMA,2CAAmE;AACnE,oDAA4B;AAC5B,qCAA+C;AAE/C,MAAa,iBAAiB;IACX,IAAI,CAAe;IAEpC,YAAY,gBAA8B;QACxC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;IAED,YAAY,CACV,MAAwC,EACxC,MAAkB;QAElB,IAAI,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAAE,CAAC;YACrB,yEAAyE;YACzE,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;gBAC/B,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,wBAAwB;YACxB,OAAO,gBAAM,CAAC,QAAQ,CACpB,MAAM,EACN,IAAA,kBAAS,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EACpE,UAAU,CACX,CAAC;QACJ,CAAC;QACD,eAAe;QACf,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,MAAM;iBACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;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default: "1.
|
|
1
|
+
declare const _default: "1.23.0-head.70ad405.1";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,uBAAuB,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@clickhouse/client",
|
|
3
3
|
"description": "Official JS client for ClickHouse DB - Node.js implementation",
|
|
4
4
|
"homepage": "https://clickhouse.com",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.23.0-head.70ad405.1",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"clickhouse",
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
},
|
|
16
16
|
"private": false,
|
|
17
17
|
"engines": {
|
|
18
|
-
"node": ">=
|
|
18
|
+
"node": ">=20"
|
|
19
19
|
},
|
|
20
20
|
"main": "dist/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
|
24
|
-
"skills"
|
|
24
|
+
"skills",
|
|
25
|
+
"CHANGELOG.md"
|
|
25
26
|
],
|
|
26
27
|
"agents": {
|
|
27
28
|
"skills": [
|
|
@@ -32,20 +33,22 @@
|
|
|
32
33
|
{
|
|
33
34
|
"name": "clickhouse-js-node-troubleshooting",
|
|
34
35
|
"path": "./skills/clickhouse-js-node-troubleshooting"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "clickhouse-js-node-rowbinary",
|
|
39
|
+
"path": "./skills/clickhouse-js-node-rowbinary"
|
|
35
40
|
}
|
|
36
41
|
]
|
|
37
42
|
},
|
|
38
43
|
"scripts": {
|
|
39
44
|
"pack": "npm pack",
|
|
40
|
-
"prepack": "rm -rf skills && cp ../../README.md ../../LICENSE . && cp -r ../../skills .",
|
|
45
|
+
"prepack": "rm -rf skills && cp ../../README.md ../../LICENSE . && cp -r ../../skills . && RBP=skills/clickhouse-js-node-rowbinary && rm -rf $RBP/tests $RBP/node_modules $RBP/dist $RBP/package.json $RBP/package-lock.json $RBP/tsconfig.json $RBP/tsconfig.build.json $RBP/vitest.config.ts $RBP/.gitignore $RBP/LICENSE $RBP/eval_result*.md",
|
|
41
46
|
"typecheck": "tsc --noEmit",
|
|
42
47
|
"lint": "eslint --max-warnings=0 .",
|
|
43
48
|
"lint:fix": "eslint . --fix",
|
|
44
49
|
"build": "rm -rf dist; tsc"
|
|
45
50
|
},
|
|
46
|
-
"dependencies": {
|
|
47
|
-
"@clickhouse/client-common": "1.22.0"
|
|
48
|
-
},
|
|
51
|
+
"dependencies": {},
|
|
49
52
|
"devDependencies": {
|
|
50
53
|
"simdjson": "^0.9.2"
|
|
51
54
|
}
|
package/skills/AGENTS.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Recommendations for AI agents — `skills/`
|
|
2
|
+
|
|
3
|
+
Guidance for the shipped agent skills. See the [repo-root `AGENTS.md`](../AGENTS.md) for cross-cutting guidance. The `@clickhouse/rowbinary` skill has its own [`clickhouse-js-node-rowbinary/AGENTS.md`](clickhouse-js-node-rowbinary/AGENTS.md).
|
|
4
|
+
|
|
5
|
+
- Each shipped skill must also be listed in the `agents.skills` array of
|
|
6
|
+
[`packages/client-node/package.json`](../packages/client-node/package.json) so downstream tooling can
|
|
7
|
+
discover it. The [`Skills E2E`](../.github/workflows/e2e-skills.yml) workflow
|
|
8
|
+
(`tests/e2e/skills/check.js`) asserts that the packaged tarball contains the declared skills.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Recommendations for AI agents — `@clickhouse/rowbinary`
|
|
2
|
+
|
|
3
|
+
Guidance for the [`clickhouse-js-node-rowbinary`](.) package (the RowBinary codec library and agent skill). See the [repo-root `AGENTS.md`](../../AGENTS.md) for cross-cutting guidance.
|
|
4
|
+
|
|
5
|
+
This package has a symmetric reader/writer codebase.
|
|
6
|
+
|
|
7
|
+
## Tests
|
|
8
|
+
|
|
9
|
+
The tests follow a few conventions worth preserving:
|
|
10
|
+
|
|
11
|
+
- **Reader and writer tests are separate files.** Readers are tested in `tests/*.test.ts`; writers in
|
|
12
|
+
`tests/*.write.test.ts`. Keep the two independent: a writer test must **never** decode its bytes back
|
|
13
|
+
through a reader (and vice versa), so a bug on one side cannot mask a bug on the other. Writer tests
|
|
14
|
+
assert the encoded bytes against **live ClickHouse output** as the source of truth.
|
|
15
|
+
- **Each case is an isolated `it()` with a fully-inline body.** Write the assertion out per case, e.g.
|
|
16
|
+
`expect(encode(writer, value)).toEqual(await query("SELECT … FORMAT RowBinary"))`. Do **not** hide the
|
|
17
|
+
assertion behind a thunk-factory helper (`it("name", expectFoo(...))`), and do **not** wrap the query
|
|
18
|
+
in a per-file helper — embed the literal SQL inline, including any `SETTINGS` clause, so the full
|
|
19
|
+
query is visible in the test. The only shared helpers are the generic `query()` (`tests/clickhouse.ts`,
|
|
20
|
+
runs SQL → bytes) and `encode()` (`tests/encode.ts`, value → bytes). Repeating SQL across cases is
|
|
21
|
+
fine; reviewability beats DRY here. See [`tests/Integers.write.test.ts`](tests/Integers.write.test.ts)
|
|
22
|
+
as the canonical example.
|
|
23
|
+
|
|
24
|
+
## No defensive validation in readers/writers
|
|
25
|
+
|
|
26
|
+
These are hot-path codecs. **Do not add runtime validation of input values** (`isFinite`,
|
|
27
|
+
range/`NaN` checks, type guards, etc.) to the `readX`/`writeX` functions. The data at this level is
|
|
28
|
+
expected to be correct, and an invalid value is a programming error — document the precondition in the
|
|
29
|
+
JSDoc instead (see `writeUVarint` and the `writeDate*`/`writeDateTime` writers as the canonical
|
|
30
|
+
examples). A `Math.round`-style transform that silently shifts a _valid_ value to the wrong encoding is
|
|
31
|
+
a correctness bug and must be fixed; rejecting an _invalid_ value is not our job here.
|
|
32
|
+
|
|
33
|
+
Two narrow exceptions where a check **is** warranted:
|
|
34
|
+
|
|
35
|
+
1. **It keeps the protocol in sync.** A check belongs in only when skipping it would desync the wire
|
|
36
|
+
stream — e.g. `writeIPv6` requires exactly 16 bytes because a wrong length shifts every subsequent
|
|
37
|
+
field, and `parseIPv6` rejects malformed groups because it can't otherwise produce 16 well-defined
|
|
38
|
+
bytes. These guard the _framing_, not the user's data semantics.
|
|
39
|
+
2. **The cost is genuinely zero or it can't reach the server.** Pure parse-time helpers (string →
|
|
40
|
+
bytes, before anything is on the wire) may validate, since there's no hot loop and no server to fall
|
|
41
|
+
back on.
|
|
42
|
+
|
|
43
|
+
Otherwise, prefer letting the ClickHouse server reject bad bytes server-side over guarding client-side:
|
|
44
|
+
it already validates, and duplicating that on the encode path costs throughput for no real safety.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Changelog — `@clickhouse/rowbinary`
|
|
2
|
+
|
|
3
|
+
> This file tracks the standalone `@clickhouse/rowbinary` package (the RowBinary
|
|
4
|
+
> parser library and agent skill). Entries relevant to it (through
|
|
5
|
+
> `@clickhouse/client` 1.23.0) were previously recorded in the now-frozen
|
|
6
|
+
> repository-wide [`CHANGELOG.md`](../../CHANGELOG.md).
|
|
7
|
+
|
|
8
|
+
# 0.2.0
|
|
9
|
+
|
|
10
|
+
## New features
|
|
11
|
+
|
|
12
|
+
- Added the RowBinary **writer** — the encode mirror of the reader: type-specific `writeX(sink, value)` building blocks and combinators that compose with no per-element closures, exported from `@clickhouse/rowbinary/writer` (or the per-type modules). ([#911])
|
|
13
|
+
|
|
14
|
+
`writeRows(writeRow)` drives an `Iterable<T>` of rows into a plain `RowBinary` payload. Note its shape: it is a **streaming generator**, not a one-shot `Writer<readonly T[]>`. It writes into a fixed-size buffer (`bufferSize`, default 64 KiB), yields each batch of whole rows when the buffer fills — rewinding so a half-written row never leaks — and starts a fresh buffer for the rest, so a result larger than the buffer (or an unbounded row source) streams out chunk by chunk. An oversized row grows the buffer (doubling) rather than failing, and per-buffer fill is published on the `@clickhouse/rowbinary:writeRows.flush` `node:diagnostics_channel` for buffer-utilization metrics. ([#915])
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import {
|
|
18
|
+
writeRows,
|
|
19
|
+
writeTupleNamed,
|
|
20
|
+
writeUInt64,
|
|
21
|
+
writeString,
|
|
22
|
+
} from "@clickhouse/rowbinary/writer";
|
|
23
|
+
|
|
24
|
+
const writeRow = writeTupleNamed({ id: writeUInt64, name: writeString });
|
|
25
|
+
for (const chunk of writeRows(writeRow)(rows, 64 * 1024)) send(chunk);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Writer edge-case hardening: `writeDate`/`writeDate32`/`writeDateTime` floor to the calendar day / whole second instead of rounding (so a non-midnight `Date` or sub-second `DateTime` no longer rounds up); `parseIPv6` rejects malformed hex groups instead of silently encoding `0`; and `writeGeometry` validates the discriminant before writing its byte, so an out-of-range value can't leave a partial payload. ([#916])
|
|
29
|
+
|
|
30
|
+
[#911]: https://github.com/ClickHouse/clickhouse-js/pull/911
|
|
31
|
+
[#915]: https://github.com/ClickHouse/clickhouse-js/pull/915
|
|
32
|
+
[#916]: https://github.com/ClickHouse/clickhouse-js/pull/916
|
|
33
|
+
|
|
34
|
+
# 0.1.2
|
|
35
|
+
|
|
36
|
+
## Improvements
|
|
37
|
+
|
|
38
|
+
- Bumped the bundled `@clickhouse/datatype-parser` dependency to `0.1.2`. ([#895])
|
|
39
|
+
- Patch release. ([#903])
|
|
40
|
+
|
|
41
|
+
# 0.1.1
|
|
42
|
+
|
|
43
|
+
## New features
|
|
44
|
+
|
|
45
|
+
- Initial release of `@clickhouse/rowbinary`: a RowBinary reader library (and the companion agent skill) shipping 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 same library is also bundled into `@clickhouse/client` (registered in `agents.skills`). Requires Node.js `>=20`. A matching RowBinary writer is planned. ([#864])
|
|
46
|
+
|
|
47
|
+
[#864]: https://github.com/ClickHouse/clickhouse-js/pull/864
|
|
48
|
+
[#895]: https://github.com/ClickHouse/clickhouse-js/pull/895
|
|
49
|
+
[#903]: https://github.com/ClickHouse/clickhouse-js/pull/903
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# RowBinary reader examples
|
|
2
|
+
|
|
3
|
+
Six end-to-end examples. Each `src/examples/*.ts` exports TWO readers for the
|
|
4
|
+
same row — `readXRow` (built from the generic combinator API; easiest to read)
|
|
5
|
+
and `readXRowFast` (the optimized, monomorphized form: leaf reads inlined,
|
|
6
|
+
combinators flattened to straight-line loops, `advance()` coalesced over
|
|
7
|
+
fixed-width runs — still streaming-safe). The matching `tests/X.example.test.ts`
|
|
8
|
+
runs the full create → populate → read-back round trip against a live ClickHouse
|
|
9
|
+
server (verified, not illustrative), and `tests/X.bench.ts` decodes a large
|
|
10
|
+
`numbers()`-generated buffer with both readers (equivalence-checked before
|
|
11
|
+
timing) to measure the speedup.
|
|
12
|
+
|
|
13
|
+
To use one: find the example whose column types match your result, open its
|
|
14
|
+
reader, and adapt it. `readRows(readXRow)` drives a row reader over a whole
|
|
15
|
+
result; `streamRowBatches(chunks, readXRow)` drives it over a chunked HTTP stream.
|
|
16
|
+
|
|
17
|
+
| Example | SQL schema (the trigger) | Speedup | Reader · Test |
|
|
18
|
+
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| **orders** | `id UInt8, uid UUID, price Decimal64(2), status Enum8(...)` | **~3.4x** | [`src/examples/orders.ts`](src/examples/orders.ts) · [`tests/orders.example.test.ts`](tests/orders.example.test.ts) |
|
|
20
|
+
| **carts** | `cart_id UInt32, items Array(Tuple(sku String, qty UInt16)), discounts Array(Nullable(Int32))` | **~2.0x** | [`src/examples/carts.ts`](src/examples/carts.ts) · [`tests/carts.example.test.ts`](tests/carts.example.test.ts) |
|
|
21
|
+
| **telemetry** | `host String, tags Map(String,String), cpu Array(Float64), region Nullable(String), window Tuple(start UInt32, count UInt16)` | **~1.4x** | [`src/examples/telemetry.ts`](src/examples/telemetry.ts) · [`tests/telemetry.example.test.ts`](tests/telemetry.example.test.ts) |
|
|
22
|
+
| **observability** | `id UInt64, ts DateTime64(3), level Enum8, trace_id UUID, payload Variant(String,Int64,Float64), tags Map(LowCardinality(String),String), metrics Array(Tuple(LowCardinality(String),Float64)), attrs Array(Nullable(Int64))` | **~1.4x** | [`src/examples/observability.ts`](src/examples/observability.ts) · [`tests/observability.example.test.ts`](tests/observability.example.test.ts) |
|
|
23
|
+
| **profiles** | `id UInt32, tags Array(String), score Nullable(Int32)` | **~1.3x** | [`src/examples/profiles.ts`](src/examples/profiles.ts) · [`tests/profiles.example.test.ts`](tests/profiles.example.test.ts) |
|
|
24
|
+
| **events** | `id UInt64, name String, ts DateTime('UTC')` | **~1.05x — on par** | [`src/examples/events.ts`](src/examples/events.ts) · [`tests/events.example.test.ts`](tests/events.example.test.ts) |
|
|
25
|
+
|
|
26
|
+
Speedups: Node 24 / V8, decoding a 20k-row buffer — read the ratio, not the
|
|
27
|
+
absolute hz, and run `npm run bench` for your own numbers. Two independent levers
|
|
28
|
+
drive them: **composite monomorphization** (removes per-row combinator closures —
|
|
29
|
+
`carts` / `telemetry` / `observability`) and **per-row formatting** (`orders` is
|
|
30
|
+
all-scalar yet the biggest win, almost entirely from the `formatUUIDTable` swap).
|
|
31
|
+
A flat scalar row with no hot formatter (`events`) is within noise, so prefer the
|
|
32
|
+
clearer API reader there. When in doubt, benchmark — the `*.bench.ts` files are
|
|
33
|
+
the template.
|
|
34
|
+
|
|
35
|
+
The readers live under `src/examples/` and are excluded from the published build
|
|
36
|
+
(`tsconfig.build.json`): reference material and test fixtures, type-checked by the
|
|
37
|
+
base `tsconfig.json` and run by the suite, not part of the package's public API.
|
|
38
|
+
|
|
39
|
+
## Columnar decode (struct-of-arrays) — the ~4x numeric path
|
|
40
|
+
|
|
41
|
+
The examples above produce one object per row (array-of-structs). For a
|
|
42
|
+
**numeric, fixed-width result the consumer reads column-wise** (aggregate / scan
|
|
43
|
+
/ filter / plot, or hand off to a Worker / WASM kernel), decode the same
|
|
44
|
+
row-major bytes directly into **one typed array per column** in the same single
|
|
45
|
+
pass — no per-row object, no `Date`, no number boxing. That removes the
|
|
46
|
+
allocation that dominates a numeric decode for a **measured ~4.2x**.
|
|
47
|
+
|
|
48
|
+
See example: [`decodeIotColumnar`](src/examples/iot.ts).
|