@clickhouse/client 0.0.10 → 0.0.12
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/dist/clickhouse_types.d.ts +1 -1
- package/dist/client.d.ts +8 -9
- package/dist/client.js +11 -13
- package/dist/client.js.map +1 -1
- package/dist/connection/adapter/base_http_adapter.d.ts +5 -4
- package/dist/connection/adapter/base_http_adapter.js +67 -7
- package/dist/connection/adapter/base_http_adapter.js.map +1 -1
- package/dist/connection/adapter/http_adapter.d.ts +2 -2
- package/dist/connection/adapter/http_adapter.js.map +1 -1
- package/dist/connection/adapter/http_search_params.d.ts +3 -2
- package/dist/connection/adapter/http_search_params.js +4 -1
- package/dist/connection/adapter/http_search_params.js.map +1 -1
- package/dist/connection/adapter/https_adapter.d.ts +2 -2
- package/dist/connection/adapter/https_adapter.js.map +1 -1
- package/dist/connection/connection.d.ts +14 -6
- package/dist/connection/connection.js.map +1 -1
- package/dist/data_formatter/formatter.d.ts +4 -4
- package/dist/logger.d.ts +29 -7
- package/dist/logger.js +87 -22
- package/dist/logger.js.map +1 -1
- package/dist/result.d.ts +2 -1
- package/dist/result.js +7 -1
- package/dist/result.js.map +1 -1
- package/dist/schema/common.d.ts +3 -3
- package/dist/schema/engines.d.ts +2 -2
- package/dist/schema/table.js +4 -3
- package/dist/schema/table.js.map +1 -1
- package/dist/schema/types.d.ts +8 -8
- package/dist/settings.d.ts +32 -32
- package/dist/utils/process.d.ts +1 -0
- package/dist/utils/process.js +9 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/user_agent.d.ts +7 -0
- package/dist/utils/user_agent.js +46 -0
- package/dist/utils/user_agent.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +23 -23
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2016-
|
|
1
|
+
Copyright 2016-2023 ClickHouse, Inc.
|
|
2
2
|
|
|
3
3
|
Apache License
|
|
4
4
|
Version 2.0, January 2004
|
|
@@ -188,7 +188,7 @@ Copyright 2016-2022 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-2023 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/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import Stream from 'stream';
|
|
4
|
-
import {
|
|
4
|
+
import type { InsertResult, QueryResult } from './connection';
|
|
5
|
+
import type { Logger } from './logger';
|
|
5
6
|
import { type DataFormat } from './data_formatter';
|
|
6
7
|
import { ResultSet } from './result';
|
|
7
8
|
import type { ClickHouseSettings } from './settings';
|
|
@@ -25,17 +26,15 @@ export interface ClickHouseClientConfigOptions {
|
|
|
25
26
|
username?: string;
|
|
26
27
|
/** The user password. Default: ''. */
|
|
27
28
|
password?: string;
|
|
28
|
-
/** The name of the application using the nodejs client. Default:
|
|
29
|
+
/** The name of the application using the nodejs client. Default: empty. */
|
|
29
30
|
application?: string;
|
|
30
31
|
/** Database name to use. Default value: `default`. */
|
|
31
32
|
database?: string;
|
|
32
33
|
/** ClickHouse settings to apply to all requests. Default value: {} */
|
|
33
34
|
clickhouse_settings?: ClickHouseSettings;
|
|
34
35
|
log?: {
|
|
35
|
-
/** Enable logging. Default value: false. */
|
|
36
|
-
enable?: boolean;
|
|
37
36
|
/** A class to instantiate a custom logger implementation. */
|
|
38
|
-
LoggerClass?: new (
|
|
37
|
+
LoggerClass?: new () => Logger;
|
|
39
38
|
};
|
|
40
39
|
tls?: BasicTLSOptions | MutualTLSOptions;
|
|
41
40
|
session_id?: string;
|
|
@@ -66,7 +65,7 @@ export interface ExecParams extends BaseParams {
|
|
|
66
65
|
/** Statement to execute. */
|
|
67
66
|
query: string;
|
|
68
67
|
}
|
|
69
|
-
|
|
68
|
+
type InsertValues<T> = ReadonlyArray<T> | Stream.Readable | InputJSON<T> | InputJSONObjectEachRow<T>;
|
|
70
69
|
export interface InsertParams<T = unknown> extends BaseParams {
|
|
71
70
|
/** Name of a table to insert into. */
|
|
72
71
|
table: string;
|
|
@@ -78,12 +77,12 @@ export interface InsertParams<T = unknown> extends BaseParams {
|
|
|
78
77
|
export declare class ClickHouseClient {
|
|
79
78
|
private readonly config;
|
|
80
79
|
private readonly connection;
|
|
81
|
-
readonly logger
|
|
80
|
+
private readonly logger;
|
|
82
81
|
constructor(config?: ClickHouseClientConfigOptions);
|
|
83
82
|
private getBaseParams;
|
|
84
83
|
query(params: QueryParams): Promise<ResultSet>;
|
|
85
|
-
exec(params: ExecParams): Promise<
|
|
86
|
-
insert<T>(params: InsertParams<T>): Promise<
|
|
84
|
+
exec(params: ExecParams): Promise<QueryResult>;
|
|
85
|
+
insert<T>(params: InsertParams<T>): Promise<InsertResult>;
|
|
87
86
|
ping(): Promise<boolean>;
|
|
88
87
|
close(): Promise<void>;
|
|
89
88
|
}
|
package/dist/client.js
CHANGED
|
@@ -24,7 +24,7 @@ function createUrl(host) {
|
|
|
24
24
|
throw new Error('Configuration parameter "host" contains malformed url.');
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function normalizeConfig(config
|
|
27
|
+
function normalizeConfig(config) {
|
|
28
28
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
29
29
|
let tls = undefined;
|
|
30
30
|
if (config.tls) {
|
|
@@ -42,6 +42,7 @@ function normalizeConfig(config, loggingEnabled) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
return {
|
|
45
|
+
application_id: config.application,
|
|
45
46
|
url: createUrl((_a = config.host) !== null && _a !== void 0 ? _a : 'http://localhost:8123'),
|
|
46
47
|
connect_timeout: (_b = config.connect_timeout) !== null && _b !== void 0 ? _b : 10000,
|
|
47
48
|
request_timeout: (_c = config.request_timeout) !== null && _c !== void 0 ? _c : 300000,
|
|
@@ -57,15 +58,13 @@ function normalizeConfig(config, loggingEnabled) {
|
|
|
57
58
|
database: (_m = config.database) !== null && _m !== void 0 ? _m : 'default',
|
|
58
59
|
clickhouse_settings: (_o = config.clickhouse_settings) !== null && _o !== void 0 ? _o : {},
|
|
59
60
|
log: {
|
|
60
|
-
|
|
61
|
-
LoggerClass: (_q = (_p = config.log) === null || _p === void 0 ? void 0 : _p.LoggerClass) !== null && _q !== void 0 ? _q : logger_1.Logger,
|
|
61
|
+
LoggerClass: (_q = (_p = config.log) === null || _p === void 0 ? void 0 : _p.LoggerClass) !== null && _q !== void 0 ? _q : logger_1.DefaultLogger,
|
|
62
62
|
},
|
|
63
63
|
session_id: config.session_id,
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
class ClickHouseClient {
|
|
67
67
|
constructor(config = {}) {
|
|
68
|
-
var _a;
|
|
69
68
|
Object.defineProperty(this, "config", {
|
|
70
69
|
enumerable: true,
|
|
71
70
|
configurable: true,
|
|
@@ -84,10 +83,9 @@ class ClickHouseClient {
|
|
|
84
83
|
writable: true,
|
|
85
84
|
value: void 0
|
|
86
85
|
});
|
|
87
|
-
|
|
88
|
-
this.config = normalizeConfig(config, loggingEnabled);
|
|
86
|
+
this.config = normalizeConfig(config);
|
|
89
87
|
validateConfig(this.config);
|
|
90
|
-
this.logger = new this.config.log.LoggerClass(
|
|
88
|
+
this.logger = new logger_1.LogWriter(new this.config.log.LoggerClass());
|
|
91
89
|
this.connection = (0, connection_1.createConnection)(this.config, this.logger);
|
|
92
90
|
}
|
|
93
91
|
getBaseParams(params) {
|
|
@@ -105,15 +103,15 @@ class ClickHouseClient {
|
|
|
105
103
|
var _a;
|
|
106
104
|
const format = (_a = params.format) !== null && _a !== void 0 ? _a : 'JSON';
|
|
107
105
|
const query = formatQuery(params.query, format);
|
|
108
|
-
const stream = await this.connection.query({
|
|
106
|
+
const { stream, query_id } = await this.connection.query({
|
|
109
107
|
query,
|
|
110
108
|
...this.getBaseParams(params),
|
|
111
109
|
});
|
|
112
|
-
return new result_1.ResultSet(stream, format);
|
|
110
|
+
return new result_1.ResultSet(stream, format, query_id);
|
|
113
111
|
}
|
|
114
|
-
exec(params) {
|
|
112
|
+
async exec(params) {
|
|
115
113
|
const query = removeTrailingSemi(params.query.trim());
|
|
116
|
-
return this.connection.exec({
|
|
114
|
+
return await this.connection.exec({
|
|
117
115
|
query,
|
|
118
116
|
...this.getBaseParams(params),
|
|
119
117
|
});
|
|
@@ -121,8 +119,8 @@ class ClickHouseClient {
|
|
|
121
119
|
async insert(params) {
|
|
122
120
|
const format = params.format || 'JSONCompactEachRow';
|
|
123
121
|
validateInsertValues(params.values, format);
|
|
124
|
-
const query = `INSERT
|
|
125
|
-
await this.connection.insert({
|
|
122
|
+
const query = `INSERT INTO ${params.table.trim()} FORMAT ${format}`;
|
|
123
|
+
return await this.connection.insert({
|
|
126
124
|
query,
|
|
127
125
|
values: encodeValues(params.values, format),
|
|
128
126
|
...this.getBaseParams(params),
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,6CAAgE;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,6CAAgE;AAEhE,qCAAmD;AACnD,mCAA6C;AAC7C,qDAIyB;AACzB,qCAAoC;AAoFpC,SAAS,cAAc,CAAC,EAAE,GAAG,EAAoB;IAC/C,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE;QACzD,MAAM,IAAI,KAAK,CACb,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,CAAC;AA5BD,oDA4BC;AAED;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAC1B,MAAuB,EACvB,MAAkB;IAElB,IAAI,IAAA,gBAAQ,EAAC,MAAM,CAAC,EAAE;QACpB,yEAAyE;QACzE,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE;YAC9B,OAAO,MAAM,CAAA;SACd;QACD,wBAAwB;QACxB,OAAO,gBAAM,CAAC,QAAQ,CACpB,MAAM,EACN,IAAA,iBAAS,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAU,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC,EAC/C,UAAU,CACX,CAAA;KACF;IACD,eAAe;IACf,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAU,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;KACjE;IACD,wCAAwC;IACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,IAAA,2BAAU,EAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAClC;IACD,MAAM,IAAI,KAAK,CACb,gCAAgC,OAAO,MAAM,SAAS,MAAM,SAAS,CACtE,CAAA;AACH,CAAC;AA3BD,oCA2BC;AAED,SAAgB,YAAY,CAC1B,MAAsC;IAEtC,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;AACrC,CAAC;AAJD,oCAIC;AAED,SAAS,UAAU,CAAC,GAAiC;IACnD,IAAI,GAAG,EAAE;QACP,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;KACnB;AACH,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import Stream from 'stream';
|
|
4
4
|
import type Http from 'http';
|
|
5
5
|
import type { Logger } from '../../logger';
|
|
6
|
-
import type { BaseParams, Connection, ConnectionParams, InsertParams } from '../connection';
|
|
6
|
+
import type { BaseParams, Connection, ConnectionParams, InsertParams, InsertResult, QueryResult } from '../connection';
|
|
7
7
|
export interface RequestParams {
|
|
8
8
|
method: 'GET' | 'POST';
|
|
9
9
|
url: URL;
|
|
@@ -22,10 +22,11 @@ export declare abstract class BaseHttpAdapter implements Connection {
|
|
|
22
22
|
protected abstract createClientRequest(url: URL, params: RequestParams): Http.ClientRequest;
|
|
23
23
|
protected request(params: RequestParams): Promise<Stream.Readable>;
|
|
24
24
|
ping(): Promise<boolean>;
|
|
25
|
-
query(params: BaseParams): Promise<
|
|
26
|
-
exec(params: BaseParams): Promise<
|
|
27
|
-
insert(params: InsertParams): Promise<
|
|
25
|
+
query(params: BaseParams): Promise<QueryResult>;
|
|
26
|
+
exec(params: BaseParams): Promise<QueryResult>;
|
|
27
|
+
insert(params: InsertParams): Promise<InsertResult>;
|
|
28
28
|
close(): Promise<void>;
|
|
29
|
+
private generateQueryId;
|
|
29
30
|
private logResponse;
|
|
30
31
|
protected getHeaders(params: RequestParams): {
|
|
31
32
|
'Content-Encoding'?: string | undefined;
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -10,6 +33,8 @@ const error_1 = require("../../error");
|
|
|
10
33
|
const http_search_params_1 = require("./http_search_params");
|
|
11
34
|
const transform_url_1 = require("./transform_url");
|
|
12
35
|
const utils_1 = require("../../utils");
|
|
36
|
+
const user_agent_1 = require("../../utils/user_agent");
|
|
37
|
+
const uuid = __importStar(require("uuid"));
|
|
13
38
|
function isSuccessfulResponse(statusCode) {
|
|
14
39
|
return Boolean(statusCode && 200 <= statusCode && statusCode < 300);
|
|
15
40
|
}
|
|
@@ -78,6 +103,7 @@ class BaseHttpAdapter {
|
|
|
78
103
|
buildDefaultHeaders(username, password) {
|
|
79
104
|
return {
|
|
80
105
|
Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
|
|
106
|
+
'User-Agent': (0, user_agent_1.getUserAgent)(this.config.application_id),
|
|
81
107
|
};
|
|
82
108
|
}
|
|
83
109
|
async request(params) {
|
|
@@ -89,7 +115,7 @@ class BaseHttpAdapter {
|
|
|
89
115
|
reject(err);
|
|
90
116
|
}
|
|
91
117
|
const onResponse = async (_response) => {
|
|
92
|
-
this.logResponse(params, _response, start);
|
|
118
|
+
this.logResponse(request, params, _response, start);
|
|
93
119
|
const decompressionResult = decompressResponse(_response);
|
|
94
120
|
if (isDecompressionError(decompressionResult)) {
|
|
95
121
|
return reject(decompressionResult.error);
|
|
@@ -185,50 +211,64 @@ class BaseHttpAdapter {
|
|
|
185
211
|
}
|
|
186
212
|
async ping() {
|
|
187
213
|
// TODO add status code check
|
|
188
|
-
const
|
|
214
|
+
const stream = await this.request({
|
|
189
215
|
method: 'GET',
|
|
190
216
|
url: (0, transform_url_1.transformUrl)({ url: this.config.url, pathname: '/ping' }),
|
|
191
217
|
});
|
|
192
|
-
|
|
218
|
+
stream.destroy();
|
|
193
219
|
return true;
|
|
194
220
|
}
|
|
195
221
|
async query(params) {
|
|
222
|
+
const query_id = this.generateQueryId();
|
|
196
223
|
const clickhouse_settings = withHttpSettings(params.clickhouse_settings, this.config.compression.decompress_response);
|
|
197
224
|
const searchParams = (0, http_search_params_1.toSearchParams)({
|
|
198
225
|
database: this.config.database,
|
|
199
226
|
clickhouse_settings,
|
|
200
227
|
query_params: params.query_params,
|
|
201
228
|
session_id: params.session_id,
|
|
229
|
+
query_id,
|
|
202
230
|
});
|
|
203
|
-
|
|
231
|
+
const stream = await this.request({
|
|
204
232
|
method: 'POST',
|
|
205
233
|
url: (0, transform_url_1.transformUrl)({ url: this.config.url, pathname: '/', searchParams }),
|
|
206
234
|
body: params.query,
|
|
207
235
|
abort_signal: params.abort_signal,
|
|
208
236
|
decompress_response: clickhouse_settings.enable_http_compression === 1,
|
|
209
237
|
});
|
|
238
|
+
return {
|
|
239
|
+
stream,
|
|
240
|
+
query_id,
|
|
241
|
+
};
|
|
210
242
|
}
|
|
211
243
|
async exec(params) {
|
|
244
|
+
const query_id = this.generateQueryId();
|
|
212
245
|
const searchParams = (0, http_search_params_1.toSearchParams)({
|
|
213
246
|
database: this.config.database,
|
|
214
247
|
clickhouse_settings: params.clickhouse_settings,
|
|
215
248
|
query_params: params.query_params,
|
|
216
249
|
session_id: params.session_id,
|
|
250
|
+
query_id,
|
|
217
251
|
});
|
|
218
|
-
|
|
252
|
+
const stream = await this.request({
|
|
219
253
|
method: 'POST',
|
|
220
254
|
url: (0, transform_url_1.transformUrl)({ url: this.config.url, pathname: '/', searchParams }),
|
|
221
255
|
body: params.query,
|
|
222
256
|
abort_signal: params.abort_signal,
|
|
223
257
|
});
|
|
258
|
+
return {
|
|
259
|
+
stream,
|
|
260
|
+
query_id,
|
|
261
|
+
};
|
|
224
262
|
}
|
|
225
263
|
async insert(params) {
|
|
264
|
+
const query_id = this.generateQueryId();
|
|
226
265
|
const searchParams = (0, http_search_params_1.toSearchParams)({
|
|
227
266
|
database: this.config.database,
|
|
228
267
|
clickhouse_settings: params.clickhouse_settings,
|
|
229
268
|
query_params: params.query_params,
|
|
230
269
|
query: params.query,
|
|
231
270
|
session_id: params.session_id,
|
|
271
|
+
query_id,
|
|
232
272
|
});
|
|
233
273
|
await this.request({
|
|
234
274
|
method: 'POST',
|
|
@@ -237,15 +277,35 @@ class BaseHttpAdapter {
|
|
|
237
277
|
abort_signal: params.abort_signal,
|
|
238
278
|
compress_request: this.config.compression.compress_request,
|
|
239
279
|
});
|
|
280
|
+
return { query_id };
|
|
240
281
|
}
|
|
241
282
|
async close() {
|
|
242
283
|
if (this.agent !== undefined && this.agent.destroy !== undefined) {
|
|
243
284
|
this.agent.destroy();
|
|
244
285
|
}
|
|
245
286
|
}
|
|
246
|
-
|
|
287
|
+
// needed for insert queries as the query_id is not generated automatically
|
|
288
|
+
// we will use it for `exec` and `insert` methods, but not `select`
|
|
289
|
+
generateQueryId() {
|
|
290
|
+
return uuid.v4();
|
|
291
|
+
}
|
|
292
|
+
logResponse(request, params, response, startTimestamp) {
|
|
293
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
294
|
+
const { authorization, host, ...headers } = request.getHeaders();
|
|
247
295
|
const duration = Date.now() - startTimestamp;
|
|
248
|
-
this.logger.debug(
|
|
296
|
+
this.logger.debug({
|
|
297
|
+
module: 'HTTP Adapter',
|
|
298
|
+
message: 'Got a response from ClickHouse',
|
|
299
|
+
args: {
|
|
300
|
+
request_method: params.method,
|
|
301
|
+
request_path: params.url.pathname,
|
|
302
|
+
request_params: params.url.search,
|
|
303
|
+
request_headers: headers,
|
|
304
|
+
response_status: response.statusCode,
|
|
305
|
+
response_headers: response.headers,
|
|
306
|
+
response_time_ms: duration,
|
|
307
|
+
},
|
|
308
|
+
});
|
|
249
309
|
}
|
|
250
310
|
getHeaders(params) {
|
|
251
311
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_http_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/base_http_adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base_http_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/base_http_adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA2B;AAE3B,gDAAuB;AACvB,uCAAwC;AAYxC,6DAAqD;AACrD,mDAA8C;AAC9C,uCAAiD;AAEjD,uDAAqD;AACrD,2CAA4B;AAW5B,SAAS,oBAAoB,CAAC,UAAmB;IAC/C,OAAO,OAAO,CAAC,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,UAAU,GAAG,GAAG,CAAC,CAAA;AACrE,CAAC;AAED,SAAS,aAAa,CAAC,MAAW;IAChC,OAAO,qBAAqB,IAAI,MAAM,CAAA;AACxC,CAAC;AAED,SAAS,gBAAgB,CACvB,mBAAwC,EACxC,WAAqB;IAErB,OAAO;QACL,GAAG,CAAC,WAAW;YACb,CAAC,CAAC;gBACE,uBAAuB,EAAE,CAAC;aAC3B;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,mBAAmB;KACvB,CAAA;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,QAA8B;IAKxD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAErD,IAAI,QAAQ,KAAK,MAAM,EAAE;QACvB,OAAO;YACL,QAAQ,EAAE,gBAAM,CAAC,QAAQ,CACvB,QAAQ,EACR,cAAI,CAAC,YAAY,EAAE,EACnB,SAAS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MAAqB,EACrB,QAA8B,EAC9B,cAAsB;QAEtB,6DAA6D;QAC7D,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAA;QAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,CAAA;QAC5C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YAChB,MAAM,EAAE,cAAc;YACtB,OAAO,EAAE,gCAAgC;YACzC,IAAI,EAAE;gBACJ,cAAc,EAAE,MAAM,CAAC,MAAM;gBAC7B,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ;gBACjC,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM;gBACjC,eAAe,EAAE,OAAO;gBACxB,eAAe,EAAE,QAAQ,CAAC,UAAU;gBACpC,gBAAgB,EAAE,QAAQ,CAAC,OAAO;gBAClC,gBAAgB,EAAE,QAAQ;aAC3B;SACF,CAAC,CAAA;IACJ,CAAC;IAES,UAAU,CAAC,MAAqB;QACxC,OAAO;YACL,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnE,CAAA;IACH,CAAC;CACF;AAhRD,0CAgRC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import Http from 'http';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LogWriter } from '../../logger';
|
|
4
4
|
import type { Connection, ConnectionParams } from '../connection';
|
|
5
5
|
import type { RequestParams } from './base_http_adapter';
|
|
6
6
|
import { BaseHttpAdapter } from './base_http_adapter';
|
|
7
7
|
export declare class HttpAdapter extends BaseHttpAdapter implements Connection {
|
|
8
|
-
constructor(config: ConnectionParams, logger:
|
|
8
|
+
constructor(config: ConnectionParams, logger: LogWriter);
|
|
9
9
|
protected createClientRequest(url: URL, params: RequestParams): Http.ClientRequest;
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/http_adapter.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAKvB,2DAAqD;AAErD,MAAa,WAAY,SAAQ,mCAAe;IAC9C,YAAY,MAAwB,EAAE,
|
|
1
|
+
{"version":3,"file":"http_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/http_adapter.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAKvB,2DAAqD;AAErD,MAAa,WAAY,SAAQ,mCAAe;IAC9C,YAAY,MAAwB,EAAE,MAAiB;QACrD,MAAM,KAAK,GAAG,IAAI,cAAI,CAAC,KAAK,CAAC;YAC3B,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,MAAM,CAAC,eAAe;YAC/B,UAAU,EAAE,MAAM,CAAC,oBAAoB;SACxC,CAAC,CAAA;QACF,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;IAES,mBAAmB,CAC3B,GAAQ,EACR,MAAqB;QAErB,OAAO,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE;YAC9B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;SACjC,CAAC,CAAA;IACJ,CAAC;CACF;AApBD,kCAoBC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ClickHouseSettings } from '../../settings';
|
|
2
|
-
|
|
2
|
+
type ToSearchParamsOptions = {
|
|
3
3
|
database: string;
|
|
4
4
|
clickhouse_settings?: ClickHouseSettings;
|
|
5
5
|
query_params?: Record<string, unknown>;
|
|
6
6
|
query?: string;
|
|
7
7
|
session_id?: string;
|
|
8
|
+
query_id?: string;
|
|
8
9
|
};
|
|
9
|
-
export declare function toSearchParams({ database, query, query_params, clickhouse_settings, session_id, }: ToSearchParamsOptions): URLSearchParams | undefined;
|
|
10
|
+
export declare function toSearchParams({ database, query, query_params, clickhouse_settings, session_id, query_id, }: ToSearchParamsOptions): URLSearchParams | undefined;
|
|
10
11
|
export {};
|
|
@@ -4,7 +4,7 @@ exports.toSearchParams = void 0;
|
|
|
4
4
|
const data_formatter_1 = require("../../data_formatter/");
|
|
5
5
|
// TODO validate max length of the resulting query
|
|
6
6
|
// https://stackoverflow.com/questions/812925/what-is-the-maximum-possible-length-of-a-query-string
|
|
7
|
-
function toSearchParams({ database, query, query_params, clickhouse_settings, session_id, }) {
|
|
7
|
+
function toSearchParams({ database, query, query_params, clickhouse_settings, session_id, query_id, }) {
|
|
8
8
|
if (clickhouse_settings === undefined &&
|
|
9
9
|
query_params === undefined &&
|
|
10
10
|
query === undefined &&
|
|
@@ -33,6 +33,9 @@ function toSearchParams({ database, query, query_params, clickhouse_settings, se
|
|
|
33
33
|
if (session_id) {
|
|
34
34
|
params.set('session_id', session_id);
|
|
35
35
|
}
|
|
36
|
+
if (query_id) {
|
|
37
|
+
params.set('query_id', query_id);
|
|
38
|
+
}
|
|
36
39
|
return params;
|
|
37
40
|
}
|
|
38
41
|
exports.toSearchParams = toSearchParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_search_params.js","sourceRoot":"","sources":["../../../src/connection/adapter/http_search_params.ts"],"names":[],"mappings":";;;AAAA,0DAA8E;
|
|
1
|
+
{"version":3,"file":"http_search_params.js","sourceRoot":"","sources":["../../../src/connection/adapter/http_search_params.ts"],"names":[],"mappings":";;;AAAA,0DAA8E;AAY9E,kDAAkD;AAClD,mGAAmG;AACnG,SAAgB,cAAc,CAA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|
2
2
|
import type { RequestParams } from './base_http_adapter';
|
|
3
3
|
import { BaseHttpAdapter } from './base_http_adapter';
|
|
4
4
|
import type { Connection, ConnectionParams } from '../connection';
|
|
5
|
-
import type {
|
|
5
|
+
import type { LogWriter } from '../../logger';
|
|
6
6
|
import type Http from 'http';
|
|
7
7
|
export declare class HttpsAdapter extends BaseHttpAdapter implements Connection {
|
|
8
|
-
constructor(config: ConnectionParams, logger:
|
|
8
|
+
constructor(config: ConnectionParams, logger: LogWriter);
|
|
9
9
|
protected buildDefaultHeaders(username: string, password: string): Http.OutgoingHttpHeaders;
|
|
10
10
|
protected createClientRequest(url: URL, params: RequestParams): Http.ClientRequest;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"https_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/https_adapter.ts"],"names":[],"mappings":";;;;;;AACA,2DAAqD;AAGrD,kDAAyB;AAGzB,MAAa,YAAa,SAAQ,mCAAe;IAC/C,YAAY,MAAwB,EAAE,
|
|
1
|
+
{"version":3,"file":"https_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/https_adapter.ts"],"names":[],"mappings":";;;;;;AACA,2DAAqD;AAGrD,kDAAyB;AAGzB,MAAa,YAAa,SAAQ,mCAAe;IAC/C,YAAY,MAAwB,EAAE,MAAiB;;QACrD,MAAM,KAAK,GAAG,IAAI,eAAK,CAAC,KAAK,CAAC;YAC5B,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,MAAM,CAAC,eAAe;YAC/B,UAAU,EAAE,MAAM,CAAC,oBAAoB;YACvC,EAAE,EAAE,MAAA,MAAM,CAAC,GAAG,0CAAE,OAAO;YACvB,GAAG,EAAE,CAAA,MAAA,MAAM,CAAC,GAAG,0CAAE,IAAI,MAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;YAC/D,IAAI,EAAE,CAAA,MAAA,MAAM,CAAC,GAAG,0CAAE,IAAI,MAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;SAClE,CAAC,CAAA;QACF,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;IAEkB,mBAAmB,CACpC,QAAgB,EAChB,QAAgB;;QAEhB,IAAI,CAAA,MAAA,IAAI,CAAC,MAAM,CAAC,GAAG,0CAAE,IAAI,MAAK,QAAQ,EAAE;YACtC,OAAO;gBACL,mBAAmB,EAAE,QAAQ;gBAC7B,kBAAkB,EAAE,QAAQ;gBAC5B,mCAAmC,EAAE,IAAI;aAC1C,CAAA;SACF;QACD,IAAI,CAAA,MAAA,IAAI,CAAC,MAAM,CAAC,GAAG,0CAAE,IAAI,MAAK,OAAO,EAAE;YACrC,OAAO;gBACL,mBAAmB,EAAE,QAAQ;gBAC7B,kBAAkB,EAAE,QAAQ;aAC7B,CAAA;SACF;QACD,OAAO,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IACtD,CAAC;IAES,mBAAmB,CAC3B,GAAQ,EACR,MAAqB;QAErB,OAAO,eAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE;YAC/B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;SACjC,CAAC,CAAA;IACJ,CAAC;CACF;AA3CD,oCA2CC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import type Stream from 'stream';
|
|
4
|
-
import type {
|
|
4
|
+
import type { LogWriter } from '../logger';
|
|
5
5
|
import type { ClickHouseSettings } from '../settings';
|
|
6
6
|
export interface ConnectionParams {
|
|
7
7
|
url: URL;
|
|
8
|
+
application_id?: string;
|
|
8
9
|
connect_timeout: number;
|
|
9
10
|
request_timeout: number;
|
|
10
11
|
max_open_connections: number;
|
|
@@ -17,7 +18,7 @@ export interface ConnectionParams {
|
|
|
17
18
|
password: string;
|
|
18
19
|
database: string;
|
|
19
20
|
}
|
|
20
|
-
export
|
|
21
|
+
export type TLSParams = {
|
|
21
22
|
ca_cert: Buffer;
|
|
22
23
|
type: 'Basic';
|
|
23
24
|
} | {
|
|
@@ -36,11 +37,18 @@ export interface BaseParams {
|
|
|
36
37
|
export interface InsertParams extends BaseParams {
|
|
37
38
|
values: string | Stream.Readable;
|
|
38
39
|
}
|
|
40
|
+
export interface QueryResult {
|
|
41
|
+
stream: Stream.Readable;
|
|
42
|
+
query_id: string;
|
|
43
|
+
}
|
|
44
|
+
export interface InsertResult {
|
|
45
|
+
query_id: string;
|
|
46
|
+
}
|
|
39
47
|
export interface Connection {
|
|
40
48
|
ping(): Promise<boolean>;
|
|
41
49
|
close(): Promise<void>;
|
|
42
|
-
query(params: BaseParams): Promise<
|
|
43
|
-
exec(params: BaseParams): Promise<
|
|
44
|
-
insert(params: InsertParams): Promise<
|
|
50
|
+
query(params: BaseParams): Promise<QueryResult>;
|
|
51
|
+
exec(params: BaseParams): Promise<QueryResult>;
|
|
52
|
+
insert(params: InsertParams): Promise<InsertResult>;
|
|
45
53
|
}
|
|
46
|
-
export declare function createConnection(params: ConnectionParams, logger:
|
|
54
|
+
export declare function createConnection(params: ConnectionParams, logger: LogWriter): Connection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection/connection.ts"],"names":[],"mappings":";;;AAEA,uCAAqD;
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection/connection.ts"],"names":[],"mappings":";;;AAEA,uCAAqD;AAiErD,SAAgB,gBAAgB,CAC9B,MAAwB,EACxB,MAAiB;IAEjB,oCAAoC;IACpC,QAAQ,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;QAC3B,KAAK,OAAO;YACV,OAAO,IAAI,qBAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACxC,KAAK,QAAQ;YACX,OAAO,IAAI,sBAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACzC;YACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;KACzD;AACH,CAAC;AAbD,4CAaC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
declare const supportedJSONFormats: readonly ["JSON", "JSONObjectEachRow", "JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
|
|
2
2
|
declare const supportedRawFormats: readonly ["CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes"];
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
3
|
+
export type JSONDataFormat = (typeof supportedJSONFormats)[number];
|
|
4
|
+
export type RawDataFormat = (typeof supportedRawFormats)[number];
|
|
5
|
+
export type DataFormat = JSONDataFormat | RawDataFormat;
|
|
6
6
|
declare const streamableFormat: readonly ["JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes", "CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes"];
|
|
7
|
-
|
|
7
|
+
type StreamableDataFormat = (typeof streamableFormat)[number];
|
|
8
8
|
export declare function isSupportedRawFormat(dataFormat: DataFormat): boolean;
|
|
9
9
|
export declare function validateStreamFormat(format: any): format is StreamableDataFormat;
|
|
10
10
|
/**
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export interface LogParams {
|
|
2
|
+
module: string;
|
|
3
|
+
message: string;
|
|
4
|
+
args?: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export type ErrorLogParams = LogParams & {
|
|
7
|
+
err: Error;
|
|
8
|
+
};
|
|
9
|
+
export interface Logger {
|
|
10
|
+
debug(params: LogParams): void;
|
|
11
|
+
info(params: LogParams): void;
|
|
12
|
+
warn(params: LogParams): void;
|
|
13
|
+
error(params: ErrorLogParams): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class DefaultLogger implements Logger {
|
|
16
|
+
debug({ module, message, args }: LogParams): void;
|
|
17
|
+
info({ module, message, args }: LogParams): void;
|
|
18
|
+
warn({ module, message, args }: LogParams): void;
|
|
19
|
+
error({ module, message, args, err }: ErrorLogParams): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class LogWriter {
|
|
22
|
+
private readonly logger;
|
|
23
|
+
private readonly logLevel;
|
|
24
|
+
constructor(logger: Logger);
|
|
25
|
+
debug(params: LogParams): void;
|
|
26
|
+
info(params: LogParams): void;
|
|
27
|
+
warn(params: LogParams): void;
|
|
28
|
+
error(params: ErrorLogParams): void;
|
|
29
|
+
private getClickHouseLogLevel;
|
|
8
30
|
}
|
package/dist/logger.js
CHANGED
|
@@ -1,35 +1,100 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.LogWriter = exports.DefaultLogger = void 0;
|
|
4
|
+
class DefaultLogger {
|
|
5
|
+
debug({ module, message, args }) {
|
|
6
|
+
console.debug(formatMessage({ module, message }), args);
|
|
7
|
+
}
|
|
8
|
+
info({ module, message, args }) {
|
|
9
|
+
console.info(formatMessage({ module, message }), args);
|
|
10
|
+
}
|
|
11
|
+
warn({ module, message, args }) {
|
|
12
|
+
console.warn(formatMessage({ module, message }), args);
|
|
13
|
+
}
|
|
14
|
+
error({ module, message, args, err }) {
|
|
15
|
+
console.error(formatMessage({ module, message }), args, err);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.DefaultLogger = DefaultLogger;
|
|
19
|
+
class LogWriter {
|
|
20
|
+
constructor(logger) {
|
|
21
|
+
Object.defineProperty(this, "logger", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: logger
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "logLevel", {
|
|
7
28
|
enumerable: true,
|
|
8
29
|
configurable: true,
|
|
9
30
|
writable: true,
|
|
10
|
-
value:
|
|
31
|
+
value: void 0
|
|
11
32
|
});
|
|
33
|
+
this.logLevel = this.getClickHouseLogLevel();
|
|
34
|
+
this.info({
|
|
35
|
+
module: 'Logger',
|
|
36
|
+
message: `Log level is set to ${ClickHouseLogLevel[this.logLevel]}`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
debug(params) {
|
|
40
|
+
if (this.logLevel <= ClickHouseLogLevel.DEBUG) {
|
|
41
|
+
this.logger.debug(params);
|
|
42
|
+
}
|
|
12
43
|
}
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
44
|
+
info(params) {
|
|
45
|
+
if (this.logLevel <= ClickHouseLogLevel.INFO) {
|
|
46
|
+
this.logger.info(params);
|
|
47
|
+
}
|
|
17
48
|
}
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
49
|
+
warn(params) {
|
|
50
|
+
if (this.logLevel <= ClickHouseLogLevel.WARN) {
|
|
51
|
+
this.logger.warn(params);
|
|
52
|
+
}
|
|
22
53
|
}
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
54
|
+
error(params) {
|
|
55
|
+
if (this.logLevel <= ClickHouseLogLevel.ERROR) {
|
|
56
|
+
this.logger.error(params);
|
|
57
|
+
}
|
|
27
58
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
59
|
+
getClickHouseLogLevel() {
|
|
60
|
+
const logLevelFromEnv = process.env['CLICKHOUSE_LOG_LEVEL'];
|
|
61
|
+
if (!logLevelFromEnv) {
|
|
62
|
+
return ClickHouseLogLevel.OFF;
|
|
63
|
+
}
|
|
64
|
+
const logLevel = logLevelFromEnv.toLocaleLowerCase();
|
|
65
|
+
if (logLevel === 'info') {
|
|
66
|
+
return ClickHouseLogLevel.INFO;
|
|
67
|
+
}
|
|
68
|
+
if (logLevel === 'warn') {
|
|
69
|
+
return ClickHouseLogLevel.WARN;
|
|
70
|
+
}
|
|
71
|
+
if (logLevel === 'error') {
|
|
72
|
+
return ClickHouseLogLevel.ERROR;
|
|
73
|
+
}
|
|
74
|
+
if (logLevel === 'debug') {
|
|
75
|
+
return ClickHouseLogLevel.DEBUG;
|
|
76
|
+
}
|
|
77
|
+
if (logLevel === 'trace') {
|
|
78
|
+
return ClickHouseLogLevel.TRACE;
|
|
79
|
+
}
|
|
80
|
+
if (logLevel === 'off') {
|
|
81
|
+
return ClickHouseLogLevel.OFF;
|
|
82
|
+
}
|
|
83
|
+
console.error(`Unknown CLICKHOUSE_LOG_LEVEL value: ${logLevelFromEnv}, logs are disabled`);
|
|
84
|
+
return ClickHouseLogLevel.OFF;
|
|
32
85
|
}
|
|
33
86
|
}
|
|
34
|
-
exports.
|
|
87
|
+
exports.LogWriter = LogWriter;
|
|
88
|
+
var ClickHouseLogLevel;
|
|
89
|
+
(function (ClickHouseLogLevel) {
|
|
90
|
+
ClickHouseLogLevel[ClickHouseLogLevel["TRACE"] = 0] = "TRACE";
|
|
91
|
+
ClickHouseLogLevel[ClickHouseLogLevel["DEBUG"] = 1] = "DEBUG";
|
|
92
|
+
ClickHouseLogLevel[ClickHouseLogLevel["INFO"] = 2] = "INFO";
|
|
93
|
+
ClickHouseLogLevel[ClickHouseLogLevel["WARN"] = 3] = "WARN";
|
|
94
|
+
ClickHouseLogLevel[ClickHouseLogLevel["ERROR"] = 4] = "ERROR";
|
|
95
|
+
ClickHouseLogLevel[ClickHouseLogLevel["OFF"] = 127] = "OFF";
|
|
96
|
+
})(ClickHouseLogLevel || (ClickHouseLogLevel = {}));
|
|
97
|
+
function formatMessage({ module, message, }) {
|
|
98
|
+
return `[@clickhouse/client][${module}] ${message}`;
|
|
99
|
+
}
|
|
35
100
|
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAaA,MAAa,aAAa;IACxB,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAa;QACxC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;IACzD,CAAC;IAED,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAa;QACvC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;IACxD,CAAC;IAED,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAa;QACvC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAA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class ResultSet {
|
|
5
5
|
private _stream;
|
|
6
6
|
private readonly format;
|
|
7
|
-
|
|
7
|
+
readonly query_id: string;
|
|
8
|
+
constructor(_stream: Stream.Readable, format: DataFormat, query_id: string);
|
|
8
9
|
/**
|
|
9
10
|
* The method waits for all the rows to be fully loaded
|
|
10
11
|
* and returns the result as a string.
|
package/dist/result.js
CHANGED
|
@@ -28,7 +28,7 @@ const stream_1 = __importStar(require("stream"));
|
|
|
28
28
|
const utils_1 = require("./utils");
|
|
29
29
|
const data_formatter_1 = require("./data_formatter");
|
|
30
30
|
class ResultSet {
|
|
31
|
-
constructor(_stream, format) {
|
|
31
|
+
constructor(_stream, format, query_id) {
|
|
32
32
|
Object.defineProperty(this, "_stream", {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
configurable: true,
|
|
@@ -41,6 +41,12 @@ class ResultSet {
|
|
|
41
41
|
writable: true,
|
|
42
42
|
value: format
|
|
43
43
|
});
|
|
44
|
+
Object.defineProperty(this, "query_id", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: query_id
|
|
49
|
+
});
|
|
44
50
|
}
|
|
45
51
|
/**
|
|
46
52
|
* The method waits for all the rows to be fully loaded
|
package/dist/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA0C;AAE1C,mCAAmC;AACnC,qDAAgF;AAEhF,MAAa,SAAS;IACpB,YACU,OAAwB,EACf,MAAkB;;;;;
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA0C;AAE1C,mCAAmC;AACnC,qDAAgF;AAEhF,MAAa,SAAS;IACpB,YACU,OAAwB,EACf,MAAkB,EACnB,QAAgB;;;;;mBAFxB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AY,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;wBAC1C,IAAI,CAAC,IAAI,CAAC;4BACR,IAAI;4BACJ,IAAI;gCACF,OAAO,IAAA,uBAAM,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;4BAC7B,CAAC;yBACF,CAAC,CAAA;qBACH;yBAAM;wBACL,IAAI,IAAI,CAAC,MAAM,EAAE;4BACf,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;yBAChB;wBACD,MAAK;qBACN;iBACF;gBACD,QAAQ,EAAE,CAAA;YACZ,CAAC;YACD,WAAW,EAAE,IAAI;YACjB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAA;QAEF,OAAO,gBAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,UAAU,CAAC,GAAG;YAClE,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;aACnB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC;CACF;AAtGD,8BAsGC;AAgBD,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
|
package/dist/schema/common.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Type } from './types';
|
|
2
|
-
export
|
|
2
|
+
export type Shape = {
|
|
3
3
|
[key: string]: Type;
|
|
4
4
|
};
|
|
5
|
-
export
|
|
5
|
+
export type Infer<S extends Shape> = {
|
|
6
6
|
[Field in keyof S]: S[Field]['underlying'];
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type NonEmptyArray<T> = [T, ...T[]];
|
package/dist/schema/engines.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export type TableEngine = MergeTreeFamily;
|
|
2
|
+
type MergeTreeFamily = ReturnType<typeof MergeTree> | ReturnType<typeof ReplicatedMergeTree> | ReturnType<typeof ReplacingMergeTree> | ReturnType<typeof SummingMergeTree> | ReturnType<typeof AggregatingMergeTree> | ReturnType<typeof CollapsingMergeTree> | ReturnType<typeof VersionedCollapsingMergeTree> | ReturnType<typeof GraphiteMergeTree>;
|
|
3
3
|
export declare const MergeTree: () => {
|
|
4
4
|
toString: () => string;
|
|
5
5
|
type: string;
|
package/dist/schema/table.js
CHANGED
|
@@ -20,13 +20,14 @@ class Table {
|
|
|
20
20
|
// TODO: better types
|
|
21
21
|
async create(options) {
|
|
22
22
|
const query = query_formatter_1.QueryFormatter.createTable(this.options, options);
|
|
23
|
-
|
|
23
|
+
const { stream } = await this.client.exec({
|
|
24
24
|
query,
|
|
25
25
|
clickhouse_settings: options.clickhouse_settings,
|
|
26
26
|
});
|
|
27
|
+
return stream;
|
|
27
28
|
}
|
|
28
|
-
insert({ abort_signal, clickhouse_settings, values, }) {
|
|
29
|
-
|
|
29
|
+
async insert({ abort_signal, clickhouse_settings, values, }) {
|
|
30
|
+
await this.client.insert({
|
|
30
31
|
clickhouse_settings,
|
|
31
32
|
abort_signal,
|
|
32
33
|
table: (0, query_formatter_1.getTableName)(this.options),
|
package/dist/schema/table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/schema/table.ts"],"names":[],"mappings":";;;AAGA,uDAAgE;AA4ChE,MAAa,KAAK;IAChB,YACmB,MAAwB,EACxB,OAAwB;;;;;mBADxB;;;;;;mBACA;;IAChB,CAAC;IAEJ,qBAAqB;IACrB,KAAK,CAAC,MAAM,CAAC,OAA8B;QACzC,MAAM,KAAK,GAAG,gCAAc,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC/D,
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/schema/table.ts"],"names":[],"mappings":";;;AAGA,uDA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AAI,IAAI,EAAE;oBACtB,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAe,CAAA;oBACrC,MAAM,KAAiB,CAAA;iBACxB;aACF;QACH,CAAC;QAED,OAAO;YACL,cAAc;YACd,IAAI,EAAE,KAAK,IAAI,EAAE;gBACf,MAAM,MAAM,GAAG,EAAE,CAAA;gBACjB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,cAAc,EAAE,EAAE;oBAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;wBACxB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;qBACtB;yBAAM;wBACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;qBACnB;iBACF;gBACD,OAAO,MAAM,CAAA;YACf,CAAC;SACF,CAAA;IACH,CAAC;CACF;AAtED,sBAsEC"}
|
package/dist/schema/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
type Int = UInt8 | UInt16 | UInt32 | UInt64 | UInt128 | UInt256;
|
|
2
|
+
type UInt = Int8 | Int16 | Int32 | Int64 | Int128 | Int256;
|
|
3
|
+
type Float = Float32 | Float64;
|
|
4
|
+
export type Type = Int | UInt | Float | Bool | String | FixedString | Array<any> | Nullable<any> | Map<any, any> | UUID | Enum<any> | LowCardinality<any> | Date | Date32 | DateTime | DateTime64 | IPv4 | IPv6;
|
|
5
5
|
export interface UInt8 {
|
|
6
6
|
underlying: number;
|
|
7
7
|
type: 'UInt8';
|
|
@@ -136,7 +136,7 @@ export interface UUID {
|
|
|
136
136
|
underlying: string;
|
|
137
137
|
}
|
|
138
138
|
export declare const UUID: UUID;
|
|
139
|
-
|
|
139
|
+
type StandardEnum<T> = {
|
|
140
140
|
[id: string]: T | string;
|
|
141
141
|
[n: number]: string;
|
|
142
142
|
};
|
|
@@ -145,7 +145,7 @@ export interface Enum<T extends StandardEnum<unknown>> {
|
|
|
145
145
|
underlying: keyof T;
|
|
146
146
|
}
|
|
147
147
|
export declare function Enum<T extends StandardEnum<unknown>>(enumVariable: T): Enum<T>;
|
|
148
|
-
|
|
148
|
+
type LowCardinalityDataType = String | FixedString | UInt | Int | Float | Date | DateTime;
|
|
149
149
|
export interface LowCardinality<T extends LowCardinalityDataType> {
|
|
150
150
|
type: 'LowCardinality';
|
|
151
151
|
underlying: T['underlying'];
|
|
@@ -156,13 +156,13 @@ export interface Array<T extends Type> {
|
|
|
156
156
|
underlying: globalThis.Array<T['underlying']>;
|
|
157
157
|
}
|
|
158
158
|
export declare const Array: <T extends Type>(inner: T) => Array<T>;
|
|
159
|
-
|
|
159
|
+
type NullableType = Int | UInt | Float | Bool | String | FixedString | UUID | Decimal | Enum<any> | Date | DateTime | Date32 | IPv4 | IPv6;
|
|
160
160
|
export interface Nullable<T extends NullableType> {
|
|
161
161
|
type: 'Nullable';
|
|
162
162
|
underlying: T['underlying'] | null;
|
|
163
163
|
}
|
|
164
164
|
export declare const Nullable: <T extends NullableType>(inner: T) => Nullable<T>;
|
|
165
|
-
|
|
165
|
+
type MapKey = String | Int | UInt | FixedString | UUID | Enum<any> | Date | DateTime | Date32;
|
|
166
166
|
export interface Map<K extends MapKey, V extends Type> {
|
|
167
167
|
type: 'Map';
|
|
168
168
|
underlying: Record<K['underlying'], V['underlying']>;
|
package/dist/settings.d.ts
CHANGED
|
@@ -1194,7 +1194,7 @@ interface ClickHouseServerSettings {
|
|
|
1194
1194
|
interface ClickHouseHTTPSettings {
|
|
1195
1195
|
wait_end_of_query?: Bool;
|
|
1196
1196
|
}
|
|
1197
|
-
export
|
|
1197
|
+
export type ClickHouseSettings = ClickHouseServerSettings & ClickHouseHTTPSettings;
|
|
1198
1198
|
export interface MergeTreeSettings {
|
|
1199
1199
|
/** When granule is written (default: 0) */
|
|
1200
1200
|
min_compress_block_size?: UInt64;
|
|
@@ -1413,41 +1413,41 @@ export interface MergeTreeSettings {
|
|
|
1413
1413
|
/** Run zero-copy in compatible mode during conversion process. (default: false) */
|
|
1414
1414
|
remote_fs_zero_copy_path_compatible_mode?: Bool;
|
|
1415
1415
|
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1416
|
+
type Bool = 0 | 1;
|
|
1417
|
+
type Int64 = string;
|
|
1418
|
+
type UInt64 = string;
|
|
1419
|
+
type UInt64Auto = string;
|
|
1420
|
+
type Float = number;
|
|
1421
|
+
type MaxThreads = number;
|
|
1422
|
+
type Seconds = number;
|
|
1423
|
+
type Milliseconds = number;
|
|
1424
|
+
type Char = string;
|
|
1425
|
+
type URI = string;
|
|
1426
|
+
type Map = SettingsMap;
|
|
1427
1427
|
export declare class SettingsMap {
|
|
1428
1428
|
private readonly record;
|
|
1429
1429
|
private constructor();
|
|
1430
1430
|
toString(): string;
|
|
1431
1431
|
static from(record: Record<string, string>): SettingsMap;
|
|
1432
1432
|
}
|
|
1433
|
-
export
|
|
1434
|
-
export
|
|
1435
|
-
export
|
|
1436
|
-
export
|
|
1437
|
-
export
|
|
1438
|
-
export
|
|
1439
|
-
export
|
|
1440
|
-
export
|
|
1441
|
-
export
|
|
1442
|
-
export
|
|
1443
|
-
export
|
|
1444
|
-
export
|
|
1445
|
-
export
|
|
1446
|
-
export
|
|
1447
|
-
export
|
|
1448
|
-
export
|
|
1449
|
-
export
|
|
1450
|
-
export
|
|
1451
|
-
export
|
|
1452
|
-
export
|
|
1433
|
+
export type LoadBalancing = 'random' | 'nearest_hostname' | 'in_order' | 'first_or_random' | 'round_robin';
|
|
1434
|
+
export type TotalsMode = 'before_having' | 'after_having_inclusive' | 'after_having_exclusive' | 'after_having_auto';
|
|
1435
|
+
export type DistributedProductMode = 'deny' | 'local' | 'global' | 'allow';
|
|
1436
|
+
export type LogsLevel = 'none' | 'fatal' | 'error' | 'warning' | 'information' | 'debug' | 'trace' | 'test';
|
|
1437
|
+
export type LogQueriesType = 'QUERY_START' | 'QUERY_FINISH' | 'EXCEPTION_BEFORE_START' | 'EXCEPTION_WHILE_PROCESSING';
|
|
1438
|
+
export type DefaultTableEngine = 'Memory' | 'ReplicatedMergeTree' | 'ReplacingMergeTree' | 'MergeTree' | 'StripeLog' | 'ReplicatedReplacingMergeTree' | 'Log' | 'None';
|
|
1439
|
+
export type MySQLDataTypesSupport = '' | 'date2String' | 'date2Date32' | 'datetime64' | 'decimal';
|
|
1440
|
+
export type UnionMode = '' | 'ALL' | 'DISTINCT';
|
|
1441
|
+
export type DistributedDDLOutputMode = 'never_throw' | 'null_status_on_timeout' | 'throw' | 'none';
|
|
1442
|
+
export type ShortCircuitFunctionEvaluation = 'force_enable' | 'disable' | 'enable';
|
|
1443
|
+
export type TransactionsWaitCSNMode = 'wait_unknown' | 'wait' | 'async';
|
|
1444
|
+
export type EscapingRule = 'CSV' | 'JSON' | 'Quoted' | 'Raw' | 'XML' | 'Escaped' | 'None';
|
|
1445
|
+
export type DateTimeOutputFormat = 'simple' | 'iso' | 'unix_timestamp';
|
|
1446
|
+
export type EnumComparingMode = 'by_names_case_insensitive' | 'by_values' | 'by_names';
|
|
1447
|
+
export type DateTimeInputFormat = 'best_effort_us' | 'best_effort' | 'basic';
|
|
1448
|
+
export type MsgPackUUIDRepresentation = 'ext' | 'str' | 'bin';
|
|
1449
|
+
export type OverflowMode = 'break' | 'throw';
|
|
1450
|
+
export type OverflowModeGroupBy = OverflowMode | 'any';
|
|
1451
|
+
export type JoinStrictness = 'ANY' | 'ALL' | '';
|
|
1452
|
+
export type JoinAlgorithm = 'prefer_partial_merge' | 'hash' | 'parallel_hash' | 'partial_merge' | 'auto';
|
|
1453
1453
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getProcessVersion(): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProcessVersion = void 0;
|
|
4
|
+
// for easy mocking in the tests
|
|
5
|
+
function getProcessVersion() {
|
|
6
|
+
return process.version;
|
|
7
|
+
}
|
|
8
|
+
exports.getProcessVersion = getProcessVersion;
|
|
9
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/utils/process.ts"],"names":[],"mappings":";;;AAAA,gCAAgC;AAChC,SAAgB,iBAAiB;IAC/B,OAAO,OAAO,CAAC,OAAO,CAAA;AACxB,CAAC;AAFD,8CAEC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getUserAgent = void 0;
|
|
30
|
+
const os = __importStar(require("os"));
|
|
31
|
+
const version_1 = __importDefault(require("../version"));
|
|
32
|
+
const process_1 = require("./process");
|
|
33
|
+
/**
|
|
34
|
+
* Generate a user agent string like
|
|
35
|
+
* clickhouse-js/0.0.11 (lv:nodejs/19.0.4; os:linux)
|
|
36
|
+
* or
|
|
37
|
+
* MyApplicationName clickhouse-js/0.0.11 (lv:nodejs/19.0.4; os:linux)
|
|
38
|
+
*/
|
|
39
|
+
function getUserAgent(application_id) {
|
|
40
|
+
const defaultUserAgent = `clickhouse-js/${version_1.default} (lv:nodejs/${(0, process_1.getProcessVersion)()}; os:${os.platform()})`;
|
|
41
|
+
return application_id
|
|
42
|
+
? `${application_id} ${defaultUserAgent}`
|
|
43
|
+
: defaultUserAgent;
|
|
44
|
+
}
|
|
45
|
+
exports.getUserAgent = getUserAgent;
|
|
46
|
+
//# sourceMappingURL=user_agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user_agent.js","sourceRoot":"","sources":["../../src/utils/user_agent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwB;AACxB,yDAAuC;AACvC,uCAA6C;AAE7C;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,cAAuB;IAClD,MAAM,gBAAgB,GAAG,iBAAiB,iBAAc,eAAe,IAAA,2BAAiB,GAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAA;IAClH,OAAO,cAAc;QACnB,CAAC,CAAC,GAAG,cAAc,IAAI,gBAAgB,EAAE;QACzC,CAAC,CAAC,gBAAgB,CAAA;AACtB,CAAC;AALD,oCAKC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,QAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clickhouse/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Official JS client for ClickHouse DB",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"typecheck": "tsc --project tsconfig.dev.json --noEmit",
|
|
24
24
|
"lint": "eslint . --ext .ts",
|
|
25
25
|
"lint:fix": "eslint --fix . --ext .ts",
|
|
26
|
-
"test": "jest --
|
|
26
|
+
"test": "jest --testPathPattern=__tests__ --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
|
|
27
27
|
"test:tls": "jest --testMatch='**/__tests__/tls/*.test.ts'",
|
|
28
|
-
"test:unit": "jest --
|
|
29
|
-
"test:integration": "jest --
|
|
30
|
-
"test:integration:local_cluster": "CLICKHOUSE_TEST_ENVIRONMENT=local_cluster jest --
|
|
31
|
-
"test:integration:cloud": "CLICKHOUSE_TEST_ENVIRONMENT=cloud jest --
|
|
28
|
+
"test:unit": "jest --testMatch='**/__tests__/{unit,utils}/*.test.ts'",
|
|
29
|
+
"test:integration": "jest --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
|
|
30
|
+
"test:integration:local_cluster": "CLICKHOUSE_TEST_ENVIRONMENT=local_cluster jest --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
|
|
31
|
+
"test:integration:cloud": "CLICKHOUSE_TEST_ENVIRONMENT=cloud jest --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
|
|
32
32
|
"prepare": "husky install"
|
|
33
33
|
},
|
|
34
34
|
"main": "dist/index.js",
|
|
@@ -37,29 +37,29 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"node-abort-controller": "^3.0.1"
|
|
40
|
+
"node-abort-controller": "^3.0.1",
|
|
41
|
+
"uuid": "^9.0.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"@types/
|
|
44
|
+
"@jest/reporters": "^29.4.0",
|
|
45
|
+
"@types/jest": "^29.4.0",
|
|
46
|
+
"@types/node": "^18.11.18",
|
|
45
47
|
"@types/split2": "^3.2.1",
|
|
46
|
-
"@types/uuid": "^
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
48
|
-
"@typescript-eslint/parser": "^5.
|
|
49
|
-
"eslint": "^8.
|
|
50
|
-
"eslint-config-prettier": "^8.
|
|
48
|
+
"@types/uuid": "^9.0.0",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^5.49.0",
|
|
50
|
+
"@typescript-eslint/parser": "^5.49.0",
|
|
51
|
+
"eslint": "^8.32.0",
|
|
52
|
+
"eslint-config-prettier": "^8.6.0",
|
|
51
53
|
"eslint-plugin-prettier": "^4.2.1",
|
|
52
|
-
"husky": "^8.0.
|
|
53
|
-
"jest": "^29.0
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"prettier": "2.7.1",
|
|
54
|
+
"husky": "^8.0.2",
|
|
55
|
+
"jest": "^29.4.0",
|
|
56
|
+
"lint-staged": "^13.1.0",
|
|
57
|
+
"prettier": "2.8.3",
|
|
57
58
|
"split2": "^4.1.0",
|
|
58
|
-
"ts-jest": "^29.0.
|
|
59
|
+
"ts-jest": "^29.0.5",
|
|
59
60
|
"ts-node": "^10.9.1",
|
|
60
|
-
"tsconfig-paths": "^4.1.
|
|
61
|
-
"typescript": "^4.
|
|
62
|
-
"uuid": "^9.0.0"
|
|
61
|
+
"tsconfig-paths": "^4.1.2",
|
|
62
|
+
"typescript": "^4.9.4"
|
|
63
63
|
},
|
|
64
64
|
"lint-staged": {
|
|
65
65
|
"*.ts": [
|