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

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 (291) hide show
  1. package/LICENSE +201 -0
  2. package/lib/_bundle/aws.js +2 -0
  3. package/lib/_bundle/aws.js.map +1 -0
  4. package/lib/_bundle/base.js +5 -0
  5. package/lib/_bundle/base.js.map +1 -0
  6. package/lib/_bundle/graphql.js +3 -0
  7. package/lib/_bundle/graphql.js.map +1 -0
  8. package/lib/_bundle/grpc.js +2 -0
  9. package/lib/_bundle/grpc.js.map +1 -0
  10. package/lib/_bundle/rest.js +2 -0
  11. package/lib/_bundle/rest.js.map +1 -0
  12. package/lib/_bundle/xml.js +4 -0
  13. package/lib/_bundle/xml.js.map +1 -0
  14. package/lib/annotations.d.ts +17 -0
  15. package/lib/annotations.d.ts.map +1 -0
  16. package/lib/annotations.js +2 -0
  17. package/lib/annotations.js.map +1 -0
  18. package/lib/api.d.ts +174 -18
  19. package/lib/api.d.ts.map +1 -1
  20. package/lib/api.js +1 -178
  21. package/lib/category.d.ts +4 -4
  22. package/lib/category.d.ts.map +1 -1
  23. package/lib/category.js +1 -280
  24. package/lib/chunks.d.ts +3 -0
  25. package/lib/chunks.d.ts.map +1 -0
  26. package/lib/chunks.js +1 -0
  27. package/lib/config.d.ts +68 -0
  28. package/lib/config.d.ts.map +1 -0
  29. package/lib/config.js +1 -0
  30. package/lib/crypto.d.ts +76 -0
  31. package/lib/crypto.d.ts.map +1 -0
  32. package/lib/crypto.js +1 -0
  33. package/lib/error-category.d.ts +1 -1
  34. package/lib/error-category.d.ts.map +1 -1
  35. package/lib/error-category.js +1 -46
  36. package/lib/errors.d.ts +64 -72
  37. package/lib/errors.d.ts.map +1 -1
  38. package/lib/errors.js +1 -186
  39. package/lib/graphql.d.ts +403 -0
  40. package/lib/graphql.d.ts.map +1 -0
  41. package/lib/graphql.js +1 -0
  42. package/lib/graphql.types.d.ts +12 -0
  43. package/lib/graphql.types.d.ts.map +1 -0
  44. package/lib/graphql.types.js +1 -0
  45. package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
  46. package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
  47. package/lib/grpc-transport-cloudflare-http2.js +6 -0
  48. package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
  49. package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
  50. package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
  51. package/lib/grpc-transport-cloudflare-sockets.js +5 -0
  52. package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
  53. package/lib/grpc-transport-node-http2.d.ts +19 -0
  54. package/lib/grpc-transport-node-http2.d.ts.map +1 -0
  55. package/lib/grpc-transport-node-http2.js +2 -0
  56. package/lib/grpc-transport-node-http2.js.map +1 -0
  57. package/lib/grpc-transport.d.ts +76 -0
  58. package/lib/grpc-transport.d.ts.map +1 -0
  59. package/lib/grpc-transport.js +1 -0
  60. package/lib/hpack.d.ts +34 -0
  61. package/lib/hpack.d.ts.map +1 -0
  62. package/lib/hpack.js +2 -0
  63. package/lib/hpack.js.map +1 -0
  64. package/lib/index.d.ts +32 -0
  65. package/lib/index.d.ts.map +1 -0
  66. package/lib/index.js +17 -0
  67. package/lib/pagination.d.ts +101 -24
  68. package/lib/pagination.d.ts.map +1 -1
  69. package/lib/pagination.js +1 -182
  70. package/lib/plain-values.d.ts +10 -0
  71. package/lib/plain-values.d.ts.map +1 -0
  72. package/lib/plain-values.js +2 -0
  73. package/lib/plain-values.js.map +1 -0
  74. package/lib/protobuf.d.ts +92 -0
  75. package/lib/protobuf.d.ts.map +1 -0
  76. package/lib/protobuf.js +1 -0
  77. package/lib/protocol-grpc.d.ts +86 -0
  78. package/lib/protocol-grpc.d.ts.map +1 -0
  79. package/lib/protocol-grpc.js +1 -0
  80. package/lib/protocol-http.d.ts +102 -23
  81. package/lib/protocol-http.d.ts.map +1 -1
  82. package/lib/protocol-http.js +1 -554
  83. package/lib/protocol-rest.d.ts +120 -50
  84. package/lib/protocol-rest.d.ts.map +1 -1
  85. package/lib/protocol-rest.js +1 -242
  86. package/lib/query.d.ts +29 -0
  87. package/lib/query.d.ts.map +1 -0
  88. package/lib/query.js +1 -0
  89. package/lib/response-validation-strict.d.ts +48 -0
  90. package/lib/response-validation-strict.d.ts.map +1 -0
  91. package/lib/response-validation-strict.js +1 -0
  92. package/lib/response-validation.d.ts +86 -0
  93. package/lib/response-validation.d.ts.map +1 -0
  94. package/lib/response-validation.js +1 -0
  95. package/lib/retry-after.d.ts +3 -3
  96. package/lib/retry-after.d.ts.map +1 -1
  97. package/lib/retry-after.js +1 -112
  98. package/lib/retry.d.ts +48 -29
  99. package/lib/retry.d.ts.map +1 -1
  100. package/lib/retry.js +1 -210
  101. package/lib/schema-lite-impl.d.ts +158 -0
  102. package/lib/schema-lite-impl.d.ts.map +1 -0
  103. package/lib/schema-lite-impl.js +1 -0
  104. package/lib/schema-lite-typed.d.ts +41 -0
  105. package/lib/schema-lite-typed.d.ts.map +1 -0
  106. package/lib/schema-lite-typed.js +1 -0
  107. package/lib/schema-lite.d.ts +40 -0
  108. package/lib/schema-lite.d.ts.map +1 -0
  109. package/lib/schema-lite.js +1 -0
  110. package/lib/schema.d.ts +21 -7
  111. package/lib/schema.d.ts.map +1 -1
  112. package/lib/schema.js +1 -48
  113. package/lib/sdk-error.d.ts +27 -0
  114. package/lib/sdk-error.d.ts.map +1 -0
  115. package/lib/sdk-error.js +1 -0
  116. package/lib/sensitive.d.ts +28 -0
  117. package/lib/sensitive.d.ts.map +1 -0
  118. package/lib/sensitive.js +2 -0
  119. package/lib/sensitive.js.map +1 -0
  120. package/lib/telemetry-debug.d.ts +6 -0
  121. package/lib/telemetry-debug.d.ts.map +1 -0
  122. package/lib/telemetry-debug.js +2 -0
  123. package/lib/telemetry-debug.js.map +1 -0
  124. package/lib/telemetry-hooks.d.ts +32 -0
  125. package/lib/telemetry-hooks.d.ts.map +1 -0
  126. package/lib/telemetry-hooks.js +2 -0
  127. package/lib/telemetry-hooks.js.map +1 -0
  128. package/lib/telemetry-host-rules.d.ts +23 -0
  129. package/lib/telemetry-host-rules.d.ts.map +1 -0
  130. package/lib/telemetry-host-rules.js +2 -0
  131. package/lib/telemetry-host-rules.js.map +1 -0
  132. package/lib/telemetry-lambda-context.d.ts +17 -0
  133. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  134. package/lib/telemetry-lambda-context.js +2 -0
  135. package/lib/telemetry-lambda-context.js.map +1 -0
  136. package/lib/telemetry-message-context.d.ts +52 -0
  137. package/lib/telemetry-message-context.d.ts.map +1 -0
  138. package/lib/telemetry-message-context.js +2 -0
  139. package/lib/telemetry-message-context.js.map +1 -0
  140. package/lib/telemetry-metrics.d.ts +6 -0
  141. package/lib/telemetry-metrics.d.ts.map +1 -0
  142. package/lib/telemetry-metrics.js +2 -0
  143. package/lib/telemetry-metrics.js.map +1 -0
  144. package/lib/telemetry-name-template.d.ts +13 -0
  145. package/lib/telemetry-name-template.d.ts.map +1 -0
  146. package/lib/telemetry-name-template.js +2 -0
  147. package/lib/telemetry-name-template.js.map +1 -0
  148. package/lib/telemetry-stream.d.ts +11 -0
  149. package/lib/telemetry-stream.d.ts.map +1 -0
  150. package/lib/telemetry-stream.js +2 -0
  151. package/lib/telemetry-stream.js.map +1 -0
  152. package/lib/telemetry-xray.d.ts +28 -0
  153. package/lib/telemetry-xray.d.ts.map +1 -0
  154. package/lib/telemetry-xray.js +2 -0
  155. package/lib/telemetry-xray.js.map +1 -0
  156. package/lib/telemetry.d.ts +288 -0
  157. package/lib/telemetry.d.ts.map +1 -0
  158. package/lib/telemetry.js +3 -0
  159. package/lib/telemetry.js.map +1 -0
  160. package/lib/trait.d.ts +71 -20
  161. package/lib/trait.d.ts.map +1 -1
  162. package/lib/trait.js +1 -107
  163. package/lib/unknown-error.d.ts +18 -0
  164. package/lib/unknown-error.d.ts.map +1 -0
  165. package/lib/unknown-error.js +1 -0
  166. package/lib/xml.d.ts +44 -0
  167. package/lib/xml.d.ts.map +1 -0
  168. package/lib/xml.js +1 -0
  169. package/package.json +13 -13
  170. package/src/annotations.ts +53 -0
  171. package/src/api.ts +1370 -200
  172. package/src/category.ts +76 -106
  173. package/src/chunks.ts +30 -0
  174. package/src/config.ts +245 -0
  175. package/src/crypto.ts +202 -0
  176. package/src/error-category.ts +16 -29
  177. package/src/errors.ts +75 -75
  178. package/src/graphql.ts +1778 -0
  179. package/src/graphql.types.ts +105 -0
  180. package/src/grpc-transport-cloudflare-http2.ts +494 -0
  181. package/src/grpc-transport-cloudflare-sockets.ts +299 -0
  182. package/src/grpc-transport-node-http2.ts +234 -0
  183. package/src/grpc-transport.ts +118 -0
  184. package/src/hpack.ts +331 -0
  185. package/src/index.ts +31 -0
  186. package/src/pagination.ts +368 -94
  187. package/src/plain-values.ts +41 -0
  188. package/src/protobuf.ts +1332 -0
  189. package/src/protocol-grpc.ts +641 -0
  190. package/src/protocol-http.ts +622 -322
  191. package/src/protocol-rest.ts +440 -227
  192. package/src/query.ts +39 -0
  193. package/src/response-validation-strict.ts +327 -0
  194. package/src/response-validation.ts +161 -0
  195. package/src/retry-after.ts +7 -13
  196. package/src/retry.ts +96 -110
  197. package/src/schema-lite-impl.ts +550 -0
  198. package/src/schema-lite-typed.ts +44 -0
  199. package/src/schema-lite.ts +44 -0
  200. package/src/schema.ts +259 -15
  201. package/src/sdk-error.ts +33 -0
  202. package/src/sensitive.ts +154 -0
  203. package/src/telemetry-debug.ts +179 -0
  204. package/src/telemetry-hooks.ts +33 -0
  205. package/src/telemetry-host-rules.ts +39 -0
  206. package/src/telemetry-lambda-context.ts +46 -0
  207. package/src/telemetry-message-context.ts +170 -0
  208. package/src/telemetry-metrics.ts +69 -0
  209. package/src/telemetry-name-template.ts +26 -0
  210. package/src/telemetry-stream.ts +100 -0
  211. package/src/telemetry-xray.ts +66 -0
  212. package/src/telemetry.ts +832 -0
  213. package/src/trait.ts +106 -67
  214. package/src/unknown-error.ts +38 -0
  215. package/src/xml.ts +346 -0
  216. package/lib/api.js.map +0 -1
  217. package/lib/category.js.map +0 -1
  218. package/lib/codegen/cli.d.ts +0 -29
  219. package/lib/codegen/cli.d.ts.map +0 -1
  220. package/lib/codegen/cli.js +0 -165
  221. package/lib/codegen/cli.js.map +0 -1
  222. package/lib/codegen/emit.d.ts +0 -129
  223. package/lib/codegen/emit.d.ts.map +0 -1
  224. package/lib/codegen/emit.js +0 -105
  225. package/lib/codegen/emit.js.map +0 -1
  226. package/lib/codegen/format.d.ts +0 -23
  227. package/lib/codegen/format.d.ts.map +0 -1
  228. package/lib/codegen/format.js +0 -28
  229. package/lib/codegen/format.js.map +0 -1
  230. package/lib/codegen/generator.d.ts +0 -334
  231. package/lib/codegen/generator.d.ts.map +0 -1
  232. package/lib/codegen/generator.js +0 -691
  233. package/lib/codegen/generator.js.map +0 -1
  234. package/lib/codegen/graph.d.ts +0 -36
  235. package/lib/codegen/graph.d.ts.map +0 -1
  236. package/lib/codegen/graph.js +0 -136
  237. package/lib/codegen/graph.js.map +0 -1
  238. package/lib/codegen/members.d.ts +0 -25
  239. package/lib/codegen/members.d.ts.map +0 -1
  240. package/lib/codegen/members.js +0 -55
  241. package/lib/codegen/members.js.map +0 -1
  242. package/lib/codegen/naming.d.ts +0 -29
  243. package/lib/codegen/naming.d.ts.map +0 -1
  244. package/lib/codegen/naming.js +0 -74
  245. package/lib/codegen/naming.js.map +0 -1
  246. package/lib/codegen/openapi-cli.d.ts +0 -38
  247. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  248. package/lib/codegen/openapi-cli.js +0 -107
  249. package/lib/codegen/openapi-cli.js.map +0 -1
  250. package/lib/codegen/openapi.d.ts +0 -115
  251. package/lib/codegen/openapi.d.ts.map +0 -1
  252. package/lib/codegen/openapi.js +0 -1220
  253. package/lib/codegen/openapi.js.map +0 -1
  254. package/lib/codegen/operations.d.ts +0 -24
  255. package/lib/codegen/operations.d.ts.map +0 -1
  256. package/lib/codegen/operations.js +0 -56
  257. package/lib/codegen/operations.js.map +0 -1
  258. package/lib/codegen/pagination.d.ts +0 -39
  259. package/lib/codegen/pagination.d.ts.map +0 -1
  260. package/lib/codegen/pagination.js +0 -33
  261. package/lib/codegen/pagination.js.map +0 -1
  262. package/lib/codegen/prelude.d.ts +0 -15
  263. package/lib/codegen/prelude.d.ts.map +0 -1
  264. package/lib/codegen/prelude.js +0 -60
  265. package/lib/codegen/prelude.js.map +0 -1
  266. package/lib/error-category.js.map +0 -1
  267. package/lib/errors.js.map +0 -1
  268. package/lib/json-patch.d.ts +0 -44
  269. package/lib/json-patch.d.ts.map +0 -1
  270. package/lib/json-patch.js +0 -174
  271. package/lib/json-patch.js.map +0 -1
  272. package/lib/pagination.js.map +0 -1
  273. package/lib/protocol-http.js.map +0 -1
  274. package/lib/protocol-rest.js.map +0 -1
  275. package/lib/retry-after.js.map +0 -1
  276. package/lib/retry.js.map +0 -1
  277. package/lib/schema.js.map +0 -1
  278. package/lib/trait.js.map +0 -1
  279. package/src/codegen/cli.ts +0 -268
  280. package/src/codegen/emit.ts +0 -207
  281. package/src/codegen/format.ts +0 -47
  282. package/src/codegen/generator.ts +0 -1153
  283. package/src/codegen/graph.ts +0 -151
  284. package/src/codegen/members.ts +0 -71
  285. package/src/codegen/naming.ts +0 -86
  286. package/src/codegen/openapi-cli.ts +0 -166
  287. package/src/codegen/openapi.ts +0 -1450
  288. package/src/codegen/operations.ts +0 -76
  289. package/src/codegen/pagination.ts +0 -71
  290. package/src/codegen/prelude.ts +0 -70
  291. package/src/json-patch.ts +0 -222
@@ -0,0 +1,76 @@
1
+ /**
2
+ * How gRPC calls reach a server.
3
+ *
4
+ * A transport is an Effect `HttpClient`: it sends the request
5
+ * `protocol-grpc` builds (`POST`, `application/grpc`, one frame) and returns
6
+ * the response with its body as a stream, so a server-streaming call reads
7
+ * each message as it arrives. gRPC puts the call's status in the trailers;
8
+ * a transport that can read them hands them over with {@link respond}, and
9
+ * the protocol reads them with {@link trailersOf} once the body has ended.
10
+ *
11
+ * By default `protocol-grpc` sends through the caller's `HttpClient`
12
+ * (`fetch`), which works where a proxy bridges HTTP/1.1 to gRPC (envoy) and
13
+ * puts the status in the headers. Provide a different transport for one
14
+ * scope with {@link layer}:
15
+ *
16
+ * - `@distilled.cloud/core/grpc-transport-node-http2` speaks HTTP/2 with
17
+ * `node:http2`, for servers that offer nothing else;
18
+ * - `@distilled.cloud/core/grpc-transport-cloudflare-sockets` speaks HTTP/1.1
19
+ * over a `cloudflare:sockets` TLS socket, for a Cloudflare Worker calling a
20
+ * gRPC server that is itself behind Cloudflare (a Worker's `fetch` to such
21
+ * a site takes Cloudflare's internal path, which resets gRPC upstreams);
22
+ * - `@distilled.cloud/core/grpc-transport-cloudflare-http2` speaks HTTP/2
23
+ * over a `cloudflare:sockets` socket, for a Cloudflare Worker calling a
24
+ * server that offers nothing else (workerd has no working `node:http2`).
25
+ *
26
+ * None is imported by this module, so a bundle only carries the ones it
27
+ * provides.
28
+ */
29
+ import * as Context from "effect/Context";
30
+ import * as Effect from "effect/Effect";
31
+ import type * as HttpClient from "effect/http/HttpClient";
32
+ import type * as HttpClientRequest from "effect/http/HttpClientRequest";
33
+ import * as HttpClientResponse from "effect/http/HttpClientResponse";
34
+ import * as Layer from "effect/Layer";
35
+ /**
36
+ * The `HttpClient` gRPC calls go through. `undefined` (the default) sends
37
+ * through the caller's `HttpClient`.
38
+ */
39
+ export declare const GrpcTransport: Context.Reference<HttpClient.HttpClient | undefined>;
40
+ /** Send gRPC calls in this scope through `client`. */
41
+ export declare const layer: (client: HttpClient.HttpClient) => Layer.Layer<never>;
42
+ /** Header and trailer names are lowercase; values as received. */
43
+ export type Trailers = Readonly<Record<string, string>>;
44
+ /**
45
+ * Whether `status` is a final HTTP status a response can carry (200 to 599).
46
+ * A transport fails the call with a transport error for any other.
47
+ */
48
+ export declare const isResponseStatus: (status: number) => boolean;
49
+ /**
50
+ * Build a transport's response: the status, the headers, the body as it
51
+ * arrives, and the trailers, which settle once the body has ended.
52
+ */
53
+ export declare const respond: (request: HttpClientRequest.HttpClientRequest, reply: {
54
+ readonly status: number;
55
+ readonly headers: Trailers;
56
+ readonly body: ReadableStream<Uint8Array>;
57
+ readonly trailers: Promise<Trailers>;
58
+ /**
59
+ * Whether the trailers always arrive. HTTP/2 delivers them end to end;
60
+ * over HTTP/1.1 a bridging proxy may drop them, so the protocol then
61
+ * treats a reply with messages and no status as OK.
62
+ * @default true
63
+ */
64
+ readonly reliableTrailers?: boolean;
65
+ }) => HttpClientResponse.HttpClientResponse;
66
+ /**
67
+ * Whether `response` came from a transport whose trailers always arrive
68
+ * ({@link respond} with `reliableTrailers`), so a missing status is an error.
69
+ */
70
+ export declare const hasTrailers: (response: HttpClientResponse.HttpClientResponse) => boolean;
71
+ /**
72
+ * The trailers of a response a transport built with {@link respond}, read
73
+ * after its body; empty for any other response (`fetch` exposes none).
74
+ */
75
+ export declare const trailersOf: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<Trailers>;
76
+ //# sourceMappingURL=grpc-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc-transport.d.ts","sourceRoot":"","sources":["../src/grpc-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,iBAAiB,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC;;;GAGG;AACH,eAAO,MAAM,aAAa,sDAGzB,CAAC;AAEF,sDAAsD;AACtD,eAAO,MAAM,KAAK,WAAY,UAAU,CAAC,UAAU,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CACjC,CAAC;AAEvC,kEAAkE;AAClE,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AASxD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,WAAY,MAAM,KAAG,OACU,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,OAAO,YACT,iBAAiB,CAAC,iBAAiB,SACrC;IACL,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACrC,KACA,kBAAkB,CAAC,kBAarB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,aAAc,kBAAkB,CAAC,kBAAkB,KAAG,OAClB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,UAAU,aACX,kBAAkB,CAAC,kBAAkB,KAC9C,MAAM,CAAC,MAAM,CAAC,QAAQ,CAKxB,CAAC"}
@@ -0,0 +1 @@
1
+ export { grpc_transport$GrpcTransport as GrpcTransport, grpc_transport$hasTrailers as hasTrailers, grpc_transport$isResponseStatus as isResponseStatus, grpc_transport$layer as layer, grpc_transport$respond as respond, grpc_transport$trailersOf as trailersOf } from "./_bundle/grpc.js";
package/lib/hpack.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * HPACK (RFC 7541), the header compression of HTTP/2, for a client that
3
+ * speaks HTTP/2 without a platform implementation
4
+ * (`grpc-transport-cloudflare-http2`).
5
+ *
6
+ * {@link makeDecoder} reads everything a server may send: the static and
7
+ * dynamic tables, every literal form, and Huffman-coded strings.
8
+ * {@link encode} writes the simplest valid form, each field as a literal
9
+ * with no indexing and no Huffman coding, so a connection keeps no encoder
10
+ * state.
11
+ */
12
+ /** A header block that breaks RFC 7541. HTTP/2 treats it as a connection error. */
13
+ export declare class HpackError extends Error {
14
+ }
15
+ /** A header field: a lowercase name and its value. */
16
+ export type HeaderField = readonly [name: string, value: string];
17
+ /** Decode a Huffman-coded string (RFC 7541 section 5.2). */
18
+ export declare const huffmanDecode: (bytes: Uint8Array) => Uint8Array;
19
+ /** Reads the header blocks of one connection, in the order they arrive. */
20
+ export interface HpackDecoder {
21
+ /** The fields of one complete header block. */
22
+ decode(block: Uint8Array): HeaderField[];
23
+ }
24
+ /**
25
+ * A decoder for one connection. `maxTableSize` is the dynamic table size
26
+ * this end allows (`SETTINGS_HEADER_TABLE_SIZE`, 4096 unless set).
27
+ */
28
+ export declare const makeDecoder: (maxTableSize?: number) => HpackDecoder;
29
+ /**
30
+ * A header block for `fields`, each a literal without indexing (RFC 7541
31
+ * section 6.2.2). Names must be lowercase, pseudo-headers first.
32
+ */
33
+ export declare const encode: (fields: ReadonlyArray<HeaderField>) => Uint8Array;
34
+ //# sourceMappingURL=hpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hpack.d.ts","sourceRoot":"","sources":["../src/hpack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,mFAAmF;AACnF,qBAAa,UAAW,SAAQ,KAAK;CAAG;AAExC,sDAAsD;AACtD,MAAM,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AA0HjE,4DAA4D;AAC5D,eAAO,MAAM,aAAa,UAAW,UAAU,KAAG,UA4BjD,CAAC;AAmBF,2EAA2E;AAC3E,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,EAAE,CAAC;CAC1C;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,6BAA0B,YAiGjD,CAAC;AAyBF;;;GAGG;AACH,eAAO,MAAM,MAAM,WAAY,aAAa,CAAC,WAAW,CAAC,KAAG,UAQ3D,CAAC"}
package/lib/hpack.js ADDED
@@ -0,0 +1,2 @@
1
+ var HpackError=class extends Error{};const e=[[`:authority`,``],[`:method`,`GET`],[`:method`,`POST`],[`:path`,`/`],[`:path`,`/index.html`],[`:scheme`,`http`],[`:scheme`,`https`],[`:status`,`200`],[`:status`,`204`],[`:status`,`206`],[`:status`,`304`],[`:status`,`400`],[`:status`,`404`],[`:status`,`500`],[`accept-charset`,``],[`accept-encoding`,`gzip, deflate`],[`accept-language`,``],[`accept-ranges`,``],[`accept`,``],[`access-control-allow-origin`,``],[`age`,``],[`allow`,``],[`authorization`,``],[`cache-control`,``],[`content-disposition`,``],[`content-encoding`,``],[`content-language`,``],[`content-length`,``],[`content-location`,``],[`content-range`,``],[`content-type`,``],[`cookie`,``],[`date`,``],[`etag`,``],[`expect`,``],[`expires`,``],[`from`,``],[`host`,``],[`if-match`,``],[`if-modified-since`,``],[`if-none-match`,``],[`if-range`,``],[`if-unmodified-since`,``],[`last-modified`,``],[`link`,``],[`location`,``],[`max-forwards`,``],[`proxy-authenticate`,``],[`proxy-authorization`,``],[`range`,``],[`referer`,``],[`refresh`,``],[`retry-after`,``],[`server`,``],[`set-cookie`,``],[`strict-transport-security`,``],[`transfer-encoding`,``],[`user-agent`,``],[`vary`,``],[`via`,``],[`www-authenticate`,``]];const t=[13,23,28,28,28,28,28,28,28,24,30,28,28,30,28,28,28,28,28,28,28,28,30,28,28,28,28,28,28,28,28,28,6,10,10,12,13,6,8,11,10,10,8,11,8,6,6,6,5,5,5,6,6,6,6,6,6,6,7,8,15,6,12,10,13,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,7,8,13,19,13,14,6,15,5,6,5,6,5,6,6,6,5,7,7,6,6,6,5,6,7,6,5,5,6,7,7,7,7,7,15,11,14,13,28,20,22,20,20,22,22,22,23,22,23,23,23,23,23,24,23,24,24,22,23,24,23,23,23,23,21,22,23,22,23,23,24,22,21,20,22,22,23,23,21,23,22,22,24,21,22,23,23,21,21,22,21,23,22,23,23,20,22,22,22,23,22,22,23,26,26,20,19,22,23,22,25,26,26,26,27,27,26,24,25,19,21,26,27,27,26,27,24,21,21,26,26,28,27,27,27,20,24,20,21,22,21,21,23,22,22,25,25,24,24,26,23,26,27,26,26,27,27,27,27,27,28,27,27,27,27,27,26,30];const n=256;const buildHuffmanTree=()=>{const e=t.map((e,t)=>({bits:e,symbol:t})).sort((e,t)=>e.bits-t.bits);const n=[0,0];let r=0;let i=0;for(const{bits:t,symbol:a}of e){r<<=t-i;i=t;let e=0;for(let i=t-1;i>=0;i--){const t=e*2+(r>>>i&1);if(i===0)n[t]=-(a+1);else{if(n[t]===0){n[t]=n.length/2;n.push(0,0)}e=n[t]}}r++}return n};let r;const huffmanDecode=e=>{const t=r??=buildHuffmanTree();const i=[];let a=0;let o=0;let s=true;for(const r of e)for(let e=7;e>=0;e--){const c=r>>>e&1;const l=t[a*2+c];if(l<0){const e=-l-1;if(e===n)throw new HpackError(`Huffman string contains EOS`);i.push(e);a=0;o=0;s=true}else{a=l;o++;if(c===0)s=false}}if(o>7||!s)throw new HpackError(`invalid Huffman padding`);return Uint8Array.from(i)};const textOf=e=>{let t=``;for(let n=0;n<e.length;n+=8192)t+=String.fromCharCode(...e.subarray(n,n+8192));return t};const makeDecoder=(t=4096)=>{const n=[];let r=0;let i=t;const evict=()=>{while(r>i)r-=n.pop().size};const lookup=t=>{if(t>=1&&t<=e.length){const[n,r]=e[t-1];return{name:n,value:r}}const r=n[t-e.length-1];if(r===void 0)throw new HpackError(`no header at index ${t}`);return r};return{decode(e){const a=[];let o=0;const integer=t=>{const n=2**t-1;let r=e[o++]&n;if(r<n)return r;for(let t=0;;t+=7){if(o>=e.length)throw new HpackError(`header block ends inside an integer`);if(t>28)throw new HpackError(`integer is too large`);const n=e[o++];r+=(n&127)*2**t;if((n&128)===0)return r}};const string=()=>{const t=e[o];if(t===void 0)throw new HpackError(`header block ends inside a string`);const n=(t&128)!==0;const r=integer(7);if(o+r>e.length)throw new HpackError(`header block ends inside a string`);const i=e.subarray(o,o+r);o+=r;const a=n?huffmanDecode(i):i;return{text:textOf(a),octets:a.length}};const literal=(e,t)=>{const i=integer(e);let o;let s;if(i===0){const e=string();o=e.text;s=e.octets}else{o=lookup(i).name;s=o.length}const c=string();a.push([o,c.text]);if(t){const e={name:o,value:c.text,size:s+c.octets+32};n.unshift(e);r+=e.size;evict()}};while(o<e.length){const n=e[o];if((n&128)!==0){const{name:e,value:t}=lookup(integer(7));a.push([e,t])}else if((n&64)!==0)literal(6,true);else if((n&32)!==0){if(a.length>0)throw new HpackError(`dynamic table size update after a header field`);const e=integer(5);if(e>t)throw new HpackError(`dynamic table size exceeds the limit`);i=e;evict()}else literal(4,false)}return a}}};const i=/*@__PURE__*/ new TextEncoder;const pushInteger=(e,t,n,r)=>{const i=2**n-1;if(t<i){e.push(r|t);return}e.push(r|i);let a=t-i;while(a>=128){e.push(a%128|128);a=Math.floor(a/128)}e.push(a)};const pushString=(e,t)=>{const n=i.encode(t);pushInteger(e,n.length,7,0);for(const t of n)e.push(t)};const encode=e=>{const t=[];for(const[n,r]of e){t.push(0);pushString(t,n);pushString(t,r)}return Uint8Array.from(t)};export{HpackError,encode,huffmanDecode,makeDecoder};
2
+ //# sourceMappingURL=hpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hpack.js","names":["STATIC_TABLE","HUFFMAN_BITS","EOS","symbols","a","b","tree","code","previous","bits","node","bit","slot","symbol","huffmanTree","out","pending","ones","byte","bytes","value","next","i","dynamic","size","limit","maxTableSize","index","name","entry","fields","at","max","prefix","block","shift","first","huffman","length","raw","nameIndex","nameOctets","read","encoder","flags","rest","text"],"sources":["../src/hpack.ts"],"mappings":"AAaA,IAAa,WAAb,cAAgC,KAAM,CAAC,EAMvC,MAAMA,EAA2C,CAC/C,CAAC,aAAc,EAAE,EACjB,CAAC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B,CAClD,MAAM1B,EAAQwB,EAAQ,OAAOG,CAAI,EACjC,YAAY/B,EAAKI,EAAM,OAAQ,EAAG,CAAC,EACnC,IAAK,MAAMD,KAAQC,EAAOJ,EAAI,KAAKG,CAAI,CACzC,EAMA,MAAa,OAAU,GAAmD,CACxE,MAAMH,EAAgB,CAAC,EACvB,IAAK,KAAM,CAACa,EAAMR,KAAUU,EAAQ,CAClCf,EAAI,KAAK,CAAC,EACV,WAAWA,EAAKa,CAAI,EACpB,WAAWb,EAAKK,CAAK,CACvB,CACA,OAAO,WAAW,KAAKL,CAAG,CAC5B"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * `@distilled.cloud/core` -- the runtime shared by every distilled SDK.
3
+ *
4
+ * ```ts
5
+ * import { ResponseValidation, Retry } from "@distilled.cloud/core";
6
+ *
7
+ * program.pipe(Effect.provide(ResponseValidation.strict));
8
+ * ```
9
+ *
10
+ * Each namespace is also importable on its own subpath
11
+ * (`@distilled.cloud/core/response-validation`, ...); generated SDKs use the
12
+ * subpaths. The code generator and test helpers live in the unpublished
13
+ * `@distilled.cloud/dev` package.
14
+ */
15
+ export * as API from "./api.ts";
16
+ export * as Category from "./category.ts";
17
+ export * as Errors from "./errors.ts";
18
+ export * as GraphQL from "./graphql.ts";
19
+ export * as GrpcTransport from "./grpc-transport.ts";
20
+ export * as Pagination from "./pagination.ts";
21
+ export * as ProtocolGrpc from "./protocol-grpc.ts";
22
+ export * as ProtocolHttp from "./protocol-http.ts";
23
+ export * as ProtocolRest from "./protocol-rest.ts";
24
+ export { Query } from "./query.ts";
25
+ export * as Crypto from "./crypto.ts";
26
+ export * as ResponseValidation from "./response-validation.ts";
27
+ export * as Retry from "./retry.ts";
28
+ export * as RetryAfter from "./retry-after.ts";
29
+ export * as Sensitive from "./sensitive.ts";
30
+ export * as Telemetry from "./telemetry.ts";
31
+ export * as Trait from "./trait.ts";
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,kBAAkB,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,17 @@
1
+ export * as API from "./api.js";
2
+ export * as Category from "./category.js";
3
+ export * as Errors from "./errors.js";
4
+ export * as GraphQL from "./graphql.js";
5
+ export * as GrpcTransport from "./grpc-transport.js";
6
+ export * as Pagination from "./pagination.js";
7
+ export * as ProtocolGrpc from "./protocol-grpc.js";
8
+ export * as ProtocolHttp from "./protocol-http.js";
9
+ export * as ProtocolRest from "./protocol-rest.js";
10
+ export { Query } from "./query.js";
11
+ export * as Crypto from "./crypto.js";
12
+ export * as ResponseValidation from "./response-validation.js";
13
+ export * as Retry from "./retry.js";
14
+ export * as RetryAfter from "./retry-after.js";
15
+ export * as Sensitive from "./sensitive.js";
16
+ export * as Telemetry from "./telemetry.js";
17
+ export * as Trait from "./trait.js";
@@ -1,17 +1,4 @@
1
- /**
2
- * Pagination utilities for streaming through paginated API responses.
3
- *
4
- * Supports multiple pagination styles:
5
- * - Page-based: page/per_page with a page number that advances
6
- * - Cursor-based: cursor/limit with an opaque next-cursor string
7
- * - Token-based (AWS style): NextToken/MaxResults continuation tokens
8
- * - Single: one-shot list endpoints that still expose the paginated surface
9
- *
10
- * Each SDK stores a {@link PaginatedTrait} on its operations (sourced from the
11
- * `smithy.api#paginated` trait in its models) and picks a
12
- * {@link PaginationStrategy}; these shared utilities handle the streaming.
13
- * Ported from the distilled repo's `core/pagination`.
14
- */
1
+ import * as Context from "effect/Context";
15
2
  import * as Effect from "effect/Effect";
16
3
  import * as Stream from "effect/Stream";
17
4
  /**
@@ -19,26 +6,64 @@ import * as Stream from "effect/Stream";
19
6
  * `"resultInfo.page"`). Used for pagination traits and nested access.
20
7
  */
21
8
  export declare const getPath: (obj: unknown, path: string) => unknown;
9
+ /**
10
+ * Collect the items a dot-separated path selects, flattening arrays as it
11
+ * goes. Unlike {@link getPath} (which walks a single value and is used for
12
+ * cursors/tokens), every segment here fans out over whatever the previous one
13
+ * produced, so a path may cross a list:
14
+ *
15
+ * - `"items"` on `{ items: [a, b] }` -> `[a, b]` (the common flat case)
16
+ * - `"edges.node"` on a Relay connection -> every edge's `node`
17
+ *
18
+ * `null`/`undefined` links are dropped rather than propagated, so a partially
19
+ * null page yields the items it does have instead of nothing.
20
+ */
21
+ export declare const getItems: (obj: unknown, path: string) => readonly unknown[];
22
22
  /** Pagination trait describing how to navigate between pages. */
23
23
  export interface PaginatedTrait {
24
24
  /** Pagination strategy */
25
- readonly mode?: "token" | "page" | "cursor" | "single";
26
- /** The name of the input member containing the page/cursor token */
25
+ readonly mode?: "token" | "page" | "cursor" | "relay" | "link" | "keyset" | "single";
26
+ /**
27
+ * The name of the input member containing the page/cursor token. In link
28
+ * mode it is also the query parameter read from the `rel="next"` URL.
29
+ */
27
30
  readonly inputToken?: string;
28
- /** The path to the output member containing the next page/cursor token */
31
+ /**
32
+ * The path to the output member containing the next page/cursor token. In
33
+ * keyset mode it is a path within one item: the key the next page starts
34
+ * after.
35
+ */
29
36
  readonly outputToken?: string;
30
- /** The path to the output member containing the paginated items */
37
+ /**
38
+ * The path to the output member containing the paginated items. Segments
39
+ * may cross arrays -- `"edges.node"` walks every edge and collects its
40
+ * `node` (see {@link getItems}).
41
+ */
31
42
  readonly items?: string;
32
43
  /** The name of the input member that limits page size */
33
44
  readonly pageSize?: string;
45
+ /**
46
+ * Relay extension: the path to the boolean that says whether another page
47
+ * exists (`"pageInfo.hasNextPage"`). Relay connections keep returning the
48
+ * last page's `endCursor` after the end, so the cursor alone can't
49
+ * terminate traversal -- see {@link paginateRelay}.
50
+ */
51
+ readonly hasNextPage?: string;
34
52
  }
35
53
  export type PaginationStrategy = <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
54
+ /**
55
+ * The stream of a paginated operation whose trait lacks a field its
56
+ * strategy reads: it fails with {@link SdkError} (part of every
57
+ * operation's error channel, so the strategy's `E` is cast to hold it).
58
+ * The generator refuses such traits.
59
+ */
60
+ export declare const missingPaginationConfig: (message: string) => Stream.Stream<never>;
36
61
  /**
37
62
  * Whether a continuation token/cursor returned by a paginated operation
38
63
  * means "no more pages".
39
64
  *
40
65
  * APIs mark the terminal page by omitting the output token, returning it
41
- * as `null`, or — for several services (e.g. SSM, CloudWatch Logs) — as an
66
+ * as `null`, or -- for several services (e.g. SSM, CloudWatch Logs) -- as an
42
67
  * empty string. Treating `""` as a live token re-requests the first page
43
68
  * forever (or fails with a ValidationException). Object tokens (e.g.
44
69
  * DynamoDB's `LastEvaluatedKey`) are always truthy and unaffected.
@@ -46,7 +71,7 @@ export type PaginationStrategy = <Input extends Record<string, unknown>, Output,
46
71
  export declare const isTerminalToken: (token: unknown) => boolean;
47
72
  /**
48
73
  * Stream for single-shot list endpoints that still expose the paginated
49
- * surface — emits exactly one page.
74
+ * surface -- emits exactly one page.
50
75
  */
51
76
  export declare const paginateSingle: PaginationStrategy;
52
77
  /**
@@ -56,15 +81,61 @@ export declare const paginateSingle: PaginationStrategy;
56
81
  */
57
82
  export declare const paginatePageNumber: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
58
83
  /**
59
- * Stream of pages using cursor-based pagination — follow `outputToken`
60
- * cursors until one comes back absent.
84
+ * Stream of pages using cursor-based pagination -- follow `outputToken`
85
+ * cursors until one comes back absent or repeats a previously requested cursor.
86
+ * Empty pages still advance when they return a new cursor.
61
87
  */
62
88
  export declare const paginateCursor: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
63
89
  /**
64
- * Stream of pages using token-based pagination — pass `outputToken` back as
90
+ * Stream of pages using token-based pagination -- pass `outputToken` back as
65
91
  * `inputToken` until it comes back absent.
66
92
  */
67
93
  export declare const paginateToken: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
94
+ /**
95
+ * Stream of pages using keyset pagination: the next request starts after
96
+ * the key of the page's last item. `inputToken` is the input member the key
97
+ * goes to and `outputToken` the key's path within an item (both may be
98
+ * dot-separated: Modal's `List*` calls take `pagination.createdBefore` and
99
+ * key on each item's `createdAt`). Traversal ends on an empty page, a page
100
+ * smaller than the requested `pageSize`, or a key that doesn't advance.
101
+ */
102
+ export declare const paginateKeyset: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
103
+ /**
104
+ * Stream of pages over a Relay connection -- pass `pageInfo.endCursor` back as
105
+ * `after` for as long as `pageInfo.hasNextPage` is true.
106
+ *
107
+ * Relay is cursor pagination with one twist that breaks
108
+ * {@link paginateCursor}: the terminal page still carries an `endCursor` (it
109
+ * points at the last edge, not at "nothing left"). Only `hasNextPage`
110
+ * distinguishes "more to fetch" from "that was everything", so this strategy
111
+ * reads the boolean and treats the cursor as a pure position marker. A
112
+ * connection that omits `pageInfo` entirely (or returns an empty page) also
113
+ * terminates, so a malformed response can't spin forever.
114
+ */
115
+ export declare const paginateRelay: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
116
+ /**
117
+ * Hand a response's headers to the link traversal running on this fiber, if
118
+ * any. Protocols call it for every response they decode; outside
119
+ * {@link paginateLink} it does nothing.
120
+ */
121
+ export declare const recordPageHeaders: (context: Context.Context<never>, headers: Readonly<Record<string, string | undefined>>) => void;
122
+ /**
123
+ * The URL of the `rel="next"` link in a `Link` header value, e.g.
124
+ * `<https://api.github.com/repositories/1/issues?page=2>; rel="next", <...>; rel="last"`.
125
+ */
126
+ export declare const nextLink: (header: string | undefined) => string | undefined;
127
+ /**
128
+ * Stream of pages that follows the `Link` response header: each request
129
+ * takes `inputToken` from the query of the previous response's `rel="next"`
130
+ * URL, and traversal ends when a response has no next link (or its token
131
+ * repeats the current one). The response body carries no token, so this
132
+ * works for APIs whose list responses are bare arrays.
133
+ *
134
+ * The protocol must report response headers through
135
+ * {@link recordPageHeaders} (the REST protocol does); otherwise traversal
136
+ * stops after the first page.
137
+ */
138
+ export declare const paginateLink: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
68
139
  /**
69
140
  * Shared default pagination dispatcher for SDKs that use generic
70
141
  * token/cursor/page traversal.
@@ -74,8 +145,14 @@ export declare const paginateWithDefaults: PaginationStrategy;
74
145
  * Extracts individual items from a page stream.
75
146
  *
76
147
  * @param pages - A stream of page responses
77
- * @param itemsPath - Dot-separated path to the items array in the page
148
+ * @param itemsPath - Dot-separated path to the items in the page; segments may
149
+ * cross arrays (see {@link getItems})
78
150
  * @returns A Stream of individual items
79
151
  */
80
152
  export declare const extractItems: <Output, Item, E, R>(pages: Stream.Stream<Output, E, R>, itemsPath: string) => Stream.Stream<Item, E, R>;
153
+ /**
154
+ * The items of a stream of pages that are themselves the lists (bare-array
155
+ * responses).
156
+ */
157
+ export declare const extractArrayItems: <Output, Item, E, R>(pages: Stream.Stream<Output, E, R>) => Stream.Stream<Item, E, R>;
81
158
  //# sourceMappingURL=pagination.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,OAAO,QAAS,OAAO,QAAQ,MAAM,KAAG,OAUpD,CAAC;AAMF,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC7B,0BAA0B;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACvD,oEAAoE;IACpE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,mEAAmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,kBAAkB,GAAG,CAC/B,KAAK,SAAS,MAAM,CAA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M,GAAG,SAAS,CAAC,CAAC,KACpD,IAGF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,WAAY,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SAQ9D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,aACnE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,SACjD,KAAK,cACA,cAAc,KACzB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAiC5B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,kBAoBlC,CAAC;AAMF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,SACtC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,aACvB,MAAM,KAChB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAA6D,CAAC;AAEzF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,SAC3C,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,KACjC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAqE,CAAC"}
package/lib/pagination.js CHANGED
@@ -1,182 +1 @@
1
- /**
2
- * Pagination utilities for streaming through paginated API responses.
3
- *
4
- * Supports multiple pagination styles:
5
- * - Page-based: page/per_page with a page number that advances
6
- * - Cursor-based: cursor/limit with an opaque next-cursor string
7
- * - Token-based (AWS style): NextToken/MaxResults continuation tokens
8
- * - Single: one-shot list endpoints that still expose the paginated surface
9
- *
10
- * Each SDK stores a {@link PaginatedTrait} on its operations (sourced from the
11
- * `smithy.api#paginated` trait in its models) and picks a
12
- * {@link PaginationStrategy}; these shared utilities handle the streaming.
13
- * Ported from the distilled repo's `core/pagination`.
14
- */
15
- import * as Effect from "effect/Effect";
16
- import * as Stream from "effect/Stream";
17
- /**
18
- * Get a value from an object using a dot-separated path (e.g.
19
- * `"resultInfo.page"`). Used for pagination traits and nested access.
20
- */
21
- export const getPath = (obj, path) => {
22
- const parts = path.split(".");
23
- let current = obj;
24
- for (const part of parts) {
25
- if (current == null || typeof current !== "object") {
26
- return undefined;
27
- }
28
- current = current[part];
29
- }
30
- return current;
31
- };
32
- const missingPaginationConfig = (kind) => Stream.die(new Error(kind));
33
- /**
34
- * Whether a continuation token/cursor returned by a paginated operation
35
- * means "no more pages".
36
- *
37
- * APIs mark the terminal page by omitting the output token, returning it
38
- * as `null`, or — for several services (e.g. SSM, CloudWatch Logs) — as an
39
- * empty string. Treating `""` as a live token re-requests the first page
40
- * forever (or fails with a ValidationException). Object tokens (e.g.
41
- * DynamoDB's `LastEvaluatedKey`) are always truthy and unaffected.
42
- */
43
- export const isTerminalToken = (token) => token === undefined || token === null || token === "";
44
- /**
45
- * Stream for single-shot list endpoints that still expose the paginated
46
- * surface — emits exactly one page.
47
- */
48
- export const paginateSingle = (operation, input) => Stream.make(input).pipe(Stream.mapEffect((requestPayload) => operation(requestPayload)));
49
- // ============================================================================
50
- // Page-based Pagination
51
- // ============================================================================
52
- /**
53
- * Stream of pages using page-number pagination. The next page is taken from
54
- * `outputToken` when it advances; otherwise the page number is incremented,
55
- * terminating when a page comes back with no items (or no token).
56
- */
57
- export const paginatePageNumber = (operation, input, pagination) => {
58
- const inputToken = pagination.inputToken;
59
- const outputToken = pagination.outputToken;
60
- if (!inputToken || !outputToken) {
61
- return missingPaginationConfig("Page-number pagination requires inputToken and outputToken");
62
- }
63
- const startPage = typeof input[inputToken] === "number" ? input[inputToken] : 1;
64
- return Stream.unfold({ page: startPage, done: false }, (state) => Effect.gen(function* () {
65
- if (state.done)
66
- return undefined;
67
- const requestPayload = { ...input, [inputToken]: state.page };
68
- const response = yield* operation(requestPayload);
69
- const nextPage = getPath(response, outputToken);
70
- // Some APIs report the CURRENT page at `outputToken` rather than the
71
- // next one (e.g. Cloudflare's `result_info.page`). Taking that value as
72
- // the next page re-requests the same page forever. Only accept an
73
- // *advancing* page number; otherwise advance by one and terminate when
74
- // a page comes back with no items (or the token is absent).
75
- const items = pagination.items
76
- ? getPath(response, pagination.items)
77
- : undefined;
78
- const nextState = {
79
- page: typeof nextPage === "number" && nextPage > state.page
80
- ? nextPage
81
- : state.page + 1,
82
- done: nextPage === null ||
83
- nextPage === undefined ||
84
- (items !== undefined && items.length === 0),
85
- };
86
- return [response, nextState];
87
- }));
88
- };
89
- // ============================================================================
90
- // Cursor-based Pagination
91
- // ============================================================================
92
- /**
93
- * Stream of pages using cursor-based pagination — follow `outputToken`
94
- * cursors until one comes back absent.
95
- */
96
- export const paginateCursor = (operation, input, pagination) => {
97
- const inputToken = pagination.inputToken;
98
- const outputToken = pagination.outputToken;
99
- if (!inputToken || !outputToken) {
100
- return missingPaginationConfig("Cursor pagination requires inputToken and outputToken");
101
- }
102
- const startCursor = typeof input[inputToken] === "string"
103
- ? input[inputToken]
104
- : undefined;
105
- return Stream.unfold({ cursor: startCursor, done: false }, (state) => Effect.gen(function* () {
106
- if (state.done)
107
- return undefined;
108
- const requestPayload = {
109
- ...input,
110
- ...(state.cursor ? { [inputToken]: state.cursor } : {}),
111
- };
112
- const response = yield* operation(requestPayload);
113
- const nextCursor = getPath(response, outputToken);
114
- const nextState = {
115
- cursor: nextCursor ?? undefined,
116
- done: isTerminalToken(nextCursor),
117
- };
118
- return [response, nextState];
119
- }));
120
- };
121
- // ============================================================================
122
- // Token-based Pagination (AWS style)
123
- // ============================================================================
124
- /**
125
- * Stream of pages using token-based pagination — pass `outputToken` back as
126
- * `inputToken` until it comes back absent.
127
- */
128
- export const paginateToken = (operation, input, pagination) => {
129
- const inputToken = pagination.inputToken;
130
- const outputToken = pagination.outputToken;
131
- if (!inputToken || !outputToken) {
132
- return missingPaginationConfig("Token pagination requires inputToken and outputToken");
133
- }
134
- const startToken = input[inputToken];
135
- return Stream.unfold({ token: startToken, done: false }, (state) => Effect.gen(function* () {
136
- if (state.done)
137
- return undefined;
138
- const requestPayload = state.token !== undefined
139
- ? { ...input, [inputToken]: state.token }
140
- : input;
141
- const response = yield* operation(requestPayload);
142
- const nextToken = getPath(response, outputToken);
143
- const nextState = {
144
- token: nextToken,
145
- done: isTerminalToken(nextToken),
146
- };
147
- return [response, nextState];
148
- }));
149
- };
150
- /**
151
- * Shared default pagination dispatcher for SDKs that use generic
152
- * token/cursor/page traversal.
153
- */
154
- export const paginateWithDefaults = (operation, input, pagination) => {
155
- const mode = pagination.mode ?? "token";
156
- switch (mode) {
157
- case "page":
158
- return paginatePageNumber(operation, input, pagination);
159
- case "cursor":
160
- return paginateCursor(operation, input, pagination);
161
- case "single":
162
- return paginateSingle(operation, input, pagination);
163
- case "token":
164
- default:
165
- return paginateToken(operation, input, pagination);
166
- }
167
- };
168
- // ============================================================================
169
- // Item extraction
170
- // ============================================================================
171
- /**
172
- * Extracts individual items from a page stream.
173
- *
174
- * @param pages - A stream of page responses
175
- * @param itemsPath - Dot-separated path to the items array in the page
176
- * @returns A Stream of individual items
177
- */
178
- export const extractItems = (pages, itemsPath) => pages.pipe(Stream.flatMap((page) => {
179
- const items = getPath(page, itemsPath);
180
- return Stream.fromIterable(items ?? []);
181
- }));
182
- //# sourceMappingURL=pagination.js.map
1
+ export { pagination$extractArrayItems as extractArrayItems, pagination$extractItems as extractItems, pagination$getItems as getItems, pagination$getPath as getPath, pagination$isTerminalToken as isTerminalToken, pagination$missingPaginationConfig as missingPaginationConfig, pagination$nextLink as nextLink, pagination$paginateCursor as paginateCursor, pagination$paginateKeyset as paginateKeyset, pagination$paginateLink as paginateLink, pagination$paginatePageNumber as paginatePageNumber, pagination$paginateRelay as paginateRelay, pagination$paginateSingle as paginateSingle, pagination$paginateToken as paginateToken, pagination$paginateWithDefaults as paginateWithDefaults, pagination$recordPageHeaders as recordPageHeaders } from "./_bundle/base.js";
@@ -0,0 +1,10 @@
1
+ /** Binary/opaque values that must never be treated as key-value objects. */
2
+ export declare const isOpaqueValue: (v: unknown) => boolean;
3
+ /**
4
+ * Deep-unwrap `Redacted` values in an input (plain objects/arrays only --
5
+ * class instances, files, and binary payloads pass through untouched).
6
+ * Sensitive input members accept `string | Redacted<string>`; the wire wants
7
+ * the raw string.
8
+ */
9
+ export declare const unwrapRedactedDeep: (value: unknown) => unknown;
10
+ //# sourceMappingURL=plain-values.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plain-values.d.ts","sourceRoot":"","sources":["../src/plain-values.ts"],"names":[],"mappings":"AAOA,4EAA4E;AAC5E,eAAO,MAAM,aAAa,MAAO,OAAO,KAAG,OAKxB,CAAC;AASpB;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,OAYnD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import*as e from"effect/Redacted";const isOpaqueValue=e=>e instanceof Blob||e instanceof File||e instanceof ArrayBuffer||e instanceof Uint8Array||e instanceof Date;const isPlainObject=e=>e!==null&&typeof e===`object`&&!Array.isArray(e)&&!isOpaqueValue(e)&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null);const unwrapRedactedDeep=t=>{if(e.isRedacted(t))return e.value(t);if(Array.isArray(t))return t.map(unwrapRedactedDeep);if(isPlainObject(t)){const e={};for(const[n,r]of Object.entries(t)){if(r===void 0)continue;e[n]=unwrapRedactedDeep(r)}return e}return t};export{isOpaqueValue,unwrapRedactedDeep};
2
+ //# sourceMappingURL=plain-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plain-values.js","names":["Redacted","v","value","out","k"],"sources":["../src/plain-values.ts"],"mappings":"kCAQA,MAAa,cAAiB,GAC5BC,aAAa,MACbA,aAAa,MACbA,aAAa,aACbA,aAAa,YACbA,aAAa,KAEf,MAAM,cAAiB,GACrBA,IAAM,MACN,OAAOA,IAAM,UACb,CAAC,MAAM,QAAQA,CAAC,GAChB,CAAC,cAAcA,CAAC,IACf,OAAO,eAAeA,CAAC,IAAM,OAAO,WAAa,OAAO,eAAeA,CAAC,IAAM,MAQjF,MAAa,mBAAsB,GAA4B,CAC7D,GAAID,EAAS,WAAWE,CAAK,EAAG,OAAOF,EAAS,MAAME,CAAK,EAC3D,GAAI,MAAM,QAAQA,CAAK,EAAG,OAAOA,EAAM,IAAI,kBAAkB,EAC7D,GAAI,cAAcA,CAAK,EAAG,CACxB,MAAMC,EAA+B,CAAC,EACtC,IAAK,KAAM,CAACC,EAAGH,KAAM,OAAO,QAAQC,CAAK,EAAG,CAC1C,GAAID,IAAM,IAAA,GAAW,SACrB,EAAIG,GAAK,mBAAmBH,CAAC,CAC/B,CACA,OAAOE,CACT,CACA,OAAOD,CACT"}