@clickhouse/client-web 1.12.0 → 1.13.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/dist/result_set.d.ts +1 -0
- package/dist/result_set.js +34 -20
- package/dist/result_set.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/result_set.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare class ResultSet<Format extends DataFormat | unknown> implements B
|
|
|
4
4
|
private readonly format;
|
|
5
5
|
readonly query_id: string;
|
|
6
6
|
readonly response_headers: ResponseHeaders;
|
|
7
|
+
private readonly exceptionTag;
|
|
7
8
|
private isAlreadyConsumed;
|
|
8
9
|
constructor(_stream: ReadableStream, format: Format, query_id: string, _response_headers?: ResponseHeaders);
|
|
9
10
|
/** See {@link BaseResultSet.text} */
|
package/dist/result_set.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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");
|
|
6
7
|
const NEWLINE = 0x0a;
|
|
7
8
|
class ResultSet {
|
|
@@ -30,6 +31,12 @@ class ResultSet {
|
|
|
30
31
|
writable: true,
|
|
31
32
|
value: void 0
|
|
32
33
|
});
|
|
34
|
+
Object.defineProperty(this, "exceptionTag", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: undefined
|
|
39
|
+
});
|
|
33
40
|
Object.defineProperty(this, "isAlreadyConsumed", {
|
|
34
41
|
enumerable: true,
|
|
35
42
|
configurable: true,
|
|
@@ -38,6 +45,7 @@ class ResultSet {
|
|
|
38
45
|
});
|
|
39
46
|
this.response_headers =
|
|
40
47
|
_response_headers !== undefined ? Object.freeze(_response_headers) : {};
|
|
48
|
+
this.exceptionTag = this.response_headers['x-clickhouse-exception-tag'];
|
|
41
49
|
}
|
|
42
50
|
/** See {@link BaseResultSet.text} */
|
|
43
51
|
async text() {
|
|
@@ -47,10 +55,9 @@ class ResultSet {
|
|
|
47
55
|
/** See {@link BaseResultSet.json} */
|
|
48
56
|
async json() {
|
|
49
57
|
// JSONEachRow, etc.
|
|
50
|
-
if ((0,
|
|
58
|
+
if ((0, client_common_2.isStreamableJSONFamily)(this.format)) {
|
|
51
59
|
const result = [];
|
|
52
60
|
const reader = this.stream().getReader();
|
|
53
|
-
// eslint-disable-next-line no-constant-condition
|
|
54
61
|
while (true) {
|
|
55
62
|
const { done, value } = await reader.read();
|
|
56
63
|
if (done) {
|
|
@@ -63,7 +70,7 @@ class ResultSet {
|
|
|
63
70
|
return result;
|
|
64
71
|
}
|
|
65
72
|
// JSON, JSONObjectEachRow, etc.
|
|
66
|
-
if ((0,
|
|
73
|
+
if ((0, client_common_2.isNotStreamableJSONFamily)(this.format)) {
|
|
67
74
|
const text = await (0, utils_1.getAsText)(this._stream);
|
|
68
75
|
return JSON.parse(text);
|
|
69
76
|
}
|
|
@@ -73,9 +80,10 @@ class ResultSet {
|
|
|
73
80
|
/** See {@link BaseResultSet.stream} */
|
|
74
81
|
stream() {
|
|
75
82
|
this.markAsConsumed();
|
|
76
|
-
(0,
|
|
83
|
+
(0, client_common_2.validateStreamFormat)(this.format);
|
|
77
84
|
let incompleteChunks = [];
|
|
78
85
|
let totalIncompleteLength = 0;
|
|
86
|
+
const exceptionTag = this.exceptionTag;
|
|
79
87
|
const decoder = new TextDecoder('utf-8');
|
|
80
88
|
const transform = new TransformStream({
|
|
81
89
|
start() {
|
|
@@ -89,24 +97,18 @@ class ResultSet {
|
|
|
89
97
|
let idx;
|
|
90
98
|
let lastIdx = 0;
|
|
91
99
|
do {
|
|
92
|
-
// an unescaped newline character denotes the end of a row
|
|
100
|
+
// an unescaped newline character denotes the end of a row,
|
|
101
|
+
// or at least the beginning of the exception marker
|
|
93
102
|
idx = chunk.indexOf(NEWLINE, lastIdx);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
totalIncompleteLength += incompleteChunk.length;
|
|
100
|
-
// send the extracted rows to the consumer, if any
|
|
101
|
-
if (rows.length > 0) {
|
|
102
|
-
controller.enqueue(rows);
|
|
103
|
+
if (idx !== -1) {
|
|
104
|
+
let bytesToDecode;
|
|
105
|
+
const maybeErr = (0, client_common_1.checkErrorInChunkAtIndex)(chunk, idx, exceptionTag);
|
|
106
|
+
if (maybeErr) {
|
|
107
|
+
controller.error(maybeErr);
|
|
103
108
|
}
|
|
104
|
-
|
|
105
|
-
else {
|
|
106
|
-
let text;
|
|
109
|
+
// using the incomplete chunks from the previous iterations
|
|
107
110
|
if (incompleteChunks.length > 0) {
|
|
108
111
|
const completeRowBytes = new Uint8Array(totalIncompleteLength + idx);
|
|
109
|
-
// using the incomplete chunks from the previous iterations
|
|
110
112
|
let offset = 0;
|
|
111
113
|
incompleteChunks.forEach((incompleteChunk) => {
|
|
112
114
|
completeRowBytes.set(incompleteChunk, offset);
|
|
@@ -118,11 +120,12 @@ class ResultSet {
|
|
|
118
120
|
// reset the incomplete chunks
|
|
119
121
|
incompleteChunks = [];
|
|
120
122
|
totalIncompleteLength = 0;
|
|
121
|
-
|
|
123
|
+
bytesToDecode = completeRowBytes;
|
|
122
124
|
}
|
|
123
125
|
else {
|
|
124
|
-
|
|
126
|
+
bytesToDecode = chunk.slice(lastIdx, idx);
|
|
125
127
|
}
|
|
128
|
+
const text = decoder.decode(bytesToDecode);
|
|
126
129
|
rows.push({
|
|
127
130
|
text,
|
|
128
131
|
json() {
|
|
@@ -131,6 +134,17 @@ class ResultSet {
|
|
|
131
134
|
});
|
|
132
135
|
lastIdx = idx + 1; // skipping newline character
|
|
133
136
|
}
|
|
137
|
+
else {
|
|
138
|
+
// there is no complete row in the rest of the current chunk
|
|
139
|
+
// to be processed during the next transform iteration
|
|
140
|
+
const incompleteChunk = chunk.slice(lastIdx);
|
|
141
|
+
incompleteChunks.push(incompleteChunk);
|
|
142
|
+
totalIncompleteLength += incompleteChunk.length;
|
|
143
|
+
// send the extracted rows to the consumer, if any
|
|
144
|
+
if (rows.length > 0) {
|
|
145
|
+
controller.enqueue(rows);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
134
148
|
} while (idx !== -1);
|
|
135
149
|
},
|
|
136
150
|
});
|
package/dist/result_set.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result_set.js","sourceRoot":"","sources":["../../../packages/client-web/src/result_set.ts"],"names":[],"mappings":";;;AAQA,6DAIkC;AAClC,mCAAmC;AAEnC,MAAM,OAAO,GAAG,IAAa,CAAA;AAE7B,MAAa,SAAS;
|
|
1
|
+
{"version":3,"file":"result_set.js","sourceRoot":"","sources":["../../../packages/client-web/src/result_set.ts"],"names":[],"mappings":";;;AAQA,6DAAoE;AACpE,6DAIkC;AAClC,mCAAmC;AAEnC,MAAM,OAAO,GAAG,IAAa,CAAA;AAE7B,MAAa,SAAS;IAQpB,YACU,OAAuB,EACd,MAAc,EACf,QAAgB,EAChC,iBAAmC;QAHnC;;;;mBAAQ,OAAO;WAAgB;QAC/B;;;;mBAAiB,MAAM;WAAQ;QAC/B;;;;mBAAgB,QAAQ;WAAQ;QARlB;;;;;WAAiC;QAEhC;;;;mBAAmC,SAAS;WAAA;QACrD;;;;mBAAoB,KAAK;WAAA;QAQ/B,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;IACf,CAAC;IAED,qCAAqC;IACrC,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,cAAc,EAA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AED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,cAAc,EAAE,CAAA;QACrB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAA;IAC7B,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;AA/JD,8BA+JC;AAED,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.13.0";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED
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": "1.
|
|
5
|
+
"version": "1.13.0",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"clickhouse",
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@clickhouse/client-common": "1.
|
|
23
|
+
"@clickhouse/client-common": "1.13.0"
|
|
24
24
|
}
|
|
25
25
|
}
|