@encore.dev/sdk 2.0.0-beta.15 → 2.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -101
- package/app_meta.ts +56 -54
- package/config/config.ts +60 -57
- package/config/secrets.ts +45 -52
- package/config/value.ts +23 -26
- package/cron/mod.ts +28 -29
- package/dist/app_meta.d.ts +52 -50
- package/dist/app_meta.d.ts.map +1 -1
- package/dist/app_meta.js +2 -2
- package/dist/app_meta.js.map +1 -1
- package/dist/config/config.d.ts +58 -55
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +8 -9
- package/dist/config/config.js.map +1 -1
- package/dist/config/secrets.d.ts +45 -52
- package/dist/config/secrets.d.ts.map +1 -1
- package/dist/config/secrets.js +8 -9
- package/dist/config/secrets.js.map +1 -1
- package/dist/config/value.d.ts +20 -23
- package/dist/config/value.d.ts.map +1 -1
- package/dist/config/value.js +20 -23
- package/dist/config/value.js.map +1 -1
- package/dist/cron/mod.d.ts +26 -27
- package/dist/cron/mod.d.ts.map +1 -1
- package/dist/cron/mod.js +13 -14
- package/dist/cron/mod.js.map +1 -1
- package/dist/frontends/mod.d.ts +20 -19
- package/dist/frontends/mod.d.ts.map +1 -1
- package/dist/frontends/mod.js +20 -19
- package/dist/frontends/mod.js.map +1 -1
- package/dist/gateway/errors.d.ts +28 -30
- package/dist/gateway/errors.d.ts.map +1 -1
- package/dist/gateway/errors.js +29 -31
- package/dist/gateway/errors.js.map +1 -1
- package/dist/gateway/match.d.ts +54 -54
- package/dist/gateway/match.d.ts.map +1 -1
- package/dist/gateway/match.js +56 -56
- package/dist/gateway/match.js.map +1 -1
- package/dist/gateway/middleware.d.ts +62 -64
- package/dist/gateway/middleware.d.ts.map +1 -1
- package/dist/gateway/middleware.js +1 -1
- package/dist/gateway/middleware.js.map +1 -1
- package/dist/gateway/mod.d.ts +64 -67
- package/dist/gateway/mod.d.ts.map +1 -1
- package/dist/gateway/mod.js +72 -76
- package/dist/gateway/mod.js.map +1 -1
- package/dist/gateway/request.d.ts +138 -134
- package/dist/gateway/request.d.ts.map +1 -1
- package/dist/gateway/request.js +117 -108
- package/dist/gateway/request.js.map +1 -1
- package/dist/gateway/serve.d.ts +29 -34
- package/dist/gateway/serve.d.ts.map +1 -1
- package/dist/gateway/serve.js +51 -56
- package/dist/gateway/serve.js.map +1 -1
- package/dist/gateways/mod.d.ts +23 -21
- package/dist/gateways/mod.d.ts.map +1 -1
- package/dist/gateways/mod.js +25 -23
- package/dist/gateways/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +1 -1
- package/dist/internal/runtime/napi/napi.d.cts +10 -3
- package/dist/internal/runtime/shutdown.d.ts +75 -57
- package/dist/internal/runtime/shutdown.d.ts.map +1 -1
- package/dist/internal/runtime/shutdown.js +88 -84
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/log/logger.d.ts +43 -37
- package/dist/log/logger.d.ts.map +1 -1
- package/dist/log/logger.js +26 -25
- package/dist/log/logger.js.map +1 -1
- package/dist/metrics/mod.d.ts +133 -114
- package/dist/metrics/mod.d.ts.map +1 -1
- package/dist/metrics/mod.js +109 -101
- package/dist/metrics/mod.js.map +1 -1
- package/dist/otel.d.ts +6 -3
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +6 -3
- package/dist/otel.js.map +1 -1
- package/dist/pubsub/subscription.d.ts +88 -116
- package/dist/pubsub/subscription.d.ts.map +1 -1
- package/dist/pubsub/subscription.js +14 -17
- package/dist/pubsub/subscription.js.map +1 -1
- package/dist/pubsub/topic.d.ts +86 -113
- package/dist/pubsub/topic.d.ts.map +1 -1
- package/dist/pubsub/topic.js +68 -82
- package/dist/pubsub/topic.js.map +1 -1
- package/dist/reqctx/mod.d.ts +83 -86
- package/dist/reqctx/mod.d.ts.map +1 -1
- package/dist/reqctx/mod.js +39 -41
- package/dist/reqctx/mod.js.map +1 -1
- package/dist/services/index.d.ts +76 -75
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +73 -71
- package/dist/services/index.js.map +1 -1
- package/dist/shutdown/mod.d.ts +26 -25
- package/dist/shutdown/mod.d.ts.map +1 -1
- package/dist/shutdown/mod.js +26 -25
- package/dist/shutdown/mod.js.map +1 -1
- package/dist/storage/clickhouse/database.d.ts +113 -115
- package/dist/storage/clickhouse/database.d.ts.map +1 -1
- package/dist/storage/clickhouse/database.js +65 -79
- package/dist/storage/clickhouse/database.js.map +1 -1
- package/dist/storage/clickhouse/errors.d.ts +25 -26
- package/dist/storage/clickhouse/errors.d.ts.map +1 -1
- package/dist/storage/clickhouse/errors.js +15 -17
- package/dist/storage/clickhouse/errors.js.map +1 -1
- package/dist/storage/clickhouse/mod.d.ts +10 -10
- package/dist/storage/clickhouse/mod.js +10 -10
- package/dist/storage/objects/bucket.d.ts +196 -225
- package/dist/storage/objects/bucket.d.ts.map +1 -1
- package/dist/storage/objects/bucket.js +71 -84
- package/dist/storage/objects/bucket.js.map +1 -1
- package/dist/storage/objects/error.d.ts +4 -4
- package/dist/storage/objects/error.js +4 -4
- package/dist/storage/postgres/database.d.ts +124 -149
- package/dist/storage/postgres/database.d.ts.map +1 -1
- package/dist/storage/postgres/database.js +98 -135
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/storage/postgres/errors.d.ts +42 -48
- package/dist/storage/postgres/errors.d.ts.map +1 -1
- package/dist/storage/postgres/errors.js +44 -51
- package/dist/storage/postgres/errors.js.map +1 -1
- package/dist/storage/postgres/interval.d.ts +19 -19
- package/dist/storage/postgres/interval.d.ts.map +1 -1
- package/dist/storage/postgres/interval.js +21 -21
- package/dist/storage/postgres/interval.js.map +1 -1
- package/dist/storage/redis/bitfield.d.ts +48 -23
- package/dist/storage/redis/bitfield.d.ts.map +1 -1
- package/dist/storage/redis/bitfield.js +38 -19
- package/dist/storage/redis/bitfield.js.map +1 -1
- package/dist/storage/redis/command.d.ts +16 -12
- package/dist/storage/redis/command.d.ts.map +1 -1
- package/dist/storage/redis/command.js +16 -12
- package/dist/storage/redis/command.js.map +1 -1
- package/dist/storage/redis/commands.d.ts +99 -100
- package/dist/storage/redis/commands.d.ts.map +1 -1
- package/dist/storage/redis/commands.js +84 -85
- package/dist/storage/redis/commands.js.map +1 -1
- package/dist/storage/redis/database.d.ts +138 -122
- package/dist/storage/redis/database.d.ts.map +1 -1
- package/dist/storage/redis/database.js +120 -101
- package/dist/storage/redis/database.js.map +1 -1
- package/dist/storage/redis/mod.d.ts +52 -48
- package/dist/storage/redis/mod.d.ts.map +1 -1
- package/dist/storage/redis/mod.js +52 -48
- package/dist/storage/redis/mod.js.map +1 -1
- package/dist/storage/redis/options.d.ts +26 -24
- package/dist/storage/redis/options.d.ts.map +1 -1
- package/dist/storage/redis/options.js.map +1 -1
- package/dist/storage/redis/pubsub.d.ts +16 -16
- package/dist/storage/redis/pubsub.d.ts.map +1 -1
- package/dist/storage/redis/pubsub.js +14 -14
- package/dist/storage/redis/pubsub.js.map +1 -1
- package/dist/storage/redis/reply.d.ts +80 -72
- package/dist/storage/redis/reply.d.ts.map +1 -1
- package/dist/storage/redis/reply.js +53 -46
- package/dist/storage/redis/reply.js.map +1 -1
- package/dist/storage/redis/scan.d.ts +4 -4
- package/dist/storage/redis/scan.d.ts.map +1 -1
- package/dist/storage/redis/scan.js +6 -6
- package/dist/storage/redis/scan.js.map +1 -1
- package/dist/storage/redis/script.d.ts +28 -21
- package/dist/storage/redis/script.d.ts.map +1 -1
- package/dist/storage/redis/script.js +29 -22
- package/dist/storage/redis/script.js.map +1 -1
- package/dist/storage/redis/target.d.ts +17 -1
- package/dist/storage/redis/target.d.ts.map +1 -1
- package/dist/storage/redis/target.js +30 -1
- package/dist/storage/redis/target.js.map +1 -1
- package/dist/storage/redis/wire.d.ts +6 -6
- package/dist/storage/redis/wire.d.ts.map +1 -1
- package/dist/storage/redis/wire.js +6 -6
- package/dist/storage/redis/wire.js.map +1 -1
- package/dist/testing/mod.d.ts +83 -88
- package/dist/testing/mod.d.ts.map +1 -1
- package/dist/testing/mod.js +75 -81
- package/dist/testing/mod.js.map +1 -1
- package/dist/testing/playwright.d.ts +28 -32
- package/dist/testing/playwright.d.ts.map +1 -1
- package/dist/testing/playwright.js +22 -27
- package/dist/testing/playwright.js.map +1 -1
- package/dist/testing/puppeteer.d.ts +11 -12
- package/dist/testing/puppeteer.d.ts.map +1 -1
- package/dist/testing/puppeteer.js +17 -18
- package/dist/testing/puppeteer.js.map +1 -1
- package/dist/testing/system.d.ts +72 -90
- package/dist/testing/system.d.ts.map +1 -1
- package/dist/testing/system.js +90 -107
- package/dist/testing/system.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/frontends/mod.test.ts +6 -2
- package/frontends/mod.ts +20 -19
- package/gateway/errors.ts +30 -32
- package/gateway/match.ts +61 -57
- package/gateway/middleware.ts +62 -64
- package/gateway/mod.ts +73 -76
- package/gateway/request.ts +143 -140
- package/gateway/serve.ts +58 -63
- package/gateways/mod.ts +25 -23
- package/internal/runtime/napi/napi.cjs +1 -1
- package/internal/runtime/napi/napi.d.cts +10 -3
- package/internal/runtime/shutdown.ts +113 -101
- package/log/logger.test.ts +8 -0
- package/log/logger.ts +48 -45
- package/metrics/mod.ts +138 -122
- package/otel.ts +6 -3
- package/package.json +1 -1
- package/pubsub/subscription.ts +93 -123
- package/pubsub/topic.ts +96 -130
- package/reqctx/mod.ts +83 -86
- package/services/index.ts +78 -78
- package/shutdown/mod.ts +26 -25
- package/storage/clickhouse/database.ts +115 -129
- package/storage/clickhouse/errors.ts +27 -29
- package/storage/clickhouse/mod.ts +10 -10
- package/storage/objects/bucket.ts +209 -239
- package/storage/objects/error.ts +4 -4
- package/storage/postgres/database.ts +131 -164
- package/storage/postgres/errors.ts +45 -52
- package/storage/postgres/interval.ts +21 -21
- package/storage/redis/bitfield.ts +51 -26
- package/storage/redis/command.ts +16 -12
- package/storage/redis/commands.ts +99 -100
- package/storage/redis/database.ts +145 -123
- package/storage/redis/mod.ts +52 -48
- package/storage/redis/options.ts +26 -24
- package/storage/redis/pubsub.ts +14 -14
- package/storage/redis/redis.test.ts +17 -2
- package/storage/redis/reply.ts +85 -77
- package/storage/redis/scan.ts +6 -6
- package/storage/redis/script.ts +29 -22
- package/storage/redis/target.ts +34 -1
- package/storage/redis/wire.ts +8 -8
- package/testing/mod.ts +99 -105
- package/testing/playwright.ts +32 -37
- package/testing/puppeteer.ts +22 -23
- 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
|
-
/**
|
|
19
|
+
/** Maximum number of messages accepted by a single `publishBatch` call. */
|
|
20
20
|
export const MaxBatchSize = 1000;
|
|
21
21
|
|
|
22
|
-
/** A message
|
|
22
|
+
/** A single message entry for {@link Topic.publishBatch}. */
|
|
23
23
|
export interface BatchMessage<Msg> {
|
|
24
|
-
/**
|
|
24
|
+
/** Message payload, encoded the same way as {@link Topic.publish}. */
|
|
25
25
|
data: Msg;
|
|
26
|
-
/**
|
|
26
|
+
/** Optional attributes delivered alongside the payload. */
|
|
27
27
|
attributes?: Record<string, string>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/** A message
|
|
30
|
+
/** A single message entry for {@link OrderedTopic.publishBatch}. */
|
|
31
31
|
export interface OrderedBatchMessage<Msg> extends BatchMessage<Msg> {
|
|
32
|
-
/**
|
|
32
|
+
/** Non-empty ordering key grouping messages for ordered delivery. */
|
|
33
33
|
orderingKey: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/**
|
|
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
|
-
*
|
|
41
|
-
*
|
|
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
|
|
60
|
-
*
|
|
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
|
-
*
|
|
66
|
-
*
|
|
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
|
-
*
|
|
80
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
96
|
+
* Publishes a message to the topic and returns its unique message ID.
|
|
98
97
|
*
|
|
99
|
-
* JSON values are serialized as
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
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
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* and
|
|
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
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
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
|
-
*
|
|
149
|
-
*
|
|
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
|
|
158
|
-
* await userEvents.publish({ action: "login" }, "user-2"); //
|
|
159
|
-
* await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after
|
|
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
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
171
|
-
*
|
|
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
|
-
*
|
|
187
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
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
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
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
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* and
|
|
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
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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,
|
|
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 ?? '
|
|
352
|
+
: {error: new Error(o.error ?? 'message failed to publish')},
|
|
367
353
|
),
|
|
368
354
|
);
|
|
369
355
|
}
|
|
370
356
|
|
|
371
357
|
/**
|
|
372
|
-
*
|
|
373
|
-
*
|
|
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
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
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
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
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
|
-
*
|
|
413
|
-
*
|
|
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
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
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>;
|