@clickhouse/client-common 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +14 -0
  3. package/dist/clickhouse_types.d.ts +59 -1
  4. package/dist/clickhouse_types.js +27 -0
  5. package/dist/clickhouse_types.js.map +1 -1
  6. package/dist/client.d.ts +126 -95
  7. package/dist/client.js +119 -76
  8. package/dist/client.js.map +1 -1
  9. package/dist/config.d.ts +173 -0
  10. package/dist/config.js +309 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/connection.d.ts +44 -13
  13. package/dist/connection.js.map +1 -1
  14. package/dist/data_formatter/format_query_params.d.ts +11 -1
  15. package/dist/data_formatter/format_query_params.js +102 -16
  16. package/dist/data_formatter/format_query_params.js.map +1 -1
  17. package/dist/data_formatter/format_query_settings.js +1 -2
  18. package/dist/data_formatter/format_query_settings.js.map +1 -1
  19. package/dist/data_formatter/formatter.d.ts +32 -14
  20. package/dist/data_formatter/formatter.js +27 -46
  21. package/dist/data_formatter/formatter.js.map +1 -1
  22. package/dist/data_formatter/index.d.ts +1 -1
  23. package/dist/data_formatter/index.js +2 -1
  24. package/dist/data_formatter/index.js.map +1 -1
  25. package/dist/error/error.d.ts +20 -0
  26. package/dist/error/error.js +69 -0
  27. package/dist/error/error.js.map +1 -0
  28. package/dist/error/index.d.ts +1 -1
  29. package/dist/error/index.js +1 -1
  30. package/dist/error/index.js.map +1 -1
  31. package/dist/index.d.ts +18 -12
  32. package/dist/index.js +34 -12
  33. package/dist/index.js.map +1 -1
  34. package/dist/logger.js +8 -8
  35. package/dist/logger.js.map +1 -1
  36. package/dist/parse/column_types.d.ts +127 -0
  37. package/dist/parse/column_types.js +540 -0
  38. package/dist/parse/column_types.js.map +1 -0
  39. package/dist/parse/index.d.ts +2 -0
  40. package/dist/parse/index.js +19 -0
  41. package/dist/parse/index.js.map +1 -0
  42. package/dist/parse/json_handling.d.ts +19 -0
  43. package/dist/parse/json_handling.js +8 -0
  44. package/dist/parse/json_handling.js.map +1 -0
  45. package/dist/result.d.ts +52 -8
  46. package/dist/result.js.map +1 -1
  47. package/dist/settings.d.ts +38 -2
  48. package/dist/settings.js.map +1 -1
  49. package/dist/ts_utils.d.ts +4 -0
  50. package/dist/ts_utils.js +3 -0
  51. package/dist/ts_utils.js.map +1 -0
  52. package/dist/utils/connection.d.ts +11 -3
  53. package/dist/utils/connection.js +19 -7
  54. package/dist/utils/connection.js.map +1 -1
  55. package/dist/utils/index.d.ts +2 -2
  56. package/dist/utils/index.js +2 -2
  57. package/dist/utils/index.js.map +1 -1
  58. package/dist/utils/sleep.d.ts +1 -0
  59. package/dist/utils/sleep.js +9 -0
  60. package/dist/utils/sleep.js.map +1 -0
  61. package/dist/utils/stream.d.ts +14 -0
  62. package/dist/utils/stream.js +53 -0
  63. package/dist/utils/stream.js.map +1 -0
  64. package/dist/utils/url.d.ts +5 -4
  65. package/dist/utils/url.js +22 -13
  66. package/dist/utils/url.js.map +1 -1
  67. package/dist/version.d.ts +1 -1
  68. package/dist/version.js +1 -1
  69. package/dist/version.js.map +1 -1
  70. package/package.json +6 -2
  71. package/dist/error/parse_error.d.ts +0 -12
  72. package/dist/error/parse_error.js +0 -41
  73. package/dist/error/parse_error.js.map +0 -1
  74. package/dist/utils/permutations.d.ts +0 -1
  75. package/dist/utils/permutations.js +0 -12
  76. package/dist/utils/permutations.js.map +0 -1
  77. package/dist/utils/string.d.ts +0 -1
  78. package/dist/utils/string.js +0 -8
  79. package/dist/utils/string.js.map +0 -1
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2016-2023 ClickHouse, Inc.
1
+ Copyright 2016-2024 ClickHouse, Inc.
2
2
 
3
3
  Apache License
4
4
  Version 2.0, January 2004
@@ -188,7 +188,7 @@ Copyright 2016-2023 ClickHouse, Inc.
188
188
  same "printed page" as the copyright notice for easier
189
189
  identification within third-party archives.
190
190
 
191
- Copyright 2016-2023 ClickHouse, Inc.
191
+ Copyright 2016-2024 ClickHouse, Inc.
192
192
 
193
193
  Licensed under the Apache License, Version 2.0 (the "License");
194
194
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -4,9 +4,23 @@
4
4
  </p>
5
5
  <br/>
6
6
  <p align="center">
7
+ <a href="https://www.npmjs.com/package/@clickhouse/client">
8
+ <img alt="NPM Version" src="https://img.shields.io/npm/v/%40clickhouse%2Fclient?color=%233178C6&logo=npm">
9
+ </a>
10
+
11
+ <a href="https://www.npmjs.com/package/@clickhouse/client">
12
+ <img alt="NPM Downloads" src="https://img.shields.io/npm/dw/%40clickhouse%2Fclient?color=%233178C6&logo=npm">
13
+ </a>
14
+
7
15
  <a href="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml">
8
16
  <img src="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml/badge.svg?branch=main">
9
17
  </a>
18
+
19
+ <a href="https://codecov.io/gh/ClickHouse/clickhouse-js">
20
+ <img src="https://codecov.io/gh/ClickHouse/clickhouse-js/graph/badge.svg?token=B832WB00WJ">
21
+ </a>
22
+
23
+ <img src="https://api.scorecard.dev/projects/github.com/ClickHouse/clickhouse-js/badge">
10
24
  </p>
11
25
 
12
26
  ## About
@@ -1,7 +1,7 @@
1
1
  export interface ResponseJSON<T = unknown> {
2
2
  data: Array<T>;
3
3
  query_id?: string;
4
- totals?: Record<string, number>;
4
+ totals?: T;
5
5
  extremes?: Record<string, any>;
6
6
  meta?: Array<{
7
7
  name: string;
@@ -13,6 +13,7 @@ export interface ResponseJSON<T = unknown> {
13
13
  bytes_read: number;
14
14
  };
15
15
  rows?: number;
16
+ rows_before_limit_at_least?: number;
16
17
  }
17
18
  export interface InputJSON<T = unknown> {
18
19
  meta: {
@@ -31,7 +32,64 @@ export interface ClickHouseSummary {
31
32
  result_rows: string;
32
33
  result_bytes: string;
33
34
  elapsed_ns: string;
35
+ /** Available only after ClickHouse 24.9 */
36
+ real_time_microseconds?: string;
34
37
  }
38
+ export type ResponseHeaders = Record<string, string | string[] | undefined>;
35
39
  export interface WithClickHouseSummary {
36
40
  summary?: ClickHouseSummary;
37
41
  }
42
+ export interface WithResponseHeaders {
43
+ response_headers: ResponseHeaders;
44
+ }
45
+ export interface ClickHouseProgress {
46
+ read_rows: string;
47
+ read_bytes: string;
48
+ elapsed_ns: string;
49
+ total_rows_to_read?: string;
50
+ }
51
+ export interface ProgressRow {
52
+ progress: ClickHouseProgress;
53
+ }
54
+ export type SpecialEventRow<T> = {
55
+ meta: Array<{
56
+ name: string;
57
+ type: string;
58
+ }>;
59
+ } | {
60
+ totals: T;
61
+ } | {
62
+ min: T;
63
+ } | {
64
+ max: T;
65
+ } | {
66
+ rows_before_limit_at_least: number | string;
67
+ } | {
68
+ rows_before_aggregation: number | string;
69
+ } | {
70
+ exception: string;
71
+ };
72
+ export type InsertValues<Stream, T = unknown> = ReadonlyArray<T> | Stream | InputJSON<T> | InputJSONObjectEachRow<T>;
73
+ export type NonEmptyArray<T> = [T, ...T[]];
74
+ export interface ClickHouseCredentialsAuth {
75
+ username?: string;
76
+ password?: string;
77
+ }
78
+ /** Supported in ClickHouse Cloud only */
79
+ export interface ClickHouseJWTAuth {
80
+ access_token: string;
81
+ }
82
+ export type ClickHouseAuth = ClickHouseCredentialsAuth | ClickHouseJWTAuth;
83
+ /** Type guard to use with `JSONEachRowWithProgress`, checking if the emitted row is a progress row.
84
+ * @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
85
+ export declare function isProgressRow(row: unknown): row is ProgressRow;
86
+ /** Type guard to use with `JSONEachRowWithProgress`, checking if the emitted row is a row with data.
87
+ * @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
88
+ export declare function isRow<T>(row: unknown): row is {
89
+ row: T;
90
+ };
91
+ /** Type guard to use with `JSONEachRowWithProgress`, checking if the row contains an exception.
92
+ * @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
93
+ export declare function isException(row: unknown): row is {
94
+ exception: string;
95
+ };
@@ -1,3 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isProgressRow = isProgressRow;
4
+ exports.isRow = isRow;
5
+ exports.isException = isException;
6
+ /** Type guard to use with `JSONEachRowWithProgress`, checking if the emitted row is a progress row.
7
+ * @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
8
+ function isProgressRow(row) {
9
+ return (row !== null &&
10
+ typeof row === 'object' &&
11
+ 'progress' in row &&
12
+ Object.keys(row).length === 1);
13
+ }
14
+ /** Type guard to use with `JSONEachRowWithProgress`, checking if the emitted row is a row with data.
15
+ * @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
16
+ function isRow(row) {
17
+ return (row !== null &&
18
+ typeof row === 'object' &&
19
+ 'row' in row &&
20
+ Object.keys(row).length === 1);
21
+ }
22
+ /** Type guard to use with `JSONEachRowWithProgress`, checking if the row contains an exception.
23
+ * @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
24
+ function isException(row) {
25
+ return (row !== null &&
26
+ typeof row === 'object' &&
27
+ 'exception' in row &&
28
+ Object.keys(row).length === 1);
29
+ }
3
30
  //# sourceMappingURL=clickhouse_types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"clickhouse_types.js","sourceRoot":"","sources":["../../../packages/client-common/src/clickhouse_types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"clickhouse_types.js","sourceRoot":"","sources":["../src/clickhouse_types.ts"],"names":[],"mappings":";;AAqFA,sCAOC;AAID,sBAOC;AAID,kCAOC;AA/BD;kFACkF;AAClF,SAAgB,aAAa,CAAC,GAAY;IACxC,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,UAAU,IAAI,GAAG;QACjB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAC9B,CAAA;AACH,CAAC;AAED;kFACkF;AAClF,SAAgB,KAAK,CAAI,GAAY;IACnC,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,KAAK,IAAI,GAAG;QACZ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAC9B,CAAA;AACH,CAAC;AAED;kFACkF;AAClF,SAAgB,WAAW,CAAC,GAAY;IACtC,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,WAAW,IAAI,GAAG;QAClB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAC9B,CAAA;AACH,CAAC"}
package/dist/client.d.ts CHANGED
@@ -1,68 +1,9 @@
1
- import type { ClickHouseLogLevel, ClickHouseSettings, Connection, ConnectionParams, ConnExecResult, Logger, WithClickHouseSummary } from '@clickhouse/client-common';
2
- import { type DataFormat } from '@clickhouse/client-common';
3
- import type { InputJSON, InputJSONObjectEachRow } from './clickhouse_types';
1
+ import type { BaseClickHouseClientConfigOptions, ClickHouseSettings, ConnExecResult, IsSame, WithClickHouseSummary, WithResponseHeaders } from './index';
2
+ import { type DataFormat } from './index';
3
+ import type { InsertValues, NonEmptyArray } from './clickhouse_types';
4
+ import type { ImplementationDetails } from './config';
4
5
  import type { ConnPingResult } from './connection';
5
6
  import type { BaseResultSet } from './result';
6
- export type MakeConnection<Stream> = (params: ConnectionParams) => Connection<Stream>;
7
- export type MakeResultSet<Stream> = (stream: Stream, format: DataFormat, session_id: string) => BaseResultSet<Stream>;
8
- export interface ValuesEncoder<Stream> {
9
- validateInsertValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): void;
10
- /**
11
- * A function encodes an array or a stream of JSON objects to a format compatible with ClickHouse.
12
- * If values are provided as an array of JSON objects, the function encodes it in place.
13
- * If values are provided as a stream of JSON objects, the function sets up the encoding of each chunk.
14
- * If values are provided as a raw non-object stream, the function does nothing.
15
- *
16
- * @param values a set of values to send to ClickHouse.
17
- * @param format a format to encode value to.
18
- */
19
- encodeValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): string | Stream;
20
- }
21
- export type CloseStream<Stream> = (stream: Stream) => Promise<void>;
22
- export interface ClickHouseClientConfigOptions<Stream> {
23
- impl: {
24
- make_connection: MakeConnection<Stream>;
25
- make_result_set: MakeResultSet<Stream>;
26
- values_encoder: ValuesEncoder<Stream>;
27
- close_stream: CloseStream<Stream>;
28
- };
29
- /** A ClickHouse instance URL. Default value: `http://localhost:8123`. */
30
- host?: string;
31
- /** The request timeout in milliseconds. Default value: `30_000`. */
32
- request_timeout?: number;
33
- /** Maximum number of sockets to allow per host. Default value: `10`. */
34
- max_open_connections?: number;
35
- compression?: {
36
- /** `response: true` instructs ClickHouse server to respond with
37
- * compressed response body. Default: true. */
38
- response?: boolean;
39
- /** `request: true` enabled compression on the client request body.
40
- * Default: false. */
41
- request?: boolean;
42
- };
43
- /** The name of the user on whose behalf requests are made.
44
- * Default: 'default'. */
45
- username?: string;
46
- /** The user password. Default: ''. */
47
- password?: string;
48
- /** The name of the application using the JS client.
49
- * Default: empty. */
50
- application?: string;
51
- /** Database name to use. Default value: `default`. */
52
- database?: string;
53
- /** ClickHouse settings to apply to all requests. Default value: {} */
54
- clickhouse_settings?: ClickHouseSettings;
55
- log?: {
56
- /** A class to instantiate a custom logger implementation.
57
- * Default: {@link DefaultLogger} */
58
- LoggerClass?: new () => Logger;
59
- /** Default: OFF */
60
- level?: ClickHouseLogLevel;
61
- };
62
- session_id?: string;
63
- additional_headers?: Record<string, string>;
64
- }
65
- export type BaseClickHouseClientConfigOptions<Stream> = Omit<ClickHouseClientConfigOptions<Stream>, 'impl'>;
66
7
  export interface BaseQueryParams {
67
8
  /** ClickHouse's settings that can be applied on query level. */
68
9
  clickhouse_settings?: ClickHouseSettings;
@@ -71,9 +12,28 @@ export interface BaseQueryParams {
71
12
  /** AbortSignal instance to cancel a request in progress. */
72
13
  abort_signal?: AbortSignal;
73
14
  /** A specific `query_id` that will be sent with this request.
74
- * If it is not set, a random identifier will be generated automatically by the client. */
15
+ * If it is not set, a random identifier will be generated automatically by the client. */
75
16
  query_id?: string;
17
+ /** A specific ClickHouse Session id for this query.
18
+ * If it is not set, {@link BaseClickHouseClientConfigOptions.session_id} will be used.
19
+ * @default undefined (no override) */
76
20
  session_id?: string;
21
+ /** A specific list of roles to use for this query.
22
+ * If it is not set, {@link BaseClickHouseClientConfigOptions.role} will be used.
23
+ * @default undefined (no override) */
24
+ role?: string | Array<string>;
25
+ /** When defined, overrides {@link BaseClickHouseClientConfigOptions.auth} for this particular request.
26
+ * @default undefined (no override) */
27
+ auth?: {
28
+ username: string;
29
+ password: string;
30
+ } | {
31
+ access_token: string;
32
+ };
33
+ /** Additional HTTP headers to attach to this particular request.
34
+ * Overrides the headers set in {@link BaseClickHouseClientConfigOptions.http_headers}.
35
+ * @default empty object */
36
+ http_headers?: Record<string, string>;
77
37
  }
78
38
  export interface QueryParams extends BaseQueryParams {
79
39
  /** Statement to execute. */
@@ -81,20 +41,56 @@ export interface QueryParams extends BaseQueryParams {
81
41
  /** Format of the resulting dataset. */
82
42
  format?: DataFormat;
83
43
  }
84
- export interface ExecParams extends BaseQueryParams {
85
- /** Statement to execute. */
44
+ /** Same parameters as {@link QueryParams}, but with `format` field as a type */
45
+ export type QueryParamsWithFormat<Format extends DataFormat> = Omit<QueryParams, 'format'> & {
46
+ format?: Format;
47
+ };
48
+ /** If the Format is not a literal type, fall back to the default behavior of the ResultSet,
49
+ * allowing to call all methods with all data shapes variants,
50
+ * and avoiding generated types that include all possible DataFormat literal values. */
51
+ export type QueryResult<Stream, Format extends DataFormat> = IsSame<Format, DataFormat> extends true ? BaseResultSet<Stream, unknown> : BaseResultSet<Stream, Format>;
52
+ export type ExecParams = BaseQueryParams & {
53
+ /** Statement to execute (including the FORMAT clause). By default, the query will be sent in the request body;
54
+ * If {@link ExecParamsWithValues.values} are defined, the query is sent as a request parameter,
55
+ * and the values are sent in the request body instead. */
86
56
  query: string;
87
- }
57
+ /** If set to `false`, the client _will not_ decompress the response stream, even if the response compression
58
+ * was requested by the client via the {@link BaseClickHouseClientConfigOptions.compression.response } setting.
59
+ * This could be useful if the response stream is passed to another application as-is,
60
+ * and the decompression is handled there.
61
+ * @note 1) Node.js only. This setting will have no effect on the Web version.
62
+ * @note 2) In case of an error, the stream will be decompressed anyway, regardless of this setting.
63
+ * @default true */
64
+ decompress_response_stream?: boolean;
65
+ /**
66
+ * If set to `true`, the client will ignore error responses from the server and return them as-is in the response stream.
67
+ * This could be useful if you want to handle error responses manually.
68
+ * @note 1) Node.js only. This setting will have no effect on the Web version.
69
+ * @note 2) Default behavior is to not ignore error responses, and throw an error when an error response
70
+ * is received. This includes decompressing the error response stream if it is compressed.
71
+ * @default false
72
+ */
73
+ ignore_error_response?: boolean;
74
+ };
75
+ export type ExecParamsWithValues<Stream> = ExecParams & {
76
+ /** If you have a custom INSERT statement to run with `exec`, the data from this stream will be inserted.
77
+ *
78
+ * NB: the data in the stream is expected to be serialized accordingly to the FORMAT clause
79
+ * used in {@link ExecParams.query} in this case.
80
+ *
81
+ * @see https://clickhouse.com/docs/en/interfaces/formats */
82
+ values: Stream;
83
+ };
88
84
  export type CommandParams = ExecParams;
89
85
  export type CommandResult = {
90
86
  query_id: string;
91
- } & WithClickHouseSummary;
87
+ } & WithClickHouseSummary & WithResponseHeaders;
92
88
  export type InsertResult = {
93
89
  /**
94
90
  * Indicates whether the INSERT statement was executed on the server.
95
91
  * Will be `false` if there was no data to insert.
96
- * For example: if {@link InsertParams.values} was an empty array,
97
- * the client does not any requests to the server, and {@link executed} is false.
92
+ * For example, if {@link InsertParams.values} was an empty array,
93
+ * the client does not send any requests to the server, and {@link executed} is false.
98
94
  */
99
95
  executed: boolean;
100
96
  /**
@@ -102,11 +98,8 @@ export type InsertResult = {
102
98
  * Otherwise, either {@link InsertParams.query_id} if it was set, or the id that was generated by the client.
103
99
  */
104
100
  query_id: string;
105
- } & WithClickHouseSummary;
101
+ } & WithClickHouseSummary & WithResponseHeaders;
106
102
  export type ExecResult<Stream> = ConnExecResult<Stream>;
107
- export type PingResult = ConnPingResult;
108
- export type InsertValues<Stream, T = unknown> = ReadonlyArray<T> | Stream | InputJSON<T> | InputJSONObjectEachRow<T>;
109
- type NonEmptyArray<T> = [T, ...T[]];
110
103
  /** {@link except} field contains a non-empty list of columns to exclude when generating `(* EXCEPT (...))` clause */
111
104
  export interface InsertColumnsExcept {
112
105
  except: NonEmptyArray<string>;
@@ -119,7 +112,7 @@ export interface InsertParams<Stream = unknown, T = unknown> extends BaseQueryPa
119
112
  /** Format of the dataset to insert. Default: `JSONCompactEachRow` */
120
113
  format?: DataFormat;
121
114
  /**
122
- * Allows to specify which columns the data will be inserted into.
115
+ * Allows specifying which columns the data will be inserted into.
123
116
  * Accepts either an array of strings (column names) or an object of {@link InsertColumnsExcept} type.
124
117
  * Examples of generated queries:
125
118
  *
@@ -132,54 +125,92 @@ export interface InsertParams<Stream = unknown, T = unknown> extends BaseQueryPa
132
125
  * See also: https://clickhouse.com/docs/en/sql-reference/statements/insert-into */
133
126
  columns?: NonEmptyArray<string> | InsertColumnsExcept;
134
127
  }
128
+ /** Parameters for the health-check request - using the built-in `/ping` endpoint.
129
+ * This is the default behavior for the Node.js version. */
130
+ export type PingParamsWithEndpoint = {
131
+ select: false;
132
+ } & Pick<BaseQueryParams, 'abort_signal' | 'http_headers'>;
133
+ /** Parameters for the health-check request - using a SELECT query.
134
+ * This is the default behavior for the Web version, as the `/ping` endpoint does not support CORS.
135
+ * Most of the standard `query` method params, e.g., `query_id`, `abort_signal`, `http_headers`, etc. will work,
136
+ * except for `query_params`, which does not make sense to allow in this method. */
137
+ export type PingParamsWithSelectQuery = {
138
+ select: true;
139
+ } & Omit<BaseQueryParams, 'query_params'>;
140
+ export type PingParams = PingParamsWithEndpoint | PingParamsWithSelectQuery;
141
+ export type PingResult = ConnPingResult;
135
142
  export declare class ClickHouseClient<Stream = unknown> {
143
+ private readonly clientClickHouseSettings;
136
144
  private readonly connectionParams;
137
145
  private readonly connection;
138
146
  private readonly makeResultSet;
139
147
  private readonly valuesEncoder;
140
- private readonly closeStream;
141
148
  private readonly sessionId?;
142
- constructor(config: ClickHouseClientConfigOptions<Stream>);
143
- private getQueryParams;
149
+ private readonly role?;
150
+ private readonly logWriter;
151
+ private readonly jsonHandling;
152
+ constructor(config: BaseClickHouseClientConfigOptions & ImplementationDetails<Stream>);
144
153
  /**
145
- * Used for most statements that can have a response, such as SELECT.
146
- * FORMAT clause should be specified separately via {@link QueryParams.format} (default is JSON)
147
- * Consider using {@link ClickHouseClient.insert} for data insertion,
148
- * or {@link ClickHouseClient.command} for DDLs.
154
+ * Used for most statements that can have a response, such as `SELECT`.
155
+ * FORMAT clause should be specified separately via {@link QueryParams.format} (default is `JSON`).
156
+ * Consider using {@link ClickHouseClient.insert} for data insertion, or {@link ClickHouseClient.command} for DDLs.
157
+ * Returns an implementation of {@link BaseResultSet}.
158
+ *
159
+ * See {@link DataFormat} for the formats supported by the client.
149
160
  */
150
- query(params: QueryParams): Promise<BaseResultSet<Stream>>;
161
+ query<Format extends DataFormat = 'JSON'>(params: QueryParamsWithFormat<Format>): Promise<QueryResult<Stream, Format>>;
151
162
  /**
152
163
  * It should be used for statements that do not have any output,
153
164
  * when the format clause is not applicable, or when you are not interested in the response at all.
154
- * Response stream is destroyed immediately as we do not expect useful information there.
165
+ * The response stream is destroyed immediately as we do not expect useful information there.
155
166
  * Examples of such statements are DDLs or custom inserts.
156
- * If you are interested in the response data, consider using {@link ClickHouseClient.exec}
167
+ *
168
+ * @note if you have a custom query that does not work with {@link ClickHouseClient.query},
169
+ * and you are interested in the response data, consider using {@link ClickHouseClient.exec}.
157
170
  */
158
171
  command(params: CommandParams): Promise<CommandResult>;
159
172
  /**
160
- * Similar to {@link ClickHouseClient.command}, but for the cases where the output is expected,
161
- * but format clause is not applicable. The caller of this method is expected to consume the stream,
162
- * otherwise, the request will eventually be timed out.
173
+ * Similar to {@link ClickHouseClient.command}, but for the cases where the output _is expected_,
174
+ * but format clause is not applicable. The caller of this method _must_ consume the stream,
175
+ * as the underlying socket will not be released until then, and the request will eventually be timed out.
176
+ *
177
+ * @note it is not intended to use this method to execute the DDLs, such as `CREATE TABLE` or similar;
178
+ * use {@link ClickHouseClient.command} instead.
163
179
  */
164
- exec(params: ExecParams): Promise<ExecResult<Stream>>;
180
+ exec(params: ExecParams | ExecParamsWithValues<Stream>): Promise<ExecResult<Stream>>;
165
181
  /**
166
182
  * The primary method for data insertion. It is recommended to avoid arrays in case of large inserts
167
183
  * to reduce application memory consumption and consider streaming for most of such use cases.
168
184
  * As the insert operation does not provide any output, the response stream is immediately destroyed.
169
- * In case of a custom insert operation, such as, for example, INSERT FROM SELECT,
170
- * consider using {@link ClickHouseClient.command}, passing the entire raw query there (including FORMAT clause).
185
+ *
186
+ * @note in case of a custom insert operation (e.g., `INSERT FROM SELECT`),
187
+ * consider using {@link ClickHouseClient.command}, passing the entire raw query there
188
+ * (including the `FORMAT` clause).
171
189
  */
172
190
  insert<T>(params: InsertParams<Stream, T>): Promise<InsertResult>;
173
191
  /**
174
- * Health-check request. It does not throw if an error occurs -
175
- * the error is returned inside the result object.
192
+ * A health-check request. It does not throw if an error occurs - the error is returned inside the result object.
193
+ *
194
+ * By default, Node.js version uses the built-in `/ping` endpoint, which does not verify credentials.
195
+ * Optionally, it can be switched to a `SELECT` query (see {@link PingParamsWithSelectQuery}).
196
+ * In that case, the server will verify the credentials.
197
+ *
198
+ * **NOTE**: Since the `/ping` endpoint does not support CORS, the Web version always uses a `SELECT` query.
176
199
  */
177
- ping(): Promise<PingResult>;
200
+ ping(params?: PingParams): Promise<PingResult>;
178
201
  /**
179
202
  * Shuts down the underlying connection.
180
203
  * This method should ideally be called only once per application lifecycle,
181
204
  * for example, during the graceful shutdown phase.
182
205
  */
183
206
  close(): Promise<void>;
207
+ /**
208
+ * Closes the client connection.
209
+ *
210
+ * Automatically called when using `using` statement in supported environments.
211
+ * @see {@link ClickHouseClient.close}
212
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using
213
+ */
214
+ [Symbol.asyncDispose](): Promise<void>;
215
+ private withClientQueryParams;
184
216
  }
185
- export {};