@distilled.cloud/core 1.0.0-rc.15 → 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
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
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
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { dirname, join } from "node:path";
|
|
5
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
6
|
-
import { lastChangeDate, specUpdatedAt, stampGeneratedAt } from "./generated-at.ts";
|
|
7
|
-
|
|
8
|
-
describe("stampGeneratedAt", () => {
|
|
9
|
-
let dir: string;
|
|
10
|
-
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
|
11
|
-
|
|
12
|
-
const setup = (pkg: object) => {
|
|
13
|
-
dir = mkdtempSync(join(tmpdir(), "generated-at-"));
|
|
14
|
-
writeFileSync(join(dir, "package.json"), `${JSON.stringify(pkg, null, 2)}\n`);
|
|
15
|
-
};
|
|
16
|
-
const read = () => readFileSync(join(dir, "package.json"), "utf8");
|
|
17
|
-
|
|
18
|
-
it("adds distilled.generatedAt as a UTC date and keeps the other fields in order", () => {
|
|
19
|
-
setup({ name: "@distilled.cloud/x", version: "1.0.0", scripts: { generate: "g" } });
|
|
20
|
-
const stamp = stampGeneratedAt(dir, {
|
|
21
|
-
now: new Date("2026-10-08T23:30:00-05:00"),
|
|
22
|
-
specUpdatedAt: "2026-10-03",
|
|
23
|
-
});
|
|
24
|
-
expect(stamp).toEqual({ generatedAt: "2026-10-09", specUpdatedAt: "2026-10-03" });
|
|
25
|
-
const text = read();
|
|
26
|
-
expect(Object.keys(JSON.parse(text))).toEqual(["name", "version", "scripts", "distilled"]);
|
|
27
|
-
expect(JSON.parse(text).distilled).toEqual({
|
|
28
|
-
generatedAt: "2026-10-09",
|
|
29
|
-
specUpdatedAt: "2026-10-03",
|
|
30
|
-
});
|
|
31
|
-
expect(text.endsWith("}\n")).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("updates existing dates and keeps other distilled fields", () => {
|
|
35
|
-
setup({ name: "x", distilled: { other: true, generatedAt: "2025-01-01" } });
|
|
36
|
-
stampGeneratedAt(dir, { now: new Date("2026-10-08T12:00:00Z"), specUpdatedAt: "2026-10-01" });
|
|
37
|
-
expect(JSON.parse(read()).distilled).toEqual({
|
|
38
|
-
other: true,
|
|
39
|
-
generatedAt: "2026-10-08",
|
|
40
|
-
specUpdatedAt: "2026-10-01",
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("keeps the existing spec date when the spec date is unknown", () => {
|
|
45
|
-
setup({ name: "x", distilled: { generatedAt: "2025-01-01", specUpdatedAt: "2024-12-31" } });
|
|
46
|
-
stampGeneratedAt(dir, { now: new Date("2026-10-08T12:00:00Z"), specUpdatedAt: undefined });
|
|
47
|
-
expect(JSON.parse(read()).distilled).toEqual({
|
|
48
|
-
generatedAt: "2026-10-08",
|
|
49
|
-
specUpdatedAt: "2024-12-31",
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("finds no spec date for a package without specs/", () => {
|
|
54
|
-
setup({ name: "x" });
|
|
55
|
-
expect(specUpdatedAt(dir)).toBeUndefined();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe("lastChangeDate", () => {
|
|
60
|
-
let dir: string;
|
|
61
|
-
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
|
62
|
-
|
|
63
|
-
const sh = (cwd: string, ...args: string[]) => execFileSync("git", args, { cwd, stdio: "pipe" });
|
|
64
|
-
const commit = (cwd: string, file: string, date: string) => {
|
|
65
|
-
mkdirSync(join(cwd, dirname(file)), { recursive: true });
|
|
66
|
-
writeFileSync(join(cwd, file), date);
|
|
67
|
-
sh(cwd, "add", "-A");
|
|
68
|
-
execFileSync("git", ["commit", "-qm", file], {
|
|
69
|
-
cwd,
|
|
70
|
-
env: { ...process.env, GIT_COMMITTER_DATE: date, GIT_AUTHOR_DATE: date },
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
it("deepens a shallow clone past commits that do not touch the path", () => {
|
|
75
|
-
dir = mkdtempSync(join(tmpdir(), "spec-date-"));
|
|
76
|
-
const upstream = join(dir, "upstream");
|
|
77
|
-
mkdirSync(upstream);
|
|
78
|
-
sh(upstream, "init", "-q", "-b", "main");
|
|
79
|
-
sh(upstream, "config", "user.email", "t@t");
|
|
80
|
-
sh(upstream, "config", "user.name", "t");
|
|
81
|
-
sh(upstream, "config", "uploadpack.allowFilter", "true");
|
|
82
|
-
commit(upstream, "specs/a.json", "2026-09-30T10:00:00Z");
|
|
83
|
-
commit(upstream, "specs/a.json", "2026-10-03T23:30:00-05:00");
|
|
84
|
-
commit(upstream, ".meta/x.ts", "2026-10-05T10:00:00Z");
|
|
85
|
-
sh(dir, "clone", "-q", "--depth=1", `file://${upstream}`, "mirror");
|
|
86
|
-
// 23:30 at UTC-5 is the next day in UTC.
|
|
87
|
-
expect(lastChangeDate(join(dir, "mirror"), "specs")).toBe("2026-10-04");
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { generateService, type SdkSpec } from "./generator.ts";
|
|
3
|
-
|
|
4
|
-
const primitiveUnionModel = (kind: "enum" | "intEnum", request: boolean) => ({
|
|
5
|
-
smithy: "2.0",
|
|
6
|
-
shapes: {
|
|
7
|
-
"com.example.union#Example": {
|
|
8
|
-
type: "service",
|
|
9
|
-
version: "2024-01-01",
|
|
10
|
-
operations: [{ target: "com.example.union#GetValue" }],
|
|
11
|
-
},
|
|
12
|
-
"com.example.union#GetValue": {
|
|
13
|
-
type: "operation",
|
|
14
|
-
input: { target: "com.example.union#Request" },
|
|
15
|
-
output: { target: "com.example.union#Response" },
|
|
16
|
-
traits: { "smithy.api#http": { method: "POST", uri: "/value" } },
|
|
17
|
-
},
|
|
18
|
-
"com.example.union#Request": {
|
|
19
|
-
type: "structure",
|
|
20
|
-
traits: { "smithy.api#input": {} },
|
|
21
|
-
members: request ? { value: { target: "com.example.union#Value" } } : {},
|
|
22
|
-
},
|
|
23
|
-
"com.example.union#Response": {
|
|
24
|
-
type: "structure",
|
|
25
|
-
members: { value: { target: "com.example.union#Value" } },
|
|
26
|
-
},
|
|
27
|
-
"com.example.union#Mode": {
|
|
28
|
-
type: kind,
|
|
29
|
-
members: {
|
|
30
|
-
STOP: {
|
|
31
|
-
target: "smithy.api#Unit",
|
|
32
|
-
traits: { "smithy.api#enumValue": kind === "enum" ? "stop" : 1 },
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
"com.example.union#Value": {
|
|
37
|
-
type: "union",
|
|
38
|
-
members: {
|
|
39
|
-
mode: { target: "com.example.union#Mode" },
|
|
40
|
-
legacy: { target: "smithy.api#Boolean" },
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const spec: SdkSpec = {
|
|
47
|
-
unionStyle: "primitive",
|
|
48
|
-
operationDecl: {
|
|
49
|
-
contextType: "ExampleContext",
|
|
50
|
-
commonErrorType: "ExampleError",
|
|
51
|
-
commonErrorClasses: [],
|
|
52
|
-
protocol: "ExampleProtocol",
|
|
53
|
-
retry: "Retry.Retry",
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
describe("operation protocol overrides", () => {
|
|
58
|
-
for (const retry of [undefined, "Retry.Retry"]) {
|
|
59
|
-
for (const overridden of [false, true]) {
|
|
60
|
-
test(`${overridden ? "overridden" : "default"} protocol with ${retry ? "configured" : "disabled"} retries`, () => {
|
|
61
|
-
const { code } = generateService(primitiveUnionModel("enum", false), {
|
|
62
|
-
...spec,
|
|
63
|
-
operationDecl: {
|
|
64
|
-
contextType: "ExampleContext",
|
|
65
|
-
commonErrorType: "ExampleError",
|
|
66
|
-
commonErrorClasses: [],
|
|
67
|
-
protocol: "ExampleProtocol",
|
|
68
|
-
retry,
|
|
69
|
-
overrides: () =>
|
|
70
|
-
overridden ? { contextType: "PublicContext", protocol: "PublicProtocol" } : undefined,
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
expect(code).toContain(` protocol: ${overridden ? "PublicProtocol" : "ExampleProtocol"},`);
|
|
74
|
-
expect(code).toContain(` ${overridden ? "PublicContext" : "ExampleContext"}\n>`);
|
|
75
|
-
if (retry) expect(code).toContain(` retry: ${retry},`);
|
|
76
|
-
else expect(code).not.toContain(" retry:");
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe("primitive union generation", () => {
|
|
83
|
-
for (const kind of ["enum", "intEnum"] as const) {
|
|
84
|
-
for (const request of [false, true]) {
|
|
85
|
-
test(`${kind}/Boolean stays open when ${request ? "request-reachable" : "response-only"}`, () => {
|
|
86
|
-
const { code } = generateService(primitiveUnionModel(kind, request), spec);
|
|
87
|
-
const primitive = kind === "enum" ? "string" : "number";
|
|
88
|
-
expect(code).toContain(`export type Value = Mode | (${primitive} & {}) | boolean;`);
|
|
89
|
-
expect(code).toContain(
|
|
90
|
-
"export const Value: S.Codec<Value> = /*@__PURE__*/ S.Union([Mode, S.Boolean]);",
|
|
91
|
-
);
|
|
92
|
-
expect(code).toContain(
|
|
93
|
-
kind === "enum" ? "export const Mode = S.String;" : "export const Mode = S.Number;",
|
|
94
|
-
);
|
|
95
|
-
expect(code).not.toContain("export type Value = Mode | boolean;");
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
test("opaque-cases retains its existing primitive union codec", () => {
|
|
101
|
-
const { code } = generateService(primitiveUnionModel("enum", false), {
|
|
102
|
-
...spec,
|
|
103
|
-
unionStyle: "opaque-cases",
|
|
104
|
-
});
|
|
105
|
-
expect(code).toContain("export type Value = Mode | boolean;");
|
|
106
|
-
expect(code).toContain(
|
|
107
|
-
"export const Value = /*@__PURE__*/ S.Unknown.pipe(T.UnionCases([[],[]]));",
|
|
108
|
-
);
|
|
109
|
-
expect(code).not.toContain("S.Union([Mode, S.Boolean])");
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("primitive union emission requires an explicit style", () => {
|
|
113
|
-
expect(() =>
|
|
114
|
-
generateService(primitiveUnionModel("enum", false), {
|
|
115
|
-
...spec,
|
|
116
|
-
unionStyle: undefined,
|
|
117
|
-
}),
|
|
118
|
-
).toThrow("no union emission configured for shape com.example.union#Value");
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("primitive style rejects object cases", () => {
|
|
122
|
-
const model = primitiveUnionModel("enum", false);
|
|
123
|
-
model.shapes["com.example.union#Value"].members.mode.target = "com.example.union#Request";
|
|
124
|
-
expect(() => generateService(model, spec)).toThrow(
|
|
125
|
-
"no union emission configured for shape com.example.union#Value",
|
|
126
|
-
);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test("custom union emission retains precedence", () => {
|
|
130
|
-
const { code } = generateService(primitiveUnionModel("enum", false), {
|
|
131
|
-
...spec,
|
|
132
|
-
union: ({ name }) => [`export type ${name} = CustomUnion;`],
|
|
133
|
-
});
|
|
134
|
-
expect(code).toContain("export type Value = CustomUnion;");
|
|
135
|
-
expect(code).not.toContain("S.Union([Mode, S.Boolean])");
|
|
136
|
-
});
|
|
137
|
-
});
|