@encore.dev/sdk 2.0.0-beta.14 → 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 (269) hide show
  1. package/README.md +144 -90
  2. package/app_meta.ts +56 -54
  3. package/config/config.test.ts +47 -13
  4. package/config/config.ts +60 -57
  5. package/config/secrets.ts +47 -50
  6. package/config/value.ts +23 -26
  7. package/cron/mod.test.ts +12 -0
  8. package/cron/mod.ts +37 -22
  9. package/dist/app_meta.d.ts +52 -50
  10. package/dist/app_meta.d.ts.map +1 -1
  11. package/dist/app_meta.js +2 -2
  12. package/dist/app_meta.js.map +1 -1
  13. package/dist/config/config.d.ts +58 -55
  14. package/dist/config/config.d.ts.map +1 -1
  15. package/dist/config/config.js +8 -9
  16. package/dist/config/config.js.map +1 -1
  17. package/dist/config/secrets.d.ts +45 -50
  18. package/dist/config/secrets.d.ts.map +1 -1
  19. package/dist/config/secrets.js +11 -9
  20. package/dist/config/secrets.js.map +1 -1
  21. package/dist/config/value.d.ts +20 -23
  22. package/dist/config/value.d.ts.map +1 -1
  23. package/dist/config/value.js +20 -23
  24. package/dist/config/value.js.map +1 -1
  25. package/dist/cron/mod.d.ts +34 -20
  26. package/dist/cron/mod.d.ts.map +1 -1
  27. package/dist/cron/mod.js +13 -13
  28. package/dist/cron/mod.js.map +1 -1
  29. package/dist/frontends/mod.d.ts +20 -19
  30. package/dist/frontends/mod.d.ts.map +1 -1
  31. package/dist/frontends/mod.js +20 -19
  32. package/dist/frontends/mod.js.map +1 -1
  33. package/dist/gateway/errors.d.ts +28 -30
  34. package/dist/gateway/errors.d.ts.map +1 -1
  35. package/dist/gateway/errors.js +29 -31
  36. package/dist/gateway/errors.js.map +1 -1
  37. package/dist/gateway/match.d.ts +54 -54
  38. package/dist/gateway/match.d.ts.map +1 -1
  39. package/dist/gateway/match.js +56 -56
  40. package/dist/gateway/match.js.map +1 -1
  41. package/dist/gateway/middleware.d.ts +62 -64
  42. package/dist/gateway/middleware.d.ts.map +1 -1
  43. package/dist/gateway/middleware.js +1 -1
  44. package/dist/gateway/middleware.js.map +1 -1
  45. package/dist/gateway/mod.d.ts +64 -67
  46. package/dist/gateway/mod.d.ts.map +1 -1
  47. package/dist/gateway/mod.js +72 -76
  48. package/dist/gateway/mod.js.map +1 -1
  49. package/dist/gateway/request.d.ts +138 -134
  50. package/dist/gateway/request.d.ts.map +1 -1
  51. package/dist/gateway/request.js +117 -108
  52. package/dist/gateway/request.js.map +1 -1
  53. package/dist/gateway/serve.d.ts +29 -34
  54. package/dist/gateway/serve.d.ts.map +1 -1
  55. package/dist/gateway/serve.js +51 -56
  56. package/dist/gateway/serve.js.map +1 -1
  57. package/dist/gateways/mod.d.ts +23 -21
  58. package/dist/gateways/mod.d.ts.map +1 -1
  59. package/dist/gateways/mod.js +25 -23
  60. package/dist/gateways/mod.js.map +1 -1
  61. package/dist/internal/otel/http.d.ts +4 -2
  62. package/dist/internal/otel/http.d.ts.map +1 -1
  63. package/dist/internal/otel/http.js +32 -5
  64. package/dist/internal/otel/http.js.map +1 -1
  65. package/dist/internal/runtime/napi/napi.cjs +6 -5
  66. package/dist/internal/runtime/napi/napi.d.cts +58 -16
  67. package/dist/internal/runtime/shutdown.d.ts +75 -57
  68. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  69. package/dist/internal/runtime/shutdown.js +88 -84
  70. package/dist/internal/runtime/shutdown.js.map +1 -1
  71. package/dist/log/logger.d.ts +43 -37
  72. package/dist/log/logger.d.ts.map +1 -1
  73. package/dist/log/logger.js +26 -25
  74. package/dist/log/logger.js.map +1 -1
  75. package/dist/metrics/mod.d.ts +133 -114
  76. package/dist/metrics/mod.d.ts.map +1 -1
  77. package/dist/metrics/mod.js +109 -101
  78. package/dist/metrics/mod.js.map +1 -1
  79. package/dist/otel.d.ts +6 -3
  80. package/dist/otel.d.ts.map +1 -1
  81. package/dist/otel.js +6 -3
  82. package/dist/otel.js.map +1 -1
  83. package/dist/pubsub/subscription.d.ts +88 -116
  84. package/dist/pubsub/subscription.d.ts.map +1 -1
  85. package/dist/pubsub/subscription.js +14 -17
  86. package/dist/pubsub/subscription.js.map +1 -1
  87. package/dist/pubsub/topic.d.ts +86 -113
  88. package/dist/pubsub/topic.d.ts.map +1 -1
  89. package/dist/pubsub/topic.js +68 -82
  90. package/dist/pubsub/topic.js.map +1 -1
  91. package/dist/redaction/mod.d.ts +62 -0
  92. package/dist/redaction/mod.d.ts.map +1 -0
  93. package/dist/redaction/mod.js +102 -0
  94. package/dist/redaction/mod.js.map +1 -0
  95. package/dist/reqctx/mod.d.ts +83 -86
  96. package/dist/reqctx/mod.d.ts.map +1 -1
  97. package/dist/reqctx/mod.js +39 -41
  98. package/dist/reqctx/mod.js.map +1 -1
  99. package/dist/services/index.d.ts +76 -75
  100. package/dist/services/index.d.ts.map +1 -1
  101. package/dist/services/index.js +73 -71
  102. package/dist/services/index.js.map +1 -1
  103. package/dist/shutdown/mod.d.ts +26 -25
  104. package/dist/shutdown/mod.d.ts.map +1 -1
  105. package/dist/shutdown/mod.js +26 -25
  106. package/dist/shutdown/mod.js.map +1 -1
  107. package/dist/storage/clickhouse/database.d.ts +113 -115
  108. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  109. package/dist/storage/clickhouse/database.js +65 -79
  110. package/dist/storage/clickhouse/database.js.map +1 -1
  111. package/dist/storage/clickhouse/errors.d.ts +25 -26
  112. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  113. package/dist/storage/clickhouse/errors.js +15 -17
  114. package/dist/storage/clickhouse/errors.js.map +1 -1
  115. package/dist/storage/clickhouse/mod.d.ts +10 -10
  116. package/dist/storage/clickhouse/mod.js +10 -10
  117. package/dist/storage/objects/bucket.d.ts +230 -203
  118. package/dist/storage/objects/bucket.d.ts.map +1 -1
  119. package/dist/storage/objects/bucket.js +146 -106
  120. package/dist/storage/objects/bucket.js.map +1 -1
  121. package/dist/storage/objects/error.d.ts +4 -4
  122. package/dist/storage/objects/error.js +4 -4
  123. package/dist/storage/objects/mod.d.ts +1 -1
  124. package/dist/storage/objects/mod.d.ts.map +1 -1
  125. package/dist/storage/objects/mod.js.map +1 -1
  126. package/dist/storage/objects/refs.d.ts +2 -5
  127. package/dist/storage/objects/refs.d.ts.map +1 -1
  128. package/dist/storage/objects/refs.js.map +1 -1
  129. package/dist/storage/postgres/database.d.ts +124 -149
  130. package/dist/storage/postgres/database.d.ts.map +1 -1
  131. package/dist/storage/postgres/database.js +98 -135
  132. package/dist/storage/postgres/database.js.map +1 -1
  133. package/dist/storage/postgres/errors.d.ts +42 -48
  134. package/dist/storage/postgres/errors.d.ts.map +1 -1
  135. package/dist/storage/postgres/errors.js +44 -51
  136. package/dist/storage/postgres/errors.js.map +1 -1
  137. package/dist/storage/postgres/interval.d.ts +19 -19
  138. package/dist/storage/postgres/interval.d.ts.map +1 -1
  139. package/dist/storage/postgres/interval.js +21 -21
  140. package/dist/storage/postgres/interval.js.map +1 -1
  141. package/dist/storage/redis/bitfield.d.ts +48 -23
  142. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  143. package/dist/storage/redis/bitfield.js +38 -19
  144. package/dist/storage/redis/bitfield.js.map +1 -1
  145. package/dist/storage/redis/command.d.ts +16 -12
  146. package/dist/storage/redis/command.d.ts.map +1 -1
  147. package/dist/storage/redis/command.js +16 -12
  148. package/dist/storage/redis/command.js.map +1 -1
  149. package/dist/storage/redis/commands.d.ts +99 -100
  150. package/dist/storage/redis/commands.d.ts.map +1 -1
  151. package/dist/storage/redis/commands.js +84 -85
  152. package/dist/storage/redis/commands.js.map +1 -1
  153. package/dist/storage/redis/database.d.ts +138 -122
  154. package/dist/storage/redis/database.d.ts.map +1 -1
  155. package/dist/storage/redis/database.js +120 -101
  156. package/dist/storage/redis/database.js.map +1 -1
  157. package/dist/storage/redis/mod.d.ts +52 -48
  158. package/dist/storage/redis/mod.d.ts.map +1 -1
  159. package/dist/storage/redis/mod.js +52 -48
  160. package/dist/storage/redis/mod.js.map +1 -1
  161. package/dist/storage/redis/options.d.ts +26 -24
  162. package/dist/storage/redis/options.d.ts.map +1 -1
  163. package/dist/storage/redis/options.js.map +1 -1
  164. package/dist/storage/redis/pubsub.d.ts +16 -16
  165. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  166. package/dist/storage/redis/pubsub.js +14 -14
  167. package/dist/storage/redis/pubsub.js.map +1 -1
  168. package/dist/storage/redis/reply.d.ts +80 -72
  169. package/dist/storage/redis/reply.d.ts.map +1 -1
  170. package/dist/storage/redis/reply.js +53 -46
  171. package/dist/storage/redis/reply.js.map +1 -1
  172. package/dist/storage/redis/scan.d.ts +4 -4
  173. package/dist/storage/redis/scan.d.ts.map +1 -1
  174. package/dist/storage/redis/scan.js +6 -6
  175. package/dist/storage/redis/scan.js.map +1 -1
  176. package/dist/storage/redis/script.d.ts +28 -21
  177. package/dist/storage/redis/script.d.ts.map +1 -1
  178. package/dist/storage/redis/script.js +29 -22
  179. package/dist/storage/redis/script.js.map +1 -1
  180. package/dist/storage/redis/target.d.ts +17 -1
  181. package/dist/storage/redis/target.d.ts.map +1 -1
  182. package/dist/storage/redis/target.js +30 -1
  183. package/dist/storage/redis/target.js.map +1 -1
  184. package/dist/storage/redis/wire.d.ts +6 -6
  185. package/dist/storage/redis/wire.d.ts.map +1 -1
  186. package/dist/storage/redis/wire.js +6 -6
  187. package/dist/storage/redis/wire.js.map +1 -1
  188. package/dist/testing/mod.d.ts +83 -88
  189. package/dist/testing/mod.d.ts.map +1 -1
  190. package/dist/testing/mod.js +75 -81
  191. package/dist/testing/mod.js.map +1 -1
  192. package/dist/testing/playwright.d.ts +28 -32
  193. package/dist/testing/playwright.d.ts.map +1 -1
  194. package/dist/testing/playwright.js +22 -27
  195. package/dist/testing/playwright.js.map +1 -1
  196. package/dist/testing/puppeteer.d.ts +11 -12
  197. package/dist/testing/puppeteer.d.ts.map +1 -1
  198. package/dist/testing/puppeteer.js +17 -18
  199. package/dist/testing/puppeteer.js.map +1 -1
  200. package/dist/testing/system.d.ts +72 -90
  201. package/dist/testing/system.d.ts.map +1 -1
  202. package/dist/testing/system.js +90 -107
  203. package/dist/testing/system.js.map +1 -1
  204. package/dist/tracing/http.d.ts +2 -1
  205. package/dist/tracing/http.d.ts.map +1 -1
  206. package/dist/tracing/http.js +2 -1
  207. package/dist/tracing/http.js.map +1 -1
  208. package/dist/tracing/node.d.ts.map +1 -1
  209. package/dist/tracing/node.js +1 -1
  210. package/dist/tracing/node.js.map +1 -1
  211. package/dist/tsconfig.build.tsbuildinfo +1 -1
  212. package/frontends/mod.test.ts +6 -2
  213. package/frontends/mod.ts +20 -19
  214. package/gateway/errors.ts +30 -32
  215. package/gateway/match.ts +61 -57
  216. package/gateway/middleware.ts +62 -64
  217. package/gateway/mod.ts +73 -76
  218. package/gateway/request.ts +143 -140
  219. package/gateway/serve.ts +58 -63
  220. package/gateways/mod.ts +25 -23
  221. package/internal/otel/http.test.ts +50 -0
  222. package/internal/otel/http.ts +40 -5
  223. package/internal/runtime/napi/napi.cjs +6 -5
  224. package/internal/runtime/napi/napi.d.cts +58 -16
  225. package/internal/runtime/shutdown.ts +113 -101
  226. package/log/logger.test.ts +8 -0
  227. package/log/logger.ts +48 -45
  228. package/metrics/mod.ts +138 -122
  229. package/otel.ts +6 -3
  230. package/package.json +6 -1
  231. package/pubsub/subscription.ts +93 -123
  232. package/pubsub/topic.ts +96 -130
  233. package/redaction/bridge.test.ts +99 -0
  234. package/redaction/mod.test.ts +188 -0
  235. package/redaction/mod.ts +226 -0
  236. package/reqctx/mod.ts +83 -86
  237. package/services/index.ts +78 -78
  238. package/shutdown/mod.ts +26 -25
  239. package/storage/clickhouse/database.ts +115 -129
  240. package/storage/clickhouse/errors.ts +27 -29
  241. package/storage/clickhouse/mod.ts +10 -10
  242. package/storage/objects/bucket.test.ts +168 -16
  243. package/storage/objects/bucket.ts +336 -247
  244. package/storage/objects/error.ts +4 -4
  245. package/storage/objects/mod.ts +1 -0
  246. package/storage/objects/refs.ts +2 -5
  247. package/storage/postgres/database.ts +131 -164
  248. package/storage/postgres/errors.ts +45 -52
  249. package/storage/postgres/interval.ts +21 -21
  250. package/storage/redis/bitfield.ts +51 -26
  251. package/storage/redis/command.ts +16 -12
  252. package/storage/redis/commands.ts +99 -100
  253. package/storage/redis/database.ts +145 -123
  254. package/storage/redis/mod.ts +52 -48
  255. package/storage/redis/options.ts +26 -24
  256. package/storage/redis/pubsub.ts +14 -14
  257. package/storage/redis/redis.test.ts +17 -2
  258. package/storage/redis/reply.ts +85 -77
  259. package/storage/redis/scan.ts +6 -6
  260. package/storage/redis/script.ts +29 -22
  261. package/storage/redis/target.ts +34 -1
  262. package/storage/redis/wire.ts +8 -8
  263. package/testing/mod.ts +99 -105
  264. package/testing/playwright.ts +32 -37
  265. package/testing/puppeteer.ts +22 -23
  266. package/testing/system.ts +117 -133
  267. package/tracing/http.ts +2 -1
  268. package/tracing/native.test.ts +158 -8
  269. package/tracing/node.ts +1 -0
@@ -13,43 +13,38 @@ import * as runtime from '../internal/runtime/mod';
13
13
  import {testMode, type Scope} from '../internal/testing/scope';
14
14
 
15
15
  /**
16
- * A delivered payload with its original bytes and provider metadata.
16
+ * A delivered Pub/Sub message along with its raw bytes and broker metadata.
17
17
  *
18
- * The handler runs in the message's context: its spans and calls continue
19
- * the trace the message was published in, and the Request Context fields it
20
- * carries are set (`@encore.dev/sdk/reqctx`).
18
+ * The subscription handler runs inside the message's context: any spans or
19
+ * downstream calls continue the publisher's trace, and propagated Request
20
+ * Context fields (`@encore.dev/sdk/reqctx`) are available via `field.get()`.
21
21
  */
22
22
  export interface Message<T = unknown> {
23
- /** The payload, decoded as the subscription says. */
23
+ /** Decoded payload according to the subscription's `encoding` and `decode` options. */
24
24
  data: T;
25
- /** The payload as it was published. */
25
+ /** Original payload bytes as published. */
26
26
  rawData: Buffer;
27
- /**
28
- * The unique id of the message: the one `publish` returned. It stays the
29
- * same across delivery attempts.
30
- */
27
+ /** Unique message ID returned by `publish`; remains stable across redelivery attempts. */
31
28
  id: string;
32
29
  /**
33
- * The attributes it was published with, without the `encore-ctx-*` ones
34
- * carrying Request Context fields, which the handler reads from its
35
- * context.
30
+ * Message attributes set by the publisher, excluding internal `encore-ctx-*`
31
+ * attributes used to propagate Request Context fields.
36
32
  */
37
33
  attributes: Record<string, string>;
38
- /** The delivery attempt, starting at 1. */
34
+ /** 1-based delivery attempt counter. */
39
35
  deliveryAttempt: number;
40
- /** When it was published. */
36
+ /** Timestamp when the message was published. */
41
37
  publishTime: Date;
42
- /** The key it was published with on an ordered topic; `null` on an
43
- * unordered one. */
38
+ /** Ordering key for ordered topics, or `null` for unordered topics. */
44
39
  orderingKey: string | null;
45
40
  }
46
41
 
47
42
  export class Subscription<Msg> {
48
43
  private readonly topic: Topic<Msg> | OrderedTopic<Msg>;
49
- /** The subscription's name, unique to its topic. */
44
+ /** Subscription name, unique within its topic. */
50
45
  readonly name: string;
51
46
  private readonly impl?: runtime.PubSubSubscription;
52
- /** Runs the handler on a message, as it is delivered. */
47
+ /** Dispatches a delivered message to the configured handler. */
53
48
  private readonly dispatch: (msg: Delivered) => Promise<void>;
54
49
 
55
50
  constructor(
@@ -105,11 +100,9 @@ export class Subscription<Msg> {
105
100
  }
106
101
 
107
102
  /**
108
- * Runs the handler on each message the test `scope` published to the
109
- * topic that the subscription has not handled and its filter matches, in
110
- * order, returning how many it handled. Stops at the first the handler
111
- * fails, rejecting with its error: that message is handed over again next
112
- * time, as its next attempt.
103
+ * Delivers pending matching messages from `scope` to this subscription in
104
+ * order and returns the number of messages handled. Rejects on the first
105
+ * handler error so that message remains pending for the next attempt.
113
106
  *
114
107
  * @internal
115
108
  */
@@ -125,9 +118,9 @@ export class Subscription<Msg> {
125
118
  if (delivery === null) return handled;
126
119
  if (handled === maxDeliveries) {
127
120
  throw new Error(
128
- `subscription ${JSON.stringify(sub.name)} handled ${maxDeliveries} messages in one ` +
129
- `delivery and was still handed more: does its handler publish to its own topic ` +
130
- `${JSON.stringify(topic)} every time?`,
121
+ `subscription ${JSON.stringify(sub.name)} handled ${maxDeliveries} messages in a ` +
122
+ `single deliver() call and still has more pending — check whether its handler ` +
123
+ `unconditionally publishes back to topic ${JSON.stringify(topic)}`,
131
124
  );
132
125
  }
133
126
  const msg = delivery.message;
@@ -150,8 +143,7 @@ export class Subscription<Msg> {
150
143
  }
151
144
  }
152
145
 
153
- /** A message to hand a subscription's handler: the runtime's, or one a test
154
- * published. */
146
+ /** Internal representation of a message delivered from the runtime or a test scope. */
155
147
  type Delivered = Pick<
156
148
  runtime.PubSubMessage,
157
149
  'id' | 'data' | 'attributes' | 'deliveryAttempt' | 'publishTime'
@@ -161,9 +153,8 @@ type Delivered = Pick<
161
153
  };
162
154
 
163
155
  /**
164
- * The context a message's handler runs in: its delivery span's, so the
165
- * handler's spans and calls continue the trace and carry Encore's propagation
166
- * mark, with the Request Context fields the message carries.
156
+ * Builds the OpenTelemetry context for a subscription handler, attaching the
157
+ * delivery span context and any propagated Request Context fields.
167
158
  */
168
159
  function handlerContext(
169
160
  msg: Delivered,
@@ -184,15 +175,15 @@ function handlerContext(
184
175
  }
185
176
 
186
177
  /**
187
- * SubscriptionConfig is used when creating a subscription: its
188
- * {@link SubscriptionOptions}, and how its messages are decoded.
178
+ * Configuration for creating a {@link Subscription}, combining
179
+ * {@link SubscriptionOptions} with payload decoding settings.
189
180
  *
190
- * Decode JSON by default; byte subscriptions must select `encoding: "raw"`.
191
- * `decode` optionally validates/transforms JSON, or decodes a custom raw format.
181
+ * Messages are JSON-decoded by default; byte subscriptions must specify
182
+ * `encoding: "raw"`. Provide `decode` to validate or transform parsed JSON, or
183
+ * to decode a custom binary format.
192
184
  *
193
- * The values given here may be clamped to the supported values by
194
- * the target cloud. (i.e. ack deadline may be brought within the supported range
195
- * by the target cloud pubsub implementation).
185
+ * Cloud providers may clamp configuration values (such as `ackDeadline`) to
186
+ * their supported ranges.
196
187
  */
197
188
  export type SubscriptionConfig<Msg> = SubscriptionOptions<Msg> &
198
189
  ([Msg] extends [Uint8Array]
@@ -200,160 +191,139 @@ export type SubscriptionConfig<Msg> = SubscriptionOptions<Msg> &
200
191
  : | {encoding?: 'json'; decode?: (data: unknown) => Msg}
201
192
  | {encoding: 'raw'; decode: (data: unknown) => Msg});
202
193
 
203
- /** A subscription's options, other than how its messages are decoded. */
194
+ /** Subscription options other than payload decoding. */
204
195
  export interface SubscriptionOptions<Msg> {
205
196
  /**
206
- * Handler is the function which will be called to process a message
207
- * sent on the topic.
197
+ * Function invoked to process each message published to the topic.
208
198
  *
209
- * It receives a {@link Message} with decoded `data` and original `rawData`.
210
- * TypeScript types do not validate JSON; use `decode` for runtime validation.
199
+ * Receives a {@link Message} containing the decoded `data` and raw bytes in
200
+ * `rawData`. TypeScript types are not checked at runtime; use `decode` for
201
+ * runtime validation.
211
202
  *
212
- * When this function returns an error the message will be
213
- * negatively acknowledged (nacked), which will cause a redelivery
214
- * attempt to be made (unless the retry policy's MaxRetries has been reached).
203
+ * Throwing or rejecting negatively acknowledges (nacks) the message,
204
+ * triggering redelivery until {@link RetryPolicy.maxRetries} is exhausted.
215
205
  */
216
206
  handler: (msg: Message<Msg>) => Promise<unknown>;
217
207
 
218
208
  /**
219
- * MaxConcurrency is the maximum number of messages which will be processed
220
- * simultaneously per instance of the service for this subscription.
221
- *
222
- * Note that this is per instance of the service, so if your service has
223
- * scaled to 10 instances and this is set to 10, then 100 messages could be
224
- * processed simultaneously.
225
- *
226
- * If the value is negative, then there will be no limit on the number
227
- * of messages processed simultaneously.
209
+ * Maximum number of messages processed concurrently per service instance.
228
210
  *
229
- * Note: This is not supported by all cloud providers; specifically on GCP
230
- * when using Cloud Run instances on an unordered topic the subscription will
231
- * be configured as a Push Subscription and will have an adaptive concurrency
232
- * See [GCP Push Delivery Rate](https://cloud.google.com/pubsub/docs/push#push_delivery_rate).
211
+ * For example, setting `maxConcurrency: 10` across 10 service instances
212
+ * allows up to 100 concurrent messages. Negative values disable the limit.
233
213
  *
234
- * This setting also has no effect on Encore Cloud environments.
235
- * If not set, it uses a reasonable default based on the cloud provider.
214
+ * Note: Not supported on all providers — on GCP Cloud Run with unordered
215
+ * topics, subscriptions use Push Delivery with adaptive concurrency (see
216
+ * [GCP Push Delivery Rate](https://cloud.google.com/pubsub/docs/push#push_delivery_rate)).
217
+ * Also has no effect in Encore Cloud environments. Defaults to a
218
+ * provider-specific value when omitted.
236
219
  */
237
220
  maxConcurrency?: number;
238
221
 
239
222
  /**
240
- * AckDeadline is how long a message is kept for its handler before
241
- * it's delivered again. While the handler runs, a pulled message's
242
- * lease is extended for an hour, or for the ack deadline when that is
243
- * longer; a message pushed to the service (a GCP push subscription)
244
- * has the ack deadline.
223
+ * Maximum time the broker waits for acknowledgment before redelivering a
224
+ * message. For pulled subscriptions, Encore automatically extends the lease
225
+ * while the handler runs (up to 1 hour, or `ackDeadline` if longer); GCP push
226
+ * subscriptions are bounded by `ackDeadline`.
245
227
  *
246
- * Default is 30 seconds, however the ack deadline must be at least
247
- * 1 second.
228
+ * Defaults to 30 seconds; must be at least 1 second.
248
229
  */
249
230
  ackDeadline?: DurationString;
250
231
 
251
232
  /**
252
- * MessageRetention is how long an undelivered message is kept
253
- * on the topic before it's purged.
254
- *
255
- * Default is 7 days.
233
+ * How long undelivered messages are retained before being purged.
234
+ * Defaults to 7 days.
256
235
  */
257
236
  messageRetention?: DurationString;
258
237
 
259
238
  /**
260
- * RetryPolicy defines how a message should be retried when
261
- * the subscriber returns an error
239
+ * Retry policy controlling redelivery backoff and dead-lettering when the
240
+ * handler fails.
262
241
  */
263
242
  retryPolicy?: RetryPolicy;
264
243
 
265
244
  /**
266
- * Which of the topic's messages the subscription receives: those whose
267
- * attributes this condition matches. Messages it does not match are never
268
- * delivered to the subscription. By default it receives them all.
245
+ * Optional attribute filter expression selecting which messages this
246
+ * subscription receives. Unmatched messages are never delivered. Receives all
247
+ * messages when omitted.
269
248
  *
270
- * It is written in a subset of the [expr language](https://expr-lang.org),
271
- * which every cloud Encore deploys to can filter on:
249
+ * Written in a cloud-portable subset of [expr](https://expr-lang.org):
272
250
  *
273
251
  * ```ts
274
252
  * filter: `attrs.region in ["eu-west-1", "eu-north-1"] and not (attrs.kind startsWith "test-")`
275
253
  * ```
276
254
  *
255
+ * Supported operators:
277
256
  * - `attrs.region == "eu"`, `!=`, `in [...]`, `not in [...]`, and
278
- * `startsWith "eu-"`; `attrs["iana.org-lang"]` for a name with other
279
- * characters than letters, digits and `_`.
280
- * - `"region" in attrs` and `"region" not in attrs`: whether a message has
281
- * the attribute. A test of a value does not hold for a message without
282
- * the attribute, and a negated one does.
283
- * - `and` (`&&`), `or` (`||`), `not (...)` (`!(...)`) and parentheses.
257
+ * `startsWith "eu-"` (use `attrs["iana.org-lang"]` for attribute names
258
+ * containing characters outside letters, digits, and `_`).
259
+ * - `"region" in attrs` and `"region" not in attrs` to check attribute
260
+ * presence. Value checks evaluate to `false` when an attribute is missing,
261
+ * while negated checks evaluate to `true`.
262
+ * - `and` (`&&`), `or` (`||`), `not (...)` (`!(...)`), and parentheses.
284
263
  *
285
- * Encore reads it from the source, so it is a string written out, and
286
- * checks it fits the clouds' limits.
264
+ * Must be a string literal so Encore can validate it statically against cloud
265
+ * provider limits.
287
266
  */
288
267
  filter?: string;
289
268
 
290
269
  /**
291
- * The Worker of the service that consumes the subscription: a long-running
292
- * process of the service that serves no requests, declared in the `workers`
293
- * section of its `encore.service.json`. Only that process takes its
294
- * messages; another process of the service that creates the subscription
295
- * takes none. By default the service's main process consumes it.
296
- *
297
- * Encore reads it from the source, so it is a string written out.
270
+ * Name of a worker declared in `encore.service.json` under `workers` that
271
+ * should consume this subscription instead of the service's main process.
272
+ * Only that worker processes messages for this subscription. Must be a string
273
+ * literal.
298
274
  */
299
275
  worker?: string;
300
276
 
301
277
  /**
302
- * Tags that classify the subscription, for policies to read: written out as
303
- * string literals, as in `{data: "pci"}`. Keys and values are lowercase
304
- * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
305
- * letter, and not with `encore`, which is reserved. At most 32 tags.
278
+ * Static string-literal tags that classify the subscription for policy checks
279
+ * (e.g. `{data: "pci"}`). Keys and values may contain lowercase letters,
280
+ * digits, `_`, and `-`, up to 63 characters. Keys must start with a letter
281
+ * and cannot start with the reserved prefix `encore`. At most 32 tags.
306
282
  */
307
283
  tags?: Record<string, string>;
308
284
  }
309
285
 
310
286
  /**
311
- * RetryPolicy defines how a subscription should handle retries
312
- * after errors either delivering the message or processing the message.
313
- *
314
- * The values given to this structure are parsed at compile time, such that
315
- * the correct Cloud resources can be provisioned to support the queue.
287
+ * Retry and dead-letter configuration for failed deliveries or handler errors.
316
288
  *
317
- * As such the values given here may be clamped to the supported values by
318
- * the target cloud. (i.e. min/max values brought within the supported range
319
- * by the target cloud).
289
+ * Values are parsed statically at compile time to provision cloud resources,
290
+ * and may be clamped to each cloud provider's supported ranges.
320
291
  */
321
292
  export interface RetryPolicy {
322
293
  /**
323
- * The minimum time to wait between retries. Defaults to 10 seconds.
294
+ * Minimum backoff delay between retry attempts. Defaults to 10 seconds.
324
295
  */
325
296
  minBackoff?: DurationString;
326
297
 
327
298
  /**
328
- * The maximum time to wait between retries. Defaults to 10 minutes.
299
+ * Maximum backoff delay between retry attempts. Defaults to 10 minutes.
329
300
  */
330
301
  maxBackoff?: DurationString;
331
302
 
332
303
  /**
333
- * How many times a message is retried after its handler fails before it is
334
- * forwarded to the dead-letter queue. Defaults to 100.
304
+ * Maximum number of retries after a handler failure before forwarding the
305
+ * message to the dead-letter queue. Defaults to 100.
335
306
  *
336
- * - `n >= 0`: retried up to `n` times. `0` retries it not at all: it is
337
- * dead-lettered as soon as its handler fails once.
338
- * - `-1`, {@link InfiniteRetries}: retried for as long as it fails, never
339
- * dead-lettered.
340
- * - `-2`, {@link NoRetries}: not retried, as `0`.
307
+ * - `n >= 0`: retry up to `n` times (`0` disables retries and dead-letters on
308
+ * the first failure).
309
+ * - `-1` ({@link InfiniteRetries}): retry indefinitely without dead-lettering.
310
+ * - `-2` ({@link NoRetries}): do not retry (equivalent to `0`).
341
311
  *
342
- * Anything below `-2` is rejected. Encore reads it from the source, so it
343
- * is a number written out, or one of the two constants imported from
344
- * `@encore.dev/sdk/pubsub`.
312
+ * Values below `-2` are rejected. Must be a numeric literal or one of the
313
+ * exported constants (`NoRetries`, `InfiniteRetries`) so Encore can parse it
314
+ * statically.
345
315
  */
346
316
  maxRetries?: number;
347
317
  }
348
318
 
349
319
  /**
350
- * The `maxRetries` that retries a message not at all: it is forwarded to the
351
- * dead-letter queue as soon as its handler fails once.
320
+ * `maxRetries` value that disables retries and immediately forwards failed
321
+ * messages to the dead-letter queue.
352
322
  */
353
323
  export const NoRetries = -2;
354
324
 
355
325
  /**
356
- * The `maxRetries` that retries a message for as long as its handler fails:
357
- * it is never forwarded to the dead-letter queue.
326
+ * `maxRetries` value that retries failed messages indefinitely without
327
+ * dead-lettering.
358
328
  */
359
329
  export const InfiniteRetries = -1;