@clickhouse/client 1.22.0 → 1.23.0-head.287977a.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.
Files changed (163) hide show
  1. package/README.md +2 -1
  2. package/dist/client.d.ts +2 -2
  3. package/dist/client.js +11 -4
  4. package/dist/client.js.map +1 -1
  5. package/dist/common/clickhouse_types.d.ts +98 -0
  6. package/dist/common/clickhouse_types.js +30 -0
  7. package/dist/common/clickhouse_types.js.map +1 -0
  8. package/dist/common/client.d.ts +233 -0
  9. package/dist/common/client.js +414 -0
  10. package/dist/common/client.js.map +1 -0
  11. package/dist/common/config.d.ts +234 -0
  12. package/dist/common/config.js +364 -0
  13. package/dist/common/config.js.map +1 -0
  14. package/dist/common/connection.d.ts +124 -0
  15. package/dist/common/connection.js +3 -0
  16. package/dist/common/connection.js.map +1 -0
  17. package/dist/common/data_formatter/format_query_params.d.ts +11 -0
  18. package/dist/common/data_formatter/format_query_params.js +128 -0
  19. package/dist/common/data_formatter/format_query_params.js.map +1 -0
  20. package/dist/common/data_formatter/format_query_settings.d.ts +2 -0
  21. package/dist/common/data_formatter/format_query_settings.js +20 -0
  22. package/dist/common/data_formatter/format_query_settings.js.map +1 -0
  23. package/dist/common/data_formatter/formatter.d.ts +41 -0
  24. package/dist/common/data_formatter/formatter.js +78 -0
  25. package/dist/common/data_formatter/formatter.js.map +1 -0
  26. package/dist/common/data_formatter/index.d.ts +3 -0
  27. package/dist/common/data_formatter/index.js +24 -0
  28. package/dist/common/data_formatter/index.js.map +1 -0
  29. package/dist/common/error/error.d.ts +20 -0
  30. package/dist/common/error/error.js +73 -0
  31. package/dist/common/error/error.js.map +1 -0
  32. package/dist/common/error/index.d.ts +1 -0
  33. package/dist/common/error/index.js +18 -0
  34. package/dist/common/error/index.js.map +1 -0
  35. package/dist/common/index.d.ts +67 -0
  36. package/dist/common/index.js +97 -0
  37. package/dist/common/index.js.map +1 -0
  38. package/dist/common/logger.d.ts +80 -0
  39. package/dist/common/logger.js +154 -0
  40. package/dist/common/logger.js.map +1 -0
  41. package/dist/common/parse/column_types.d.ts +155 -0
  42. package/dist/common/parse/column_types.js +594 -0
  43. package/dist/common/parse/column_types.js.map +1 -0
  44. package/dist/common/parse/index.d.ts +2 -0
  45. package/dist/common/parse/index.js +19 -0
  46. package/dist/common/parse/index.js.map +1 -0
  47. package/dist/common/parse/json_handling.d.ts +19 -0
  48. package/dist/common/parse/json_handling.js +8 -0
  49. package/dist/common/parse/json_handling.js.map +1 -0
  50. package/dist/common/result.d.ts +90 -0
  51. package/dist/common/result.js +3 -0
  52. package/dist/common/result.js.map +1 -0
  53. package/dist/common/settings.d.ts +2007 -0
  54. package/dist/common/settings.js +19 -0
  55. package/dist/common/settings.js.map +1 -0
  56. package/dist/common/tracing.d.ts +146 -0
  57. package/dist/common/tracing.js +76 -0
  58. package/dist/common/tracing.js.map +1 -0
  59. package/dist/common/ts_utils.d.ts +4 -0
  60. package/dist/common/ts_utils.js +3 -0
  61. package/dist/common/ts_utils.js.map +1 -0
  62. package/dist/common/utils/connection.d.ts +21 -0
  63. package/dist/common/utils/connection.js +43 -0
  64. package/dist/common/utils/connection.js.map +1 -0
  65. package/dist/common/utils/index.d.ts +5 -0
  66. package/dist/common/utils/index.js +22 -0
  67. package/dist/common/utils/index.js.map +1 -0
  68. package/dist/common/utils/multipart.d.ts +34 -0
  69. package/dist/common/utils/multipart.js +81 -0
  70. package/dist/common/utils/multipart.js.map +1 -0
  71. package/dist/common/utils/sleep.d.ts +4 -0
  72. package/dist/common/utils/sleep.js +12 -0
  73. package/dist/common/utils/sleep.js.map +1 -0
  74. package/dist/common/utils/stream.d.ts +15 -0
  75. package/dist/common/utils/stream.js +50 -0
  76. package/dist/common/utils/stream.js.map +1 -0
  77. package/dist/common/utils/url.d.ts +20 -0
  78. package/dist/common/utils/url.js +67 -0
  79. package/dist/common/utils/url.js.map +1 -0
  80. package/dist/common/version.d.ts +2 -0
  81. package/dist/common/version.js +4 -0
  82. package/dist/common/version.js.map +1 -0
  83. package/dist/config.d.ts +22 -2
  84. package/dist/config.js +2 -2
  85. package/dist/config.js.map +1 -1
  86. package/dist/connection/compression.d.ts +2 -2
  87. package/dist/connection/compression.js +4 -4
  88. package/dist/connection/compression.js.map +1 -1
  89. package/dist/connection/create_connection.d.ts +1 -1
  90. package/dist/connection/node_base_connection.d.ts +3 -3
  91. package/dist/connection/node_base_connection.js +22 -22
  92. package/dist/connection/node_base_connection.js.map +1 -1
  93. package/dist/connection/node_custom_agent_connection.js +2 -2
  94. package/dist/connection/node_custom_agent_connection.js.map +1 -1
  95. package/dist/connection/node_http_connection.js +2 -2
  96. package/dist/connection/node_http_connection.js.map +1 -1
  97. package/dist/connection/node_https_connection.d.ts +1 -1
  98. package/dist/connection/node_https_connection.js +3 -3
  99. package/dist/connection/node_https_connection.js.map +1 -1
  100. package/dist/connection/socket_pool.d.ts +1 -1
  101. package/dist/connection/socket_pool.js +30 -30
  102. package/dist/connection/socket_pool.js.map +1 -1
  103. package/dist/connection/stream.d.ts +1 -1
  104. package/dist/connection/stream.js +9 -9
  105. package/dist/connection/stream.js.map +1 -1
  106. package/dist/index.d.ts +9 -7
  107. package/dist/index.js +26 -24
  108. package/dist/index.js.map +1 -1
  109. package/dist/result_set.d.ts +1 -1
  110. package/dist/result_set.js +10 -10
  111. package/dist/result_set.js.map +1 -1
  112. package/dist/utils/encoder.d.ts +1 -1
  113. package/dist/utils/encoder.js +5 -5
  114. package/dist/utils/encoder.js.map +1 -1
  115. package/dist/version.d.ts +1 -1
  116. package/dist/version.js +1 -1
  117. package/dist/version.js.map +1 -1
  118. package/package.json +7 -5
  119. package/skills/clickhouse-js-node-rowbinary-parser/EXAMPLES.md +48 -0
  120. package/skills/clickhouse-js-node-rowbinary-parser/README.md +255 -0
  121. package/skills/clickhouse-js-node-rowbinary-parser/SKILL.md +206 -0
  122. package/skills/clickhouse-js-node-rowbinary-parser/case-studies/iot-rowbinary-vs-json.md +83 -0
  123. package/skills/clickhouse-js-node-rowbinary-parser/case-studies/ledger-rowbinary-vs-json.md +103 -0
  124. package/skills/clickhouse-js-node-rowbinary-parser/case-studies/logs-json-wins.md +86 -0
  125. package/skills/clickhouse-js-node-rowbinary-parser/case-studies/wasm-vs-js.md +172 -0
  126. package/skills/clickhouse-js-node-rowbinary-parser/src/aggregateFunction.ts +34 -0
  127. package/skills/clickhouse-js-node-rowbinary-parser/src/bool.ts +10 -0
  128. package/skills/clickhouse-js-node-rowbinary-parser/src/columnar.ts +125 -0
  129. package/skills/clickhouse-js-node-rowbinary-parser/src/compile.ts +318 -0
  130. package/skills/clickhouse-js-node-rowbinary-parser/src/composite.ts +181 -0
  131. package/skills/clickhouse-js-node-rowbinary-parser/src/core.ts +77 -0
  132. package/skills/clickhouse-js-node-rowbinary-parser/src/datetime.ts +113 -0
  133. package/skills/clickhouse-js-node-rowbinary-parser/src/decimals.ts +57 -0
  134. package/skills/clickhouse-js-node-rowbinary-parser/src/dynamic.ts +328 -0
  135. package/skills/clickhouse-js-node-rowbinary-parser/src/enums.ts +28 -0
  136. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/carts.ts +71 -0
  137. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/events.ts +51 -0
  138. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/iot.ts +158 -0
  139. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/ledger.ts +98 -0
  140. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/logs.ts +73 -0
  141. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/observability.ts +142 -0
  142. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/orders.ts +65 -0
  143. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/profiles.ts +60 -0
  144. package/skills/clickhouse-js-node-rowbinary-parser/src/examples/telemetry.ts +102 -0
  145. package/skills/clickhouse-js-node-rowbinary-parser/src/floats.ts +32 -0
  146. package/skills/clickhouse-js-node-rowbinary-parser/src/geo.ts +109 -0
  147. package/skills/clickhouse-js-node-rowbinary-parser/src/header.ts +29 -0
  148. package/skills/clickhouse-js-node-rowbinary-parser/src/integers.ts +95 -0
  149. package/skills/clickhouse-js-node-rowbinary-parser/src/interval.ts +54 -0
  150. package/skills/clickhouse-js-node-rowbinary-parser/src/ip.ts +93 -0
  151. package/skills/clickhouse-js-node-rowbinary-parser/src/json.ts +33 -0
  152. package/skills/clickhouse-js-node-rowbinary-parser/src/lowCardinality.ts +18 -0
  153. package/skills/clickhouse-js-node-rowbinary-parser/src/nested.ts +23 -0
  154. package/skills/clickhouse-js-node-rowbinary-parser/src/nothing.ts +29 -0
  155. package/skills/clickhouse-js-node-rowbinary-parser/src/reader.ts +68 -0
  156. package/skills/clickhouse-js-node-rowbinary-parser/src/rowBinaryWithNamesAndTypes.ts +155 -0
  157. package/skills/clickhouse-js-node-rowbinary-parser/src/rows.ts +58 -0
  158. package/skills/clickhouse-js-node-rowbinary-parser/src/simpleAggregateFunction.ts +20 -0
  159. package/skills/clickhouse-js-node-rowbinary-parser/src/stream.ts +276 -0
  160. package/skills/clickhouse-js-node-rowbinary-parser/src/strings.ts +55 -0
  161. package/skills/clickhouse-js-node-rowbinary-parser/src/time.ts +61 -0
  162. package/skills/clickhouse-js-node-rowbinary-parser/src/uuid.ts +153 -0
  163. package/skills/clickhouse-js-node-rowbinary-parser/src/varint.ts +70 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SettingsMap = void 0;
4
+ class SettingsMap {
5
+ record;
6
+ constructor(record) {
7
+ this.record = record;
8
+ }
9
+ toString() {
10
+ return `{${Object.entries(this.record)
11
+ .map(([k, v]) => `'${k}':'${v}'`)
12
+ .join(",")}}`;
13
+ }
14
+ static from(record) {
15
+ return new this(record);
16
+ }
17
+ }
18
+ exports.SettingsMap = SettingsMap;
19
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/common/settings.ts"],"names":[],"mappings":";;;AAm8DA,MAAa,WAAW;IACL,MAAM,CAAyB;IAChD,YAAoB,MAA8B;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,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,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,MAA8B;QACxC,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;CACF;AAfD,kCAeC"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * A minimal, dependency-free tracer interface that is a structural subset of
3
+ * the {@link https://opentelemetry.io/docs/specs/otel/trace/api/#tracer OpenTelemetry `Tracer` API}.
4
+ *
5
+ * The shapes below are deliberately declared so that a raw OpenTelemetry
6
+ * tracer (the object returned by `trace.getTracer(...)` from
7
+ * `@opentelemetry/api`) is assignable to {@link ClickHouseTracer} **as-is**,
8
+ * with no adapter and no casts:
9
+ *
10
+ * ```ts
11
+ * import { trace } from '@opentelemetry/api'
12
+ * const client = createClient({ tracer: trace.getTracer('clickhouse-js') })
13
+ * ```
14
+ *
15
+ * At the same time, the client itself imports nothing from OpenTelemetry -
16
+ * non-OTEL backends (Prometheus counters, an `EventEmitter`, a plain logger)
17
+ * can implement the same small surface directly.
18
+ *
19
+ * When a {@link ClickHouseTracer} is provided via
20
+ * {@link BaseClickHouseClientConfigOptions.tracer}, the client runs each
21
+ * tracked operation (`query`, `command`, `exec`, `insert`, `ping`) inside
22
+ * {@link ClickHouseTracer.startActiveSpan}, mutates the provided
23
+ * {@link ClickHouseSpan} during the operation
24
+ * ({@link ClickHouseSpan.setAttributes}, {@link ClickHouseSpan.setStatus},
25
+ * {@link ClickHouseSpan.recordException}), and calls
26
+ * {@link ClickHouseSpan.end} exactly once. For `command`, `exec`, `insert`,
27
+ * and `ping`, the span ends when the operation settles (regardless of
28
+ * outcome). For `query`, two spans are emitted: the `clickhouse.query` span
29
+ * ends as soon as the HTTP response headers are received; a child
30
+ * `clickhouse.query.stream` span is then handed to the `ResultSet`, which
31
+ * tracks the streaming progress and ends it when the response stream is fully
32
+ * consumed, closed, or fails.
33
+ *
34
+ * Calls are inlined directly into the client's hot path - there is no
35
+ * defensive wrapper around them. Any exception thrown by a tracer or span
36
+ * method will propagate up to the caller of the corresponding client method
37
+ * (`query`/`command`/`exec`/`insert`/`ping`). Implementations are therefore
38
+ * expected to be non-throwing; a trivial e2e test against your tracer is
39
+ * usually enough to catch regressions.
40
+ */
41
+ export interface ClickHouseTracer<TSpan extends ClickHouseSpan = ClickHouseSpan> {
42
+ /**
43
+ * Called when a tracked operation begins. Same shape as OpenTelemetry's
44
+ * `Tracer.startActiveSpan(name, options, fn)` overload: implementations
45
+ * must invoke `fn` with the new span and return `fn`'s result untouched.
46
+ * The client runs the entire operation (an `async` function) inside `fn`,
47
+ * mutates the span during the operation, and ends it exactly once.
48
+ *
49
+ * @note The callback is asynchronous under the hood: the client keeps using
50
+ * the span across `await` points inside `fn`. For OpenTelemetry, active-span
51
+ * context propagation across those `await`s requires the
52
+ * `AsyncLocalStorageContextManager` (from
53
+ * `@opentelemetry/context-async-hooks`) to be registered - which is the
54
+ * default context manager in the OpenTelemetry Node.js SDK
55
+ * (`@opentelemetry/sdk-node` / `NodeTracerProvider`). With it in place,
56
+ * auto-instrumented child spans (e.g. from
57
+ * `@opentelemetry/instrumentation-http`) are parented under the ClickHouse
58
+ * operation span.
59
+ */
60
+ startActiveSpan<T>(name: string, options: ClickHouseSpanOptions, fn: (span: TSpan) => T): T;
61
+ }
62
+ /** Structural subset of the OpenTelemetry `Span` interface - a real OTEL
63
+ * `Span` is assignable to this type as-is. Methods are declared as
64
+ * `void`-returning, so OTEL's chainable `this`-returning methods remain
65
+ * compatible. */
66
+ export interface ClickHouseSpan {
67
+ /** Attach additional attributes to an in-flight span. Called at least once
68
+ * for every span - typically right before {@link ClickHouseSpan.end} -
69
+ * with operation-specific attributes such as `clickhouse.request.query_id`. */
70
+ setAttributes(attributes: ClickHouseSpanAttributes): void;
71
+ /** Set the logical status of the span. The codes are value-identical to
72
+ * OTEL's `SpanStatusCode`; see {@link ClickHouseSpanStatusCode}. */
73
+ setStatus(status: ClickHouseSpanStatus): void;
74
+ /** Attach an exception that occurred during the span. Called before
75
+ * {@link ClickHouseSpan.setStatus} with the `ERROR` code, before
76
+ * {@link ClickHouseSpan.end}. Non-`Error` throwables are normalized
77
+ * to `Error` by the client before this call. */
78
+ recordException(error: Error): void;
79
+ /** Called exactly once per span, regardless of success or failure. */
80
+ end(): void;
81
+ }
82
+ /** Structural subset of OTEL's `SpanOptions`. */
83
+ export interface ClickHouseSpanOptions {
84
+ /** Value-identical to OTEL's `SpanKind`; see {@link ClickHouseSpanKind}.
85
+ * The client always passes {@link ClickHouseSpanKind.CLIENT}, per the
86
+ * OTEL database semantic conventions. */
87
+ kind?: number;
88
+ /** Initial attributes for the span. */
89
+ attributes?: ClickHouseSpanAttributes;
90
+ }
91
+ /** Span status; `code` values are listed in {@link ClickHouseSpanStatusCode}
92
+ * and are value-identical to OTEL's `SpanStatusCode`. */
93
+ export interface ClickHouseSpanStatus {
94
+ code: number;
95
+ message?: string;
96
+ }
97
+ /** Value-identical to OTEL's `SpanStatusCode`, so non-OTEL implementations
98
+ * do not have to deal with magic numbers. */
99
+ export declare const ClickHouseSpanStatusCode: {
100
+ readonly UNSET: 0;
101
+ readonly OK: 1;
102
+ readonly ERROR: 2;
103
+ };
104
+ /** Value-identical to OTEL's `SpanKind`. The client only ever uses
105
+ * {@link ClickHouseSpanKind.CLIENT}. */
106
+ export declare const ClickHouseSpanKind: {
107
+ readonly INTERNAL: 0;
108
+ readonly SERVER: 1;
109
+ readonly CLIENT: 2;
110
+ readonly PRODUCER: 3;
111
+ readonly CONSUMER: 4;
112
+ };
113
+ /** Free-form attribute bag; a subset of OTEL's `Attributes`. Implementations
114
+ * should be tolerant of `undefined` values (skip them) and stringify
115
+ * non-primitive values as needed. */
116
+ export type ClickHouseSpanAttributes = Record<string, string | number | boolean | undefined>;
117
+ /** Span name constants used by the client when starting spans.
118
+ * Exposed so that adapters and tests can match on them. */
119
+ export declare const ClickHouseSpanNames: {
120
+ readonly query: "clickhouse.query";
121
+ /** A child of {@link ClickHouseSpanNames.query} that covers the lifetime
122
+ * of the `ResultSet` stream - from the first byte read to full
123
+ * consumption, cancellation, or failure. Ends with
124
+ * `clickhouse.response.decoded_bytes` and (for row-streaming paths)
125
+ * `db.response.returned_rows`. */
126
+ readonly query_stream: "clickhouse.query.stream";
127
+ readonly command: "clickhouse.command";
128
+ readonly exec: "clickhouse.exec";
129
+ readonly insert: "clickhouse.insert";
130
+ readonly ping: "clickhouse.ping";
131
+ };
132
+ export type ClickHouseSpanName = (typeof ClickHouseSpanNames)[keyof typeof ClickHouseSpanNames];
133
+ /** Shared no-op span handed out by {@link NoopClickHouseTracer}. @internal */
134
+ export declare const NoopClickHouseSpan: ClickHouseSpan;
135
+ /** No-op tracer assigned once at client creation when no tracer is
136
+ * configured, so the hot path stays branch-free (monomorphic call sites
137
+ * that the JIT can inline). @internal */
138
+ export declare const NoopClickHouseTracer: ClickHouseTracer;
139
+ /** Records the exception on the span and marks it with the ERROR status,
140
+ * normalizing non-`Error` throwables to `Error`.
141
+ *
142
+ * Sets the {@link https://opentelemetry.io/docs/specs/semconv/registry/attributes/error/#error-type `error.type`}
143
+ * attribute to the error class name (e.g. `ClickHouseError`, `TypeError`),
144
+ * and, for server-side errors ({@link ClickHouseError}), the numeric server
145
+ * error code as `clickhouse.error.code`. */
146
+ export declare function recordSpanError(span: ClickHouseSpan, err: unknown): void;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoopClickHouseTracer = exports.NoopClickHouseSpan = exports.ClickHouseSpanNames = exports.ClickHouseSpanKind = exports.ClickHouseSpanStatusCode = void 0;
4
+ exports.recordSpanError = recordSpanError;
5
+ const error_1 = require("./error");
6
+ /** Value-identical to OTEL's `SpanStatusCode`, so non-OTEL implementations
7
+ * do not have to deal with magic numbers. */
8
+ exports.ClickHouseSpanStatusCode = {
9
+ UNSET: 0,
10
+ OK: 1,
11
+ ERROR: 2,
12
+ };
13
+ /** Value-identical to OTEL's `SpanKind`. The client only ever uses
14
+ * {@link ClickHouseSpanKind.CLIENT}. */
15
+ exports.ClickHouseSpanKind = {
16
+ INTERNAL: 0,
17
+ SERVER: 1,
18
+ CLIENT: 2,
19
+ PRODUCER: 3,
20
+ CONSUMER: 4,
21
+ };
22
+ /** Span name constants used by the client when starting spans.
23
+ * Exposed so that adapters and tests can match on them. */
24
+ exports.ClickHouseSpanNames = {
25
+ query: "clickhouse.query",
26
+ /** A child of {@link ClickHouseSpanNames.query} that covers the lifetime
27
+ * of the `ResultSet` stream - from the first byte read to full
28
+ * consumption, cancellation, or failure. Ends with
29
+ * `clickhouse.response.decoded_bytes` and (for row-streaming paths)
30
+ * `db.response.returned_rows`. */
31
+ query_stream: "clickhouse.query.stream",
32
+ command: "clickhouse.command",
33
+ exec: "clickhouse.exec",
34
+ insert: "clickhouse.insert",
35
+ ping: "clickhouse.ping",
36
+ };
37
+ const noop = () => undefined;
38
+ /** Shared no-op span handed out by {@link NoopClickHouseTracer}. @internal */
39
+ exports.NoopClickHouseSpan = {
40
+ setAttributes: noop,
41
+ setStatus: noop,
42
+ recordException: noop,
43
+ end: noop,
44
+ };
45
+ /** No-op tracer assigned once at client creation when no tracer is
46
+ * configured, so the hot path stays branch-free (monomorphic call sites
47
+ * that the JIT can inline). @internal */
48
+ exports.NoopClickHouseTracer = {
49
+ startActiveSpan: (_name, _options, fn) => fn(exports.NoopClickHouseSpan),
50
+ };
51
+ /** Records the exception on the span and marks it with the ERROR status,
52
+ * normalizing non-`Error` throwables to `Error`.
53
+ *
54
+ * Sets the {@link https://opentelemetry.io/docs/specs/semconv/registry/attributes/error/#error-type `error.type`}
55
+ * attribute to the error class name (e.g. `ClickHouseError`, `TypeError`),
56
+ * and, for server-side errors ({@link ClickHouseError}), the numeric server
57
+ * error code as `clickhouse.error.code`. */
58
+ function recordSpanError(span, err) {
59
+ const error = err instanceof Error ? err : new Error(String(err));
60
+ const attributes = {
61
+ "error.type": error.constructor.name,
62
+ };
63
+ if (error instanceof error_1.ClickHouseError) {
64
+ const code = Number(error.code);
65
+ attributes["clickhouse.error.code"] = Number.isNaN(code)
66
+ ? error.code
67
+ : code;
68
+ }
69
+ span.setAttributes(attributes);
70
+ span.recordException(error);
71
+ span.setStatus({
72
+ code: exports.ClickHouseSpanStatusCode.ERROR,
73
+ message: error.message,
74
+ });
75
+ }
76
+ //# sourceMappingURL=tracing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../src/common/tracing.ts"],"names":[],"mappings":";;;AA+KA,0CAiBC;AAhMD,mCAA0C;AA4G1C;8CAC8C;AACjC,QAAA,wBAAwB,GAAG;IACtC,KAAK,EAAE,CAAC;IACR,EAAE,EAAE,CAAC;IACL,KAAK,EAAE,CAAC;CACA,CAAC;AAEX;yCACyC;AAC5B,QAAA,kBAAkB,GAAG;IAChC,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;CACH,CAAC;AAUX;4DAC4D;AAC/C,QAAA,mBAAmB,GAAG;IACjC,KAAK,EAAE,kBAAkB;IACzB;;;;uCAImC;IACnC,YAAY,EAAE,yBAAyB;IACvC,OAAO,EAAE,oBAAoB;IAC7B,IAAI,EAAE,iBAAiB;IACvB,MAAM,EAAE,mBAAmB;IAC3B,IAAI,EAAE,iBAAiB;CACf,CAAC;AAIX,MAAM,IAAI,GAAG,GAAS,EAAE,CAAC,SAAS,CAAC;AACnC,8EAA8E;AACjE,QAAA,kBAAkB,GAAmB;IAChD,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,IAAI;IACf,eAAe,EAAE,IAAI;IACrB,GAAG,EAAE,IAAI;CACV,CAAC;AAEF;;0CAE0C;AAC7B,QAAA,oBAAoB,GAAqB;IACpD,eAAe,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,0BAAkB,CAAC;CACjE,CAAC;AAEF;;;;;;6CAM6C;AAC7C,SAAgB,eAAe,CAAC,IAAoB,EAAE,GAAY;IAChE,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAClE,MAAM,UAAU,GAA6B;QAC3C,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,IAAI;KACrC,CAAC;IACF,IAAI,KAAK,YAAY,uBAAe,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,UAAU,CAAC,uBAAuB,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YACtD,CAAC,CAAC,KAAK,CAAC,IAAI;YACZ,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC/B,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,CAAC,SAAS,CAAC;QACb,IAAI,EAAE,gCAAwB,CAAC,KAAK;QACpC,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC,CAAC;AACL,CAAC"}
@@ -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":["../../src/common/ts_utils.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { CompressionMethod } from "../connection";
2
+ import type { ClickHouseSettings } from "../settings";
3
+ export type HttpHeader = number | string | string[];
4
+ export type HttpHeaders = Record<string, HttpHeader | undefined>;
5
+ export declare function withCompressionHeaders({ headers, request_compression_codec, response_compression_codec, }: {
6
+ headers: HttpHeaders;
7
+ request_compression_codec: CompressionMethod | undefined;
8
+ response_compression_codec: CompressionMethod | undefined;
9
+ }): Record<string, string>;
10
+ export declare function withHttpSettings(clickhouse_settings?: ClickHouseSettings, compression?: {
11
+ codec: CompressionMethod;
12
+ } | undefined): ClickHouseSettings;
13
+ export declare function isSuccessfulResponse(statusCode?: number): boolean;
14
+ export declare function isJWTAuth(auth: unknown): auth is {
15
+ access_token: string;
16
+ };
17
+ export declare function isCredentialsAuth(auth: unknown): auth is {
18
+ username: string;
19
+ password: string;
20
+ };
21
+ export declare const EXCEPTION_TAG_HEADER_NAME = "x-clickhouse-exception-tag";
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXCEPTION_TAG_HEADER_NAME = void 0;
4
+ exports.withCompressionHeaders = withCompressionHeaders;
5
+ exports.withHttpSettings = withHttpSettings;
6
+ exports.isSuccessfulResponse = isSuccessfulResponse;
7
+ exports.isJWTAuth = isJWTAuth;
8
+ exports.isCredentialsAuth = isCredentialsAuth;
9
+ function withCompressionHeaders({ headers, request_compression_codec, response_compression_codec, }) {
10
+ return {
11
+ ...headers,
12
+ ...(response_compression_codec
13
+ ? { "Accept-Encoding": response_compression_codec }
14
+ : {}),
15
+ ...(request_compression_codec
16
+ ? { "Content-Encoding": request_compression_codec }
17
+ : {}),
18
+ };
19
+ }
20
+ function withHttpSettings(clickhouse_settings, compression) {
21
+ return {
22
+ ...(compression
23
+ ? {
24
+ enable_http_compression: 1,
25
+ }
26
+ : {}),
27
+ ...clickhouse_settings,
28
+ };
29
+ }
30
+ function isSuccessfulResponse(statusCode) {
31
+ return Boolean(statusCode && 200 <= statusCode && statusCode < 300);
32
+ }
33
+ function isJWTAuth(auth) {
34
+ return auth !== null && typeof auth === "object" && "access_token" in auth;
35
+ }
36
+ function isCredentialsAuth(auth) {
37
+ return (auth !== null &&
38
+ typeof auth === "object" &&
39
+ "username" in auth &&
40
+ "password" in auth);
41
+ }
42
+ exports.EXCEPTION_TAG_HEADER_NAME = "x-clickhouse-exception-tag";
43
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/common/utils/connection.ts"],"names":[],"mappings":";;;AAMA,wDAoBC;AAED,4CAYC;AAED,oDAEC;AAED,8BAEC;AAED,8CASC;AArDD,SAAgB,sBAAsB,CAAC,EACrC,OAAO,EACP,yBAAyB,EACzB,0BAA0B,GAO3B;IACC,OAAO;QACL,GAAG,OAAO;QACV,GAAG,CAAC,0BAA0B;YAC5B,CAAC,CAAC,EAAE,iBAAiB,EAAE,0BAA0B,EAAE;YACnD,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,yBAAyB;YAC3B,CAAC,CAAC,EAAE,kBAAkB,EAAE,yBAAyB,EAAE;YACnD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC;AAED,SAAgB,gBAAgB,CAC9B,mBAAwC,EACxC,WAAsD;IAEtD,OAAO;QACL,GAAG,CAAC,WAAW;YACb,CAAC,CAAC;gBACE,uBAAuB,EAAE,CAAC;aAC3B;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,mBAAmB;KACvB,CAAC;AACJ,CAAC;AAED,SAAgB,oBAAoB,CAAC,UAAmB;IACtD,OAAO,OAAO,CAAC,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,UAAU,GAAG,GAAG,CAAC,CAAC;AACtE,CAAC;AAED,SAAgB,SAAS,CAAC,IAAa;IACrC,OAAO,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,cAAc,IAAI,IAAI,CAAC;AAC7E,CAAC;AAED,SAAgB,iBAAiB,CAC/B,IAAa;IAEb,OAAO,CACL,IAAI,KAAK,IAAI;QACb,OAAO,IAAI,KAAK,QAAQ;QACxB,UAAU,IAAI,IAAI;QAClB,UAAU,IAAI,IAAI,CACnB,CAAC;AACJ,CAAC;AAEY,QAAA,yBAAyB,GAAG,4BAA4B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./connection";
2
+ export * from "./multipart";
3
+ export * from "./sleep";
4
+ export * from "./stream";
5
+ export * from "./url";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./connection"), exports);
18
+ __exportStar(require("./multipart"), exports);
19
+ __exportStar(require("./sleep"), exports);
20
+ __exportStar(require("./stream"), exports);
21
+ __exportStar(require("./url"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,8CAA4B;AAC5B,0CAAwB;AACxB,2CAAyB;AACzB,wCAAsB"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Query parameters are URL-encoded into the request URL as `param_*` entries.
3
+ * Once their encoded length passes this budget, {@link serializeQueryParamsForUrl}
4
+ * returns null so that they are routed through the multipart body instead, keeping
5
+ * oversized payloads out of the URL where HTTP intermediaries (nginx, AWS ALB,
6
+ * CloudFront) reject them with HTTP 414 or 400. The threshold leaves ample
7
+ * headroom under common request line limits.
8
+ */
9
+ export declare const MAX_URL_BIND_PARAM_LENGTH = 4096;
10
+ /**
11
+ * Early-return variant of the `param_*` serialization performed by
12
+ * {@link toSearchParams}: serializes {@link query_params} into `param_*`
13
+ * URL entries, returning them so the caller can reuse the result without
14
+ * serializing the params a second time, or returns null as soon as the
15
+ * URL-encoded length exceeds {@link MAX_URL_BIND_PARAM_LENGTH} — in which
16
+ * case the params should be sent as a multipart/form-data body instead.
17
+ */
18
+ export declare function serializeQueryParamsForUrl(query_params: Record<string, unknown>): [string, string][] | null;
19
+ /**
20
+ * Builds a multipart/form-data body from a record of named string parts.
21
+ *
22
+ * Example output:
23
+ *
24
+ * --BOUNDARY\r\n
25
+ * Content-Disposition: form-data; name="query"\r\n
26
+ * \r\n
27
+ * SELECT * FROM t WHERE x IN {values:Array(String)}\r\n
28
+ * --BOUNDARY\r\n
29
+ * Content-Disposition: form-data; name="param_values"\r\n
30
+ * \r\n
31
+ * ['a@b.com','c@d.com']\r\n
32
+ * --BOUNDARY--\r\n
33
+ */
34
+ export declare function buildMultipartBody(parts: Record<string, string>, boundary: string): string;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_URL_BIND_PARAM_LENGTH = void 0;
4
+ exports.serializeQueryParamsForUrl = serializeQueryParamsForUrl;
5
+ exports.buildMultipartBody = buildMultipartBody;
6
+ const data_formatter_1 = require("../data_formatter");
7
+ const SAFE_PART_NAME = /^[A-Za-z0-9_.-]+$/;
8
+ /**
9
+ * Query parameters are URL-encoded into the request URL as `param_*` entries.
10
+ * Once their encoded length passes this budget, {@link serializeQueryParamsForUrl}
11
+ * returns null so that they are routed through the multipart body instead, keeping
12
+ * oversized payloads out of the URL where HTTP intermediaries (nginx, AWS ALB,
13
+ * CloudFront) reject them with HTTP 414 or 400. The threshold leaves ample
14
+ * headroom under common request line limits.
15
+ */
16
+ exports.MAX_URL_BIND_PARAM_LENGTH = 4096;
17
+ /**
18
+ * Early-return variant of the `param_*` serialization performed by
19
+ * {@link toSearchParams}: serializes {@link query_params} into `param_*`
20
+ * URL entries, returning them so the caller can reuse the result without
21
+ * serializing the params a second time, or returns null as soon as the
22
+ * URL-encoded length exceeds {@link MAX_URL_BIND_PARAM_LENGTH} — in which
23
+ * case the params should be sent as a multipart/form-data body instead.
24
+ */
25
+ function serializeQueryParamsForUrl(query_params) {
26
+ const entries = [];
27
+ // Raw length is a lower bound on the encoded length, so large payloads
28
+ // short-circuit without materializing the encoded string.
29
+ let rawLength = 0;
30
+ for (const [key, value] of Object.entries(query_params)) {
31
+ const name = `param_${key}`;
32
+ const formatted = (0, data_formatter_1.formatQueryParams)({ value });
33
+ rawLength += name.length + formatted.length;
34
+ if (rawLength > exports.MAX_URL_BIND_PARAM_LENGTH) {
35
+ return null;
36
+ }
37
+ entries.push([name, formatted]);
38
+ }
39
+ // Measure the exact encoded length, accounting for percent-encoding expansion.
40
+ if (new URLSearchParams(entries).toString().length > exports.MAX_URL_BIND_PARAM_LENGTH) {
41
+ return null;
42
+ }
43
+ return entries;
44
+ }
45
+ /**
46
+ * Builds a multipart/form-data body from a record of named string parts.
47
+ *
48
+ * Example output:
49
+ *
50
+ * --BOUNDARY\r\n
51
+ * Content-Disposition: form-data; name="query"\r\n
52
+ * \r\n
53
+ * SELECT * FROM t WHERE x IN {values:Array(String)}\r\n
54
+ * --BOUNDARY\r\n
55
+ * Content-Disposition: form-data; name="param_values"\r\n
56
+ * \r\n
57
+ * ['a@b.com','c@d.com']\r\n
58
+ * --BOUNDARY--\r\n
59
+ */
60
+ function buildMultipartBody(parts, boundary) {
61
+ const chunks = [];
62
+ // Part names are validated against SAFE_PART_NAME to prevent header injection
63
+ // (a name could otherwise smuggle CRLF or quotes into the Content-Disposition
64
+ // line). Part values are intentionally NOT validated/escaped: the only way a
65
+ // value could forge a part delimiter is by containing the boundary, and the
66
+ // boundary is a random UUID generated per request by the caller, so it cannot
67
+ // be predicted or collided with by user-supplied input.
68
+ for (const [name, value] of Object.entries(parts)) {
69
+ if (!SAFE_PART_NAME.test(name)) {
70
+ throw new Error(`Invalid multipart part name: "${name}". ` +
71
+ `Part names must match ${SAFE_PART_NAME}.`);
72
+ }
73
+ chunks.push(`--${boundary}\r\n` +
74
+ `Content-Disposition: form-data; name="${name}"\r\n` +
75
+ `\r\n` +
76
+ `${value}\r\n`);
77
+ }
78
+ chunks.push(`--${boundary}--\r\n`);
79
+ return chunks.join("");
80
+ }
81
+ //# sourceMappingURL=multipart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../../src/common/utils/multipart.ts"],"names":[],"mappings":";;;AAsBA,gEAuBC;AAiBD,gDA8BC;AA5FD,sDAAsD;AAEtD,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAE3C;;;;;;;GAOG;AACU,QAAA,yBAAyB,GAAG,IAAI,CAAC;AAE9C;;;;;;;GAOG;AACH,SAAgB,0BAA0B,CACxC,YAAqC;IAErC,MAAM,OAAO,GAAuB,EAAE,CAAC;IACvC,uEAAuE;IACvE,0DAA0D;IAC1D,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,GAAG,SAAS,GAAG,EAAE,CAAC;QAC5B,MAAM,SAAS,GAAG,IAAA,kCAAiB,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC/C,SAAS,IAAI,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;QAC5C,IAAI,SAAS,GAAG,iCAAyB,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IAClC,CAAC;IACD,+EAA+E;IAC/E,IACE,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,GAAG,iCAAyB,EAC1E,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,kBAAkB,CAChC,KAA6B,EAC7B,QAAgB;IAEhB,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,8EAA8E;IAC9E,8EAA8E;IAC9E,6EAA6E;IAC7E,4EAA4E;IAC5E,8EAA8E;IAC9E,wDAAwD;IACxD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,iCAAiC,IAAI,KAAK;gBACxC,yBAAyB,cAAc,GAAG,CAC7C,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,IAAI,CACT,KAAK,QAAQ,MAAM;YACjB,yCAAyC,IAAI,OAAO;YACpD,MAAM;YACN,GAAG,KAAK,MAAM,CACjB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,KAAK,QAAQ,QAAQ,CAAC,CAAC;IAEnC,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @deprecated This utility function is not intended to be used outside of the client implementation anymore. Please, use `setTimeout` directly or a more full-featured utility library if you need additional features like cancellation or timers management.
3
+ */
4
+ export declare function sleep(ms: number): Promise<void>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sleep = sleep;
4
+ /**
5
+ * @deprecated This utility function is not intended to be used outside of the client implementation anymore. Please, use `setTimeout` directly or a more full-featured utility library if you need additional features like cancellation or timers management.
6
+ */
7
+ async function sleep(ms) {
8
+ await new Promise((resolve) => setTimeout(() => {
9
+ resolve(void 0);
10
+ }, ms));
11
+ }
12
+ //# sourceMappingURL=sleep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sleep.js","sourceRoot":"","sources":["../../../src/common/utils/sleep.ts"],"names":[],"mappings":";;AAGA,sBAMC;AATD;;GAEG;AACI,KAAK,UAAU,KAAK,CAAC,EAAU;IACpC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAClB,CAAC,EAAE,EAAE,CAAC,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ export declare const CARET_RETURN: 13;
2
+ /**
3
+ * After 25.11, a newline error character is preceded by a caret return
4
+ * this is a strong indication that we have an exception in the stream.
5
+ *
6
+ * Example with exception marker `FOOBAR`:
7
+ *
8
+ * \r\n__exception__\r\nFOOBAR
9
+ * boom
10
+ * 5 FOOBAR\r\n__exception__\r\n
11
+ *
12
+ * In this case, the exception length is 5 (including the newline character),
13
+ * and the exception message is "boom".
14
+ */
15
+ export declare function extractErrorAtTheEndOfChunk(chunk: Uint8Array, exceptionTag: string): Error;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CARET_RETURN = void 0;
4
+ exports.extractErrorAtTheEndOfChunk = extractErrorAtTheEndOfChunk;
5
+ const error_1 = require("../error");
6
+ const EXCEPTION_MARKER = "__exception__";
7
+ const NEWLINE = 0x0a;
8
+ exports.CARET_RETURN = 0x0d;
9
+ /**
10
+ * After 25.11, a newline error character is preceded by a caret return
11
+ * this is a strong indication that we have an exception in the stream.
12
+ *
13
+ * Example with exception marker `FOOBAR`:
14
+ *
15
+ * \r\n__exception__\r\nFOOBAR
16
+ * boom
17
+ * 5 FOOBAR\r\n__exception__\r\n
18
+ *
19
+ * In this case, the exception length is 5 (including the newline character),
20
+ * and the exception message is "boom".
21
+ */
22
+ function extractErrorAtTheEndOfChunk(chunk, exceptionTag) {
23
+ try {
24
+ const bytesCountAfterErrLenHint = 1 + // space
25
+ EXCEPTION_MARKER.length + // __exception__
26
+ 2 + // \r\n
27
+ exceptionTag.length + // <value taken from the header>
28
+ 2; // \r\n
29
+ let errMsgLenStartIdx = chunk.length - bytesCountAfterErrLenHint;
30
+ if (errMsgLenStartIdx < 1) {
31
+ return new Error("there was an error in the stream, but the last chunk is malformed");
32
+ }
33
+ do {
34
+ --errMsgLenStartIdx;
35
+ } while (chunk[errMsgLenStartIdx] !== NEWLINE);
36
+ const textDecoder = new TextDecoder("utf-8");
37
+ const errMsgLen = parseInt(textDecoder.decode(chunk.subarray(errMsgLenStartIdx, -bytesCountAfterErrLenHint)));
38
+ if (isNaN(errMsgLen) || errMsgLen <= 0) {
39
+ return new Error("there was an error in the stream; failed to parse the message length");
40
+ }
41
+ const errMsg = textDecoder.decode(chunk.subarray(errMsgLenStartIdx - errMsgLen + 1, // skipping the newline character
42
+ errMsgLenStartIdx));
43
+ return (0, error_1.parseError)(errMsg);
44
+ }
45
+ catch (err) {
46
+ // theoretically, it can happen if a proxy cuts the last chunk
47
+ return err;
48
+ }
49
+ }
50
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/common/utils/stream.ts"],"names":[],"mappings":";;;AAoBA,kEAiDC;AArED,oCAAsC;AAEtC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AAEzC,MAAM,OAAO,GAAG,IAAa,CAAC;AACjB,QAAA,YAAY,GAAG,IAAa,CAAC;AAE1C;;;;;;;;;;;;GAYG;AACH,SAAgB,2BAA2B,CACzC,KAAiB,EACjB,YAAoB;IAEpB,IAAI,CAAC;QACH,MAAM,yBAAyB,GAC7B,CAAC,GAAG,QAAQ;YACZ,gBAAgB,CAAC,MAAM,GAAG,gBAAgB;YAC1C,CAAC,GAAG,OAAO;YACX,YAAY,CAAC,MAAM,GAAG,gCAAgC;YACtD,CAAC,CAAC,CAAC,OAAO;QAEZ,IAAI,iBAAiB,GAAG,KAAK,CAAC,MAAM,GAAG,yBAAyB,CAAC;QACjE,IAAI,iBAAiB,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,KAAK,CACd,mEAAmE,CACpE,CAAC;QACJ,CAAC;QAED,GAAG,CAAC;YACF,EAAE,iBAAiB,CAAC;QACtB,CAAC,QAAQ,KAAK,CAAC,iBAAiB,CAAC,KAAK,OAAO,EAAE;QAE/C,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;QAE7C,MAAM,SAAS,GAAG,QAAQ,CACxB,WAAW,CAAC,MAAM,CAChB,KAAK,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC,yBAAyB,CAAC,CAC9D,CACF,CAAC;QAEF,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;YACvC,OAAO,IAAI,KAAK,CACd,sEAAsE,CACvE,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAC/B,KAAK,CAAC,QAAQ,CACZ,iBAAiB,GAAG,SAAS,GAAG,CAAC,EAAE,iCAAiC;QACpE,iBAAiB,CAClB,CACF,CAAC;QAEF,OAAO,IAAA,kBAAU,EAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,8DAA8D;QAC9D,OAAO,GAAY,CAAC;IACtB,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { ClickHouseSettings } from "../settings";
2
+ export declare function transformUrl({ url, pathname, searchParams, }: {
3
+ url: URL;
4
+ pathname?: string;
5
+ searchParams?: URLSearchParams;
6
+ }): URL;
7
+ interface ToSearchParamsOptions {
8
+ database: string | undefined;
9
+ clickhouse_settings?: ClickHouseSettings;
10
+ query_params?: Record<string, unknown>;
11
+ /** Pre-serialized `param_*` entries (e.g. from {@link serializeQueryParamsForUrl});
12
+ * used as-is instead of serializing {@link query_params} again. */
13
+ param_entries?: [string, string][];
14
+ query?: string;
15
+ session_id?: string;
16
+ query_id: string;
17
+ role?: string | Array<string>;
18
+ }
19
+ export declare function toSearchParams({ database, query, query_params, param_entries, clickhouse_settings, session_id, query_id, role, }: ToSearchParamsOptions): URLSearchParams;
20
+ export {};