@clickhouse/client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +636 -0
  3. package/dist/clickhouse_types.d.ts +17 -0
  4. package/dist/clickhouse_types.js +3 -0
  5. package/dist/clickhouse_types.js.map +1 -0
  6. package/dist/client.d.ts +56 -0
  7. package/dist/client.js +180 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/connection/adapter/base_http_adapter.d.ts +33 -0
  10. package/dist/connection/adapter/base_http_adapter.js +257 -0
  11. package/dist/connection/adapter/base_http_adapter.js.map +1 -0
  12. package/dist/connection/adapter/http_adapter.d.ts +10 -0
  13. package/dist/connection/adapter/http_adapter.js +27 -0
  14. package/dist/connection/adapter/http_adapter.js.map +1 -0
  15. package/dist/connection/adapter/http_search_params.d.ts +9 -0
  16. package/dist/connection/adapter/http_search_params.js +36 -0
  17. package/dist/connection/adapter/http_search_params.js.map +1 -0
  18. package/dist/connection/adapter/https_adapter.d.ts +10 -0
  19. package/dist/connection/adapter/https_adapter.js +27 -0
  20. package/dist/connection/adapter/https_adapter.js.map +1 -0
  21. package/dist/connection/adapter/index.d.ts +2 -0
  22. package/dist/connection/adapter/index.js +8 -0
  23. package/dist/connection/adapter/index.js.map +1 -0
  24. package/dist/connection/adapter/transform_url.d.ts +5 -0
  25. package/dist/connection/adapter/transform_url.js +15 -0
  26. package/dist/connection/adapter/transform_url.js.map +1 -0
  27. package/dist/connection/connection.d.ts +34 -0
  28. package/dist/connection/connection.js +17 -0
  29. package/dist/connection/connection.js.map +1 -0
  30. package/dist/connection/index.d.ts +1 -0
  31. package/dist/connection/index.js +18 -0
  32. package/dist/connection/index.js.map +1 -0
  33. package/dist/data_formatter/format_query_params.d.ts +1 -0
  34. package/dist/data_formatter/format_query_params.js +61 -0
  35. package/dist/data_formatter/format_query_params.js.map +1 -0
  36. package/dist/data_formatter/format_query_settings.d.ts +2 -0
  37. package/dist/data_formatter/format_query_settings.js +21 -0
  38. package/dist/data_formatter/format_query_settings.js.map +1 -0
  39. package/dist/data_formatter/formatter.d.ts +23 -0
  40. package/dist/data_formatter/formatter.js +81 -0
  41. package/dist/data_formatter/formatter.js.map +1 -0
  42. package/dist/data_formatter/index.d.ts +3 -0
  43. package/dist/data_formatter/index.js +23 -0
  44. package/dist/data_formatter/index.js.map +1 -0
  45. package/dist/error/index.d.ts +1 -0
  46. package/dist/error/index.js +18 -0
  47. package/dist/error/index.js.map +1 -0
  48. package/dist/error/parse_error.d.ts +12 -0
  49. package/dist/error/parse_error.js +39 -0
  50. package/dist/error/parse_error.js.map +1 -0
  51. package/dist/index.d.ts +15 -0
  52. package/dist/index.js +14 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/logger.d.ts +8 -0
  55. package/dist/logger.js +35 -0
  56. package/dist/logger.js.map +1 -0
  57. package/dist/rows.d.ts +50 -0
  58. package/dist/rows.js +114 -0
  59. package/dist/rows.js.map +1 -0
  60. package/dist/schema/common.d.ts +8 -0
  61. package/dist/schema/common.js +3 -0
  62. package/dist/schema/common.js.map +1 -0
  63. package/dist/schema/compact.d.ts +3 -0
  64. package/dist/schema/compact.js +24 -0
  65. package/dist/schema/compact.js.map +1 -0
  66. package/dist/schema/engines.d.ts +40 -0
  67. package/dist/schema/engines.js +61 -0
  68. package/dist/schema/engines.js.map +1 -0
  69. package/dist/schema/index.d.ts +7 -0
  70. package/dist/schema/index.js +24 -0
  71. package/dist/schema/index.js.map +1 -0
  72. package/dist/schema/query_formatter.d.ts +9 -0
  73. package/dist/schema/query_formatter.js +48 -0
  74. package/dist/schema/query_formatter.js.map +1 -0
  75. package/dist/schema/result.d.ts +13 -0
  76. package/dist/schema/result.js +3 -0
  77. package/dist/schema/result.js.map +1 -0
  78. package/dist/schema/schema.d.ts +6 -0
  79. package/dist/schema/schema.js +20 -0
  80. package/dist/schema/schema.js.map +1 -0
  81. package/dist/schema/stream.d.ts +11 -0
  82. package/dist/schema/stream.js +25 -0
  83. package/dist/schema/stream.js.map +1 -0
  84. package/dist/schema/table.d.ts +44 -0
  85. package/dist/schema/table.js +70 -0
  86. package/dist/schema/table.js.map +1 -0
  87. package/dist/schema/types.d.ts +201 -0
  88. package/dist/schema/types.js +268 -0
  89. package/dist/schema/types.js.map +1 -0
  90. package/dist/schema/where.d.ts +8 -0
  91. package/dist/schema/where.js +43 -0
  92. package/dist/schema/where.js.map +1 -0
  93. package/dist/settings.d.ts +1453 -0
  94. package/dist/settings.js +28 -0
  95. package/dist/settings.js.map +1 -0
  96. package/dist/utils/index.d.ts +2 -0
  97. package/dist/utils/index.js +19 -0
  98. package/dist/utils/index.js.map +1 -0
  99. package/dist/utils/stream.d.ts +5 -0
  100. package/dist/utils/stream.js +32 -0
  101. package/dist/utils/stream.js.map +1 -0
  102. package/dist/utils/string.d.ts +1 -0
  103. package/dist/utils/string.js +9 -0
  104. package/dist/utils/string.js.map +1 -0
  105. package/package.json +63 -0
@@ -0,0 +1,27 @@
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.HttpsAdapter = void 0;
7
+ const base_http_adapter_1 = require("./base_http_adapter");
8
+ const https_1 = __importDefault(require("https"));
9
+ class HttpsAdapter extends base_http_adapter_1.BaseHttpAdapter {
10
+ constructor(config, logger) {
11
+ const agent = new https_1.default.Agent({
12
+ keepAlive: true,
13
+ timeout: config.request_timeout,
14
+ maxSockets: config.max_open_connections,
15
+ });
16
+ super(config, logger, agent);
17
+ }
18
+ createClientRequest(url, params) {
19
+ return https_1.default.request(params.url, {
20
+ method: params.method,
21
+ agent: this.agent,
22
+ headers: this.getHeaders(params),
23
+ });
24
+ }
25
+ }
26
+ exports.HttpsAdapter = HttpsAdapter;
27
+ //# sourceMappingURL=https_adapter.js.map
@@ -0,0 +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,MAAc;QAClD,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;SACxC,CAAC,CAAA;QACF,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IAC9B,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;AApBD,oCAoBC"}
@@ -0,0 +1,2 @@
1
+ export { HttpAdapter } from './http_adapter';
2
+ export { HttpsAdapter } from './https_adapter';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpsAdapter = exports.HttpAdapter = void 0;
4
+ var http_adapter_1 = require("./http_adapter");
5
+ Object.defineProperty(exports, "HttpAdapter", { enumerable: true, get: function () { return http_adapter_1.HttpAdapter; } });
6
+ var https_adapter_1 = require("./https_adapter");
7
+ Object.defineProperty(exports, "HttpsAdapter", { enumerable: true, get: function () { return https_adapter_1.HttpsAdapter; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection/adapter/index.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAAnC,2GAAA,WAAW,OAAA;AACpB,iDAA8C;AAArC,6GAAA,YAAY,OAAA"}
@@ -0,0 +1,5 @@
1
+ export declare function transformUrl({ url, pathname, searchParams, }: {
2
+ url: URL;
3
+ pathname?: string;
4
+ searchParams?: URLSearchParams;
5
+ }): URL;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformUrl = void 0;
4
+ function transformUrl({ url, pathname, searchParams, }) {
5
+ const newUrl = new URL(url);
6
+ if (pathname) {
7
+ newUrl.pathname = pathname;
8
+ }
9
+ if (searchParams) {
10
+ newUrl.search = searchParams === null || searchParams === void 0 ? void 0 : searchParams.toString();
11
+ }
12
+ return newUrl;
13
+ }
14
+ exports.transformUrl = transformUrl;
15
+ //# sourceMappingURL=transform_url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform_url.js","sourceRoot":"","sources":["../../../src/connection/adapter/transform_url.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,EAC3B,GAAG,EACH,QAAQ,EACR,YAAY,GAKb;IACC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;IAE3B,IAAI,QAAQ,EAAE;QACZ,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAA;KAC3B;IAED,IAAI,YAAY,EAAE;QAChB,MAAM,CAAC,MAAM,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,QAAQ,EAAE,CAAA;KACzC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AApBD,oCAoBC"}
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ import type Stream from 'stream';
3
+ import type { Logger } from '../logger';
4
+ import type { ClickHouseSettings } from '../settings';
5
+ export interface ConnectionParams {
6
+ url: URL;
7
+ connect_timeout: number;
8
+ request_timeout: number;
9
+ max_open_connections: number;
10
+ compression: {
11
+ decompress_response: boolean;
12
+ compress_request: boolean;
13
+ };
14
+ username: string;
15
+ password: string;
16
+ database: string;
17
+ }
18
+ export interface BaseParams {
19
+ query: string;
20
+ clickhouse_settings?: ClickHouseSettings;
21
+ query_params?: Record<string, unknown>;
22
+ abort_signal?: AbortSignal;
23
+ }
24
+ export interface InsertParams extends BaseParams {
25
+ values: string | Stream.Readable;
26
+ }
27
+ export interface Connection {
28
+ ping(): Promise<boolean>;
29
+ close(): Promise<void>;
30
+ select(params: BaseParams): Promise<Stream.Readable>;
31
+ command(params: BaseParams): Promise<Stream.Readable>;
32
+ insert(params: InsertParams): Promise<void>;
33
+ }
34
+ export declare function createConnection(params: ConnectionParams, logger: Logger): Connection;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConnection = void 0;
4
+ const adapter_1 = require("./adapter");
5
+ function createConnection(params, logger) {
6
+ // TODO throw ClickHouseClient error
7
+ switch (params.url.protocol) {
8
+ case 'http:':
9
+ return new adapter_1.HttpAdapter(params, logger);
10
+ case 'https:':
11
+ return new adapter_1.HttpsAdapter(params, logger);
12
+ default:
13
+ throw new Error('Only HTTP(s) adapters are supported');
14
+ }
15
+ }
16
+ exports.createConnection = createConnection;
17
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection/connection.ts"],"names":[],"mappings":";;;AAEA,uCAAqD;AAuCrD,SAAgB,gBAAgB,CAC9B,MAAwB,EACxB,MAAc;IAEd,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"}
@@ -0,0 +1 @@
1
+ export * from './connection';
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./connection"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B"}
@@ -0,0 +1 @@
1
+ export declare function formatQueryParams(value: any, wrapStringInQuotes?: boolean): string;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatQueryParams = void 0;
4
+ const utils_1 = require("../utils");
5
+ function withPadding(value) {
6
+ if (value > 9)
7
+ return String(value);
8
+ return `0${value}`;
9
+ }
10
+ function formatMillis(value) {
11
+ const ms = value.getMilliseconds();
12
+ if (ms === 0) {
13
+ return '';
14
+ }
15
+ if (ms > 99) {
16
+ return `.${ms}`;
17
+ }
18
+ if (ms > 9) {
19
+ return `.0${ms}`;
20
+ }
21
+ return `.00${ms}`;
22
+ }
23
+ function formatQueryParams(value, wrapStringInQuotes = false) {
24
+ if (value === null)
25
+ return 'NULL';
26
+ if (Number.isNaN(value))
27
+ return 'nan';
28
+ if (value === Number.POSITIVE_INFINITY)
29
+ return '+inf';
30
+ if (value === Number.NEGATIVE_INFINITY)
31
+ return '-inf';
32
+ if (typeof value === 'number')
33
+ return String(value);
34
+ if (typeof value === 'boolean')
35
+ return value ? '1' : '0';
36
+ if (typeof value === 'string') {
37
+ const escapedValue = (0, utils_1.replaceAll)((0, utils_1.replaceAll)(value, `\\`, `\\\\`), `'`, `\\'`);
38
+ return wrapStringInQuotes ? `'${escapedValue}'` : escapedValue;
39
+ }
40
+ if (Array.isArray(value)) {
41
+ const formatted = value.map((v) => formatQueryParams(v, true));
42
+ return `[${formatted.join(',')}]`;
43
+ }
44
+ if (value instanceof Date) {
45
+ // TODO add timezone support
46
+ const date = `${value.getFullYear()}-${withPadding(value.getMonth() + 1)}-${withPadding(value.getDate())}`;
47
+ const time = `${withPadding(value.getHours())}:${withPadding(value.getMinutes())}:${withPadding(value.getSeconds())}`;
48
+ const ms = formatMillis(value);
49
+ return `${date} ${time}${ms}`;
50
+ }
51
+ if (typeof value === 'object') {
52
+ const formatted = [];
53
+ for (const [key, val] of Object.entries(value)) {
54
+ formatted.push(`${formatQueryParams(key, true)}:${formatQueryParams(val, true)}`);
55
+ }
56
+ return `{${formatted.join(',')}}`;
57
+ }
58
+ throw new Error(`Unsupported value in query parameters: [${value}].`);
59
+ }
60
+ exports.formatQueryParams = formatQueryParams;
61
+ //# sourceMappingURL=format_query_params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format_query_params.js","sourceRoot":"","sources":["../../src/data_formatter/format_query_params.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ import { SettingsMap } from '../settings';
2
+ export declare function formatQuerySettings(value: number | string | boolean | SettingsMap): string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatQuerySettings = void 0;
4
+ const settings_1 = require("../settings");
5
+ function formatQuerySettings(value) {
6
+ if (typeof value === 'boolean')
7
+ return value ? '1' : '0';
8
+ if (typeof value === 'number')
9
+ return String(value);
10
+ if (typeof value === 'string')
11
+ return value;
12
+ // ClickHouse requires a specific, non-JSON format for passing maps
13
+ // as a setting value - single quotes instead of double
14
+ // Example: {'system.numbers':'number != 3'}
15
+ if (value instanceof settings_1.SettingsMap) {
16
+ return value.toString();
17
+ }
18
+ throw new Error(`Unsupported value in query settings: [${value}].`);
19
+ }
20
+ exports.formatQuerySettings = formatQuerySettings;
21
+ //# sourceMappingURL=format_query_settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format_query_settings.js","sourceRoot":"","sources":["../../src/data_formatter/format_query_settings.ts"],"names":[],"mappings":";;;AAAA,0CAAyC;AAEzC,SAAgB,mBAAmB,CACjC,KAA8C;IAE9C,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,mEAAmE;IACnE,uDAAuD;IACvD,4CAA4C;IAC5C,IAAI,KAAK,YAAY,sBAAW,EAAE;QAChC,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;KACxB;IACD,MAAM,IAAI,KAAK,CAAC,yCAAyC,KAAK,IAAI,CAAC,CAAA;AACrE,CAAC;AAbD,kDAaC"}
@@ -0,0 +1,23 @@
1
+ declare const supportedJSONFormats: readonly ["JSON", "JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
2
+ declare const supportedRawFormats: readonly ["CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes"];
3
+ export declare type JSONDataFormat = typeof supportedJSONFormats[number];
4
+ export declare type RawDataFormat = typeof supportedRawFormats[number];
5
+ export declare type DataFormat = JSONDataFormat | RawDataFormat;
6
+ declare const streamableFormat: readonly ["JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes", "CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes"];
7
+ declare type StreamableDataFormat = typeof streamableFormat[number];
8
+ export declare function isSupportedRawFormat(dataFormat: DataFormat): boolean;
9
+ export declare function validateStreamFormat(format: any): format is StreamableDataFormat;
10
+ /**
11
+ * Decodes a string in a ClickHouse format into a plain JavaScript object or an array of objects.
12
+ * @param text a string in a ClickHouse data format
13
+ * @param format One of the supported formats: https://clickhouse.com/docs/en/interfaces/formats/
14
+ */
15
+ export declare function decode(text: string, format: DataFormat): any;
16
+ /**
17
+ * Encodes a single row of values into a string in a JSON format acceptable by ClickHouse.
18
+ * @param value a single value to encode.
19
+ * @param format One of the supported JSON formats: https://clickhouse.com/docs/en/interfaces/formats/
20
+ * @returns string
21
+ */
22
+ export declare function encodeJSON(value: any, format: DataFormat): string;
23
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeJSON = exports.decode = exports.validateStreamFormat = exports.isSupportedRawFormat = void 0;
4
+ const streamableJSONFormats = [
5
+ 'JSONEachRow',
6
+ 'JSONStringsEachRow',
7
+ 'JSONCompactEachRow',
8
+ 'JSONCompactStringsEachRow',
9
+ 'JSONCompactEachRowWithNames',
10
+ 'JSONCompactEachRowWithNamesAndTypes',
11
+ 'JSONCompactStringsEachRowWithNames',
12
+ 'JSONCompactStringsEachRowWithNamesAndTypes',
13
+ ];
14
+ const supportedJSONFormats = ['JSON', ...streamableJSONFormats];
15
+ const supportedRawFormats = [
16
+ 'CSV',
17
+ 'CSVWithNames',
18
+ 'CSVWithNamesAndTypes',
19
+ 'TabSeparated',
20
+ 'TabSeparatedRaw',
21
+ 'TabSeparatedWithNames',
22
+ 'TabSeparatedWithNamesAndTypes',
23
+ 'CustomSeparated',
24
+ 'CustomSeparatedWithNames',
25
+ 'CustomSeparatedWithNamesAndTypes',
26
+ ];
27
+ // TODO add others formats
28
+ const streamableFormat = [
29
+ ...streamableJSONFormats,
30
+ ...supportedRawFormats,
31
+ ];
32
+ function isStreamableJSONFamily(format) {
33
+ // @ts-expect-error JSON is not assignable to streamableJSONFormats
34
+ return streamableJSONFormats.includes(format);
35
+ }
36
+ function isSupportedRawFormat(dataFormat) {
37
+ return supportedRawFormats.includes(dataFormat);
38
+ }
39
+ exports.isSupportedRawFormat = isSupportedRawFormat;
40
+ function validateStreamFormat(format) {
41
+ if (!streamableFormat.includes(format)) {
42
+ throw new Error(`${format} format is not streamable. Streamable formats: ${streamableFormat.join(',')}`);
43
+ }
44
+ return true;
45
+ }
46
+ exports.validateStreamFormat = validateStreamFormat;
47
+ /**
48
+ * Decodes a string in a ClickHouse format into a plain JavaScript object or an array of objects.
49
+ * @param text a string in a ClickHouse data format
50
+ * @param format One of the supported formats: https://clickhouse.com/docs/en/interfaces/formats/
51
+ */
52
+ function decode(text, format) {
53
+ if (format === 'JSON') {
54
+ return JSON.parse(text);
55
+ }
56
+ if (isStreamableJSONFamily(format)) {
57
+ return text
58
+ .split('\n')
59
+ .filter(Boolean)
60
+ .map((l) => decode(l, 'JSON'));
61
+ }
62
+ if (isSupportedRawFormat(format)) {
63
+ throw new Error(`cannot decode ${format} to JSON`);
64
+ }
65
+ throw new Error(`The client does not support [${format}] format decoding.`);
66
+ }
67
+ exports.decode = decode;
68
+ /**
69
+ * Encodes a single row of values into a string in a JSON format acceptable by ClickHouse.
70
+ * @param value a single value to encode.
71
+ * @param format One of the supported JSON formats: https://clickhouse.com/docs/en/interfaces/formats/
72
+ * @returns string
73
+ */
74
+ function encodeJSON(value, format) {
75
+ if (streamableJSONFormats.includes(format)) {
76
+ return JSON.stringify(value) + '\n';
77
+ }
78
+ throw new Error(`The client does not support JSON encoding in [${format}] format.`);
79
+ }
80
+ exports.encodeJSON = encodeJSON;
81
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/data_formatter/formatter.ts"],"names":[],"mappings":";;;AAAA,MAAM,qBAAqB,GAAG;IAC5B,aAAa;IACb,oBAAoB;IACpB,oBAAoB;IACpB,2BAA2B;IAC3B,6BAA6B;IAC7B,qCAAqC;IACrC,oCAAoC;IACpC,4CAA4C;CACpC,CAAA;AACV,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,GAAG,qBAAqB,CAAU,CAAA;AACxE,MAAM,mBAAmB,GAAG;IAC1B,KAAK;IACL,cAAc;IACd,sBAAsB;IACtB,cAAc;IACd,iBAAiB;IACjB,uBAAuB;IACvB,+BAA+B;IAC/B,iBAAiB;IACjB,0BAA0B;IAC1B,kCAAkC;CAC1B,CAAA;AAQV,0BAA0B;AAC1B,MAAM,gBAAgB,GAAG;IACvB,GAAG,qBAAqB;IACxB,GAAG,mBAAmB;CACd,CAAA;AAGV,SAAS,sBAAsB,CAC7B,MAAkB;IAElB,mEAAmE;IACnE,OAAO,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC/C,CAAC;AAED,SAAgB,oBAAoB,CAAC,UAAsB;IACzD,OAAQ,mBAAyC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;AACxE,CAAC;AAFD,oDAEC;AAED,SAAgB,oBAAoB,CAClC,MAAW;IAEX,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACtC,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,kDAAkD,gBAAgB,CAAC,IAAI,CAC9E,GAAG,CACJ,EAAE,CACJ,CAAA;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAXD,oDAWC;AAED;;;;GAIG;AACH,SAAgB,MAAM,CAAC,IAAY,EAAE,MAAkB;IACrD,IAAI,MAAM,KAAK,MAAM,EAAE;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;KACxB;IACD,IAAI,sBAAsB,CAAC,MAAM,CAAC,EAAE;QAClC,OAAO,IAAI;aACR,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,OAAO,CAAC;aACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;KACjC;IACD,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,iBAAiB,MAAM,UAAU,CAAC,CAAA;KACnD;IACD,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,oBAAoB,CAAC,CAAA;AAC7E,CAAC;AAdD,wBAcC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAU,EAAE,MAAkB;IACvD,IAAK,qBAA2C,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACjE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAA;KACpC;IACD,MAAM,IAAI,KAAK,CACb,iDAAiD,MAAM,WAAW,CACnE,CAAA;AACH,CAAC;AAPD,gCAOC"}
@@ -0,0 +1,3 @@
1
+ export * from './formatter';
2
+ export { formatQueryParams } from './format_query_params';
3
+ export { formatQuerySettings } from './format_query_settings';
@@ -0,0 +1,23 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.formatQuerySettings = exports.formatQueryParams = void 0;
18
+ __exportStar(require("./formatter"), exports);
19
+ var format_query_params_1 = require("./format_query_params");
20
+ Object.defineProperty(exports, "formatQueryParams", { enumerable: true, get: function () { return format_query_params_1.formatQueryParams; } });
21
+ var format_query_settings_1 = require("./format_query_settings");
22
+ Object.defineProperty(exports, "formatQuerySettings", { enumerable: true, get: function () { return format_query_settings_1.formatQuerySettings; } });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/data_formatter/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA;AAC1B,iEAA6D;AAApD,4HAAA,mBAAmB,OAAA"}
@@ -0,0 +1 @@
1
+ export * from './parse_error';
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./parse_error"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B"}
@@ -0,0 +1,12 @@
1
+ interface ParsedClickHouseError {
2
+ message: string;
3
+ code: string;
4
+ type?: string;
5
+ }
6
+ export declare class ClickHouseError extends Error {
7
+ readonly code: string;
8
+ readonly type: string | undefined;
9
+ constructor({ message, code, type }: ParsedClickHouseError);
10
+ }
11
+ export declare function parseError(input: string): ClickHouseError | Error;
12
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseError = exports.ClickHouseError = void 0;
4
+ const errorRe = /(Code|Error): (?<code>\d+).*Exception: (?<message>.+)\((?<type>(?=.+[A-Z]{3})[A-Z0-9_]+?)\)/s;
5
+ class ClickHouseError extends Error {
6
+ constructor({ message, code, type }) {
7
+ super(message);
8
+ Object.defineProperty(this, "code", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: void 0
13
+ });
14
+ Object.defineProperty(this, "type", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ this.code = code;
21
+ this.type = type;
22
+ // Set the prototype explicitly, see:
23
+ // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
24
+ Object.setPrototypeOf(this, ClickHouseError.prototype);
25
+ }
26
+ }
27
+ exports.ClickHouseError = ClickHouseError;
28
+ function parseError(input) {
29
+ const match = input.match(errorRe);
30
+ const groups = match === null || match === void 0 ? void 0 : match.groups;
31
+ if (groups) {
32
+ return new ClickHouseError(groups);
33
+ }
34
+ else {
35
+ return new Error(input);
36
+ }
37
+ }
38
+ exports.parseError = parseError;
39
+ //# sourceMappingURL=parse_error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse_error.js","sourceRoot":"","sources":["../../src/error/parse_error.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GACX,8FAA8F,CAAA;AAOhG,MAAa,eAAgB,SAAQ,KAAK;IAGxC,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAyB;QACxD,KAAK,CAAC,OAAO,CAAC,CAAA;QAHhB;;;;;WAAqB;QACrB;;;;;WAAiC;QAG/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAEhB,qCAAqC;QACrC,gIAAgI;QAChI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAA;IACxD,CAAC;CACF;AAZD,0CAYC;AAED,SAAgB,UAAU,CAAC,KAAa;IACtC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAClC,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAA2C,CAAA;IACjE,IAAI,MAAM,EAAE;QACV,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAA;KACnC;SAAM;QACL,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;KACxB;AACH,CAAC;AARD,gCAQC"}
@@ -0,0 +1,15 @@
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, } from './client';
8
+ export { Row, Rows } from './rows';
9
+ export type { Connection } 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, DataType } from './clickhouse_types';
14
+ export type { ClickHouseSettings } from './settings';
15
+ export { SettingsMap } from './settings';
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SettingsMap = exports.Rows = exports.Row = exports.createClient = void 0;
4
+ const client_1 = require("./client");
5
+ Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
6
+ exports.default = {
7
+ createClient: client_1.createClient,
8
+ };
9
+ var rows_1 = require("./rows");
10
+ Object.defineProperty(exports, "Row", { enumerable: true, get: function () { return rows_1.Row; } });
11
+ Object.defineProperty(exports, "Rows", { enumerable: true, get: function () { return rows_1.Rows; } });
12
+ var settings_1 = require("./settings");
13
+ Object.defineProperty(exports, "SettingsMap", { enumerable: true, get: function () { return settings_1.SettingsMap; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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;AAWD,+BAAkC;AAAzB,2FAAA,GAAG,OAAA;AAAE,4FAAA,IAAI,OAAA;AAQlB,uCAAwC;AAA/B,uGAAA,WAAW,OAAA"}
@@ -0,0 +1,8 @@
1
+ export declare class Logger {
2
+ readonly enabled: boolean;
3
+ constructor(enabled?: boolean);
4
+ debug(message: string): void;
5
+ info(message: string): void;
6
+ warning(message: string): void;
7
+ error(message: string): void;
8
+ }
package/dist/logger.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ class Logger {
5
+ constructor(enabled = false) {
6
+ Object.defineProperty(this, "enabled", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: enabled
11
+ });
12
+ }
13
+ debug(message) {
14
+ if (!this.enabled)
15
+ return;
16
+ console.log(message);
17
+ }
18
+ info(message) {
19
+ if (!this.enabled)
20
+ return;
21
+ console.log(message);
22
+ }
23
+ warning(message) {
24
+ if (!this.enabled)
25
+ return;
26
+ console.warn(message);
27
+ }
28
+ error(message) {
29
+ if (!this.enabled)
30
+ return;
31
+ console.error(message);
32
+ }
33
+ }
34
+ exports.Logger = Logger;
35
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAAA,MAAa,MAAM;IACjB,YAAqB,UAAU,KAAK;;;;;mBAAf;;IAAkB,CAAC;IAExC,KAAK,CAAC,OAAe;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAM;QACzB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACtB,CAAC;IAED,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAM;QACzB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACtB,CAAC;IAED,OAAO,CAAC,OAAe;QACrB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAM;QACzB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvB,CAAC;IAED,KAAK,CAAC,OAAe;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAM;QACzB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACxB,CAAC;CACF;AAtBD,wBAsBC"}
package/dist/rows.d.ts ADDED
@@ -0,0 +1,50 @@
1
+ /// <reference types="node" />
2
+ import Stream from 'stream';
3
+ import { type DataFormat } from './data_formatter';
4
+ export declare class Rows {
5
+ private _stream;
6
+ private readonly format;
7
+ constructor(_stream: Stream.Readable, format: DataFormat);
8
+ /**
9
+ * The method waits for all the rows to be fully loaded
10
+ * and returns the result as a string.
11
+ *
12
+ * The method will throw if the underlying stream was already consumed
13
+ * by calling the other methods
14
+ */
15
+ text(): Promise<string>;
16
+ /**
17
+ * The method waits for the all the rows to be fully loaded.
18
+ * When the response is received in full, it will be decoded to return JSON.
19
+ *
20
+ * The method will throw if the underlying stream was already consumed
21
+ * by calling the other methods
22
+ */
23
+ json<T>(): Promise<T>;
24
+ /**
25
+ * Returns a readable stream of {@link Row}s for responses
26
+ * in {@link StreamableDataFormat} format.
27
+ *
28
+ * The method will throw if called on a response in non-streamable format,
29
+ * and if the underlying stream was already consumed
30
+ * by calling the other methods
31
+ */
32
+ stream(): Stream.Readable;
33
+ close(): void;
34
+ }
35
+ export declare class Row {
36
+ private readonly chunk;
37
+ private readonly format;
38
+ constructor(chunk: string, format: DataFormat);
39
+ /**
40
+ * Returns a string representation of a row.
41
+ */
42
+ text(): string;
43
+ /**
44
+ * Returns a JSON representation of a row.
45
+ * The method will throw if called on a response in JSON incompatible format.
46
+ *
47
+ * It is safe to call this method multiple times.
48
+ */
49
+ json<T>(): T;
50
+ }