@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.
- package/README.md +111 -101
- package/app_meta.ts +56 -54
- package/config/config.ts +60 -57
- package/config/secrets.ts +45 -52
- package/config/value.ts +23 -26
- package/cron/mod.ts +28 -29
- package/dist/app_meta.d.ts +52 -50
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +2 -2
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -55
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +8 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +45 -52
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +8 -9
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +20 -23
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +20 -23
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +26 -27
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -14
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +20 -19
- package/dist/frontends/mod.d.ts.map +1 -1
- package/dist/frontends/mod.js +20 -19
- package/dist/frontends/mod.js.map +1 -1
- package/dist/gateway/errors.d.ts +28 -30
- package/dist/gateway/errors.d.ts.map +1 -1
- package/dist/gateway/errors.js +29 -31
- package/dist/gateway/errors.js.map +1 -1
- package/dist/gateway/match.d.ts +54 -54
- package/dist/gateway/match.d.ts.map +1 -1
- package/dist/gateway/match.js +56 -56
- package/dist/gateway/match.js.map +1 -1
- package/dist/gateway/middleware.d.ts +62 -64
- package/dist/gateway/middleware.d.ts.map +1 -1
- package/dist/gateway/middleware.js +1 -1
- package/dist/gateway/middleware.js.map +1 -1
- package/dist/gateway/mod.d.ts +64 -67
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +72 -76
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateway/request.d.ts +138 -134
- package/dist/gateway/request.d.ts.map +1 -1
- package/dist/gateway/request.js +117 -108
- package/dist/gateway/request.js.map +1 -1
- package/dist/gateway/serve.d.ts +29 -34
- package/dist/gateway/serve.d.ts.map +1 -1
- package/dist/gateway/serve.js +51 -56
- package/dist/gateway/serve.js.map +1 -1
- package/dist/gateways/mod.d.ts +23 -21
- package/dist/gateways/mod.d.ts.map +1 -1
- package/dist/gateways/mod.js +25 -23
- package/dist/gateways/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +1 -1
- package/dist/internal/runtime/napi/napi.d.cts +10 -3
- package/dist/internal/runtime/shutdown.d.ts +75 -57
- package/dist/internal/runtime/shutdown.d.ts.map +1 -1
- package/dist/internal/runtime/shutdown.js +88 -84
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/log/logger.d.ts +43 -37
- package/dist/log/logger.d.ts.map +1 -1
- package/dist/log/logger.js +26 -25
- package/dist/log/logger.js.map +1 -1
- package/dist/metrics/mod.d.ts +133 -114
- package/dist/metrics/mod.d.ts.map +1 -1
- package/dist/metrics/mod.js +109 -101
- package/dist/metrics/mod.js.map +1 -1
- package/dist/otel.d.ts +6 -3
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +6 -3
- package/dist/otel.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +88 -116
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js +14 -17
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +86 -113
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +68 -82
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +83 -86
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +39 -41
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +76 -75
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +73 -71
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +26 -25
- package/dist/shutdown/mod.d.ts.map +1 -1
- package/dist/shutdown/mod.js +26 -25
- package/dist/shutdown/mod.js.map +1 -1
- package/dist/storage/clickhouse/database.d.ts +113 -115
- package/dist/storage/clickhouse/database.d.ts.map +1 -1
- package/dist/storage/clickhouse/database.js +65 -79
- package/dist/storage/clickhouse/database.js.map +1 -1
- package/dist/storage/clickhouse/errors.d.ts +25 -26
- package/dist/storage/clickhouse/errors.d.ts.map +1 -1
- package/dist/storage/clickhouse/errors.js +15 -17
- package/dist/storage/clickhouse/errors.js.map +1 -1
- package/dist/storage/clickhouse/mod.d.ts +10 -10
- package/dist/storage/clickhouse/mod.js +10 -10
- package/dist/storage/objects/bucket.d.ts +196 -225
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +71 -84
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +4 -4
- package/dist/storage/objects/error.js +4 -4
- package/dist/storage/postgres/database.d.ts +124 -149
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +98 -135
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +42 -48
- package/dist/storage/postgres/errors.d.ts.map +1 -1
- package/dist/storage/postgres/errors.js +44 -51
- package/dist/storage/postgres/errors.js.map +1 -1
- package/dist/storage/postgres/interval.d.ts +19 -19
- package/dist/storage/postgres/interval.d.ts.map +1 -1
- package/dist/storage/postgres/interval.js +21 -21
- package/dist/storage/postgres/interval.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +48 -23
- package/dist/storage/redis/bitfield.d.ts.map +1 -1
- package/dist/storage/redis/bitfield.js +38 -19
- package/dist/storage/redis/bitfield.js.map +1 -1
- package/dist/storage/redis/command.d.ts +16 -12
- package/dist/storage/redis/command.d.ts.map +1 -1
- package/dist/storage/redis/command.js +16 -12
- package/dist/storage/redis/command.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +99 -100
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +84 -85
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +138 -122
- package/dist/storage/redis/database.d.ts.map +1 -1
- package/dist/storage/redis/database.js +120 -101
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +52 -48
- package/dist/storage/redis/mod.d.ts.map +1 -1
- package/dist/storage/redis/mod.js +52 -48
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/options.d.ts +26 -24
- package/dist/storage/redis/options.d.ts.map +1 -1
- package/dist/storage/redis/options.js.map +1 -1
- package/dist/storage/redis/pubsub.d.ts +16 -16
- package/dist/storage/redis/pubsub.d.ts.map +1 -1
- package/dist/storage/redis/pubsub.js +14 -14
- package/dist/storage/redis/pubsub.js.map +1 -1
- package/dist/storage/redis/reply.d.ts +80 -72
- package/dist/storage/redis/reply.d.ts.map +1 -1
- package/dist/storage/redis/reply.js +53 -46
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +4 -4
- package/dist/storage/redis/scan.d.ts.map +1 -1
- package/dist/storage/redis/scan.js +6 -6
- package/dist/storage/redis/scan.js.map +1 -1
- package/dist/storage/redis/script.d.ts +28 -21
- package/dist/storage/redis/script.d.ts.map +1 -1
- package/dist/storage/redis/script.js +29 -22
- package/dist/storage/redis/script.js.map +1 -1
- package/dist/storage/redis/target.d.ts +17 -1
- package/dist/storage/redis/target.d.ts.map +1 -1
- package/dist/storage/redis/target.js +30 -1
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +6 -6
- package/dist/storage/redis/wire.d.ts.map +1 -1
- package/dist/storage/redis/wire.js +6 -6
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/mod.d.ts +83 -88
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +75 -81
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +28 -32
- package/dist/testing/playwright.d.ts.map +1 -1
- package/dist/testing/playwright.js +22 -27
- package/dist/testing/playwright.js.map +1 -1
- package/dist/testing/puppeteer.d.ts +11 -12
- package/dist/testing/puppeteer.d.ts.map +1 -1
- package/dist/testing/puppeteer.js +17 -18
- package/dist/testing/puppeteer.js.map +1 -1
- package/dist/testing/system.d.ts +72 -90
- package/dist/testing/system.d.ts.map +1 -1
- package/dist/testing/system.js +90 -107
- package/dist/testing/system.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +6 -2
- package/frontends/mod.ts +20 -19
- package/gateway/errors.ts +30 -32
- package/gateway/match.ts +61 -57
- package/gateway/middleware.ts +62 -64
- package/gateway/mod.ts +73 -76
- package/gateway/request.ts +143 -140
- package/gateway/serve.ts +58 -63
- package/gateways/mod.ts +25 -23
- package/internal/runtime/napi/napi.cjs +1 -1
- package/internal/runtime/napi/napi.d.cts +10 -3
- package/internal/runtime/shutdown.ts +113 -101
- package/log/logger.test.ts +8 -0
- package/log/logger.ts +48 -45
- package/metrics/mod.ts +138 -122
- package/otel.ts +6 -3
- package/package.json +1 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/reqctx/mod.ts +83 -86
- package/services/index.ts +78 -78
- package/shutdown/mod.ts +26 -25
- package/storage/clickhouse/database.ts +115 -129
- package/storage/clickhouse/errors.ts +27 -29
- package/storage/clickhouse/mod.ts +10 -10
- package/storage/objects/bucket.ts +209 -239
- package/storage/objects/error.ts +4 -4
- package/storage/postgres/database.ts +131 -164
- package/storage/postgres/errors.ts +45 -52
- package/storage/postgres/interval.ts +21 -21
- package/storage/redis/bitfield.ts +51 -26
- package/storage/redis/command.ts +16 -12
- package/storage/redis/commands.ts +99 -100
- package/storage/redis/database.ts +145 -123
- package/storage/redis/mod.ts +52 -48
- package/storage/redis/options.ts +26 -24
- package/storage/redis/pubsub.ts +14 -14
- package/storage/redis/redis.test.ts +17 -2
- package/storage/redis/reply.ts +85 -77
- package/storage/redis/scan.ts +6 -6
- package/storage/redis/script.ts +29 -22
- package/storage/redis/target.ts +34 -1
- package/storage/redis/wire.ts +8 -8
- package/testing/mod.ts +99 -105
- package/testing/playwright.ts +32 -37
- package/testing/puppeteer.ts +22 -23
- package/testing/system.ts +117 -133
|
@@ -3,20 +3,20 @@ import * as runtime from '../../internal/runtime/mod.js';
|
|
|
3
3
|
import { currentScope, testMode } from '../../internal/testing/scope.js';
|
|
4
4
|
import { Decimal } from '../../types/mod.js';
|
|
5
5
|
import { native, nativeSync, TooManyRowsError } from './errors.js';
|
|
6
|
-
/**
|
|
7
|
-
* prototype, so a parameter that is an object of data is never taken for one. */
|
|
6
|
+
/** Prototype marker used by the native module to identify {@link Typed} wrappers. */
|
|
8
7
|
const TYPED_MARKER = '__encore_clickhouse_type';
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
9
|
+
* Wraps a query parameter value with an explicit ClickHouse type (see
|
|
10
|
+
* {@link typed}).
|
|
11
11
|
*/
|
|
12
12
|
export class Typed {
|
|
13
13
|
value;
|
|
14
14
|
type;
|
|
15
15
|
/** @internal */
|
|
16
16
|
constructor(
|
|
17
|
-
/** The value. */
|
|
17
|
+
/** The parameter value. */
|
|
18
18
|
value,
|
|
19
|
-
/**
|
|
19
|
+
/** Explicit ClickHouse type name (e.g. `'UUID'` or `'Array(UInt32)'`). */
|
|
20
20
|
type) {
|
|
21
21
|
this.value = value;
|
|
22
22
|
this.type = type;
|
|
@@ -24,10 +24,10 @@ export class Typed {
|
|
|
24
24
|
}
|
|
25
25
|
Object.defineProperty(Typed.prototype, TYPED_MARKER, { value: true });
|
|
26
26
|
/**
|
|
27
|
-
* Binds `value` as the ClickHouse type `type`
|
|
28
|
-
*
|
|
29
|
-
* `{p0:UUID}
|
|
30
|
-
* `Date` or `Date32
|
|
27
|
+
* Binds `value` as the explicit ClickHouse type `type` instead of inferring
|
|
28
|
+
* one in tagged-template queries (e.g. `` ${typed(id, 'UUID')} `` emits
|
|
29
|
+
* `{p0:UUID}`). A `Date` bound as `DateTime` truncates to whole seconds; bound
|
|
30
|
+
* as `Date` or `Date32`, it uses the UTC calendar date.
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* await db.queryAll`SELECT * FROM events WHERE user_id = ${typed(userId, 'UUID')}`;
|
|
@@ -35,7 +35,7 @@ Object.defineProperty(Typed.prototype, TYPED_MARKER, { value: true });
|
|
|
35
35
|
export function typed(value, type) {
|
|
36
36
|
return new Typed(value, type);
|
|
37
37
|
}
|
|
38
|
-
/** Base class
|
|
38
|
+
/** Base class providing shared ClickHouse query and execution methods. */
|
|
39
39
|
class BaseQueryExecutor {
|
|
40
40
|
handle;
|
|
41
41
|
access;
|
|
@@ -44,71 +44,70 @@ class BaseQueryExecutor {
|
|
|
44
44
|
this.handle = handle;
|
|
45
45
|
this.access = access;
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
47
|
+
/** Native database handle (resolves to the current test's instance in test mode). */
|
|
48
48
|
get impl() {
|
|
49
49
|
return typeof this.handle === 'function' ? this.handle() : this.handle;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
52
|
+
* HTTP connection string (`http://user:password@host:port/database`) scoped
|
|
53
|
+
* to this handle's access level, compatible with `@clickhouse/client`'s `url`
|
|
54
|
+
* option.
|
|
55
55
|
*/
|
|
56
56
|
get connectionString() {
|
|
57
57
|
return nativeSync(() => this.impl.connectionString(this.access));
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* `` query`SELECT * FROM events WHERE id = ${id}` ``
|
|
63
|
-
* events WHERE id = {p0:Int64}`.
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* It streams the rows: iterate it with `for await`.
|
|
60
|
+
* Streams rows from a tagged-template query, binding each `${value}` as a
|
|
61
|
+
* typed server parameter (see {@link Param}). For example,
|
|
62
|
+
* `` query`SELECT * FROM events WHERE id = ${id}` `` sends
|
|
63
|
+
* `SELECT * FROM events WHERE id = {p0:Int64}`. Use {@link typed} to
|
|
64
|
+
* override the inferred type. Iterate results with `for await`.
|
|
67
65
|
*/
|
|
68
66
|
async *query(strings, ...params) {
|
|
69
67
|
const { sql, args } = buildQuery(strings, params);
|
|
70
68
|
yield* this.rows(sql, args, undefined);
|
|
71
69
|
}
|
|
72
70
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
71
|
+
* Streams rows from a raw SQL query with named typed placeholders (such as
|
|
72
|
+
* `{id:UInt64}`) and matching entries in `params`. Iterate results with
|
|
73
|
+
* `for await`.
|
|
75
74
|
*
|
|
76
75
|
* ```ts
|
|
77
76
|
* db.rawQuery('SELECT * FROM events WHERE id = {id:UInt64}', {id: 5});
|
|
78
77
|
* ```
|
|
79
|
-
*
|
|
80
|
-
* It streams the rows: iterate it with `for await`.
|
|
81
78
|
*/
|
|
82
79
|
async *rawQuery(sql, params, options) {
|
|
83
80
|
yield* this.rows(sql, namedParams(params), options);
|
|
84
81
|
}
|
|
85
|
-
/** {@link query}
|
|
82
|
+
/** Runs a tagged-template query (like {@link query}) and collects all rows into an array. */
|
|
86
83
|
async queryAll(strings, ...params) {
|
|
87
84
|
const { sql, args } = buildQuery(strings, params);
|
|
88
85
|
return this.all(sql, args, undefined);
|
|
89
86
|
}
|
|
90
|
-
/** {@link rawQuery}
|
|
87
|
+
/** Runs a raw query (like {@link rawQuery}) and collects all rows into an array. */
|
|
91
88
|
async rawQueryAll(sql, params, options) {
|
|
92
89
|
return this.all(sql, namedParams(params), options);
|
|
93
90
|
}
|
|
94
91
|
/**
|
|
95
|
-
* {@link query}
|
|
96
|
-
*
|
|
92
|
+
* Runs a tagged-template query (like {@link query}) expecting at most one
|
|
93
|
+
* row. Returns `null` if no rows match, or throws {@link TooManyRowsError}
|
|
94
|
+
* if more than one row is returned.
|
|
97
95
|
*/
|
|
98
96
|
async queryRow(strings, ...params) {
|
|
99
97
|
const { sql, args } = buildQuery(strings, params);
|
|
100
98
|
return this.one(sql, args, undefined);
|
|
101
99
|
}
|
|
102
100
|
/**
|
|
103
|
-
* {@link rawQuery}
|
|
104
|
-
* {@link TooManyRowsError} if
|
|
101
|
+
* Runs a raw query (like {@link rawQuery}) expecting at most one row.
|
|
102
|
+
* Returns `null` if no rows match, or throws {@link TooManyRowsError} if
|
|
103
|
+
* more than one row is returned.
|
|
105
104
|
*/
|
|
106
105
|
async rawQueryRow(sql, params, options) {
|
|
107
106
|
return this.one(sql, namedParams(params), options);
|
|
108
107
|
}
|
|
109
108
|
/**
|
|
110
|
-
*
|
|
111
|
-
* {@link query}
|
|
109
|
+
* Executes a tagged-template statement (binding `${value}` placeholders like
|
|
110
|
+
* {@link query}) and discards any returned rows.
|
|
112
111
|
*
|
|
113
112
|
* @example
|
|
114
113
|
* await db.exec`ALTER TABLE events DELETE WHERE user_id = ${id}`;
|
|
@@ -118,21 +117,20 @@ class BaseQueryExecutor {
|
|
|
118
117
|
return this.run(sql, args, undefined);
|
|
119
118
|
}
|
|
120
119
|
/**
|
|
121
|
-
*
|
|
122
|
-
* and discards any rows
|
|
120
|
+
* Executes a raw statement with named typed parameters (like
|
|
121
|
+
* {@link rawQuery}) and discards any returned rows.
|
|
123
122
|
*/
|
|
124
123
|
async rawExec(sql, params, options) {
|
|
125
124
|
return this.run(sql, namedParams(params), options);
|
|
126
125
|
}
|
|
127
126
|
/**
|
|
128
|
-
*
|
|
129
|
-
* an object
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* a column that isn't `Nullable` also takes as its default.
|
|
127
|
+
* Bulk-inserts `rows` into `table` (`table` or `database.table`). Each row
|
|
128
|
+
* is an object or `Map` keyed by column name. Omitted or `undefined` fields
|
|
129
|
+
* use the column's default; `null` inserts `NULL` (or the column default for
|
|
130
|
+
* non-`Nullable` columns).
|
|
133
131
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
132
|
+
* Rows are serialized as JSON, so non-UTF-8 binary strings are not preserved
|
|
133
|
+
* — use a parameterized `INSERT ... VALUES` statement for binary data.
|
|
136
134
|
*
|
|
137
135
|
* @example
|
|
138
136
|
* await db.insert('events', [
|
|
@@ -211,26 +209,25 @@ class BaseQueryExecutor {
|
|
|
211
209
|
}
|
|
212
210
|
}
|
|
213
211
|
/**
|
|
214
|
-
* A query handle
|
|
215
|
-
* with `read()`, `write()
|
|
216
|
-
*
|
|
212
|
+
* A scoped query handle safe to pass into application or library code. Obtain
|
|
213
|
+
* one with `read()`, `write()`, or `admin()`. {@link Database} deliberately
|
|
214
|
+
* does not extend `Queryable`.
|
|
217
215
|
*/
|
|
218
216
|
export class Queryable extends BaseQueryExecutor {
|
|
219
217
|
queryableBrand = true;
|
|
220
218
|
}
|
|
221
219
|
/**
|
|
222
|
-
* A handle to a
|
|
223
|
-
*
|
|
220
|
+
* A ClickHouse database handle scoped to a specific access level recorded by
|
|
221
|
+
* Encore's parser where it is created:
|
|
224
222
|
*
|
|
225
|
-
* - `read()`: `SELECT` and `SHOW
|
|
226
|
-
* grants
|
|
227
|
-
*
|
|
228
|
-
* - `write()`: reads, and `INSERT`, `ALTER … UPDATE/DELETE` and lightweight
|
|
223
|
+
* - `read()`: `SELECT` and `SHOW` only (writes are rejected by the user's
|
|
224
|
+
* grants or the `readonly` setting).
|
|
225
|
+
* - `write()`: reads plus `INSERT`, `ALTER ... UPDATE/DELETE`, and lightweight
|
|
229
226
|
* `DELETE`.
|
|
230
|
-
* - `admin()`:
|
|
227
|
+
* - `admin()`: full access including DDL, `TRUNCATE`, and `OPTIMIZE`.
|
|
231
228
|
*
|
|
232
|
-
* Each level
|
|
233
|
-
* with
|
|
229
|
+
* Each access level uses its own ClickHouse user, so `connectionString`
|
|
230
|
+
* connects with matching grants.
|
|
234
231
|
*/
|
|
235
232
|
export class DatabaseRef extends Queryable {
|
|
236
233
|
/** @internal */
|
|
@@ -239,13 +236,13 @@ export class DatabaseRef extends Queryable {
|
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
238
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
239
|
+
* Declares a ClickHouse database. Encore provisions the database, runs its
|
|
240
|
+
* migrations, and returns this handle. Methods called directly on `Database`
|
|
241
|
+
* run with write access; call `read()`, `write()`, or `admin()` to obtain a
|
|
242
|
+
* handle with a specific access level.
|
|
246
243
|
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
244
|
+
* To reference an existing database without declaring a duplicate, use
|
|
245
|
+
* {@link Database.named}.
|
|
249
246
|
*
|
|
250
247
|
* @example
|
|
251
248
|
* import { Database } from "@encore.dev/sdk/storage/clickhouse";
|
|
@@ -266,21 +263,21 @@ export class Database extends BaseQueryExecutor {
|
|
|
266
263
|
this.handles = handle;
|
|
267
264
|
}
|
|
268
265
|
/**
|
|
269
|
-
*
|
|
270
|
-
*
|
|
266
|
+
* References an existing ClickHouse database by name. Use
|
|
267
|
+
* `new Database(name)` to declare a new database.
|
|
271
268
|
*/
|
|
272
269
|
static named(name) {
|
|
273
270
|
return new Database(name);
|
|
274
271
|
}
|
|
275
|
-
/**
|
|
272
|
+
/** Returns a read-only handle (`SELECT` and `SHOW`). */
|
|
276
273
|
read() {
|
|
277
274
|
return this.ref(runtime.ClickHouseAccess.Read);
|
|
278
275
|
}
|
|
279
|
-
/**
|
|
276
|
+
/** Returns a read-write handle (`SELECT`, `INSERT`, and mutations). */
|
|
280
277
|
write() {
|
|
281
278
|
return this.ref(runtime.ClickHouseAccess.Write);
|
|
282
279
|
}
|
|
283
|
-
/**
|
|
280
|
+
/** Returns an admin handle with full access (including DDL). */
|
|
284
281
|
admin() {
|
|
285
282
|
return this.ref(runtime.ClickHouseAccess.Admin);
|
|
286
283
|
}
|
|
@@ -293,21 +290,13 @@ export class Database extends BaseQueryExecutor {
|
|
|
293
290
|
return ref;
|
|
294
291
|
}
|
|
295
292
|
}
|
|
296
|
-
/**
|
|
297
|
-
* The handle of the database `name` in test mode, for each call: the current
|
|
298
|
-
* test's instance of it, or the process's own outside any test, made on
|
|
299
|
-
* first use.
|
|
300
|
-
*/
|
|
293
|
+
/** Resolves the ClickHouse handle for `name` in test mode (per-test or process fallback). */
|
|
301
294
|
function testHandle(name) {
|
|
302
295
|
let own;
|
|
303
296
|
return () => currentScope()?.clickhouseDatabase(name) ??
|
|
304
297
|
(own ??= runtime.RT.clickhouseDatabase(name));
|
|
305
298
|
}
|
|
306
|
-
/**
|
|
307
|
-
* A tagged template's SQL, each `${value}` a `{pN:Type}` placeholder, and its
|
|
308
|
-
* parameters. The types are the native module's: the ones it infers from the
|
|
309
|
-
* values it converts, or those {@link typed} gave them.
|
|
310
|
-
*/
|
|
299
|
+
/** Compiles a tagged template into SQL with `{pN:Type}` placeholders and bound native params. */
|
|
311
300
|
function buildQuery(strings, params) {
|
|
312
301
|
const names = params.map((_, i) => `p${i}`);
|
|
313
302
|
const args = nativeSync(() => new runtime.ClickHouseParams(names, params.map(prepare)));
|
|
@@ -324,10 +313,7 @@ function namedParams(params) {
|
|
|
324
313
|
const entries = Object.entries(params ?? {});
|
|
325
314
|
return nativeSync(() => new runtime.ClickHouseParams(entries.map(([name]) => name), entries.map(([, value]) => prepare(value))));
|
|
326
315
|
}
|
|
327
|
-
/**
|
|
328
|
-
* `value` as the native module takes it: a `Decimal` as its text, bound as
|
|
329
|
-
* `Decimal(76, s)`, in an array too.
|
|
330
|
-
*/
|
|
316
|
+
/** Converts `Decimal` values (including inside arrays) into explicit `Typed` values for the native layer. */
|
|
331
317
|
function prepare(value) {
|
|
332
318
|
if (value instanceof Decimal) {
|
|
333
319
|
const text = value.toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../storage/clickhouse/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAA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,CAAC;AAED,SAAS,UAAU,CAAC,CAA4B;IAC9C,OAAO;QACL,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,YAAY,EAAE,CAAC,CAAC,YAAY;QAC5B,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,OAAO,EAAE,CAAC,CAAC,OAAO;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Category of failure for a {@link DatabaseError}.
|
|
3
3
|
*
|
|
4
|
-
* - `server`:
|
|
5
|
-
*
|
|
6
|
-
* - `unavailable`: the server
|
|
7
|
-
* configured for this process
|
|
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`:
|
|
10
|
-
*
|
|
11
|
-
* - `invalid_argument`:
|
|
12
|
-
*
|
|
13
|
-
* - `too_many_rows`: `queryRow` or `rawQueryRow`
|
|
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
|
|
16
|
-
*
|
|
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 = 'server' | 'unavailable' | 'canceled' | 'decode' | 'invalid_argument' | 'no_rows' | 'too_many_rows';
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Error returned when a ClickHouse operation fails (either on the server or in
|
|
21
|
+
* the SDK).
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* `0` and `codeName` `''`.
|
|
25
|
-
* every `Error` has for its class: `'DatabaseError'`.
|
|
23
|
+
* For `kind === 'server'`, `code` (e.g. `60`) and `codeName` (e.g.
|
|
24
|
+
* `'UNKNOWN_TABLE'`) hold the ClickHouse exception code and name; for all other
|
|
25
|
+
* kinds, `code` is `0` and `codeName` is `''`.
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
28
|
* try {
|
|
@@ -36,11 +36,11 @@ export type ErrorKind = 'server' | 'unavailable' | 'canceled' | 'decode' | 'inva
|
|
|
36
36
|
*/
|
|
37
37
|
export declare class DatabaseError extends Error {
|
|
38
38
|
readonly name: 'DatabaseError' | 'TooManyRowsError';
|
|
39
|
-
/**
|
|
39
|
+
/** Category of error. */
|
|
40
40
|
readonly kind: ErrorKind;
|
|
41
|
-
/** ClickHouse
|
|
41
|
+
/** ClickHouse exception code (e.g. `60`), or `0` for non-server errors. */
|
|
42
42
|
readonly code: number;
|
|
43
|
-
/**
|
|
43
|
+
/** ClickHouse exception name (e.g. `'UNKNOWN_TABLE'`), or `''` for non-server errors. */
|
|
44
44
|
readonly codeName: string;
|
|
45
45
|
constructor(fields: {
|
|
46
46
|
message: string;
|
|
@@ -50,18 +50,17 @@ export declare class DatabaseError extends Error {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Thrown by `queryRow` and `rawQueryRow`
|
|
54
|
-
*
|
|
53
|
+
* Thrown by `queryRow` and `rawQueryRow` when a query returns more than one
|
|
54
|
+
* row. Subclass of {@link DatabaseError} with `kind === 'too_many_rows'`.
|
|
55
55
|
*/
|
|
56
56
|
export declare class TooManyRowsError extends DatabaseError {
|
|
57
57
|
readonly name: 'TooManyRowsError';
|
|
58
58
|
constructor();
|
|
59
59
|
}
|
|
60
|
-
/** Awaits a native call
|
|
61
|
-
* `DatabaseError` if it is one. */
|
|
60
|
+
/** Awaits a native call and converts encoded native errors into {@link DatabaseError}. */
|
|
62
61
|
export declare function native<T>(call: Promise<T>): Promise<T>;
|
|
63
|
-
/** Runs a synchronous native call
|
|
62
|
+
/** Runs a synchronous native call and converts encoded native errors into {@link DatabaseError}. */
|
|
64
63
|
export declare function nativeSync<T>(call: () => T): T;
|
|
65
|
-
/**
|
|
64
|
+
/** Converts an encoded native error into a {@link DatabaseError}, passing other errors through. */
|
|
66
65
|
export declare function fromNative(err: unknown): unknown;
|
|
67
66
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../storage/clickhouse/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,aAAa,GACb,UAAU,GACV,QAAQ,GACR,kBAAkB,GAClB,SAAS,GACT,eAAe,CAAC;AAEpB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAiB,IAAI,EAAE,eAAe,GAAG,kBAAkB,CAAC;IAC5D,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../storage/clickhouse/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,aAAa,GACb,UAAU,GACV,QAAQ,GACR,kBAAkB,GAClB,SAAS,GACT,eAAe,CAAC;AAEpB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAiB,IAAI,EAAE,eAAe,GAAG,kBAAkB,CAAC;IAC5D,yBAAyB;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,MAAM,EAAE;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,SAAS,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;CAWF;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,SAAiB,IAAI,EAAE,kBAAkB,CAAC;;CAU3C;AAQD,0FAA0F;AAC1F,wBAAsB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAM5D;AAED,oGAAoG;AACpG,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAM9C;AAED,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAchD"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Error returned when a ClickHouse operation fails (either on the server or in
|
|
3
|
+
* the SDK).
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `0` and `codeName` `''`.
|
|
7
|
-
* every `Error` has for its class: `'DatabaseError'`.
|
|
5
|
+
* For `kind === 'server'`, `code` (e.g. `60`) and `codeName` (e.g.
|
|
6
|
+
* `'UNKNOWN_TABLE'`) hold the ClickHouse exception code and name; for all other
|
|
7
|
+
* kinds, `code` is `0` and `codeName` is `''`.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* try {
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
* }
|
|
18
18
|
*/
|
|
19
19
|
export class DatabaseError extends Error {
|
|
20
|
-
/**
|
|
20
|
+
/** Category of error. */
|
|
21
21
|
kind;
|
|
22
|
-
/** ClickHouse
|
|
22
|
+
/** ClickHouse exception code (e.g. `60`), or `0` for non-server errors. */
|
|
23
23
|
code;
|
|
24
|
-
/**
|
|
24
|
+
/** ClickHouse exception name (e.g. `'UNKNOWN_TABLE'`), or `''` for non-server errors. */
|
|
25
25
|
codeName;
|
|
26
26
|
constructor(fields) {
|
|
27
27
|
super(fields.message);
|
|
@@ -36,8 +36,8 @@ export class DatabaseError extends Error {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* Thrown by `queryRow` and `rawQueryRow`
|
|
40
|
-
*
|
|
39
|
+
* Thrown by `queryRow` and `rawQueryRow` when a query returns more than one
|
|
40
|
+
* row. Subclass of {@link DatabaseError} with `kind === 'too_many_rows'`.
|
|
41
41
|
*/
|
|
42
42
|
export class TooManyRowsError extends DatabaseError {
|
|
43
43
|
constructor() {
|
|
@@ -50,13 +50,11 @@ export class TooManyRowsError extends DatabaseError {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* `DATABASE_ERROR_PREFIX` in `sdk/ts/src/clickhouse.rs`.
|
|
53
|
+
* Prefix for JSON-encoded `DatabaseError` messages from the native module.
|
|
54
|
+
* Must match `DATABASE_ERROR_PREFIX` in `sdk/ts/src/clickhouse.rs`.
|
|
56
55
|
*/
|
|
57
56
|
const DATABASE_ERROR_PREFIX = 'encore:clickhouse.DatabaseError:';
|
|
58
|
-
/** Awaits a native call
|
|
59
|
-
* `DatabaseError` if it is one. */
|
|
57
|
+
/** Awaits a native call and converts encoded native errors into {@link DatabaseError}. */
|
|
60
58
|
export async function native(call) {
|
|
61
59
|
try {
|
|
62
60
|
return await call;
|
|
@@ -65,7 +63,7 @@ export async function native(call) {
|
|
|
65
63
|
throw fromNative(err);
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
|
-
/** Runs a synchronous native call
|
|
66
|
+
/** Runs a synchronous native call and converts encoded native errors into {@link DatabaseError}. */
|
|
69
67
|
export function nativeSync(call) {
|
|
70
68
|
try {
|
|
71
69
|
return call();
|
|
@@ -74,7 +72,7 @@ export function nativeSync(call) {
|
|
|
74
72
|
throw fromNative(err);
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
|
-
/**
|
|
75
|
+
/** Converts an encoded native error into a {@link DatabaseError}, passing other errors through. */
|
|
78
76
|
export function fromNative(err) {
|
|
79
77
|
if (!(err instanceof Error) ||
|
|
80
78
|
!err.message.startsWith(DATABASE_ERROR_PREFIX)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../storage/clickhouse/errors.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAEtC,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../storage/clickhouse/errors.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAEtC,yBAAyB;IAChB,IAAI,CAAY;IACzB,2EAA2E;IAClE,IAAI,CAAS;IACtB,yFAAyF;IAChF,QAAQ,CAAS;IAE1B,YAAY,MAKX;QACC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE;YAClC,KAAK,EAAE,eAAe;YACtB,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;IACxC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IAGjD;QACE,KAAK,CAAC,EAAC,OAAO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|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ClickHouse databases.
|
|
3
|
-
* directory
|
|
4
|
-
*
|
|
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
|
|
17
|
-
* template
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ClickHouse databases.
|
|
3
|
-
* directory
|
|
4
|
-
*
|
|
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
|
|
17
|
-
* template
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
|
*/
|