@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.
Files changed (250) hide show
  1. package/LICENSE +362 -0
  2. package/README.md +122 -2
  3. package/app_meta.test.ts +134 -0
  4. package/app_meta.ts +186 -0
  5. package/config/config.test.ts +381 -0
  6. package/config/config.ts +178 -0
  7. package/config/mod.ts +14 -0
  8. package/config/secrets.ts +147 -0
  9. package/config/value.ts +243 -0
  10. package/cron/mod.ts +23 -0
  11. package/dist/app_meta.d.ts +93 -0
  12. package/dist/app_meta.js +65 -0
  13. package/dist/app_meta.js.map +1 -0
  14. package/dist/config/config.d.ts +105 -0
  15. package/dist/config/config.js +87 -0
  16. package/dist/config/config.js.map +1 -0
  17. package/dist/config/mod.d.ts +4 -0
  18. package/dist/config/mod.js +3 -0
  19. package/dist/config/mod.js.map +1 -0
  20. package/dist/config/secrets.d.ts +92 -0
  21. package/dist/config/secrets.js +80 -0
  22. package/dist/config/secrets.js.map +1 -0
  23. package/dist/config/value.d.ts +51 -0
  24. package/dist/config/value.js +178 -0
  25. package/dist/config/value.js.map +1 -0
  26. package/dist/cron/mod.d.ts +22 -0
  27. package/dist/cron/mod.js +9 -0
  28. package/dist/cron/mod.js.map +1 -0
  29. package/dist/internal/otel/backend.d.ts +50 -0
  30. package/dist/internal/otel/backend.js +2 -0
  31. package/dist/internal/otel/backend.js.map +1 -0
  32. package/dist/internal/otel/context.d.ts +10 -0
  33. package/dist/internal/otel/context.js +34 -0
  34. package/dist/internal/otel/context.js.map +1 -0
  35. package/dist/internal/otel/context_manager.d.ts +22 -0
  36. package/dist/internal/otel/context_manager.js +120 -0
  37. package/dist/internal/otel/context_manager.js.map +1 -0
  38. package/dist/internal/otel/encode.d.ts +112 -0
  39. package/dist/internal/otel/encode.js +290 -0
  40. package/dist/internal/otel/encode.js.map +1 -0
  41. package/dist/internal/otel/index.d.ts +9 -0
  42. package/dist/internal/otel/index.js +9 -0
  43. package/dist/internal/otel/index.js.map +1 -0
  44. package/dist/internal/otel/meter.d.ts +73 -0
  45. package/dist/internal/otel/meter.js +265 -0
  46. package/dist/internal/otel/meter.js.map +1 -0
  47. package/dist/internal/otel/propagator.d.ts +14 -0
  48. package/dist/internal/otel/propagator.js +61 -0
  49. package/dist/internal/otel/propagator.js.map +1 -0
  50. package/dist/internal/otel/provider.d.ts +9 -0
  51. package/dist/internal/otel/provider.js +19 -0
  52. package/dist/internal/otel/provider.js.map +1 -0
  53. package/dist/internal/otel/request_context.d.ts +11 -0
  54. package/dist/internal/otel/request_context.js +20 -0
  55. package/dist/internal/otel/request_context.js.map +1 -0
  56. package/dist/internal/otel/span.d.ts +61 -0
  57. package/dist/internal/otel/span.js +206 -0
  58. package/dist/internal/otel/span.js.map +1 -0
  59. package/dist/internal/otel/tracer.d.ts +15 -0
  60. package/dist/internal/otel/tracer.js +65 -0
  61. package/dist/internal/otel/tracer.js.map +1 -0
  62. package/dist/internal/reqtrack/mod.d.ts +6 -0
  63. package/dist/internal/reqtrack/mod.js +28 -0
  64. package/dist/internal/reqtrack/mod.js.map +1 -0
  65. package/dist/internal/runtime/meter.d.ts +11 -0
  66. package/dist/internal/runtime/meter.js +22 -0
  67. package/dist/internal/runtime/meter.js.map +1 -0
  68. package/dist/internal/runtime/mod.d.ts +12 -0
  69. package/dist/internal/runtime/mod.js +28 -0
  70. package/dist/internal/runtime/mod.js.map +1 -0
  71. package/dist/internal/runtime/napi/napi.cjs +122 -0
  72. package/dist/internal/runtime/napi/napi.d.cts +601 -0
  73. package/dist/internal/runtime/shutdown.d.ts +13 -0
  74. package/dist/internal/runtime/shutdown.js +56 -0
  75. package/dist/internal/runtime/shutdown.js.map +1 -0
  76. package/dist/internal/utils/constraints.d.ts +9 -0
  77. package/dist/internal/utils/constraints.js +2 -0
  78. package/dist/internal/utils/constraints.js.map +1 -0
  79. package/dist/log/index.d.ts +39 -0
  80. package/dist/log/index.js +44 -0
  81. package/dist/log/index.js.map +1 -0
  82. package/dist/log/logger.d.ts +123 -0
  83. package/dist/log/logger.js +203 -0
  84. package/dist/log/logger.js.map +1 -0
  85. package/dist/log/runtime.d.ts +19 -0
  86. package/dist/log/runtime.js +22 -0
  87. package/dist/log/runtime.js.map +1 -0
  88. package/dist/log/stderr.d.ts +9 -0
  89. package/dist/log/stderr.js +25 -0
  90. package/dist/log/stderr.js.map +1 -0
  91. package/dist/metrics/mod.d.ts +315 -0
  92. package/dist/metrics/mod.js +488 -0
  93. package/dist/metrics/mod.js.map +1 -0
  94. package/dist/mod.d.ts +6 -0
  95. package/dist/mod.js +4 -0
  96. package/dist/mod.js.map +1 -0
  97. package/dist/otel.d.ts +9 -0
  98. package/dist/otel.js +13 -0
  99. package/dist/otel.js.map +1 -0
  100. package/dist/pubsub/encoding.d.ts +3 -0
  101. package/dist/pubsub/encoding.js +10 -0
  102. package/dist/pubsub/encoding.js.map +1 -0
  103. package/dist/pubsub/mod.d.ts +6 -0
  104. package/dist/pubsub/mod.js +3 -0
  105. package/dist/pubsub/mod.js.map +1 -0
  106. package/dist/pubsub/refs.d.ts +12 -0
  107. package/dist/pubsub/refs.js +11 -0
  108. package/dist/pubsub/refs.js.map +1 -0
  109. package/dist/pubsub/subscription.d.ts +128 -0
  110. package/dist/pubsub/subscription.js +39 -0
  111. package/dist/pubsub/subscription.js.map +1 -0
  112. package/dist/pubsub/topic.d.ts +148 -0
  113. package/dist/pubsub/topic.js +164 -0
  114. package/dist/pubsub/topic.js.map +1 -0
  115. package/dist/req_meta.d.ts +47 -0
  116. package/dist/req_meta.js +26 -0
  117. package/dist/req_meta.js.map +1 -0
  118. package/dist/services/index.d.ts +12 -0
  119. package/dist/services/index.js +22 -0
  120. package/dist/services/index.js.map +1 -0
  121. package/dist/shutdown/mod.d.ts +23 -0
  122. package/dist/shutdown/mod.js +24 -0
  123. package/dist/shutdown/mod.js.map +1 -0
  124. package/dist/storage/objects/bucket.d.ts +216 -0
  125. package/dist/storage/objects/bucket.js +123 -0
  126. package/dist/storage/objects/bucket.js.map +1 -0
  127. package/dist/storage/objects/error.d.ts +14 -0
  128. package/dist/storage/objects/error.js +81 -0
  129. package/dist/storage/objects/error.js.map +1 -0
  130. package/dist/storage/objects/mod.d.ts +4 -0
  131. package/dist/storage/objects/mod.js +3 -0
  132. package/dist/storage/objects/mod.js.map +1 -0
  133. package/dist/storage/objects/refs.d.ts +31 -0
  134. package/dist/storage/objects/refs.js +20 -0
  135. package/dist/storage/objects/refs.js.map +1 -0
  136. package/dist/storage/postgres/database.d.ts +295 -0
  137. package/dist/storage/postgres/database.js +378 -0
  138. package/dist/storage/postgres/database.js.map +1 -0
  139. package/dist/storage/postgres/mod.d.ts +2 -0
  140. package/dist/storage/postgres/mod.js +2 -0
  141. package/dist/storage/postgres/mod.js.map +1 -0
  142. package/dist/storage/redis/commands.d.ts +573 -0
  143. package/dist/storage/redis/commands.js +637 -0
  144. package/dist/storage/redis/commands.js.map +1 -0
  145. package/dist/storage/redis/database.d.ts +302 -0
  146. package/dist/storage/redis/database.js +336 -0
  147. package/dist/storage/redis/database.js.map +1 -0
  148. package/dist/storage/redis/mod.d.ts +88 -0
  149. package/dist/storage/redis/mod.js +84 -0
  150. package/dist/storage/redis/mod.js.map +1 -0
  151. package/dist/storage/redis/native.d.ts +8 -0
  152. package/dist/storage/redis/native.js +11 -0
  153. package/dist/storage/redis/native.js.map +1 -0
  154. package/dist/storage/redis/options.d.ts +89 -0
  155. package/dist/storage/redis/options.js +53 -0
  156. package/dist/storage/redis/options.js.map +1 -0
  157. package/dist/storage/redis/pubsub.d.ts +53 -0
  158. package/dist/storage/redis/pubsub.js +88 -0
  159. package/dist/storage/redis/pubsub.js.map +1 -0
  160. package/dist/storage/redis/reply.d.ts +256 -0
  161. package/dist/storage/redis/reply.js +572 -0
  162. package/dist/storage/redis/reply.js.map +1 -0
  163. package/dist/storage/redis/scan.d.ts +11 -0
  164. package/dist/storage/redis/scan.js +76 -0
  165. package/dist/storage/redis/scan.js.map +1 -0
  166. package/dist/storage/redis/script.d.ts +91 -0
  167. package/dist/storage/redis/script.js +143 -0
  168. package/dist/storage/redis/script.js.map +1 -0
  169. package/dist/storage/redis/target.d.ts +47 -0
  170. package/dist/storage/redis/target.js +82 -0
  171. package/dist/storage/redis/target.js.map +1 -0
  172. package/dist/storage/redis/wire.d.ts +105 -0
  173. package/dist/storage/redis/wire.js +333 -0
  174. package/dist/storage/redis/wire.js.map +1 -0
  175. package/dist/tsconfig.build.tsbuildinfo +1 -0
  176. package/dist/types/mod.d.ts +42 -0
  177. package/dist/types/mod.js +65 -0
  178. package/dist/types/mod.js.map +1 -0
  179. package/internal/otel/backend.ts +60 -0
  180. package/internal/otel/context.test.ts +70 -0
  181. package/internal/otel/context.ts +48 -0
  182. package/internal/otel/context_manager.test.ts +154 -0
  183. package/internal/otel/context_manager.ts +141 -0
  184. package/internal/otel/encode.test.ts +266 -0
  185. package/internal/otel/encode.ts +408 -0
  186. package/internal/otel/index.ts +20 -0
  187. package/internal/otel/meter.test.ts +231 -0
  188. package/internal/otel/meter.ts +332 -0
  189. package/internal/otel/propagator.test.ts +105 -0
  190. package/internal/otel/propagator.ts +68 -0
  191. package/internal/otel/provider.ts +23 -0
  192. package/internal/otel/request_context.ts +32 -0
  193. package/internal/otel/span.ts +252 -0
  194. package/internal/otel/tracer.test.ts +352 -0
  195. package/internal/otel/tracer.ts +104 -0
  196. package/internal/reqtrack/mod.ts +39 -0
  197. package/internal/runtime/meter.ts +26 -0
  198. package/internal/runtime/mod.ts +41 -0
  199. package/internal/runtime/napi/napi.cjs +122 -0
  200. package/internal/runtime/napi/napi.d.cts +601 -0
  201. package/internal/runtime/shutdown.test.ts +248 -0
  202. package/internal/runtime/shutdown.ts +64 -0
  203. package/internal/utils/constraints.ts +12 -0
  204. package/log/index.ts +107 -0
  205. package/log/logger.test.ts +194 -0
  206. package/log/logger.ts +308 -0
  207. package/log/runtime.test.ts +65 -0
  208. package/log/runtime.ts +40 -0
  209. package/log/stderr.test.ts +23 -0
  210. package/log/stderr.ts +24 -0
  211. package/metrics/export.test.ts +337 -0
  212. package/metrics/mod.test.ts +180 -0
  213. package/metrics/mod.ts +619 -0
  214. package/mod.ts +22 -0
  215. package/otel.test.ts +84 -0
  216. package/otel.ts +17 -0
  217. package/package.json +121 -5
  218. package/pubsub/encoding.ts +8 -0
  219. package/pubsub/mod.ts +14 -0
  220. package/pubsub/pubsub.test.ts +186 -0
  221. package/pubsub/refs.ts +22 -0
  222. package/pubsub/subscription.ts +180 -0
  223. package/pubsub/topic.test.ts +121 -0
  224. package/pubsub/topic.ts +212 -0
  225. package/req_meta.ts +75 -0
  226. package/services/index.test.ts +30 -0
  227. package/services/index.ts +21 -0
  228. package/shutdown/mod.ts +24 -0
  229. package/storage/objects/bucket.ts +338 -0
  230. package/storage/objects/error.ts +94 -0
  231. package/storage/objects/mod.ts +35 -0
  232. package/storage/objects/refs.ts +69 -0
  233. package/storage/postgres/database.integration.test.ts +175 -0
  234. package/storage/postgres/database.test.ts +241 -0
  235. package/storage/postgres/database.ts +497 -0
  236. package/storage/postgres/mod.ts +15 -0
  237. package/storage/redis/commands.ts +1221 -0
  238. package/storage/redis/database.ts +466 -0
  239. package/storage/redis/mod.ts +135 -0
  240. package/storage/redis/native.ts +11 -0
  241. package/storage/redis/options.ts +119 -0
  242. package/storage/redis/pubsub.ts +92 -0
  243. package/storage/redis/redis.test.ts +706 -0
  244. package/storage/redis/reply.ts +705 -0
  245. package/storage/redis/runtime.test.ts +233 -0
  246. package/storage/redis/scan.ts +125 -0
  247. package/storage/redis/script.ts +162 -0
  248. package/storage/redis/target.ts +131 -0
  249. package/storage/redis/wire.ts +369 -0
  250. 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;
@@ -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"}