@clickhouse/client-common 0.3.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/result.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- export interface Row {
1
+ import type { ResponseJSON } from './clickhouse_types';
2
+ import type { DataFormat, RawDataFormat, RecordsJSONFormat, SingleDocumentJSONFormat, StreamableDataFormat, StreamableJSONDataFormat } from './data_formatter';
3
+ export type ResultStream<Format extends DataFormat | unknown, Stream> = Format extends StreamableDataFormat ? Stream : Format extends SingleDocumentJSONFormat ? never : Format extends RecordsJSONFormat ? never : Stream;
4
+ export type ResultJSONType<T, F extends DataFormat | unknown> = F extends StreamableJSONDataFormat ? T[] : F extends SingleDocumentJSONFormat ? ResponseJSON<T> : F extends RecordsJSONFormat ? Record<string, T> : F extends RawDataFormat ? never : // happens only when Format could not be inferred from a literal
5
+ T[] | Record<string, T> | ResponseJSON<T>;
6
+ export type RowJSONType<T, F extends DataFormat | unknown> = F extends StreamableJSONDataFormat ? T : F extends RawDataFormat | SingleDocumentJSONFormat | RecordsJSONFormat ? never : T;
7
+ export interface Row<JSONType = unknown, Format extends DataFormat | unknown = unknown> {
2
8
  /** A string representation of a row. */
3
9
  text: string;
4
10
  /**
@@ -6,13 +12,15 @@ export interface Row {
6
12
  * The method will throw if called on a response in JSON incompatible format.
7
13
  * It is safe to call this method multiple times.
8
14
  */
9
- json<T>(): T;
15
+ json<T = JSONType>(): RowJSONType<T, Format>;
10
16
  }
11
- export interface BaseResultSet<Stream> {
17
+ export interface BaseResultSet<Stream, Format extends DataFormat | unknown> {
12
18
  /**
13
19
  * The method waits for all the rows to be fully loaded
14
20
  * and returns the result as a string.
15
21
  *
22
+ * It is possible to call this method for all supported formats.
23
+ *
16
24
  * The method should throw if the underlying stream was already consumed
17
25
  * by calling the other methods.
18
26
  */
@@ -21,13 +29,44 @@ export interface BaseResultSet<Stream> {
21
29
  * The method waits for the all the rows to be fully loaded.
22
30
  * When the response is received in full, it will be decoded to return JSON.
23
31
  *
32
+ * Should be called only for JSON* formats family.
33
+ *
24
34
  * The method should throw if the underlying stream was already consumed
25
- * by calling the other methods.
35
+ * by calling the other methods, or if it is called for non-JSON formats,
36
+ * such as CSV, TSV etc.
26
37
  */
27
- json<T>(): Promise<T>;
38
+ json<T = unknown>(): Promise<ResultJSONType<T, Format>>;
28
39
  /**
29
- * Returns a readable stream for responses that can be streamed
30
- * (i.e. all except JSON).
40
+ * Returns a readable stream for responses that can be streamed.
41
+ *
42
+ * Formats that CAN be streamed ({@link StreamableDataFormat}):
43
+ * * JSONEachRow
44
+ * * JSONStringsEachRow
45
+ * * JSONCompactEachRow
46
+ * * JSONCompactStringsEachRow
47
+ * * JSONCompactEachRowWithNames
48
+ * * JSONCompactEachRowWithNamesAndTypes
49
+ * * JSONCompactStringsEachRowWithNames
50
+ * * JSONCompactStringsEachRowWithNamesAndTypes
51
+ * * CSV
52
+ * * CSVWithNames
53
+ * * CSVWithNamesAndTypes
54
+ * * TabSeparated
55
+ * * TabSeparatedRaw
56
+ * * TabSeparatedWithNames
57
+ * * TabSeparatedWithNamesAndTypes
58
+ * * CustomSeparated
59
+ * * CustomSeparatedWithNames
60
+ * * CustomSeparatedWithNamesAndTypes
61
+ * * Parquet
62
+ *
63
+ * Formats that CANNOT be streamed (the method returns "never" in TS):
64
+ * * JSON
65
+ * * JSONStrings
66
+ * * JSONCompact
67
+ * * JSONCompactStrings
68
+ * * JSONColumnsWithMetadata
69
+ * * JSONObjectEachRow
31
70
  *
32
71
  * Every iteration provides an array of {@link Row} instances
33
72
  * for {@link StreamableDataFormat} format.
@@ -38,7 +77,7 @@ export interface BaseResultSet<Stream> {
38
77
  * and if the underlying stream was already consumed
39
78
  * by calling the other methods.
40
79
  */
41
- stream(): Stream;
80
+ stream(): ResultStream<Format, Stream>;
42
81
  /** Close the underlying stream. */
43
82
  close(): void;
44
83
  /** ClickHouse server QueryID. */
@@ -1577,7 +1577,7 @@ interface ClickHouseHTTPSettings {
1577
1577
  wait_end_of_query: Bool;
1578
1578
  default_format: DataFormat;
1579
1579
  }
1580
- export type ClickHouseSettings = Partial<ClickHouseServerSettings> & Partial<ClickHouseHTTPSettings>;
1580
+ export type ClickHouseSettings = Partial<ClickHouseServerSettings> & Partial<ClickHouseHTTPSettings> & Record<string, number | string | boolean | SettingsMap | undefined>;
1581
1581
  export interface MergeTreeSettings {
1582
1582
  /** Allow floating point as partition key */
1583
1583
  allow_floating_point_partition_key?: Bool;
@@ -1 +1 @@
1
- {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../packages/client-common/src/settings.ts"],"names":[],"mappings":";;;AAq3DA,MAAa,WAAW;IACtB,YAAqC,MAA8B;;;;;mBAA9B;;IAAiC,CAAC;IAEvE,QAAQ;QACN,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;aACnC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;aAChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAA;IACjB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,MAA8B;QACxC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC;CACF;AAZD,kCAYC"}
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../packages/client-common/src/settings.ts"],"names":[],"mappings":";;;AAu3DA,MAAa,WAAW;IACtB,YAAqC,MAA8B;QAA/C;;;;mBAAiB,MAAM;WAAwB;IAAG,CAAC;IAEvE,QAAQ;QACN,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;aACnC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;aAChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAA;IACjB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,MAA8B;QACxC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC;CACF;AAZD,kCAYC"}
@@ -0,0 +1,4 @@
1
+ /** Adjusted from https://stackoverflow.com/a/72801672/4575540.
2
+ * Useful for checking if we could not infer a concrete literal type
3
+ * (i.e. if instead of 'JSONEachRow' or other literal we just get a generic {@link DataFormat} as an argument). */
4
+ export type IsSame<A, B> = [A] extends [B] ? B extends A ? true : false : false;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ts_utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts_utils.js","sourceRoot":"","sources":["../../../packages/client-common/src/ts_utils.ts"],"names":[],"mappings":""}
@@ -1,3 +1,2 @@
1
1
  export * from './connection';
2
2
  export * from './url';
3
- export * from './permutations';
@@ -16,5 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./connection"), exports);
18
18
  __exportStar(require("./url"), exports);
19
- __exportStar(require("./permutations"), exports);
20
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/client-common/src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,wCAAqB;AACrB,iDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/client-common/src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,wCAAqB"}
@@ -1 +1 @@
1
- {"version":3,"file":"url.js","sourceRoot":"","sources":["../../../../packages/client-common/src/utils/url.ts"],"names":[],"mappings":";;;AAAA,sDAA0E;AAG1E,SAAgB,YAAY,CAAC,EAC3B,GAAG,EACH,QAAQ,EACR,YAAY,GAK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QAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACxD,MAAM,CAAC,GAAG,CAAC,SAAS,GAAG,EAAE,EAAE,IAAA,kCAAiB,EAAC,KAAK,CAAC,CAAC,CAAA;QACtD,CAAC;IACH,CAAC;IAED,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;QACtC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAC/D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAA,oCAAmB,EAAC,KAAK,CAAC,CAAC,CAAA;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC5B,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;IACtC,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAtCD,wCAsCC"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "0.3.1";
1
+ declare const _default: "1.0.1";
2
2
  export default _default;
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '0.3.1';
3
+ exports.default = '1.0.1';
4
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@clickhouse/client-common",
3
3
  "description": "Official JS client for ClickHouse DB - common types",
4
4
  "homepage": "https://clickhouse.com",
5
- "version": "0.3.1",
5
+ "version": "1.0.1",
6
6
  "license": "Apache-2.0",
7
7
  "keywords": [
8
8
  "clickhouse",
@@ -1 +0,0 @@
1
- export declare function permutations<T>(args: T[], n: number, prefix?: T[]): T[][];
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.permutations = void 0;
4
- // adjusted from https://stackoverflow.com/a/64414875/4575540
5
- function permutations(args, n, prefix = []) {
6
- if (n === 0) {
7
- return [prefix];
8
- }
9
- return args.flatMap((arg, i) => permutations(args.slice(i + 1), n - 1, [...prefix, arg]));
10
- }
11
- exports.permutations = permutations;
12
- //# sourceMappingURL=permutations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"permutations.js","sourceRoot":"","sources":["../../../../packages/client-common/src/utils/permutations.ts"],"names":[],"mappings":";;;AAAA,6DAA6D;AAC7D,SAAgB,YAAY,CAAI,IAAS,EAAE,CAAS,EAAE,SAAc,EAAE;IACpE,IAAI,CAAC,KAAK,CAAC,EAAE;QACX,OAAO,CAAC,MAAM,CAAC,CAAA;KAChB;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAC7B,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,CACzD,CAAA;AACH,CAAC;AAPD,oCAOC"}