@clickhouse/client-common 0.3.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +12 -0
- package/dist/client.d.ts +15 -65
- package/dist/client.js +25 -52
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +159 -0
- package/dist/config.js +292 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +9 -5
- package/dist/data_formatter/format_query_params.js.map +1 -1
- package/dist/data_formatter/format_query_settings.js.map +1 -1
- package/dist/data_formatter/formatter.d.ts +26 -9
- package/dist/data_formatter/formatter.js +7 -27
- package/dist/data_formatter/formatter.js.map +1 -1
- package/dist/error/parse_error.js.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/logger.js +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/result.d.ts +47 -8
- package/dist/settings.d.ts +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/ts_utils.d.ts +4 -0
- package/dist/ts_utils.js +3 -0
- package/dist/ts_utils.js.map +1 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/url.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/utils/permutations.d.ts +0 -1
- package/dist/utils/permutations.js +0 -12
- package/dist/utils/permutations.js.map +0 -1
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,21 @@
|
|
|
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
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=ClickHouse_clickhouse-js&metric=alert_status">
|
|
20
|
+
|
|
21
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=ClickHouse_clickhouse-js&metric=coverage">
|
|
10
22
|
</p>
|
|
11
23
|
|
|
12
24
|
## About
|
package/dist/client.d.ts
CHANGED
|
@@ -1,68 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseClickHouseClientConfigOptions, ClickHouseSettings, ConnExecResult, IsSame, WithClickHouseSummary } from '@clickhouse/client-common';
|
|
2
2
|
import { type DataFormat } from '@clickhouse/client-common';
|
|
3
3
|
import type { InputJSON, InputJSONObjectEachRow } from './clickhouse_types';
|
|
4
|
+
import type { ImplementationDetails } from './config';
|
|
4
5
|
import type { ConnPingResult } from './connection';
|
|
5
6
|
import type { BaseResultSet } from './result';
|
|
6
|
-
export type MakeConnection<Stream> = (params: ConnectionParams) => Connection<Stream>;
|
|
7
|
-
export type MakeResultSet<Stream> = (stream: Stream, format: DataFormat, session_id: string) => BaseResultSet<Stream>;
|
|
8
|
-
export interface ValuesEncoder<Stream> {
|
|
9
|
-
validateInsertValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): void;
|
|
10
|
-
/**
|
|
11
|
-
* A function encodes an array or a stream of JSON objects to a format compatible with ClickHouse.
|
|
12
|
-
* If values are provided as an array of JSON objects, the function encodes it in place.
|
|
13
|
-
* If values are provided as a stream of JSON objects, the function sets up the encoding of each chunk.
|
|
14
|
-
* If values are provided as a raw non-object stream, the function does nothing.
|
|
15
|
-
*
|
|
16
|
-
* @param values a set of values to send to ClickHouse.
|
|
17
|
-
* @param format a format to encode value to.
|
|
18
|
-
*/
|
|
19
|
-
encodeValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): string | Stream;
|
|
20
|
-
}
|
|
21
|
-
export type CloseStream<Stream> = (stream: Stream) => Promise<void>;
|
|
22
|
-
export interface ClickHouseClientConfigOptions<Stream> {
|
|
23
|
-
impl: {
|
|
24
|
-
make_connection: MakeConnection<Stream>;
|
|
25
|
-
make_result_set: MakeResultSet<Stream>;
|
|
26
|
-
values_encoder: ValuesEncoder<Stream>;
|
|
27
|
-
close_stream: CloseStream<Stream>;
|
|
28
|
-
};
|
|
29
|
-
/** A ClickHouse instance URL. Default value: `http://localhost:8123`. */
|
|
30
|
-
host?: string;
|
|
31
|
-
/** The request timeout in milliseconds. Default value: `30_000`. */
|
|
32
|
-
request_timeout?: number;
|
|
33
|
-
/** Maximum number of sockets to allow per host. Default value: `10`. */
|
|
34
|
-
max_open_connections?: number;
|
|
35
|
-
compression?: {
|
|
36
|
-
/** `response: true` instructs ClickHouse server to respond with
|
|
37
|
-
* compressed response body. Default: true. */
|
|
38
|
-
response?: boolean;
|
|
39
|
-
/** `request: true` enabled compression on the client request body.
|
|
40
|
-
* Default: false. */
|
|
41
|
-
request?: boolean;
|
|
42
|
-
};
|
|
43
|
-
/** The name of the user on whose behalf requests are made.
|
|
44
|
-
* Default: 'default'. */
|
|
45
|
-
username?: string;
|
|
46
|
-
/** The user password. Default: ''. */
|
|
47
|
-
password?: string;
|
|
48
|
-
/** The name of the application using the JS client.
|
|
49
|
-
* Default: empty. */
|
|
50
|
-
application?: string;
|
|
51
|
-
/** Database name to use. Default value: `default`. */
|
|
52
|
-
database?: string;
|
|
53
|
-
/** ClickHouse settings to apply to all requests. Default value: {} */
|
|
54
|
-
clickhouse_settings?: ClickHouseSettings;
|
|
55
|
-
log?: {
|
|
56
|
-
/** A class to instantiate a custom logger implementation.
|
|
57
|
-
* Default: {@link DefaultLogger} */
|
|
58
|
-
LoggerClass?: new () => Logger;
|
|
59
|
-
/** Default: OFF */
|
|
60
|
-
level?: ClickHouseLogLevel;
|
|
61
|
-
};
|
|
62
|
-
session_id?: string;
|
|
63
|
-
additional_headers?: Record<string, string>;
|
|
64
|
-
}
|
|
65
|
-
export type BaseClickHouseClientConfigOptions<Stream> = Omit<ClickHouseClientConfigOptions<Stream>, 'impl'>;
|
|
66
7
|
export interface BaseQueryParams {
|
|
67
8
|
/** ClickHouse's settings that can be applied on query level. */
|
|
68
9
|
clickhouse_settings?: ClickHouseSettings;
|
|
@@ -81,6 +22,14 @@ export interface QueryParams extends BaseQueryParams {
|
|
|
81
22
|
/** Format of the resulting dataset. */
|
|
82
23
|
format?: DataFormat;
|
|
83
24
|
}
|
|
25
|
+
/** Same parameters as {@link QueryParams}, but with `format` field as a type */
|
|
26
|
+
export type QueryParamsWithFormat<Format extends DataFormat> = Omit<QueryParams, 'format'> & {
|
|
27
|
+
format?: Format;
|
|
28
|
+
};
|
|
29
|
+
/** If the Format is not a literal type, fall back to the default behavior of the ResultSet,
|
|
30
|
+
* allowing to call all methods with all data shapes variants,
|
|
31
|
+
* and avoiding generated types that include all possible DataFormat literal values. */
|
|
32
|
+
export type QueryResult<Stream, Format extends DataFormat> = IsSame<Format, DataFormat> extends true ? BaseResultSet<Stream, unknown> : BaseResultSet<Stream, Format>;
|
|
84
33
|
export interface ExecParams extends BaseQueryParams {
|
|
85
34
|
/** Statement to execute. */
|
|
86
35
|
query: string;
|
|
@@ -133,21 +82,21 @@ export interface InsertParams<Stream = unknown, T = unknown> extends BaseQueryPa
|
|
|
133
82
|
columns?: NonEmptyArray<string> | InsertColumnsExcept;
|
|
134
83
|
}
|
|
135
84
|
export declare class ClickHouseClient<Stream = unknown> {
|
|
136
|
-
private readonly
|
|
85
|
+
private readonly clientClickHouseSettings;
|
|
137
86
|
private readonly connection;
|
|
138
87
|
private readonly makeResultSet;
|
|
139
88
|
private readonly valuesEncoder;
|
|
140
89
|
private readonly closeStream;
|
|
141
90
|
private readonly sessionId?;
|
|
142
|
-
constructor(config:
|
|
143
|
-
private getQueryParams;
|
|
91
|
+
constructor(config: BaseClickHouseClientConfigOptions & ImplementationDetails<Stream>);
|
|
144
92
|
/**
|
|
145
93
|
* Used for most statements that can have a response, such as SELECT.
|
|
146
94
|
* FORMAT clause should be specified separately via {@link QueryParams.format} (default is JSON)
|
|
147
95
|
* Consider using {@link ClickHouseClient.insert} for data insertion,
|
|
148
96
|
* or {@link ClickHouseClient.command} for DDLs.
|
|
97
|
+
* Returns an implementation of {@link BaseResultSet}.
|
|
149
98
|
*/
|
|
150
|
-
query(params:
|
|
99
|
+
query<Format extends DataFormat = 'JSON'>(params: QueryParamsWithFormat<Format>): Promise<QueryResult<Stream, Format>>;
|
|
151
100
|
/**
|
|
152
101
|
* It should be used for statements that do not have any output,
|
|
153
102
|
* when the format clause is not applicable, or when you are not interested in the response at all.
|
|
@@ -181,5 +130,6 @@ export declare class ClickHouseClient<Stream = unknown> {
|
|
|
181
130
|
* for example, during the graceful shutdown phase.
|
|
182
131
|
*/
|
|
183
132
|
close(): Promise<void>;
|
|
133
|
+
private withClientQueryParams;
|
|
184
134
|
}
|
|
185
135
|
export {};
|
package/dist/client.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClickHouseClient = void 0;
|
|
4
4
|
const client_common_1 = require("@clickhouse/client-common");
|
|
5
|
+
const config_1 = require("./config");
|
|
5
6
|
class ClickHouseClient {
|
|
6
7
|
constructor(config) {
|
|
7
|
-
Object.defineProperty(this, "
|
|
8
|
+
Object.defineProperty(this, "clientClickHouseSettings", {
|
|
8
9
|
enumerable: true,
|
|
9
10
|
configurable: true,
|
|
10
11
|
writable: true,
|
|
@@ -40,38 +41,31 @@ class ClickHouseClient {
|
|
|
40
41
|
writable: true,
|
|
41
42
|
value: void 0
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
+
const logger = config?.log?.LoggerClass
|
|
45
|
+
? new config.log.LoggerClass()
|
|
46
|
+
: new client_common_1.DefaultLogger();
|
|
47
|
+
const configWithURL = (0, config_1.prepareConfigWithURL)(config, logger, config.impl.handle_specific_url_params ?? null);
|
|
48
|
+
const connectionParams = (0, config_1.getConnectionParams)(configWithURL, logger);
|
|
49
|
+
this.clientClickHouseSettings = connectionParams.clickhouse_settings;
|
|
44
50
|
this.sessionId = config.session_id;
|
|
45
|
-
|
|
46
|
-
this.connection = config.impl.make_connection(this.connectionParams);
|
|
51
|
+
this.connection = config.impl.make_connection(configWithURL, connectionParams);
|
|
47
52
|
this.makeResultSet = config.impl.make_result_set;
|
|
48
53
|
this.valuesEncoder = config.impl.values_encoder;
|
|
49
54
|
this.closeStream = config.impl.close_stream;
|
|
50
55
|
}
|
|
51
|
-
getQueryParams(params) {
|
|
52
|
-
return {
|
|
53
|
-
clickhouse_settings: {
|
|
54
|
-
...this.connectionParams.clickhouse_settings,
|
|
55
|
-
...params.clickhouse_settings,
|
|
56
|
-
},
|
|
57
|
-
query_params: params.query_params,
|
|
58
|
-
abort_signal: params.abort_signal,
|
|
59
|
-
query_id: params.query_id,
|
|
60
|
-
session_id: this.sessionId,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
56
|
/**
|
|
64
57
|
* Used for most statements that can have a response, such as SELECT.
|
|
65
58
|
* FORMAT clause should be specified separately via {@link QueryParams.format} (default is JSON)
|
|
66
59
|
* Consider using {@link ClickHouseClient.insert} for data insertion,
|
|
67
60
|
* or {@link ClickHouseClient.command} for DDLs.
|
|
61
|
+
* Returns an implementation of {@link BaseResultSet}.
|
|
68
62
|
*/
|
|
69
63
|
async query(params) {
|
|
70
64
|
const format = params.format ?? 'JSON';
|
|
71
65
|
const query = formatQuery(params.query, format);
|
|
72
66
|
const { stream, query_id } = await this.connection.query({
|
|
73
67
|
query,
|
|
74
|
-
...this.
|
|
68
|
+
...this.withClientQueryParams(params),
|
|
75
69
|
});
|
|
76
70
|
return this.makeResultSet(stream, format, query_id);
|
|
77
71
|
}
|
|
@@ -96,7 +90,7 @@ class ClickHouseClient {
|
|
|
96
90
|
const query = removeTrailingSemi(params.query.trim());
|
|
97
91
|
return await this.connection.exec({
|
|
98
92
|
query,
|
|
99
|
-
...this.
|
|
93
|
+
...this.withClientQueryParams(params),
|
|
100
94
|
});
|
|
101
95
|
}
|
|
102
96
|
/**
|
|
@@ -116,7 +110,7 @@ class ClickHouseClient {
|
|
|
116
110
|
const result = await this.connection.insert({
|
|
117
111
|
query,
|
|
118
112
|
values: this.valuesEncoder.encodeValues(params.values, format),
|
|
119
|
-
...this.
|
|
113
|
+
...this.withClientQueryParams(params),
|
|
120
114
|
});
|
|
121
115
|
return { ...result, executed: true };
|
|
122
116
|
}
|
|
@@ -135,6 +129,18 @@ class ClickHouseClient {
|
|
|
135
129
|
async close() {
|
|
136
130
|
return await this.connection.close();
|
|
137
131
|
}
|
|
132
|
+
withClientQueryParams(params) {
|
|
133
|
+
return {
|
|
134
|
+
clickhouse_settings: {
|
|
135
|
+
...this.clientClickHouseSettings,
|
|
136
|
+
...params.clickhouse_settings,
|
|
137
|
+
},
|
|
138
|
+
query_params: params.query_params,
|
|
139
|
+
abort_signal: params.abort_signal,
|
|
140
|
+
query_id: params.query_id,
|
|
141
|
+
session_id: this.sessionId,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
138
144
|
}
|
|
139
145
|
exports.ClickHouseClient = ClickHouseClient;
|
|
140
146
|
function formatQuery(query, format) {
|
|
@@ -155,39 +161,6 @@ function removeTrailingSemi(query) {
|
|
|
155
161
|
}
|
|
156
162
|
return query;
|
|
157
163
|
}
|
|
158
|
-
function validateConnectionParams({ url }) {
|
|
159
|
-
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
160
|
-
throw new Error(`Only http(s) protocol is supported, but given: [${url.protocol}]`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
function createUrl(host) {
|
|
164
|
-
try {
|
|
165
|
-
return new URL(host);
|
|
166
|
-
}
|
|
167
|
-
catch (err) {
|
|
168
|
-
throw new Error('Configuration parameter "host" contains malformed url.');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function getConnectionParams(config) {
|
|
172
|
-
return {
|
|
173
|
-
application_id: config.application,
|
|
174
|
-
url: createUrl(config.host ?? 'http://localhost:8123'),
|
|
175
|
-
request_timeout: config.request_timeout ?? 30000,
|
|
176
|
-
max_open_connections: config.max_open_connections ?? 10,
|
|
177
|
-
compression: {
|
|
178
|
-
decompress_response: config.compression?.response ?? true,
|
|
179
|
-
compress_request: config.compression?.request ?? false,
|
|
180
|
-
},
|
|
181
|
-
username: config.username ?? 'default',
|
|
182
|
-
password: config.password ?? '',
|
|
183
|
-
database: config.database ?? 'default',
|
|
184
|
-
clickhouse_settings: config.clickhouse_settings ?? {},
|
|
185
|
-
log_writer: new client_common_1.LogWriter(config?.log?.LoggerClass
|
|
186
|
-
? new config.log.LoggerClass()
|
|
187
|
-
: new client_common_1.DefaultLogger(), 'Connection', config.log?.level),
|
|
188
|
-
additional_headers: config.additional_headers,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
164
|
function isInsertColumnsExcept(obj) {
|
|
192
165
|
return (obj !== undefined &&
|
|
193
166
|
obj !== null &&
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../packages/client-common/src/client.ts"],"names":[],"mappings":";;;AASA,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../packages/client-common/src/client.ts"],"names":[],"mappings":";;;AASA,6DAA0E;AAO1E,qCAAoE;AAoGpE,MAAa,gBAAgB;IAQ3B,YACE,MAAyE;QAR1D;;;;;WAA4C;QAC5C;;;;;WAA8B;QAC9B;;;;;WAAoC;QACpC;;;;;WAAoC;QACpC;;;;;WAAgC;QAChC;;;;;WAAkB;QAKjC,MAAM,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,WAAW;YACrC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE;YAC9B,CAAC,CAAC,IAAI,6BAAa,EAAE,CAAA;QACvB,MAAM,aAAa,GAAG,IAAA,6BAAoB,EACxC,MAAM,EACN,MAAM,EACN,MAAM,CAAC,IAAI,CAAC,0BAA0B,IAAI,IAAI,CAC/C,CAAA;QACD,MAAM,gBAAgB,GAAG,IAAA,4BAAmB,EAAC,aAAa,EAAE,MAAM,CAAC,CAAA;QACnE,IAAI,CAAC,wBAAwB,GAAG,gBAAgB,CAAC,mBAAmB,CAAA;QACpE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAA;QAClC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAC3C,aAAa,EACb,gBAAgB,CACjB,CAAA;QACD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAA;QAChD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAA;QAC/C,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAA;IAC7C,CAAC;IAED;;;;;;OAMG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GAAG,CAAC,EAChC,CAAC;YACD,WAAW,GAAG,eAAe,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAA;QACnE,CAAC;IACH,CAAC;IACD,OAAO,eAAe,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,WAAW,WAAW,MAAM,EAAE,CAAA;AAC5E,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { InsertValues } from './client';
|
|
2
|
+
import type { Connection, ConnectionParams } from './connection';
|
|
3
|
+
import type { DataFormat } from './data_formatter';
|
|
4
|
+
import type { Logger } from './logger';
|
|
5
|
+
import { ClickHouseLogLevel } from './logger';
|
|
6
|
+
import type { BaseResultSet } from './result';
|
|
7
|
+
import type { ClickHouseSettings } from './settings';
|
|
8
|
+
export interface BaseClickHouseClientConfigOptions {
|
|
9
|
+
/** @deprecated since version 1.0.0. Use {@link url} instead. <br/>
|
|
10
|
+
* A ClickHouse instance URL.
|
|
11
|
+
* @default http://localhost:8123 */
|
|
12
|
+
host?: string;
|
|
13
|
+
/** A ClickHouse instance URL.
|
|
14
|
+
* @default http://localhost:8123 */
|
|
15
|
+
url?: string | URL;
|
|
16
|
+
/** An optional pathname to add to the ClickHouse URL after it is parsed by the client.
|
|
17
|
+
* For example, if you use a proxy, and your ClickHouse instance can be accessed as http://proxy:8123/clickhouse_server,
|
|
18
|
+
* specify `clickhouse_server` here (with or without a leading slash);
|
|
19
|
+
* otherwise, if provided directly in the {@link url}, it will be considered as the `database` option.<br/>
|
|
20
|
+
* Multiple segments are supported, e.g. `/my_proxy/db`.
|
|
21
|
+
* @default empty string */
|
|
22
|
+
pathname?: string;
|
|
23
|
+
/** The request timeout in milliseconds.
|
|
24
|
+
* @default 30_000 */
|
|
25
|
+
request_timeout?: number;
|
|
26
|
+
/** Maximum number of sockets to allow per host.
|
|
27
|
+
* @default 10 */
|
|
28
|
+
max_open_connections?: number;
|
|
29
|
+
/** Request and response compression settings. */
|
|
30
|
+
compression?: {
|
|
31
|
+
/** `response: true` instructs ClickHouse server to respond with compressed response body. <br/>
|
|
32
|
+
* This will add `Accept-Encoding: gzip` header in the request and `enable_http_compression=1` ClickHouse HTTP setting.
|
|
33
|
+
* <p><b>Warning</b>: Response compression can't be enabled for a user with readonly=1, as ClickHouse will not allow settings modifications for such user.</p>
|
|
34
|
+
* @default false */
|
|
35
|
+
response?: boolean;
|
|
36
|
+
/** `request: true` enabled compression on the client request body.
|
|
37
|
+
* @default false */
|
|
38
|
+
request?: boolean;
|
|
39
|
+
};
|
|
40
|
+
/** The name of the user on whose behalf requests are made.
|
|
41
|
+
* @default default */
|
|
42
|
+
username?: string;
|
|
43
|
+
/** The user password.
|
|
44
|
+
* @default empty string */
|
|
45
|
+
password?: string;
|
|
46
|
+
/** The name of the application using the JS client.
|
|
47
|
+
* @default empty string */
|
|
48
|
+
application?: string;
|
|
49
|
+
/** Database name to use.
|
|
50
|
+
* @default default */
|
|
51
|
+
database?: string;
|
|
52
|
+
/** ClickHouse settings to apply to all requests.
|
|
53
|
+
* @default empty object */
|
|
54
|
+
clickhouse_settings?: ClickHouseSettings;
|
|
55
|
+
log?: {
|
|
56
|
+
/** A class to instantiate a custom logger implementation.
|
|
57
|
+
* @default see {@link DefaultLogger} */
|
|
58
|
+
LoggerClass?: new () => Logger;
|
|
59
|
+
/** @default set to {@link ClickHouseLogLevel.OFF} */
|
|
60
|
+
level?: ClickHouseLogLevel;
|
|
61
|
+
};
|
|
62
|
+
/** ClickHouse Session id to attach to the outgoing requests.
|
|
63
|
+
* @default empty string */
|
|
64
|
+
session_id?: string;
|
|
65
|
+
/** @deprecated since version 1.0.0. Use {@link http_headers} instead. <br/>
|
|
66
|
+
* Additional HTTP headers to attach to the outgoing requests.
|
|
67
|
+
* @default empty object */
|
|
68
|
+
additional_headers?: Record<string, string>;
|
|
69
|
+
/** Additional HTTP headers to attach to the outgoing requests.
|
|
70
|
+
* @default empty object */
|
|
71
|
+
http_headers?: Record<string, string>;
|
|
72
|
+
/** HTTP Keep-Alive related settings. */
|
|
73
|
+
keep_alive?: {
|
|
74
|
+
/** Enable or disable HTTP Keep-Alive mechanism.
|
|
75
|
+
* @default true */
|
|
76
|
+
enabled?: boolean;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export type MakeConnection<Stream, Config = BaseClickHouseClientConfigOptionsWithURL> = (config: Config, params: ConnectionParams) => Connection<Stream>;
|
|
80
|
+
export type MakeResultSet<Stream> = <Format extends DataFormat, ResultSet extends BaseResultSet<Stream, Format>>(stream: Stream, format: Format, query_id: string) => ResultSet;
|
|
81
|
+
export interface ValuesEncoder<Stream> {
|
|
82
|
+
validateInsertValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): void;
|
|
83
|
+
/**
|
|
84
|
+
* A function encodes an array or a stream of JSON objects to a format compatible with ClickHouse.
|
|
85
|
+
* If values are provided as an array of JSON objects, the function encodes it in place.
|
|
86
|
+
* If values are provided as a stream of JSON objects, the function sets up the encoding of each chunk.
|
|
87
|
+
* If values are provided as a raw non-object stream, the function does nothing.
|
|
88
|
+
*
|
|
89
|
+
* @param values a set of values to send to ClickHouse.
|
|
90
|
+
* @param format a format to encode value to.
|
|
91
|
+
*/
|
|
92
|
+
encodeValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): string | Stream;
|
|
93
|
+
}
|
|
94
|
+
export type CloseStream<Stream> = (stream: Stream) => Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* An implementation might have extra config parameters that we can parse from the connection URL.
|
|
97
|
+
* These are supposed to be processed after we finish parsing the base configuration.
|
|
98
|
+
* URL params handled in the common package will be deleted from the URL object.
|
|
99
|
+
* This way we ensure that only implementation-specific params are passed there,
|
|
100
|
+
* so we can indicate which URL parameters are unknown by both common and implementation packages.
|
|
101
|
+
*/
|
|
102
|
+
export type HandleImplSpecificURLParams = (config: BaseClickHouseClientConfigOptions, url: URL) => {
|
|
103
|
+
config: BaseClickHouseClientConfigOptions;
|
|
104
|
+
handled_params: Set<string>;
|
|
105
|
+
unknown_params: Set<string>;
|
|
106
|
+
};
|
|
107
|
+
/** Things that may vary between Web/Node.js/etc client implementations. */
|
|
108
|
+
export interface ImplementationDetails<Stream> {
|
|
109
|
+
impl: {
|
|
110
|
+
make_connection: MakeConnection<Stream>;
|
|
111
|
+
make_result_set: MakeResultSet<Stream>;
|
|
112
|
+
values_encoder: ValuesEncoder<Stream>;
|
|
113
|
+
close_stream: CloseStream<Stream>;
|
|
114
|
+
handle_specific_url_params?: HandleImplSpecificURLParams;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export type BaseClickHouseClientConfigOptionsWithURL = Omit<BaseClickHouseClientConfigOptions, 'url'> & {
|
|
118
|
+
url: URL;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Validates and normalizes the provided "base" config.
|
|
122
|
+
* Warns about deprecated configuration parameters usage.
|
|
123
|
+
* Parses the common URL parameters into the configuration parameters (these are the same for all implementations).
|
|
124
|
+
* Parses implementation-specific URL parameters using the handler provided by that implementation.
|
|
125
|
+
* Merges these parameters with the base config and implementation-specific defaults.
|
|
126
|
+
* Enforces certain defaults in case of deprecated keys or readonly mode.
|
|
127
|
+
*/
|
|
128
|
+
export declare function prepareConfigWithURL(baseConfigOptions: BaseClickHouseClientConfigOptions, logger: Logger, handleImplURLParams: HandleImplSpecificURLParams | null): BaseClickHouseClientConfigOptionsWithURL;
|
|
129
|
+
export declare function getConnectionParams(config: BaseClickHouseClientConfigOptionsWithURL, logger: Logger): ConnectionParams;
|
|
130
|
+
/**
|
|
131
|
+
* Merge two versions of the config: base (hardcoded) from the instance creation and the URL parsed one.
|
|
132
|
+
* URL config takes priority and overrides the base config parameters.
|
|
133
|
+
* If a value is overridden, then a warning will be logged (even if the log level is OFF).
|
|
134
|
+
*/
|
|
135
|
+
export declare function mergeConfigs(baseConfig: BaseClickHouseClientConfigOptions, configFromURL: BaseClickHouseClientConfigOptions, logger: Logger): BaseClickHouseClientConfigOptions;
|
|
136
|
+
export declare function createUrl(configURL: string | URL | undefined): URL;
|
|
137
|
+
/**
|
|
138
|
+
* @param url potentially contains auth, database and URL params to parse the configuration from
|
|
139
|
+
* @param handleExtraURLParams some platform-specific URL params might be unknown by the common package;
|
|
140
|
+
* use this function defined in the implementation to handle them. Logs warnings in case of hardcode overrides.
|
|
141
|
+
*/
|
|
142
|
+
export declare function loadConfigOptionsFromURL(url: URL, handleExtraURLParams: HandleImplSpecificURLParams | null): [URL, BaseClickHouseClientConfigOptions];
|
|
143
|
+
export declare function booleanConfigURLValue({ key, value, }: {
|
|
144
|
+
key: string;
|
|
145
|
+
value: string;
|
|
146
|
+
}): boolean;
|
|
147
|
+
export declare function numberConfigURLValue({ key, value, min, max, }: {
|
|
148
|
+
key: string;
|
|
149
|
+
value: string;
|
|
150
|
+
min?: number;
|
|
151
|
+
max?: number;
|
|
152
|
+
}): number;
|
|
153
|
+
export declare function enumConfigURLValue<Enum, Key extends string>({ key, value, enumObject, }: {
|
|
154
|
+
key: string;
|
|
155
|
+
value: string;
|
|
156
|
+
enumObject: {
|
|
157
|
+
[k in Key]: Enum;
|
|
158
|
+
};
|
|
159
|
+
}): Enum;
|