@distilled.cloud/core 1.0.0-rc.15 → 1.0.0-rc.17
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/_bundle/aws.js +2 -0
- package/lib/_bundle/aws.js.map +1 -0
- package/lib/_bundle/base.js +5 -0
- package/lib/_bundle/base.js.map +1 -0
- package/lib/_bundle/graphql.js +3 -0
- package/lib/_bundle/graphql.js.map +1 -0
- package/lib/_bundle/rest.js +2 -0
- package/lib/_bundle/rest.js.map +1 -0
- package/lib/_bundle/xml.js +4 -0
- package/lib/_bundle/xml.js.map +1 -0
- package/lib/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -188
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -278
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +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 +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +1 -46
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -195
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +1 -1027
- package/lib/graphql.types.js +1 -5
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -15
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +1 -226
- package/lib/json-patch.js.map +1 -1
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -266
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +2 -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 +1 -639
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -267
- package/lib/query.js +1 -27
- 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 +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +1 -76
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +1 -112
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -209
- 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 +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 +2 -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 +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -48
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -40
- 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 +1 -131
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +1 -311
- package/package.json +9 -7
- package/src/api.ts +1080 -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/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- 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/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.js.map +0 -1
- 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/graphql.types.js.map +0 -1
- package/lib/index.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.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.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.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/query.js.map +0 -1
- package/lib/response-validation.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.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.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/schema.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/trait.js.map +0 -1
- package/lib/xml.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/lib/xml.test.js
DELETED
|
@@ -1,210 +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.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=""'	">&<>A😀&lt;</R>'), {
|
|
60
|
-
R: { "@_a": "\"'\t", "#text": "&<>A😀<" },
|
|
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 	">a\r\nb\rc </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>&]]><![CDATA[c]]>d&</R>"), {
|
|
70
|
-
R: "a<b>&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", " ", "\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>&</R>",
|
|
119
|
-
"<R>&nope;</R>",
|
|
120
|
-
"<R>�</R>",
|
|
121
|
-
"<R>�</R>",
|
|
122
|
-
"<R>�</R>",
|
|
123
|
-
"<R></R>",
|
|
124
|
-
"<R>&#-1;</R>",
|
|
125
|
-
"<R>A</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
|
package/lib/xml.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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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
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { booleanStringEnums, STRING_ENCODED_TRAIT } from "./boolean-string-enums.ts";
|
|
3
|
-
import { generateService } from "./generator.ts";
|
|
4
|
-
|
|
5
|
-
const boolEnum = {
|
|
6
|
-
type: "enum",
|
|
7
|
-
members: {
|
|
8
|
-
TRUE: {
|
|
9
|
-
target: "smithy.api#Unit",
|
|
10
|
-
traits: { "smithy.api#enumValue": "true" },
|
|
11
|
-
},
|
|
12
|
-
FALSE: {
|
|
13
|
-
target: "smithy.api#Unit",
|
|
14
|
-
traits: { "smithy.api#enumValue": "false" },
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const model = (shapes: Record<string, any>) => ({ smithy: "2.0", shapes });
|
|
20
|
-
|
|
21
|
-
describe("booleanStringEnums", () => {
|
|
22
|
-
test("retargets a request member and stamps the trait", () => {
|
|
23
|
-
const m = model({
|
|
24
|
-
"com.example.x#Flag": boolEnum,
|
|
25
|
-
"com.example.x#Request": {
|
|
26
|
-
type: "structure",
|
|
27
|
-
traits: { "smithy.api#input": {} },
|
|
28
|
-
members: { validation_enabled: { target: "com.example.x#Flag" } },
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
expect(booleanStringEnums(m)).toEqual({ members: 1, lists: 0 });
|
|
32
|
-
const member = m.shapes["com.example.x#Request"].members.validation_enabled;
|
|
33
|
-
expect(member.target).toBe("smithy.api#Boolean");
|
|
34
|
-
expect(member.traits[STRING_ENCODED_TRAIT]).toEqual({});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test("leaves response members alone", () => {
|
|
38
|
-
const m = model({
|
|
39
|
-
"com.example.x#Flag": boolEnum,
|
|
40
|
-
"com.example.x#Response": {
|
|
41
|
-
type: "structure",
|
|
42
|
-
members: { active: { target: "com.example.x#Flag" } },
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
|
|
46
|
-
expect(m.shapes["com.example.x#Response"].members.active.target).toBe("com.example.x#Flag");
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("retargets a request-only list's element type", () => {
|
|
50
|
-
const m = model({
|
|
51
|
-
"com.example.x#Flag": boolEnum,
|
|
52
|
-
"com.example.x#FlagList": {
|
|
53
|
-
type: "list",
|
|
54
|
-
member: { target: "com.example.x#Flag" },
|
|
55
|
-
},
|
|
56
|
-
"com.example.x#Request": {
|
|
57
|
-
type: "structure",
|
|
58
|
-
traits: { "smithy.api#input": {} },
|
|
59
|
-
members: { unique_entries: { target: "com.example.x#FlagList" } },
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
expect(booleanStringEnums(m)).toEqual({ members: 1, lists: 1 });
|
|
63
|
-
expect(m.shapes["com.example.x#FlagList"].member.target).toBe("smithy.api#Boolean");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("leaves a list a response also uses", () => {
|
|
67
|
-
const m = model({
|
|
68
|
-
"com.example.x#Flag": boolEnum,
|
|
69
|
-
"com.example.x#FlagList": {
|
|
70
|
-
type: "list",
|
|
71
|
-
member: { target: "com.example.x#Flag" },
|
|
72
|
-
},
|
|
73
|
-
"com.example.x#Request": {
|
|
74
|
-
type: "structure",
|
|
75
|
-
traits: { "smithy.api#input": {} },
|
|
76
|
-
members: { unique_entries: { target: "com.example.x#FlagList" } },
|
|
77
|
-
},
|
|
78
|
-
"com.example.x#Response": {
|
|
79
|
-
type: "structure",
|
|
80
|
-
members: { seen: { target: "com.example.x#FlagList" } },
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
|
|
84
|
-
expect(m.shapes["com.example.x#FlagList"].member.target).toBe("com.example.x#Flag");
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("leaves an enum that is not exactly true/false", () => {
|
|
88
|
-
const m = model({
|
|
89
|
-
"com.example.x#Tri": {
|
|
90
|
-
type: "enum",
|
|
91
|
-
members: {
|
|
92
|
-
TRUE: {
|
|
93
|
-
target: "smithy.api#Unit",
|
|
94
|
-
traits: { "smithy.api#enumValue": "true" },
|
|
95
|
-
},
|
|
96
|
-
FALSE: {
|
|
97
|
-
target: "smithy.api#Unit",
|
|
98
|
-
traits: { "smithy.api#enumValue": "false" },
|
|
99
|
-
},
|
|
100
|
-
AUTO: {
|
|
101
|
-
target: "smithy.api#Unit",
|
|
102
|
-
traits: { "smithy.api#enumValue": "auto" },
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
"com.example.x#Request": {
|
|
107
|
-
type: "structure",
|
|
108
|
-
traits: { "smithy.api#input": {} },
|
|
109
|
-
members: { mode: { target: "com.example.x#Tri" } },
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe("generateService", () => {
|
|
117
|
-
test("member schema overrides retain nullability, query bindings and protocol traits", () => {
|
|
118
|
-
const { code } = generateService(
|
|
119
|
-
model({
|
|
120
|
-
"ns#Example": {
|
|
121
|
-
type: "service",
|
|
122
|
-
version: "1",
|
|
123
|
-
operations: [{ target: "ns#GetThing" }],
|
|
124
|
-
},
|
|
125
|
-
"ns#GetThing": {
|
|
126
|
-
type: "operation",
|
|
127
|
-
input: { target: "ns#Input" },
|
|
128
|
-
output: { target: "smithy.api#Unit" },
|
|
129
|
-
traits: { "smithy.api#http": { method: "GET", uri: "/things" } },
|
|
130
|
-
},
|
|
131
|
-
"ns#Input": {
|
|
132
|
-
type: "structure",
|
|
133
|
-
members: {
|
|
134
|
-
secret: {
|
|
135
|
-
target: "smithy.api#String",
|
|
136
|
-
traits: {
|
|
137
|
-
"smithy.api#httpQuery": "secret",
|
|
138
|
-
"smithy.api#sensitive": {},
|
|
139
|
-
"ns#nullable": {},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
}),
|
|
145
|
-
{
|
|
146
|
-
nullableTrait: "ns#nullable",
|
|
147
|
-
memberSchema: (member, ref) =>
|
|
148
|
-
`S.Union([${ref(member.target)}, S.Redacted(${ref(member.target)})])`,
|
|
149
|
-
memberTraitPipes: { "smithy.api#sensitive": "T.SensitiveValue" },
|
|
150
|
-
operationDecl: {
|
|
151
|
-
contextType: "ExampleOpContext",
|
|
152
|
-
commonErrorType: "ExampleOpError",
|
|
153
|
-
commonErrorClasses: [],
|
|
154
|
-
protocol: "ExampleProtocol",
|
|
155
|
-
retry: "Retry.Retry",
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
);
|
|
159
|
-
expect(code).toContain(
|
|
160
|
-
'"secret": S.optional(S.NullOr(S.Union([S.String, S.Redacted(S.String)])).pipe(T.Query(), T.SensitiveValue({})))',
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test("service-free schemas preserve Codec annotations across structures, collections and raw outputs", () => {
|
|
165
|
-
const input = model({
|
|
166
|
-
"ns#Example": {
|
|
167
|
-
type: "service",
|
|
168
|
-
version: "1",
|
|
169
|
-
operations: [{ target: "ns#GetThing" }],
|
|
170
|
-
},
|
|
171
|
-
"ns#GetThing": {
|
|
172
|
-
type: "operation",
|
|
173
|
-
input: { target: "ns#Input" },
|
|
174
|
-
output: { target: "ns#Output" },
|
|
175
|
-
traits: { "smithy.api#http": { method: "GET", uri: "/things" } },
|
|
176
|
-
},
|
|
177
|
-
"ns#Input": {
|
|
178
|
-
type: "structure",
|
|
179
|
-
members: { list: { target: "ns#List" }, map: { target: "ns#Map" } },
|
|
180
|
-
},
|
|
181
|
-
"ns#List": { type: "list", member: { target: "smithy.api#String" } },
|
|
182
|
-
"ns#Map": {
|
|
183
|
-
type: "map",
|
|
184
|
-
key: { target: "smithy.api#String" },
|
|
185
|
-
value: { target: "smithy.api#String" },
|
|
186
|
-
},
|
|
187
|
-
"ns#Output": {
|
|
188
|
-
type: "structure",
|
|
189
|
-
members: { body: { target: "ns#List", traits: { "ns#raw": {} } } },
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
const spec = {
|
|
193
|
-
extraBindings: [
|
|
194
|
-
{
|
|
195
|
-
trait: "ns#raw",
|
|
196
|
-
binding: "rawResponse",
|
|
197
|
-
pipe: "T.RawResponse()",
|
|
198
|
-
rootPipe: "T.RawResponseRoot()",
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
operationDecl: {
|
|
202
|
-
contextType: "ExampleOpContext",
|
|
203
|
-
commonErrorType: "ExampleOpError",
|
|
204
|
-
commonErrorClasses: [],
|
|
205
|
-
protocol: "ExampleProtocol",
|
|
206
|
-
retry: "Retry.Retry",
|
|
207
|
-
},
|
|
208
|
-
} as const;
|
|
209
|
-
const { code } = generateService(input, { ...spec, schemaType: "Codec" });
|
|
210
|
-
for (const name of ["Input", "List", "Map", "Output"]) {
|
|
211
|
-
expect(code).toContain(`as any as S.Codec<${name}>`);
|
|
212
|
-
}
|
|
213
|
-
expect(code).not.toContain("S.Schema<");
|
|
214
|
-
expect(generateService(input, spec).code).toContain("as any as S.Schema<Input>");
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test("emits a boolean piped through T.StringEncoded()", () => {
|
|
218
|
-
const { code } = generateService(
|
|
219
|
-
model({
|
|
220
|
-
"com.example.x#Example": {
|
|
221
|
-
type: "service",
|
|
222
|
-
version: "2024-01-01",
|
|
223
|
-
operations: [{ target: "com.example.x#GetThing" }],
|
|
224
|
-
},
|
|
225
|
-
"com.example.x#GetThing": {
|
|
226
|
-
type: "operation",
|
|
227
|
-
input: { target: "com.example.x#GetThingRequest" },
|
|
228
|
-
output: { target: "smithy.api#Unit" },
|
|
229
|
-
traits: { "smithy.api#http": { method: "GET", uri: "/things" } },
|
|
230
|
-
},
|
|
231
|
-
"com.example.x#GetThingRequest": {
|
|
232
|
-
type: "structure",
|
|
233
|
-
traits: { "smithy.api#input": {} },
|
|
234
|
-
members: {
|
|
235
|
-
verbose: {
|
|
236
|
-
target: "com.example.x#Flag",
|
|
237
|
-
traits: { "smithy.api#httpQuery": "verbose" },
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
"com.example.x#Flag": boolEnum,
|
|
242
|
-
}),
|
|
243
|
-
{
|
|
244
|
-
operationDecl: {
|
|
245
|
-
contextType: "ExampleOpContext",
|
|
246
|
-
commonErrorType: "ExampleOpError",
|
|
247
|
-
commonErrorClasses: [],
|
|
248
|
-
protocol: "ExampleProtocol",
|
|
249
|
-
retry: "Retry.Retry",
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
);
|
|
253
|
-
expect(code).toContain('"verbose": S.optional(S.Boolean.pipe(T.Query(), T.StringEncoded())),');
|
|
254
|
-
expect(code).toContain("verbose?: boolean;");
|
|
255
|
-
expect(code).not.toContain('"true" | "false"');
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
describe("nested structures", () => {
|
|
260
|
-
const nested = (sharedWithResponse: boolean) =>
|
|
261
|
-
model({
|
|
262
|
-
"com.example.x#GetThing": {
|
|
263
|
-
type: "operation",
|
|
264
|
-
input: { target: "com.example.x#GetThingRequest" },
|
|
265
|
-
output: { target: "com.example.x#GetThingResponse" },
|
|
266
|
-
},
|
|
267
|
-
"com.example.x#GetThingRequest": {
|
|
268
|
-
type: "structure",
|
|
269
|
-
traits: { "smithy.api#input": {} },
|
|
270
|
-
members: { profile: { target: "com.example.x#Profile" } },
|
|
271
|
-
},
|
|
272
|
-
"com.example.x#GetThingResponse": {
|
|
273
|
-
type: "structure",
|
|
274
|
-
traits: { "smithy.api#output": {} },
|
|
275
|
-
members: sharedWithResponse ? { profile: { target: "com.example.x#Profile" } } : {},
|
|
276
|
-
},
|
|
277
|
-
"com.example.x#Profile": {
|
|
278
|
-
type: "structure",
|
|
279
|
-
members: { dynamicMemoryEnabled: { target: "com.example.x#Flag" } },
|
|
280
|
-
},
|
|
281
|
-
"com.example.x#Flag": boolEnum,
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
test("retargets a member of a structure only requests reach", () => {
|
|
285
|
-
const m = nested(false);
|
|
286
|
-
expect(booleanStringEnums(m)).toEqual({ members: 1, lists: 0 });
|
|
287
|
-
const member = m.shapes["com.example.x#Profile"].members.dynamicMemoryEnabled;
|
|
288
|
-
expect(member.target).toBe("smithy.api#Boolean");
|
|
289
|
-
expect(member.traits[STRING_ENCODED_TRAIT]).toEqual({});
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
test("leaves a structure a response also delivers", () => {
|
|
293
|
-
const m = nested(true);
|
|
294
|
-
expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
|
|
295
|
-
expect(m.shapes["com.example.x#Profile"].members.dynamicMemoryEnabled.target).toBe(
|
|
296
|
-
"com.example.x#Flag",
|
|
297
|
-
);
|
|
298
|
-
});
|
|
299
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { afterEach, describe, expect, test } from "vitest";
|
|
5
|
-
import { convertOpenApiToSmithy, RENAME_METADATA_KEY } from "./openapi.ts";
|
|
6
|
-
import { FINALIZED_KEY, finalizeConvert } from "./patches.ts";
|
|
7
|
-
|
|
8
|
-
const spec = {
|
|
9
|
-
openapi: "3.0.3",
|
|
10
|
-
info: { title: "Apps", version: "1" },
|
|
11
|
-
paths: {
|
|
12
|
-
"/apps": {
|
|
13
|
-
get: {
|
|
14
|
-
operationId: "Apps_list",
|
|
15
|
-
responses: {
|
|
16
|
-
"200": {
|
|
17
|
-
content: {
|
|
18
|
-
"application/json": {
|
|
19
|
-
schema: { type: "array", items: { $ref: "#/components/schemas/App" } },
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
"/apps/{id}": {
|
|
27
|
-
get: {
|
|
28
|
-
operationId: "Apps_get",
|
|
29
|
-
parameters: [{ name: "id", in: "path", required: true, schema: { type: "string" } }],
|
|
30
|
-
responses: {
|
|
31
|
-
"200": {
|
|
32
|
-
content: { "application/json": { schema: { $ref: "#/components/schemas/App" } } },
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
components: {
|
|
39
|
-
schemas: {
|
|
40
|
-
App: { type: "object", properties: { name: { type: "string" } } },
|
|
41
|
-
// Takes the name the final-named run gives `Apps_list`'s response, so
|
|
42
|
-
// the two runs disagree on which shape gets the `2` suffix.
|
|
43
|
-
ListAppsResponse: { type: "object", properties: { n: { type: "integer" } } },
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const options = { namespace: "ns", serviceName: "Apps" };
|
|
49
|
-
|
|
50
|
-
const dirs: string[] = [];
|
|
51
|
-
afterEach(() => {
|
|
52
|
-
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
/** Write `model` as `.generated-specs/apps.json`, with optional patch files. */
|
|
56
|
-
const finalize = async (model: unknown, patches: Record<string, unknown[]> = {}) => {
|
|
57
|
-
const root = mkdtempSync(join(tmpdir(), "defer-naming-"));
|
|
58
|
-
dirs.push(root);
|
|
59
|
-
mkdirSync(join(root, ".generated-specs"));
|
|
60
|
-
writeFileSync(join(root, ".generated-specs", "apps.json"), JSON.stringify(model));
|
|
61
|
-
mkdirSync(join(root, "patches", "apps"), { recursive: true });
|
|
62
|
-
for (const [name, ops] of Object.entries(patches)) {
|
|
63
|
-
writeFileSync(join(root, "patches", "apps", name), JSON.stringify({ patches: ops }));
|
|
64
|
-
}
|
|
65
|
-
await finalizeConvert({ root, operationNaming: "as-is" });
|
|
66
|
-
return JSON.parse(readFileSync(join(root, ".generated-specs", "apps.json"), "utf8"));
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
describe("deferNaming", () => {
|
|
70
|
-
test("names shapes from the spec and records the final names", () => {
|
|
71
|
-
const model = convertOpenApiToSmithy(spec, { ...options, deferNaming: true });
|
|
72
|
-
expect(model.shapes["ns#AppsList"]?.type).toBe("operation");
|
|
73
|
-
expect(model.shapes["ns#ListApps"]).toBeUndefined();
|
|
74
|
-
expect(model.metadata[RENAME_METADATA_KEY]).toMatchObject({
|
|
75
|
-
"ns#AppsList": "ns#ListApps",
|
|
76
|
-
"ns#AppsGet": "ns#GetApp",
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("finalize renames to exactly the model converted with final names", async () => {
|
|
81
|
-
const named = convertOpenApiToSmithy(spec, options);
|
|
82
|
-
const deferred = convertOpenApiToSmithy(spec, { ...options, deferNaming: true });
|
|
83
|
-
const finalized = await finalize(deferred);
|
|
84
|
-
expect(finalized).toEqual({
|
|
85
|
-
...named,
|
|
86
|
-
metadata: { ...named.metadata, [FINALIZED_KEY]: true },
|
|
87
|
-
});
|
|
88
|
-
expect(Object.keys(finalized.shapes)).toEqual(Object.keys(named.shapes));
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("a Smithy patch targets the upstream name", async () => {
|
|
92
|
-
const deferred = convertOpenApiToSmithy(spec, { ...options, deferNaming: true });
|
|
93
|
-
const finalized = await finalize(deferred, {
|
|
94
|
-
"doc.json": [
|
|
95
|
-
{
|
|
96
|
-
op: "add",
|
|
97
|
-
path: "/shapes/ns#AppsList/traits/smithy.api#documentation",
|
|
98
|
-
value: "Every app.",
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
});
|
|
102
|
-
expect(finalized.shapes["ns#ListApps"].traits["smithy.api#documentation"]).toBe("Every app.");
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("a patch that takes a final name fails the rename", async () => {
|
|
106
|
-
const deferred = convertOpenApiToSmithy(spec, { ...options, deferNaming: true });
|
|
107
|
-
await expect(
|
|
108
|
-
finalize(deferred, {
|
|
109
|
-
"clash.json": [{ op: "add", path: "/shapes/ns#GetApp", value: { type: "structure" } }],
|
|
110
|
-
}),
|
|
111
|
-
).rejects.toThrow(/already taken/);
|
|
112
|
-
});
|
|
113
|
-
});
|