@clickhouse/client-common 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/clickhouse_types.d.ts +59 -1
- package/dist/clickhouse_types.js +27 -0
- package/dist/clickhouse_types.js.map +1 -1
- package/dist/client.d.ts +126 -95
- package/dist/client.js +119 -76
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +173 -0
- package/dist/config.js +309 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +44 -13
- package/dist/connection.js.map +1 -1
- package/dist/data_formatter/format_query_params.d.ts +11 -1
- package/dist/data_formatter/format_query_params.js +74 -13
- package/dist/data_formatter/format_query_params.js.map +1 -1
- package/dist/data_formatter/format_query_settings.js +1 -2
- package/dist/data_formatter/format_query_settings.js.map +1 -1
- package/dist/data_formatter/formatter.d.ts +32 -14
- package/dist/data_formatter/formatter.js +27 -46
- package/dist/data_formatter/formatter.js.map +1 -1
- package/dist/data_formatter/index.d.ts +1 -1
- package/dist/data_formatter/index.js +2 -1
- package/dist/data_formatter/index.js.map +1 -1
- package/dist/error/error.d.ts +20 -0
- package/dist/error/error.js +69 -0
- package/dist/error/error.js.map +1 -0
- package/dist/error/index.d.ts +1 -1
- package/dist/error/index.js +1 -1
- package/dist/error/index.js.map +1 -1
- package/dist/index.d.ts +18 -12
- package/dist/index.js +35 -12
- package/dist/index.js.map +1 -1
- package/dist/logger.js +8 -8
- package/dist/logger.js.map +1 -1
- package/dist/parse/column_types.d.ts +127 -0
- package/dist/parse/column_types.js +540 -0
- package/dist/parse/column_types.js.map +1 -0
- package/dist/parse/index.d.ts +2 -0
- package/dist/parse/index.js +19 -0
- package/dist/parse/index.js.map +1 -0
- package/dist/parse/json_handling.d.ts +19 -0
- package/dist/parse/json_handling.js +8 -0
- package/dist/parse/json_handling.js.map +1 -0
- package/dist/result.d.ts +52 -8
- package/dist/result.js.map +1 -1
- package/dist/settings.d.ts +38 -2
- 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/connection.d.ts +11 -3
- package/dist/utils/connection.js +19 -7
- package/dist/utils/connection.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/sleep.d.ts +1 -0
- package/dist/utils/sleep.js +9 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/stream.d.ts +15 -0
- package/dist/utils/stream.js +50 -0
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/url.d.ts +5 -4
- package/dist/utils/url.js +22 -13
- package/dist/utils/url.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 +6 -2
- package/dist/error/parse_error.d.ts +0 -12
- package/dist/error/parse_error.js +0 -41
- package/dist/error/parse_error.js.map +0 -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/dist/client.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClickHouseClient = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const config_1 = require("./config");
|
|
5
6
|
class ClickHouseClient {
|
|
6
7
|
constructor(config) {
|
|
8
|
+
Object.defineProperty(this, "clientClickHouseSettings", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
7
14
|
Object.defineProperty(this, "connectionParams", {
|
|
8
15
|
enumerable: true,
|
|
9
16
|
configurable: true,
|
|
@@ -28,87 +35,126 @@ class ClickHouseClient {
|
|
|
28
35
|
writable: true,
|
|
29
36
|
value: void 0
|
|
30
37
|
});
|
|
31
|
-
Object.defineProperty(this, "
|
|
38
|
+
Object.defineProperty(this, "sessionId", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: void 0
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(this, "role", {
|
|
32
45
|
enumerable: true,
|
|
33
46
|
configurable: true,
|
|
34
47
|
writable: true,
|
|
35
48
|
value: void 0
|
|
36
49
|
});
|
|
37
|
-
Object.defineProperty(this, "
|
|
50
|
+
Object.defineProperty(this, "logWriter", {
|
|
38
51
|
enumerable: true,
|
|
39
52
|
configurable: true,
|
|
40
53
|
writable: true,
|
|
41
54
|
value: void 0
|
|
42
55
|
});
|
|
43
|
-
this
|
|
56
|
+
Object.defineProperty(this, "jsonHandling", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
const logger = config?.log?.LoggerClass
|
|
63
|
+
? new config.log.LoggerClass()
|
|
64
|
+
: new index_1.DefaultLogger();
|
|
65
|
+
const configWithURL = (0, config_1.prepareConfigWithURL)(config, logger, config.impl.handle_specific_url_params ?? null);
|
|
66
|
+
this.connectionParams = (0, config_1.getConnectionParams)(configWithURL, logger);
|
|
67
|
+
this.logWriter = this.connectionParams.log_writer;
|
|
68
|
+
this.clientClickHouseSettings = this.connectionParams.clickhouse_settings;
|
|
44
69
|
this.sessionId = config.session_id;
|
|
45
|
-
|
|
46
|
-
this.connection = config.impl.make_connection(this.connectionParams);
|
|
70
|
+
this.role = config.role;
|
|
71
|
+
this.connection = config.impl.make_connection(configWithURL, this.connectionParams);
|
|
47
72
|
this.makeResultSet = config.impl.make_result_set;
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
|
|
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,
|
|
73
|
+
this.jsonHandling = {
|
|
74
|
+
...index_1.defaultJSONHandling,
|
|
75
|
+
...config.json,
|
|
61
76
|
};
|
|
77
|
+
this.valuesEncoder = config.impl.values_encoder(this.jsonHandling);
|
|
62
78
|
}
|
|
63
79
|
/**
|
|
64
|
-
* Used for most statements that can have a response, such as SELECT
|
|
65
|
-
* FORMAT clause should be specified separately via {@link QueryParams.format} (default is JSON)
|
|
66
|
-
* Consider using {@link ClickHouseClient.insert} for data insertion,
|
|
67
|
-
*
|
|
80
|
+
* Used for most statements that can have a response, such as `SELECT`.
|
|
81
|
+
* FORMAT clause should be specified separately via {@link QueryParams.format} (default is `JSON`).
|
|
82
|
+
* Consider using {@link ClickHouseClient.insert} for data insertion, or {@link ClickHouseClient.command} for DDLs.
|
|
83
|
+
* Returns an implementation of {@link BaseResultSet}.
|
|
84
|
+
*
|
|
85
|
+
* See {@link DataFormat} for the formats supported by the client.
|
|
68
86
|
*/
|
|
69
87
|
async query(params) {
|
|
70
88
|
const format = params.format ?? 'JSON';
|
|
71
89
|
const query = formatQuery(params.query, format);
|
|
72
|
-
const
|
|
90
|
+
const queryParams = this.withClientQueryParams(params);
|
|
91
|
+
const { stream, query_id, response_headers } = await this.connection.query({
|
|
73
92
|
query,
|
|
74
|
-
...
|
|
93
|
+
...queryParams,
|
|
75
94
|
});
|
|
76
|
-
return this.makeResultSet(stream, format, query_id)
|
|
95
|
+
return this.makeResultSet(stream, format, query_id, (err) => {
|
|
96
|
+
this.logWriter.error({
|
|
97
|
+
err,
|
|
98
|
+
module: 'Client',
|
|
99
|
+
message: 'Error while processing the ResultSet.',
|
|
100
|
+
args: {
|
|
101
|
+
session_id: queryParams.session_id,
|
|
102
|
+
role: queryParams.role,
|
|
103
|
+
query,
|
|
104
|
+
query_id,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}, response_headers, this.jsonHandling);
|
|
77
108
|
}
|
|
78
109
|
/**
|
|
79
110
|
* It should be used for statements that do not have any output,
|
|
80
111
|
* when the format clause is not applicable, or when you are not interested in the response at all.
|
|
81
|
-
*
|
|
112
|
+
* The response stream is destroyed immediately as we do not expect useful information there.
|
|
82
113
|
* Examples of such statements are DDLs or custom inserts.
|
|
83
|
-
*
|
|
114
|
+
*
|
|
115
|
+
* @note if you have a custom query that does not work with {@link ClickHouseClient.query},
|
|
116
|
+
* and you are interested in the response data, consider using {@link ClickHouseClient.exec}.
|
|
84
117
|
*/
|
|
85
118
|
async command(params) {
|
|
86
|
-
const
|
|
87
|
-
await this.
|
|
88
|
-
|
|
119
|
+
const query = removeTrailingSemi(params.query.trim());
|
|
120
|
+
return await this.connection.command({
|
|
121
|
+
query,
|
|
122
|
+
...this.withClientQueryParams(params),
|
|
123
|
+
});
|
|
89
124
|
}
|
|
90
125
|
/**
|
|
91
|
-
* Similar to {@link ClickHouseClient.command}, but for the cases where the output
|
|
92
|
-
* but format clause is not applicable. The caller of this method
|
|
93
|
-
*
|
|
126
|
+
* Similar to {@link ClickHouseClient.command}, but for the cases where the output _is expected_,
|
|
127
|
+
* but format clause is not applicable. The caller of this method _must_ consume the stream,
|
|
128
|
+
* as the underlying socket will not be released until then, and the request will eventually be timed out.
|
|
129
|
+
*
|
|
130
|
+
* @note it is not intended to use this method to execute the DDLs, such as `CREATE TABLE` or similar;
|
|
131
|
+
* use {@link ClickHouseClient.command} instead.
|
|
94
132
|
*/
|
|
95
133
|
async exec(params) {
|
|
96
134
|
const query = removeTrailingSemi(params.query.trim());
|
|
135
|
+
const values = 'values' in params ? params.values : undefined;
|
|
136
|
+
const decompress_response_stream = params.decompress_response_stream ?? true;
|
|
137
|
+
const ignore_error_response = params.ignore_error_response ?? false;
|
|
97
138
|
return await this.connection.exec({
|
|
98
139
|
query,
|
|
99
|
-
|
|
140
|
+
values,
|
|
141
|
+
decompress_response_stream,
|
|
142
|
+
ignore_error_response,
|
|
143
|
+
...this.withClientQueryParams(params),
|
|
100
144
|
});
|
|
101
145
|
}
|
|
102
146
|
/**
|
|
103
147
|
* The primary method for data insertion. It is recommended to avoid arrays in case of large inserts
|
|
104
148
|
* to reduce application memory consumption and consider streaming for most of such use cases.
|
|
105
149
|
* As the insert operation does not provide any output, the response stream is immediately destroyed.
|
|
106
|
-
*
|
|
107
|
-
*
|
|
150
|
+
*
|
|
151
|
+
* @note in case of a custom insert operation (e.g., `INSERT FROM SELECT`),
|
|
152
|
+
* consider using {@link ClickHouseClient.command}, passing the entire raw query there
|
|
153
|
+
* (including the `FORMAT` clause).
|
|
108
154
|
*/
|
|
109
155
|
async insert(params) {
|
|
110
156
|
if (Array.isArray(params.values) && params.values.length === 0) {
|
|
111
|
-
return { executed: false, query_id: '' };
|
|
157
|
+
return { executed: false, query_id: '', response_headers: {} };
|
|
112
158
|
}
|
|
113
159
|
const format = params.format || 'JSONCompactEachRow';
|
|
114
160
|
this.valuesEncoder.validateInsertValues(params.values, format);
|
|
@@ -116,16 +162,21 @@ class ClickHouseClient {
|
|
|
116
162
|
const result = await this.connection.insert({
|
|
117
163
|
query,
|
|
118
164
|
values: this.valuesEncoder.encodeValues(params.values, format),
|
|
119
|
-
...this.
|
|
165
|
+
...this.withClientQueryParams(params),
|
|
120
166
|
});
|
|
121
167
|
return { ...result, executed: true };
|
|
122
168
|
}
|
|
123
169
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
170
|
+
* A health-check request. It does not throw if an error occurs - the error is returned inside the result object.
|
|
171
|
+
*
|
|
172
|
+
* By default, Node.js version uses the built-in `/ping` endpoint, which does not verify credentials.
|
|
173
|
+
* Optionally, it can be switched to a `SELECT` query (see {@link PingParamsWithSelectQuery}).
|
|
174
|
+
* In that case, the server will verify the credentials.
|
|
175
|
+
*
|
|
176
|
+
* **NOTE**: Since the `/ping` endpoint does not support CORS, the Web version always uses a `SELECT` query.
|
|
126
177
|
*/
|
|
127
|
-
async ping() {
|
|
128
|
-
return await this.connection.ping();
|
|
178
|
+
async ping(params) {
|
|
179
|
+
return await this.connection.ping(params ?? { select: false });
|
|
129
180
|
}
|
|
130
181
|
/**
|
|
131
182
|
* Shuts down the underlying connection.
|
|
@@ -135,6 +186,31 @@ class ClickHouseClient {
|
|
|
135
186
|
async close() {
|
|
136
187
|
return await this.connection.close();
|
|
137
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Closes the client connection.
|
|
191
|
+
*
|
|
192
|
+
* Automatically called when using `using` statement in supported environments.
|
|
193
|
+
* @see {@link ClickHouseClient.close}
|
|
194
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using
|
|
195
|
+
*/
|
|
196
|
+
async [Symbol.asyncDispose]() {
|
|
197
|
+
await this.close();
|
|
198
|
+
}
|
|
199
|
+
withClientQueryParams(params) {
|
|
200
|
+
return {
|
|
201
|
+
clickhouse_settings: {
|
|
202
|
+
...this.clientClickHouseSettings,
|
|
203
|
+
...params.clickhouse_settings,
|
|
204
|
+
},
|
|
205
|
+
query_params: params.query_params,
|
|
206
|
+
abort_signal: params.abort_signal,
|
|
207
|
+
query_id: params.query_id,
|
|
208
|
+
session_id: params.session_id ?? this.sessionId,
|
|
209
|
+
role: params.role ?? this.role,
|
|
210
|
+
auth: params.auth,
|
|
211
|
+
http_headers: params.http_headers,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
138
214
|
}
|
|
139
215
|
exports.ClickHouseClient = ClickHouseClient;
|
|
140
216
|
function formatQuery(query, format) {
|
|
@@ -155,39 +231,6 @@ function removeTrailingSemi(query) {
|
|
|
155
231
|
}
|
|
156
232
|
return query;
|
|
157
233
|
}
|
|
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
234
|
function isInsertColumnsExcept(obj) {
|
|
192
235
|
return (obj !== undefined &&
|
|
193
236
|
obj !== null &&
|
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":";;;AAYA,mCAA6E;AAG7E,qCAAoE;AAgKpE,MAAa,gBAAgB;IAW3B,YACE,MAAyE;QAX1D;;;;;WAA4C;QAC5C;;;;;WAAkC;QAClC;;;;;WAA8B;QAC9B;;;;;WAAoC;QACpC;;;;;WAAo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
|
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 JSONHandling } from './parse/json_handling';
|
|
7
|
+
import type { BaseResultSet } from './result';
|
|
8
|
+
import type { ClickHouseSettings } from './settings';
|
|
9
|
+
export interface BaseClickHouseClientConfigOptions {
|
|
10
|
+
/** @deprecated since version 1.0.0. Use {@link url} instead. <br/>
|
|
11
|
+
* A ClickHouse instance URL.
|
|
12
|
+
* @default http://localhost:8123 */
|
|
13
|
+
host?: string;
|
|
14
|
+
/** A ClickHouse instance URL.
|
|
15
|
+
* @default http://localhost:8123 */
|
|
16
|
+
url?: string | URL;
|
|
17
|
+
/** An optional pathname to add to the ClickHouse URL after it is parsed by the client.
|
|
18
|
+
* For example, if you use a proxy, and your ClickHouse instance can be accessed as http://proxy:8123/clickhouse_server,
|
|
19
|
+
* specify `clickhouse_server` here (with or without a leading slash);
|
|
20
|
+
* otherwise, if provided directly in the {@link url}, it will be considered as the `database` option.<br/>
|
|
21
|
+
* Multiple segments are supported, e.g. `/my_proxy/db`.
|
|
22
|
+
* @default empty string */
|
|
23
|
+
pathname?: string;
|
|
24
|
+
/** The request timeout in milliseconds.
|
|
25
|
+
* @default 30_000 */
|
|
26
|
+
request_timeout?: number;
|
|
27
|
+
/** Maximum number of sockets to allow per host.
|
|
28
|
+
* @default 10 */
|
|
29
|
+
max_open_connections?: number;
|
|
30
|
+
/** Request and response compression settings. */
|
|
31
|
+
compression?: {
|
|
32
|
+
/** `response: true` instructs ClickHouse server to respond with compressed response body. <br/>
|
|
33
|
+
* This will add `Accept-Encoding: gzip` header in the request and `enable_http_compression=1` ClickHouse HTTP setting.
|
|
34
|
+
* <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>
|
|
35
|
+
* @default false */
|
|
36
|
+
response?: boolean;
|
|
37
|
+
/** `request: true` enabled compression on the client request body.
|
|
38
|
+
* @default false */
|
|
39
|
+
request?: boolean;
|
|
40
|
+
};
|
|
41
|
+
/** The name of the user on whose behalf requests are made.
|
|
42
|
+
* Should not be set if {@link access_token} is provided.
|
|
43
|
+
* @default default */
|
|
44
|
+
username?: string;
|
|
45
|
+
/** The user password.
|
|
46
|
+
* Should not be set if {@link access_token} is provided.
|
|
47
|
+
* @default empty string */
|
|
48
|
+
password?: string;
|
|
49
|
+
/** A JWT access token to authenticate with ClickHouse.
|
|
50
|
+
* JWT token authentication is supported in ClickHouse Cloud only.
|
|
51
|
+
* Should not be set if {@link username} or {@link password} are provided.
|
|
52
|
+
* @default empty */
|
|
53
|
+
access_token?: string;
|
|
54
|
+
/** The name of the application using the JS client.
|
|
55
|
+
* @default empty string */
|
|
56
|
+
application?: string;
|
|
57
|
+
/** Database name to use.
|
|
58
|
+
* @default default */
|
|
59
|
+
database?: string;
|
|
60
|
+
/** ClickHouse settings to apply to all requests.
|
|
61
|
+
* @default empty object */
|
|
62
|
+
clickhouse_settings?: ClickHouseSettings;
|
|
63
|
+
log?: {
|
|
64
|
+
/** A class to instantiate a custom logger implementation.
|
|
65
|
+
* @default see {@link DefaultLogger} */
|
|
66
|
+
LoggerClass?: new () => Logger;
|
|
67
|
+
/** @default set to {@link ClickHouseLogLevel.OFF} */
|
|
68
|
+
level?: ClickHouseLogLevel;
|
|
69
|
+
};
|
|
70
|
+
/** ClickHouse Session id to attach to the outgoing requests.
|
|
71
|
+
* @default empty string (no session) */
|
|
72
|
+
session_id?: string;
|
|
73
|
+
/** ClickHouse role name(s) to attach to the outgoing requests.
|
|
74
|
+
* @default undefined string (no roles) */
|
|
75
|
+
role?: string | Array<string>;
|
|
76
|
+
/** @deprecated since version 1.0.0. Use {@link http_headers} instead. <br/>
|
|
77
|
+
* Additional HTTP headers to attach to the outgoing requests.
|
|
78
|
+
* @default empty object */
|
|
79
|
+
additional_headers?: Record<string, string>;
|
|
80
|
+
/** Additional HTTP headers to attach to the outgoing requests.
|
|
81
|
+
* @default empty object */
|
|
82
|
+
http_headers?: Record<string, string>;
|
|
83
|
+
/** HTTP Keep-Alive related settings. */
|
|
84
|
+
keep_alive?: {
|
|
85
|
+
/** Enable or disable HTTP Keep-Alive mechanism.
|
|
86
|
+
* @default true */
|
|
87
|
+
enabled?: boolean;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Custom parsing when handling with JSON objects
|
|
91
|
+
*
|
|
92
|
+
* Defaults to using standard `JSON.parse` and `JSON.stringify`
|
|
93
|
+
*/
|
|
94
|
+
json?: Partial<JSONHandling>;
|
|
95
|
+
}
|
|
96
|
+
export type MakeConnection<Stream, Config = BaseClickHouseClientConfigOptionsWithURL> = (config: Config, params: ConnectionParams) => Connection<Stream>;
|
|
97
|
+
export type MakeResultSet<Stream> = <Format extends DataFormat, ResultSet extends BaseResultSet<Stream, Format>>(stream: Stream, format: Format, query_id: string, log_error: (err: Error) => void, response_headers: ResponseHeaders, jsonHandling: JSONHandling) => ResultSet;
|
|
98
|
+
export type MakeValuesEncoder<Stream> = (jsonHandling: JSONHandling) => ValuesEncoder<Stream>;
|
|
99
|
+
export interface ValuesEncoder<Stream> {
|
|
100
|
+
validateInsertValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): void;
|
|
101
|
+
/**
|
|
102
|
+
* A function encodes an array or a stream of JSON objects to a format compatible with ClickHouse.
|
|
103
|
+
* If values are provided as an array of JSON objects, the function encodes it in place.
|
|
104
|
+
* If values are provided as a stream of JSON objects, the function sets up the encoding of each chunk.
|
|
105
|
+
* If values are provided as a raw non-object stream, the function does nothing.
|
|
106
|
+
*
|
|
107
|
+
* @param values a set of values to send to ClickHouse.
|
|
108
|
+
* @param format a format to encode value to.
|
|
109
|
+
*/
|
|
110
|
+
encodeValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): string | Stream;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* An implementation might have extra config parameters that we can parse from the connection URL.
|
|
114
|
+
* These are supposed to be processed after we finish parsing the base configuration.
|
|
115
|
+
* URL params handled in the common package will be deleted from the URL object.
|
|
116
|
+
* This way we ensure that only implementation-specific params are passed there,
|
|
117
|
+
* so we can indicate which URL parameters are unknown by both common and implementation packages.
|
|
118
|
+
*/
|
|
119
|
+
export type HandleImplSpecificURLParams = (config: BaseClickHouseClientConfigOptions, url: URL) => {
|
|
120
|
+
config: BaseClickHouseClientConfigOptions;
|
|
121
|
+
handled_params: Set<string>;
|
|
122
|
+
unknown_params: Set<string>;
|
|
123
|
+
};
|
|
124
|
+
/** Things that may vary between Web/Node.js/etc client implementations. */
|
|
125
|
+
export interface ImplementationDetails<Stream> {
|
|
126
|
+
impl: {
|
|
127
|
+
make_connection: MakeConnection<Stream>;
|
|
128
|
+
make_result_set: MakeResultSet<Stream>;
|
|
129
|
+
values_encoder: MakeValuesEncoder<Stream>;
|
|
130
|
+
handle_specific_url_params?: HandleImplSpecificURLParams;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export type BaseClickHouseClientConfigOptionsWithURL = Omit<BaseClickHouseClientConfigOptions, 'url'> & {
|
|
134
|
+
url: URL;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Validates and normalizes the provided "base" config.
|
|
138
|
+
* Warns about deprecated configuration parameters usage.
|
|
139
|
+
* Parses the common URL parameters into the configuration parameters (these are the same for all implementations).
|
|
140
|
+
* Parses implementation-specific URL parameters using the handler provided by that implementation.
|
|
141
|
+
* Merges these parameters with the base config and implementation-specific defaults.
|
|
142
|
+
* Enforces certain defaults in case of deprecated keys or readonly mode.
|
|
143
|
+
*/
|
|
144
|
+
export declare function prepareConfigWithURL(baseConfigOptions: BaseClickHouseClientConfigOptions, logger: Logger, handleImplURLParams: HandleImplSpecificURLParams | null): BaseClickHouseClientConfigOptionsWithURL;
|
|
145
|
+
export declare function getConnectionParams(config: BaseClickHouseClientConfigOptionsWithURL, logger: Logger): ConnectionParams;
|
|
146
|
+
/**
|
|
147
|
+
* Merge two versions of the config: base (hardcoded) from the instance creation and the URL parsed one.
|
|
148
|
+
* URL config takes priority and overrides the base config parameters.
|
|
149
|
+
* If a value is overridden, then a warning will be logged (even if the log level is OFF).
|
|
150
|
+
*/
|
|
151
|
+
export declare function mergeConfigs(baseConfig: BaseClickHouseClientConfigOptions, configFromURL: BaseClickHouseClientConfigOptions, logger: Logger): BaseClickHouseClientConfigOptions;
|
|
152
|
+
export declare function createUrl(configURL: string | URL | undefined): URL;
|
|
153
|
+
/**
|
|
154
|
+
* @param url potentially contains auth, database and URL params to parse the configuration from
|
|
155
|
+
* @param handleExtraURLParams some platform-specific URL params might be unknown by the common package;
|
|
156
|
+
* use this function defined in the implementation to handle them. Logs warnings in case of hardcode overrides.
|
|
157
|
+
*/
|
|
158
|
+
export declare function loadConfigOptionsFromURL(url: URL, handleExtraURLParams: HandleImplSpecificURLParams | null): [URL, BaseClickHouseClientConfigOptions];
|
|
159
|
+
export declare function booleanConfigURLValue({ key, value, }: {
|
|
160
|
+
key: string;
|
|
161
|
+
value: string;
|
|
162
|
+
}): boolean;
|
|
163
|
+
export declare function numberConfigURLValue({ key, value, min, max, }: {
|
|
164
|
+
key: string;
|
|
165
|
+
value: string;
|
|
166
|
+
min?: number;
|
|
167
|
+
max?: number;
|
|
168
|
+
}): number;
|
|
169
|
+
export declare function enumConfigURLValue<Enum, Key extends string>({ key, value, enumObject, }: {
|
|
170
|
+
key: string;
|
|
171
|
+
value: string;
|
|
172
|
+
enumObject: Record<Key, Enum>;
|
|
173
|
+
}): Enum;
|