@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
package/pubsub/topic.ts CHANGED
@@ -16,29 +16,29 @@ import {
16
16
  TopicPerms,
17
17
  } from './refs';
18
18
 
19
- /** The most messages one `publishBatch` call takes. */
19
+ /** Maximum number of messages accepted by a single `publishBatch` call. */
20
20
  export const MaxBatchSize = 1000;
21
21
 
22
- /** A message to publish with `Topic.publishBatch`. */
22
+ /** A single message entry for {@link Topic.publishBatch}. */
23
23
  export interface BatchMessage<Msg> {
24
- /** The message, encoded as `publish` encodes it. */
24
+ /** Message payload, encoded the same way as {@link Topic.publish}. */
25
25
  data: Msg;
26
- /** Attributes delivered alongside the payload. */
26
+ /** Optional attributes delivered alongside the payload. */
27
27
  attributes?: Record<string, string>;
28
28
  }
29
29
 
30
- /** A message to publish with `OrderedTopic.publishBatch`. */
30
+ /** A single message entry for {@link OrderedTopic.publishBatch}. */
31
31
  export interface OrderedBatchMessage<Msg> extends BatchMessage<Msg> {
32
- /** The message's ordering key, which cannot be empty. */
32
+ /** Non-empty ordering key grouping messages for ordered delivery. */
33
33
  orderingKey: string;
34
34
  }
35
35
 
36
- /** What became of one message of a batch: its id, or why it was not published. */
36
+ /** Per-message outcome from `publishBatch`: either the message ID or the error. */
37
37
  export type PublishBatchResult = {id: string} | {error: Error};
38
38
 
39
39
  /**
40
- * Some messages of a batch were not published. `results` says, in the order
41
- * the messages were given, each one's id or why it was not published.
40
+ * Thrown when one or more messages in a `publishBatch` call fail to publish.
41
+ * {@link results} contains each message's ID or error in input order.
42
42
  */
43
43
  export class PublishBatchError extends Error {
44
44
  readonly results: ReadonlyArray<PublishBatchResult>;
@@ -56,14 +56,14 @@ export class PublishBatchError extends Error {
56
56
  }
57
57
 
58
58
  /**
59
- * A topic is a resource to which you can publish messages
60
- * to be delivered to subscribers of that topic.
59
+ * A Pub/Sub topic to which services can publish messages for asynchronous
60
+ * delivery to subscribers.
61
61
  */
62
62
  export class Topic<Msg> extends TopicPerms implements Publisher<Msg> {
63
63
  readonly name: string;
64
64
  /**
65
- * The topic's configuration, as declared. `undefined` for a topic referenced
66
- * with `Topic.named`, which is configured where it is declared.
65
+ * Topic configuration as declared, or `undefined` for topics referenced via
66
+ * {@link Topic.named}.
67
67
  */
68
68
  readonly cfg?: TopicConfig<Msg>;
69
69
  private readonly sender: Sender;
@@ -76,17 +76,16 @@ export class Topic<Msg> extends TopicPerms implements Publisher<Msg> {
76
76
  }
77
77
 
78
78
  /**
79
- * Reference an existing topic by name — one another service declares,
80
- * possibly in another language. To declare a new topic, use
81
- * `new Topic(...)` instead.
79
+ * References an existing topic declared elsewhere (including in another
80
+ * service or language). Use `new Topic(...)` to declare a new topic.
82
81
  *
83
- * The message type cannot be inferred, so it must be given:
82
+ * Specify the message type explicitly since it cannot be inferred:
84
83
  *
85
84
  * ```ts
86
85
  * const signups = Topic.named<SignupEvent>("signups");
87
86
  * ```
88
87
  *
89
- * The name must be a string literal, so Encore can resolve it statically.
88
+ * `name` must be a string literal so Encore can resolve it statically.
90
89
  */
91
90
  static named<Msg>(name: string): Topic<Msg> {
92
91
  // Configured where it is declared, so it has no `cfg` of its own.
@@ -94,14 +93,13 @@ export class Topic<Msg> extends TopicPerms implements Publisher<Msg> {
94
93
  }
95
94
 
96
95
  /**
97
- * Publish a message to the topic, returning its unique id.
96
+ * Publishes a message to the topic and returns its unique message ID.
98
97
  *
99
- * JSON values are serialized as the payload; Buffer and Uint8Array payloads
100
- * are sent as raw bytes. Messages are delivered to subscribers verbatim.
101
- * `attributes` are delivered alongside the payload. The message also
102
- * carries the Request Context fields of the active context declared with
103
- * `pubsub`, into its handler's context; `encore-ctx-*` attributes are
104
- * Encore's, and replaced by them.
98
+ * JSON values are serialized as JSON; `Buffer` and `Uint8Array` values are
99
+ * sent as raw bytes. Optional `attributes` are delivered alongside the
100
+ * payload. Any active Request Context fields declared with `pubsub: true`
101
+ * are propagated automatically (overwriting any reserved `encore-ctx-*`
102
+ * attributes).
105
103
  */
106
104
  async publish(
107
105
  msg: Msg,
@@ -116,14 +114,14 @@ export class Topic<Msg> extends TopicPerms implements Publisher<Msg> {
116
114
  }
117
115
 
118
116
  /**
119
- * Publish up to {@link MaxBatchSize} messages to the topic, returning their
120
- * ids in the order given. Each message is encoded as `publish` encodes it,
121
- * and carries the Request Context and trace context as a published one does.
117
+ * Publishes up to {@link MaxBatchSize} messages to the topic and returns
118
+ * their message IDs in input order. Each message is encoded and propagates
119
+ * trace and Request Context the same way as {@link publish}.
122
120
  *
123
- * It is not atomic: if some messages are not published, the rest still
124
- * are, and it rejects with a {@link PublishBatchError} saying which. A
125
- * batch of more than {@link MaxBatchSize} messages is refused whole, and
126
- * none of it published. An empty batch publishes nothing.
121
+ * Batch publishing is not atomic: if some messages fail, the others may still
122
+ * succeed, and the call rejects with {@link PublishBatchError}. Batches
123
+ * exceeding {@link MaxBatchSize} are rejected before any message is
124
+ * published. An empty batch resolves to `[]`.
127
125
  */
128
126
  async publishBatch(
129
127
  messages: readonly BatchMessage<Msg>[],
@@ -145,34 +143,31 @@ export class Topic<Msg> extends TopicPerms implements Publisher<Msg> {
145
143
  }
146
144
 
147
145
  /**
148
- * An ordered topic is a topic that delivers the messages sharing an ordering
149
- * key in the order they were published. Each message is published with its
150
- * key:
146
+ * A Pub/Sub topic that delivers messages sharing an ordering key in the exact
147
+ * order they were published:
151
148
  *
152
149
  * ```ts
153
150
  * const userEvents = new OrderedTopic<UserEvent>("user-events", {
154
151
  * deliveryGuarantee: "at-least-once",
155
152
  * });
156
153
  *
157
- * await userEvents.publish({ action: "login" }, "user-1"); // Delivered before the logout
158
- * await userEvents.publish({ action: "login" }, "user-2"); // Delivered at any time: a different key
159
- * await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after the first login
154
+ * await userEvents.publish({ action: "login" }, "user-1"); // Delivered before logout
155
+ * await userEvents.publish({ action: "login" }, "user-2"); // Independent ordering key
156
+ * await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after login
160
157
  * ```
161
158
  *
162
- * A message whose handler fails is retried before the next one with its key
163
- * is delivered, so depending on the retry policy a backlog can build up
164
- * behind it. Once it has been retried as often as the subscription allows, it
165
- * is dead-lettered and the next message with its key delivered. Reason about
166
- * your failure modes and set the retry policy accordingly.
159
+ * If a handler fails on a message, that message is retried before any
160
+ * subsequent message with the same ordering key is delivered. Until it succeeds
161
+ * or exhausts its retry policy and moves to the dead-letter queue, later
162
+ * messages for that key wait behind it — configure your retry policy
163
+ * accordingly.
167
164
  *
168
- * Its throughput is limited by the cloud provider:
165
+ * Cloud provider throughput limits:
166
+ * - AWS: 300 messages/second per topic (see [AWS SQS Quotas]).
167
+ * - GCP: 1 MB/s per ordering key (see [GCP PubSub Quotas]).
169
168
  *
170
- * - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
171
- * - GCP: 1MB/s for each ordering key (see [GCP PubSub Quotas]).
172
- *
173
- * Locally (`encore run`, `encore test`) messages are delivered in order too:
174
- * a message waits until the earlier ones with the same key are processed or
175
- * dead-lettered.
169
+ * Locally (`encore run`, `encore test`), messages with the same ordering key
170
+ * are likewise delivered sequentially until processed or dead-lettered.
176
171
  *
177
172
  * [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
178
173
  * [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#resource_limits
@@ -183,8 +178,8 @@ export class OrderedTopic<Msg>
183
178
  {
184
179
  readonly name: string;
185
180
  /**
186
- * The topic's configuration, as declared. `undefined` for a topic referenced
187
- * with `OrderedTopic.named`, which is configured where it is declared.
181
+ * Topic configuration as declared, or `undefined` for topics referenced via
182
+ * {@link OrderedTopic.named}.
188
183
  */
189
184
  readonly cfg?: OrderedTopicConfig<Msg>;
190
185
  private readonly sender: Sender;
@@ -197,7 +192,7 @@ export class OrderedTopic<Msg>
197
192
  }
198
193
 
199
194
  /**
200
- * Reference an existing ordered topic by name. See `Topic.named`.
195
+ * References an existing ordered topic by name (see {@link Topic.named}).
201
196
  *
202
197
  * ```ts
203
198
  * const changes = OrderedTopic.named<ChangeEvent>("changes");
@@ -209,16 +204,15 @@ export class OrderedTopic<Msg>
209
204
  }
210
205
 
211
206
  /**
212
- * Publish a message to the topic, returning its unique id. Messages
213
- * published with the same `orderingKey`, which cannot be empty, are
214
- * delivered in the order they were published.
207
+ * Publishes a message with a non-empty `orderingKey` and returns its unique
208
+ * message ID. Messages sharing an ordering key are delivered in publish
209
+ * order.
215
210
  *
216
- * JSON values are serialized as the payload; Buffer and Uint8Array payloads
217
- * are sent as raw bytes. Messages are delivered to subscribers verbatim.
218
- * `attributes` are delivered alongside the payload. The message also
219
- * carries the Request Context fields of the active context declared with
220
- * `pubsub`, into its handler's context; `encore-ctx-*` attributes are
221
- * Encore's, and replaced by them.
211
+ * JSON values are serialized as JSON; `Buffer` and `Uint8Array` values are
212
+ * sent as raw bytes. Optional `attributes` are delivered alongside the
213
+ * payload. Any active Request Context fields declared with `pubsub: true`
214
+ * are propagated automatically (overwriting any reserved `encore-ctx-*`
215
+ * attributes).
222
216
  */
223
217
  async publish(
224
218
  msg: Msg,
@@ -242,17 +236,16 @@ export class OrderedTopic<Msg>
242
236
  }
243
237
 
244
238
  /**
245
- * Publish up to {@link MaxBatchSize} messages to the topic, returning their
246
- * ids in the order given. Each message is encoded as `publish` encodes it,
247
- * and carries the Request Context and trace context as a published one does.
239
+ * Publishes up to {@link MaxBatchSize} ordered messages and returns their
240
+ * message IDs in input order. Each message is encoded and propagates trace
241
+ * and Request Context the same way as {@link publish}.
248
242
  *
249
- * The messages sharing an ordering key are published in the order given,
250
- * and once one of them is not published, neither are the later ones with
251
- * its key. It is not atomic: if some messages are not published, the rest
252
- * still are, and it rejects with a {@link PublishBatchError} saying which.
253
- * A batch of more than {@link MaxBatchSize} messages, or with a message
254
- * whose `orderingKey` is not a non-empty string, is refused whole, and none
255
- * of it published. An empty batch publishes nothing.
243
+ * Messages with the same ordering key are published in order; if one fails,
244
+ * subsequent messages with that key in the batch are not published. Batch
245
+ * publishing is not atomic across keys — on partial failure, rejects with
246
+ * {@link PublishBatchError}. Batches exceeding {@link MaxBatchSize} or
247
+ * containing an empty `orderingKey` are rejected before any message is
248
+ * published. An empty batch resolves to `[]`.
256
249
  */
257
250
  async publishBatch(
258
251
  messages: readonly OrderedBatchMessage<Msg>[],
@@ -281,17 +274,16 @@ export class OrderedTopic<Msg>
281
274
  }
282
275
  }
283
276
 
284
- /** What a topic publishes with: the runtime's topic, or the test's record. */
277
+ /** Publishing target: either the native runtime topic or a unit-test recorder. */
285
278
  type Publish = Pick<runtime.PubSubTopic, 'publish' | 'publishBatch'>;
286
279
 
287
280
  /**
288
- * Where a topic's messages go: to the runtime's topic, or, in a test, to the
289
- * test's record of what it published, sent nowhere, for it to read back with
290
- * `published` or hand to a subscription with `deliver`. A system test's are
291
- * sent: the subscriptions handle them, in the services that declare them.
281
+ * Routes publishes to the native runtime topic, or to the active unit-test
282
+ * scope recorder (in system tests, messages go through the real runtime so
283
+ * service subscriptions consume them).
292
284
  */
293
285
  class Sender {
294
- /** The runtime's topic, made on first use in test mode. */
286
+ /** Native runtime topic, initialized lazily in test mode. */
295
287
  private topic?: runtime.PubSubTopic;
296
288
 
297
289
  constructor(private readonly name: string) {
@@ -307,7 +299,7 @@ class Sender {
307
299
  }
308
300
  }
309
301
 
310
- /** Publishes to the record of what the test `scope` published to `topic`. */
302
+ /** Records published messages into the active unit-test scope. */
311
303
  function recorder(scope: Scope, topic: string): Publish {
312
304
  const record = (
313
305
  data: Buffer,
@@ -333,22 +325,16 @@ function recorder(scope: Scope, topic: string): Publish {
333
325
  };
334
326
  }
335
327
 
336
- /**
337
- * Refuses a batch of more than {@link MaxBatchSize} messages before any of
338
- * it is encoded, as the runtime would refuse it once it was.
339
- */
328
+ /** Rejects batches larger than {@link MaxBatchSize} before encoding payloads. */
340
329
  function checkBatchSize(count: number): void {
341
330
  if (count > MaxBatchSize) {
342
331
  throw new Error(
343
- `failed to publish: a batch has at most ${MaxBatchSize} messages, and this one has ${count}`,
332
+ `failed to publish: a batch has at most ${MaxBatchSize} messages, got ${count}`,
344
333
  );
345
334
  }
346
335
  }
347
336
 
348
- /**
349
- * Publishes the encoded messages, answering with their ids, or rejecting
350
- * with a {@link PublishBatchError} if any was not published.
351
- */
337
+ /** Publishes encoded batch entries, rejecting with {@link PublishBatchError} if any failed. */
352
338
  async function publishBatch(
353
339
  impl: runtime.PubSubTopic,
354
340
  entries: runtime.PubSubBatchEntry[],
@@ -363,69 +349,49 @@ async function publishBatch(
363
349
  outcomes.map(o =>
364
350
  o.id !== undefined && o.id !== null
365
351
  ? {id: o.id}
366
- : {error: new Error(o.error ?? 'the message was not published')},
352
+ : {error: new Error(o.error ?? 'message failed to publish')},
367
353
  ),
368
354
  );
369
355
  }
370
356
 
371
357
  /**
372
- * DeliveryGuarantee is used to configure the delivery contract for a topic,
373
- * written out as one of the two strings: Encore reads it from the source.
374
- *
375
- * `"at-least-once"` guarantees that a message for a subscription is
376
- * delivered to a consumer at least once. On AWS and GCP there is no limit to
377
- * the throughput for a topic.
378
- *
379
- * `"exactly-once"` guarantees that a message for a subscription is delivered
380
- * to a consumer exactly once, to the best of the system's ability.
358
+ * Delivery guarantee for a topic. Must be written as a string literal so
359
+ * Encore can read it statically:
381
360
  *
382
- * However, there are edge cases when a message might be redelivered.
383
- * For example, if a networking issue causes the acknowledgement of success
384
- * processing the message to be lost before the cloud provider receives it.
361
+ * - `"at-least-once"`: guarantees each message is delivered at least once,
362
+ * with no provider throughput limit on AWS or GCP.
363
+ * - `"exactly-once"`: delivers each message once on a best-effort basis. Edge
364
+ * cases (such as a lost acknowledgment over the network) can still cause
365
+ * redelivery, and publishing the same message twice will still deliver it
366
+ * twice (no publish-side deduplication). Handlers should therefore remain
367
+ * idempotent.
385
368
  *
386
- * It is also important to note that the exactly-once delivery guarantee only
387
- * applies to the delivery of the message to the consumer, and not to the
388
- * original publishing of the message, such that if a message is published twice,
389
- * such as due to an retry within the application logic, it will be delivered twice.
390
- * (i.e. exactly-once delivery does not imply message deduplication on publish)
391
- *
392
- * As such it's recommended that the subscription handler function is idempotent
393
- * and is able to handle duplicate messages.
394
- *
395
- * Subscriptions attached to exactly-once topics have higher message delivery latency compared to at-least-once.
396
- *
397
- * By using exactly-once semantics on a topic, the throughput will be limited depending on the cloud provider:
398
- * - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
399
- * - GCP: At least 3,000 messages per second across all topics in the region
400
- * (can be higher on the region see [GCP PubSub Quotas]).
369
+ * `"exactly-once"` has higher delivery latency and lower throughput limits:
370
+ * - AWS: 300 messages/second per topic (see [AWS SQS Quotas]).
371
+ * - GCP: at least 3,000 messages/second across all topics in a region (see
372
+ * [GCP PubSub Quotas]).
401
373
  *
402
374
  * [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
403
375
  * [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#quotas
404
376
  */
405
377
  export type DeliveryGuarantee = 'at-least-once' | 'exactly-once';
406
378
 
407
- /**
408
- * TopicConfig is used when creating a Topic
409
- */
379
+ /** Configuration options for declaring a {@link Topic}. */
410
380
  export interface TopicConfig<_Msg> {
411
381
  /**
412
- * DeliveryGuarantee is used to configure the delivery guarantee of a Topic:
413
- * `"at-least-once"` or `"exactly-once"`, written out. Defaults to
414
- * `"at-least-once"`.
382
+ * Delivery guarantee for the topic (`"at-least-once"` or `"exactly-once"`),
383
+ * written as a string literal. Defaults to `"at-least-once"`.
415
384
  */
416
385
  deliveryGuarantee?: DeliveryGuarantee;
417
386
 
418
387
  /**
419
- * Tags that classify the topic, for policies to read: written out as
420
- * string literals, as in `{data: "pci"}`. Keys and values are lowercase
421
- * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
422
- * letter, and not with `encore`, which is reserved. At most 32 tags.
388
+ * Static string-literal tags that classify the topic for policy checks
389
+ * (e.g. `{data: "pci"}`). Keys and values may contain lowercase letters,
390
+ * digits, `_`, and `-`, up to 63 characters. Keys must start with a letter
391
+ * and cannot start with the reserved prefix `encore`. At most 32 tags.
423
392
  */
424
393
  tags?: Record<string, string>;
425
394
  }
426
395
 
427
- /**
428
- * OrderedTopicConfig is used when creating an OrderedTopic. It configures what
429
- * a TopicConfig does; the ordering key is given with each message.
430
- */
396
+ /** Configuration options for declaring an {@link OrderedTopic}. */
431
397
  export type OrderedTopicConfig<Msg = unknown> = TopicConfig<Msg>;