@encore.dev/sdk 2.0.0-beta.6 → 2.0.0-beta.8

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 (356) hide show
  1. package/README.md +55 -0
  2. package/app_meta.ts +8 -0
  3. package/config/config.test.ts +10 -3
  4. package/config/config.ts +75 -21
  5. package/config/mod.ts +4 -3
  6. package/config/secrets.ts +72 -55
  7. package/cron/mod.ts +32 -0
  8. package/dist/app_meta.d.ts +7 -0
  9. package/dist/app_meta.d.ts.map +1 -0
  10. package/dist/app_meta.js +1 -0
  11. package/dist/app_meta.js.map +1 -1
  12. package/dist/config/config.d.ts +44 -18
  13. package/dist/config/config.d.ts.map +1 -0
  14. package/dist/config/config.js +43 -18
  15. package/dist/config/config.js.map +1 -1
  16. package/dist/config/mod.d.ts +5 -4
  17. package/dist/config/mod.d.ts.map +1 -0
  18. package/dist/config/mod.js +2 -2
  19. package/dist/config/mod.js.map +1 -1
  20. package/dist/config/secrets.d.ts +62 -39
  21. package/dist/config/secrets.d.ts.map +1 -0
  22. package/dist/config/secrets.js +21 -37
  23. package/dist/config/secrets.js.map +1 -1
  24. package/dist/config/value.d.ts +1 -0
  25. package/dist/config/value.d.ts.map +1 -0
  26. package/dist/cron/mod.d.ts +31 -0
  27. package/dist/cron/mod.d.ts.map +1 -0
  28. package/dist/cron/mod.js +23 -0
  29. package/dist/cron/mod.js.map +1 -1
  30. package/dist/gateway/errors.d.ts +101 -0
  31. package/dist/gateway/errors.d.ts.map +1 -0
  32. package/dist/gateway/errors.js +146 -0
  33. package/dist/gateway/errors.js.map +1 -0
  34. package/dist/gateway/match.d.ts +127 -0
  35. package/dist/gateway/match.d.ts.map +1 -0
  36. package/dist/gateway/match.js +206 -0
  37. package/dist/gateway/match.js.map +1 -0
  38. package/dist/gateway/middleware.d.ts +108 -0
  39. package/dist/gateway/middleware.d.ts.map +1 -0
  40. package/dist/gateway/middleware.js +9 -0
  41. package/dist/gateway/middleware.js.map +1 -0
  42. package/dist/gateway/mod.d.ts +129 -0
  43. package/dist/gateway/mod.d.ts.map +1 -0
  44. package/dist/gateway/mod.js +187 -0
  45. package/dist/gateway/mod.js.map +1 -0
  46. package/dist/gateway/request.d.ts +304 -0
  47. package/dist/gateway/request.d.ts.map +1 -0
  48. package/dist/gateway/request.js +403 -0
  49. package/dist/gateway/request.js.map +1 -0
  50. package/dist/gateway/serve.d.ts +114 -0
  51. package/dist/gateway/serve.d.ts.map +1 -0
  52. package/dist/gateway/serve.js +510 -0
  53. package/dist/gateway/serve.js.map +1 -0
  54. package/dist/internal/clients/call.d.ts +147 -0
  55. package/dist/internal/clients/call.d.ts.map +1 -0
  56. package/dist/internal/clients/call.js +274 -0
  57. package/dist/internal/clients/call.js.map +1 -0
  58. package/dist/internal/clients/grpc.d.ts +90 -0
  59. package/dist/internal/clients/grpc.d.ts.map +1 -0
  60. package/dist/internal/clients/grpc.js +355 -0
  61. package/dist/internal/clients/grpc.js.map +1 -0
  62. package/dist/internal/clients/mod.d.ts +81 -0
  63. package/dist/internal/clients/mod.d.ts.map +1 -0
  64. package/dist/internal/clients/mod.js +237 -0
  65. package/dist/internal/clients/mod.js.map +1 -0
  66. package/dist/internal/fetch.d.ts +54 -0
  67. package/dist/internal/fetch.d.ts.map +1 -0
  68. package/dist/internal/fetch.js +240 -0
  69. package/dist/internal/fetch.js.map +1 -0
  70. package/dist/internal/otel/backend.d.ts +2 -0
  71. package/dist/internal/otel/backend.d.ts.map +1 -0
  72. package/dist/internal/otel/context.d.ts +1 -0
  73. package/dist/internal/otel/context.d.ts.map +1 -0
  74. package/dist/internal/otel/context_manager.d.ts +1 -0
  75. package/dist/internal/otel/context_manager.d.ts.map +1 -0
  76. package/dist/internal/otel/encode.d.ts +2 -0
  77. package/dist/internal/otel/encode.d.ts.map +1 -0
  78. package/dist/internal/otel/index.d.ts +2 -2
  79. package/dist/internal/otel/index.d.ts.map +1 -0
  80. package/dist/internal/otel/index.js +1 -2
  81. package/dist/internal/otel/index.js.map +1 -1
  82. package/dist/internal/otel/meter.d.ts +1 -0
  83. package/dist/internal/otel/meter.d.ts.map +1 -0
  84. package/dist/internal/otel/propagator.d.ts +1 -0
  85. package/dist/internal/otel/propagator.d.ts.map +1 -0
  86. package/dist/internal/otel/provider.d.ts +1 -0
  87. package/dist/internal/otel/provider.d.ts.map +1 -0
  88. package/dist/internal/otel/span.d.ts +4 -0
  89. package/dist/internal/otel/span.d.ts.map +1 -0
  90. package/dist/internal/otel/span.js +5 -0
  91. package/dist/internal/otel/span.js.map +1 -1
  92. package/dist/internal/otel/tracer.d.ts +1 -0
  93. package/dist/internal/otel/tracer.d.ts.map +1 -0
  94. package/dist/internal/otel/tracer.js +11 -5
  95. package/dist/internal/otel/tracer.js.map +1 -1
  96. package/dist/internal/reqfields.d.ts +150 -0
  97. package/dist/internal/reqfields.d.ts.map +1 -0
  98. package/dist/internal/reqfields.js +312 -0
  99. package/dist/internal/reqfields.js.map +1 -0
  100. package/dist/internal/runtime/meter.d.ts +1 -0
  101. package/dist/internal/runtime/meter.d.ts.map +1 -0
  102. package/dist/internal/runtime/mod.d.ts +6 -0
  103. package/dist/internal/runtime/mod.d.ts.map +1 -0
  104. package/dist/internal/runtime/mod.js +32 -2
  105. package/dist/internal/runtime/mod.js.map +1 -1
  106. package/dist/internal/runtime/napi/napi.cjs +160 -16
  107. package/dist/internal/runtime/napi/napi.d.cts +474 -29
  108. package/dist/internal/runtime/shutdown.d.ts +5 -0
  109. package/dist/internal/runtime/shutdown.d.ts.map +1 -0
  110. package/dist/internal/runtime/shutdown.js +9 -1
  111. package/dist/internal/runtime/shutdown.js.map +1 -1
  112. package/dist/internal/testing/runner.d.ts +2 -0
  113. package/dist/internal/testing/runner.d.ts.map +1 -0
  114. package/dist/internal/testing/runner.js +10 -0
  115. package/dist/internal/testing/runner.js.map +1 -0
  116. package/dist/internal/testing/scope.d.ts +81 -0
  117. package/dist/internal/testing/scope.d.ts.map +1 -0
  118. package/dist/internal/testing/scope.js +237 -0
  119. package/dist/internal/testing/scope.js.map +1 -0
  120. package/dist/internal/utils/constraints.d.ts +1 -0
  121. package/dist/internal/utils/constraints.d.ts.map +1 -0
  122. package/dist/log/index.d.ts +1 -0
  123. package/dist/log/index.d.ts.map +1 -0
  124. package/dist/log/logger.d.ts +2 -0
  125. package/dist/log/logger.d.ts.map +1 -0
  126. package/dist/log/runtime.d.ts +2 -0
  127. package/dist/log/runtime.d.ts.map +1 -0
  128. package/dist/log/stderr.d.ts +1 -0
  129. package/dist/log/stderr.d.ts.map +1 -0
  130. package/dist/metrics/mod.d.ts +45 -118
  131. package/dist/metrics/mod.d.ts.map +1 -0
  132. package/dist/metrics/mod.js +44 -179
  133. package/dist/metrics/mod.js.map +1 -1
  134. package/dist/mod.d.ts +1 -2
  135. package/dist/mod.d.ts.map +1 -0
  136. package/dist/mod.js +0 -1
  137. package/dist/mod.js.map +1 -1
  138. package/dist/otel.d.ts +1 -0
  139. package/dist/otel.d.ts.map +1 -0
  140. package/dist/pubsub/encoding.d.ts +5 -0
  141. package/dist/pubsub/encoding.d.ts.map +1 -0
  142. package/dist/pubsub/encoding.js +10 -2
  143. package/dist/pubsub/encoding.js.map +1 -1
  144. package/dist/pubsub/mod.d.ts +4 -3
  145. package/dist/pubsub/mod.d.ts.map +1 -0
  146. package/dist/pubsub/mod.js +2 -2
  147. package/dist/pubsub/mod.js.map +1 -1
  148. package/dist/pubsub/refs.d.ts +8 -0
  149. package/dist/pubsub/refs.d.ts.map +1 -0
  150. package/dist/pubsub/refs.js.map +1 -1
  151. package/dist/pubsub/subscription.d.ts +104 -10
  152. package/dist/pubsub/subscription.d.ts.map +1 -0
  153. package/dist/pubsub/subscription.js +98 -16
  154. package/dist/pubsub/subscription.js.map +1 -1
  155. package/dist/pubsub/topic.d.ts +87 -23
  156. package/dist/pubsub/topic.d.ts.map +1 -0
  157. package/dist/pubsub/topic.js +143 -40
  158. package/dist/pubsub/topic.js.map +1 -1
  159. package/dist/reqctx/mod.d.ts +191 -0
  160. package/dist/reqctx/mod.d.ts.map +1 -0
  161. package/dist/reqctx/mod.js +160 -0
  162. package/dist/reqctx/mod.js.map +1 -0
  163. package/dist/services/index.d.ts +145 -4
  164. package/dist/services/index.d.ts.map +1 -0
  165. package/dist/services/index.js +155 -8
  166. package/dist/services/index.js.map +1 -1
  167. package/dist/shutdown/mod.d.ts +1 -0
  168. package/dist/shutdown/mod.d.ts.map +1 -0
  169. package/dist/storage/objects/bucket.d.ts +312 -7
  170. package/dist/storage/objects/bucket.d.ts.map +1 -0
  171. package/dist/storage/objects/bucket.js +305 -15
  172. package/dist/storage/objects/bucket.js.map +1 -1
  173. package/dist/storage/objects/error.d.ts +10 -0
  174. package/dist/storage/objects/error.d.ts.map +1 -0
  175. package/dist/storage/objects/error.js +25 -1
  176. package/dist/storage/objects/error.js.map +1 -1
  177. package/dist/storage/objects/mod.d.ts +4 -3
  178. package/dist/storage/objects/mod.d.ts.map +1 -0
  179. package/dist/storage/objects/mod.js +1 -1
  180. package/dist/storage/objects/mod.js.map +1 -1
  181. package/dist/storage/objects/refs.d.ts +20 -4
  182. package/dist/storage/objects/refs.d.ts.map +1 -0
  183. package/dist/storage/objects/refs.js +6 -0
  184. package/dist/storage/objects/refs.js.map +1 -1
  185. package/dist/storage/postgres/database.d.ts +81 -25
  186. package/dist/storage/postgres/database.d.ts.map +1 -0
  187. package/dist/storage/postgres/database.js +125 -37
  188. package/dist/storage/postgres/database.js.map +1 -1
  189. package/dist/storage/postgres/errors.d.ts +120 -0
  190. package/dist/storage/postgres/errors.d.ts.map +1 -0
  191. package/dist/storage/postgres/errors.js +162 -0
  192. package/dist/storage/postgres/errors.js.map +1 -0
  193. package/dist/storage/postgres/interval.d.ts +44 -0
  194. package/dist/storage/postgres/interval.d.ts.map +1 -0
  195. package/dist/storage/postgres/interval.js +153 -0
  196. package/dist/storage/postgres/interval.js.map +1 -0
  197. package/dist/storage/postgres/mod.d.ts +4 -1
  198. package/dist/storage/postgres/mod.d.ts.map +1 -0
  199. package/dist/storage/postgres/mod.js +2 -0
  200. package/dist/storage/postgres/mod.js.map +1 -1
  201. package/dist/storage/redis/bitfield.d.ts +67 -0
  202. package/dist/storage/redis/bitfield.d.ts.map +1 -0
  203. package/dist/storage/redis/bitfield.js +114 -0
  204. package/dist/storage/redis/bitfield.js.map +1 -0
  205. package/dist/storage/redis/command.d.ts +45 -0
  206. package/dist/storage/redis/command.d.ts.map +1 -0
  207. package/dist/storage/redis/command.js +78 -0
  208. package/dist/storage/redis/command.js.map +1 -0
  209. package/dist/storage/redis/commands.d.ts +223 -139
  210. package/dist/storage/redis/commands.d.ts.map +1 -0
  211. package/dist/storage/redis/commands.js +128 -6
  212. package/dist/storage/redis/commands.js.map +1 -1
  213. package/dist/storage/redis/database.d.ts +56 -22
  214. package/dist/storage/redis/database.d.ts.map +1 -0
  215. package/dist/storage/redis/database.js +62 -0
  216. package/dist/storage/redis/database.js.map +1 -1
  217. package/dist/storage/redis/mod.d.ts +31 -4
  218. package/dist/storage/redis/mod.d.ts.map +1 -0
  219. package/dist/storage/redis/mod.js +26 -1
  220. package/dist/storage/redis/mod.js.map +1 -1
  221. package/dist/storage/redis/native.d.ts +8 -0
  222. package/dist/storage/redis/native.d.ts.map +1 -0
  223. package/dist/storage/redis/native.js +10 -0
  224. package/dist/storage/redis/native.js.map +1 -1
  225. package/dist/storage/redis/options.d.ts +1 -0
  226. package/dist/storage/redis/options.d.ts.map +1 -0
  227. package/dist/storage/redis/pubsub.d.ts +2 -0
  228. package/dist/storage/redis/pubsub.d.ts.map +1 -0
  229. package/dist/storage/redis/reply.d.ts +34 -0
  230. package/dist/storage/redis/reply.d.ts.map +1 -0
  231. package/dist/storage/redis/reply.js +40 -1
  232. package/dist/storage/redis/reply.js.map +1 -1
  233. package/dist/storage/redis/scan.d.ts +1 -0
  234. package/dist/storage/redis/scan.d.ts.map +1 -0
  235. package/dist/storage/redis/script.d.ts +1 -0
  236. package/dist/storage/redis/script.d.ts.map +1 -0
  237. package/dist/storage/redis/target.d.ts +5 -3
  238. package/dist/storage/redis/target.d.ts.map +1 -0
  239. package/dist/storage/redis/target.js +39 -28
  240. package/dist/storage/redis/target.js.map +1 -1
  241. package/dist/storage/redis/wire.d.ts +7 -10
  242. package/dist/storage/redis/wire.d.ts.map +1 -0
  243. package/dist/storage/redis/wire.js +8 -32
  244. package/dist/storage/redis/wire.js.map +1 -1
  245. package/dist/testing/bun.d.ts +8 -0
  246. package/dist/testing/bun.d.ts.map +1 -0
  247. package/dist/testing/bun.js +13 -0
  248. package/dist/testing/bun.js.map +1 -0
  249. package/dist/testing/jest.d.ts +8 -0
  250. package/dist/testing/jest.d.ts.map +1 -0
  251. package/dist/testing/jest.js +11 -0
  252. package/dist/testing/jest.js.map +1 -0
  253. package/dist/testing/mod.d.ts +160 -0
  254. package/dist/testing/mod.d.ts.map +1 -0
  255. package/dist/testing/mod.js +227 -0
  256. package/dist/testing/mod.js.map +1 -0
  257. package/dist/testing/node.d.ts +9 -0
  258. package/dist/testing/node.d.ts.map +1 -0
  259. package/dist/testing/node.js +12 -0
  260. package/dist/testing/node.js.map +1 -0
  261. package/dist/testing/vitest.d.ts +8 -0
  262. package/dist/testing/vitest.d.ts.map +1 -0
  263. package/dist/testing/vitest.js +13 -0
  264. package/dist/testing/vitest.js.map +1 -0
  265. package/dist/tracing/mod.d.ts +19 -0
  266. package/dist/tracing/mod.d.ts.map +1 -0
  267. package/dist/tracing/mod.js +46 -0
  268. package/dist/tracing/mod.js.map +1 -0
  269. package/dist/tsconfig.build.tsbuildinfo +1 -1
  270. package/dist/types/mod.d.ts +1 -0
  271. package/dist/types/mod.d.ts.map +1 -0
  272. package/gateway/errors.ts +172 -0
  273. package/gateway/gateway.e2e.test.ts +297 -0
  274. package/gateway/gateway.test.ts +891 -0
  275. package/gateway/match.ts +239 -0
  276. package/gateway/middleware.ts +134 -0
  277. package/gateway/mod.ts +210 -0
  278. package/gateway/request.ts +578 -0
  279. package/gateway/serve.ts +738 -0
  280. package/internal/clients/call.ts +389 -0
  281. package/internal/clients/grpc.test.ts +368 -0
  282. package/internal/clients/grpc.ts +485 -0
  283. package/internal/clients/mod.test.ts +464 -0
  284. package/internal/clients/mod.ts +337 -0
  285. package/internal/fetch.ts +276 -0
  286. package/internal/otel/index.ts +1 -7
  287. package/internal/otel/span.ts +6 -0
  288. package/internal/otel/tracer.test.ts +43 -15
  289. package/internal/otel/tracer.ts +12 -5
  290. package/internal/reqfields.ts +390 -0
  291. package/internal/runtime/mod.ts +41 -2
  292. package/internal/runtime/napi/napi.cjs +160 -16
  293. package/internal/runtime/napi/napi.d.cts +474 -29
  294. package/internal/runtime/shutdown.ts +11 -1
  295. package/internal/testing/runner.ts +10 -0
  296. package/internal/testing/scope.ts +273 -0
  297. package/metrics/mod.test.ts +13 -16
  298. package/metrics/mod.ts +57 -226
  299. package/mod.ts +0 -8
  300. package/otel.test.ts +13 -6
  301. package/package.json +67 -15
  302. package/pubsub/encoding.ts +11 -1
  303. package/pubsub/mod.ts +10 -3
  304. package/pubsub/pubsub.test.ts +232 -14
  305. package/pubsub/refs.ts +16 -0
  306. package/pubsub/subscription.ts +194 -16
  307. package/pubsub/topic.test.ts +26 -0
  308. package/pubsub/topic.ts +220 -25
  309. package/reqctx/mod.ts +284 -0
  310. package/reqctx/reqctx.test.ts +193 -0
  311. package/scripts/postprocess-docs.test.ts +48 -0
  312. package/services/index.test.ts +341 -1
  313. package/services/index.ts +183 -8
  314. package/storage/objects/bucket.test.ts +573 -0
  315. package/storage/objects/bucket.ts +649 -20
  316. package/storage/objects/error.ts +28 -1
  317. package/storage/objects/mod.ts +15 -0
  318. package/storage/objects/refs.ts +51 -3
  319. package/storage/postgres/database.integration.test.ts +275 -0
  320. package/storage/postgres/database.test.ts +193 -6
  321. package/storage/postgres/database.ts +202 -55
  322. package/storage/postgres/errors.ts +186 -0
  323. package/storage/postgres/interval.test.ts +72 -0
  324. package/storage/postgres/interval.ts +170 -0
  325. package/storage/postgres/mod.ts +4 -0
  326. package/storage/redis/bitfield.ts +162 -0
  327. package/storage/redis/command.ts +84 -0
  328. package/storage/redis/commands.ts +271 -21
  329. package/storage/redis/database.ts +77 -23
  330. package/storage/redis/mod.ts +38 -2
  331. package/storage/redis/native.ts +11 -0
  332. package/storage/redis/redis.test.ts +170 -10
  333. package/storage/redis/reply.ts +76 -1
  334. package/storage/redis/runtime.test.ts +15 -0
  335. package/storage/redis/target.ts +47 -44
  336. package/storage/redis/wire.ts +8 -32
  337. package/testing/bun.ts +13 -0
  338. package/testing/jest.ts +11 -0
  339. package/testing/mod.ts +337 -0
  340. package/testing/node.ts +12 -0
  341. package/testing/vitest.ts +13 -0
  342. package/tracing/mod.ts +82 -0
  343. package/tracing/native.test.ts +170 -0
  344. package/tracing/tracing.test.ts +317 -0
  345. package/dist/internal/otel/request_context.d.ts +0 -11
  346. package/dist/internal/otel/request_context.js +0 -20
  347. package/dist/internal/otel/request_context.js.map +0 -1
  348. package/dist/internal/reqtrack/mod.d.ts +0 -6
  349. package/dist/internal/reqtrack/mod.js +0 -28
  350. package/dist/internal/reqtrack/mod.js.map +0 -1
  351. package/dist/req_meta.d.ts +0 -47
  352. package/dist/req_meta.js +0 -26
  353. package/dist/req_meta.js.map +0 -1
  354. package/internal/otel/request_context.ts +0 -32
  355. package/internal/reqtrack/mod.ts +0 -39
  356. package/req_meta.ts +0 -75
package/README.md CHANGED
@@ -116,6 +116,61 @@ handlers that parse JSON manually should use the decoded value, or explicitly
116
116
  select `encoding: "raw"`. Consumer termination no longer starts another consumer
117
117
  after a timer: failures are logged, and normal completion leaves it stopped.
118
118
 
119
+ ## Tracing
120
+
121
+ ```typescript
122
+ import {span} from '@encore.dev/sdk/tracing';
123
+ import log from '@encore.dev/sdk/log';
124
+
125
+ const items = await span(
126
+ 'place_order',
127
+ {attributes: {'order.id': orderId}},
128
+ async current => {
129
+ const count = await span('validate_order', () => validate(orderId));
130
+ current.setAttribute('order.items', count);
131
+ log.info('Order placed', {order_id: orderId});
132
+ return count;
133
+ },
134
+ );
135
+ ```
136
+
137
+ `span(name, callback)` omits attributes. The callback gets
138
+ an OpenTelemetry `Span`; the helper owns completion, so do not call `end()`.
139
+ Synchronous callbacks return or throw synchronously. PromiseLike results become
140
+ Promises, and the span ends after settlement. Throws and rejections record an
141
+ exception and ERROR status, preserving the original value. OTel's OK status is
142
+ final: setting it prevents a later ERROR status. Successful callbacks leave
143
+ status UNSET unless the callback sets it.
144
+
145
+ Use bounded span names; put order IDs and other variable data in attributes.
146
+ Nested spans, logs, metric exemplars, and service calls share the active context
147
+ across awaits and timers. Detached work must manage its own lifetime.
148
+
149
+ Encore always uses its cached, owned provider, independent of OTel globals.
150
+ Importing or using tracing registers no global provider, context manager,
151
+ propagator, meter, or logger. Native `span` works without OTel setup. For OTel
152
+ interop, the app owns its context manager and configures it through normal OTel
153
+ setup before instrumented work. Pass Encore's tracer provider explicitly:
154
+
155
+ ```typescript
156
+ import {span, tracerProvider} from '@encore.dev/sdk/tracing';
157
+
158
+ // Configure the app's OTel context manager before instrumented work.
159
+ const tracer = tracerProvider().getTracer('orders');
160
+ await tracer.startActiveSpan('order_request', async current => {
161
+ try {
162
+ await span('place_order', () => placeOrder());
163
+ } finally {
164
+ current.end(); // OTel callbacks own their span lifetime.
165
+ }
166
+ });
167
+ ```
168
+
169
+ The app may choose `trace.setGlobalTracerProvider(tracerProvider())` for libraries
170
+ that use the global API; Encore never does this automatically. `tracerProvider`
171
+ remains available from `@encore.dev/sdk`. See the paired
172
+ [tracing fixtures](../../../tests/ts/telemetry) for runnable examples.
173
+
119
174
  ## Formatting and linting
120
175
 
121
176
  Use Node.js 24 LTS for SDK development and install dependencies with `npm ci`.
package/app_meta.ts CHANGED
@@ -111,6 +111,13 @@ export interface DeployMeta {
111
111
 
112
112
  /** The services hosted by this deployment, keyed by the service name. */
113
113
  hostedServices: Record<string, HostedService>;
114
+
115
+ /**
116
+ * The Worker of its service this process runs: a long-running process of
117
+ * the service that serves no requests, declared in the `workers` section of
118
+ * its `encore.service.json`. Undefined for the service's main process.
119
+ */
120
+ worker?: string;
114
121
  }
115
122
 
116
123
  export interface HostedService {
@@ -144,6 +151,7 @@ export function appMeta(): AppMeta {
144
151
  id: rt.deploy.id,
145
152
  time: new Date(rt.deploy.deployTime),
146
153
  hostedServices: rt.deploy.hostedServices,
154
+ worker: rt.deploy.worker ?? undefined,
147
155
  },
148
156
  };
149
157
  }
@@ -186,11 +186,13 @@ describe('config', () => {
186
186
  const mod = JSON.stringify(`${import.meta.dir}/mod`);
187
187
  const out = run(`
188
188
  import { writeFileSync } from "node:fs";
189
- import { config, sharedConfig, Duration } from ${mod};
189
+ import { config, secret, Duration } from ${mod};
190
190
  const checkout = config("checkout");
191
- const flags = sharedConfig("flags");
191
+ const flags = config("flags", { scope: "shared" });
192
192
  const missing = config("nothing");
193
193
  const a = checkout(), b = checkout();
194
+ let unset;
195
+ try { secret("Unset")(); } catch (e) { unset = e.message; }
194
196
  console.log(JSON.stringify({
195
197
  maxItems: a.max_items,
196
198
  timeout: a.timeout instanceof Duration ? a.timeout.seconds : null,
@@ -201,6 +203,7 @@ describe('config', () => {
201
203
  flagKey: flags().key(),
202
204
  missing: missing(),
203
205
  name: checkout.name,
206
+ unset,
204
207
  }));
205
208
  const stop = checkout.onChange((v) => {
206
209
  console.log(JSON.stringify({ changed: v.max_items, timeout: v.timeout.seconds, now: checkout().max_items }));
@@ -223,6 +226,8 @@ describe('config', () => {
223
226
  flagKey: 'shared-flag-key',
224
227
  missing: {},
225
228
  name: 'checkout',
229
+ // Not set is an error wherever the app runs, locally too.
230
+ unset: 'secret Unset is not set',
226
231
  });
227
232
  expect(out[1]).toEqual({changed: 7, timeout: 60, now: 7});
228
233
  });
@@ -334,7 +339,8 @@ function runtimeConfig(live: string): string {
334
339
  },
335
340
  additionalProperties: false,
336
341
  };
337
- // AppConfig{rid=1, encore_name=2, service=3, json_schema=4, value=5}
342
+ // AppConfig{rid=1, encore_name=2, services=3, json_schema=4, value=5}: the
343
+ // service's own config given to orders, the shared one to every service.
338
344
  const checkout = [
339
345
  ...str(1, 'config:orders.checkout'),
340
346
  ...str(2, 'checkout'),
@@ -345,6 +351,7 @@ function runtimeConfig(live: string): string {
345
351
  const flags = [
346
352
  ...str(1, 'config:flags'),
347
353
  ...str(2, 'flags'),
354
+ ...str(3, '*'),
348
355
  ...str(4, JSON.stringify(flagsSchema)),
349
356
  ...str(5, JSON.stringify({new_checkout: true})),
350
357
  ];
package/config/config.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as runtime from '../internal/runtime/mod';
2
+ import {lookupScope, testMode, type Scope} from '../internal/testing/scope';
2
3
  import {secretOfField} from './secrets';
3
4
  import {build} from './value';
4
5
 
@@ -8,10 +9,9 @@ export {Duration} from './value';
8
9
  * A config: a typed value a service reads, written in files beside the code
9
10
  * and changed while the app runs. Calling it reads the value now.
10
11
  *
11
- * Declare one with {@link config}, {@link sharedConfig} or
12
- * {@link globalConfig}, giving the value's type as the type argument. Encore
13
- * reads that type to know what the config's files may hold, and checks them
14
- * against it before the value reaches the code.
12
+ * Declare one with {@link config}, giving the value's type as the type
13
+ * argument. Encore reads that type to know what the config's files may hold,
14
+ * and checks them against it before the value reaches the code.
15
15
  *
16
16
  * @example
17
17
  * import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
@@ -57,31 +57,80 @@ export interface Config<T> {
57
57
  onChange(listener: (value: T) => void): () => void;
58
58
  }
59
59
 
60
- /**
61
- * config declares a {@link Config} belonging to the service that declares it,
62
- * which holds its own value for it. Two services may each declare a config of
63
- * the same name. The declaration must live inside a service, as a module-level
64
- * `export const`, with the name a string literal.
65
- */
66
- export function config<T>(name: string): Config<T> {
67
- return makeConfig<T>(name, runtime.RT.config(name));
60
+ /** The options a config is declared with. */
61
+ export interface ConfigOptions {
62
+ /**
63
+ * Who the config belongs to, written as a string literal for Encore to
64
+ * read:
65
+ *
66
+ * - `"service"`, the default: the service that declares it, which holds
67
+ * its own value for it. Two services may each declare a config of the
68
+ * same name. The declaration must live inside a service.
69
+ * - `"shared"`: the whole app, with one value. A service that reads it is
70
+ * recorded as using it. It may be declared outside a service.
71
+ * - `"global"`: the whole app, with one value available to every service
72
+ * without being recorded as used. It may be declared outside a service.
73
+ *
74
+ * A config name has one scope across the app, as a secret's has: a name
75
+ * declared shared or global can't also be a service's own.
76
+ */
77
+ scope?: 'service' | 'shared' | 'global';
78
+
79
+ /**
80
+ * Tags that classify the config, for policies to read: written out as
81
+ * string literals, as in `{data: "pci"}`. Keys and values are lowercase
82
+ * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
83
+ * letter, and not with `encore`, which is reserved. At most 32 tags.
84
+ */
85
+ tags?: Record<string, string>;
68
86
  }
69
87
 
70
88
  /**
71
- * sharedConfig declares a {@link Config} with one value for the whole app. A
72
- * service that reads it is recorded as using it. Unlike {@link config} it may
73
- * be declared outside a service.
89
+ * config declares a {@link Config}, by default belonging to the service that
90
+ * declares it (see {@link ConfigOptions.scope}). The declaration is a
91
+ * module-level `export const`, with the name a string literal.
92
+ *
93
+ * @example a config several services read
94
+ * export const flags = config<Flags>("flags", {scope: "shared"});
74
95
  */
75
- export function sharedConfig<T>(name: string): Config<T> {
76
- return makeConfig<T>(name, runtime.RT.sharedConfig(name));
96
+ export function config<T>(
97
+ name: string,
98
+ // The options are Encore's parser's to read: a config is read by name
99
+ // whatever its scope, a name having one scope across the app.
100
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
101
+ opts?: ConfigOptions,
102
+ ): Config<T> {
103
+ const handle = makeConfig<T>(name, runtime.RT.config(name));
104
+ names.set(handle, name);
105
+ return handle;
77
106
  }
78
107
 
108
+ /** The name of the config each handle reads. */
109
+ const names = new WeakMap<Config<any>, string>();
110
+
79
111
  /**
80
- * globalConfig declares a {@link Config} with one value for the whole app,
81
- * available to every service without being recorded as used.
112
+ * Gives `cfg` the value `value` for the test `scope`, once the core has
113
+ * checked it against the config's schema: reading the config in the test
114
+ * returns it from then on. For `@encore.dev/sdk/testing`.
115
+ *
116
+ * @internal
82
117
  */
83
- export function globalConfig<T>(name: string): Config<T> {
84
- return makeConfig<T>(name, runtime.RT.sharedConfig(name));
118
+ export function setTestValue<T>(scope: Scope, cfg: Config<T>, value: T): void {
119
+ const name = names.get(cfg);
120
+ if (name === undefined) {
121
+ throw new TypeError('setConfig takes a config declared with `config()`');
122
+ }
123
+ const json = JSON.stringify(value);
124
+ if (json === undefined) {
125
+ throw new TypeError(`config ${name}: the value has no JSON form`);
126
+ }
127
+ const prepared = JSON.parse(scope.native.setConfig(name, json));
128
+ const impl = runtime.RT.config(name);
129
+ const built =
130
+ impl === null
131
+ ? prepared
132
+ : build(JSON.parse(impl.schema()), prepared, secretOfField);
133
+ scope.configs.set(name, built);
85
134
  }
86
135
 
87
136
  /** The native handle to a config, when the runtime config has it. */
@@ -116,6 +165,11 @@ function makeConfig<T>(name: string, impl: Impl | null): Config<T> {
116
165
  };
117
166
 
118
167
  const read = (): T => {
168
+ if (testMode) {
169
+ // The value the current test gave it, if it did.
170
+ const configs = lookupScope()?.configs;
171
+ if (configs?.has(name)) return configs.get(name) as T;
172
+ }
119
173
  if (impl === null) {
120
174
  // No value at all: every field takes its default, which in TypeScript is
121
175
  // none. The runtime config has every config the app declares, so this
package/config/mod.ts CHANGED
@@ -1,7 +1,8 @@
1
- export type {Secret, AnySecret} from './secrets';
2
- export {secret, sharedSecret, globalSecret} from './secrets';
1
+ export type {Secret, AnySecret, SecretOptions} from './secrets';
2
+ export {secret} from './secrets';
3
3
  export type {
4
4
  Config,
5
+ ConfigOptions,
5
6
  Min,
6
7
  Max,
7
8
  Int,
@@ -11,4 +12,4 @@ export type {
11
12
  MinItems,
12
13
  MaxItems,
13
14
  } from './config';
14
- export {config, sharedConfig, globalConfig, Duration} from './config';
15
+ export {config, Duration} from './config';
package/config/secrets.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as runtime from '../internal/runtime/mod';
2
+ import {lookupScope, testMode} from '../internal/testing/scope';
2
3
  import {StringLiteral} from '../internal/utils/constraints';
3
4
 
4
5
  /**
@@ -9,22 +10,25 @@ import {StringLiteral} from '../internal/utils/constraints';
9
10
  * You can use {@link AnySecret} to represent any secret without knowing
10
11
  * it's name.
11
12
  *
13
+ * `T` is the type of the secret's value. Only `string` is supported.
14
+ *
12
15
  * @example
13
16
  *
14
17
  * function doFoo(s: Secret<"foo">): void {
15
18
  * const foo = s();
16
19
  * }
17
20
  */
18
- export interface Secret<Name extends string> {
21
+ export interface Secret<Name extends string, T extends string = string> {
19
22
  /**
20
- * Returns the current value of the secret.
23
+ * Returns the value of the secret.
24
+ *
25
+ * The value is read once per process and does not change while it runs:
26
+ * a new value reaches a service when it restarts.
21
27
  *
22
- * Encore will periodically refresh the value of the secret, so this
23
- * value may change over time and could be stale for upto a couple of
24
- * minutes. If you need to ensure you have the latest value, use
25
- * `latest`.
28
+ * Throws an `Error` naming the secret when it has no value, in every
29
+ * environment, local development too.
26
30
  */
27
- (): string;
31
+ (): T;
28
32
 
29
33
  /**
30
34
  * The name of the secret.
@@ -37,9 +41,8 @@ export interface Secret<Name extends string> {
37
41
  *
38
42
  * As a field of a config's type, `apiKey: Secret<"StripeKey">` reads the
39
43
  * secret of that name in the config's own scope: the declaring service's
40
- * own for `config()`, the app's for `sharedConfig()` and `globalConfig()`.
41
- * The secret is declared as any other is, with {@link secret},
42
- * {@link sharedSecret} or {@link globalSecret}.
44
+ * own for a service config, the app's for a shared or global one. The
45
+ * secret is declared as any other is, with {@link secret}.
43
46
  */
44
47
  readonly '~encore.secret'?: true;
45
48
  }
@@ -51,54 +54,71 @@ export interface Secret<Name extends string> {
51
54
  export type AnySecret = Secret<string>;
52
55
 
53
56
  /**
54
- * secret declares a {@link Secret} belonging to the service that declares it.
55
- *
56
- * Two services may each declare a secret of the same name and hold different
57
- * values in them, so adding a secret to one service can never collide with — or
58
- * silently reuse — a name another service already took. The declaration must
59
- * therefore live inside a service; Encore reports an error otherwise.
60
- *
61
- * For a value several services genuinely share, use {@link sharedSecret}.
62
- *
63
- * @example loading a single secret
64
- * import {secret} from "@encore.dev/sdk/config";
65
- * const foo = secret("foo");
57
+ * The options a secret is declared with. Read by Encore's parser, so the
58
+ * values must be literals.
66
59
  */
67
- export function secret<Name extends string>(
68
- name: StringLiteral<Name>,
69
- ): Secret<Name> {
70
- return makeSecret<Secret<Name>>(name, runtime.RT.secret(name));
60
+ export interface SecretOptions {
61
+ /**
62
+ * Who the secret belongs to, written as a string literal for Encore to
63
+ * read:
64
+ *
65
+ * - `"service"`, the default: the service that declares it. Two services
66
+ * may each declare a secret of the same name and hold different values
67
+ * in them, so adding a secret to one service can never collide with, or
68
+ * silently reuse, a name another service already took. The declaration
69
+ * must therefore live inside a service; Encore reports an error
70
+ * otherwise.
71
+ * - `"shared"`: the whole app, readable from any service, each that reads
72
+ * it recorded as using it. It may be declared outside a service. Use it
73
+ * only for a value several services genuinely share: a shared secret
74
+ * couples every service that reads it, and widening a secret's scope
75
+ * later is easier than narrowing it.
76
+ * - `"global"`: the whole app, with one value available to every service
77
+ * without being granted. It may be declared outside a service.
78
+ */
79
+ scope?: 'service' | 'shared' | 'global';
80
+
81
+ /**
82
+ * What the secret is, who issues it and how to rotate it, shown wherever its
83
+ * values are managed. The declaration's doc comment wins when there is one.
84
+ */
85
+ description?: string;
86
+
87
+ /**
88
+ * Tags that classify the secret, for policies to read: written out as
89
+ * string literals, as in `{data: "pci"}`. Keys and values are lowercase
90
+ * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
91
+ * letter, and not with `encore`, which is reserved. At most 32 tags.
92
+ */
93
+ tags?: Record<string, string>;
71
94
  }
72
95
 
73
96
  /**
74
- * sharedSecret declares a {@link Secret} shared by the whole app, readable from
75
- * any service. Unlike {@link secret} it may be declared outside a service.
97
+ * secret declares a {@link Secret}, by default belonging to the service that
98
+ * declares it. See {@link SecretOptions.scope} for a secret of the whole app.
76
99
  *
77
- * Use it only for a value several services genuinely share: a shared secret
78
- * couples every service that reads it, and widening a secret's scope later is
79
- * easier than narrowing it.
100
+ * A doc comment on the declaration, or a `description` option, is shown
101
+ * wherever the secret's values are managed.
80
102
  *
81
- * @example
82
- * import {sharedSecret} from "@encore.dev/sdk/config";
83
- * const signingKey = sharedSecret("SigningKey");
84
- */
85
- export function sharedSecret<Name extends string>(
86
- name: StringLiteral<Name>,
87
- ): Secret<Name> {
88
- return makeSecret<Secret<Name>>(name, runtime.RT.secret(name));
89
- }
90
-
91
- /**
92
- * globalSecret declares a {@link Secret} with one value for the whole app,
93
- * available to every service without being granted. Like
94
- * {@link sharedSecret} it may be declared outside a service.
103
+ * @example loading a single secret
104
+ * import {secret} from "@encore.dev/sdk/config";
105
+ * const foo = secret("foo");
95
106
  *
96
- * @example
97
- * import {globalSecret} from "@encore.dev/sdk/config";
98
- * const telemetryKey = globalSecret("TelemetryKey");
107
+ * @example a secret several services share
108
+ * import {secret} from "@encore.dev/sdk/config";
109
+ * const signingKey = secret("SigningKey", {scope: "shared"});
110
+ *
111
+ * @example documenting it
112
+ * const apiKey = secret("ApiKey", {
113
+ * description: "Issued by Acme Pay. Rotate it in their portal under Settings → API.",
114
+ * });
99
115
  */
100
- export function globalSecret<Name extends string>(
116
+ export function secret<Name extends string>(
101
117
  name: StringLiteral<Name>,
118
+ // The options are Encore's parser's to read: a secret is read by name
119
+ // whatever its scope, a name having one scope across the app.
120
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
121
+ opts?: SecretOptions,
102
122
  ): Secret<Name> {
103
123
  return makeSecret<Secret<Name>>(name, runtime.RT.secret(name));
104
124
  }
@@ -123,13 +143,10 @@ function makeSecret<S extends AnySecret>(
123
143
  impl: ReturnType<typeof runtime.RT.secret>,
124
144
  ): S {
125
145
  const secretObj = () => {
146
+ // The value the current test gave it, if it did.
147
+ const override = testMode ? lookupScope()?.native.secret(name) : null;
148
+ if (override != null) return override.toString('utf8');
126
149
  if (impl === null) {
127
- // During local development we don't consider missing secrets a fatal error.
128
- if (
129
- runtime.RT.appMeta().environment.cloud === runtime.CloudProvider.Local
130
- ) {
131
- return '';
132
- }
133
150
  throw new Error(`secret ${name} is not set`);
134
151
  }
135
152
  return impl.cached();
package/cron/mod.ts CHANGED
@@ -1,5 +1,30 @@
1
1
  import {DurationString} from '../types/mod';
2
2
 
3
+ /**
4
+ * The header with a run's idempotency key: an id that is the same each time
5
+ * Encore sends the run, as when it sends it again after a failure. A job
6
+ * that must not do its work twice can check whether it has seen the key
7
+ * before:
8
+ *
9
+ * ```ts
10
+ * app.post('/internal/cleanup', (req, res) => {
11
+ * const key = req.get(IDEMPOTENCY_KEY_HEADER);
12
+ * // ...
13
+ * });
14
+ * ```
15
+ *
16
+ * Only Encore sends it: a gateway removes it from the requests it takes from
17
+ * clients. `encore cron trigger <name>` runs a job locally, as Encore runs it
18
+ * when it is due.
19
+ */
20
+ export const IDEMPOTENCY_KEY_HEADER = 'x-encore-cron-execution';
21
+
22
+ /**
23
+ * The header that says why a job runs: `scheduled`, when it was due, or
24
+ * `manual`, when someone asked for it to run now.
25
+ */
26
+ export const TRIGGER_HEADER = 'x-encore-cron-trigger';
27
+
3
28
  export class CronJob {
4
29
  readonly name: string;
5
30
  readonly cfg: CronJobConfig;
@@ -20,4 +45,11 @@ export type CronJobConfig = {
20
45
  /** The path the job requests of its service, starting with `/`. */
21
46
  path: string;
22
47
  title?: string;
48
+ /**
49
+ * Tags that classify the cron job, for policies to read: written out as
50
+ * string literals, as in `{data: "pci"}`. Keys and values are lowercase
51
+ * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
52
+ * letter, and not with `encore`, which is reserved. At most 32 tags.
53
+ */
54
+ tags?: Record<string, string>;
23
55
  } & ({every: DurationString} | {schedule: string});
@@ -80,6 +80,12 @@ export interface DeployMeta {
80
80
  time: Date;
81
81
  /** The services hosted by this deployment, keyed by the service name. */
82
82
  hostedServices: Record<string, HostedService>;
83
+ /**
84
+ * The Worker of its service this process runs: a long-running process of
85
+ * the service that serves no requests, declared in the `workers` section of
86
+ * its `encore.service.json`. Undefined for the service's main process.
87
+ */
88
+ worker?: string;
83
89
  }
84
90
  export interface HostedService {
85
91
  /** The name of the service */
@@ -92,3 +98,4 @@ export interface HostedService {
92
98
  * and therefore must not be modified by the caller.
93
99
  */
94
100
  export declare function appMeta(): AppMeta;
101
+ //# sourceMappingURL=app_meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app_meta.d.ts","sourceRoot":"","sources":["../app_meta.ts"],"names":[],"mappings":"AAEA,gDAAgD;AAChD,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;OAOG;IACH,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAEtC,+DAA+D;IAC/D,WAAW,EAAE,eAAe,CAAC;IAE7B,mCAAmC;IACnC,KAAK,EAAE,SAAS,CAAC;IAEjB,wCAAwC;IACxC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,wDAAwD;AACxD,MAAM,WAAW,WAAW;IAC1B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,sEAAsE;AACtE,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,eAAe,CAAC;IAEtB;;;OAGG;IACH,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,wEAAwE;AACxE,MAAM,MAAM,eAAe,GAEvB,YAAY,GAEZ,aAAa,GAEb,WAAW,GAEX,MAAM,CAAC;AAEX,mEAAmE;AACnE,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,KAAK,GACL,OAAO,GACP,QAAQ,GACR,OAAO,CAAC;AAEZ,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACxB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,mEAAmE;AACnE,MAAM,WAAW,UAAU;IACzB,yEAAyE;IACzE,EAAE,EAAE,MAAM,CAAC;IAEX,2EAA2E;IAC3E,IAAI,EAAE,IAAI,CAAC;IAEX,yEAAyE;IACzE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAE9C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,IAAI,OAAO,CA0BjC"}
package/dist/app_meta.js CHANGED
@@ -25,6 +25,7 @@ export function appMeta() {
25
25
  id: rt.deploy.id,
26
26
  time: new Date(rt.deploy.deployTime),
27
27
  hostedServices: rt.deploy.hostedServices,
28
+ worker: rt.deploy.worker ?? undefined,
28
29
  },
29
30
  };
30
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"app_meta.js","sourceRoot":"","sources":["../app_meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAwHlD;;;;;GAKG;AACH,MAAM,UAAU,OAAO;IACrB,qCAAqC;IACrC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QAChC,MAAM,GAAG;YACP,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,OAAO,EAAE,EAAE,CAAC,OAAO;YACnB,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,WAAW,EAAE;gBACX,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI;gBACzB,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;gBAClC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC;aAC3C;YACD,KAAK,EAAE;gBACL,QAA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Ae,CAAC,IAAI;YAC/B,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,aAAa,CAAC;IACzB,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,MAA6B;IAClD,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO,CAAC,aAAa,CAAC,GAAG;YAC5B,OAAO,KAAK,CAAC;QACf,KAAK,OAAO,CAAC,aAAa,CAAC,GAAG;YAC5B,OAAO,KAAK,CAAC;QACf,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK;YAC9B,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO,CAAC,aAAa,CAAC,MAAM;YAC/B,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK;YAC9B,OAAO,OAAO,CAAC;QACjB;YACE,OAAO,OAAO,CAAC;IACnB,CAAC;AACH,CAAC;AAED,6CAA6C;AAC7C,IAAI,MAAM,GAAmB,IAAI,CAAC"}
@@ -1,12 +1,12 @@
1
+ import { type Scope } from '../internal/testing/scope.js';
1
2
  export { Duration } from './value.js';
2
3
  /**
3
4
  * A config: a typed value a service reads, written in files beside the code
4
5
  * and changed while the app runs. Calling it reads the value now.
5
6
  *
6
- * Declare one with {@link config}, {@link sharedConfig} or
7
- * {@link globalConfig}, giving the value's type as the type argument. Encore
8
- * reads that type to know what the config's files may hold, and checks them
9
- * against it before the value reaches the code.
7
+ * Declare one with {@link config}, giving the value's type as the type
8
+ * argument. Encore reads that type to know what the config's files may hold,
9
+ * and checks them against it before the value reaches the code.
10
10
  *
11
11
  * @example
12
12
  * import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
@@ -49,24 +49,49 @@ export interface Config<T> {
49
49
  */
50
50
  onChange(listener: (value: T) => void): () => void;
51
51
  }
52
+ /** The options a config is declared with. */
53
+ export interface ConfigOptions {
54
+ /**
55
+ * Who the config belongs to, written as a string literal for Encore to
56
+ * read:
57
+ *
58
+ * - `"service"`, the default: the service that declares it, which holds
59
+ * its own value for it. Two services may each declare a config of the
60
+ * same name. The declaration must live inside a service.
61
+ * - `"shared"`: the whole app, with one value. A service that reads it is
62
+ * recorded as using it. It may be declared outside a service.
63
+ * - `"global"`: the whole app, with one value available to every service
64
+ * without being recorded as used. It may be declared outside a service.
65
+ *
66
+ * A config name has one scope across the app, as a secret's has: a name
67
+ * declared shared or global can't also be a service's own.
68
+ */
69
+ scope?: 'service' | 'shared' | 'global';
70
+ /**
71
+ * Tags that classify the config, for policies to read: written out as
72
+ * string literals, as in `{data: "pci"}`. Keys and values are lowercase
73
+ * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
74
+ * letter, and not with `encore`, which is reserved. At most 32 tags.
75
+ */
76
+ tags?: Record<string, string>;
77
+ }
52
78
  /**
53
- * config declares a {@link Config} belonging to the service that declares it,
54
- * which holds its own value for it. Two services may each declare a config of
55
- * the same name. The declaration must live inside a service, as a module-level
56
- * `export const`, with the name a string literal.
57
- */
58
- export declare function config<T>(name: string): Config<T>;
59
- /**
60
- * sharedConfig declares a {@link Config} with one value for the whole app. A
61
- * service that reads it is recorded as using it. Unlike {@link config} it may
62
- * be declared outside a service.
79
+ * config declares a {@link Config}, by default belonging to the service that
80
+ * declares it (see {@link ConfigOptions.scope}). The declaration is a
81
+ * module-level `export const`, with the name a string literal.
82
+ *
83
+ * @example a config several services read
84
+ * export const flags = config<Flags>("flags", {scope: "shared"});
63
85
  */
64
- export declare function sharedConfig<T>(name: string): Config<T>;
86
+ export declare function config<T>(name: string, opts?: ConfigOptions): Config<T>;
65
87
  /**
66
- * globalConfig declares a {@link Config} with one value for the whole app,
67
- * available to every service without being recorded as used.
88
+ * Gives `cfg` the value `value` for the test `scope`, once the core has
89
+ * checked it against the config's schema: reading the config in the test
90
+ * returns it from then on. For `@encore.dev/sdk/testing`.
91
+ *
92
+ * @internal
68
93
  */
69
- export declare function globalConfig<T>(name: string): Config<T>;
94
+ export declare function setTestValue<T>(scope: Scope, cfg: Config<T>, value: T): void;
70
95
  /**
71
96
  * The value is at least `N`. A constraint on a `number` field of a config's
72
97
  * type, written as an intersection: `number & Min<1>`. Encore checks the
@@ -103,3 +128,4 @@ export type MinItems<N extends number> = {
103
128
  export type MaxItems<N extends number> = {
104
129
  readonly '~encore.max_items'?: N;
105
130
  };
131
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../config/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,KAAK,EAAC,MAAM,2BAA2B,CAAC;AAI5E,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,8BAA8B;IAC9B,IAAI,CAAC,CAAC;IAEN,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACpD;AAED,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAExC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,IAAI,EAAE,MAAM,EAIZ,IAAI,CAAC,EAAE,aAAa,GACnB,MAAM,CAAC,CAAC,CAAC,CAIX;AAKD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAgB5E;AAwED;;;;GAIG;AACH,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