@clickhouse/client 0.3.1 → 0.100.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/LICENSE +2 -2
- package/README.md +14 -0
- package/dist/client.d.ts +11 -26
- package/dist/client.js +11 -53
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +52 -0
- package/dist/config.js +80 -0
- package/dist/config.js.map +1 -0
- package/dist/connection/compression.d.ts +4 -3
- package/dist/connection/compression.js +7 -5
- package/dist/connection/compression.js.map +1 -1
- package/dist/connection/create_connection.d.ts +16 -0
- package/dist/connection/create_connection.js +42 -0
- package/dist/connection/create_connection.js.map +1 -0
- package/dist/connection/index.d.ts +1 -0
- package/dist/connection/index.js +1 -0
- package/dist/connection/index.js.map +1 -1
- package/dist/connection/node_base_connection.d.ts +23 -12
- package/dist/connection/node_base_connection.js +428 -227
- package/dist/connection/node_base_connection.js.map +1 -1
- package/dist/connection/node_custom_agent_connection.d.ts +8 -0
- package/dist/connection/node_custom_agent_connection.js +47 -0
- package/dist/connection/node_custom_agent_connection.js.map +1 -0
- package/dist/connection/node_http_connection.d.ts +1 -5
- package/dist/connection/node_http_connection.js +6 -5
- package/dist/connection/node_http_connection.js.map +1 -1
- package/dist/connection/node_https_connection.d.ts +3 -6
- package/dist/connection/node_https_connection.js +39 -19
- package/dist/connection/node_https_connection.js.map +1 -1
- package/dist/connection/stream.d.ts +3 -2
- package/dist/connection/stream.js +4 -3
- package/dist/connection/stream.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/result_set.d.ts +41 -6
- package/dist/result_set.js +133 -51
- package/dist/result_set.js.map +1 -1
- package/dist/utils/encoder.d.ts +3 -2
- package/dist/utils/encoder.js +16 -3
- package/dist/utils/encoder.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/process.js +1 -2
- package/dist/utils/process.js.map +1 -1
- package/dist/utils/runtime.d.ts +6 -0
- package/dist/utils/runtime.js +65 -0
- package/dist/utils/runtime.js.map +1 -0
- package/dist/utils/stream.d.ts +1 -2
- package/dist/utils/stream.js +23 -9
- package/dist/utils/stream.js.map +1 -1
- package/dist/utils/user_agent.d.ts +4 -0
- package/dist/utils/user_agent.js +7 -31
- package/dist/utils/user_agent.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 -3
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2016-
|
|
1
|
+
Copyright 2016-2024 ClickHouse, Inc.
|
|
2
2
|
|
|
3
3
|
Apache License
|
|
4
4
|
Version 2.0, January 2004
|
|
@@ -188,7 +188,7 @@ Copyright 2016-2023 ClickHouse, Inc.
|
|
|
188
188
|
same "printed page" as the copyright notice for easier
|
|
189
189
|
identification within third-party archives.
|
|
190
190
|
|
|
191
|
-
Copyright 2016-
|
|
191
|
+
Copyright 2016-2024 ClickHouse, Inc.
|
|
192
192
|
|
|
193
193
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
194
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -4,9 +4,23 @@
|
|
|
4
4
|
</p>
|
|
5
5
|
<br/>
|
|
6
6
|
<p align="center">
|
|
7
|
+
<a href="https://www.npmjs.com/package/@clickhouse/client">
|
|
8
|
+
<img alt="NPM Version" src="https://img.shields.io/npm/v/%40clickhouse%2Fclient?color=%233178C6&logo=npm">
|
|
9
|
+
</a>
|
|
10
|
+
|
|
11
|
+
<a href="https://www.npmjs.com/package/@clickhouse/client">
|
|
12
|
+
<img alt="NPM Downloads" src="https://img.shields.io/npm/dw/%40clickhouse%2Fclient?color=%233178C6&logo=npm">
|
|
13
|
+
</a>
|
|
14
|
+
|
|
7
15
|
<a href="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml">
|
|
8
16
|
<img src="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml/badge.svg?branch=main">
|
|
9
17
|
</a>
|
|
18
|
+
|
|
19
|
+
<a href="https://codecov.io/gh/ClickHouse/clickhouse-js">
|
|
20
|
+
<img src="https://codecov.io/gh/ClickHouse/clickhouse-js/graph/badge.svg?token=B832WB00WJ">
|
|
21
|
+
</a>
|
|
22
|
+
|
|
23
|
+
<img src="https://api.scorecard.dev/projects/github.com/ClickHouse/clickhouse-js/badge">
|
|
10
24
|
</p>
|
|
11
25
|
|
|
12
26
|
## About
|
package/dist/client.d.ts
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import type { BaseClickHouseClientConfigOptions, Connection } from '@clickhouse/client-common';
|
|
1
|
+
import type { DataFormat, IsSame, QueryParamsWithFormat } from '@clickhouse/client-common';
|
|
4
2
|
import { ClickHouseClient } from '@clickhouse/client-common';
|
|
5
3
|
import type Stream from 'stream';
|
|
6
|
-
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* Default value: 2500 */
|
|
16
|
-
idle_socket_ttl?: number;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
interface BasicTLSOptions {
|
|
20
|
-
ca_cert: Buffer;
|
|
4
|
+
import type { NodeClickHouseClientConfigOptions } from './config';
|
|
5
|
+
import type { ResultSet } from './result_set';
|
|
6
|
+
/** If the Format is not a literal type, fall back to the default behavior of the ResultSet,
|
|
7
|
+
* allowing to call all methods with all data shapes variants,
|
|
8
|
+
* and avoiding generated types that include all possible DataFormat literal values. */
|
|
9
|
+
export type QueryResult<Format extends DataFormat> = IsSame<Format, DataFormat> extends true ? ResultSet<unknown> : ResultSet<Format>;
|
|
10
|
+
export declare class NodeClickHouseClient extends ClickHouseClient<Stream.Readable> {
|
|
11
|
+
/** See {@link ClickHouseClient.query}. */
|
|
12
|
+
query<Format extends DataFormat = 'JSON'>(params: QueryParamsWithFormat<Format>): Promise<QueryResult<Format>>;
|
|
21
13
|
}
|
|
22
|
-
|
|
23
|
-
ca_cert: Buffer;
|
|
24
|
-
cert: Buffer;
|
|
25
|
-
key: Buffer;
|
|
26
|
-
}
|
|
27
|
-
export declare function createClient(config?: NodeClickHouseClientConfigOptions): ClickHouseClient<Stream.Readable>;
|
|
28
|
-
export declare function createConnection(params: NodeConnectionParams): Connection<Stream.Readable>;
|
|
29
|
-
export {};
|
|
14
|
+
export declare function createClient(config?: NodeClickHouseClientConfigOptions): NodeClickHouseClient;
|
package/dist/client.js
CHANGED
|
@@ -1,62 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.NodeClickHouseClient = void 0;
|
|
4
|
+
exports.createClient = createClient;
|
|
4
5
|
const client_common_1 = require("@clickhouse/client-common");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (config?.tls) {
|
|
11
|
-
if ('cert' in config.tls && 'key' in config.tls) {
|
|
12
|
-
tls = {
|
|
13
|
-
type: 'Mutual',
|
|
14
|
-
...config.tls,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
tls = {
|
|
19
|
-
type: 'Basic',
|
|
20
|
-
...config.tls,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
6
|
+
const config_1 = require("./config");
|
|
7
|
+
class NodeClickHouseClient extends client_common_1.ClickHouseClient {
|
|
8
|
+
/** See {@link ClickHouseClient.query}. */
|
|
9
|
+
query(params) {
|
|
10
|
+
return super.query(params);
|
|
23
11
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
12
|
+
}
|
|
13
|
+
exports.NodeClickHouseClient = NodeClickHouseClient;
|
|
14
|
+
function createClient(config) {
|
|
28
15
|
return new client_common_1.ClickHouseClient({
|
|
29
|
-
impl:
|
|
30
|
-
make_connection: (params) => {
|
|
31
|
-
switch (params.url.protocol) {
|
|
32
|
-
case 'http:':
|
|
33
|
-
return new connection_1.NodeHttpConnection({ ...params, keep_alive });
|
|
34
|
-
case 'https:':
|
|
35
|
-
return new connection_1.NodeHttpsConnection({ ...params, tls, keep_alive });
|
|
36
|
-
default:
|
|
37
|
-
throw new Error('Only HTTP(s) adapters are supported');
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
make_result_set: (stream, format, session_id) => new result_set_1.ResultSet(stream, format, session_id),
|
|
41
|
-
values_encoder: new utils_1.NodeValuesEncoder(),
|
|
42
|
-
close_stream: async (stream) => {
|
|
43
|
-
stream.destroy();
|
|
44
|
-
},
|
|
45
|
-
},
|
|
16
|
+
impl: config_1.NodeConfigImpl,
|
|
46
17
|
...(config || {}),
|
|
47
18
|
});
|
|
48
19
|
}
|
|
49
|
-
exports.createClient = createClient;
|
|
50
|
-
function createConnection(params) {
|
|
51
|
-
// TODO throw ClickHouseClient error
|
|
52
|
-
switch (params.url.protocol) {
|
|
53
|
-
case 'http:':
|
|
54
|
-
return new connection_1.NodeHttpConnection(params);
|
|
55
|
-
case 'https:':
|
|
56
|
-
return new connection_1.NodeHttpsConnection(params);
|
|
57
|
-
default:
|
|
58
|
-
throw new Error('Only HTTP(s) adapters are supported');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.createConnection = createConnection;
|
|
62
20
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AA4BA,oCAOC;AA9BD,6DAA4D;AAG5D,qCAAyC;AAWzC,MAAa,oBAAqB,SAAQ,gCAAiC;IACzE,0CAA0C;IAC1C,KAAK,CACH,MAAqC;QAErC,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAA+B,CAAA;IAC1D,CAAC;CACF;AAPD,oDAOC;AAED,SAAgB,YAAY,CAC1B,MAA0C;IAE1C,OAAO,IAAI,gCAAgB,CAAkB;QAC3C,IAAI,EAAE,uBAAc;QACpB,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;KAClB,CAAyB,CAAA;AAC5B,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ImplementationDetails } from '@clickhouse/client-common';
|
|
2
|
+
import { type BaseClickHouseClientConfigOptions } from '@clickhouse/client-common';
|
|
3
|
+
import type http from 'http';
|
|
4
|
+
import type https from 'node:https';
|
|
5
|
+
import type Stream from 'stream';
|
|
6
|
+
export type NodeClickHouseClientConfigOptions = BaseClickHouseClientConfigOptions & {
|
|
7
|
+
tls?: BasicTLSOptions | MutualTLSOptions;
|
|
8
|
+
/** HTTP Keep-Alive related settings */
|
|
9
|
+
keep_alive?: {
|
|
10
|
+
/** Enable or disable the HTTP Keep-Alive mechanism.
|
|
11
|
+
* @default true */
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
/** For how long keep a particular idle socket alive on the client side (in milliseconds).
|
|
14
|
+
* It is supposed to be a fair bit less that the ClickHouse server KeepAlive timeout,
|
|
15
|
+
* which is by default 3000 ms for pre-23.11 versions. <br/>
|
|
16
|
+
* When set to `0`, the idle socket management feature is disabled.
|
|
17
|
+
* @default 2500 */
|
|
18
|
+
idle_socket_ttl?: number;
|
|
19
|
+
};
|
|
20
|
+
/** Custom HTTP agent to use for the outgoing HTTP(s) requests.
|
|
21
|
+
* If set, {@link BaseClickHouseClientConfigOptions.max_open_connections}, {@link tls} and {@link keep_alive}
|
|
22
|
+
* options have no effect, as it is part of the default underlying agent configuration.
|
|
23
|
+
* @experimental - unstable API; it might be a subject to change in the future;
|
|
24
|
+
* please provide your feedback in the repository.
|
|
25
|
+
* @default undefined */
|
|
26
|
+
http_agent?: http.Agent | https.Agent;
|
|
27
|
+
/** Enable or disable the `Authorization` header with basic auth for the outgoing HTTP(s) requests.
|
|
28
|
+
* @experimental - unstable API; it might be a subject to change in the future;
|
|
29
|
+
* please provide your feedback in the repository.
|
|
30
|
+
* @default true (enabled) */
|
|
31
|
+
set_basic_auth_header?: boolean;
|
|
32
|
+
/** You could try enabling this option if you encounter an error with an unclear or truncated stack trace;
|
|
33
|
+
* as it might happen due to the way the Node.js handles the stack traces in the async code.
|
|
34
|
+
* Note that it might have a noticeable performance impact due to
|
|
35
|
+
* capturing the full stack trace on each client method call.
|
|
36
|
+
* It could also be necessary to override `Error.stackTraceLimit` and increase it
|
|
37
|
+
* to a higher value, or even to `Infinity`, as the default value Node.js is just `10`.
|
|
38
|
+
* @experimental - unstable API; it might be a subject to change in the future;
|
|
39
|
+
* please provide your feedback in the repository.
|
|
40
|
+
* @default false (disabled) */
|
|
41
|
+
capture_enhanced_stack_trace?: boolean;
|
|
42
|
+
};
|
|
43
|
+
interface BasicTLSOptions {
|
|
44
|
+
ca_cert: Buffer;
|
|
45
|
+
}
|
|
46
|
+
interface MutualTLSOptions {
|
|
47
|
+
ca_cert: Buffer;
|
|
48
|
+
cert: Buffer;
|
|
49
|
+
key: Buffer;
|
|
50
|
+
}
|
|
51
|
+
export declare const NodeConfigImpl: Required<ImplementationDetails<Stream.Readable>['impl']>;
|
|
52
|
+
export {};
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeConfigImpl = void 0;
|
|
4
|
+
const client_common_1 = require("@clickhouse/client-common");
|
|
5
|
+
const connection_1 = require("./connection");
|
|
6
|
+
const result_set_1 = require("./result_set");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
exports.NodeConfigImpl = {
|
|
9
|
+
handle_specific_url_params: (config, url) => {
|
|
10
|
+
const nodeConfig = { ...config };
|
|
11
|
+
const unknownParams = new Set();
|
|
12
|
+
const handledParams = new Set();
|
|
13
|
+
const urlSearchParamsKeys = [...url.searchParams.keys()];
|
|
14
|
+
if (urlSearchParamsKeys.length > 0) {
|
|
15
|
+
urlSearchParamsKeys.forEach((key) => {
|
|
16
|
+
const value = url.searchParams.get(key);
|
|
17
|
+
switch (key) {
|
|
18
|
+
case 'keep_alive_idle_socket_ttl':
|
|
19
|
+
if (nodeConfig.keep_alive === undefined) {
|
|
20
|
+
nodeConfig.keep_alive = {};
|
|
21
|
+
}
|
|
22
|
+
nodeConfig.keep_alive.idle_socket_ttl = (0, client_common_1.numberConfigURLValue)({
|
|
23
|
+
key,
|
|
24
|
+
value,
|
|
25
|
+
min: 0,
|
|
26
|
+
});
|
|
27
|
+
handledParams.add(key);
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
unknownParams.add(key);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
config: nodeConfig,
|
|
36
|
+
unknown_params: unknownParams,
|
|
37
|
+
handled_params: handledParams,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
make_connection: (nodeConfig, params) => {
|
|
41
|
+
let tls = undefined;
|
|
42
|
+
if (nodeConfig.tls !== undefined) {
|
|
43
|
+
if ('cert' in nodeConfig.tls && 'key' in nodeConfig.tls) {
|
|
44
|
+
tls = {
|
|
45
|
+
type: 'Mutual',
|
|
46
|
+
...nodeConfig.tls,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
tls = {
|
|
51
|
+
type: 'Basic',
|
|
52
|
+
...nodeConfig.tls,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// normally, it should be already set after processing the config
|
|
57
|
+
const keep_alive = {
|
|
58
|
+
enabled: nodeConfig?.keep_alive?.enabled ?? true,
|
|
59
|
+
idle_socket_ttl: nodeConfig?.keep_alive?.idle_socket_ttl ?? 2500,
|
|
60
|
+
};
|
|
61
|
+
return connection_1.NodeConnectionFactory.create({
|
|
62
|
+
connection_params: params,
|
|
63
|
+
set_basic_auth_header: nodeConfig.set_basic_auth_header ?? true,
|
|
64
|
+
capture_enhanced_stack_trace: nodeConfig.capture_enhanced_stack_trace ?? false,
|
|
65
|
+
http_agent: nodeConfig.http_agent,
|
|
66
|
+
keep_alive,
|
|
67
|
+
tls,
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
values_encoder: (jsonHandling) => new utils_1.NodeValuesEncoder(jsonHandling),
|
|
71
|
+
make_result_set: ((stream, format, query_id, log_error, response_headers, jsonHandling) => result_set_1.ResultSet.instance({
|
|
72
|
+
stream,
|
|
73
|
+
format,
|
|
74
|
+
query_id,
|
|
75
|
+
log_error,
|
|
76
|
+
response_headers,
|
|
77
|
+
jsonHandling,
|
|
78
|
+
})),
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
1
|
+
import type { LogWriter } from '@clickhouse/client-common';
|
|
3
2
|
import type Http from 'http';
|
|
4
3
|
import Stream from 'stream';
|
|
5
|
-
|
|
4
|
+
type DecompressResponseResult = {
|
|
6
5
|
response: Stream.Readable;
|
|
7
6
|
} | {
|
|
8
7
|
error: Error;
|
|
9
8
|
};
|
|
9
|
+
export declare function decompressResponse(response: Http.IncomingMessage, logWriter: LogWriter): DecompressResponseResult;
|
|
10
10
|
export declare function isDecompressionError(result: any): result is {
|
|
11
11
|
error: Error;
|
|
12
12
|
};
|
|
13
|
+
export {};
|
|
@@ -3,16 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.decompressResponse = decompressResponse;
|
|
7
|
+
exports.isDecompressionError = isDecompressionError;
|
|
7
8
|
const stream_1 = __importDefault(require("stream"));
|
|
8
9
|
const zlib_1 = __importDefault(require("zlib"));
|
|
9
|
-
function decompressResponse(response) {
|
|
10
|
+
function decompressResponse(response, logWriter) {
|
|
10
11
|
const encoding = response.headers['content-encoding'];
|
|
11
12
|
if (encoding === 'gzip') {
|
|
12
13
|
return {
|
|
13
14
|
response: stream_1.default.pipeline(response, zlib_1.default.createGunzip(), function pipelineCb(err) {
|
|
14
15
|
if (err) {
|
|
15
|
-
|
|
16
|
+
logWriter.error({
|
|
17
|
+
message: 'An error occurred while decompressing the response',
|
|
18
|
+
err,
|
|
19
|
+
});
|
|
16
20
|
}
|
|
17
21
|
}),
|
|
18
22
|
};
|
|
@@ -24,9 +28,7 @@ function decompressResponse(response) {
|
|
|
24
28
|
}
|
|
25
29
|
return { response };
|
|
26
30
|
}
|
|
27
|
-
exports.decompressResponse = decompressResponse;
|
|
28
31
|
function isDecompressionError(result) {
|
|
29
32
|
return result.error !== undefined;
|
|
30
33
|
}
|
|
31
|
-
exports.isDecompressionError = isDecompressionError;
|
|
32
34
|
//# sourceMappingURL=compression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compression.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"compression.js","sourceRoot":"","sources":["../../src/connection/compression.ts"],"names":[],"mappings":";;;;;AAOA,gDA4BC;AAED,oDAEC;AArCD,oDAA2B;AAC3B,gDAAuB;AAIvB,SAAgB,kBAAkB,CAChC,QAA8B,EAC9B,SAAoB;IAEpB,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAErD,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QACxB,OAAO;YACL,QAAQ,EAAE,gBAAM,CAAC,QAAQ,CACvB,QAAQ,EACR,cAAI,CAAC,YAAY,EAAE,EACnB,SAAS,UAAU,CAAC,GAAG;gBACrB,IAAI,GAAG,EAAE,CAAC;oBACR,SAAS,CAAC,KAAK,CAAC;wBACd,OAAO,EAAE,oDAAoD;wBAC7D,GAAG;qBACJ,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC,CACF;SACF,CAAA;IACH,CAAC;SAAM,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO;YACL,KAAK,EAAE,IAAI,KAAK,CAAC,wBAAwB,QAAQ,EAAE,CAAC;SACrD,CAAA;IACH,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,CAAA;AACrB,CAAC;AAED,SAAgB,oBAAoB,CAAC,MAAW;IAC9C,OAAO,MAAM,CAAC,KAAK,KAAK,SAAS,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ConnectionParams } from '@clickhouse/client-common';
|
|
2
|
+
import type http from 'http';
|
|
3
|
+
import type https from 'node:https';
|
|
4
|
+
import type { NodeBaseConnection, NodeConnectionParams } from './node_base_connection';
|
|
5
|
+
export interface CreateConnectionParams {
|
|
6
|
+
connection_params: ConnectionParams;
|
|
7
|
+
tls: NodeConnectionParams['tls'];
|
|
8
|
+
keep_alive: NodeConnectionParams['keep_alive'];
|
|
9
|
+
http_agent: http.Agent | https.Agent | undefined;
|
|
10
|
+
set_basic_auth_header: boolean;
|
|
11
|
+
capture_enhanced_stack_trace: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** A factory for easier mocking after Node.js 22.18 */
|
|
14
|
+
export declare class NodeConnectionFactory {
|
|
15
|
+
static create({ connection_params, tls, keep_alive, http_agent, set_basic_auth_header, capture_enhanced_stack_trace, }: CreateConnectionParams): NodeBaseConnection;
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeConnectionFactory = void 0;
|
|
4
|
+
const node_custom_agent_connection_1 = require("./node_custom_agent_connection");
|
|
5
|
+
const node_http_connection_1 = require("./node_http_connection");
|
|
6
|
+
const node_https_connection_1 = require("./node_https_connection");
|
|
7
|
+
/** A factory for easier mocking after Node.js 22.18 */
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
9
|
+
class NodeConnectionFactory {
|
|
10
|
+
static create({ connection_params, tls, keep_alive, http_agent, set_basic_auth_header, capture_enhanced_stack_trace, }) {
|
|
11
|
+
if (http_agent !== undefined) {
|
|
12
|
+
return new node_custom_agent_connection_1.NodeCustomAgentConnection({
|
|
13
|
+
...connection_params,
|
|
14
|
+
set_basic_auth_header,
|
|
15
|
+
capture_enhanced_stack_trace,
|
|
16
|
+
keep_alive, // only used to enforce proper KeepAlive headers
|
|
17
|
+
http_agent,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
switch (connection_params.url.protocol) {
|
|
21
|
+
case 'http:':
|
|
22
|
+
return new node_http_connection_1.NodeHttpConnection({
|
|
23
|
+
...connection_params,
|
|
24
|
+
set_basic_auth_header,
|
|
25
|
+
capture_enhanced_stack_trace,
|
|
26
|
+
keep_alive,
|
|
27
|
+
});
|
|
28
|
+
case 'https:':
|
|
29
|
+
return new node_https_connection_1.NodeHttpsConnection({
|
|
30
|
+
...connection_params,
|
|
31
|
+
set_basic_auth_header,
|
|
32
|
+
capture_enhanced_stack_trace,
|
|
33
|
+
keep_alive,
|
|
34
|
+
tls,
|
|
35
|
+
});
|
|
36
|
+
default:
|
|
37
|
+
throw new Error('Only HTTP and HTTPS protocols are supported');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.NodeConnectionFactory = NodeConnectionFactory;
|
|
42
|
+
//# sourceMappingURL=create_connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_connection.js","sourceRoot":"","sources":["../../src/connection/create_connection.ts"],"names":[],"mappings":";;;AAOA,iFAA0E;AAC1E,iEAA2D;AAC3D,mEAA6D;AAW7D,uDAAuD;AACvD,kEAAkE;AAClE,MAAa,qBAAqB;IAChC,MAAM,CAAC,MAAM,CAAC,EACZ,iBAAiB,EACjB,GAAG,EACH,UAAU,EACV,UAAU,EACV,qBAAqB,EACrB,4BAA4B,GACL;QACvB,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,IAAI,wDAAyB,CAAC;gBACnC,GAAG,iBAAiB;gBACpB,qBAAqB;gBACrB,4BAA4B;gBAC5B,UAAU,EAAE,gDAAgD;gBAC5D,UAAU;aACX,CAAC,CAAA;QACJ,CAAC;QACD,QAAQ,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YACvC,KAAK,OAAO;gBACV,OAAO,IAAI,yCAAkB,CAAC;oBAC5B,GAAG,iBAAiB;oBACpB,qBAAqB;oBACrB,4BAA4B;oBAC5B,UAAU;iBACX,CAAC,CAAA;YACJ,KAAK,QAAQ;gBACX,OAAO,IAAI,2CAAmB,CAAC;oBAC7B,GAAG,iBAAiB;oBACpB,qBAAqB;oBACrB,4BAA4B;oBAC5B,UAAU;oBACV,GAAG;iBACJ,CAAC,CAAA;YACJ;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;QAClE,CAAC;IACH,CAAC;CACF;AAtCD,sDAsCC"}
|
package/dist/connection/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./node_base_connection"), exports);
|
|
18
18
|
__exportStar(require("./node_http_connection"), exports);
|
|
19
19
|
__exportStar(require("./node_https_connection"), exports);
|
|
20
|
+
__exportStar(require("./create_connection"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC;AACtC,yDAAsC;AACtC,0DAAuC;AACvC,sDAAmC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
import type { ConnBaseQueryParams, Connection, ConnectionParams, ConnExecResult, ConnInsertParams, ConnInsertResult, ConnPingResult, ConnQueryResult } from '@clickhouse/client-common';
|
|
1
|
+
import type { ConnBaseQueryParams, ConnCommandResult, Connection, ConnectionParams, ConnExecParams, ConnExecResult, ConnInsertParams, ConnInsertResult, ConnPingResult, ConnQueryResult } from '@clickhouse/client-common';
|
|
2
|
+
import { type ConnPingParams } from '@clickhouse/client-common';
|
|
5
3
|
import type Http from 'http';
|
|
4
|
+
import type Https from 'node:https';
|
|
6
5
|
import Stream from 'stream';
|
|
7
6
|
export type NodeConnectionParams = ConnectionParams & {
|
|
8
7
|
tls?: TLSParams;
|
|
8
|
+
http_agent?: Http.Agent | Https.Agent;
|
|
9
|
+
set_basic_auth_header: boolean;
|
|
10
|
+
capture_enhanced_stack_trace: boolean;
|
|
9
11
|
keep_alive: {
|
|
10
12
|
enabled: boolean;
|
|
11
13
|
idle_socket_ttl: number;
|
|
@@ -23,32 +25,41 @@ export type TLSParams = {
|
|
|
23
25
|
export interface RequestParams {
|
|
24
26
|
method: 'GET' | 'POST';
|
|
25
27
|
url: URL;
|
|
28
|
+
headers: Http.OutgoingHttpHeaders;
|
|
26
29
|
body?: string | Stream.Readable;
|
|
27
30
|
abort_signal: AbortSignal;
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
enable_response_compression?: boolean;
|
|
32
|
+
enable_request_compression?: boolean;
|
|
33
|
+
try_decompress_response_stream?: boolean;
|
|
34
|
+
ignore_error_response?: boolean;
|
|
30
35
|
parse_summary?: boolean;
|
|
36
|
+
query: string;
|
|
31
37
|
}
|
|
32
38
|
export declare abstract class NodeBaseConnection implements Connection<Stream.Readable> {
|
|
33
39
|
protected readonly params: NodeConnectionParams;
|
|
34
40
|
protected readonly agent: Http.Agent;
|
|
35
|
-
protected readonly
|
|
41
|
+
protected readonly defaultAuthHeader: string;
|
|
42
|
+
protected readonly defaultHeaders: Http.OutgoingHttpHeaders;
|
|
43
|
+
private readonly jsonHandling;
|
|
36
44
|
private readonly logger;
|
|
37
45
|
private readonly knownSockets;
|
|
38
46
|
private readonly idleSocketTTL;
|
|
39
47
|
protected constructor(params: NodeConnectionParams, agent: Http.Agent);
|
|
40
|
-
|
|
41
|
-
protected abstract createClientRequest(params: RequestParams): Http.ClientRequest;
|
|
42
|
-
private request;
|
|
43
|
-
ping(): Promise<ConnPingResult>;
|
|
48
|
+
ping(params: ConnPingParams): Promise<ConnPingResult>;
|
|
44
49
|
query(params: ConnBaseQueryParams): Promise<ConnQueryResult<Stream.Readable>>;
|
|
45
|
-
exec(params: ConnBaseQueryParams): Promise<ConnExecResult<Stream.Readable>>;
|
|
46
50
|
insert(params: ConnInsertParams<Stream.Readable>): Promise<ConnInsertResult>;
|
|
51
|
+
exec(params: ConnExecParams<Stream.Readable>): Promise<ConnExecResult<Stream.Readable>>;
|
|
52
|
+
command(params: ConnBaseQueryParams): Promise<ConnCommandResult>;
|
|
47
53
|
close(): Promise<void>;
|
|
54
|
+
protected defaultHeadersWithOverride(params?: ConnBaseQueryParams): Http.OutgoingHttpHeaders;
|
|
55
|
+
protected buildRequestHeaders(params?: ConnBaseQueryParams): Http.OutgoingHttpHeaders;
|
|
56
|
+
protected abstract createClientRequest(params: RequestParams): Http.ClientRequest;
|
|
48
57
|
private getQueryId;
|
|
49
58
|
private getAbortController;
|
|
50
59
|
private logResponse;
|
|
51
60
|
private logRequestError;
|
|
52
61
|
private httpRequestErrorMessage;
|
|
53
62
|
private parseSummary;
|
|
63
|
+
private runExec;
|
|
64
|
+
private request;
|
|
54
65
|
}
|