@distilled.cloud/core 1.0.0-rc.16 → 1.0.0-rc.18

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 (306) hide show
  1. package/lib/_bundle/aws.js +2 -0
  2. package/lib/_bundle/aws.js.map +1 -0
  3. package/lib/_bundle/base.js +5 -0
  4. package/lib/_bundle/base.js.map +1 -0
  5. package/lib/_bundle/graphql.js +3 -0
  6. package/lib/_bundle/graphql.js.map +1 -0
  7. package/lib/_bundle/rest.js +2 -0
  8. package/lib/_bundle/rest.js.map +1 -0
  9. package/lib/_bundle/xml.js +4 -0
  10. package/lib/_bundle/xml.js.map +1 -0
  11. package/lib/annotations.d.ts +15 -0
  12. package/lib/annotations.d.ts.map +1 -0
  13. package/lib/annotations.js +2 -0
  14. package/lib/annotations.js.map +1 -0
  15. package/lib/api.d.ts +15 -0
  16. package/lib/api.d.ts.map +1 -1
  17. package/lib/api.js +1 -796
  18. package/lib/category.d.ts.map +1 -1
  19. package/lib/category.js +1 -278
  20. package/lib/chunks.js +1 -11
  21. package/lib/config.d.ts +54 -13
  22. package/lib/config.d.ts.map +1 -1
  23. package/lib/config.js +1 -161
  24. package/lib/crypto.js +1 -130
  25. package/lib/debug.d.ts.map +1 -1
  26. package/lib/debug.js +1 -8
  27. package/lib/error-category.d.ts.map +1 -1
  28. package/lib/error-category.js +1 -47
  29. package/lib/errors.d.ts +2 -13
  30. package/lib/errors.d.ts.map +1 -1
  31. package/lib/errors.js +1 -198
  32. package/lib/graphql.d.ts +14 -0
  33. package/lib/graphql.d.ts.map +1 -1
  34. package/lib/graphql.js +1 -1058
  35. package/lib/graphql.types.js +1 -6
  36. package/lib/index.d.ts +3 -2
  37. package/lib/index.d.ts.map +1 -1
  38. package/lib/index.js +1 -15
  39. package/lib/pagination.d.ts +34 -2
  40. package/lib/pagination.d.ts.map +1 -1
  41. package/lib/pagination.js +1 -271
  42. package/lib/plain-values.js +1 -39
  43. package/lib/plain-values.js.map +1 -1
  44. package/lib/protocol-http.d.ts +30 -6
  45. package/lib/protocol-http.d.ts.map +1 -1
  46. package/lib/protocol-http.js +1 -812
  47. package/lib/protocol-rest.d.ts +53 -39
  48. package/lib/protocol-rest.d.ts.map +1 -1
  49. package/lib/protocol-rest.js +1 -375
  50. package/lib/query.js +1 -27
  51. package/lib/response-validation-strict.js +1 -284
  52. package/lib/response-validation.d.ts +4 -3
  53. package/lib/response-validation.d.ts.map +1 -1
  54. package/lib/response-validation.js +1 -118
  55. package/lib/retry-after.js +1 -112
  56. package/lib/retry.js +1 -197
  57. package/lib/schema-lite-impl.js +1 -341
  58. package/lib/schema-lite-typed.js +1 -27
  59. package/lib/schema-lite.js +1 -31
  60. package/lib/schema.js +1 -220
  61. package/lib/telemetry-debug.d.ts +14 -0
  62. package/lib/telemetry-debug.d.ts.map +1 -0
  63. package/lib/telemetry-debug.js +2 -0
  64. package/lib/telemetry-debug.js.map +1 -0
  65. package/lib/telemetry-hooks.d.ts +32 -0
  66. package/lib/telemetry-hooks.d.ts.map +1 -0
  67. package/lib/telemetry-hooks.js +2 -0
  68. package/lib/telemetry-hooks.js.map +1 -0
  69. package/lib/telemetry-host-rules.d.ts +23 -0
  70. package/lib/telemetry-host-rules.d.ts.map +1 -0
  71. package/lib/telemetry-host-rules.js +2 -0
  72. package/lib/telemetry-host-rules.js.map +1 -0
  73. package/lib/telemetry-lambda-context.d.ts +17 -0
  74. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  75. package/lib/telemetry-lambda-context.js +2 -0
  76. package/lib/telemetry-lambda-context.js.map +1 -0
  77. package/lib/telemetry-message-context.d.ts +52 -0
  78. package/lib/telemetry-message-context.d.ts.map +1 -0
  79. package/lib/telemetry-message-context.js +2 -0
  80. package/lib/telemetry-message-context.js.map +1 -0
  81. package/lib/telemetry-metrics.d.ts +6 -0
  82. package/lib/telemetry-metrics.d.ts.map +1 -0
  83. package/lib/telemetry-metrics.js +2 -0
  84. package/lib/telemetry-metrics.js.map +1 -0
  85. package/lib/telemetry-name-template.d.ts +13 -0
  86. package/lib/telemetry-name-template.d.ts.map +1 -0
  87. package/lib/telemetry-name-template.js +2 -0
  88. package/lib/telemetry-name-template.js.map +1 -0
  89. package/lib/telemetry-stream.d.ts +9 -0
  90. package/lib/telemetry-stream.d.ts.map +1 -0
  91. package/lib/telemetry-stream.js +2 -0
  92. package/lib/telemetry-stream.js.map +1 -0
  93. package/lib/telemetry-xray.d.ts +28 -0
  94. package/lib/telemetry-xray.d.ts.map +1 -0
  95. package/lib/telemetry-xray.js +2 -0
  96. package/lib/telemetry-xray.js.map +1 -0
  97. package/lib/telemetry.d.ts +269 -0
  98. package/lib/telemetry.d.ts.map +1 -0
  99. package/lib/telemetry.js +3 -0
  100. package/lib/telemetry.js.map +1 -0
  101. package/lib/trait.js +1 -131
  102. package/lib/xml.js +1 -323
  103. package/package.json +1 -3
  104. package/src/annotations.ts +37 -0
  105. package/src/api.ts +130 -30
  106. package/src/category.ts +21 -22
  107. package/src/config.ts +58 -29
  108. package/src/debug.ts +9 -6
  109. package/src/error-category.ts +12 -14
  110. package/src/errors.ts +7 -7
  111. package/src/graphql.ts +123 -18
  112. package/src/index.ts +3 -2
  113. package/src/pagination.ts +119 -6
  114. package/src/protocol-http.ts +63 -43
  115. package/src/protocol-rest.ts +201 -140
  116. package/src/response-validation.ts +4 -3
  117. package/src/telemetry-debug.ts +135 -0
  118. package/src/telemetry-hooks.ts +33 -0
  119. package/src/telemetry-host-rules.ts +39 -0
  120. package/src/telemetry-lambda-context.ts +46 -0
  121. package/src/telemetry-message-context.ts +170 -0
  122. package/src/telemetry-metrics.ts +69 -0
  123. package/src/telemetry-name-template.ts +26 -0
  124. package/src/telemetry-stream.ts +91 -0
  125. package/src/telemetry-xray.ts +66 -0
  126. package/src/telemetry.ts +768 -0
  127. package/lib/api.js.map +0 -1
  128. package/lib/category.js.map +0 -1
  129. package/lib/chunks.js.map +0 -1
  130. package/lib/codegen/boolean-string-enums.d.ts +0 -36
  131. package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
  132. package/lib/codegen/boolean-string-enums.js +0 -147
  133. package/lib/codegen/boolean-string-enums.js.map +0 -1
  134. package/lib/codegen/chunk.d.ts +0 -7
  135. package/lib/codegen/chunk.d.ts.map +0 -1
  136. package/lib/codegen/chunk.js +0 -139
  137. package/lib/codegen/chunk.js.map +0 -1
  138. package/lib/codegen/cli.d.ts +0 -80
  139. package/lib/codegen/cli.d.ts.map +0 -1
  140. package/lib/codegen/cli.js +0 -166
  141. package/lib/codegen/cli.js.map +0 -1
  142. package/lib/codegen/datafy.d.ts +0 -14
  143. package/lib/codegen/datafy.d.ts.map +0 -1
  144. package/lib/codegen/datafy.js +0 -853
  145. package/lib/codegen/datafy.js.map +0 -1
  146. package/lib/codegen/dedupe.d.ts +0 -5
  147. package/lib/codegen/dedupe.d.ts.map +0 -1
  148. package/lib/codegen/dedupe.js +0 -153
  149. package/lib/codegen/dedupe.js.map +0 -1
  150. package/lib/codegen/emit.d.ts +0 -125
  151. package/lib/codegen/emit.d.ts.map +0 -1
  152. package/lib/codegen/emit.js +0 -99
  153. package/lib/codegen/emit.js.map +0 -1
  154. package/lib/codegen/format.d.ts +0 -11
  155. package/lib/codegen/format.d.ts.map +0 -1
  156. package/lib/codegen/format.js +0 -32
  157. package/lib/codegen/format.js.map +0 -1
  158. package/lib/codegen/generated-at.d.ts +0 -29
  159. package/lib/codegen/generated-at.d.ts.map +0 -1
  160. package/lib/codegen/generated-at.js +0 -78
  161. package/lib/codegen/generated-at.js.map +0 -1
  162. package/lib/codegen/generator.d.ts +0 -353
  163. package/lib/codegen/generator.d.ts.map +0 -1
  164. package/lib/codegen/generator.js +0 -810
  165. package/lib/codegen/generator.js.map +0 -1
  166. package/lib/codegen/graph.d.ts +0 -36
  167. package/lib/codegen/graph.d.ts.map +0 -1
  168. package/lib/codegen/graph.js +0 -136
  169. package/lib/codegen/graph.js.map +0 -1
  170. package/lib/codegen/graphql-client.d.ts +0 -70
  171. package/lib/codegen/graphql-client.d.ts.map +0 -1
  172. package/lib/codegen/graphql-client.js +0 -439
  173. package/lib/codegen/graphql-client.js.map +0 -1
  174. package/lib/codegen/graphql.d.ts +0 -207
  175. package/lib/codegen/graphql.d.ts.map +0 -1
  176. package/lib/codegen/graphql.js +0 -786
  177. package/lib/codegen/graphql.js.map +0 -1
  178. package/lib/codegen/latin1.d.ts +0 -3
  179. package/lib/codegen/latin1.d.ts.map +0 -1
  180. package/lib/codegen/latin1.js +0 -126
  181. package/lib/codegen/latin1.js.map +0 -1
  182. package/lib/codegen/members.d.ts +0 -32
  183. package/lib/codegen/members.d.ts.map +0 -1
  184. package/lib/codegen/members.js +0 -62
  185. package/lib/codegen/members.js.map +0 -1
  186. package/lib/codegen/model-diff.d.ts +0 -10
  187. package/lib/codegen/model-diff.d.ts.map +0 -1
  188. package/lib/codegen/model-diff.js +0 -67
  189. package/lib/codegen/model-diff.js.map +0 -1
  190. package/lib/codegen/naming.d.ts +0 -29
  191. package/lib/codegen/naming.d.ts.map +0 -1
  192. package/lib/codegen/naming.js +0 -74
  193. package/lib/codegen/naming.js.map +0 -1
  194. package/lib/codegen/openapi-cli.d.ts +0 -52
  195. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  196. package/lib/codegen/openapi-cli.js +0 -84
  197. package/lib/codegen/openapi-cli.js.map +0 -1
  198. package/lib/codegen/openapi.d.ts +0 -209
  199. package/lib/codegen/openapi.d.ts.map +0 -1
  200. package/lib/codegen/openapi.js +0 -1548
  201. package/lib/codegen/openapi.js.map +0 -1
  202. package/lib/codegen/operations.d.ts +0 -24
  203. package/lib/codegen/operations.d.ts.map +0 -1
  204. package/lib/codegen/operations.js +0 -56
  205. package/lib/codegen/operations.js.map +0 -1
  206. package/lib/codegen/pagination.d.ts +0 -39
  207. package/lib/codegen/pagination.d.ts.map +0 -1
  208. package/lib/codegen/pagination.js +0 -31
  209. package/lib/codegen/pagination.js.map +0 -1
  210. package/lib/codegen/patch-audit.d.ts +0 -84
  211. package/lib/codegen/patch-audit.d.ts.map +0 -1
  212. package/lib/codegen/patch-audit.js +0 -366
  213. package/lib/codegen/patch-audit.js.map +0 -1
  214. package/lib/codegen/patches.d.ts +0 -129
  215. package/lib/codegen/patches.d.ts.map +0 -1
  216. package/lib/codegen/patches.js +0 -472
  217. package/lib/codegen/patches.js.map +0 -1
  218. package/lib/codegen/prelude.d.ts +0 -15
  219. package/lib/codegen/prelude.d.ts.map +0 -1
  220. package/lib/codegen/prelude.js +0 -60
  221. package/lib/codegen/prelude.js.map +0 -1
  222. package/lib/codegen/privatize.d.ts +0 -21
  223. package/lib/codegen/privatize.d.ts.map +0 -1
  224. package/lib/codegen/privatize.js +0 -176
  225. package/lib/codegen/privatize.js.map +0 -1
  226. package/lib/codegen/proto.d.ts +0 -121
  227. package/lib/codegen/proto.d.ts.map +0 -1
  228. package/lib/codegen/proto.js +0 -960
  229. package/lib/codegen/proto.js.map +0 -1
  230. package/lib/codegen/pure.d.ts +0 -6
  231. package/lib/codegen/pure.d.ts.map +0 -1
  232. package/lib/codegen/pure.js +0 -91
  233. package/lib/codegen/pure.js.map +0 -1
  234. package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
  235. package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
  236. package/lib/codegen/rewrite-operation-ids.js +0 -1117
  237. package/lib/codegen/rewrite-operation-ids.js.map +0 -1
  238. package/lib/codegen/spec-path.d.ts +0 -16
  239. package/lib/codegen/spec-path.d.ts.map +0 -1
  240. package/lib/codegen/spec-path.js +0 -101
  241. package/lib/codegen/spec-path.js.map +0 -1
  242. package/lib/codegen/table.d.ts +0 -5
  243. package/lib/codegen/table.d.ts.map +0 -1
  244. package/lib/codegen/table.js +0 -249
  245. package/lib/codegen/table.js.map +0 -1
  246. package/lib/config.js.map +0 -1
  247. package/lib/crypto.js.map +0 -1
  248. package/lib/debug.js.map +0 -1
  249. package/lib/error-category.js.map +0 -1
  250. package/lib/errors.js.map +0 -1
  251. package/lib/graphql.js.map +0 -1
  252. package/lib/graphql.types.js.map +0 -1
  253. package/lib/index.js.map +0 -1
  254. package/lib/json-patch.d.ts +0 -58
  255. package/lib/json-patch.d.ts.map +0 -1
  256. package/lib/json-patch.js +0 -227
  257. package/lib/json-patch.js.map +0 -1
  258. package/lib/pagination.js.map +0 -1
  259. package/lib/protocol-http.js.map +0 -1
  260. package/lib/protocol-rest.js.map +0 -1
  261. package/lib/query.js.map +0 -1
  262. package/lib/response-validation-strict.js.map +0 -1
  263. package/lib/response-validation.js.map +0 -1
  264. package/lib/retry-after.js.map +0 -1
  265. package/lib/retry.js.map +0 -1
  266. package/lib/schema-lite-impl.js.map +0 -1
  267. package/lib/schema-lite-typed.js.map +0 -1
  268. package/lib/schema-lite.js.map +0 -1
  269. package/lib/schema.js.map +0 -1
  270. package/lib/testing.d.ts +0 -40
  271. package/lib/testing.d.ts.map +0 -1
  272. package/lib/testing.js +0 -42
  273. package/lib/testing.js.map +0 -1
  274. package/lib/trait.js.map +0 -1
  275. package/lib/xml.js.map +0 -1
  276. package/src/codegen/boolean-string-enums.ts +0 -155
  277. package/src/codegen/chunk.ts +0 -147
  278. package/src/codegen/cli.ts +0 -293
  279. package/src/codegen/datafy.ts +0 -874
  280. package/src/codegen/dedupe.ts +0 -173
  281. package/src/codegen/emit.ts +0 -200
  282. package/src/codegen/format.ts +0 -49
  283. package/src/codegen/generated-at.ts +0 -88
  284. package/src/codegen/generator.ts +0 -1229
  285. package/src/codegen/graph.ts +0 -151
  286. package/src/codegen/graphql-client.ts +0 -545
  287. package/src/codegen/graphql.ts +0 -1145
  288. package/src/codegen/latin1.ts +0 -131
  289. package/src/codegen/members.ts +0 -79
  290. package/src/codegen/model-diff.ts +0 -67
  291. package/src/codegen/naming.ts +0 -85
  292. package/src/codegen/openapi-cli.ts +0 -141
  293. package/src/codegen/openapi.ts +0 -1845
  294. package/src/codegen/operations.ts +0 -73
  295. package/src/codegen/pagination.ts +0 -64
  296. package/src/codegen/patch-audit.ts +0 -480
  297. package/src/codegen/patches.ts +0 -581
  298. package/src/codegen/prelude.ts +0 -70
  299. package/src/codegen/privatize.ts +0 -200
  300. package/src/codegen/proto.ts +0 -1092
  301. package/src/codegen/pure.ts +0 -94
  302. package/src/codegen/rewrite-operation-ids.ts +0 -1219
  303. package/src/codegen/spec-path.ts +0 -112
  304. package/src/codegen/table.ts +0 -254
  305. package/src/json-patch.ts +0 -273
  306. package/src/testing.ts +0 -74
@@ -1,40 +1,15 @@
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`) -> in strict mode, a schema check
16
- * failing with the provider's `parseError` (see
17
- * `core/response-validation`) -> `Redacted` wrapping of members
18
- * marked with {@link SensitiveValue}; non-2xx -> typed error:
19
- * per-op matcher classes (`matchTypedError`), then the status
20
- * map (default `HTTP_STATUS_MAP`), then an `InternalServerError`
21
- * for unmapped 5xx, then the provider's `unknownError` fallback
22
- * -- with `retryAfter` durations stamped from the standard hint
23
- * headers on retryable statuses.
24
- *
25
- * Anything provider-specific (envelope quirks, bespoke error codes) belongs
26
- * in the provider package -- via these options or a hand-written protocol.
27
- */
28
1
  import * as Context from "effect/Context";
29
2
  import * as Effect from "effect/Effect";
30
3
  import * as Layer from "effect/Layer";
31
4
  import type * as AST from "effect/SchemaAST";
5
+ import { rawResponseRootSymbol } from "./annotations.ts";
32
6
  import * as API from "./api.ts";
33
7
  import { unwrapRedactedDeep } from "./plain-values.ts";
34
8
  export declare const sensitiveValueSymbol: unique symbol;
35
9
  /**
36
- * Marks a string member as sensitive (mirrors `smithy.api#sensitive`).
37
- * The REST protocol wraps decoded values in `Redacted` on the way out and
10
+ * Marks a string member, map value or list element as sensitive (mirrors
11
+ * `smithy.api#sensitive`). The REST protocol wraps decoded values in
12
+ * `Redacted` on the way out (an untyped `S.Unknown` value whole) and
38
13
  * accepts `string | Redacted<string>` on the way in (unwrapped before
39
14
  * serialization). Takes an ignored argument so generators can inline the
40
15
  * smithy trait value (`T.SensitiveValue({})`).
@@ -46,28 +21,30 @@ export declare const rawResponseSymbol: unique symbol;
46
21
  * body (mirrors `com.distilled.openapi#rawResponse`).
47
22
  */
48
23
  export declare const RawResponse: (_value?: unknown) => import("./trait.ts").Annotation;
49
- export declare const rawResponseRootSymbol: unique symbol;
50
24
  /**
51
25
  * Marks a response schema whose ENTIRE value is the response body (the
52
26
  * generator's `rootPipe` for synthesized bare-payload wrappers): the emitted
53
27
  * response type IS the payload type and the protocol returns the mapped body
54
28
  * directly.
55
29
  */
30
+ export { rawResponseRootSymbol };
56
31
  export declare const RawResponseRoot: () => import("./trait.ts").Annotation;
57
32
  export declare const binaryResponseSymbol: unique symbol;
58
33
  /** Decode a successful raw binary response as bytes, without text conversion. */
59
34
  export declare const BinaryResponse: () => import("./trait.ts").Annotation;
60
35
  export { unwrapRedactedDeep };
61
36
  /**
62
- * Walk a decoded (TS-named) value alongside its schema AST, wrapping members
63
- * marked {@link SensitiveValue} in `Redacted`. Keys the schema doesn't model
64
- * pass through verbatim.
37
+ * Walk a decoded (TS-named) value alongside its schema AST, wrapping values
38
+ * marked {@link SensitiveValue} (members, map values, list elements) in
39
+ * `Redacted`. Keys the schema doesn't model pass through. A union applies
40
+ * every arm in turn; a map arm skips keys a sibling arm names.
65
41
  */
66
- export declare const wrapSensitive: (ast: AST.AST, value: unknown) => unknown;
42
+ export declare const wrapSensitive: (ast: AST.AST, value: unknown, siblingNames?: ReadonlySet<string>) => unknown;
67
43
  /**
68
- * Whether any member reachable from `ast` is marked {@link SensitiveValue}.
69
- * Parse errors for such an output withhold the response body (see
70
- * {@link RestParseErrorInfo}); hand-written protocols use this to do the same.
44
+ * Whether any member, map value or list element reachable from `ast` is
45
+ * marked {@link SensitiveValue}. Such an output is decoded through
46
+ * {@link wrapSensitive}, and its parse errors withhold the response body (see
47
+ * {@link checkSuccess}, which every REST-style protocol's success path uses).
71
48
  */
72
49
  export declare const hasSensitiveMember: (ast: AST.AST) => boolean;
73
50
  /** What the wire said about a failure, for the `unknownError` fallback. */
@@ -153,8 +130,45 @@ export interface RestProtocolOptions<C> {
153
130
  /** Passed through to `buildRequest` (wire names for unmodeled input keys). */
154
131
  readonly unknownKeyToWire?: (key: string) => string;
155
132
  }
156
- /** Whether {@link wrapSensitive} can change any value of `root`. Cached per schema. */
157
- export declare const hasSensitive: (root: AST.AST) => boolean;
133
+ /** A 2xx body a protocol read, for {@link checkSuccess}. */
134
+ export interface SuccessBody {
135
+ /** The value to check and return: the body mapped onto the output's TS names. */
136
+ readonly value: unknown;
137
+ /** What a parse error reports as `body` for an output without sensitive members. */
138
+ readonly body: unknown;
139
+ /** Whether the body was not JSON. */
140
+ readonly nonJson: boolean;
141
+ }
142
+ /** The outcome of {@link checkSuccess}: the value, or the parse error's fields. */
143
+ export type SuccessCheck = {
144
+ readonly ok: true;
145
+ readonly value: unknown;
146
+ } | {
147
+ readonly ok: false;
148
+ readonly error: RestParseErrorInfo;
149
+ };
150
+ /**
151
+ * Check a 2xx body against the operation's output schema and deliver its
152
+ * sensitive values as `Redacted`. Every REST-style protocol ends its success
153
+ * path here, so all of them treat a body that can hold a secret alike:
154
+ *
155
+ * - The checked value comes back through {@link wrapSensitive}.
156
+ * - A mismatch (validating modes, see `core/response-validation`) reports
157
+ * `read.body` and the schema error.
158
+ * - For an output with sensitive members ({@link hasSensitiveMember}), a
159
+ * non-JSON body fails in every mode with `"Invalid JSON response"`, and a
160
+ * mismatch reports `body: "[REDACTED]"` and the schema error without the
161
+ * value it found (`withholdActual`).
162
+ *
163
+ * Synchronous, for protocols that already hold the calling fiber's context;
164
+ * {@link validateSuccess} is the `Effect` form.
165
+ */
166
+ export declare const checkSuccess: (context: Context.Context<any>, outputAst: AST.AST, read: SuccessBody) => SuccessCheck;
167
+ /**
168
+ * {@link checkSuccess} on the calling fiber, failing with `parseError` (the
169
+ * SDK's `<Sdk>ParseError`) built from the withheld-or-not fields.
170
+ */
171
+ export declare const validateSuccess: <E>(outputAst: AST.AST, read: SuccessBody, parseError: (info: RestParseErrorInfo) => E) => Effect.Effect<unknown, E>;
158
172
  /**
159
173
  * Build a `Layer<Protocol>` for a simple REST JSON API. Assign the result to
160
174
  * a module-level const in the provider's `protocol.ts` -- `API.make` memoizes
@@ -1 +1 @@
1
- {"version":3,"file":"protocol-rest.d.ts","sourceRoot":"","sources":["../src/protocol-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAGhC,OAAO,EAAiB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAsBtE,eAAO,MAAM,oBAAoB,eAEhC,CAAC;AACF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,YAAa,OAAO,oCAA+C,CAAC;AAE/F,eAAO,MAAM,iBAAiB,eAAiE,CAAC;AAChG;;;GAGG;AACH,eAAO,MAAM,WAAW,YAAa,OAAO,oCAA4C,CAAC;AAEzF,eAAO,MAAM,qBAAqB,eAEjC,CAAC;AACF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,uCAAoD,CAAC;AAEjF,eAAO,MAAM,oBAAoB,eAEhC,CAAC;AAEF,iFAAiF;AACjF,eAAO,M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AAM,eAAe,GAAI,CAAC,aACpB,GAAG,CAAC,GAAG,QACZ,WAAW,cACL,CAAC,IAAI,EAAE,kBAAkB,KAAK,CAAC,KAC1C,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAIvB,CAAC;AAgCL;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,WAAW,mBAAmB,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CA+M7F,CAAC"}
@@ -1,375 +1 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
- import * as Context from "effect/Context";
29
- import * as Effect from "effect/Effect";
30
- import * as HttpClient from "effect/http/HttpClient";
31
- import * as Layer from "effect/Layer";
32
- import * as Redacted from "effect/Redacted";
33
- import * as API from "./api.js";
34
- import { debugHttp } from "./debug.js";
35
- import { HTTP_STATUS_MAP, InternalServerError } from "./errors.js";
36
- import { isOpaqueValue, unwrapRedactedDeep } from "./plain-values.js";
37
- import { buildRequest, getAnn, getPropAnn, getProps, mapKeys, mapsVerbatim, matchTypedError, resolveNode, responseHeaderMembers, withResponseHeaders, } from "./protocol-http.js";
38
- import { checkResponse, withholdActual } from "./response-validation.js";
39
- import { parseRetryAfterForStatus } from "./retry-after.js";
40
- import { httpSymbol, makeAnnotation } from "./trait.js";
41
- // =============================================================================
42
- // Traits
43
- // =============================================================================
44
- export const sensitiveValueSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/sensitive-value");
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
- export const SensitiveValue = (_value) => makeAnnotation(sensitiveValueSymbol, true);
53
- export const rawResponseSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/raw-response");
54
-
55
-
56
-
57
-
58
- export const RawResponse = (_value) => makeAnnotation(rawResponseSymbol, true);
59
- export const rawResponseRootSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/raw-response-root");
60
-
61
-
62
-
63
-
64
-
65
-
66
- export const RawResponseRoot = () => makeAnnotation(rawResponseRootSymbol, true);
67
- export const binaryResponseSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/binary-response");
68
-
69
- export const BinaryResponse = () => makeAnnotation(binaryResponseSymbol, true);
70
- // =============================================================================
71
- // Value helpers
72
- // =============================================================================
73
- export { unwrapRedactedDeep };
74
-
75
-
76
-
77
-
78
-
79
- export const wrapSensitive = (ast, value) => {
80
- if (value === null || typeof value !== "object" || isOpaqueValue(value)) {
81
- return value;
82
- }
83
- const node = resolveNode(ast);
84
- if (node._tag === "Union") {
85
- // Redact every possible sensitive member, including in partial responses.
86
- return node.types.reduce((redacted, arm) => wrapSensitive(arm, redacted), value);
87
- }
88
- if (node._tag === "Arrays") {
89
- if (!Array.isArray(value))
90
- return value;
91
- const elem = node.rest?.[0];
92
- return elem ? value.map((v) => wrapSensitive(elem, v)) : value;
93
- }
94
- if (node._tag === "Objects" && !Array.isArray(value)) {
95
- const props = getProps(node);
96
- if (props.length === 0)
97
- return value;
98
- const byName = new Map(props.map((p) => [String(p.name), p]));
99
- const out = {};
100
- for (const [k, v] of Object.entries(value)) {
101
- if (v === undefined)
102
- continue;
103
- const prop = byName.get(k);
104
- if (!prop) {
105
- out[k] = v;
106
- }
107
- else if (getPropAnn(prop, sensitiveValueSymbol) !== undefined && typeof v === "string") {
108
- out[k] = Redacted.make(v);
109
- }
110
- else {
111
- out[k] = wrapSensitive(prop.type, v);
112
- }
113
- }
114
- return out;
115
- }
116
- return value;
117
- };
118
- const sensitiveOutputs = /*@__PURE__*/ new WeakMap();
119
-
120
-
121
-
122
-
123
-
124
- export const hasSensitiveMember = (ast) => {
125
- const cached = sensitiveOutputs.get(ast);
126
- if (cached !== undefined)
127
- return cached;
128
- const seen = new Set();
129
- const visit = (node) => {
130
- node = resolveNode(node);
131
- if (seen.has(node))
132
- return false;
133
- seen.add(node);
134
- if (node._tag === "Union")
135
- return node.types.some(visit);
136
- if (node._tag === "Arrays") {
137
- return [...node.elements, ...node.rest].some((e) => getAnn(e, sensitiveValueSymbol) !== undefined || visit(e));
138
- }
139
- if (node._tag !== "Objects")
140
- return false;
141
- return [...node.propertySignatures, ...node.indexSignatures].some((member) => getAnn(member.type, sensitiveValueSymbol) !== undefined || visit(member.type));
142
- };
143
- const result = visit(ast);
144
- sensitiveOutputs.set(ast, result);
145
- return result;
146
- };
147
- const defaultErrorEnvelope = (body) => {
148
- if (body === null || typeof body !== "object")
149
- return undefined;
150
- const b = body;
151
- const code = typeof b.code === "string" || typeof b.code === "number" ? b.code : undefined;
152
- const message = typeof b.message === "string" ? b.message : typeof b.error === "string" ? b.error : undefined;
153
- return { code, message };
154
- };
155
- // Bridge: Protocol.decode is typed as Effect<unknown> (no error channel),
156
- // but REST failures are real typed errors that operations re-surface via
157
- // their `errors: [...]` lists. Fail with the instance and erase the type
158
- // here; the generated operation annotations reintroduce it for callers.
159
- const fail = (e) => Effect.fail(e);
160
-
161
- export const hasSensitive = (root) => {
162
- let result = sensitiveCache.get(root);
163
- if (result !== undefined)
164
- return result;
165
- result = false;
166
- const seen = new Set();
167
- const stack = [root];
168
- walk: while (stack.length > 0) {
169
- const ast = stack.pop();
170
- if (seen.has(ast))
171
- continue;
172
- seen.add(ast);
173
- const node = resolveNode(ast);
174
- if (node._tag === "Union") {
175
- for (const t of node.types)
176
- stack.push(t);
177
- }
178
- else if (node._tag === "Arrays") {
179
- const elem = node.rest?.[0];
180
- if (elem)
181
- stack.push(elem);
182
- }
183
- else if (node._tag === "Objects") {
184
- for (const p of getProps(node)) {
185
- if (getPropAnn(p, sensitiveValueSymbol) !== undefined) {
186
- result = true;
187
- break walk;
188
- }
189
- stack.push(p.type);
190
- }
191
- }
192
- }
193
- sensitiveCache.set(root, result);
194
- return result;
195
- };
196
- const sensitiveCache = /*@__PURE__*/ new WeakMap();
197
- const decodePlans = /*@__PURE__*/ new WeakMap();
198
- const decodePlanFor = (outputAst) => {
199
- let plan = decodePlans.get(outputAst);
200
- if (plan === undefined) {
201
- plan = {
202
- binary: getAnn(outputAst, binaryResponseSymbol) !== undefined,
203
- verbatim: mapsVerbatim(outputAst, "decode"),
204
- sensitive: hasSensitive(outputAst),
205
- withholdBody: hasSensitiveMember(outputAst),
206
- headers: responseHeaderMembers(outputAst),
207
- };
208
- decodePlans.set(outputAst, plan);
209
- }
210
- return plan;
211
- };
212
-
213
-
214
-
215
-
216
-
217
- export const makeRestProtocol = (options) => {
218
- const errorEnvelope = options.errorEnvelope ?? defaultErrorEnvelope;
219
- const statusMap = options.statusMap ?? HTTP_STATUS_MAP;
220
- const credentialsKey = Context.isKey(options.credentials)
221
- ? options.credentials
222
- : undefined;
223
- const credentialsEffect = options.credentials;
224
-
225
- const withCredentials = (context, f) => API.withValue(credentialsKey === undefined ? credentialsEffect : Context.get(context, credentialsKey), f);
226
-
227
- const requestFor = (creds, input, inputAst) => {
228
- const http = getAnn(inputAst, httpSymbol);
229
- let baseUrl;
230
- try {
231
- baseUrl = options.baseUrl(creds, {
232
- uri: http?.uri ?? "",
233
- method: http?.method ?? "",
234
- });
235
- }
236
- catch (e) {
237
- // A baseUrl that refuses the route (missing scope in the
238
- // credentials) fails the call with that error, typed for callers by
239
- // the operation's declared error channel.
240
- return { refused: e };
241
- }
242
- return buildRequest({
243
- input: unwrapRedactedDeep(input),
244
- inputAst,
245
- baseUrl,
246
- headers: options.headers(creds),
247
- mapMemberHeader: options.mapMemberHeader,
248
- unknownKeyToWire: options.unknownKeyToWire,
249
- });
250
- };
251
-
252
- const decodeText = (context, status, headers, text, outputAst, errorClasses) => {
253
- // Read as text and parse tolerantly -- error pages are often non-JSON.
254
- if (debugHttp()) {
255
- console.error(`[distilled] <- ${status}`);
256
- }
257
- let json;
258
- let nonJson = false;
259
- if (text.trim().length > 0) {
260
- try {
261
- json = JSON.parse(text);
262
- }
263
- catch {
264
- nonJson = true;
265
- }
266
- }
267
- if (status >= 400) {
268
- const env = (nonJson ? undefined : errorEnvelope(json)) ?? {};
269
- const message = env.message ?? (nonJson && text.trim() ? text.trim() : `HTTP ${status}`);
270
- // 1. Per-operation typed error (matcher metadata on the class).
271
- const typed = matchTypedError(errorClasses, status, [
272
- {
273
- code: typeof env.code === "number" ? env.code : undefined,
274
- message,
275
- },
276
- ], { body: nonJson ? text : json, headers });
277
- if (typed !== undefined)
278
- return { ok: false, error: typed };
279
- // 2. Status-mapped class (retryAfter only stamps on retryable
280
- // statuses -- parseRetryAfterForStatus gates on that).
281
- const StatusErrorClass = statusMap[status];
282
- if (StatusErrorClass) {
283
- return {
284
- ok: false,
285
- error: new StatusErrorClass({
286
- message,
287
- retryAfter: parseRetryAfterForStatus(status, headers),
288
- }),
289
- };
290
- }
291
- // 3. Unmapped 5xx (e.g. proxy-specific statuses) -> retryable server
292
- // error rather than the unknown fallback.
293
- if (status >= 500) {
294
- return {
295
- ok: false,
296
- error: new InternalServerError({
297
- message,
298
- retryAfter: parseRetryAfterForStatus(status, headers),
299
- }),
300
- };
301
- }
302
- // 4. Provider fallback.
303
- return {
304
- ok: false,
305
- error: options.unknownError({
306
- status,
307
- code: env.code,
308
- message,
309
- body: nonJson ? text : json,
310
- headers,
311
- }),
312
- };
313
- }
314
- // 2xx: the response body IS the payload (no envelope). Wire->TS key
315
- // mapping is schema-driven; `RawResponseRoot` responses are the body
316
- // verbatim (mapKeys handles arrays/scalars structurally either way).
317
- // Strict mode (core/response-validation) checks the mapped body against
318
- // the output schema -- a non-JSON body reaches it as a string and fails
319
- // there unless the operation's output is itself a string. For an output
320
- // with sensitive members, a non-JSON body fails in every mode and parse
321
- // errors withhold the body.
322
- const plan = decodePlanFor(outputAst);
323
- if (nonJson && plan.withholdBody) {
324
- return {
325
- ok: false,
326
- error: options.parseError({ body: "[REDACTED]", cause: "Invalid JSON response" }),
327
- };
328
- }
329
- let body = nonJson ? text : (json ?? {});
330
- if (options.transformResponse)
331
- body = options.transformResponse(body);
332
- const mapped = withResponseHeaders(plan.headers, plan.verbatim ? body : mapKeys(outputAst, body, "decode"), headers);
333
- const invalid = checkResponse(context, outputAst, mapped);
334
- if (invalid !== undefined) {
335
- return {
336
- ok: false,
337
- error: options.parseError({
338
- body: plan.withholdBody ? "[REDACTED]" : nonJson ? text : json,
339
- cause: plan.withholdBody ? withholdActual(invalid) : invalid,
340
- }),
341
- };
342
- }
343
- return { ok: true, value: plan.sensitive ? wrapSensitive(outputAst, mapped) : mapped };
344
- };
345
- const decodeResponse = (context, response, outputAst, errorClasses) => response.status >= 200 && response.status < 300 && decodePlanFor(outputAst).binary
346
- ? Effect.map(Effect.orDie(response.arrayBuffer), (bytes) => new Uint8Array(bytes))
347
- : Effect.matchEffect(response.text, {
348
- onFailure: Effect.die,
349
- onSuccess: (text) => {
350
- const decoded = decodeText(context, response.status, response.headers, text ?? "", outputAst, errorClasses);
351
- return decoded.ok ? Effect.succeed(decoded.value) : fail(decoded.error);
352
- },
353
- });
354
- const call = (op, input) => Effect.withFiber((fiber) => {
355
- const context = fiber.context;
356
- return withCredentials(context, (creds) => {
357
- const request = requestFor(creds, input, op.inputAst);
358
- if ("refused" in request)
359
- return fail(request.refused);
360
- const client = Context.get(context, HttpClient.HttpClient);
361
- return Effect.flatMap(client.execute(request), (response) => decodeResponse(context, response, op.outputAst, op.errors));
362
- });
363
- });
364
- return Layer.succeed(API.Protocol, API.Protocol.of({
365
- // Erase encode's credentials requirement (resolved on the calling
366
- // fiber; see RestProtocolOptions.credentials).
367
- encode: ({ input, inputAst }) => Effect.withFiber((fiber) => withCredentials(fiber.context, (creds) => {
368
- const request = requestFor(creds, input, inputAst);
369
- return "refused" in request ? fail(request.refused) : Effect.succeed(request);
370
- })),
371
- decode: ({ response, outputAst, errors }) => Effect.withFiber((fiber) => decodeResponse(fiber.context, response, outputAst, errors)),
372
- call,
373
- }));
374
- };
375
- //# sourceMappingURL=protocol-rest.js.map
1
+ export { protocol_rest$BinaryResponse as BinaryResponse, 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$hasSensitiveMember as hasSensitiveMember, protocol_rest$makeRestProtocol as makeRestProtocol, protocol_rest$rawResponseRootSymbol as rawResponseRootSymbol, protocol_rest$rawResponseSymbol as rawResponseSymbol, protocol_rest$sensitiveValueSymbol as sensitiveValueSymbol, protocol_rest$unwrapRedactedDeep as unwrapRedactedDeep, protocol_rest$validateSuccess as validateSuccess, protocol_rest$wrapSensitive as wrapSensitive } from "./_bundle/rest.js";
package/lib/query.js CHANGED
@@ -1,27 +1 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
- import { filterQuery, flatMapQuery, itemsQuery, mapQuery, ofQuery, pagesQuery, queryFn, } from "./graphql.js";
18
- export const Query = {
19
- fn: queryFn,
20
- filter: filterQuery,
21
- map: mapQuery,
22
- flatMap: flatMapQuery,
23
- of: ofQuery,
24
- pages: pagesQuery,
25
- items: itemsQuery,
26
- };
27
- //# sourceMappingURL=query.js.map
1
+ export { query$Query as Query } from "./_bundle/graphql.js";