@encore.dev/sdk 2.0.0-beta.7 → 2.0.0-beta.9

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 (424) hide show
  1. package/README.md +109 -0
  2. package/app_meta.test.ts +25 -5
  3. package/app_meta.ts +51 -12
  4. package/config/config.test.ts +18 -15
  5. package/config/config.ts +89 -31
  6. package/config/mod.ts +4 -3
  7. package/config/secrets.ts +79 -53
  8. package/config/value.ts +13 -17
  9. package/cron/mod.test.ts +52 -0
  10. package/cron/mod.ts +41 -2
  11. package/dist/app_meta.d.ts +44 -12
  12. package/dist/app_meta.d.ts.map +1 -0
  13. package/dist/app_meta.js +2 -0
  14. package/dist/app_meta.js.map +1 -1
  15. package/dist/config/config.d.ts +58 -28
  16. package/dist/config/config.d.ts.map +1 -0
  17. package/dist/config/config.js +46 -18
  18. package/dist/config/config.js.map +1 -1
  19. package/dist/config/mod.d.ts +5 -4
  20. package/dist/config/mod.d.ts.map +1 -0
  21. package/dist/config/mod.js +2 -2
  22. package/dist/config/mod.js.map +1 -1
  23. package/dist/config/secrets.d.ts +71 -39
  24. package/dist/config/secrets.d.ts.map +1 -0
  25. package/dist/config/secrets.js +31 -38
  26. package/dist/config/secrets.js.map +1 -1
  27. package/dist/config/value.d.ts +8 -5
  28. package/dist/config/value.d.ts.map +1 -0
  29. package/dist/config/value.js +10 -7
  30. package/dist/config/value.js.map +1 -1
  31. package/dist/cron/mod.d.ts +36 -1
  32. package/dist/cron/mod.d.ts.map +1 -0
  33. package/dist/cron/mod.js +31 -1
  34. package/dist/cron/mod.js.map +1 -1
  35. package/dist/frontends/mod.d.ts +39 -0
  36. package/dist/frontends/mod.d.ts.map +1 -0
  37. package/dist/frontends/mod.js +47 -0
  38. package/dist/frontends/mod.js.map +1 -0
  39. package/dist/gateway/errors.d.ts +101 -0
  40. package/dist/gateway/errors.d.ts.map +1 -0
  41. package/dist/gateway/errors.js +146 -0
  42. package/dist/gateway/errors.js.map +1 -0
  43. package/dist/gateway/match.d.ts +127 -0
  44. package/dist/gateway/match.d.ts.map +1 -0
  45. package/dist/gateway/match.js +206 -0
  46. package/dist/gateway/match.js.map +1 -0
  47. package/dist/gateway/middleware.d.ts +108 -0
  48. package/dist/gateway/middleware.d.ts.map +1 -0
  49. package/dist/gateway/middleware.js +9 -0
  50. package/dist/gateway/middleware.js.map +1 -0
  51. package/dist/gateway/mod.d.ts +130 -0
  52. package/dist/gateway/mod.d.ts.map +1 -0
  53. package/dist/gateway/mod.js +188 -0
  54. package/dist/gateway/mod.js.map +1 -0
  55. package/dist/gateway/request.d.ts +304 -0
  56. package/dist/gateway/request.d.ts.map +1 -0
  57. package/dist/gateway/request.js +403 -0
  58. package/dist/gateway/request.js.map +1 -0
  59. package/dist/gateway/serve.d.ts +114 -0
  60. package/dist/gateway/serve.d.ts.map +1 -0
  61. package/dist/gateway/serve.js +510 -0
  62. package/dist/gateway/serve.js.map +1 -0
  63. package/dist/gateways/mod.d.ts +42 -0
  64. package/dist/gateways/mod.d.ts.map +1 -0
  65. package/dist/gateways/mod.js +55 -0
  66. package/dist/gateways/mod.js.map +1 -0
  67. package/dist/internal/clients/call.d.ts +147 -0
  68. package/dist/internal/clients/call.d.ts.map +1 -0
  69. package/dist/internal/clients/call.js +274 -0
  70. package/dist/internal/clients/call.js.map +1 -0
  71. package/dist/internal/clients/grpc.d.ts +90 -0
  72. package/dist/internal/clients/grpc.d.ts.map +1 -0
  73. package/dist/internal/clients/grpc.js +355 -0
  74. package/dist/internal/clients/grpc.js.map +1 -0
  75. package/dist/internal/clients/mod.d.ts +81 -0
  76. package/dist/internal/clients/mod.d.ts.map +1 -0
  77. package/dist/internal/clients/mod.js +237 -0
  78. package/dist/internal/clients/mod.js.map +1 -0
  79. package/dist/internal/fetch.d.ts +58 -0
  80. package/dist/internal/fetch.d.ts.map +1 -0
  81. package/dist/internal/fetch.js +251 -0
  82. package/dist/internal/fetch.js.map +1 -0
  83. package/dist/internal/otel/backend.d.ts +2 -0
  84. package/dist/internal/otel/backend.d.ts.map +1 -0
  85. package/dist/internal/otel/context.d.ts +1 -0
  86. package/dist/internal/otel/context.d.ts.map +1 -0
  87. package/dist/internal/otel/context_manager.d.ts +1 -0
  88. package/dist/internal/otel/context_manager.d.ts.map +1 -0
  89. package/dist/internal/otel/encode.d.ts +2 -0
  90. package/dist/internal/otel/encode.d.ts.map +1 -0
  91. package/dist/internal/otel/http.d.ts +11 -0
  92. package/dist/internal/otel/http.d.ts.map +1 -0
  93. package/dist/internal/otel/http.js +64 -0
  94. package/dist/internal/otel/http.js.map +1 -0
  95. package/dist/internal/otel/index.d.ts +2 -2
  96. package/dist/internal/otel/index.d.ts.map +1 -0
  97. package/dist/internal/otel/index.js +1 -2
  98. package/dist/internal/otel/index.js.map +1 -1
  99. package/dist/internal/otel/meter.d.ts +1 -0
  100. package/dist/internal/otel/meter.d.ts.map +1 -0
  101. package/dist/internal/otel/propagator.d.ts +1 -0
  102. package/dist/internal/otel/propagator.d.ts.map +1 -0
  103. package/dist/internal/otel/provider.d.ts +4 -0
  104. package/dist/internal/otel/provider.d.ts.map +1 -0
  105. package/dist/internal/otel/provider.js +3 -0
  106. package/dist/internal/otel/provider.js.map +1 -1
  107. package/dist/internal/otel/span.d.ts +15 -1
  108. package/dist/internal/otel/span.d.ts.map +1 -0
  109. package/dist/internal/otel/span.js +30 -2
  110. package/dist/internal/otel/span.js.map +1 -1
  111. package/dist/internal/otel/tracer.d.ts +1 -0
  112. package/dist/internal/otel/tracer.d.ts.map +1 -0
  113. package/dist/internal/otel/tracer.js +11 -5
  114. package/dist/internal/otel/tracer.js.map +1 -1
  115. package/dist/internal/reqfields.d.ts +170 -0
  116. package/dist/internal/reqfields.d.ts.map +1 -0
  117. package/dist/internal/reqfields.js +349 -0
  118. package/dist/internal/reqfields.js.map +1 -0
  119. package/dist/internal/runtime/meter.d.ts +1 -0
  120. package/dist/internal/runtime/meter.d.ts.map +1 -0
  121. package/dist/internal/runtime/mod.d.ts +6 -0
  122. package/dist/internal/runtime/mod.d.ts.map +1 -0
  123. package/dist/internal/runtime/mod.js +32 -2
  124. package/dist/internal/runtime/mod.js.map +1 -1
  125. package/dist/internal/runtime/napi/napi.cjs +192 -16
  126. package/dist/internal/runtime/napi/napi.d.cts +573 -33
  127. package/dist/internal/runtime/shutdown.d.ts +5 -0
  128. package/dist/internal/runtime/shutdown.d.ts.map +1 -0
  129. package/dist/internal/runtime/shutdown.js +9 -1
  130. package/dist/internal/runtime/shutdown.js.map +1 -1
  131. package/dist/internal/testing/carry.d.ts +49 -0
  132. package/dist/internal/testing/carry.d.ts.map +1 -0
  133. package/dist/internal/testing/carry.js +77 -0
  134. package/dist/internal/testing/carry.js.map +1 -0
  135. package/dist/internal/testing/runner.d.ts +2 -0
  136. package/dist/internal/testing/runner.d.ts.map +1 -0
  137. package/dist/internal/testing/runner.js +10 -0
  138. package/dist/internal/testing/runner.js.map +1 -0
  139. package/dist/internal/testing/scope.d.ts +109 -0
  140. package/dist/internal/testing/scope.d.ts.map +1 -0
  141. package/dist/internal/testing/scope.js +335 -0
  142. package/dist/internal/testing/scope.js.map +1 -0
  143. package/dist/internal/testing/steps.d.ts +55 -0
  144. package/dist/internal/testing/steps.d.ts.map +1 -0
  145. package/dist/internal/testing/steps.js +295 -0
  146. package/dist/internal/testing/steps.js.map +1 -0
  147. package/dist/internal/testing/telemetry.d.ts +305 -0
  148. package/dist/internal/testing/telemetry.d.ts.map +1 -0
  149. package/dist/internal/testing/telemetry.js +188 -0
  150. package/dist/internal/testing/telemetry.js.map +1 -0
  151. package/dist/internal/utils/constraints.d.ts +1 -0
  152. package/dist/internal/utils/constraints.d.ts.map +1 -0
  153. package/dist/log/index.d.ts +1 -0
  154. package/dist/log/index.d.ts.map +1 -0
  155. package/dist/log/logger.d.ts +2 -0
  156. package/dist/log/logger.d.ts.map +1 -0
  157. package/dist/log/runtime.d.ts +2 -0
  158. package/dist/log/runtime.d.ts.map +1 -0
  159. package/dist/log/stderr.d.ts +1 -0
  160. package/dist/log/stderr.d.ts.map +1 -0
  161. package/dist/metrics/mod.d.ts +45 -118
  162. package/dist/metrics/mod.d.ts.map +1 -0
  163. package/dist/metrics/mod.js +44 -179
  164. package/dist/metrics/mod.js.map +1 -1
  165. package/dist/mod.d.ts +2 -3
  166. package/dist/mod.d.ts.map +1 -0
  167. package/dist/mod.js +0 -1
  168. package/dist/mod.js.map +1 -1
  169. package/dist/otel.d.ts +1 -0
  170. package/dist/otel.d.ts.map +1 -0
  171. package/dist/pubsub/encoding.d.ts +5 -0
  172. package/dist/pubsub/encoding.d.ts.map +1 -0
  173. package/dist/pubsub/encoding.js +10 -2
  174. package/dist/pubsub/encoding.js.map +1 -1
  175. package/dist/pubsub/mod.d.ts +5 -4
  176. package/dist/pubsub/mod.d.ts.map +1 -0
  177. package/dist/pubsub/mod.js +2 -2
  178. package/dist/pubsub/mod.js.map +1 -1
  179. package/dist/pubsub/refs.d.ts +8 -0
  180. package/dist/pubsub/refs.d.ts.map +1 -0
  181. package/dist/pubsub/refs.js.map +1 -1
  182. package/dist/pubsub/subscription.d.ts +110 -15
  183. package/dist/pubsub/subscription.d.ts.map +1 -0
  184. package/dist/pubsub/subscription.js +98 -16
  185. package/dist/pubsub/subscription.js.map +1 -1
  186. package/dist/pubsub/topic.d.ts +101 -31
  187. package/dist/pubsub/topic.d.ts.map +1 -0
  188. package/dist/pubsub/topic.js +168 -51
  189. package/dist/pubsub/topic.js.map +1 -1
  190. package/dist/reqctx/mod.d.ts +174 -0
  191. package/dist/reqctx/mod.d.ts.map +1 -0
  192. package/dist/reqctx/mod.js +144 -0
  193. package/dist/reqctx/mod.js.map +1 -0
  194. package/dist/services/index.d.ts +147 -5
  195. package/dist/services/index.d.ts.map +1 -0
  196. package/dist/services/index.js +157 -9
  197. package/dist/services/index.js.map +1 -1
  198. package/dist/shutdown/mod.d.ts +1 -0
  199. package/dist/shutdown/mod.d.ts.map +1 -0
  200. package/dist/storage/objects/bucket.d.ts +313 -7
  201. package/dist/storage/objects/bucket.d.ts.map +1 -0
  202. package/dist/storage/objects/bucket.js +306 -15
  203. package/dist/storage/objects/bucket.js.map +1 -1
  204. package/dist/storage/objects/error.d.ts +10 -0
  205. package/dist/storage/objects/error.d.ts.map +1 -0
  206. package/dist/storage/objects/error.js +25 -1
  207. package/dist/storage/objects/error.js.map +1 -1
  208. package/dist/storage/objects/mod.d.ts +4 -3
  209. package/dist/storage/objects/mod.d.ts.map +1 -0
  210. package/dist/storage/objects/mod.js +1 -1
  211. package/dist/storage/objects/mod.js.map +1 -1
  212. package/dist/storage/objects/refs.d.ts +20 -4
  213. package/dist/storage/objects/refs.d.ts.map +1 -0
  214. package/dist/storage/objects/refs.js +6 -0
  215. package/dist/storage/objects/refs.js.map +1 -1
  216. package/dist/storage/postgres/database.d.ts +85 -25
  217. package/dist/storage/postgres/database.d.ts.map +1 -0
  218. package/dist/storage/postgres/database.js +129 -37
  219. package/dist/storage/postgres/database.js.map +1 -1
  220. package/dist/storage/postgres/errors.d.ts +120 -0
  221. package/dist/storage/postgres/errors.d.ts.map +1 -0
  222. package/dist/storage/postgres/errors.js +162 -0
  223. package/dist/storage/postgres/errors.js.map +1 -0
  224. package/dist/storage/postgres/interval.d.ts +44 -0
  225. package/dist/storage/postgres/interval.d.ts.map +1 -0
  226. package/dist/storage/postgres/interval.js +153 -0
  227. package/dist/storage/postgres/interval.js.map +1 -0
  228. package/dist/storage/postgres/mod.d.ts +4 -1
  229. package/dist/storage/postgres/mod.d.ts.map +1 -0
  230. package/dist/storage/postgres/mod.js +2 -0
  231. package/dist/storage/postgres/mod.js.map +1 -1
  232. package/dist/storage/redis/bitfield.d.ts +67 -0
  233. package/dist/storage/redis/bitfield.d.ts.map +1 -0
  234. package/dist/storage/redis/bitfield.js +114 -0
  235. package/dist/storage/redis/bitfield.js.map +1 -0
  236. package/dist/storage/redis/command.d.ts +45 -0
  237. package/dist/storage/redis/command.d.ts.map +1 -0
  238. package/dist/storage/redis/command.js +78 -0
  239. package/dist/storage/redis/command.js.map +1 -0
  240. package/dist/storage/redis/commands.d.ts +223 -139
  241. package/dist/storage/redis/commands.d.ts.map +1 -0
  242. package/dist/storage/redis/commands.js +128 -6
  243. package/dist/storage/redis/commands.js.map +1 -1
  244. package/dist/storage/redis/database.d.ts +56 -22
  245. package/dist/storage/redis/database.d.ts.map +1 -0
  246. package/dist/storage/redis/database.js +62 -0
  247. package/dist/storage/redis/database.js.map +1 -1
  248. package/dist/storage/redis/mod.d.ts +31 -4
  249. package/dist/storage/redis/mod.d.ts.map +1 -0
  250. package/dist/storage/redis/mod.js +26 -1
  251. package/dist/storage/redis/mod.js.map +1 -1
  252. package/dist/storage/redis/native.d.ts +8 -0
  253. package/dist/storage/redis/native.d.ts.map +1 -0
  254. package/dist/storage/redis/native.js +10 -0
  255. package/dist/storage/redis/native.js.map +1 -1
  256. package/dist/storage/redis/options.d.ts +1 -0
  257. package/dist/storage/redis/options.d.ts.map +1 -0
  258. package/dist/storage/redis/pubsub.d.ts +2 -0
  259. package/dist/storage/redis/pubsub.d.ts.map +1 -0
  260. package/dist/storage/redis/reply.d.ts +34 -0
  261. package/dist/storage/redis/reply.d.ts.map +1 -0
  262. package/dist/storage/redis/reply.js +40 -1
  263. package/dist/storage/redis/reply.js.map +1 -1
  264. package/dist/storage/redis/scan.d.ts +1 -0
  265. package/dist/storage/redis/scan.d.ts.map +1 -0
  266. package/dist/storage/redis/script.d.ts +1 -0
  267. package/dist/storage/redis/script.d.ts.map +1 -0
  268. package/dist/storage/redis/target.d.ts +5 -3
  269. package/dist/storage/redis/target.d.ts.map +1 -0
  270. package/dist/storage/redis/target.js +39 -28
  271. package/dist/storage/redis/target.js.map +1 -1
  272. package/dist/storage/redis/wire.d.ts +7 -10
  273. package/dist/storage/redis/wire.d.ts.map +1 -0
  274. package/dist/storage/redis/wire.js +8 -32
  275. package/dist/storage/redis/wire.js.map +1 -1
  276. package/dist/testing/bun.d.ts +8 -0
  277. package/dist/testing/bun.d.ts.map +1 -0
  278. package/dist/testing/bun.js +13 -0
  279. package/dist/testing/bun.js.map +1 -0
  280. package/dist/testing/jest.d.ts +8 -0
  281. package/dist/testing/jest.d.ts.map +1 -0
  282. package/dist/testing/jest.js +11 -0
  283. package/dist/testing/jest.js.map +1 -0
  284. package/dist/testing/mod.d.ts +183 -0
  285. package/dist/testing/mod.d.ts.map +1 -0
  286. package/dist/testing/mod.js +271 -0
  287. package/dist/testing/mod.js.map +1 -0
  288. package/dist/testing/node.d.ts +9 -0
  289. package/dist/testing/node.d.ts.map +1 -0
  290. package/dist/testing/node.js +12 -0
  291. package/dist/testing/node.js.map +1 -0
  292. package/dist/testing/playwright.d.ts +93 -0
  293. package/dist/testing/playwright.d.ts.map +1 -0
  294. package/dist/testing/playwright.js +164 -0
  295. package/dist/testing/playwright.js.map +1 -0
  296. package/dist/testing/puppeteer.d.ts +36 -0
  297. package/dist/testing/puppeteer.d.ts.map +1 -0
  298. package/dist/testing/puppeteer.js +70 -0
  299. package/dist/testing/puppeteer.js.map +1 -0
  300. package/dist/testing/system.d.ts +181 -0
  301. package/dist/testing/system.d.ts.map +1 -0
  302. package/dist/testing/system.js +255 -0
  303. package/dist/testing/system.js.map +1 -0
  304. package/dist/testing/vitest.d.ts +8 -0
  305. package/dist/testing/vitest.d.ts.map +1 -0
  306. package/dist/testing/vitest.js +13 -0
  307. package/dist/testing/vitest.js.map +1 -0
  308. package/dist/tracing/http.d.ts +11 -0
  309. package/dist/tracing/http.d.ts.map +1 -0
  310. package/dist/tracing/http.js +34 -0
  311. package/dist/tracing/http.js.map +1 -0
  312. package/dist/tracing/mod.d.ts +20 -0
  313. package/dist/tracing/mod.d.ts.map +1 -0
  314. package/dist/tracing/mod.js +47 -0
  315. package/dist/tracing/mod.js.map +1 -0
  316. package/dist/tracing/node.d.ts +10 -0
  317. package/dist/tracing/node.d.ts.map +1 -0
  318. package/dist/tracing/node.js +142 -0
  319. package/dist/tracing/node.js.map +1 -0
  320. package/dist/tsconfig.build.tsbuildinfo +1 -1
  321. package/dist/types/mod.d.ts +1 -0
  322. package/dist/types/mod.d.ts.map +1 -0
  323. package/frontends/mod.test.ts +51 -0
  324. package/frontends/mod.ts +50 -0
  325. package/gateway/errors.ts +172 -0
  326. package/gateway/gateway.e2e.test.ts +297 -0
  327. package/gateway/gateway.test.ts +891 -0
  328. package/gateway/match.ts +239 -0
  329. package/gateway/middleware.ts +134 -0
  330. package/gateway/mod.ts +211 -0
  331. package/gateway/request.ts +578 -0
  332. package/gateway/serve.ts +738 -0
  333. package/gateways/mod.ts +60 -0
  334. package/internal/clients/call.ts +389 -0
  335. package/internal/clients/grpc.test.ts +368 -0
  336. package/internal/clients/grpc.ts +485 -0
  337. package/internal/clients/mod.test.ts +464 -0
  338. package/internal/clients/mod.ts +337 -0
  339. package/internal/fetch.ts +287 -0
  340. package/internal/otel/http.ts +91 -0
  341. package/internal/otel/index.ts +1 -7
  342. package/internal/otel/provider.ts +3 -0
  343. package/internal/otel/span.ts +31 -2
  344. package/internal/otel/tracer.test.ts +43 -15
  345. package/internal/otel/tracer.ts +12 -5
  346. package/internal/reqfields.ts +423 -0
  347. package/internal/runtime/mod.ts +41 -2
  348. package/internal/runtime/napi/napi.cjs +192 -16
  349. package/internal/runtime/napi/napi.d.cts +573 -33
  350. package/internal/runtime/shutdown.ts +11 -1
  351. package/internal/testing/carry.test.ts +242 -0
  352. package/internal/testing/carry.ts +101 -0
  353. package/internal/testing/runner.ts +10 -0
  354. package/internal/testing/scope.ts +372 -0
  355. package/internal/testing/steps.test.ts +152 -0
  356. package/internal/testing/steps.ts +342 -0
  357. package/internal/testing/telemetry.test.ts +210 -0
  358. package/internal/testing/telemetry.ts +466 -0
  359. package/metrics/mod.test.ts +13 -16
  360. package/metrics/mod.ts +57 -226
  361. package/mod.ts +1 -8
  362. package/otel.test.ts +13 -6
  363. package/package.json +92 -15
  364. package/pubsub/encoding.ts +11 -1
  365. package/pubsub/mod.ts +16 -4
  366. package/pubsub/pubsub.test.ts +233 -14
  367. package/pubsub/refs.ts +16 -0
  368. package/pubsub/subscription.ts +200 -21
  369. package/pubsub/topic.test.ts +26 -0
  370. package/pubsub/topic.ts +255 -36
  371. package/reqctx/mod.ts +267 -0
  372. package/reqctx/reqctx.test.ts +216 -0
  373. package/scripts/postprocess-docs.test.ts +58 -0
  374. package/services/index.test.ts +341 -1
  375. package/services/index.ts +185 -9
  376. package/storage/objects/bucket.test.ts +573 -0
  377. package/storage/objects/bucket.ts +650 -20
  378. package/storage/objects/error.ts +28 -1
  379. package/storage/objects/mod.ts +15 -0
  380. package/storage/objects/refs.ts +51 -3
  381. package/storage/postgres/database.integration.test.ts +275 -0
  382. package/storage/postgres/database.test.ts +193 -6
  383. package/storage/postgres/database.ts +206 -55
  384. package/storage/postgres/errors.ts +186 -0
  385. package/storage/postgres/interval.test.ts +72 -0
  386. package/storage/postgres/interval.ts +170 -0
  387. package/storage/postgres/mod.ts +4 -0
  388. package/storage/redis/bitfield.ts +162 -0
  389. package/storage/redis/command.ts +84 -0
  390. package/storage/redis/commands.ts +271 -21
  391. package/storage/redis/database.ts +77 -23
  392. package/storage/redis/mod.ts +38 -2
  393. package/storage/redis/native.ts +11 -0
  394. package/storage/redis/redis.test.ts +170 -10
  395. package/storage/redis/reply.ts +76 -1
  396. package/storage/redis/runtime.test.ts +15 -0
  397. package/storage/redis/target.ts +47 -44
  398. package/storage/redis/wire.ts +8 -32
  399. package/testing/bun.ts +13 -0
  400. package/testing/jest.ts +11 -0
  401. package/testing/mod.ts +393 -0
  402. package/testing/node.ts +12 -0
  403. package/testing/playwright.ts +247 -0
  404. package/testing/puppeteer.ts +101 -0
  405. package/testing/system.test.ts +108 -0
  406. package/testing/system.ts +373 -0
  407. package/testing/vitest.ts +13 -0
  408. package/tracing/http.ts +49 -0
  409. package/tracing/mod.ts +83 -0
  410. package/tracing/native.test.ts +267 -0
  411. package/tracing/node.ts +176 -0
  412. package/tracing/tracing.test.ts +953 -0
  413. package/dist/internal/otel/request_context.d.ts +0 -11
  414. package/dist/internal/otel/request_context.js +0 -20
  415. package/dist/internal/otel/request_context.js.map +0 -1
  416. package/dist/internal/reqtrack/mod.d.ts +0 -6
  417. package/dist/internal/reqtrack/mod.js +0 -28
  418. package/dist/internal/reqtrack/mod.js.map +0 -1
  419. package/dist/req_meta.d.ts +0 -47
  420. package/dist/req_meta.js +0 -26
  421. package/dist/req_meta.js.map +0 -1
  422. package/internal/otel/request_context.ts +0 -32
  423. package/internal/reqtrack/mod.ts +0 -39
  424. package/req_meta.ts +0 -75
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,80 @@ 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
103
  * @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.
104
+ * ```ts
105
+ * // Loading a single secret.
106
+ * import {secret} from "@encore.dev/sdk/config";
107
+ * const foo = secret("foo");
108
+ * ```
95
109
  *
96
110
  * @example
97
- * import {globalSecret} from "@encore.dev/sdk/config";
98
- * const telemetryKey = globalSecret("TelemetryKey");
111
+ * ```ts
112
+ * // A secret several services share.
113
+ * import {secret} from "@encore.dev/sdk/config";
114
+ * const signingKey = secret("SigningKey", {scope: "shared"});
115
+ * ```
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * // Documenting it.
120
+ * const apiKey = secret("ApiKey", {
121
+ * description: "Issued by Acme Pay. Rotate it in their portal under Settings → API.",
122
+ * });
123
+ * ```
99
124
  */
100
- export function globalSecret<Name extends string>(
125
+ export function secret<Name extends string>(
101
126
  name: StringLiteral<Name>,
127
+ // The options are Encore's parser's to read: a secret is read by name
128
+ // whatever its scope, a name having one scope across the app.
129
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
130
+ opts?: SecretOptions,
102
131
  ): Secret<Name> {
103
132
  return makeSecret<Secret<Name>>(name, runtime.RT.secret(name));
104
133
  }
@@ -123,13 +152,10 @@ function makeSecret<S extends AnySecret>(
123
152
  impl: ReturnType<typeof runtime.RT.secret>,
124
153
  ): S {
125
154
  const secretObj = () => {
155
+ // The value the current test gave it, if it did.
156
+ const override = testMode ? lookupScope()?.native.secret(name) : null;
157
+ if (override != null) return override.toString('utf8');
126
158
  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
159
  throw new Error(`secret ${name} is not set`);
134
160
  }
135
161
  return impl.cached();
package/config/value.ts CHANGED
@@ -103,14 +103,15 @@ export class Duration {
103
103
  }
104
104
  }
105
105
 
106
- /** The key of the runtime's placeholder for a secret field. */
106
+ /**
107
+ * The key of the runtime's placeholder for a secret field:
108
+ * `{"$encore_secret": "<name>"}`. The name alone says which secret it is: a
109
+ * secret's name has one scope across the app.
110
+ */
107
111
  export const PLACEHOLDER_KEY = '$encore_secret';
108
112
 
109
- /** A secret's scope, as a placeholder names it. */
110
- export type SecretScope = 'service' | 'shared' | 'global';
111
-
112
- /** Builds the secret a placeholder stands for. */
113
- export type SecretOf = (name: string, scope: SecretScope) => unknown;
113
+ /** Builds the secret a placeholder stands for, by its name. */
114
+ export type SecretOf = (name: string) => unknown;
114
115
 
115
116
  type Schema = Record<string, any>;
116
117
 
@@ -154,19 +155,16 @@ function convert(
154
155
 
155
156
  // Only a field the schema says reads a secret is one: anywhere else, a
156
157
  // value shaped like a placeholder is just data, and must not reach a secret.
158
+ // The keyword is the secret's name: its scope is the config's.
157
159
  const secret = schema['x-encore-secret'];
158
- if (secret) {
159
- if (
160
- !isPlaceholder(value) ||
161
- value[PLACEHOLDER_KEY].name !== secret.name ||
162
- value[PLACEHOLDER_KEY].scope !== secret.scope
163
- ) {
160
+ if (typeof secret === 'string') {
161
+ if (!isPlaceholder(value) || value[PLACEHOLDER_KEY] !== secret) {
164
162
  // Never say what the value is: it may be a pasted secret.
165
163
  throw new Error(
166
- `a secret field reads the secret ${secret.name}, and is not set in config`,
164
+ `a secret field reads the secret ${secret}, and is not set in config`,
167
165
  );
168
166
  }
169
- return secretOf(secret.name, secret.scope);
167
+ return secretOf(secret);
170
168
  }
171
169
 
172
170
  if (schema['x-encore-format'] === 'duration' && typeof value === 'string') {
@@ -233,9 +231,7 @@ function branchOf(
233
231
  return undefined;
234
232
  }
235
233
 
236
- function isPlaceholder(
237
- value: unknown,
238
- ): value is {[PLACEHOLDER_KEY]: {name: string; scope: SecretScope}} {
234
+ function isPlaceholder(value: unknown): value is {[PLACEHOLDER_KEY]: string} {
239
235
  if (value === null || typeof value !== 'object' || Array.isArray(value))
240
236
  return false;
241
237
  const keys = Object.keys(value);
@@ -0,0 +1,52 @@
1
+ import {describe, expect, test} from 'bun:test';
2
+
3
+ import {CronJob} from './mod';
4
+
5
+ describe('CronJob', () => {
6
+ test('reads as it was declared', () => {
7
+ const job = new CronJob('cleanup', {
8
+ title: 'Nightly cleanup',
9
+ every: '24h',
10
+ path: '/internal/cleanup',
11
+ });
12
+ expect(job.name).toBe('cleanup');
13
+ expect(job.cfg).toEqual({
14
+ title: 'Nightly cleanup',
15
+ every: '24h',
16
+ path: '/internal/cleanup',
17
+ });
18
+ });
19
+
20
+ // Encore requests the declared path: a route from a changed one would
21
+ // never be called. `tsc` refuses the writes (below); an app run without it
22
+ // has them throw.
23
+ test('cannot be changed', () => {
24
+ const cfg = {every: '24h' as const, path: '/internal/cleanup'};
25
+ const job = new CronJob('cleanup', cfg);
26
+ const writable = job as unknown as {name: string; cfg: {path: string}};
27
+ expect(() => {
28
+ writable.cfg.path = '/other';
29
+ }).toThrow(TypeError);
30
+ expect(() => {
31
+ writable.cfg = {path: '/other'};
32
+ }).toThrow(TypeError);
33
+ expect(() => {
34
+ writable.name = 'other';
35
+ }).toThrow(TypeError);
36
+ expect(job.cfg.path).toBe('/internal/cleanup');
37
+ // The declaration's own object is the app's, and is left as it was.
38
+ expect(Object.isFrozen(cfg)).toBe(false);
39
+ });
40
+ });
41
+
42
+ // Compile-only: `tsc` checks that a job's config can be read but not changed.
43
+ // Never called.
44
+ function _cfgTyping(job: CronJob) {
45
+ const path: string = job.cfg.path;
46
+ void path;
47
+ // @ts-expect-error Encore requests the declared path, not a changed one
48
+ job.cfg.path = '/other';
49
+ // @ts-expect-error the title is read from the source, too
50
+ job.cfg.title = 'Other';
51
+ }
52
+ void _cfgTyping;
package/cron/mod.ts CHANGED
@@ -1,11 +1,43 @@
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
- readonly cfg: CronJobConfig;
30
+ /**
31
+ * What the job was declared with. Read-only: Encore schedules the job from
32
+ * the declaration in the source, so a changed path would not be requested.
33
+ */
34
+ readonly cfg: Readonly<CronJobConfig>;
6
35
  constructor(name: string, cfg: CronJobConfig) {
7
36
  this.name = name;
8
- this.cfg = cfg;
37
+ // Frozen as well as typed `readonly`, so a write throws in an app that
38
+ // runs without `tsc` checking it.
39
+ this.cfg = Object.freeze({...cfg});
40
+ Object.freeze(this);
9
41
  }
10
42
  }
11
43
 
@@ -20,4 +52,11 @@ export type CronJobConfig = {
20
52
  /** The path the job requests of its service, starting with `/`. */
21
53
  path: string;
22
54
  title?: string;
55
+ /**
56
+ * Tags that classify the cron job, for policies to read: written out as
57
+ * string literals, as in `{data: "pci"}`. Keys and values are lowercase
58
+ * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
59
+ * letter, and not with `encore`, which is reserved. At most 32 tags.
60
+ */
61
+ tags?: Record<string, string>;
23
62
  } & ({every: DurationString} | {schedule: string});
@@ -15,14 +15,23 @@ export interface AppMeta {
15
15
  */
16
16
  appSlug: string;
17
17
  /**
18
- * The API gateways that serve this application, keyed by gateway name.
18
+ * The API gateways of this application this service is given, keyed by
19
+ * gateway name: those its code looks up the URL of, and the one it hosts.
19
20
  *
20
21
  * An application can declare several gateways, so there is no single base URL for
21
- * the API — look up the gateway you mean by name. Every process lists them,
22
- * whether it serves one or not; one told of none, as under `encore test`,
23
- * reports an empty object.
22
+ * the API — look up the gateway you mean by name. A service's processes, its
23
+ * Workers' included, list the gateways its code names (`url("api")` from
24
+ * `@encore.dev/sdk/gateways`) and the one it hosts, and no other, the default
25
+ * included; one told of none, as under `encore test`, reports an empty object.
24
26
  */
25
27
  gateways: Record<string, GatewayMeta>;
28
+ /**
29
+ * The frontends of this application this service is given — those its code
30
+ * looks up the URL of (`url("web")` from `@encore.dev/sdk/frontends`), and
31
+ * the one it hosts — keyed by name, with where each is reached. One the
32
+ * environment gives no origins is left out.
33
+ */
34
+ frontends: Record<string, FrontendMeta>;
26
35
  /** Information about the environment the app is running in. */
27
36
  environment: EnvironmentMeta;
28
37
  /** Information about the build. */
@@ -35,15 +44,31 @@ export interface GatewayMeta {
35
44
  /** The name of the gateway, as declared by the application. */
36
45
  name: string;
37
46
  /**
38
- * The base URL which can be used to call the API of this running application
39
- * through this gateway.
40
- *
41
- * For local development it is "http://localhost:<port>", typically "http://localhost:4000".
42
- *
43
- * If a custom domain is used for this environment it is returned here, but note that
44
- * changes only take effect at the time of deployment while custom domains can be updated at any time.
47
+ * The URL the API of this running application is called at through this
48
+ * gateway: the first of its origins. Empty when the environment gives the
49
+ * gateway no origins.
50
+ */
51
+ url: string;
52
+ /**
53
+ * Every origin the gateway is reached at in this environment
54
+ * (`scheme://host[:port]`), the first its URL. After the first, an entry may
55
+ * be a pattern of one, `https://*.example.com`, or `*`, which makes the
56
+ * gateway the one serving requests no other origin matches.
45
57
  */
46
- baseUrl: string;
58
+ origins: string[];
59
+ }
60
+ /** Describes a frontend of the application, and where it is reached. */
61
+ export interface FrontendMeta {
62
+ /** The name of the frontend: for one a service hosts, the service's. */
63
+ name: string;
64
+ /** The URL the frontend is reached at: the first of its origins. */
65
+ url: string;
66
+ /**
67
+ * Every origin the frontend is reached at in this environment, the first its
68
+ * URL; after the first, an entry may be a pattern of one,
69
+ * `https://*.example.com`.
70
+ */
71
+ origins: string[];
47
72
  }
48
73
  /** Describes the environment the Encore application is running in. */
49
74
  export interface EnvironmentMeta {
@@ -80,6 +105,12 @@ export interface DeployMeta {
80
105
  time: Date;
81
106
  /** The services hosted by this deployment, keyed by the service name. */
82
107
  hostedServices: Record<string, HostedService>;
108
+ /**
109
+ * The Worker of its service this process runs: a long-running process of
110
+ * the service that serves no requests, declared in the `workers` section of
111
+ * its `encore.service.json`. Undefined for the service's main process.
112
+ */
113
+ worker?: string;
83
114
  }
84
115
  export interface HostedService {
85
116
  /** The name of the service */
@@ -92,3 +123,4 @@ export interface HostedService {
92
123
  * and therefore must not be modified by the caller.
93
124
  */
94
125
  export declare function appMeta(): AppMeta;
126
+ //# sourceMappingURL=app_meta.d.ts.map
@@ -0,0 +1 @@
1
+ {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,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,CA2BjC"}
package/dist/app_meta.js CHANGED
@@ -13,6 +13,7 @@ export function appMeta() {
13
13
  appId: rt.appId,
14
14
  appSlug: rt.appSlug,
15
15
  gateways: rt.gateways,
16
+ frontends: rt.frontends,
16
17
  environment: {
17
18
  name: rt.environment.name,
18
19
  type: envType(rt.environment.type),
@@ -25,6 +26,7 @@ export function appMeta() {
25
26
  id: rt.deploy.id,
26
27
  time: new Date(rt.deploy.deployTime),
27
28
  hostedServices: rt.deploy.hostedServices,
29
+ worker: rt.deploy.worker ?? undefined,
28
30
  },
29
31
  };
30
32
  }
@@ -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,EA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,CAAC;AAED,SAAS,OAAO,CAAC,MAA+B;IAC9C,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO,CAAC,eAAe,CAAC,UAAU;YACrC,OAAO,YAAY,CAAC;QACtB,KAAK,OAAO,CAAC,eAAe,CAAC,WAAW;YACtC,OAAO,aAAa,CAAC;QACvB,KAAK,OAAO,CAAC,eAAe,CAAC,SAAS;YACpC,OAAO,WAAW,CAAC;QACrB,KAAK,OAAO,CAAC,eAAe,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,26 +1,27 @@
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
- * @example
12
- * import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
11
+ * ```ts
12
+ * import { config, type Min, type Max, type Duration } from "@encore.dev/sdk/config";
13
13
  *
14
- * interface Checkout {
15
- * // Most items one order may hold.
16
- * maxItems: number & Int & Min<1> & Max<500>;
17
- * currencies?: string[];
18
- * paymentTimeout: Duration;
19
- * }
14
+ * interface Checkout {
15
+ * // Most items one order may hold.
16
+ * maxItems: number & Int & Min<1> & Max<500>;
17
+ * currencies?: string[];
18
+ * paymentTimeout: Duration;
19
+ * }
20
20
  *
21
- * export const checkout = config<Checkout>("checkout");
21
+ * export const checkout = config<Checkout>("checkout");
22
22
  *
23
- * if (items.length > checkout().maxItems) { ... }
23
+ * if (items.length > checkout().maxItems) { ... }
24
+ * ```
24
25
  *
25
26
  * # Values
26
27
  *
@@ -49,24 +50,52 @@ export interface Config<T> {
49
50
  */
50
51
  onChange(listener: (value: T) => void): () => void;
51
52
  }
53
+ /** The options a config is declared with. */
54
+ export interface ConfigOptions {
55
+ /**
56
+ * Who the config belongs to, written as a string literal for Encore to
57
+ * read:
58
+ *
59
+ * - `"service"`, the default: the service that declares it, which holds
60
+ * its own value for it. Two services may each declare a config of the
61
+ * same name. The declaration must live inside a service.
62
+ * - `"shared"`: the whole app, with one value. A service that reads it is
63
+ * recorded as using it. It may be declared outside a service.
64
+ * - `"global"`: the whole app, with one value available to every service
65
+ * without being recorded as used. It may be declared outside a service.
66
+ *
67
+ * A config name has one scope across the app, as a secret's has: a name
68
+ * declared shared or global can't also be a service's own.
69
+ */
70
+ scope?: 'service' | 'shared' | 'global';
71
+ /**
72
+ * Tags that classify the config, for policies to read: written out as
73
+ * string literals, as in `{data: "pci"}`. Keys and values are lowercase
74
+ * letters, digits, `_` and `-`, at most 63 characters; a key starts with a
75
+ * letter, and not with `encore`, which is reserved. At most 32 tags.
76
+ */
77
+ tags?: Record<string, string>;
78
+ }
52
79
  /**
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.
80
+ * config declares a {@link Config}, by default belonging to the service that
81
+ * declares it (see {@link ConfigOptions.scope}). The declaration is a
82
+ * module-level `export const`, with the name a string literal.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * // A config several services read.
87
+ * export const flags = config<Flags>("flags", {scope: "shared"});
88
+ * ```
63
89
  */
64
- export declare function sharedConfig<T>(name: string): Config<T>;
90
+ export declare function config<T>(name: string, opts?: ConfigOptions): Config<T>;
65
91
  /**
66
- * globalConfig declares a {@link Config} with one value for the whole app,
67
- * available to every service without being recorded as used.
92
+ * Gives `cfg` the value `value` for the test `scope`, once the core has
93
+ * checked it against the config's schema: reading the config in the test
94
+ * returns it from then on. For `@encore.dev/sdk/testing`.
95
+ *
96
+ * @internal
68
97
  */
69
- export declare function globalConfig<T>(name: string): Config<T>;
98
+ export declare function setTestValue<T>(scope: Scope, cfg: Config<T>, value: T): void;
70
99
  /**
71
100
  * The value is at least `N`. A constraint on a `number` field of a config's
72
101
  * type, written as an intersection: `number & Min<1>`. Encore checks the
@@ -103,3 +132,4 @@ export type MinItems<N extends number> = {
103
132
  export type MaxItems<N extends number> = {
104
133
  readonly '~encore.max_items'?: N;
105
134
  };
135
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,M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