@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.
Files changed (235) hide show
  1. package/README.md +111 -101
  2. package/app_meta.ts +56 -54
  3. package/config/config.ts +60 -57
  4. package/config/secrets.ts +45 -52
  5. package/config/value.ts +23 -26
  6. package/cron/mod.ts +28 -29
  7. package/dist/app_meta.d.ts +52 -50
  8. package/dist/app_meta.d.ts.map +1 -1
  9. package/dist/app_meta.js +2 -2
  10. package/dist/app_meta.js.map +1 -1
  11. package/dist/config/config.d.ts +58 -55
  12. package/dist/config/config.d.ts.map +1 -1
  13. package/dist/config/config.js +8 -9
  14. package/dist/config/config.js.map +1 -1
  15. package/dist/config/secrets.d.ts +45 -52
  16. package/dist/config/secrets.d.ts.map +1 -1
  17. package/dist/config/secrets.js +8 -9
  18. package/dist/config/secrets.js.map +1 -1
  19. package/dist/config/value.d.ts +20 -23
  20. package/dist/config/value.d.ts.map +1 -1
  21. package/dist/config/value.js +20 -23
  22. package/dist/config/value.js.map +1 -1
  23. package/dist/cron/mod.d.ts +26 -27
  24. package/dist/cron/mod.d.ts.map +1 -1
  25. package/dist/cron/mod.js +13 -14
  26. package/dist/cron/mod.js.map +1 -1
  27. package/dist/frontends/mod.d.ts +20 -19
  28. package/dist/frontends/mod.d.ts.map +1 -1
  29. package/dist/frontends/mod.js +20 -19
  30. package/dist/frontends/mod.js.map +1 -1
  31. package/dist/gateway/errors.d.ts +28 -30
  32. package/dist/gateway/errors.d.ts.map +1 -1
  33. package/dist/gateway/errors.js +29 -31
  34. package/dist/gateway/errors.js.map +1 -1
  35. package/dist/gateway/match.d.ts +54 -54
  36. package/dist/gateway/match.d.ts.map +1 -1
  37. package/dist/gateway/match.js +56 -56
  38. package/dist/gateway/match.js.map +1 -1
  39. package/dist/gateway/middleware.d.ts +62 -64
  40. package/dist/gateway/middleware.d.ts.map +1 -1
  41. package/dist/gateway/middleware.js +1 -1
  42. package/dist/gateway/middleware.js.map +1 -1
  43. package/dist/gateway/mod.d.ts +64 -67
  44. package/dist/gateway/mod.d.ts.map +1 -1
  45. package/dist/gateway/mod.js +72 -76
  46. package/dist/gateway/mod.js.map +1 -1
  47. package/dist/gateway/request.d.ts +138 -134
  48. package/dist/gateway/request.d.ts.map +1 -1
  49. package/dist/gateway/request.js +117 -108
  50. package/dist/gateway/request.js.map +1 -1
  51. package/dist/gateway/serve.d.ts +29 -34
  52. package/dist/gateway/serve.d.ts.map +1 -1
  53. package/dist/gateway/serve.js +51 -56
  54. package/dist/gateway/serve.js.map +1 -1
  55. package/dist/gateways/mod.d.ts +23 -21
  56. package/dist/gateways/mod.d.ts.map +1 -1
  57. package/dist/gateways/mod.js +25 -23
  58. package/dist/gateways/mod.js.map +1 -1
  59. package/dist/internal/runtime/napi/napi.cjs +1 -1
  60. package/dist/internal/runtime/napi/napi.d.cts +10 -3
  61. package/dist/internal/runtime/shutdown.d.ts +75 -57
  62. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  63. package/dist/internal/runtime/shutdown.js +88 -84
  64. package/dist/internal/runtime/shutdown.js.map +1 -1
  65. package/dist/log/logger.d.ts +43 -37
  66. package/dist/log/logger.d.ts.map +1 -1
  67. package/dist/log/logger.js +26 -25
  68. package/dist/log/logger.js.map +1 -1
  69. package/dist/metrics/mod.d.ts +133 -114
  70. package/dist/metrics/mod.d.ts.map +1 -1
  71. package/dist/metrics/mod.js +109 -101
  72. package/dist/metrics/mod.js.map +1 -1
  73. package/dist/otel.d.ts +6 -3
  74. package/dist/otel.d.ts.map +1 -1
  75. package/dist/otel.js +6 -3
  76. package/dist/otel.js.map +1 -1
  77. package/dist/pubsub/subscription.d.ts +88 -116
  78. package/dist/pubsub/subscription.d.ts.map +1 -1
  79. package/dist/pubsub/subscription.js +14 -17
  80. package/dist/pubsub/subscription.js.map +1 -1
  81. package/dist/pubsub/topic.d.ts +86 -113
  82. package/dist/pubsub/topic.d.ts.map +1 -1
  83. package/dist/pubsub/topic.js +68 -82
  84. package/dist/pubsub/topic.js.map +1 -1
  85. package/dist/reqctx/mod.d.ts +83 -86
  86. package/dist/reqctx/mod.d.ts.map +1 -1
  87. package/dist/reqctx/mod.js +39 -41
  88. package/dist/reqctx/mod.js.map +1 -1
  89. package/dist/services/index.d.ts +76 -75
  90. package/dist/services/index.d.ts.map +1 -1
  91. package/dist/services/index.js +73 -71
  92. package/dist/services/index.js.map +1 -1
  93. package/dist/shutdown/mod.d.ts +26 -25
  94. package/dist/shutdown/mod.d.ts.map +1 -1
  95. package/dist/shutdown/mod.js +26 -25
  96. package/dist/shutdown/mod.js.map +1 -1
  97. package/dist/storage/clickhouse/database.d.ts +113 -115
  98. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  99. package/dist/storage/clickhouse/database.js +65 -79
  100. package/dist/storage/clickhouse/database.js.map +1 -1
  101. package/dist/storage/clickhouse/errors.d.ts +25 -26
  102. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  103. package/dist/storage/clickhouse/errors.js +15 -17
  104. package/dist/storage/clickhouse/errors.js.map +1 -1
  105. package/dist/storage/clickhouse/mod.d.ts +10 -10
  106. package/dist/storage/clickhouse/mod.js +10 -10
  107. package/dist/storage/objects/bucket.d.ts +196 -225
  108. package/dist/storage/objects/bucket.d.ts.map +1 -1
  109. package/dist/storage/objects/bucket.js +71 -84
  110. package/dist/storage/objects/bucket.js.map +1 -1
  111. package/dist/storage/objects/error.d.ts +4 -4
  112. package/dist/storage/objects/error.js +4 -4
  113. package/dist/storage/postgres/database.d.ts +124 -149
  114. package/dist/storage/postgres/database.d.ts.map +1 -1
  115. package/dist/storage/postgres/database.js +98 -135
  116. package/dist/storage/postgres/database.js.map +1 -1
  117. package/dist/storage/postgres/errors.d.ts +42 -48
  118. package/dist/storage/postgres/errors.d.ts.map +1 -1
  119. package/dist/storage/postgres/errors.js +44 -51
  120. package/dist/storage/postgres/errors.js.map +1 -1
  121. package/dist/storage/postgres/interval.d.ts +19 -19
  122. package/dist/storage/postgres/interval.d.ts.map +1 -1
  123. package/dist/storage/postgres/interval.js +21 -21
  124. package/dist/storage/postgres/interval.js.map +1 -1
  125. package/dist/storage/redis/bitfield.d.ts +48 -23
  126. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  127. package/dist/storage/redis/bitfield.js +38 -19
  128. package/dist/storage/redis/bitfield.js.map +1 -1
  129. package/dist/storage/redis/command.d.ts +16 -12
  130. package/dist/storage/redis/command.d.ts.map +1 -1
  131. package/dist/storage/redis/command.js +16 -12
  132. package/dist/storage/redis/command.js.map +1 -1
  133. package/dist/storage/redis/commands.d.ts +99 -100
  134. package/dist/storage/redis/commands.d.ts.map +1 -1
  135. package/dist/storage/redis/commands.js +84 -85
  136. package/dist/storage/redis/commands.js.map +1 -1
  137. package/dist/storage/redis/database.d.ts +138 -122
  138. package/dist/storage/redis/database.d.ts.map +1 -1
  139. package/dist/storage/redis/database.js +120 -101
  140. package/dist/storage/redis/database.js.map +1 -1
  141. package/dist/storage/redis/mod.d.ts +52 -48
  142. package/dist/storage/redis/mod.d.ts.map +1 -1
  143. package/dist/storage/redis/mod.js +52 -48
  144. package/dist/storage/redis/mod.js.map +1 -1
  145. package/dist/storage/redis/options.d.ts +26 -24
  146. package/dist/storage/redis/options.d.ts.map +1 -1
  147. package/dist/storage/redis/options.js.map +1 -1
  148. package/dist/storage/redis/pubsub.d.ts +16 -16
  149. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  150. package/dist/storage/redis/pubsub.js +14 -14
  151. package/dist/storage/redis/pubsub.js.map +1 -1
  152. package/dist/storage/redis/reply.d.ts +80 -72
  153. package/dist/storage/redis/reply.d.ts.map +1 -1
  154. package/dist/storage/redis/reply.js +53 -46
  155. package/dist/storage/redis/reply.js.map +1 -1
  156. package/dist/storage/redis/scan.d.ts +4 -4
  157. package/dist/storage/redis/scan.d.ts.map +1 -1
  158. package/dist/storage/redis/scan.js +6 -6
  159. package/dist/storage/redis/scan.js.map +1 -1
  160. package/dist/storage/redis/script.d.ts +28 -21
  161. package/dist/storage/redis/script.d.ts.map +1 -1
  162. package/dist/storage/redis/script.js +29 -22
  163. package/dist/storage/redis/script.js.map +1 -1
  164. package/dist/storage/redis/target.d.ts +17 -1
  165. package/dist/storage/redis/target.d.ts.map +1 -1
  166. package/dist/storage/redis/target.js +30 -1
  167. package/dist/storage/redis/target.js.map +1 -1
  168. package/dist/storage/redis/wire.d.ts +6 -6
  169. package/dist/storage/redis/wire.d.ts.map +1 -1
  170. package/dist/storage/redis/wire.js +6 -6
  171. package/dist/storage/redis/wire.js.map +1 -1
  172. package/dist/testing/mod.d.ts +83 -88
  173. package/dist/testing/mod.d.ts.map +1 -1
  174. package/dist/testing/mod.js +75 -81
  175. package/dist/testing/mod.js.map +1 -1
  176. package/dist/testing/playwright.d.ts +28 -32
  177. package/dist/testing/playwright.d.ts.map +1 -1
  178. package/dist/testing/playwright.js +22 -27
  179. package/dist/testing/playwright.js.map +1 -1
  180. package/dist/testing/puppeteer.d.ts +11 -12
  181. package/dist/testing/puppeteer.d.ts.map +1 -1
  182. package/dist/testing/puppeteer.js +17 -18
  183. package/dist/testing/puppeteer.js.map +1 -1
  184. package/dist/testing/system.d.ts +72 -90
  185. package/dist/testing/system.d.ts.map +1 -1
  186. package/dist/testing/system.js +90 -107
  187. package/dist/testing/system.js.map +1 -1
  188. package/dist/tsconfig.build.tsbuildinfo +1 -1
  189. package/frontends/mod.test.ts +6 -2
  190. package/frontends/mod.ts +20 -19
  191. package/gateway/errors.ts +30 -32
  192. package/gateway/match.ts +61 -57
  193. package/gateway/middleware.ts +62 -64
  194. package/gateway/mod.ts +73 -76
  195. package/gateway/request.ts +143 -140
  196. package/gateway/serve.ts +58 -63
  197. package/gateways/mod.ts +25 -23
  198. package/internal/runtime/napi/napi.cjs +1 -1
  199. package/internal/runtime/napi/napi.d.cts +10 -3
  200. package/internal/runtime/shutdown.ts +113 -101
  201. package/log/logger.test.ts +8 -0
  202. package/log/logger.ts +48 -45
  203. package/metrics/mod.ts +138 -122
  204. package/otel.ts +6 -3
  205. package/package.json +1 -1
  206. package/pubsub/subscription.ts +93 -123
  207. package/pubsub/topic.ts +96 -130
  208. package/reqctx/mod.ts +83 -86
  209. package/services/index.ts +78 -78
  210. package/shutdown/mod.ts +26 -25
  211. package/storage/clickhouse/database.ts +115 -129
  212. package/storage/clickhouse/errors.ts +27 -29
  213. package/storage/clickhouse/mod.ts +10 -10
  214. package/storage/objects/bucket.ts +209 -239
  215. package/storage/objects/error.ts +4 -4
  216. package/storage/postgres/database.ts +131 -164
  217. package/storage/postgres/errors.ts +45 -52
  218. package/storage/postgres/interval.ts +21 -21
  219. package/storage/redis/bitfield.ts +51 -26
  220. package/storage/redis/command.ts +16 -12
  221. package/storage/redis/commands.ts +99 -100
  222. package/storage/redis/database.ts +145 -123
  223. package/storage/redis/mod.ts +52 -48
  224. package/storage/redis/options.ts +26 -24
  225. package/storage/redis/pubsub.ts +14 -14
  226. package/storage/redis/redis.test.ts +17 -2
  227. package/storage/redis/reply.ts +85 -77
  228. package/storage/redis/scan.ts +6 -6
  229. package/storage/redis/script.ts +29 -22
  230. package/storage/redis/target.ts +34 -1
  231. package/storage/redis/wire.ts +8 -8
  232. package/testing/mod.ts +99 -105
  233. package/testing/playwright.ts +32 -37
  234. package/testing/puppeteer.ts +22 -23
  235. package/testing/system.ts +117 -133
@@ -1,9 +1,10 @@
1
1
  import {MapReply, ServerError, Status, Value} from './wire';
2
2
 
3
3
  /**
4
- * A reply as plain values: what {@link Reply.value} returns. A string reply is
5
- * text, an integer a `number` (a `bigint` past what a `number` holds exactly),
6
- * a map an object keyed by its keys' text, with no prototype.
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 member of a sorted set, with its score. */
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 of a hash, with its value. */
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
- /** An entry of a stream: its id and its fields. */
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
- /** The entries read from one stream. */
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
- * The summary of what a consumer group has been given and not acknowledged,
43
- * as `xpending` replies.
43
+ * Summary of pending (unacknowledged) entries for a consumer group, as
44
+ * returned by `xpending`.
44
45
  */
45
46
  export interface StreamPending {
46
- /** How many entries are pending. */
47
+ /** Number of pending entries. */
47
48
  count: number;
48
- /** The lowest pending id: `null` when nothing is pending. */
49
+ /** Lowest pending entry ID, or `null` if no entries are pending. */
49
50
  lowest: string | null;
50
- /** The highest pending id: `null` when nothing is pending. */
51
+ /** Highest pending entry ID, or `null` if no entries are pending. */
51
52
  highest: string | null;
52
- /** The consumers with pending entries, and how many each has. */
53
+ /** Consumers with pending entries and the pending count for each. */
53
54
  consumers: {name: string; pending: number}[];
54
55
  }
55
56
 
56
- /** What the server knows about a stream, as `xinfoStream` replies. */
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` for an empty stream. */
64
+ /** The first entry in the stream, or `null` if the stream is empty. */
64
65
  firstEntry: StreamEntry | null;
65
- /** `null` for an empty stream. */
66
+ /** The last entry in the stream, or `null` if the stream is empty. */
66
67
  lastEntry: StreamEntry | null;
67
68
  }
68
69
 
69
- /** What `xautoclaim` replies. */
70
+ /** Result of an `xautoclaim` command. */
70
71
  export interface StreamAutoClaim {
71
72
  /**
72
- * The id to pass as the next call's start, or `"0-0"` when the scan of
73
- * pending entries is done.
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 now held by the consumer. */
77
+ /** The entries successfully claimed by the consumer. */
77
78
  claimed: StreamEntry[];
78
- /** The ids of pending entries that no longer exist. */
79
+ /** IDs of pending entries that no longer exist in the stream. */
79
80
  deleted: string[];
80
81
  }
81
82
 
82
83
  /**
83
- * What a blocking pop of one element replies: the key it came from, without
84
- * the database's prefix, and the element.
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
- /** What a blocking pop of several elements replies, in the order popped. */
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
- /** What a blocking pop of a sorted set's member replies. */
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
- /** What a blocking pop of several of a sorted set's members replies. */
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
- /** A position on Earth. */
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 found by a radius search, with what the search asked for of it. */
117
+ /** A member matched by a geo radius search, with any requested metadata. */
117
118
  export interface GeoRadiusResult {
118
119
  name: string;
119
- /** The distance from the center, with `withDist`. */
120
+ /** Distance from the search center (present when `withDist` is enabled). */
120
121
  dist?: number;
121
- /** The member's geohash as an integer, with `withHash`. */
122
+ /** Geohash integer of the member (present when `withHash` is enabled). */
122
123
  hash?: bigint;
123
- /** The member's position, with `withCoord`. */
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 array of ${items.length} elements is not pairs`,
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 array of ${items.length} elements is not members and scores`,
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
- * What Redis replied to a command, or the error the command failed with. Read
299
- * it as what it holds: {@link Reply.text}, {@link Reply.number},
300
- * {@link Reply.textMap}, …; each throws the command's error if it failed, and
301
- * reads a nil reply as `null`.
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 it did. A nil reply is not one. */
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
- /** Whether the command succeeded and replied nil. */
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
- /** The reply as plain values. */
334
+ /** Decodes the reply as plain JavaScript values. */
334
335
  value(): RedisValue {
335
336
  return plain(this.v);
336
337
  }
337
338
 
338
- /** The reply as text: a string's bytes as UTF-8, or a number's digits. */
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
- /** The reply as bytes. */
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
- * The reply as a number, parsing a string that holds one. An integer past
352
- * what a `number` holds exactly is rounded: read it with
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
- /** The reply as an integer, parsing a string that holds one. */
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
- /** The reply as a boolean: an integer is true unless 0, and `OK` is true. */
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
- /** The reply's text, parsed as JSON. */
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
- /** An array reply as each of its elements, to read each as what it holds. */
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
- * An array reply as text. A nil element throws; to tell missing elements
382
- * apart, use {@link Reply.optionalTexts}.
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 is not text');
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
- * An array reply as text, a nil element as `null`: what `mget` and `hmget`
394
- * reply for a missing key or field.
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
- /** An array reply as numbers. */
401
+ /** Decodes an array reply as numbers. */
401
402
  numbers(): number[] {
402
403
  return arrayOf(this.v).map(numberOf);
403
404
  }
404
405
 
405
- /** An array reply as booleans. */
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
- * A map reply, or an array of keys and values in turn, as an object: what
412
- * `hgetall` replies. The object has no prototype, so each field is its own
413
- * key, `__proto__` too.
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
- * The members of a sorted set with their scores, as `zrangeWithscores` and
421
- * `zpopmin` reply.
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
- * The entries of a stream, as `xrange`, `xrevrange` and `xclaim` reply.
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
- * The entries read from each stream, as `xread` and `xreadGroup` reply. A
436
- * read that found nothing is no streams.
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
- /** The reply of `xpending`. */
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
- /** The reply of `xinfoStream`. */
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
- /** The reply of `xautoclaim`. */
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
- /** The position of each member, a missing one as `null`, as `geoPos` replies. */
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
- /** The members a radius search found, as `geoRadius` replies. */
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's reply, on its way. Await it for the {@link Reply}, which
555
- * rejects if the command failed; or read it as what it holds straight away:
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 it is called, whether or not this is awaited.
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
- * The error a pipeline or a transaction fails with when the server rejected
697
- * some of its commands. The others ran: Redis has no rollback.
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
- /** Every command's reply, in the order queued, each holding its own error. */
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: a pop replied ${parts.length} values, not ${n}`,
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: the command replied nil');
787
+ throw new TypeError('redis: command returned an unexpected nil reply');
780
788
  }
@@ -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's keys. */
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's members. */
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 a hash's fields, each with its value. */
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
- "redis: the scan's reply does not divide into fields and values",
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 a sorted set's members, each with its score. */
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: a scan replied something other than a cursor and a batch',
114
+ 'redis: unexpected scan reply format; expected a cursor and a batch',
115
115
  );
116
116
  }
117
117
  cursor = textOf(parts[0]);
@@ -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 the database runs, declared at module scope.
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 the keys passed through `KEYS`, with {@link Invocation.key}, get the
29
- * database's key prefix. The script's source and its `ARGV` are sent as they
30
- * are, and Redis cannot hold a script to `KEYS`: a key it names any other way
31
- * is the server's key of that name, unprefixed, outside this database's
32
- * isolation, which can be another database's on the same server. So a script
33
- * must take every key it touches through `KEYS`.
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 script's source. */
36
+ /** The Lua source code of the script. */
37
37
  readonly source: string;
38
- /** Whether it only reads: see {@link Script.readOnly}. */
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 script that only reads. The server refuses to let it write,
51
- * which is what lets it run on a handle that can only read.
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
- /** A call to a {@link Script}, to give its keys and arguments and then invoke. */
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
- /** A key the script works on: the next of its `KEYS`. */
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
- /** An argument: the next of the script's `ARGV`. */
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
- /** Runs the script, replying what it returns. */
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: a handle that can only read runs only scripts declared with Script.readOnly',
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
- /** A call to a {@link Script} being queued on a pipeline or a transaction. */
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
- /** A key the script works on: the next of its `KEYS`. */
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
- /** An argument: the next of the script's `ARGV`. */
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
- * Queues the call. It is sent by source rather than by hash: a batch cannot
157
- * stop halfway to send a script the server turns out not to have.
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));