@clickhouse/client 0.0.4 → 0.0.5
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/README.md +51 -300
- package/dist/client.d.ts +24 -2
- package/dist/client.js +4 -4
- package/dist/client.js.map +1 -1
- package/dist/connection/adapter/base_http_adapter.d.ts +2 -2
- package/dist/connection/adapter/base_http_adapter.js +2 -2
- package/dist/connection/adapter/base_http_adapter.js.map +1 -1
- package/dist/connection/connection.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/{rows.d.ts → result.d.ts} +14 -13
- package/dist/result.js +134 -0
- package/dist/result.js.map +1 -0
- package/dist/schema/query_formatter.d.ts +1 -1
- package/dist/schema/table.js +7 -5
- package/dist/schema/table.js.map +1 -1
- package/package.json +5 -4
- package/dist/rows.js +0 -114
- package/dist/rows.js.map +0 -1
- package/dist/schema/compact.d.ts +0 -3
- package/dist/schema/compact.js +0 -24
- package/dist/schema/compact.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
</p>
|
|
5
5
|
<br/>
|
|
6
6
|
<p align="center">
|
|
7
|
-
<a href="https://github.com/ClickHouse/clickhouse-js/actions/workflows/
|
|
8
|
-
<img src="https://github.com/ClickHouse/clickhouse-js/actions/workflows/
|
|
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
|
+
<a href="http://htmlpreview.github.io/?https://github.com/ClickHouse/clickhouse-js/blob/main/coverage/lcov-report/index.html">
|
|
11
|
+
<img src="./coverage/badge.svg">
|
|
9
12
|
</a>
|
|
10
13
|
</p>
|
|
11
14
|
|
|
@@ -20,7 +23,7 @@ It is focused on data streaming for both inserts and selects using standard [Nod
|
|
|
20
23
|
The client is tested with the following ClickHouse and Node.js versions:
|
|
21
24
|
|
|
22
25
|
| Node.js | ClickHouse | Status |
|
|
23
|
-
|
|
26
|
+
| ------- | ---------- | ------ |
|
|
24
27
|
| 14.x | 22.8 | ✔ |
|
|
25
28
|
| 16.x | 22.8 | ✔ |
|
|
26
29
|
| 18.x | 22.8 | ✔ |
|
|
@@ -148,8 +151,8 @@ See also:
|
|
|
148
151
|
## Supported formats
|
|
149
152
|
|
|
150
153
|
| Format | Input (array) | Input (stream) | Output (JSON) | Output (text) |
|
|
151
|
-
|
|
152
|
-
| JSON | ❌
|
|
154
|
+
| ------------------------------------------ | ------------- | -------------- | ------------- | ------------- |
|
|
155
|
+
| JSON | ❌ | ❌ | ✔️ | ✔️ |
|
|
153
156
|
| JSONEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
154
157
|
| JSONStringsEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
155
158
|
| JSONCompactEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
@@ -158,49 +161,49 @@ See also:
|
|
|
158
161
|
| JSONCompactEachRowWithNamesAndTypes | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
159
162
|
| JSONCompactStringsEachRowWithNames | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
160
163
|
| JSONCompactStringsEachRowWithNamesAndTypes | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
161
|
-
| CSV | ❌
|
|
162
|
-
| CSVWithNames | ❌
|
|
163
|
-
| CSVWithNamesAndTypes | ❌
|
|
164
|
-
| TabSeparated | ❌
|
|
165
|
-
| TabSeparatedRaw | ❌
|
|
166
|
-
| TabSeparatedWithNames | ❌
|
|
167
|
-
| TabSeparatedWithNamesAndTypes | ❌
|
|
168
|
-
| CustomSeparated | ❌
|
|
169
|
-
| CustomSeparatedWithNames | ❌
|
|
170
|
-
| CustomSeparatedWithNamesAndTypes | ❌
|
|
164
|
+
| CSV | ❌ | ✔️ | ❌ | ✔️ |
|
|
165
|
+
| CSVWithNames | ❌ | ✔️ | ❌ | ✔️ |
|
|
166
|
+
| CSVWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
|
|
167
|
+
| TabSeparated | ❌ | ✔️ | ❌ | ✔️ |
|
|
168
|
+
| TabSeparatedRaw | ❌ | ✔️ | ❌ | ✔️ |
|
|
169
|
+
| TabSeparatedWithNames | ❌ | ✔️ | ❌ | ✔️ |
|
|
170
|
+
| TabSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
|
|
171
|
+
| CustomSeparated | ❌ | ✔️ | ❌ | ✔️ |
|
|
172
|
+
| CustomSeparatedWithNames | ❌ | ✔️ | ❌ | ✔️ |
|
|
173
|
+
| CustomSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
|
|
171
174
|
|
|
172
175
|
The entire list of ClickHouse input and output formats is available [here](https://clickhouse.com/docs/en/interfaces/formats).
|
|
173
176
|
|
|
174
177
|
## Supported ClickHouse data types
|
|
175
178
|
|
|
176
|
-
| Type | Status
|
|
177
|
-
|
|
178
|
-
| UInt8/16/32 | ✔️
|
|
179
|
+
| Type | Status | JS type |
|
|
180
|
+
| -------------- | --------------- | ------------------------------------- |
|
|
181
|
+
| UInt8/16/32 | ✔️ | number |
|
|
179
182
|
| UInt64/128/256 | ✔️❗- see below | string |
|
|
180
|
-
| Int8/16/32 | ✔️
|
|
183
|
+
| Int8/16/32 | ✔️ | number |
|
|
181
184
|
| Int64/128/256 | ✔️❗- see below | string |
|
|
182
|
-
| Float32/64 | ✔️
|
|
185
|
+
| Float32/64 | ✔️ | number |
|
|
183
186
|
| Decimal | ✔️❗- see below | number |
|
|
184
|
-
| Boolean | ✔️
|
|
185
|
-
| String | ✔️
|
|
186
|
-
| FixedString | ✔️
|
|
187
|
-
| UUID | ✔️
|
|
187
|
+
| Boolean | ✔️ | boolean |
|
|
188
|
+
| String | ✔️ | string |
|
|
189
|
+
| FixedString | ✔️ | string |
|
|
190
|
+
| UUID | ✔️ | string |
|
|
188
191
|
| Date32/64 | ✔️❗- see below | string |
|
|
189
192
|
| DateTime32/64 | ✔️❗- see below | string |
|
|
190
|
-
| Enum | ✔️
|
|
191
|
-
| LowCardinality | ✔️
|
|
192
|
-
| Array(T) | ✔️
|
|
193
|
-
| JSON | ✔️
|
|
193
|
+
| Enum | ✔️ | string |
|
|
194
|
+
| LowCardinality | ✔️ | string |
|
|
195
|
+
| Array(T) | ✔️ | Array\<JS type for T> |
|
|
196
|
+
| JSON | ✔️ | object |
|
|
194
197
|
| Nested | ❌ | - |
|
|
195
|
-
| Tuple | ✔️
|
|
196
|
-
| Nullable(T) | ✔️
|
|
197
|
-
| IPv4 | ✔️
|
|
198
|
-
| IPv6 | ✔️
|
|
199
|
-
| Point | ✔️
|
|
200
|
-
| Ring | ✔️
|
|
201
|
-
| Polygon | ✔️
|
|
202
|
-
| MultiPolygon | ✔️
|
|
203
|
-
| Map(K, V) | ✔️
|
|
198
|
+
| Tuple | ✔️ | Tuple |
|
|
199
|
+
| Nullable(T) | ✔️ | JS type for T or null |
|
|
200
|
+
| IPv4 | ✔️ | string |
|
|
201
|
+
| IPv6 | ✔️ | string |
|
|
202
|
+
| Point | ✔️ | [ number, number ] |
|
|
203
|
+
| Ring | ✔️ | Array\<Point> |
|
|
204
|
+
| Polygon | ✔️ | Array\<Ring> |
|
|
205
|
+
| MultiPolygon | ✔️ | Array\<Polygon> |
|
|
206
|
+
| Map(K, V) | ✔️ | Record\<JS type for K, JS type for V> |
|
|
204
207
|
|
|
205
208
|
The entire list of supported ClickHouse formats is available [here](https://clickhouse.com/docs/en/sql-reference/data-types/).
|
|
206
209
|
|
|
@@ -251,12 +254,12 @@ class ClickHouseClient {
|
|
|
251
254
|
}
|
|
252
255
|
```
|
|
253
256
|
|
|
254
|
-
####
|
|
257
|
+
#### ResultSet response abstraction
|
|
255
258
|
|
|
256
|
-
Provides several convenience methods for data processing in your application.
|
|
259
|
+
Provides several convenience methods for data processing of select results in your application.
|
|
257
260
|
|
|
258
261
|
```ts
|
|
259
|
-
class
|
|
262
|
+
class ResultSet {
|
|
260
263
|
// Consume the entire stream and get the contents as a string
|
|
261
264
|
// Can be used with any DataFormat
|
|
262
265
|
// Should be called only once
|
|
@@ -265,17 +268,18 @@ class Rows {
|
|
|
265
268
|
// Can be used only with JSON formats
|
|
266
269
|
// Should be called only once
|
|
267
270
|
json<T>(): Promise<T> {}
|
|
268
|
-
// Returns a readable stream
|
|
271
|
+
// Returns a readable stream for responses that can be streamed (i.e. all except JSON)
|
|
272
|
+
// Every iteration provides an array of `Row` instances
|
|
269
273
|
// Should be called only once
|
|
270
274
|
// NB: if called for the second time, the second stream will be just empty
|
|
271
275
|
stream(): Stream.Readable {}
|
|
272
276
|
}
|
|
273
277
|
|
|
274
|
-
|
|
275
|
-
// Get the content of
|
|
276
|
-
text(): string
|
|
277
|
-
// Get the content of
|
|
278
|
-
json<T>(): T
|
|
278
|
+
interface Row {
|
|
279
|
+
// Get the content of an individual row as a plain string
|
|
280
|
+
text(): string
|
|
281
|
+
// Get the content of an individual row as a JS object
|
|
282
|
+
json<T>(): T
|
|
279
283
|
}
|
|
280
284
|
```
|
|
281
285
|
|
|
@@ -365,265 +369,12 @@ class ClickHouseClient {
|
|
|
365
369
|
|
|
366
370
|
## Usage examples
|
|
367
371
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
```ts
|
|
371
|
-
await client.exec({
|
|
372
|
-
query: `
|
|
373
|
-
CREATE TABLE foobar
|
|
374
|
-
(id UInt64, name String)
|
|
375
|
-
ENGINE MergeTree()
|
|
376
|
-
ORDER BY (id)
|
|
377
|
-
`,
|
|
378
|
-
})
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
### Create a table (local cluster)
|
|
382
|
-
|
|
383
|
-
```ts
|
|
384
|
-
await client.exec({
|
|
385
|
-
query: `
|
|
386
|
-
CREATE TABLE foobar ON CLUSTER '{cluster}'
|
|
387
|
-
(id UInt64, name String)
|
|
388
|
-
ENGINE ReplicatedMergeTree(
|
|
389
|
-
'/clickhouse/{cluster}/tables/{database}/{table}/{shard}',
|
|
390
|
-
'{replica}'
|
|
391
|
-
)
|
|
392
|
-
ORDER BY (id)
|
|
393
|
-
`,
|
|
394
|
-
// Recommended for cluster usage to avoid situations
|
|
395
|
-
// where a query processing error occurred after the response code
|
|
396
|
-
// and HTTP headers were sent to the client.
|
|
397
|
-
// See https://clickhouse.com/docs/en/interfaces/http/#response-buffering
|
|
398
|
-
clickhouse_settings: {
|
|
399
|
-
wait_end_of_query: 1,
|
|
400
|
-
},
|
|
401
|
-
})
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
### Create a table (ClickHouse cloud)
|
|
405
|
-
|
|
406
|
-
Note that `ENGINE` and `ON CLUSTER` clauses can be omitted entirely here.
|
|
407
|
-
|
|
408
|
-
ClickHouse cloud will automatically use `ReplicatedMergeTree` with appropriate settings in this case.
|
|
409
|
-
|
|
410
|
-
```ts
|
|
411
|
-
await client.exec({
|
|
412
|
-
query: `
|
|
413
|
-
CREATE TABLE foobar
|
|
414
|
-
(id UInt64, name String)
|
|
415
|
-
ORDER BY (id)
|
|
416
|
-
`,
|
|
417
|
-
// Recommended for cluster usage to avoid situations
|
|
418
|
-
// where a query processing error occurred after the response code
|
|
419
|
-
// and HTTP headers were sent to the client.
|
|
420
|
-
// See https://clickhouse.com/docs/en/interfaces/http/#response-buffering
|
|
421
|
-
clickhouse_settings: {
|
|
422
|
-
wait_end_of_query: 1,
|
|
423
|
-
},
|
|
424
|
-
})
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
### Insert with array input (JSON\* family formats only)
|
|
428
|
-
|
|
429
|
-
```ts
|
|
430
|
-
await client.insert({
|
|
431
|
-
table: tableName,
|
|
432
|
-
// structure should match the desired format, JSONEachRow in this example
|
|
433
|
-
values: [
|
|
434
|
-
{ id: 42, name: 'foo' },
|
|
435
|
-
{ id: 42, name: 'bar' },
|
|
436
|
-
],
|
|
437
|
-
format: 'JSONEachRow',
|
|
438
|
-
})
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
### Insert with stream input (any format except JSON, stream is created out of an array)
|
|
442
|
-
|
|
443
|
-
```ts
|
|
444
|
-
await client.insert({
|
|
445
|
-
table: tableName,
|
|
446
|
-
// structure should match the desired format, JSONCompactEachRow in this example
|
|
447
|
-
values: Stream.Readable.from([
|
|
448
|
-
[42, 'foo'],
|
|
449
|
-
[42, 'bar'],
|
|
450
|
-
]),
|
|
451
|
-
format: 'JSONCompactEachRow',
|
|
452
|
-
})
|
|
453
|
-
```
|
|
454
|
-
|
|
455
|
-
### Insert with stream input (any format except JSON, flowing stream)
|
|
456
|
-
|
|
457
|
-
```ts
|
|
458
|
-
const stream = new Stream.Readable({
|
|
459
|
-
objectMode: true, // required for JSON* family formats
|
|
460
|
-
read() {
|
|
461
|
-
/* stub */
|
|
462
|
-
},
|
|
463
|
-
})
|
|
464
|
-
// ... your (async) code pushing the values into the stream...
|
|
465
|
-
await client.insert({
|
|
466
|
-
table: tableName,
|
|
467
|
-
values: stream,
|
|
468
|
-
format: 'JSONEachRow', // or any other desired JSON* format
|
|
469
|
-
})
|
|
470
|
-
// close the stream when finished by pushing a null value there
|
|
471
|
-
stream.push(null)
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
### Insert with stream input ("raw" formats like CSV* / TabSeparated* / CustomSeparated\*, stream is created out of an array)
|
|
475
|
-
|
|
476
|
-
```ts
|
|
477
|
-
await client.insert({
|
|
478
|
-
table: tableName,
|
|
479
|
-
// structure should match the desired format, TabSeparated in this example
|
|
480
|
-
values: Stream.Readable.from(['42,foobar'], {
|
|
481
|
-
objectMode: false, // required for "raw" family formats
|
|
482
|
-
}),
|
|
483
|
-
format: 'TabSeparated', // or any other desired "raw" format
|
|
484
|
-
})
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
### Insert with stream input ("raw" formats like CSV* / TabSeparated* / CustomSeparated\*, flowing stream)
|
|
488
|
-
|
|
489
|
-
```ts
|
|
490
|
-
const stream = new Stream.Readable({
|
|
491
|
-
objectMode: false, // required for "raw" family formats
|
|
492
|
-
read() {
|
|
493
|
-
/* stub */
|
|
494
|
-
},
|
|
495
|
-
})
|
|
496
|
-
// ... your (async) code pushing the values into the stream...
|
|
497
|
-
await client.insert({
|
|
498
|
-
table: tableName,
|
|
499
|
-
values: stream,
|
|
500
|
-
format: 'TabSeparated', // or any other desired "raw" format
|
|
501
|
-
})
|
|
502
|
-
// close the stream when finished by pushing a null value there
|
|
503
|
-
stream.push(null)
|
|
504
|
-
```
|
|
505
|
-
|
|
506
|
-
### Inserting a file (for example, CSV)
|
|
507
|
-
|
|
508
|
-
```ts
|
|
509
|
-
const filename = Path.resolve(process.cwd(), 'path/to/file.csv')
|
|
510
|
-
await client.insert({
|
|
511
|
-
table: tableName,
|
|
512
|
-
values: Fs.createReadStream(filename),
|
|
513
|
-
format: 'CSVWithNames',
|
|
514
|
-
})
|
|
515
|
-
```
|
|
372
|
+
You can find code samples in the [examples](./examples) folder (with [README](./examples/README.md)).
|
|
516
373
|
|
|
517
374
|
See also:
|
|
518
375
|
|
|
519
|
-
- [NDJSON file streaming example](https://github.com/ClickHouse/clickhouse-js/blob/60c484a3492420baed4b4c6c33cc0845262285e7/examples/streaming/stream_ndjson.ts)
|
|
520
376
|
- [Memory leaks test using Brown University benchmarks files](https://github.com/ClickHouse/clickhouse-js/blob/60c484a3492420baed4b4c6c33cc0845262285e7/benchmarks/leaks/memory_leak_brown.ts#L72-L80)
|
|
521
377
|
|
|
522
|
-
### Selecting the data as JSON using a JSON\* family format
|
|
523
|
-
|
|
524
|
-
```ts
|
|
525
|
-
const rows = await client.query({
|
|
526
|
-
query: 'SELECT number FROM system.numbers LIMIT 5',
|
|
527
|
-
format: 'JSONCompactEachRow',
|
|
528
|
-
})
|
|
529
|
-
const result = await rows.json()
|
|
530
|
-
// result is [['0'], ['1'], ['2'], ['3'], ['4']]
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
### Selecting the data as JSON including response metadata
|
|
534
|
-
|
|
535
|
-
```ts
|
|
536
|
-
const rows = await client.query({
|
|
537
|
-
query: 'SELECT number FROM system.numbers LIMIT 2',
|
|
538
|
-
format: 'JSON',
|
|
539
|
-
})
|
|
540
|
-
const result = await rows.json<ResponseJSON<{ number: string }>>()
|
|
541
|
-
|
|
542
|
-
/* result will look like
|
|
543
|
-
|
|
544
|
-
{
|
|
545
|
-
"meta": [ { "name": "number", "type": "UInt64" } ],
|
|
546
|
-
"data": [ { "number": "0"}, { "number": "1" } ],
|
|
547
|
-
"rows": 2,
|
|
548
|
-
"rows_before_limit_at_least": 2,
|
|
549
|
-
"statistics": {
|
|
550
|
-
"elapsed": 0.00013129,
|
|
551
|
-
"rows_read": 2,
|
|
552
|
-
"bytes_read": 16
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
*/
|
|
557
|
-
```
|
|
558
|
-
|
|
559
|
-
### Selecting the data as text
|
|
560
|
-
|
|
561
|
-
```ts
|
|
562
|
-
const rows = await client.query({
|
|
563
|
-
query: `SELECT number FROM system.numbers LIMIT 2`,
|
|
564
|
-
format: 'CSV',
|
|
565
|
-
})
|
|
566
|
-
const result = await rows.text()
|
|
567
|
-
// result is now '0\n1\n'
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
### Selecting the data as a stream
|
|
571
|
-
|
|
572
|
-
```ts
|
|
573
|
-
const rows = await client.query({
|
|
574
|
-
query: `SELECT * from ${tableName}`,
|
|
575
|
-
format: 'JSONCompactEachRow',
|
|
576
|
-
})
|
|
577
|
-
for await (const row of rows.stream()) {
|
|
578
|
-
const data = (row as Row).json()
|
|
579
|
-
// ... your code processing the data here
|
|
580
|
-
}
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
### Query with parameter binding
|
|
584
|
-
|
|
585
|
-
```ts
|
|
586
|
-
const rows = await client.query({
|
|
587
|
-
query: 'SELECT plus({val1: Int32}, {val2: Int32})',
|
|
588
|
-
format: 'CSV',
|
|
589
|
-
query_params: {
|
|
590
|
-
val1: 10,
|
|
591
|
-
val2: 20,
|
|
592
|
-
},
|
|
593
|
-
})
|
|
594
|
-
const result = await rows.text()
|
|
595
|
-
// result is '30\n'
|
|
596
|
-
```
|
|
597
|
-
|
|
598
|
-
### Query with custom ClickHouse settings
|
|
599
|
-
|
|
600
|
-
```ts
|
|
601
|
-
await client.insert({
|
|
602
|
-
table: tableName,
|
|
603
|
-
values: [
|
|
604
|
-
{ id: 42, name: 'foo' },
|
|
605
|
-
{ id: 42, name: 'bar' },
|
|
606
|
-
],
|
|
607
|
-
format: 'JSONEachRow',
|
|
608
|
-
clickhouse_settings: { insert_quorum: '2' },
|
|
609
|
-
})
|
|
610
|
-
```
|
|
611
|
-
|
|
612
|
-
### Abort query
|
|
613
|
-
|
|
614
|
-
```ts
|
|
615
|
-
import { AbortController } from 'node-abort-controller'
|
|
616
|
-
|
|
617
|
-
const controller = new AbortController()
|
|
618
|
-
const selectPromise = client.query({
|
|
619
|
-
query: 'SELECT sleep(3)',
|
|
620
|
-
format: 'CSV',
|
|
621
|
-
abort_signal: controller.signal as AbortSignal,
|
|
622
|
-
})
|
|
623
|
-
controller.abort()
|
|
624
|
-
// selectPromise is now rejected with "The request was aborted" message
|
|
625
|
-
```
|
|
626
|
-
|
|
627
378
|
## Known limitations
|
|
628
379
|
|
|
629
380
|
- Browser usage is not supported.
|
package/dist/client.d.ts
CHANGED
|
@@ -2,42 +2,64 @@
|
|
|
2
2
|
import Stream from 'stream';
|
|
3
3
|
import { Logger } from './logger';
|
|
4
4
|
import { type DataFormat } from './data_formatter';
|
|
5
|
-
import {
|
|
5
|
+
import { ResultSet } from './result';
|
|
6
6
|
import type { ClickHouseSettings } from './settings';
|
|
7
7
|
export interface ClickHouseClientConfigOptions {
|
|
8
|
+
/** A ClickHouse instance URL. Default value: `http://localhost:8123`. */
|
|
8
9
|
host?: string;
|
|
10
|
+
/** The timeout to setup a connection in milliseconds. Default value: `10_000`. */
|
|
9
11
|
connect_timeout?: number;
|
|
12
|
+
/** The request timeout in milliseconds. Default value: `30_000`. */
|
|
10
13
|
request_timeout?: number;
|
|
14
|
+
/** Maximum number of sockets to allow per host. Default value: `Infinity`. */
|
|
11
15
|
max_open_connections?: number;
|
|
12
16
|
compression?: {
|
|
17
|
+
/** `response: true` instructs ClickHouse server to respond with compressed response body. Default: true. */
|
|
13
18
|
response?: boolean;
|
|
19
|
+
/** `request: true` enabled compression on the client request body. Default: false. */
|
|
14
20
|
request?: boolean;
|
|
15
21
|
};
|
|
22
|
+
/** The name of the user on whose behalf requests are made. Default: 'default'. */
|
|
16
23
|
username?: string;
|
|
24
|
+
/** The user password. Default: ''. */
|
|
17
25
|
password?: string;
|
|
26
|
+
/** The name of the application using the nodejs client. Default: 'clickhouse-js'. */
|
|
18
27
|
application?: string;
|
|
28
|
+
/** Database name to use. Default value: `default`. */
|
|
19
29
|
database?: string;
|
|
30
|
+
/** ClickHouse settings to apply to all requests. Default value: {} */
|
|
20
31
|
clickhouse_settings?: ClickHouseSettings;
|
|
21
32
|
log?: {
|
|
33
|
+
/** Enable logging. Default value: false. */
|
|
22
34
|
enable?: boolean;
|
|
35
|
+
/** A class to instantiate a custom logger implementation. */
|
|
23
36
|
LoggerClass?: new (enabled: boolean) => Logger;
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
39
|
export interface BaseParams {
|
|
40
|
+
/** ClickHouse settings that can be applied on query level. */
|
|
27
41
|
clickhouse_settings?: ClickHouseSettings;
|
|
42
|
+
/** Parameters for query binding. https://clickhouse.com/docs/en/interfaces/http/#cli-queries-with-parameters */
|
|
28
43
|
query_params?: Record<string, unknown>;
|
|
44
|
+
/** AbortSignal instance (using `node-abort-controller` package) to cancel a request in progress. */
|
|
29
45
|
abort_signal?: AbortSignal;
|
|
30
46
|
}
|
|
31
47
|
export interface QueryParams extends BaseParams {
|
|
48
|
+
/** Statement to execute. */
|
|
32
49
|
query: string;
|
|
50
|
+
/** Format of the resulting dataset. */
|
|
33
51
|
format?: DataFormat;
|
|
34
52
|
}
|
|
35
53
|
export interface ExecParams extends BaseParams {
|
|
54
|
+
/** Statement to execute. */
|
|
36
55
|
query: string;
|
|
37
56
|
}
|
|
38
57
|
export interface InsertParams<T = unknown> extends BaseParams {
|
|
58
|
+
/** Name of a table to insert into. */
|
|
39
59
|
table: string;
|
|
60
|
+
/** A dataset to insert. */
|
|
40
61
|
values: ReadonlyArray<T> | Stream.Readable;
|
|
62
|
+
/** Format of the dataset to insert. */
|
|
41
63
|
format?: DataFormat;
|
|
42
64
|
}
|
|
43
65
|
export declare class ClickHouseClient {
|
|
@@ -46,7 +68,7 @@ export declare class ClickHouseClient {
|
|
|
46
68
|
readonly logger: Logger;
|
|
47
69
|
constructor(config?: ClickHouseClientConfigOptions);
|
|
48
70
|
private getBaseParams;
|
|
49
|
-
query(params: QueryParams): Promise<
|
|
71
|
+
query(params: QueryParams): Promise<ResultSet>;
|
|
50
72
|
exec(params: ExecParams): Promise<Stream.Readable>;
|
|
51
73
|
insert<T>(params: InsertParams<T>): Promise<void>;
|
|
52
74
|
ping(): Promise<boolean>;
|
package/dist/client.js
CHANGED
|
@@ -9,7 +9,7 @@ const connection_1 = require("./connection");
|
|
|
9
9
|
const logger_1 = require("./logger");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
const data_formatter_1 = require("./data_formatter");
|
|
12
|
-
const
|
|
12
|
+
const result_1 = require("./result");
|
|
13
13
|
function validateConfig({ url }) {
|
|
14
14
|
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
15
15
|
throw new Error(`Only http(s) protocol is supported, but given: [${url.protocol}]`);
|
|
@@ -88,15 +88,15 @@ class ClickHouseClient {
|
|
|
88
88
|
var _a;
|
|
89
89
|
const format = (_a = params.format) !== null && _a !== void 0 ? _a : 'JSON';
|
|
90
90
|
const query = formatQuery(params.query, format);
|
|
91
|
-
const stream = await this.connection.
|
|
91
|
+
const stream = await this.connection.query({
|
|
92
92
|
query,
|
|
93
93
|
...this.getBaseParams(params),
|
|
94
94
|
});
|
|
95
|
-
return new
|
|
95
|
+
return new result_1.ResultSet(stream, format);
|
|
96
96
|
}
|
|
97
97
|
exec(params) {
|
|
98
98
|
const query = removeSemi(params.query.trim());
|
|
99
|
-
return this.connection.
|
|
99
|
+
return this.connection.exec({
|
|
100
100
|
query,
|
|
101
101
|
...this.getBaseParams(params),
|
|
102
102
|
});
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,6CAAgE;AAChE,qCAAiC;AACjC,mCAA6C;AAC7C,qDAIyB;AACzB,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,6CAAgE;AAChE,qCAAiC;AACjC,mCAA6C;AAC7C,qDAIyB;AACzB,qCAAoC;AAmEpC,SAAS,cAAc,CAAC,EAAE,GAAG,EAAoB;IAC/C,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE;QACzD,MAAM,IAAI,KAAK,CACb,mDAAmD,GAAG,CAAC,QAAQ,GAAG,CACnE,CAAA;KACF;IACD,0BAA0B;AAC5B,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI;QACF,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,CAAA;KACrB;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;KAC1E;AACH,CAAC;AAED,SAAS,eAAe,CACtB,MAAqC,EACrC,cAAuB;;IAEvB,OAAO;QACL,GAAG,EAAE,SAAS,CAAC,MAAA,MAAM,CAAC,IAAI,mCAAI,uBAAuB,CAAC;QACtD,eAAe,EAAE,MAAA,MAAM,CAAC,eAAe,mCAAI,K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,CAAC,kBAAkB,EAAE;gBAC7B,MAAM,IAAI,KAAK,CACb,cAAc,MAAM,sDAAsD,CAC3E,CAAA;aACF;SACF;aAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE;YACrC,MAAM,IAAI,KAAK,CACb,cAAc,MAAM,qDAAqD,CAC1E,CAAA;SACF;KACF;AACH,CAAC;AAvBD,oDAuBC;AAED;;;;;;;;GAQG;AACH,SAAS,YAAY,CACnB,MAA4C,EAC5C,MAAkB;IAElB,IAAI,IAAA,gBAAQ,EAAC,MAAM,CAAC,EAAE;QACpB,yEAAyE;QACzE,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE;YAC9B,OAAO,MAAM,CAAA;SACd;QACD,wBAAwB;QACxB,OAAO,gBAAM,CAAC,QAAQ,CACpB,MAAM,EACN,IAAA,iBAAS,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAU,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC,EAC/C,UAAU,CACX,CAAA;KACF;IACD,eAAe;IACf,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAU,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAClE,CAAC;AAED,SAAgB,YAAY,CAC1B,MAAsC;IAEtC,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;AACrC,CAAC;AAJD,oCAIC;AAED,SAAS,UAAU,CAAC,GAAiC;IACnD,IAAI,GAAG,EAAE;QACP,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;KACnB;AACH,CAAC"}
|
|
@@ -21,8 +21,8 @@ export declare abstract class BaseHttpAdapter implements Connection {
|
|
|
21
21
|
protected abstract createClientRequest(url: URL, params: RequestParams): Http.ClientRequest;
|
|
22
22
|
protected request(params: RequestParams): Promise<Stream.Readable>;
|
|
23
23
|
ping(): Promise<boolean>;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
query(params: BaseParams): Promise<Stream.Readable>;
|
|
25
|
+
exec(params: BaseParams): Promise<Stream.Readable>;
|
|
26
26
|
insert(params: InsertParams): Promise<void>;
|
|
27
27
|
close(): Promise<void>;
|
|
28
28
|
private logResponse;
|
|
@@ -193,7 +193,7 @@ class BaseHttpAdapter {
|
|
|
193
193
|
response.destroy();
|
|
194
194
|
return true;
|
|
195
195
|
}
|
|
196
|
-
async
|
|
196
|
+
async query(params) {
|
|
197
197
|
const clickhouse_settings = withHttpSettings(params.clickhouse_settings, this.config.compression.decompress_response);
|
|
198
198
|
const searchParams = (0, http_search_params_1.toSearchParams)({
|
|
199
199
|
database: this.config.database,
|
|
@@ -208,7 +208,7 @@ class BaseHttpAdapter {
|
|
|
208
208
|
decompress_response: clickhouse_settings.enable_http_compression === 1,
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
|
-
async
|
|
211
|
+
async exec(params) {
|
|
212
212
|
const searchParams = (0, http_search_params_1.toSearchParams)({
|
|
213
213
|
database: this.config.database,
|
|
214
214
|
clickhouse_settings: params.clickhouse_settings,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base_http_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/base_http_adapter.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,gDAAuB;AACvB,uCAAwC;AAUxC,6DAAqD;AACrD,mDAA8C;AAC9C,uCAAiD;AAYjD,SAAS,oBAAoB,CAAC,UAAmB;IAC/C,OAAO,OAAO,CAAC,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,UAAU,GAAG,GAAG,CAAC,CAAA;AACrE,CAAC;AAED,SAAS,aAAa,CAAC,MAAW;IAChC,OAAO,qBAAqB,IAAI,MAAM,CAAA;AACxC,CAAC;AAED,SAAS,gBAAgB,CACvB,mBAAwC,EACxC,WAAqB;IAErB,OAAO;QACL,GAAG,CAAC,WAAW;YACb,CAAC,CAAC;gBACE,uBAAuB,E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,EAAE,OAAO,EAAE,CAAC;SAC/D,CAAC,CAAA;QACF,QAAQ,CAAC,OAAO,EAAE,CAAA;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"base_http_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/base_http_adapter.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,gDAAuB;AACvB,uCAAwC;AAUxC,6DAAqD;AACrD,mDAA8C;AAC9C,uCAAiD;AAYjD,SAAS,oBAAoB,CAAC,UAAmB;IAC/C,OAAO,OAAO,CAAC,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,UAAU,GAAG,GAAG,CAAC,CAAA;AACrE,CAAC;AAED,SAAS,aAAa,CAAC,MAAW;IAChC,OAAO,qBAAqB,IAAI,MAAM,CAAA;AACxC,CAAC;AAED,SAAS,gBAAgB,CACvB,mBAAwC,EACxC,WAAqB;IAErB,OAAO;QACL,GAAG,CAAC,WAAW;YACb,CAAC,CAAC;gBACE,uBAAuB,EAAE,CAAC;aAC3B;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,mBAAmB;KACvB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,QAAgB;IAEhB,OAAO;QACL,aAAa,EAAE,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC,CAAC,QAAQ,CACrE,QAAQ,CACT,EAAE;KACJ,CAAA;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,QAA8B;IAKxD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAErD,IAAI,QAAQ,KAAK,MAAM,EAAE;QACvB,OAAO;YACL,QAAQ,EAAE,gBAAM,CAAC,QAAQ,CACvB,QAAQ,EACR,cAAI,CAAC,YAAY,EAAE,EACnB,SAAS,UAAU,CAAC,GAAG;gBACrB,IAAI,GA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,MAAM,CAAC,MAAM;YACnB,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAgB;SAC3D,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE;YAChE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAA;SACrB;IACH,CAAC;IAEO,WAAW,CACjB,MAAqB,EACrB,QAA8B,EAC9B,cAAsB;QAEtB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,CAAA;QAE5C,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,4BAA4B,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,GAC9D,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAChD,IAAI,QAAQ,CAAC,UAAU,IAAI,QAAQ,IAAI,CACxC,CAAA;IACH,CAAC;IAES,UAAU,CAAC,MAAqB;QACxC,OAAO;YACL,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnE,CAAA;IACH,CAAC;CACF;AAhOD,0CAgOC"}
|
|
@@ -27,8 +27,8 @@ export interface InsertParams extends BaseParams {
|
|
|
27
27
|
export interface Connection {
|
|
28
28
|
ping(): Promise<boolean>;
|
|
29
29
|
close(): Promise<void>;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
query(params: BaseParams): Promise<Stream.Readable>;
|
|
31
|
+
exec(params: BaseParams): Promise<Stream.Readable>;
|
|
32
32
|
insert(params: InsertParams): Promise<void>;
|
|
33
33
|
}
|
|
34
34
|
export declare function createConnection(params: ConnectionParams, logger: Logger): Connection;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare const _default: {
|
|
|
5
5
|
};
|
|
6
6
|
export default _default;
|
|
7
7
|
export { type ClickHouseClientConfigOptions, type ClickHouseClient, type BaseParams, type QueryParams, type ExecParams, type InsertParams, } from './client';
|
|
8
|
-
export { Row,
|
|
8
|
+
export { Row, ResultSet } from './result';
|
|
9
9
|
export type { Connection } from './connection';
|
|
10
10
|
export type { DataFormat } from './data_formatter';
|
|
11
11
|
export type { ClickHouseError } from './error';
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SettingsMap = exports.
|
|
3
|
+
exports.SettingsMap = exports.ResultSet = exports.createClient = void 0;
|
|
4
4
|
const client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
|
|
6
6
|
exports.default = {
|
|
7
7
|
createClient: client_1.createClient,
|
|
8
8
|
};
|
|
9
|
-
var
|
|
10
|
-
Object.defineProperty(exports, "
|
|
11
|
-
Object.defineProperty(exports, "Rows", { enumerable: true, get: function () { return rows_1.Rows; } });
|
|
9
|
+
var result_1 = require("./result");
|
|
10
|
+
Object.defineProperty(exports, "ResultSet", { enumerable: true, get: function () { return result_1.ResultSet; } });
|
|
12
11
|
var settings_1 = require("./settings");
|
|
13
12
|
Object.defineProperty(exports, "SettingsMap", { enumerable: true, get: function () { return settings_1.SettingsMap; } });
|
|
14
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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
|
|
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,mCAAyC;AAA3B,mGAAA,SAAS,OAAA;AAQvB,uCAAwC;AAA/B,uGAAA,WAAW,OAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import Stream from 'stream';
|
|
3
3
|
import { type DataFormat } from './data_formatter';
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class ResultSet {
|
|
5
5
|
private _stream;
|
|
6
6
|
private readonly format;
|
|
7
7
|
constructor(_stream: Stream.Readable, format: DataFormat);
|
|
@@ -10,7 +10,7 @@ export declare class Rows {
|
|
|
10
10
|
* and returns the result as a string.
|
|
11
11
|
*
|
|
12
12
|
* The method will throw if the underlying stream was already consumed
|
|
13
|
-
* by calling the other methods
|
|
13
|
+
* by calling the other methods.
|
|
14
14
|
*/
|
|
15
15
|
text(): Promise<string>;
|
|
16
16
|
/**
|
|
@@ -18,32 +18,33 @@ export declare class Rows {
|
|
|
18
18
|
* When the response is received in full, it will be decoded to return JSON.
|
|
19
19
|
*
|
|
20
20
|
* The method will throw if the underlying stream was already consumed
|
|
21
|
-
* by calling the other methods
|
|
21
|
+
* by calling the other methods.
|
|
22
22
|
*/
|
|
23
23
|
json<T>(): Promise<T>;
|
|
24
24
|
/**
|
|
25
|
-
* Returns a readable stream
|
|
26
|
-
*
|
|
25
|
+
* Returns a readable stream for responses that can be streamed
|
|
26
|
+
* (i.e. all except JSON).
|
|
27
|
+
*
|
|
28
|
+
* Every iteration provides an array of {@link Row} instances
|
|
29
|
+
* for {@link StreamableDataFormat} format.
|
|
30
|
+
*
|
|
31
|
+
* Should be called only once.
|
|
27
32
|
*
|
|
28
33
|
* The method will throw if called on a response in non-streamable format,
|
|
29
34
|
* and if the underlying stream was already consumed
|
|
30
|
-
* by calling the other methods
|
|
35
|
+
* by calling the other methods.
|
|
31
36
|
*/
|
|
32
37
|
stream(): Stream.Readable;
|
|
33
38
|
close(): void;
|
|
34
39
|
}
|
|
35
|
-
export
|
|
36
|
-
private readonly chunk;
|
|
37
|
-
private readonly format;
|
|
38
|
-
constructor(chunk: string, format: DataFormat);
|
|
40
|
+
export interface Row {
|
|
39
41
|
/**
|
|
40
|
-
*
|
|
42
|
+
* A string representation of a row.
|
|
41
43
|
*/
|
|
42
|
-
text
|
|
44
|
+
text: string;
|
|
43
45
|
/**
|
|
44
46
|
* Returns a JSON representation of a row.
|
|
45
47
|
* The method will throw if called on a response in JSON incompatible format.
|
|
46
|
-
*
|
|
47
48
|
* It is safe to call this method multiple times.
|
|
48
49
|
*/
|
|
49
50
|
json<T>(): T;
|
package/dist/result.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ResultSet = void 0;
|
|
27
|
+
const stream_1 = __importStar(require("stream"));
|
|
28
|
+
const utils_1 = require("./utils");
|
|
29
|
+
const data_formatter_1 = require("./data_formatter");
|
|
30
|
+
class ResultSet {
|
|
31
|
+
constructor(_stream, format) {
|
|
32
|
+
Object.defineProperty(this, "_stream", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: _stream
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(this, "format", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: format
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The method waits for all the rows to be fully loaded
|
|
47
|
+
* and returns the result as a string.
|
|
48
|
+
*
|
|
49
|
+
* The method will throw if the underlying stream was already consumed
|
|
50
|
+
* by calling the other methods.
|
|
51
|
+
*/
|
|
52
|
+
async text() {
|
|
53
|
+
if (this._stream.readableEnded) {
|
|
54
|
+
throw Error(streamAlreadyConsumedMessage);
|
|
55
|
+
}
|
|
56
|
+
return (await (0, utils_1.getAsText)(this._stream)).toString();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The method waits for the all the rows to be fully loaded.
|
|
60
|
+
* When the response is received in full, it will be decoded to return JSON.
|
|
61
|
+
*
|
|
62
|
+
* The method will throw if the underlying stream was already consumed
|
|
63
|
+
* by calling the other methods.
|
|
64
|
+
*/
|
|
65
|
+
async json() {
|
|
66
|
+
if (this._stream.readableEnded) {
|
|
67
|
+
throw Error(streamAlreadyConsumedMessage);
|
|
68
|
+
}
|
|
69
|
+
return (0, data_formatter_1.decode)(await this.text(), this.format);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns a readable stream for responses that can be streamed
|
|
73
|
+
* (i.e. all except JSON).
|
|
74
|
+
*
|
|
75
|
+
* Every iteration provides an array of {@link Row} instances
|
|
76
|
+
* for {@link StreamableDataFormat} format.
|
|
77
|
+
*
|
|
78
|
+
* Should be called only once.
|
|
79
|
+
*
|
|
80
|
+
* The method will throw if called on a response in non-streamable format,
|
|
81
|
+
* and if the underlying stream was already consumed
|
|
82
|
+
* by calling the other methods.
|
|
83
|
+
*/
|
|
84
|
+
stream() {
|
|
85
|
+
// If the underlying stream has already ended by calling `text` or `json`,
|
|
86
|
+
// Stream.pipeline will create a new empty stream
|
|
87
|
+
// but without "readableEnded" flag set to true
|
|
88
|
+
if (this._stream.readableEnded) {
|
|
89
|
+
throw Error(streamAlreadyConsumedMessage);
|
|
90
|
+
}
|
|
91
|
+
(0, data_formatter_1.validateStreamFormat)(this.format);
|
|
92
|
+
let decodedChunk = '';
|
|
93
|
+
const toRows = new stream_1.Transform({
|
|
94
|
+
transform(chunk, encoding, callback) {
|
|
95
|
+
decodedChunk += chunk.toString();
|
|
96
|
+
const rows = [];
|
|
97
|
+
// eslint-disable-next-line no-constant-condition
|
|
98
|
+
while (true) {
|
|
99
|
+
const idx = decodedChunk.indexOf('\n');
|
|
100
|
+
if (idx !== -1) {
|
|
101
|
+
const text = decodedChunk.slice(0, idx);
|
|
102
|
+
decodedChunk = decodedChunk.slice(idx + 1);
|
|
103
|
+
rows.push({
|
|
104
|
+
text,
|
|
105
|
+
json() {
|
|
106
|
+
return (0, data_formatter_1.decode)(text, 'JSON');
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
if (rows.length) {
|
|
112
|
+
this.push(rows);
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
callback();
|
|
118
|
+
},
|
|
119
|
+
autoDestroy: true,
|
|
120
|
+
objectMode: true,
|
|
121
|
+
});
|
|
122
|
+
return stream_1.default.pipeline(this._stream, toRows, function pipelineCb(err) {
|
|
123
|
+
if (err) {
|
|
124
|
+
console.error(err);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
close() {
|
|
129
|
+
this._stream.destroy();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.ResultSet = ResultSet;
|
|
133
|
+
const streamAlreadyConsumedMessage = 'Stream has been already consumed';
|
|
134
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA0C;AAE1C,mCAAmC;AACnC,qDAAgF;AAEhF,MAAa,SAAS;IACpB,YACU,OAAwB,EACf,MAAkB;;;;;mBAD3B;;;;;;mBACS;;IAChB,CAAC;IAEJ;;;;;;OAMG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YAC9B,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC1C;QACD,OAAO,CAAC,MAAM,IAAA,iBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;IACnD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YAC9B,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC1C;QACD,OAAO,IAAA,uBAAM,EAAC,MAAM,IAA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AC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,UAAU,CAAC,GAAG;YAClE,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;aACnB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC;CACF;AArGD,8BAqGC;AAgBD,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
|
|
@@ -3,7 +3,7 @@ import type { CreateTableOptions, TableOptions } from './index';
|
|
|
3
3
|
import type { WhereExpr } from './where';
|
|
4
4
|
import type { NonEmptyArray } from './common';
|
|
5
5
|
export declare const QueryFormatter: {
|
|
6
|
-
createTable: <S extends Shape>(tableOptions: TableOptions<S>, { engine, if_not_exists, on_cluster, order_by, partition_by, primary_key, settings, }: CreateTableOptions<S>) => string;
|
|
6
|
+
createTable: <S extends Shape>(tableOptions: TableOptions<S>, { engine: _engine, if_not_exists, on_cluster, order_by, partition_by, primary_key, settings: _settings, }: CreateTableOptions<S>) => string;
|
|
7
7
|
select: <S_1 extends Shape>(tableOptions: TableOptions<S_1>, whereExpr?: WhereExpr<S_1> | undefined, columns?: NonEmptyArray<keyof S_1> | undefined, orderBy?: NonEmptyArray<[keyof S_1, "ASC" | "DESC"]> | undefined) => string;
|
|
8
8
|
};
|
|
9
9
|
export declare function getTableName<S extends Shape>({ database, name, }: TableOptions<S>): string;
|
package/dist/schema/table.js
CHANGED
|
@@ -36,17 +36,19 @@ class Table {
|
|
|
36
36
|
}
|
|
37
37
|
async select({ abort_signal, clickhouse_settings, columns, order_by, where, } = {}) {
|
|
38
38
|
const query = query_formatter_1.QueryFormatter.select(this.options, where, columns, order_by);
|
|
39
|
-
const
|
|
39
|
+
const rs = await this.client.query({
|
|
40
40
|
query,
|
|
41
41
|
clickhouse_settings,
|
|
42
42
|
abort_signal,
|
|
43
43
|
format: 'JSONEachRow',
|
|
44
44
|
});
|
|
45
|
-
const stream =
|
|
45
|
+
const stream = rs.stream();
|
|
46
46
|
async function* asyncGenerator() {
|
|
47
|
-
for await (const
|
|
48
|
-
const
|
|
49
|
-
|
|
47
|
+
for await (const rows of stream) {
|
|
48
|
+
for (const row of rows) {
|
|
49
|
+
const value = row.json();
|
|
50
|
+
yield value;
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
return {
|
package/dist/schema/table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/schema/table.ts"],"names":[],"mappings":";;;AAGA,uDAAgE;
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/schema/table.ts"],"names":[],"mappings":";;;AAGA,uDAAgE;AA4ChE,MAAa,KAAK;IAChB,YACmB,MAAwB,EACxB,OAAwB;;;;;mBADxB;;;;;;mBACA;;IAChB,CAAC;IAEJ,qBAAqB;IACrB,KAAK,CAAC,MAAM,CAAC,OAA8B;QACzC,MAAM,KAAK,GAAG,gCAAc,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACtB,KAAK;YACL,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;SACjD,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,CAAC,EACL,YAAY,EACZ,mBAAmB,EACnB,MAAM,GACW;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACxB,mBAAmB;YACnB,YAAY;YACZ,KAAK,EAAE,IAAA,8BAAY,EAAC,IAAI,CAAC,OAAO,CAAC;YACjC,MAAM,EAAE,aAAa;YACrB,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EACX,YAAY,EACZ,mBAAmB,EACnB,OAAO,EACP,QAAQ,EACR,KAAK,MACe,EAAE;QACtB,MAAM,KAAK,GAAG,gCAAc,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;QAC3E,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YACjC,KAAK;YACL,mBAAmB;YACnB,YAAY;YACZ,MAAM,EAAE,aAAa;SACtB,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAA;QAC1B,KAAK,SAAS,CAAC,CAAC,cAAc;YAC5B,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE;gBAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;oBACtB,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAe,CAAA;oBACrC,MAAM,KAAiB,CAAA;iBACxB;aACF;QACH,CAAC;QAED,OAAO;YACL,cAAc;YACd,IAAI,EAAE,KAAK,IAAI,EAAE;gBACf,MAAM,MAAM,GAAG,EAAE,CAAA;gBACjB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,cAAc,EAAE,EAAE;oBAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;wBACxB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;qBACtB;yBAAM;wBACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;qBACnB;iBACF;gBACD,OAAO,MAAM,CAAA;YACf,CAAC;SACF,CAAA;IACH,CAAC;CACF;AArED,sBAqEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clickhouse/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Official JS client for ClickHouse DB",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -36,8 +36,7 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"node-abort-controller": "^3.0.1"
|
|
40
|
-
"split2": "^4.1.0"
|
|
39
|
+
"node-abort-controller": "^3.0.1"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@types/jest": "^29.0.2",
|
|
@@ -54,8 +53,10 @@
|
|
|
54
53
|
"jest-silent-reporter": "^0.5.0",
|
|
55
54
|
"lint-staged": "^13.0.3",
|
|
56
55
|
"prettier": "2.7.1",
|
|
56
|
+
"split2": "^4.1.0",
|
|
57
57
|
"ts-jest": "^29.0.1",
|
|
58
|
-
"ts-
|
|
58
|
+
"ts-node": "^10.9.1",
|
|
59
|
+
"tsconfig-paths": "^4.1.0",
|
|
59
60
|
"typescript": "^4.8.3",
|
|
60
61
|
"uuid": "^9.0.0"
|
|
61
62
|
},
|
package/dist/rows.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
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.Row = exports.Rows = void 0;
|
|
7
|
-
const stream_1 = __importDefault(require("stream"));
|
|
8
|
-
const split2_1 = __importDefault(require("split2"));
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const data_formatter_1 = require("./data_formatter");
|
|
11
|
-
class Rows {
|
|
12
|
-
constructor(_stream, format) {
|
|
13
|
-
Object.defineProperty(this, "_stream", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: _stream
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(this, "format", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: format
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* The method waits for all the rows to be fully loaded
|
|
28
|
-
* and returns the result as a string.
|
|
29
|
-
*
|
|
30
|
-
* The method will throw if the underlying stream was already consumed
|
|
31
|
-
* by calling the other methods
|
|
32
|
-
*/
|
|
33
|
-
async text() {
|
|
34
|
-
if (this._stream.readableEnded) {
|
|
35
|
-
throw Error(streamAlreadyConsumedMessage);
|
|
36
|
-
}
|
|
37
|
-
return (await (0, utils_1.getAsText)(this._stream)).toString();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* The method waits for the all the rows to be fully loaded.
|
|
41
|
-
* When the response is received in full, it will be decoded to return JSON.
|
|
42
|
-
*
|
|
43
|
-
* The method will throw if the underlying stream was already consumed
|
|
44
|
-
* by calling the other methods
|
|
45
|
-
*/
|
|
46
|
-
async json() {
|
|
47
|
-
if (this._stream.readableEnded) {
|
|
48
|
-
throw Error(streamAlreadyConsumedMessage);
|
|
49
|
-
}
|
|
50
|
-
return (0, data_formatter_1.decode)(await this.text(), this.format);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns a readable stream of {@link Row}s for responses
|
|
54
|
-
* in {@link StreamableDataFormat} format.
|
|
55
|
-
*
|
|
56
|
-
* The method will throw if called on a response in non-streamable format,
|
|
57
|
-
* and if the underlying stream was already consumed
|
|
58
|
-
* by calling the other methods
|
|
59
|
-
*/
|
|
60
|
-
stream() {
|
|
61
|
-
// If the underlying stream has already ended by calling `text` or `json`,
|
|
62
|
-
// Stream.pipeline will create a new empty stream
|
|
63
|
-
// but without "readableEnded" flag set to true
|
|
64
|
-
if (this._stream.readableEnded) {
|
|
65
|
-
throw Error(streamAlreadyConsumedMessage);
|
|
66
|
-
}
|
|
67
|
-
(0, data_formatter_1.validateStreamFormat)(this.format);
|
|
68
|
-
return stream_1.default.pipeline(this._stream,
|
|
69
|
-
// only JSON-based format are supported at the moment
|
|
70
|
-
(0, split2_1.default)((row) => new Row(row, 'JSON')), function pipelineCb(err) {
|
|
71
|
-
if (err) {
|
|
72
|
-
console.error(err);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
close() {
|
|
77
|
-
this._stream.destroy();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.Rows = Rows;
|
|
81
|
-
class Row {
|
|
82
|
-
constructor(chunk, format) {
|
|
83
|
-
Object.defineProperty(this, "chunk", {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
configurable: true,
|
|
86
|
-
writable: true,
|
|
87
|
-
value: chunk
|
|
88
|
-
});
|
|
89
|
-
Object.defineProperty(this, "format", {
|
|
90
|
-
enumerable: true,
|
|
91
|
-
configurable: true,
|
|
92
|
-
writable: true,
|
|
93
|
-
value: format
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Returns a string representation of a row.
|
|
98
|
-
*/
|
|
99
|
-
text() {
|
|
100
|
-
return this.chunk;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns a JSON representation of a row.
|
|
104
|
-
* The method will throw if called on a response in JSON incompatible format.
|
|
105
|
-
*
|
|
106
|
-
* It is safe to call this method multiple times.
|
|
107
|
-
*/
|
|
108
|
-
json() {
|
|
109
|
-
return (0, data_formatter_1.decode)(this.text(), this.format);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.Row = Row;
|
|
113
|
-
const streamAlreadyConsumedMessage = 'Stream has been already consumed';
|
|
114
|
-
//# sourceMappingURL=rows.js.map
|
package/dist/rows.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rows.js","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,oDAA0B;AAE1B,mCAAmC;AACnC,qDAAgF;AAEhF,MAAa,IAAI;IACf,YACU,OAAwB,EACf,MAAkB;;;;;mBAD3B;;;;;;mBACS;;IAChB,CAAC;IAEJ;;;;;;OAM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F,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED;;;;;OAKG;IACH,IAAI;QACF,OAAO,IAAA,uBAAM,EAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;CACF;AAtBD,kBAsBC;AAED,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
|
package/dist/schema/compact.d.ts
DELETED
package/dist/schema/compact.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decompactJson = exports.compactJson = void 0;
|
|
4
|
-
function compactJson(shape, value) {
|
|
5
|
-
const compacted = [];
|
|
6
|
-
for (const key in shape) {
|
|
7
|
-
if (key in value) {
|
|
8
|
-
compacted.push(value[key]);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return compacted;
|
|
12
|
-
}
|
|
13
|
-
exports.compactJson = compactJson;
|
|
14
|
-
function decompactJson(shape, [row]) {
|
|
15
|
-
const obj = {};
|
|
16
|
-
let i = 0;
|
|
17
|
-
for (const key in shape) {
|
|
18
|
-
obj[key] = row[i];
|
|
19
|
-
i++;
|
|
20
|
-
}
|
|
21
|
-
return obj;
|
|
22
|
-
}
|
|
23
|
-
exports.decompactJson = decompactJson;
|
|
24
|
-
//# sourceMappingURL=compact.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compact.js","sourceRoot":"","sources":["../../src/schema/compact.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAkB,KAAQ,EAAE,KAAe;IACpE,MAAM,SAAS,GAAG,EAAE,CAAA;IACpB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,IAAI,GAAG,IAAI,KAAK,EAAE;YAChB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;SAC3B;KACF;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AARD,kCAQC;AAED,SAAgB,aAAa,CAAkB,KAAQ,EAAE,CAAC,GAAG,CAAc;IACzE,MAAM,GAAG,GAA4B,EAAE,CAAA;IACvC,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC,EAAE,CAAA;KACJ;IACD,OAAO,GAAe,CAAA;AACxB,CAAC;AARD,sCAQC"}
|