@clickhouse/client-web 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.
- package/LICENSE +2 -2
- package/README.md +14 -0
- package/dist/client.d.ts +21 -9
- package/dist/client.js +10 -15
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.js +15 -0
- package/dist/config.js.map +1 -0
- package/dist/connection/index.js.map +1 -1
- package/dist/connection/web_connection.d.ts +6 -5
- package/dist/connection/web_connection.js +93 -32
- package/dist/connection/web_connection.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/result_set.d.ts +19 -5
- package/dist/result_set.js +111 -19
- package/dist/result_set.js.map +1 -1
- package/dist/utils/encoder.d.ts +3 -0
- package/dist/utils/encoder.js +16 -2
- package/dist/utils/encoder.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/stream.js +10 -4
- package/dist/utils/stream.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +7 -3
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2016-
|
|
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-
|
|
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
|
package/dist/client.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DataFormat, ExecParams, ExecResult, InputJSON, InputJSONObjectEachRow, InsertParams, InsertResult, IsSame, QueryParamsWithFormat } from '@clickhouse/client-common';
|
|
2
2
|
import { ClickHouseClient } from '@clickhouse/client-common';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type WebClickHouseClient = Omit<
|
|
3
|
+
import type { WebClickHouseClientConfigOptions } from './config';
|
|
4
|
+
import type { ResultSet } from './result_set';
|
|
5
|
+
/** If the Format is not a literal type, fall back to the default behavior of the ResultSet,
|
|
6
|
+
* allowing to call all methods with all data shapes variants,
|
|
7
|
+
* and avoiding generated types that include all possible DataFormat literal values. */
|
|
8
|
+
export type QueryResult<Format extends DataFormat> = IsSame<Format, DataFormat> extends true ? ResultSet<unknown> : ResultSet<Format>;
|
|
9
|
+
export type WebClickHouseClient = Omit<WebClickHouseClientImpl, 'insert' | 'exec'> & {
|
|
10
|
+
/** See {@link ClickHouseClient.insert}.
|
|
11
|
+
*
|
|
12
|
+
* ReadableStream is removed from possible insert values
|
|
13
|
+
* until it is supported by all major web platforms. */
|
|
10
14
|
insert<T>(params: Omit<InsertParams<ReadableStream, T>, 'values'> & {
|
|
11
15
|
values: ReadonlyArray<T> | InputJSON<T> | InputJSONObjectEachRow<T>;
|
|
12
16
|
}): Promise<InsertResult>;
|
|
13
|
-
|
|
17
|
+
/** See {@link ClickHouseClient.exec}.
|
|
18
|
+
*
|
|
19
|
+
* Custom values are currently not supported in the web versions. */
|
|
20
|
+
exec(params: ExecParams): Promise<ExecResult<ReadableStream>>;
|
|
14
21
|
};
|
|
22
|
+
declare class WebClickHouseClientImpl extends ClickHouseClient<ReadableStream> {
|
|
23
|
+
/** See {@link ClickHouseClient.query}. */
|
|
24
|
+
query<Format extends DataFormat>(params: QueryParamsWithFormat<Format>): Promise<QueryResult<Format>>;
|
|
25
|
+
}
|
|
15
26
|
export declare function createClient(config?: WebClickHouseClientConfigOptions): WebClickHouseClient;
|
|
27
|
+
export {};
|
package/dist/client.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createClient =
|
|
3
|
+
exports.createClient = createClient;
|
|
4
4
|
const client_common_1 = require("@clickhouse/client-common");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
class WebClickHouseClientImpl extends client_common_1.ClickHouseClient {
|
|
7
|
+
/** See {@link ClickHouseClient.query}. */
|
|
8
|
+
query(params) {
|
|
9
|
+
return super.query(params);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
8
12
|
function createClient(config) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
return new client_common_1.ClickHouseClient({
|
|
13
|
-
impl: {
|
|
14
|
-
make_connection: (params) => new connection_1.WebConnection({ ...params, keep_alive }),
|
|
15
|
-
make_result_set: (stream, format, query_id) => new result_set_1.ResultSet(stream, format, query_id),
|
|
16
|
-
values_encoder: new utils_1.WebValuesEncoder(),
|
|
17
|
-
close_stream: (stream) => stream.cancel(),
|
|
18
|
-
},
|
|
13
|
+
return new WebClickHouseClientImpl({
|
|
14
|
+
impl: config_1.WebImpl,
|
|
19
15
|
...(config || {}),
|
|
20
16
|
});
|
|
21
17
|
}
|
|
22
|
-
exports.createClient = createClient;
|
|
23
18
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;AAoDA,oCAOC;AAhDD,6DAA4D;AAE5D,qCAAkC;AA8BlC,MAAM,uBAAwB,SAAQ,gCAAgC;IACpE,0CAA0C;IAC1C,KAAK,CACH,MAAqC;QAErC,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAA+B,CAAA;IAC1D,CAAC;CACF;AAED,SAAgB,YAAY,CAC1B,MAAyC;IAEzC,OAAO,IAAI,uBAAuB,CAAC;QACjC,IAAI,EAAE,gBAAO;QACb,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;KAClB,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BaseClickHouseClientConfigOptions, ImplementationDetails } from '@clickhouse/client-common';
|
|
2
|
+
export type WebClickHouseClientConfigOptions = BaseClickHouseClientConfigOptions & {
|
|
3
|
+
/** A custom implementation or wrapper over the global `fetch` method that will be used by the client internally.
|
|
4
|
+
* This might be helpful if you want to configure mTLS or change other default `fetch` settings. */
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
};
|
|
7
|
+
export declare const WebImpl: ImplementationDetails<ReadableStream>['impl'];
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebImpl = void 0;
|
|
4
|
+
const connection_1 = require("./connection");
|
|
5
|
+
const result_set_1 = require("./result_set");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
exports.WebImpl = {
|
|
8
|
+
make_connection: (config, params) => new connection_1.WebConnection({
|
|
9
|
+
...params,
|
|
10
|
+
fetch: config.fetch,
|
|
11
|
+
}),
|
|
12
|
+
make_result_set: ((stream, format, query_id, _log_error, response_headers) => new result_set_1.ResultSet(stream, format, query_id, response_headers)),
|
|
13
|
+
values_encoder: (jsonHandling) => new utils_1.WebValuesEncoder(jsonHandling),
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAQA,6CAA4C;AAC5C,6CAAwC;AACxC,mCAA0C;AAS7B,QAAA,OAAO,GAAkD;IACpE,eAAe,EAAE,CACf,MAAwC,EACxC,MAAwB,EACxB,EAAE,CACF,IAAI,0BAAa,CAAC;QAChB,GAAG,MAAM;QACT,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;IACJ,eAAe,EAAE,CAAC,CAChB,MAAsB,EACtB,MAAkB,EAClB,QAAgB,EAChB,UAAgC,EAChC,gBAAiC,EACjC,EAAE,CAAC,IAAI,sBAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAQ;IACtE,cAAc,EAAE,CAAC,YAA0B,EAAE,EAAE,CAC7C,IAAI,wBAAgB,CAAC,YAAY,CAAC;CACrC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import type { ConnBaseQueryParams, Connection, ConnectionParams, ConnInsertParams, ConnInsertResult, ConnPingResult, ConnQueryResult } from '@clickhouse/client-common';
|
|
1
|
+
import type { ConnBaseQueryParams, ConnCommandResult, Connection, ConnectionParams, ConnInsertParams, ConnInsertResult, ConnPingResult, ConnQueryResult } from '@clickhouse/client-common';
|
|
2
2
|
type WebInsertParams<T> = Omit<ConnInsertParams<ReadableStream<T>>, 'values'> & {
|
|
3
3
|
values: string;
|
|
4
4
|
};
|
|
5
5
|
export type WebConnectionParams = ConnectionParams & {
|
|
6
|
-
|
|
7
|
-
enabled: boolean;
|
|
8
|
-
};
|
|
6
|
+
fetch?: typeof fetch;
|
|
9
7
|
};
|
|
10
8
|
export declare class WebConnection implements Connection<ReadableStream> {
|
|
11
9
|
private readonly params;
|
|
12
|
-
private readonly
|
|
10
|
+
private readonly defaultAuthHeader;
|
|
13
11
|
constructor(params: WebConnectionParams);
|
|
14
12
|
query(params: ConnBaseQueryParams): Promise<ConnQueryResult<ReadableStream<Uint8Array>>>;
|
|
15
13
|
exec(params: ConnBaseQueryParams): Promise<ConnQueryResult<ReadableStream<Uint8Array>>>;
|
|
14
|
+
command(params: ConnBaseQueryParams): Promise<ConnCommandResult>;
|
|
16
15
|
insert<T = unknown>(params: WebInsertParams<T>): Promise<ConnInsertResult>;
|
|
17
16
|
ping(): Promise<ConnPingResult>;
|
|
18
17
|
close(): Promise<void>;
|
|
19
18
|
private request;
|
|
19
|
+
private runExec;
|
|
20
|
+
private defaultHeadersWithOverride;
|
|
20
21
|
}
|
|
21
22
|
export {};
|
|
@@ -11,16 +11,21 @@ class WebConnection {
|
|
|
11
11
|
writable: true,
|
|
12
12
|
value: params
|
|
13
13
|
});
|
|
14
|
-
Object.defineProperty(this, "
|
|
14
|
+
Object.defineProperty(this, "defaultAuthHeader", {
|
|
15
15
|
enumerable: true,
|
|
16
16
|
configurable: true,
|
|
17
17
|
writable: true,
|
|
18
18
|
value: void 0
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
if (params.auth.type === 'JWT') {
|
|
21
|
+
this.defaultAuthHeader = `Bearer ${params.auth.access_token}`;
|
|
22
|
+
}
|
|
23
|
+
else if (params.auth.type === 'Credentials') {
|
|
24
|
+
this.defaultAuthHeader = `Basic ${btoa(`${params.auth.username}:${params.auth.password}`)}`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error(`Unknown auth type: ${params.auth.type}`);
|
|
28
|
+
}
|
|
24
29
|
}
|
|
25
30
|
async query(params) {
|
|
26
31
|
const query_id = getQueryId(params.query_id);
|
|
@@ -30,37 +35,35 @@ class WebConnection {
|
|
|
30
35
|
clickhouse_settings,
|
|
31
36
|
query_params: params.query_params,
|
|
32
37
|
session_id: params.session_id,
|
|
38
|
+
role: params.role,
|
|
33
39
|
query_id,
|
|
34
40
|
});
|
|
35
41
|
const response = await this.request({
|
|
36
|
-
|
|
42
|
+
body: params.query,
|
|
37
43
|
params,
|
|
38
44
|
searchParams,
|
|
39
45
|
});
|
|
40
46
|
return {
|
|
41
47
|
query_id,
|
|
42
48
|
stream: response.body || new ReadableStream(),
|
|
49
|
+
response_headers: getResponseHeaders(response),
|
|
43
50
|
};
|
|
44
51
|
}
|
|
45
52
|
async exec(params) {
|
|
46
|
-
const
|
|
47
|
-
const searchParams = (0, client_common_1.toSearchParams)({
|
|
48
|
-
database: this.params.database,
|
|
49
|
-
clickhouse_settings: params.clickhouse_settings,
|
|
50
|
-
query_params: params.query_params,
|
|
51
|
-
session_id: params.session_id,
|
|
52
|
-
query_id,
|
|
53
|
-
});
|
|
54
|
-
const response = await this.request({
|
|
55
|
-
values: params.query,
|
|
56
|
-
params,
|
|
57
|
-
searchParams,
|
|
58
|
-
});
|
|
53
|
+
const result = await this.runExec(params);
|
|
59
54
|
return {
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
query_id: result.query_id,
|
|
56
|
+
stream: result.stream || new ReadableStream(),
|
|
57
|
+
response_headers: result.response_headers,
|
|
62
58
|
};
|
|
63
59
|
}
|
|
60
|
+
async command(params) {
|
|
61
|
+
const { stream, query_id, response_headers } = await this.runExec(params);
|
|
62
|
+
if (stream !== null) {
|
|
63
|
+
await stream.cancel();
|
|
64
|
+
}
|
|
65
|
+
return { query_id, response_headers };
|
|
66
|
+
}
|
|
64
67
|
async insert(params) {
|
|
65
68
|
const query_id = getQueryId(params.query_id);
|
|
66
69
|
const searchParams = (0, client_common_1.toSearchParams)({
|
|
@@ -69,18 +72,20 @@ class WebConnection {
|
|
|
69
72
|
query_params: params.query_params,
|
|
70
73
|
query: params.query,
|
|
71
74
|
session_id: params.session_id,
|
|
75
|
+
role: params.role,
|
|
72
76
|
query_id,
|
|
73
77
|
});
|
|
74
|
-
const
|
|
75
|
-
|
|
78
|
+
const response = await this.request({
|
|
79
|
+
body: params.values,
|
|
76
80
|
params,
|
|
77
81
|
searchParams,
|
|
78
82
|
});
|
|
79
|
-
if (
|
|
80
|
-
await
|
|
83
|
+
if (response.body !== null) {
|
|
84
|
+
await response.text(); // drain the response (it's empty anyway)
|
|
81
85
|
}
|
|
82
86
|
return {
|
|
83
87
|
query_id,
|
|
88
|
+
response_headers: getResponseHeaders(response),
|
|
84
89
|
};
|
|
85
90
|
}
|
|
86
91
|
async ping() {
|
|
@@ -88,7 +93,13 @@ class WebConnection {
|
|
|
88
93
|
// so we are using a simple SELECT as a workaround
|
|
89
94
|
try {
|
|
90
95
|
const response = await this.request({
|
|
91
|
-
|
|
96
|
+
body: null,
|
|
97
|
+
searchParams: (0, client_common_1.toSearchParams)({
|
|
98
|
+
database: undefined,
|
|
99
|
+
query: `SELECT 'ping'`,
|
|
100
|
+
query_id: getQueryId(undefined),
|
|
101
|
+
}),
|
|
102
|
+
method: 'GET',
|
|
92
103
|
});
|
|
93
104
|
if (response.body !== null) {
|
|
94
105
|
await response.body.cancel();
|
|
@@ -108,7 +119,7 @@ class WebConnection {
|
|
|
108
119
|
async close() {
|
|
109
120
|
return;
|
|
110
121
|
}
|
|
111
|
-
async request({
|
|
122
|
+
async request({ body, params, searchParams, pathname, method, }) {
|
|
112
123
|
const url = (0, client_common_1.transformUrl)({
|
|
113
124
|
url: this.params.url,
|
|
114
125
|
pathname,
|
|
@@ -129,12 +140,15 @@ class WebConnection {
|
|
|
129
140
|
}
|
|
130
141
|
try {
|
|
131
142
|
const headers = (0, client_common_1.withCompressionHeaders)({
|
|
132
|
-
headers: this.
|
|
133
|
-
|
|
134
|
-
|
|
143
|
+
headers: this.defaultHeadersWithOverride(params),
|
|
144
|
+
// It is not currently working as expected in all major browsers
|
|
145
|
+
enable_request_compression: false,
|
|
146
|
+
enable_response_compression: this.params.compression.decompress_response,
|
|
135
147
|
});
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
// avoiding "fetch called on an object that does not implement interface Window" error
|
|
149
|
+
const fetchFn = this.params.fetch ?? fetch;
|
|
150
|
+
const response = await fetchFn(url, {
|
|
151
|
+
body,
|
|
138
152
|
headers,
|
|
139
153
|
keepalive: this.params.keep_alive.enabled,
|
|
140
154
|
method: method ?? 'POST',
|
|
@@ -164,9 +178,56 @@ class WebConnection {
|
|
|
164
178
|
throw err;
|
|
165
179
|
}
|
|
166
180
|
}
|
|
181
|
+
async runExec(params) {
|
|
182
|
+
const query_id = getQueryId(params.query_id);
|
|
183
|
+
const searchParams = (0, client_common_1.toSearchParams)({
|
|
184
|
+
database: this.params.database,
|
|
185
|
+
clickhouse_settings: params.clickhouse_settings,
|
|
186
|
+
query_params: params.query_params,
|
|
187
|
+
session_id: params.session_id,
|
|
188
|
+
role: params.role,
|
|
189
|
+
query_id,
|
|
190
|
+
});
|
|
191
|
+
const response = await this.request({
|
|
192
|
+
body: params.query,
|
|
193
|
+
params,
|
|
194
|
+
searchParams,
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
stream: response.body,
|
|
198
|
+
response_headers: getResponseHeaders(response),
|
|
199
|
+
query_id,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
defaultHeadersWithOverride(params) {
|
|
203
|
+
let authHeader;
|
|
204
|
+
if ((0, client_common_1.isJWTAuth)(params?.auth)) {
|
|
205
|
+
authHeader = `Bearer ${params?.auth.access_token}`;
|
|
206
|
+
}
|
|
207
|
+
else if ((0, client_common_1.isCredentialsAuth)(params?.auth)) {
|
|
208
|
+
authHeader = `Basic ${btoa(`${params?.auth.username}:${params?.auth.password}`)}`;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
authHeader = this.defaultAuthHeader;
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
// Custom HTTP headers from the client configuration
|
|
215
|
+
...(this.params.http_headers ?? {}),
|
|
216
|
+
// Custom HTTP headers for this particular request; it will override the client configuration with the same keys
|
|
217
|
+
...(params?.http_headers ?? {}),
|
|
218
|
+
Authorization: authHeader,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
167
221
|
}
|
|
168
222
|
exports.WebConnection = WebConnection;
|
|
169
223
|
function getQueryId(query_id) {
|
|
170
224
|
return query_id || crypto.randomUUID();
|
|
171
225
|
}
|
|
226
|
+
function getResponseHeaders(response) {
|
|
227
|
+
const headers = {};
|
|
228
|
+
response.headers.forEach((value, key) => {
|
|
229
|
+
headers[key] = value;
|
|
230
|
+
});
|
|
231
|
+
return headers;
|
|
232
|
+
}
|
|
172
233
|
//# sourceMappingURL=web_connection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web_connection.js","sourceRoot":"","sources":["
|
|
1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C,GAAG,CAAC,GAAG,KAAK,CAAA;IACtB,CAAC,CAAC,CAAA;IACF,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { WebClickHouseClient as ClickHouseClient, type QueryResult, } from './client';
|
|
1
2
|
export { createClient } from './client';
|
|
3
|
+
export { type WebClickHouseClientConfigOptions as ClickHouseClientConfigOptions } from './config';
|
|
2
4
|
export { ResultSet } from './result_set';
|
|
3
5
|
/** Re-export @clickhouse/client-common types */
|
|
4
|
-
export { type BaseClickHouseClientConfigOptions, type
|
|
6
|
+
export { type BaseClickHouseClientConfigOptions, type BaseQueryParams, type QueryParams, type ExecParams, type InsertParams, type InsertValues, type CommandParams, type CommandResult, type ExecResult, type InsertResult, type DataFormat, type RawDataFormat, type JSONDataFormat, type StreamableDataFormat, type StreamableJSONDataFormat, type SingleDocumentJSONFormat, type Logger, type LogParams, type ErrorLogParams, type WarnLogParams, type ClickHouseSettings, type MergeTreeSettings, type Row, type ResponseJSON, type InputJSON, type InputJSONObjectEachRow, type BaseResultSet, type PingResult, ClickHouseError, parseError, ClickHouseLogLevel, SettingsMap, SupportedJSONFormats, SupportedRawFormats, StreamableFormats, StreamableJSONFormats, SingleDocumentJSONFormats, RecordsJSONFormats, type SimpleColumnType, type ParsedColumnSimple, type ParsedColumnEnum, type ParsedColumnFixedString, type ParsedColumnNullable, type ParsedColumnDecimal, type ParsedColumnDateTime, type ParsedColumnDateTime64, type ParsedColumnArray, type ParsedColumnTuple, type ParsedColumnMap, type ParsedColumnType, parseColumnType, SimpleColumnTypes, type ProgressRow, isProgressRow, isRow, isException, type RowOrProgress, type ClickHouseAuth, type ClickHouseJWTAuth, type ClickHouseCredentialsAuth, TupleParam, } from '@clickhouse/client-common';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TupleParam = exports.isException = exports.isRow = exports.isProgressRow = exports.SimpleColumnTypes = exports.parseColumnType = exports.SettingsMap = exports.ClickHouseLogLevel = exports.parseError = exports.ClickHouseError = exports.ResultSet = exports.createClient = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
|
|
6
6
|
var result_set_1 = require("./result_set");
|
|
@@ -8,7 +8,13 @@ Object.defineProperty(exports, "ResultSet", { enumerable: true, get: function ()
|
|
|
8
8
|
/** Re-export @clickhouse/client-common types */
|
|
9
9
|
var client_common_1 = require("@clickhouse/client-common");
|
|
10
10
|
Object.defineProperty(exports, "ClickHouseError", { enumerable: true, get: function () { return client_common_1.ClickHouseError; } });
|
|
11
|
+
Object.defineProperty(exports, "parseError", { enumerable: true, get: function () { return client_common_1.parseError; } });
|
|
11
12
|
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
13
|
Object.defineProperty(exports, "SettingsMap", { enumerable: true, get: function () { return client_common_1.SettingsMap; } });
|
|
14
|
+
Object.defineProperty(exports, "parseColumnType", { enumerable: true, get: function () { return client_common_1.parseColumnType; } });
|
|
15
|
+
Object.defineProperty(exports, "SimpleColumnTypes", { enumerable: true, get: function () { return client_common_1.SimpleColumnTypes; } });
|
|
16
|
+
Object.defineProperty(exports, "isProgressRow", { enumerable: true, get: function () { return client_common_1.isProgressRow; } });
|
|
17
|
+
Object.defineProperty(exports, "isRow", { enumerable: true, get: function () { return client_common_1.isRow; } });
|
|
18
|
+
Object.defineProperty(exports, "isException", { enumerable: true, get: function () { return client_common_1.isException; } });
|
|
19
|
+
Object.defineProperty(exports, "TupleParam", { enumerable: true, get: function () { return client_common_1.TupleParam; } });
|
|
14
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAIA,mCAAuC;AAA9B,sGAAA,YAAY,OAAA;AAErB,2CAAwC;AAA/B,uGAAA,SAAS,OAAA;AAElB,gDAAgD;AAChD,2DA8DkC;AAjChC,gHAAA,eAAe,OAAA;AACf,2GAAA,UAAU,OAAA;AACV,mHAAA,kBAAkB,OAAA;AAClB,4GAAA,WAAW,OAAA;AAmBX,gHAAA,eAAe,OAAA;AACf,kHAAA,iBAAiB,OAAA;AAEjB,8GAAA,aAAa,OAAA;AACb,sGAAA,KAAK,OAAA;AACL,4GAAA,WAAW,OAAA;AAKX,2GAAA,UAAU,OAAA"}
|
package/dist/result_set.d.ts
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
import type { BaseResultSet, DataFormat, Row } from '@clickhouse/client-common';
|
|
2
|
-
export declare class ResultSet implements BaseResultSet<ReadableStream<Row[]
|
|
1
|
+
import type { BaseResultSet, DataFormat, JSONHandling, ResponseHeaders, ResultJSONType, ResultStream, Row } from '@clickhouse/client-common';
|
|
2
|
+
export declare class ResultSet<Format extends DataFormat | unknown> implements BaseResultSet<ReadableStream<Row[]>, Format> {
|
|
3
3
|
private _stream;
|
|
4
4
|
private readonly format;
|
|
5
5
|
readonly query_id: string;
|
|
6
|
+
readonly response_headers: ResponseHeaders;
|
|
7
|
+
private readonly exceptionTag;
|
|
6
8
|
private isAlreadyConsumed;
|
|
7
|
-
|
|
9
|
+
private readonly jsonHandling;
|
|
10
|
+
constructor(_stream: ReadableStream, format: Format, query_id: string, _response_headers?: ResponseHeaders, jsonHandling?: JSONHandling);
|
|
11
|
+
/** See {@link BaseResultSet.text} */
|
|
8
12
|
text(): Promise<string>;
|
|
9
|
-
json
|
|
10
|
-
|
|
13
|
+
/** See {@link BaseResultSet.json} */
|
|
14
|
+
json<T>(): Promise<ResultJSONType<T, Format>>;
|
|
15
|
+
/** See {@link BaseResultSet.stream} */
|
|
16
|
+
stream<T>(): ResultStream<Format, ReadableStream<Row<T, Format>[]>>;
|
|
11
17
|
close(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Closes the `ResultSet`.
|
|
20
|
+
*
|
|
21
|
+
* Automatically called when using `using` statement in supported environments.
|
|
22
|
+
* @see {@link ResultSet.close}
|
|
23
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using
|
|
24
|
+
*/
|
|
25
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
12
26
|
private markAsConsumed;
|
|
13
27
|
}
|
package/dist/result_set.js
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ResultSet = void 0;
|
|
4
4
|
const client_common_1 = require("@clickhouse/client-common");
|
|
5
|
+
const client_common_2 = require("@clickhouse/client-common");
|
|
5
6
|
const utils_1 = require("./utils");
|
|
7
|
+
const NEWLINE = 0x0a;
|
|
6
8
|
class ResultSet {
|
|
7
|
-
constructor(_stream, format, query_id
|
|
9
|
+
constructor(_stream, format, query_id, _response_headers, jsonHandling = {
|
|
10
|
+
parse: JSON.parse,
|
|
11
|
+
stringify: JSON.stringify,
|
|
12
|
+
}) {
|
|
8
13
|
Object.defineProperty(this, "_stream", {
|
|
9
14
|
enumerable: true,
|
|
10
15
|
configurable: true,
|
|
@@ -23,25 +28,73 @@ class ResultSet {
|
|
|
23
28
|
writable: true,
|
|
24
29
|
value: query_id
|
|
25
30
|
});
|
|
31
|
+
Object.defineProperty(this, "response_headers", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "exceptionTag", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: undefined
|
|
42
|
+
});
|
|
26
43
|
Object.defineProperty(this, "isAlreadyConsumed", {
|
|
27
44
|
enumerable: true,
|
|
28
45
|
configurable: true,
|
|
29
46
|
writable: true,
|
|
30
47
|
value: false
|
|
31
48
|
});
|
|
49
|
+
Object.defineProperty(this, "jsonHandling", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
this.response_headers =
|
|
56
|
+
_response_headers !== undefined ? Object.freeze(_response_headers) : {};
|
|
57
|
+
this.exceptionTag = this.response_headers['x-clickhouse-exception-tag'];
|
|
58
|
+
this.jsonHandling = jsonHandling;
|
|
32
59
|
}
|
|
60
|
+
/** See {@link BaseResultSet.text} */
|
|
33
61
|
async text() {
|
|
34
62
|
this.markAsConsumed();
|
|
35
63
|
return (0, utils_1.getAsText)(this._stream);
|
|
36
64
|
}
|
|
65
|
+
/** See {@link BaseResultSet.json} */
|
|
37
66
|
async json() {
|
|
38
|
-
|
|
39
|
-
|
|
67
|
+
// JSONEachRow, etc.
|
|
68
|
+
if ((0, client_common_2.isStreamableJSONFamily)(this.format)) {
|
|
69
|
+
const result = [];
|
|
70
|
+
const reader = this.stream().getReader();
|
|
71
|
+
while (true) {
|
|
72
|
+
const { done, value } = await reader.read();
|
|
73
|
+
if (done) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
for (const row of value) {
|
|
77
|
+
result.push(row.json());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
// JSON, JSONObjectEachRow, etc.
|
|
83
|
+
if ((0, client_common_2.isNotStreamableJSONFamily)(this.format)) {
|
|
84
|
+
const text = await (0, utils_1.getAsText)(this._stream);
|
|
85
|
+
return this.jsonHandling.parse(text);
|
|
86
|
+
}
|
|
87
|
+
// should not be called for CSV, etc.
|
|
88
|
+
throw new Error(`Cannot decode ${this.format} as JSON`);
|
|
40
89
|
}
|
|
90
|
+
/** See {@link BaseResultSet.stream} */
|
|
41
91
|
stream() {
|
|
42
92
|
this.markAsConsumed();
|
|
43
|
-
(0,
|
|
44
|
-
let
|
|
93
|
+
(0, client_common_2.validateStreamFormat)(this.format);
|
|
94
|
+
let incompleteChunks = [];
|
|
95
|
+
let totalIncompleteLength = 0;
|
|
96
|
+
const exceptionTag = this.exceptionTag;
|
|
97
|
+
const jsonHandling = this.jsonHandling;
|
|
45
98
|
const decoder = new TextDecoder('utf-8');
|
|
46
99
|
const transform = new TransformStream({
|
|
47
100
|
start() {
|
|
@@ -51,43 +104,82 @@ class ResultSet {
|
|
|
51
104
|
if (chunk === null) {
|
|
52
105
|
controller.terminate();
|
|
53
106
|
}
|
|
54
|
-
decodedChunk += decoder.decode(chunk);
|
|
55
107
|
const rows = [];
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
108
|
+
let idx;
|
|
109
|
+
let lastIdx = 0;
|
|
110
|
+
do {
|
|
111
|
+
// an unescaped newline character denotes the end of a row,
|
|
112
|
+
// or at least the beginning of the exception marker
|
|
113
|
+
idx = chunk.indexOf(NEWLINE, lastIdx);
|
|
59
114
|
if (idx !== -1) {
|
|
60
|
-
|
|
61
|
-
|
|
115
|
+
let bytesToDecode;
|
|
116
|
+
const maybeErr = (0, client_common_1.checkErrorInChunkAtIndex)(chunk, idx, exceptionTag);
|
|
117
|
+
if (maybeErr) {
|
|
118
|
+
controller.error(maybeErr);
|
|
119
|
+
}
|
|
120
|
+
// using the incomplete chunks from the previous iterations
|
|
121
|
+
if (incompleteChunks.length > 0) {
|
|
122
|
+
const completeRowBytes = new Uint8Array(totalIncompleteLength + idx);
|
|
123
|
+
let offset = 0;
|
|
124
|
+
incompleteChunks.forEach((incompleteChunk) => {
|
|
125
|
+
completeRowBytes.set(incompleteChunk, offset);
|
|
126
|
+
offset += incompleteChunk.length;
|
|
127
|
+
});
|
|
128
|
+
// finalize the row with the current chunk slice that ends with a newline
|
|
129
|
+
const finalChunk = chunk.slice(0, idx);
|
|
130
|
+
completeRowBytes.set(finalChunk, offset);
|
|
131
|
+
// reset the incomplete chunks
|
|
132
|
+
incompleteChunks = [];
|
|
133
|
+
totalIncompleteLength = 0;
|
|
134
|
+
bytesToDecode = completeRowBytes;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
bytesToDecode = chunk.slice(lastIdx, idx);
|
|
138
|
+
}
|
|
139
|
+
const text = decoder.decode(bytesToDecode);
|
|
62
140
|
rows.push({
|
|
63
141
|
text,
|
|
64
142
|
json() {
|
|
65
|
-
return
|
|
143
|
+
return jsonHandling.parse(text);
|
|
66
144
|
},
|
|
67
145
|
});
|
|
146
|
+
lastIdx = idx + 1; // skipping newline character
|
|
68
147
|
}
|
|
69
148
|
else {
|
|
70
|
-
|
|
149
|
+
// there is no complete row in the rest of the current chunk
|
|
150
|
+
// to be processed during the next transform iteration
|
|
151
|
+
const incompleteChunk = chunk.slice(lastIdx);
|
|
152
|
+
incompleteChunks.push(incompleteChunk);
|
|
153
|
+
totalIncompleteLength += incompleteChunk.length;
|
|
154
|
+
// send the extracted rows to the consumer, if any
|
|
155
|
+
if (rows.length > 0) {
|
|
71
156
|
controller.enqueue(rows);
|
|
72
157
|
}
|
|
73
|
-
break;
|
|
74
158
|
}
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
flush() {
|
|
78
|
-
decodedChunk = '';
|
|
159
|
+
} while (idx !== -1);
|
|
79
160
|
},
|
|
80
161
|
});
|
|
81
|
-
|
|
162
|
+
const pipeline = this._stream.pipeThrough(transform, {
|
|
82
163
|
preventClose: false,
|
|
83
164
|
preventAbort: false,
|
|
84
165
|
preventCancel: false,
|
|
85
166
|
});
|
|
167
|
+
return pipeline;
|
|
86
168
|
}
|
|
87
169
|
async close() {
|
|
88
170
|
this.markAsConsumed();
|
|
89
171
|
await this._stream.cancel();
|
|
90
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Closes the `ResultSet`.
|
|
175
|
+
*
|
|
176
|
+
* Automatically called when using `using` statement in supported environments.
|
|
177
|
+
* @see {@link ResultSet.close}
|
|
178
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using
|
|
179
|
+
*/
|
|
180
|
+
async [Symbol.asyncDispose]() {
|
|
181
|
+
await this.close();
|
|
182
|
+
}
|
|
91
183
|
markAsConsumed() {
|
|
92
184
|
if (this.isAlreadyConsumed) {
|
|
93
185
|
throw new Error(streamAlreadyConsumedMessage);
|
package/dist/result_set.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result_set.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"result_set.js","sourceRoot":"","sources":["../src/result_set.ts"],"names":[],"mappings":";;;AASA,6DAAoE;AACpE,6DAIkC;AAClC,mCAAmC;AAEnC,MAAM,OAAO,GAAG,IAAa,CAAA;AAE7B,MAAa,SAAS;IASpB,YACU,OAAuB,EACd,MAAc,EACf,QAAgB,EAChC,iBAAmC,EACnC,eAA6B;QAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B;QAPD;;;;mBAAQ,OAAO;WAAgB;QAC/B;;;;mBAAiB,MAAM;WAAQ;QAC/B;;;;mBAAgB,QAAQ;WAAQ;QATlB;;;;;WAAiC;QAEhC;;;;mBAAmC,SAAS;WAAA;QACrD;;;;mBAAoB,KAAK;WAAA;QAChB;;;;;WAA0B;QAYzC,IAAI,CAAC,gBAAgB;YACnB,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QACzE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,4BAA4B,CAEzD,CAAA;QAEb,IAAI,CAAC,YAAY,G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C,WAAW,CAAC,SAAS,EAAE;YACnD,YAAY,EAAE,KAAK;YACnB,YAAY,EAAE,KAAK;YACnB,aAAa,EAAE,KAAK;SACrB,CAAC,CAAA;QACF,OAAO,QAAe,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,cAAc,EAAE,CAAA;QACrB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAA;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAEO,cAAc;QACpB,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;QAC/C,CAAC;QACD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAA;IAC/B,CAAC;CACF;AAlLD,8BAkLC;AAED,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
|
package/dist/utils/encoder.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { DataFormat, InsertValues, ValuesEncoder } from '@clickhouse/client-common';
|
|
2
|
+
import { type JSONHandling } from '@clickhouse/client-common';
|
|
2
3
|
export declare class WebValuesEncoder implements ValuesEncoder<ReadableStream> {
|
|
4
|
+
private readonly json;
|
|
5
|
+
constructor(jsonHandling?: JSONHandling);
|
|
3
6
|
encodeValues<T = unknown>(values: InsertValues<T>, format: DataFormat): string | ReadableStream;
|
|
4
7
|
validateInsertValues<T = unknown>(values: InsertValues<T>): void;
|
|
5
8
|
}
|
package/dist/utils/encoder.js
CHANGED
|
@@ -4,15 +4,29 @@ exports.WebValuesEncoder = void 0;
|
|
|
4
4
|
const client_common_1 = require("@clickhouse/client-common");
|
|
5
5
|
const stream_1 = require("./stream");
|
|
6
6
|
class WebValuesEncoder {
|
|
7
|
+
constructor(jsonHandling = {
|
|
8
|
+
parse: JSON.parse,
|
|
9
|
+
stringify: JSON.stringify,
|
|
10
|
+
}) {
|
|
11
|
+
Object.defineProperty(this, "json", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
17
|
+
this.json = jsonHandling;
|
|
18
|
+
}
|
|
7
19
|
encodeValues(values, format) {
|
|
8
20
|
throwIfStream(values);
|
|
9
21
|
// JSON* arrays
|
|
10
22
|
if (Array.isArray(values)) {
|
|
11
|
-
return values
|
|
23
|
+
return values
|
|
24
|
+
.map((value) => (0, client_common_1.encodeJSON)(value, format, this.json.stringify))
|
|
25
|
+
.join('');
|
|
12
26
|
}
|
|
13
27
|
// JSON & JSONObjectEachRow format input
|
|
14
28
|
if (typeof values === 'object') {
|
|
15
|
-
return (0, client_common_1.encodeJSON)(values, format);
|
|
29
|
+
return (0, client_common_1.encodeJSON)(values, format, this.json.stringify);
|
|
16
30
|
}
|
|
17
31
|
throw new Error(`Cannot encode values of type ${typeof values} with ${format} format`);
|
|
18
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoder.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../src/utils/encoder.ts"],"names":[],"mappings":";;;AAKA,6DAAyE;AACzE,qCAAmC;AAEnC,MAAa,gBAAgB;IAG3B,YACE,eAA6B;QAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B;QANc;;;;;WAAkB;QAQjC,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;IAC1B,CAAC;IAED,YAAY,CACV,MAAuB,EACvB,MAAkB;QAElB,aAAa,CAAC,MAAM,CAAC,CAAA;QACrB,eAAe;QACf,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,MAAM;iBACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,0BAAU,EAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBAC9D,IAAI,CAAC,EAAE,CAAC,CAAA;QACb,CAAC;QACD,wCAAwC;QACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,IAAA,0BAAU,EAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACxD,CAAC;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,CAAC;YACzD,MAAM,IAAI,KAAK,CACb,4DAA4D;gBAC1D,QAAQ,OAAO,MAAM,EAAE,CAC1B,CAAA;QACH,CAAC;IACH,CAAC;CACF;AAzCD,4CAyCC;AAED,SAAS,aAAa,CAAC,MAAe;IACpC,IAAI,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAA;IACH,CAAC;AACH,CAAC"}
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,4CAAyB"}
|
package/dist/utils/stream.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isStream = isStream;
|
|
4
|
+
exports.getAsText = getAsText;
|
|
5
|
+
// See https://github.com/v8/v8/commit/ea56bf5513d0cbd2a35a9035c5c2996272b8b728
|
|
6
|
+
const MaxStringLength = Math.pow(2, 29) - 24;
|
|
4
7
|
function isStream(obj) {
|
|
5
8
|
return (obj !== null && obj !== undefined && typeof obj.pipeThrough === 'function');
|
|
6
9
|
}
|
|
7
|
-
exports.isStream = isStream;
|
|
8
10
|
async function getAsText(stream) {
|
|
9
11
|
let result = '';
|
|
10
12
|
let isDone = false;
|
|
@@ -12,12 +14,16 @@ async function getAsText(stream) {
|
|
|
12
14
|
const reader = stream.getReader();
|
|
13
15
|
while (!isDone) {
|
|
14
16
|
const { done, value } = await reader.read();
|
|
15
|
-
|
|
17
|
+
const decoded = textDecoder.decode(value, { stream: true });
|
|
18
|
+
if (decoded.length + result.length > MaxStringLength) {
|
|
19
|
+
throw new Error('The response length exceeds the maximum allowed size of V8 String: ' +
|
|
20
|
+
`${MaxStringLength}; consider limiting the amount of requested rows.`);
|
|
21
|
+
}
|
|
22
|
+
result += decoded;
|
|
16
23
|
isDone = done;
|
|
17
24
|
}
|
|
18
25
|
// flush
|
|
19
26
|
result += textDecoder.decode();
|
|
20
27
|
return result;
|
|
21
28
|
}
|
|
22
|
-
exports.getAsText = getAsText;
|
|
23
29
|
//# sourceMappingURL=stream.js.map
|
package/dist/utils/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":";;AAGA,4BAIC;AAED,8BAuBC;AAhCD,+EAA+E;AAC/E,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAA;AAE5C,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;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,CAAC;QACf,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAC3C,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QAC3D,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;YACrD,MAAM,IAAI,KAAK,CACb,qEAAqE;gBACnE,GAAG,eAAe,mDAAmD,CACxE,CAAA;QACH,CAAC;QACD,MAAM,IAAI,OAAO,CAAA;QACjB,MAAM,GAAG,IAAI,CAAA;IACf,CAAC;IAED,QAAQ;IACR,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,CAAA;IAC9B,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "
|
|
1
|
+
declare const _default: "1.15.0";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,QAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@clickhouse/client-web",
|
|
3
3
|
"description": "Official JS client for ClickHouse DB - Web API implementation",
|
|
4
4
|
"homepage": "https://clickhouse.com",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.4.0",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"clickhouse",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/ClickHouse/clickhouse-js.git"
|
|
14
|
+
"url": "git+https://github.com/ClickHouse/clickhouse-js.git"
|
|
15
15
|
},
|
|
16
16
|
"private": false,
|
|
17
17
|
"main": "dist/index.js",
|
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prepack": "cp ../../README.md ../../LICENSE .",
|
|
24
|
+
"build": "rm -rf dist; tsc"
|
|
25
|
+
},
|
|
22
26
|
"dependencies": {
|
|
23
|
-
"@clickhouse/client-common": "0.
|
|
27
|
+
"@clickhouse/client-common": "0.4.0"
|
|
24
28
|
}
|
|
25
29
|
}
|