@distilled.cloud/core 1.0.0-rc.2 → 1.0.0-rc.21

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 (321) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +33 -0
  3. package/lib/_bundle/aws.js +2 -0
  4. package/lib/_bundle/aws.js.map +1 -0
  5. package/lib/_bundle/base.js +5 -0
  6. package/lib/_bundle/base.js.map +1 -0
  7. package/lib/_bundle/graphql.js +3 -0
  8. package/lib/_bundle/graphql.js.map +1 -0
  9. package/lib/_bundle/grpc.js +3 -0
  10. package/lib/_bundle/grpc.js.map +1 -0
  11. package/lib/_bundle/rest.js +2 -0
  12. package/lib/_bundle/rest.js.map +1 -0
  13. package/lib/_bundle/xml.js +4 -0
  14. package/lib/_bundle/xml.js.map +1 -0
  15. package/lib/annotations.d.ts +17 -0
  16. package/lib/annotations.d.ts.map +1 -0
  17. package/lib/annotations.js +2 -0
  18. package/lib/annotations.js.map +1 -0
  19. package/lib/api.d.ts +220 -51
  20. package/lib/api.d.ts.map +1 -1
  21. package/lib/api.js +1 -178
  22. package/lib/category.d.ts +19 -16
  23. package/lib/category.d.ts.map +1 -1
  24. package/lib/category.js +1 -280
  25. package/lib/chunks.d.ts +3 -0
  26. package/lib/chunks.d.ts.map +1 -0
  27. package/lib/chunks.js +1 -0
  28. package/lib/config.d.ts +81 -0
  29. package/lib/config.d.ts.map +1 -0
  30. package/lib/config.js +1 -0
  31. package/lib/crypto.d.ts +76 -0
  32. package/lib/crypto.d.ts.map +1 -0
  33. package/lib/crypto.js +1 -0
  34. package/lib/error-category.d.ts +1 -1
  35. package/lib/error-category.d.ts.map +1 -1
  36. package/lib/error-category.js +1 -46
  37. package/lib/errors.d.ts +99 -74
  38. package/lib/errors.d.ts.map +1 -1
  39. package/lib/errors.js +1 -186
  40. package/lib/graphql.d.ts +420 -0
  41. package/lib/graphql.d.ts.map +1 -0
  42. package/lib/graphql.js +1 -0
  43. package/lib/graphql.types.d.ts +11 -0
  44. package/lib/graphql.types.d.ts.map +1 -0
  45. package/lib/graphql.types.js +1 -0
  46. package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
  47. package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
  48. package/lib/grpc-transport-cloudflare-http2.js +6 -0
  49. package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
  50. package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
  51. package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
  52. package/lib/grpc-transport-cloudflare-sockets.js +5 -0
  53. package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
  54. package/lib/grpc-transport-node-http2.d.ts +19 -0
  55. package/lib/grpc-transport-node-http2.d.ts.map +1 -0
  56. package/lib/grpc-transport-node-http2.js +2 -0
  57. package/lib/grpc-transport-node-http2.js.map +1 -0
  58. package/lib/grpc-transport.d.ts +111 -0
  59. package/lib/grpc-transport.d.ts.map +1 -0
  60. package/lib/grpc-transport.js +1 -0
  61. package/lib/hpack.d.ts +34 -0
  62. package/lib/hpack.d.ts.map +1 -0
  63. package/lib/hpack.js +2 -0
  64. package/lib/hpack.js.map +1 -0
  65. package/lib/index.d.ts +32 -0
  66. package/lib/index.d.ts.map +1 -0
  67. package/lib/index.js +17 -0
  68. package/lib/max-message-bytes.d.ts +42 -0
  69. package/lib/max-message-bytes.d.ts.map +1 -0
  70. package/lib/max-message-bytes.js +2 -0
  71. package/lib/max-message-bytes.js.map +1 -0
  72. package/lib/ndjson.d.ts +3 -0
  73. package/lib/ndjson.d.ts.map +1 -0
  74. package/lib/ndjson.js +2 -0
  75. package/lib/ndjson.js.map +1 -0
  76. package/lib/pagination.d.ts +105 -25
  77. package/lib/pagination.d.ts.map +1 -1
  78. package/lib/pagination.js +1 -182
  79. package/lib/plain-values.d.ts +21 -0
  80. package/lib/plain-values.d.ts.map +1 -0
  81. package/lib/plain-values.js +2 -0
  82. package/lib/plain-values.js.map +1 -0
  83. package/lib/protobuf.d.ts +85 -0
  84. package/lib/protobuf.d.ts.map +1 -0
  85. package/lib/protobuf.js +1 -0
  86. package/lib/protocol-grpc.d.ts +123 -0
  87. package/lib/protocol-grpc.d.ts.map +1 -0
  88. package/lib/protocol-grpc.js +1 -0
  89. package/lib/protocol-http.d.ts +206 -25
  90. package/lib/protocol-http.d.ts.map +1 -1
  91. package/lib/protocol-http.js +1 -554
  92. package/lib/protocol-rest.d.ts +258 -64
  93. package/lib/protocol-rest.d.ts.map +1 -1
  94. package/lib/protocol-rest.js +1 -242
  95. package/lib/protocol.d.ts +113 -0
  96. package/lib/protocol.d.ts.map +1 -0
  97. package/lib/protocol.js +0 -0
  98. package/lib/query.d.ts +29 -0
  99. package/lib/query.d.ts.map +1 -0
  100. package/lib/query.js +1 -0
  101. package/lib/response-validation-strict.d.ts +48 -0
  102. package/lib/response-validation-strict.d.ts.map +1 -0
  103. package/lib/response-validation-strict.js +1 -0
  104. package/lib/response-validation.d.ts +86 -0
  105. package/lib/response-validation.d.ts.map +1 -0
  106. package/lib/response-validation.js +1 -0
  107. package/lib/retry-after.d.ts +4 -4
  108. package/lib/retry-after.d.ts.map +1 -1
  109. package/lib/retry-after.js +1 -112
  110. package/lib/retry-state.d.ts +26 -0
  111. package/lib/retry-state.d.ts.map +1 -0
  112. package/lib/retry-state.js +2 -0
  113. package/lib/retry-state.js.map +1 -0
  114. package/lib/retry.d.ts +141 -42
  115. package/lib/retry.d.ts.map +1 -1
  116. package/lib/retry.js +1 -210
  117. package/lib/schema-lite-impl.d.ts +179 -0
  118. package/lib/schema-lite-impl.d.ts.map +1 -0
  119. package/lib/schema-lite-impl.js +1 -0
  120. package/lib/schema-lite-typed.d.ts +41 -0
  121. package/lib/schema-lite-typed.d.ts.map +1 -0
  122. package/lib/schema-lite-typed.js +1 -0
  123. package/lib/schema-lite.d.ts +41 -0
  124. package/lib/schema-lite.d.ts.map +1 -0
  125. package/lib/schema-lite.js +1 -0
  126. package/lib/schema.d.ts +21 -7
  127. package/lib/schema.d.ts.map +1 -1
  128. package/lib/schema.js +1 -48
  129. package/lib/sdk-error.d.ts +31 -0
  130. package/lib/sdk-error.d.ts.map +1 -0
  131. package/lib/sdk-error.js +1 -0
  132. package/lib/send.d.ts +37 -0
  133. package/lib/send.d.ts.map +1 -0
  134. package/lib/send.js +2 -0
  135. package/lib/send.js.map +1 -0
  136. package/lib/sensitive.d.ts +28 -0
  137. package/lib/sensitive.d.ts.map +1 -0
  138. package/lib/sensitive.js +2 -0
  139. package/lib/sensitive.js.map +1 -0
  140. package/lib/telemetry-debug.d.ts +6 -0
  141. package/lib/telemetry-debug.d.ts.map +1 -0
  142. package/lib/telemetry-debug.js +2 -0
  143. package/lib/telemetry-debug.js.map +1 -0
  144. package/lib/telemetry-hooks.d.ts +32 -0
  145. package/lib/telemetry-hooks.d.ts.map +1 -0
  146. package/lib/telemetry-hooks.js +2 -0
  147. package/lib/telemetry-hooks.js.map +1 -0
  148. package/lib/telemetry-host-rules.d.ts +23 -0
  149. package/lib/telemetry-host-rules.d.ts.map +1 -0
  150. package/lib/telemetry-host-rules.js +2 -0
  151. package/lib/telemetry-host-rules.js.map +1 -0
  152. package/lib/telemetry-lambda-context.d.ts +17 -0
  153. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  154. package/lib/telemetry-lambda-context.js +2 -0
  155. package/lib/telemetry-lambda-context.js.map +1 -0
  156. package/lib/telemetry-message-context.d.ts +52 -0
  157. package/lib/telemetry-message-context.d.ts.map +1 -0
  158. package/lib/telemetry-message-context.js +2 -0
  159. package/lib/telemetry-message-context.js.map +1 -0
  160. package/lib/telemetry-metrics.d.ts +6 -0
  161. package/lib/telemetry-metrics.d.ts.map +1 -0
  162. package/lib/telemetry-metrics.js +2 -0
  163. package/lib/telemetry-metrics.js.map +1 -0
  164. package/lib/telemetry-name-template.d.ts +13 -0
  165. package/lib/telemetry-name-template.d.ts.map +1 -0
  166. package/lib/telemetry-name-template.js +2 -0
  167. package/lib/telemetry-name-template.js.map +1 -0
  168. package/lib/telemetry-stream.d.ts +11 -0
  169. package/lib/telemetry-stream.d.ts.map +1 -0
  170. package/lib/telemetry-stream.js +2 -0
  171. package/lib/telemetry-stream.js.map +1 -0
  172. package/lib/telemetry-xray.d.ts +28 -0
  173. package/lib/telemetry-xray.d.ts.map +1 -0
  174. package/lib/telemetry-xray.js +2 -0
  175. package/lib/telemetry-xray.js.map +1 -0
  176. package/lib/telemetry.d.ts +317 -0
  177. package/lib/telemetry.d.ts.map +1 -0
  178. package/lib/telemetry.js +3 -0
  179. package/lib/telemetry.js.map +1 -0
  180. package/lib/token-cache.d.ts +31 -0
  181. package/lib/token-cache.d.ts.map +1 -0
  182. package/lib/token-cache.js +2 -0
  183. package/lib/token-cache.js.map +1 -0
  184. package/lib/trait.d.ts +94 -20
  185. package/lib/trait.d.ts.map +1 -1
  186. package/lib/trait.js +1 -107
  187. package/lib/unknown-error.d.ts +18 -0
  188. package/lib/unknown-error.d.ts.map +1 -0
  189. package/lib/unknown-error.js +1 -0
  190. package/lib/xml.d.ts +44 -0
  191. package/lib/xml.d.ts.map +1 -0
  192. package/lib/xml.js +1 -0
  193. package/package.json +13 -13
  194. package/src/annotations.ts +53 -0
  195. package/src/api.ts +1597 -234
  196. package/src/category.ts +97 -134
  197. package/src/chunks.ts +30 -0
  198. package/src/config.ts +261 -0
  199. package/src/crypto.ts +202 -0
  200. package/src/error-category.ts +16 -29
  201. package/src/errors.ts +99 -77
  202. package/src/graphql.ts +1817 -0
  203. package/src/graphql.types.ts +120 -0
  204. package/src/grpc-transport-cloudflare-http2.ts +569 -0
  205. package/src/grpc-transport-cloudflare-sockets.ts +368 -0
  206. package/src/grpc-transport-node-http2.ts +307 -0
  207. package/src/grpc-transport.ts +287 -0
  208. package/src/hpack.ts +331 -0
  209. package/src/index.ts +31 -0
  210. package/src/max-message-bytes.ts +58 -0
  211. package/src/ndjson.ts +55 -0
  212. package/src/pagination.ts +379 -94
  213. package/src/plain-values.ts +70 -0
  214. package/src/protobuf.ts +1367 -0
  215. package/src/protocol-grpc.ts +811 -0
  216. package/src/protocol-http.ts +1045 -371
  217. package/src/protocol-rest.ts +908 -255
  218. package/src/protocol.ts +150 -0
  219. package/src/query.ts +39 -0
  220. package/src/response-validation-strict.ts +333 -0
  221. package/src/response-validation.ts +161 -0
  222. package/src/retry-after.ts +8 -14
  223. package/src/retry-state.ts +105 -0
  224. package/src/retry.ts +260 -145
  225. package/src/schema-lite-impl.ts +621 -0
  226. package/src/schema-lite-typed.ts +44 -0
  227. package/src/schema-lite.ts +45 -0
  228. package/src/schema.ts +259 -15
  229. package/src/sdk-error.ts +37 -0
  230. package/src/send.ts +156 -0
  231. package/src/sensitive.ts +188 -0
  232. package/src/telemetry-debug.ts +179 -0
  233. package/src/telemetry-hooks.ts +33 -0
  234. package/src/telemetry-host-rules.ts +39 -0
  235. package/src/telemetry-lambda-context.ts +46 -0
  236. package/src/telemetry-message-context.ts +170 -0
  237. package/src/telemetry-metrics.ts +69 -0
  238. package/src/telemetry-name-template.ts +26 -0
  239. package/src/telemetry-stream.ts +100 -0
  240. package/src/telemetry-xray.ts +66 -0
  241. package/src/telemetry.ts +800 -0
  242. package/src/token-cache.ts +117 -0
  243. package/src/trait.ts +139 -67
  244. package/src/unknown-error.ts +38 -0
  245. package/src/xml.ts +346 -0
  246. package/lib/api.js.map +0 -1
  247. package/lib/category.js.map +0 -1
  248. package/lib/codegen/cli.d.ts +0 -29
  249. package/lib/codegen/cli.d.ts.map +0 -1
  250. package/lib/codegen/cli.js +0 -165
  251. package/lib/codegen/cli.js.map +0 -1
  252. package/lib/codegen/emit.d.ts +0 -129
  253. package/lib/codegen/emit.d.ts.map +0 -1
  254. package/lib/codegen/emit.js +0 -105
  255. package/lib/codegen/emit.js.map +0 -1
  256. package/lib/codegen/format.d.ts +0 -23
  257. package/lib/codegen/format.d.ts.map +0 -1
  258. package/lib/codegen/format.js +0 -28
  259. package/lib/codegen/format.js.map +0 -1
  260. package/lib/codegen/generator.d.ts +0 -334
  261. package/lib/codegen/generator.d.ts.map +0 -1
  262. package/lib/codegen/generator.js +0 -691
  263. package/lib/codegen/generator.js.map +0 -1
  264. package/lib/codegen/graph.d.ts +0 -36
  265. package/lib/codegen/graph.d.ts.map +0 -1
  266. package/lib/codegen/graph.js +0 -136
  267. package/lib/codegen/graph.js.map +0 -1
  268. package/lib/codegen/members.d.ts +0 -25
  269. package/lib/codegen/members.d.ts.map +0 -1
  270. package/lib/codegen/members.js +0 -55
  271. package/lib/codegen/members.js.map +0 -1
  272. package/lib/codegen/naming.d.ts +0 -29
  273. package/lib/codegen/naming.d.ts.map +0 -1
  274. package/lib/codegen/naming.js +0 -74
  275. package/lib/codegen/naming.js.map +0 -1
  276. package/lib/codegen/openapi-cli.d.ts +0 -38
  277. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  278. package/lib/codegen/openapi-cli.js +0 -107
  279. package/lib/codegen/openapi-cli.js.map +0 -1
  280. package/lib/codegen/openapi.d.ts +0 -115
  281. package/lib/codegen/openapi.d.ts.map +0 -1
  282. package/lib/codegen/openapi.js +0 -1220
  283. package/lib/codegen/openapi.js.map +0 -1
  284. package/lib/codegen/operations.d.ts +0 -24
  285. package/lib/codegen/operations.d.ts.map +0 -1
  286. package/lib/codegen/operations.js +0 -56
  287. package/lib/codegen/operations.js.map +0 -1
  288. package/lib/codegen/pagination.d.ts +0 -39
  289. package/lib/codegen/pagination.d.ts.map +0 -1
  290. package/lib/codegen/pagination.js +0 -33
  291. package/lib/codegen/pagination.js.map +0 -1
  292. package/lib/codegen/prelude.d.ts +0 -15
  293. package/lib/codegen/prelude.d.ts.map +0 -1
  294. package/lib/codegen/prelude.js +0 -60
  295. package/lib/codegen/prelude.js.map +0 -1
  296. package/lib/error-category.js.map +0 -1
  297. package/lib/errors.js.map +0 -1
  298. package/lib/json-patch.d.ts +0 -44
  299. package/lib/json-patch.d.ts.map +0 -1
  300. package/lib/json-patch.js +0 -174
  301. package/lib/json-patch.js.map +0 -1
  302. package/lib/pagination.js.map +0 -1
  303. package/lib/protocol-http.js.map +0 -1
  304. package/lib/protocol-rest.js.map +0 -1
  305. package/lib/retry-after.js.map +0 -1
  306. package/lib/retry.js.map +0 -1
  307. package/lib/schema.js.map +0 -1
  308. package/lib/trait.js.map +0 -1
  309. package/src/codegen/cli.ts +0 -268
  310. package/src/codegen/emit.ts +0 -207
  311. package/src/codegen/format.ts +0 -47
  312. package/src/codegen/generator.ts +0 -1153
  313. package/src/codegen/graph.ts +0 -151
  314. package/src/codegen/members.ts +0 -71
  315. package/src/codegen/naming.ts +0 -86
  316. package/src/codegen/openapi-cli.ts +0 -166
  317. package/src/codegen/openapi.ts +0 -1450
  318. package/src/codegen/operations.ts +0 -76
  319. package/src/codegen/pagination.ts +0 -71
  320. package/src/codegen/prelude.ts +0 -70
  321. package/src/json-patch.ts +0 -222
@@ -0,0 +1,113 @@
1
+ /**
2
+ * What a protocol is, typed by the errors it declares.
3
+ *
4
+ * An operation fails with three groups of errors, each named for where it
5
+ * is declared:
6
+ *
7
+ * 1. on the operation its `errors` list
8
+ * 2. on the service its `serviceErrors` list, the same for every
9
+ * operation of the service
10
+ * 3. on the protocol the {@link Protocol}'s own error type: what the
11
+ * code that builds requests and reads responses
12
+ * fails with (a response it can't parse, mostly)
13
+ *
14
+ * `API.make` adds the three together. A protocol never names an error of
15
+ * groups 1 and 2: it receives their classes, matches a failed response
16
+ * against them, and fails with the instance as a {@link DeclaredError}.
17
+ * Everything else it fails with is in its own type, and passes through to
18
+ * every operation that names the protocol. Nobody writes that list: the
19
+ * compiler reads it from the protocol's code ({@link ErrorOf}, and
20
+ * {@link ProtocolOf} for a protocol written by hand).
21
+ *
22
+ * export const NeonProtocol = restProtocol({ ... });
23
+ * export type NeonOpError = NeonServiceError | ErrorOf<typeof NeonProtocol>;
24
+ *
25
+ * Types only: this module has no runtime code.
26
+ */
27
+ import type * as Effect from "effect/Effect";
28
+ import type * as HttpClientRequest from "effect/http/HttpClientRequest";
29
+ import type * as HttpClientResponse from "effect/http/HttpClientResponse";
30
+ import type * as AST from "effect/SchemaAST";
31
+ import type * as Stream from "effect/Stream";
32
+ import type { PreparedOperation, ProtocolOperationConfig } from "./api.ts";
33
+ declare const declaredError: unique symbol;
34
+ /**
35
+ * An error of group 1 or 2 as a protocol sees it: an instance of a class
36
+ * that the operation or its service declares. A protocol can construct one
37
+ * from a {@link DeclaredErrorClass} and fail with it; `API.make` puts the
38
+ * real classes in the operation's error type.
39
+ */
40
+ export interface DeclaredError {
41
+ readonly [declaredError]: true;
42
+ }
43
+ /** A class that the operation or its service declares, as a protocol receives it. */
44
+ export type DeclaredErrorClass = new (props: any) => DeclaredError;
45
+ /** What {@link Protocol.encode} receives. */
46
+ export interface EncodeArgs {
47
+ readonly input: unknown;
48
+ readonly inputAst: AST.AST;
49
+ /** The operation's config (the same object on every call of the operation). */
50
+ readonly config: ProtocolOperationConfig;
51
+ }
52
+ /** What {@link Protocol.decode} receives. */
53
+ export interface DecodeArgs {
54
+ readonly response: HttpClientResponse.HttpClientResponse;
55
+ readonly outputAst: AST.AST;
56
+ /** The operation's declared classes, then its service's. */
57
+ readonly errors: ReadonlyArray<DeclaredErrorClass>;
58
+ /** The operation's config (the same object on every call of the operation). */
59
+ readonly config: ProtocolOperationConfig;
60
+ }
61
+ /** One operation as {@link Protocol.call} and {@link Protocol.stream} see it. */
62
+ export interface Operation extends Omit<PreparedOperation, "errors"> {
63
+ /** The operation's declared classes, then its service's. */
64
+ readonly errors: ReadonlyArray<DeclaredErrorClass>;
65
+ }
66
+ /**
67
+ * How an SDK turns an input into an HTTP request and a response into an
68
+ * output. `ProtocolError` is what the protocol declares (group 3), and
69
+ * `Requirements` is what its methods read from the calling fiber
70
+ * (credentials, a region).
71
+ *
72
+ * A request that was not sent has no response to match, so `encode` fails
73
+ * with the protocol's errors only.
74
+ */
75
+ export interface Protocol<ProtocolError, Requirements = never> {
76
+ readonly encode: (args: EncodeArgs) => Effect.Effect<HttpClientRequest.HttpClientRequest, ProtocolError, Requirements>;
77
+ readonly decode: (args: DecodeArgs) => Effect.Effect<unknown, DeclaredError | ProtocolError, Requirements>;
78
+ /**
79
+ * Optional whole call. When present, `API.make` runs a call as
80
+ * `call(operation, input)` in place of encode, send, decode. It reads the
81
+ * `HttpClient` from the calling fiber and produces the same request,
82
+ * result and errors as `encode` and `decode`.
83
+ */
84
+ readonly call?: (operation: Operation, input: unknown) => Effect.Effect<unknown, DeclaredError | ProtocolError, Requirements>;
85
+ /**
86
+ * Server streaming (see `API.makeStreaming`): each response message as it
87
+ * arrives, decoded as one element of the output's `items`. Ending the
88
+ * stream early cancels the call. A protocol that can't stream leaves it
89
+ * out; one that streams only some operations fails the others with
90
+ * `API.cannotStream`.
91
+ */
92
+ readonly stream?: (operation: Operation, input: unknown) => Stream.Stream<unknown, DeclaredError | ProtocolError, Requirements>;
93
+ }
94
+ /** What the methods of `P` return: its effects and its stream. */
95
+ type Outcome<P> = P[Extract<keyof P, keyof Protocol<unknown>>] extends infer Method ? Method extends (...args: any) => infer Result ? Result : never : never;
96
+ /**
97
+ * The errors a protocol declares (group 3), read from what its methods fail
98
+ * with. An SDK uses it to name what every operation fails with besides its
99
+ * own errors: `<Sdk>ServiceError | ErrorOf<typeof <Sdk>Protocol>`.
100
+ */
101
+ export type ErrorOf<P> = Outcome<P> extends infer Result ? Result extends Effect.Effect<any, infer Failure, any> ? Exclude<Failure, DeclaredError> : Result extends Stream.Stream<any, infer Failure, any> ? Exclude<Failure, DeclaredError> : never : never;
102
+ /** What a protocol's methods read from the calling fiber. */
103
+ export type RequirementsOf<P> = Outcome<P> extends infer Result ? Result extends Effect.Effect<any, any, infer Requirements> ? Requirements : Result extends Stream.Stream<any, any, infer Requirements> ? Requirements : never : never;
104
+ /**
105
+ * The type of a protocol written by hand, read from its methods, so that
106
+ * nobody lists its errors:
107
+ *
108
+ * const methods = { encode, decode } satisfies Protocol<unknown, unknown>;
109
+ * export const GcpProtocol: ProtocolOf<typeof methods> = methods;
110
+ */
111
+ export type ProtocolOf<Methods> = Protocol<ErrorOf<Methods>, RequirementsOf<Methods>>;
112
+ export {};
113
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,KAAK,iBAAiB,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAE3E,OAAO,CAAC,MAAM,aAAa,EAAE,OAAO,MAAM,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC;CAChC;AAED,qFAAqF;AACrF,MAAM,MAAM,kBAAkB,GAAG,KAAK,KAAK,EAAE,GAAG,KAAK,aAAa,CAAC;AAEnE,6CAA6C;AAC7C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC;IAC3B,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;CAC1C;AAED,6CAA6C;AAC7C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC,kBAAkB,CAAC;IACzD,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,kBAAkB,CA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KAAK,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IACnB,OAAO,CAAC,CAAC,CAAC,SAAS,MAAM,MAAM,GAC3B,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,OAAO,EAAE,GAAG,CAAC,GACnD,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,GAC/B,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,OAAO,EAAE,GAAG,CAAC,GACnD,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,GAC/B,KAAK,GACT,KAAK,CAAC;AAEZ,6DAA6D;AAC7D,MAAM,MAAM,cAAc,CAAC,CAAC,IAC1B,OAAO,CAAC,CAAC,CAAC,SAAS,MAAM,MAAM,GAC3B,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC,GACxD,YAAY,GACZ,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC,GACxD,YAAY,GACZ,KAAK,GACT,KAAK,CAAC;AAEZ;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC"}
File without changes
package/lib/query.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Query combinators for GraphQL SDKs.
3
+ *
4
+ * Import this module next to a generated client:
5
+ *
6
+ * import { Query } from "@distilled.cloud/core/query"
7
+ * import { Railway } from "@distilled.cloud/railway"
8
+ *
9
+ * `Query.fn` takes a **builder** (plain function, not `Effect.gen`) that
10
+ * returns a plan of `Query<Value>` and `Effect` values. It walks Map /
11
+ * Filter / FlatMap / Of, posts one GraphQL document, then interprets the
12
+ * plan. Roots (`Railway.me`) come from the generated SDK; they are not
13
+ * combinators.
14
+ *
15
+ * @see {@link file://./graphql.ts} for the algebra, compiler, and transport.
16
+ */
17
+ import { filterQuery, flatMapQuery, itemsQuery, mapQuery, ofQuery, pagesQuery, queryFn, type Query as QueryType } from "./graphql.ts";
18
+ export type Query<Value, Error = never> = QueryType<Value, Error>;
19
+ export type { PlanError, QueryError, UnwrapPlan } from "./graphql.ts";
20
+ export declare const Query: {
21
+ fn: typeof queryFn;
22
+ filter: typeof filterQuery;
23
+ map: typeof mapQuery;
24
+ flatMap: typeof flatMapQuery;
25
+ of: typeof ofQuery;
26
+ pages: typeof pagesQuery;
27
+ items: typeof itemsQuery;
28
+ };
29
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sources":["../src/query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,OAAO,EACP,UAAU,EACV,OAAO,EACP,KAAK,KAAK,IAAI,SAAS,EACxB,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,IAAI,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAClE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEtE,eAAO,MAAM,KAAK;IAChB,EAAE;IACF,MAAM;IACN,GAAG;IACH,OAAO;IACP,EAAE;IACF,KAAK;IACL,KAAK;CACN,CAAC"}
package/lib/query.js ADDED
@@ -0,0 +1 @@
1
+ export { query$Query as Query } from "./_bundle/graphql.js";
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The strict response checker: validates a decoded response against its
3
+ * output AST without Effect Schema.
4
+ *
5
+ * Generated output schemas are lite nodes (`schema-lite-impl.ts`); the
6
+ * checker accepts what Effect Schema's decoder accepted for the schema
7
+ * `toEffect` built from them (`response-validation-strict.test.ts` compares
8
+ * the two on random schemas and values). Each AST node compiles once to a
9
+ * closure, so a check walks the value only.
10
+ *
11
+ * Two modes: `additionalProperties` lets keys an object does not model
12
+ * through (Effect's default), `strict` (`exact`) rejects them (Effect's
13
+ * `onExcessProperty: "error"`). In both, an index signature covers only the
14
+ * keys the object does not declare (OpenAPI `additionalProperties`), and an
15
+ * empty struct accepts any object (generated code's opaque output).
16
+ *
17
+ * Hand-written protocols may pass real Effect ASTs. Their structure is
18
+ * checked the same way; refinement `checks` run, but a real `Declaration`
19
+ * with type parameters and `TemplateLiteral` contents are not checked.
20
+ */
21
+ import type * as AST from "effect/SchemaAST";
22
+ /** A response that does not match its output schema (the `cause` of a strict `<Sdk>ParseError`). */
23
+ export declare class SchemaMismatch extends Error {
24
+ readonly name = "SchemaError";
25
+ /** Where in the response the mismatch is, outermost key first. */
26
+ readonly path: ReadonlyArray<PropertyKey>;
27
+ /** What the schema expected there, e.g. `string`. */
28
+ readonly expected: string;
29
+ readonly actual: unknown;
30
+ constructor(path: ReadonlyArray<PropertyKey>, expected: string, actual: unknown);
31
+ }
32
+ /**
33
+ * `mismatch` with its offending value replaced by `"[REDACTED]"`, for a parse
34
+ * error that withholds the body (the value may be a secret).
35
+ */
36
+ export declare const withholdActual: (mismatch: SchemaMismatch) => SchemaMismatch;
37
+ /**
38
+ * Validate `input` synchronously: `undefined` when it matches, else the
39
+ * mismatch.
40
+ */
41
+ export type Decode = (input: unknown) => SchemaMismatch | undefined;
42
+ /**
43
+ * The checker for an output AST: compiled once per node and mode, then
44
+ * reused. `exact` also rejects keys an object does not model (the `strict`
45
+ * mode); without it they pass (`additionalProperties`).
46
+ */
47
+ export declare const decoderFor: (ast: AST.AST, exact?: boolean) => Decode;
48
+ //# sourceMappingURL=response-validation-strict.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-validation-strict.d.ts","sources":["../src/response-validation-strict.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAG7C,oGAAoG;AACpG,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAkB,IAAI,iBAAiB;IACvC,kEAAkE;IAClE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,YAAY,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAO9E;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,aAAc,cAAc,KAAG,cACU,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,cAAc,GAAG,SAAS,CAAC;AAiQpE;;;;GAIG;AACH,eAAO,MAAM,UAAU,QAAS,GAAG,CAAC,GAAG,sBAAkB,MAgBxD,CAAC"}
@@ -0,0 +1 @@
1
+ export { response_validation_strict$SchemaMismatch as SchemaMismatch, response_validation_strict$decoderFor as decoderFor, response_validation_strict$withholdActual as withholdActual } from "./_bundle/base.js";
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Response validation mode, shared by every distilled SDK.
3
+ *
4
+ * Generated SDKs carry a schema for every operation's output. What a
5
+ * protocol does with it on a 2xx response depends on the mode:
6
+ *
7
+ * lenient (default): the response is returned as the protocol read it.
8
+ * A body that does not match the declared output type
9
+ * (a missing member, a wrong primitive, a non-JSON
10
+ * body) still succeeds, except that a non-JSON body for
11
+ * an output with sensitive members fails in every mode
12
+ * (REST-style protocols through core's `checkSuccess`
13
+ * in `protocol-rest`, plus ZeroSSL and AWS).
14
+ * additionalProperties: the response is checked against the output
15
+ * schema, and a mismatch fails the call with the SDK's
16
+ * `<Sdk>ParseError` (AWS: `ParseError`). Keys the
17
+ * schema does not model are allowed and kept.
18
+ * strict: as `additionalProperties`, and a key the schema does
19
+ * not model also fails the call, at any depth. Open
20
+ * objects (an index signature, e.g. OpenAPI
21
+ * `additionalProperties`) and empty structs (opaque
22
+ * outputs) still accept any key.
23
+ *
24
+ * The mode is one {@link ResponseValidation} reference keyed by a string, so
25
+ * a single `Layer` switches every distilled SDK in a program -- AWS,
26
+ * Cloudflare, Neon, ... -- at once, and nests like any other Effect service:
27
+ *
28
+ * ```ts
29
+ * import { ResponseValidation } from "@distilled.cloud/core";
30
+ *
31
+ * // whole program
32
+ * program.pipe(Effect.provide(ResponseValidation.strict));
33
+ *
34
+ * // one call back to lenient inside a strict program
35
+ * Neon.getProject({ projectId }).pipe(Effect.provide(ResponseValidation.lenient));
36
+ * ```
37
+ *
38
+ * The mode is set only by these layers; without one, every call is lenient.
39
+ */
40
+ import * as Context from "effect/Context";
41
+ import * as Effect from "effect/Effect";
42
+ import * as Layer from "effect/Layer";
43
+ import type * as AST from "effect/SchemaAST";
44
+ import { type Decode, SchemaMismatch } from "./response-validation-strict.ts";
45
+ export { SchemaMismatch, withholdActual } from "./response-validation-strict.ts";
46
+ export type Mode = "lenient" | "additionalProperties" | "strict";
47
+ /**
48
+ * The active validation mode. Read by protocols at call time on the calling
49
+ * fiber; `lenient` unless an {@link additionalProperties} or {@link strict}
50
+ * layer is provided.
51
+ */
52
+ export declare const ResponseValidation: Context.Reference<Mode>;
53
+ /**
54
+ * The checker the validating modes use (`exact`: reject unmodeled keys). The
55
+ * `additionalProperties` and `strict` layers provide it, so the checker is
56
+ * bundled only with programs that validate.
57
+ */
58
+ export declare const StrictDecoder: Context.Reference<((ast: AST.AST, exact: boolean) => Decode) | undefined>;
59
+ /**
60
+ * Check every 2xx response against its output schema and fail on a
61
+ * mismatch, including any key the schema does not model.
62
+ */
63
+ export declare const strict: Layer.Layer<never>;
64
+ /**
65
+ * Check every 2xx response against its output schema and fail on a
66
+ * mismatch; keys the schema does not model are allowed.
67
+ */
68
+ export declare const additionalProperties: Layer.Layer<never>;
69
+ /** Return 2xx responses as read, without checking them against the schema. */
70
+ export declare const lenient: Layer.Layer<never>;
71
+ /** Whether the calling fiber validates responses (any mode but lenient). */
72
+ export declare const isValidating: Effect.Effect<boolean>;
73
+ /**
74
+ * For a 2xx body the protocol could not read into the shape it transforms
75
+ * (e.g. invalid JSON): fail with `error` when validating, succeed with
76
+ * `asRead` (usually the body text) in lenient mode.
77
+ */
78
+ export declare const failUnlessLenient: <A, E>(error: E, asRead: A) => Effect.Effect<A, E>;
79
+ /**
80
+ * The schema error for `value` against `outputAst` when validating,
81
+ * `undefined` when it matches or the mode is lenient. Synchronous, for
82
+ * protocols that already hold the calling fiber's context.
83
+ */
84
+ export declare const checkResponse: (context: Context.Context<any>, outputAst: AST.AST, value: unknown) => SchemaMismatch | undefined;
85
+ export declare const validateResponse: <E>(outputAst: AST.AST, value: unknown, onError: (cause: SchemaMismatch) => E) => Effect.Effect<unknown, E>;
86
+ //# sourceMappingURL=response-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-validation.d.ts","sources":["../src/response-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,KAAK,MAAM,EAAc,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE1F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjF,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,sBAAsB,GAAG,QAAQ,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,yBAG9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,2BACjB,GAAG,CAAC,GAAG,SAAS,OAAO,KAAK,MAAM,cACmD,CAAC;AAoB/F;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAMrC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAMnD,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAEtC,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAG/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAG7E,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,aAAa,YACf,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,aAClB,GAAG,CAAC,GAAG,SACX,OAAO,KACb,cAAc,GAAG,SAUnB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,CAAC,aACrB,GAAG,CAAC,GAAG,SACX,OAAO,WACL,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,KACpC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAIvB,CAAC"}
@@ -0,0 +1 @@
1
+ export { response_validation$ResponseValidation as ResponseValidation, response_validation$SchemaMismatch as SchemaMismatch, response_validation$StrictDecoder as StrictDecoder, response_validation$additionalProperties as additionalProperties, response_validation$checkResponse as checkResponse, response_validation$failUnlessLenient as failUnlessLenient, response_validation$isValidating as isValidating, response_validation$lenient as lenient, response_validation$strict as strict, response_validation$validateResponse as validateResponse, response_validation$withholdActual as withholdActual } from "./_bundle/base.js";
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Each SDK's `matchError` calls these helpers and attaches the resulting
10
10
  * `Duration` to retryable errors via the optional `retryAfter` field, where
11
- * the retry policy will honor it with precedence over the default backoff.
11
+ * the retry policy waits at least that long (RFC 9110).
12
12
  *
13
13
  * Services that use bespoke headers or body fields are expected to do their
14
14
  * own parsing in the SDK's `matchError`, optionally falling back to these
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import * as Duration from "effect/Duration";
18
18
  /**
19
- * Header bag — case-insensitive lookup is the caller's responsibility.
19
+ * Header bag -- case-insensitive lookup is the caller's responsibility.
20
20
  *
21
21
  * The helpers in this module read lowercase keys (`retry-after`, `ratelimit`)
22
22
  * because most HTTP clients normalize headers to lowercase. If your client
@@ -41,7 +41,7 @@ export declare const parseRetryAfter: (headers: Headers) => Duration.Duration |
41
41
  * `RateLimit: r=0, t=30` (compact form)
42
42
  *
43
43
  * Returns the `t` (seconds until reset) value as a Duration, but only when
44
- * `r` (remaining quota) is present and equals `0` — i.e., we're actually
44
+ * `r` (remaining quota) is present and equals `0` -- i.e., we're actually
45
45
  * rate-limited right now. Returns `undefined` otherwise.
46
46
  */
47
47
  export declare const parseRatelimit: (headers: Headers) => Duration.Duration | undefined;
@@ -55,7 +55,7 @@ export declare const parseServerRetryHint: (headers: Headers) => Duration.Durati
55
55
  * unless `status` is one whose error class actually declares a `retryAfter`
56
56
  * field (see `RETRYABLE_HTTP_STATUSES`). Use this in `matchError` when you
57
57
  * dispatch off a generic `HTTP_STATUS_MAP` lookup that includes both
58
- * retryable (429/5xx/423) and non-retryable (4xx) classes — it prevents
58
+ * retryable (429/5xx/423) and non-retryable (4xx) classes -- it prevents
59
59
  * stale `retryAfter` properties from being attached to errors like
60
60
  * `BadRequest` or `NotFound` (which would otherwise leak into JSON output).
61
61
  */
@@ -1 +1 @@
1
- {"version":3,"file":"retry-after.d.ts","sourceRoot":"","sources":["../src/retry-after.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C;;;;;;GAMG;AACH,MAAM,M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izes parsing of:
5
- * - `Retry-After` (RFC 7231 §7.1.3): `delay-seconds` (integer) or `HTTP-date`.
6
- * - `RateLimit` (IETF draft-ietf-httpapi-ratelimit-headers): structured
7
- * dictionary `r=<remaining>, t=<seconds-until-reset>`.
8
- *
9
- * Each SDK's `matchError` calls these helpers and attaches the resulting
10
- * `Duration` to retryable errors via the optional `retryAfter` field, where
11
- * the retry policy will honor it with precedence over the default backoff.
12
- *
13
- * Services that use bespoke headers or body fields are expected to do their
14
- * own parsing in the SDK's `matchError`, optionally falling back to these
15
- * helpers for the standard cases.
16
- */
17
- import * as Duration from "effect/Duration";
18
- import { RETRYABLE_HTTP_STATUSES } from "./errors.js";
19
- /**
20
- * Parse the standard `Retry-After` HTTP header per RFC 7231 §7.1.3.
21
- *
22
- * Accepts either a non-negative integer number of seconds (the common case)
23
- * or an HTTP-date. HTTP-dates in the past produce a zero duration.
24
- *
25
- * Returns `undefined` when the header is missing or unparseable.
26
- */
27
- export const parseRetryAfter = (headers) => {
28
- const raw = headers?.["retry-after"];
29
- if (!raw)
30
- return undefined;
31
- const trimmed = raw.trim();
32
- if (trimmed.length === 0)
33
- return undefined;
34
- // delay-seconds: 1*DIGIT (non-negative decimal integer per RFC).
35
- if (/^\d+$/.test(trimmed)) {
36
- const seconds = Number(trimmed);
37
- if (Number.isFinite(seconds) && seconds >= 0) {
38
- return Duration.seconds(seconds);
39
- }
40
- }
41
- // Reject anything that *looks* numeric but isn't a valid delay-seconds.
42
- // Without this, `Date.parse("-5")` happens to return 0 on some engines and
43
- // would silently yield a zero-duration instead of the expected undefined.
44
- if (/^[-+]?\d+(?:\.\d+)?$/.test(trimmed))
45
- return undefined;
46
- // HTTP-date: try Date.parse, which handles RFC 1123 / RFC 850 / asctime.
47
- const ts = Date.parse(trimmed);
48
- if (!Number.isNaN(ts)) {
49
- const ms = Math.max(0, ts - Date.now());
50
- return Duration.millis(ms);
51
- }
52
- return undefined;
53
- };
54
- /**
55
- * Parse the IETF `RateLimit` structured header.
56
- *
57
- * Examples:
58
- * `RateLimit: limit=100, remaining=0, reset=30` (older draft)
59
- * `RateLimit: "default";r=0;t=30` (newer draft)
60
- * `RateLimit: r=0, t=30` (compact form)
61
- *
62
- * Returns the `t` (seconds until reset) value as a Duration, but only when
63
- * `r` (remaining quota) is present and equals `0` — i.e., we're actually
64
- * rate-limited right now. Returns `undefined` otherwise.
65
- */
66
- export const parseRatelimit = (headers) => {
67
- const raw = headers?.["ratelimit"];
68
- if (!raw)
69
- return undefined;
70
- let remaining;
71
- let reset;
72
- // Tokenize on commas and semicolons; tolerate `key=value` and `key =value`.
73
- for (const piece of raw.split(/[,;]/)) {
74
- const eq = piece.indexOf("=");
75
- if (eq < 0)
76
- continue;
77
- const key = piece.slice(0, eq).trim().toLowerCase();
78
- const value = piece.slice(eq + 1).trim();
79
- const num = Number(value);
80
- if (!Number.isFinite(num))
81
- continue;
82
- if (key === "r" || key === "remaining")
83
- remaining = num;
84
- else if (key === "t" || key === "reset")
85
- reset = num;
86
- }
87
- if (remaining !== undefined && remaining > 0)
88
- return undefined;
89
- if (reset === undefined || reset < 0)
90
- return undefined;
91
- return Duration.seconds(reset);
92
- };
93
- /**
94
- * Convenience: try `Retry-After` first, then `RateLimit`. Returns the first
95
- * successful parse, or `undefined` if neither header yields a usable value.
96
- */
97
- export const parseServerRetryHint = (headers) => parseRetryAfter(headers) ?? parseRatelimit(headers);
98
- /**
99
- * Status-gated variant of {@link parseServerRetryHint}. Returns `undefined`
100
- * unless `status` is one whose error class actually declares a `retryAfter`
101
- * field (see `RETRYABLE_HTTP_STATUSES`). Use this in `matchError` when you
102
- * dispatch off a generic `HTTP_STATUS_MAP` lookup that includes both
103
- * retryable (429/5xx/423) and non-retryable (4xx) classes — it prevents
104
- * stale `retryAfter` properties from being attached to errors like
105
- * `BadRequest` or `NotFound` (which would otherwise leak into JSON output).
106
- */
107
- export const parseRetryAfterForStatus = (status, headers) => {
108
- if (!RETRYABLE_HTTP_STATUSES.has(status))
109
- return undefined;
110
- return parseServerRetryHint(headers);
111
- };
112
- //# sourceMappingURL=retry-after.js.map
1
+ export { retry_after$parseRatelimit as parseRatelimit, retry_after$parseRetryAfter as parseRetryAfter, retry_after$parseRetryAfterForStatus as parseRetryAfterForStatus, retry_after$parseServerRetryHint as parseServerRetryHint } from "./_bundle/rest.js";
@@ -0,0 +1,26 @@
1
+ /** The host of `url` (no port); `""` when it has none. */
2
+ export declare const hostOf: (url: string) => string;
3
+ /**
4
+ * The bounded server hint of a response: `x-amz-retry-after` or
5
+ * `x-distilled-retry-after` in milliseconds, the larger when both are set.
6
+ */
7
+ export declare const boundedHintOf: (headers: Readonly<Record<string, string | undefined>>) => number | undefined;
8
+ /**
9
+ * Record that the current fiber is sending a request to `url`; `oneShot`
10
+ * when its body can be read only once.
11
+ */
12
+ export declare const recordRequest: (url: string, oneShot?: boolean) => void;
13
+ /** Record the response to the current fiber's last request. */
14
+ export declare const recordResponse: (status: number, headers: Readonly<Record<string, string | undefined>>) => void;
15
+ /**
16
+ * The current fiber's last request, removed so that a later failure that
17
+ * sent nothing cannot reuse its hint.
18
+ */
19
+ export declare const takeLastRequest: () => {
20
+ readonly host: string;
21
+ readonly oneShot: boolean;
22
+ readonly hintMs?: number;
23
+ };
24
+ /** Successful responses from `host` so far in this process. */
25
+ export declare const successesOf: (host: string) => number;
26
+ //# sourceMappingURL=retry-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-state.d.ts","sources":["../src/retry-state.ts"],"names":[],"mappings":"AA2BA,0DAA0D;AAC1D,eAAO,MAAM,MAAM,QAAS,MAAM,KAAG,MASpC,CAAC;AAWF;;;GAGG;AACH,eAAO,MAAM,aAAa,YACf,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,KACpD,MAAM,GAAG,SAKX,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM,wBAAoB,IAK5D,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,cAAc,WACjB,MAAM,WACL,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,KACpD,IASF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAO;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAO1B,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,MAAwC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import*as e from"effect/Fiber";const t=/*@__PURE__*/ new WeakMap;const n=/*@__PURE__*/ new Map;const hostOf=e=>{const t=e.indexOf(`://`);if(t===-1)return``;const n=t+3;let r=n;while(r<e.length&&!`/?#`.includes(e[r]))r++;const i=e.slice(e.lastIndexOf(`@`,r)+1||n,r);const a=i.lastIndexOf(`:`);return a!==-1&&!i.endsWith(`]`)?i.slice(0,a):i};const parseMs=e=>{if(e===void 0)return void 0;const t=e.trim();if(!/^\d+$/.test(t))return void 0;const n=Number(t);return Number.isSafeInteger(n)?n:void 0};const boundedHintOf=e=>{const t=parseMs(e[`x-amz-retry-after`]);const n=parseMs(e[`x-distilled-retry-after`]);if(t===void 0)return n;return n===void 0?t:Math.max(t,n)};const recordRequest=(n,r=false)=>{const i=e.getCurrent();if(i!==void 0)t.set(i,{host:hostOf(n),oneShot:r,hintMs:void 0})};const recordResponse=(r,i)=>{const a=e.getCurrent();const o=a===void 0?void 0:t.get(a);if(o===void 0)return;if(r<300)n.set(o.host,(n.get(o.host)??0)+1);else o.hintMs=boundedHintOf(i)};const takeLastRequest=()=>{const n=e.getCurrent();const r=n===void 0?void 0:t.get(n);if(r===void 0)return{host:``,oneShot:false};t.delete(n);return r.hintMs===void 0?{host:r.host,oneShot:r.oneShot}:r};const successesOf=e=>n.get(e)??0;export{boundedHintOf,hostOf,recordRequest,recordResponse,successesOf,takeLastRequest};
2
+ //# sourceMappingURL=retry-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-state.js","names":["Fiber","lastByFiber","successesByHost","schemeEnd","url","start","end","authority","colon","value","trimmed","ms","amz","headers","distilled","fiber","last","status","host"],"sources":["../src/retry-state.ts"],"mappings":"+BAwBA,MAAMC,gBAA4B,IAAI,QACtC,MAAMC,gBAAgC,IAAI,IAG1C,MAAa,OAAU,GAAwB,CAC7C,MAAMC,EAAYC,EAAI,QAAQ,KAAK,EACnC,GAAID,IAAc,CAAA,EAAI,MAAO,GAC7B,MAAME,EAAQF,EAAY,EAC1B,IAAIG,EAAMD,EACV,MAAOC,EAAMF,EAAI,QAAU,CAAC,MAAM,SAASA,EAAIE,EAAK,EAAG,IACvD,MAAMC,EAAYH,EAAI,MAAMA,EAAI,YAAY,IAAKE,CAAG,EAAI,GAAKD,EAAOC,CAAG,EACvE,MAAME,EAAQD,EAAU,YAAY,GAAG,EACvC,OAAOC,IAAU,CAAA,GAAM,CAACD,EAAU,SAAS,GAAG,EAAIA,EAAU,MAAM,EAAGC,CAAK,EAAID,CAChF,EAGA,MAAM,QAAW,GAAkD,CACjE,GAAIE,IAAU,IAAA,GAAW,OAAO,IAAA,GAChC,MAAMC,EAAUD,EAAM,KAAK,EAC3B,GAAI,CAAC,QAAQ,KAAKC,CAAO,EAAG,OAAO,IAAA,GACnC,MAAMC,EAAK,OAAOD,CAAO,EACzB,OAAO,OAAO,cAAcC,CAAE,EAAIA,EAAK,IAAA,EACzC,EAMA,MAAa,cACX,GACuB,CACvB,MAAMC,EAAM,QAAQC,EAAQ,oBAAoB,EAChD,MAAMC,EAAY,QAAQD,EAAQ,0BAA0B,EAC5D,GAAID,IAAQ,IAAA,GAAW,OAAOE,EAC9B,OAAOA,IAAc,IAAA,GAAYF,EAAM,KAAK,IAAIA,EAAKE,CAAS,CAChE,EAMA,MAAa,eAAiB,EAAa,EAAU,QAAgB,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