@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
package/storage/redis/reply.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {MapReply, ServerError, Status, Value} from './wire';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A reply
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A Redis reply decoded into plain JavaScript values, as returned by
|
|
5
|
+
* {@link Reply.value}. Strings decode to UTF-8 text, integers decode to
|
|
6
|
+
* `number` (or `bigint` when outside the safe integer range), and maps decode
|
|
7
|
+
* to prototype-less objects keyed by their string keys.
|
|
7
8
|
*/
|
|
8
9
|
export type RedisValue =
|
|
9
10
|
| null
|
|
@@ -14,113 +15,113 @@ export type RedisValue =
|
|
|
14
15
|
| RedisValue[]
|
|
15
16
|
| {[key: string]: RedisValue};
|
|
16
17
|
|
|
17
|
-
/** A
|
|
18
|
+
/** A sorted set member along with its score. */
|
|
18
19
|
export interface ScoredMember {
|
|
19
20
|
member: string;
|
|
20
21
|
score: number;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
/** A field
|
|
24
|
+
/** A hash field along with its value. */
|
|
24
25
|
export interface FieldValue {
|
|
25
26
|
field: string;
|
|
26
27
|
value: string;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
/**
|
|
30
|
+
/** A stream entry containing its ID and field-value pairs. */
|
|
30
31
|
export interface StreamEntry {
|
|
31
32
|
id: string;
|
|
32
33
|
fields: Record<string, string>;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
/**
|
|
36
|
+
/** Entries read from a single stream. */
|
|
36
37
|
export interface Stream {
|
|
37
38
|
key: string;
|
|
38
39
|
entries: StreamEntry[];
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
43
|
+
* Summary of pending (unacknowledged) entries for a consumer group, as
|
|
44
|
+
* returned by `xpending`.
|
|
44
45
|
*/
|
|
45
46
|
export interface StreamPending {
|
|
46
|
-
/**
|
|
47
|
+
/** Number of pending entries. */
|
|
47
48
|
count: number;
|
|
48
|
-
/**
|
|
49
|
+
/** Lowest pending entry ID, or `null` if no entries are pending. */
|
|
49
50
|
lowest: string | null;
|
|
50
|
-
/**
|
|
51
|
+
/** Highest pending entry ID, or `null` if no entries are pending. */
|
|
51
52
|
highest: string | null;
|
|
52
|
-
/**
|
|
53
|
+
/** Consumers with pending entries and the pending count for each. */
|
|
53
54
|
consumers: {name: string; pending: number}[];
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
/**
|
|
57
|
+
/** Metadata about a stream, as returned by `xinfoStream`. */
|
|
57
58
|
export interface StreamInfo {
|
|
58
59
|
length: number;
|
|
59
60
|
radixTreeKeys: number;
|
|
60
61
|
radixTreeNodes: number;
|
|
61
62
|
groups: number;
|
|
62
63
|
lastGeneratedId: string;
|
|
63
|
-
/** `null`
|
|
64
|
+
/** The first entry in the stream, or `null` if the stream is empty. */
|
|
64
65
|
firstEntry: StreamEntry | null;
|
|
65
|
-
/** `null`
|
|
66
|
+
/** The last entry in the stream, or `null` if the stream is empty. */
|
|
66
67
|
lastEntry: StreamEntry | null;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
/**
|
|
70
|
+
/** Result of an `xautoclaim` command. */
|
|
70
71
|
export interface StreamAutoClaim {
|
|
71
72
|
/**
|
|
72
|
-
* The
|
|
73
|
-
* pending entries is
|
|
73
|
+
* The cursor ID to pass as the starting point for the next call, or `"0-0"`
|
|
74
|
+
* when the pending entries scan is complete.
|
|
74
75
|
*/
|
|
75
76
|
next: string;
|
|
76
|
-
/** The entries
|
|
77
|
+
/** The entries successfully claimed by the consumer. */
|
|
77
78
|
claimed: StreamEntry[];
|
|
78
|
-
/**
|
|
79
|
+
/** IDs of pending entries that no longer exist in the stream. */
|
|
79
80
|
deleted: string[];
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
84
|
+
* Result of a blocking pop of a single element: the source key (with the
|
|
85
|
+
* database's prefix stripped) and the popped element.
|
|
85
86
|
*/
|
|
86
87
|
export interface Popped {
|
|
87
88
|
key: string;
|
|
88
89
|
value: Reply;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
/**
|
|
92
|
+
/** Result of a blocking pop of multiple elements, in the order they were popped. */
|
|
92
93
|
export interface PoppedMany {
|
|
93
94
|
key: string;
|
|
94
95
|
values: Reply[];
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
/**
|
|
98
|
+
/** Result of a blocking pop of a single sorted set member. */
|
|
98
99
|
export interface PoppedScored {
|
|
99
100
|
key: string;
|
|
100
101
|
member: Reply;
|
|
101
102
|
score: number;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
/**
|
|
105
|
+
/** Result of a blocking pop of multiple sorted set members. */
|
|
105
106
|
export interface PoppedScoredMany {
|
|
106
107
|
key: string;
|
|
107
108
|
members: {member: Reply; score: number}[];
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
/**
|
|
111
|
+
/** Geographic coordinates (longitude and latitude). */
|
|
111
112
|
export interface GeoPosition {
|
|
112
113
|
longitude: number;
|
|
113
114
|
latitude: number;
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
/** A member
|
|
117
|
+
/** A member matched by a geo radius search, with any requested metadata. */
|
|
117
118
|
export interface GeoRadiusResult {
|
|
118
119
|
name: string;
|
|
119
|
-
/**
|
|
120
|
+
/** Distance from the search center (present when `withDist` is enabled). */
|
|
120
121
|
dist?: number;
|
|
121
|
-
/**
|
|
122
|
+
/** Geohash integer of the member (present when `withHash` is enabled). */
|
|
122
123
|
hash?: bigint;
|
|
123
|
-
/**
|
|
124
|
+
/** Coordinates of the member (present when `withCoord` is enabled). */
|
|
124
125
|
coord?: GeoPosition;
|
|
125
126
|
}
|
|
126
127
|
|
|
@@ -249,7 +250,7 @@ function textMapOf(v: Value): Record<string, string> {
|
|
|
249
250
|
const items = arrayOf(v);
|
|
250
251
|
if (items.length % 2 !== 0) {
|
|
251
252
|
throw new TypeError(
|
|
252
|
-
`redis: an
|
|
253
|
+
`redis: expected an even number of elements for key-value pairs, got ${items.length}`,
|
|
253
254
|
);
|
|
254
255
|
}
|
|
255
256
|
const out = dict<string>();
|
|
@@ -272,7 +273,7 @@ export function scoredMembersOf(items: Value[]): ScoredMember[] {
|
|
|
272
273
|
}
|
|
273
274
|
if (items.length % 2 !== 0) {
|
|
274
275
|
throw new TypeError(
|
|
275
|
-
`redis: an
|
|
276
|
+
`redis: expected an even number of elements for members and scores, got ${items.length}`,
|
|
276
277
|
);
|
|
277
278
|
}
|
|
278
279
|
const out: ScoredMember[] = [];
|
|
@@ -295,10 +296,10 @@ function geoPositionOf(v: Value): GeoPosition {
|
|
|
295
296
|
}
|
|
296
297
|
|
|
297
298
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* {@link Reply.
|
|
301
|
-
*
|
|
299
|
+
* A Redis command reply, or the error the command failed with. Decode it into
|
|
300
|
+
* the expected type using methods such as {@link Reply.text},
|
|
301
|
+
* {@link Reply.number}, or {@link Reply.textMap}. Every accessor throws if the
|
|
302
|
+
* command failed and returns `null` for a nil reply.
|
|
302
303
|
*/
|
|
303
304
|
export class Reply {
|
|
304
305
|
/** @internal */
|
|
@@ -312,14 +313,14 @@ export class Reply {
|
|
|
312
313
|
return new Reply(null, err instanceof Error ? err : new Error(String(err)));
|
|
313
314
|
}
|
|
314
315
|
|
|
315
|
-
/** The error the command failed with, if
|
|
316
|
+
/** The error the command failed with, if any. A nil reply is not an error. */
|
|
316
317
|
get error(): Error | undefined {
|
|
317
318
|
return (
|
|
318
319
|
this.err ?? (this.reply instanceof ServerError ? this.reply : undefined)
|
|
319
320
|
);
|
|
320
321
|
}
|
|
321
322
|
|
|
322
|
-
/**
|
|
323
|
+
/** Returns `true` if the command succeeded and returned nil. */
|
|
323
324
|
isNull(): boolean {
|
|
324
325
|
return !this.err && this.reply === null;
|
|
325
326
|
}
|
|
@@ -330,17 +331,17 @@ export class Reply {
|
|
|
330
331
|
return this.reply;
|
|
331
332
|
}
|
|
332
333
|
|
|
333
|
-
/**
|
|
334
|
+
/** Decodes the reply as plain JavaScript values. */
|
|
334
335
|
value(): RedisValue {
|
|
335
336
|
return plain(this.v);
|
|
336
337
|
}
|
|
337
338
|
|
|
338
|
-
/**
|
|
339
|
+
/** Decodes the reply as UTF-8 text (or stringified digits for a number). */
|
|
339
340
|
text(): string | null {
|
|
340
341
|
return this.v === null ? null : textOf(this.v);
|
|
341
342
|
}
|
|
342
343
|
|
|
343
|
-
/**
|
|
344
|
+
/** Returns the reply as raw bytes. */
|
|
344
345
|
bytes(): Buffer | null {
|
|
345
346
|
const v = ok(this.v);
|
|
346
347
|
if (v === null) return null;
|
|
@@ -348,92 +349,93 @@ export class Reply {
|
|
|
348
349
|
}
|
|
349
350
|
|
|
350
351
|
/**
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
* {@link Reply.bigint}.
|
|
352
|
+
* Decodes the reply as a number, parsing numeric strings if necessary.
|
|
353
|
+
* Integers outside the safe integer range lose precision; use
|
|
354
|
+
* {@link Reply.bigint} for exact 64-bit integers.
|
|
354
355
|
*/
|
|
355
356
|
number(): number | null {
|
|
356
357
|
return this.v === null ? null : numberOf(this.v);
|
|
357
358
|
}
|
|
358
359
|
|
|
359
|
-
/**
|
|
360
|
+
/** Decodes the reply as a `bigint`, parsing numeric strings if necessary. */
|
|
360
361
|
bigint(): bigint | null {
|
|
361
362
|
return this.v === null ? null : bigintOf(this.v);
|
|
362
363
|
}
|
|
363
364
|
|
|
364
|
-
/**
|
|
365
|
+
/** Decodes the reply as a boolean (non-zero integers and `"OK"` are `true`). */
|
|
365
366
|
bool(): boolean | null {
|
|
366
367
|
return this.v === null ? null : boolOf(this.v);
|
|
367
368
|
}
|
|
368
369
|
|
|
369
|
-
/**
|
|
370
|
+
/** Decodes the reply as UTF-8 text and parses it as JSON. */
|
|
370
371
|
json<T = unknown>(): T | null {
|
|
371
372
|
const text = this.text();
|
|
372
373
|
return text === null ? null : (JSON.parse(text) as T);
|
|
373
374
|
}
|
|
374
375
|
|
|
375
|
-
/**
|
|
376
|
+
/** Decodes an array reply as an array of {@link Reply} instances. */
|
|
376
377
|
replies(): Reply[] {
|
|
377
378
|
return arrayOf(this.v).map(item => new Reply(item));
|
|
378
379
|
}
|
|
379
380
|
|
|
380
381
|
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
382
|
+
* Decodes an array reply as strings. Throws if any element is nil; use
|
|
383
|
+
* {@link Reply.optionalTexts} to preserve missing elements as `null`.
|
|
383
384
|
*/
|
|
384
385
|
texts(): string[] {
|
|
385
386
|
return arrayOf(this.v).map(item => {
|
|
386
387
|
if (item === null)
|
|
387
|
-
throw new TypeError('redis: a nil element
|
|
388
|
+
throw new TypeError('redis: cannot read a nil element as text');
|
|
388
389
|
return textOf(item);
|
|
389
390
|
});
|
|
390
391
|
}
|
|
391
392
|
|
|
392
393
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
394
|
+
* Decodes an array reply as strings, mapping nil elements to `null` (as
|
|
395
|
+
* returned by `mget` and `hmget` for missing keys or fields).
|
|
395
396
|
*/
|
|
396
397
|
optionalTexts(): (string | null)[] {
|
|
397
398
|
return arrayOf(this.v).map(item => (item === null ? null : textOf(item)));
|
|
398
399
|
}
|
|
399
400
|
|
|
400
|
-
/**
|
|
401
|
+
/** Decodes an array reply as numbers. */
|
|
401
402
|
numbers(): number[] {
|
|
402
403
|
return arrayOf(this.v).map(numberOf);
|
|
403
404
|
}
|
|
404
405
|
|
|
405
|
-
/**
|
|
406
|
+
/** Decodes an array reply as booleans. */
|
|
406
407
|
bools(): boolean[] {
|
|
407
408
|
return arrayOf(this.v).map(boolOf);
|
|
408
409
|
}
|
|
409
410
|
|
|
410
411
|
/**
|
|
411
|
-
*
|
|
412
|
-
* `hgetall`
|
|
413
|
-
*
|
|
412
|
+
* Decodes a map reply (or flat array of key-value pairs, as returned by
|
|
413
|
+
* `hgetall`) into a prototype-less object so keys like `__proto__` are
|
|
414
|
+
* handled safely.
|
|
414
415
|
*/
|
|
415
416
|
textMap(): Record<string, string> {
|
|
416
417
|
return textMapOf(this.v);
|
|
417
418
|
}
|
|
418
419
|
|
|
419
420
|
/**
|
|
420
|
-
*
|
|
421
|
-
* `
|
|
421
|
+
* Decodes sorted set members with their scores, as returned by
|
|
422
|
+
* `zrangeWithscores` and `zpopmin`.
|
|
422
423
|
*/
|
|
423
424
|
scoredMembers(): ScoredMember[] {
|
|
424
425
|
return scoredMembersOf(arrayOf(this.v));
|
|
425
426
|
}
|
|
426
427
|
|
|
427
428
|
/**
|
|
428
|
-
*
|
|
429
|
+
* Decodes stream entries, as returned by `xrange`, `xrevrange`, and
|
|
430
|
+
* `xclaim`.
|
|
429
431
|
*/
|
|
430
432
|
streamEntries(): StreamEntry[] {
|
|
431
433
|
return arrayOf(this.v).map(streamEntryOf);
|
|
432
434
|
}
|
|
433
435
|
|
|
434
436
|
/**
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
+
* Decodes entries grouped by stream, as returned by `xread` and
|
|
438
|
+
* `xreadGroup`. Returns an empty array if no entries were read.
|
|
437
439
|
*/
|
|
438
440
|
streams(): Stream[] {
|
|
439
441
|
const v = ok(this.v);
|
|
@@ -453,7 +455,7 @@ export class Reply {
|
|
|
453
455
|
}));
|
|
454
456
|
}
|
|
455
457
|
|
|
456
|
-
/**
|
|
458
|
+
/** Decodes a pending-entries summary returned by `xpending`. */
|
|
457
459
|
streamPending(): StreamPending {
|
|
458
460
|
const parts = arrayOf(this.v);
|
|
459
461
|
if (parts.length !== 4) throw typeErr(this.v, 'a pending summary');
|
|
@@ -471,7 +473,7 @@ export class Reply {
|
|
|
471
473
|
};
|
|
472
474
|
}
|
|
473
475
|
|
|
474
|
-
/**
|
|
476
|
+
/** Decodes stream metadata returned by `xinfoStream`. */
|
|
475
477
|
streamInfo(): StreamInfo {
|
|
476
478
|
const items = arrayOf(this.v);
|
|
477
479
|
const out: StreamInfo = {
|
|
@@ -512,7 +514,7 @@ export class Reply {
|
|
|
512
514
|
return out;
|
|
513
515
|
}
|
|
514
516
|
|
|
515
|
-
/**
|
|
517
|
+
/** Decodes an `xautoclaim` reply. */
|
|
516
518
|
streamAutoClaim(): StreamAutoClaim {
|
|
517
519
|
const parts = arrayOf(this.v);
|
|
518
520
|
if (parts.length < 2) throw typeErr(this.v, 'an autoclaim reply');
|
|
@@ -523,14 +525,17 @@ export class Reply {
|
|
|
523
525
|
};
|
|
524
526
|
}
|
|
525
527
|
|
|
526
|
-
/**
|
|
528
|
+
/**
|
|
529
|
+
* Decodes member positions returned by `geoPos`, with `null` for missing
|
|
530
|
+
* members.
|
|
531
|
+
*/
|
|
527
532
|
geoPositions(): (GeoPosition | null)[] {
|
|
528
533
|
return arrayOf(this.v).map(item =>
|
|
529
534
|
item === null ? null : geoPositionOf(item),
|
|
530
535
|
);
|
|
531
536
|
}
|
|
532
537
|
|
|
533
|
-
/**
|
|
538
|
+
/** Decodes members matched by a `geoRadius` search. */
|
|
534
539
|
geoRadius(): GeoRadiusResult[] {
|
|
535
540
|
return arrayOf(this.v).map(item => {
|
|
536
541
|
// A plain name without any of withDist, withHash and withCoord;
|
|
@@ -551,14 +556,16 @@ export class Reply {
|
|
|
551
556
|
}
|
|
552
557
|
|
|
553
558
|
/**
|
|
554
|
-
* A command
|
|
555
|
-
* rejects if the command
|
|
559
|
+
* A pending command reply. Await it directly to get the {@link Reply} (which
|
|
560
|
+
* rejects if the command fails), or chain a decoder method to read the value
|
|
561
|
+
* directly:
|
|
556
562
|
*
|
|
557
563
|
* ```ts
|
|
558
564
|
* const name = await SESSIONS.string.get("name:1").text();
|
|
559
565
|
* ```
|
|
560
566
|
*
|
|
561
|
-
* The command is sent when
|
|
567
|
+
* The command is sent immediately when called, whether or not the returned
|
|
568
|
+
* promise is awaited.
|
|
562
569
|
*/
|
|
563
570
|
export class ReplyPromise implements PromiseLike<Reply> {
|
|
564
571
|
/** @internal */
|
|
@@ -693,11 +700,12 @@ export class ReplyPromise implements PromiseLike<Reply> {
|
|
|
693
700
|
}
|
|
694
701
|
|
|
695
702
|
/**
|
|
696
|
-
*
|
|
697
|
-
*
|
|
703
|
+
* Error thrown by a pipeline or transaction when the server rejects one or
|
|
704
|
+
* more queued commands. The remaining commands still executed, as Redis does
|
|
705
|
+
* not support rollbacks.
|
|
698
706
|
*/
|
|
699
707
|
export class BatchError extends Error {
|
|
700
|
-
/**
|
|
708
|
+
/** Replies for every queued command in order, including each command's error. */
|
|
701
709
|
readonly replies: Reply[];
|
|
702
710
|
|
|
703
711
|
/** @internal */
|
|
@@ -769,12 +777,12 @@ function popParts(v: Value, n: number): Value[] | null {
|
|
|
769
777
|
const parts = arrayOf(v);
|
|
770
778
|
if (parts.length !== n) {
|
|
771
779
|
throw new TypeError(
|
|
772
|
-
`redis:
|
|
780
|
+
`redis: expected ${n} values in pop reply, got ${parts.length}`,
|
|
773
781
|
);
|
|
774
782
|
}
|
|
775
783
|
return parts;
|
|
776
784
|
}
|
|
777
785
|
|
|
778
786
|
function nilErr(): never {
|
|
779
|
-
throw new TypeError('redis:
|
|
787
|
+
throw new TypeError('redis: command returned an unexpected nil reply');
|
|
780
788
|
}
|
package/storage/redis/scan.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {Cmd, type Value} from './wire';
|
|
|
15
15
|
// returned at least once — possibly more — and one added or removed during it
|
|
16
16
|
// may or may not be.
|
|
17
17
|
|
|
18
|
-
/** Iterates over the database
|
|
18
|
+
/** Iterates over the keys in the database. */
|
|
19
19
|
export async function* scanKeys(
|
|
20
20
|
t: Target,
|
|
21
21
|
options: ScanOptions = {},
|
|
@@ -35,7 +35,7 @@ export async function* scanKeys(
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/** Iterates over a set
|
|
38
|
+
/** Iterates over the members of a set. */
|
|
39
39
|
export async function* scanMembers(
|
|
40
40
|
t: Target,
|
|
41
41
|
key: string,
|
|
@@ -52,7 +52,7 @@ export async function* scanMembers(
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/** Iterates over
|
|
55
|
+
/** Iterates over the fields and values of a hash. */
|
|
56
56
|
export async function* scanFields(
|
|
57
57
|
t: Target,
|
|
58
58
|
key: string,
|
|
@@ -67,7 +67,7 @@ export async function* scanFields(
|
|
|
67
67
|
)) {
|
|
68
68
|
if (batch.length % 2 !== 0) {
|
|
69
69
|
throw new TypeError(
|
|
70
|
-
|
|
70
|
+
'redis: HSCAN reply contains an odd number of elements; expected field-value pairs',
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
for (let i = 0; i < batch.length; i += 2) {
|
|
@@ -76,7 +76,7 @@ export async function* scanFields(
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/** Iterates over
|
|
79
|
+
/** Iterates over the members and scores of a sorted set. */
|
|
80
80
|
export async function* scanScored(
|
|
81
81
|
t: Target,
|
|
82
82
|
key: string,
|
|
@@ -111,7 +111,7 @@ async function* scanBatches(
|
|
|
111
111
|
const parts = arrayOf(await t.run(cmd));
|
|
112
112
|
if (parts.length !== 2) {
|
|
113
113
|
throw new TypeError(
|
|
114
|
-
'redis:
|
|
114
|
+
'redis: unexpected scan reply format; expected a cursor and a batch',
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
cursor = textOf(parts[0]);
|
package/storage/redis/script.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {Target} from './target';
|
|
|
5
5
|
import {Cmd, ServerError, type RedisArg} from './wire';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A Lua script
|
|
8
|
+
* A Lua script executed on a Redis database, declared at module scope.
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
11
|
* import { Database, Script } from "@encore.dev/sdk/storage/redis";
|
|
@@ -25,30 +25,30 @@ import {Cmd, ServerError, type RedisArg} from './wire';
|
|
|
25
25
|
* }
|
|
26
26
|
* ```
|
|
27
27
|
*
|
|
28
|
-
* Only
|
|
29
|
-
* database's key prefix. The script's source and
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* isolation
|
|
33
|
-
*
|
|
28
|
+
* Only keys passed through `KEYS` via {@link Invocation.key} receive the
|
|
29
|
+
* database's key prefix. The script's source and `ARGV` are sent unmodified,
|
|
30
|
+
* and Redis does not restrict scripts to `KEYS`: any key referenced in another
|
|
31
|
+
* way accesses the server's unprefixed keyspace outside this database's
|
|
32
|
+
* isolation (potentially colliding with another database on the same server).
|
|
33
|
+
* Always pass every key a script accesses through `KEYS`.
|
|
34
34
|
*/
|
|
35
35
|
export class Script {
|
|
36
|
-
/** The
|
|
36
|
+
/** The Lua source code of the script. */
|
|
37
37
|
readonly source: string;
|
|
38
|
-
/** Whether
|
|
38
|
+
/** Whether the script is read-only (see {@link Script.readOnly}). */
|
|
39
39
|
readonly isReadOnly: boolean = false;
|
|
40
40
|
/** The source's SHA-1, which the server caches the script under. */
|
|
41
41
|
private readonly hash: string;
|
|
42
42
|
|
|
43
|
-
/** Declares a script. */
|
|
43
|
+
/** Declares a Redis Lua script. */
|
|
44
44
|
constructor(source: string) {
|
|
45
45
|
this.source = source;
|
|
46
46
|
this.hash = createHash('sha1').update(source).digest('hex');
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
* Declares a
|
|
51
|
-
* which
|
|
50
|
+
* Declares a read-only Lua script. Redis rejects any write attempts during
|
|
51
|
+
* execution, which allows the script to run on read-only database handles.
|
|
52
52
|
*/
|
|
53
53
|
static readOnly(source: string): Script {
|
|
54
54
|
const script = new Script(source);
|
|
@@ -76,7 +76,10 @@ export class Script {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Builder for invoking a {@link Script}. Attach keys and arguments, then call
|
|
81
|
+
* {@link Invocation.invoke}.
|
|
82
|
+
*/
|
|
80
83
|
export class Invocation {
|
|
81
84
|
private readonly keys: string[] = [];
|
|
82
85
|
private readonly args: RedisArg[] = [];
|
|
@@ -89,19 +92,19 @@ export class Invocation {
|
|
|
89
92
|
private readonly readOnly: boolean,
|
|
90
93
|
) {}
|
|
91
94
|
|
|
92
|
-
/**
|
|
95
|
+
/** Appends a key to the script's `KEYS` array, applying the database's key prefix. */
|
|
93
96
|
key(key: string): this {
|
|
94
97
|
this.keys.push(key);
|
|
95
98
|
return this;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
|
-
/**
|
|
101
|
+
/** Appends an argument to the script's `ARGV` array. */
|
|
99
102
|
arg(arg: RedisArg): this {
|
|
100
103
|
this.args.push(arg);
|
|
101
104
|
return this;
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
/**
|
|
107
|
+
/** Executes the script and returns its reply. */
|
|
105
108
|
invoke(): ReplyPromise {
|
|
106
109
|
return new ReplyPromise(this.run());
|
|
107
110
|
}
|
|
@@ -110,7 +113,7 @@ export class Invocation {
|
|
|
110
113
|
try {
|
|
111
114
|
if (this.readOnly && !this.script.isReadOnly) {
|
|
112
115
|
throw new Error(
|
|
113
|
-
'redis:
|
|
116
|
+
'redis: read-only handles can only run scripts declared with Script.readOnly',
|
|
114
117
|
);
|
|
115
118
|
}
|
|
116
119
|
const reply = await this.t.run(
|
|
@@ -129,7 +132,10 @@ export class Invocation {
|
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
|
|
132
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Builder for queueing a {@link Script} invocation on a pipeline or
|
|
137
|
+
* transaction.
|
|
138
|
+
*/
|
|
133
139
|
export class QueuedInvocation {
|
|
134
140
|
private readonly keys: string[] = [];
|
|
135
141
|
private readonly args: RedisArg[] = [];
|
|
@@ -140,21 +146,22 @@ export class QueuedInvocation {
|
|
|
140
146
|
private readonly script: Script,
|
|
141
147
|
) {}
|
|
142
148
|
|
|
143
|
-
/**
|
|
149
|
+
/** Appends a key to the script's `KEYS` array, applying the database's key prefix. */
|
|
144
150
|
key(key: string): this {
|
|
145
151
|
this.keys.push(key);
|
|
146
152
|
return this;
|
|
147
153
|
}
|
|
148
154
|
|
|
149
|
-
/**
|
|
155
|
+
/** Appends an argument to the script's `ARGV` array. */
|
|
150
156
|
arg(arg: RedisArg): this {
|
|
151
157
|
this.args.push(arg);
|
|
152
158
|
return this;
|
|
153
159
|
}
|
|
154
160
|
|
|
155
161
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
162
|
+
* Appends the script invocation to the pipeline or transaction queue. Queued
|
|
163
|
+
* scripts are sent by source rather than hash, because a batch cannot pause
|
|
164
|
+
* midway to upload a script the server has not cached.
|
|
158
165
|
*/
|
|
159
166
|
queue(): void {
|
|
160
167
|
this.queued.push(this.script.command(false, this.keys, this.args));
|