@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
package/lib/trait.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const annotationMetaSymbol: unique symbol;
2
- type Annotatable = {
2
+ export type Annotatable = {
3
3
  annotate(annotations: any): Annotatable;
4
4
  };
5
5
  export interface Annotation {
@@ -15,12 +15,12 @@ export interface Annotation {
15
15
  * Build a pipeable schema annotation carrying `value` under `sym`. Exported
16
16
  * so SDK packages can define their own protocol traits (e.g. cloudflare's
17
17
  * envelope traits, aws's smithy traits) with the same mechanics as the
18
- * generic ones here. Keys may be symbols or plain strings — effect Schema
18
+ * generic ones here. Keys may be symbols or plain strings -- effect Schema
19
19
  * annotation dictionaries accept both.
20
20
  */
21
21
  export declare function makeAnnotation<T>(sym: symbol | string, value: T): Annotation;
22
22
  /**
23
- * Combine several annotations into one — needed where only a single
23
+ * Combine several annotations into one -- needed where only a single
24
24
  * annotations object can be supplied (e.g. the second argument of
25
25
  * `S.Class`).
26
26
  */
@@ -33,7 +33,7 @@ export interface HttpTrait {
33
33
  readonly code?: number;
34
34
  /**
35
35
  * Request body encoding. Default is JSON; `"multipart"` sends
36
- * multipart/form-data — body members become form parts (objects
36
+ * multipart/form-data -- body members become form parts (objects
37
37
  * JSON-encoded) and members marked `FormDataFile()` append their files.
38
38
  * `"form-urlencoded"` sends application/x-www-form-urlencoded with
39
39
  * Stripe-style bracket notation for nested objects and arrays (see
@@ -50,10 +50,18 @@ export interface HttpTrait {
50
50
  /**
51
51
  * Explicit `Accept` for the operation, when the API serves more than one
52
52
  * response media type. Atlas pins an API version this way (e.g.
53
- * `application/vnd.atlas.2024-05-30+json` — `application/json` alone is a
53
+ * `application/vnd.atlas.2024-05-30+json` -- `application/json` alone is a
54
54
  * 406). Protocols that don't read it fall back to their own default.
55
55
  */
56
56
  readonly accept?: string;
57
+ /**
58
+ * Name of the host the operation runs on, when the API serves it from a
59
+ * host other than the service's main one (DigitalOcean's `"inference"`
60
+ * for `inference.do-ai.run`). It names a host and is never a URL: the
61
+ * protocol maps it to a base URL from its credentials, so the caller's
62
+ * configuration decides where the request and its credentials go.
63
+ */
64
+ readonly server?: string;
57
65
  }
58
66
  export declare const httpSymbol: unique symbol;
59
67
  /**
@@ -65,6 +73,11 @@ export declare const Http: (trait: HttpTrait) => Annotation;
65
73
  export declare const labelSymbol: unique symbol;
66
74
  /** Bind a member to a `{name}` placeholder in the operation's URI template. */
67
75
  export declare const Label: (name?: string) => Annotation;
76
+ export declare const labelEncodingSymbol: unique symbol;
77
+ /** Preserve selected RFC 3986 pchar delimiters inside a single URI label. */
78
+ export declare const LabelEncoding: (options: {
79
+ readonly preserve: string;
80
+ }) => Annotation;
68
81
  export declare const responseCodeSymbol: unique symbol;
69
82
  export declare const ResponseCode: () => Annotation;
70
83
  export declare const headerSymbol: unique symbol;
@@ -73,11 +86,27 @@ export declare const bodySymbol: unique symbol;
73
86
  export declare const Body: (name?: string) => Annotation;
74
87
  export declare const querySymbol: unique symbol;
75
88
  export declare const Query: (name?: string) => Annotation;
89
+ export declare const idempotencyTokenSymbol: unique symbol;
90
+ /**
91
+ * `smithy.api#idempotencyToken`: an input member the API uses to recognize
92
+ * a retried request. When the caller leaves it out, each call fills it with
93
+ * a new UUID, and every automatic retry of that call sends the same one.
94
+ * The UUID is random (v4), or time-ordered (v7, RFC 9562) with `"uuidv7"`
95
+ * for APIs that require it (`distilled.idempotency#format` in the model).
96
+ */
97
+ export declare const IdempotencyToken: (format?: "uuidv7") => Annotation;
98
+ export declare const commaDelimitedSymbol: unique symbol;
99
+ /**
100
+ * Sends a list-valued `Query` member as ONE comma-separated parameter
101
+ * (`?state=running,paused`) instead of one parameter per item -- OpenAPI's
102
+ * `style: form, explode: false`. Takes the trait value the codegen inlines.
103
+ */
104
+ export declare const CommaDelimited: (_trait?: unknown) => Annotation;
76
105
  export declare const deepQuerySymbol: unique symbol;
77
106
  /**
78
107
  * Binds a struct-valued input member to a family of DOTTED query parameters:
79
108
  * `{ account: { id, name } }` with `DeepQuery("account")` serializes as
80
- * `?account.id=…&account.name=…` (null/undefined entries skipped). This is
109
+ * `?account.id=...&account.name=...` (null/undefined entries skipped). This is
81
110
  * how several list endpoints model their filters on the wire (e.g.
82
111
  * Cloudflare zones list `account.id` / `account.name`) while the TS surface
83
112
  * keeps the nested-object shape (v0 parity).
@@ -86,10 +115,21 @@ export declare const DeepQuery: (name?: string) => Annotation;
86
115
  export declare const httpBodySymbol: unique symbol;
87
116
  /**
88
117
  * Marks the input member whose value IS the entire request body (raw arrays/
89
- * scalars — e.g. endpoints that POST a bare JSON array). Mirrors
118
+ * scalars -- e.g. endpoints that POST a bare JSON array). Mirrors
90
119
  * `smithy.api#httpPayload`.
91
120
  */
92
121
  export declare const HttpBody: () => Annotation;
122
+ export declare const stringEncodedSymbol: unique symbol;
123
+ /**
124
+ * Marks a member the API only accepts as the STRING spelling of its value --
125
+ * `true` travels as `"true"`, `3` as `"3"` -- while the TS surface keeps the
126
+ * natural type (e.g. Cloudflare's multipart `validation_enabled`, which the
127
+ * docs model as the enum `"true" | "false"`). The protocol stringifies body
128
+ * members on encode, element-wise for lists; `null` is left alone. Query and
129
+ * header bindings already serialize their values as strings, so the trait is
130
+ * documentation there.
131
+ */
132
+ export declare const StringEncoded: () => Annotation;
93
133
  export declare const formDataFileSymbol: unique symbol;
94
134
  /**
95
135
  * Marks an input member holding `File`/`Blob` parts for a multipart upload
@@ -99,7 +139,7 @@ export declare const formDataFileSymbol: unique symbol;
99
139
  export declare const FormDataFile: () => Annotation;
100
140
  export declare const keyDictionarySymbol: unique symbol;
101
141
  /**
102
- * Deep TS-name→wire-name key dictionary for members whose full structure is
142
+ * Deep TS-name->wire-name key dictionary for members whose full structure is
103
143
  * not modeled (opaque `Document` content). The protocol renames any matching
104
144
  * key at any depth on encode (and the reverse on decode); keys not in the
105
145
  * dictionary pass through verbatim.
@@ -113,38 +153,72 @@ export declare const keyDictionarySymbol: unique symbol;
113
153
  export type KeyDictionaryEntries = Record<string, string | ReadonlyArray<string>>;
114
154
  export declare const KeyDictionary: (dict: KeyDictionaryEntries) => Annotation;
115
155
  export declare const unionCasesSymbol: unique symbol;
156
+ /**
157
+ * The literal member every case of a union fixes to its own value -- what the
158
+ * docs call the resource `type` or the action `id`. `values[i]` is the value
159
+ * case `i` carries.
160
+ */
161
+ export interface UnionDiscriminator {
162
+ readonly key: string;
163
+ readonly values: ReadonlyArray<string>;
164
+ }
116
165
  /**
117
166
  * Marks an opaque schema standing in for a discriminated union of object
118
167
  * cases, carrying each case's TS-facing key set. For APIs that return every
119
168
  * case's keys with `null` for the inactive ones, the protocol uses these key
120
169
  * sets to pick the active case and drop the others, so consumers' `"key" in
121
170
  * value` discrimination works.
171
+ *
172
+ * Key sets alone cannot tell apart cases that share them -- the 41 resource
173
+ * kinds of `resource_tagging`, the 34 page-rule actions -- so when the union
174
+ * has a discriminator the protocol reads the case off it and only falls back
175
+ * to key-set scoring for a value whose tag is missing or unknown.
176
+ *
177
+ * `dictionaries[i]` holds case `i`'s member-level `T.KeyDictionary`s by TS
178
+ * member name, which the opaque schema cannot carry on the members
179
+ * themselves. An empty one (`{}`) keeps a member's content keys as written:
180
+ * a Worker binding's `json` or `props` is the caller's own JSON. A union
181
+ * with dictionaries is mapped per case in both directions.
122
182
  */
123
- export declare const UnionCases: (cases: ReadonlyArray<ReadonlyArray<string>>) => Annotation;
183
+ export declare const UnionCases: (cases: ReadonlyArray<ReadonlyArray<string>>, discriminator?: UnionDiscriminator, dictionaries?: ReadonlyArray<Readonly<Record<string, KeyDictionaryEntries>>>) => Annotation;
124
184
  export declare const errorMatchersSymbol: unique symbol;
185
+ /** Exact text, or the conjunction of substring and regular-expression constraints. */
186
+ export type ErrorTextMatcher = string | {
187
+ readonly includes?: string;
188
+ readonly matches?: string;
189
+ };
125
190
  /**
126
- * One wire-matching rule for a typed error class. A matcher matches a wire
127
- * failure when every present field matches: `code` equals the wire error's
128
- * code, `status` equals the HTTP status, and `message` either equals the
129
- * error message (string form) or satisfies `includes` (substring) /
130
- * `matches` (regex). A matcher with no fields matches nothing.
191
+ * One wire-matching rule. All supplied constraints must match; separate
192
+ * matchers on a class are alternatives. Empty matchers match nothing.
193
+ *
194
+ * `body` maps RFC 6901 JSON Pointers to scalar constraints. For example,
195
+ * `{ "/success": false, "/result/status": "error" }`. Strings also accept
196
+ * `includes` / `matches`. Missing fields never match, including against null.
197
+ * The empty pointer addresses the entire body; array indices are supported.
198
+ * Header names are case-insensitive; their value constraints are case-sensitive.
199
+ * Each body path and header adds one specificity point, like code/status/message.
200
+ * Protocols evaluate these rules only after identifying a failed response.
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * { status: 200, body: { "/success": false, "/result/status": "error" } }
205
+ * { status: 409, headers: { "x-error-type": { includes: "Conflict" } } }
206
+ * ```
131
207
  */
132
208
  export interface ErrorMatcher {
133
209
  readonly code?: number;
134
210
  readonly status?: number;
135
- readonly message?: string | {
136
- readonly includes?: string;
137
- readonly matches?: string;
138
- };
211
+ readonly message?: ErrorTextMatcher;
212
+ readonly body?: Readonly<Record<string, ErrorTextMatcher | number | boolean | null>>;
213
+ readonly headers?: Readonly<Record<string, ErrorTextMatcher>>;
139
214
  }
140
215
  /**
141
216
  * Stamp wire-matching rules onto a generated error class. Protocols consult
142
217
  * these to decide which of an operation's declared error classes a failed
143
218
  * response should surface as (most specific matcher wins; ties break by
144
- * declaration order — see `matchTypedError` in `core/protocol-http`).
219
+ * declaration order -- see `matchTypedError` in `core/protocol-http`).
145
220
  */
146
221
  export declare const applyErrorMatchers: <C>(cls: C, matchers: ReadonlyArray<ErrorMatcher>) => C;
147
222
  /** Read the matchers stamped on an error class, if any. */
148
223
  export declare const getErrorMatchers: (cls: unknown) => ReadonlyArray<ErrorMatcher> | undefined;
149
- export {};
150
224
  //# sourceMappingURL=trait.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trait.d.ts","sourceRoot":"","sources":["../src/trait.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,eAEhC,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,QAAQ,CAAC,WAAW,EAAE,GAAG,GAAG,WAAW,CAAC;CACzC,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,CAAC,CAAC,SAAS,WAAW,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IACtC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,EAAE,KAAK,CAAC;QACrC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;QACxB,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC,CAAC;IACH,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAM5E;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,GAAG,WAAW,EAAE,UAAU,EAAE,GAAG,UAAU,CAe5D;AAOD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EACX,KAAK,GACL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C,KAAG,CAGrF,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,gBAAgB,QAAS,OAAO,KAAG,aAAa,CAAC,YAAY,CAAC,GAAG,SACzC,CAAC"}
package/lib/trait.js CHANGED
@@ -1,107 +1 @@
1
- export const annotationMetaSymbol = Symbol.for("@distilled.cloud/core/annotation-meta");
2
- /**
3
- * Build a pipeable schema annotation carrying `value` under `sym`. Exported
4
- * so SDK packages can define their own protocol traits (e.g. cloudflare's
5
- * envelope traits, aws's smithy traits) with the same mechanics as the
6
- * generic ones here. Keys may be symbols or plain strings — effect Schema
7
- * annotation dictionaries accept both.
8
- */
9
- export function makeAnnotation(sym, value) {
10
- const fn = (schema) => schema.annotate({ [sym]: value });
11
- fn[annotationMetaSymbol] = [{ symbol: sym, value }];
12
- fn[sym] = value;
13
- return fn;
14
- }
15
- /**
16
- * Combine several annotations into one — needed where only a single
17
- * annotations object can be supplied (e.g. the second argument of
18
- * `S.Class`).
19
- */
20
- export function all(...annotations) {
21
- const entries = [];
22
- const raw = {};
23
- for (const a of annotations) {
24
- for (const entry of a[annotationMetaSymbol]) {
25
- entries.push(entry);
26
- raw[entry.symbol] = entry.value;
27
- }
28
- }
29
- const fn = (schema) => schema.annotate(raw);
30
- fn[annotationMetaSymbol] = entries;
31
- for (const { symbol: sym, value } of entries) {
32
- fn[sym] = value;
33
- }
34
- return fn;
35
- }
36
- export const httpSymbol = Symbol.for("@distilled.cloud/core/http");
37
- /**
38
- * Operation-level HTTP binding: the request method + URI template. Stamped on
39
- * the input schema so the protocol can build the request line. URI `{labels}`
40
- * are filled from members marked with `Label()`.
41
- */
42
- export const Http = (trait) => makeAnnotation(httpSymbol, trait);
43
- export const labelSymbol = Symbol.for("@distilled.cloud/core/http/label");
44
- /** Bind a member to a `{name}` placeholder in the operation's URI template. */
45
- export const Label = (name) => makeAnnotation(labelSymbol, name ?? true);
46
- export const responseCodeSymbol = Symbol.for("@distilled.cloud/core/http/response-code");
47
- export const ResponseCode = () => makeAnnotation(responseCodeSymbol, true);
48
- export const headerSymbol = Symbol.for("@distilled.cloud/core/http/header");
49
- export const Header = (name) => makeAnnotation(headerSymbol, name ?? true);
50
- export const bodySymbol = Symbol.for("@distilled.cloud/core/http/body");
51
- export const Body = (name) => makeAnnotation(bodySymbol, name ?? true);
52
- export const querySymbol = Symbol.for("@distilled.cloud/core/http/query");
53
- export const Query = (name) => makeAnnotation(querySymbol, name ?? true);
54
- export const deepQuerySymbol = Symbol.for("@distilled.cloud/core/http/deep-query");
55
- /**
56
- * Binds a struct-valued input member to a family of DOTTED query parameters:
57
- * `{ account: { id, name } }` with `DeepQuery("account")` serializes as
58
- * `?account.id=…&account.name=…` (null/undefined entries skipped). This is
59
- * how several list endpoints model their filters on the wire (e.g.
60
- * Cloudflare zones list `account.id` / `account.name`) while the TS surface
61
- * keeps the nested-object shape (v0 parity).
62
- */
63
- export const DeepQuery = (name) => makeAnnotation(deepQuerySymbol, name ?? true);
64
- export const httpBodySymbol = Symbol.for("@distilled.cloud/core/http-body");
65
- /**
66
- * Marks the input member whose value IS the entire request body (raw arrays/
67
- * scalars — e.g. endpoints that POST a bare JSON array). Mirrors
68
- * `smithy.api#httpPayload`.
69
- */
70
- export const HttpBody = () => makeAnnotation(httpBodySymbol, true);
71
- export const formDataFileSymbol = Symbol.for("@distilled.cloud/core/form-data-file");
72
- /**
73
- * Marks an input member holding `File`/`Blob` parts for a multipart upload
74
- * (`Http({ contentType: "multipart" })`). Each file is appended to the form
75
- * under its own filename.
76
- */
77
- export const FormDataFile = () => makeAnnotation(formDataFileSymbol, true);
78
- //#endregion
79
- //#region Generic JSON traits
80
- export const keyDictionarySymbol = Symbol.for("@distilled.cloud/core/key-dictionary");
81
- export const KeyDictionary = (dict) => makeAnnotation(keyDictionarySymbol, dict);
82
- export const unionCasesSymbol = Symbol.for("@distilled.cloud/core/union-cases");
83
- /**
84
- * Marks an opaque schema standing in for a discriminated union of object
85
- * cases, carrying each case's TS-facing key set. For APIs that return every
86
- * case's keys with `null` for the inactive ones, the protocol uses these key
87
- * sets to pick the active case and drop the others, so consumers' `"key" in
88
- * value` discrimination works.
89
- */
90
- export const UnionCases = (cases) => makeAnnotation(unionCasesSymbol, cases);
91
- //#endregion
92
- //#region Error matcher traits
93
- export const errorMatchersSymbol = Symbol.for("@distilled.cloud/core/error-matchers");
94
- /**
95
- * Stamp wire-matching rules onto a generated error class. Protocols consult
96
- * these to decide which of an operation's declared error classes a failed
97
- * response should surface as (most specific matcher wins; ties break by
98
- * declaration order — see `matchTypedError` in `core/protocol-http`).
99
- */
100
- export const applyErrorMatchers = (cls, matchers) => {
101
- cls[errorMatchersSymbol] = matchers;
102
- return cls;
103
- };
104
- /** Read the matchers stamped on an error class, if any. */
105
- export const getErrorMatchers = (cls) => cls?.[errorMatchersSymbol];
106
- //#endregion
107
- //# sourceMappingURL=trait.js.map
1
+ export { trait$Body as Body, trait$CommaDelimited as CommaDelimited, trait$DeepQuery as DeepQuery, trait$FormDataFile as FormDataFile, trait$Header as Header, trait$Http as Http, trait$HttpBody as HttpBody, trait$IdempotencyToken as IdempotencyToken, trait$KeyDictionary as KeyDictionary, trait$Label as Label, trait$LabelEncoding as LabelEncoding, trait$Query as Query, trait$ResponseCode as ResponseCode, trait$StringEncoded as StringEncoded, trait$UnionCases as UnionCases, trait$all as all, trait$annotationMetaSymbol as annotationMetaSymbol, trait$applyErrorMatchers as applyErrorMatchers, trait$bodySymbol as bodySymbol, trait$commaDelimitedSymbol as commaDelimitedSymbol, trait$deepQuerySymbol as deepQuerySymbol, trait$errorMatchersSymbol as errorMatchersSymbol, trait$formDataFileSymbol as formDataFileSymbol, trait$getErrorMatchers as getErrorMatchers, trait$headerSymbol as headerSymbol, trait$httpBodySymbol as httpBodySymbol, trait$httpSymbol as httpSymbol, trait$idempotencyTokenSymbol as idempotencyTokenSymbol, trait$keyDictionarySymbol as keyDictionarySymbol, trait$labelEncodingSymbol as labelEncodingSymbol, trait$labelSymbol as labelSymbol, trait$makeAnnotation as makeAnnotation, trait$querySymbol as querySymbol, trait$responseCodeSymbol as responseCodeSymbol, trait$stringEncodedSymbol as stringEncodedSymbol, trait$unionCasesSymbol as unionCasesSymbol } from "./_bundle/base.js";
@@ -0,0 +1,18 @@
1
+ export declare const UnknownErrorFields: {
2
+ /** HTTP status of the response that carried the failure. */
3
+ status: import("effect/Schema").Number;
4
+ /** The provider's machine-readable error code, when the response has one. */
5
+ code: import("effect/Schema").optional<import("effect/Schema").String>;
6
+ /** The provider's error message, when the response has one. */
7
+ message: import("effect/Schema").optional<import("effect/Schema").String>;
8
+ /** Parsed JSON body, or the raw text when the body wasn't JSON. */
9
+ body: import("effect/Schema").Unknown;
10
+ };
11
+ /** The values of {@link UnknownErrorFields}. */
12
+ export interface UnknownErrorProps {
13
+ readonly status: number;
14
+ readonly code?: string | undefined;
15
+ readonly message?: string | undefined;
16
+ readonly body: unknown;
17
+ }
18
+ //# sourceMappingURL=unknown-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown-error.d.ts","sources":["../src/unknown-error.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB;IAC7B,4DAA4D;IAC5D,MAAM;IACN,6EAA6E;IAC7E,IAAI;IACJ,+DAA+D;IAC/D,OAAO;IACP,mEAAmE;IACnE,IAAI;CACL,CAAC;AAEF,gDAAgD;AAChD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB"}
@@ -0,0 +1 @@
1
+ export { unknown_error$UnknownErrorFields as UnknownErrorFields } from "./_bundle/base.js";
package/lib/xml.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import * as Effect from "effect/Effect";
2
+ export type XmlValue = string | XmlObject | XmlValue[];
3
+ export interface XmlObject {
4
+ [name: string]: XmlValue;
5
+ }
6
+ declare const XmlParseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
7
+ readonly _tag: "XmlParseError";
8
+ } & Readonly<A>;
9
+ export declare class XmlParseError extends /*@__PURE__*/ XmlParseError_base<{
10
+ readonly message: string;
11
+ /** UTF-16 offset in the original input; line and column are one-based. */
12
+ readonly offset: number;
13
+ readonly line: number;
14
+ readonly column: number;
15
+ }> {
16
+ }
17
+ export interface XmlParseOptions {
18
+ /** Maximum open elements, including the root. Defaults to 256. */
19
+ readonly maxDepth?: number;
20
+ /** Maximum input length in UTF-16 code units. Defaults to 64 Mi. */
21
+ readonly maxLength?: number;
22
+ }
23
+ /**
24
+ * Parse DTD-free XML 1.0. Values remain strings;
25
+ * repeated children become arrays, attributes use @_ and mixed text uses #text.
26
+ * Names are preserved verbatim (no namespace resolution). Comments and PIs are
27
+ * ignored. Text whitespace is preserved, except layout-only text in containers.
28
+ * Empty HTTP bodies produce {}. This is not a DOM or a validating DTD processor.
29
+ * Throws XmlParseError for malformed input or exceeded limits.
30
+ * The iterative scanner allocates no Effects while traversing the document.
31
+ */
32
+ export declare function parseXmlSync(xml: string, options?: XmlParseOptions): XmlObject;
33
+ /** Parse XML lazily, reporting malformed documents in the typed error channel. */
34
+ export declare const parseXml: (xml: string, options?: XmlParseOptions) => Effect.Effect<XmlObject, XmlParseError>;
35
+ /**
36
+ * Escape special XML characters in a string.
37
+ */
38
+ export declare const escapeXml: (s: string) => string;
39
+ /**
40
+ * Wrap content in an XML tag with optional xmlns attribute.
41
+ */
42
+ export declare const wrapTag: (tag: string, content: string, xmlns?: string) => string;
43
+ export {};
44
+ //# sourceMappingURL=xml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml.d.ts","sources":["../src/xml.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,EAAE,CAAC;AACvD,MAAM,WAAW,SAAS;IACxB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC1B;;;;AAED,qBAAa,aACX,SAAQ,aAAa,CAAC,mBAAkC;IACtD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;CAAG;AAEP,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,oEAAoE;IACpE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAmCD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,SAAS,CAyOlF;AAED,kFAAkF;AAClF,eAAO,MAAM,QAAQ,QACd,MAAM,YACD,eAAe,KACxB,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,aAAa,CAiBrC,CAAC;AAUL;;GAEG;AACH,eAAO,MAAM,SAAS,MAAO,MAAM,KAAG,MAAqD,CAAC;AAM5F;;GAEG;AACH,eAAO,MAAM,OAAO,QAAS,MAAM,WAAW,MAAM,UAAU,MAAM,KAAG,MACM,CAAC"}
package/lib/xml.js ADDED
@@ -0,0 +1 @@
1
+ export { xml$XmlParseError as XmlParseError, xml$escapeXml as escapeXml, xml$parseXml as parseXml, xml$parseXmlSync as parseXmlSync, xml$wrapTag as wrapTag } from "./_bundle/xml.js";
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@distilled.cloud/core",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.21",
4
+ "license": "Apache-2.0",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "https://github.com/alchemy-run/distilled",
7
8
  "directory": "packages/core"
8
9
  },
9
- "license": "Apache-2.0",
10
- "type": "module",
11
- "sideEffects": false,
12
10
  "files": [
13
11
  "lib",
14
12
  "src"
15
13
  ],
14
+ "type": "module",
15
+ "sideEffects": false,
16
16
  "exports": {
17
17
  ".": {
18
18
  "types": "./lib/index.d.ts",
@@ -20,6 +20,7 @@
20
20
  "worker": "./src/index.ts",
21
21
  "import": "./lib/index.js"
22
22
  },
23
+ "./_bundle/*": "./lib/_bundle/*.js",
23
24
  "./*": {
24
25
  "types": "./lib/*.d.ts",
25
26
  "bun": "./src/*.ts",
@@ -27,16 +28,15 @@
27
28
  "import": "./lib/*.js"
28
29
  }
29
30
  },
30
- "scripts": {
31
- "build": "tsc -b"
32
- },
33
31
  "devDependencies": {
34
- "@effect/platform-bun": ">=4.0.0-beta.102 || >=4.0.0",
35
- "@types/bun": "latest",
36
- "@types/node": "latest",
37
- "effect": ">=4.0.0-beta.102 || >=4.0.0"
32
+ "@types/node": "26.6.5",
33
+ "effect": "~4.1.7",
34
+ "vitest": "^5.0.4"
38
35
  },
39
36
  "peerDependencies": {
40
- "effect": ">=4.0.0-beta.102 || >=4.0.0"
37
+ "effect": "~4.1.7"
38
+ },
39
+ "scripts": {
40
+ "build": "tsrs -b"
41
41
  }
42
- }
42
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Reading schema annotations through the wrappers a generated schema has:
3
+ * Suspend, encodings, and `S.optional` / nullable unions. Shared by the
4
+ * protocols (via `./protocol-http.ts`) and by `./telemetry.ts`, which
5
+ * derives span facts from the same annotations.
6
+ */
7
+ import type * as AST from "effect/SchemaAST";
8
+
9
+ /**
10
+ * Marks a response schema whose entire value is the response body (see
11
+ * `RawResponseRoot` in `./protocol-rest.ts`).
12
+ */
13
+ export const rawResponseRootSymbol = /*@__PURE__*/ Symbol.for(
14
+ "@distilled.cloud/core/raw-response-root",
15
+ );
16
+
17
+ export const getProps = (ast: AST.AST): readonly AST.PropertySignature[] => {
18
+ if (ast._tag === "Objects") return ast.propertySignatures;
19
+ if (ast._tag === "Suspend") return getProps(ast.thunk());
20
+ if (ast.encoding && ast.encoding.length > 0) return getProps(ast.encoding[0]!.to);
21
+ return [];
22
+ };
23
+
24
+ export const getAnn = (ast: AST.AST, symbol: symbol): unknown => {
25
+ const direct = (ast.annotations as Record<symbol, unknown> | undefined)?.[symbol];
26
+ if (direct !== undefined) return direct;
27
+ if (ast._tag === "Suspend") return getAnn(ast.thunk(), symbol);
28
+ if (ast.encoding && ast.encoding.length > 0) return getAnn(ast.encoding[0]!.to, symbol);
29
+ // S.optional -> Union[self, Undefined]; descend into the single real member.
30
+ if (ast._tag === "Union") {
31
+ const real = (ast as AST.Union).types.filter(
32
+ (t) => t._tag !== "Undefined" && !(t._tag === "Literal" && (t as any).literal === null),
33
+ );
34
+ if (real.length === 1) return getAnn(real[0]!, symbol);
35
+ }
36
+ return undefined;
37
+ };
38
+
39
+ /** Resolve wrappers to the real node: Suspend, encoding, optional/null unions. */
40
+ export const resolveNode = (ast: AST.AST): AST.AST => {
41
+ if (ast._tag === "Suspend") return resolveNode(ast.thunk());
42
+ if (ast.encoding && ast.encoding.length > 0) return resolveNode(ast.encoding[0]!.to);
43
+ if (ast._tag === "Union") {
44
+ const real = (ast as AST.Union).types.filter(
45
+ (t) =>
46
+ t._tag !== "Undefined" &&
47
+ t._tag !== "Null" &&
48
+ !(t._tag === "Literal" && (t as any).literal === null),
49
+ );
50
+ if (real.length === 1) return resolveNode(real[0]!);
51
+ }
52
+ return ast;
53
+ };