@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
@@ -0,0 +1,101 @@
1
+ /**
2
+ * A system test's browser, driven with Puppeteer.
3
+ *
4
+ * {@link connect} connects Puppeteer to the browser Encore runs for the
5
+ * current test (see `system.browser` in `@encore.dev/sdk/testing`): a page
6
+ * reaches the app where `encore run` has it, in the test session; its
7
+ * requests are the test's; and what it shows is recorded.
8
+ *
9
+ * Each call the test makes on a page is reported as it is written, with
10
+ * where it is, so that the recording and the test's telemetry say which
11
+ * statement had the browser do what, and which requests came of it:
12
+ *
13
+ * page.locator("#pay").click() checkout.test.ts:14
14
+ * click button "Pay"
15
+ * POST http://localhost:4000/orders 500
16
+ * POST orders /orders 500
17
+ *
18
+ * Puppeteer is the test's own, passed in: `puppeteer` or `puppeteer-core`.
19
+ * Neither downloads a browser for this, as Encore runs its own.
20
+ *
21
+ * @example
22
+ * import puppeteer from "puppeteer-core";
23
+ * import {system} from "@encore.dev/sdk/testing";
24
+ * import {connect, url} from "@encore.dev/sdk/testing/puppeteer";
25
+ *
26
+ * test("pays from the browser", async () => {
27
+ * const browser = await connect(puppeteer);
28
+ * const page = await browser.newPage();
29
+ * await page.goto(await url("web"));
30
+ * await page.locator("button#pay").click();
31
+ * await page.waitForSelector("#thanks");
32
+ * await system.settled();
33
+ * });
34
+ *
35
+ * @module
36
+ */
37
+ import {Steps, wrap} from '../internal/testing/steps';
38
+ import {browser as testBrowser, type BrowserOptions} from './system';
39
+
40
+ /** Puppeteer, as much of it as {@link connect} uses. */
41
+ export interface Puppeteer<B> {
42
+ connect(options: {
43
+ browserWSEndpoint: string;
44
+ defaultViewport?: {width: number; height: number} | null;
45
+ [option: string]: unknown;
46
+ }): Promise<B>;
47
+ }
48
+
49
+ /** The options of {@link connect}. */
50
+ export interface ConnectOptions extends BrowserOptions {
51
+ /**
52
+ * More of Puppeteer's own options for `connect`, such as `slowMo` and
53
+ * `protocolTimeout`.
54
+ */
55
+ connect?: Record<string, unknown>;
56
+ }
57
+
58
+ /** What {@link connect} uses of a Puppeteer browser. */
59
+ interface Connected {
60
+ target(): {
61
+ createCDPSession(): Promise<{
62
+ send(method: string, params?: Record<string, unknown>): Promise<unknown>;
63
+ }>;
64
+ };
65
+ }
66
+
67
+ /**
68
+ * Connects `puppeteer` to the current test's browser, starting it if the
69
+ * test has none yet, and returns Puppeteer's `Browser`. The browser ends
70
+ * with the test: there is nothing to close.
71
+ *
72
+ * Its pages' viewport is the browser's window (`options.window`), unless
73
+ * `options.connect.defaultViewport` says otherwise.
74
+ */
75
+ export async function connect<B>(
76
+ puppeteer: Puppeteer<B>,
77
+ options?: ConnectOptions,
78
+ ): Promise<B> {
79
+ const info = await testBrowser(options);
80
+ const browser = await puppeteer.connect({
81
+ defaultViewport: options?.window ?? {width: 1280, height: 800},
82
+ ...options?.connect,
83
+ browserWSEndpoint: info.wsEndpoint,
84
+ });
85
+ // The commands that say which statement is running go over the
86
+ // connection Puppeteer's own do, so they arrive in order with them.
87
+ const session = await (browser as unknown as Connected)
88
+ .target()
89
+ .createCDPSession();
90
+ const steps = new Steps((method, params) => session.send(method, params));
91
+ return wrap(browser as object, 'browser', steps) as B;
92
+ }
93
+
94
+ /**
95
+ * The URL a page of the current test's browser reaches the gateway or
96
+ * frontend `name` at: the one `encore run` has it at, which the frontend is
97
+ * written against.
98
+ */
99
+ export async function url(name: string): Promise<string> {
100
+ return (await testBrowser()).url(name);
101
+ }
@@ -0,0 +1,108 @@
1
+ import {describe, expect, test} from 'bun:test';
2
+
3
+ /**
4
+ * What the `system` helpers say in a process that is no system test's. The
5
+ * native runtime reads its config from the environment when it is first
6
+ * imported, so this runs in a child process, as `app_meta.test.ts` does: a
7
+ * service's, which runs no tests at all.
8
+ */
9
+ const outcomes = (() => {
10
+ const probe = `
11
+ import { deliver, published, system } from ${JSON.stringify(`${import.meta.dir}/mod`)};
12
+ const said = (fn) => {
13
+ try {
14
+ return Promise.resolve(fn()).then(() => "returned", (e) => String(e.message ?? e));
15
+ } catch (e) {
16
+ return String(e.message ?? e);
17
+ }
18
+ };
19
+ console.log(JSON.stringify({
20
+ settled: await said(() => system.settled()),
21
+ url: await said(() => system.url("api")),
22
+ headers: await said(() => system.headers()),
23
+ telemetry: await said(() => system.telemetry({ settle: false })),
24
+ // Its other helpers are a service test's, as before.
25
+ published: await said(() => published({ name: "events" })),
26
+ deliver: await said(() => deliver({})),
27
+ }));
28
+ `;
29
+ const proc = Bun.spawnSync({
30
+ cmd: [process.execPath, '-e', probe],
31
+ cwd: import.meta.dir,
32
+ env: {...process.env, ENCORE_RUNTIME_CONFIG: runtimeConfig()},
33
+ });
34
+ const stdout = proc.stdout.toString();
35
+ if (proc.exitCode !== 0) {
36
+ throw new Error(
37
+ `system probe failed (exit ${proc.exitCode}):\n${stdout}\n${proc.stderr.toString()}`,
38
+ );
39
+ }
40
+ // The core logs to stdout as it initializes; the probe's JSON is the last line.
41
+ const lines = stdout.trim().split('\n');
42
+ return JSON.parse(lines[lines.length - 1]!);
43
+ })();
44
+
45
+ describe('outside a system test', () => {
46
+ const NOT_A_SYSTEM_TEST =
47
+ 'this is not a system test: only the tests of a system test suite, a directory ' +
48
+ 'with an `encore.systest.json`, run against the app';
49
+
50
+ test('each helper says it is for a system test', () => {
51
+ expect(outcomes.settled).toBe(NOT_A_SYSTEM_TEST);
52
+ expect(outcomes.url).toBe(NOT_A_SYSTEM_TEST);
53
+ expect(outcomes.headers).toBe(NOT_A_SYSTEM_TEST);
54
+ expect(outcomes.telemetry).toBe(NOT_A_SYSTEM_TEST);
55
+ });
56
+
57
+ test('published and deliver are a service test’s', () => {
58
+ expect(outcomes.published).toContain('not running as a test');
59
+ expect(outcomes.deliver).toContain('not running as a test');
60
+ });
61
+ });
62
+
63
+ /**
64
+ * A serialized `encore.runtime.v1.RuntimeConfig` of a process that hosts a
65
+ * service, base64-encoded as the runtime expects it. Hand-encoded, as in
66
+ * `app_meta.test.ts`.
67
+ */
68
+ function runtimeConfig(): string {
69
+ const varint = (n: number): number[] => {
70
+ const out: number[] = [];
71
+ for (;;) {
72
+ const b = n & 0x7f;
73
+ n >>>= 7;
74
+ out.push(n ? b | 0x80 : b);
75
+ if (!n) return out;
76
+ }
77
+ };
78
+ const tag = (field: number, wire: number) => varint((field << 3) | wire);
79
+ const str = (field: number, value: string): number[] => {
80
+ const raw = [...new TextEncoder().encode(value)];
81
+ return [...tag(field, 2), ...varint(raw.length), ...raw];
82
+ };
83
+ const msg = (field: number, body: number[]): number[] => [
84
+ ...tag(field, 2),
85
+ ...varint(body.length),
86
+ ...body,
87
+ ];
88
+ const varintField = (field: number, value: number): number[] => [
89
+ ...tag(field, 0),
90
+ ...varint(value),
91
+ ];
92
+
93
+ // Environment{app_id=1, app_slug=2, env_id=3, env_name=4, env_type=5, cloud=6}
94
+ const environment = [
95
+ ...str(1, 'app-id'),
96
+ ...str(2, 'my-app'),
97
+ ...str(3, 'env-1'),
98
+ ...str(4, 'local'),
99
+ ...varintField(5, 1), // TYPE_DEVELOPMENT
100
+ ...varintField(6, 1), // CLOUD_LOCAL
101
+ ];
102
+ // Deployment{deploy_id=1, hosted_services=5}
103
+ const deployment = [...str(1, 'deploy-1'), ...msg(5, str(1, 'svc'))];
104
+
105
+ // RuntimeConfig{environment=1, deployment=3}
106
+ const cfg = [...msg(1, environment), ...msg(3, deployment)];
107
+ return Buffer.from(Uint8Array.from(cfg)).toString('base64');
108
+ }
@@ -0,0 +1,373 @@
1
+ /**
2
+ * System tests: tests of the whole app, which run as no service.
3
+ *
4
+ * A test in a service runs as that service, alone: a call to another service
5
+ * is not answered, and what it publishes nothing handles. A test in a system
6
+ * test suite — a directory with an `encore.systest.json` — runs against the
7
+ * app instead, in its test session: each service starts when something first
8
+ * reaches it, as under `encore run`, with the secrets and configs configured
9
+ * for tests and data that is the session's own.
10
+ *
11
+ * ```ts
12
+ * import {client} from "@encore.dev/sdk/services";
13
+ * import {Database} from "@encore.dev/sdk/storage/postgres";
14
+ * import {system} from "@encore.dev/sdk/testing";
15
+ *
16
+ * const orders = client("orders");
17
+ * const billing = Database.named("billing");
18
+ *
19
+ * test("placing an order charges the card", async () => {
20
+ * const res = await orders.fetch("/orders", {
21
+ * method: "POST",
22
+ * body: JSON.stringify({sku: "tee", qty: 2}),
23
+ * });
24
+ * const order = await res.json();
25
+ * // The order's event has been handled by billing's subscription.
26
+ * await system.settled();
27
+ *
28
+ * const row = await billing.queryRow`
29
+ * SELECT amount FROM charges WHERE order_id = ${order.id}`;
30
+ * expect(row?.amount).toBe(4000);
31
+ * });
32
+ * ```
33
+ *
34
+ * A system test may use any resource the app declares, bound with `named` or
35
+ * through a service's own declaration, and call any service.
36
+ *
37
+ * Each test has data of its own: an instance of every database, Redis
38
+ * database and bucket, which starts as a service's test's does, the
39
+ * databases migrated and the rest empty. What the services do for the test
40
+ * they do on that data, whichever of them it is, so a test reads what they
41
+ * wrote for it and nothing of another test's, and tests run side by side.
42
+ *
43
+ * A test can start from a `fixture` instead, as a service's test can. Its
44
+ * setup calls the app, and what the services made of that, in every
45
+ * database, bucket and Redis database, once what the setup set in motion
46
+ * has finished, is what each test that loads the fixture gets a copy of.
47
+ *
48
+ * What the app does for no request, as a Worker's loop or a job that finds
49
+ * its work in a table, is done on the data the services share, which a test
50
+ * does not see. A suite that tests such work says `"data": "shared"` in its
51
+ * `encore.systest.json`: its tests then share that data too, and each
52
+ * other's.
53
+ *
54
+ * What a test publishes is sent, and each subscription handles it in the
55
+ * service that declares it. {@link settled} waits for that: there is nothing
56
+ * to `deliver`.
57
+ *
58
+ * Each test has an id, which travels with every call and message it makes,
59
+ * and with what those cause in turn, so that what the app did for the test
60
+ * can be told from the rest. A test that fails prints what it caused in the
61
+ * app under its failure, where its runner says how it ended: under vitest
62
+ * and `node --test`, and in any runner for a test wrapped in `scoped`.
63
+ *
64
+ * The suite needs the runner adapter for its test runner, as a service's
65
+ * tests do (such as `@encore.dev/sdk/testing/vitest`). Run the tests with
66
+ * `encore test`, or with the runner itself in the suite's directory.
67
+ *
68
+ * @module
69
+ */
70
+ import {requireScope, systemTest, type Scope} from '../internal/testing/scope';
71
+ import {caller, Steps} from '../internal/testing/steps';
72
+ import {Telemetry} from '../internal/testing/telemetry';
73
+
74
+ export {Telemetry} from '../internal/testing/telemetry';
75
+ export type {LostContext} from '../internal/testing/telemetry';
76
+ export type {
77
+ DeliveryWhat,
78
+ Filter,
79
+ HopWhat,
80
+ Log,
81
+ OtherWhat,
82
+ PublishWhat,
83
+ QueryWhat,
84
+ RequestWhat,
85
+ Span,
86
+ SpanEvent,
87
+ SpanKind,
88
+ SpanLink,
89
+ SpanStatus,
90
+ TestWhat,
91
+ What,
92
+ } from '../internal/testing/telemetry';
93
+
94
+ /** The test session the process's tests run against. */
95
+ function session(): NonNullable<typeof systemTest> {
96
+ if (systemTest === null) {
97
+ throw new Error(
98
+ 'this is not a system test: only the tests of a system test suite, a directory ' +
99
+ 'with an `encore.systest.json`, run against the app',
100
+ );
101
+ }
102
+ return systemTest;
103
+ }
104
+
105
+ /** The current test, of a system test's process. */
106
+ function current(): Scope {
107
+ session();
108
+ return requireScope();
109
+ }
110
+
111
+ /** The options of {@link settled}. */
112
+ export interface SettledOptions {
113
+ /** How long to wait at most, in milliseconds: 30 seconds when not given. */
114
+ timeout?: number;
115
+ }
116
+
117
+ /**
118
+ * Waits until nothing the test set in motion is still running or queued: no
119
+ * request in flight to a service or through a gateway, and no message
120
+ * waiting, being handled or due a retry on a subscription. For at most 30
121
+ * seconds, or `options.timeout`: it rejects when the app has not settled by
122
+ * then, with an error saying what was still under way.
123
+ *
124
+ * It is the current test's work that is waited for, which is told by the
125
+ * test's id travelling with it, and nothing else: not what another test set
126
+ * in motion, so tests running side by side do not wait for each other, and
127
+ * not what the app does for no test. The work of a service that did not
128
+ * pass its request's context on has lost the test's id: it is not waited
129
+ * for, and is done on data the test does not see. The test's telemetry says
130
+ * which call lost it.
131
+ *
132
+ * In a suite whose tests share the session's data (`"data": "shared"`),
133
+ * everything the app has under way is waited for instead.
134
+ *
135
+ * What a service does that is neither — work that goes on after its request
136
+ * was answered — is not waited for.
137
+ *
138
+ * @example
139
+ * await orders.fetch("/orders", {method: "POST", body}); // publishes `order-placed`
140
+ * await system.settled(); // billing has handled it
141
+ */
142
+ export async function settled(options?: SettledOptions): Promise<void> {
143
+ await current().native.settled(options?.timeout ?? null);
144
+ }
145
+
146
+ /**
147
+ * The URL of the gateway or frontend `name` in the test session, for a
148
+ * client of the test's own, such as a WebSocket client. A frontend starts
149
+ * when something first connects to it.
150
+ *
151
+ * A request made with the SDK's clients, or the suite's generated ones,
152
+ * carries the test already: a generated Gateway Client made with no options
153
+ * calls the gateway here, for the test making the request. One made with
154
+ * another client carries the test with {@link headers}.
155
+ *
156
+ * @example
157
+ * import {Client} from "./encore_gen/gateway/api";
158
+ * const api = new Client();
159
+ */
160
+ export function url(name: string): string {
161
+ const system = session();
162
+ const found = system.url(name);
163
+ if (found === null) {
164
+ const known = system.gateways();
165
+ throw new Error(
166
+ `the app has no gateway or frontend ${JSON.stringify(name)} ` +
167
+ `(its gateways: ${known.length === 0 ? 'none' : known.join(', ')})`,
168
+ );
169
+ }
170
+ return found;
171
+ }
172
+
173
+ /**
174
+ * The headers that make a request part of the current test, for a client of
175
+ * the test's own: the test's id, as the Request Context field Encore carries
176
+ * it in, and the test's span for the request to continue. By lowercase name.
177
+ *
178
+ * @example
179
+ * const res = await fetch(`${system.url("api")}/health`, {
180
+ * headers: system.headers(),
181
+ * });
182
+ */
183
+ export function headers(): Record<string, string> {
184
+ return {...current().carried?.headers};
185
+ }
186
+
187
+ /** The options of {@link telemetry}. */
188
+ export interface TelemetryOptions {
189
+ /**
190
+ * Whether to wait for the app to settle first, as {@link settled} does,
191
+ * which is when all of what the test caused is recorded. `false` reads
192
+ * what has been recorded by now. Defaults to `true`.
193
+ */
194
+ settle?: boolean;
195
+ /** How long to wait for the app to settle at most, in milliseconds: 30
196
+ * seconds when not given. */
197
+ timeout?: number;
198
+ }
199
+
200
+ /**
201
+ * What the app recorded for the current test, once it has {@link settled}:
202
+ * every span of what the test caused — in the services it reached, in the
203
+ * requests between them, in the deliveries of what was published for it —
204
+ * and the lines logged in them.
205
+ *
206
+ * Each span says what it is of ({@link Span.what}): a request a service was
207
+ * handed, a query, a message published or delivered, for a test to assert
208
+ * on. As a string it is the tree of it a failed test prints, and
209
+ * {@link Telemetry.shape} the same without what differs between runs, to
210
+ * keep as a snapshot of which services a flow touches.
211
+ *
212
+ * @example
213
+ * const recorded = await system.telemetry();
214
+ * expect(recorded.requests({service: "catalog"})).toHaveLength(1);
215
+ * expect(recorded.deliveries().every(d => d.what.handled)).toBe(true);
216
+ * expect(recorded.errors()).toEqual([]);
217
+ */
218
+ export async function telemetry(
219
+ options?: TelemetryOptions,
220
+ ): Promise<Telemetry> {
221
+ const json = await current().native.telemetry(
222
+ options?.settle ?? true,
223
+ options?.timeout ?? null,
224
+ );
225
+ return Telemetry.parse(json);
226
+ }
227
+
228
+ /** The options of {@link browser}. */
229
+ export interface BrowserOptions {
230
+ /**
231
+ * When what the browser recorded is kept: for a test that `'failed'`, or
232
+ * whose runner does not say how it ended; for `'all'` tests; or `'off'`.
233
+ * Defaults to what `ENCORE_TEST_RECORD` says, else `'failed'`.
234
+ */
235
+ record?: 'failed' | 'all' | 'off';
236
+ /** More command-line arguments for the browser. */
237
+ args?: string[];
238
+ /** The size of the browser's window, in CSS pixels: 1280×800 by default. */
239
+ window?: {width: number; height: number};
240
+ }
241
+
242
+ /** The current test's browser: see {@link browser}. */
243
+ export interface Browser {
244
+ /**
245
+ * What a DevTools Protocol client connects to: the address of a WebSocket,
246
+ * as a browser gives for itself. Puppeteer's `connect`, Playwright's
247
+ * `connectOverCDP`.
248
+ */
249
+ readonly wsEndpoint: string;
250
+ /**
251
+ * The file the recording is written to when the test ends, if it is kept:
252
+ * one HTML file that plays the pages back beside what the test and the app
253
+ * did. `null` when nothing is recorded.
254
+ */
255
+ readonly recording: string | null;
256
+ /**
257
+ * The URL a page reaches the gateway or frontend `name` at: the one
258
+ * `encore run` has it at, which the frontend is written against. The
259
+ * browser's requests there go to the test session.
260
+ */
261
+ url(name: string): string;
262
+ /**
263
+ * Runs `fn` as one statement of the test, called `name`: what `fn` has the
264
+ * browser do, and the requests that come of it, are recorded under it, in
265
+ * the test's telemetry and in its recording, with where `step` was called.
266
+ * It resolves to what `fn` returns, and a `fn` that throws fails the step.
267
+ *
268
+ * An adapter reports each call a test makes on its tool by itself: this is
269
+ * for a tool that has none, and for naming several calls as one.
270
+ *
271
+ * @example
272
+ * await browser.step("pay with a saved card", async () => {
273
+ * await page.click("#saved-card");
274
+ * await page.click("#pay");
275
+ * });
276
+ */
277
+ step<R>(name: string, fn: () => R | Promise<R>): Promise<R>;
278
+ }
279
+
280
+ /**
281
+ * The current test's browser: a headless Chromium Encore runs for the test,
282
+ * for a tool of the test's own to drive. It is started the first time the
283
+ * test asks, and ends with the test.
284
+ *
285
+ * It is the test's in every way a call the test makes is:
286
+ *
287
+ * - It reaches the app where `encore run` has it. A frontend says itself
288
+ * where its API is, as `http://localhost:4000`: a page's requests there,
289
+ * and to the frontends' own addresses, go to the test session.
290
+ * - Each request a page makes to the app carries the test, so what the app
291
+ * does for a click is done on the test's data, and {@link settled} waits
292
+ * for it.
293
+ * - What the test has the browser do, and each request a page makes, is in
294
+ * the test's {@link telemetry}, with what the app did for a request
295
+ * under it. So is what a page says went wrong: an error on its console,
296
+ * an exception nothing caught, a request that failed.
297
+ * - Its pages are recorded. A test that fails is left a file that plays
298
+ * them back beside all of that ({@link Browser.recording}).
299
+ *
300
+ * The adapters connect a tool to it and say which statement of the test
301
+ * is running: `@encore.dev/sdk/testing/puppeteer`,
302
+ * `@encore.dev/sdk/testing/playwright`. This is for any other tool that
303
+ * speaks the DevTools Protocol.
304
+ *
305
+ * The browser is the `browser/chromium` component, which Encore downloads
306
+ * the first time a test asks for one.
307
+ *
308
+ * @example
309
+ * const {wsEndpoint, url} = await system.browser();
310
+ * const browser = await puppeteer.connect({browserWSEndpoint: wsEndpoint});
311
+ * const page = await browser.newPage();
312
+ * await page.goto(url("web"));
313
+ */
314
+ export async function browser(options?: BrowserOptions): Promise<Browser> {
315
+ const json = await current().native.browser(
316
+ options?.record ?? null,
317
+ options?.args ?? null,
318
+ options?.window?.width ?? null,
319
+ options?.window?.height ?? null,
320
+ );
321
+ const info = JSON.parse(json) as {
322
+ wsEndpoint: string;
323
+ urls: Record<string, string>;
324
+ recording: string;
325
+ stepsUrl: string;
326
+ };
327
+ // Said to the session over HTTP, on the listener the browser's DevTools
328
+ // endpoint is on: a test with a tool of its own has no hold on the tool's
329
+ // connection. Each word is answered before the next thing is done.
330
+ const steps = new Steps(async (method, params) => {
331
+ if (info.stepsUrl === '') throw new Error('the session takes no steps');
332
+ const response = await fetch(
333
+ `${info.stepsUrl}/${method.replace('Encore.', '')}`,
334
+ {
335
+ method: 'POST',
336
+ headers: {'content-type': 'application/json'},
337
+ body: JSON.stringify(params),
338
+ },
339
+ );
340
+ if (!response.ok)
341
+ throw new Error(`the session answered ${response.status}`);
342
+ return response.json();
343
+ });
344
+ return {
345
+ async step<R>(name: string, fn: () => R | Promise<R>): Promise<R> {
346
+ const at = caller();
347
+ const step = steps.begin(name, at);
348
+ // The session has heard the step began before `fn` does anything.
349
+ await step;
350
+ try {
351
+ const result = await fn();
352
+ await steps.end(step);
353
+ return result;
354
+ } catch (err) {
355
+ await steps.end(step, err instanceof Error ? err.message : String(err));
356
+ throw err;
357
+ }
358
+ },
359
+ wsEndpoint: info.wsEndpoint,
360
+ recording: info.recording === '' ? null : info.recording,
361
+ url(name: string): string {
362
+ const found = info.urls[name];
363
+ if (found === undefined) {
364
+ const known = Object.keys(info.urls).filter(n => n !== 'proxy');
365
+ throw new Error(
366
+ `the app has no gateway or frontend ${JSON.stringify(name)} ` +
367
+ `(it has: ${known.length === 0 ? 'none' : known.sort().join(', ')})`,
368
+ );
369
+ }
370
+ return found;
371
+ },
372
+ };
373
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Per-test infrastructure under vitest: `test.setupFiles:
3
+ * ["@encore.dev/sdk/testing/vitest"]` in the vitest config.
4
+ *
5
+ * @module
6
+ */
7
+ import '../internal/testing/runner';
8
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- an error in the build, which has no vitest
9
+ // @ts-ignore: vitest's own module, there when vitest runs this.
10
+ import {afterAll, afterEach, beforeEach} from 'vitest';
11
+ import {setup} from './mod';
12
+
13
+ setup({beforeEach, afterEach, afterAll});
@@ -0,0 +1,49 @@
1
+ import type {TextMapGetter} from '@opentelemetry/api';
2
+ import {withContext} from '../internal/otel/context';
3
+ import {
4
+ recordHTTPError,
5
+ recordHTTPStatus,
6
+ startHTTPSpan,
7
+ } from '../internal/otel/http';
8
+
9
+ const headersGetter: TextMapGetter<Headers> = {
10
+ keys: headers => Array.from(headers.keys()),
11
+ get: (headers, key) => headers.get(key) ?? undefined,
12
+ };
13
+
14
+ /**
15
+ * Wraps a Request handler with an active SERVER span and incoming trace and
16
+ * Request Context fields. Preserves the receiver, extra arguments and Response.
17
+ * No OpenTelemetry globals are registered.
18
+ *
19
+ * The span ends when the handler produces a Response, not when its streaming
20
+ * body completes. Framework-specific code can add route-based span naming.
21
+ */
22
+ export function instrumentHTTP<This, Args extends unknown[]>(
23
+ handler: (
24
+ this: This,
25
+ request: Request,
26
+ ...args: Args
27
+ ) => Response | PromiseLike<Response>,
28
+ ): (this: This, request: Request, ...args: Args) => Promise<Response> {
29
+ return async function (this: This, request: Request, ...args: Args) {
30
+ const {span, context} = startHTTPSpan(
31
+ request.headers,
32
+ headersGetter,
33
+ request.method,
34
+ new URL(request.url),
35
+ );
36
+ return withContext(context, async () => {
37
+ try {
38
+ const response = await handler.call(this, request, ...args);
39
+ recordHTTPStatus(span, response.status);
40
+ return response;
41
+ } catch (error) {
42
+ recordHTTPError(span, error);
43
+ throw error;
44
+ } finally {
45
+ span.end();
46
+ }
47
+ });
48
+ };
49
+ }