@encore.dev/sdk 0.0.0 → 2.0.0-beta.5
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/LICENSE +362 -0
- package/README.md +122 -2
- package/app_meta.test.ts +134 -0
- package/app_meta.ts +186 -0
- package/config/config.test.ts +381 -0
- package/config/config.ts +178 -0
- package/config/mod.ts +14 -0
- package/config/secrets.ts +147 -0
- package/config/value.ts +243 -0
- package/cron/mod.ts +23 -0
- package/dist/app_meta.d.ts +93 -0
- package/dist/app_meta.js +65 -0
- package/dist/app_meta.js.map +1 -0
- package/dist/config/config.d.ts +105 -0
- package/dist/config/config.js +87 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/mod.d.ts +4 -0
- package/dist/config/mod.js +3 -0
- package/dist/config/mod.js.map +1 -0
- package/dist/config/secrets.d.ts +92 -0
- package/dist/config/secrets.js +80 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/value.d.ts +51 -0
- package/dist/config/value.js +178 -0
- package/dist/config/value.js.map +1 -0
- package/dist/cron/mod.d.ts +22 -0
- package/dist/cron/mod.js +9 -0
- package/dist/cron/mod.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +50 -0
- package/dist/internal/otel/backend.js +2 -0
- package/dist/internal/otel/backend.js.map +1 -0
- package/dist/internal/otel/context.d.ts +10 -0
- package/dist/internal/otel/context.js +34 -0
- package/dist/internal/otel/context.js.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +22 -0
- package/dist/internal/otel/context_manager.js +120 -0
- package/dist/internal/otel/context_manager.js.map +1 -0
- package/dist/internal/otel/encode.d.ts +112 -0
- package/dist/internal/otel/encode.js +290 -0
- package/dist/internal/otel/encode.js.map +1 -0
- package/dist/internal/otel/index.d.ts +9 -0
- package/dist/internal/otel/index.js +9 -0
- package/dist/internal/otel/index.js.map +1 -0
- package/dist/internal/otel/meter.d.ts +73 -0
- package/dist/internal/otel/meter.js +265 -0
- package/dist/internal/otel/meter.js.map +1 -0
- package/dist/internal/otel/propagator.d.ts +14 -0
- package/dist/internal/otel/propagator.js +61 -0
- package/dist/internal/otel/propagator.js.map +1 -0
- package/dist/internal/otel/provider.d.ts +9 -0
- package/dist/internal/otel/provider.js +19 -0
- package/dist/internal/otel/provider.js.map +1 -0
- package/dist/internal/otel/request_context.d.ts +11 -0
- package/dist/internal/otel/request_context.js +20 -0
- package/dist/internal/otel/request_context.js.map +1 -0
- package/dist/internal/otel/span.d.ts +61 -0
- package/dist/internal/otel/span.js +206 -0
- package/dist/internal/otel/span.js.map +1 -0
- package/dist/internal/otel/tracer.d.ts +15 -0
- package/dist/internal/otel/tracer.js +65 -0
- package/dist/internal/otel/tracer.js.map +1 -0
- package/dist/internal/reqtrack/mod.d.ts +6 -0
- package/dist/internal/reqtrack/mod.js +28 -0
- package/dist/internal/reqtrack/mod.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +11 -0
- package/dist/internal/runtime/meter.js +22 -0
- package/dist/internal/runtime/meter.js.map +1 -0
- package/dist/internal/runtime/mod.d.ts +12 -0
- package/dist/internal/runtime/mod.js +28 -0
- package/dist/internal/runtime/mod.js.map +1 -0
- package/dist/internal/runtime/napi/napi.cjs +122 -0
- package/dist/internal/runtime/napi/napi.d.cts +601 -0
- package/dist/internal/runtime/shutdown.d.ts +13 -0
- package/dist/internal/runtime/shutdown.js +56 -0
- package/dist/internal/runtime/shutdown.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +9 -0
- package/dist/internal/utils/constraints.js +2 -0
- package/dist/internal/utils/constraints.js.map +1 -0
- package/dist/log/index.d.ts +39 -0
- package/dist/log/index.js +44 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +123 -0
- package/dist/log/logger.js +203 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/log/runtime.d.ts +19 -0
- package/dist/log/runtime.js +22 -0
- package/dist/log/runtime.js.map +1 -0
- package/dist/log/stderr.d.ts +9 -0
- package/dist/log/stderr.js +25 -0
- package/dist/log/stderr.js.map +1 -0
- package/dist/metrics/mod.d.ts +315 -0
- package/dist/metrics/mod.js +488 -0
- package/dist/metrics/mod.js.map +1 -0
- package/dist/mod.d.ts +6 -0
- package/dist/mod.js +4 -0
- package/dist/mod.js.map +1 -0
- package/dist/otel.d.ts +9 -0
- package/dist/otel.js +13 -0
- package/dist/otel.js.map +1 -0
- package/dist/pubsub/encoding.d.ts +3 -0
- package/dist/pubsub/encoding.js +10 -0
- package/dist/pubsub/encoding.js.map +1 -0
- package/dist/pubsub/mod.d.ts +6 -0
- package/dist/pubsub/mod.js +3 -0
- package/dist/pubsub/mod.js.map +1 -0
- package/dist/pubsub/refs.d.ts +12 -0
- package/dist/pubsub/refs.js +11 -0
- package/dist/pubsub/refs.js.map +1 -0
- package/dist/pubsub/subscription.d.ts +128 -0
- package/dist/pubsub/subscription.js +39 -0
- package/dist/pubsub/subscription.js.map +1 -0
- package/dist/pubsub/topic.d.ts +148 -0
- package/dist/pubsub/topic.js +164 -0
- package/dist/pubsub/topic.js.map +1 -0
- package/dist/req_meta.d.ts +47 -0
- package/dist/req_meta.js +26 -0
- package/dist/req_meta.js.map +1 -0
- package/dist/services/index.d.ts +12 -0
- package/dist/services/index.js +22 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shutdown/mod.d.ts +23 -0
- package/dist/shutdown/mod.js +24 -0
- package/dist/shutdown/mod.js.map +1 -0
- package/dist/storage/objects/bucket.d.ts +216 -0
- package/dist/storage/objects/bucket.js +123 -0
- package/dist/storage/objects/bucket.js.map +1 -0
- package/dist/storage/objects/error.d.ts +14 -0
- package/dist/storage/objects/error.js +81 -0
- package/dist/storage/objects/error.js.map +1 -0
- package/dist/storage/objects/mod.d.ts +4 -0
- package/dist/storage/objects/mod.js +3 -0
- package/dist/storage/objects/mod.js.map +1 -0
- package/dist/storage/objects/refs.d.ts +31 -0
- package/dist/storage/objects/refs.js +20 -0
- package/dist/storage/objects/refs.js.map +1 -0
- package/dist/storage/postgres/database.d.ts +295 -0
- package/dist/storage/postgres/database.js +378 -0
- package/dist/storage/postgres/database.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +2 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +573 -0
- package/dist/storage/redis/commands.js +637 -0
- package/dist/storage/redis/commands.js.map +1 -0
- package/dist/storage/redis/database.d.ts +302 -0
- package/dist/storage/redis/database.js +336 -0
- package/dist/storage/redis/database.js.map +1 -0
- package/dist/storage/redis/mod.d.ts +88 -0
- package/dist/storage/redis/mod.js +84 -0
- package/dist/storage/redis/mod.js.map +1 -0
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.js +11 -0
- package/dist/storage/redis/native.js.map +1 -0
- package/dist/storage/redis/options.d.ts +89 -0
- package/dist/storage/redis/options.js +53 -0
- package/dist/storage/redis/options.js.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +53 -0
- package/dist/storage/redis/pubsub.js +88 -0
- package/dist/storage/redis/pubsub.js.map +1 -0
- package/dist/storage/redis/reply.d.ts +256 -0
- package/dist/storage/redis/reply.js +572 -0
- package/dist/storage/redis/reply.js.map +1 -0
- package/dist/storage/redis/scan.d.ts +11 -0
- package/dist/storage/redis/scan.js +76 -0
- package/dist/storage/redis/scan.js.map +1 -0
- package/dist/storage/redis/script.d.ts +91 -0
- package/dist/storage/redis/script.js +143 -0
- package/dist/storage/redis/script.js.map +1 -0
- package/dist/storage/redis/target.d.ts +47 -0
- package/dist/storage/redis/target.js +82 -0
- package/dist/storage/redis/target.js.map +1 -0
- package/dist/storage/redis/wire.d.ts +105 -0
- package/dist/storage/redis/wire.js +333 -0
- package/dist/storage/redis/wire.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +42 -0
- package/dist/types/mod.js +65 -0
- package/dist/types/mod.js.map +1 -0
- package/internal/otel/backend.ts +60 -0
- package/internal/otel/context.test.ts +70 -0
- package/internal/otel/context.ts +48 -0
- package/internal/otel/context_manager.test.ts +154 -0
- package/internal/otel/context_manager.ts +141 -0
- package/internal/otel/encode.test.ts +266 -0
- package/internal/otel/encode.ts +408 -0
- package/internal/otel/index.ts +20 -0
- package/internal/otel/meter.test.ts +231 -0
- package/internal/otel/meter.ts +332 -0
- package/internal/otel/propagator.test.ts +105 -0
- package/internal/otel/propagator.ts +68 -0
- package/internal/otel/provider.ts +23 -0
- package/internal/otel/request_context.ts +32 -0
- package/internal/otel/span.ts +252 -0
- package/internal/otel/tracer.test.ts +352 -0
- package/internal/otel/tracer.ts +104 -0
- package/internal/reqtrack/mod.ts +39 -0
- package/internal/runtime/meter.ts +26 -0
- package/internal/runtime/mod.ts +41 -0
- package/internal/runtime/napi/napi.cjs +122 -0
- package/internal/runtime/napi/napi.d.cts +601 -0
- package/internal/runtime/shutdown.test.ts +248 -0
- package/internal/runtime/shutdown.ts +64 -0
- package/internal/utils/constraints.ts +12 -0
- package/log/index.ts +107 -0
- package/log/logger.test.ts +194 -0
- package/log/logger.ts +308 -0
- package/log/runtime.test.ts +65 -0
- package/log/runtime.ts +40 -0
- package/log/stderr.test.ts +23 -0
- package/log/stderr.ts +24 -0
- package/metrics/export.test.ts +337 -0
- package/metrics/mod.test.ts +180 -0
- package/metrics/mod.ts +619 -0
- package/mod.ts +22 -0
- package/otel.test.ts +84 -0
- package/otel.ts +17 -0
- package/package.json +121 -5
- package/pubsub/encoding.ts +8 -0
- package/pubsub/mod.ts +14 -0
- package/pubsub/pubsub.test.ts +186 -0
- package/pubsub/refs.ts +22 -0
- package/pubsub/subscription.ts +180 -0
- package/pubsub/topic.test.ts +121 -0
- package/pubsub/topic.ts +212 -0
- package/req_meta.ts +75 -0
- package/services/index.test.ts +30 -0
- package/services/index.ts +21 -0
- package/shutdown/mod.ts +24 -0
- package/storage/objects/bucket.ts +338 -0
- package/storage/objects/error.ts +94 -0
- package/storage/objects/mod.ts +35 -0
- package/storage/objects/refs.ts +69 -0
- package/storage/postgres/database.integration.test.ts +175 -0
- package/storage/postgres/database.test.ts +241 -0
- package/storage/postgres/database.ts +497 -0
- package/storage/postgres/mod.ts +15 -0
- package/storage/redis/commands.ts +1221 -0
- package/storage/redis/database.ts +466 -0
- package/storage/redis/mod.ts +135 -0
- package/storage/redis/native.ts +11 -0
- package/storage/redis/options.ts +119 -0
- package/storage/redis/pubsub.ts +92 -0
- package/storage/redis/redis.test.ts +706 -0
- package/storage/redis/reply.ts +705 -0
- package/storage/redis/runtime.test.ts +233 -0
- package/storage/redis/scan.ts +125 -0
- package/storage/redis/script.ts +162 -0
- package/storage/redis/target.ts +131 -0
- package/storage/redis/wire.ts +369 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DurationString } from '../types/mod.js';
|
|
3
|
+
import { OrderedTopic, Topic } from './topic.js';
|
|
4
|
+
/**
|
|
5
|
+
* A delivered payload with its original bytes and provider metadata.
|
|
6
|
+
*
|
|
7
|
+
* `orderingKey` is the key a message on an ordered topic was published with,
|
|
8
|
+
* and `null` on an unordered topic.
|
|
9
|
+
*/
|
|
10
|
+
export interface Message<T = unknown> {
|
|
11
|
+
data: T;
|
|
12
|
+
rawData: Buffer;
|
|
13
|
+
id: string;
|
|
14
|
+
attributes: Record<string, string>;
|
|
15
|
+
deliveryAttempt: number;
|
|
16
|
+
publishTime: Date;
|
|
17
|
+
orderingKey: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare class Subscription<Msg> {
|
|
20
|
+
private readonly topic;
|
|
21
|
+
private readonly name;
|
|
22
|
+
private readonly impl;
|
|
23
|
+
constructor(topic: Topic<Msg> | OrderedTopic<Msg>, name: string, cfg: SubscriptionConfig<Msg>);
|
|
24
|
+
private startSubscribing;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* SubscriptionConfig is used when creating a subscription
|
|
28
|
+
*
|
|
29
|
+
* The values given here may be clamped to the supported values by
|
|
30
|
+
* the target cloud. (i.e. ack deadline may be brought within the supported range
|
|
31
|
+
* by the target cloud pubsub implementation).
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Decode JSON by default; byte subscriptions must select `encoding: "raw"`.
|
|
35
|
+
* `decode` optionally validates/transforms JSON, or decodes a custom raw format.
|
|
36
|
+
*/
|
|
37
|
+
export type SubscriptionConfig<Msg> = SubscriptionOptions<Msg> & ([Msg] extends [Uint8Array] ? {
|
|
38
|
+
encoding: 'raw';
|
|
39
|
+
decode?: never;
|
|
40
|
+
} : {
|
|
41
|
+
encoding?: 'json';
|
|
42
|
+
decode?: (data: unknown) => Msg;
|
|
43
|
+
} | {
|
|
44
|
+
encoding: 'raw';
|
|
45
|
+
decode: (data: unknown) => Msg;
|
|
46
|
+
});
|
|
47
|
+
export interface SubscriptionOptions<Msg> {
|
|
48
|
+
/**
|
|
49
|
+
* Handler is the function which will be called to process a message
|
|
50
|
+
* sent on the topic.
|
|
51
|
+
*
|
|
52
|
+
* It receives a {@link Message} with decoded `data` and original `rawData`.
|
|
53
|
+
* TypeScript types do not validate JSON; use `decode` for runtime validation.
|
|
54
|
+
*
|
|
55
|
+
* When this function returns an error the message will be
|
|
56
|
+
* negatively acknowledged (nacked), which will cause a redelivery
|
|
57
|
+
* attempt to be made (unless the retry policy's MaxRetries has been reached).
|
|
58
|
+
*/
|
|
59
|
+
handler: (msg: Message<Msg>) => Promise<unknown>;
|
|
60
|
+
/**
|
|
61
|
+
* MaxConcurrency is the maximum number of messages which will be processed
|
|
62
|
+
* simultaneously per instance of the service for this subscription.
|
|
63
|
+
*
|
|
64
|
+
* Note that this is per instance of the service, so if your service has
|
|
65
|
+
* scaled to 10 instances and this is set to 10, then 100 messages could be
|
|
66
|
+
* processed simultaneously.
|
|
67
|
+
*
|
|
68
|
+
* If the value is negative, then there will be no limit on the number
|
|
69
|
+
* of messages processed simultaneously.
|
|
70
|
+
*
|
|
71
|
+
* Note: This is not supported by all cloud providers; specifically on GCP
|
|
72
|
+
* when using Cloud Run instances on an unordered topic the subscription will
|
|
73
|
+
* be configured as a Push Subscription and will have an adaptive concurrency
|
|
74
|
+
* See [GCP Push Delivery Rate](https://cloud.google.com/pubsub/docs/push#push_delivery_rate).
|
|
75
|
+
*
|
|
76
|
+
* This setting also has no effect on Encore Cloud environments.
|
|
77
|
+
* If not set, it uses a reasonable default based on the cloud provider.
|
|
78
|
+
*/
|
|
79
|
+
maxConcurrency?: number;
|
|
80
|
+
/**
|
|
81
|
+
* AckDeadline is the time a consumer has to process a message
|
|
82
|
+
* before it's returned to the subscription
|
|
83
|
+
*
|
|
84
|
+
* Default is 30 seconds, however the ack deadline must be at least
|
|
85
|
+
* 1 second.
|
|
86
|
+
*/
|
|
87
|
+
ackDeadline?: DurationString;
|
|
88
|
+
/**
|
|
89
|
+
* MessageRetention is how long an undelivered message is kept
|
|
90
|
+
* on the topic before it's purged.
|
|
91
|
+
*
|
|
92
|
+
* Default is 7 days.
|
|
93
|
+
*/
|
|
94
|
+
messageRetention?: DurationString;
|
|
95
|
+
/**
|
|
96
|
+
* RetryPolicy defines how a message should be retried when
|
|
97
|
+
* the subscriber returns an error
|
|
98
|
+
*/
|
|
99
|
+
retryPolicy?: RetryPolicy;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* RetryPolicy defines how a subscription should handle retries
|
|
103
|
+
* after errors either delivering the message or processing the message.
|
|
104
|
+
*
|
|
105
|
+
* The values given to this structure are parsed at compile time, such that
|
|
106
|
+
* the correct Cloud resources can be provisioned to support the queue.
|
|
107
|
+
*
|
|
108
|
+
* As such the values given here may be clamped to the supported values by
|
|
109
|
+
* the target cloud. (i.e. min/max values brought within the supported range
|
|
110
|
+
* by the target cloud).
|
|
111
|
+
*/
|
|
112
|
+
export interface RetryPolicy {
|
|
113
|
+
/**
|
|
114
|
+
* The minimum time to wait between retries. Defaults to 10 seconds.
|
|
115
|
+
*/
|
|
116
|
+
minBackoff?: DurationString;
|
|
117
|
+
/**
|
|
118
|
+
* The maximum time to wait between retries. Defaults to 10 minutes.
|
|
119
|
+
*/
|
|
120
|
+
maxBackoff?: DurationString;
|
|
121
|
+
/**
|
|
122
|
+
* MaxRetries is used to control deadletter queuing logic, when:
|
|
123
|
+
* n == 0: A default value of 100 retries will be used
|
|
124
|
+
* n > 0: Encore will forward a message to a dead letter queue after n retries
|
|
125
|
+
* n == pubsub.InfiniteRetries: Messages will not be forwarded to the dead letter queue by the Encore framework
|
|
126
|
+
*/
|
|
127
|
+
maxRetries?: number;
|
|
128
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import log from '../log/index.js';
|
|
2
|
+
import { runWithRequest } from '../internal/reqtrack/mod.js';
|
|
3
|
+
import * as runtime from '../internal/runtime/mod.js';
|
|
4
|
+
export class Subscription {
|
|
5
|
+
topic;
|
|
6
|
+
name;
|
|
7
|
+
impl;
|
|
8
|
+
constructor(topic, name, cfg) {
|
|
9
|
+
this.topic = topic;
|
|
10
|
+
this.name = name;
|
|
11
|
+
const handler = (req, msg) => runWithRequest(req, async () => {
|
|
12
|
+
const rawData = msg.data;
|
|
13
|
+
const data = cfg.encoding === 'raw'
|
|
14
|
+
? rawData
|
|
15
|
+
: JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(rawData));
|
|
16
|
+
await cfg.handler({
|
|
17
|
+
data: cfg.decode ? cfg.decode(data) : data,
|
|
18
|
+
rawData,
|
|
19
|
+
id: msg.id,
|
|
20
|
+
attributes: msg.attributes,
|
|
21
|
+
deliveryAttempt: msg.deliveryAttempt,
|
|
22
|
+
publishTime: msg.publishTime,
|
|
23
|
+
orderingKey: msg.orderingKey ?? null,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
this.impl = runtime.RT.pubsubSubscription({
|
|
27
|
+
topicName: topic.name,
|
|
28
|
+
subscriptionName: name,
|
|
29
|
+
handler,
|
|
30
|
+
});
|
|
31
|
+
this.startSubscribing();
|
|
32
|
+
}
|
|
33
|
+
startSubscribing() {
|
|
34
|
+
void this.impl.subscribe().catch((error) => {
|
|
35
|
+
log.error(error, `Encore subscription ${this.topic.name}/${this.name} failed`);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../pubsub/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AAGxD,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAkBnD,MAAM,OAAO,YAAY;IACN,KAAK,CAAiC;IACtC,IAAI,CAAS;IACb,IAAI,CAA6B;IAElD,YACE,KAAqC,EACrC,IAAY,EACZ,GAA4B;QAE5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,MAAM,OAAO,GAAG,CAAC,GAAoB,EAAE,GAA0B,EAAE,EAAE,CACnE,cAAc,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE;YAC7B,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC;YACzB,MAAM,IAAI,GACR,GAAG,CAAC,QAAQ,KAAK,KAAK;gBACpB,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,IAAI,CAAC,KAAK,CACR,IAAI,WAAW,CAAC,OAAO,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CACxD,CAAC;YACR,MAAM,GAAG,CAAC,OAAO,CAAC;gBAChB,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;gBAC1C,OAAO;gBACP,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,UAAU,EAAE,GAAG,CAAC,UAAU;gBAC1B,eAAe,EAAE,GAAG,CAAC,eAAe;gBACpC,WAAW,EAAE,GAAG,CAAC,WAAW;gBAC5B,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,IAAI;aACrC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEL,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,kBAAkB,CAAC;YACxC,SAAS,EAAE,KAAK,CAAC,IAAI;YACrB,gBAAgB,EAAE,IAAI;YACtB,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEO,gBAAgB;QACtB,KAAK,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YAClD,GAAG,CAAC,KAAK,CACP,KAAK,EACL,uBAAuB,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,SAAS,CAC7D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { OrderedPublisher, OrderedTopicPerms, Publisher, TopicPerms } from './refs.js';
|
|
2
|
+
/**
|
|
3
|
+
* A topic is a resource to which you can publish messages
|
|
4
|
+
* to be delivered to subscribers of that topic.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Topic<Msg> extends TopicPerms implements Publisher<Msg> {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/**
|
|
9
|
+
* The topic's configuration, as declared. `undefined` for a topic referenced
|
|
10
|
+
* with `Topic.named`, which is configured where it is declared.
|
|
11
|
+
*/
|
|
12
|
+
readonly cfg?: TopicConfig<Msg>;
|
|
13
|
+
private impl;
|
|
14
|
+
constructor(name: string, cfg?: TopicConfig<Msg>);
|
|
15
|
+
/**
|
|
16
|
+
* Reference an existing topic by name — one another service declares,
|
|
17
|
+
* possibly in another language. To declare a new topic, use
|
|
18
|
+
* `new Topic(...)` instead.
|
|
19
|
+
*
|
|
20
|
+
* The message type cannot be inferred, so it must be given:
|
|
21
|
+
*
|
|
22
|
+
* const signups = Topic.named<SignupEvent>("signups");
|
|
23
|
+
*
|
|
24
|
+
* The name must be a string literal, so Encore can resolve it statically.
|
|
25
|
+
*/
|
|
26
|
+
static named<Msg>(name: string): Topic<Msg>;
|
|
27
|
+
/**
|
|
28
|
+
* Publish a message to the topic, returning its unique id.
|
|
29
|
+
*
|
|
30
|
+
* JSON values are serialized as the payload; Buffer and Uint8Array payloads
|
|
31
|
+
* are sent as raw bytes. Messages are delivered to subscribers verbatim.
|
|
32
|
+
* `attributes` are delivered alongside the payload.
|
|
33
|
+
*/
|
|
34
|
+
publish(msg: Msg, attributes?: Record<string, string>): Promise<string>;
|
|
35
|
+
ref<P extends TopicPerms>(): P;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An ordered topic is a topic that delivers the messages sharing an ordering
|
|
39
|
+
* key in the order they were published. Each message is published with its
|
|
40
|
+
* key:
|
|
41
|
+
*
|
|
42
|
+
* const userEvents = new OrderedTopic<UserEvent>("user-events", {
|
|
43
|
+
* deliveryGuarantee: "at-least-once",
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* await userEvents.publish({ action: "login" }, "user-1"); // Delivered before the logout
|
|
47
|
+
* await userEvents.publish({ action: "login" }, "user-2"); // Delivered at any time: a different key
|
|
48
|
+
* await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after the first login
|
|
49
|
+
*
|
|
50
|
+
* A message whose handler fails is retried before the next one with its key
|
|
51
|
+
* is delivered, so depending on the retry policy a backlog can build up
|
|
52
|
+
* behind it. Once it has been retried as often as the subscription allows, it
|
|
53
|
+
* is dead-lettered and the next message with its key delivered. Reason about
|
|
54
|
+
* your failure modes and set the retry policy accordingly.
|
|
55
|
+
*
|
|
56
|
+
* Its throughput is limited by the cloud provider:
|
|
57
|
+
*
|
|
58
|
+
* - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
|
|
59
|
+
* - GCP: 1MB/s for each ordering key (see [GCP PubSub Quotas]).
|
|
60
|
+
*
|
|
61
|
+
* Locally (`encore run`, `encore test`) messages are delivered in order too:
|
|
62
|
+
* a message waits until the earlier ones with the same key are processed or
|
|
63
|
+
* dead-lettered.
|
|
64
|
+
*
|
|
65
|
+
* [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
|
|
66
|
+
* [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#resource_limits
|
|
67
|
+
*/
|
|
68
|
+
export declare class OrderedTopic<Msg> extends OrderedTopicPerms implements OrderedPublisher<Msg> {
|
|
69
|
+
readonly name: string;
|
|
70
|
+
/**
|
|
71
|
+
* The topic's configuration, as declared. `undefined` for a topic referenced
|
|
72
|
+
* with `OrderedTopic.named`, which is configured where it is declared.
|
|
73
|
+
*/
|
|
74
|
+
readonly cfg?: OrderedTopicConfig<Msg>;
|
|
75
|
+
private impl;
|
|
76
|
+
constructor(name: string, cfg?: OrderedTopicConfig<Msg>);
|
|
77
|
+
/**
|
|
78
|
+
* Reference an existing ordered topic by name. See `Topic.named`.
|
|
79
|
+
*
|
|
80
|
+
* const changes = OrderedTopic.named<ChangeEvent>("changes");
|
|
81
|
+
*/
|
|
82
|
+
static named<Msg>(name: string): OrderedTopic<Msg>;
|
|
83
|
+
/**
|
|
84
|
+
* Publish a message to the topic, returning its unique id. Messages
|
|
85
|
+
* published with the same `orderingKey`, which cannot be empty, are
|
|
86
|
+
* delivered in the order they were published.
|
|
87
|
+
*
|
|
88
|
+
* JSON values are serialized as the payload; Buffer and Uint8Array payloads
|
|
89
|
+
* are sent as raw bytes. Messages are delivered to subscribers verbatim.
|
|
90
|
+
* `attributes` are delivered alongside the payload.
|
|
91
|
+
*/
|
|
92
|
+
publish(msg: Msg, orderingKey: string, attributes?: Record<string, string>): Promise<string>;
|
|
93
|
+
ref<P extends OrderedTopicPerms>(): P;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* DeliveryGuarantee is used to configure the delivery contract for a topic.
|
|
97
|
+
*/
|
|
98
|
+
export type DeliveryGuarantee = 'at-least-once' | 'exactly-once';
|
|
99
|
+
/**
|
|
100
|
+
* At Least Once delivery guarantees that a message for a subscription is delivered to
|
|
101
|
+
* a consumer at least once.
|
|
102
|
+
*
|
|
103
|
+
* On AWS and GCP there is no limit to the throughput for a topic.
|
|
104
|
+
*/
|
|
105
|
+
export declare const atLeastOnce: DeliveryGuarantee;
|
|
106
|
+
/**
|
|
107
|
+
* ExactlyOnce guarantees that a message for a subscription is delivered to
|
|
108
|
+
* a consumer exactly once, to the best of the system's ability.
|
|
109
|
+
*
|
|
110
|
+
* However, there are edge cases when a message might be redelivered.
|
|
111
|
+
* For example, if a networking issue causes the acknowledgement of success
|
|
112
|
+
* processing the message to be lost before the cloud provider receives it.
|
|
113
|
+
*
|
|
114
|
+
* It is also important to note that the ExactlyOnce delivery guarantee only
|
|
115
|
+
* applies to the delivery of the message to the consumer, and not to the
|
|
116
|
+
* original publishing of the message, such that if a message is published twice,
|
|
117
|
+
* such as due to an retry within the application logic, it will be delivered twice.
|
|
118
|
+
* (i.e. ExactlyOnce delivery does not imply message deduplication on publish)
|
|
119
|
+
*
|
|
120
|
+
* As such it's recommended that the subscription handler function is idempotent
|
|
121
|
+
* and is able to handle duplicate messages.
|
|
122
|
+
*
|
|
123
|
+
* Subscriptions attached to ExactlyOnce topics have higher message delivery latency compared to AtLeastOnce.
|
|
124
|
+
*
|
|
125
|
+
* By using ExactlyOnce semantics on a topic, the throughput will be limited depending on the cloud provider:
|
|
126
|
+
* - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
|
|
127
|
+
* - GCP: At least 3,000 messages per second across all topics in the region
|
|
128
|
+
* (can be higher on the region see [GCP PubSub Quotas]).
|
|
129
|
+
*
|
|
130
|
+
* [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
|
|
131
|
+
* [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#quotas
|
|
132
|
+
*/
|
|
133
|
+
export declare const exactlyOnce: DeliveryGuarantee;
|
|
134
|
+
/**
|
|
135
|
+
* TopicConfig is used when creating a Topic
|
|
136
|
+
*/
|
|
137
|
+
export interface TopicConfig<_Msg> {
|
|
138
|
+
/**
|
|
139
|
+
* DeliveryGuarantee is used to configure the delivery guarantee of a Topic.
|
|
140
|
+
* Defaults to at-least-once.
|
|
141
|
+
*/
|
|
142
|
+
deliveryGuarantee?: DeliveryGuarantee;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* OrderedTopicConfig is used when creating an OrderedTopic. It configures what
|
|
146
|
+
* a TopicConfig does; the ordering key is given with each message.
|
|
147
|
+
*/
|
|
148
|
+
export type OrderedTopicConfig<Msg = unknown> = TopicConfig<Msg>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { activeCtxBytes } from '../internal/otel/index.js';
|
|
2
|
+
import * as runtime from '../internal/runtime/mod.js';
|
|
3
|
+
import { encodePayload } from './encoding.js';
|
|
4
|
+
import { OrderedTopicPerms, TopicPerms, } from './refs.js';
|
|
5
|
+
/**
|
|
6
|
+
* A topic is a resource to which you can publish messages
|
|
7
|
+
* to be delivered to subscribers of that topic.
|
|
8
|
+
*/
|
|
9
|
+
export class Topic extends TopicPerms {
|
|
10
|
+
name;
|
|
11
|
+
/**
|
|
12
|
+
* The topic's configuration, as declared. `undefined` for a topic referenced
|
|
13
|
+
* with `Topic.named`, which is configured where it is declared.
|
|
14
|
+
*/
|
|
15
|
+
cfg;
|
|
16
|
+
impl;
|
|
17
|
+
constructor(name, cfg) {
|
|
18
|
+
super();
|
|
19
|
+
this.name = name;
|
|
20
|
+
this.cfg = cfg;
|
|
21
|
+
this.impl = runtime.RT.pubsubTopic(name);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reference an existing topic by name — one another service declares,
|
|
25
|
+
* possibly in another language. To declare a new topic, use
|
|
26
|
+
* `new Topic(...)` instead.
|
|
27
|
+
*
|
|
28
|
+
* The message type cannot be inferred, so it must be given:
|
|
29
|
+
*
|
|
30
|
+
* const signups = Topic.named<SignupEvent>("signups");
|
|
31
|
+
*
|
|
32
|
+
* The name must be a string literal, so Encore can resolve it statically.
|
|
33
|
+
*/
|
|
34
|
+
static named(name) {
|
|
35
|
+
// Configured where it is declared, so it has no `cfg` of its own.
|
|
36
|
+
return new Topic(name);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Publish a message to the topic, returning its unique id.
|
|
40
|
+
*
|
|
41
|
+
* JSON values are serialized as the payload; Buffer and Uint8Array payloads
|
|
42
|
+
* are sent as raw bytes. Messages are delivered to subscribers verbatim.
|
|
43
|
+
* `attributes` are delivered alongside the payload.
|
|
44
|
+
*/
|
|
45
|
+
async publish(msg, attributes) {
|
|
46
|
+
const source = activeCtxBytes();
|
|
47
|
+
const payload = encodePayload(msg);
|
|
48
|
+
return this.impl.publish(payload, attributes, source);
|
|
49
|
+
}
|
|
50
|
+
ref() {
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* An ordered topic is a topic that delivers the messages sharing an ordering
|
|
56
|
+
* key in the order they were published. Each message is published with its
|
|
57
|
+
* key:
|
|
58
|
+
*
|
|
59
|
+
* const userEvents = new OrderedTopic<UserEvent>("user-events", {
|
|
60
|
+
* deliveryGuarantee: "at-least-once",
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* await userEvents.publish({ action: "login" }, "user-1"); // Delivered before the logout
|
|
64
|
+
* await userEvents.publish({ action: "login" }, "user-2"); // Delivered at any time: a different key
|
|
65
|
+
* await userEvents.publish({ action: "logout" }, "user-1"); // Delivered after the first login
|
|
66
|
+
*
|
|
67
|
+
* A message whose handler fails is retried before the next one with its key
|
|
68
|
+
* is delivered, so depending on the retry policy a backlog can build up
|
|
69
|
+
* behind it. Once it has been retried as often as the subscription allows, it
|
|
70
|
+
* is dead-lettered and the next message with its key delivered. Reason about
|
|
71
|
+
* your failure modes and set the retry policy accordingly.
|
|
72
|
+
*
|
|
73
|
+
* Its throughput is limited by the cloud provider:
|
|
74
|
+
*
|
|
75
|
+
* - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
|
|
76
|
+
* - GCP: 1MB/s for each ordering key (see [GCP PubSub Quotas]).
|
|
77
|
+
*
|
|
78
|
+
* Locally (`encore run`, `encore test`) messages are delivered in order too:
|
|
79
|
+
* a message waits until the earlier ones with the same key are processed or
|
|
80
|
+
* dead-lettered.
|
|
81
|
+
*
|
|
82
|
+
* [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
|
|
83
|
+
* [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#resource_limits
|
|
84
|
+
*/
|
|
85
|
+
export class OrderedTopic extends OrderedTopicPerms {
|
|
86
|
+
name;
|
|
87
|
+
/**
|
|
88
|
+
* The topic's configuration, as declared. `undefined` for a topic referenced
|
|
89
|
+
* with `OrderedTopic.named`, which is configured where it is declared.
|
|
90
|
+
*/
|
|
91
|
+
cfg;
|
|
92
|
+
impl;
|
|
93
|
+
constructor(name, cfg) {
|
|
94
|
+
super();
|
|
95
|
+
this.name = name;
|
|
96
|
+
this.cfg = cfg;
|
|
97
|
+
this.impl = runtime.RT.pubsubTopic(name);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Reference an existing ordered topic by name. See `Topic.named`.
|
|
101
|
+
*
|
|
102
|
+
* const changes = OrderedTopic.named<ChangeEvent>("changes");
|
|
103
|
+
*/
|
|
104
|
+
static named(name) {
|
|
105
|
+
// Configured where it is declared, so it has no `cfg` of its own.
|
|
106
|
+
return new OrderedTopic(name);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Publish a message to the topic, returning its unique id. Messages
|
|
110
|
+
* published with the same `orderingKey`, which cannot be empty, are
|
|
111
|
+
* delivered in the order they were published.
|
|
112
|
+
*
|
|
113
|
+
* JSON values are serialized as the payload; Buffer and Uint8Array payloads
|
|
114
|
+
* are sent as raw bytes. Messages are delivered to subscribers verbatim.
|
|
115
|
+
* `attributes` are delivered alongside the payload.
|
|
116
|
+
*/
|
|
117
|
+
async publish(msg, orderingKey, attributes) {
|
|
118
|
+
if (typeof orderingKey !== 'string' || orderingKey.length === 0) {
|
|
119
|
+
throw new TypeError('orderingKey must be a non-empty string');
|
|
120
|
+
}
|
|
121
|
+
const source = activeCtxBytes();
|
|
122
|
+
const payload = encodePayload(msg);
|
|
123
|
+
return this.impl.publish(payload, attributes, source, orderingKey);
|
|
124
|
+
}
|
|
125
|
+
ref() {
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* At Least Once delivery guarantees that a message for a subscription is delivered to
|
|
131
|
+
* a consumer at least once.
|
|
132
|
+
*
|
|
133
|
+
* On AWS and GCP there is no limit to the throughput for a topic.
|
|
134
|
+
*/
|
|
135
|
+
export const atLeastOnce = 'at-least-once';
|
|
136
|
+
/**
|
|
137
|
+
* ExactlyOnce guarantees that a message for a subscription is delivered to
|
|
138
|
+
* a consumer exactly once, to the best of the system's ability.
|
|
139
|
+
*
|
|
140
|
+
* However, there are edge cases when a message might be redelivered.
|
|
141
|
+
* For example, if a networking issue causes the acknowledgement of success
|
|
142
|
+
* processing the message to be lost before the cloud provider receives it.
|
|
143
|
+
*
|
|
144
|
+
* It is also important to note that the ExactlyOnce delivery guarantee only
|
|
145
|
+
* applies to the delivery of the message to the consumer, and not to the
|
|
146
|
+
* original publishing of the message, such that if a message is published twice,
|
|
147
|
+
* such as due to an retry within the application logic, it will be delivered twice.
|
|
148
|
+
* (i.e. ExactlyOnce delivery does not imply message deduplication on publish)
|
|
149
|
+
*
|
|
150
|
+
* As such it's recommended that the subscription handler function is idempotent
|
|
151
|
+
* and is able to handle duplicate messages.
|
|
152
|
+
*
|
|
153
|
+
* Subscriptions attached to ExactlyOnce topics have higher message delivery latency compared to AtLeastOnce.
|
|
154
|
+
*
|
|
155
|
+
* By using ExactlyOnce semantics on a topic, the throughput will be limited depending on the cloud provider:
|
|
156
|
+
* - AWS: 300 messages per second for the topic (see [AWS SQS Quotas]).
|
|
157
|
+
* - GCP: At least 3,000 messages per second across all topics in the region
|
|
158
|
+
* (can be higher on the region see [GCP PubSub Quotas]).
|
|
159
|
+
*
|
|
160
|
+
* [AWS SQS Quotas]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
|
|
161
|
+
* [GCP PubSub Quotas]: https://cloud.google.com/pubsub/quotas#quotas
|
|
162
|
+
*/
|
|
163
|
+
export const exactlyOnce = 'exactly-once';
|
|
164
|
+
//# sourceMappingURL=topic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topic.js","sourceRoot":"","sources":["../../pubsub/topic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAEL,iBAAiB,EAEjB,UAAU,GACX,MAAM,QAAQ,CAAC;AAEhB;;;GAGG;AACH,MAAM,OAAO,KAAW,SAAQ,UAAU;IAC/B,IAAI,CAAS;IACtB;;;OAGG;IACM,GAAG,CAAoB;IACxB,IAAI,CAAsB;IAElC,YAAY,IAAY,EAAE,GAAsB;QAC9C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,CAAM,IAAY;QAC5B,kEAAkE;QAClE,OAAO,IAAI,KAAK,CAAM,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CACX,GAAQ,EACR,UAAmC;QAEnC,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,GAAG;QACD,OAAO,IAAoB,CAAC;IAC9B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,YACX,SAAQ,iBAAiB;IAGhB,IAAI,CAAS;IACtB;;;OAGG;IACM,GAAG,CAA2B;IAC/B,IAAI,CAAsB;IAElC,YAAY,IAAY,EAAE,GAA6B;QACrD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAM,IAAY;QAC5B,kEAAkE;QAClE,OAAO,IAAI,YAAY,CAAM,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO,CACX,GAAQ,EACR,WAAmB,EACnB,UAAmC;QAEnC,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChE,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;QAChE,CAAC;QACD,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACrE,CAAC;IAED,GAAG;QACD,OAAO,IAAoB,CAAC;IAC9B,CAAC;CACF;AAOD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAsB,eAAe,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAsB,cAAc,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Describes a Pub/Sub message being processed. */
|
|
2
|
+
export interface PubSubMessageMeta {
|
|
3
|
+
/** Specifies that the request is a Pub/Sub message. */
|
|
4
|
+
type: 'pubsub-message';
|
|
5
|
+
/** The service processing the message. */
|
|
6
|
+
service: string;
|
|
7
|
+
/** The name of the Pub/Sub topic. */
|
|
8
|
+
topic: string;
|
|
9
|
+
/** The name of the Pub/Sub subscription. */
|
|
10
|
+
subscription: string;
|
|
11
|
+
/**
|
|
12
|
+
* The unique id of the Pub/Sub message.
|
|
13
|
+
* It is the same id returned by `topic.publish()`.
|
|
14
|
+
* The message id stays the same across delivery attempts.
|
|
15
|
+
*/
|
|
16
|
+
messageId: string;
|
|
17
|
+
/**
|
|
18
|
+
* The delivery attempt. The first attempt starts at 1,
|
|
19
|
+
* and increases by 1 for each retry.
|
|
20
|
+
*/
|
|
21
|
+
deliveryAttempt: number;
|
|
22
|
+
}
|
|
23
|
+
/** Provides information about the active trace. */
|
|
24
|
+
export interface TraceData {
|
|
25
|
+
/** The trace id, 32 lowercase hex characters. */
|
|
26
|
+
traceId: string;
|
|
27
|
+
/**
|
|
28
|
+
* The span id of the request's trace context, the calling gateway's span,
|
|
29
|
+
* 16 lowercase hex characters.
|
|
30
|
+
*/
|
|
31
|
+
spanId: string;
|
|
32
|
+
}
|
|
33
|
+
/** Common fields shared by all request meta types. */
|
|
34
|
+
export interface BaseRequestMeta {
|
|
35
|
+
/** The request's trace context; unset if the request arrived without one. */
|
|
36
|
+
trace?: TraceData;
|
|
37
|
+
}
|
|
38
|
+
/** Describes the Pub/Sub message being processed. */
|
|
39
|
+
export type RequestMeta = PubSubMessageMeta & BaseRequestMeta;
|
|
40
|
+
/**
|
|
41
|
+
* Returns information about the running Encore request: the Pub/Sub
|
|
42
|
+
* message being processed.
|
|
43
|
+
*
|
|
44
|
+
* Returns undefined only if no request is being processed,
|
|
45
|
+
* such as during system initialization.
|
|
46
|
+
*/
|
|
47
|
+
export declare function currentRequest(): RequestMeta | undefined;
|
package/dist/req_meta.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getCurrentRequest } from './internal/reqtrack/mod.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns information about the running Encore request: the Pub/Sub
|
|
4
|
+
* message being processed.
|
|
5
|
+
*
|
|
6
|
+
* Returns undefined only if no request is being processed,
|
|
7
|
+
* such as during system initialization.
|
|
8
|
+
*/
|
|
9
|
+
export function currentRequest() {
|
|
10
|
+
const req = getCurrentRequest();
|
|
11
|
+
if (!req) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const meta = req.meta();
|
|
15
|
+
const msg = meta.pubsubMessage;
|
|
16
|
+
return {
|
|
17
|
+
type: 'pubsub-message',
|
|
18
|
+
service: msg.service,
|
|
19
|
+
topic: msg.topic,
|
|
20
|
+
subscription: msg.subscription,
|
|
21
|
+
messageId: msg.id,
|
|
22
|
+
deliveryAttempt: msg.deliveryAttempt,
|
|
23
|
+
trace: meta.trace,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=req_meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"req_meta.js","sourceRoot":"","sources":["../req_meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AAkD1D;;;;;;GAMG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,iBAAiB,EAAE,CAAC;IAChC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAExB,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC;IAC/B,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,SAAS,EAAE,GAAG,CAAC,EAAE;QACjB,eAAe,EAAE,GAAG,CAAC,eAAe;QACpC,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* The base URL of `service`, ending in `/`. Resolve relative paths against
|
|
4
|
+
* it: `new URL("orders/1", serviceUrl("orders"))`. Throws if the service is
|
|
5
|
+
* unknown to this process.
|
|
6
|
+
*
|
|
7
|
+
* No service runs under `encore test`. Every service still has a base URL
|
|
8
|
+
* there, but a call to it is answered with `501 Not Implemented` and an error
|
|
9
|
+
* saying which service and path the test called: mock the call in the test
|
|
10
|
+
* instead.
|
|
11
|
+
*/
|
|
12
|
+
export declare function serviceUrl(service: string): URL;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { runtimeConfig } from '../internal/runtime/mod.js';
|
|
2
|
+
/**
|
|
3
|
+
* The base URL of `service`, ending in `/`. Resolve relative paths against
|
|
4
|
+
* it: `new URL("orders/1", serviceUrl("orders"))`. Throws if the service is
|
|
5
|
+
* unknown to this process.
|
|
6
|
+
*
|
|
7
|
+
* No service runs under `encore test`. Every service still has a base URL
|
|
8
|
+
* there, but a call to it is answered with `501 Not Implemented` and an error
|
|
9
|
+
* saying which service and path the test called: mock the call in the test
|
|
10
|
+
* instead.
|
|
11
|
+
*/
|
|
12
|
+
export function serviceUrl(service) {
|
|
13
|
+
const base = runtimeConfig().services[service];
|
|
14
|
+
if (base === undefined) {
|
|
15
|
+
throw new Error(`encore: unknown service ${JSON.stringify(service)}`);
|
|
16
|
+
}
|
|
17
|
+
const u = new URL(base);
|
|
18
|
+
if (!u.pathname.endsWith('/'))
|
|
19
|
+
u.pathname += '/';
|
|
20
|
+
return u;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,CAAC,CAAC,QAAQ,IAAI,GAAG,CAAC;IACjD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graceful shutdown on SIGTERM or SIGINT.
|
|
3
|
+
*
|
|
4
|
+
* On the signal Encore stops Pub/Sub intake, waits for in-flight message
|
|
5
|
+
* handlers, flushes metrics and telemetry, and exits: 0 when this finished
|
|
6
|
+
* within the shutdown deadline, else 1.
|
|
7
|
+
*
|
|
8
|
+
* An app serving requests drains them first by registering a drain:
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { onShutdown } from "@encore.dev/sdk/shutdown";
|
|
12
|
+
*
|
|
13
|
+
* const server = app.listen(port);
|
|
14
|
+
* onShutdown(() => new Promise((resolve) => server.close(() => resolve())));
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Encore cleans up once every drain settles or the shutdown deadline passes,
|
|
18
|
+
* whichever comes first.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import '../internal/runtime/mod.js';
|
|
23
|
+
export { onShutdown } from '../internal/runtime/shutdown.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graceful shutdown on SIGTERM or SIGINT.
|
|
3
|
+
*
|
|
4
|
+
* On the signal Encore stops Pub/Sub intake, waits for in-flight message
|
|
5
|
+
* handlers, flushes metrics and telemetry, and exits: 0 when this finished
|
|
6
|
+
* within the shutdown deadline, else 1.
|
|
7
|
+
*
|
|
8
|
+
* An app serving requests drains them first by registering a drain:
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { onShutdown } from "@encore.dev/sdk/shutdown";
|
|
12
|
+
*
|
|
13
|
+
* const server = app.listen(port);
|
|
14
|
+
* onShutdown(() => new Promise((resolve) => server.close(() => resolve())));
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Encore cleans up once every drain settles or the shutdown deadline passes,
|
|
18
|
+
* whichever comes first.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import '../internal/runtime/mod.js';
|
|
23
|
+
export { onShutdown } from '../internal/runtime/shutdown.js';
|
|
24
|
+
//# sourceMappingURL=mod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../shutdown/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAC"}
|