@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.16
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
|
@@ -16,26 +16,22 @@ function batchReplies(values) {
|
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
17
17
|
export class ReadOnlyDatabaseRef {
|
|
18
18
|
t;
|
|
19
|
-
primary;
|
|
20
19
|
/** @internal */
|
|
21
|
-
constructor(t, groups
|
|
22
|
-
/**
|
|
23
|
-
* The runtime gives a database one pool for now, on the primary, which
|
|
24
|
-
* every handle shares.
|
|
25
|
-
*/
|
|
26
|
-
primary) {
|
|
20
|
+
constructor(t, groups) {
|
|
27
21
|
this.t = t;
|
|
28
|
-
this.primary = primary;
|
|
29
22
|
Object.assign(this, groups);
|
|
30
23
|
}
|
|
31
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Prepares an invocation of `script`, which must have been created with
|
|
26
|
+
* {@link Script.readOnly}.
|
|
27
|
+
*/
|
|
32
28
|
script(script) {
|
|
33
29
|
return new Invocation(this.t, script, true);
|
|
34
30
|
}
|
|
35
31
|
/**
|
|
36
|
-
*
|
|
37
|
-
* {@link DatabaseRef.command}
|
|
38
|
-
*
|
|
32
|
+
* Prepares an arbitrary Redis command that is not covered by the typed
|
|
33
|
+
* command groups, as described in {@link DatabaseRef.command}. Only commands
|
|
34
|
+
* that Redis marks as read-only are allowed.
|
|
39
35
|
*/
|
|
40
36
|
command(name) {
|
|
41
37
|
return new CommandInvocation(this.t, rawCommand(name, true));
|
|
@@ -56,9 +52,9 @@ export class DatabaseRef {
|
|
|
56
52
|
Object.assign(this, groups);
|
|
57
53
|
}
|
|
58
54
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* the rest.
|
|
55
|
+
* Creates a pipeline that sends a batch of commands in a single round trip.
|
|
56
|
+
* A pipeline is not a transaction: commands from other clients may run
|
|
57
|
+
* between queued commands, and one failing command does not stop the rest.
|
|
62
58
|
*
|
|
63
59
|
* ```ts
|
|
64
60
|
* const pipe = SESSIONS.pipeline();
|
|
@@ -71,11 +67,11 @@ export class DatabaseRef {
|
|
|
71
67
|
return new Pipeline(this.t);
|
|
72
68
|
}
|
|
73
69
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
70
|
+
* Creates a transaction (`MULTI`/`EXEC`) whose queued commands run together
|
|
71
|
+
* without commands from other clients interleaving between them.
|
|
76
72
|
*
|
|
77
|
-
* Nothing is sent until {@link Transaction.exec}, so a transaction
|
|
78
|
-
*
|
|
73
|
+
* Nothing is sent until {@link Transaction.exec} is called, so a transaction
|
|
74
|
+
* is never held open while your code awaits other work.
|
|
79
75
|
*
|
|
80
76
|
* ```ts
|
|
81
77
|
* const tx = LEDGER.transaction();
|
|
@@ -88,19 +84,19 @@ export class DatabaseRef {
|
|
|
88
84
|
return new Transaction(this.t);
|
|
89
85
|
}
|
|
90
86
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* {@link Connection.close}, or
|
|
87
|
+
* Acquires a dedicated connection from the pool for operations that must run
|
|
88
|
+
* on the same connection, such as watching keys before a transaction. Return
|
|
89
|
+
* it with {@link Connection.close}, or manage it with `await using`.
|
|
94
90
|
*/
|
|
95
91
|
async acquire() {
|
|
96
92
|
const impl = await this.t.database().acquire(activeCtxBytes());
|
|
97
93
|
return new Connection(impl, this.t);
|
|
98
94
|
}
|
|
99
95
|
/**
|
|
100
|
-
* Runs `body` as an optimistic transaction
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
96
|
+
* Runs `body` as an optimistic transaction watching `keys`. `body` reads
|
|
97
|
+
* values through the connection and queues writes on the transaction; the
|
|
98
|
+
* transaction commits only if none of `keys` changed in the meantime. If a
|
|
99
|
+
* watched key changes, `body` is retried.
|
|
104
100
|
*
|
|
105
101
|
* ```ts
|
|
106
102
|
* const left = await LEDGER.watch(["balance"], async (conn, tx) => {
|
|
@@ -123,50 +119,57 @@ export class DatabaseRef {
|
|
|
123
119
|
if ((await tx.exec()) !== null)
|
|
124
120
|
return out;
|
|
125
121
|
}
|
|
126
|
-
throw new Error(`redis:
|
|
122
|
+
throw new Error(`redis: watched keys kept changing; gave up after ${attempts} attempts`);
|
|
127
123
|
}
|
|
128
124
|
finally {
|
|
129
125
|
await conn.close();
|
|
130
126
|
}
|
|
131
127
|
}
|
|
132
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Prepares an invocation of `script` so you can attach its keys and
|
|
130
|
+
* arguments and then invoke it.
|
|
131
|
+
*/
|
|
133
132
|
script(script) {
|
|
134
133
|
return new Invocation(this.t, script, false);
|
|
135
134
|
}
|
|
136
135
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
136
|
+
* Prepares an arbitrary Redis command that is not covered by the typed
|
|
137
|
+
* command groups. Pass the command name as a string literal, add its
|
|
138
|
+
* arguments in order (marking keys with `key()`), and then call `invoke()`.
|
|
139
139
|
*
|
|
140
140
|
* ```ts
|
|
141
141
|
* const freq = await SESSIONS.command("OBJECT").arg("FREQ").key("hot").invoke().number();
|
|
142
142
|
* ```
|
|
143
143
|
*
|
|
144
|
-
* Encore reads the name to grant the access
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* database,
|
|
149
|
-
*
|
|
150
|
-
*
|
|
144
|
+
* Encore reads the command name statically to grant the required access.
|
|
145
|
+
* Before sending the command, the runtime checks it against Redis's command
|
|
146
|
+
* table and throws a `TypeError` if a required key argument was not passed
|
|
147
|
+
* with `key()` (which applies the database's key prefix), or if the command
|
|
148
|
+
* reaches outside the database, modifies a shared connection, or already has
|
|
149
|
+
* a dedicated API (`MULTI`, `SUBSCRIBE`, `EVAL`, `SCAN`, `FLUSHALL`, …).
|
|
150
|
+
* Unknown commands, such as module commands, are sent with their keys as
|
|
151
|
+
* marked.
|
|
151
152
|
*/
|
|
152
153
|
command(name) {
|
|
153
154
|
return new CommandInvocation(this.t, rawCommand(name, false));
|
|
154
155
|
}
|
|
155
156
|
/**
|
|
156
|
-
* The connection string
|
|
157
|
-
*
|
|
157
|
+
* The connection string for connecting to this database from an external
|
|
158
|
+
* client.
|
|
158
159
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
160
|
+
* Note that external clients connect without the database's key prefix, so
|
|
161
|
+
* keys stored by an external client will not match keys read by this SDK
|
|
162
|
+
* under the same names.
|
|
161
163
|
*/
|
|
162
164
|
get connectionString() {
|
|
163
165
|
return this.t.database().connectionUrl();
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
/**
|
|
167
|
-
* A Redis database
|
|
169
|
+
* A Redis database backed by a connection pool created on first use.
|
|
168
170
|
*
|
|
169
|
-
* Declare
|
|
171
|
+
* Declare databases at module scope and run commands through their command
|
|
172
|
+
* groups:
|
|
170
173
|
*
|
|
171
174
|
* ```ts
|
|
172
175
|
* import { Database } from "@encore.dev/sdk/storage/redis";
|
|
@@ -178,15 +181,16 @@ export class DatabaseRef {
|
|
|
178
181
|
* ```
|
|
179
182
|
*/
|
|
180
183
|
export class Database extends DatabaseRef {
|
|
181
|
-
|
|
184
|
+
reader;
|
|
185
|
+
primaryReader;
|
|
182
186
|
/**
|
|
183
187
|
* Declares a Redis database.
|
|
184
188
|
*
|
|
185
|
-
* Encore reads the name and
|
|
186
|
-
* must be literals
|
|
189
|
+
* Encore reads the name and configuration statically from the declaration, so
|
|
190
|
+
* both must be literals and the database must be declared at module scope.
|
|
187
191
|
*
|
|
188
|
-
* The name must be unique within the Encore application
|
|
189
|
-
* Once deployed, never
|
|
192
|
+
* The name must be unique within the Encore application and use kebab-case.
|
|
193
|
+
* Once deployed, never rename it — doing so creates a new database under the
|
|
190
194
|
* new name.
|
|
191
195
|
*/
|
|
192
196
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -198,36 +202,38 @@ export class Database extends DatabaseRef {
|
|
|
198
202
|
* References an existing database by name. To declare a new database, use
|
|
199
203
|
* `new Database(...)` instead.
|
|
200
204
|
*
|
|
201
|
-
* The name must be a string literal
|
|
202
|
-
*
|
|
205
|
+
* The name must be a string literal so Encore can resolve it statically. A
|
|
206
|
+
* referenced database takes no configuration; it is configured where it is
|
|
203
207
|
* declared.
|
|
204
208
|
*/
|
|
205
209
|
static named(name) {
|
|
206
210
|
return new Database(name);
|
|
207
211
|
}
|
|
208
|
-
/**
|
|
212
|
+
/** Returns a read-write handle to the database. */
|
|
209
213
|
write() {
|
|
210
214
|
return new DatabaseRef(this.t, this.groups);
|
|
211
215
|
}
|
|
212
216
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
217
|
+
* Returns a read-only handle to the database. Reads from a read replica when
|
|
218
|
+
* a read-only connection pool is configured, and from the primary server
|
|
219
|
+
* otherwise. Write commands are rejected before being sent. To always read
|
|
220
|
+
* from the primary server, use {@link Database.readPrimary}.
|
|
216
221
|
*/
|
|
217
222
|
read() {
|
|
218
|
-
return
|
|
223
|
+
return (this.reader ??= readOnlyRef(this.t.reader(false)));
|
|
219
224
|
}
|
|
220
225
|
/**
|
|
221
|
-
*
|
|
222
|
-
* server even
|
|
226
|
+
* Returns a read-only handle to the database that always reads from the
|
|
227
|
+
* primary server, even when read replicas are available. Write commands are
|
|
228
|
+
* rejected before being sent.
|
|
223
229
|
*/
|
|
224
230
|
readPrimary() {
|
|
225
|
-
return
|
|
226
|
-
}
|
|
227
|
-
readOnlyGroups() {
|
|
228
|
-
return (this.readGroups ??= readCommandGroups(this.t));
|
|
231
|
+
return (this.primaryReader ??= readOnlyRef(this.t.reader(true)));
|
|
229
232
|
}
|
|
230
233
|
}
|
|
234
|
+
function readOnlyRef(t) {
|
|
235
|
+
return new ReadOnlyDatabaseRef(t, readCommandGroups(t));
|
|
236
|
+
}
|
|
231
237
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
232
238
|
export class Pipeline {
|
|
233
239
|
t;
|
|
@@ -237,27 +243,29 @@ export class Pipeline {
|
|
|
237
243
|
this.t = t;
|
|
238
244
|
Object.assign(this, queueGroups(this.queued));
|
|
239
245
|
}
|
|
240
|
-
/**
|
|
246
|
+
/** The number of commands currently queued. */
|
|
241
247
|
get length() {
|
|
242
248
|
return this.queued.length;
|
|
243
249
|
}
|
|
244
|
-
/**
|
|
250
|
+
/**
|
|
251
|
+
* Prepares a call to `script` to be queued on this pipeline. Call
|
|
252
|
+
* {@link QueuedInvocation.queue} to append it.
|
|
253
|
+
*/
|
|
245
254
|
script(script) {
|
|
246
255
|
return new QueuedInvocation(this.queued, script);
|
|
247
256
|
}
|
|
248
257
|
/**
|
|
249
|
-
*
|
|
250
|
-
* {@link
|
|
251
|
-
*
|
|
252
|
-
* queued: the batch fails.
|
|
258
|
+
* Prepares an arbitrary Redis command (see {@link DatabaseRef.command}) to
|
|
259
|
+
* be queued on this pipeline. Call {@link QueuedCommandInvocation.queue} to
|
|
260
|
+
* append it. Blocking commands cannot be queued and will fail the batch.
|
|
253
261
|
*/
|
|
254
262
|
command(name) {
|
|
255
263
|
return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
|
|
256
264
|
}
|
|
257
265
|
/**
|
|
258
|
-
* Sends
|
|
259
|
-
*
|
|
260
|
-
*
|
|
266
|
+
* Sends all queued commands and returns their replies in order. If the server
|
|
267
|
+
* rejects any command, throws a {@link BatchError} containing all replies.
|
|
268
|
+
* Clears the pipeline afterwards.
|
|
261
269
|
*/
|
|
262
270
|
async exec() {
|
|
263
271
|
const values = await this.t.runAll(this.queued.splice(0), false);
|
|
@@ -273,35 +281,38 @@ export class Transaction {
|
|
|
273
281
|
this.t = t;
|
|
274
282
|
Object.assign(this, queueGroups(this.queued));
|
|
275
283
|
}
|
|
276
|
-
/**
|
|
284
|
+
/** The number of commands currently queued. */
|
|
277
285
|
get length() {
|
|
278
286
|
return this.queued.length;
|
|
279
287
|
}
|
|
280
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* Prepares a call to `script` to be queued on this transaction. Call
|
|
290
|
+
* {@link QueuedInvocation.queue} to append it.
|
|
291
|
+
*/
|
|
281
292
|
script(script) {
|
|
282
293
|
return new QueuedInvocation(this.queued, script);
|
|
283
294
|
}
|
|
284
295
|
/**
|
|
285
|
-
*
|
|
286
|
-
* {@link
|
|
287
|
-
*
|
|
288
|
-
* queued: the batch fails.
|
|
296
|
+
* Prepares an arbitrary Redis command (see {@link DatabaseRef.command}) to
|
|
297
|
+
* be queued on this transaction. Call {@link QueuedCommandInvocation.queue}
|
|
298
|
+
* to append it. Blocking commands cannot be queued and will fail the batch.
|
|
289
299
|
*/
|
|
290
300
|
command(name) {
|
|
291
301
|
return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
|
|
292
302
|
}
|
|
293
303
|
/**
|
|
294
|
-
* Runs
|
|
295
|
-
* {@link Pipeline.exec}
|
|
296
|
-
*
|
|
304
|
+
* Runs all queued commands as a single transaction and returns their replies,
|
|
305
|
+
* matching {@link Pipeline.exec}. If the server rejects a command during
|
|
306
|
+
* execution, the remaining commands still run — Redis does not support
|
|
307
|
+
* rollbacks.
|
|
297
308
|
*/
|
|
298
309
|
async exec() {
|
|
299
310
|
const values = await this.t.runAll(this.queued.splice(0), true);
|
|
300
311
|
return batchReplies(values ?? []);
|
|
301
312
|
}
|
|
302
313
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
314
|
+
* Discards the transaction by clearing its queue. Because nothing has been
|
|
315
|
+
* sent yet, there is nothing to undo on the server.
|
|
305
316
|
*/
|
|
306
317
|
discard() {
|
|
307
318
|
this.queued.splice(0);
|
|
@@ -316,28 +327,30 @@ export class WatchedTransaction {
|
|
|
316
327
|
this.t = t;
|
|
317
328
|
Object.assign(this, queueGroups(this.queued));
|
|
318
329
|
}
|
|
319
|
-
/**
|
|
330
|
+
/** The number of commands currently queued. */
|
|
320
331
|
get length() {
|
|
321
332
|
return this.queued.length;
|
|
322
333
|
}
|
|
323
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* Prepares a call to `script` to be queued on this transaction. Call
|
|
336
|
+
* {@link QueuedInvocation.queue} to append it.
|
|
337
|
+
*/
|
|
324
338
|
script(script) {
|
|
325
339
|
return new QueuedInvocation(this.queued, script);
|
|
326
340
|
}
|
|
327
341
|
/**
|
|
328
|
-
*
|
|
329
|
-
* {@link
|
|
330
|
-
*
|
|
331
|
-
* queued: the batch fails.
|
|
342
|
+
* Prepares an arbitrary Redis command (see {@link DatabaseRef.command}) to
|
|
343
|
+
* be queued on this transaction. Call {@link QueuedCommandInvocation.queue}
|
|
344
|
+
* to append it. Blocking commands cannot be queued and will fail the batch.
|
|
332
345
|
*/
|
|
333
346
|
command(name) {
|
|
334
347
|
return new QueuedCommandInvocation(this.queued, rawCommand(name, false));
|
|
335
348
|
}
|
|
336
349
|
/**
|
|
337
|
-
* Runs
|
|
338
|
-
* {@link Transaction.exec}
|
|
339
|
-
* which case none of
|
|
340
|
-
* afterwards.
|
|
350
|
+
* Runs all queued commands as a single transaction and returns their replies
|
|
351
|
+
* (as in {@link Transaction.exec}), or `null` if a watched key changed (in
|
|
352
|
+
* which case none of the commands ran). Either way, all watches on the
|
|
353
|
+
* connection are cleared afterwards.
|
|
341
354
|
*/
|
|
342
355
|
async exec() {
|
|
343
356
|
const values = await this.t.runAll(this.queued.splice(0), true);
|
|
@@ -355,38 +368,44 @@ export class Connection {
|
|
|
355
368
|
Object.assign(this, commandGroups(this.t));
|
|
356
369
|
}
|
|
357
370
|
/**
|
|
358
|
-
* Watches `keys
|
|
359
|
-
*
|
|
371
|
+
* Watches `keys` for changes. A subsequent {@link Connection.transaction}
|
|
372
|
+
* will abort without running if any watched key changes before `exec()`.
|
|
360
373
|
*/
|
|
361
374
|
async watch(...keys) {
|
|
362
375
|
await this.impl.watch(encodeList(keys), activeCtxBytes());
|
|
363
376
|
}
|
|
364
|
-
/** Stops watching
|
|
377
|
+
/** Stops watching all keys on this connection. */
|
|
365
378
|
async unwatch() {
|
|
366
379
|
await this.impl.unwatch(activeCtxBytes());
|
|
367
380
|
}
|
|
368
|
-
/**
|
|
381
|
+
/**
|
|
382
|
+
* Creates a transaction on this connection that depends on its watched keys.
|
|
383
|
+
*/
|
|
369
384
|
transaction() {
|
|
370
385
|
return new WatchedTransaction(this.t);
|
|
371
386
|
}
|
|
372
|
-
/**
|
|
387
|
+
/**
|
|
388
|
+
* Creates a pipeline that sends a batch of commands in a single round trip
|
|
389
|
+
* on this connection.
|
|
390
|
+
*/
|
|
373
391
|
pipeline() {
|
|
374
392
|
return new Pipeline(this.t);
|
|
375
393
|
}
|
|
376
|
-
/**
|
|
394
|
+
/** Prepares an invocation of `script` on this connection. */
|
|
377
395
|
script(script) {
|
|
378
396
|
return new Invocation(this.t, script, false);
|
|
379
397
|
}
|
|
380
398
|
/**
|
|
381
|
-
*
|
|
382
|
-
* {@link DatabaseRef.command}.
|
|
399
|
+
* Prepares an arbitrary Redis command on this connection (see
|
|
400
|
+
* {@link DatabaseRef.command}). Blocking commands are not allowed on an
|
|
401
|
+
* acquired connection.
|
|
383
402
|
*/
|
|
384
403
|
command(name) {
|
|
385
404
|
return new CommandInvocation(this.t, rawCommand(name, false));
|
|
386
405
|
}
|
|
387
406
|
/**
|
|
388
|
-
* Returns the connection to its pool
|
|
389
|
-
*
|
|
407
|
+
* Returns the connection to its pool, automatically unwatching any keys that
|
|
408
|
+
* are still watched.
|
|
390
409
|
*/
|
|
391
410
|
async close() {
|
|
392
411
|
await this.impl.release();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../storage/redis/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAC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AAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Redis databases.
|
|
3
|
-
* is
|
|
2
|
+
* Redis databases. Declare a database at module scope; its connection pool
|
|
3
|
+
* is created on first use and reused thereafter.
|
|
4
4
|
*
|
|
5
5
|
* ```ts
|
|
6
6
|
* import { Database } from "@encore.dev/sdk/storage/redis";
|
|
@@ -13,22 +13,22 @@
|
|
|
13
13
|
* }
|
|
14
14
|
* ```
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Each database is a standalone resource with no clusters or keyspaces to
|
|
17
|
+
* declare; keys are arbitrary strings passed by your code.
|
|
18
18
|
*
|
|
19
19
|
* ## Commands
|
|
20
20
|
*
|
|
21
|
-
* Commands are grouped by
|
|
22
|
-
*
|
|
23
|
-
* `
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* `
|
|
27
|
-
* `zrangeWithscores`.
|
|
21
|
+
* Commands are grouped by data type as properties on the database: `string`,
|
|
22
|
+
* `hash`, `list`, `set`, `sortedSet`, `stream`, `geo`, `bitmap`,
|
|
23
|
+
* `hyperloglog`, `pubsub`, and `generic` (for commands that work on any key).
|
|
24
|
+
* Within each group, methods are named after the underlying Redis command —
|
|
25
|
+
* `get`, `hset`, `zadd`, `xadd` — with descriptive names for variants such as
|
|
26
|
+
* `setEx` and `zrangeWithscores`.
|
|
28
27
|
*
|
|
29
|
-
*
|
|
30
|
-
* `sismember` a boolean.
|
|
31
|
-
* {@link ReplyPromise},
|
|
28
|
+
* Commands with a fixed reply type return it directly (`strlen` returns a
|
|
29
|
+
* number; `sismember` returns a boolean). Commands whose reply format depends
|
|
30
|
+
* on the caller return a {@link ReplyPromise}, which you can decode into the
|
|
31
|
+
* desired type:
|
|
32
32
|
*
|
|
33
33
|
* ```ts
|
|
34
34
|
* const name = await SESSIONS.string.get("name:1").text();
|
|
@@ -36,45 +36,47 @@
|
|
|
36
36
|
* const fields = await SESSIONS.hash.hgetall("user:1").textMap();
|
|
37
37
|
* ```
|
|
38
38
|
*
|
|
39
|
-
* A missing key
|
|
39
|
+
* A missing key decodes as `null`.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
41
|
+
* Always call a command in the same expression that accesses its group. This
|
|
42
|
+
* makes the command visible at the call site so Encore's parser can statically
|
|
43
|
+
* grant each service only the access it uses. Storing or passing a command
|
|
44
|
+
* group obscures how it will be used and results in a compile error — to pass
|
|
45
|
+
* database access around, create a handle instead.
|
|
46
46
|
*
|
|
47
|
-
*
|
|
48
|
-
* `
|
|
49
|
-
*
|
|
50
|
-
*
|
|
47
|
+
* Blocking commands — such as `list.blpop`, `sortedSet.bzpopmin`, and
|
|
48
|
+
* `stream.xreadBlock` — run on a dedicated connection so they do not block
|
|
49
|
+
* other calls. A timeout resolves to `null`. Blocking commands cannot be
|
|
50
|
+
* queued in pipelines or transactions, and cannot run on an acquired
|
|
51
|
+
* connection.
|
|
51
52
|
*
|
|
52
53
|
* ## Any command
|
|
53
54
|
*
|
|
54
|
-
* {@link DatabaseRef.command} sends a command
|
|
55
|
-
*
|
|
55
|
+
* {@link DatabaseRef.command} sends a command that is not covered by the typed
|
|
56
|
+
* command groups, by specifying its name and marking any key arguments:
|
|
56
57
|
*
|
|
57
58
|
* ```ts
|
|
58
59
|
* const freq = await SESSIONS.command("OBJECT").arg("FREQ").key("hot").invoke().number();
|
|
59
60
|
* ```
|
|
60
61
|
*
|
|
61
|
-
* The name must be a string literal
|
|
62
|
-
*
|
|
63
|
-
* command table:
|
|
64
|
-
* that
|
|
65
|
-
*
|
|
66
|
-
* `FLUSHALL`, …) fail with a `TypeError`. A handle
|
|
67
|
-
*
|
|
62
|
+
* The command name must be a string literal so Encore can statically grant the
|
|
63
|
+
* required access. Before sending the command, the runtime validates it against
|
|
64
|
+
* Redis's command table: every key argument must be passed with `key()`, and
|
|
65
|
+
* commands that reach outside the database, alter a shared connection, or
|
|
66
|
+
* already have dedicated APIs (`MULTI`, `SUBSCRIBE`, `EVAL`, `SCAN`,
|
|
67
|
+
* `FLUSHALL`, …) fail with a `TypeError`. A read-only handle only allows
|
|
68
|
+
* commands that Redis marks as read-only.
|
|
68
69
|
*
|
|
69
70
|
* ## Handles
|
|
70
71
|
*
|
|
71
|
-
* A
|
|
72
|
-
*
|
|
73
|
-
* {@link Database.
|
|
74
|
-
*
|
|
72
|
+
* A {@link Database} instance cannot be passed around as a value. To pass
|
|
73
|
+
* database access to other code, create a handle with the permissions that
|
|
74
|
+
* code needs — {@link Database.write}, {@link Database.read}, or
|
|
75
|
+
* {@link Database.readPrimary}. Creating a handle grants the calling service
|
|
76
|
+
* full access at that permission level:
|
|
75
77
|
*
|
|
76
78
|
* ```ts
|
|
77
|
-
* // Library code takes a handle
|
|
79
|
+
* // Library code takes a handle and can only perform the operations it allows.
|
|
78
80
|
* function nameOf(db: ReadOnlyDatabaseRef, user: string) {
|
|
79
81
|
* return db.string.get(`name:${user}`).text();
|
|
80
82
|
* }
|
|
@@ -86,16 +88,18 @@
|
|
|
86
88
|
*
|
|
87
89
|
* ## Keys
|
|
88
90
|
*
|
|
89
|
-
* Every key is stored under a
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* -
|
|
95
|
-
*
|
|
96
|
-
* database's isolation, so
|
|
97
|
-
*
|
|
98
|
-
*
|
|
91
|
+
* Every key is automatically stored under a database-specific prefix to isolate
|
|
92
|
+
* databases sharing a server. The SDK applies the prefix to every key passed to
|
|
93
|
+
* a command and strips it from every key returned, so application code never
|
|
94
|
+
* sees it. Keep two caveats in mind:
|
|
95
|
+
*
|
|
96
|
+
* - A {@link Script}'s `KEYS` are prefixed automatically, but nothing else in
|
|
97
|
+
* the script is. Any key referenced directly in script source or `ARGV` is
|
|
98
|
+
* accessed unprefixed, outside the database's isolation, so always pass keys
|
|
99
|
+
* through `KEYS`.
|
|
100
|
+
* - {@link DatabaseRef.connectionString} connects without key prefixing, so
|
|
101
|
+
* external clients will not see keys written by this SDK under the same
|
|
102
|
+
* names.
|
|
99
103
|
*
|
|
100
104
|
* @module
|
|
101
105
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../storage/redis/mod.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../storage/redis/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwGG;AAEH,OAAO,EACL,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,YAAY,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAC/C,YAAY,EACV,cAAc,EACd,aAAa,EACb,QAAQ,EACR,eAAe,EACf,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,KAAK,EACL,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,SAAS,EACT,MAAM,EACN,aAAa,EACb,WAAW,EACX,SAAS,EACT,UAAU,EACV,YAAY,EACZ,IAAI,GACL,MAAM,WAAW,CAAC;AACnB,OAAO,EAAC,UAAU,EAAE,KAAK,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AACxD,YAAY,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV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