@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
@@ -1,36 +1,23 @@
1
- /**
2
- * Generic REST protocol factory for simple bearer/header-auth JSON APIs
3
- * (Neon, Fly.io, PlanetScale, Supabase, Turso, …).
4
- *
5
- * `makeRestProtocol(options)` builds a core {@link API.Protocol} layer:
6
- *
7
- * request: credentials resolved from the CALLING fiber's context on every
8
- * request (the layer itself is memoized per process — see
9
- * `core/api`), auth headers + base URL from the provider's
10
- * options, request built by `buildRequest` from
11
- * `core/protocol-http` (deep-unwrapping any `Redacted` input
12
- * values first)
13
- *
14
- * response: 2xx JSON → optional `transformResponse` → recursive wire→TS
15
- * key mapping (`mapKeys`) → `Redacted` wrapping of members
16
- * marked with {@link SensitiveValue}; non-2xx → typed error:
17
- * per-op matcher classes (`matchTypedError`), then the status
18
- * map (default `HTTP_STATUS_MAP`), then an `InternalServerError`
19
- * for unmapped 5xx, then the provider's `unknownError` fallback
20
- * — with `retryAfter` durations stamped from the standard hint
21
- * headers on retryable statuses.
22
- *
23
- * Anything provider-specific (envelope quirks, bespoke error codes) belongs
24
- * in the provider package — via these options or a hand-written protocol.
25
- */
1
+ import * as Context from "effect/Context";
26
2
  import * as Effect from "effect/Effect";
27
- import * as Layer from "effect/Layer";
3
+ import type * as HttpClientError from "effect/http/HttpClientError";
4
+ import type * as HttpClientResponse from "effect/http/HttpClientResponse";
5
+ import type * as Schema from "effect/Schema";
28
6
  import type * as AST from "effect/SchemaAST";
29
- import * as API from "./api.ts";
30
- export declare const sensitiveValueSymbol: unique symbol;
7
+ import type * as Stream from "effect/Stream";
8
+ import { rawResponseRootSymbol } from "./annotations.ts";
9
+ import { InternalServerError } from "./errors.ts";
10
+ import { unwrapRedactedDeep } from "./plain-values.ts";
11
+ import { type InvalidInput } from "./protocol-http.ts";
12
+ import type { DeclaredErrorClass, Protocol } from "./protocol.ts";
13
+ import { SdkError } from "./sdk-error.ts";
14
+ import { sensitiveValueSymbol, wrapSensitive } from "./sensitive.ts";
15
+ import type { UnknownErrorProps } from "./unknown-error.ts";
16
+ export { sensitiveValueSymbol };
31
17
  /**
32
- * Marks a string member as sensitive (mirrors `smithy.api#sensitive`).
33
- * The REST protocol wraps decoded values in `Redacted` on the way out and
18
+ * Marks a string member, map value or list element as sensitive (mirrors
19
+ * `smithy.api#sensitive`). The REST protocol wraps decoded values in
20
+ * `Redacted` on the way out (an untyped `S.Unknown` value whole) and
34
21
  * accepts `string | Redacted<string>` on the way in (unwrapped before
35
22
  * serialization). Takes an ignored argument so generators can inline the
36
23
  * smithy trait value (`T.SensitiveValue({})`).
@@ -42,27 +29,51 @@ export declare const rawResponseSymbol: unique symbol;
42
29
  * body (mirrors `com.distilled.openapi#rawResponse`).
43
30
  */
44
31
  export declare const RawResponse: (_value?: unknown) => import("./trait.ts").Annotation;
45
- export declare const rawResponseRootSymbol: unique symbol;
46
32
  /**
47
33
  * Marks a response schema whose ENTIRE value is the response body (the
48
34
  * generator's `rootPipe` for synthesized bare-payload wrappers): the emitted
49
35
  * response type IS the payload type and the protocol returns the mapped body
50
36
  * directly.
51
37
  */
38
+ export { rawResponseRootSymbol };
52
39
  export declare const RawResponseRoot: () => import("./trait.ts").Annotation;
40
+ export declare const binaryResponseSymbol: unique symbol;
41
+ /**
42
+ * Decode a successful raw binary response as a {@link BinaryStream} of the
43
+ * body, never read as text or into one buffer. On a whole output, the
44
+ * output is the stream. On the `RawResponse()` member of a structure
45
+ * output, that member gets the stream and the structure's `Header` members
46
+ * get their response headers (a download's `Content-Type`).
47
+ */
48
+ export declare const BinaryResponse: () => import("./trait.ts").Annotation;
53
49
  /**
54
- * Deep-unwrap `Redacted` values in an input (plain objects/arrays only —
55
- * class instances, files, and binary payloads pass through untouched).
56
- * Sensitive input members accept `string | Redacted<string>`; the wire wants
57
- * the raw string.
50
+ * A binary download's body, read as it arrives. It fails with the
51
+ * `HttpClientError` of a read that breaks off (a connection reset).
52
+ * `Stream.mkUint8Array` collects it into one buffer.
58
53
  */
59
- export declare const unwrapRedactedDeep: (value: unknown) => unknown;
54
+ export type BinaryStream = Stream.Stream<Uint8Array, HttpClientError.HttpClientError>;
55
+ /** The schema of a {@link BinaryStream}, for a binary download's body member. */
56
+ export declare const BinaryStream: Schema.Schema<BinaryStream>;
60
57
  /**
61
- * Walk a decoded (TS-named) value alongside its schema AST, wrapping members
62
- * marked {@link SensitiveValue} in `Redacted`. Keys the schema doesn't model
63
- * pass through verbatim.
58
+ * A binary upload's body from a stream: a `T.HttpBody()` member may take
59
+ * one, and the protocol sends it as it is pulled, without buffering it.
60
+ * A stream can be sent once, so a call with one is never retried. With no
61
+ * modeled `Content-Length` member set, the body goes out chunked.
64
62
  */
65
- export declare const wrapSensitive: (ast: AST.AST, value: unknown) => unknown;
63
+ export type UploadStream = Stream.Stream<Uint8Array, unknown>;
64
+ /** A raw request body (`T.HttpBody()` on a binary member): what `buildRequest` sends verbatim. */
65
+ export type RawBody = string | Uint8Array | ArrayBuffer | Blob | UploadStream;
66
+ /** The schema of a {@link RawBody}, for a binary upload's body member. */
67
+ export declare const RawBody: Schema.Schema<RawBody>;
68
+ export { unwrapRedactedDeep };
69
+ export { wrapSensitive };
70
+ /**
71
+ * Whether any member, map value or list element reachable from `ast` is
72
+ * marked {@link SensitiveValue}. Such an output is decoded through
73
+ * {@link wrapSensitive}, and its parse errors withhold the response body (see
74
+ * {@link checkSuccess}, which every REST-style protocol's success path uses).
75
+ */
76
+ export declare const hasSensitiveMember: (ast: AST.AST) => boolean;
66
77
  /** What the wire said about a failure, for the `unknownError` fallback. */
67
78
  export interface RestErrorInfo {
68
79
  readonly status: number;
@@ -73,26 +84,69 @@ export interface RestErrorInfo {
73
84
  readonly body: unknown;
74
85
  readonly headers: Record<string, string | undefined>;
75
86
  }
87
+ /**
88
+ * The core {@link UnknownErrorProps} of a failure, for an SDK's
89
+ * `unknownError`: `new UnknownNeonError(unknownErrorProps(info))`. A number
90
+ * code becomes its string.
91
+ */
92
+ export declare const unknownErrorProps: (info: RestErrorInfo) => UnknownErrorProps;
93
+ /**
94
+ * A 2xx body that failed strict validation, or a non-JSON 2xx body for an
95
+ * output with sensitive members, for the `parseError` option.
96
+ */
97
+ export interface RestParseErrorInfo {
98
+ /** `"[REDACTED]"` when the output has sensitive members. */
99
+ readonly body: unknown;
100
+ readonly cause: unknown;
101
+ }
76
102
  export interface RestErrorEnvelope {
77
103
  readonly code?: string | number;
78
104
  readonly message?: string;
79
105
  }
80
- export interface RestProtocolOptions<C> {
106
+ /**
107
+ * What this module's own code fails with, whatever the options: the errors
108
+ * every REST protocol declares. A label that would address another resource
109
+ * (`InvalidInput`), a request it can't build or an operation it can't
110
+ * stream (`SdkError`), the transport or a body read (`HttpClientError`), and
111
+ * a 5xx response that neither the operation nor its service declares
112
+ * (`InternalServerError`, which the retry policy retries).
113
+ */
114
+ export type RestProtocolError = InvalidInput | SdkError | HttpClientError.HttpClientError | InternalServerError;
115
+ /**
116
+ * Options of {@link restProtocol}. The type parameters after `Credentials`
117
+ * are what each option fails with or reads; `restProtocol` infers them from
118
+ * the options, and they are the errors its protocol declares.
119
+ */
120
+ export interface RestProtocolOptions<Credentials, CredentialsError, CredentialsRequirements, RouteError, ClassifiedError, UnknownError, ParseError> {
121
+ /**
122
+ * Resolve credentials ON THE CALLING FIBER -- evaluated per request, so
123
+ * context-provided credentials and token refreshes are picked up. Either
124
+ * an effect, or -- for the distilled credentials-service convention --
125
+ * the `Credentials` service key whose value is that effect (read from the calling fiber's context; an
126
+ * already-resolved `Effect.succeed` value costs no extra fiber step). What
127
+ * it fails with (declared on the credentials) reaches every operation
128
+ * through the protocol, and what it reads is the protocol's requirement.
129
+ */
130
+ readonly credentials: Effect.Effect<Credentials, CredentialsError, CredentialsRequirements> | Context.Key<CredentialsRequirements, Effect.Effect<Credentials, CredentialsError>>;
81
131
  /**
82
- * Resolve credentials ON THE CALLING FIBER — evaluated per request, never
83
- * at layer build time, so context-provided credentials and token refreshes
84
- * are picked up. Typically `Effect.gen(function* () { const resolve =
85
- * yield* Credentials; return yield* resolve; })` for the distilled
86
- * credentials-service convention. Its error/requirement channels are
87
- * erased at the protocol boundary (Protocol effects carry none) and
88
- * reintroduced for callers by the generated `<Sdk>OpError` /
89
- * `<Sdk>OpContext` annotations.
132
+ * API base URL from the resolved credentials. Receives the operation's
133
+ * route so APIs with more than one endpoint (e.g. S2's account vs
134
+ * per-basin hosts, chosen by path) can route per request; single-endpoint
135
+ * providers ignore the argument. `server` is the operation's host name
136
+ * (`T.Http({ server })`) for APIs that serve some operations from another
137
+ * host; map it to a base URL from the credentials. To refuse a route (e.g.
138
+ * a required scope missing from the credentials), return `Effect.fail` of
139
+ * the error the call fails with. A THROWN error fails the call with
140
+ * `SdkError`, as anything thrown under a call does (the defect boundary,
141
+ * `./api.ts`).
90
142
  */
91
- readonly credentials: Effect.Effect<C, any, any>;
92
- /** API base URL from the resolved credentials. */
93
- readonly baseUrl: (credentials: C) => string;
143
+ readonly baseUrl: (credentials: Credentials, target: {
144
+ readonly uri: string;
145
+ readonly method: string;
146
+ readonly server?: string | undefined;
147
+ }) => string | Effect.Effect<never, RouteError>;
94
148
  /** Auth (and any fixed) headers from the resolved credentials. */
95
- readonly headers: (credentials: C) => Record<string, string>;
149
+ readonly headers: (credentials: Credentials) => Record<string, string>;
96
150
  /**
97
151
  * Extract `{ code?, message? }` from a parsed non-2xx JSON body. Default:
98
152
  * lenient `{ code?, message? | error? }` (covers the common REST error
@@ -100,25 +154,165 @@ export interface RestProtocolOptions<C> {
100
154
  */
101
155
  readonly errorEnvelope?: (body: unknown) => RestErrorEnvelope | undefined;
102
156
  /**
103
- * HTTP status → error class constructed as `new Cls({ message, retryAfter
104
- * })`. Default: core `HTTP_STATUS_MAP`. Consulted after per-op typed error
105
- * matching; unmapped 5xx fall back to `InternalServerError`, everything
106
- * else to {@link unknownError}.
157
+ * JSON pointer to the object that holds a failure's fields when the
158
+ * provider nests them, e.g. `"/error"` for `{ error: { status, details } }`.
159
+ * A typed error's declared fields are read there first, then at the top
160
+ * level of the body.
107
161
  */
108
- readonly statusMap?: Readonly<Record<number, new (args: any) => any>>;
109
- /** Fallback error for failures nothing else matched. */
110
- readonly unknownError: (info: RestErrorInfo) => unknown;
162
+ readonly errorFieldsAt?: string;
163
+ /**
164
+ * The provider's own reading of a failure, consulted before the classes
165
+ * the operation and its service declare: return the error to fail with, or
166
+ * `undefined` to decode the failure as usual. For rules a status alone
167
+ * can't express, e.g. a 403 that is a rate limit because of its headers.
168
+ */
169
+ readonly classifyError?: (info: RestErrorInfo) => ClassifiedError | undefined;
170
+ /**
171
+ * Fallback error for failures nothing else matched: the SDK's
172
+ * `Unknown<Sdk>Error`, built from {@link unknownErrorProps}. Only non-5xx
173
+ * statuses reach it (an undeclared 5xx is `InternalServerError`), so the
174
+ * class carries no retryable category.
175
+ */
176
+ readonly unknownError: (info: RestErrorInfo) => UnknownError;
177
+ /**
178
+ * The SDK's `<Sdk>ParseError`, raised when a 2xx body does not match the
179
+ * operation's output schema in strict mode (see
180
+ * `core/response-validation`), and in every mode when a 2xx body for an
181
+ * output with sensitive members is not JSON. `body` is the parsed JSON, or
182
+ * the raw text when the body wasn't JSON, and `"[REDACTED]"` for an output
183
+ * with sensitive members; `cause` is the schema error, or `"Invalid JSON
184
+ * response"`.
185
+ */
186
+ readonly parseError: (info: RestParseErrorInfo) => ParseError;
111
187
  /** Transform the parsed 2xx JSON before decoding (e.g. stripNulls). */
112
188
  readonly transformResponse?: (body: unknown) => unknown;
113
189
  /** Passed through to `buildRequest` (member-header transforms). */
114
190
  readonly mapMemberHeader?: (name: string, value: string) => string;
115
191
  /** Passed through to `buildRequest` (wire names for unmodeled input keys). */
116
192
  readonly unknownKeyToWire?: (key: string) => string;
193
+ /** Passed through to `buildRequest`: send `{}` when a bodied call has no body members. */
194
+ readonly emptyJsonBody?: boolean;
117
195
  }
118
196
  /**
119
- * Build a `Layer<Protocol>` for a simple REST JSON API. Assign the result to
120
- * a module-level const in the provider's `protocol.ts` — `API.make` memoizes
121
- * protocol layers by value identity.
197
+ * The body of a streamed 2xx response, for {@link StreamFraming.stream}.
198
+ * `Failure` is what the call fails with.
199
+ */
200
+ export interface FramedBody<Failure> {
201
+ readonly body: Stream.Stream<Uint8Array, Failure>;
202
+ /**
203
+ * Decode one parsed frame as one element of the output's `items`, as a
204
+ * 2xx body decodes (key mapping, strict validation, `Redacted`).
205
+ */
206
+ readonly item: (json: unknown, text: string) => Effect.Effect<unknown, Failure>;
207
+ /** The SDK's parse error for a frame that is not JSON. */
208
+ readonly invalid: (text: string) => Failure;
209
+ }
210
+ /** A plain call's framed body, read whole: the output JSON, or not JSON. */
211
+ export interface CollectedBody {
212
+ readonly json: unknown;
213
+ readonly nonJson: boolean;
214
+ }
215
+ /**
216
+ * How a server-streaming operation's body is framed (`API.makeStreaming`,
217
+ * output `{ items }`): its `framing` config, e.g. `ndjson` from
218
+ * core/ndjson. An operation without one can't stream (`.stream()` fails
219
+ * with `SdkError`, see `API.cannotStream`).
220
+ */
221
+ export interface StreamFraming {
222
+ /**
223
+ * A plain call's whole body as `{ items }`, or `undefined` when the
224
+ * response's `Content-Type` is not this framing (decoded as usual).
225
+ */
226
+ readonly collect: (text: string, contentType: string | undefined) => CollectedBody | undefined;
227
+ /**
228
+ * Each frame as it arrives, through `item`. `open` sends the request and
229
+ * fails with the operation's typed error on a failed status.
230
+ */
231
+ readonly stream: <Failure, Requirements>(open: Effect.Effect<FramedBody<Failure>, Failure, Requirements>) => Stream.Stream<unknown, Failure, Requirements>;
232
+ }
233
+ /** A 2xx body a protocol read, for {@link checkSuccess}. */
234
+ export interface SuccessBody {
235
+ /** The value to check and return: the body mapped onto the output's TS names. */
236
+ readonly value: unknown;
237
+ /** What a parse error reports as `body` for an output without sensitive members. */
238
+ readonly body: unknown;
239
+ /** Whether the body was not JSON. */
240
+ readonly nonJson: boolean;
241
+ }
242
+ /** The outcome of {@link checkSuccess}: the value, or the parse error's fields. */
243
+ export type SuccessCheck = {
244
+ readonly ok: true;
245
+ readonly value: unknown;
246
+ } | {
247
+ readonly ok: false;
248
+ readonly error: RestParseErrorInfo;
249
+ };
250
+ /**
251
+ * Check a 2xx body against the operation's output schema and deliver its
252
+ * sensitive values as `Redacted`. Every REST-style protocol ends its success
253
+ * path here, so all of them treat a body that can hold a secret alike:
254
+ *
255
+ * - The checked value comes back through {@link wrapSensitive}.
256
+ * - A mismatch (validating modes, see `core/response-validation`) reports
257
+ * `read.body` and the schema error.
258
+ * - For an output with sensitive members ({@link hasSensitiveMember}), a
259
+ * non-JSON body fails in every mode with `"Invalid JSON response"`, and a
260
+ * mismatch reports `body: "[REDACTED]"` and the schema error without the
261
+ * value it found (`withholdActual`).
262
+ *
263
+ * Synchronous, for protocols that already hold the calling fiber's context;
264
+ * {@link validateSuccess} is the `Effect` form.
265
+ */
266
+ export declare const checkSuccess: (context: Context.Context<any>, outputAst: AST.AST, read: SuccessBody) => SuccessCheck;
267
+ /**
268
+ * {@link checkSuccess} on the calling fiber, failing with `parseError` (the
269
+ * SDK's `<Sdk>ParseError`) built from the withheld-or-not fields.
270
+ */
271
+ export declare const validateSuccess: <E>(outputAst: AST.AST, read: SuccessBody, parseError: (info: RestParseErrorInfo) => E) => Effect.Effect<unknown, E>;
272
+ /**
273
+ * Read a 2xx response of a binary output ({@link BinaryResponse}) as a
274
+ * {@link BinaryStream}: the stream itself for a binary whole output, or the
275
+ * structure with the stream in its body member and its header members
276
+ * filled. `undefined` when the output is not binary. The call returns once
277
+ * the headers arrive; a body read that fails later (reset or abort
278
+ * mid-body) fails the stream with its `HttpClientError`. For hand-written
279
+ * protocols too, so every SDK decodes a download the same way.
280
+ */
281
+ export declare const readBinaryResponse: (response: HttpClientResponse.HttpClientResponse, outputAst: AST.AST) => Effect.Effect<unknown> | undefined;
282
+ /**
283
+ * The class core has for `status`, when the operation or its service
284
+ * declares it: a list of declared errors can hold core's status classes
285
+ * (`Unauthorized`, `TooManyRequests`, ...), which are matched by status.
286
+ * For a protocol that reads failed responses itself.
287
+ */
288
+ export declare const declaredStatusClass: (status: number, declared: ReadonlyArray<DeclaredErrorClass>) => DeclaredErrorClass | undefined;
289
+ /**
290
+ * The methods of {@link restProtocol}, for either form of `credentials`.
291
+ * For the protocols core builds on them (core/protocol-grpc).
292
+ */
293
+ export declare const restProtocolMethods: <Credentials, CredentialsError = never, CredentialsRequirements = never, RouteError = never, ClassifiedError = never, UnknownError = never, ParseError = never>(options: RestProtocolOptions<Credentials, CredentialsError, CredentialsRequirements, RouteError, ClassifiedError, UnknownError, ParseError>) => Protocol<CredentialsError | RouteError | ClassifiedError | UnknownError | ParseError | RestProtocolError, CredentialsRequirements>;
294
+ /**
295
+ * {@link restProtocol}'s options for one form of `credentials`. The service
296
+ * key and the effect are separate signatures: a key is also an effect (of
297
+ * the service), so one signature for both could not tell which it is given.
298
+ */
299
+ type TypedRestOptions<CredentialsSource, Credentials, RouteError, ClassifiedError, UnknownError, ParseError> = Omit<RestProtocolOptions<Credentials, never, never, RouteError, ClassifiedError, UnknownError, ParseError>, "credentials"> & {
300
+ /** See {@link RestProtocolOptions.credentials}. */
301
+ readonly credentials: CredentialsSource;
302
+ };
303
+ /**
304
+ * The protocol for a simple REST JSON API (core/protocol). Assign the
305
+ * result to a module-level const in the provider's `protocol.ts`:
306
+ *
307
+ * export const NeonProtocol = restProtocol({ ... });
308
+ *
309
+ * A failed response becomes, in this order: what `classifyError` returns, a
310
+ * class the operation or its service declares (by its matchers, or by status
311
+ * for one of core's status classes), `InternalServerError` for any other
312
+ * 5xx, and `unknownError` for the rest. The protocol declares what the
313
+ * options and {@link RestProtocolError} fail with: the result's type lists
314
+ * them, so no SDK writes that list by hand.
122
315
  */
123
- export declare const makeRestProtocol: <C>(options: RestProtocolOptions<C>) => Layer.Layer<API.Protocol>;
316
+ export declare function restProtocol<Credentials, CredentialsError = never, CredentialsRequirements = never, RouteError = never, ClassifiedError = never, UnknownError = never, ParseError = never>(options: TypedRestOptions<Context.Key<CredentialsRequirements, Effect.Effect<Credentials, CredentialsError>>, Credentials, RouteError, ClassifiedError, UnknownError, ParseError>): Protocol<CredentialsError | RouteError | ClassifiedError | UnknownError | ParseError | RestProtocolError, CredentialsRequirements>;
317
+ export declare function restProtocol<Credentials, CredentialsError = never, CredentialsRequirements = never, RouteError = never, ClassifiedError = never, UnknownError = never, ParseError = never>(options: TypedRestOptions<Effect.Effect<Credentials, CredentialsError, CredentialsRequirements>, Credentials, RouteError, ClassifiedError, UnknownError, ParseError>): Protocol<CredentialsError | RouteError | ClassifiedError | UnknownError | ParseError | RestProtocolError, CredentialsRequirements>;
124
318
  //# sourceMappingURL=protocol-rest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol-rest.d.ts","sourceRoot":"","sources":["../src/protocol-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAG7C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAkBhC,eAAO,MAAM,oBAAoB,eAEhC,CAAC;AACF;;;;;;GAMG;AACH,e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KAAK,EACpB,UAAU,GAAG,KAAK,EAElB,OAAO,EAAE,gBAAgB,CACvB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,EAAE,uBAAuB,CAAC,EACrE,WAAW,EACX,UAAU,EACV,eAAe,EACf,YAAY,EACZ,UAAU,CACX,GACA,QAAQ,CACT,gBAAgB,GAAG,UAAU,GAAG,eAAe,GAAG,YAAY,GAAG,UAAU,GAAG,iBAAiB,EAC/F,uBAAuB,CACxB,CAAC"}
@@ -1,242 +1 @@
1
- /**
2
- * Generic REST protocol factory for simple bearer/header-auth JSON APIs
3
- * (Neon, Fly.io, PlanetScale, Supabase, Turso, …).
4
- *
5
- * `makeRestProtocol(options)` builds a core {@link API.Protocol} layer:
6
- *
7
- * request: credentials resolved from the CALLING fiber's context on every
8
- * request (the layer itself is memoized per process — see
9
- * `core/api`), auth headers + base URL from the provider's
10
- * options, request built by `buildRequest` from
11
- * `core/protocol-http` (deep-unwrapping any `Redacted` input
12
- * values first)
13
- *
14
- * response: 2xx JSON → optional `transformResponse` → recursive wire→TS
15
- * key mapping (`mapKeys`) → `Redacted` wrapping of members
16
- * marked with {@link SensitiveValue}; non-2xx → typed error:
17
- * per-op matcher classes (`matchTypedError`), then the status
18
- * map (default `HTTP_STATUS_MAP`), then an `InternalServerError`
19
- * for unmapped 5xx, then the provider's `unknownError` fallback
20
- * — with `retryAfter` durations stamped from the standard hint
21
- * headers on retryable statuses.
22
- *
23
- * Anything provider-specific (envelope quirks, bespoke error codes) belongs
24
- * in the provider package — via these options or a hand-written protocol.
25
- */
26
- import * as Effect from "effect/Effect";
27
- import * as Layer from "effect/Layer";
28
- import * as Redacted from "effect/Redacted";
29
- import * as API from "./api.js";
30
- import { makeAnnotation } from "./trait.js";
31
- import { buildRequest, getPropAnn, getProps, isOpaqueValue, mapKeys, matchTypedError, resolveNode, } from "./protocol-http.js";
32
- import { HTTP_STATUS_MAP, InternalServerError } from "./errors.js";
33
- import { parseRetryAfterForStatus } from "./retry-after.js";
34
- // =============================================================================
35
- // Traits
36
- // =============================================================================
37
- export const sensitiveValueSymbol = Symbol.for("@distilled.cloud/core/sensitive-value");
38
- /**
39
- * Marks a string member as sensitive (mirrors `smithy.api#sensitive`).
40
- * The REST protocol wraps decoded values in `Redacted` on the way out and
41
- * accepts `string | Redacted<string>` on the way in (unwrapped before
42
- * serialization). Takes an ignored argument so generators can inline the
43
- * smithy trait value (`T.SensitiveValue({})`).
44
- */
45
- export const SensitiveValue = (_value) => makeAnnotation(sensitiveValueSymbol, true);
46
- export const rawResponseSymbol = Symbol.for("@distilled.cloud/core/raw-response");
47
- /**
48
- * Marks the sole output member that carries a bare (array/scalar) response
49
- * body (mirrors `com.distilled.openapi#rawResponse`).
50
- */
51
- export const RawResponse = (_value) => makeAnnotation(rawResponseSymbol, true);
52
- export const rawResponseRootSymbol = Symbol.for("@distilled.cloud/core/raw-response-root");
53
- /**
54
- * Marks a response schema whose ENTIRE value is the response body (the
55
- * generator's `rootPipe` for synthesized bare-payload wrappers): the emitted
56
- * response type IS the payload type and the protocol returns the mapped body
57
- * directly.
58
- */
59
- export const RawResponseRoot = () => makeAnnotation(rawResponseRootSymbol, true);
60
- // =============================================================================
61
- // Value helpers
62
- // =============================================================================
63
- const isPlainObject = (v) => v !== null &&
64
- typeof v === "object" &&
65
- !Array.isArray(v) &&
66
- !isOpaqueValue(v) &&
67
- (Object.getPrototypeOf(v) === Object.prototype ||
68
- Object.getPrototypeOf(v) === null);
69
- /**
70
- * Deep-unwrap `Redacted` values in an input (plain objects/arrays only —
71
- * class instances, files, and binary payloads pass through untouched).
72
- * Sensitive input members accept `string | Redacted<string>`; the wire wants
73
- * the raw string.
74
- */
75
- export const unwrapRedactedDeep = (value) => {
76
- if (Redacted.isRedacted(value))
77
- return Redacted.value(value);
78
- if (Array.isArray(value))
79
- return value.map(unwrapRedactedDeep);
80
- if (isPlainObject(value)) {
81
- const out = {};
82
- for (const [k, v] of Object.entries(value)) {
83
- if (v === undefined)
84
- continue;
85
- out[k] = unwrapRedactedDeep(v);
86
- }
87
- return out;
88
- }
89
- return value;
90
- };
91
- /**
92
- * Walk a decoded (TS-named) value alongside its schema AST, wrapping members
93
- * marked {@link SensitiveValue} in `Redacted`. Keys the schema doesn't model
94
- * pass through verbatim.
95
- */
96
- export const wrapSensitive = (ast, value) => {
97
- if (value === null || typeof value !== "object" || isOpaqueValue(value)) {
98
- return value;
99
- }
100
- const node = resolveNode(ast);
101
- if (node._tag === "Arrays") {
102
- if (!Array.isArray(value))
103
- return value;
104
- const elem = node.rest?.[0];
105
- return elem ? value.map((v) => wrapSensitive(elem, v)) : value;
106
- }
107
- if (node._tag === "Objects" && !Array.isArray(value)) {
108
- const props = getProps(node);
109
- if (props.length === 0)
110
- return value;
111
- const byName = new Map(props.map((p) => [String(p.name), p]));
112
- const out = {};
113
- for (const [k, v] of Object.entries(value)) {
114
- if (v === undefined)
115
- continue;
116
- const prop = byName.get(k);
117
- if (!prop) {
118
- out[k] = v;
119
- }
120
- else if (getPropAnn(prop, sensitiveValueSymbol) !== undefined &&
121
- typeof v === "string") {
122
- out[k] = Redacted.make(v);
123
- }
124
- else {
125
- out[k] = wrapSensitive(prop.type, v);
126
- }
127
- }
128
- return out;
129
- }
130
- return value;
131
- };
132
- const defaultErrorEnvelope = (body) => {
133
- if (body === null || typeof body !== "object")
134
- return undefined;
135
- const b = body;
136
- const code = typeof b.code === "string" || typeof b.code === "number"
137
- ? b.code
138
- : undefined;
139
- const message = typeof b.message === "string"
140
- ? b.message
141
- : typeof b.error === "string"
142
- ? b.error
143
- : undefined;
144
- return { code, message };
145
- };
146
- // Bridge: Protocol.decode is typed as Effect<unknown> (no error channel),
147
- // but REST failures are real typed errors that operations re-surface via
148
- // their `errors: [...]` lists. Fail with the instance and erase the type
149
- // here; the generated operation annotations reintroduce it for callers.
150
- const fail = (e) => Effect.fail(e);
151
- /**
152
- * Build a `Layer<Protocol>` for a simple REST JSON API. Assign the result to
153
- * a module-level const in the provider's `protocol.ts` — `API.make` memoizes
154
- * protocol layers by value identity.
155
- */
156
- export const makeRestProtocol = (options) => {
157
- const errorEnvelope = options.errorEnvelope ?? defaultErrorEnvelope;
158
- const statusMap = options.statusMap ?? HTTP_STATUS_MAP;
159
- const encode = ({ input, inputAst, }) => Effect.gen(function* () {
160
- const creds = yield* options.credentials;
161
- return buildRequest({
162
- input: unwrapRedactedDeep(input),
163
- inputAst,
164
- baseUrl: options.baseUrl(creds),
165
- headers: options.headers(creds),
166
- mapMemberHeader: options.mapMemberHeader,
167
- unknownKeyToWire: options.unknownKeyToWire,
168
- });
169
- });
170
- const decode = ({ response, outputAst, errors: errorClasses, }) => Effect.gen(function* () {
171
- // Read as text and parse tolerantly — error pages are often non-JSON.
172
- const text = (yield* response.text.pipe(Effect.orDie)) ?? "";
173
- if (process.env.DISTILLED_DEBUG_HTTP) {
174
- console.error(`[distilled] <- ${response.status} ${text.slice(0, 400)}`);
175
- }
176
- let json;
177
- let nonJson = false;
178
- if (text.trim().length > 0) {
179
- try {
180
- json = JSON.parse(text);
181
- }
182
- catch {
183
- nonJson = true;
184
- }
185
- }
186
- const status = response.status;
187
- const headers = response.headers;
188
- if (status >= 400) {
189
- const env = (nonJson ? undefined : errorEnvelope(json)) ?? {};
190
- const message = env.message ??
191
- (nonJson && text.trim() ? text.trim() : `HTTP ${status}`);
192
- // 1. Per-operation typed error (matcher metadata on the class).
193
- const typed = matchTypedError(errorClasses, status, [
194
- {
195
- code: typeof env.code === "number" ? env.code : undefined,
196
- message,
197
- },
198
- ]);
199
- if (typed !== undefined)
200
- return yield* fail(typed);
201
- // 2. Status-mapped class (retryAfter only stamps on retryable
202
- // statuses — parseRetryAfterForStatus gates on that).
203
- const StatusErrorClass = statusMap[status];
204
- if (StatusErrorClass) {
205
- return yield* fail(new StatusErrorClass({
206
- message,
207
- retryAfter: parseRetryAfterForStatus(status, headers),
208
- }));
209
- }
210
- // 3. Unmapped 5xx (e.g. proxy-specific statuses) → retryable server
211
- // error rather than the unknown fallback.
212
- if (status >= 500) {
213
- return yield* fail(new InternalServerError({
214
- message,
215
- retryAfter: parseRetryAfterForStatus(status, headers),
216
- }));
217
- }
218
- // 4. Provider fallback.
219
- return yield* fail(options.unknownError({
220
- status,
221
- code: env.code,
222
- message,
223
- body: nonJson ? text : json,
224
- headers,
225
- }));
226
- }
227
- // 2xx: the response body IS the payload (no envelope). Wire→TS key
228
- // mapping is schema-driven; `RawResponseRoot` responses are the body
229
- // verbatim (mapKeys handles arrays/scalars structurally either way).
230
- let body = nonJson ? text : (json ?? {});
231
- if (options.transformResponse)
232
- body = options.transformResponse(body);
233
- return wrapSensitive(outputAst, mapKeys(outputAst, body, "decode"));
234
- });
235
- return Layer.succeed(API.Protocol, API.Protocol.of({
236
- // Erase encode's credentials requirement (resolved on the calling
237
- // fiber; see RestProtocolOptions.credentials).
238
- encode: (args) => encode(args),
239
- decode,
240
- }));
241
- };
242
- //# sourceMappingURL=protocol-rest.js.map
1
+ export { protocol_rest$BinaryResponse as BinaryResponse, protocol_rest$BinaryStream as BinaryStream, protocol_rest$RawBody as RawBody, protocol_rest$RawResponse as RawResponse, protocol_rest$RawResponseRoot as RawResponseRoot, protocol_rest$SensitiveValue as SensitiveValue, protocol_rest$binaryResponseSymbol as binaryResponseSymbol, protocol_rest$checkSuccess as checkSuccess, protocol_rest$declaredStatusClass as declaredStatusClass, protocol_rest$hasSensitiveMember as hasSensitiveMember, protocol_rest$rawResponseRootSymbol as rawResponseRootSymbol, protocol_rest$rawResponseSymbol as rawResponseSymbol, protocol_rest$readBinaryResponse as readBinaryResponse, protocol_rest$restProtocol as restProtocol, protocol_rest$restProtocolMethods as restProtocolMethods, protocol_rest$sensitiveValueSymbol as sensitiveValueSymbol, protocol_rest$unknownErrorProps as unknownErrorProps, protocol_rest$unwrapRedactedDeep as unwrapRedactedDeep, protocol_rest$validateSuccess as validateSuccess, protocol_rest$wrapSensitive as wrapSensitive } from "./_bundle/rest.js";