@distilled.cloud/core 1.0.0-rc.14 → 1.0.0-rc.16
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.
- package/lib/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +755 -147
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +146 -146
- package/lib/category.js.map +1 -1
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +11 -0
- package/lib/chunks.js.map +1 -0
- package/lib/codegen/boolean-string-enums.js +36 -36
- package/lib/codegen/chunk.d.ts +7 -0
- package/lib/codegen/chunk.d.ts.map +1 -0
- package/lib/codegen/chunk.js +139 -0
- package/lib/codegen/chunk.js.map +1 -0
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +28 -14
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/datafy.d.ts +14 -0
- package/lib/codegen/datafy.d.ts.map +1 -0
- package/lib/codegen/datafy.js +853 -0
- package/lib/codegen/datafy.js.map +1 -0
- package/lib/codegen/dedupe.d.ts +5 -0
- package/lib/codegen/dedupe.d.ts.map +1 -0
- package/lib/codegen/dedupe.js +153 -0
- package/lib/codegen/dedupe.js.map +1 -0
- package/lib/codegen/emit.js +56 -56
- package/lib/codegen/format.js +18 -18
- package/lib/codegen/generated-at.js +29 -29
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +92 -84
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graph.js +36 -36
- package/lib/codegen/graphql-client.d.ts +2 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +55 -26
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql.js +113 -113
- package/lib/codegen/latin1.d.ts +3 -0
- package/lib/codegen/latin1.d.ts.map +1 -0
- package/lib/codegen/latin1.js +126 -0
- package/lib/codegen/latin1.js.map +1 -0
- package/lib/codegen/members.d.ts +7 -0
- package/lib/codegen/members.d.ts.map +1 -1
- package/lib/codegen/members.js +26 -19
- package/lib/codegen/members.js.map +1 -1
- package/lib/codegen/model-diff.js +6 -6
- package/lib/codegen/naming.js +19 -19
- package/lib/codegen/openapi-cli.js +15 -15
- package/lib/codegen/openapi.d.ts +17 -0
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +323 -169
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.js +14 -14
- package/lib/codegen/pagination.js +11 -11
- package/lib/codegen/patch-audit.js +57 -57
- package/lib/codegen/patches.js +79 -79
- package/lib/codegen/prelude.js +19 -19
- package/lib/codegen/privatize.d.ts +21 -0
- package/lib/codegen/privatize.d.ts.map +1 -0
- package/lib/codegen/privatize.js +176 -0
- package/lib/codegen/privatize.js.map +1 -0
- package/lib/codegen/proto.js +25 -25
- package/lib/codegen/pure.d.ts +6 -0
- package/lib/codegen/pure.d.ts.map +1 -0
- package/lib/codegen/pure.js +91 -0
- package/lib/codegen/pure.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +108 -108
- package/lib/codegen/spec-path.js +57 -57
- package/lib/codegen/table.d.ts +5 -0
- package/lib/codegen/table.d.ts.map +1 -0
- package/lib/codegen/table.js +249 -0
- package/lib/codegen/table.js.map +1 -0
- package/lib/config.d.ts +27 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +161 -0
- package/lib/config.js.map +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +130 -0
- package/lib/crypto.js.map +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +8 -0
- package/lib/debug.js.map +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +7 -6
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +117 -114
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +150 -119
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.types.js +4 -3
- package/lib/graphql.types.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +15 -14
- package/lib/index.js.map +1 -1
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +28 -28
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +95 -90
- package/lib/pagination.js.map +1 -1
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +40 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protocol-http.d.ts +50 -14
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +351 -178
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +238 -130
- package/lib/protocol-rest.js.map +1 -1
- package/lib/query.js +16 -16
- package/lib/response-validation-strict.d.ts +48 -0
- package/lib/response-validation-strict.d.ts.map +1 -0
- package/lib/response-validation-strict.js +284 -0
- package/lib/response-validation-strict.js.map +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +112 -70
- package/lib/response-validation.js.map +1 -1
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +49 -49
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +142 -154
- package/lib/retry.js.map +1 -1
- package/lib/schema-lite-impl.d.ts +158 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +341 -0
- package/lib/schema-lite-impl.js.map +1 -0
- package/lib/schema-lite-typed.d.ts +41 -0
- package/lib/schema-lite-typed.d.ts.map +1 -0
- package/lib/schema-lite-typed.js +27 -0
- package/lib/schema-lite-typed.js.map +1 -0
- package/lib/schema-lite.d.ts +40 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +31 -0
- package/lib/schema-lite.js.map +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +202 -30
- package/lib/schema.js.map +1 -1
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +22 -21
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts +13 -13
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +80 -80
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +38 -26
- package/lib/xml.js.map +1 -1
- package/package.json +9 -7
- package/src/api.ts +1079 -180
- package/src/category.ts +33 -33
- package/src/chunks.ts +30 -0
- package/src/codegen/chunk.ts +147 -0
- package/src/codegen/cli.ts +27 -1
- package/src/codegen/datafy.ts +874 -0
- package/src/codegen/dedupe.ts +173 -0
- package/src/codegen/generator.ts +10 -3
- package/src/codegen/graphql-client.ts +49 -15
- package/src/codegen/latin1.ts +131 -0
- package/src/codegen/members.ts +8 -0
- package/src/codegen/openapi.ts +194 -3
- package/src/codegen/privatize.ts +200 -0
- package/src/codegen/pure.ts +94 -0
- package/src/codegen/table.ts +254 -0
- package/src/config.ts +216 -0
- package/src/crypto.ts +202 -0
- package/src/debug.ts +8 -0
- package/src/error-category.ts +2 -1
- package/src/errors.ts +65 -56
- package/src/graphql.ts +109 -62
- package/src/graphql.types.ts +9 -7
- package/src/index.ts +3 -2
- package/src/json-patch.ts +2 -2
- package/src/pagination.ts +37 -18
- package/src/plain-values.ts +41 -0
- package/src/protocol-http.ts +378 -145
- package/src/protocol-rest.ts +337 -169
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +101 -50
- package/src/retry-after.ts +3 -3
- package/src/retry.ts +94 -93
- package/src/schema-lite-impl.ts +550 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +44 -0
- package/src/schema.ts +258 -14
- package/src/testing.ts +4 -2
- package/src/trait.ts +36 -28
- package/src/xml.ts +31 -17
- package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
- package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.test.js +0 -275
- package/lib/codegen/boolean-string-enums.test.js.map +0 -1
- package/lib/codegen/defer-naming.test.d.ts +0 -2
- package/lib/codegen/defer-naming.test.d.ts.map +0 -1
- package/lib/codegen/defer-naming.test.js +0 -105
- package/lib/codegen/defer-naming.test.js.map +0 -1
- package/lib/codegen/generated-at.test.d.ts +0 -2
- package/lib/codegen/generated-at.test.d.ts.map +0 -1
- package/lib/codegen/generated-at.test.js +0 -81
- package/lib/codegen/generated-at.test.js.map +0 -1
- package/lib/codegen/generator.test.d.ts +0 -2
- package/lib/codegen/generator.test.d.ts.map +0 -1
- package/lib/codegen/generator.test.js +0 -121
- package/lib/codegen/generator.test.js.map +0 -1
- package/lib/codegen/graphql-client.test.d.ts +0 -2
- package/lib/codegen/graphql-client.test.d.ts.map +0 -1
- package/lib/codegen/graphql-client.test.js +0 -171
- package/lib/codegen/graphql-client.test.js.map +0 -1
- package/lib/codegen/openapi-binary.test.d.ts +0 -2
- package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
- package/lib/codegen/openapi-binary.test.js +0 -67
- package/lib/codegen/openapi-binary.test.js.map +0 -1
- package/lib/codegen/patch-audit.test.d.ts +0 -2
- package/lib/codegen/patch-audit.test.d.ts.map +0 -1
- package/lib/codegen/patch-audit.test.js +0 -141
- package/lib/codegen/patch-audit.test.js.map +0 -1
- package/lib/codegen/patches.test.d.ts +0 -2
- package/lib/codegen/patches.test.d.ts.map +0 -1
- package/lib/codegen/patches.test.js +0 -155
- package/lib/codegen/patches.test.js.map +0 -1
- package/lib/codegen/protocol-imports.test.d.ts +0 -2
- package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
- package/lib/codegen/protocol-imports.test.js +0 -36
- package/lib/codegen/protocol-imports.test.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.js +0 -451
- package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
- package/lib/codegen/untagged-unions.test.d.ts +0 -2
- package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
- package/lib/codegen/untagged-unions.test.js +0 -80
- package/lib/codegen/untagged-unions.test.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.test.d.ts +0 -2
- package/lib/graphql.test.d.ts.map +0 -1
- package/lib/graphql.test.js +0 -151
- package/lib/graphql.test.js.map +0 -1
- package/lib/json-patch.test.d.ts +0 -2
- package/lib/json-patch.test.d.ts.map +0 -1
- package/lib/json-patch.test.js +0 -65
- package/lib/json-patch.test.js.map +0 -1
- package/lib/pagination.test.d.ts +0 -2
- package/lib/pagination.test.d.ts.map +0 -1
- package/lib/pagination.test.js +0 -131
- package/lib/pagination.test.js.map +0 -1
- package/lib/protocol-http.test.d.ts +0 -2
- package/lib/protocol-http.test.d.ts.map +0 -1
- package/lib/protocol-http.test.js +0 -228
- package/lib/protocol-http.test.js.map +0 -1
- package/lib/protocol-rest.test.d.ts +0 -2
- package/lib/protocol-rest.test.d.ts.map +0 -1
- package/lib/protocol-rest.test.js +0 -498
- package/lib/protocol-rest.test.js.map +0 -1
- package/lib/response-validation.test.d.ts +0 -2
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -72
- package/lib/response-validation.test.js.map +0 -1
- package/lib/retry-after.test.d.ts +0 -2
- package/lib/retry-after.test.d.ts.map +0 -1
- package/lib/retry-after.test.js +0 -204
- package/lib/retry-after.test.js.map +0 -1
- package/lib/retry.test.d.ts +0 -2
- package/lib/retry.test.d.ts.map +0 -1
- package/lib/retry.test.js +0 -407
- package/lib/retry.test.js.map +0 -1
- package/lib/sdks.test.d.ts +0 -2
- package/lib/sdks.test.d.ts.map +0 -1
- package/lib/sdks.test.js +0 -76
- package/lib/sdks.test.js.map +0 -1
- package/lib/xml.test.d.ts +0 -2
- package/lib/xml.test.d.ts.map +0 -1
- package/lib/xml.test.js +0 -210
- package/lib/xml.test.js.map +0 -1
- package/src/codegen/boolean-string-enums.test.ts +0 -299
- package/src/codegen/defer-naming.test.ts +0 -113
- package/src/codegen/generated-at.test.ts +0 -89
- package/src/codegen/generator.test.ts +0 -137
- package/src/codegen/graphql-client.test.ts +0 -189
- package/src/codegen/openapi-binary.test.ts +0 -91
- package/src/codegen/patch-audit.test.ts +0 -160
- package/src/codegen/patches.test.ts +0 -188
- package/src/codegen/protocol-imports.test.ts +0 -39
- package/src/codegen/rewrite-operation-ids.test.ts +0 -472
- package/src/codegen/untagged-unions.test.ts +0 -85
- package/src/fixtures/xml/upstream-validator.json +0 -397
- package/src/graphql.test.ts +0 -198
- package/src/json-patch.test.ts +0 -77
- package/src/pagination.test.ts +0 -169
- package/src/protocol-http.test.ts +0 -276
- package/src/protocol-rest.test.ts +0 -703
- package/src/response-validation.test.ts +0 -89
- package/src/retry-after.test.ts +0 -267
- package/src/retry.test.ts +0 -566
- package/src/sdks.test.ts +0 -87
- package/src/xml.test.ts +0 -251
package/src/xml.test.ts
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
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.ts";
|
|
6
|
-
|
|
7
|
-
function parse(xml: string) {
|
|
8
|
-
// Compare the wire values independently of the null prototypes used for safety.
|
|
9
|
-
return JSON.parse(JSON.stringify(parseXmlSync(xml)));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
describe("upstream fast-xml-parser validation corpus", () => {
|
|
13
|
-
for (const [index, fixture] of fixtures.entries()) {
|
|
14
|
-
it(`${index}: ${fixture.name}`, () => {
|
|
15
|
-
if (fixture.parserValid ?? fixture.valid) {
|
|
16
|
-
assert.doesNotThrow(() => parseXmlSync(fixture.xml));
|
|
17
|
-
} else {
|
|
18
|
-
assert.throws(() => parseXmlSync(fixture.xml), XmlParseError);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("XML object format", () => {
|
|
25
|
-
it("keeps primitives as strings and groups repeated children", () => {
|
|
26
|
-
assert.deepEqual(parse("<R><x>001</x><x>false</x><x>1e3</x><empty/><empty></empty></R>"), {
|
|
27
|
-
R: { x: ["001", "false", "1e3"], empty: ["", ""] },
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("preserves namespace names, attributes, and text with attributes", () => {
|
|
32
|
-
assert.deepEqual(
|
|
33
|
-
parse('<ns:R xmlns:ns="urn:r"><ns:x ns:id="01">value</ns:x><empty a=""/></ns:R>'),
|
|
34
|
-
{
|
|
35
|
-
"ns:R": {
|
|
36
|
-
"@_xmlns:ns": "urn:r",
|
|
37
|
-
"ns:x": { "@_ns:id": "01", "#text": "value" },
|
|
38
|
-
empty: { "@_a": "" },
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("preserves string whitespace, including attribute and CDATA values", () => {
|
|
45
|
-
assert.deepEqual(
|
|
46
|
-
parse(
|
|
47
|
-
'<R><Key> key </Key><blank> \t </blank><x a=" b "> text </x><c><![CDATA[ c ]]></c></R>',
|
|
48
|
-
),
|
|
49
|
-
{
|
|
50
|
-
R: {
|
|
51
|
-
Key: " key ",
|
|
52
|
-
blank: " \t ",
|
|
53
|
-
x: { "@_a": " b ", "#text": " text " },
|
|
54
|
-
c: " c ",
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("discards layout-only container text but preserves mixed content", () => {
|
|
61
|
-
assert.deepEqual(parse("<R>\n <x/>\n <y/>\n</R>"), {
|
|
62
|
-
R: { x: "", y: "" },
|
|
63
|
-
});
|
|
64
|
-
assert.deepEqual(parse("<R>Hello <b>world</b> !</R>"), {
|
|
65
|
-
R: { b: "world", "#text": "Hello !" },
|
|
66
|
-
});
|
|
67
|
-
assert.deepEqual(parse("<R><![CDATA[ ]]><b/></R>"), {
|
|
68
|
-
R: { b: "", "#text": " " },
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("decodes predefined and numeric entities exactly once", () => {
|
|
73
|
-
assert.deepEqual(parse('<R a=""'	">&<>A😀&lt;</R>'), {
|
|
74
|
-
R: { "@_a": "\"'\t", "#text": "&<>A😀<" },
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("normalizes literal line endings and attribute whitespace, not character references", () => {
|
|
79
|
-
assert.deepEqual(parse('<R a="x\r\ny\tz\r 	">a\r\nb\rc </R>'), {
|
|
80
|
-
R: { "@_a": "x y z \r\n\t", "#text": "a\nb\nc\r" },
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("joins CDATA and text without decoding CDATA entities", () => {
|
|
85
|
-
assert.deepEqual(parse("<R>a<![CDATA[<b>&]]><![CDATA[c]]>d&</R>"), {
|
|
86
|
-
R: "a<b>&cd&",
|
|
87
|
-
});
|
|
88
|
-
assert.deepEqual(parse("<R><![CDATA[]]></R>"), { R: "" });
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("ignores declarations, comments and processing instructions", () => {
|
|
92
|
-
assert.deepEqual(
|
|
93
|
-
parse(
|
|
94
|
-
'\uFEFF<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!--before--><?before a?><R>a<!--ignored--><?in x?>b</R><?after?><!--after-->',
|
|
95
|
-
),
|
|
96
|
-
{ R: "ab" },
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("supports XML Unicode names", () => {
|
|
101
|
-
assert.deepEqual(parse('<根 é="oui"><𐀀>😀</𐀀><á/></根>'), {
|
|
102
|
-
根: { "@_é": "oui", 𐀀: "😀", á: "" },
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("accepts empty HTTP bodies", () => {
|
|
107
|
-
for (const xml of ["", " \r\n\t", "\uFEFF"]) assert.deepEqual(parse(xml), {});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("stores prototype-related names as own data properties", () => {
|
|
111
|
-
const result = parseXmlSync(
|
|
112
|
-
"<__proto__><constructor>one</constructor><constructor>two</constructor><__proto__>safe</__proto__><toString/></__proto__>",
|
|
113
|
-
);
|
|
114
|
-
const root = result.__proto__;
|
|
115
|
-
assert.equal(Object.getPrototypeOf(result), null);
|
|
116
|
-
assert.equal(Object.getPrototypeOf(root), null);
|
|
117
|
-
assert.deepEqual(
|
|
118
|
-
JSON.parse(JSON.stringify(root)),
|
|
119
|
-
JSON.parse('{"constructor":["one","two"],"__proto__":"safe","toString":""}'),
|
|
120
|
-
);
|
|
121
|
-
assert.equal(Object.hasOwn(Object.prototype, "safe"), false);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("round trips escaped strings", () => {
|
|
125
|
-
for (const text of [' <tag a="x">&\'😀 ', "", "false", "001", " ", "\t\n"]) {
|
|
126
|
-
assert.deepEqual(parse(`<R>${escapeXml(text)}</R>`), { R: text });
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("handles large lists without recursion", () => {
|
|
131
|
-
const result = parse(`<R>${'<item a="1">value</item>'.repeat(10_000)}</R>`);
|
|
132
|
-
assert.equal(result.R.item.length, 10_000);
|
|
133
|
-
assert.deepEqual(result.R.item[9_999], { "@_a": "1", "#text": "value" });
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe("malformed and unsupported XML", () => {
|
|
138
|
-
const invalid = [
|
|
139
|
-
'<R a="1"a="2"/>',
|
|
140
|
-
'<R a="<"/>',
|
|
141
|
-
'<R a="&bad;"/>',
|
|
142
|
-
"<R a=1/>",
|
|
143
|
-
'<R a="1" a="2"/>',
|
|
144
|
-
"<R/ >",
|
|
145
|
-
"< R/>",
|
|
146
|
-
"<R></ R>",
|
|
147
|
-
"<R></R x>",
|
|
148
|
-
"<R>]]></R>",
|
|
149
|
-
"<R>&</R>",
|
|
150
|
-
"<R>&</R>",
|
|
151
|
-
"<R>&nope;</R>",
|
|
152
|
-
"<R>�</R>",
|
|
153
|
-
"<R>�</R>",
|
|
154
|
-
"<R>�</R>",
|
|
155
|
-
"<R></R>",
|
|
156
|
-
"<R>&#-1;</R>",
|
|
157
|
-
"<R>A</R>",
|
|
158
|
-
"<R>&#x;</R>",
|
|
159
|
-
"<R>&#;</R>",
|
|
160
|
-
"<R>\u0000</R>",
|
|
161
|
-
"<R>\u000B</R>",
|
|
162
|
-
"<R>\uD800</R>",
|
|
163
|
-
"<R>\uDC00</R>",
|
|
164
|
-
"<R>\uFFFE</R>",
|
|
165
|
-
"<R>\uFFFF</R>",
|
|
166
|
-
"<R><!--a--b--></R>",
|
|
167
|
-
"<R><!--a---></R>",
|
|
168
|
-
"<R><!--",
|
|
169
|
-
"<R><![CDATA[",
|
|
170
|
-
"<![CDATA[x]]><R/>",
|
|
171
|
-
"<R/><![CDATA[x]]>",
|
|
172
|
-
"<R><?pi",
|
|
173
|
-
"<R><?1bad?></R>",
|
|
174
|
-
"<R><?pi!?></R>",
|
|
175
|
-
'<?XML version="1.0"?><R/>',
|
|
176
|
-
"<?xml?><R/>",
|
|
177
|
-
'<?xml version="1.1"?><R/>',
|
|
178
|
-
'<?xml encoding="UTF-8"?><R/>',
|
|
179
|
-
'<?xml version="1.0" junk="x"?><R/>',
|
|
180
|
-
'<R><?xml version="1.0"?></R>',
|
|
181
|
-
'<!--x--><?xml version="1.0"?><R/>',
|
|
182
|
-
'<?xml version="1.0"?>',
|
|
183
|
-
"<!--only-->",
|
|
184
|
-
"<!DOCTYPE R><R/>",
|
|
185
|
-
'<!DOCTYPE R SYSTEM "file:///etc/passwd"><R/>',
|
|
186
|
-
'<!DOCTYPE R [<!ENTITY a "&a;">]><R>&a;</R>',
|
|
187
|
-
"<R/><R/>",
|
|
188
|
-
"before<R/>",
|
|
189
|
-
"<R/>after",
|
|
190
|
-
"<R><x></R>",
|
|
191
|
-
"<R>",
|
|
192
|
-
"<",
|
|
193
|
-
'<R a="',
|
|
194
|
-
"<R a",
|
|
195
|
-
"<R a=",
|
|
196
|
-
"<R ",
|
|
197
|
-
"</R>",
|
|
198
|
-
"<1bad/>",
|
|
199
|
-
'<R\u00A0a="x"/>',
|
|
200
|
-
];
|
|
201
|
-
for (const xml of invalid) {
|
|
202
|
-
it(`rejects ${JSON.stringify(xml)}`, () => {
|
|
203
|
-
assert.throws(
|
|
204
|
-
() => parseXmlSync(xml),
|
|
205
|
-
(error) => {
|
|
206
|
-
assert.ok(error instanceof XmlParseError);
|
|
207
|
-
assert.ok(error.offset >= 0 && error.offset <= xml.length);
|
|
208
|
-
return true;
|
|
209
|
-
},
|
|
210
|
-
);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
it("reports original input offsets and CRLF-aware line numbers", () => {
|
|
215
|
-
const xml = "<R>\r\n&bad;</R>";
|
|
216
|
-
assert.throws(
|
|
217
|
-
() => parseXmlSync(xml),
|
|
218
|
-
(error) => {
|
|
219
|
-
assert.ok(error instanceof XmlParseError);
|
|
220
|
-
assert.equal(error.offset, 5);
|
|
221
|
-
assert.equal(error.line, 2);
|
|
222
|
-
assert.equal(error.column, 1);
|
|
223
|
-
return true;
|
|
224
|
-
},
|
|
225
|
-
);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("enforces depth and input length limits", () => {
|
|
229
|
-
assert.doesNotThrow(() => parseXmlSync("<a><b/></a>", { maxDepth: 2 }));
|
|
230
|
-
assert.throws(() => parseXmlSync("<a><b/></a>", { maxDepth: 1 }), XmlParseError);
|
|
231
|
-
assert.doesNotThrow(() => parseXmlSync("<a/>", { maxLength: 4 }));
|
|
232
|
-
assert.throws(() => parseXmlSync("<a/>", { maxLength: 3 }), XmlParseError);
|
|
233
|
-
assert.throws(() => parseXmlSync("<a/>", { maxDepth: NaN }), XmlParseError);
|
|
234
|
-
assert.throws(() => parseXmlSync("<a/>", { maxLength: -1 }), XmlParseError);
|
|
235
|
-
const nested = "<a>".repeat(2_000) + "</a>".repeat(2_000);
|
|
236
|
-
assert.throws(() => parseXmlSync(nested), XmlParseError);
|
|
237
|
-
assert.doesNotThrow(() => parseXmlSync(nested, { maxDepth: 2_000 }));
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it("exposes parser failures through Effect's typed channel", () => {
|
|
241
|
-
const result = Effect.runSync(Effect.flip(parseXml("<R>")));
|
|
242
|
-
assert.ok(result instanceof XmlParseError);
|
|
243
|
-
assert.match(result.message, /Unclosed element/);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("can execute the same lazy Effect repeatedly", () => {
|
|
247
|
-
const effect = parseXml("<R>ok</R>");
|
|
248
|
-
assert.equal(Effect.runSync(effect).R, "ok");
|
|
249
|
-
assert.equal(Effect.runSync(effect).R, "ok");
|
|
250
|
-
});
|
|
251
|
-
});
|