@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.17

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 (235) hide show
  1. package/README.md +111 -101
  2. package/app_meta.ts +56 -54
  3. package/config/config.ts +60 -57
  4. package/config/secrets.ts +45 -52
  5. package/config/value.ts +23 -26
  6. package/cron/mod.ts +28 -29
  7. package/dist/app_meta.d.ts +52 -50
  8. package/dist/app_meta.d.ts.map +1 -1
  9. package/dist/app_meta.js +2 -2
  10. package/dist/app_meta.js.map +1 -1
  11. package/dist/config/config.d.ts +58 -55
  12. package/dist/config/config.d.ts.map +1 -1
  13. package/dist/config/config.js +8 -9
  14. package/dist/config/config.js.map +1 -1
  15. package/dist/config/secrets.d.ts +45 -52
  16. package/dist/config/secrets.d.ts.map +1 -1
  17. package/dist/config/secrets.js +8 -9
  18. package/dist/config/secrets.js.map +1 -1
  19. package/dist/config/value.d.ts +20 -23
  20. package/dist/config/value.d.ts.map +1 -1
  21. package/dist/config/value.js +20 -23
  22. package/dist/config/value.js.map +1 -1
  23. package/dist/cron/mod.d.ts +26 -27
  24. package/dist/cron/mod.d.ts.map +1 -1
  25. package/dist/cron/mod.js +13 -14
  26. package/dist/cron/mod.js.map +1 -1
  27. package/dist/frontends/mod.d.ts +20 -19
  28. package/dist/frontends/mod.d.ts.map +1 -1
  29. package/dist/frontends/mod.js +20 -19
  30. package/dist/frontends/mod.js.map +1 -1
  31. package/dist/gateway/errors.d.ts +28 -30
  32. package/dist/gateway/errors.d.ts.map +1 -1
  33. package/dist/gateway/errors.js +29 -31
  34. package/dist/gateway/errors.js.map +1 -1
  35. package/dist/gateway/match.d.ts +54 -54
  36. package/dist/gateway/match.d.ts.map +1 -1
  37. package/dist/gateway/match.js +56 -56
  38. package/dist/gateway/match.js.map +1 -1
  39. package/dist/gateway/middleware.d.ts +62 -64
  40. package/dist/gateway/middleware.d.ts.map +1 -1
  41. package/dist/gateway/middleware.js +1 -1
  42. package/dist/gateway/middleware.js.map +1 -1
  43. package/dist/gateway/mod.d.ts +64 -67
  44. package/dist/gateway/mod.d.ts.map +1 -1
  45. package/dist/gateway/mod.js +72 -76
  46. package/dist/gateway/mod.js.map +1 -1
  47. package/dist/gateway/request.d.ts +138 -134
  48. package/dist/gateway/request.d.ts.map +1 -1
  49. package/dist/gateway/request.js +117 -108
  50. package/dist/gateway/request.js.map +1 -1
  51. package/dist/gateway/serve.d.ts +29 -34
  52. package/dist/gateway/serve.d.ts.map +1 -1
  53. package/dist/gateway/serve.js +51 -56
  54. package/dist/gateway/serve.js.map +1 -1
  55. package/dist/gateways/mod.d.ts +23 -21
  56. package/dist/gateways/mod.d.ts.map +1 -1
  57. package/dist/gateways/mod.js +25 -23
  58. package/dist/gateways/mod.js.map +1 -1
  59. package/dist/internal/runtime/napi/napi.cjs +1 -1
  60. package/dist/internal/runtime/napi/napi.d.cts +10 -3
  61. package/dist/internal/runtime/shutdown.d.ts +75 -57
  62. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  63. package/dist/internal/runtime/shutdown.js +88 -84
  64. package/dist/internal/runtime/shutdown.js.map +1 -1
  65. package/dist/log/logger.d.ts +43 -37
  66. package/dist/log/logger.d.ts.map +1 -1
  67. package/dist/log/logger.js +26 -25
  68. package/dist/log/logger.js.map +1 -1
  69. package/dist/metrics/mod.d.ts +133 -114
  70. package/dist/metrics/mod.d.ts.map +1 -1
  71. package/dist/metrics/mod.js +109 -101
  72. package/dist/metrics/mod.js.map +1 -1
  73. package/dist/otel.d.ts +6 -3
  74. package/dist/otel.d.ts.map +1 -1
  75. package/dist/otel.js +6 -3
  76. package/dist/otel.js.map +1 -1
  77. package/dist/pubsub/subscription.d.ts +88 -116
  78. package/dist/pubsub/subscription.d.ts.map +1 -1
  79. package/dist/pubsub/subscription.js +14 -17
  80. package/dist/pubsub/subscription.js.map +1 -1
  81. package/dist/pubsub/topic.d.ts +86 -113
  82. package/dist/pubsub/topic.d.ts.map +1 -1
  83. package/dist/pubsub/topic.js +68 -82
  84. package/dist/pubsub/topic.js.map +1 -1
  85. package/dist/reqctx/mod.d.ts +83 -86
  86. package/dist/reqctx/mod.d.ts.map +1 -1
  87. package/dist/reqctx/mod.js +39 -41
  88. package/dist/reqctx/mod.js.map +1 -1
  89. package/dist/services/index.d.ts +76 -75
  90. package/dist/services/index.d.ts.map +1 -1
  91. package/dist/services/index.js +73 -71
  92. package/dist/services/index.js.map +1 -1
  93. package/dist/shutdown/mod.d.ts +26 -25
  94. package/dist/shutdown/mod.d.ts.map +1 -1
  95. package/dist/shutdown/mod.js +26 -25
  96. package/dist/shutdown/mod.js.map +1 -1
  97. package/dist/storage/clickhouse/database.d.ts +113 -115
  98. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  99. package/dist/storage/clickhouse/database.js +65 -79
  100. package/dist/storage/clickhouse/database.js.map +1 -1
  101. package/dist/storage/clickhouse/errors.d.ts +25 -26
  102. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  103. package/dist/storage/clickhouse/errors.js +15 -17
  104. package/dist/storage/clickhouse/errors.js.map +1 -1
  105. package/dist/storage/clickhouse/mod.d.ts +10 -10
  106. package/dist/storage/clickhouse/mod.js +10 -10
  107. package/dist/storage/objects/bucket.d.ts +196 -225
  108. package/dist/storage/objects/bucket.d.ts.map +1 -1
  109. package/dist/storage/objects/bucket.js +71 -84
  110. package/dist/storage/objects/bucket.js.map +1 -1
  111. package/dist/storage/objects/error.d.ts +4 -4
  112. package/dist/storage/objects/error.js +4 -4
  113. package/dist/storage/postgres/database.d.ts +124 -149
  114. package/dist/storage/postgres/database.d.ts.map +1 -1
  115. package/dist/storage/postgres/database.js +98 -135
  116. package/dist/storage/postgres/database.js.map +1 -1
  117. package/dist/storage/postgres/errors.d.ts +42 -48
  118. package/dist/storage/postgres/errors.d.ts.map +1 -1
  119. package/dist/storage/postgres/errors.js +44 -51
  120. package/dist/storage/postgres/errors.js.map +1 -1
  121. package/dist/storage/postgres/interval.d.ts +19 -19
  122. package/dist/storage/postgres/interval.d.ts.map +1 -1
  123. package/dist/storage/postgres/interval.js +21 -21
  124. package/dist/storage/postgres/interval.js.map +1 -1
  125. package/dist/storage/redis/bitfield.d.ts +48 -23
  126. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  127. package/dist/storage/redis/bitfield.js +38 -19
  128. package/dist/storage/redis/bitfield.js.map +1 -1
  129. package/dist/storage/redis/command.d.ts +16 -12
  130. package/dist/storage/redis/command.d.ts.map +1 -1
  131. package/dist/storage/redis/command.js +16 -12
  132. package/dist/storage/redis/command.js.map +1 -1
  133. package/dist/storage/redis/commands.d.ts +99 -100
  134. package/dist/storage/redis/commands.d.ts.map +1 -1
  135. package/dist/storage/redis/commands.js +84 -85
  136. package/dist/storage/redis/commands.js.map +1 -1
  137. package/dist/storage/redis/database.d.ts +138 -122
  138. package/dist/storage/redis/database.d.ts.map +1 -1
  139. package/dist/storage/redis/database.js +120 -101
  140. package/dist/storage/redis/database.js.map +1 -1
  141. package/dist/storage/redis/mod.d.ts +52 -48
  142. package/dist/storage/redis/mod.d.ts.map +1 -1
  143. package/dist/storage/redis/mod.js +52 -48
  144. package/dist/storage/redis/mod.js.map +1 -1
  145. package/dist/storage/redis/options.d.ts +26 -24
  146. package/dist/storage/redis/options.d.ts.map +1 -1
  147. package/dist/storage/redis/options.js.map +1 -1
  148. package/dist/storage/redis/pubsub.d.ts +16 -16
  149. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  150. package/dist/storage/redis/pubsub.js +14 -14
  151. package/dist/storage/redis/pubsub.js.map +1 -1
  152. package/dist/storage/redis/reply.d.ts +80 -72
  153. package/dist/storage/redis/reply.d.ts.map +1 -1
  154. package/dist/storage/redis/reply.js +53 -46
  155. package/dist/storage/redis/reply.js.map +1 -1
  156. package/dist/storage/redis/scan.d.ts +4 -4
  157. package/dist/storage/redis/scan.d.ts.map +1 -1
  158. package/dist/storage/redis/scan.js +6 -6
  159. package/dist/storage/redis/scan.js.map +1 -1
  160. package/dist/storage/redis/script.d.ts +28 -21
  161. package/dist/storage/redis/script.d.ts.map +1 -1
  162. package/dist/storage/redis/script.js +29 -22
  163. package/dist/storage/redis/script.js.map +1 -1
  164. package/dist/storage/redis/target.d.ts +17 -1
  165. package/dist/storage/redis/target.d.ts.map +1 -1
  166. package/dist/storage/redis/target.js +30 -1
  167. package/dist/storage/redis/target.js.map +1 -1
  168. package/dist/storage/redis/wire.d.ts +6 -6
  169. package/dist/storage/redis/wire.d.ts.map +1 -1
  170. package/dist/storage/redis/wire.js +6 -6
  171. package/dist/storage/redis/wire.js.map +1 -1
  172. package/dist/testing/mod.d.ts +83 -88
  173. package/dist/testing/mod.d.ts.map +1 -1
  174. package/dist/testing/mod.js +75 -81
  175. package/dist/testing/mod.js.map +1 -1
  176. package/dist/testing/playwright.d.ts +28 -32
  177. package/dist/testing/playwright.d.ts.map +1 -1
  178. package/dist/testing/playwright.js +22 -27
  179. package/dist/testing/playwright.js.map +1 -1
  180. package/dist/testing/puppeteer.d.ts +11 -12
  181. package/dist/testing/puppeteer.d.ts.map +1 -1
  182. package/dist/testing/puppeteer.js +17 -18
  183. package/dist/testing/puppeteer.js.map +1 -1
  184. package/dist/testing/system.d.ts +72 -90
  185. package/dist/testing/system.d.ts.map +1 -1
  186. package/dist/testing/system.js +90 -107
  187. package/dist/testing/system.js.map +1 -1
  188. package/dist/tsconfig.build.tsbuildinfo +1 -1
  189. package/frontends/mod.test.ts +6 -2
  190. package/frontends/mod.ts +20 -19
  191. package/gateway/errors.ts +30 -32
  192. package/gateway/match.ts +61 -57
  193. package/gateway/middleware.ts +62 -64
  194. package/gateway/mod.ts +73 -76
  195. package/gateway/request.ts +143 -140
  196. package/gateway/serve.ts +58 -63
  197. package/gateways/mod.ts +25 -23
  198. package/internal/runtime/napi/napi.cjs +1 -1
  199. package/internal/runtime/napi/napi.d.cts +10 -3
  200. package/internal/runtime/shutdown.ts +113 -101
  201. package/log/logger.test.ts +8 -0
  202. package/log/logger.ts +48 -45
  203. package/metrics/mod.ts +138 -122
  204. package/otel.ts +6 -3
  205. package/package.json +1 -1
  206. package/pubsub/subscription.ts +93 -123
  207. package/pubsub/topic.ts +96 -130
  208. package/reqctx/mod.ts +83 -86
  209. package/services/index.ts +78 -78
  210. package/shutdown/mod.ts +26 -25
  211. package/storage/clickhouse/database.ts +115 -129
  212. package/storage/clickhouse/errors.ts +27 -29
  213. package/storage/clickhouse/mod.ts +10 -10
  214. package/storage/objects/bucket.ts +209 -239
  215. package/storage/objects/error.ts +4 -4
  216. package/storage/postgres/database.ts +131 -164
  217. package/storage/postgres/errors.ts +45 -52
  218. package/storage/postgres/interval.ts +21 -21
  219. package/storage/redis/bitfield.ts +51 -26
  220. package/storage/redis/command.ts +16 -12
  221. package/storage/redis/commands.ts +99 -100
  222. package/storage/redis/database.ts +145 -123
  223. package/storage/redis/mod.ts +52 -48
  224. package/storage/redis/options.ts +26 -24
  225. package/storage/redis/pubsub.ts +14 -14
  226. package/storage/redis/redis.test.ts +17 -2
  227. package/storage/redis/reply.ts +85 -77
  228. package/storage/redis/scan.ts +6 -6
  229. package/storage/redis/script.ts +29 -22
  230. package/storage/redis/target.ts +34 -1
  231. package/storage/redis/wire.ts +8 -8
  232. package/testing/mod.ts +99 -105
  233. package/testing/playwright.ts +32 -37
  234. package/testing/puppeteer.ts +22 -23
  235. package/testing/system.ts +117 -133
@@ -6,62 +6,62 @@ import {Decimal} from '../../types/mod';
6
6
  import {native, nativeSync, TooManyRowsError} from './errors';
7
7
 
8
8
  /**
9
- * Configuration for a ClickHouse `Database`.
9
+ * Configuration for a ClickHouse {@link Database}.
10
10
  */
11
11
  export interface DatabaseConfig {
12
12
  /**
13
- * The directory of the database's migrations, relative to the file that
14
- * declares it: `1_create_events.up.sql` and so on, with optional
15
- * `.down.sql` files. Each file's statements run one at a time; a failed
16
- * one leaves the database's version dirty, as ClickHouse can't roll DDL
17
- * back.
13
+ * Path to the migrations directory relative to the declaring file (containing
14
+ * files such as `1_create_events.up.sql` and optional `.down.sql` files).
15
+ * Statements in each file run sequentially; because ClickHouse cannot roll
16
+ * back DDL, a failed migration leaves the schema version dirty.
18
17
  */
19
18
  migrations?: string;
20
19
 
21
20
  /**
22
- * Tags that classify the database, for policies to read: written out as
23
- * string literals, as in `{data: "pci"}`. Keys and values are lowercase
24
- * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
25
- * letter, and not with `encore`, which is reserved. At most 32 tags.
21
+ * Static string-literal tags that classify the database for policy checks
22
+ * (e.g. `{data: "pci"}`). Keys and values may contain lowercase letters,
23
+ * digits, `_`, and `-`, up to 63 characters. Keys must start with a letter
24
+ * and cannot start with the reserved prefix `encore`. At most 32 tags.
26
25
  */
27
26
  tags?: Record<string, string>;
28
27
  }
29
28
 
30
29
  /**
31
- * A row of a query's result, keyed by column name.
30
+ * A single query result row, keyed by column name.
32
31
  *
33
- * - Integers and floats are numbers, but for 64-bit integers beyond what a
34
- * number holds exactly (±(2^53−1)), and `Int128`/`UInt128`/`Int256`/
35
- * `UInt256`, which are `bigint`s, so they are never rounded.
36
- * - `Decimal` is its exact text: `'12.30'`.
37
- * - `String` is a string (invalid UTF-8 replaced), and a `FixedString`
38
- * that isn't UTF-8 a `Buffer`.
39
- * - `UUID`, `Enum`, `IPv4` and `IPv6` are strings.
40
- * - `Date`/`Date32` is a `'YYYY-MM-DD'` string, `DateTime`/`DateTime64` a
41
- * `Date` (to the millisecond), and `Time`/`Time64` a number of seconds.
42
- * - `Array` and `Tuple` are arrays, a `Map` with string keys an object and
43
- * any other `Map` a `Map`, and `JSON` its parsed value.
44
- * - `NULL` is `null`.
32
+ * Column types map to JavaScript values as follows:
33
+ * - Integers and floats decode to `number`, except 64-bit integers outside the
34
+ * safe integer range (±(2^53−1)) and `Int128`/`UInt128`/`Int256`/`UInt256`,
35
+ * which decode to `bigint` to avoid precision loss.
36
+ * - `Decimal` decodes to its exact string representation (e.g. `'12.30'`).
37
+ * - `String` decodes to `string` (invalid UTF-8 replaced); non-UTF-8
38
+ * `FixedString` decodes to `Buffer`.
39
+ * - `UUID`, `Enum`, `IPv4`, and `IPv6` decode to `string`.
40
+ * - `Date`/`Date32` decode to `'YYYY-MM-DD'`, `DateTime`/`DateTime64` to
41
+ * `Date` (millisecond precision), and `Time`/`Time64` to seconds (`number`).
42
+ * - `Array` and `Tuple` decode to arrays; `Map` with string keys decodes to a
43
+ * plain object (other key types decode to `Map`); `JSON` decodes to its
44
+ * parsed value.
45
+ * - `NULL` decodes to `null`.
45
46
  */
46
47
  export type Row = Record<string, any>;
47
48
 
48
49
  /**
49
- * A value a query parameter or an inserted column takes. Its ClickHouse type,
50
- * when a tagged template names it for you, is inferred from it:
50
+ * A value accepted as a query parameter or inserted column. In tagged-template
51
+ * queries, the ClickHouse parameter type is inferred automatically:
51
52
  *
52
- * - `boolean`: `Bool`
53
- * - an integer `number` (to ±(2^53−1)): `Int64`; any other `number`: `Float64`
54
- * - `bigint`: `Int64`, or `UInt64` above its maximum (wider ones up to 256 bits)
55
- * - `string`: `String`; `Buffer`/`Uint8Array`: `String` (its bytes)
56
- * - `Date`: `DateTime64(6, 'UTC')`
57
- * - `Decimal`: `Decimal(76, s)`, `s` its digits after the point
58
- * - an array: `Array(T)`, `T` its first non-null element's type, made
59
- * `Nullable` if it holds a null
60
- * - a plain object, or a `Map`: `Map(String, T)` (a `Map`'s keys as their
61
- * own type)
62
- * - `null`/`undefined`: `Nullable(String)`, `NULL`
53
+ * - `boolean` → `Bool`
54
+ * - safe integer `number` → `Int64`; other `number` → `Float64`
55
+ * - `bigint` → `Int64`, or `UInt64` (and wider types up to 256 bits) as needed
56
+ * - `string`, `Buffer`, `Uint8Array` → `String`
57
+ * - `Date` → `DateTime64(6, 'UTC')`
58
+ * - `Decimal` → `Decimal(76, s)` where `s` is the decimal scale
59
+ * - array → `Array(T)` inferred from the first non-null element (`Nullable(T)`
60
+ * if the array contains `null`)
61
+ * - plain object or `Map` → `Map(K, V)`
62
+ * - `null`/`undefined` → `Nullable(String)` (`NULL`)
63
63
  *
64
- * Wrap a value whose type should be another in {@link typed}.
64
+ * Wrap a value with {@link typed} to specify an explicit ClickHouse type.
65
65
  */
66
66
  export type Param =
67
67
  | string
@@ -79,57 +79,57 @@ export type Param =
79
79
  | Map<Param, Param>
80
80
  | {[key: string]: Param};
81
81
 
82
- /** A setting's value: sent as its text, a boolean as `1` or `0`. */
82
+ /** ClickHouse query setting value (booleans are sent as `1` or `0`). */
83
83
  export type SettingValue = string | number | boolean;
84
84
 
85
- /** Options for one call. */
85
+ /** Per-call options for ClickHouse queries and statements. */
86
86
  export interface QueryOptions {
87
87
  /**
88
- * ClickHouse settings for this call only, such as `{max_execution_time: 5}`
89
- * or `{async_insert: true}`. There are no sessions: each call is a request
90
- * of its own, so `SET` doesn't carry over to the next one. An unknown
91
- * setting is the server's error.
88
+ * ClickHouse settings applied only to this call (e.g.
89
+ * `{max_execution_time: 5}` or `{async_insert: true}`). Because calls are
90
+ * stateless, `SET` does not carry over between calls. Unknown settings cause
91
+ * a server error.
92
92
  */
93
93
  settings?: Record<string, SettingValue>;
94
- /** The query's id on the server, for `system.query_log`: one is made if not given. */
94
+ /** Custom server query ID for `system.query_log` (auto-generated if omitted). */
95
95
  queryId?: string;
96
96
  }
97
97
 
98
- /** What a statement or insert did, as the server summarizes it. */
98
+ /** Execution statistics returned by ClickHouse for a statement or insert. */
99
99
  export interface ExecResult {
100
- /** How many rows it wrote. */
100
+ /** Number of rows written. */
101
101
  rowsWritten: number;
102
- /** How many bytes it wrote, uncompressed. */
102
+ /** Number of uncompressed bytes written. */
103
103
  bytesWritten: number;
104
- /** How many rows it read. */
104
+ /** Number of rows read. */
105
105
  rowsRead: number;
106
- /** The query's id on the server. */
106
+ /** Server-assigned or caller-provided query ID. */
107
107
  queryId: string;
108
108
  }
109
109
 
110
- /** The marker the native module recognizes a {@link Typed} by: on the
111
- * prototype, so a parameter that is an object of data is never taken for one. */
110
+ /** Prototype marker used by the native module to identify {@link Typed} wrappers. */
112
111
  const TYPED_MARKER = '__encore_clickhouse_type';
113
112
 
114
113
  /**
115
- * A value with the ClickHouse type it is bound as: see {@link typed}.
114
+ * Wraps a query parameter value with an explicit ClickHouse type (see
115
+ * {@link typed}).
116
116
  */
117
117
  export class Typed<T = unknown> {
118
118
  /** @internal */
119
119
  constructor(
120
- /** The value. */
120
+ /** The parameter value. */
121
121
  readonly value: T,
122
- /** Its ClickHouse type, such as `'UUID'` or `'Array(UInt32)'`. */
122
+ /** Explicit ClickHouse type name (e.g. `'UUID'` or `'Array(UInt32)'`). */
123
123
  readonly type: string,
124
124
  ) {}
125
125
  }
126
126
  Object.defineProperty(Typed.prototype, TYPED_MARKER, {value: true});
127
127
 
128
128
  /**
129
- * Binds `value` as the ClickHouse type `type` rather than the one inferred
130
- * from it, in a tagged template: `` ${typed(id, 'UUID')} `` becomes
131
- * `{p0:UUID}`. A `Date` bound as `DateTime` is its whole seconds, and as
132
- * `Date` or `Date32` its day in UTC.
129
+ * Binds `value` as the explicit ClickHouse type `type` instead of inferring
130
+ * one in tagged-template queries (e.g. `` ${typed(id, 'UUID')} `` emits
131
+ * `{p0:UUID}`). A `Date` bound as `DateTime` truncates to whole seconds; bound
132
+ * as `Date` or `Date32`, it uses the UTC calendar date.
133
133
  *
134
134
  * @example
135
135
  * await db.queryAll`SELECT * FROM events WHERE user_id = ${typed(userId, 'UUID')}`;
@@ -138,10 +138,10 @@ export function typed<T>(value: T, type: string): Typed<T> {
138
138
  return new Typed(value, type);
139
139
  }
140
140
 
141
- /** The native database a handle's calls go to. */
141
+ /** Native ClickHouse handle or lazy test-scoped resolver. */
142
142
  type Handle = runtime.ClickHouseDatabase | (() => runtime.ClickHouseDatabase);
143
143
 
144
- /** Base class with the query methods every handle has. */
144
+ /** Base class providing shared ClickHouse query and execution methods. */
145
145
  class BaseQueryExecutor {
146
146
  /** @internal */
147
147
  constructor(
@@ -149,28 +149,26 @@ class BaseQueryExecutor {
149
149
  private readonly access: runtime.ClickHouseAccess,
150
150
  ) {}
151
151
 
152
- /** The native database: in test mode the current test's instance. */
152
+ /** Native database handle (resolves to the current test's instance in test mode). */
153
153
  protected get impl(): runtime.ClickHouseDatabase {
154
154
  return typeof this.handle === 'function' ? this.handle() : this.handle;
155
155
  }
156
156
 
157
157
  /**
158
- * The connection string to connect to the database with another client,
159
- * as this handle's user: `http://user:password@host:port/database`.
160
- * `@clickhouse/client` reads it as its `url`.
158
+ * HTTP connection string (`http://user:password@host:port/database`) scoped
159
+ * to this handle's access level, compatible with `@clickhouse/client`'s `url`
160
+ * option.
161
161
  */
162
162
  get connectionString(): string {
163
163
  return nativeSync(() => this.impl.connectionString(this.access));
164
164
  }
165
165
 
166
166
  /**
167
- * Queries the database with a template string, binding each `${value}` as
168
- * a parameter of the type inferred from it (see {@link Param}):
169
- * `` query`SELECT * FROM events WHERE id = ${id}` `` runs `SELECT * FROM
170
- * events WHERE id = {p0:Int64}`. Wrap a value in {@link typed} to bind it
171
- * as another type.
172
- *
173
- * It streams the rows: iterate it with `for await`.
167
+ * Streams rows from a tagged-template query, binding each `${value}` as a
168
+ * typed server parameter (see {@link Param}). For example,
169
+ * `` query`SELECT * FROM events WHERE id = ${id}` `` sends
170
+ * `SELECT * FROM events WHERE id = {p0:Int64}`. Use {@link typed} to
171
+ * override the inferred type. Iterate results with `for await`.
174
172
  */
175
173
  async *query<T extends Row = Record<string, any>>(
176
174
  strings: TemplateStringsArray,
@@ -181,14 +179,13 @@ class BaseQueryExecutor {
181
179
  }
182
180
 
183
181
  /**
184
- * Queries the database with SQL whose parameters it names, with their
185
- * types, as `{name:Type}`, and `params` their values by name:
182
+ * Streams rows from a raw SQL query with named typed placeholders (such as
183
+ * `{id:UInt64}`) and matching entries in `params`. Iterate results with
184
+ * `for await`.
186
185
  *
187
186
  * ```ts
188
187
  * db.rawQuery('SELECT * FROM events WHERE id = {id:UInt64}', {id: 5});
189
188
  * ```
190
- *
191
- * It streams the rows: iterate it with `for await`.
192
189
  */
193
190
  async *rawQuery<T extends Row = Record<string, any>>(
194
191
  sql: string,
@@ -198,7 +195,7 @@ class BaseQueryExecutor {
198
195
  yield* this.rows<T>(sql, namedParams(params), options);
199
196
  }
200
197
 
201
- /** {@link query}, returning every row. */
198
+ /** Runs a tagged-template query (like {@link query}) and collects all rows into an array. */
202
199
  async queryAll<T extends Row = Record<string, any>>(
203
200
  strings: TemplateStringsArray,
204
201
  ...params: Param[]
@@ -207,7 +204,7 @@ class BaseQueryExecutor {
207
204
  return this.all<T>(sql, args, undefined);
208
205
  }
209
206
 
210
- /** {@link rawQuery}, returning every row. */
207
+ /** Runs a raw query (like {@link rawQuery}) and collects all rows into an array. */
211
208
  async rawQueryAll<T extends Row = Record<string, any>>(
212
209
  sql: string,
213
210
  params?: Record<string, Param>,
@@ -217,8 +214,9 @@ class BaseQueryExecutor {
217
214
  }
218
215
 
219
216
  /**
220
- * {@link query}, returning its one row: `null` if there is none, and a
221
- * {@link TooManyRowsError} if there is more than one.
217
+ * Runs a tagged-template query (like {@link query}) expecting at most one
218
+ * row. Returns `null` if no rows match, or throws {@link TooManyRowsError}
219
+ * if more than one row is returned.
222
220
  */
223
221
  async queryRow<T extends Row = Record<string, any>>(
224
222
  strings: TemplateStringsArray,
@@ -229,8 +227,9 @@ class BaseQueryExecutor {
229
227
  }
230
228
 
231
229
  /**
232
- * {@link rawQuery}, returning its one row: `null` if there is none, and a
233
- * {@link TooManyRowsError} if there is more than one.
230
+ * Runs a raw query (like {@link rawQuery}) expecting at most one row.
231
+ * Returns `null` if no rows match, or throws {@link TooManyRowsError} if
232
+ * more than one row is returned.
234
233
  */
235
234
  async rawQueryRow<T extends Row = Record<string, any>>(
236
235
  sql: string,
@@ -241,8 +240,8 @@ class BaseQueryExecutor {
241
240
  }
242
241
 
243
242
  /**
244
- * Runs a statement with a template string, binding each `${value}` as
245
- * {@link query} does, and discards any rows it returns.
243
+ * Executes a tagged-template statement (binding `${value}` placeholders like
244
+ * {@link query}) and discards any returned rows.
246
245
  *
247
246
  * @example
248
247
  * await db.exec`ALTER TABLE events DELETE WHERE user_id = ${id}`;
@@ -256,8 +255,8 @@ class BaseQueryExecutor {
256
255
  }
257
256
 
258
257
  /**
259
- * Runs a statement whose parameters it names, as {@link rawQuery} does,
260
- * and discards any rows it returns.
258
+ * Executes a raw statement with named typed parameters (like
259
+ * {@link rawQuery}) and discards any returned rows.
261
260
  */
262
261
  async rawExec(
263
262
  sql: string,
@@ -268,14 +267,13 @@ class BaseQueryExecutor {
268
267
  }
269
268
 
270
269
  /**
271
- * Inserts `rows` into `table` (`table`, or `database.table`). Each row is
272
- * an object, or a `Map`, keyed by column name. The columns are those the
273
- * rows have keys for; a row without one of them, or with it `undefined`,
274
- * leaves it out, so it gets the column's default. `null` is `NULL`, which
275
- * a column that isn't `Nullable` also takes as its default.
270
+ * Bulk-inserts `rows` into `table` (`table` or `database.table`). Each row
271
+ * is an object or `Map` keyed by column name. Omitted or `undefined` fields
272
+ * use the column's default; `null` inserts `NULL` (or the column default for
273
+ * non-`Nullable` columns).
276
274
  *
277
- * The rows travel as JSON: binary strings that aren't UTF-8 don't survive
278
- * it, so insert those with a parameterized `INSERT … VALUES`.
275
+ * Rows are serialized as JSON, so non-UTF-8 binary strings are not preserved
276
+ * — use a parameterized `INSERT ... VALUES` statement for binary data.
279
277
  *
280
278
  * @example
281
279
  * await db.insert('events', [
@@ -408,27 +406,26 @@ class BaseQueryExecutor {
408
406
  }
409
407
 
410
408
  /**
411
- * A query handle that can be passed to application/library code. Obtain one
412
- * with `read()`, `write()` or `admin()`. A `Database` declaration
413
- * deliberately does not implement this class.
409
+ * A scoped query handle safe to pass into application or library code. Obtain
410
+ * one with `read()`, `write()`, or `admin()`. {@link Database} deliberately
411
+ * does not extend `Queryable`.
414
412
  */
415
413
  export abstract class Queryable extends BaseQueryExecutor {
416
414
  private readonly queryableBrand = true;
417
415
  }
418
416
 
419
417
  /**
420
- * A handle to a database with one access level, which Encore's parser
421
- * records where it is made:
418
+ * A ClickHouse database handle scoped to a specific access level recorded by
419
+ * Encore's parser where it is created:
422
420
  *
423
- * - `read()`: `SELECT` and `SHOW`. Its writes are refused, by its user's
424
- * grants, or the `readonly` setting when the runtime config gives the read
425
- * level no user of its own.
426
- * - `write()`: reads, and `INSERT`, `ALTER … UPDATE/DELETE` and lightweight
421
+ * - `read()`: `SELECT` and `SHOW` only (writes are rejected by the user's
422
+ * grants or the `readonly` setting).
423
+ * - `write()`: reads plus `INSERT`, `ALTER ... UPDATE/DELETE`, and lightweight
427
424
  * `DELETE`.
428
- * - `admin()`: anything on the database: DDL, `TRUNCATE`, `OPTIMIZE`.
425
+ * - `admin()`: full access including DDL, `TRUNCATE`, and `OPTIMIZE`.
429
426
  *
430
- * Each level is its own ClickHouse user, so its connection string connects
431
- * with that level's grants.
427
+ * Each access level uses its own ClickHouse user, so `connectionString`
428
+ * connects with matching grants.
432
429
  */
433
430
  export class DatabaseRef extends Queryable {
434
431
  /** @internal */
@@ -438,13 +435,13 @@ export class DatabaseRef extends Queryable {
438
435
  }
439
436
 
440
437
  /**
441
- * A ClickHouse database. Constructing one makes Encore provision a database
442
- * with that name, run its migrations, and return this object to represent
443
- * it. Its own methods have write access; `read()`, `write()` and `admin()`
444
- * select a level.
438
+ * Declares a ClickHouse database. Encore provisions the database, runs its
439
+ * migrations, and returns this handle. Methods called directly on `Database`
440
+ * run with write access; call `read()`, `write()`, or `admin()` to obtain a
441
+ * handle with a specific access level.
445
442
  *
446
- * If you want to reference an existing database, use `Database.named(name)`,
447
- * as it is a compile error to create duplicate databases.
443
+ * To reference an existing database without declaring a duplicate, use
444
+ * {@link Database.named}.
448
445
  *
449
446
  * @example
450
447
  * import { Database } from "@encore.dev/sdk/storage/clickhouse";
@@ -467,24 +464,24 @@ export class Database extends BaseQueryExecutor {
467
464
  }
468
465
 
469
466
  /**
470
- * Reference an existing database by name. If the database doesn't exist
471
- * yet, use `new Database(name)` instead.
467
+ * References an existing ClickHouse database by name. Use
468
+ * `new Database(name)` to declare a new database.
472
469
  */
473
470
  static named<name extends string>(name: StringLiteral<name>): Database {
474
471
  return new Database(name);
475
472
  }
476
473
 
477
- /** Select read access: `SELECT` and `SHOW`. */
474
+ /** Returns a read-only handle (`SELECT` and `SHOW`). */
478
475
  read(): DatabaseRef {
479
476
  return this.ref(runtime.ClickHouseAccess.Read);
480
477
  }
481
478
 
482
- /** Select read and write access: also `INSERT` and mutations. */
479
+ /** Returns a read-write handle (`SELECT`, `INSERT`, and mutations). */
483
480
  write(): DatabaseRef {
484
481
  return this.ref(runtime.ClickHouseAccess.Write);
485
482
  }
486
483
 
487
- /** Select read, write and admin access: anything on the database. */
484
+ /** Returns an admin handle with full access (including DDL). */
488
485
  admin(): DatabaseRef {
489
486
  return this.ref(runtime.ClickHouseAccess.Admin);
490
487
  }
@@ -499,11 +496,7 @@ export class Database extends BaseQueryExecutor {
499
496
  }
500
497
  }
501
498
 
502
- /**
503
- * The handle of the database `name` in test mode, for each call: the current
504
- * test's instance of it, or the process's own outside any test, made on
505
- * first use.
506
- */
499
+ /** Resolves the ClickHouse handle for `name` in test mode (per-test or process fallback). */
507
500
  function testHandle(name: string): () => runtime.ClickHouseDatabase {
508
501
  let own: runtime.ClickHouseDatabase | undefined;
509
502
  return () =>
@@ -511,11 +504,7 @@ function testHandle(name: string): () => runtime.ClickHouseDatabase {
511
504
  (own ??= runtime.RT.clickhouseDatabase(name));
512
505
  }
513
506
 
514
- /**
515
- * A tagged template's SQL, each `${value}` a `{pN:Type}` placeholder, and its
516
- * parameters. The types are the native module's: the ones it infers from the
517
- * values it converts, or those {@link typed} gave them.
518
- */
507
+ /** Compiles a tagged template into SQL with `{pN:Type}` placeholders and bound native params. */
519
508
  function buildQuery(
520
509
  strings: TemplateStringsArray,
521
510
  params: Param[],
@@ -546,10 +535,7 @@ function namedParams(
546
535
  );
547
536
  }
548
537
 
549
- /**
550
- * `value` as the native module takes it: a `Decimal` as its text, bound as
551
- * `Decimal(76, s)`, in an array too.
552
- */
538
+ /** Converts `Decimal` values (including inside arrays) into explicit `Typed` values for the native layer. */
553
539
  function prepare(value: unknown): unknown {
554
540
  if (value instanceof Decimal) {
555
541
  const text = value.toString();
@@ -1,19 +1,19 @@
1
1
  /**
2
- * What kind of error a ClickHouse call failed with.
2
+ * Category of failure for a {@link DatabaseError}.
3
3
  *
4
- * - `server`: the server refused or failed the query; `code` and `codeName`
5
- * say why.
6
- * - `unavailable`: the server can't be reached, or the database isn't
7
- * configured for this process; the message says which.
4
+ * - `server`: ClickHouse rejected or failed the query (`code` and `codeName`
5
+ * contain the ClickHouse exception details).
6
+ * - `unavailable`: the server could not be reached, or the database is not
7
+ * configured for this process.
8
8
  * - `canceled`: the call was canceled.
9
- * - `decode`: a response the SDK couldn't decode, such as a column of a type
10
- * it doesn't read (`Dynamic`, `AggregateFunction`: cast it in the query).
11
- * - `invalid_argument`: an argument the call can't use, such as a parameter
12
- * value of no ClickHouse type or a bad table name.
13
- * - `too_many_rows`: `queryRow` or `rawQueryRow` got more than one row
9
+ * - `decode`: the SDK could not decode a response column (for example,
10
+ * unsupported types like `Dynamic` or `AggregateFunction` — cast them in SQL).
11
+ * - `invalid_argument`: invalid call argument, such as an unsupported parameter
12
+ * type or invalid table name.
13
+ * - `too_many_rows`: `queryRow` or `rawQueryRow` returned more than one row
14
14
  * ({@link TooManyRowsError}).
15
- * - `no_rows`: reserved for the other SDKs' one-row forms; `queryRow`
16
- * returns `null` for no rows instead.
15
+ * - `no_rows`: reserved for parity with other Encore SDKs (`queryRow` returns
16
+ * `null` when no rows match).
17
17
  */
18
18
  export type ErrorKind =
19
19
  | 'server'
@@ -25,12 +25,12 @@ export type ErrorKind =
25
25
  | 'too_many_rows';
26
26
 
27
27
  /**
28
- * An error of a ClickHouse call: the server's, or the SDK's own.
28
+ * Error returned when a ClickHouse operation fails (either on the server or in
29
+ * the SDK).
29
30
  *
30
- * A server error has ClickHouse's exception `code` (such as `60`) and its
31
- * name, `codeName` (such as `'UNKNOWN_TABLE'`); every other kind has `code`
32
- * `0` and `codeName` `''`. The name is `codeName` rather than `name`, which
33
- * every `Error` has for its class: `'DatabaseError'`.
31
+ * For `kind === 'server'`, `code` (e.g. `60`) and `codeName` (e.g.
32
+ * `'UNKNOWN_TABLE'`) hold the ClickHouse exception code and name; for all other
33
+ * kinds, `code` is `0` and `codeName` is `''`.
34
34
  *
35
35
  * @example
36
36
  * try {
@@ -44,11 +44,11 @@ export type ErrorKind =
44
44
  */
45
45
  export class DatabaseError extends Error {
46
46
  declare readonly name: 'DatabaseError' | 'TooManyRowsError';
47
- /** What kind of error it is. */
47
+ /** Category of error. */
48
48
  readonly kind: ErrorKind;
49
- /** ClickHouse's exception code, such as `60`: `0` for other kinds. */
49
+ /** ClickHouse exception code (e.g. `60`), or `0` for non-server errors. */
50
50
  readonly code: number;
51
- /** The exception code's name, such as `'UNKNOWN_TABLE'`: `''` for other kinds. */
51
+ /** ClickHouse exception name (e.g. `'UNKNOWN_TABLE'`), or `''` for non-server errors. */
52
52
  readonly codeName: string;
53
53
 
54
54
  constructor(fields: {
@@ -70,8 +70,8 @@ export class DatabaseError extends Error {
70
70
  }
71
71
 
72
72
  /**
73
- * Thrown by `queryRow` and `rawQueryRow` for a query that returns more than
74
- * one row: a {@link DatabaseError} of kind `too_many_rows`.
73
+ * Thrown by `queryRow` and `rawQueryRow` when a query returns more than one
74
+ * row. Subclass of {@link DatabaseError} with `kind === 'too_many_rows'`.
75
75
  */
76
76
  export class TooManyRowsError extends DatabaseError {
77
77
  declare readonly name: 'TooManyRowsError';
@@ -87,14 +87,12 @@ export class TooManyRowsError extends DatabaseError {
87
87
  }
88
88
 
89
89
  /**
90
- * Begins the message of an error the native module fails with for a
91
- * `DatabaseError`, which the rest of the message holds as JSON. The same as
92
- * `DATABASE_ERROR_PREFIX` in `sdk/ts/src/clickhouse.rs`.
90
+ * Prefix for JSON-encoded `DatabaseError` messages from the native module.
91
+ * Must match `DATABASE_ERROR_PREFIX` in `sdk/ts/src/clickhouse.rs`.
93
92
  */
94
93
  const DATABASE_ERROR_PREFIX = 'encore:clickhouse.DatabaseError:';
95
94
 
96
- /** Awaits a native call, throwing the error it rejects with as a
97
- * `DatabaseError` if it is one. */
95
+ /** Awaits a native call and converts encoded native errors into {@link DatabaseError}. */
98
96
  export async function native<T>(call: Promise<T>): Promise<T> {
99
97
  try {
100
98
  return await call;
@@ -103,7 +101,7 @@ export async function native<T>(call: Promise<T>): Promise<T> {
103
101
  }
104
102
  }
105
103
 
106
- /** Runs a synchronous native call, as {@link native} does an async one. */
104
+ /** Runs a synchronous native call and converts encoded native errors into {@link DatabaseError}. */
107
105
  export function nativeSync<T>(call: () => T): T {
108
106
  try {
109
107
  return call();
@@ -112,7 +110,7 @@ export function nativeSync<T>(call: () => T): T {
112
110
  }
113
111
  }
114
112
 
115
- /** `err`, a native call's, as a `DatabaseError` if it is one. */
113
+ /** Converts an encoded native error into a {@link DatabaseError}, passing other errors through. */
116
114
  export function fromNative(err: unknown): unknown {
117
115
  if (
118
116
  !(err instanceof Error) ||
@@ -1,7 +1,7 @@
1
1
  /**
2
- * ClickHouse databases. A database is declared at module scope, with the
3
- * directory of its migrations; Encore provisions it, runs them, and gives
4
- * each service the access its code uses.
2
+ * ClickHouse databases. Declare a database at module scope with its migrations
3
+ * directory; Encore provisions it, runs migrations, and grants each service
4
+ * the access level its code uses.
5
5
  *
6
6
  * ```ts
7
7
  * import { Database } from "@encore.dev/sdk/storage/clickhouse";
@@ -13,14 +13,14 @@
13
13
  * SELECT name, count() AS n FROM events WHERE at > ${since} GROUP BY name`;
14
14
  * ```
15
15
  *
16
- * Parameters are bound on the server, never spliced into the SQL: a tagged
17
- * template's `${value}` becomes `{p0:Type}` with the type inferred from the
18
- * value (or given with {@link typed}), and the `raw` forms take SQL that names
19
- * its parameters and their types, `{id:UInt64}`, with the values by name.
16
+ * Parameters are always bound on the server rather than interpolated into SQL:
17
+ * tagged-template `${value}` placeholders become `{p0:Type}` using the inferred
18
+ * ClickHouse type (override with {@link typed}), while the `raw*` methods take
19
+ * SQL with named typed placeholders (e.g. `{id:UInt64}`) and a params object.
20
20
  *
21
- * There are no transactions, and no sessions: each call is a request of its
22
- * own, so temporary tables and `SET` don't carry over to the next one. Use
23
- * the per-call `settings` option instead.
21
+ * ClickHouse calls are stateless — there are no transactions or sessions, so
22
+ * temporary tables and `SET` do not persist across calls. Pass per-query
23
+ * settings via {@link QueryOptions.settings} instead.
24
24
  *
25
25
  * @module
26
26
  */