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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/lib/_bundle/aws.js +2 -0
  2. package/lib/_bundle/aws.js.map +1 -0
  3. package/lib/_bundle/base.js +5 -0
  4. package/lib/_bundle/base.js.map +1 -0
  5. package/lib/_bundle/graphql.js +3 -0
  6. package/lib/_bundle/graphql.js.map +1 -0
  7. package/lib/_bundle/rest.js +2 -0
  8. package/lib/_bundle/rest.js.map +1 -0
  9. package/lib/_bundle/xml.js +4 -0
  10. package/lib/_bundle/xml.js.map +1 -0
  11. package/lib/annotations.d.ts +15 -0
  12. package/lib/annotations.d.ts.map +1 -0
  13. package/lib/annotations.js +2 -0
  14. package/lib/annotations.js.map +1 -0
  15. package/lib/api.d.ts +15 -0
  16. package/lib/api.d.ts.map +1 -1
  17. package/lib/api.js +1 -796
  18. package/lib/category.d.ts.map +1 -1
  19. package/lib/category.js +1 -278
  20. package/lib/chunks.js +1 -11
  21. package/lib/config.d.ts +54 -13
  22. package/lib/config.d.ts.map +1 -1
  23. package/lib/config.js +1 -161
  24. package/lib/crypto.js +1 -130
  25. package/lib/debug.d.ts.map +1 -1
  26. package/lib/debug.js +1 -8
  27. package/lib/error-category.d.ts.map +1 -1
  28. package/lib/error-category.js +1 -47
  29. package/lib/errors.d.ts +2 -13
  30. package/lib/errors.d.ts.map +1 -1
  31. package/lib/errors.js +1 -198
  32. package/lib/graphql.d.ts +14 -0
  33. package/lib/graphql.d.ts.map +1 -1
  34. package/lib/graphql.js +1 -1058
  35. package/lib/graphql.types.js +1 -6
  36. package/lib/index.d.ts +3 -2
  37. package/lib/index.d.ts.map +1 -1
  38. package/lib/index.js +1 -15
  39. package/lib/pagination.d.ts +34 -2
  40. package/lib/pagination.d.ts.map +1 -1
  41. package/lib/pagination.js +1 -271
  42. package/lib/plain-values.js +1 -39
  43. package/lib/plain-values.js.map +1 -1
  44. package/lib/protocol-http.d.ts +30 -6
  45. package/lib/protocol-http.d.ts.map +1 -1
  46. package/lib/protocol-http.js +1 -812
  47. package/lib/protocol-rest.d.ts +53 -39
  48. package/lib/protocol-rest.d.ts.map +1 -1
  49. package/lib/protocol-rest.js +1 -375
  50. package/lib/query.js +1 -27
  51. package/lib/response-validation-strict.js +1 -284
  52. package/lib/response-validation.d.ts +4 -3
  53. package/lib/response-validation.d.ts.map +1 -1
  54. package/lib/response-validation.js +1 -118
  55. package/lib/retry-after.js +1 -112
  56. package/lib/retry.js +1 -197
  57. package/lib/schema-lite-impl.js +1 -341
  58. package/lib/schema-lite-typed.js +1 -27
  59. package/lib/schema-lite.js +1 -31
  60. package/lib/schema.js +1 -220
  61. package/lib/telemetry-debug.d.ts +14 -0
  62. package/lib/telemetry-debug.d.ts.map +1 -0
  63. package/lib/telemetry-debug.js +2 -0
  64. package/lib/telemetry-debug.js.map +1 -0
  65. package/lib/telemetry-hooks.d.ts +32 -0
  66. package/lib/telemetry-hooks.d.ts.map +1 -0
  67. package/lib/telemetry-hooks.js +2 -0
  68. package/lib/telemetry-hooks.js.map +1 -0
  69. package/lib/telemetry-host-rules.d.ts +23 -0
  70. package/lib/telemetry-host-rules.d.ts.map +1 -0
  71. package/lib/telemetry-host-rules.js +2 -0
  72. package/lib/telemetry-host-rules.js.map +1 -0
  73. package/lib/telemetry-lambda-context.d.ts +17 -0
  74. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  75. package/lib/telemetry-lambda-context.js +2 -0
  76. package/lib/telemetry-lambda-context.js.map +1 -0
  77. package/lib/telemetry-message-context.d.ts +52 -0
  78. package/lib/telemetry-message-context.d.ts.map +1 -0
  79. package/lib/telemetry-message-context.js +2 -0
  80. package/lib/telemetry-message-context.js.map +1 -0
  81. package/lib/telemetry-metrics.d.ts +6 -0
  82. package/lib/telemetry-metrics.d.ts.map +1 -0
  83. package/lib/telemetry-metrics.js +2 -0
  84. package/lib/telemetry-metrics.js.map +1 -0
  85. package/lib/telemetry-name-template.d.ts +13 -0
  86. package/lib/telemetry-name-template.d.ts.map +1 -0
  87. package/lib/telemetry-name-template.js +2 -0
  88. package/lib/telemetry-name-template.js.map +1 -0
  89. package/lib/telemetry-stream.d.ts +9 -0
  90. package/lib/telemetry-stream.d.ts.map +1 -0
  91. package/lib/telemetry-stream.js +2 -0
  92. package/lib/telemetry-stream.js.map +1 -0
  93. package/lib/telemetry-xray.d.ts +28 -0
  94. package/lib/telemetry-xray.d.ts.map +1 -0
  95. package/lib/telemetry-xray.js +2 -0
  96. package/lib/telemetry-xray.js.map +1 -0
  97. package/lib/telemetry.d.ts +269 -0
  98. package/lib/telemetry.d.ts.map +1 -0
  99. package/lib/telemetry.js +3 -0
  100. package/lib/telemetry.js.map +1 -0
  101. package/lib/trait.js +1 -131
  102. package/lib/xml.js +1 -323
  103. package/package.json +1 -3
  104. package/src/annotations.ts +37 -0
  105. package/src/api.ts +130 -30
  106. package/src/category.ts +21 -22
  107. package/src/config.ts +58 -29
  108. package/src/debug.ts +9 -6
  109. package/src/error-category.ts +12 -14
  110. package/src/errors.ts +7 -7
  111. package/src/graphql.ts +123 -18
  112. package/src/index.ts +3 -2
  113. package/src/pagination.ts +119 -6
  114. package/src/protocol-http.ts +63 -43
  115. package/src/protocol-rest.ts +201 -140
  116. package/src/response-validation.ts +4 -3
  117. package/src/telemetry-debug.ts +135 -0
  118. package/src/telemetry-hooks.ts +33 -0
  119. package/src/telemetry-host-rules.ts +39 -0
  120. package/src/telemetry-lambda-context.ts +46 -0
  121. package/src/telemetry-message-context.ts +170 -0
  122. package/src/telemetry-metrics.ts +69 -0
  123. package/src/telemetry-name-template.ts +26 -0
  124. package/src/telemetry-stream.ts +91 -0
  125. package/src/telemetry-xray.ts +66 -0
  126. package/src/telemetry.ts +768 -0
  127. package/lib/api.js.map +0 -1
  128. package/lib/category.js.map +0 -1
  129. package/lib/chunks.js.map +0 -1
  130. package/lib/codegen/boolean-string-enums.d.ts +0 -36
  131. package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
  132. package/lib/codegen/boolean-string-enums.js +0 -147
  133. package/lib/codegen/boolean-string-enums.js.map +0 -1
  134. package/lib/codegen/chunk.d.ts +0 -7
  135. package/lib/codegen/chunk.d.ts.map +0 -1
  136. package/lib/codegen/chunk.js +0 -139
  137. package/lib/codegen/chunk.js.map +0 -1
  138. package/lib/codegen/cli.d.ts +0 -80
  139. package/lib/codegen/cli.d.ts.map +0 -1
  140. package/lib/codegen/cli.js +0 -166
  141. package/lib/codegen/cli.js.map +0 -1
  142. package/lib/codegen/datafy.d.ts +0 -14
  143. package/lib/codegen/datafy.d.ts.map +0 -1
  144. package/lib/codegen/datafy.js +0 -853
  145. package/lib/codegen/datafy.js.map +0 -1
  146. package/lib/codegen/dedupe.d.ts +0 -5
  147. package/lib/codegen/dedupe.d.ts.map +0 -1
  148. package/lib/codegen/dedupe.js +0 -153
  149. package/lib/codegen/dedupe.js.map +0 -1
  150. package/lib/codegen/emit.d.ts +0 -125
  151. package/lib/codegen/emit.d.ts.map +0 -1
  152. package/lib/codegen/emit.js +0 -99
  153. package/lib/codegen/emit.js.map +0 -1
  154. package/lib/codegen/format.d.ts +0 -11
  155. package/lib/codegen/format.d.ts.map +0 -1
  156. package/lib/codegen/format.js +0 -32
  157. package/lib/codegen/format.js.map +0 -1
  158. package/lib/codegen/generated-at.d.ts +0 -29
  159. package/lib/codegen/generated-at.d.ts.map +0 -1
  160. package/lib/codegen/generated-at.js +0 -78
  161. package/lib/codegen/generated-at.js.map +0 -1
  162. package/lib/codegen/generator.d.ts +0 -353
  163. package/lib/codegen/generator.d.ts.map +0 -1
  164. package/lib/codegen/generator.js +0 -810
  165. package/lib/codegen/generator.js.map +0 -1
  166. package/lib/codegen/graph.d.ts +0 -36
  167. package/lib/codegen/graph.d.ts.map +0 -1
  168. package/lib/codegen/graph.js +0 -136
  169. package/lib/codegen/graph.js.map +0 -1
  170. package/lib/codegen/graphql-client.d.ts +0 -70
  171. package/lib/codegen/graphql-client.d.ts.map +0 -1
  172. package/lib/codegen/graphql-client.js +0 -439
  173. package/lib/codegen/graphql-client.js.map +0 -1
  174. package/lib/codegen/graphql.d.ts +0 -207
  175. package/lib/codegen/graphql.d.ts.map +0 -1
  176. package/lib/codegen/graphql.js +0 -786
  177. package/lib/codegen/graphql.js.map +0 -1
  178. package/lib/codegen/latin1.d.ts +0 -3
  179. package/lib/codegen/latin1.d.ts.map +0 -1
  180. package/lib/codegen/latin1.js +0 -126
  181. package/lib/codegen/latin1.js.map +0 -1
  182. package/lib/codegen/members.d.ts +0 -32
  183. package/lib/codegen/members.d.ts.map +0 -1
  184. package/lib/codegen/members.js +0 -62
  185. package/lib/codegen/members.js.map +0 -1
  186. package/lib/codegen/model-diff.d.ts +0 -10
  187. package/lib/codegen/model-diff.d.ts.map +0 -1
  188. package/lib/codegen/model-diff.js +0 -67
  189. package/lib/codegen/model-diff.js.map +0 -1
  190. package/lib/codegen/naming.d.ts +0 -29
  191. package/lib/codegen/naming.d.ts.map +0 -1
  192. package/lib/codegen/naming.js +0 -74
  193. package/lib/codegen/naming.js.map +0 -1
  194. package/lib/codegen/openapi-cli.d.ts +0 -52
  195. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  196. package/lib/codegen/openapi-cli.js +0 -84
  197. package/lib/codegen/openapi-cli.js.map +0 -1
  198. package/lib/codegen/openapi.d.ts +0 -209
  199. package/lib/codegen/openapi.d.ts.map +0 -1
  200. package/lib/codegen/openapi.js +0 -1548
  201. package/lib/codegen/openapi.js.map +0 -1
  202. package/lib/codegen/operations.d.ts +0 -24
  203. package/lib/codegen/operations.d.ts.map +0 -1
  204. package/lib/codegen/operations.js +0 -56
  205. package/lib/codegen/operations.js.map +0 -1
  206. package/lib/codegen/pagination.d.ts +0 -39
  207. package/lib/codegen/pagination.d.ts.map +0 -1
  208. package/lib/codegen/pagination.js +0 -31
  209. package/lib/codegen/pagination.js.map +0 -1
  210. package/lib/codegen/patch-audit.d.ts +0 -84
  211. package/lib/codegen/patch-audit.d.ts.map +0 -1
  212. package/lib/codegen/patch-audit.js +0 -366
  213. package/lib/codegen/patch-audit.js.map +0 -1
  214. package/lib/codegen/patches.d.ts +0 -129
  215. package/lib/codegen/patches.d.ts.map +0 -1
  216. package/lib/codegen/patches.js +0 -472
  217. package/lib/codegen/patches.js.map +0 -1
  218. package/lib/codegen/prelude.d.ts +0 -15
  219. package/lib/codegen/prelude.d.ts.map +0 -1
  220. package/lib/codegen/prelude.js +0 -60
  221. package/lib/codegen/prelude.js.map +0 -1
  222. package/lib/codegen/privatize.d.ts +0 -21
  223. package/lib/codegen/privatize.d.ts.map +0 -1
  224. package/lib/codegen/privatize.js +0 -176
  225. package/lib/codegen/privatize.js.map +0 -1
  226. package/lib/codegen/proto.d.ts +0 -121
  227. package/lib/codegen/proto.d.ts.map +0 -1
  228. package/lib/codegen/proto.js +0 -960
  229. package/lib/codegen/proto.js.map +0 -1
  230. package/lib/codegen/pure.d.ts +0 -6
  231. package/lib/codegen/pure.d.ts.map +0 -1
  232. package/lib/codegen/pure.js +0 -91
  233. package/lib/codegen/pure.js.map +0 -1
  234. package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
  235. package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
  236. package/lib/codegen/rewrite-operation-ids.js +0 -1117
  237. package/lib/codegen/rewrite-operation-ids.js.map +0 -1
  238. package/lib/codegen/spec-path.d.ts +0 -16
  239. package/lib/codegen/spec-path.d.ts.map +0 -1
  240. package/lib/codegen/spec-path.js +0 -101
  241. package/lib/codegen/spec-path.js.map +0 -1
  242. package/lib/codegen/table.d.ts +0 -5
  243. package/lib/codegen/table.d.ts.map +0 -1
  244. package/lib/codegen/table.js +0 -249
  245. package/lib/codegen/table.js.map +0 -1
  246. package/lib/config.js.map +0 -1
  247. package/lib/crypto.js.map +0 -1
  248. package/lib/debug.js.map +0 -1
  249. package/lib/error-category.js.map +0 -1
  250. package/lib/errors.js.map +0 -1
  251. package/lib/graphql.js.map +0 -1
  252. package/lib/graphql.types.js.map +0 -1
  253. package/lib/index.js.map +0 -1
  254. package/lib/json-patch.d.ts +0 -58
  255. package/lib/json-patch.d.ts.map +0 -1
  256. package/lib/json-patch.js +0 -227
  257. package/lib/json-patch.js.map +0 -1
  258. package/lib/pagination.js.map +0 -1
  259. package/lib/protocol-http.js.map +0 -1
  260. package/lib/protocol-rest.js.map +0 -1
  261. package/lib/query.js.map +0 -1
  262. package/lib/response-validation-strict.js.map +0 -1
  263. package/lib/response-validation.js.map +0 -1
  264. package/lib/retry-after.js.map +0 -1
  265. package/lib/retry.js.map +0 -1
  266. package/lib/schema-lite-impl.js.map +0 -1
  267. package/lib/schema-lite-typed.js.map +0 -1
  268. package/lib/schema-lite.js.map +0 -1
  269. package/lib/schema.js.map +0 -1
  270. package/lib/testing.d.ts +0 -40
  271. package/lib/testing.d.ts.map +0 -1
  272. package/lib/testing.js +0 -42
  273. package/lib/testing.js.map +0 -1
  274. package/lib/trait.js.map +0 -1
  275. package/lib/xml.js.map +0 -1
  276. package/src/codegen/boolean-string-enums.ts +0 -155
  277. package/src/codegen/chunk.ts +0 -147
  278. package/src/codegen/cli.ts +0 -293
  279. package/src/codegen/datafy.ts +0 -874
  280. package/src/codegen/dedupe.ts +0 -173
  281. package/src/codegen/emit.ts +0 -200
  282. package/src/codegen/format.ts +0 -49
  283. package/src/codegen/generated-at.ts +0 -88
  284. package/src/codegen/generator.ts +0 -1229
  285. package/src/codegen/graph.ts +0 -151
  286. package/src/codegen/graphql-client.ts +0 -545
  287. package/src/codegen/graphql.ts +0 -1145
  288. package/src/codegen/latin1.ts +0 -131
  289. package/src/codegen/members.ts +0 -79
  290. package/src/codegen/model-diff.ts +0 -67
  291. package/src/codegen/naming.ts +0 -85
  292. package/src/codegen/openapi-cli.ts +0 -141
  293. package/src/codegen/openapi.ts +0 -1845
  294. package/src/codegen/operations.ts +0 -73
  295. package/src/codegen/pagination.ts +0 -64
  296. package/src/codegen/patch-audit.ts +0 -480
  297. package/src/codegen/patches.ts +0 -581
  298. package/src/codegen/prelude.ts +0 -70
  299. package/src/codegen/privatize.ts +0 -200
  300. package/src/codegen/proto.ts +0 -1092
  301. package/src/codegen/pure.ts +0 -94
  302. package/src/codegen/rewrite-operation-ids.ts +0 -1219
  303. package/src/codegen/spec-path.ts +0 -112
  304. package/src/codegen/table.ts +0 -254
  305. package/src/json-patch.ts +0 -273
  306. package/src/testing.ts +0 -74
@@ -1,284 +1 @@
1
-
2
- export class SchemaMismatch extends Error {
3
- name = "SchemaError";
4
-
5
- path;
6
-
7
- expected;
8
- actual;
9
- constructor(path, expected, actual) {
10
- super(`Expected ${expected}, got ${show(actual)}${path.length ? ` at ${JSON.stringify(path.map((k) => (typeof k === "symbol" ? String(k) : k)))}` : ""}`);
11
- this.path = path;
12
- this.expected = expected;
13
- this.actual = actual;
14
- }
15
- }
16
-
17
-
18
-
19
-
20
- export const withholdActual = (mismatch) => new SchemaMismatch(mismatch.path, mismatch.expected, "[REDACTED]");
21
- const show = (u) => {
22
- if (u === MISSING)
23
- return "nothing (missing key)";
24
- if (u === undefined)
25
- return "undefined";
26
- if (typeof u === "string")
27
- return JSON.stringify(u.length > 40 ? `${u.slice(0, 40)}...` : u);
28
- if (Array.isArray(u))
29
- return "an array";
30
- if (u !== null && typeof u === "object")
31
- return "an object";
32
- return String(u);
33
- };
34
- const MISSING = Symbol("missing");
35
-
36
-
37
-
38
-
39
- const makeCompile = (exact) => {
40
- const fail = (expected, actual) => ({ path: [], expected, actual });
41
- const ok = () => undefined;
42
- const typeOf = (t) => (u) => typeof u === t ? undefined : fail(t, u);
43
- const compiled = new WeakMap();
44
- const compile = (n) => {
45
- let c = compiled.get(n);
46
- if (c === undefined) {
47
- // A node reached again while it compiles (only through Suspend) calls
48
- // through this slot.
49
- let self;
50
- compiled.set(n, (u) => self(u));
51
- self = c = withChecks(n, build(n));
52
- compiled.set(n, c);
53
- }
54
- return c;
55
- };
56
-
57
- const withChecks = (n, base) => {
58
- const checks = n.checks;
59
- if (!checks?.length || isLite(n))
60
- return base;
61
- const flat = [];
62
- const add = (c) => (c._tag === "FilterGroup" ? c.checks.forEach(add) : flat.push(c));
63
- checks.forEach(add);
64
- return (u) => {
65
- const f = base(u);
66
- if (f)
67
- return f;
68
- for (const c of flat) {
69
- const r = c.run(u, n, {});
70
- if (r !== undefined && r !== true)
71
- return fail(String(c.annotations?.expected ?? "a valid value"), u);
72
- }
73
- return undefined;
74
- };
75
- };
76
- const isLite = (n) => n["~lite"] === true;
77
- const isOptional = (n) => n.context?.isOptional === true;
78
- const build = (n) => {
79
- // A real node that decodes from another form is checked in that form (the
80
- // body as read); lite encodings are type-side only.
81
- const encoding = n.encoding;
82
- if (encoding?.length && !isLite(n))
83
- return compile(encoding[encoding.length - 1].to);
84
- switch (n._tag) {
85
- case "String":
86
- case "TemplateLiteral":
87
- return typeOf("string");
88
- case "Number":
89
- return typeOf("number");
90
- case "Boolean":
91
- return typeOf("boolean");
92
- case "BigInt":
93
- return typeOf("bigint");
94
- case "Symbol":
95
- return typeOf("symbol");
96
- case "Null":
97
- return (u) => (u === null ? undefined : fail("null", u));
98
- case "Undefined":
99
- return (u) => (u === undefined ? undefined : fail("undefined", u));
100
- case "Never":
101
- return (u) => fail("never", u);
102
- case "Literal":
103
- case "UniqueSymbol": {
104
- const lit = n._tag === "Literal" ? n.literal : n.symbol;
105
- return (u) => (u === lit ? undefined : fail(show(lit), u));
106
- }
107
- case "Enum": {
108
- const values = n.enums.map((e) => e[1]);
109
- return (u) => (values.includes(u) ? undefined : fail("an enum value", u));
110
- }
111
- case "ObjectKeyword":
112
- return (u) => (typeof u === "object" && u !== null) || typeof u === "function"
113
- ? undefined
114
- : fail("object | function", u);
115
- case "Union":
116
- return union(n);
117
- case "Arrays":
118
- return arrays(n);
119
- case "Objects":
120
- return objects(n);
121
- case "Suspend": {
122
- let inner;
123
- return (u) => (inner ??= compile(n.thunk()))(u);
124
- }
125
- case "Declaration": {
126
- if (isLite(n)) {
127
- const check = n.check;
128
- const name = String(n.annotations?.identifier ?? "a valid value");
129
- return check ? (u) => (check(u) ? undefined : fail(name, u)) : ok;
130
- }
131
- return declaration(n);
132
- }
133
- default:
134
- // Unknown, Any, Void (Effect's `void` accepts any value) and anything
135
- // without structure.
136
- return ok;
137
- }
138
- };
139
-
140
- const declaration = (n) => {
141
- const run = n.run;
142
- if (!run || n.typeParameters?.length)
143
- return ok;
144
- let parse;
145
- return (u) => {
146
- const exit = (parse ??= run([]))(u, n, {});
147
- return exit?._tag === "Failure"
148
- ? fail(String(n.annotations?.identifier ?? n.annotations?.expected ?? "a valid value"), u)
149
- : undefined;
150
- };
151
- };
152
- const union = (n) => {
153
- const members = n.types.map(compile);
154
- return (u) => {
155
- let first;
156
- for (let i = 0; i < members.length; i++) {
157
- const f = members[i](u);
158
- if (f === undefined)
159
- return undefined;
160
- first ??= f;
161
- }
162
- return members.length === 1 ? first : fail("a union member", u);
163
- };
164
- };
165
- const arrays = (n) => {
166
- const elements = (n.elements ?? []).map((e) => [compile(e), isOptional(e)]);
167
- const rest = (n.rest ?? []).map(compile);
168
- const head = rest[0];
169
- const tail = rest.slice(1);
170
- return (u) => {
171
- if (!Array.isArray(u))
172
- return fail("array", u);
173
- const len = u.length;
174
- for (let i = 0; i < elements.length; i++) {
175
- const [check, optional] = elements[i];
176
- if (i >= len) {
177
- if (optional)
178
- continue;
179
- return at(fail("an element", MISSING), i);
180
- }
181
- const f = check(u[i]);
182
- if (f)
183
- return at(f, i);
184
- }
185
- if (head === undefined) {
186
- return len > elements.length
187
- ? at(fail("never", u[elements.length]), elements.length)
188
- : undefined;
189
- }
190
- const end = len - tail.length;
191
- if (end < elements.length)
192
- return at(fail("an element", MISSING), len);
193
- for (let i = elements.length; i < end; i++) {
194
- const f = head(u[i]);
195
- if (f)
196
- return at(f, i);
197
- }
198
- for (let j = 0; j < tail.length; j++) {
199
- const f = tail[j](u[end + j]);
200
- if (f)
201
- return at(f, end + j);
202
- }
203
- return undefined;
204
- };
205
- };
206
- const at = (f, key) => {
207
- f.path.push(key);
208
- return f;
209
- };
210
- const objects = (n) => {
211
- const props = (n.propertySignatures ?? []).map((p) => [p.name, compile(p.type), isOptional(p.type)]);
212
- const index = (n.indexSignatures ?? []).map((s) => [compile(s.parameter), compile(s.type)]);
213
- const known = new Set(props.map((p) => p[0]));
214
- // Effect's empty struct is TypeScript's `{}`: any value but null and undefined.
215
- // Exact mode leaves it open too: generated code emits `{}` for outputs
216
- // it does not model.
217
- if (props.length === 0 && index.length === 0) {
218
- return (u) => (u === null || u === undefined ? fail("{}", u) : undefined);
219
- }
220
- return (u) => {
221
- if (typeof u !== "object" || u === null || Array.isArray(u))
222
- return fail("object", u);
223
- const o = u;
224
- for (let i = 0; i < props.length; i++) {
225
- const [name, check, optional] = props[i];
226
- if (!(name === "__proto__" ? Object.hasOwn(o, name) : name in o)) {
227
- if (optional)
228
- continue;
229
- return at(fail("a value", MISSING), name);
230
- }
231
- const f = check(o[name]);
232
- if (f)
233
- return at(f, name);
234
- }
235
- if (index.length || exact) {
236
- for (const key of Object.keys(o)) {
237
- if (known.has(key))
238
- continue;
239
- let covered = false;
240
- for (const [param, check] of index) {
241
- if (param(key) !== undefined)
242
- continue;
243
- covered = true;
244
- const f = check(o[key]);
245
- if (f)
246
- return at(f, key);
247
- }
248
- if (exact && !covered) {
249
- return at(fail("no value (the schema does not model this key)", o[key]), key);
250
- }
251
- }
252
- }
253
- return undefined;
254
- };
255
- };
256
- return compile;
257
- };
258
- let compileNode;
259
- let compileExact;
260
-
261
-
262
-
263
-
264
-
265
- export const decoderFor = (ast, exact = false) => {
266
- const decoders = exact ? exactDecoders : openDecoders;
267
- let decode = decoders.get(ast);
268
- if (decode === undefined) {
269
- const check = exact
270
- ? (compileExact ??= makeCompile(true))(ast)
271
- : (compileNode ??= makeCompile(false))(ast);
272
- decode = (input) => {
273
- const f = check(input);
274
- return f === undefined
275
- ? undefined
276
- : new SchemaMismatch(f.path.reverse(), f.expected, f.actual);
277
- };
278
- decoders.set(ast, decode);
279
- }
280
- return decode;
281
- };
282
- const openDecoders = /*@__PURE__*/ new WeakMap();
283
- const exactDecoders = /*@__PURE__*/ new WeakMap();
284
- //# sourceMappingURL=response-validation-strict.js.map
1
+ export { response_validation_strict$SchemaMismatch as SchemaMismatch, response_validation_strict$decoderFor as decoderFor, response_validation_strict$withholdActual as withholdActual } from "./_bundle/base.js";
@@ -7,9 +7,10 @@
7
7
  * lenient (default): the response is returned as the protocol read it.
8
8
  * A body that does not match the declared output type
9
9
  * (a missing member, a wrong primitive, a non-JSON
10
- * body) still succeeds, except that core's REST
11
- * protocol, Stripe and Fly.io fail a non-JSON body for
12
- * an output with sensitive members in every mode.
10
+ * body) still succeeds, except that a non-JSON body for
11
+ * an output with sensitive members fails in every mode
12
+ * (REST-style protocols through core's `checkSuccess`
13
+ * in `protocol-rest`, plus ZeroSSL and AWS).
13
14
  * additionalProperties: the response is checked against the output
14
15
  * schema, and a mismatch fails the call with the SDK's
15
16
  * `<Sdk>ParseError` (AWS: `ParseError`). Keys the
@@ -1 +1 @@
1
- {"version":3,"file":"response-validation.d.ts","sourceRoot":"","sources":["../src/response-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,KAAK,MAAM,EAAc,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE/F,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjF,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,sBAAsB,GAAG,QAAQ,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB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 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
- import * as Context from "effect/Context";
40
- import * as Effect from "effect/Effect";
41
- import * as Layer from "effect/Layer";
42
- import { decoderFor } from "./response-validation-strict.js";
43
- export { SchemaMismatch, withholdActual } from "./response-validation-strict.js";
44
-
45
-
46
-
47
-
48
-
49
- export const ResponseValidation = /*@__PURE__*/ Context.Reference("@distilled.cloud/core/ResponseValidation", { defaultValue: () => "lenient" });
50
-
51
-
52
-
53
-
54
-
55
- export const StrictDecoder = /*@__PURE__*/ Context.Reference("@distilled.cloud/core/ResponseValidation/StrictDecoder", { defaultValue: () => undefined });
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
- const layerOfContext = (context) => {
64
- const layer = Layer.succeedContext(context);
65
- const both = Object.create(context);
66
- const layerProto = Object.getPrototypeOf(layer);
67
- for (const key of Reflect.ownKeys(layerProto)) {
68
- if (key !== "pipe")
69
- both[key] = layerProto[key];
70
- }
71
- both.build = layer.build;
72
- return both;
73
- };
74
-
75
-
76
-
77
-
78
- export const strict = /*@__PURE__*/ layerOfContext(
79
- /*@__PURE__*/ Context.add(
80
- /*@__PURE__*/ Context.make(ResponseValidation, "strict"), StrictDecoder, decoderFor));
81
-
82
-
83
-
84
-
85
- export const additionalProperties = /*@__PURE__*/ layerOfContext(
86
- /*@__PURE__*/ Context.add(
87
- /*@__PURE__*/ Context.make(ResponseValidation, "additionalProperties"), StrictDecoder, decoderFor));
88
-
89
- export const lenient = /*@__PURE__*/ layerOfContext(
90
- /*@__PURE__*/ Context.make(ResponseValidation, "lenient"));
91
-
92
- export const isValidating = /*@__PURE__*/ Effect.map(ResponseValidation, (mode) => mode !== "lenient");
93
-
94
-
95
-
96
-
97
-
98
- export const failUnlessLenient = (error, asRead) => Effect.flatMap(ResponseValidation, (mode) => mode === "lenient" ? Effect.succeed(asRead) : Effect.fail(error));
99
-
100
-
101
-
102
-
103
-
104
- export const checkResponse = (context, outputAst, value) => {
105
- const mode = Context.get(context, ResponseValidation);
106
- if (mode === "lenient")
107
- return undefined;
108
- const decoderOf = Context.get(context, StrictDecoder);
109
- if (!decoderOf) {
110
- throw new Error(`${mode} response validation needs the ResponseValidation.${mode} layer`);
111
- }
112
- return decoderOf(outputAst, mode === "strict")(value);
113
- };
114
- export const validateResponse = (outputAst, value, onError) => Effect.withFiber((fiber) => {
115
- const error = checkResponse(fiber.context, outputAst, value);
116
- return error === undefined ? Effect.succeed(value) : Effect.fail(onError(error));
117
- });
118
- //# sourceMappingURL=response-validation.js.map
1
+ export { response_validation$ResponseValidation as ResponseValidation, response_validation$SchemaMismatch as SchemaMismatch, response_validation$StrictDecoder as StrictDecoder, response_validation$additionalProperties as additionalProperties, response_validation$checkResponse as checkResponse, response_validation$failUnlessLenient as failUnlessLenient, response_validation$isValidating as isValidating, response_validation$lenient as lenient, response_validation$strict as strict, response_validation$validateResponse as validateResponse, response_validation$withholdActual as withholdActual } from "./_bundle/base.js";
@@ -1,112 +1 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
- import * as Duration from "effect/Duration";
18
- import { RETRYABLE_HTTP_STATUSES } from "./errors.js";
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
- export const parseRetryAfter = (headers) => {
28
- const raw = headers?.["retry-after"];
29
- if (!raw)
30
- return undefined;
31
- const trimmed = raw.trim();
32
- if (trimmed.length === 0)
33
- return undefined;
34
- // delay-seconds: 1*DIGIT (non-negative decimal integer per RFC).
35
- if (/^\d+$/.test(trimmed)) {
36
- const seconds = Number(trimmed);
37
- if (Number.isFinite(seconds) && seconds >= 0) {
38
- return Duration.seconds(seconds);
39
- }
40
- }
41
- // Reject anything that *looks* numeric but isn't a valid delay-seconds.
42
- // Without this, `Date.parse("-5")` happens to return 0 on some engines and
43
- // would silently yield a zero-duration instead of the expected undefined.
44
- if (/^[-+]?\d+(?:\.\d+)?$/.test(trimmed))
45
- return undefined;
46
- // HTTP-date: try Date.parse, which handles RFC 1123 / RFC 850 / asctime.
47
- const ts = Date.parse(trimmed);
48
- if (!Number.isNaN(ts)) {
49
- const ms = Math.max(0, ts - Date.now());
50
- return Duration.millis(ms);
51
- }
52
- return undefined;
53
- };
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
- export const parseRatelimit = (headers) => {
67
- const raw = headers?.["ratelimit"];
68
- if (!raw)
69
- return undefined;
70
- let remaining;
71
- let reset;
72
- // Tokenize on commas and semicolons; tolerate `key=value` and `key =value`.
73
- for (const piece of raw.split(/[,;]/)) {
74
- const eq = piece.indexOf("=");
75
- if (eq < 0)
76
- continue;
77
- const key = piece.slice(0, eq).trim().toLowerCase();
78
- const value = piece.slice(eq + 1).trim();
79
- const num = Number(value);
80
- if (!Number.isFinite(num))
81
- continue;
82
- if (key === "r" || key === "remaining")
83
- remaining = num;
84
- else if (key === "t" || key === "reset")
85
- reset = num;
86
- }
87
- if (remaining !== 0)
88
- return undefined;
89
- if (reset === undefined || reset < 0)
90
- return undefined;
91
- return Duration.seconds(reset);
92
- };
93
-
94
-
95
-
96
-
97
- export const parseServerRetryHint = (headers) => parseRetryAfter(headers) ?? parseRatelimit(headers);
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
- export const parseRetryAfterForStatus = (status, headers) => {
108
- if (!RETRYABLE_HTTP_STATUSES.has(status))
109
- return undefined;
110
- return parseServerRetryHint(headers);
111
- };
112
- //# sourceMappingURL=retry-after.js.map
1
+ export { retry_after$parseRatelimit as parseRatelimit, retry_after$parseRetryAfter as parseRetryAfter, retry_after$parseRetryAfterForStatus as parseRetryAfterForStatus, retry_after$parseServerRetryHint as parseServerRetryHint } from "./_bundle/rest.js";