@clickhouse/client-common 0.3.1 → 0.4.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 +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 +34 -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 +14 -0
- package/dist/utils/stream.js +53 -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/config.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareConfigWithURL = prepareConfigWithURL;
|
|
4
|
+
exports.getConnectionParams = getConnectionParams;
|
|
5
|
+
exports.mergeConfigs = mergeConfigs;
|
|
6
|
+
exports.createUrl = createUrl;
|
|
7
|
+
exports.loadConfigOptionsFromURL = loadConfigOptionsFromURL;
|
|
8
|
+
exports.booleanConfigURLValue = booleanConfigURLValue;
|
|
9
|
+
exports.numberConfigURLValue = numberConfigURLValue;
|
|
10
|
+
exports.enumConfigURLValue = enumConfigURLValue;
|
|
11
|
+
const logger_1 = require("./logger");
|
|
12
|
+
const json_handling_1 = require("./parse/json_handling");
|
|
13
|
+
/**
|
|
14
|
+
* Validates and normalizes the provided "base" config.
|
|
15
|
+
* Warns about deprecated configuration parameters usage.
|
|
16
|
+
* Parses the common URL parameters into the configuration parameters (these are the same for all implementations).
|
|
17
|
+
* Parses implementation-specific URL parameters using the handler provided by that implementation.
|
|
18
|
+
* Merges these parameters with the base config and implementation-specific defaults.
|
|
19
|
+
* Enforces certain defaults in case of deprecated keys or readonly mode.
|
|
20
|
+
*/
|
|
21
|
+
function prepareConfigWithURL(baseConfigOptions, logger, handleImplURLParams) {
|
|
22
|
+
const baseConfig = { ...baseConfigOptions };
|
|
23
|
+
if (baseConfig.additional_headers !== undefined) {
|
|
24
|
+
logger.warn({
|
|
25
|
+
module: 'Config',
|
|
26
|
+
message: '"additional_headers" is deprecated. Use "http_headers" instead.',
|
|
27
|
+
});
|
|
28
|
+
baseConfig.http_headers = baseConfig.additional_headers;
|
|
29
|
+
delete baseConfig.additional_headers;
|
|
30
|
+
}
|
|
31
|
+
let configURL;
|
|
32
|
+
if (baseConfig.host !== undefined) {
|
|
33
|
+
logger.warn({
|
|
34
|
+
module: 'Config',
|
|
35
|
+
message: '"host" is deprecated. Use "url" instead.',
|
|
36
|
+
});
|
|
37
|
+
configURL = createUrl(baseConfig.host);
|
|
38
|
+
delete baseConfig.host;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
configURL = createUrl(baseConfig.url);
|
|
42
|
+
}
|
|
43
|
+
const [url, configFromURL] = loadConfigOptionsFromURL(configURL, handleImplURLParams);
|
|
44
|
+
const config = mergeConfigs(baseConfig, configFromURL, logger);
|
|
45
|
+
if (config.pathname !== undefined) {
|
|
46
|
+
url.pathname = config.pathname;
|
|
47
|
+
}
|
|
48
|
+
config.url = url;
|
|
49
|
+
return config;
|
|
50
|
+
}
|
|
51
|
+
function getConnectionParams(config, logger) {
|
|
52
|
+
let auth;
|
|
53
|
+
if (config.access_token !== undefined) {
|
|
54
|
+
if (config.username !== undefined || config.password !== undefined) {
|
|
55
|
+
throw new Error('Both access token and username/password are provided in the configuration. Please use only one authentication method.');
|
|
56
|
+
}
|
|
57
|
+
auth = { access_token: config.access_token, type: 'JWT' };
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
auth = {
|
|
61
|
+
username: config.username ?? 'default',
|
|
62
|
+
password: config.password ?? '',
|
|
63
|
+
type: 'Credentials',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
auth,
|
|
68
|
+
url: config.url,
|
|
69
|
+
application_id: config.application,
|
|
70
|
+
request_timeout: config.request_timeout ?? 30000,
|
|
71
|
+
max_open_connections: config.max_open_connections ?? 10,
|
|
72
|
+
compression: {
|
|
73
|
+
decompress_response: config.compression?.response ?? false,
|
|
74
|
+
compress_request: config.compression?.request ?? false,
|
|
75
|
+
},
|
|
76
|
+
database: config.database ?? 'default',
|
|
77
|
+
log_writer: new logger_1.LogWriter(logger, 'Connection', config.log?.level),
|
|
78
|
+
keep_alive: { enabled: config.keep_alive?.enabled ?? true },
|
|
79
|
+
clickhouse_settings: config.clickhouse_settings ?? {},
|
|
80
|
+
http_headers: config.http_headers ?? {},
|
|
81
|
+
json: {
|
|
82
|
+
...json_handling_1.defaultJSONHandling,
|
|
83
|
+
...config.json,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Merge two versions of the config: base (hardcoded) from the instance creation and the URL parsed one.
|
|
89
|
+
* URL config takes priority and overrides the base config parameters.
|
|
90
|
+
* If a value is overridden, then a warning will be logged (even if the log level is OFF).
|
|
91
|
+
*/
|
|
92
|
+
function mergeConfigs(baseConfig, configFromURL, logger) {
|
|
93
|
+
function deepMerge(base, fromURL, path = []) {
|
|
94
|
+
for (const key of Object.keys(fromURL)) {
|
|
95
|
+
if (typeof fromURL[key] === 'object') {
|
|
96
|
+
deepMerge(base, fromURL[key], path.concat(key));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
let baseAtPath = base;
|
|
100
|
+
for (const key of path) {
|
|
101
|
+
if (baseAtPath[key] === undefined) {
|
|
102
|
+
baseAtPath[key] = {};
|
|
103
|
+
}
|
|
104
|
+
baseAtPath = baseAtPath[key];
|
|
105
|
+
}
|
|
106
|
+
const baseAtKey = baseAtPath[key];
|
|
107
|
+
if (baseAtKey !== undefined) {
|
|
108
|
+
const fullPath = path.concat(key).join('.');
|
|
109
|
+
logger.warn({
|
|
110
|
+
module: 'Config',
|
|
111
|
+
message: `"${fullPath}" is overridden by a URL parameter.`,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
baseAtPath[key] = fromURL[key];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const config = { ...baseConfig };
|
|
119
|
+
deepMerge(config, configFromURL);
|
|
120
|
+
return config;
|
|
121
|
+
}
|
|
122
|
+
function createUrl(configURL) {
|
|
123
|
+
let url;
|
|
124
|
+
try {
|
|
125
|
+
if (typeof configURL === 'string' || configURL instanceof URL) {
|
|
126
|
+
url = new URL(configURL);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return new URL('http://localhost:8123');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
throw new Error('ClickHouse URL is malformed. Expected format: http[s]://[username:password@]hostname:port[/database][?param1=value1¶m2=value2]', { cause: err });
|
|
134
|
+
}
|
|
135
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
136
|
+
throw new Error(`ClickHouse URL protocol must be either http or https. Got: ${url.protocol}`);
|
|
137
|
+
}
|
|
138
|
+
return url;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @param url potentially contains auth, database and URL params to parse the configuration from
|
|
142
|
+
* @param handleExtraURLParams some platform-specific URL params might be unknown by the common package;
|
|
143
|
+
* use this function defined in the implementation to handle them. Logs warnings in case of hardcode overrides.
|
|
144
|
+
*/
|
|
145
|
+
function loadConfigOptionsFromURL(url, handleExtraURLParams) {
|
|
146
|
+
let config = {};
|
|
147
|
+
// trim is not needed, cause space is not allowed in the URL basic auth and should be encoded as %20
|
|
148
|
+
if (url.username !== '') {
|
|
149
|
+
config.username = decodeURIComponent(url.username);
|
|
150
|
+
}
|
|
151
|
+
if (url.password !== '') {
|
|
152
|
+
config.password = decodeURIComponent(url.password);
|
|
153
|
+
}
|
|
154
|
+
if (url.pathname.trim().length > 1) {
|
|
155
|
+
config.database = url.pathname.slice(1);
|
|
156
|
+
}
|
|
157
|
+
const urlSearchParamsKeys = [...url.searchParams.keys()];
|
|
158
|
+
if (urlSearchParamsKeys.length > 0) {
|
|
159
|
+
const unknownParams = new Set();
|
|
160
|
+
const settingPrefix = 'clickhouse_setting_';
|
|
161
|
+
const settingShortPrefix = 'ch_';
|
|
162
|
+
const httpHeaderPrefix = 'http_header_';
|
|
163
|
+
urlSearchParamsKeys.forEach((key) => {
|
|
164
|
+
let paramWasProcessed = true;
|
|
165
|
+
const value = url.searchParams.get(key);
|
|
166
|
+
if (key.startsWith(settingPrefix)) {
|
|
167
|
+
// clickhouse_settings_*
|
|
168
|
+
const settingKey = key.slice(settingPrefix.length);
|
|
169
|
+
if (config.clickhouse_settings === undefined) {
|
|
170
|
+
config.clickhouse_settings = {};
|
|
171
|
+
}
|
|
172
|
+
config.clickhouse_settings[settingKey] = value;
|
|
173
|
+
}
|
|
174
|
+
else if (key.startsWith(settingShortPrefix)) {
|
|
175
|
+
// ch_*
|
|
176
|
+
const settingKey = key.slice(settingShortPrefix.length);
|
|
177
|
+
if (config.clickhouse_settings === undefined) {
|
|
178
|
+
config.clickhouse_settings = {};
|
|
179
|
+
}
|
|
180
|
+
config.clickhouse_settings[settingKey] = value;
|
|
181
|
+
}
|
|
182
|
+
else if (key.startsWith(httpHeaderPrefix)) {
|
|
183
|
+
// http_headers_*
|
|
184
|
+
const headerKey = key.slice(httpHeaderPrefix.length);
|
|
185
|
+
if (config.http_headers === undefined) {
|
|
186
|
+
config.http_headers = {};
|
|
187
|
+
}
|
|
188
|
+
config.http_headers[headerKey] = value;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// static known parameters
|
|
192
|
+
switch (key) {
|
|
193
|
+
case 'application':
|
|
194
|
+
config.application = value;
|
|
195
|
+
break;
|
|
196
|
+
case 'pathname':
|
|
197
|
+
config.pathname = value;
|
|
198
|
+
break;
|
|
199
|
+
case 'session_id':
|
|
200
|
+
config.session_id = value;
|
|
201
|
+
break;
|
|
202
|
+
case 'request_timeout':
|
|
203
|
+
config.request_timeout = numberConfigURLValue({
|
|
204
|
+
key,
|
|
205
|
+
value,
|
|
206
|
+
min: 0,
|
|
207
|
+
});
|
|
208
|
+
break;
|
|
209
|
+
case 'max_open_connections':
|
|
210
|
+
config.max_open_connections = numberConfigURLValue({
|
|
211
|
+
key,
|
|
212
|
+
value,
|
|
213
|
+
min: 1,
|
|
214
|
+
});
|
|
215
|
+
break;
|
|
216
|
+
case 'compression_request':
|
|
217
|
+
if (config.compression === undefined) {
|
|
218
|
+
config.compression = {};
|
|
219
|
+
}
|
|
220
|
+
config.compression.request = booleanConfigURLValue({ key, value });
|
|
221
|
+
break;
|
|
222
|
+
case 'compression_response':
|
|
223
|
+
if (config.compression === undefined) {
|
|
224
|
+
config.compression = {};
|
|
225
|
+
}
|
|
226
|
+
config.compression.response = booleanConfigURLValue({
|
|
227
|
+
key,
|
|
228
|
+
value,
|
|
229
|
+
});
|
|
230
|
+
break;
|
|
231
|
+
case 'log_level':
|
|
232
|
+
if (config.log === undefined) {
|
|
233
|
+
config.log = {};
|
|
234
|
+
}
|
|
235
|
+
config.log.level = enumConfigURLValue({
|
|
236
|
+
key,
|
|
237
|
+
value,
|
|
238
|
+
enumObject: logger_1.ClickHouseLogLevel,
|
|
239
|
+
});
|
|
240
|
+
break;
|
|
241
|
+
case 'keep_alive_enabled':
|
|
242
|
+
if (config.keep_alive === undefined) {
|
|
243
|
+
config.keep_alive = {};
|
|
244
|
+
}
|
|
245
|
+
config.keep_alive.enabled = booleanConfigURLValue({ key, value });
|
|
246
|
+
break;
|
|
247
|
+
case 'access_token':
|
|
248
|
+
config.access_token = value;
|
|
249
|
+
break;
|
|
250
|
+
default:
|
|
251
|
+
paramWasProcessed = false;
|
|
252
|
+
unknownParams.add(key);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (paramWasProcessed) {
|
|
257
|
+
// so it won't be passed to the impl URL params handler
|
|
258
|
+
url.searchParams.delete(key);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
if (handleExtraURLParams !== null) {
|
|
262
|
+
const res = handleExtraURLParams(config, url);
|
|
263
|
+
config = res.config;
|
|
264
|
+
if (unknownParams.size > 0) {
|
|
265
|
+
res.handled_params.forEach((k) => unknownParams.delete(k));
|
|
266
|
+
}
|
|
267
|
+
if (res.unknown_params.size > 0) {
|
|
268
|
+
res.unknown_params.forEach((k) => unknownParams.add(k));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (unknownParams.size > 0) {
|
|
272
|
+
throw new Error(`Unknown URL parameters: ${Array.from(unknownParams).join(', ')}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// clean up the final ClickHouse URL to be used in the connection
|
|
276
|
+
const clickHouseURL = new URL(`${url.protocol}//${url.host}`);
|
|
277
|
+
return [clickHouseURL, config];
|
|
278
|
+
}
|
|
279
|
+
function booleanConfigURLValue({ key, value, }) {
|
|
280
|
+
const trimmed = value.trim();
|
|
281
|
+
if (trimmed === 'true' || trimmed === '1')
|
|
282
|
+
return true;
|
|
283
|
+
if (trimmed === 'false' || trimmed === '0')
|
|
284
|
+
return false;
|
|
285
|
+
throw new Error(`"${key}" has invalid boolean value: ${trimmed}. Expected one of: 0, 1, true, false.`);
|
|
286
|
+
}
|
|
287
|
+
function numberConfigURLValue({ key, value, min, max, }) {
|
|
288
|
+
const trimmed = value.trim();
|
|
289
|
+
const number = Number(trimmed);
|
|
290
|
+
if (isNaN(number))
|
|
291
|
+
throw new Error(`"${key}" has invalid numeric value: ${trimmed}`);
|
|
292
|
+
if (min !== undefined && number < min) {
|
|
293
|
+
throw new Error(`"${key}" value ${trimmed} is less than min allowed ${min}`);
|
|
294
|
+
}
|
|
295
|
+
if (max !== undefined && number > max) {
|
|
296
|
+
throw new Error(`"${key}" value ${trimmed} is greater than max allowed ${max}`);
|
|
297
|
+
}
|
|
298
|
+
return number;
|
|
299
|
+
}
|
|
300
|
+
function enumConfigURLValue({ key, value, enumObject, }) {
|
|
301
|
+
const values = Object.keys(enumObject).filter((item) => isNaN(Number(item)));
|
|
302
|
+
const trimmed = value.trim();
|
|
303
|
+
if (!values.includes(trimmed)) {
|
|
304
|
+
const expected = values.join(', ');
|
|
305
|
+
throw new Error(`"${key}" has invalid value: ${trimmed}. Expected one of: ${expected}.`);
|
|
306
|
+
}
|
|
307
|
+
return enumObject[trimmed];
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAuLA,oDAoCC;AAED,kDAuCC;AAOD,oCAqCC;AAED,8BAoBC;AAOD,4DAuIC;AAED,sDAaC;AAED,oDAwBC;AAED,gDAkBC;AA7gBD,qCAAwD;AACxD,yDAA8E;AA0K9E;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,iBAAoD,EACpD,MAAc,EACd,mBAAuD;IAEvD,MAAM,UAAU,GAAG,EAAE,GAAG,iBAAiB,EAAE,CAAA;IAC3C,IAAI,UAAU,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC;YACV,MAAM,EAAE,QAAQ;YAChB,OAAO,EACL,iEAAiE;SACpE,CAAC,CAAA;QACF,UAAU,CAAC,YAAY,GAAG,UAAU,CAAC,kBAAkB,CAAA;QACvD,OAAO,UAAU,CAAC,kBAAkB,CAAA;IACtC,CAAC;IACD,IA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,GAAG,WAAW,OAAO,gCAAgC,GAAG,EAAE,CAC/D,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAgB,kBAAkB,CAA2B,EAC3D,GAAG,EACH,KAAK,EACL,UAAU,GAKX;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC5E,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;IAC5B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClC,MAAM,IAAI,KAAK,CACb,IAAI,GAAG,wBAAwB,OAAO,sBAAsB,QAAQ,GAAG,CACxE,CAAA;IACH,CAAC;IACD,OAAO,UAAU,CAAC,OAAc,CAAC,CAAA;AACnC,CAAC"}
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JSONHandling } from '.';
|
|
2
|
+
import type { WithClickHouseSummary, WithResponseHeaders } from './clickhouse_types';
|
|
2
3
|
import type { LogWriter } from './logger';
|
|
3
4
|
import type { ClickHouseSettings } from './settings';
|
|
5
|
+
export type ConnectionAuth = {
|
|
6
|
+
username: string;
|
|
7
|
+
password: string;
|
|
8
|
+
type: 'Credentials';
|
|
9
|
+
} | {
|
|
10
|
+
access_token: string;
|
|
11
|
+
type: 'JWT';
|
|
12
|
+
};
|
|
4
13
|
export interface ConnectionParams {
|
|
5
14
|
url: URL;
|
|
6
15
|
request_timeout: number;
|
|
7
16
|
max_open_connections: number;
|
|
8
|
-
compression:
|
|
9
|
-
decompress_response: boolean;
|
|
10
|
-
compress_request: boolean;
|
|
11
|
-
};
|
|
12
|
-
username: string;
|
|
13
|
-
password: string;
|
|
17
|
+
compression: CompressionSettings;
|
|
14
18
|
database: string;
|
|
15
19
|
clickhouse_settings: ClickHouseSettings;
|
|
16
20
|
log_writer: LogWriter;
|
|
21
|
+
keep_alive: {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
};
|
|
17
24
|
application_id?: string;
|
|
18
|
-
|
|
25
|
+
http_headers?: Record<string, string>;
|
|
26
|
+
auth: ConnectionAuth;
|
|
27
|
+
json?: JSONHandling;
|
|
28
|
+
}
|
|
29
|
+
export interface CompressionSettings {
|
|
30
|
+
decompress_response: boolean;
|
|
31
|
+
compress_request: boolean;
|
|
19
32
|
}
|
|
20
33
|
export interface ConnBaseQueryParams {
|
|
21
34
|
query: string;
|
|
@@ -24,11 +37,27 @@ export interface ConnBaseQueryParams {
|
|
|
24
37
|
abort_signal?: AbortSignal;
|
|
25
38
|
session_id?: string;
|
|
26
39
|
query_id?: string;
|
|
40
|
+
auth?: {
|
|
41
|
+
username: string;
|
|
42
|
+
password: string;
|
|
43
|
+
} | {
|
|
44
|
+
access_token: string;
|
|
45
|
+
};
|
|
46
|
+
role?: string | Array<string>;
|
|
47
|
+
http_headers?: Record<string, string>;
|
|
27
48
|
}
|
|
49
|
+
export type ConnPingParams = {
|
|
50
|
+
select: boolean;
|
|
51
|
+
} & Omit<ConnBaseQueryParams, 'query' | 'query_params'>;
|
|
28
52
|
export interface ConnInsertParams<Stream> extends ConnBaseQueryParams {
|
|
29
53
|
values: string | Stream;
|
|
30
54
|
}
|
|
31
|
-
export interface
|
|
55
|
+
export interface ConnExecParams<Stream> extends ConnBaseQueryParams {
|
|
56
|
+
values?: Stream;
|
|
57
|
+
decompress_response_stream?: boolean;
|
|
58
|
+
ignore_error_response?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface ConnBaseResult extends WithResponseHeaders {
|
|
32
61
|
query_id: string;
|
|
33
62
|
}
|
|
34
63
|
export interface ConnQueryResult<Stream> extends ConnBaseResult {
|
|
@@ -37,17 +66,19 @@ export interface ConnQueryResult<Stream> extends ConnBaseResult {
|
|
|
37
66
|
}
|
|
38
67
|
export type ConnInsertResult = ConnBaseResult & WithClickHouseSummary;
|
|
39
68
|
export type ConnExecResult<Stream> = ConnQueryResult<Stream> & WithClickHouseSummary;
|
|
69
|
+
export type ConnCommandResult = ConnBaseResult & WithClickHouseSummary;
|
|
40
70
|
export type ConnPingResult = {
|
|
41
71
|
success: true;
|
|
42
72
|
} | {
|
|
43
73
|
success: false;
|
|
44
74
|
error: Error;
|
|
45
75
|
};
|
|
46
|
-
export type ConnOperation = 'Ping' | 'Query' | 'Insert' | 'Exec';
|
|
76
|
+
export type ConnOperation = 'Ping' | 'Query' | 'Insert' | 'Exec' | 'Command';
|
|
47
77
|
export interface Connection<Stream> {
|
|
48
|
-
ping(): Promise<ConnPingResult>;
|
|
49
|
-
close(): Promise<void>;
|
|
78
|
+
ping(params: ConnPingParams): Promise<ConnPingResult>;
|
|
50
79
|
query(params: ConnBaseQueryParams): Promise<ConnQueryResult<Stream>>;
|
|
51
|
-
exec(params: ConnBaseQueryParams): Promise<ConnExecResult<Stream>>;
|
|
52
80
|
insert(params: ConnInsertParams<Stream>): Promise<ConnInsertResult>;
|
|
81
|
+
command(params: ConnBaseQueryParams): Promise<ConnCommandResult>;
|
|
82
|
+
exec(params: ConnExecParams<Stream>): Promise<ConnExecResult<Stream>>;
|
|
83
|
+
close(): Promise<void>;
|
|
53
84
|
}
|
package/dist/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare class TupleParam {
|
|
2
|
+
readonly values: readonly unknown[];
|
|
3
|
+
constructor(values: readonly unknown[]);
|
|
4
|
+
}
|
|
5
|
+
export declare function formatQueryParams({ value, wrapStringInQuotes, printNullAsKeyword, }: FormatQueryParamsOptions): string;
|
|
6
|
+
interface FormatQueryParamsOptions {
|
|
7
|
+
value: unknown;
|
|
8
|
+
wrapStringInQuotes?: boolean;
|
|
9
|
+
printNullAsKeyword?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -1,19 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.TupleParam = void 0;
|
|
4
|
+
exports.formatQueryParams = formatQueryParams;
|
|
5
|
+
class TupleParam {
|
|
6
|
+
constructor(values) {
|
|
7
|
+
Object.defineProperty(this, "values", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: values
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.TupleParam = TupleParam;
|
|
16
|
+
function formatQueryParams({ value, wrapStringInQuotes, printNullAsKeyword, }) {
|
|
17
|
+
return formatQueryParamsInternal({
|
|
18
|
+
value,
|
|
19
|
+
wrapStringInQuotes,
|
|
20
|
+
printNullAsKeyword,
|
|
21
|
+
isInArrayOrTuple: false,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function formatQueryParamsInternal({ value, wrapStringInQuotes, printNullAsKeyword, isInArrayOrTuple, }) {
|
|
25
|
+
if (value === null || value === undefined) {
|
|
26
|
+
if (printNullAsKeyword)
|
|
27
|
+
return 'NULL';
|
|
6
28
|
return '\\N';
|
|
29
|
+
}
|
|
7
30
|
if (Number.isNaN(value))
|
|
8
31
|
return 'nan';
|
|
9
32
|
if (value === Number.POSITIVE_INFINITY)
|
|
10
33
|
return '+inf';
|
|
11
34
|
if (value === Number.NEGATIVE_INFINITY)
|
|
12
35
|
return '-inf';
|
|
13
|
-
if (typeof value === 'number')
|
|
36
|
+
if (typeof value === 'number' || typeof value === 'bigint')
|
|
14
37
|
return String(value);
|
|
15
|
-
if (typeof value === 'boolean')
|
|
38
|
+
if (typeof value === 'boolean') {
|
|
39
|
+
if (isInArrayOrTuple) {
|
|
40
|
+
return value ? 'TRUE' : 'FALSE';
|
|
41
|
+
}
|
|
16
42
|
return value ? '1' : '0';
|
|
43
|
+
}
|
|
17
44
|
if (typeof value === 'string') {
|
|
18
45
|
let result = '';
|
|
19
46
|
for (let i = 0; i < value.length; i++) {
|
|
@@ -40,8 +67,14 @@ function formatQueryParams(value, wrapStringInQuotes = false) {
|
|
|
40
67
|
return wrapStringInQuotes ? `'${result}'` : result;
|
|
41
68
|
}
|
|
42
69
|
if (Array.isArray(value)) {
|
|
43
|
-
|
|
44
|
-
|
|
70
|
+
return `[${value
|
|
71
|
+
.map((v) => formatQueryParamsInternal({
|
|
72
|
+
value: v,
|
|
73
|
+
wrapStringInQuotes: true,
|
|
74
|
+
printNullAsKeyword: true,
|
|
75
|
+
isInArrayOrTuple: true,
|
|
76
|
+
}))
|
|
77
|
+
.join(',')}]`;
|
|
45
78
|
}
|
|
46
79
|
if (value instanceof Date) {
|
|
47
80
|
// The ClickHouse server parses numbers as time-zone-agnostic Unix timestamps
|
|
@@ -53,16 +86,44 @@ function formatQueryParams(value, wrapStringInQuotes = false) {
|
|
|
53
86
|
? unixTimestamp
|
|
54
87
|
: `${unixTimestamp}.${milliseconds.toString().padStart(3, '0')}`;
|
|
55
88
|
}
|
|
89
|
+
// (42,'foo',NULL)
|
|
90
|
+
if (value instanceof TupleParam) {
|
|
91
|
+
return `(${value.values
|
|
92
|
+
.map((v) => formatQueryParamsInternal({
|
|
93
|
+
value: v,
|
|
94
|
+
wrapStringInQuotes: true,
|
|
95
|
+
printNullAsKeyword: true,
|
|
96
|
+
isInArrayOrTuple: true,
|
|
97
|
+
}))
|
|
98
|
+
.join(',')})`;
|
|
99
|
+
}
|
|
100
|
+
if (value instanceof Map) {
|
|
101
|
+
return formatObjectLikeParam(value.entries());
|
|
102
|
+
}
|
|
103
|
+
// This is only useful for simple maps where the keys are strings
|
|
56
104
|
if (typeof value === 'object') {
|
|
57
|
-
|
|
58
|
-
for (const [key, val] of Object.entries(value)) {
|
|
59
|
-
formatted.push(`${formatQueryParams(key, true)}:${formatQueryParams(val, true)}`);
|
|
60
|
-
}
|
|
61
|
-
return `{${formatted.join(',')}}`;
|
|
105
|
+
return formatObjectLikeParam(Object.entries(value));
|
|
62
106
|
}
|
|
63
107
|
throw new Error(`Unsupported value in query parameters: [${value}].`);
|
|
64
108
|
}
|
|
65
|
-
|
|
109
|
+
// {'key1':'value1',42:'value2'}
|
|
110
|
+
function formatObjectLikeParam(entries) {
|
|
111
|
+
const formatted = [];
|
|
112
|
+
for (const [key, val] of entries) {
|
|
113
|
+
formatted.push(`${formatQueryParamsInternal({
|
|
114
|
+
value: key,
|
|
115
|
+
wrapStringInQuotes: true,
|
|
116
|
+
printNullAsKeyword: true,
|
|
117
|
+
isInArrayOrTuple: true,
|
|
118
|
+
})}:${formatQueryParamsInternal({
|
|
119
|
+
value: val,
|
|
120
|
+
wrapStringInQuotes: true,
|
|
121
|
+
printNullAsKeyword: true,
|
|
122
|
+
isInArrayOrTuple: true,
|
|
123
|
+
})}`);
|
|
124
|
+
}
|
|
125
|
+
return `{${formatted.join(',')}}`;
|
|
126
|
+
}
|
|
66
127
|
const TabASCII = 9;
|
|
67
128
|
const NewlineASCII = 10;
|
|
68
129
|
const CarriageReturnASCII = 13;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format_query_params.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"format_query_params.js","sourceRoot":"","sources":["../../src/data_formatter/format_query_params.ts"],"names":[],"mappings":";;;AAIA,8CAWC;AAfD,MAAa,UAAU;IACrB,YAA4B,MAA0B;QAA1C;;;;mBAAgB,MAAM;WAAoB;IAAG,CAAC;CAC3D;AAFD,gCAEC;AAED,SAAgB,iBAAiB,CAAC,EAChC,KAAK,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ASD,MAAM,QAAQ,GAAG,CAAC,CAAA;AAClB,MAAM,YAAY,GAAG,EAAE,CAAA;AACvB,MAAM,mBAAmB,GAAG,EAAE,CAAA;AAC9B,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAC3B,MAAM,cAAc,GAAG,EAAE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatQuerySettings =
|
|
3
|
+
exports.formatQuerySettings = formatQuerySettings;
|
|
4
4
|
const settings_1 = require("../settings");
|
|
5
5
|
function formatQuerySettings(value) {
|
|
6
6
|
if (typeof value === 'boolean')
|
|
@@ -17,5 +17,4 @@ function formatQuerySettings(value) {
|
|
|
17
17
|
}
|
|
18
18
|
throw new Error(`Unsupported value in query settings: [${value}].`);
|
|
19
19
|
}
|
|
20
|
-
exports.formatQuerySettings = formatQuerySettings;
|
|
21
20
|
//# sourceMappingURL=format_query_settings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format_query_settings.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"format_query_settings.js","sourceRoot":"","sources":["../../src/data_formatter/format_query_settings.ts"],"names":[],"mappings":";;AAEA,kDAaC;AAfD,0CAAyC;AAEzC,SAAgB,mBAAmB,CACjC,KAA8C;IAE9C,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,mEAAmE;IACnE,uDAAuD;IACvD,4CAA4C;IAC5C,IAAI,KAAK,YAAY,sBAAW,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;IACzB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,yCAAyC,KAAK,IAAI,CAAC,CAAA;AACrE,CAAC"}
|