@encore.dev/sdk 2.0.0-beta.14 → 2.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +144 -90
  2. package/app_meta.ts +56 -54
  3. package/config/config.test.ts +47 -13
  4. package/config/config.ts +60 -57
  5. package/config/secrets.ts +47 -50
  6. package/config/value.ts +23 -26
  7. package/cron/mod.test.ts +12 -0
  8. package/cron/mod.ts +37 -22
  9. package/dist/app_meta.d.ts +52 -50
  10. package/dist/app_meta.d.ts.map +1 -1
  11. package/dist/app_meta.js +2 -2
  12. package/dist/app_meta.js.map +1 -1
  13. package/dist/config/config.d.ts +58 -55
  14. package/dist/config/config.d.ts.map +1 -1
  15. package/dist/config/config.js +8 -9
  16. package/dist/config/config.js.map +1 -1
  17. package/dist/config/secrets.d.ts +45 -50
  18. package/dist/config/secrets.d.ts.map +1 -1
  19. package/dist/config/secrets.js +11 -9
  20. package/dist/config/secrets.js.map +1 -1
  21. package/dist/config/value.d.ts +20 -23
  22. package/dist/config/value.d.ts.map +1 -1
  23. package/dist/config/value.js +20 -23
  24. package/dist/config/value.js.map +1 -1
  25. package/dist/cron/mod.d.ts +34 -20
  26. package/dist/cron/mod.d.ts.map +1 -1
  27. package/dist/cron/mod.js +13 -13
  28. package/dist/cron/mod.js.map +1 -1
  29. package/dist/frontends/mod.d.ts +20 -19
  30. package/dist/frontends/mod.d.ts.map +1 -1
  31. package/dist/frontends/mod.js +20 -19
  32. package/dist/frontends/mod.js.map +1 -1
  33. package/dist/gateway/errors.d.ts +28 -30
  34. package/dist/gateway/errors.d.ts.map +1 -1
  35. package/dist/gateway/errors.js +29 -31
  36. package/dist/gateway/errors.js.map +1 -1
  37. package/dist/gateway/match.d.ts +54 -54
  38. package/dist/gateway/match.d.ts.map +1 -1
  39. package/dist/gateway/match.js +56 -56
  40. package/dist/gateway/match.js.map +1 -1
  41. package/dist/gateway/middleware.d.ts +62 -64
  42. package/dist/gateway/middleware.d.ts.map +1 -1
  43. package/dist/gateway/middleware.js +1 -1
  44. package/dist/gateway/middleware.js.map +1 -1
  45. package/dist/gateway/mod.d.ts +64 -67
  46. package/dist/gateway/mod.d.ts.map +1 -1
  47. package/dist/gateway/mod.js +72 -76
  48. package/dist/gateway/mod.js.map +1 -1
  49. package/dist/gateway/request.d.ts +138 -134
  50. package/dist/gateway/request.d.ts.map +1 -1
  51. package/dist/gateway/request.js +117 -108
  52. package/dist/gateway/request.js.map +1 -1
  53. package/dist/gateway/serve.d.ts +29 -34
  54. package/dist/gateway/serve.d.ts.map +1 -1
  55. package/dist/gateway/serve.js +51 -56
  56. package/dist/gateway/serve.js.map +1 -1
  57. package/dist/gateways/mod.d.ts +23 -21
  58. package/dist/gateways/mod.d.ts.map +1 -1
  59. package/dist/gateways/mod.js +25 -23
  60. package/dist/gateways/mod.js.map +1 -1
  61. package/dist/internal/otel/http.d.ts +4 -2
  62. package/dist/internal/otel/http.d.ts.map +1 -1
  63. package/dist/internal/otel/http.js +32 -5
  64. package/dist/internal/otel/http.js.map +1 -1
  65. package/dist/internal/runtime/napi/napi.cjs +6 -5
  66. package/dist/internal/runtime/napi/napi.d.cts +58 -16
  67. package/dist/internal/runtime/shutdown.d.ts +75 -57
  68. package/dist/internal/runtime/shutdown.d.ts.map +1 -1
  69. package/dist/internal/runtime/shutdown.js +88 -84
  70. package/dist/internal/runtime/shutdown.js.map +1 -1
  71. package/dist/log/logger.d.ts +43 -37
  72. package/dist/log/logger.d.ts.map +1 -1
  73. package/dist/log/logger.js +26 -25
  74. package/dist/log/logger.js.map +1 -1
  75. package/dist/metrics/mod.d.ts +133 -114
  76. package/dist/metrics/mod.d.ts.map +1 -1
  77. package/dist/metrics/mod.js +109 -101
  78. package/dist/metrics/mod.js.map +1 -1
  79. package/dist/otel.d.ts +6 -3
  80. package/dist/otel.d.ts.map +1 -1
  81. package/dist/otel.js +6 -3
  82. package/dist/otel.js.map +1 -1
  83. package/dist/pubsub/subscription.d.ts +88 -116
  84. package/dist/pubsub/subscription.d.ts.map +1 -1
  85. package/dist/pubsub/subscription.js +14 -17
  86. package/dist/pubsub/subscription.js.map +1 -1
  87. package/dist/pubsub/topic.d.ts +86 -113
  88. package/dist/pubsub/topic.d.ts.map +1 -1
  89. package/dist/pubsub/topic.js +68 -82
  90. package/dist/pubsub/topic.js.map +1 -1
  91. package/dist/redaction/mod.d.ts +62 -0
  92. package/dist/redaction/mod.d.ts.map +1 -0
  93. package/dist/redaction/mod.js +102 -0
  94. package/dist/redaction/mod.js.map +1 -0
  95. package/dist/reqctx/mod.d.ts +83 -86
  96. package/dist/reqctx/mod.d.ts.map +1 -1
  97. package/dist/reqctx/mod.js +39 -41
  98. package/dist/reqctx/mod.js.map +1 -1
  99. package/dist/services/index.d.ts +76 -75
  100. package/dist/services/index.d.ts.map +1 -1
  101. package/dist/services/index.js +73 -71
  102. package/dist/services/index.js.map +1 -1
  103. package/dist/shutdown/mod.d.ts +26 -25
  104. package/dist/shutdown/mod.d.ts.map +1 -1
  105. package/dist/shutdown/mod.js +26 -25
  106. package/dist/shutdown/mod.js.map +1 -1
  107. package/dist/storage/clickhouse/database.d.ts +113 -115
  108. package/dist/storage/clickhouse/database.d.ts.map +1 -1
  109. package/dist/storage/clickhouse/database.js +65 -79
  110. package/dist/storage/clickhouse/database.js.map +1 -1
  111. package/dist/storage/clickhouse/errors.d.ts +25 -26
  112. package/dist/storage/clickhouse/errors.d.ts.map +1 -1
  113. package/dist/storage/clickhouse/errors.js +15 -17
  114. package/dist/storage/clickhouse/errors.js.map +1 -1
  115. package/dist/storage/clickhouse/mod.d.ts +10 -10
  116. package/dist/storage/clickhouse/mod.js +10 -10
  117. package/dist/storage/objects/bucket.d.ts +230 -203
  118. package/dist/storage/objects/bucket.d.ts.map +1 -1
  119. package/dist/storage/objects/bucket.js +146 -106
  120. package/dist/storage/objects/bucket.js.map +1 -1
  121. package/dist/storage/objects/error.d.ts +4 -4
  122. package/dist/storage/objects/error.js +4 -4
  123. package/dist/storage/objects/mod.d.ts +1 -1
  124. package/dist/storage/objects/mod.d.ts.map +1 -1
  125. package/dist/storage/objects/mod.js.map +1 -1
  126. package/dist/storage/objects/refs.d.ts +2 -5
  127. package/dist/storage/objects/refs.d.ts.map +1 -1
  128. package/dist/storage/objects/refs.js.map +1 -1
  129. package/dist/storage/postgres/database.d.ts +124 -149
  130. package/dist/storage/postgres/database.d.ts.map +1 -1
  131. package/dist/storage/postgres/database.js +98 -135
  132. package/dist/storage/postgres/database.js.map +1 -1
  133. package/dist/storage/postgres/errors.d.ts +42 -48
  134. package/dist/storage/postgres/errors.d.ts.map +1 -1
  135. package/dist/storage/postgres/errors.js +44 -51
  136. package/dist/storage/postgres/errors.js.map +1 -1
  137. package/dist/storage/postgres/interval.d.ts +19 -19
  138. package/dist/storage/postgres/interval.d.ts.map +1 -1
  139. package/dist/storage/postgres/interval.js +21 -21
  140. package/dist/storage/postgres/interval.js.map +1 -1
  141. package/dist/storage/redis/bitfield.d.ts +48 -23
  142. package/dist/storage/redis/bitfield.d.ts.map +1 -1
  143. package/dist/storage/redis/bitfield.js +38 -19
  144. package/dist/storage/redis/bitfield.js.map +1 -1
  145. package/dist/storage/redis/command.d.ts +16 -12
  146. package/dist/storage/redis/command.d.ts.map +1 -1
  147. package/dist/storage/redis/command.js +16 -12
  148. package/dist/storage/redis/command.js.map +1 -1
  149. package/dist/storage/redis/commands.d.ts +99 -100
  150. package/dist/storage/redis/commands.d.ts.map +1 -1
  151. package/dist/storage/redis/commands.js +84 -85
  152. package/dist/storage/redis/commands.js.map +1 -1
  153. package/dist/storage/redis/database.d.ts +138 -122
  154. package/dist/storage/redis/database.d.ts.map +1 -1
  155. package/dist/storage/redis/database.js +120 -101
  156. package/dist/storage/redis/database.js.map +1 -1
  157. package/dist/storage/redis/mod.d.ts +52 -48
  158. package/dist/storage/redis/mod.d.ts.map +1 -1
  159. package/dist/storage/redis/mod.js +52 -48
  160. package/dist/storage/redis/mod.js.map +1 -1
  161. package/dist/storage/redis/options.d.ts +26 -24
  162. package/dist/storage/redis/options.d.ts.map +1 -1
  163. package/dist/storage/redis/options.js.map +1 -1
  164. package/dist/storage/redis/pubsub.d.ts +16 -16
  165. package/dist/storage/redis/pubsub.d.ts.map +1 -1
  166. package/dist/storage/redis/pubsub.js +14 -14
  167. package/dist/storage/redis/pubsub.js.map +1 -1
  168. package/dist/storage/redis/reply.d.ts +80 -72
  169. package/dist/storage/redis/reply.d.ts.map +1 -1
  170. package/dist/storage/redis/reply.js +53 -46
  171. package/dist/storage/redis/reply.js.map +1 -1
  172. package/dist/storage/redis/scan.d.ts +4 -4
  173. package/dist/storage/redis/scan.d.ts.map +1 -1
  174. package/dist/storage/redis/scan.js +6 -6
  175. package/dist/storage/redis/scan.js.map +1 -1
  176. package/dist/storage/redis/script.d.ts +28 -21
  177. package/dist/storage/redis/script.d.ts.map +1 -1
  178. package/dist/storage/redis/script.js +29 -22
  179. package/dist/storage/redis/script.js.map +1 -1
  180. package/dist/storage/redis/target.d.ts +17 -1
  181. package/dist/storage/redis/target.d.ts.map +1 -1
  182. package/dist/storage/redis/target.js +30 -1
  183. package/dist/storage/redis/target.js.map +1 -1
  184. package/dist/storage/redis/wire.d.ts +6 -6
  185. package/dist/storage/redis/wire.d.ts.map +1 -1
  186. package/dist/storage/redis/wire.js +6 -6
  187. package/dist/storage/redis/wire.js.map +1 -1
  188. package/dist/testing/mod.d.ts +83 -88
  189. package/dist/testing/mod.d.ts.map +1 -1
  190. package/dist/testing/mod.js +75 -81
  191. package/dist/testing/mod.js.map +1 -1
  192. package/dist/testing/playwright.d.ts +28 -32
  193. package/dist/testing/playwright.d.ts.map +1 -1
  194. package/dist/testing/playwright.js +22 -27
  195. package/dist/testing/playwright.js.map +1 -1
  196. package/dist/testing/puppeteer.d.ts +11 -12
  197. package/dist/testing/puppeteer.d.ts.map +1 -1
  198. package/dist/testing/puppeteer.js +17 -18
  199. package/dist/testing/puppeteer.js.map +1 -1
  200. package/dist/testing/system.d.ts +72 -90
  201. package/dist/testing/system.d.ts.map +1 -1
  202. package/dist/testing/system.js +90 -107
  203. package/dist/testing/system.js.map +1 -1
  204. package/dist/tracing/http.d.ts +2 -1
  205. package/dist/tracing/http.d.ts.map +1 -1
  206. package/dist/tracing/http.js +2 -1
  207. package/dist/tracing/http.js.map +1 -1
  208. package/dist/tracing/node.d.ts.map +1 -1
  209. package/dist/tracing/node.js +1 -1
  210. package/dist/tracing/node.js.map +1 -1
  211. package/dist/tsconfig.build.tsbuildinfo +1 -1
  212. package/frontends/mod.test.ts +6 -2
  213. package/frontends/mod.ts +20 -19
  214. package/gateway/errors.ts +30 -32
  215. package/gateway/match.ts +61 -57
  216. package/gateway/middleware.ts +62 -64
  217. package/gateway/mod.ts +73 -76
  218. package/gateway/request.ts +143 -140
  219. package/gateway/serve.ts +58 -63
  220. package/gateways/mod.ts +25 -23
  221. package/internal/otel/http.test.ts +50 -0
  222. package/internal/otel/http.ts +40 -5
  223. package/internal/runtime/napi/napi.cjs +6 -5
  224. package/internal/runtime/napi/napi.d.cts +58 -16
  225. package/internal/runtime/shutdown.ts +113 -101
  226. package/log/logger.test.ts +8 -0
  227. package/log/logger.ts +48 -45
  228. package/metrics/mod.ts +138 -122
  229. package/otel.ts +6 -3
  230. package/package.json +6 -1
  231. package/pubsub/subscription.ts +93 -123
  232. package/pubsub/topic.ts +96 -130
  233. package/redaction/bridge.test.ts +99 -0
  234. package/redaction/mod.test.ts +188 -0
  235. package/redaction/mod.ts +226 -0
  236. package/reqctx/mod.ts +83 -86
  237. package/services/index.ts +78 -78
  238. package/shutdown/mod.ts +26 -25
  239. package/storage/clickhouse/database.ts +115 -129
  240. package/storage/clickhouse/errors.ts +27 -29
  241. package/storage/clickhouse/mod.ts +10 -10
  242. package/storage/objects/bucket.test.ts +168 -16
  243. package/storage/objects/bucket.ts +336 -247
  244. package/storage/objects/error.ts +4 -4
  245. package/storage/objects/mod.ts +1 -0
  246. package/storage/objects/refs.ts +2 -5
  247. package/storage/postgres/database.ts +131 -164
  248. package/storage/postgres/errors.ts +45 -52
  249. package/storage/postgres/interval.ts +21 -21
  250. package/storage/redis/bitfield.ts +51 -26
  251. package/storage/redis/command.ts +16 -12
  252. package/storage/redis/commands.ts +99 -100
  253. package/storage/redis/database.ts +145 -123
  254. package/storage/redis/mod.ts +52 -48
  255. package/storage/redis/options.ts +26 -24
  256. package/storage/redis/pubsub.ts +14 -14
  257. package/storage/redis/redis.test.ts +17 -2
  258. package/storage/redis/reply.ts +85 -77
  259. package/storage/redis/scan.ts +6 -6
  260. package/storage/redis/script.ts +29 -22
  261. package/storage/redis/target.ts +34 -1
  262. package/storage/redis/wire.ts +8 -8
  263. package/testing/mod.ts +99 -105
  264. package/testing/playwright.ts +32 -37
  265. package/testing/puppeteer.ts +22 -23
  266. package/testing/system.ts +117 -133
  267. package/tracing/http.ts +2 -1
  268. package/tracing/native.test.ts +158 -8
  269. package/tracing/node.ts +1 -0
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Calling the app's other services.
2
+ * Calling other services within your Encore application.
3
3
  *
4
- * {@link client} returns a client for one service, whose `fetch` takes the
5
- * service's paths:
4
+ * {@link client} creates a client for a target service whose `fetch` method
5
+ * accepts service-relative paths:
6
6
  *
7
7
  * ```ts
8
8
  * import {client} from '@encore.dev/sdk/services';
@@ -16,17 +16,19 @@
16
16
  * }
17
17
  * ```
18
18
  *
19
- * Its calls, and those made with this module's {@link fetch}, carry the
20
- * trace and Request Context (`@encore.dev/sdk/reqctx`) of the active context
21
- * to the app's services, so the services they reach continue the request
22
- * they are made for. A request to anything else carries no Request Context:
23
- * who a request is made for is no business of a third party's. Pass
24
- * {@link fetch} to a library that takes one, such as a generated client.
19
+ * Calls made with {@link client} or this module's {@link fetch} automatically
20
+ * propagate the active trace context and Request Context
21
+ * (`@encore.dev/sdk/reqctx`) to other services in the app. Requests to external
22
+ * URLs never receive Request Context headers so internal context is not leaked
23
+ * to third parties. Pass {@link fetch} to any HTTP library or generated client
24
+ * that accepts a custom fetch implementation.
25
25
  *
26
- * A service that lists another in its `encore.service.json` `clients` gets
27
- * generated clients for calling it in `encore_gen/clients`: a module per
28
- * service, with a module per API the service declares. Each operation is a
29
- * function of its module, so there is no client to make first:
26
+ * ## Generated clients
27
+ *
28
+ * When a service lists another service in `encore.service.json` under
29
+ * `clients`, Encore generates typed clients under `encore_gen/clients` (one
30
+ * module per service and API). Each endpoint is exported as a plain function,
31
+ * so no manual client setup is needed:
30
32
  *
31
33
  * ```ts
32
34
  * import {catalog} from "./encore_gen/clients/index.js";
@@ -36,14 +38,14 @@
36
38
  * const stuff = await catalog.grpc.stuffService.doStuff({});
37
39
  * ```
38
40
  *
39
- * Importing the index loads every client of every service, cheaply: a gRPC
40
- * client loads connect-es only for its first call. A deep import loads one
41
- * alone: `import * as openapi from "./encore_gen/clients/catalog/openapi.js"`.
41
+ * Importing the top-level index is lightweight — gRPC clients lazily load
42
+ * connect-es on their first call. You can also deep-import a single API:
43
+ * `import * as openapi from "./encore_gen/clients/catalog/openapi.js"`.
42
44
  *
43
- * A gRPC client's messages are protobuf-es's, which protoc-gen-es generates
44
- * in `encore_gen/protos`, a module per `.proto` file, which every client of
45
- * the service shares. A call takes its request as a message or its init,
46
- * as protobuf-es's `create` does, and gives its answer as a message:
45
+ * gRPC clients use protobuf-es messages generated in `encore_gen/protos` (one
46
+ * module per `.proto` file, shared across all clients of the service). Calls
47
+ * accept either a message instance or a plain init object (like protobuf-es's
48
+ * `create`) and return a message:
47
49
  *
48
50
  * ```ts
49
51
  * import {create} from "@bufbuild/protobuf";
@@ -54,13 +56,14 @@
54
56
  * const stuff = await catalog.grpc.stuffService.doStuff({id: "x", note});
55
57
  * ```
56
58
  *
57
- * A generated call that fails throws a {@link CallError}, whatever kind of
58
- * API it calls, which `instanceof CallError` tells from any other error. Its
59
- * code is the service's answer to the caller, not the caller's to its own
60
- * clients: one an `@encore.dev/framework` handler lets escape answers internal, as
61
- * any error but an APIError does. A handler answers with a code of its own
62
- * where it means one, and {@link unlessNotFound} makes a `not_found` failure
63
- * `undefined`, for a call for something that may not be there:
59
+ * ## Error handling
60
+ *
61
+ * Failed generated calls throw a {@link CallError} regardless of protocol. Its
62
+ * `code` reflects the callee's response and is not automatically forwarded to
63
+ * your own callers — an uncaught `CallError` in an `@encore.dev/framework`
64
+ * handler becomes an internal error just like any non-`APIError` exception.
65
+ * Convert it explicitly when appropriate, or use {@link unlessNotFound} to turn
66
+ * `not_found` errors into `undefined`:
64
67
  *
65
68
  * ```ts
66
69
  * import {APIError} from "@encore.dev/framework";
@@ -78,10 +81,12 @@
78
81
  * const product = await unlessNotFound(catalog.openapi.getProduct("xyz"));
79
82
  * ```
80
83
  *
81
- * Every generated call also takes {@link CallOptions}: a timeout, in
82
- * milliseconds, headers and an `AbortSignal` of its own, which go over its
83
- * client's. A module's `Client` holds {@link ClientOptions} for every call
84
- * made with it:
84
+ * ## Options and transport
85
+ *
86
+ * Every generated call accepts {@link CallOptions} (per-call `timeout` in
87
+ * milliseconds, extra `headers`, and an `AbortSignal`), which override client
88
+ * defaults. Construct a module's `Client` with {@link ClientOptions} to share
89
+ * settings across calls:
85
90
  *
86
91
  * ```ts
87
92
  * const fresh = await catalog.openapi.getProduct("xyz", {timeout: 2_000});
@@ -89,26 +94,25 @@
89
94
  * const mocked = new catalog.openapi.Client({baseUrl: mockServer.url});
90
95
  * ```
91
96
  *
92
- * The generated clients send through this module's {@link fetch}, so their
93
- * calls carry the trace and Request Context as {@link client}'s do. The gRPC
94
- * ones speak gRPC over HTTP/2, which fetch cannot, and carry them the same:
95
- * h2c to an `http://` base URL, TLS to an `https://` one, with one
96
- * connection per base URL that every call to it shares. A gRPC error
97
- * answer's status details are a {@link CallError}'s `grpcDetails`. A client
98
- * holds only its settings, so one made for a single call costs nothing, and
99
- * there is nothing to close.
100
- *
101
- * Looking up a service's URL, or making a client for it, makes the calling
102
- * service depend on it. Encore reads the dependency from the code, as it
103
- * reads which resources a service uses: so the name must be a string
104
- * literal, the function must be called directly rather than stored or passed
105
- * around, and the call must be in a service.
106
- *
107
- * No service runs under `encore test`. Every service still has a base URL
108
- * there, but a call to it is answered with `501 Not Implemented` and an error
109
- * saying which service and path the test called: mock the call in the test
110
- * instead. A system test's calls do reach the services, which start when
111
- * first called (`system` of `@encore.dev/sdk/testing`).
97
+ * HTTP generated clients use this module's {@link fetch}, propagating traces
98
+ * and Request Context automatically. gRPC clients speak gRPC over HTTP/2
99
+ * (h2c for `http://`, TLS for `https://`), sharing one connection per base URL
100
+ * and propagating traces and Request Context the same way; gRPC status details
101
+ * are exposed on {@link CallError.grpcDetails}. Client instances hold only
102
+ * configuration, so creating one is cheap and requires no cleanup.
103
+ *
104
+ * ## Static dependencies and testing
105
+ *
106
+ * Calling {@link baseUrl}, {@link serviceUrl}, or {@link client} registers a
107
+ * static dependency from the calling service to the target service. Therefore,
108
+ * the service name must be a string literal, the function must be called
109
+ * directly (not aliased or passed around), and the call must occur inside a
110
+ * service.
111
+ *
112
+ * Under `encore test` (unit tests), no other services are running; service
113
+ * calls receive `501 Not Implemented` identifying the target service and path
114
+ * so you can mock them. In system tests (`system` from
115
+ * `@encore.dev/sdk/testing`), calls reach real services, which start on demand.
112
116
  *
113
117
  * @module
114
118
  */
@@ -117,11 +121,11 @@ import { runtimeConfig } from '../internal/runtime/mod.js';
117
121
  export { fetch, wrapFetch } from '../internal/fetch.js';
118
122
  export { CallError, httpStatus, isErrCode, unlessNotFound, } from '../internal/clients/call.js';
119
123
  /**
120
- * The base URL the calling service reaches `service` at, without a trailing
121
- * slash: a call's path goes after it, `` `${baseUrl("orders")}/orders/1` ``.
124
+ * Returns the base URL for `service` without a trailing slash, so paths can be
125
+ * appended directly (e.g. `` `${baseUrl("orders")}/orders/1` ``).
122
126
  *
123
- * Throws if the service is unknown to this process: the app has no service of
124
- * that name, or the process was started without the app's service discovery.
127
+ * Throws if `service` is unknown to this process (either no such service exists
128
+ * or service discovery was not configured).
125
129
  *
126
130
  * @example
127
131
  * import {baseUrl} from "@encore.dev/sdk/services";
@@ -131,15 +135,15 @@ export function baseUrl(service) {
131
135
  return lookup(service).replace(/\/+$/, '');
132
136
  }
133
137
  /**
134
- * The base URL of `service` as a `URL`, ending in `/`. Resolve relative paths
135
- * against it: `new URL("orders/1", serviceUrl("orders"))`. Throws if the
136
- * service is unknown to this process.
138
+ * Returns the base URL of `service` as a `URL` ending with `/`, suitable for
139
+ * resolving relative paths (`new URL("orders/1", serviceUrl("orders"))`).
140
+ * Throws if `service` is unknown to this process.
137
141
  *
138
- * Looking it up makes the calling service depend on `service`, as
139
- * {@link baseUrl} does, under the same rules.
142
+ * Registers a static dependency on `service` under the same rules as
143
+ * {@link baseUrl}.
140
144
  *
141
- * @deprecated Use {@link baseUrl}, which returns the URL as a string without a
142
- * trailing slash, as the other Encore SDKs do.
145
+ * @deprecated Use {@link baseUrl}, which returns a string without a trailing
146
+ * slash consistently across Encore SDKs.
143
147
  */
144
148
  export function serviceUrl(service) {
145
149
  const u = new URL(lookup(service));
@@ -147,8 +151,7 @@ export function serviceUrl(service) {
147
151
  u.pathname += '/';
148
152
  return u;
149
153
  }
150
- /** The base URL of `service` as the runtime config gives it, whose origin
151
- * it records as one of the app's services'. */
154
+ /** Looks up `service`'s base URL from runtime config and marks its origin as internal. */
152
155
  function lookup(service) {
153
156
  const base = runtimeConfig().services[service];
154
157
  if (base === undefined) {
@@ -158,13 +161,12 @@ function lookup(service) {
158
161
  return base;
159
162
  }
160
163
  /**
161
- * A client for `service`, for service-to-service calls: its `fetch` takes the
162
- * service's paths, and carries the trace and Request Context of the active
163
- * context.
164
+ * Returns a {@link ServiceClient} for `service` whose `fetch` accepts
165
+ * service-relative paths and propagates the active trace and Request Context.
164
166
  *
165
- * Like {@link baseUrl}, it makes the calling service depend on `service`, so
166
- * the name must be a string literal and the call made directly, in a service.
167
- * Throws if the service is unknown to this process.
167
+ * Like {@link baseUrl}, registers a static dependency on `service`, so the name
168
+ * must be a string literal and the function must be called directly inside a
169
+ * service. Throws if `service` is unknown to this process.
168
170
  *
169
171
  * @example
170
172
  * import {client} from "@encore.dev/sdk/services";
@@ -178,7 +180,7 @@ export function client(service) {
178
180
  fetch: (path, init) => fetch(join(base, path), init),
179
181
  };
180
182
  }
181
- /** `path` under `base`, with one `/` between; an absolute URL as it is. */
183
+ /** Joins `path` onto `base` with a single `/`, leaving absolute URLs unchanged. */
182
184
  function join(base, path) {
183
185
  if (/^[a-z][a-z0-9+.-]*:/i.test(path))
184
186
  return path;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../services/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHG;AAEH,OAAO,EAAC,KAAK,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAC,KAAK,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,cAAc,GAMf,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,OAAO,CAAC,OAAe;IACrC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,CAAC,CAAC,QAAQ,IAAI,GAAG,CAAC;IACjD,OAAO,CAAC,CAAC;AACX,CAAC;AAED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AAE,IAAY;IACtC,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;AAC/C,CAAC"}
@@ -1,14 +1,15 @@
1
1
  /**
2
- * Graceful shutdown on SIGTERM or SIGINT.
2
+ * Graceful shutdown on `SIGTERM` or `SIGINT`.
3
3
  *
4
- * On the signal Encore stops Pub/Sub intake, waits for in-flight message
5
- * handlers and for the app's own work, closes its resources, flushes metrics
6
- * and telemetry, and exits: with `process.exitCode` (0 unless the app set it)
7
- * when this finished within the shutdown deadline, else 1. A second SIGINT,
8
- * a second Ctrl-C, stops waiting for the app.
4
+ * When a shutdown signal arrives, Encore stops accepting new Pub/Sub messages,
5
+ * waits for in-flight message handlers and application work to finish, closes
6
+ * managed resources, flushes metrics and telemetry, and exits. If cleanup
7
+ * finishes within the shutdown deadline, the process exits with
8
+ * `process.exitCode` (0 unless set by the application); otherwise it exits
9
+ * with 1. A second `SIGINT` (Ctrl-C) skips waiting for application work and
10
+ * forces immediate cleanup.
9
11
  *
10
- * The app tells Encore what to wait for. A server drains its requests in an
11
- * {@link onShutdown} callback:
12
+ * Use {@link onShutdown} to drain servers or close frameworks cleanly:
12
13
  *
13
14
  * ```typescript
14
15
  * import { onShutdown } from "@encore.dev/sdk/shutdown";
@@ -17,17 +18,17 @@
17
18
  * onShutdown(() => new Promise((resolve) => server.close(() => resolve())));
18
19
  * ```
19
20
  *
20
- * A framework that runs shutdown hooks of its own closes in one, rather than
21
- * on a signal listener of its own; with NestJS, instead of
22
- * `enableShutdownHooks()`:
21
+ * If your framework has its own shutdown hooks, invoke them inside
22
+ * `onShutdown` instead of registering separate signal handlers. For example,
23
+ * with NestJS (instead of `enableShutdownHooks()`):
23
24
  *
24
25
  * ```typescript
25
26
  * onShutdown(() => app.close());
26
27
  * ```
27
28
  *
28
- * Work that isn't a callback holds the shutdown back with {@link hold}, or
29
- * {@link waitUntil} for a promise. `using` releases a hold at the end of its
30
- * scope, a job's for example:
29
+ * For in-flight background work that isn't a shutdown callback, delay cleanup
30
+ * with {@link hold} or {@link waitUntil}. With `using`, a hold is released
31
+ * automatically when the block exits:
31
32
  *
32
33
  * ```typescript
33
34
  * import * as shutdown from "@encore.dev/sdk/shutdown";
@@ -38,19 +39,19 @@
38
39
  * }
39
40
  * ```
40
41
  *
41
- * Encore cleans up once every hold is released, or the shutdown deadline
42
- * passes, whichever comes first. {@link signal} aborts when the shutdown
43
- * begins; a callback's own signal aborts when cleanup does.
42
+ * Encore begins resource cleanup once all holds are released or the shutdown
43
+ * deadline expires, whichever comes first. {@link signal} aborts when shutdown
44
+ * starts; each callback's `ctx.signal` aborts when cleanup starts.
44
45
  *
45
- * An app that listens for the signal itself and holds nothing, as NestJS's
46
- * `enableShutdownHooks()` does, is waited for: Encore stops taking work at
47
- * once and cleans up once the app raises the signal again, exits, or has
48
- * closed everything it had open. The process then ends as the app meant it
49
- * to, with its own exit code, unless the shutdown deadline passed first:
50
- * then the exit code is 1.
46
+ * If an application registers its own signal listener without using Encore's
47
+ * shutdown APIs (such as NestJS's `enableShutdownHooks()`), Encore stops
48
+ * taking new work immediately and waits for the application to re-raise the
49
+ * signal, exit, or drain its event loop before cleaning up. The process then
50
+ * exits with the application's own exit code, or with 1 if the shutdown
51
+ * deadline expires first.
51
52
  *
52
- * Connections the app's own database pools hold, as `pg` and Drizzle's do,
53
- * stay open until the app closes them or the process exits.
53
+ * Database connections owned by third-party pools (such as `pg` or Drizzle)
54
+ * stay open until the application closes them or the process exits.
54
55
  *
55
56
  * @module
56
57
  */
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../shutdown/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,SAAS,EACT,aAAa,GACd,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,cAAc,GACf,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../shutdown/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,SAAS,EACT,aAAa,GACd,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,cAAc,GACf,MAAM,8BAA8B,CAAC"}
@@ -1,14 +1,15 @@
1
1
  /**
2
- * Graceful shutdown on SIGTERM or SIGINT.
2
+ * Graceful shutdown on `SIGTERM` or `SIGINT`.
3
3
  *
4
- * On the signal Encore stops Pub/Sub intake, waits for in-flight message
5
- * handlers and for the app's own work, closes its resources, flushes metrics
6
- * and telemetry, and exits: with `process.exitCode` (0 unless the app set it)
7
- * when this finished within the shutdown deadline, else 1. A second SIGINT,
8
- * a second Ctrl-C, stops waiting for the app.
4
+ * When a shutdown signal arrives, Encore stops accepting new Pub/Sub messages,
5
+ * waits for in-flight message handlers and application work to finish, closes
6
+ * managed resources, flushes metrics and telemetry, and exits. If cleanup
7
+ * finishes within the shutdown deadline, the process exits with
8
+ * `process.exitCode` (0 unless set by the application); otherwise it exits
9
+ * with 1. A second `SIGINT` (Ctrl-C) skips waiting for application work and
10
+ * forces immediate cleanup.
9
11
  *
10
- * The app tells Encore what to wait for. A server drains its requests in an
11
- * {@link onShutdown} callback:
12
+ * Use {@link onShutdown} to drain servers or close frameworks cleanly:
12
13
  *
13
14
  * ```typescript
14
15
  * import { onShutdown } from "@encore.dev/sdk/shutdown";
@@ -17,17 +18,17 @@
17
18
  * onShutdown(() => new Promise((resolve) => server.close(() => resolve())));
18
19
  * ```
19
20
  *
20
- * A framework that runs shutdown hooks of its own closes in one, rather than
21
- * on a signal listener of its own; with NestJS, instead of
22
- * `enableShutdownHooks()`:
21
+ * If your framework has its own shutdown hooks, invoke them inside
22
+ * `onShutdown` instead of registering separate signal handlers. For example,
23
+ * with NestJS (instead of `enableShutdownHooks()`):
23
24
  *
24
25
  * ```typescript
25
26
  * onShutdown(() => app.close());
26
27
  * ```
27
28
  *
28
- * Work that isn't a callback holds the shutdown back with {@link hold}, or
29
- * {@link waitUntil} for a promise. `using` releases a hold at the end of its
30
- * scope, a job's for example:
29
+ * For in-flight background work that isn't a shutdown callback, delay cleanup
30
+ * with {@link hold} or {@link waitUntil}. With `using`, a hold is released
31
+ * automatically when the block exits:
31
32
  *
32
33
  * ```typescript
33
34
  * import * as shutdown from "@encore.dev/sdk/shutdown";
@@ -38,19 +39,19 @@
38
39
  * }
39
40
  * ```
40
41
  *
41
- * Encore cleans up once every hold is released, or the shutdown deadline
42
- * passes, whichever comes first. {@link signal} aborts when the shutdown
43
- * begins; a callback's own signal aborts when cleanup does.
42
+ * Encore begins resource cleanup once all holds are released or the shutdown
43
+ * deadline expires, whichever comes first. {@link signal} aborts when shutdown
44
+ * starts; each callback's `ctx.signal` aborts when cleanup starts.
44
45
  *
45
- * An app that listens for the signal itself and holds nothing, as NestJS's
46
- * `enableShutdownHooks()` does, is waited for: Encore stops taking work at
47
- * once and cleans up once the app raises the signal again, exits, or has
48
- * closed everything it had open. The process then ends as the app meant it
49
- * to, with its own exit code, unless the shutdown deadline passed first:
50
- * then the exit code is 1.
46
+ * If an application registers its own signal listener without using Encore's
47
+ * shutdown APIs (such as NestJS's `enableShutdownHooks()`), Encore stops
48
+ * taking new work immediately and waits for the application to re-raise the
49
+ * signal, exit, or drain its event loop before cleaning up. The process then
50
+ * exits with the application's own exit code, or with 1 if the shutdown
51
+ * deadline expires first.
51
52
  *
52
- * Connections the app's own database pools hold, as `pg` and Drizzle's do,
53
- * stay open until the app closes them or the process exits.
53
+ * Database connections owned by third-party pools (such as `pg` or Drizzle)
54
+ * stay open until the application closes them or the process exits.
54
55
  *
55
56
  * @module
56
57
  */
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../shutdown/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,SAAS,EACT,aAAa,GACd,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../shutdown/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,SAAS,EACT,aAAa,GACd,MAAM,8BAA8B,CAAC"}