@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/dist/pubsub/topic.d.ts
CHANGED
|
@@ -1,112 +1,107 @@
|
|
|
1
1
|
import { OrderedPublisher, OrderedTopicPerms, Publisher, TopicPerms } from './refs.js';
|
|
2
|
-
/**
|
|
2
|
+
/** Maximum number of messages accepted by a single `publishBatch` call. */
|
|
3
3
|
export declare const MaxBatchSize = 1000;
|
|
4
|
-
/** A message
|
|
4
|
+
/** A single message entry for {@link Topic.publishBatch}. */
|
|
5
5
|
export interface BatchMessage<Msg> {
|
|
6
|
-
/**
|
|
6
|
+
/** Message payload, encoded the same way as {@link Topic.publish}. */
|
|
7
7
|
data: Msg;
|
|
8
|
-
/**
|
|
8
|
+
/** Optional attributes delivered alongside the payload. */
|
|
9
9
|
attributes?: Record<string, string>;
|
|
10
10
|
}
|
|
11
|
-
/** A message
|
|
11
|
+
/** A single message entry for {@link OrderedTopic.publishBatch}. */
|
|
12
12
|
export interface OrderedBatchMessage<Msg> extends BatchMessage<Msg> {
|
|
13
|
-
/**
|
|
13
|
+
/** Non-empty ordering key grouping messages for ordered delivery. */
|
|
14
14
|
orderingKey: string;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
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
|
-
*
|
|
24
|
-
*
|
|
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
|
|
32
|
-
*
|
|
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
|
-
*
|
|
38
|
-
*
|
|
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
|
-
*
|
|
45
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
57
|
+
* Publishes a message to the topic and returns its unique message ID.
|
|
59
58
|
*
|
|
60
|
-
* JSON values are serialized as
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
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
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* and
|
|
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
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
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
|
-
*
|
|
83
|
-
*
|
|
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
|
|
92
|
-
* await userEvents.publish({ action: "login" }, "user-2"); //
|
|
93
|
-
* await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after
|
|
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
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
105
|
-
*
|
|
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
|
-
*
|
|
118
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
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
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
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
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* and
|
|
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
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
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
|
-
*
|
|
162
|
-
*
|
|
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
|
-
*
|
|
182
|
-
*
|
|
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
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
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
|
-
*
|
|
201
|
-
*
|
|
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
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
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,
|
|
1
|
+
{"version":3,"file":"topic.d.ts","sourceRoot":"","sources":["../../pubsub/topic.ts"],"names":[],"mappings":"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"}
|
package/dist/pubsub/topic.js
CHANGED
|
@@ -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
|
-
/**
|
|
8
|
+
/** Maximum number of messages accepted by a single `publishBatch` call. */
|
|
9
9
|
export const MaxBatchSize = 1000;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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
|
|
27
|
-
*
|
|
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
|
-
*
|
|
33
|
-
*
|
|
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
|
-
*
|
|
45
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
60
|
+
* Publishes a message to the topic and returns its unique message ID.
|
|
62
61
|
*
|
|
63
|
-
* JSON values are serialized as
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
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
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* and
|
|
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
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
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
|
-
*
|
|
105
|
-
*
|
|
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
|
|
114
|
-
* await userEvents.publish({ action: "login" }, "user-2"); //
|
|
115
|
-
* await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after
|
|
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
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
127
|
-
*
|
|
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
|
-
*
|
|
140
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
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
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
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
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* and
|
|
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
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
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
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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,
|
|
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 ?? '
|
|
265
|
+
: { error: new Error(o.error ?? 'message failed to publish') }));
|
|
280
266
|
}
|
|
281
267
|
//# sourceMappingURL=topic.js.map
|