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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (356) hide show
  1. package/README.md +55 -0
  2. package/app_meta.ts +8 -0
  3. package/config/config.test.ts +10 -3
  4. package/config/config.ts +75 -21
  5. package/config/mod.ts +4 -3
  6. package/config/secrets.ts +72 -55
  7. package/cron/mod.ts +32 -0
  8. package/dist/app_meta.d.ts +7 -0
  9. package/dist/app_meta.d.ts.map +1 -0
  10. package/dist/app_meta.js +1 -0
  11. package/dist/app_meta.js.map +1 -1
  12. package/dist/config/config.d.ts +44 -18
  13. package/dist/config/config.d.ts.map +1 -0
  14. package/dist/config/config.js +43 -18
  15. package/dist/config/config.js.map +1 -1
  16. package/dist/config/mod.d.ts +5 -4
  17. package/dist/config/mod.d.ts.map +1 -0
  18. package/dist/config/mod.js +2 -2
  19. package/dist/config/mod.js.map +1 -1
  20. package/dist/config/secrets.d.ts +62 -39
  21. package/dist/config/secrets.d.ts.map +1 -0
  22. package/dist/config/secrets.js +21 -37
  23. package/dist/config/secrets.js.map +1 -1
  24. package/dist/config/value.d.ts +1 -0
  25. package/dist/config/value.d.ts.map +1 -0
  26. package/dist/cron/mod.d.ts +31 -0
  27. package/dist/cron/mod.d.ts.map +1 -0
  28. package/dist/cron/mod.js +23 -0
  29. package/dist/cron/mod.js.map +1 -1
  30. package/dist/gateway/errors.d.ts +101 -0
  31. package/dist/gateway/errors.d.ts.map +1 -0
  32. package/dist/gateway/errors.js +146 -0
  33. package/dist/gateway/errors.js.map +1 -0
  34. package/dist/gateway/match.d.ts +127 -0
  35. package/dist/gateway/match.d.ts.map +1 -0
  36. package/dist/gateway/match.js +206 -0
  37. package/dist/gateway/match.js.map +1 -0
  38. package/dist/gateway/middleware.d.ts +108 -0
  39. package/dist/gateway/middleware.d.ts.map +1 -0
  40. package/dist/gateway/middleware.js +9 -0
  41. package/dist/gateway/middleware.js.map +1 -0
  42. package/dist/gateway/mod.d.ts +129 -0
  43. package/dist/gateway/mod.d.ts.map +1 -0
  44. package/dist/gateway/mod.js +187 -0
  45. package/dist/gateway/mod.js.map +1 -0
  46. package/dist/gateway/request.d.ts +304 -0
  47. package/dist/gateway/request.d.ts.map +1 -0
  48. package/dist/gateway/request.js +403 -0
  49. package/dist/gateway/request.js.map +1 -0
  50. package/dist/gateway/serve.d.ts +114 -0
  51. package/dist/gateway/serve.d.ts.map +1 -0
  52. package/dist/gateway/serve.js +510 -0
  53. package/dist/gateway/serve.js.map +1 -0
  54. package/dist/internal/clients/call.d.ts +147 -0
  55. package/dist/internal/clients/call.d.ts.map +1 -0
  56. package/dist/internal/clients/call.js +274 -0
  57. package/dist/internal/clients/call.js.map +1 -0
  58. package/dist/internal/clients/grpc.d.ts +90 -0
  59. package/dist/internal/clients/grpc.d.ts.map +1 -0
  60. package/dist/internal/clients/grpc.js +355 -0
  61. package/dist/internal/clients/grpc.js.map +1 -0
  62. package/dist/internal/clients/mod.d.ts +81 -0
  63. package/dist/internal/clients/mod.d.ts.map +1 -0
  64. package/dist/internal/clients/mod.js +237 -0
  65. package/dist/internal/clients/mod.js.map +1 -0
  66. package/dist/internal/fetch.d.ts +54 -0
  67. package/dist/internal/fetch.d.ts.map +1 -0
  68. package/dist/internal/fetch.js +240 -0
  69. package/dist/internal/fetch.js.map +1 -0
  70. package/dist/internal/otel/backend.d.ts +2 -0
  71. package/dist/internal/otel/backend.d.ts.map +1 -0
  72. package/dist/internal/otel/context.d.ts +1 -0
  73. package/dist/internal/otel/context.d.ts.map +1 -0
  74. package/dist/internal/otel/context_manager.d.ts +1 -0
  75. package/dist/internal/otel/context_manager.d.ts.map +1 -0
  76. package/dist/internal/otel/encode.d.ts +2 -0
  77. package/dist/internal/otel/encode.d.ts.map +1 -0
  78. package/dist/internal/otel/index.d.ts +2 -2
  79. package/dist/internal/otel/index.d.ts.map +1 -0
  80. package/dist/internal/otel/index.js +1 -2
  81. package/dist/internal/otel/index.js.map +1 -1
  82. package/dist/internal/otel/meter.d.ts +1 -0
  83. package/dist/internal/otel/meter.d.ts.map +1 -0
  84. package/dist/internal/otel/propagator.d.ts +1 -0
  85. package/dist/internal/otel/propagator.d.ts.map +1 -0
  86. package/dist/internal/otel/provider.d.ts +1 -0
  87. package/dist/internal/otel/provider.d.ts.map +1 -0
  88. package/dist/internal/otel/span.d.ts +4 -0
  89. package/dist/internal/otel/span.d.ts.map +1 -0
  90. package/dist/internal/otel/span.js +5 -0
  91. package/dist/internal/otel/span.js.map +1 -1
  92. package/dist/internal/otel/tracer.d.ts +1 -0
  93. package/dist/internal/otel/tracer.d.ts.map +1 -0
  94. package/dist/internal/otel/tracer.js +11 -5
  95. package/dist/internal/otel/tracer.js.map +1 -1
  96. package/dist/internal/reqfields.d.ts +150 -0
  97. package/dist/internal/reqfields.d.ts.map +1 -0
  98. package/dist/internal/reqfields.js +312 -0
  99. package/dist/internal/reqfields.js.map +1 -0
  100. package/dist/internal/runtime/meter.d.ts +1 -0
  101. package/dist/internal/runtime/meter.d.ts.map +1 -0
  102. package/dist/internal/runtime/mod.d.ts +6 -0
  103. package/dist/internal/runtime/mod.d.ts.map +1 -0
  104. package/dist/internal/runtime/mod.js +32 -2
  105. package/dist/internal/runtime/mod.js.map +1 -1
  106. package/dist/internal/runtime/napi/napi.cjs +160 -16
  107. package/dist/internal/runtime/napi/napi.d.cts +474 -29
  108. package/dist/internal/runtime/shutdown.d.ts +5 -0
  109. package/dist/internal/runtime/shutdown.d.ts.map +1 -0
  110. package/dist/internal/runtime/shutdown.js +9 -1
  111. package/dist/internal/runtime/shutdown.js.map +1 -1
  112. package/dist/internal/testing/runner.d.ts +2 -0
  113. package/dist/internal/testing/runner.d.ts.map +1 -0
  114. package/dist/internal/testing/runner.js +10 -0
  115. package/dist/internal/testing/runner.js.map +1 -0
  116. package/dist/internal/testing/scope.d.ts +81 -0
  117. package/dist/internal/testing/scope.d.ts.map +1 -0
  118. package/dist/internal/testing/scope.js +237 -0
  119. package/dist/internal/testing/scope.js.map +1 -0
  120. package/dist/internal/utils/constraints.d.ts +1 -0
  121. package/dist/internal/utils/constraints.d.ts.map +1 -0
  122. package/dist/log/index.d.ts +1 -0
  123. package/dist/log/index.d.ts.map +1 -0
  124. package/dist/log/logger.d.ts +2 -0
  125. package/dist/log/logger.d.ts.map +1 -0
  126. package/dist/log/runtime.d.ts +2 -0
  127. package/dist/log/runtime.d.ts.map +1 -0
  128. package/dist/log/stderr.d.ts +1 -0
  129. package/dist/log/stderr.d.ts.map +1 -0
  130. package/dist/metrics/mod.d.ts +45 -118
  131. package/dist/metrics/mod.d.ts.map +1 -0
  132. package/dist/metrics/mod.js +44 -179
  133. package/dist/metrics/mod.js.map +1 -1
  134. package/dist/mod.d.ts +1 -2
  135. package/dist/mod.d.ts.map +1 -0
  136. package/dist/mod.js +0 -1
  137. package/dist/mod.js.map +1 -1
  138. package/dist/otel.d.ts +1 -0
  139. package/dist/otel.d.ts.map +1 -0
  140. package/dist/pubsub/encoding.d.ts +5 -0
  141. package/dist/pubsub/encoding.d.ts.map +1 -0
  142. package/dist/pubsub/encoding.js +10 -2
  143. package/dist/pubsub/encoding.js.map +1 -1
  144. package/dist/pubsub/mod.d.ts +4 -3
  145. package/dist/pubsub/mod.d.ts.map +1 -0
  146. package/dist/pubsub/mod.js +2 -2
  147. package/dist/pubsub/mod.js.map +1 -1
  148. package/dist/pubsub/refs.d.ts +8 -0
  149. package/dist/pubsub/refs.d.ts.map +1 -0
  150. package/dist/pubsub/refs.js.map +1 -1
  151. package/dist/pubsub/subscription.d.ts +104 -10
  152. package/dist/pubsub/subscription.d.ts.map +1 -0
  153. package/dist/pubsub/subscription.js +98 -16
  154. package/dist/pubsub/subscription.js.map +1 -1
  155. package/dist/pubsub/topic.d.ts +87 -23
  156. package/dist/pubsub/topic.d.ts.map +1 -0
  157. package/dist/pubsub/topic.js +143 -40
  158. package/dist/pubsub/topic.js.map +1 -1
  159. package/dist/reqctx/mod.d.ts +191 -0
  160. package/dist/reqctx/mod.d.ts.map +1 -0
  161. package/dist/reqctx/mod.js +160 -0
  162. package/dist/reqctx/mod.js.map +1 -0
  163. package/dist/services/index.d.ts +145 -4
  164. package/dist/services/index.d.ts.map +1 -0
  165. package/dist/services/index.js +155 -8
  166. package/dist/services/index.js.map +1 -1
  167. package/dist/shutdown/mod.d.ts +1 -0
  168. package/dist/shutdown/mod.d.ts.map +1 -0
  169. package/dist/storage/objects/bucket.d.ts +312 -7
  170. package/dist/storage/objects/bucket.d.ts.map +1 -0
  171. package/dist/storage/objects/bucket.js +305 -15
  172. package/dist/storage/objects/bucket.js.map +1 -1
  173. package/dist/storage/objects/error.d.ts +10 -0
  174. package/dist/storage/objects/error.d.ts.map +1 -0
  175. package/dist/storage/objects/error.js +25 -1
  176. package/dist/storage/objects/error.js.map +1 -1
  177. package/dist/storage/objects/mod.d.ts +4 -3
  178. package/dist/storage/objects/mod.d.ts.map +1 -0
  179. package/dist/storage/objects/mod.js +1 -1
  180. package/dist/storage/objects/mod.js.map +1 -1
  181. package/dist/storage/objects/refs.d.ts +20 -4
  182. package/dist/storage/objects/refs.d.ts.map +1 -0
  183. package/dist/storage/objects/refs.js +6 -0
  184. package/dist/storage/objects/refs.js.map +1 -1
  185. package/dist/storage/postgres/database.d.ts +81 -25
  186. package/dist/storage/postgres/database.d.ts.map +1 -0
  187. package/dist/storage/postgres/database.js +125 -37
  188. package/dist/storage/postgres/database.js.map +1 -1
  189. package/dist/storage/postgres/errors.d.ts +120 -0
  190. package/dist/storage/postgres/errors.d.ts.map +1 -0
  191. package/dist/storage/postgres/errors.js +162 -0
  192. package/dist/storage/postgres/errors.js.map +1 -0
  193. package/dist/storage/postgres/interval.d.ts +44 -0
  194. package/dist/storage/postgres/interval.d.ts.map +1 -0
  195. package/dist/storage/postgres/interval.js +153 -0
  196. package/dist/storage/postgres/interval.js.map +1 -0
  197. package/dist/storage/postgres/mod.d.ts +4 -1
  198. package/dist/storage/postgres/mod.d.ts.map +1 -0
  199. package/dist/storage/postgres/mod.js +2 -0
  200. package/dist/storage/postgres/mod.js.map +1 -1
  201. package/dist/storage/redis/bitfield.d.ts +67 -0
  202. package/dist/storage/redis/bitfield.d.ts.map +1 -0
  203. package/dist/storage/redis/bitfield.js +114 -0
  204. package/dist/storage/redis/bitfield.js.map +1 -0
  205. package/dist/storage/redis/command.d.ts +45 -0
  206. package/dist/storage/redis/command.d.ts.map +1 -0
  207. package/dist/storage/redis/command.js +78 -0
  208. package/dist/storage/redis/command.js.map +1 -0
  209. package/dist/storage/redis/commands.d.ts +223 -139
  210. package/dist/storage/redis/commands.d.ts.map +1 -0
  211. package/dist/storage/redis/commands.js +128 -6
  212. package/dist/storage/redis/commands.js.map +1 -1
  213. package/dist/storage/redis/database.d.ts +56 -22
  214. package/dist/storage/redis/database.d.ts.map +1 -0
  215. package/dist/storage/redis/database.js +62 -0
  216. package/dist/storage/redis/database.js.map +1 -1
  217. package/dist/storage/redis/mod.d.ts +31 -4
  218. package/dist/storage/redis/mod.d.ts.map +1 -0
  219. package/dist/storage/redis/mod.js +26 -1
  220. package/dist/storage/redis/mod.js.map +1 -1
  221. package/dist/storage/redis/native.d.ts +8 -0
  222. package/dist/storage/redis/native.d.ts.map +1 -0
  223. package/dist/storage/redis/native.js +10 -0
  224. package/dist/storage/redis/native.js.map +1 -1
  225. package/dist/storage/redis/options.d.ts +1 -0
  226. package/dist/storage/redis/options.d.ts.map +1 -0
  227. package/dist/storage/redis/pubsub.d.ts +2 -0
  228. package/dist/storage/redis/pubsub.d.ts.map +1 -0
  229. package/dist/storage/redis/reply.d.ts +34 -0
  230. package/dist/storage/redis/reply.d.ts.map +1 -0
  231. package/dist/storage/redis/reply.js +40 -1
  232. package/dist/storage/redis/reply.js.map +1 -1
  233. package/dist/storage/redis/scan.d.ts +1 -0
  234. package/dist/storage/redis/scan.d.ts.map +1 -0
  235. package/dist/storage/redis/script.d.ts +1 -0
  236. package/dist/storage/redis/script.d.ts.map +1 -0
  237. package/dist/storage/redis/target.d.ts +5 -3
  238. package/dist/storage/redis/target.d.ts.map +1 -0
  239. package/dist/storage/redis/target.js +39 -28
  240. package/dist/storage/redis/target.js.map +1 -1
  241. package/dist/storage/redis/wire.d.ts +7 -10
  242. package/dist/storage/redis/wire.d.ts.map +1 -0
  243. package/dist/storage/redis/wire.js +8 -32
  244. package/dist/storage/redis/wire.js.map +1 -1
  245. package/dist/testing/bun.d.ts +8 -0
  246. package/dist/testing/bun.d.ts.map +1 -0
  247. package/dist/testing/bun.js +13 -0
  248. package/dist/testing/bun.js.map +1 -0
  249. package/dist/testing/jest.d.ts +8 -0
  250. package/dist/testing/jest.d.ts.map +1 -0
  251. package/dist/testing/jest.js +11 -0
  252. package/dist/testing/jest.js.map +1 -0
  253. package/dist/testing/mod.d.ts +160 -0
  254. package/dist/testing/mod.d.ts.map +1 -0
  255. package/dist/testing/mod.js +227 -0
  256. package/dist/testing/mod.js.map +1 -0
  257. package/dist/testing/node.d.ts +9 -0
  258. package/dist/testing/node.d.ts.map +1 -0
  259. package/dist/testing/node.js +12 -0
  260. package/dist/testing/node.js.map +1 -0
  261. package/dist/testing/vitest.d.ts +8 -0
  262. package/dist/testing/vitest.d.ts.map +1 -0
  263. package/dist/testing/vitest.js +13 -0
  264. package/dist/testing/vitest.js.map +1 -0
  265. package/dist/tracing/mod.d.ts +19 -0
  266. package/dist/tracing/mod.d.ts.map +1 -0
  267. package/dist/tracing/mod.js +46 -0
  268. package/dist/tracing/mod.js.map +1 -0
  269. package/dist/tsconfig.build.tsbuildinfo +1 -1
  270. package/dist/types/mod.d.ts +1 -0
  271. package/dist/types/mod.d.ts.map +1 -0
  272. package/gateway/errors.ts +172 -0
  273. package/gateway/gateway.e2e.test.ts +297 -0
  274. package/gateway/gateway.test.ts +891 -0
  275. package/gateway/match.ts +239 -0
  276. package/gateway/middleware.ts +134 -0
  277. package/gateway/mod.ts +210 -0
  278. package/gateway/request.ts +578 -0
  279. package/gateway/serve.ts +738 -0
  280. package/internal/clients/call.ts +389 -0
  281. package/internal/clients/grpc.test.ts +368 -0
  282. package/internal/clients/grpc.ts +485 -0
  283. package/internal/clients/mod.test.ts +464 -0
  284. package/internal/clients/mod.ts +337 -0
  285. package/internal/fetch.ts +276 -0
  286. package/internal/otel/index.ts +1 -7
  287. package/internal/otel/span.ts +6 -0
  288. package/internal/otel/tracer.test.ts +43 -15
  289. package/internal/otel/tracer.ts +12 -5
  290. package/internal/reqfields.ts +390 -0
  291. package/internal/runtime/mod.ts +41 -2
  292. package/internal/runtime/napi/napi.cjs +160 -16
  293. package/internal/runtime/napi/napi.d.cts +474 -29
  294. package/internal/runtime/shutdown.ts +11 -1
  295. package/internal/testing/runner.ts +10 -0
  296. package/internal/testing/scope.ts +273 -0
  297. package/metrics/mod.test.ts +13 -16
  298. package/metrics/mod.ts +57 -226
  299. package/mod.ts +0 -8
  300. package/otel.test.ts +13 -6
  301. package/package.json +67 -15
  302. package/pubsub/encoding.ts +11 -1
  303. package/pubsub/mod.ts +10 -3
  304. package/pubsub/pubsub.test.ts +232 -14
  305. package/pubsub/refs.ts +16 -0
  306. package/pubsub/subscription.ts +194 -16
  307. package/pubsub/topic.test.ts +26 -0
  308. package/pubsub/topic.ts +220 -25
  309. package/reqctx/mod.ts +284 -0
  310. package/reqctx/reqctx.test.ts +193 -0
  311. package/scripts/postprocess-docs.test.ts +48 -0
  312. package/services/index.test.ts +341 -1
  313. package/services/index.ts +183 -8
  314. package/storage/objects/bucket.test.ts +573 -0
  315. package/storage/objects/bucket.ts +649 -20
  316. package/storage/objects/error.ts +28 -1
  317. package/storage/objects/mod.ts +15 -0
  318. package/storage/objects/refs.ts +51 -3
  319. package/storage/postgres/database.integration.test.ts +275 -0
  320. package/storage/postgres/database.test.ts +193 -6
  321. package/storage/postgres/database.ts +202 -55
  322. package/storage/postgres/errors.ts +186 -0
  323. package/storage/postgres/interval.test.ts +72 -0
  324. package/storage/postgres/interval.ts +170 -0
  325. package/storage/postgres/mod.ts +4 -0
  326. package/storage/redis/bitfield.ts +162 -0
  327. package/storage/redis/command.ts +84 -0
  328. package/storage/redis/commands.ts +271 -21
  329. package/storage/redis/database.ts +77 -23
  330. package/storage/redis/mod.ts +38 -2
  331. package/storage/redis/native.ts +11 -0
  332. package/storage/redis/redis.test.ts +170 -10
  333. package/storage/redis/reply.ts +76 -1
  334. package/storage/redis/runtime.test.ts +15 -0
  335. package/storage/redis/target.ts +47 -44
  336. package/storage/redis/wire.ts +8 -32
  337. package/testing/bun.ts +13 -0
  338. package/testing/jest.ts +11 -0
  339. package/testing/mod.ts +337 -0
  340. package/testing/node.ts +12 -0
  341. package/testing/vitest.ts +13 -0
  342. package/tracing/mod.ts +82 -0
  343. package/tracing/native.test.ts +170 -0
  344. package/tracing/tracing.test.ts +317 -0
  345. package/dist/internal/otel/request_context.d.ts +0 -11
  346. package/dist/internal/otel/request_context.js +0 -20
  347. package/dist/internal/otel/request_context.js.map +0 -1
  348. package/dist/internal/reqtrack/mod.d.ts +0 -6
  349. package/dist/internal/reqtrack/mod.js +0 -28
  350. package/dist/internal/reqtrack/mod.js.map +0 -1
  351. package/dist/req_meta.d.ts +0 -47
  352. package/dist/req_meta.js +0 -26
  353. package/dist/req_meta.js.map +0 -1
  354. package/internal/otel/request_context.ts +0 -32
  355. package/internal/reqtrack/mod.ts +0 -39
  356. package/req_meta.ts +0 -75
@@ -0,0 +1,237 @@
1
+ /**
2
+ * What the service clients Encore generates call through: a service, looked
3
+ * up on the first call that needs it, and its HTTP calls. For the generated
4
+ * code: it may change with the generator. Code calling the clients takes
5
+ * their errors and options from `@encore.dev/sdk/services`.
6
+ *
7
+ * Nothing here loads the runtime until a call needs a service's base URL, so
8
+ * a generated client given a `baseUrl` runs without Encore, as against a
9
+ * mock server in a plain test.
10
+ *
11
+ * @hidden
12
+ * @module
13
+ */
14
+ import { CallError, callHeaders, deadline, errorBody, errorText, failure, fetchFor, httpStatus, isErrCode, } from './call.js';
15
+ export { CallError, } from './call.js';
16
+ /**
17
+ * A service the generated clients call, looked up on the first call that
18
+ * needs its base URL. For the generated code: it may change with the
19
+ * generator.
20
+ *
21
+ * @hidden
22
+ */
23
+ export class Service {
24
+ name;
25
+ /** The base URL, once looked up. */
26
+ base;
27
+ constructor(name) {
28
+ this.name = name;
29
+ }
30
+ /**
31
+ * The base URL calls made with `client` go to, without a trailing slash:
32
+ * its `baseUrl`, else the one Encore gives the service.
33
+ */
34
+ async baseUrl(client) {
35
+ if (client.baseUrl !== undefined)
36
+ return client.baseUrl.replace(/\/+$/, '');
37
+ // A failed lookup is tried again by the next call.
38
+ this.base ??= lookup(this.name).catch((err) => {
39
+ this.base = undefined;
40
+ throw err;
41
+ });
42
+ return this.base;
43
+ }
44
+ /** Sends `call`, and decodes its answer from JSON. */
45
+ async json(client, options, call) {
46
+ return this.send(client, options, call, async (res) => {
47
+ const text = await res.text();
48
+ // An empty answer is JSON's `null`.
49
+ if (text === '')
50
+ return null;
51
+ try {
52
+ return JSON.parse(text);
53
+ }
54
+ catch (err) {
55
+ throw failure('internal', `decoding the answer: ${errorText(err)}`, err);
56
+ }
57
+ });
58
+ }
59
+ /** Sends `call`, and reads its answer's body. */
60
+ async bytes(client, options, call) {
61
+ return this.send(client, options, call, async (res) => new Uint8Array(await res.arrayBuffer()));
62
+ }
63
+ /** Sends `call`, and drops its answer. */
64
+ async empty(client, options, call) {
65
+ await this.send(client, options, call, async (res) => {
66
+ await res.body?.cancel();
67
+ });
68
+ }
69
+ /**
70
+ * Sends GraphQL `document` with `variables` to the service's `path`, and
71
+ * returns the answer's `field` of its data. A variable left `undefined` is
72
+ * left out, which a `null` is not. A `required` field missing or null fails
73
+ * the call with `internal`.
74
+ */
75
+ async graphql(client, options, path, document, variables, field, required = false) {
76
+ const call = {
77
+ method: 'POST',
78
+ path,
79
+ json: { query: document, variables },
80
+ };
81
+ return this.exchange(client, options, call, async (res) => {
82
+ const text = await res.text();
83
+ let envelope;
84
+ try {
85
+ const parsed = JSON.parse(text);
86
+ if (typeof parsed === 'object' && parsed !== null) {
87
+ envelope = parsed;
88
+ }
89
+ }
90
+ catch {
91
+ envelope = undefined;
92
+ }
93
+ const errors = envelope?.errors;
94
+ if (errors !== undefined &&
95
+ errors !== null &&
96
+ !(Array.isArray(errors) && errors.length === 0)) {
97
+ throw graphqlError(errors, res.status);
98
+ }
99
+ if (!res.ok)
100
+ throw errorBody(res, text);
101
+ const data = envelope?.data;
102
+ if (data === undefined || data === null) {
103
+ throw failure('unknown', 'graphql: the answer has neither data nor errors');
104
+ }
105
+ const value = data[field] ?? null;
106
+ if (value === null && required) {
107
+ throw failure('internal', `graphql: the answer's ${field} is missing or null`);
108
+ }
109
+ return value;
110
+ });
111
+ }
112
+ /** Sends `call`, failing on an error answer, and reads the answer with
113
+ * `read`. */
114
+ async send(client, options, call, read) {
115
+ return this.exchange(client, options, call, async (res) => {
116
+ if (!res.ok)
117
+ throw errorBody(res, await res.text());
118
+ return read(res);
119
+ });
120
+ }
121
+ /** Sends `call` and reads its answer with `read`, under the call's
122
+ * timeout and signal, which cover the answer's body too. */
123
+ async exchange(client, options, call, read) {
124
+ const limit = deadline(client, options);
125
+ try {
126
+ let url = (await this.baseUrl(client)) + call.path;
127
+ const query = new URLSearchParams();
128
+ for (const [name, value] of call.query ?? []) {
129
+ for (const v of Array.isArray(value) ? value : [value]) {
130
+ if (v !== undefined && v !== null)
131
+ query.append(name, paramText(v));
132
+ }
133
+ }
134
+ const qs = query.toString();
135
+ if (qs !== '')
136
+ url += `?${qs}`;
137
+ const params = [];
138
+ for (const [name, value] of call.headers ?? []) {
139
+ if (value !== undefined && value !== null) {
140
+ params.push([name, paramText(value)]);
141
+ }
142
+ }
143
+ const headers = callHeaders(client, options, params);
144
+ let body;
145
+ if (call.json !== undefined) {
146
+ headers.set('Content-Type', 'application/json');
147
+ try {
148
+ body = JSON.stringify(call.json);
149
+ }
150
+ catch (err) {
151
+ // A cycle, or a BigInt, which JSON has no form for.
152
+ throw failure('invalid_argument', `encoding the body: ${errorText(err)}`, err);
153
+ }
154
+ }
155
+ else if (call.body !== undefined) {
156
+ if (call.contentType !== undefined) {
157
+ headers.set('Content-Type', call.contentType);
158
+ }
159
+ // TS ≥5.7's Uint8Array<ArrayBufferLike> is no BodyInit, though fetch
160
+ // takes one.
161
+ body = call.body;
162
+ }
163
+ let res;
164
+ try {
165
+ res = await fetchFor(client)(url, {
166
+ method: call.method,
167
+ headers,
168
+ body,
169
+ signal: limit.signal,
170
+ });
171
+ }
172
+ catch (err) {
173
+ throw limit.error(err, `${call.method} ${shownUrl(url)}`, 'unavailable');
174
+ }
175
+ try {
176
+ return await read(res);
177
+ }
178
+ catch (err) {
179
+ if (err instanceof CallError)
180
+ throw err;
181
+ throw limit.error(err, 'reading the answer', 'unavailable');
182
+ }
183
+ }
184
+ finally {
185
+ limit.done();
186
+ }
187
+ }
188
+ }
189
+ /**
190
+ * The service named `name`, looked up on the first call that needs it. For
191
+ * the generated code: it may change with the generator.
192
+ *
193
+ * @hidden
194
+ */
195
+ export function service(name) {
196
+ return new Service(name);
197
+ }
198
+ /** The base URL Encore gives `name`: the services module, and with it the
199
+ * runtime, is loaded only now, so a client given a `baseUrl` runs without
200
+ * Encore. */
201
+ async function lookup(name) {
202
+ try {
203
+ const services = await import('../../services/index.js');
204
+ return services.baseUrl(name);
205
+ }
206
+ catch (err) {
207
+ throw failure('unavailable', `encore: no base URL is known for service ${JSON.stringify(name)}: ${errorText(err)}`, err);
208
+ }
209
+ }
210
+ /** `url` as an error shows it: without its query, fragment or credentials,
211
+ * which may hold secrets, as an error that escapes a handler is logged. */
212
+ function shownUrl(url) {
213
+ return url
214
+ .replace(/[?#].*$/s, '')
215
+ .replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/@]*@/i, '$1');
216
+ }
217
+ /** A parameter's text: a structured one as JSON. */
218
+ function paramText(value) {
219
+ return typeof value === 'object' ? JSON.stringify(value) : String(value);
220
+ }
221
+ /** The error a GraphQL answer with `errors` in it is. */
222
+ function graphqlError(errors, status) {
223
+ const list = (Array.isArray(errors) ? errors : [errors]).map(e => typeof e === 'object' && e !== null && !Array.isArray(e)
224
+ ? e
225
+ : { message: JSON.stringify(e) });
226
+ const first = list[0]?.extensions?.['code'];
227
+ const lower = typeof first === 'string' ? first.toLowerCase() : undefined;
228
+ const code = isErrCode(lower) ? lower : 'unknown';
229
+ const message = list
230
+ .map(e => (typeof e.message === 'string' ? e.message : ''))
231
+ .join('; ');
232
+ return new CallError(code, message, {
233
+ status: status >= 400 ? status : httpStatus(code),
234
+ graphqlErrors: list,
235
+ });
236
+ }
237
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../internal/clients/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,SAAS,EACT,WAAW,EACX,QAAQ,EACR,SAAS,EACT,SAAS,EACT,OAAO,EACP,QAAQ,EACR,UAAU,EACV,SAAS,GAKV,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,SAAS,GAIV,MAAM,QAAQ,CAAC;AAwBhB;;;;;;GAMG;AACH,MAAM,OAAO,OAAO;IAIG;IAHrB,oCAAoC;IAC5B,IAAI,CAA8B;IAE1C,YAAqB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAErC;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,MAAqB;QACjC,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC5E,mDAAmD;QACnD,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACrD,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;YACtB,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,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AS,CAAC;IAC3D,MAAM,OAAO,GAAG,IAAI;SACjB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE;QAClC,MAAM,EAAE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;QACjD,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The `fetch` of `@encore.dev/sdk/services`, which sends the app's services
3
+ * the trace and Request Context: apart from the module looking services up,
4
+ * so what sends calls loads without the runtime, as a generated client
5
+ * pointed at a mock server does.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * The global `fetch`, carrying the trace and Request Context of the active
11
+ * context to the app's services.
12
+ *
13
+ * A request for one of the app's services gets the active context's Request
14
+ * Context fields, in place of any its headers carried, and the active span's
15
+ * W3C `traceparent` and `tracestate`, unless it carries a `traceparent`
16
+ * already, as an instrumented client's does: Encore records the call's span
17
+ * where it reaches the service. A request to anything else goes without any
18
+ * Request Context headers, even those copied from a request the service
19
+ * received.
20
+ *
21
+ * A request is for the app's services when its URL is at the origin of a
22
+ * base URL `baseUrl`, `serviceUrl` or `client` of `@encore.dev/sdk/services`
23
+ * returned in this process, as every service URL is made from one.
24
+ *
25
+ * A request made in a context with a trace or Request Context follows its
26
+ * redirects here, rather than in the global `fetch`, so that each is sent
27
+ * what its own URL is due: a redirect away from the app's services carries
28
+ * no Request Context, and one to them carries the context's. It follows them
29
+ * by fetch's own rules for each status, and its response's `url` and
30
+ * `redirected` say where it ended. A `Request`'s body is streamed, not read
31
+ * first, so a 307 or 308 that would send it again fails, as fetch's does for
32
+ * a streamed body.
33
+ *
34
+ * @example
35
+ * import {fetch} from "@encore.dev/sdk/services";
36
+ * const res = await fetch(`${baseUrl("orders")}/orders/1`);
37
+ */
38
+ export declare const fetch: typeof globalThis.fetch;
39
+ /**
40
+ * `base`, sending the trace and Request Context of the active context to the
41
+ * app's services as {@link fetch} does: for a `fetch` of the app's own, as an
42
+ * instrumented or retrying one. Without `base`, the global `fetch`, looked up
43
+ * at each call.
44
+ *
45
+ * @example
46
+ * import {wrapFetch} from "@encore.dev/sdk/services";
47
+ * const tracedFetch = wrapFetch(instrumentedFetch);
48
+ */
49
+ export declare function wrapFetch(base?: typeof globalThis.fetch): typeof globalThis.fetch;
50
+ /** Records `base`, a service's base URL looked up in this process, as one
51
+ * of the app's services': a request for its origin is sent the trace and
52
+ * Request Context. */
53
+ export declare function recordOrigin(base: string): void;
54
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../internal/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,KAAK,EAAE,OAAO,UAAU,CAAC,KAAmB,CAAC;AAE1D;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CACvB,IAAI,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,GAC7B,OAAO,UAAU,CAAC,KAAK,CAiBzB;AA4BD;;sBAEsB;AACtB,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAG/C"}
@@ -0,0 +1,240 @@
1
+ /**
2
+ * The `fetch` of `@encore.dev/sdk/services`, which sends the app's services
3
+ * the trace and Request Context: apart from the module looking services up,
4
+ * so what sends calls loads without the runtime, as a generated client
5
+ * pointed at a mock server does.
6
+ *
7
+ * @module
8
+ */
9
+ import { isSpanContextValid, trace } from '@opentelemetry/api';
10
+ import { activeContext } from './otel/context.js';
11
+ import { W3CPropagator } from './otel/propagator.js';
12
+ import * as reqfields from './reqfields.js';
13
+ /**
14
+ * The global `fetch`, carrying the trace and Request Context of the active
15
+ * context to the app's services.
16
+ *
17
+ * A request for one of the app's services gets the active context's Request
18
+ * Context fields, in place of any its headers carried, and the active span's
19
+ * W3C `traceparent` and `tracestate`, unless it carries a `traceparent`
20
+ * already, as an instrumented client's does: Encore records the call's span
21
+ * where it reaches the service. A request to anything else goes without any
22
+ * Request Context headers, even those copied from a request the service
23
+ * received.
24
+ *
25
+ * A request is for the app's services when its URL is at the origin of a
26
+ * base URL `baseUrl`, `serviceUrl` or `client` of `@encore.dev/sdk/services`
27
+ * returned in this process, as every service URL is made from one.
28
+ *
29
+ * A request made in a context with a trace or Request Context follows its
30
+ * redirects here, rather than in the global `fetch`, so that each is sent
31
+ * what its own URL is due: a redirect away from the app's services carries
32
+ * no Request Context, and one to them carries the context's. It follows them
33
+ * by fetch's own rules for each status, and its response's `url` and
34
+ * `redirected` say where it ended. A `Request`'s body is streamed, not read
35
+ * first, so a 307 or 308 that would send it again fails, as fetch's does for
36
+ * a streamed body.
37
+ *
38
+ * @example
39
+ * import {fetch} from "@encore.dev/sdk/services";
40
+ * const res = await fetch(`${baseUrl("orders")}/orders/1`);
41
+ */
42
+ export const fetch = wrapFetch();
43
+ /**
44
+ * `base`, sending the trace and Request Context of the active context to the
45
+ * app's services as {@link fetch} does: for a `fetch` of the app's own, as an
46
+ * instrumented or retrying one. Without `base`, the global `fetch`, looked up
47
+ * at each call.
48
+ *
49
+ * @example
50
+ * import {wrapFetch} from "@encore.dev/sdk/services";
51
+ * const tracedFetch = wrapFetch(instrumentedFetch);
52
+ */
53
+ export function wrapFetch(base) {
54
+ const send = base ?? ((input, init) => globalThis.fetch(input, init));
55
+ return withMembersOfGlobalFetch(async (input, init) => {
56
+ const request = input instanceof Request ? input : undefined;
57
+ const url = request?.url ?? String(input);
58
+ const headers = new Headers(init?.headers ?? request?.headers);
59
+ const ctx = activeContext();
60
+ prepare(url, headers, ctx);
61
+ const redirect = init?.redirect ?? request?.redirect ?? 'follow';
62
+ if (!hasContext(ctx) || redirect !== 'follow') {
63
+ return send(input, { ...init, headers });
64
+ }
65
+ return followRedirects(send, url, initOf(request, init), headers, ctx);
66
+ }, base ?? globalThis.fetch);
67
+ }
68
+ /** `fn` with the members `base` has besides its call, as Bun's global
69
+ * `preconnect`, so it is a `typeof fetch` wherever the global is. */
70
+ function withMembersOfGlobalFetch(fn, base) {
71
+ const global = base;
72
+ const out = fn;
73
+ for (const key of Object.getOwnPropertyNames(global)) {
74
+ if (!(key in out))
75
+ out[key] = global[key];
76
+ }
77
+ return fn;
78
+ }
79
+ /** The origins of the base URLs looked up in this process: where the app's
80
+ * services are reached. Every service URL is the egress endpoint's, or
81
+ * locally the run proxy's, plus the service's path; nothing else is served
82
+ * at either. */
83
+ const origins = new Set();
84
+ /** Records `base`, a service's base URL looked up in this process, as one
85
+ * of the app's services': a request for its origin is sent the trace and
86
+ * Request Context. */
87
+ export function recordOrigin(base) {
88
+ const origin = originOf(base);
89
+ if (origin !== undefined)
90
+ origins.add(origin);
91
+ }
92
+ const DEFAULT_PORTS = { 'http:': '80', 'https:': '443' };
93
+ /** `url`'s scheme, host and port, with the scheme's default port when it
94
+ * has none; `undefined` when it is not a URL. */
95
+ function originOf(url) {
96
+ let u;
97
+ try {
98
+ u = new URL(url);
99
+ }
100
+ catch {
101
+ return undefined;
102
+ }
103
+ if (u.hostname === '')
104
+ return undefined;
105
+ const port = u.port || DEFAULT_PORTS[u.protocol] || '';
106
+ return `${u.protocol}//${u.hostname}:${port}`;
107
+ }
108
+ const w3c = new W3CPropagator();
109
+ const setter = { set: (h, k, v) => h.set(k, v) };
110
+ /**
111
+ * Sets the trace and Request Context of `ctx` on a request to `url`: drops
112
+ * the Request Context headers it carried, then, when it is for one of the
113
+ * app's services, sets the context's fields and, unless it carries one, its
114
+ * `traceparent`.
115
+ */
116
+ function prepare(url, headers, ctx) {
117
+ if (!origins.has(originOf(url) ?? '')) {
118
+ const stale = [];
119
+ headers.forEach((_, name) => {
120
+ if (name.toLowerCase().startsWith(reqfields.HEADER_PREFIX))
121
+ stale.push(name);
122
+ });
123
+ for (const name of stale)
124
+ headers.delete(name);
125
+ return;
126
+ }
127
+ reqfields.toHeaders(headers, ctx);
128
+ const span = trace.getSpanContext(ctx);
129
+ if (!headers.has('traceparent') && span && isSpanContextValid(span)) {
130
+ // A tracestate the request carried belongs to another trace's
131
+ // traceparent: the span's own, with Encore's mark, replaces it.
132
+ headers.delete('tracestate');
133
+ w3c.inject(ctx, headers, setter);
134
+ }
135
+ }
136
+ /** Whether `ctx` holds a trace or Request Context to send. */
137
+ function hasContext(ctx) {
138
+ const span = trace.getSpanContext(ctx);
139
+ return ((span !== undefined && isSpanContextValid(span)) ||
140
+ Object.keys(reqfields.current(ctx)).length > 0);
141
+ }
142
+ /** The statuses a redirect is answered with. */
143
+ const REDIRECTS = new Set([301, 302, 303, 307, 308]);
144
+ /** As many redirects as fetch follows. */
145
+ const MAX_REDIRECTS = 20;
146
+ /** The headers that describe a body, dropped with it. */
147
+ const BODY_HEADERS = [
148
+ 'content-encoding',
149
+ 'content-language',
150
+ 'content-location',
151
+ 'content-type',
152
+ 'content-length',
153
+ ];
154
+ /** The headers a redirect to another origin drops, as fetch does. */
155
+ const CREDENTIAL_HEADERS = ['authorization', 'cookie', 'proxy-authorization'];
156
+ /** `init` with what `request`, if any, says and `init` does not. Its body
157
+ * is streamed, not read first: a redirect that would send it again fails, as
158
+ * fetch's does for a streamed body. */
159
+ function initOf(request, init) {
160
+ if (request === undefined)
161
+ return { ...init };
162
+ const out = {
163
+ method: request.method,
164
+ signal: request.signal,
165
+ credentials: request.credentials,
166
+ keepalive: request.keepalive,
167
+ body: init?.body === undefined ? request.body : undefined,
168
+ };
169
+ // The fetch policies a Request has where the runtime has them: Node's and
170
+ // Bun's types disagree on which.
171
+ const policies = request;
172
+ for (const key of POLICIES) {
173
+ if (policies[key] !== undefined)
174
+ out[key] = policies[key];
175
+ }
176
+ // An option set to `undefined` is not given, as fetch takes it.
177
+ for (const [key, value] of Object.entries(init ?? {})) {
178
+ if (value !== undefined)
179
+ out[key] = value;
180
+ }
181
+ return out;
182
+ }
183
+ /** The fetch policies of a Request a redirect followed here keeps. */
184
+ const POLICIES = ['cache', 'integrity', 'mode', 'referrer', 'referrerPolicy'];
185
+ /** `res`, the answer to the last of a request's redirects, at `url`, saying
186
+ * so as fetch's own would. */
187
+ function redirected(res, url) {
188
+ return Object.defineProperties(res, {
189
+ url: { value: url, enumerable: true },
190
+ redirected: { value: true, enumerable: true },
191
+ });
192
+ }
193
+ /**
194
+ * Sends a request and follows the redirects it is answered with, as fetch's
195
+ * `redirect: "follow"` does, preparing the headers of each for its own URL
196
+ * in `ctx`, the context the call was made in.
197
+ */
198
+ async function followRedirects(send, url, init, headers, ctx) {
199
+ let method = (init.method ?? 'GET').toUpperCase();
200
+ let body = init.body ?? null;
201
+ for (let redirects = 0;; redirects++) {
202
+ const res = await send(url, {
203
+ ...init,
204
+ method,
205
+ body,
206
+ headers,
207
+ redirect: 'manual',
208
+ // Node sends a streamed body only half-duplex, and says so.
209
+ ...(body instanceof ReadableStream ? { duplex: 'half' } : {}),
210
+ });
211
+ const location = res.headers.get('location');
212
+ if (!REDIRECTS.has(res.status) || location === null) {
213
+ return redirects === 0 ? res : redirected(res, url);
214
+ }
215
+ if (redirects === MAX_REDIRECTS) {
216
+ await res.body?.cancel();
217
+ throw new TypeError(`fetch failed: more than ${MAX_REDIRECTS} redirects`);
218
+ }
219
+ const next = new URL(location, url).href;
220
+ if (((res.status === 301 || res.status === 302) && method === 'POST') ||
221
+ (res.status === 303 && method !== 'GET' && method !== 'HEAD')) {
222
+ method = 'GET';
223
+ body = null;
224
+ for (const name of BODY_HEADERS)
225
+ headers.delete(name);
226
+ }
227
+ else if (body instanceof ReadableStream) {
228
+ await res.body?.cancel();
229
+ throw new TypeError('fetch failed: a redirect cannot send a streamed body again');
230
+ }
231
+ if (originOf(next) !== originOf(url)) {
232
+ for (const name of CREDENTIAL_HEADERS)
233
+ headers.delete(name);
234
+ }
235
+ await res.body?.cancel();
236
+ url = next;
237
+ prepare(url, headers, ctx);
238
+ }
239
+ }
240
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../internal/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAC,kBAAkB,EAAE,KAAK,EAAe,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,KAAK,GAA4B,SAAS,EAAE,CAAC;AAE1D;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CACvB,IAA8B;IAE9B,MAAM,IAAI,GAAS,IAAI,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAC5E,OAAO,wBAAwB,CAC7B,KAAK,EAAE,KAA6B,EAAE,IAAkB,EAAE,EAAE;QAC1D,MAAM,OAAO,GAAG,KAAK,YAAY,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7D,MAAM,GAAG,GAAG,OAAO,EAAE,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/D,MAAM,GAAG,GAAG,aAAa,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,C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CAAC,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,MAAM,CAAC,EAC7D,CAAC;YACD,MAAM,GAAG,KAAK,CAAC;YACf,IAAI,GAAG,IAAI,CAAC;YACZ,KAAK,MAAM,IAAI,IAAI,YAAY;gBAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC;aAAM,IAAI,IAAI,YAAY,cAAc,EAAE,CAAC;YAC1C,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;YACzB,MAAM,IAAI,SAAS,CACjB,4DAA4D,CAC7D,CAAC;QACJ,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACrC,KAAK,MAAM,IAAI,IAAI,kBAAkB;gBAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QACzB,GAAG,GAAG,IAAI,CAAC;QACX,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC"}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  /** The runtime's span calls (the napi `Pipeline` class). */
3
4
  export interface Backend {
4
5
  /** `parent`: 25-byte context. `packed`: start scope, attributes, and
@@ -48,3 +49,4 @@ export interface MeterBackend {
48
49
  /** Adds this thread's collector, called once per collection. */
49
50
  addCollector(collect: (reply: CollectReply) => void): void;
50
51
  }
52
+ //# sourceMappingURL=backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../../internal/otel/backend.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,MAAM,WAAW,OAAO;IACtB;6EACyE;IACzE,SAAS,CACP,IAAI,EAAE,MAA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AgE;AAChE,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,gBAAgB,CAAC;IACtD,gEAAgE;IAChE,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;CAC5D"}
@@ -8,3 +8,4 @@ export declare function activeContext(): Context;
8
8
  /** Runs `fn` with `ctx` active, in Encore's context manager too when it is
9
9
  * not the global. */
10
10
  export declare function withContext<T>(ctx: Context, fn: () => T): T;
11
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../internal/otel/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,OAAO,EACb,MAAM,oBAAoB,CAAC;AAoB5B;2EAC2E;AAC3E,wBAAgB,qBAAqB,IAAI,OAAO,CAK/C;AAED;4CAC4C;AAC5C,wBAAgB,aAAa,IAAI,OAAO,CAGvC;AAED;qBACqB;AACrB,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAI3D"}
@@ -20,3 +20,4 @@ export declare class ContextManager implements ApiContextManager {
20
20
  enable(): this;
21
21
  disable(): this;
22
22
  }
23
+ //# sourceMappingURL=context_manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context_manager.d.ts","sourceRoot":"","sources":["../../../internal/otel/context_manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,cAAc,IAAI,iBAAiB,EACzC,MAAM,oBAAoB,CAAC;AAgB5B;gBACgB;AAChB,qBAAa,cAAe,YAAW,iBAAiB;IACtD,OAAO,CAAC,GAAG,CAAoC;IAC/C,yCAAyC;IACzC,OAAO,CAAC,OAAO,CAAyC;IACxD;8CAC0C;IAC1C,OAAO,CAAC,MAAM,CAAS;IAEvB,MAAM,IAAI,OAAO;IAIjB,IAAI,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAC/D,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE,CAAC,EACL,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC9B,GAAG,IAAI,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,CAAC;IAKhB;2EACuE;IACvE,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC;IAiBnC,OAAO,CAAC,WAAW;IAsBnB,OAAO,CAAC,QAAQ;IAuBhB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,cAAc;IAYtB,MAAM,IAAI,IAAI;IAId,OAAO,IAAI,IAAI;CAIhB"}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import type { Attributes, Link, SpanContext, TimeInput } from '@opentelemetry/api';
3
4
  export declare const VERSION = 1;
4
5
  export declare const HEADER_LEN = 120;
@@ -110,3 +111,4 @@ export declare function isTimeInput(t: unknown): t is TimeInput;
110
111
  * the OTel SDK. */
111
112
  export declare function timeToUnixNanos(t: TimeInput): bigint;
112
113
  export {};
114
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../internal/otel/encode.ts"],"names":[],"mappings":";;AAGA,OAAO,KAAK,EACV,UAAU,EAEV,IAAI,EACJ,WAAW,EACX,SAAS,EACV,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,OAAO,IAAI,CAAC;AACzB,eAAO,MAAM,UAAU,MAAM,CAAC;AAC9B,eAAO,MAAM,QAAQ,KAAK,CAAC;AAC3B,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,M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;AAYD,yEAAyE;AACzE,wBAAgB,WAAW,CACzB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,UAAU,GAAG,SAAS,EAC7B,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,SAAS,GACjC,MAAM,CAIR;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,0CAA0C;AAC1C,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IAC/B,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CACxB;AAED,yCAAyC;AACzC,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAKrD;AAKD,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAWD,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,SAAS,CAEtD;AAOD;;mBAEmB;AACnB,wBAAgB,eAAe,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAKpD"}
@@ -4,6 +4,6 @@ export { ContextManager } from './context_manager.js';
4
4
  export { W3CPropagator, formatTraceparent, parseTraceparent } from './propagator.js';
5
5
  export { Meter, MeterProvider } from './meter.js';
6
6
  export { TracerProvider } from './provider.js';
7
- export { activeCtxBytes, ENCORE_REQUEST_KEY, getRequestFromContext, withRequestContext, } from './request_context.js';
8
- export { Span } from './span.js';
7
+ export { activeCtxBytes, Span } from './span.js';
9
8
  export { Tracer } from './tracer.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../internal/otel/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAC,aAAa,EAAE,qBAAqB,EAAE,WAAW,EAAC,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAChF,OAAO,EAAC,KAAK,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAE,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC"}
@@ -3,7 +3,6 @@ export { ContextManager } from './context_manager.js';
3
3
  export { W3CPropagator, formatTraceparent, parseTraceparent } from './propagator.js';
4
4
  export { Meter, MeterProvider } from './meter.js';
5
5
  export { TracerProvider } from './provider.js';
6
- export { activeCtxBytes, ENCORE_REQUEST_KEY, getRequestFromContext, withRequestContext, } from './request_context.js';
7
- export { Span } from './span.js';
6
+ export { activeCtxBytes, Span } from './span.js';
8
7
  export { Tracer } from './tracer.js';
9
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../internal/otel/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,aAAa,EAAE,qBAAqB,EAAE,WAAW,EAAC,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAChF,OAAO,EAAC,KAAK,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../internal/otel/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,aAAa,EAAE,qBAAqB,EAAE,WAAW,EAAC,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAChF,OAAO,EAAC,KAAK,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAE,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC"}