@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,147 @@
1
+ /**
2
+ * The errors and options of the service clients Encore generates, which
3
+ * `@encore.dev/sdk/services` exports, and what the clients' calls share to
4
+ * make and limit one.
5
+ *
6
+ * @module
7
+ */
8
+ /// <reference types="node" />
9
+ /// <reference types="node" />
10
+ /** The code of a failed call: what went wrong, as Encore's errors say. */
11
+ export type ErrCode = 'canceled' | 'unknown' | 'invalid_argument' | 'deadline_exceeded' | 'not_found' | 'already_exists' | 'permission_denied' | 'resource_exhausted' | 'failed_precondition' | 'aborted' | 'out_of_range' | 'unimplemented' | 'internal' | 'unavailable' | 'data_loss' | 'unauthenticated';
12
+ /** The HTTP status Encore answers `code` with: 404 for `not_found`. */
13
+ export declare function httpStatus(code: ErrCode): number;
14
+ /** Whether `code` is one of the codes. */
15
+ export declare function isErrCode(code: unknown): code is ErrCode;
16
+ /** One error of a GraphQL answer, as the service sent it. */
17
+ export interface GraphQLError {
18
+ message: string;
19
+ path?: (string | number)[];
20
+ locations?: {
21
+ line: number;
22
+ column: number;
23
+ }[];
24
+ extensions?: Record<string, unknown>;
25
+ }
26
+ /**
27
+ * A call to another service that failed: an error answer, or none at all.
28
+ *
29
+ * `err instanceof CallError` knows one from any copy of this package, as a
30
+ * monorepo with two versions of it installed has, not only from its own.
31
+ */
32
+ export declare class CallError extends Error {
33
+ /**
34
+ * The failure's code: the one the service answered with, in Encore's
35
+ * error body or as its gRPC status; `unavailable` when no answer came;
36
+ * `deadline_exceeded` when the call took longer than its timeout;
37
+ * `canceled` when its signal aborted it; else the one the answer's HTTP
38
+ * status means, as `not_found` for 404.
39
+ */
40
+ readonly code: ErrCode;
41
+ /**
42
+ * The HTTP status of the service's answer: the answer's own, when it was
43
+ * an error status, else (a gRPC or GraphQL error) the one Encore answers
44
+ * {@link code} with. 0 when the call got no answer, or failed before it
45
+ * was sent.
46
+ */
47
+ readonly status: number;
48
+ /**
49
+ * A GraphQL answer's errors, as it sent them. Empty for any other
50
+ * failure. Its code is the first error's `extensions.code` when that is
51
+ * one of Encore's codes, and `unknown` otherwise.
52
+ */
53
+ readonly graphqlErrors: GraphQLError[];
54
+ /**
55
+ * The service's answer with `code` and `message`, and the HTTP status
56
+ * Encore answers `code` with unless `options` says another: as a mock of
57
+ * a call throws one.
58
+ */
59
+ constructor(code: ErrCode, message: string, options?: {
60
+ status?: number;
61
+ graphqlErrors?: GraphQLError[];
62
+ cause?: unknown;
63
+ });
64
+ /**
65
+ * Whether `value` is a CallError: one of this copy of the package, or of
66
+ * another, known by its name and code.
67
+ */
68
+ static [Symbol.hasInstance](value: unknown): value is CallError;
69
+ }
70
+ /**
71
+ * The error of a call that failed before or without an answer: with `code`
72
+ * and `message`, what the client saw, and no status.
73
+ */
74
+ export declare function failure(code: ErrCode, message: string, cause?: unknown): CallError;
75
+ /**
76
+ * The headers of a call made with `client` and `options`, the call's over
77
+ * its client's, and `more` over both. Throws an `invalid_argument`
78
+ * {@link CallError} for one no request can carry.
79
+ */
80
+ export declare function callHeaders(client: ClientOptions, options: CallOptions | undefined, more?: Iterable<[string, string]>): Headers;
81
+ /** The settings of one call, which go over its client's. */
82
+ export interface CallOptions {
83
+ /** A limit on the call, in milliseconds, in place of its client's: `null`
84
+ * lifts the client's, leaving the call no limit but its signal. */
85
+ timeout?: number | null;
86
+ /** Headers sent with the call, over its client's. */
87
+ headers?: Record<string, string>;
88
+ /** Aborts the call: it then fails with `canceled`. */
89
+ signal?: AbortSignal;
90
+ }
91
+ /** The settings of a client, for every call made with it. */
92
+ export interface ClientOptions {
93
+ /**
94
+ * In place of the base URL Encore gives the service, as a mock server's.
95
+ * A client with one never looks the service up. Its calls carry the
96
+ * Request Context only to the origin the app's services are reached at,
97
+ * where Encore serves nothing else: a mock server's carry none.
98
+ */
99
+ baseUrl?: string;
100
+ /** A limit on each call, in milliseconds, unless the call sets its own. */
101
+ timeout?: number;
102
+ /** Sent with every call, under the call's own. */
103
+ headers?: Record<string, string>;
104
+ /**
105
+ * Sends the calls in place of the global `fetch`, as an instrumented or
106
+ * retrying one: it is wrapped as `@encore.dev/sdk/services`' `wrapFetch`
107
+ * wraps it, so the calls still carry their context.
108
+ */
109
+ fetch?: typeof globalThis.fetch;
110
+ }
111
+ /**
112
+ * What `call` resolves to, or `undefined` when it fails with a
113
+ * {@link CallError} whose code is `not_found`: for a call for something that
114
+ * may not be there. Any other failure is thrown as it is.
115
+ *
116
+ * ```ts
117
+ * const product = await unlessNotFound(catalog.openapi.getProduct("xyz"));
118
+ * ```
119
+ */
120
+ export declare function unlessNotFound<T>(call: Promise<T>): Promise<T | undefined>;
121
+ /** The `fetch` `client`'s calls are sent with: its own, or the global
122
+ * one, wrapped to carry the context. */
123
+ export declare function fetchFor(client: ClientOptions): typeof globalThis.fetch;
124
+ /**
125
+ * The limits of one call: its timeout and its signal, and the error a call
126
+ * they ended failed with.
127
+ */
128
+ export interface Deadline {
129
+ /** Aborts the call: undefined when nothing limits it. */
130
+ readonly signal: AbortSignal | undefined;
131
+ /** The call's timeout, in milliseconds, if it has one. */
132
+ readonly timeout: number | undefined;
133
+ /** The error `err`, which the call failed with doing `what`, is: the
134
+ * timeout's or the signal's when either ended it, else `code`'s. */
135
+ error(err: unknown, what: string, code: ErrCode): CallError;
136
+ /** Ends the timeout. */
137
+ done(): void;
138
+ }
139
+ /** The limits of a call made with `client` and `options`. */
140
+ export declare function deadline(client: ClientOptions, options: CallOptions | undefined): Deadline;
141
+ export declare function errorText(err: unknown): string;
142
+ /**
143
+ * The error an error answer with body `text` is: the code and message of
144
+ * Encore's error body, else those its status means.
145
+ */
146
+ export declare function errorBody(res: Response, text: string): CallError;
147
+ //# sourceMappingURL=call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../../../internal/clients/call.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;;AAIH,0EAA0E;AAC1E,MAAM,MAAM,OAAO,GACf,UAAU,GACV,SAAS,GACT,kBAAkB,GAClB,mBAAmB,GACnB,WAAW,GACX,gBAAgB,GAChB,mBAAmB,GACnB,oBAAoB,GACpB,qBAAqB,GACrB,SAAS,GACT,cAAc,GACd,eAAe,GACf,UAAU,GACV,aAAa,GACb,WAAW,GACX,iBAAiB,CAAC;AAsBtB,uEAAuE;AACvE,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,0CAA0C;AAC1C,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,OAAO,CAExD;AAED,6DAA6D;AAC7D,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,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,MAAM,GAAG,SAAS,CAuBhE"}
@@ -0,0 +1,274 @@
1
+ /**
2
+ * The errors and options of the service clients Encore generates, which
3
+ * `@encore.dev/sdk/services` exports, and what the clients' calls share to
4
+ * make and limit one.
5
+ *
6
+ * @module
7
+ */
8
+ import { fetch as servicesFetch, wrapFetch } from '../fetch.js';
9
+ /** Each code, with the HTTP status Encore answers it with. */
10
+ const STATUS = {
11
+ canceled: 499,
12
+ unknown: 500,
13
+ invalid_argument: 400,
14
+ deadline_exceeded: 504,
15
+ not_found: 404,
16
+ already_exists: 409,
17
+ permission_denied: 403,
18
+ resource_exhausted: 429,
19
+ failed_precondition: 400,
20
+ aborted: 409,
21
+ out_of_range: 400,
22
+ unimplemented: 501,
23
+ internal: 500,
24
+ unavailable: 503,
25
+ data_loss: 500,
26
+ unauthenticated: 401,
27
+ };
28
+ /** The HTTP status Encore answers `code` with: 404 for `not_found`. */
29
+ export function httpStatus(code) {
30
+ return STATUS[code];
31
+ }
32
+ /** Whether `code` is one of the codes. */
33
+ export function isErrCode(code) {
34
+ return typeof code === 'string' && Object.hasOwn(STATUS, code);
35
+ }
36
+ /**
37
+ * A call to another service that failed: an error answer, or none at all.
38
+ *
39
+ * `err instanceof CallError` knows one from any copy of this package, as a
40
+ * monorepo with two versions of it installed has, not only from its own.
41
+ */
42
+ export class CallError extends Error {
43
+ /**
44
+ * The failure's code: the one the service answered with, in Encore's
45
+ * error body or as its gRPC status; `unavailable` when no answer came;
46
+ * `deadline_exceeded` when the call took longer than its timeout;
47
+ * `canceled` when its signal aborted it; else the one the answer's HTTP
48
+ * status means, as `not_found` for 404.
49
+ */
50
+ code;
51
+ /**
52
+ * The HTTP status of the service's answer: the answer's own, when it was
53
+ * an error status, else (a gRPC or GraphQL error) the one Encore answers
54
+ * {@link code} with. 0 when the call got no answer, or failed before it
55
+ * was sent.
56
+ */
57
+ status;
58
+ /**
59
+ * A GraphQL answer's errors, as it sent them. Empty for any other
60
+ * failure. Its code is the first error's `extensions.code` when that is
61
+ * one of Encore's codes, and `unknown` otherwise.
62
+ */
63
+ graphqlErrors;
64
+ /**
65
+ * The service's answer with `code` and `message`, and the HTTP status
66
+ * Encore answers `code` with unless `options` says another: as a mock of
67
+ * a call throws one.
68
+ */
69
+ constructor(code, message, options) {
70
+ super(message, options?.cause === undefined ? undefined : { cause: options.cause });
71
+ this.code = code;
72
+ this.status = options?.status ?? httpStatus(code);
73
+ this.graphqlErrors = options?.graphqlErrors ?? [];
74
+ // Not enumerable, as an Error's own name.
75
+ Object.defineProperty(this, 'name', {
76
+ value: 'CallError',
77
+ enumerable: false,
78
+ configurable: true,
79
+ });
80
+ }
81
+ /**
82
+ * Whether `value` is a CallError: one of this copy of the package, or of
83
+ * another, known by its name and code.
84
+ */
85
+ static [Symbol.hasInstance](value) {
86
+ if (Function.prototype[Symbol.hasInstance].call(this, value))
87
+ return true;
88
+ return (this === CallError &&
89
+ value instanceof Error &&
90
+ value.name === 'CallError' &&
91
+ isErrCode(value.code));
92
+ }
93
+ }
94
+ /**
95
+ * The error of a call that failed before or without an answer: with `code`
96
+ * and `message`, what the client saw, and no status.
97
+ */
98
+ export function failure(code, message, cause) {
99
+ return new CallError(code, message, { status: 0, cause });
100
+ }
101
+ /**
102
+ * The headers of a call made with `client` and `options`, the call's over
103
+ * its client's, and `more` over both. Throws an `invalid_argument`
104
+ * {@link CallError} for one no request can carry.
105
+ */
106
+ export function callHeaders(client, options, more = []) {
107
+ const headers = new Headers();
108
+ try {
109
+ for (const [name, value] of Object.entries(client.headers ?? {})) {
110
+ headers.set(name, value);
111
+ }
112
+ for (const [name, value] of Object.entries(options?.headers ?? {})) {
113
+ headers.set(name, value);
114
+ }
115
+ for (const [name, value] of more)
116
+ headers.set(name, value);
117
+ }
118
+ catch (err) {
119
+ throw failure('invalid_argument', `invalid header: ${errorText(err)}`, err);
120
+ }
121
+ return headers;
122
+ }
123
+ /**
124
+ * What `call` resolves to, or `undefined` when it fails with a
125
+ * {@link CallError} whose code is `not_found`: for a call for something that
126
+ * may not be there. Any other failure is thrown as it is.
127
+ *
128
+ * ```ts
129
+ * const product = await unlessNotFound(catalog.openapi.getProduct("xyz"));
130
+ * ```
131
+ */
132
+ export async function unlessNotFound(call) {
133
+ try {
134
+ return await call;
135
+ }
136
+ catch (err) {
137
+ if (err instanceof CallError && err.code === 'not_found')
138
+ return undefined;
139
+ throw err;
140
+ }
141
+ }
142
+ /** Each `fetch` of a client's, wrapped. */
143
+ const wrapped = new WeakMap();
144
+ /** The `fetch` `client`'s calls are sent with: its own, or the global
145
+ * one, wrapped to carry the context. */
146
+ export function fetchFor(client) {
147
+ if (client.fetch === undefined)
148
+ return servicesFetch;
149
+ let fetch = wrapped.get(client.fetch);
150
+ if (fetch === undefined) {
151
+ fetch = wrapFetch(client.fetch);
152
+ wrapped.set(client.fetch, fetch);
153
+ }
154
+ return fetch;
155
+ }
156
+ /** The limits of a call made with `client` and `options`. */
157
+ export function deadline(client, options) {
158
+ const timeout = options?.timeout === null
159
+ ? undefined
160
+ : (options?.timeout ?? client.timeout);
161
+ const user = options?.signal;
162
+ const timer = timeout === undefined ? undefined : new AbortController();
163
+ const handle = timer === undefined || timeout === undefined
164
+ ? undefined
165
+ : setTimeout(() => timer.abort(failure('deadline_exceeded', timedOut(timeout))), timeout);
166
+ let signal = user;
167
+ if (timer !== undefined) {
168
+ signal = user === undefined ? timer.signal : anySignal(user, timer.signal);
169
+ }
170
+ return {
171
+ signal,
172
+ timeout,
173
+ error(err, what, code) {
174
+ if (err instanceof CallError)
175
+ return err;
176
+ if (timer?.signal.aborted === true && timeout !== undefined) {
177
+ return failure('deadline_exceeded', timedOut(timeout), err);
178
+ }
179
+ if (user?.aborted === true) {
180
+ return failure('canceled', `${what}: the call was aborted`, err);
181
+ }
182
+ return failure(code, `${what}: ${errorText(err)}`, err);
183
+ },
184
+ done() {
185
+ if (handle !== undefined)
186
+ clearTimeout(handle);
187
+ },
188
+ };
189
+ }
190
+ function timedOut(timeout) {
191
+ return `the call took longer than its timeout of ${timeout}ms`;
192
+ }
193
+ /** A signal aborted when either `a` or `b` is, with its reason. */
194
+ function anySignal(a, b) {
195
+ if (typeof AbortSignal.any === 'function')
196
+ return AbortSignal.any([a, b]);
197
+ const both = new AbortController();
198
+ for (const s of [a, b]) {
199
+ if (s.aborted) {
200
+ both.abort(s.reason);
201
+ return both.signal;
202
+ }
203
+ s.addEventListener('abort', () => both.abort(s.reason), { once: true });
204
+ }
205
+ return both.signal;
206
+ }
207
+ export function errorText(err) {
208
+ if (err instanceof Error) {
209
+ // Node's fetch says only "fetch failed", and why in its cause.
210
+ const cause = err.cause instanceof Error ? `: ${err.cause.message}` : '';
211
+ return err.message + cause;
212
+ }
213
+ return String(err);
214
+ }
215
+ /**
216
+ * The error an error answer with body `text` is: the code and message of
217
+ * Encore's error body, else those its status means.
218
+ */
219
+ export function errorBody(res, text) {
220
+ let parsed;
221
+ try {
222
+ const value = JSON.parse(text);
223
+ if (typeof value === 'object' && value !== null) {
224
+ parsed = value;
225
+ }
226
+ }
227
+ catch {
228
+ parsed = undefined;
229
+ }
230
+ // In either case, as Go's client reads it.
231
+ const named = typeof parsed?.code === 'string' ? parsed.code.toLowerCase() : undefined;
232
+ const code = isErrCode(named) ? named : statusCode(res.status);
233
+ const message = typeof parsed?.message === 'string'
234
+ ? parsed.message
235
+ : text !== ''
236
+ ? text
237
+ : res.statusText;
238
+ return new CallError(code, message, {
239
+ status: res.status >= 400 ? res.status : httpStatus(code),
240
+ });
241
+ }
242
+ /** The code an error answer without Encore's error body means: as the
243
+ * other SDKs' generated clients read it. */
244
+ function statusCode(status) {
245
+ switch (status) {
246
+ case 400:
247
+ return 'invalid_argument';
248
+ case 401:
249
+ return 'unauthenticated';
250
+ case 403:
251
+ return 'permission_denied';
252
+ case 404:
253
+ return 'not_found';
254
+ case 408:
255
+ case 504:
256
+ return 'deadline_exceeded';
257
+ case 409:
258
+ return 'already_exists';
259
+ case 429:
260
+ return 'resource_exhausted';
261
+ case 499:
262
+ return 'canceled';
263
+ case 500:
264
+ return 'internal';
265
+ case 501:
266
+ return 'unimplemented';
267
+ case 502:
268
+ case 503:
269
+ return 'unavailable';
270
+ default:
271
+ return 'unknown';
272
+ }
273
+ }
274
+ //# sourceMappingURL=call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.js","sourceRoot":"","sources":["../../../internal/clients/call.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAC,KAAK,IAAI,aAAa,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AAqB3D,8DAA8D;AAC9D,MAAM,MAAM,GAA4B;IACtC,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;IACZ,gBAAgB,EAAE,GAAG;IACrB,iBAAiB,EAAE,GAAG;IACtB,SAAS,EAAE,GAAG;IACd,cAAc,EAAE,GAAG;IACnB,iBAAiB,EAAE,GAAG;IACtB,kBAAkB,EAAE,GAAG;IACvB,mBAAmB,EAAE,GAAG;IACxB,OAAO,EAAE,GAAG;IACZ,YAAY,EAAE,GAAG;IACjB,aAAa,EAAE,GAAG;IAClB,QAAQ,EAAE,GAAG;IACb,WAAW,EAAE,GAAG;IAChB,SAAS,EAAE,GAAG;IACd,eAAe,EAAE,GAAG;CACrB,CAAC;AAEF,uEAAuE;AACvE,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,SAAS,CAAC,IAAa;IACrC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC;AAUD;;;;;GAKG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC;;;;;;OAMG;IACM,IAAI,CAAU;IACvB;;;;;OAKG;IACM,MAAM,CAAS;IACxB;;;;OAIG;IACM,aAAa,CAAiB;IAEvC;;;;OAIG;IACH,YACE,IAA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QAChB,CAAC,CAAC,IAAI,KAAK,EAAE;YACX,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC;IACvB,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE;QAClC,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAED;4CAC4C;AAC5C,SAAS,UAAU,CAAC,MAAc;IAChC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,GAAG;YACN,OAAO,kBAAkB,CAAC;QAC5B,KAAK,GAAG;YACN,OAAO,iBAAiB,CAAC;QAC3B,KAAK,GAAG;YACN,OAAO,mBAAmB,CAAC;QAC7B,KAAK,GAAG;YACN,OAAO,WAAW,CAAC;QACrB,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,OAAO,mBAAmB,CAAC;QAC7B,KAAK,GAAG;YACN,OAAO,gBAAgB,CAAC;QAC1B,KAAK,GAAG;YACN,OAAO,oBAAoB,CAAC;QAC9B,KAAK,GAAG;YACN,OAAO,UAAU,CAAC;QACpB,KAAK,GAAG;YACN,OAAO,UAAU,CAAC;QACpB,KAAK,GAAG;YACN,OAAO,eAAe,CAAC;QACzB,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,OAAO,aAAa,CAAC;QACvB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Calls of the generated gRPC clients, over the Connect protocol. For the
3
+ * generated code: it may change with the generator.
4
+ *
5
+ * It needs `@bufbuild/protobuf` and `@connectrpc/connect`, optional peer
6
+ * dependencies of the SDK that a service with gRPC clients installs:
7
+ *
8
+ * ```sh
9
+ * npm install @bufbuild/protobuf@^2 @connectrpc/connect@^2.2
10
+ * ```
11
+ *
12
+ * Calls go through Connect's own transport for the Connect protocol, sent
13
+ * with the `fetch` of `@encore.dev/sdk/services`, so they carry the trace and Request Context of
14
+ * the context they are made in, over HTTP/1.1 as well as HTTP/2. A unary call
15
+ * returns a `Promise`; a server stream is an `AsyncIterable`. A client or
16
+ * bidirectional stream sends its requests as one streamed request body, and
17
+ * reads the answers after it: over HTTP/1.1, which has no full-duplex
18
+ * streams, a bidirectional stream's answers come once its requests are done.
19
+ * Every failure is a {@link CallError}, and a call's timeout is sent as its
20
+ * deadline.
21
+ *
22
+ * The peers are loaded, and a registry's descriptors decoded, by the first
23
+ * call, not on import: a module importing the generated clients loads
24
+ * without them, and with no top-level await, so `require()` loads it too. A
25
+ * call made without them fails saying what to install.
26
+ *
27
+ * @hidden
28
+ * @module
29
+ */
30
+ import type { DescService } from '@bufbuild/protobuf';
31
+ import { type CallOptions, type ClientOptions } from './call.js';
32
+ import type { Service } from './mod.js';
33
+ /** The packages the calls go through, loaded by the first call: a module
34
+ * that only imports the clients needs none of them, nor waits for them. */
35
+ interface Peers {
36
+ protobuf: typeof import('@bufbuild/protobuf');
37
+ wkt: typeof import('@bufbuild/protobuf/wkt');
38
+ wire: typeof import('@bufbuild/protobuf/wire');
39
+ connect: typeof import('@connectrpc/connect');
40
+ protocol: typeof import('@connectrpc/connect/protocol');
41
+ protocolConnect: typeof import('@connectrpc/connect/protocol-connect');
42
+ }
43
+ /**
44
+ * The services of an embedded descriptor set, decoded by the first call to
45
+ * one of them: a module holding one decodes nothing when imported.
46
+ */
47
+ export declare class Registry {
48
+ private readonly data;
49
+ /** The set, once decoded. */
50
+ private files;
51
+ constructor(data: string);
52
+ /** The service of fully-qualified name `typeName`, looked up by its first
53
+ * call. */
54
+ service(typeName: string): ServiceRef;
55
+ /** The service of fully-qualified name `typeName`. */
56
+ resolve(p: Peers, typeName: string): DescService;
57
+ }
58
+ /** A service of a {@link Registry}, by its name. */
59
+ export interface ServiceRef {
60
+ readonly registry: Registry;
61
+ readonly typeName: string;
62
+ }
63
+ /** The registry of `data`, a base64-encoded
64
+ * `google.protobuf.FileDescriptorSet`. */
65
+ export declare function registry(data: string): Registry;
66
+ /** The calls of one gRPC service of a service's, made with a client's
67
+ * settings. */
68
+ export declare class ServiceClient {
69
+ private readonly svc;
70
+ private readonly client;
71
+ private readonly ref;
72
+ constructor(svc: Service, client: ClientOptions, ref: ServiceRef);
73
+ /** Calls unary `method` with `request`. */
74
+ unary(method: string, request: unknown, options?: CallOptions): Promise<unknown>;
75
+ /** Calls server-streaming `method` with `request`: its answers. */
76
+ serverStream(method: string, request: unknown, options?: CallOptions): AsyncIterable<unknown>;
77
+ /** Calls client-streaming `method` with `requests`: its one answer. */
78
+ clientStream(method: string, requests: AsyncIterable<unknown>, options?: CallOptions): Promise<unknown>;
79
+ /** Calls bidirectional-streaming `method` with `requests`: its answers. */
80
+ bidiStream(method: string, requests: AsyncIterable<unknown>, options?: CallOptions): AsyncIterable<unknown>;
81
+ /** The answers `start` reads of `method`, under the call's limits,
82
+ * failing with a CallError. */
83
+ private answers;
84
+ private method;
85
+ private headers;
86
+ /** The transport of the service's base URL and the client's fetch. */
87
+ private transport;
88
+ }
89
+ export {};
90
+ //# sourceMappingURL=grpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc.d.ts","sourceRoot":"","sources":["../../../internal/clients/grpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAGV,WAAW,EAEZ,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,aAAa,EAGnB,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAkBnC;2EAC2E;AAC3E,UAAU,KAAK;IACb,QAAQ,EAAE,cAAc,oBAAoB,CAAC,CAAC;IAC9C,GAAG,EAAE,cAAc,wBAAwB,CAAC,CAAC;IAC7C,IAAI,EAAE,cAAc,yBAAyB,CAAC,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