@distilled.cloud/core 1.0.0-rc.12 → 1.0.0-rc.14

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 (276) hide show
  1. package/lib/api.d.ts +4 -4
  2. package/lib/api.d.ts.map +1 -1
  3. package/lib/api.js +3 -5
  4. package/lib/api.js.map +1 -1
  5. package/lib/category.d.ts.map +1 -1
  6. package/lib/category.js +3 -5
  7. package/lib/category.js.map +1 -1
  8. package/lib/codegen/boolean-string-enums.d.ts +8 -8
  9. package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
  10. package/lib/codegen/boolean-string-enums.js +83 -30
  11. package/lib/codegen/boolean-string-enums.js.map +1 -1
  12. package/lib/codegen/boolean-string-enums.test.js +130 -2
  13. package/lib/codegen/boolean-string-enums.test.js.map +1 -1
  14. package/lib/codegen/cli.d.ts +5 -4
  15. package/lib/codegen/cli.d.ts.map +1 -1
  16. package/lib/codegen/cli.js +12 -9
  17. package/lib/codegen/cli.js.map +1 -1
  18. package/lib/codegen/defer-naming.test.d.ts +2 -0
  19. package/lib/codegen/defer-naming.test.d.ts.map +1 -0
  20. package/lib/codegen/defer-naming.test.js +105 -0
  21. package/lib/codegen/defer-naming.test.js.map +1 -0
  22. package/lib/codegen/emit.d.ts.map +1 -1
  23. package/lib/codegen/emit.js +1 -3
  24. package/lib/codegen/emit.js.map +1 -1
  25. package/lib/codegen/format.d.ts +0 -12
  26. package/lib/codegen/format.d.ts.map +1 -1
  27. package/lib/codegen/format.js +10 -6
  28. package/lib/codegen/format.js.map +1 -1
  29. package/lib/codegen/generated-at.d.ts +29 -0
  30. package/lib/codegen/generated-at.d.ts.map +1 -0
  31. package/lib/codegen/generated-at.js +78 -0
  32. package/lib/codegen/generated-at.js.map +1 -0
  33. package/lib/codegen/generated-at.test.d.ts +2 -0
  34. package/lib/codegen/generated-at.test.d.ts.map +1 -0
  35. package/lib/codegen/generated-at.test.js +81 -0
  36. package/lib/codegen/generated-at.test.js.map +1 -0
  37. package/lib/codegen/generator.d.ts +24 -5
  38. package/lib/codegen/generator.d.ts.map +1 -1
  39. package/lib/codegen/generator.js +69 -80
  40. package/lib/codegen/generator.js.map +1 -1
  41. package/lib/codegen/generator.test.d.ts +2 -0
  42. package/lib/codegen/generator.test.d.ts.map +1 -0
  43. package/lib/codegen/generator.test.js +121 -0
  44. package/lib/codegen/generator.test.js.map +1 -0
  45. package/lib/codegen/graphql-client.d.ts +7 -1
  46. package/lib/codegen/graphql-client.d.ts.map +1 -1
  47. package/lib/codegen/graphql-client.js +264 -148
  48. package/lib/codegen/graphql-client.js.map +1 -1
  49. package/lib/codegen/graphql-client.test.js +98 -238
  50. package/lib/codegen/graphql-client.test.js.map +1 -1
  51. package/lib/codegen/graphql.d.ts.map +1 -1
  52. package/lib/codegen/graphql.js +7 -20
  53. package/lib/codegen/graphql.js.map +1 -1
  54. package/lib/codegen/model-diff.d.ts +10 -0
  55. package/lib/codegen/model-diff.d.ts.map +1 -0
  56. package/lib/codegen/model-diff.js +67 -0
  57. package/lib/codegen/model-diff.js.map +1 -0
  58. package/lib/codegen/naming.d.ts.map +1 -1
  59. package/lib/codegen/naming.js.map +1 -1
  60. package/lib/codegen/openapi-binary.test.d.ts +2 -0
  61. package/lib/codegen/openapi-binary.test.d.ts.map +1 -0
  62. package/lib/codegen/openapi-binary.test.js +67 -0
  63. package/lib/codegen/openapi-binary.test.js.map +1 -0
  64. package/lib/codegen/openapi-cli.d.ts +11 -11
  65. package/lib/codegen/openapi-cli.d.ts.map +1 -1
  66. package/lib/codegen/openapi-cli.js +26 -51
  67. package/lib/codegen/openapi-cli.js.map +1 -1
  68. package/lib/codegen/openapi.d.ts +16 -2
  69. package/lib/codegen/openapi.d.ts.map +1 -1
  70. package/lib/codegen/openapi.js +56 -39
  71. package/lib/codegen/openapi.js.map +1 -1
  72. package/lib/codegen/operations.d.ts.map +1 -1
  73. package/lib/codegen/operations.js.map +1 -1
  74. package/lib/codegen/pagination.d.ts.map +1 -1
  75. package/lib/codegen/pagination.js +2 -4
  76. package/lib/codegen/pagination.js.map +1 -1
  77. package/lib/codegen/patch-audit.d.ts +84 -0
  78. package/lib/codegen/patch-audit.d.ts.map +1 -0
  79. package/lib/codegen/patch-audit.js +366 -0
  80. package/lib/codegen/patch-audit.js.map +1 -0
  81. package/lib/codegen/patch-audit.test.d.ts +2 -0
  82. package/lib/codegen/patch-audit.test.d.ts.map +1 -0
  83. package/lib/codegen/patch-audit.test.js +141 -0
  84. package/lib/codegen/patch-audit.test.js.map +1 -0
  85. package/lib/codegen/patches.d.ts +75 -11
  86. package/lib/codegen/patches.d.ts.map +1 -1
  87. package/lib/codegen/patches.js +301 -65
  88. package/lib/codegen/patches.js.map +1 -1
  89. package/lib/codegen/patches.test.js +55 -5
  90. package/lib/codegen/patches.test.js.map +1 -1
  91. package/lib/codegen/prelude.js +1 -1
  92. package/lib/codegen/prelude.js.map +1 -1
  93. package/lib/codegen/proto.d.ts.map +1 -1
  94. package/lib/codegen/proto.js +2 -4
  95. package/lib/codegen/proto.js.map +1 -1
  96. package/lib/codegen/protocol-imports.test.d.ts +2 -0
  97. package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
  98. package/lib/codegen/protocol-imports.test.js +36 -0
  99. package/lib/codegen/protocol-imports.test.js.map +1 -0
  100. package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
  101. package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
  102. package/lib/codegen/rewrite-operation-ids.js +97 -59
  103. package/lib/codegen/rewrite-operation-ids.js.map +1 -1
  104. package/lib/codegen/rewrite-operation-ids.test.js +19 -101
  105. package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
  106. package/lib/codegen/spec-path.d.ts +1 -1
  107. package/lib/codegen/spec-path.d.ts.map +1 -1
  108. package/lib/codegen/spec-path.js +1 -1
  109. package/lib/codegen/spec-path.js.map +1 -1
  110. package/lib/codegen/untagged-unions.test.d.ts +2 -0
  111. package/lib/codegen/untagged-unions.test.d.ts.map +1 -0
  112. package/lib/codegen/untagged-unions.test.js +80 -0
  113. package/lib/codegen/untagged-unions.test.js.map +1 -0
  114. package/lib/error-category.d.ts.map +1 -1
  115. package/lib/error-category.js.map +1 -1
  116. package/lib/errors.d.ts +2 -1
  117. package/lib/errors.d.ts.map +1 -1
  118. package/lib/errors.js +9 -4
  119. package/lib/errors.js.map +1 -1
  120. package/lib/fixtures/xml/upstream-validator.json +397 -0
  121. package/lib/graphql.d.ts +292 -205
  122. package/lib/graphql.d.ts.map +1 -1
  123. package/lib/graphql.js +945 -636
  124. package/lib/graphql.js.map +1 -1
  125. package/lib/graphql.test.js +135 -764
  126. package/lib/graphql.test.js.map +1 -1
  127. package/lib/graphql.types.d.ts +10 -0
  128. package/lib/graphql.types.d.ts.map +1 -1
  129. package/lib/graphql.types.js +4 -44
  130. package/lib/graphql.types.js.map +1 -1
  131. package/lib/index.d.ts +27 -0
  132. package/lib/index.d.ts.map +1 -0
  133. package/lib/index.js +27 -0
  134. package/lib/index.js.map +1 -0
  135. package/lib/json-patch.d.ts +13 -6
  136. package/lib/json-patch.d.ts.map +1 -1
  137. package/lib/json-patch.js +34 -19
  138. package/lib/json-patch.js.map +1 -1
  139. package/lib/json-patch.test.d.ts +2 -0
  140. package/lib/json-patch.test.d.ts.map +1 -0
  141. package/lib/json-patch.test.js +65 -0
  142. package/lib/json-patch.test.js.map +1 -0
  143. package/lib/pagination.d.ts +2 -1
  144. package/lib/pagination.d.ts.map +1 -1
  145. package/lib/pagination.js +28 -30
  146. package/lib/pagination.js.map +1 -1
  147. package/lib/pagination.test.d.ts +2 -0
  148. package/lib/pagination.test.d.ts.map +1 -0
  149. package/lib/pagination.test.js +131 -0
  150. package/lib/pagination.test.js.map +1 -0
  151. package/lib/protocol-http.d.ts +30 -16
  152. package/lib/protocol-http.d.ts.map +1 -1
  153. package/lib/protocol-http.js +133 -84
  154. package/lib/protocol-http.js.map +1 -1
  155. package/lib/protocol-http.test.js +141 -1
  156. package/lib/protocol-http.test.js.map +1 -1
  157. package/lib/protocol-rest.d.ts +18 -1
  158. package/lib/protocol-rest.d.ts.map +1 -1
  159. package/lib/protocol-rest.js +32 -21
  160. package/lib/protocol-rest.js.map +1 -1
  161. package/lib/protocol-rest.test.d.ts +2 -0
  162. package/lib/protocol-rest.test.d.ts.map +1 -0
  163. package/lib/protocol-rest.test.js +498 -0
  164. package/lib/protocol-rest.test.js.map +1 -0
  165. package/lib/query.d.ts +29 -0
  166. package/lib/query.d.ts.map +1 -0
  167. package/lib/query.js +27 -0
  168. package/lib/query.js.map +1 -0
  169. package/lib/response-validation.d.ts +67 -0
  170. package/lib/response-validation.d.ts.map +1 -0
  171. package/lib/response-validation.js +76 -0
  172. package/lib/response-validation.js.map +1 -0
  173. package/lib/response-validation.test.d.ts +2 -0
  174. package/lib/response-validation.test.d.ts.map +1 -0
  175. package/lib/response-validation.test.js +72 -0
  176. package/lib/response-validation.test.js.map +1 -0
  177. package/lib/retry-after.d.ts.map +1 -1
  178. package/lib/retry-after.js +1 -1
  179. package/lib/retry-after.js.map +1 -1
  180. package/lib/retry-after.test.d.ts +2 -0
  181. package/lib/retry-after.test.d.ts.map +1 -0
  182. package/lib/retry-after.test.js +204 -0
  183. package/lib/retry-after.test.js.map +1 -0
  184. package/lib/retry.d.ts.map +1 -1
  185. package/lib/retry.js +1 -2
  186. package/lib/retry.js.map +1 -1
  187. package/lib/retry.test.d.ts +2 -0
  188. package/lib/retry.test.d.ts.map +1 -0
  189. package/lib/retry.test.js +407 -0
  190. package/lib/retry.test.js.map +1 -0
  191. package/lib/sdks.test.d.ts +2 -0
  192. package/lib/sdks.test.d.ts.map +1 -0
  193. package/lib/sdks.test.js +76 -0
  194. package/lib/sdks.test.js.map +1 -0
  195. package/lib/testing.d.ts +39 -0
  196. package/lib/testing.d.ts.map +1 -0
  197. package/lib/testing.js +41 -0
  198. package/lib/testing.js.map +1 -0
  199. package/lib/trait.d.ts +29 -9
  200. package/lib/trait.d.ts.map +1 -1
  201. package/lib/trait.js +8 -0
  202. package/lib/trait.js.map +1 -1
  203. package/lib/xml.d.ts +44 -0
  204. package/lib/xml.d.ts.map +1 -0
  205. package/lib/xml.js +311 -0
  206. package/lib/xml.js.map +1 -0
  207. package/lib/xml.test.d.ts +2 -0
  208. package/lib/xml.test.d.ts.map +1 -0
  209. package/lib/xml.test.js +210 -0
  210. package/lib/xml.test.js.map +1 -0
  211. package/package.json +8 -11
  212. package/src/api.ts +38 -55
  213. package/src/category.ts +21 -50
  214. package/src/codegen/boolean-string-enums.test.ts +148 -17
  215. package/src/codegen/boolean-string-enums.ts +81 -32
  216. package/src/codegen/cli.ts +29 -47
  217. package/src/codegen/defer-naming.test.ts +113 -0
  218. package/src/codegen/emit.ts +2 -5
  219. package/src/codegen/format.ts +12 -10
  220. package/src/codegen/generated-at.test.ts +89 -0
  221. package/src/codegen/generated-at.ts +88 -0
  222. package/src/codegen/generator.test.ts +137 -0
  223. package/src/codegen/generator.ts +132 -193
  224. package/src/codegen/graphql-client.test.ts +100 -297
  225. package/src/codegen/graphql-client.ts +302 -210
  226. package/src/codegen/graphql.ts +22 -94
  227. package/src/codegen/model-diff.ts +67 -0
  228. package/src/codegen/naming.ts +1 -2
  229. package/src/codegen/openapi-binary.test.ts +91 -0
  230. package/src/codegen/openapi-cli.ts +38 -79
  231. package/src/codegen/openapi.ts +98 -133
  232. package/src/codegen/operations.ts +2 -5
  233. package/src/codegen/pagination.ts +4 -11
  234. package/src/codegen/patch-audit.test.ts +160 -0
  235. package/src/codegen/patch-audit.ts +480 -0
  236. package/src/codegen/patches.test.ts +73 -15
  237. package/src/codegen/patches.ts +389 -99
  238. package/src/codegen/prelude.ts +1 -1
  239. package/src/codegen/proto.ts +18 -54
  240. package/src/codegen/protocol-imports.test.ts +39 -0
  241. package/src/codegen/rewrite-operation-ids.test.ts +23 -114
  242. package/src/codegen/rewrite-operation-ids.ts +111 -98
  243. package/src/codegen/spec-path.ts +3 -6
  244. package/src/codegen/untagged-unions.test.ts +85 -0
  245. package/src/error-category.ts +5 -17
  246. package/src/errors.ts +18 -30
  247. package/src/fixtures/xml/upstream-validator.json +397 -0
  248. package/src/graphql.test.ts +173 -949
  249. package/src/graphql.ts +1468 -1186
  250. package/src/graphql.types.ts +78 -164
  251. package/src/index.ts +26 -0
  252. package/src/json-patch.test.ts +77 -0
  253. package/src/json-patch.ts +54 -60
  254. package/src/pagination.test.ts +169 -0
  255. package/src/pagination.ts +46 -103
  256. package/src/protocol-http.test.ts +178 -9
  257. package/src/protocol-http.ts +174 -163
  258. package/src/protocol-rest.test.ts +703 -0
  259. package/src/protocol-rest.ts +76 -65
  260. package/src/query.ts +39 -0
  261. package/src/response-validation.test.ts +89 -0
  262. package/src/response-validation.ts +107 -0
  263. package/src/retry-after.test.ts +267 -0
  264. package/src/retry-after.ts +4 -10
  265. package/src/retry.test.ts +566 -0
  266. package/src/retry.ts +6 -21
  267. package/src/sdks.test.ts +87 -0
  268. package/src/testing.ts +72 -0
  269. package/src/trait.ts +48 -63
  270. package/src/xml.test.ts +251 -0
  271. package/src/xml.ts +323 -0
  272. package/lib/graphql.fixture.d.ts +0 -249
  273. package/lib/graphql.fixture.d.ts.map +0 -1
  274. package/lib/graphql.fixture.js +0 -240
  275. package/lib/graphql.fixture.js.map +0 -1
  276. package/src/graphql.fixture.ts +0 -371
@@ -0,0 +1,210 @@
1
+ import assert from "node:assert/strict";
2
+ import * as Effect from "effect/Effect";
3
+ import { describe, it } from "vitest";
4
+ import fixtures from "./fixtures/xml/upstream-validator.json" with { type: "json" };
5
+ import { escapeXml, parseXml, parseXmlSync, XmlParseError } from "./xml.js";
6
+ function parse(xml) {
7
+ // Compare the wire values independently of the null prototypes used for safety.
8
+ return JSON.parse(JSON.stringify(parseXmlSync(xml)));
9
+ }
10
+ describe("upstream fast-xml-parser validation corpus", () => {
11
+ for (const [index, fixture] of fixtures.entries()) {
12
+ it(`${index}: ${fixture.name}`, () => {
13
+ if (fixture.parserValid ?? fixture.valid) {
14
+ assert.doesNotThrow(() => parseXmlSync(fixture.xml));
15
+ }
16
+ else {
17
+ assert.throws(() => parseXmlSync(fixture.xml), XmlParseError);
18
+ }
19
+ });
20
+ }
21
+ });
22
+ describe("XML object format", () => {
23
+ it("keeps primitives as strings and groups repeated children", () => {
24
+ assert.deepEqual(parse("<R><x>001</x><x>false</x><x>1e3</x><empty/><empty></empty></R>"), {
25
+ R: { x: ["001", "false", "1e3"], empty: ["", ""] },
26
+ });
27
+ });
28
+ it("preserves namespace names, attributes, and text with attributes", () => {
29
+ assert.deepEqual(parse('<ns:R xmlns:ns="urn:r"><ns:x ns:id="01">value</ns:x><empty a=""/></ns:R>'), {
30
+ "ns:R": {
31
+ "@_xmlns:ns": "urn:r",
32
+ "ns:x": { "@_ns:id": "01", "#text": "value" },
33
+ empty: { "@_a": "" },
34
+ },
35
+ });
36
+ });
37
+ it("preserves string whitespace, including attribute and CDATA values", () => {
38
+ assert.deepEqual(parse('<R><Key> key </Key><blank> \t </blank><x a=" b "> text </x><c><![CDATA[ c ]]></c></R>'), {
39
+ R: {
40
+ Key: " key ",
41
+ blank: " \t ",
42
+ x: { "@_a": " b ", "#text": " text " },
43
+ c: " c ",
44
+ },
45
+ });
46
+ });
47
+ it("discards layout-only container text but preserves mixed content", () => {
48
+ assert.deepEqual(parse("<R>\n <x/>\n <y/>\n</R>"), {
49
+ R: { x: "", y: "" },
50
+ });
51
+ assert.deepEqual(parse("<R>Hello <b>world</b> !</R>"), {
52
+ R: { b: "world", "#text": "Hello !" },
53
+ });
54
+ assert.deepEqual(parse("<R><![CDATA[ ]]><b/></R>"), {
55
+ R: { b: "", "#text": " " },
56
+ });
57
+ });
58
+ it("decodes predefined and numeric entities exactly once", () => {
59
+ assert.deepEqual(parse('<R a="&quot;&apos;&#9;">&amp;&lt;&gt;&#65;&#x1F600;&amp;lt;</R>'), {
60
+ R: { "@_a": "\"'\t", "#text": "&<>A😀&lt;" },
61
+ });
62
+ });
63
+ it("normalizes literal line endings and attribute whitespace, not character references", () => {
64
+ assert.deepEqual(parse('<R a="x\r\ny\tz\r&#13;&#10;&#9;">a\r\nb\rc&#13;</R>'), {
65
+ R: { "@_a": "x y z \r\n\t", "#text": "a\nb\nc\r" },
66
+ });
67
+ });
68
+ it("joins CDATA and text without decoding CDATA entities", () => {
69
+ assert.deepEqual(parse("<R>a<![CDATA[<b>&amp;]]><![CDATA[c]]>d&amp;</R>"), {
70
+ R: "a<b>&amp;cd&",
71
+ });
72
+ assert.deepEqual(parse("<R><![CDATA[]]></R>"), { R: "" });
73
+ });
74
+ it("ignores declarations, comments and processing instructions", () => {
75
+ assert.deepEqual(parse('\uFEFF<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!--before--><?before a?><R>a<!--ignored--><?in x?>b</R><?after?><!--after-->'), { R: "ab" });
76
+ });
77
+ it("supports XML Unicode names", () => {
78
+ assert.deepEqual(parse('<根 é="oui"><𐀀>😀</𐀀><á/></根>'), {
79
+ 根: { "@_é": "oui", 𐀀: "😀", á: "" },
80
+ });
81
+ });
82
+ it("accepts empty HTTP bodies", () => {
83
+ for (const xml of ["", " \r\n\t", "\uFEFF"])
84
+ assert.deepEqual(parse(xml), {});
85
+ });
86
+ it("stores prototype-related names as own data properties", () => {
87
+ const result = parseXmlSync("<__proto__><constructor>one</constructor><constructor>two</constructor><__proto__>safe</__proto__><toString/></__proto__>");
88
+ const root = result.__proto__;
89
+ assert.equal(Object.getPrototypeOf(result), null);
90
+ assert.equal(Object.getPrototypeOf(root), null);
91
+ assert.deepEqual(JSON.parse(JSON.stringify(root)), JSON.parse('{"constructor":["one","two"],"__proto__":"safe","toString":""}'));
92
+ assert.equal(Object.hasOwn(Object.prototype, "safe"), false);
93
+ });
94
+ it("round trips escaped strings", () => {
95
+ for (const text of [' <tag a="x">&\'😀 ', "", "false", "001", "&#13;", "\t\n"]) {
96
+ assert.deepEqual(parse(`<R>${escapeXml(text)}</R>`), { R: text });
97
+ }
98
+ });
99
+ it("handles large lists without recursion", () => {
100
+ const result = parse(`<R>${'<item a="1">value</item>'.repeat(10_000)}</R>`);
101
+ assert.equal(result.R.item.length, 10_000);
102
+ assert.deepEqual(result.R.item[9_999], { "@_a": "1", "#text": "value" });
103
+ });
104
+ });
105
+ describe("malformed and unsupported XML", () => {
106
+ const invalid = [
107
+ '<R a="1"a="2"/>',
108
+ '<R a="<"/>',
109
+ '<R a="&bad;"/>',
110
+ "<R a=1/>",
111
+ '<R a="1" a="2"/>',
112
+ "<R/ >",
113
+ "< R/>",
114
+ "<R></ R>",
115
+ "<R></R x>",
116
+ "<R>]]></R>",
117
+ "<R>&</R>",
118
+ "<R>&amp</R>",
119
+ "<R>&nope;</R>",
120
+ "<R>&#0;</R>",
121
+ "<R>&#xD800;</R>",
122
+ "<R>&#x110000;</R>",
123
+ "<R>&#xFFFE;</R>",
124
+ "<R>&#-1;</R>",
125
+ "<R>&#X41;</R>",
126
+ "<R>&#x;</R>",
127
+ "<R>&#;</R>",
128
+ "<R>\u0000</R>",
129
+ "<R>\u000B</R>",
130
+ "<R>\uD800</R>",
131
+ "<R>\uDC00</R>",
132
+ "<R>\uFFFE</R>",
133
+ "<R>\uFFFF</R>",
134
+ "<R><!--a--b--></R>",
135
+ "<R><!--a---></R>",
136
+ "<R><!--",
137
+ "<R><![CDATA[",
138
+ "<![CDATA[x]]><R/>",
139
+ "<R/><![CDATA[x]]>",
140
+ "<R><?pi",
141
+ "<R><?1bad?></R>",
142
+ "<R><?pi!?></R>",
143
+ '<?XML version="1.0"?><R/>',
144
+ "<?xml?><R/>",
145
+ '<?xml version="1.1"?><R/>',
146
+ '<?xml encoding="UTF-8"?><R/>',
147
+ '<?xml version="1.0" junk="x"?><R/>',
148
+ '<R><?xml version="1.0"?></R>',
149
+ '<!--x--><?xml version="1.0"?><R/>',
150
+ '<?xml version="1.0"?>',
151
+ "<!--only-->",
152
+ "<!DOCTYPE R><R/>",
153
+ '<!DOCTYPE R SYSTEM "file:///etc/passwd"><R/>',
154
+ '<!DOCTYPE R [<!ENTITY a "&a;">]><R>&a;</R>',
155
+ "<R/><R/>",
156
+ "before<R/>",
157
+ "<R/>after",
158
+ "<R><x></R>",
159
+ "<R>",
160
+ "<",
161
+ '<R a="',
162
+ "<R a",
163
+ "<R a=",
164
+ "<R ",
165
+ "</R>",
166
+ "<1bad/>",
167
+ '<R\u00A0a="x"/>',
168
+ ];
169
+ for (const xml of invalid) {
170
+ it(`rejects ${JSON.stringify(xml)}`, () => {
171
+ assert.throws(() => parseXmlSync(xml), (error) => {
172
+ assert.ok(error instanceof XmlParseError);
173
+ assert.ok(error.offset >= 0 && error.offset <= xml.length);
174
+ return true;
175
+ });
176
+ });
177
+ }
178
+ it("reports original input offsets and CRLF-aware line numbers", () => {
179
+ const xml = "<R>\r\n&bad;</R>";
180
+ assert.throws(() => parseXmlSync(xml), (error) => {
181
+ assert.ok(error instanceof XmlParseError);
182
+ assert.equal(error.offset, 5);
183
+ assert.equal(error.line, 2);
184
+ assert.equal(error.column, 1);
185
+ return true;
186
+ });
187
+ });
188
+ it("enforces depth and input length limits", () => {
189
+ assert.doesNotThrow(() => parseXmlSync("<a><b/></a>", { maxDepth: 2 }));
190
+ assert.throws(() => parseXmlSync("<a><b/></a>", { maxDepth: 1 }), XmlParseError);
191
+ assert.doesNotThrow(() => parseXmlSync("<a/>", { maxLength: 4 }));
192
+ assert.throws(() => parseXmlSync("<a/>", { maxLength: 3 }), XmlParseError);
193
+ assert.throws(() => parseXmlSync("<a/>", { maxDepth: NaN }), XmlParseError);
194
+ assert.throws(() => parseXmlSync("<a/>", { maxLength: -1 }), XmlParseError);
195
+ const nested = "<a>".repeat(2_000) + "</a>".repeat(2_000);
196
+ assert.throws(() => parseXmlSync(nested), XmlParseError);
197
+ assert.doesNotThrow(() => parseXmlSync(nested, { maxDepth: 2_000 }));
198
+ });
199
+ it("exposes parser failures through Effect's typed channel", () => {
200
+ const result = Effect.runSync(Effect.flip(parseXml("<R>")));
201
+ assert.ok(result instanceof XmlParseError);
202
+ assert.match(result.message, /Unclosed element/);
203
+ });
204
+ it("can execute the same lazy Effect repeatedly", () => {
205
+ const effect = parseXml("<R>ok</R>");
206
+ assert.equal(Effect.runSync(effect).R, "ok");
207
+ assert.equal(Effect.runSync(effect).R, "ok");
208
+ });
209
+ });
210
+ //# sourceMappingURL=xml.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml.test.js","sourceRoot":"","sources":["../src/xml.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,QAAQ,MAAM,wCAAwC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE5E,SAAS,KAAK,CAAC,GAAW;IACxB,gFAAgF;IAChF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,QAAQ,CAAC,4CAA4C,EAAE,GAAG,EAAE;IAC1D,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAClD,EAAE,CAAC,GAAG,KAAK,KAAK,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE;YACnC,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBACzC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YACvD,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CA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EH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,EAAE,CAAC,MAAM,YAAY,aAAa,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAC7C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@distilled.cloud/core",
3
- "version": "1.0.0-rc.12",
3
+ "version": "1.0.0-rc.14",
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",
@@ -28,16 +28,13 @@
28
28
  }
29
29
  },
30
30
  "devDependencies": {
31
- "@effect/platform-bun": ">=4.0.0-rc.115 || >=4.0.0",
32
- "@types/bun": "1.3.14",
31
+ "@effect/platform-node": "^4.0.0",
33
32
  "@types/node": "26.2.0",
34
- "effect": ">=4.0.0-rc.115 || >=4.0.0"
33
+ "effect": "^4.0.0",
34
+ "vitest": "^4.1.8"
35
35
  },
36
36
  "peerDependencies": {
37
- "effect": ">=4.0.0-rc.115 || >=4.0.0"
38
- },
39
- "dependencies": {
40
- "graphql": "16.11.0"
37
+ "effect": "^4.0.0"
41
38
  },
42
39
  "scripts": {
43
40
  "build": "tsc -b"
package/src/api.ts CHANGED
@@ -1,20 +1,20 @@
1
1
  import * as Context from "effect/Context";
2
2
  import * as Effect from "effect/Effect";
3
+ import * as HttpClient from "effect/http/HttpClient";
4
+ import type * as HttpClientError from "effect/http/HttpClientError";
5
+ import type * as HttpClientRequest from "effect/http/HttpClientRequest";
6
+ import type * as HttpClientResponse from "effect/http/HttpClientResponse";
3
7
  import * as Layer from "effect/Layer";
4
8
  import * as Option from "effect/Option";
5
- import * as S from "effect/Schema";
6
- import type * as AST from "effect/SchemaAST";
7
9
  import { pipeArguments } from "effect/Pipeable";
8
10
  import * as Ref from "effect/Ref";
11
+ import * as S from "effect/Schema";
12
+ import type * as AST from "effect/SchemaAST";
9
13
  import * as Scope from "effect/Scope";
10
14
  import type * as Stream from "effect/Stream";
11
15
  import { SingleShotGen } from "effect/Utils";
12
16
  import * as Pagination from "./pagination.ts";
13
17
  import { makeDefault, type Policy as RetryPolicy } from "./retry.ts";
14
- import * as HttpClient from "effect/unstable/http/HttpClient";
15
- import type * as HttpClientError from "effect/unstable/http/HttpClientError";
16
- import type * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
17
- import type * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
18
18
 
19
19
  //#region Protocol
20
20
 
@@ -128,23 +128,17 @@ export type OperationMethod<I, O, E, R> = Effect.Effect<
128
128
  */
129
129
  const protocolMemoMap = Layer.makeMemoMapUnsafe();
130
130
  const protocolScope = Scope.makeUnsafe();
131
- const protocolContexts = new WeakMap<
132
- Layer.Layer<Protocol, any, any>,
133
- Context.Context<Protocol>
134
- >();
131
+ const protocolContexts = new WeakMap<Layer.Layer<Protocol, any, any>, Context.Context<Protocol>>();
135
132
 
136
133
  const protocolContext = <PE, PR>(
137
134
  layer: Layer.Layer<Protocol, PE, PR>,
138
135
  ): Effect.Effect<Context.Context<Protocol>, PE, PR> => {
139
136
  const cached = protocolContexts.get(layer);
140
137
  if (cached) return Effect.succeed(cached);
141
- return Effect.map(
142
- Layer.buildWithMemoMap(layer, protocolMemoMap, protocolScope),
143
- (ctx) => {
144
- protocolContexts.set(layer, ctx);
145
- return ctx;
146
- },
147
- );
138
+ return Effect.map(Layer.buildWithMemoMap(layer, protocolMemoMap, protocolScope), (ctx) => {
139
+ protocolContexts.set(layer, ctx);
140
+ return ctx;
141
+ });
148
142
  };
149
143
 
150
144
  export interface OperationConfig<
@@ -199,8 +193,7 @@ const applyRetry = (
199
193
  // errors, capped exponential backoff + jitter, honors server
200
194
  // retryAfter hints). Mirrors the distilled client.
201
195
  const policy = Option.isSome(opt) ? opt.value : makeDefault;
202
- const opts =
203
- typeof policy === "function" ? policy(lastError) : policy;
196
+ const opts = typeof policy === "function" ? policy(lastError) : policy;
204
197
  if (!opts.while) return yield* base;
205
198
  return yield* base.pipe(
206
199
  Effect.tapError((e) => Ref.set(lastError, e)),
@@ -251,25 +244,23 @@ export function make<
251
244
  const fn = (input: unknown) =>
252
245
  Effect.suspend(() => {
253
246
  const { cfg, inputAst, outputAst } = prepare();
254
- const call = Effect.flatMap(
255
- protocolContext(cfg.protocol),
256
- (protocolCtx) =>
257
- Effect.gen(function* () {
258
- const protocol = yield* Protocol;
259
- const client = yield* HttpClient.HttpClient;
260
- const request = yield* protocol.encode({
261
- input,
262
- inputAst,
263
- config: cfg,
264
- });
265
- const response = yield* client.execute(request);
266
- return yield* protocol.decode({
267
- response,
268
- outputAst,
269
- errors: cfg.errors ?? [],
270
- config: cfg,
271
- });
272
- }).pipe(Effect.provideContext(protocolCtx)),
247
+ const call = Effect.flatMap(protocolContext(cfg.protocol), (protocolCtx) =>
248
+ Effect.gen(function* () {
249
+ const protocol = yield* Protocol;
250
+ const client = yield* HttpClient.HttpClient;
251
+ const request = yield* protocol.encode({
252
+ input,
253
+ inputAst,
254
+ config: cfg,
255
+ });
256
+ const response = yield* client.execute(request);
257
+ return yield* protocol.decode({
258
+ response,
259
+ outputAst,
260
+ errors: cfg.errors ?? [],
261
+ config: cfg,
262
+ });
263
+ }).pipe(Effect.provideContext(protocolCtx)),
273
264
  );
274
265
  return applyRetry(call, cfg.retry);
275
266
  });
@@ -317,8 +308,7 @@ export function make<
317
308
  configurable: true,
318
309
  },
319
310
  pagination: {
320
- get: () =>
321
- (prepare().cfg as PaginatedOperationConfig<I, O, PE, PR, E>).pagination,
311
+ get: () => (prepare().cfg as PaginatedOperationConfig<I, O, PE, PR, E>).pagination,
322
312
  configurable: true,
323
313
  },
324
314
  });
@@ -371,13 +361,11 @@ export interface PaginatedCall<I, O, E, R, Item> {
371
361
  * `yield* op.items(input)`, and the requirement-free call function for
372
362
  * `const op = yield* operation; yield* op.items(input)` (distilled #145).
373
363
  */
374
- export type PaginatedOperationMethod<
375
- I,
376
- O,
377
- E,
378
- R,
379
- Item = PaginatedItem<O>,
380
- > = Effect.Effect<PaginatedCall<I, O, E, never, Item>, never, R> &
364
+ export type PaginatedOperationMethod<I, O, E, R, Item = PaginatedItem<O>> = Effect.Effect<
365
+ PaginatedCall<I, O, E, never, Item>,
366
+ never,
367
+ R
368
+ > &
381
369
  PaginatedCall<I, O, E, R, Item>;
382
370
 
383
371
  export interface PaginatedOperationConfig<
@@ -424,16 +412,11 @@ export function makePaginated<
424
412
  // call styles: the operation itself (requirements intact), and the
425
413
  // context-bound function `yield* operation` hands back — whose streams
426
414
  // inherit that captured context and so need nothing after the yield.
427
- const withStreams = (
428
- call: (input: any) => Effect.Effect<any, any, any>,
429
- ): any => {
430
- const pages = (input: Record<string, unknown>) =>
431
- paginate(call, input, pag());
415
+ const withStreams = (call: (input: any) => Effect.Effect<any, any, any>): any => {
416
+ const pages = (input: Record<string, unknown>) => paginate(call, input, pag());
432
417
  const items = (input: Record<string, unknown>) => {
433
418
  const p = pag();
434
- return p.items
435
- ? Pagination.extractItems(pages(input), p.items)
436
- : pages(input);
419
+ return p.items ? Pagination.extractItems(pages(input), p.items) : pages(input);
437
420
  };
438
421
  return Object.assign(call, { pages, items });
439
422
  };
package/src/category.ts CHANGED
@@ -19,8 +19,8 @@
19
19
  * ```
20
20
  */
21
21
  import * as Effect from "effect/Effect";
22
+ import * as HttpClientError from "effect/http/HttpClientError";
22
23
  import * as Predicate from "effect/Predicate";
23
- import * as HttpClientError from "effect/unstable/http/HttpClientError";
24
24
 
25
25
  // ============================================================================
26
26
  // Error Category Constants
@@ -103,9 +103,7 @@ export const withCategory =
103
103
  <Args extends Array<any>, Ret, C extends { new (...args: Args): Ret }>(
104
104
  C: C,
105
105
  ): C & {
106
- new (
107
- ...args: Args
108
- ): Ret & { [categoriesKey]: { [Cat in Categories[number]]: true } };
106
+ new (...args: Args): Ret & { [categoriesKey]: { [Cat in Categories[number]]: true } };
109
107
  } => {
110
108
  for (const category of categories) {
111
109
  if (!(categoriesKey in C.prototype)) {
@@ -165,9 +163,7 @@ export const withRetryableError = withCategory(RetryableError);
165
163
  export const withLockedError = withCategory(LockedError);
166
164
  export const withAbortedError = withCategory(AbortedError);
167
165
  export const withAlreadyExistsError = withCategory(AlreadyExistsError);
168
- export const withDependencyViolationError = withCategory(
169
- DependencyViolationError,
170
- );
166
+ export const withDependencyViolationError = withCategory(DependencyViolationError);
171
167
 
172
168
  // ============================================================================
173
169
  // Category Predicates
@@ -177,57 +173,41 @@ export const withDependencyViolationError = withCategory(
177
173
  * Check if an error has a specific category.
178
174
  */
179
175
  export const hasCategory = (error: unknown, category: Category): boolean => {
180
- if (
181
- Predicate.isObject(error) &&
182
- Predicate.hasProperty(categoriesKey)(error)
183
- ) {
176
+ if (Predicate.isObject(error) && Predicate.hasProperty(categoriesKey)(error)) {
184
177
  // @ts-expect-error - dynamic property access
185
178
  return category in error[categoriesKey];
186
179
  }
187
180
  return false;
188
181
  };
189
182
 
190
- export const isAuthError = (error: unknown): boolean =>
191
- hasCategory(error, AuthError);
183
+ export const isAuthError = (error: unknown): boolean => hasCategory(error, AuthError);
192
184
 
193
- export const isBadRequestError = (error: unknown): boolean =>
194
- hasCategory(error, BadRequestError);
185
+ export const isBadRequestError = (error: unknown): boolean => hasCategory(error, BadRequestError);
195
186
 
196
- export const isConflictError = (error: unknown): boolean =>
197
- hasCategory(error, ConflictError);
187
+ export const isConflictError = (error: unknown): boolean => hasCategory(error, ConflictError);
198
188
 
199
- export const isNotFoundError = (error: unknown): boolean =>
200
- hasCategory(error, NotFoundError);
189
+ export const isNotFoundError = (error: unknown): boolean => hasCategory(error, NotFoundError);
201
190
 
202
- export const isQuotaError = (error: unknown): boolean =>
203
- hasCategory(error, QuotaError);
191
+ export const isQuotaError = (error: unknown): boolean => hasCategory(error, QuotaError);
204
192
 
205
- export const isServerError = (error: unknown): boolean =>
206
- hasCategory(error, ServerError);
193
+ export const isServerError = (error: unknown): boolean => hasCategory(error, ServerError);
207
194
 
208
- export const isThrottlingError = (error: unknown): boolean =>
209
- hasCategory(error, ThrottlingError);
195
+ export const isThrottlingError = (error: unknown): boolean => hasCategory(error, ThrottlingError);
210
196
 
211
- export const isNetworkError = (error: unknown): boolean =>
212
- hasCategory(error, NetworkError);
197
+ export const isNetworkError = (error: unknown): boolean => hasCategory(error, NetworkError);
213
198
 
214
- export const isParseError = (error: unknown): boolean =>
215
- hasCategory(error, ParseError);
199
+ export const isParseError = (error: unknown): boolean => hasCategory(error, ParseError);
216
200
 
217
201
  export const isConfigurationError = (error: unknown): boolean =>
218
202
  hasCategory(error, ConfigurationError);
219
203
 
220
- export const isTimeoutError = (error: unknown): boolean =>
221
- hasCategory(error, TimeoutError);
204
+ export const isTimeoutError = (error: unknown): boolean => hasCategory(error, TimeoutError);
222
205
 
223
- export const isRetryableError = (error: unknown): boolean =>
224
- hasCategory(error, RetryableError);
206
+ export const isRetryableError = (error: unknown): boolean => hasCategory(error, RetryableError);
225
207
 
226
- export const isLockedError = (error: unknown): boolean =>
227
- hasCategory(error, LockedError);
208
+ export const isLockedError = (error: unknown): boolean => hasCategory(error, LockedError);
228
209
 
229
- export const isAbortedError = (error: unknown): boolean =>
230
- hasCategory(error, AbortedError);
210
+ export const isAbortedError = (error: unknown): boolean => hasCategory(error, AbortedError);
231
211
 
232
212
  export const isAlreadyExistsError = (error: unknown): boolean =>
233
213
  hasCategory(error, AlreadyExistsError);
@@ -271,8 +251,7 @@ export const isThrottling = (error: unknown): boolean => {
271
251
  * which knows whether a given response is genuinely retryable.
272
252
  */
273
253
  const isHttpTransportError = (error: unknown): boolean =>
274
- HttpClientError.isHttpClientError(error) &&
275
- error.reason._tag === "TransportError";
254
+ HttpClientError.isHttpClientError(error) && error.reason._tag === "TransportError";
276
255
 
277
256
  /**
278
257
  * Check if an error is a transient error that should be automatically retried.
@@ -309,9 +288,7 @@ export const isTransientError = (error: unknown): boolean => {
309
288
  // Category Type Utilities
310
289
  // ============================================================================
311
290
 
312
- export type AllKeys<E> = E extends { [categoriesKey]: infer Q }
313
- ? keyof Q
314
- : never;
291
+ export type AllKeys<E> = E extends { [categoriesKey]: infer Q } ? keyof Q : never;
315
292
 
316
293
  export type ExtractAll<E, Cats extends PropertyKey> = Cats extends any
317
294
  ? Extract<E, { [categoriesKey]: { [K in Cats]: any } }>
@@ -375,9 +352,7 @@ export const catchRetryableError = makeCatcher(RetryableError);
375
352
  export const catchLockedError = makeCatcher(LockedError);
376
353
  export const catchAbortedError = makeCatcher(AbortedError);
377
354
  export const catchAlreadyExistsError = makeCatcher(AlreadyExistsError);
378
- export const catchDependencyViolationError = makeCatcher(
379
- DependencyViolationError,
380
- );
355
+ export const catchDependencyViolationError = makeCatcher(DependencyViolationError);
381
356
 
382
357
  /**
383
358
  * Catch errors with specified categories with full type narrowing.
@@ -398,11 +373,7 @@ export const catchCategory =
398
373
  ) =>
399
374
  <A, R>(
400
375
  effect: Effect.Effect<A, E, R>,
401
- ): Effect.Effect<
402
- A | A2,
403
- E2 | Exclude<E, ExtractAll<E, Categories[number]>>,
404
- R | R2
405
- > => {
376
+ ): Effect.Effect<A | A2, E2 | Exclude<E, ExtractAll<E, Categories[number]>>, R | R2> => {
406
377
  const f = args.pop()!;
407
378
  const categories = args;
408
379
  return Effect.catchIf(