@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.
- 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
|
@@ -4,66 +4,59 @@ import { DurationString } from '../types/mod.js';
|
|
|
4
4
|
import { OrderedTopic, Topic } from './topic.js';
|
|
5
5
|
import { type Scope } from '../internal/testing/scope.js';
|
|
6
6
|
/**
|
|
7
|
-
* A delivered
|
|
7
|
+
* A delivered Pub/Sub message along with its raw bytes and broker metadata.
|
|
8
8
|
*
|
|
9
|
-
* The handler runs
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* The subscription handler runs inside the message's context: any spans or
|
|
10
|
+
* downstream calls continue the publisher's trace, and propagated Request
|
|
11
|
+
* Context fields (`@encore.dev/sdk/reqctx`) are available via `field.get()`.
|
|
12
12
|
*/
|
|
13
13
|
export interface Message<T = unknown> {
|
|
14
|
-
/**
|
|
14
|
+
/** Decoded payload according to the subscription's `encoding` and `decode` options. */
|
|
15
15
|
data: T;
|
|
16
|
-
/**
|
|
16
|
+
/** Original payload bytes as published. */
|
|
17
17
|
rawData: Buffer;
|
|
18
|
-
/**
|
|
19
|
-
* The unique id of the message: the one `publish` returned. It stays the
|
|
20
|
-
* same across delivery attempts.
|
|
21
|
-
*/
|
|
18
|
+
/** Unique message ID returned by `publish`; remains stable across redelivery attempts. */
|
|
22
19
|
id: string;
|
|
23
20
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* context.
|
|
21
|
+
* Message attributes set by the publisher, excluding internal `encore-ctx-*`
|
|
22
|
+
* attributes used to propagate Request Context fields.
|
|
27
23
|
*/
|
|
28
24
|
attributes: Record<string, string>;
|
|
29
|
-
/**
|
|
25
|
+
/** 1-based delivery attempt counter. */
|
|
30
26
|
deliveryAttempt: number;
|
|
31
|
-
/**
|
|
27
|
+
/** Timestamp when the message was published. */
|
|
32
28
|
publishTime: Date;
|
|
33
|
-
/**
|
|
34
|
-
* unordered one. */
|
|
29
|
+
/** Ordering key for ordered topics, or `null` for unordered topics. */
|
|
35
30
|
orderingKey: string | null;
|
|
36
31
|
}
|
|
37
32
|
export declare class Subscription<Msg> {
|
|
38
33
|
private readonly topic;
|
|
39
|
-
/**
|
|
34
|
+
/** Subscription name, unique within its topic. */
|
|
40
35
|
readonly name: string;
|
|
41
36
|
private readonly impl?;
|
|
42
|
-
/**
|
|
37
|
+
/** Dispatches a delivered message to the configured handler. */
|
|
43
38
|
private readonly dispatch;
|
|
44
39
|
constructor(topic: Topic<Msg> | OrderedTopic<Msg>, name: string, cfg: SubscriptionConfig<Msg>);
|
|
45
40
|
private startSubscribing;
|
|
46
41
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* fails, rejecting with its error: that message is handed over again next
|
|
51
|
-
* time, as its next attempt.
|
|
42
|
+
* Delivers pending matching messages from `scope` to this subscription in
|
|
43
|
+
* order and returns the number of messages handled. Rejects on the first
|
|
44
|
+
* handler error so that message remains pending for the next attempt.
|
|
52
45
|
*
|
|
53
46
|
* @internal
|
|
54
47
|
*/
|
|
55
48
|
static deliverIn(sub: Subscription<unknown>, scope: Scope, maxDeliveries: number): Promise<number>;
|
|
56
49
|
}
|
|
57
50
|
/**
|
|
58
|
-
*
|
|
59
|
-
* {@link SubscriptionOptions}
|
|
51
|
+
* Configuration for creating a {@link Subscription}, combining
|
|
52
|
+
* {@link SubscriptionOptions} with payload decoding settings.
|
|
60
53
|
*
|
|
61
|
-
*
|
|
62
|
-
* `decode`
|
|
54
|
+
* Messages are JSON-decoded by default; byte subscriptions must specify
|
|
55
|
+
* `encoding: "raw"`. Provide `decode` to validate or transform parsed JSON, or
|
|
56
|
+
* to decode a custom binary format.
|
|
63
57
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* by the target cloud pubsub implementation).
|
|
58
|
+
* Cloud providers may clamp configuration values (such as `ackDeadline`) to
|
|
59
|
+
* their supported ranges.
|
|
67
60
|
*/
|
|
68
61
|
export type SubscriptionConfig<Msg> = SubscriptionOptions<Msg> & ([Msg] extends [Uint8Array] ? {
|
|
69
62
|
encoding: 'raw';
|
|
@@ -75,149 +68,128 @@ export type SubscriptionConfig<Msg> = SubscriptionOptions<Msg> & ([Msg] extends
|
|
|
75
68
|
encoding: 'raw';
|
|
76
69
|
decode: (data: unknown) => Msg;
|
|
77
70
|
});
|
|
78
|
-
/**
|
|
71
|
+
/** Subscription options other than payload decoding. */
|
|
79
72
|
export interface SubscriptionOptions<Msg> {
|
|
80
73
|
/**
|
|
81
|
-
*
|
|
82
|
-
* sent on the topic.
|
|
74
|
+
* Function invoked to process each message published to the topic.
|
|
83
75
|
*
|
|
84
|
-
*
|
|
85
|
-
* TypeScript types
|
|
76
|
+
* Receives a {@link Message} containing the decoded `data` and raw bytes in
|
|
77
|
+
* `rawData`. TypeScript types are not checked at runtime; use `decode` for
|
|
78
|
+
* runtime validation.
|
|
86
79
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* attempt to be made (unless the retry policy's MaxRetries has been reached).
|
|
80
|
+
* Throwing or rejecting negatively acknowledges (nacks) the message,
|
|
81
|
+
* triggering redelivery until {@link RetryPolicy.maxRetries} is exhausted.
|
|
90
82
|
*/
|
|
91
83
|
handler: (msg: Message<Msg>) => Promise<unknown>;
|
|
92
84
|
/**
|
|
93
|
-
*
|
|
94
|
-
* simultaneously per instance of the service for this subscription.
|
|
95
|
-
*
|
|
96
|
-
* Note that this is per instance of the service, so if your service has
|
|
97
|
-
* scaled to 10 instances and this is set to 10, then 100 messages could be
|
|
98
|
-
* processed simultaneously.
|
|
99
|
-
*
|
|
100
|
-
* If the value is negative, then there will be no limit on the number
|
|
101
|
-
* of messages processed simultaneously.
|
|
85
|
+
* Maximum number of messages processed concurrently per service instance.
|
|
102
86
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* be configured as a Push Subscription and will have an adaptive concurrency
|
|
106
|
-
* See [GCP Push Delivery Rate](https://cloud.google.com/pubsub/docs/push#push_delivery_rate).
|
|
87
|
+
* For example, setting `maxConcurrency: 10` across 10 service instances
|
|
88
|
+
* allows up to 100 concurrent messages. Negative values disable the limit.
|
|
107
89
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
90
|
+
* Note: Not supported on all providers — on GCP Cloud Run with unordered
|
|
91
|
+
* topics, subscriptions use Push Delivery with adaptive concurrency (see
|
|
92
|
+
* [GCP Push Delivery Rate](https://cloud.google.com/pubsub/docs/push#push_delivery_rate)).
|
|
93
|
+
* Also has no effect in Encore Cloud environments. Defaults to a
|
|
94
|
+
* provider-specific value when omitted.
|
|
110
95
|
*/
|
|
111
96
|
maxConcurrency?: number;
|
|
112
97
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* has the ack deadline.
|
|
98
|
+
* Maximum time the broker waits for acknowledgment before redelivering a
|
|
99
|
+
* message. For pulled subscriptions, Encore automatically extends the lease
|
|
100
|
+
* while the handler runs (up to 1 hour, or `ackDeadline` if longer); GCP push
|
|
101
|
+
* subscriptions are bounded by `ackDeadline`.
|
|
118
102
|
*
|
|
119
|
-
*
|
|
120
|
-
* 1 second.
|
|
103
|
+
* Defaults to 30 seconds; must be at least 1 second.
|
|
121
104
|
*/
|
|
122
105
|
ackDeadline?: DurationString;
|
|
123
106
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* Default is 7 days.
|
|
107
|
+
* How long undelivered messages are retained before being purged.
|
|
108
|
+
* Defaults to 7 days.
|
|
128
109
|
*/
|
|
129
110
|
messageRetention?: DurationString;
|
|
130
111
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
112
|
+
* Retry policy controlling redelivery backoff and dead-lettering when the
|
|
113
|
+
* handler fails.
|
|
133
114
|
*/
|
|
134
115
|
retryPolicy?: RetryPolicy;
|
|
135
116
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
117
|
+
* Optional attribute filter expression selecting which messages this
|
|
118
|
+
* subscription receives. Unmatched messages are never delivered. Receives all
|
|
119
|
+
* messages when omitted.
|
|
139
120
|
*
|
|
140
|
-
*
|
|
141
|
-
* which every cloud Encore deploys to can filter on:
|
|
121
|
+
* Written in a cloud-portable subset of [expr](https://expr-lang.org):
|
|
142
122
|
*
|
|
143
123
|
* ```ts
|
|
144
124
|
* filter: `attrs.region in ["eu-west-1", "eu-north-1"] and not (attrs.kind startsWith "test-")`
|
|
145
125
|
* ```
|
|
146
126
|
*
|
|
127
|
+
* Supported operators:
|
|
147
128
|
* - `attrs.region == "eu"`, `!=`, `in [...]`, `not in [...]`, and
|
|
148
|
-
* `startsWith "eu-"
|
|
149
|
-
* characters
|
|
150
|
-
* - `"region" in attrs` and `"region" not in attrs
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* - `and` (`&&`), `or` (`||`), `not (...)` (`!(...)`) and parentheses.
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
129
|
+
* `startsWith "eu-"` (use `attrs["iana.org-lang"]` for attribute names
|
|
130
|
+
* containing characters outside letters, digits, and `_`).
|
|
131
|
+
* - `"region" in attrs` and `"region" not in attrs` to check attribute
|
|
132
|
+
* presence. Value checks evaluate to `false` when an attribute is missing,
|
|
133
|
+
* while negated checks evaluate to `true`.
|
|
134
|
+
* - `and` (`&&`), `or` (`||`), `not (...)` (`!(...)`), and parentheses.
|
|
135
|
+
*
|
|
136
|
+
* Must be a string literal so Encore can validate it statically against cloud
|
|
137
|
+
* provider limits.
|
|
157
138
|
*/
|
|
158
139
|
filter?: string;
|
|
159
140
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* takes none. By default the service's main process consumes it.
|
|
165
|
-
*
|
|
166
|
-
* Encore reads it from the source, so it is a string written out.
|
|
141
|
+
* Name of a worker declared in `encore.service.json` under `workers` that
|
|
142
|
+
* should consume this subscription instead of the service's main process.
|
|
143
|
+
* Only that worker processes messages for this subscription. Must be a string
|
|
144
|
+
* literal.
|
|
167
145
|
*/
|
|
168
146
|
worker?: string;
|
|
169
147
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
148
|
+
* Static string-literal tags that classify the subscription for policy checks
|
|
149
|
+
* (e.g. `{data: "pci"}`). Keys and values may contain lowercase letters,
|
|
150
|
+
* digits, `_`, and `-`, up to 63 characters. Keys must start with a letter
|
|
151
|
+
* and cannot start with the reserved prefix `encore`. At most 32 tags.
|
|
174
152
|
*/
|
|
175
153
|
tags?: Record<string, string>;
|
|
176
154
|
}
|
|
177
155
|
/**
|
|
178
|
-
*
|
|
179
|
-
* after errors either delivering the message or processing the message.
|
|
180
|
-
*
|
|
181
|
-
* The values given to this structure are parsed at compile time, such that
|
|
182
|
-
* the correct Cloud resources can be provisioned to support the queue.
|
|
156
|
+
* Retry and dead-letter configuration for failed deliveries or handler errors.
|
|
183
157
|
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* by the target cloud).
|
|
158
|
+
* Values are parsed statically at compile time to provision cloud resources,
|
|
159
|
+
* and may be clamped to each cloud provider's supported ranges.
|
|
187
160
|
*/
|
|
188
161
|
export interface RetryPolicy {
|
|
189
162
|
/**
|
|
190
|
-
*
|
|
163
|
+
* Minimum backoff delay between retry attempts. Defaults to 10 seconds.
|
|
191
164
|
*/
|
|
192
165
|
minBackoff?: DurationString;
|
|
193
166
|
/**
|
|
194
|
-
*
|
|
167
|
+
* Maximum backoff delay between retry attempts. Defaults to 10 minutes.
|
|
195
168
|
*/
|
|
196
169
|
maxBackoff?: DurationString;
|
|
197
170
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
171
|
+
* Maximum number of retries after a handler failure before forwarding the
|
|
172
|
+
* message to the dead-letter queue. Defaults to 100.
|
|
200
173
|
*
|
|
201
|
-
* - `n >= 0`:
|
|
202
|
-
*
|
|
203
|
-
* - `-1
|
|
204
|
-
*
|
|
205
|
-
* - `-2`, {@link NoRetries}: not retried, as `0`.
|
|
174
|
+
* - `n >= 0`: retry up to `n` times (`0` disables retries and dead-letters on
|
|
175
|
+
* the first failure).
|
|
176
|
+
* - `-1` ({@link InfiniteRetries}): retry indefinitely without dead-lettering.
|
|
177
|
+
* - `-2` ({@link NoRetries}): do not retry (equivalent to `0`).
|
|
206
178
|
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
179
|
+
* Values below `-2` are rejected. Must be a numeric literal or one of the
|
|
180
|
+
* exported constants (`NoRetries`, `InfiniteRetries`) so Encore can parse it
|
|
181
|
+
* statically.
|
|
210
182
|
*/
|
|
211
183
|
maxRetries?: number;
|
|
212
184
|
}
|
|
213
185
|
/**
|
|
214
|
-
*
|
|
215
|
-
* dead-letter queue
|
|
186
|
+
* `maxRetries` value that disables retries and immediately forwards failed
|
|
187
|
+
* messages to the dead-letter queue.
|
|
216
188
|
*/
|
|
217
189
|
export declare const NoRetries = -2;
|
|
218
190
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
191
|
+
* `maxRetries` value that retries failed messages indefinitely without
|
|
192
|
+
* dead-lettering.
|
|
221
193
|
*/
|
|
222
194
|
export declare const InfiniteRetries = -1;
|
|
223
195
|
//# sourceMappingURL=subscription.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../pubsub/subscription.ts"],"names":[],"mappings":";;AASA,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAE,KAAK,EAAC,M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AED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B;;OAEG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,eAAe,KAAK,CAAC"}
|
|
@@ -6,10 +6,10 @@ import * as runtime from '../internal/runtime/mod.js';
|
|
|
6
6
|
import { testMode } from '../internal/testing/scope.js';
|
|
7
7
|
export class Subscription {
|
|
8
8
|
topic;
|
|
9
|
-
/**
|
|
9
|
+
/** Subscription name, unique within its topic. */
|
|
10
10
|
name;
|
|
11
11
|
impl;
|
|
12
|
-
/**
|
|
12
|
+
/** Dispatches a delivered message to the configured handler. */
|
|
13
13
|
dispatch;
|
|
14
14
|
constructor(topic, name, cfg) {
|
|
15
15
|
this.topic = topic;
|
|
@@ -49,11 +49,9 @@ export class Subscription {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* fails, rejecting with its error: that message is handed over again next
|
|
56
|
-
* time, as its next attempt.
|
|
52
|
+
* Delivers pending matching messages from `scope` to this subscription in
|
|
53
|
+
* order and returns the number of messages handled. Rejects on the first
|
|
54
|
+
* handler error so that message remains pending for the next attempt.
|
|
57
55
|
*
|
|
58
56
|
* @internal
|
|
59
57
|
*/
|
|
@@ -65,9 +63,9 @@ export class Subscription {
|
|
|
65
63
|
if (delivery === null)
|
|
66
64
|
return handled;
|
|
67
65
|
if (handled === maxDeliveries) {
|
|
68
|
-
throw new Error(`subscription ${JSON.stringify(sub.name)} handled ${maxDeliveries} messages in
|
|
69
|
-
`
|
|
70
|
-
|
|
66
|
+
throw new Error(`subscription ${JSON.stringify(sub.name)} handled ${maxDeliveries} messages in a ` +
|
|
67
|
+
`single deliver() call and still has more pending — check whether its handler ` +
|
|
68
|
+
`unconditionally publishes back to topic ${JSON.stringify(topic)}`);
|
|
71
69
|
}
|
|
72
70
|
const msg = delivery.message;
|
|
73
71
|
try {
|
|
@@ -90,9 +88,8 @@ export class Subscription {
|
|
|
90
88
|
}
|
|
91
89
|
}
|
|
92
90
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* mark, with the Request Context fields the message carries.
|
|
91
|
+
* Builds the OpenTelemetry context for a subscription handler, attaching the
|
|
92
|
+
* delivery span context and any propagated Request Context fields.
|
|
96
93
|
*/
|
|
97
94
|
function handlerContext(msg, fields) {
|
|
98
95
|
let ctx = ROOT_CONTEXT;
|
|
@@ -109,13 +106,13 @@ function handlerContext(msg, fields) {
|
|
|
109
106
|
return Object.keys(fields).length === 0 ? ctx : withFields(fields, ctx);
|
|
110
107
|
}
|
|
111
108
|
/**
|
|
112
|
-
*
|
|
113
|
-
* dead-letter queue
|
|
109
|
+
* `maxRetries` value that disables retries and immediately forwards failed
|
|
110
|
+
* messages to the dead-letter queue.
|
|
114
111
|
*/
|
|
115
112
|
export const NoRetries = -2;
|
|
116
113
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
114
|
+
* `maxRetries` value that retries failed messages indefinitely without
|
|
115
|
+
* dead-lettering.
|
|
119
116
|
*/
|
|
120
117
|
export const InfiniteRetries = -1;
|
|
121
118
|
//# sourceMappingURL=subscription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../pubsub/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,KAAK,GAEN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAC,WAAW,EAAC,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAC,qBAAqB,EAAE,UAAU,EA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