@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,112 +1,107 @@
1
1
  import { OrderedPublisher, OrderedTopicPerms, Publisher, TopicPerms } from './refs.js';
2
- /** The most messages one `publishBatch` call takes. */
2
+ /** Maximum number of messages accepted by a single `publishBatch` call. */
3
3
  export declare const MaxBatchSize = 1000;
4
- /** A message to publish with `Topic.publishBatch`. */
4
+ /** A single message entry for {@link Topic.publishBatch}. */
5
5
  export interface BatchMessage<Msg> {
6
- /** The message, encoded as `publish` encodes it. */
6
+ /** Message payload, encoded the same way as {@link Topic.publish}. */
7
7
  data: Msg;
8
- /** Attributes delivered alongside the payload. */
8
+ /** Optional attributes delivered alongside the payload. */
9
9
  attributes?: Record<string, string>;
10
10
  }
11
- /** A message to publish with `OrderedTopic.publishBatch`. */
11
+ /** A single message entry for {@link OrderedTopic.publishBatch}. */
12
12
  export interface OrderedBatchMessage<Msg> extends BatchMessage<Msg> {
13
- /** The message's ordering key, which cannot be empty. */
13
+ /** Non-empty ordering key grouping messages for ordered delivery. */
14
14
  orderingKey: string;
15
15
  }
16
- /** What became of one message of a batch: its id, or why it was not published. */
16
+ /** Per-message outcome from `publishBatch`: either the message ID or the error. */
17
17
  export type PublishBatchResult = {
18
18
  id: string;
19
19
  } | {
20
20
  error: Error;
21
21
  };
22
22
  /**
23
- * Some messages of a batch were not published. `results` says, in the order
24
- * the messages were given, each one's id or why it was not published.
23
+ * Thrown when one or more messages in a `publishBatch` call fail to publish.
24
+ * {@link results} contains each message's ID or error in input order.
25
25
  */
26
26
  export declare class PublishBatchError extends Error {
27
27
  readonly results: ReadonlyArray<PublishBatchResult>;
28
28
  constructor(results: ReadonlyArray<PublishBatchResult>);
29
29
  }
30
30
  /**
31
- * A topic is a resource to which you can publish messages
32
- * to be delivered to subscribers of that topic.
31
+ * A Pub/Sub topic to which services can publish messages for asynchronous
32
+ * delivery to subscribers.
33
33
  */
34
34
  export declare class Topic<Msg> extends TopicPerms implements Publisher<Msg> {
35
35
  readonly name: string;
36
36
  /**
37
- * The topic's configuration, as declared. `undefined` for a topic referenced
38
- * with `Topic.named`, which is configured where it is declared.
37
+ * Topic configuration as declared, or `undefined` for topics referenced via
38
+ * {@link Topic.named}.
39
39
  */
40
40
  readonly cfg?: TopicConfig<Msg>;
41
41
  private readonly sender;
42
42
  constructor(name: string, cfg?: TopicConfig<Msg>);
43
43
  /**
44
- * Reference an existing topic by name — one another service declares,
45
- * possibly in another language. To declare a new topic, use
46
- * `new Topic(...)` instead.
44
+ * References an existing topic declared elsewhere (including in another
45
+ * service or language). Use `new Topic(...)` to declare a new topic.
47
46
  *
48
- * The message type cannot be inferred, so it must be given:
47
+ * Specify the message type explicitly since it cannot be inferred:
49
48
  *
50
49
  * ```ts
51
50
  * const signups = Topic.named<SignupEvent>("signups");
52
51
  * ```
53
52
  *
54
- * The name must be a string literal, so Encore can resolve it statically.
53
+ * `name` must be a string literal so Encore can resolve it statically.
55
54
  */
56
55
  static named<Msg>(name: string): Topic<Msg>;
57
56
  /**
58
- * Publish a message to the topic, returning its unique id.
57
+ * Publishes a message to the topic and returns its unique message ID.
59
58
  *
60
- * JSON values are serialized as the payload; Buffer and Uint8Array payloads
61
- * are sent as raw bytes. Messages are delivered to subscribers verbatim.
62
- * `attributes` are delivered alongside the payload. The message also
63
- * carries the Request Context fields of the active context declared with
64
- * `pubsub`, into its handler's context; `encore-ctx-*` attributes are
65
- * Encore's, and replaced by them.
59
+ * JSON values are serialized as JSON; `Buffer` and `Uint8Array` values are
60
+ * sent as raw bytes. Optional `attributes` are delivered alongside the
61
+ * payload. Any active Request Context fields declared with `pubsub: true`
62
+ * are propagated automatically (overwriting any reserved `encore-ctx-*`
63
+ * attributes).
66
64
  */
67
65
  publish(msg: Msg, attributes?: Record<string, string>): Promise<string>;
68
66
  /**
69
- * Publish up to {@link MaxBatchSize} messages to the topic, returning their
70
- * ids in the order given. Each message is encoded as `publish` encodes it,
71
- * and carries the Request Context and trace context as a published one does.
67
+ * Publishes up to {@link MaxBatchSize} messages to the topic and returns
68
+ * their message IDs in input order. Each message is encoded and propagates
69
+ * trace and Request Context the same way as {@link publish}.
72
70
  *
73
- * It is not atomic: if some messages are not published, the rest still
74
- * are, and it rejects with a {@link PublishBatchError} saying which. A
75
- * batch of more than {@link MaxBatchSize} messages is refused whole, and
76
- * none of it published. An empty batch publishes nothing.
71
+ * Batch publishing is not atomic: if some messages fail, the others may still
72
+ * succeed, and the call rejects with {@link PublishBatchError}. Batches
73
+ * exceeding {@link MaxBatchSize} are rejected before any message is
74
+ * published. An empty batch resolves to `[]`.
77
75
  */
78
76
  publishBatch(messages: readonly BatchMessage<Msg>[]): Promise<string[]>;
79
77
  ref<P extends TopicPerms>(): P;
80
78
  }
81
79
  /**
82
- * An ordered topic is a topic that delivers the messages sharing an ordering
83
- * key in the order they were published. Each message is published with its
84
- * key:
80
+ * A Pub/Sub topic that delivers messages sharing an ordering key in the exact
81
+ * order they were published:
85
82
  *
86
83
  * ```ts
87
84
  * const userEvents = new OrderedTopic<UserEvent>("user-events", {
88
85
  * deliveryGuarantee: "at-least-once",
89
86
  * });
90
87
  *
91
- * await userEvents.publish({ action: "login" }, "user-1"); // Delivered before the logout
92
- * await userEvents.publish({ action: "login" }, "user-2"); // Delivered at any time: a different key
93
- * await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after the first login
88
+ * await userEvents.publish({ action: "login" }, "user-1"); // Delivered before logout
89
+ * await userEvents.publish({ action: "login" }, "user-2"); // Independent ordering key
90
+ * await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after login
94
91
  * ```
95
92
  *
96
- * A message whose handler fails is retried before the next one with its key
97
- * is delivered, so depending on the retry policy a backlog can build up
98
- * behind it. Once it has been retried as often as the subscription allows, it
99
- * is dead-lettered and the next message with its key delivered. Reason about
100
- * your failure modes and set the retry policy accordingly.
93
+ * If a handler fails on a message, that message is retried before any
94
+ * subsequent message with the same ordering key is delivered. Until it succeeds
95
+ * or exhausts its retry policy and moves to the dead-letter queue, later
96
+ * messages for that key wait behind it — configure your retry policy
97
+ * accordingly.
101
98
  *
102
- * Its throughput is limited by the cloud provider:
99
+ * Cloud provider throughput limits:
100
+ * - AWS: 300 messages/second per topic (see [AWS SQS Quotas]).
101
+ * - GCP: 1 MB/s per ordering key (see [GCP PubSub Quotas]).
103
102
  *
104
- * - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
105
- * - GCP: 1MB/s for each ordering key (see [GCP PubSub Quotas]).
106
- *
107
- * Locally (`encore run`, `encore test`) messages are delivered in order too:
108
- * a message waits until the earlier ones with the same key are processed or
109
- * dead-lettered.
103
+ * Locally (`encore run`, `encore test`), messages with the same ordering key
104
+ * are likewise delivered sequentially until processed or dead-lettered.
110
105
  *
111
106
  * [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
112
107
  * [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#resource_limits
@@ -114,14 +109,14 @@ export declare class Topic<Msg> extends TopicPerms implements Publisher<Msg> {
114
109
  export declare class OrderedTopic<Msg> extends OrderedTopicPerms implements OrderedPublisher<Msg> {
115
110
  readonly name: string;
116
111
  /**
117
- * The topic's configuration, as declared. `undefined` for a topic referenced
118
- * with `OrderedTopic.named`, which is configured where it is declared.
112
+ * Topic configuration as declared, or `undefined` for topics referenced via
113
+ * {@link OrderedTopic.named}.
119
114
  */
120
115
  readonly cfg?: OrderedTopicConfig<Msg>;
121
116
  private readonly sender;
122
117
  constructor(name: string, cfg?: OrderedTopicConfig<Msg>);
123
118
  /**
124
- * Reference an existing ordered topic by name. See `Topic.named`.
119
+ * References an existing ordered topic by name (see {@link Topic.named}).
125
120
  *
126
121
  * ```ts
127
122
  * const changes = OrderedTopic.named<ChangeEvent>("changes");
@@ -129,90 +124,68 @@ export declare class OrderedTopic<Msg> extends OrderedTopicPerms implements Orde
129
124
  */
130
125
  static named<Msg>(name: string): OrderedTopic<Msg>;
131
126
  /**
132
- * Publish a message to the topic, returning its unique id. Messages
133
- * published with the same `orderingKey`, which cannot be empty, are
134
- * delivered in the order they were published.
127
+ * Publishes a message with a non-empty `orderingKey` and returns its unique
128
+ * message ID. Messages sharing an ordering key are delivered in publish
129
+ * order.
135
130
  *
136
- * JSON values are serialized as the payload; Buffer and Uint8Array payloads
137
- * are sent as raw bytes. Messages are delivered to subscribers verbatim.
138
- * `attributes` are delivered alongside the payload. The message also
139
- * carries the Request Context fields of the active context declared with
140
- * `pubsub`, into its handler's context; `encore-ctx-*` attributes are
141
- * Encore's, and replaced by them.
131
+ * JSON values are serialized as JSON; `Buffer` and `Uint8Array` values are
132
+ * sent as raw bytes. Optional `attributes` are delivered alongside the
133
+ * payload. Any active Request Context fields declared with `pubsub: true`
134
+ * are propagated automatically (overwriting any reserved `encore-ctx-*`
135
+ * attributes).
142
136
  */
143
137
  publish(msg: Msg, orderingKey: string, attributes?: Record<string, string>): Promise<string>;
144
138
  /**
145
- * Publish up to {@link MaxBatchSize} messages to the topic, returning their
146
- * ids in the order given. Each message is encoded as `publish` encodes it,
147
- * and carries the Request Context and trace context as a published one does.
139
+ * Publishes up to {@link MaxBatchSize} ordered messages and returns their
140
+ * message IDs in input order. Each message is encoded and propagates trace
141
+ * and Request Context the same way as {@link publish}.
148
142
  *
149
- * The messages sharing an ordering key are published in the order given,
150
- * and once one of them is not published, neither are the later ones with
151
- * its key. It is not atomic: if some messages are not published, the rest
152
- * still are, and it rejects with a {@link PublishBatchError} saying which.
153
- * A batch of more than {@link MaxBatchSize} messages, or with a message
154
- * whose `orderingKey` is not a non-empty string, is refused whole, and none
155
- * of it published. An empty batch publishes nothing.
143
+ * Messages with the same ordering key are published in order; if one fails,
144
+ * subsequent messages with that key in the batch are not published. Batch
145
+ * publishing is not atomic across keys — on partial failure, rejects with
146
+ * {@link PublishBatchError}. Batches exceeding {@link MaxBatchSize} or
147
+ * containing an empty `orderingKey` are rejected before any message is
148
+ * published. An empty batch resolves to `[]`.
156
149
  */
157
150
  publishBatch(messages: readonly OrderedBatchMessage<Msg>[]): Promise<string[]>;
158
151
  ref<P extends OrderedTopicPerms>(): P;
159
152
  }
160
153
  /**
161
- * DeliveryGuarantee is used to configure the delivery contract for a topic,
162
- * written out as one of the two strings: Encore reads it from the source.
163
- *
164
- * `"at-least-once"` guarantees that a message for a subscription is
165
- * delivered to a consumer at least once. On AWS and GCP there is no limit to
166
- * the throughput for a topic.
167
- *
168
- * `"exactly-once"` guarantees that a message for a subscription is delivered
169
- * to a consumer exactly once, to the best of the system's ability.
170
- *
171
- * However, there are edge cases when a message might be redelivered.
172
- * For example, if a networking issue causes the acknowledgement of success
173
- * processing the message to be lost before the cloud provider receives it.
174
- *
175
- * It is also important to note that the exactly-once delivery guarantee only
176
- * applies to the delivery of the message to the consumer, and not to the
177
- * original publishing of the message, such that if a message is published twice,
178
- * such as due to an retry within the application logic, it will be delivered twice.
179
- * (i.e. exactly-once delivery does not imply message deduplication on publish)
154
+ * Delivery guarantee for a topic. Must be written as a string literal so
155
+ * Encore can read it statically:
180
156
  *
181
- * As such it's recommended that the subscription handler function is idempotent
182
- * and is able to handle duplicate messages.
157
+ * - `"at-least-once"`: guarantees each message is delivered at least once,
158
+ * with no provider throughput limit on AWS or GCP.
159
+ * - `"exactly-once"`: delivers each message once on a best-effort basis. Edge
160
+ * cases (such as a lost acknowledgment over the network) can still cause
161
+ * redelivery, and publishing the same message twice will still deliver it
162
+ * twice (no publish-side deduplication). Handlers should therefore remain
163
+ * idempotent.
183
164
  *
184
- * Subscriptions attached to exactly-once topics have higher message delivery latency compared to at-least-once.
185
- *
186
- * By using exactly-once semantics on a topic, the throughput will be limited depending on the cloud provider:
187
- * - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
188
- * - GCP: At least 3,000 messages per second across all topics in the region
189
- * (can be higher on the region see [GCP PubSub Quotas]).
165
+ * `"exactly-once"` has higher delivery latency and lower throughput limits:
166
+ * - AWS: 300 messages/second per topic (see [AWS SQS Quotas]).
167
+ * - GCP: at least 3,000 messages/second across all topics in a region (see
168
+ * [GCP PubSub Quotas]).
190
169
  *
191
170
  * [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
192
171
  * [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#quotas
193
172
  */
194
173
  export type DeliveryGuarantee = 'at-least-once' | 'exactly-once';
195
- /**
196
- * TopicConfig is used when creating a Topic
197
- */
174
+ /** Configuration options for declaring a {@link Topic}. */
198
175
  export interface TopicConfig<_Msg> {
199
176
  /**
200
- * DeliveryGuarantee is used to configure the delivery guarantee of a Topic:
201
- * `"at-least-once"` or `"exactly-once"`, written out. Defaults to
202
- * `"at-least-once"`.
177
+ * Delivery guarantee for the topic (`"at-least-once"` or `"exactly-once"`),
178
+ * written as a string literal. Defaults to `"at-least-once"`.
203
179
  */
204
180
  deliveryGuarantee?: DeliveryGuarantee;
205
181
  /**
206
- * Tags that classify the topic, for policies to read: written out as
207
- * string literals, as in `{data: "pci"}`. Keys and values are lowercase
208
- * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
209
- * letter, and not with `encore`, which is reserved. At most 32 tags.
182
+ * Static string-literal tags that classify the topic for policy checks
183
+ * (e.g. `{data: "pci"}`). Keys and values may contain lowercase letters,
184
+ * digits, `_`, and `-`, up to 63 characters. Keys must start with a letter
185
+ * and cannot start with the reserved prefix `encore`. At most 32 tags.
210
186
  */
211
187
  tags?: Record<string, string>;
212
188
  }
213
- /**
214
- * OrderedTopicConfig is used when creating an OrderedTopic. It configures what
215
- * a TopicConfig does; the ordering key is given with each message.
216
- */
189
+ /** Configuration options for declaring an {@link OrderedTopic}. */
217
190
  export type OrderedTopicConfig<Msg = unknown> = TopicConfig<Msg>;
218
191
  //# sourceMappingURL=topic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"topic.d.ts","sourceRoot":"","sources":["../../pubsub/topic.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,UAAU,EACX,MAAM,QAAQ,CAAC;AAEhB,uDAAuD;AACvD,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,sDAAsD;AACtD,MAAM,WAAW,YAAY,CAAC,GAAG;IAC/B,oDAAoD;IACpD,IAAI,EAAE,GAAG,CAAC;IACV,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,6DAA6D;AAC7D,MAAM,WAAW,mBAAmB,CAAC,GAAG,CAAE,SAAQ,YAAY,CAAC,GAAG,CAAC;IACjE,yDAAyD;IACzD,WAAW,EAAE,MAA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AW,CAAC,IAAI;IAC/B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAEtC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,CAAC,GAAG,GAAG,OAAO,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC"}
@@ -5,11 +5,11 @@ import { outgoingContext } from '../internal/testing/carry.js';
5
5
  import { currentScope, systemTest, testMode, } from '../internal/testing/scope.js';
6
6
  import { encodePayload, rawPayloads } from './encoding.js';
7
7
  import { OrderedTopicPerms, TopicPerms, } from './refs.js';
8
- /** The most messages one `publishBatch` call takes. */
8
+ /** Maximum number of messages accepted by a single `publishBatch` call. */
9
9
  export const MaxBatchSize = 1000;
10
10
  /**
11
- * Some messages of a batch were not published. `results` says, in the order
12
- * the messages were given, each one's id or why it was not published.
11
+ * Thrown when one or more messages in a `publishBatch` call fail to publish.
12
+ * {@link results} contains each message's ID or error in input order.
13
13
  */
14
14
  export class PublishBatchError extends Error {
15
15
  results;
@@ -23,14 +23,14 @@ export class PublishBatchError extends Error {
23
23
  }
24
24
  }
25
25
  /**
26
- * A topic is a resource to which you can publish messages
27
- * to be delivered to subscribers of that topic.
26
+ * A Pub/Sub topic to which services can publish messages for asynchronous
27
+ * delivery to subscribers.
28
28
  */
29
29
  export class Topic extends TopicPerms {
30
30
  name;
31
31
  /**
32
- * The topic's configuration, as declared. `undefined` for a topic referenced
33
- * with `Topic.named`, which is configured where it is declared.
32
+ * Topic configuration as declared, or `undefined` for topics referenced via
33
+ * {@link Topic.named}.
34
34
  */
35
35
  cfg;
36
36
  sender;
@@ -41,31 +41,29 @@ export class Topic extends TopicPerms {
41
41
  this.sender = new Sender(name);
42
42
  }
43
43
  /**
44
- * Reference an existing topic by name — one another service declares,
45
- * possibly in another language. To declare a new topic, use
46
- * `new Topic(...)` instead.
44
+ * References an existing topic declared elsewhere (including in another
45
+ * service or language). Use `new Topic(...)` to declare a new topic.
47
46
  *
48
- * The message type cannot be inferred, so it must be given:
47
+ * Specify the message type explicitly since it cannot be inferred:
49
48
  *
50
49
  * ```ts
51
50
  * const signups = Topic.named<SignupEvent>("signups");
52
51
  * ```
53
52
  *
54
- * The name must be a string literal, so Encore can resolve it statically.
53
+ * `name` must be a string literal so Encore can resolve it statically.
55
54
  */
56
55
  static named(name) {
57
56
  // Configured where it is declared, so it has no `cfg` of its own.
58
57
  return new Topic(name);
59
58
  }
60
59
  /**
61
- * Publish a message to the topic, returning its unique id.
60
+ * Publishes a message to the topic and returns its unique message ID.
62
61
  *
63
- * JSON values are serialized as the payload; Buffer and Uint8Array payloads
64
- * are sent as raw bytes. Messages are delivered to subscribers verbatim.
65
- * `attributes` are delivered alongside the payload. The message also
66
- * carries the Request Context fields of the active context declared with
67
- * `pubsub`, into its handler's context; `encore-ctx-*` attributes are
68
- * Encore's, and replaced by them.
62
+ * JSON values are serialized as JSON; `Buffer` and `Uint8Array` values are
63
+ * sent as raw bytes. Optional `attributes` are delivered alongside the
64
+ * payload. Any active Request Context fields declared with `pubsub: true`
65
+ * are propagated automatically (overwriting any reserved `encore-ctx-*`
66
+ * attributes).
69
67
  */
70
68
  async publish(msg, attributes) {
71
69
  const ctx = outgoingContext();
@@ -76,14 +74,14 @@ export class Topic extends TopicPerms {
76
74
  .publish(payload, messageAttributes(attributes, ctx), source);
77
75
  }
78
76
  /**
79
- * Publish up to {@link MaxBatchSize} messages to the topic, returning their
80
- * ids in the order given. Each message is encoded as `publish` encodes it,
81
- * and carries the Request Context and trace context as a published one does.
77
+ * Publishes up to {@link MaxBatchSize} messages to the topic and returns
78
+ * their message IDs in input order. Each message is encoded and propagates
79
+ * trace and Request Context the same way as {@link publish}.
82
80
  *
83
- * It is not atomic: if some messages are not published, the rest still
84
- * are, and it rejects with a {@link PublishBatchError} saying which. A
85
- * batch of more than {@link MaxBatchSize} messages is refused whole, and
86
- * none of it published. An empty batch publishes nothing.
81
+ * Batch publishing is not atomic: if some messages fail, the others may still
82
+ * succeed, and the call rejects with {@link PublishBatchError}. Batches
83
+ * exceeding {@link MaxBatchSize} are rejected before any message is
84
+ * published. An empty batch resolves to `[]`.
87
85
  */
88
86
  async publishBatch(messages) {
89
87
  checkBatchSize(messages.length);
@@ -101,34 +99,31 @@ export class Topic extends TopicPerms {
101
99
  }
102
100
  }
103
101
  /**
104
- * An ordered topic is a topic that delivers the messages sharing an ordering
105
- * key in the order they were published. Each message is published with its
106
- * key:
102
+ * A Pub/Sub topic that delivers messages sharing an ordering key in the exact
103
+ * order they were published:
107
104
  *
108
105
  * ```ts
109
106
  * const userEvents = new OrderedTopic<UserEvent>("user-events", {
110
107
  * deliveryGuarantee: "at-least-once",
111
108
  * });
112
109
  *
113
- * await userEvents.publish({ action: "login" }, "user-1"); // Delivered before the logout
114
- * await userEvents.publish({ action: "login" }, "user-2"); // Delivered at any time: a different key
115
- * await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after the first login
110
+ * await userEvents.publish({ action: "login" }, "user-1"); // Delivered before logout
111
+ * await userEvents.publish({ action: "login" }, "user-2"); // Independent ordering key
112
+ * await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after login
116
113
  * ```
117
114
  *
118
- * A message whose handler fails is retried before the next one with its key
119
- * is delivered, so depending on the retry policy a backlog can build up
120
- * behind it. Once it has been retried as often as the subscription allows, it
121
- * is dead-lettered and the next message with its key delivered. Reason about
122
- * your failure modes and set the retry policy accordingly.
115
+ * If a handler fails on a message, that message is retried before any
116
+ * subsequent message with the same ordering key is delivered. Until it succeeds
117
+ * or exhausts its retry policy and moves to the dead-letter queue, later
118
+ * messages for that key wait behind it — configure your retry policy
119
+ * accordingly.
123
120
  *
124
- * Its throughput is limited by the cloud provider:
121
+ * Cloud provider throughput limits:
122
+ * - AWS: 300 messages/second per topic (see [AWS SQS Quotas]).
123
+ * - GCP: 1 MB/s per ordering key (see [GCP PubSub Quotas]).
125
124
  *
126
- * - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
127
- * - GCP: 1MB/s for each ordering key (see [GCP PubSub Quotas]).
128
- *
129
- * Locally (`encore run`, `encore test`) messages are delivered in order too:
130
- * a message waits until the earlier ones with the same key are processed or
131
- * dead-lettered.
125
+ * Locally (`encore run`, `encore test`), messages with the same ordering key
126
+ * are likewise delivered sequentially until processed or dead-lettered.
132
127
  *
133
128
  * [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
134
129
  * [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#resource_limits
@@ -136,8 +131,8 @@ export class Topic extends TopicPerms {
136
131
  export class OrderedTopic extends OrderedTopicPerms {
137
132
  name;
138
133
  /**
139
- * The topic's configuration, as declared. `undefined` for a topic referenced
140
- * with `OrderedTopic.named`, which is configured where it is declared.
134
+ * Topic configuration as declared, or `undefined` for topics referenced via
135
+ * {@link OrderedTopic.named}.
141
136
  */
142
137
  cfg;
143
138
  sender;
@@ -148,7 +143,7 @@ export class OrderedTopic extends OrderedTopicPerms {
148
143
  this.sender = new Sender(name);
149
144
  }
150
145
  /**
151
- * Reference an existing ordered topic by name. See `Topic.named`.
146
+ * References an existing ordered topic by name (see {@link Topic.named}).
152
147
  *
153
148
  * ```ts
154
149
  * const changes = OrderedTopic.named<ChangeEvent>("changes");
@@ -159,16 +154,15 @@ export class OrderedTopic extends OrderedTopicPerms {
159
154
  return new OrderedTopic(name);
160
155
  }
161
156
  /**
162
- * Publish a message to the topic, returning its unique id. Messages
163
- * published with the same `orderingKey`, which cannot be empty, are
164
- * delivered in the order they were published.
157
+ * Publishes a message with a non-empty `orderingKey` and returns its unique
158
+ * message ID. Messages sharing an ordering key are delivered in publish
159
+ * order.
165
160
  *
166
- * JSON values are serialized as the payload; Buffer and Uint8Array payloads
167
- * are sent as raw bytes. Messages are delivered to subscribers verbatim.
168
- * `attributes` are delivered alongside the payload. The message also
169
- * carries the Request Context fields of the active context declared with
170
- * `pubsub`, into its handler's context; `encore-ctx-*` attributes are
171
- * Encore's, and replaced by them.
161
+ * JSON values are serialized as JSON; `Buffer` and `Uint8Array` values are
162
+ * sent as raw bytes. Optional `attributes` are delivered alongside the
163
+ * payload. Any active Request Context fields declared with `pubsub: true`
164
+ * are propagated automatically (overwriting any reserved `encore-ctx-*`
165
+ * attributes).
172
166
  */
173
167
  async publish(msg, orderingKey, attributes) {
174
168
  if (typeof orderingKey !== 'string' || orderingKey.length === 0) {
@@ -182,17 +176,16 @@ export class OrderedTopic extends OrderedTopicPerms {
182
176
  .publish(payload, messageAttributes(attributes, ctx), source, orderingKey);
183
177
  }
184
178
  /**
185
- * Publish up to {@link MaxBatchSize} messages to the topic, returning their
186
- * ids in the order given. Each message is encoded as `publish` encodes it,
187
- * and carries the Request Context and trace context as a published one does.
179
+ * Publishes up to {@link MaxBatchSize} ordered messages and returns their
180
+ * message IDs in input order. Each message is encoded and propagates trace
181
+ * and Request Context the same way as {@link publish}.
188
182
  *
189
- * The messages sharing an ordering key are published in the order given,
190
- * and once one of them is not published, neither are the later ones with
191
- * its key. It is not atomic: if some messages are not published, the rest
192
- * still are, and it rejects with a {@link PublishBatchError} saying which.
193
- * A batch of more than {@link MaxBatchSize} messages, or with a message
194
- * whose `orderingKey` is not a non-empty string, is refused whole, and none
195
- * of it published. An empty batch publishes nothing.
183
+ * Messages with the same ordering key are published in order; if one fails,
184
+ * subsequent messages with that key in the batch are not published. Batch
185
+ * publishing is not atomic across keys — on partial failure, rejects with
186
+ * {@link PublishBatchError}. Batches exceeding {@link MaxBatchSize} or
187
+ * containing an empty `orderingKey` are rejected before any message is
188
+ * published. An empty batch resolves to `[]`.
196
189
  */
197
190
  async publishBatch(messages) {
198
191
  checkBatchSize(messages.length);
@@ -216,14 +209,13 @@ export class OrderedTopic extends OrderedTopicPerms {
216
209
  }
217
210
  }
218
211
  /**
219
- * Where a topic's messages go: to the runtime's topic, or, in a test, to the
220
- * test's record of what it published, sent nowhere, for it to read back with
221
- * `published` or hand to a subscription with `deliver`. A system test's are
222
- * sent: the subscriptions handle them, in the services that declare them.
212
+ * Routes publishes to the native runtime topic, or to the active unit-test
213
+ * scope recorder (in system tests, messages go through the real runtime so
214
+ * service subscriptions consume them).
223
215
  */
224
216
  class Sender {
225
217
  name;
226
- /** The runtime's topic, made on first use in test mode. */
218
+ /** Native runtime topic, initialized lazily in test mode. */
227
219
  topic;
228
220
  constructor(name) {
229
221
  this.name = name;
@@ -239,7 +231,7 @@ class Sender {
239
231
  return (this.topic ??= runtime.RT.pubsubTopic(this.name));
240
232
  }
241
233
  }
242
- /** Publishes to the record of what the test `scope` published to `topic`. */
234
+ /** Records published messages into the active unit-test scope. */
243
235
  function recorder(scope, topic) {
244
236
  const record = (data, attributes, orderingKey) => {
245
237
  const id = scope.native.recordPublished(topic, data, attributes ?? undefined, orderingKey ?? undefined);
@@ -254,19 +246,13 @@ function recorder(scope, topic) {
254
246
  })),
255
247
  };
256
248
  }
257
- /**
258
- * Refuses a batch of more than {@link MaxBatchSize} messages before any of
259
- * it is encoded, as the runtime would refuse it once it was.
260
- */
249
+ /** Rejects batches larger than {@link MaxBatchSize} before encoding payloads. */
261
250
  function checkBatchSize(count) {
262
251
  if (count > MaxBatchSize) {
263
- throw new Error(`failed to publish: a batch has at most ${MaxBatchSize} messages, and this one has ${count}`);
252
+ throw new Error(`failed to publish: a batch has at most ${MaxBatchSize} messages, got ${count}`);
264
253
  }
265
254
  }
266
- /**
267
- * Publishes the encoded messages, answering with their ids, or rejecting
268
- * with a {@link PublishBatchError} if any was not published.
269
- */
255
+ /** Publishes encoded batch entries, rejecting with {@link PublishBatchError} if any failed. */
270
256
  async function publishBatch(impl, entries, source) {
271
257
  if (entries.length === 0)
272
258
  return [];
@@ -276,6 +262,6 @@ async function publishBatch(impl, entries, source) {
276
262
  }
277
263
  throw new PublishBatchError(outcomes.map(o => o.id !== undefined && o.id !== null
278
264
  ? { id: o.id }
279
- : { error: new Error(o.error ?? 'the message was not published') }));
265
+ : { error: new Error(o.error ?? 'message failed to publish') }));
280
266
  }
281
267
  //# sourceMappingURL=topic.js.map