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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +111 -101
  2. package/app_meta.ts +56 -54
  3. package/config/config.ts +60 -57
  4. package/config/secrets.ts +45 -52
  5. package/config/value.ts +23 -26
  6. package/cron/mod.ts +28 -29
  7. package/dist/app_meta.d.ts +52 -50
  8. package/dist/app_meta.d.ts.map +1 -1
  9. package/dist/app_meta.js +2 -2
  10. package/dist/app_meta.js.map +1 -1
  11. package/dist/config/config.d.ts +58 -55
  12. package/dist/config/config.d.ts.map +1 -1
  13. package/dist/config/config.js +8 -9
  14. package/dist/config/config.js.map +1 -1
  15. package/dist/config/secrets.d.ts +45 -52
  16. package/dist/config/secrets.d.ts.map +1 -1
  17. package/dist/config/secrets.js +8 -9
  18. package/dist/config/secrets.js.map +1 -1
  19. package/dist/config/value.d.ts +20 -23
  20. package/dist/config/value.d.ts.map +1 -1
  21. package/dist/config/value.js +20 -23
  22. package/dist/config/value.js.map +1 -1
  23. package/dist/cron/mod.d.ts +26 -27
  24. package/dist/cron/mod.d.ts.map +1 -1
  25. package/dist/cron/mod.js +13 -14
  26. package/dist/cron/mod.js.map +1 -1
  27. package/dist/frontends/mod.d.ts +20 -19
  28. package/dist/frontends/mod.d.ts.map +1 -1
  29. package/dist/frontends/mod.js +20 -19
  30. package/dist/frontends/mod.js.map +1 -1
  31. package/dist/gateway/errors.d.ts +28 -30
  32. package/dist/gateway/errors.d.ts.map +1 -1
  33. package/dist/gateway/errors.js +29 -31
  34. package/dist/gateway/errors.js.map +1 -1
  35. package/dist/gateway/match.d.ts +54 -54
  36. package/dist/gateway/match.d.ts.map +1 -1
  37. package/dist/gateway/match.js +56 -56
  38. package/dist/gateway/match.js.map +1 -1
  39. package/dist/gateway/middleware.d.ts +62 -64
  40. package/dist/gateway/middleware.d.ts.map +1 -1
  41. package/dist/gateway/middleware.js +1 -1
  42. package/dist/gateway/middleware.js.map +1 -1
  43. package/dist/gateway/mod.d.ts +64 -67
  44. package/dist/gateway/mod.d.ts.map +1 -1
  45. package/dist/gateway/mod.js +72 -76
  46. package/dist/gateway/mod.js.map +1 -1
  47. package/dist/gateway/request.d.ts +138 -134
  48. package/dist/gateway/request.d.ts.map +1 -1
  49. package/dist/gateway/request.js +117 -108
  50. package/dist/gateway/request.js.map +1 -1
  51. package/dist/gateway/serve.d.ts +29 -34
  52. package/dist/gateway/serve.d.ts.map +1 -1
  53. package/dist/gateway/serve.js +51 -56
  54. package/dist/gateway/serve.js.map +1 -1
  55. package/dist/gateways/mod.d.ts +23 -21
  56. package/dist/gateways/mod.d.ts.map +1 -1
  57. package/dist/gateways/mod.js +25 -23
  58. package/dist/gateways/mod.js.map +1 -1
  59. package/dist/internal/runtime/napi/napi.cjs +1 -1
  60. package/dist/internal/runtime/napi/napi.d.cts +10 -3
  61. package/dist/internal/runtime/shutdown.d.ts +75 -57
  62. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  63. package/dist/internal/runtime/shutdown.js +88 -84
  64. package/dist/internal/runtime/shutdown.js.map +1 -1
  65. package/dist/log/logger.d.ts +43 -37
  66. package/dist/log/logger.d.ts.map +1 -1
  67. package/dist/log/logger.js +26 -25
  68. package/dist/log/logger.js.map +1 -1
  69. package/dist/metrics/mod.d.ts +133 -114
  70. package/dist/metrics/mod.d.ts.map +1 -1
  71. package/dist/metrics/mod.js +109 -101
  72. package/dist/metrics/mod.js.map +1 -1
  73. package/dist/otel.d.ts +6 -3
  74. package/dist/otel.d.ts.map +1 -1
  75. package/dist/otel.js +6 -3
  76. package/dist/otel.js.map +1 -1
  77. package/dist/pubsub/subscription.d.ts +88 -116
  78. package/dist/pubsub/subscription.d.ts.map +1 -1
  79. package/dist/pubsub/subscription.js +14 -17
  80. package/dist/pubsub/subscription.js.map +1 -1
  81. package/dist/pubsub/topic.d.ts +86 -113
  82. package/dist/pubsub/topic.d.ts.map +1 -1
  83. package/dist/pubsub/topic.js +68 -82
  84. package/dist/pubsub/topic.js.map +1 -1
  85. package/dist/reqctx/mod.d.ts +83 -86
  86. package/dist/reqctx/mod.d.ts.map +1 -1
  87. package/dist/reqctx/mod.js +39 -41
  88. package/dist/reqctx/mod.js.map +1 -1
  89. package/dist/services/index.d.ts +76 -75
  90. package/dist/services/index.d.ts.map +1 -1
  91. package/dist/services/index.js +73 -71
  92. package/dist/services/index.js.map +1 -1
  93. package/dist/shutdown/mod.d.ts +26 -25
  94. package/dist/shutdown/mod.d.ts.map +1 -1
  95. package/dist/shutdown/mod.js +26 -25
  96. package/dist/shutdown/mod.js.map +1 -1
  97. package/dist/storage/clickhouse/database.d.ts +113 -115
  98. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  99. package/dist/storage/clickhouse/database.js +65 -79
  100. package/dist/storage/clickhouse/database.js.map +1 -1
  101. package/dist/storage/clickhouse/errors.d.ts +25 -26
  102. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  103. package/dist/storage/clickhouse/errors.js +15 -17
  104. package/dist/storage/clickhouse/errors.js.map +1 -1
  105. package/dist/storage/clickhouse/mod.d.ts +10 -10
  106. package/dist/storage/clickhouse/mod.js +10 -10
  107. package/dist/storage/objects/bucket.d.ts +196 -225
  108. package/dist/storage/objects/bucket.d.ts.map +1 -1
  109. package/dist/storage/objects/bucket.js +71 -84
  110. package/dist/storage/objects/bucket.js.map +1 -1
  111. package/dist/storage/objects/error.d.ts +4 -4
  112. package/dist/storage/objects/error.js +4 -4
  113. package/dist/storage/postgres/database.d.ts +124 -149
  114. package/dist/storage/postgres/database.d.ts.map +1 -1
  115. package/dist/storage/postgres/database.js +98 -135
  116. package/dist/storage/postgres/database.js.map +1 -1
  117. package/dist/storage/postgres/errors.d.ts +42 -48
  118. package/dist/storage/postgres/errors.d.ts.map +1 -1
  119. package/dist/storage/postgres/errors.js +44 -51
  120. package/dist/storage/postgres/errors.js.map +1 -1
  121. package/dist/storage/postgres/interval.d.ts +19 -19
  122. package/dist/storage/postgres/interval.d.ts.map +1 -1
  123. package/dist/storage/postgres/interval.js +21 -21
  124. package/dist/storage/postgres/interval.js.map +1 -1
  125. package/dist/storage/redis/bitfield.d.ts +48 -23
  126. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  127. package/dist/storage/redis/bitfield.js +38 -19
  128. package/dist/storage/redis/bitfield.js.map +1 -1
  129. package/dist/storage/redis/command.d.ts +16 -12
  130. package/dist/storage/redis/command.d.ts.map +1 -1
  131. package/dist/storage/redis/command.js +16 -12
  132. package/dist/storage/redis/command.js.map +1 -1
  133. package/dist/storage/redis/commands.d.ts +99 -100
  134. package/dist/storage/redis/commands.d.ts.map +1 -1
  135. package/dist/storage/redis/commands.js +84 -85
  136. package/dist/storage/redis/commands.js.map +1 -1
  137. package/dist/storage/redis/database.d.ts +138 -122
  138. package/dist/storage/redis/database.d.ts.map +1 -1
  139. package/dist/storage/redis/database.js +120 -101
  140. package/dist/storage/redis/database.js.map +1 -1
  141. package/dist/storage/redis/mod.d.ts +52 -48
  142. package/dist/storage/redis/mod.d.ts.map +1 -1
  143. package/dist/storage/redis/mod.js +52 -48
  144. package/dist/storage/redis/mod.js.map +1 -1
  145. package/dist/storage/redis/options.d.ts +26 -24
  146. package/dist/storage/redis/options.d.ts.map +1 -1
  147. package/dist/storage/redis/options.js.map +1 -1
  148. package/dist/storage/redis/pubsub.d.ts +16 -16
  149. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  150. package/dist/storage/redis/pubsub.js +14 -14
  151. package/dist/storage/redis/pubsub.js.map +1 -1
  152. package/dist/storage/redis/reply.d.ts +80 -72
  153. package/dist/storage/redis/reply.d.ts.map +1 -1
  154. package/dist/storage/redis/reply.js +53 -46
  155. package/dist/storage/redis/reply.js.map +1 -1
  156. package/dist/storage/redis/scan.d.ts +4 -4
  157. package/dist/storage/redis/scan.d.ts.map +1 -1
  158. package/dist/storage/redis/scan.js +6 -6
  159. package/dist/storage/redis/scan.js.map +1 -1
  160. package/dist/storage/redis/script.d.ts +28 -21
  161. package/dist/storage/redis/script.d.ts.map +1 -1
  162. package/dist/storage/redis/script.js +29 -22
  163. package/dist/storage/redis/script.js.map +1 -1
  164. package/dist/storage/redis/target.d.ts +17 -1
  165. package/dist/storage/redis/target.d.ts.map +1 -1
  166. package/dist/storage/redis/target.js +30 -1
  167. package/dist/storage/redis/target.js.map +1 -1
  168. package/dist/storage/redis/wire.d.ts +6 -6
  169. package/dist/storage/redis/wire.d.ts.map +1 -1
  170. package/dist/storage/redis/wire.js +6 -6
  171. package/dist/storage/redis/wire.js.map +1 -1
  172. package/dist/testing/mod.d.ts +83 -88
  173. package/dist/testing/mod.d.ts.map +1 -1
  174. package/dist/testing/mod.js +75 -81
  175. package/dist/testing/mod.js.map +1 -1
  176. package/dist/testing/playwright.d.ts +28 -32
  177. package/dist/testing/playwright.d.ts.map +1 -1
  178. package/dist/testing/playwright.js +22 -27
  179. package/dist/testing/playwright.js.map +1 -1
  180. package/dist/testing/puppeteer.d.ts +11 -12
  181. package/dist/testing/puppeteer.d.ts.map +1 -1
  182. package/dist/testing/puppeteer.js +17 -18
  183. package/dist/testing/puppeteer.js.map +1 -1
  184. package/dist/testing/system.d.ts +72 -90
  185. package/dist/testing/system.d.ts.map +1 -1
  186. package/dist/testing/system.js +90 -107
  187. package/dist/testing/system.js.map +1 -1
  188. package/dist/tsconfig.build.tsbuildinfo +1 -1
  189. package/frontends/mod.test.ts +6 -2
  190. package/frontends/mod.ts +20 -19
  191. package/gateway/errors.ts +30 -32
  192. package/gateway/match.ts +61 -57
  193. package/gateway/middleware.ts +62 -64
  194. package/gateway/mod.ts +73 -76
  195. package/gateway/request.ts +143 -140
  196. package/gateway/serve.ts +58 -63
  197. package/gateways/mod.ts +25 -23
  198. package/internal/runtime/napi/napi.cjs +1 -1
  199. package/internal/runtime/napi/napi.d.cts +10 -3
  200. package/internal/runtime/shutdown.ts +113 -101
  201. package/log/logger.test.ts +8 -0
  202. package/log/logger.ts +48 -45
  203. package/metrics/mod.ts +138 -122
  204. package/otel.ts +6 -3
  205. package/package.json +1 -1
  206. package/pubsub/subscription.ts +93 -123
  207. package/pubsub/topic.ts +96 -130
  208. package/reqctx/mod.ts +83 -86
  209. package/services/index.ts +78 -78
  210. package/shutdown/mod.ts +26 -25
  211. package/storage/clickhouse/database.ts +115 -129
  212. package/storage/clickhouse/errors.ts +27 -29
  213. package/storage/clickhouse/mod.ts +10 -10
  214. package/storage/objects/bucket.ts +209 -239
  215. package/storage/objects/error.ts +4 -4
  216. package/storage/postgres/database.ts +131 -164
  217. package/storage/postgres/errors.ts +45 -52
  218. package/storage/postgres/interval.ts +21 -21
  219. package/storage/redis/bitfield.ts +51 -26
  220. package/storage/redis/command.ts +16 -12
  221. package/storage/redis/commands.ts +99 -100
  222. package/storage/redis/database.ts +145 -123
  223. package/storage/redis/mod.ts +52 -48
  224. package/storage/redis/options.ts +26 -24
  225. package/storage/redis/pubsub.ts +14 -14
  226. package/storage/redis/redis.test.ts +17 -2
  227. package/storage/redis/reply.ts +85 -77
  228. package/storage/redis/scan.ts +6 -6
  229. package/storage/redis/script.ts +29 -22
  230. package/storage/redis/target.ts +34 -1
  231. package/storage/redis/wire.ts +8 -8
  232. package/testing/mod.ts +99 -105
  233. package/testing/playwright.ts +32 -37
  234. package/testing/puppeteer.ts +22 -23
  235. package/testing/system.ts +117 -133
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Redis databases. A database is declared at module scope; its connection pool
3
- * is built on first use and reused thereafter.
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
- * A database is a resource of its own: there is no cluster to put it in, and
17
- * no keyspaces to declare in it. Its keys are whatever the code passes.
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 the data type they work on, each group a property of
22
- * the database: `string`, `hash`, `list`, `set`, `sortedSet`, `stream`, `geo`,
23
- * `bitmap`, `hyperloglog`, `pubsub`, and `generic` for the ones that work on
24
- * any key. Within a
25
- * group a command is named after the Redis command it runs — `get`, `hset`,
26
- * `zadd`, `xadd` — with words of its own for its variants: `setEx`,
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
- * A command whose reply has one shape returns it: `strlen` a number,
30
- * `sismember` a boolean. One whose reply is the caller's to read returns a
31
- * {@link ReplyPromise}, read as what it holds:
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 reads as `null`.
39
+ * A missing key decodes as `null`.
40
40
  *
41
- * A command is called in the same expression that names its group. That is
42
- * what lets Encore grant each service exactly the access it uses: the command
43
- * is visible at the call, so Encore's parser can read it. A group that is
44
- * stored or passed on instead says nothing about what it will be used for, and
45
- * is reported as an error — to do that, start from a handle.
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
- * A command that waits for something to pop — `list.blpop`,
48
- * `sortedSet.bzpopmin`, `stream.xreadBlock` and the like — runs on a
49
- * connection of its own, so it holds up no other call. A timeout resolves to
50
- * `null`. These can't be queued, and don't run on an acquired connection.
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 the groups lack, by its name,
55
- * with the arguments that are keys marked:
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, which Encore reads to grant the access
62
- * the command needs. Before it is sent, the runtime checks it against Redis's
63
- * command table: each key it takes must be passed with `key`, and the commands
64
- * that would reach past the database, change a connection other calls share,
65
- * or have a call of their own here (`MULTI`, `SUBSCRIBE`, `EVAL`, `SCAN`,
66
- * `FLUSHALL`, …) fail with a `TypeError`. A handle that can only read sends
67
- * only the commands Redis says don't write.
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 database cannot be passed around as a value. To hand it to other code,
72
- * make a handle with the access that code needs — {@link Database.write},
73
- * {@link Database.read} or {@link Database.readPrimary} — which the service is
74
- * then granted in full:
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, and can only do what the handle allows.
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 prefix of the database's own, which is what
90
- * keeps databases sharing a server apart. It is applied to every key a command
91
- * takes and removed from every key a command returns, so code never sees it.
92
- * Two things follow:
93
- *
94
- * - a {@link Script}'s `KEYS` are prefixed, but nothing else in it is: a key
95
- * it names in its source or its `ARGV` is reached unprefixed, outside the
96
- * database's isolation, so a script must take its keys through `KEYS`;
97
- * - {@link DatabaseRef.connectionString} connects past the prefix, so a client
98
- * using it does not see the keys this SDK writes under the same names.
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,9 +1,10 @@
1
1
  import type {RedisArg} from './wire';
2
2
 
3
3
  /**
4
- * When a key `setOptions` sets expires: in seconds (`ex`) or milliseconds
5
- * (`px`), at a Unix time in seconds (`exAt`) or milliseconds (`pxAt`), or
6
- * keeping the expiry it has.
4
+ * Expiration setting for `setOptions`: expire after a relative duration in
5
+ * seconds (`ex`) or milliseconds (`px`), at a Unix timestamp in seconds
6
+ * (`exAt`) or milliseconds (`pxAt`), or preserve the key's existing expiration
7
+ * (`keepTtl`).
7
8
  */
8
9
  export type SetExpiry =
9
10
  | {ex: number}
@@ -12,25 +13,25 @@ export type SetExpiry =
12
13
  | {pxAt: number}
13
14
  | {keepTtl: true};
14
15
 
15
- /** How `setOptions` sets a key. */
16
+ /** Options for setting a key with `setOptions`. */
16
17
  export interface SetOptions {
17
18
  /**
18
- * When to set the key: only if it does not exist (`"nx"`), or only if it
19
- * does (`"xx"`).
19
+ * Condition for setting the key: only if it does not exist (`"nx"`), or only
20
+ * if it already exists (`"xx"`).
20
21
  */
21
22
  condition?: 'nx' | 'xx';
22
- /** Reply with the key's old value, or nil if it had none. */
23
+ /** Return the key's previous value, or `null` if it did not exist. */
23
24
  get?: boolean;
24
25
  /**
25
- * When the key expires. Without one it never does, and loses any expiry it
26
- * had.
26
+ * When the key should expire. If omitted, the key does not expire and any
27
+ * existing expiration is cleared.
27
28
  */
28
29
  expiry?: SetExpiry;
29
30
  }
30
31
 
31
32
  /**
32
- * How `getEx` changes a key's expiry: as {@link SetExpiry} says, or removing
33
- * it.
33
+ * Expiration update for `getEx`: set a new expiration as in {@link SetExpiry},
34
+ * or remove the existing expiration (`persist`).
34
35
  */
35
36
  export type Expiry =
36
37
  | {ex: number}
@@ -39,40 +40,41 @@ export type Expiry =
39
40
  | {pxAt: number}
40
41
  | {persist: true};
41
42
 
42
- /** An end of a list: its head, or its tail. */
43
+ /** The end of a list: its head (`"left"`) or its tail (`"right"`). */
43
44
  export type Direction = 'left' | 'right';
44
45
 
45
- /** A unit of distance: meters, kilometers, miles or feet. */
46
+ /** A unit of distance: meters, kilometers, miles, or feet. */
46
47
  export type Unit = 'm' | 'km' | 'mi' | 'ft';
47
48
 
48
- /** What a radius search returns of each member it finds, and how many. */
49
+ /** Options controlling which fields and how many results a geo radius search returns. */
49
50
  export interface RadiusOptions {
50
- /** Return each member's position. */
51
+ /** Include each member's longitude and latitude coordinates. */
51
52
  withCoord?: boolean;
52
- /** Return each member's distance from the center. */
53
+ /** Include each member's distance from the search center. */
53
54
  withDist?: boolean;
54
- /** Return each member's geohash, as an integer. */
55
+ /** Include each member's geohash integer. */
55
56
  withHash?: boolean;
56
- /** The most members to return. */
57
+ /** Maximum number of matching members to return. */
57
58
  count?: number;
58
- /** The nearest first (`"asc"`), or the farthest. In no order without. */
59
+ /** Sort order: nearest first (`"asc"`) or farthest first (`"desc"`). Unsorted if omitted. */
59
60
  order?: 'asc' | 'desc';
60
61
  }
61
62
 
62
63
  /**
63
- * The most entries a stream is trimmed to: exactly `maxlen`, or with `approx`
64
- * about that many, never fewer, which is cheaper.
64
+ * Maximum number of entries to keep when trimming a stream: exact (`approx`
65
+ * omitted or `false`), or approximate (`approx: true`), which keeps at least
66
+ * `maxlen` entries and is cheaper to compute.
65
67
  */
66
68
  export interface StreamMaxlen {
67
69
  maxlen: number;
68
70
  approx?: boolean;
69
71
  }
70
72
 
71
- /** What a scan looks through, and how much at a time. */
73
+ /** Options controlling what a scan matches and how much work it does per round trip. */
72
74
  export interface ScanOptions {
73
- /** Only what matches a glob-style pattern: `user:*`. */
75
+ /** Only return elements matching a glob-style pattern (for example, `user:*`). */
74
76
  pattern?: string;
75
- /** A hint for how many elements to look at per round trip. */
77
+ /** Hint for how many elements to inspect per round trip. */
76
78
  count?: number;
77
79
  }
78
80
 
@@ -9,32 +9,32 @@ import {encodeList} from './wire';
9
9
  export class Message {
10
10
  /** @internal */
11
11
  constructor(
12
- /** The channel it was published to. */
12
+ /** The channel the message was published to. */
13
13
  readonly channel: string,
14
- /** What was published, as it was sent. */
14
+ /** The raw message payload as published. */
15
15
  readonly payload: Buffer,
16
16
  ) {}
17
17
 
18
- /** The payload as UTF-8 text. */
18
+ /** Returns the payload decoded as UTF-8 text. */
19
19
  text(): string {
20
20
  return this.payload.toString('utf8');
21
21
  }
22
22
 
23
- /** The payload's text, parsed as JSON. */
23
+ /** Parses the UTF-8 payload as JSON. */
24
24
  json<T = unknown>(): T {
25
25
  return JSON.parse(this.text()) as T;
26
26
  }
27
27
  }
28
28
 
29
29
  /**
30
- * An open subscription, on a connection of its own: Redis's own channel
31
- * messaging, where a message reaches whoever is subscribed at that moment and
32
- * nobody else. For messages that are kept until they are handled, use
33
- * `@encore.dev/sdk/pubsub`.
30
+ * An active Redis pub/sub subscription running on a dedicated connection.
31
+ * Redis pub/sub delivers messages only to subscribers connected at the time of
32
+ * publishing. For durable messaging where messages are retained until handled,
33
+ * use `@encore.dev/sdk/pubsub`.
34
34
  *
35
- * Iterate over it for its messages. Close it when done with it, which closes
36
- * its connection and unsubscribes; leaving a `for await` loop over it early
37
- * closes it too.
35
+ * Iterate over the subscription with `for await` to receive messages. Call
36
+ * {@link Subscription.close} when done to unsubscribe and close the underlying
37
+ * connection; breaking out of a `for await` loop closes it automatically.
38
38
  *
39
39
  * ```ts
40
40
  * const sub = await EVENTS.pubsub.subscribe("orders");
@@ -47,7 +47,7 @@ export class Subscription implements AsyncIterable<Message>, AsyncDisposable {
47
47
  /** @internal */
48
48
  constructor(private readonly impl: runtime.RedisSubscription) {}
49
49
 
50
- /** The next message, or `null` once the subscription is closed. */
50
+ /** Returns the next message, or `null` once the subscription has closed. */
51
51
  async next(): Promise<Message | null> {
52
52
  const message = await this.impl.next();
53
53
  if (message === null) return null;
@@ -66,7 +66,7 @@ export class Subscription implements AsyncIterable<Message>, AsyncDisposable {
66
66
  }
67
67
  }
68
68
 
69
- /** Closes the subscription. Safe to call more than once. */
69
+ /** Closes the subscription. Safe to call multiple times. */
70
70
  async close(): Promise<void> {
71
71
  await this.impl.close();
72
72
  }
@@ -76,7 +76,7 @@ export class Subscription implements AsyncIterable<Message>, AsyncDisposable {
76
76
  }
77
77
  }
78
78
 
79
- /** Subscribes to `channels` and to the channels matching `patterns`. */
79
+ /** Subscribes to `channels` and to channels matching `patterns`. */
80
80
  export async function subscribe(
81
81
  t: Target,
82
82
  channels: string[],
@@ -174,8 +174,16 @@ function executeEach(batch: Buffer, atomic: boolean): Promise<Buffer> {
174
174
  return Promise.resolve(encode(cmds.map(answer)));
175
175
  }
176
176
 
177
+ /** Whether each reader the runtime was asked for reads from the primary. */
178
+ const readers: boolean[] = [];
179
+
177
180
  const native = {
178
181
  keyPrefix: () => server.prefix,
182
+ // The runtime's reader refuses writes itself; here it is the same handle.
183
+ reader: (primary: boolean) => {
184
+ readers.push(primary);
185
+ return native;
186
+ },
179
187
  connectionUrl: () => 'redis://127.0.0.1:6379/0',
180
188
  execute,
181
189
  executeEach,
@@ -527,8 +535,15 @@ describe('handles', () => {
527
535
  expect((reader.pubsub as Record<string, unknown>).publish).toBeUndefined();
528
536
  expect(typeof reader.pubsub.subscribe).toBe('function');
529
537
  expect(typeof reader.generic.scan).toBe('function');
530
- expect(reader.primary).toBe(false);
531
- expect(DB.readPrimary().primary).toBe(true);
538
+
539
+ // Each reads through the runtime's reader for it, made once.
540
+ script('GET', 'v');
541
+ expect(await reader.string.get('k').text()).toBe('v');
542
+ expect(await DB.readPrimary().string.get('k').text()).toBe('v');
543
+ expect(await DB.read().string.get('k').text()).toBe('v');
544
+ expect(readers.filter(primary => !primary)).toEqual([false]);
545
+ expect(readers.filter(primary => primary)).toEqual([true]);
546
+ server.sent = [];
532
547
 
533
548
  const writer = DB.write();
534
549
  await writer.string.set('k', 'v');