@clickhouse/client 0.1.0 → 0.2.0-beta1

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.
Files changed (120) hide show
  1. package/README.md +10 -6
  2. package/dist/client.d.ts +26 -128
  3. package/dist/client.js +39 -225
  4. package/dist/client.js.map +1 -1
  5. package/dist/connection/index.d.ts +3 -1
  6. package/dist/connection/index.js +3 -1
  7. package/dist/connection/index.js.map +1 -1
  8. package/dist/connection/node_base_connection.d.ts +50 -0
  9. package/dist/connection/node_base_connection.js +350 -0
  10. package/dist/connection/node_base_connection.js.map +1 -0
  11. package/dist/connection/node_http_connection.d.ts +11 -0
  12. package/dist/connection/node_http_connection.js +32 -0
  13. package/dist/connection/node_http_connection.js.map +1 -0
  14. package/dist/connection/node_https_connection.d.ts +12 -0
  15. package/dist/connection/node_https_connection.js +53 -0
  16. package/dist/connection/node_https_connection.js.map +1 -0
  17. package/dist/index.d.ts +4 -15
  18. package/dist/index.js +11 -9
  19. package/dist/index.js.map +1 -1
  20. package/dist/result_set.d.ts +13 -0
  21. package/dist/{result.js → result_set.js} +5 -32
  22. package/dist/result_set.js.map +1 -0
  23. package/dist/utils/encoder.d.ts +7 -0
  24. package/dist/utils/encoder.js +55 -0
  25. package/dist/utils/encoder.js.map +1 -0
  26. package/dist/utils/index.d.ts +3 -1
  27. package/dist/utils/index.js +3 -1
  28. package/dist/utils/index.js.map +1 -1
  29. package/dist/utils/process.js.map +1 -1
  30. package/dist/utils/stream.d.ts +1 -1
  31. package/dist/utils/stream.js.map +1 -1
  32. package/dist/utils/user_agent.js +1 -2
  33. package/dist/utils/user_agent.js.map +1 -1
  34. package/dist/version.d.ts +2 -2
  35. package/dist/version.js +2 -1
  36. package/dist/version.js.map +1 -1
  37. package/package.json +7 -48
  38. package/dist/clickhouse_types.d.ts +0 -24
  39. package/dist/clickhouse_types.js +0 -3
  40. package/dist/clickhouse_types.js.map +0 -1
  41. package/dist/connection/adapter/base_http_adapter.d.ts +0 -35
  42. package/dist/connection/adapter/base_http_adapter.js +0 -302
  43. package/dist/connection/adapter/base_http_adapter.js.map +0 -1
  44. package/dist/connection/adapter/http_adapter.d.ts +0 -10
  45. package/dist/connection/adapter/http_adapter.js +0 -27
  46. package/dist/connection/adapter/http_adapter.js.map +0 -1
  47. package/dist/connection/adapter/http_search_params.d.ts +0 -11
  48. package/dist/connection/adapter/http_search_params.js +0 -42
  49. package/dist/connection/adapter/http_search_params.js.map +0 -1
  50. package/dist/connection/adapter/https_adapter.d.ts +0 -11
  51. package/dist/connection/adapter/https_adapter.js +0 -48
  52. package/dist/connection/adapter/https_adapter.js.map +0 -1
  53. package/dist/connection/adapter/index.d.ts +0 -2
  54. package/dist/connection/adapter/index.js +0 -8
  55. package/dist/connection/adapter/index.js.map +0 -1
  56. package/dist/connection/adapter/transform_url.d.ts +0 -5
  57. package/dist/connection/adapter/transform_url.js +0 -15
  58. package/dist/connection/adapter/transform_url.js.map +0 -1
  59. package/dist/connection/connection.d.ts +0 -58
  60. package/dist/connection/connection.js +0 -17
  61. package/dist/connection/connection.js.map +0 -1
  62. package/dist/data_formatter/format_query_params.d.ts +0 -1
  63. package/dist/data_formatter/format_query_params.js +0 -61
  64. package/dist/data_formatter/format_query_params.js.map +0 -1
  65. package/dist/data_formatter/format_query_settings.d.ts +0 -2
  66. package/dist/data_formatter/format_query_settings.js +0 -21
  67. package/dist/data_formatter/format_query_settings.js.map +0 -1
  68. package/dist/data_formatter/formatter.d.ts +0 -23
  69. package/dist/data_formatter/formatter.js +0 -96
  70. package/dist/data_formatter/formatter.js.map +0 -1
  71. package/dist/data_formatter/index.d.ts +0 -3
  72. package/dist/data_formatter/index.js +0 -23
  73. package/dist/data_formatter/index.js.map +0 -1
  74. package/dist/error/index.d.ts +0 -1
  75. package/dist/error/index.js +0 -18
  76. package/dist/error/index.js.map +0 -1
  77. package/dist/error/parse_error.d.ts +0 -12
  78. package/dist/error/parse_error.js +0 -39
  79. package/dist/error/parse_error.js.map +0 -1
  80. package/dist/logger.d.ts +0 -30
  81. package/dist/logger.js +0 -100
  82. package/dist/logger.js.map +0 -1
  83. package/dist/result.d.ts +0 -52
  84. package/dist/result.js.map +0 -1
  85. package/dist/schema/common.d.ts +0 -8
  86. package/dist/schema/common.js +0 -3
  87. package/dist/schema/common.js.map +0 -1
  88. package/dist/schema/engines.d.ts +0 -40
  89. package/dist/schema/engines.js +0 -61
  90. package/dist/schema/engines.js.map +0 -1
  91. package/dist/schema/index.d.ts +0 -7
  92. package/dist/schema/index.js +0 -24
  93. package/dist/schema/index.js.map +0 -1
  94. package/dist/schema/query_formatter.d.ts +0 -9
  95. package/dist/schema/query_formatter.js +0 -48
  96. package/dist/schema/query_formatter.js.map +0 -1
  97. package/dist/schema/result.d.ts +0 -13
  98. package/dist/schema/result.js +0 -3
  99. package/dist/schema/result.js.map +0 -1
  100. package/dist/schema/schema.d.ts +0 -6
  101. package/dist/schema/schema.js +0 -20
  102. package/dist/schema/schema.js.map +0 -1
  103. package/dist/schema/stream.d.ts +0 -11
  104. package/dist/schema/stream.js +0 -25
  105. package/dist/schema/stream.js.map +0 -1
  106. package/dist/schema/table.d.ts +0 -44
  107. package/dist/schema/table.js +0 -73
  108. package/dist/schema/table.js.map +0 -1
  109. package/dist/schema/types.d.ts +0 -201
  110. package/dist/schema/types.js +0 -268
  111. package/dist/schema/types.js.map +0 -1
  112. package/dist/schema/where.d.ts +0 -8
  113. package/dist/schema/where.js +0 -43
  114. package/dist/schema/where.js.map +0 -1
  115. package/dist/settings.d.ts +0 -1453
  116. package/dist/settings.js +0 -28
  117. package/dist/settings.js.map +0 -1
  118. package/dist/utils/string.d.ts +0 -1
  119. package/dist/utils/string.js +0 -9
  120. package/dist/utils/string.js.map +0 -1
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeBaseConnection = void 0;
7
+ const client_common_1 = require("@clickhouse/client-common");
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const stream_1 = __importDefault(require("stream"));
10
+ const zlib_1 = __importDefault(require("zlib"));
11
+ const utils_1 = require("../utils");
12
+ const expiredSocketMessage = 'expired socket';
13
+ class NodeBaseConnection {
14
+ constructor(params, agent) {
15
+ Object.defineProperty(this, "params", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: params
20
+ });
21
+ Object.defineProperty(this, "agent", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: agent
26
+ });
27
+ Object.defineProperty(this, "headers", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ Object.defineProperty(this, "logger", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "retry_expired_sockets", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "known_sockets", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: new WeakMap()
50
+ });
51
+ this.logger = params.logWriter;
52
+ this.retry_expired_sockets =
53
+ params.keep_alive.enabled && params.keep_alive.retry_on_expired_socket;
54
+ this.headers = this.buildDefaultHeaders(params.username, params.password);
55
+ }
56
+ buildDefaultHeaders(username, password) {
57
+ return {
58
+ Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`,
59
+ 'User-Agent': (0, utils_1.getUserAgent)(this.params.application_id),
60
+ };
61
+ }
62
+ async request(params, retryCount = 0) {
63
+ try {
64
+ return await this._request(params);
65
+ }
66
+ catch (e) {
67
+ if (e instanceof Error && e.message === expiredSocketMessage) {
68
+ if (this.retry_expired_sockets && retryCount < 3) {
69
+ this.logger.trace({
70
+ module: 'Connection',
71
+ message: `Keep-Alive socket is expired, retrying with a new one, retries so far: ${retryCount}`,
72
+ });
73
+ return await this.request(params, retryCount + 1);
74
+ }
75
+ else {
76
+ throw new Error(`Socket hang up after ${retryCount} retries`);
77
+ }
78
+ }
79
+ throw e;
80
+ }
81
+ }
82
+ async _request(params) {
83
+ return new Promise((resolve, reject) => {
84
+ const start = Date.now();
85
+ const request = this.createClientRequest(params);
86
+ function onError(err) {
87
+ removeRequestListeners();
88
+ reject(err);
89
+ }
90
+ const onResponse = async (_response) => {
91
+ this.logResponse(request, params, _response, start);
92
+ const decompressionResult = decompressResponse(_response);
93
+ if (isDecompressionError(decompressionResult)) {
94
+ return reject(decompressionResult.error);
95
+ }
96
+ if ((0, client_common_1.isSuccessfulResponse)(_response.statusCode)) {
97
+ return resolve(decompressionResult.response);
98
+ }
99
+ else {
100
+ reject((0, client_common_1.parseError)(await (0, utils_1.getAsText)(decompressionResult.response)));
101
+ }
102
+ };
103
+ function onAbort() {
104
+ // Prefer 'abort' event since it always triggered unlike 'error' and 'close'
105
+ // see the full sequence of events https://nodejs.org/api/http.html#httprequesturl-options-callback
106
+ removeRequestListeners();
107
+ request.once('error', function () {
108
+ /**
109
+ * catch "Error: ECONNRESET" error which shouldn't be reported to users.
110
+ * see the full sequence of events https://nodejs.org/api/http.html#httprequesturl-options-callback
111
+ * */
112
+ });
113
+ reject(new Error('The user aborted a request.'));
114
+ }
115
+ function onClose() {
116
+ // Adapter uses 'close' event to clean up listeners after the successful response.
117
+ // It's necessary in order to handle 'abort' and 'timeout' events while response is streamed.
118
+ // It's always the last event, according to https://nodejs.org/docs/latest-v14.x/api/http.html#http_http_request_url_options_callback
119
+ removeRequestListeners();
120
+ }
121
+ function pipeStream() {
122
+ // if request.end() was called due to no data to send
123
+ if (request.writableEnded) {
124
+ return;
125
+ }
126
+ const bodyStream = (0, utils_1.isStream)(params.body)
127
+ ? params.body
128
+ : stream_1.default.Readable.from([params.body]);
129
+ const callback = (err) => {
130
+ if (err) {
131
+ removeRequestListeners();
132
+ reject(err);
133
+ }
134
+ };
135
+ if (params.compress_request) {
136
+ stream_1.default.pipeline(bodyStream, zlib_1.default.createGzip(), request, callback);
137
+ }
138
+ else {
139
+ stream_1.default.pipeline(bodyStream, request, callback);
140
+ }
141
+ }
142
+ const onSocket = (socket) => {
143
+ if (this.retry_expired_sockets) {
144
+ // if socket is reused
145
+ const socketInfo = this.known_sockets.get(socket);
146
+ if (socketInfo !== undefined) {
147
+ this.logger.trace({
148
+ module: 'Connection',
149
+ message: `Reused socket ${socketInfo.id}`,
150
+ });
151
+ // if a socket was reused at an unfortunate time,
152
+ // and is likely about to expire
153
+ const isPossiblyExpired = Date.now() - socketInfo.last_used_time >
154
+ this.params.keep_alive.socket_ttl;
155
+ if (isPossiblyExpired) {
156
+ this.logger.trace({
157
+ module: 'Connection',
158
+ message: 'Socket should be expired - terminate it',
159
+ });
160
+ this.known_sockets.delete(socket);
161
+ socket.destroy(); // immediately terminate the connection
162
+ request.destroy();
163
+ reject(new Error(expiredSocketMessage));
164
+ }
165
+ else {
166
+ this.logger.trace({
167
+ module: 'Connection',
168
+ message: `Socket ${socketInfo.id} is safe to be reused`,
169
+ });
170
+ this.known_sockets.set(socket, {
171
+ id: socketInfo.id,
172
+ last_used_time: Date.now(),
173
+ });
174
+ pipeStream();
175
+ }
176
+ }
177
+ else {
178
+ const socketId = crypto_1.default.randomUUID();
179
+ this.logger.trace({
180
+ module: 'Connection',
181
+ message: `Using a new socket ${socketId}`,
182
+ });
183
+ this.known_sockets.set(socket, {
184
+ id: socketId,
185
+ last_used_time: Date.now(),
186
+ });
187
+ pipeStream();
188
+ }
189
+ }
190
+ else {
191
+ // no need to track the reused sockets;
192
+ // keep alive is disabled or retry mechanism is not enabled
193
+ pipeStream();
194
+ }
195
+ // this is for request timeout only.
196
+ // The socket won't be actually destroyed,
197
+ // and it will be returned to the pool.
198
+ // TODO: investigate if can actually remove the idle sockets properly
199
+ socket.setTimeout(this.params.request_timeout, onTimeout);
200
+ };
201
+ function onTimeout() {
202
+ removeRequestListeners();
203
+ request.destroy();
204
+ reject(new Error('Timeout error.'));
205
+ }
206
+ function removeRequestListeners() {
207
+ if (request.socket !== null) {
208
+ request.socket.setTimeout(0); // reset previously set timeout
209
+ request.socket.removeListener('timeout', onTimeout);
210
+ }
211
+ request.removeListener('socket', onSocket);
212
+ request.removeListener('response', onResponse);
213
+ request.removeListener('error', onError);
214
+ request.removeListener('close', onClose);
215
+ if (params.abort_signal !== undefined) {
216
+ request.removeListener('abort', onAbort);
217
+ }
218
+ }
219
+ request.on('socket', onSocket);
220
+ request.on('response', onResponse);
221
+ request.on('error', onError);
222
+ request.on('close', onClose);
223
+ if (params.abort_signal !== undefined) {
224
+ params.abort_signal.addEventListener('abort', onAbort, { once: true });
225
+ }
226
+ if (!params.body)
227
+ return request.end();
228
+ });
229
+ }
230
+ async ping() {
231
+ // TODO add status code check
232
+ const stream = await this.request({
233
+ method: 'GET',
234
+ url: (0, client_common_1.transformUrl)({ url: this.params.url, pathname: '/ping' }),
235
+ });
236
+ stream.destroy();
237
+ return true;
238
+ }
239
+ async query(params) {
240
+ const query_id = getQueryId(params.query_id);
241
+ const clickhouse_settings = (0, client_common_1.withHttpSettings)(params.clickhouse_settings, this.params.compression.decompress_response);
242
+ const searchParams = (0, client_common_1.toSearchParams)({
243
+ database: this.params.database,
244
+ clickhouse_settings,
245
+ query_params: params.query_params,
246
+ session_id: params.session_id,
247
+ query_id,
248
+ });
249
+ const stream = await this.request({
250
+ method: 'POST',
251
+ url: (0, client_common_1.transformUrl)({ url: this.params.url, pathname: '/', searchParams }),
252
+ body: params.query,
253
+ abort_signal: params.abort_signal,
254
+ decompress_response: clickhouse_settings.enable_http_compression === 1,
255
+ });
256
+ return {
257
+ stream,
258
+ query_id,
259
+ };
260
+ }
261
+ async exec(params) {
262
+ const query_id = getQueryId(params.query_id);
263
+ const searchParams = (0, client_common_1.toSearchParams)({
264
+ database: this.params.database,
265
+ clickhouse_settings: params.clickhouse_settings,
266
+ query_params: params.query_params,
267
+ session_id: params.session_id,
268
+ query_id,
269
+ });
270
+ const stream = await this.request({
271
+ method: 'POST',
272
+ url: (0, client_common_1.transformUrl)({ url: this.params.url, pathname: '/', searchParams }),
273
+ body: params.query,
274
+ abort_signal: params.abort_signal,
275
+ });
276
+ return {
277
+ stream,
278
+ query_id,
279
+ };
280
+ }
281
+ async insert(params) {
282
+ const query_id = getQueryId(params.query_id);
283
+ const searchParams = (0, client_common_1.toSearchParams)({
284
+ database: this.params.database,
285
+ clickhouse_settings: params.clickhouse_settings,
286
+ query_params: params.query_params,
287
+ query: params.query,
288
+ session_id: params.session_id,
289
+ query_id,
290
+ });
291
+ const stream = await this.request({
292
+ method: 'POST',
293
+ url: (0, client_common_1.transformUrl)({ url: this.params.url, pathname: '/', searchParams }),
294
+ body: params.values,
295
+ abort_signal: params.abort_signal,
296
+ compress_request: this.params.compression.compress_request,
297
+ });
298
+ stream.destroy();
299
+ return { query_id };
300
+ }
301
+ async close() {
302
+ if (this.agent !== undefined && this.agent.destroy !== undefined) {
303
+ this.agent.destroy();
304
+ }
305
+ }
306
+ logResponse(request, params, response, startTimestamp) {
307
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
308
+ const { authorization, host, ...headers } = request.getHeaders();
309
+ const duration = Date.now() - startTimestamp;
310
+ this.params.logWriter.debug({
311
+ module: 'HTTP Adapter',
312
+ message: 'Got a response from ClickHouse',
313
+ args: {
314
+ request_method: params.method,
315
+ request_path: params.url.pathname,
316
+ request_params: params.url.search,
317
+ request_headers: headers,
318
+ response_status: response.statusCode,
319
+ response_headers: response.headers,
320
+ response_time_ms: duration,
321
+ },
322
+ });
323
+ }
324
+ }
325
+ exports.NodeBaseConnection = NodeBaseConnection;
326
+ function decompressResponse(response) {
327
+ const encoding = response.headers['content-encoding'];
328
+ if (encoding === 'gzip') {
329
+ return {
330
+ response: stream_1.default.pipeline(response, zlib_1.default.createGunzip(), function pipelineCb(err) {
331
+ if (err) {
332
+ console.error(err);
333
+ }
334
+ }),
335
+ };
336
+ }
337
+ else if (encoding !== undefined) {
338
+ return {
339
+ error: new Error(`Unexpected encoding: ${encoding}`),
340
+ };
341
+ }
342
+ return { response };
343
+ }
344
+ function isDecompressionError(result) {
345
+ return result.error !== undefined;
346
+ }
347
+ function getQueryId(query_id) {
348
+ return query_id || crypto_1.default.randomUUID();
349
+ }
350
+ //# sourceMappingURL=node_base_connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node_base_connection.js","sourceRoot":"","sources":["../../../../packages/client-node/src/connection/node_base_connection.ts"],"names":[],"mappings":";;;;;;AAUA,6DAMkC;AAClC,oDAA2B;AAG3B,oDAA2B;AAC3B,gDAAuB;AACvB,oCAA4D;AAgC5D,MAAM,oBAAoB,GAAG,gBAAgB,CAAA;AAE7C,MAAsB,kBAAkB;IAatC,YACqB,MAA4B,EAC5B,KAAiB;;;;;mBADjB;;;;;;mBACA;;QAZrB;;;;;WAAoD;QACpD;;;;;WAAkC;QAClC;;;;;WAA+C;QAC/C;;;;mBAAiC,IAAI,OAAO,EAMzC;WAAA;QAKD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;QAC9B,IAAI,CAAC,qBAAqB;YACxB,MAAM,CAAC,UAAU,CAAC,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,uBAAuB,CAAA;QACxE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC3E,CAAC;IAES,mBAAmB,CAC3B,QAAgB,EAChB,QAAgB;QAEhB,OAAO;YACL,aAAa,EAAE,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC,CAAC,QAAQ,CACrE,QAAQ,CACT,EAAE;YACH,YAAY,EAAE,IAAA,oBAAY,EAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;SACvD,CAAA;IACH,CAAC;IAMO,KAAK,CAAC,OAAO,CACn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O,EAAE,QAAQ,EAAE,CAAA;AACrB,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAW;IACvC,OAAO,MAAM,CAAC,KAAK,KAAK,SAAS,CAAA;AACnC,CAAC;AAED,SAAS,UAAU,CAAC,QAA4B;IAC9C,OAAO,QAAQ,IAAI,gBAAM,CAAC,UAAU,EAAE,CAAA;AACxC,CAAC"}
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { Connection } from '@clickhouse/client-common';
4
+ import Http from 'http';
5
+ import type Stream from 'stream';
6
+ import type { NodeConnectionParams, RequestParams } from './node_base_connection';
7
+ import { NodeBaseConnection } from './node_base_connection';
8
+ export declare class NodeHttpConnection extends NodeBaseConnection implements Connection<Stream.Readable> {
9
+ constructor(params: NodeConnectionParams);
10
+ protected createClientRequest(params: RequestParams): Http.ClientRequest;
11
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeHttpConnection = void 0;
7
+ const client_common_1 = require("@clickhouse/client-common");
8
+ const http_1 = __importDefault(require("http"));
9
+ const node_base_connection_1 = require("./node_base_connection");
10
+ class NodeHttpConnection extends node_base_connection_1.NodeBaseConnection {
11
+ constructor(params) {
12
+ const agent = new http_1.default.Agent({
13
+ keepAlive: params.keep_alive.enabled,
14
+ maxSockets: params.max_open_connections,
15
+ });
16
+ super(params, agent);
17
+ }
18
+ createClientRequest(params) {
19
+ return http_1.default.request(params.url, {
20
+ method: params.method,
21
+ agent: this.agent,
22
+ headers: (0, client_common_1.withCompressionHeaders)({
23
+ headers: this.headers,
24
+ compress_request: params.compress_request,
25
+ decompress_response: params.decompress_response,
26
+ }),
27
+ signal: params.abort_signal,
28
+ });
29
+ }
30
+ }
31
+ exports.NodeHttpConnection = NodeHttpConnection;
32
+ //# sourceMappingURL=node_http_connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node_http_connection.js","sourceRoot":"","sources":["../../../../packages/client-node/src/connection/node_http_connection.ts"],"names":[],"mappings":";;;;;;AACA,6DAAkE;AAClE,gDAAuB;AAMvB,iEAA2D;AAE3D,MAAa,kBACX,SAAQ,yCAAkB;IAG1B,YAAY,MAA4B;QACtC,MAAM,KAAK,GAAG,IAAI,cAAI,CAAC,KAAK,CAAC;YAC3B,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO;YACpC,UAAU,EAAE,MAAM,CAAC,oBAAoB;SACxC,CAAC,CAAA;QACF,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACtB,CAAC;IAES,mBAAmB,CAAC,MAAqB;QACjD,OAAO,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE;YAC9B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAA,sCAAsB,EAAC;gBAC9B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;gBACzC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;aAChD,CAAC;YACF,MAAM,EAAE,MAAM,CAAC,YAAY;SAC5B,CAAC,CAAA;IACJ,CAAC;CACF;AAxBD,gDAwBC"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { Connection } from '@clickhouse/client-common';
4
+ import type Http from 'http';
5
+ import type Stream from 'stream';
6
+ import type { NodeConnectionParams, RequestParams } from './node_base_connection';
7
+ import { NodeBaseConnection } from './node_base_connection';
8
+ export declare class NodeHttpsConnection extends NodeBaseConnection implements Connection<Stream.Readable> {
9
+ constructor(params: NodeConnectionParams);
10
+ protected buildDefaultHeaders(username: string, password: string): Http.OutgoingHttpHeaders;
11
+ protected createClientRequest(params: RequestParams): Http.ClientRequest;
12
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeHttpsConnection = void 0;
7
+ const client_common_1 = require("@clickhouse/client-common");
8
+ const https_1 = __importDefault(require("https"));
9
+ const node_base_connection_1 = require("./node_base_connection");
10
+ class NodeHttpsConnection extends node_base_connection_1.NodeBaseConnection {
11
+ constructor(params) {
12
+ var _a, _b, _c;
13
+ const agent = new https_1.default.Agent({
14
+ keepAlive: params.keep_alive.enabled,
15
+ maxSockets: params.max_open_connections,
16
+ ca: (_a = params.tls) === null || _a === void 0 ? void 0 : _a.ca_cert,
17
+ key: ((_b = params.tls) === null || _b === void 0 ? void 0 : _b.type) === 'Mutual' ? params.tls.key : undefined,
18
+ cert: ((_c = params.tls) === null || _c === void 0 ? void 0 : _c.type) === 'Mutual' ? params.tls.cert : undefined,
19
+ });
20
+ super(params, agent);
21
+ }
22
+ buildDefaultHeaders(username, password) {
23
+ var _a, _b;
24
+ if (((_a = this.params.tls) === null || _a === void 0 ? void 0 : _a.type) === 'Mutual') {
25
+ return {
26
+ 'X-ClickHouse-User': username,
27
+ 'X-ClickHouse-Key': password,
28
+ 'X-ClickHouse-SSL-Certificate-Auth': 'on',
29
+ };
30
+ }
31
+ if (((_b = this.params.tls) === null || _b === void 0 ? void 0 : _b.type) === 'Basic') {
32
+ return {
33
+ 'X-ClickHouse-User': username,
34
+ 'X-ClickHouse-Key': password,
35
+ };
36
+ }
37
+ return super.buildDefaultHeaders(username, password);
38
+ }
39
+ createClientRequest(params) {
40
+ return https_1.default.request(params.url, {
41
+ method: params.method,
42
+ agent: this.agent,
43
+ headers: (0, client_common_1.withCompressionHeaders)({
44
+ headers: this.headers,
45
+ compress_request: params.compress_request,
46
+ decompress_response: params.decompress_response,
47
+ }),
48
+ signal: params.abort_signal,
49
+ });
50
+ }
51
+ }
52
+ exports.NodeHttpsConnection = NodeHttpsConnection;
53
+ //# sourceMappingURL=node_https_connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node_https_connection.js","sourceRoot":"","sources":["../../../../packages/client-node/src/connection/node_https_connection.ts"],"names":[],"mappings":";;;;;;AACA,6DAAkE;AAElE,kDAAyB;AAMzB,iEAA2D;AAE3D,MAAa,mBACX,SAAQ,yCAAkB;IAG1B,YAAY,MAA4B;;QACtC,MAAM,KAAK,GAAG,IAAI,eAAK,CAAC,KAAK,CAAC;YAC5B,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO;YACpC,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,KAAK,CAAC,CAAA;IACtB,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,CAAC,MAAqB;QACjD,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,IAAA,sCAAsB,EAAC;gBAC9B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;gBACzC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;aAChD,CAAC;YACF,MAAM,EAAE,MAAM,CAAC,YAAY;SAC5B,CAAC,CAAA;IACJ,CAAC;CACF;AA/CD,kDA+CC"}
package/dist/index.d.ts CHANGED
@@ -1,15 +1,4 @@
1
- import { createClient } from './client';
2
- export { createClient };
3
- declare const _default: {
4
- createClient: typeof createClient;
5
- };
6
- export default _default;
7
- export { type ClickHouseClientConfigOptions, type ClickHouseClient, type BaseParams, type QueryParams, type ExecParams, type InsertParams, type CommandParams, type CommandResult, } from './client';
8
- export { Row, ResultSet } from './result';
9
- export type { Connection, ExecResult, InsertResult } from './connection';
10
- export type { DataFormat } from './data_formatter';
11
- export type { ClickHouseError } from './error';
12
- export type { Logger } from './logger';
13
- export type { ResponseJSON, InputJSON, InputJSONObjectEachRow, } from './clickhouse_types';
14
- export type { ClickHouseSettings } from './settings';
15
- export { SettingsMap } from './settings';
1
+ export { createConnection, createClient } from './client';
2
+ export { ResultSet } from './result_set';
3
+ /** Re-export @clickhouse/client-common types */
4
+ export { type BaseClickHouseClientConfigOptions, type ClickHouseClientConfigOptions, type BaseQueryParams, type QueryParams, type ExecParams, type InsertParams, type InsertValues, type CommandParams, type CommandResult, type ExecResult, type InsertResult, type DataFormat, type ErrorLogParams, type Logger, type LogParams, type ClickHouseSettings, type MergeTreeSettings, type Row, type ResponseJSON, type InputJSON, type InputJSONObjectEachRow, type BaseResultSet, ClickHouseError, ClickHouseLogLevel, ClickHouseClient, SettingsMap, } from '@clickhouse/client-common';
package/dist/index.js CHANGED
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SettingsMap = exports.ResultSet = exports.createClient = void 0;
4
- const client_1 = require("./client");
3
+ exports.SettingsMap = exports.ClickHouseClient = exports.ClickHouseLogLevel = exports.ClickHouseError = exports.ResultSet = exports.createClient = exports.createConnection = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "createConnection", { enumerable: true, get: function () { return client_1.createConnection; } });
5
6
  Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
6
- exports.default = {
7
- createClient: client_1.createClient,
8
- };
9
- var result_1 = require("./result");
10
- Object.defineProperty(exports, "ResultSet", { enumerable: true, get: function () { return result_1.ResultSet; } });
11
- var settings_1 = require("./settings");
12
- Object.defineProperty(exports, "SettingsMap", { enumerable: true, get: function () { return settings_1.SettingsMap; } });
7
+ var result_set_1 = require("./result_set");
8
+ Object.defineProperty(exports, "ResultSet", { enumerable: true, get: function () { return result_set_1.ResultSet; } });
9
+ /** Re-export @clickhouse/client-common types */
10
+ var client_common_1 = require("@clickhouse/client-common");
11
+ Object.defineProperty(exports, "ClickHouseError", { enumerable: true, get: function () { return client_common_1.ClickHouseError; } });
12
+ Object.defineProperty(exports, "ClickHouseLogLevel", { enumerable: true, get: function () { return client_common_1.ClickHouseLogLevel; } });
13
+ Object.defineProperty(exports, "ClickHouseClient", { enumerable: true, get: function () { return client_common_1.ClickHouseClient; } });
14
+ Object.defineProperty(exports, "SettingsMap", { enumerable: true, get: function () { return client_common_1.SettingsMap; } });
13
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAE9B,6FAFA,qBAAY,OAEA;AACrB,kBAAe;IACb,YAAY,EAAZ,qBAAY;CACb,CAAA;AAaD,mCAAyC;AAA3B,mGAAA,SAAS,OAAA;AAYvB,uCAAwC;AAA/B,uGAAA,WAAW,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/client-node/src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAyD;AAAhD,0GAAA,gBAAgB,OAAA;AAAE,sGAAA,YAAY,OAAA;AACvC,2CAAwC;AAA/B,uGAAA,SAAS,OAAA;AAElB,gDAAgD;AAChD,2DA2BkC;AAJhC,gHAAA,eAAe,OAAA;AACf,mHAAA,kBAAkB,OAAA;AAClB,iHAAA,gBAAgB,OAAA;AAChB,4GAAA,WAAW,OAAA"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import type { BaseResultSet, DataFormat } from '@clickhouse/client-common';
3
+ import Stream from 'stream';
4
+ export declare class ResultSet implements BaseResultSet<Stream.Readable> {
5
+ private _stream;
6
+ private readonly format;
7
+ readonly query_id: string;
8
+ constructor(_stream: Stream.Readable, format: DataFormat, query_id: string);
9
+ text(): Promise<string>;
10
+ json<T>(): Promise<T>;
11
+ stream(): Stream.Readable;
12
+ close(): void;
13
+ }
@@ -24,9 +24,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ResultSet = void 0;
27
+ const client_common_1 = require("@clickhouse/client-common");
27
28
  const stream_1 = __importStar(require("stream"));
28
29
  const utils_1 = require("./utils");
29
- const data_formatter_1 = require("./data_formatter");
30
30
  class ResultSet {
31
31
  constructor(_stream, format, query_id) {
32
32
  Object.defineProperty(this, "_stream", {
@@ -48,45 +48,18 @@ class ResultSet {
48
48
  value: query_id
49
49
  });
50
50
  }
51
- /**
52
- * The method waits for all the rows to be fully loaded
53
- * and returns the result as a string.
54
- *
55
- * The method will throw if the underlying stream was already consumed
56
- * by calling the other methods.
57
- */
58
51
  async text() {
59
52
  if (this._stream.readableEnded) {
60
53
  throw Error(streamAlreadyConsumedMessage);
61
54
  }
62
55
  return (await (0, utils_1.getAsText)(this._stream)).toString();
63
56
  }
64
- /**
65
- * The method waits for the all the rows to be fully loaded.
66
- * When the response is received in full, it will be decoded to return JSON.
67
- *
68
- * The method will throw if the underlying stream was already consumed
69
- * by calling the other methods.
70
- */
71
57
  async json() {
72
58
  if (this._stream.readableEnded) {
73
59
  throw Error(streamAlreadyConsumedMessage);
74
60
  }
75
- return (0, data_formatter_1.decode)(await this.text(), this.format);
61
+ return (0, client_common_1.decode)(await this.text(), this.format);
76
62
  }
77
- /**
78
- * Returns a readable stream for responses that can be streamed
79
- * (i.e. all except JSON).
80
- *
81
- * Every iteration provides an array of {@link Row} instances
82
- * for {@link StreamableDataFormat} format.
83
- *
84
- * Should be called only once.
85
- *
86
- * The method will throw if called on a response in non-streamable format,
87
- * and if the underlying stream was already consumed
88
- * by calling the other methods.
89
- */
90
63
  stream() {
91
64
  // If the underlying stream has already ended by calling `text` or `json`,
92
65
  // Stream.pipeline will create a new empty stream
@@ -94,7 +67,7 @@ class ResultSet {
94
67
  if (this._stream.readableEnded) {
95
68
  throw Error(streamAlreadyConsumedMessage);
96
69
  }
97
- (0, data_formatter_1.validateStreamFormat)(this.format);
70
+ (0, client_common_1.validateStreamFormat)(this.format);
98
71
  let decodedChunk = '';
99
72
  const toRows = new stream_1.Transform({
100
73
  transform(chunk, encoding, callback) {
@@ -109,7 +82,7 @@ class ResultSet {
109
82
  rows.push({
110
83
  text,
111
84
  json() {
112
- return (0, data_formatter_1.decode)(text, 'JSON');
85
+ return (0, client_common_1.decode)(text, 'JSON');
113
86
  },
114
87
  });
115
88
  }
@@ -137,4 +110,4 @@ class ResultSet {
137
110
  }
138
111
  exports.ResultSet = ResultSet;
139
112
  const streamAlreadyConsumedMessage = 'Stream has been already consumed';
140
- //# sourceMappingURL=result.js.map
113
+ //# sourceMappingURL=result_set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result_set.js","sourceRoot":"","sources":["../../../packages/client-node/src/result_set.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6DAAwE;AAExE,iDAA0C;AAC1C,mCAAmC;AAEnC,MAAa,SAAS;IACpB,YACU,OAAwB,EACf,MAAkB,EACnB,QAAgB;;;;;mBAFxB;;;;;;mBACS;;;;;;mBACD;;IACf,CAAC;IAEJ,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YAC9B,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC1C;QACD,OAAO,CAAC,MAAM,IAAA,iBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YAC9B,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC1C;QACD,OAAO,IAAA,sBAAM,EAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IAED,MAAM;QACJ,0EAA0E;QAC1E,iDAAiD;QACjD,+CAA+C;QAC/C,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YAC9B,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC1C;QAED,IAAA,oCAAoB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAEjC,IAAI,YAAY,GAAG,EAAE,CAAA;QACrB,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC;YAC3B,SAAS,CACP,KAAa,EACb,QAAwB,EACxB,QAA2B;gBAE3B,YAAY,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAA;gBAChC,MAAM,IAAI,GAAU,EAAE,CAAA;gBACtB,iDAAiD;gBACjD,OAAO,IAAI,EAAE;oBACX,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;oBACtC,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE;wBACd,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;wBACvC,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;wBAC1C,IAAI,CAAC,IAAI,CAAC;4BACR,IAAI;4BACJ,IAAI;gCACF,OAAO,IAAA,sBAAM,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;AA3ED,8BA2EC;AAED,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import type { DataFormat, InsertValues, ValuesEncoder } from '@clickhouse/client-common';
3
+ import Stream from 'stream';
4
+ export declare class NodeValuesEncoder implements ValuesEncoder<Stream.Readable> {
5
+ encodeValues<T>(values: InsertValues<Stream.Readable, T>, format: DataFormat): string | Stream.Readable;
6
+ validateInsertValues<T>(values: InsertValues<Stream.Readable, T>, format: DataFormat): void;
7
+ }