@clickhouse/client-web 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Copyright 2016-2023 ClickHouse, Inc.
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright 2016-2023 ClickHouse, Inc.
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ <p align="center">
2
+ <img src=".static/logo.png" width="200px" align="center">
3
+ <h1 align="center">ClickHouse JS client</h1>
4
+ </p>
5
+ <br/>
6
+ <p align="center">
7
+ <a href="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml">
8
+ <img src="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml/badge.svg?branch=main">
9
+ </a>
10
+ </p>
11
+
12
+ ## About
13
+
14
+ Official JS client for [ClickHouse](https://clickhouse.com/), written purely in TypeScript,
15
+ thoroughly tested with actual ClickHouse versions.
16
+
17
+ The repository consists of three packages:
18
+
19
+ - `@clickhouse/client` - a version of the client designed for Node.js platform only. It is built on top of [HTTP](https://nodejs.org/api/http.html)
20
+ and [Stream](https://nodejs.org/api/stream.html) APIs; supports streaming for both selects and inserts.
21
+ - `@clickhouse/client-web` - a version of the client built on top of [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
22
+ and [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) APIs; supports streaming for selects.
23
+ Compatible with Chrome/Firefox browsers and CloudFlare workers.
24
+ - `@clickhouse/client-common` - shared common types and the base framework for building a custom client implementation.
25
+
26
+ ## Documentation
27
+
28
+ See the [ClickHouse website](https://clickhouse.com/docs/en/integrations/language-clients/nodejs) for the full documentation entry.
29
+
30
+ ## Usage examples
31
+
32
+ You can find code samples in the [examples](./examples) folder (with [README](./examples/README.md)).
33
+
34
+ ## Contributing
35
+
36
+ Check out our [contributing guide](./CONTRIBUTING.md).
@@ -0,0 +1,9 @@
1
+ import type { BaseClickHouseClientConfigOptions, BaseResultSet, InputJSON, InputJSONObjectEachRow, InsertParams, InsertResult, QueryParams, Row } from '@clickhouse/client-common';
2
+ import { ClickHouseClient } from '@clickhouse/client-common';
3
+ export type WebClickHouseClient = Omit<ClickHouseClient<ReadableStream>, 'insert' | 'query'> & {
4
+ insert<T>(params: Omit<InsertParams<ReadableStream, T>, 'values'> & {
5
+ values: ReadonlyArray<T> | InputJSON<T> | InputJSONObjectEachRow<T>;
6
+ }): Promise<InsertResult>;
7
+ query(params: QueryParams): Promise<BaseResultSet<ReadableStream<Row[]>>>;
8
+ };
9
+ export declare function createClient(config?: BaseClickHouseClientConfigOptions<ReadableStream>): WebClickHouseClient;
package/dist/client.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createClient = void 0;
4
+ const client_common_1 = require("@clickhouse/client-common");
5
+ const connection_1 = require("./connection");
6
+ const result_set_1 = require("./result_set");
7
+ const utils_1 = require("./utils");
8
+ function createClient(config) {
9
+ return new client_common_1.ClickHouseClient({
10
+ impl: {
11
+ make_connection: (params) => new connection_1.WebConnection(params),
12
+ make_result_set: (stream, format, query_id) => new result_set_1.ResultSet(stream, format, query_id),
13
+ values_encoder: new utils_1.WebValuesEncoder(),
14
+ close_stream: (stream) => stream.cancel(),
15
+ },
16
+ ...(config || {}),
17
+ });
18
+ }
19
+ exports.createClient = createClient;
20
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../packages/client-web/src/client.ts"],"names":[],"mappings":";;;AAYA,6DAA4D;AAC5D,6CAA4C;AAC5C,6CAAwC;AACxC,mCAA0C;AAgB1C,SAAgB,YAAY,CAC1B,MAA0D;IAE1D,OAAO,IAAI,gCAAgB,CAAiB;QAC1C,IAAI,EAAE;YACJ,eAAe,EAAE,CAAC,MAAwB,EAAE,EAAE,CAAC,IAAI,0BAAa,CAAC,MAAM,CAAC;YACxE,eAAe,EAAE,CACf,MAAsB,EACtB,MAAkB,EAClB,QAAgB,EAChB,EAAE,CAAC,IAAI,sBAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;YAC5C,cAAc,EAAE,IAAI,wBAAgB,EAAE;YACtC,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE;SAC1C;QACD,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;KAClB,CAAC,CAAA;AACJ,CAAC;AAhBD,oCAgBC"}
@@ -0,0 +1 @@
1
+ export * from './web_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("./web_connection"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/client-web/src/connection/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC"}
@@ -0,0 +1,16 @@
1
+ import type { ConnBaseQueryParams, Connection, ConnectionParams, ConnInsertParams, ConnInsertResult, ConnPingResult, ConnQueryResult } from '@clickhouse/client-common';
2
+ type WebInsertParams<T> = Omit<ConnInsertParams<ReadableStream<T>>, 'values'> & {
3
+ values: string;
4
+ };
5
+ export declare class WebConnection implements Connection<ReadableStream> {
6
+ private readonly params;
7
+ private readonly defaultHeaders;
8
+ constructor(params: ConnectionParams);
9
+ query(params: ConnBaseQueryParams): Promise<ConnQueryResult<ReadableStream<Uint8Array>>>;
10
+ exec(params: ConnBaseQueryParams): Promise<ConnQueryResult<ReadableStream<Uint8Array>>>;
11
+ insert<T = unknown>(params: WebInsertParams<T>): Promise<ConnInsertResult>;
12
+ ping(): Promise<ConnPingResult>;
13
+ close(): Promise<void>;
14
+ private request;
15
+ }
16
+ export {};
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebConnection = void 0;
4
+ const client_common_1 = require("@clickhouse/client-common");
5
+ const utils_1 = require("../utils");
6
+ class WebConnection {
7
+ constructor(params) {
8
+ Object.defineProperty(this, "params", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: params
13
+ });
14
+ Object.defineProperty(this, "defaultHeaders", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ this.defaultHeaders = {
21
+ Authorization: `Basic ${btoa(`${params.username}:${params.password}`)}`,
22
+ };
23
+ }
24
+ async query(params) {
25
+ const query_id = getQueryId(params.query_id);
26
+ const clickhouse_settings = (0, client_common_1.withHttpSettings)(params.clickhouse_settings, this.params.compression.decompress_response);
27
+ const searchParams = (0, client_common_1.toSearchParams)({
28
+ database: this.params.database,
29
+ clickhouse_settings,
30
+ query_params: params.query_params,
31
+ session_id: params.session_id,
32
+ query_id,
33
+ });
34
+ const response = await this.request({
35
+ values: params.query,
36
+ params,
37
+ searchParams,
38
+ });
39
+ return {
40
+ query_id,
41
+ stream: response.body || new ReadableStream(),
42
+ };
43
+ }
44
+ async exec(params) {
45
+ const query_id = getQueryId(params.query_id);
46
+ const searchParams = (0, client_common_1.toSearchParams)({
47
+ database: this.params.database,
48
+ clickhouse_settings: params.clickhouse_settings,
49
+ query_params: params.query_params,
50
+ session_id: params.session_id,
51
+ query_id,
52
+ });
53
+ const response = await this.request({
54
+ values: params.query,
55
+ params,
56
+ searchParams,
57
+ });
58
+ return {
59
+ stream: response.body || new ReadableStream(),
60
+ query_id,
61
+ };
62
+ }
63
+ async insert(params) {
64
+ const query_id = getQueryId(params.query_id);
65
+ const searchParams = (0, client_common_1.toSearchParams)({
66
+ database: this.params.database,
67
+ clickhouse_settings: params.clickhouse_settings,
68
+ query_params: params.query_params,
69
+ query: params.query,
70
+ session_id: params.session_id,
71
+ query_id,
72
+ });
73
+ await this.request({
74
+ values: params.values,
75
+ params,
76
+ searchParams,
77
+ });
78
+ return {
79
+ query_id,
80
+ };
81
+ }
82
+ async ping() {
83
+ // ClickHouse /ping endpoint does not support CORS,
84
+ // so we are using a simple SELECT as a workaround
85
+ try {
86
+ const response = await this.request({
87
+ values: 'SELECT 1 FORMAT CSV',
88
+ });
89
+ if (response.body !== null) {
90
+ await response.body.cancel();
91
+ }
92
+ return { success: true };
93
+ }
94
+ catch (error) {
95
+ if (error instanceof Error) {
96
+ return {
97
+ success: false,
98
+ error,
99
+ };
100
+ }
101
+ throw error; // should never happen
102
+ }
103
+ }
104
+ async close() {
105
+ return;
106
+ }
107
+ async request({ values, params, searchParams, pathname, method, }) {
108
+ const url = (0, client_common_1.transformUrl)({
109
+ url: this.params.url,
110
+ pathname: pathname !== null && pathname !== void 0 ? pathname : '/',
111
+ searchParams,
112
+ }).toString();
113
+ const abortController = new AbortController();
114
+ let isTimedOut = false;
115
+ const timeout = setTimeout(() => {
116
+ isTimedOut = true;
117
+ abortController.abort();
118
+ }, this.params.request_timeout);
119
+ let isAborted = false;
120
+ if ((params === null || params === void 0 ? void 0 : params.abort_signal) !== undefined) {
121
+ params.abort_signal.onabort = () => {
122
+ isAborted = true;
123
+ abortController.abort();
124
+ };
125
+ }
126
+ try {
127
+ const headers = (0, client_common_1.withCompressionHeaders)({
128
+ headers: this.defaultHeaders,
129
+ compress_request: false,
130
+ decompress_response: this.params.compression.decompress_response,
131
+ });
132
+ const response = await fetch(url, {
133
+ body: values,
134
+ headers,
135
+ keepalive: false,
136
+ method: method !== null && method !== void 0 ? method : 'POST',
137
+ signal: abortController.signal,
138
+ });
139
+ clearTimeout(timeout);
140
+ if ((0, client_common_1.isSuccessfulResponse)(response.status)) {
141
+ return response;
142
+ }
143
+ else {
144
+ return Promise.reject((0, client_common_1.parseError)(await (0, utils_1.getAsText)(response.body || new ReadableStream())));
145
+ }
146
+ }
147
+ catch (err) {
148
+ clearTimeout(timeout);
149
+ if (isAborted) {
150
+ return Promise.reject(new Error('The user aborted a request.'));
151
+ }
152
+ if (isTimedOut) {
153
+ return Promise.reject(new Error('Timeout error.'));
154
+ }
155
+ if (err instanceof Error) {
156
+ // maybe it's a ClickHouse error
157
+ return Promise.reject((0, client_common_1.parseError)(err));
158
+ }
159
+ // shouldn't happen
160
+ throw err;
161
+ }
162
+ }
163
+ }
164
+ exports.WebConnection = WebConnection;
165
+ function getQueryId(query_id) {
166
+ return query_id || crypto.randomUUID();
167
+ }
168
+ //# sourceMappingURL=web_connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web_connection.js","sourceRoot":"","sources":["../../../../packages/client-web/src/connection/web_connection.ts"],"names":[],"mappings":";;;AASA,6DAOkC;AAClC,oCAAoC;AASpC,MAAa,aAAa;IAExB,YAA6B,MAAwB;;;;;mBAAxB;;QAD7B;;;;;WAAuD;QAErD,IAAI,CAAC,cAAc,GAAG;YACpB,aAAa,EAAE,SAAS,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE;SACxE,CAAA;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CACT,MAA2B;QAE3B,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QAC5C,MAAM,mBAAmB,GAAG,IAAA,gCAAgB,EAC1C,MAAM,CAAC,mBAAm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AI,cAAc,EAAc,CAAC,CACnE,CACF,CAAA;aACF;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,YAAY,CAAC,OAAO,CAAC,CAAA;YACrB,IAAI,SAAS,EAAE;gBACb,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAA;aAChE;YACD,IAAI,UAAU,EAAE;gBACd,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAA;aACnD;YACD,IAAI,GAAG,YAAY,KAAK,EAAE;gBACxB,gCAAgC;gBAChC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAA,0BAAU,EAAC,GAAG,CAAC,CAAC,CAAA;aACvC;YACD,mBAAmB;YACnB,MAAM,GAAG,CAAA;SACV;IACH,CAAC;CACF;AAlLD,sCAkLC;AAED,SAAS,UAAU,CAAC,QAA4B;IAC9C,OAAO,QAAQ,IAAI,MAAM,CAAC,UAAU,EAAE,CAAA;AACxC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { 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, type PingResult, ClickHouseError, ClickHouseLogLevel, ClickHouseClient, SettingsMap, } from '@clickhouse/client-common';
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SettingsMap = exports.ClickHouseClient = exports.ClickHouseLogLevel = exports.ClickHouseError = exports.ResultSet = exports.createClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
6
+ var result_set_1 = require("./result_set");
7
+ Object.defineProperty(exports, "ResultSet", { enumerable: true, get: function () { return result_set_1.ResultSet; } });
8
+ /** Re-export @clickhouse/client-common types */
9
+ var client_common_1 = require("@clickhouse/client-common");
10
+ Object.defineProperty(exports, "ClickHouseError", { enumerable: true, get: function () { return client_common_1.ClickHouseError; } });
11
+ Object.defineProperty(exports, "ClickHouseLogLevel", { enumerable: true, get: function () { return client_common_1.ClickHouseLogLevel; } });
12
+ Object.defineProperty(exports, "ClickHouseClient", { enumerable: true, get: function () { return client_common_1.ClickHouseClient; } });
13
+ Object.defineProperty(exports, "SettingsMap", { enumerable: true, get: function () { return client_common_1.SettingsMap; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/client-web/src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AAA9B,sGAAA,YAAY,OAAA;AACrB,2CAAwC;AAA/B,uGAAA,SAAS,OAAA;AAElB,gDAAgD;AAChD,2DA4BkC;AAJhC,gHAAA,eAAe,OAAA;AACf,mHAAA,kBAAkB,OAAA;AAClB,iHAAA,gBAAgB,OAAA;AAChB,4GAAA,WAAW,OAAA"}
@@ -0,0 +1,13 @@
1
+ import type { BaseResultSet, DataFormat, Row } from '@clickhouse/client-common';
2
+ export declare class ResultSet implements BaseResultSet<ReadableStream<Row[]>> {
3
+ private _stream;
4
+ private readonly format;
5
+ readonly query_id: string;
6
+ private isAlreadyConsumed;
7
+ constructor(_stream: ReadableStream, format: DataFormat, query_id: string);
8
+ text(): Promise<string>;
9
+ json<T>(): Promise<T>;
10
+ stream(): ReadableStream<Row[]>;
11
+ close(): Promise<void>;
12
+ private markAsConsumed;
13
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResultSet = void 0;
4
+ const client_common_1 = require("@clickhouse/client-common");
5
+ const utils_1 = require("./utils");
6
+ class ResultSet {
7
+ constructor(_stream, format, query_id) {
8
+ Object.defineProperty(this, "_stream", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: _stream
13
+ });
14
+ Object.defineProperty(this, "format", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: format
19
+ });
20
+ Object.defineProperty(this, "query_id", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: query_id
25
+ });
26
+ Object.defineProperty(this, "isAlreadyConsumed", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: false
31
+ });
32
+ }
33
+ async text() {
34
+ this.markAsConsumed();
35
+ return (0, utils_1.getAsText)(this._stream);
36
+ }
37
+ async json() {
38
+ const text = await this.text();
39
+ return (0, client_common_1.decode)(text, this.format);
40
+ }
41
+ stream() {
42
+ this.markAsConsumed();
43
+ (0, client_common_1.validateStreamFormat)(this.format);
44
+ let decodedChunk = '';
45
+ const decoder = new TextDecoder('utf-8');
46
+ const transform = new TransformStream({
47
+ start() {
48
+ //
49
+ },
50
+ transform: (chunk, controller) => {
51
+ if (chunk === null) {
52
+ controller.terminate();
53
+ }
54
+ decodedChunk += decoder.decode(chunk);
55
+ const rows = [];
56
+ // eslint-disable-next-line no-constant-condition
57
+ while (true) {
58
+ const idx = decodedChunk.indexOf('\n');
59
+ if (idx !== -1) {
60
+ const text = decodedChunk.slice(0, idx);
61
+ decodedChunk = decodedChunk.slice(idx + 1);
62
+ rows.push({
63
+ text,
64
+ json() {
65
+ return (0, client_common_1.decode)(text, 'JSON');
66
+ },
67
+ });
68
+ }
69
+ else {
70
+ if (rows.length) {
71
+ controller.enqueue(rows);
72
+ }
73
+ break;
74
+ }
75
+ }
76
+ },
77
+ flush() {
78
+ decodedChunk = '';
79
+ },
80
+ });
81
+ return this._stream.pipeThrough(transform, {
82
+ preventClose: false,
83
+ preventAbort: false,
84
+ preventCancel: false,
85
+ });
86
+ }
87
+ async close() {
88
+ this.markAsConsumed();
89
+ await this._stream.cancel();
90
+ }
91
+ markAsConsumed() {
92
+ if (this.isAlreadyConsumed) {
93
+ throw new Error(streamAlreadyConsumedMessage);
94
+ }
95
+ this.isAlreadyConsumed = true;
96
+ }
97
+ }
98
+ exports.ResultSet = ResultSet;
99
+ const streamAlreadyConsumedMessage = 'Stream has been already consumed';
100
+ //# sourceMappingURL=result_set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result_set.js","sourceRoot":"","sources":["../../../packages/client-web/src/result_set.ts"],"names":[],"mappings":";;;AACA,6DAAwE;AACxE,mCAAmC;AAEnC,MAAa,SAAS;IAEpB,YACU,OAAuB,EACd,MAAkB,EACnB,QAAgB;;;;;mBAFxB;;;;;;mBACS;;;;;;mBACD;;QAJlB;;;;mBAA4B,KAAK;WAAA;IAK9B,CAAC;IAEJ,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,cAAc,EAAE,CAAA;QACrB,OAAO,IAAA,iBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QAC9B,OAAO,IAAA,sBAAM,EAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAClC,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,cAAc,EAAE,CAAA;QACrB,IAAA,oCAAoB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAEjC,IAAI,YAAY,GAAG,EAAE,CAAA;QACrB,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;QACxC,MAAM,SAAS,GAAG,IAAI,eAAe,CAAC;YACpC,KAAK;gBACH,EAAE;YACJ,CAAC;YACD,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;gBAC/B,IAAI,KAAK,KAAK,IAAI,EAAE;oBACl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I,CAAA;IAC/B,CAAC;CACF;AA7ED,8BA6EC;AAED,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { DataFormat, InsertValues, ValuesEncoder } from '@clickhouse/client-common';
2
+ export declare class WebValuesEncoder implements ValuesEncoder<ReadableStream> {
3
+ encodeValues<T = unknown>(values: InsertValues<T>, format: DataFormat): string | ReadableStream;
4
+ validateInsertValues<T = unknown>(values: InsertValues<T>): void;
5
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebValuesEncoder = void 0;
4
+ const client_common_1 = require("@clickhouse/client-common");
5
+ const stream_1 = require("./stream");
6
+ class WebValuesEncoder {
7
+ encodeValues(values, format) {
8
+ throwIfStream(values);
9
+ // JSON* arrays
10
+ if (Array.isArray(values)) {
11
+ return values.map((value) => (0, client_common_1.encodeJSON)(value, format)).join('');
12
+ }
13
+ // JSON & JSONObjectEachRow format input
14
+ if (typeof values === 'object') {
15
+ return (0, client_common_1.encodeJSON)(values, format);
16
+ }
17
+ throw new Error(`Cannot encode values of type ${typeof values} with ${format} format`);
18
+ }
19
+ validateInsertValues(values) {
20
+ throwIfStream(values);
21
+ if (!Array.isArray(values) && typeof values !== 'object') {
22
+ throw new Error('Insert expected "values" to be an array or a JSON object, ' +
23
+ `got: ${typeof values}`);
24
+ }
25
+ }
26
+ }
27
+ exports.WebValuesEncoder = WebValuesEncoder;
28
+ function throwIfStream(values) {
29
+ if ((0, stream_1.isStream)(values)) {
30
+ throw new Error('Streaming is not supported for inserts in the web version of the client');
31
+ }
32
+ }
33
+ //# sourceMappingURL=encoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../../../packages/client-web/src/utils/encoder.ts"],"names":[],"mappings":";;;AAKA,6DAAsD;AACtD,qCAAmC;AAEnC,MAAa,gBAAgB;IAC3B,YAAY,CACV,MAAuB,EACvB,MAAkB;QAElB,aAAa,CAAC,MAAM,CAAC,CAAA;QACrB,eAAe;QACf,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACzB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,0BAAU,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;SACjE;QACD,wCAAwC;QACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,OAAO,IAAA,0BAAU,EAAC,MAAM,EAAE,MAAM,CAAC,CAAA;SAClC;QACD,MAAM,IAAI,KAAK,CACb,gCAAgC,OAAO,MAAM,SAAS,MAAM,SAAS,CACtE,CAAA;IACH,CAAC;IAED,oBAAoB,CAAc,MAAuB;QACvD,aAAa,CAAC,MAAM,CAAC,CAAA;QACrB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YACxD,MAAM,IAAI,KAAK,CACb,4DAA4D;gBAC1D,QAAQ,OAAO,MAAM,EAAE,CAC1B,CAAA;SACF;IACH,CAAC;CACF;AA5BD,4CA4BC;AAED,SAAS,aAAa,CAAC,MAAe;IACpC,IAAI,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAAE;QACpB,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAA;KACF;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './stream';
2
+ export * from './encoder';
@@ -0,0 +1,19 @@
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("./stream"), exports);
18
+ __exportStar(require("./encoder"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/client-web/src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,4CAAyB"}
@@ -0,0 +1,2 @@
1
+ export declare function isStream(obj: any): obj is ReadableStream;
2
+ export declare function getAsText(stream: ReadableStream): Promise<string>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAsText = exports.isStream = void 0;
4
+ function isStream(obj) {
5
+ return (obj !== null && obj !== undefined && typeof obj.pipeThrough === 'function');
6
+ }
7
+ exports.isStream = isStream;
8
+ async function getAsText(stream) {
9
+ let result = '';
10
+ let isDone = false;
11
+ const textDecoder = new TextDecoder();
12
+ const reader = stream.getReader();
13
+ while (!isDone) {
14
+ const { done, value } = await reader.read();
15
+ result += textDecoder.decode(value, { stream: true });
16
+ isDone = done;
17
+ }
18
+ // flush
19
+ result += textDecoder.decode();
20
+ return result;
21
+ }
22
+ exports.getAsText = getAsText;
23
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../packages/client-web/src/utils/stream.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,GAAQ;IAC/B,OAAO,CACL,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,WAAW,KAAK,UAAU,CAC3E,CAAA;AACH,CAAC;AAJD,4BAIC;AAEM,KAAK,UAAU,SAAS,CAAC,MAAsB;IACpD,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,MAAM,GAAG,KAAK,CAAA;IAElB,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;IACrC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IAEjC,OAAO,CAAC,MAAM,EAAE;QACd,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAC3C,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QACrD,MAAM,GAAG,IAAI,CAAA;KACd;IAED,QAAQ;IACR,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,CAAA;IAC9B,OAAO,MAAM,CAAA;AACf,CAAC;AAhBD,8BAgBC"}
@@ -0,0 +1,2 @@
1
+ declare const _default: "0.2.0";
2
+ export default _default;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = '0.2.0';
4
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../packages/client-web/src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,OAAO,CAAA"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@clickhouse/client-web",
3
+ "description": "Official JS client for ClickHouse DB - Web API implementation",
4
+ "homepage": "https://clickhouse.com",
5
+ "version": "0.2.0",
6
+ "license": "Apache-2.0",
7
+ "keywords": [
8
+ "clickhouse",
9
+ "sql",
10
+ "client"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/ClickHouse/clickhouse-js.git"
15
+ },
16
+ "private": false,
17
+ "main": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "dependencies": {
23
+ "@clickhouse/client-common": "0.2.0"
24
+ }
25
+ }