@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
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { stripTypeScriptTypes } from "node:module";
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { applyOperation } from "../json-patch.ts";
|
|
4
|
-
import {
|
|
5
|
-
convertGraphQLClient,
|
|
6
|
-
generateGraphQLClient,
|
|
7
|
-
graphqlTypeString,
|
|
8
|
-
validateGraphQLModel,
|
|
9
|
-
} from "./graphql-client.ts";
|
|
10
|
-
|
|
11
|
-
const named = (name: string, kind = "OBJECT") => ({ kind, name });
|
|
12
|
-
const required = (ofType: object) => ({ kind: "NON_NULL", ofType });
|
|
13
|
-
const field = (name: string, type: object, args: object[] = []) => ({
|
|
14
|
-
name,
|
|
15
|
-
type,
|
|
16
|
-
args,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const fixture = {
|
|
20
|
-
queryType: { name: "Query" },
|
|
21
|
-
mutationType: { name: "Mutation" },
|
|
22
|
-
types: [
|
|
23
|
-
{ kind: "SCALAR", name: "String" },
|
|
24
|
-
{ kind: "SCALAR", name: "Int" },
|
|
25
|
-
{
|
|
26
|
-
kind: "OBJECT",
|
|
27
|
-
name: "Query",
|
|
28
|
-
fields: [
|
|
29
|
-
field("project", required(named("Project")), [
|
|
30
|
-
{ name: "id", type: required(named("String", "SCALAR")) },
|
|
31
|
-
]),
|
|
32
|
-
field("me", required(named("User"))),
|
|
33
|
-
field("projects", required(named("ProjectConnection")), [
|
|
34
|
-
{
|
|
35
|
-
name: "first",
|
|
36
|
-
type: named("Int", "SCALAR"),
|
|
37
|
-
},
|
|
38
|
-
]),
|
|
39
|
-
],
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
kind: "OBJECT",
|
|
43
|
-
name: "Mutation",
|
|
44
|
-
fields: [
|
|
45
|
-
field("projectCreate", named("Project"), [
|
|
46
|
-
{ name: "name", type: required(named("String", "SCALAR")) },
|
|
47
|
-
]),
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
kind: "OBJECT",
|
|
52
|
-
name: "Project",
|
|
53
|
-
fields: [
|
|
54
|
-
field("id", required(named("String", "SCALAR"))),
|
|
55
|
-
field("name", required(named("String", "SCALAR"))),
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
kind: "OBJECT",
|
|
60
|
-
name: "User",
|
|
61
|
-
fields: [
|
|
62
|
-
field("email", required(named("String", "SCALAR"))),
|
|
63
|
-
field("name", named("String", "SCALAR")),
|
|
64
|
-
field("projects", required(named("ProjectConnection")), [
|
|
65
|
-
{ name: "first", type: named("Int", "SCALAR") },
|
|
66
|
-
]),
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
kind: "OBJECT",
|
|
71
|
-
name: "ProjectConnection",
|
|
72
|
-
fields: [
|
|
73
|
-
field("edges", required({ kind: "LIST", ofType: named("ProjectEdge") })),
|
|
74
|
-
field("pageInfo", required(named("PageInfo"))),
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
kind: "OBJECT",
|
|
79
|
-
name: "ProjectEdge",
|
|
80
|
-
fields: [
|
|
81
|
-
field("cursor", required(named("String", "SCALAR"))),
|
|
82
|
-
field("node", required(named("Project"))),
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
kind: "OBJECT",
|
|
87
|
-
name: "PageInfo",
|
|
88
|
-
fields: [
|
|
89
|
-
field("endCursor", named("String", "SCALAR")),
|
|
90
|
-
field("hasNextPage", required(named("Boolean", "SCALAR"))),
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
{ kind: "SCALAR", name: "Boolean" },
|
|
94
|
-
],
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const options = {
|
|
98
|
-
transportImport: "./transport.ts",
|
|
99
|
-
requirementsImport: "./transport.ts",
|
|
100
|
-
requirementsType: "Requirements",
|
|
101
|
-
sdkName: "Railway",
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
describe("GraphQL Query SDK generator", () => {
|
|
105
|
-
test("emits TypeMeta, interfaces, and named roots on the SDK object", () => {
|
|
106
|
-
const model = convertGraphQLClient(fixture);
|
|
107
|
-
const output = generateGraphQLClient(model, options);
|
|
108
|
-
expect(output).toContain("export interface Project");
|
|
109
|
-
expect(output).toContain("export interface User");
|
|
110
|
-
expect(output).toContain('export const Project: TypeMeta = { name: "Project", fields: {} };');
|
|
111
|
-
expect(output).toContain("export const Railway = {");
|
|
112
|
-
expect(output).toContain('root("query", "me", User, undefined, undefined, globalErrors)');
|
|
113
|
-
expect(output).toContain('root("query", "project", Project');
|
|
114
|
-
expect(output).toContain('rootConnection("query", "projects", Project');
|
|
115
|
-
expect(output).toContain("Query<ReadonlyArray<Project>, RailwayGlobalError>");
|
|
116
|
-
expect(output).toContain('connectionField("projects", Project, { first: "Int" })');
|
|
117
|
-
expect(output).toContain('root("mutation", "projectCreate", Project');
|
|
118
|
-
// Nullable GraphQL types include null; non-null ones do not.
|
|
119
|
-
expect(output).toContain("readonly name: string | null;");
|
|
120
|
-
expect(output).toContain("readonly email: string;");
|
|
121
|
-
expect(output).toContain("Query<Project | null, RailwayGlobalError>");
|
|
122
|
-
expect(output).toContain("args?: { readonly first?: number | null }");
|
|
123
|
-
expect(output).toContain('from "@distilled.cloud/core/graphql"');
|
|
124
|
-
expect(() => stripTypeScriptTypes(output)).not.toThrow();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test("emits error classes and scopes them to roots", () => {
|
|
128
|
-
const model = convertGraphQLClient(fixture);
|
|
129
|
-
for (const operation of [
|
|
130
|
-
{
|
|
131
|
-
op: "add" as const,
|
|
132
|
-
path: "/errors/RailwayNotFound",
|
|
133
|
-
value: {
|
|
134
|
-
description: "Missing.",
|
|
135
|
-
category: "notFound",
|
|
136
|
-
matchers: [{ code: "NOT_FOUND" }],
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
op: "add" as const,
|
|
141
|
-
path: "/errors/RailwayRateLimited",
|
|
142
|
-
value: {
|
|
143
|
-
category: "throttling",
|
|
144
|
-
retryable: true,
|
|
145
|
-
matchers: [{ code: "RATE_LIMITED" }],
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
op: "add" as const,
|
|
150
|
-
path: "/globalErrors/-",
|
|
151
|
-
value: "RailwayRateLimited",
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
op: "add" as const,
|
|
155
|
-
path: "/types/Query/fields/project/errors/-",
|
|
156
|
-
value: "RailwayNotFound",
|
|
157
|
-
},
|
|
158
|
-
])
|
|
159
|
-
applyOperation(model, operation);
|
|
160
|
-
const output = generateGraphQLClient(model, options);
|
|
161
|
-
expect(output).toContain(
|
|
162
|
-
'export class RailwayNotFound extends S.TaggedError<RailwayNotFound>()("RailwayNotFound", errorFields).pipe(Category.withNotFoundError) {}',
|
|
163
|
-
);
|
|
164
|
-
expect(output).toContain(
|
|
165
|
-
"Category.withThrottlingError, Category.withRetryable({ throttling: true })",
|
|
166
|
-
);
|
|
167
|
-
expect(output).toContain(
|
|
168
|
-
'errorSpec(RailwayRateLimited, "RailwayRateLimited", [{"code":"RATE_LIMITED"}], { retryable: true, global: true })',
|
|
169
|
-
);
|
|
170
|
-
expect(output).toContain("export type RailwayGlobalError = RailwayRateLimited;");
|
|
171
|
-
expect(output).toContain("Query<Project, RailwayNotFound | RailwayGlobalError>");
|
|
172
|
-
expect(output).toContain("[RailwayNotFoundSpec, ...globalErrors]");
|
|
173
|
-
expect(output).toContain("Query<User, RailwayGlobalError>");
|
|
174
|
-
expect(() => stripTypeScriptTypes(output)).not.toThrow();
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test("unknown coordinates fail validateGraphQLModel", () => {
|
|
178
|
-
const model = convertGraphQLClient(fixture);
|
|
179
|
-
applyOperation(model, {
|
|
180
|
-
op: "add",
|
|
181
|
-
path: "/types/Project/fields/id/errors/-",
|
|
182
|
-
value: "MissingError",
|
|
183
|
-
});
|
|
184
|
-
expect(() => validateGraphQLModel(model)).toThrow(
|
|
185
|
-
"Project.id: unknown GraphQL error MissingError",
|
|
186
|
-
);
|
|
187
|
-
expect(() => graphqlTypeString({ kind: "NON_NULL" })).toThrow("Incomplete GraphQL NON_NULL");
|
|
188
|
-
});
|
|
189
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { convertOpenApiToSmithy } from "./openapi.ts";
|
|
3
|
-
|
|
4
|
-
const model = (
|
|
5
|
-
schema: unknown,
|
|
6
|
-
mediaType = "multipart/form-data",
|
|
7
|
-
responseSchema: unknown = { type: "string", format: "binary" },
|
|
8
|
-
components: Record<string, unknown> = {},
|
|
9
|
-
options: { binaryTypes?: boolean } = { binaryTypes: true },
|
|
10
|
-
) =>
|
|
11
|
-
convertOpenApiToSmithy(
|
|
12
|
-
{
|
|
13
|
-
openapi: "3.0.3",
|
|
14
|
-
info: { title: "Binary", version: "1" },
|
|
15
|
-
components,
|
|
16
|
-
paths: {
|
|
17
|
-
"/files": {
|
|
18
|
-
post: {
|
|
19
|
-
operationId: "uploadFile",
|
|
20
|
-
requestBody: { content: { [mediaType]: { schema } } },
|
|
21
|
-
responses: {
|
|
22
|
-
"200": {
|
|
23
|
-
content: {
|
|
24
|
-
"application/octet-stream": {
|
|
25
|
-
schema: responseSchema,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
{ namespace: "com.example.binary", serviceName: "Binary", ...options },
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
describe("OpenAPI binary contracts", () => {
|
|
38
|
-
for (const options of [{}, { binaryTypes: false }]) {
|
|
39
|
-
test(`binary conversion preserves existing contracts with ${JSON.stringify(options)}`, () => {
|
|
40
|
-
const result = model(
|
|
41
|
-
{
|
|
42
|
-
type: "object",
|
|
43
|
-
properties: {
|
|
44
|
-
zip: { type: "string", format: "binary" },
|
|
45
|
-
archive: { $ref: "#/components/schemas/Archive" },
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
"multipart/form-data",
|
|
49
|
-
{ $ref: "#/components/schemas/Archive" },
|
|
50
|
-
{ schemas: { Archive: { type: "string", format: "binary" } } },
|
|
51
|
-
options,
|
|
52
|
-
);
|
|
53
|
-
const request = result.shapes["com.example.binary#UploadFileRequest"];
|
|
54
|
-
expect(request.members.zip.target).toBe("smithy.api#String");
|
|
55
|
-
expect(request.members.archive.target).toBe("smithy.api#String");
|
|
56
|
-
expect(result.shapes["com.example.binary#UploadFile"].output.target).toBe("smithy.api#Unit");
|
|
57
|
-
expect(result.shapes["com.example.binary#UploadFileResponse"]).toBeUndefined();
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
test("component-referenced binary responses retain the original reference's nullability", () => {
|
|
62
|
-
const result = model(
|
|
63
|
-
{ type: "object" },
|
|
64
|
-
"application/json",
|
|
65
|
-
{ $ref: "#/components/schemas/Archive", nullable: true },
|
|
66
|
-
{ schemas: { Archive: { type: "string", format: "binary" } } },
|
|
67
|
-
);
|
|
68
|
-
const body = result.shapes["com.example.binary#UploadFileResponse"].members.body;
|
|
69
|
-
expect(body.target).toBe("smithy.api#Blob");
|
|
70
|
-
expect(body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
|
|
71
|
-
expect(body.traits["com.distilled.openapi#nullable"]).toEqual({});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("multipart binary fields become blobs, not text or base64", () => {
|
|
75
|
-
const result = model({
|
|
76
|
-
type: "object",
|
|
77
|
-
properties: {
|
|
78
|
-
zip: { type: "string", format: "binary" },
|
|
79
|
-
encoded: { type: "string", format: "byte" },
|
|
80
|
-
environment: { type: "string" },
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
const request = result.shapes["com.example.binary#UploadFileRequest"];
|
|
84
|
-
expect(request.members.zip.target).toBe("smithy.api#Blob");
|
|
85
|
-
expect(request.members.encoded.target).toBe("smithy.api#String");
|
|
86
|
-
expect(request.members.environment.target).toBe("smithy.api#String");
|
|
87
|
-
const response = result.shapes["com.example.binary#UploadFileResponse"];
|
|
88
|
-
expect(response.members.body.target).toBe("smithy.api#Blob");
|
|
89
|
-
expect(response.members.body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
mkdirSync,
|
|
4
|
-
mkdtempSync,
|
|
5
|
-
readdirSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
rmSync,
|
|
8
|
-
writeFileSync,
|
|
9
|
-
} from "node:fs";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { afterEach, describe, expect, test } from "vitest";
|
|
13
|
-
import { auditPackage } from "./patch-audit.ts";
|
|
14
|
-
|
|
15
|
-
const dirs: string[] = [];
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
|
|
22
|
-
const PATCHES_TS = join(import.meta.dirname, "patches.ts");
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A package: `spec.json` lists field names, and every field becomes a
|
|
26
|
-
* member of `x#Thing`. `patches/spec/` edit the spec in the convert script
|
|
27
|
-
* itself (the way Railway patches its GraphQL schema, out of
|
|
28
|
-
* finalizeConvert's reach); `patches/svc/` are Smithy ops applied in
|
|
29
|
-
* finalizeConvert, whose transform drops a member named `dropped`.
|
|
30
|
-
*/
|
|
31
|
-
const convertFixture = (patches: Record<string, unknown[]>): string => {
|
|
32
|
-
const parent = mkdtempSync(join(tmpdir(), "patch-audit-convert-"));
|
|
33
|
-
dirs.push(parent);
|
|
34
|
-
const root = join(parent, "pkg");
|
|
35
|
-
mkdirSync(join(root, "scripts"), { recursive: true });
|
|
36
|
-
writeFileSync(
|
|
37
|
-
join(root, "package.json"),
|
|
38
|
-
JSON.stringify({ name: "fixture", scripts: { convert: "node scripts/convert.ts" } }),
|
|
39
|
-
);
|
|
40
|
-
writeFileSync(join(root, "spec.json"), JSON.stringify({ fields: { a: true } }));
|
|
41
|
-
writeFileSync(
|
|
42
|
-
join(root, "scripts", "convert.ts"),
|
|
43
|
-
`
|
|
44
|
-
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
45
|
-
import { join } from "node:path";
|
|
46
|
-
import { applyRfc6902Files, finalizeConvert, isSmithyPatchPath, listRfc6902PatchFiles } from ${JSON.stringify(PATCHES_TS)};
|
|
47
|
-
const root = join(import.meta.dirname, "..");
|
|
48
|
-
const spec = JSON.parse(readFileSync(join(root, "spec.json"), "utf8"));
|
|
49
|
-
const files = await listRfc6902PatchFiles(join(root, "patches", "spec"));
|
|
50
|
-
const applied = await applyRfc6902Files(spec, files, { include: (op) => !isSmithyPatchPath(op.path) });
|
|
51
|
-
if (applied.errors.length) throw new Error(applied.errors.join("\\n"));
|
|
52
|
-
const members = Object.fromEntries(Object.keys(spec.fields).map((k) => [k, { target: "smithy.api#String" }]));
|
|
53
|
-
mkdirSync(join(root, ".generated-specs"), { recursive: true });
|
|
54
|
-
writeFileSync(join(root, ".generated-specs", "svc.json"), JSON.stringify({ smithy: "2.0", shapes: { "x#Thing": { type: "structure", members } } }));
|
|
55
|
-
await finalizeConvert({
|
|
56
|
-
root,
|
|
57
|
-
operationNaming: "as-is",
|
|
58
|
-
transform: (model) => { delete model.shapes["x#Thing"].members.dropped; },
|
|
59
|
-
});
|
|
60
|
-
`,
|
|
61
|
-
);
|
|
62
|
-
for (const [key, ops] of Object.entries(patches)) {
|
|
63
|
-
const dir = key.startsWith("spec/") ? "spec" : "svc";
|
|
64
|
-
mkdirSync(join(root, "patches", dir), { recursive: true });
|
|
65
|
-
const name = key.replace(/^spec\//, "");
|
|
66
|
-
writeFileSync(join(root, "patches", dir, name), JSON.stringify({ patches: ops }));
|
|
67
|
-
}
|
|
68
|
-
mkdirSync(join(root, ".generated-specs"));
|
|
69
|
-
writeFileSync(join(root, ".generated-specs", "svc.json"), "committed\n");
|
|
70
|
-
return root;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const addField = (name: string) => ({ op: "add", path: `/fields/${name}`, value: true });
|
|
74
|
-
const addMember = (name: string) => ({
|
|
75
|
-
op: "add",
|
|
76
|
-
path: `/shapes/x#Thing/members/${name}`,
|
|
77
|
-
value: { target: "smithy.api#String" },
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe("convert-stage patch audit", () => {
|
|
81
|
-
test("judges Smithy files in memory and the rest by convert", async () => {
|
|
82
|
-
const root = convertFixture({
|
|
83
|
-
"spec/1-spec.json": [addField("s")],
|
|
84
|
-
"2-member.json": [addMember("b")],
|
|
85
|
-
"3-noop.json": [{ op: "replace", path: "/shapes/x#Thing/type", value: "structure" }],
|
|
86
|
-
"4-dropped.json": [addMember("dropped")],
|
|
87
|
-
"5-uses-b.json": [{ op: "add", path: "/shapes/x#Thing/members/b/traits", value: {} }],
|
|
88
|
-
});
|
|
89
|
-
const result = await auditPackage(root, { jobs: 2 });
|
|
90
|
-
if (result.kind !== "audited") throw new Error(result.reason);
|
|
91
|
-
expect(Object.fromEntries(result.files.map((f) => [f.file.key, f.verdict]))).toEqual({
|
|
92
|
-
"spec/1-spec.json": { kind: "needed", diff: ["+ Thing/members/s"] },
|
|
93
|
-
"svc/2-member.json": { kind: "depended", error: expect.stringMatching(/members\/b/) },
|
|
94
|
-
"svc/3-noop.json": { kind: "unused" },
|
|
95
|
-
// The transform removes it again, so it changes nothing.
|
|
96
|
-
"svc/4-dropped.json": { kind: "unused" },
|
|
97
|
-
"svc/5-uses-b.json": { kind: "needed", diff: ["+ Thing/members/b/traits"] },
|
|
98
|
-
});
|
|
99
|
-
expect(result.judged).toEqual({ inMemory: 4, perFile: 1 });
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("--ops in memory finds the dead op", async () => {
|
|
103
|
-
const root = convertFixture({
|
|
104
|
-
"mixed.json": [
|
|
105
|
-
addMember("b"),
|
|
106
|
-
{ op: "replace", path: "/shapes/x#Thing/type", value: "structure" },
|
|
107
|
-
],
|
|
108
|
-
});
|
|
109
|
-
const result = await auditPackage(root, { ops: true, jobs: 1 });
|
|
110
|
-
if (result.kind !== "audited") throw new Error(result.reason);
|
|
111
|
-
expect(result.files[0]!.deadOps).toEqual([1]);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test("a file that only orders keys is needed", async () => {
|
|
115
|
-
const root = convertFixture({
|
|
116
|
-
"1-member.json": [addMember("b")],
|
|
117
|
-
"2-order.json": [
|
|
118
|
-
{
|
|
119
|
-
op: "move",
|
|
120
|
-
from: "/shapes/x#Thing/members/b",
|
|
121
|
-
path: "/shapes/x#Thing/members/b",
|
|
122
|
-
before: "a",
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
});
|
|
126
|
-
const result = await auditPackage(root, { jobs: 1 });
|
|
127
|
-
if (result.kind !== "audited") throw new Error(result.reason);
|
|
128
|
-
expect(result.files.find((f) => f.file.key === "svc/2-order.json")!.verdict).toEqual({
|
|
129
|
-
kind: "needed",
|
|
130
|
-
diff: ["(key order only)"],
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("leaves the package as it was and removes its scratch copies", async () => {
|
|
135
|
-
const root = convertFixture({
|
|
136
|
-
"member.json": [addMember("b")],
|
|
137
|
-
"spec/s.json": [addField("s")],
|
|
138
|
-
});
|
|
139
|
-
const result = await auditPackage(root, { jobs: 2 });
|
|
140
|
-
expect(result.kind).toBe("audited");
|
|
141
|
-
expect(readFileSync(join(root, ".generated-specs", "svc.json"), "utf8")).toBe("committed\n");
|
|
142
|
-
expect(readdirSync(join(root, ".."))).toEqual(["pkg"]);
|
|
143
|
-
expect(existsSync(join(root, ".audit-request.json"))).toBe(false);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test("a patch that changes nothing has no effect", async () => {
|
|
147
|
-
const root = convertFixture({
|
|
148
|
-
"noop.json": [{ op: "replace", path: "/shapes/x#Thing/type", value: "structure" }],
|
|
149
|
-
});
|
|
150
|
-
const result = await auditPackage(root, { jobs: 1 });
|
|
151
|
-
if (result.kind !== "audited") throw new Error(result.reason);
|
|
152
|
-
expect(result.files[0]!.verdict).toEqual({ kind: "unused" });
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test("a baseline that fails to convert is skipped", async () => {
|
|
156
|
-
const root = convertFixture({ "stale.json": [{ op: "remove", path: "/shapes/x#Gone" }] });
|
|
157
|
-
const result = await auditPackage(root, { jobs: 1 });
|
|
158
|
-
expect(result.kind).toBe("skipped");
|
|
159
|
-
});
|
|
160
|
-
});
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { mkdtempSync, mkdirSync, readFileSync, 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 {
|
|
6
|
-
FINALIZED_KEY,
|
|
7
|
-
SKIP_PATCHES_ENV,
|
|
8
|
-
applyRfc6902Files,
|
|
9
|
-
danglingTargets,
|
|
10
|
-
finalizeConvert,
|
|
11
|
-
listRfc6902PatchFiles,
|
|
12
|
-
syncServiceOperations,
|
|
13
|
-
} from "./patches.ts";
|
|
14
|
-
|
|
15
|
-
const model = () => ({
|
|
16
|
-
smithy: "2.0",
|
|
17
|
-
shapes: {
|
|
18
|
-
"ns#Svc": {
|
|
19
|
-
type: "service",
|
|
20
|
-
operations: [{ target: "ns#AppsList" }, { target: "ns#AppsGet" }],
|
|
21
|
-
},
|
|
22
|
-
"ns#AppsList": {
|
|
23
|
-
type: "operation",
|
|
24
|
-
input: { target: "ns#AppsListRequest" },
|
|
25
|
-
output: { target: "smithy.api#Unit" },
|
|
26
|
-
},
|
|
27
|
-
"ns#AppsListRequest": { type: "structure", members: {} },
|
|
28
|
-
"ns#AppsGet": {
|
|
29
|
-
type: "operation",
|
|
30
|
-
input: { target: "smithy.api#Unit" },
|
|
31
|
-
output: { target: "smithy.api#Unit" },
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const scaffold = (patches?: Record<string, unknown>) => {
|
|
37
|
-
const root = mkdtempSync(join(tmpdir(), "finalize-"));
|
|
38
|
-
mkdirSync(join(root, ".generated-specs"));
|
|
39
|
-
writeFileSync(join(root, ".generated-specs", "svc.json"), JSON.stringify(model()));
|
|
40
|
-
if (patches) {
|
|
41
|
-
mkdirSync(join(root, "patches", "svc"), { recursive: true });
|
|
42
|
-
writeFileSync(join(root, "patches", "svc", "a.json"), JSON.stringify(patches));
|
|
43
|
-
}
|
|
44
|
-
return root;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const read = (root: string) =>
|
|
48
|
-
JSON.parse(readFileSync(join(root, ".generated-specs", "svc.json"), "utf8"));
|
|
49
|
-
|
|
50
|
-
describe("finalizeConvert", () => {
|
|
51
|
-
test("renames, syncs the service list, stamps the marker", async () => {
|
|
52
|
-
const root = scaffold();
|
|
53
|
-
await finalizeConvert({ root });
|
|
54
|
-
const m = read(root);
|
|
55
|
-
expect(Object.keys(m.shapes).sort()).toEqual(
|
|
56
|
-
["ns#Svc", "ns#ListApps", "ns#ListAppsRequest", "ns#GetApp"].sort(),
|
|
57
|
-
);
|
|
58
|
-
expect(m.shapes["ns#Svc"].operations).toEqual([
|
|
59
|
-
{ target: "ns#ListApps" },
|
|
60
|
-
{ target: "ns#GetApp" },
|
|
61
|
-
]);
|
|
62
|
-
expect(m.metadata[FINALIZED_KEY]).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("refuses a second pass", async () => {
|
|
66
|
-
const root = scaffold();
|
|
67
|
-
await finalizeConvert({ root });
|
|
68
|
-
await expect(finalizeConvert({ root })).rejects.toThrow(/already finalized/);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("applies Smithy patches and repairs the service list after a move", async () => {
|
|
72
|
-
const root = scaffold({
|
|
73
|
-
patches: [{ op: "move", from: "/shapes/ns#AppsGet", path: "/shapes/ns#FetchApp" }],
|
|
74
|
-
});
|
|
75
|
-
await finalizeConvert({ root });
|
|
76
|
-
const m = read(root);
|
|
77
|
-
expect(m.shapes["ns#FetchApp"]).toBeDefined();
|
|
78
|
-
expect(m.shapes["ns#Svc"].operations.map((o: any) => o.target)).toEqual([
|
|
79
|
-
"ns#ListApps",
|
|
80
|
-
"ns#FetchApp",
|
|
81
|
-
]);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("rejects a patch that edits the spec", async () => {
|
|
85
|
-
const root = scaffold({
|
|
86
|
-
patches: [{ op: "add", path: "/paths/~1apps/get/responses/404", value: {} }],
|
|
87
|
-
});
|
|
88
|
-
await expect(finalizeConvert({ root })).rejects.toThrow(/target the Smithy model/);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("fails on a stale patch pointer by default", async () => {
|
|
92
|
-
const root = scaffold({
|
|
93
|
-
patches: [{ op: "remove", path: "/shapes/ns#Missing" }],
|
|
94
|
-
});
|
|
95
|
-
await expect(finalizeConvert({ root })).rejects.toThrow(/failed/);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("fails on dangling targets and leaves the model unstamped", async () => {
|
|
99
|
-
const root = scaffold({
|
|
100
|
-
patches: [
|
|
101
|
-
{
|
|
102
|
-
op: "replace",
|
|
103
|
-
path: "/shapes/ns#AppsList/output/target",
|
|
104
|
-
value: "ns#Nope",
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
});
|
|
108
|
-
await expect(finalizeConvert({ root })).rejects.toThrow(/do not exist/);
|
|
109
|
-
expect(read(root).metadata?.[FINALIZED_KEY]).toBeUndefined();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe("danglingTargets", () => {
|
|
114
|
-
test("ignores prelude ids", () => {
|
|
115
|
-
expect(danglingTargets(model())).toEqual([]);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("syncServiceOperations", () => {
|
|
120
|
-
test("drops missing and appends unlisted, keeping order", () => {
|
|
121
|
-
const m = model();
|
|
122
|
-
delete (m.shapes as any)["ns#AppsGet"];
|
|
123
|
-
(m.shapes as any)["ns#Zed"] = { type: "operation" };
|
|
124
|
-
expect(syncServiceOperations(m)).toBe(1);
|
|
125
|
-
expect((m.shapes as any)["ns#Svc"].operations).toEqual([
|
|
126
|
-
{ target: "ns#AppsList" },
|
|
127
|
-
{ target: "ns#Zed" },
|
|
128
|
-
]);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe(SKIP_PATCHES_ENV, () => {
|
|
133
|
-
afterEach(() => {
|
|
134
|
-
delete process.env[SKIP_PATCHES_ENV];
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const patchDir = () => {
|
|
138
|
-
const dir = mkdtempSync(join(tmpdir(), "skip-"));
|
|
139
|
-
mkdirSync(join(dir, "svc"));
|
|
140
|
-
writeFileSync(
|
|
141
|
-
join(dir, "svc", "a.json"),
|
|
142
|
-
JSON.stringify({
|
|
143
|
-
patches: [
|
|
144
|
-
{ op: "add", path: "/x", value: 1 },
|
|
145
|
-
{ op: "add", path: "/y", value: 2 },
|
|
146
|
-
],
|
|
147
|
-
}),
|
|
148
|
-
);
|
|
149
|
-
writeFileSync(
|
|
150
|
-
join(dir, "svc", "b.json"),
|
|
151
|
-
JSON.stringify({ patches: [{ op: "add", path: "/z", value: 3 }] }),
|
|
152
|
-
);
|
|
153
|
-
return join(dir, "svc");
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
test("unset applies everything", async () => {
|
|
157
|
-
const target: Record<string, unknown> = {};
|
|
158
|
-
const files = await listRfc6902PatchFiles(patchDir());
|
|
159
|
-
expect(files.map((f) => f.split("/").pop())).toEqual(["a.json", "b.json"]);
|
|
160
|
-
expect((await applyRfc6902Files(target, files)).applied).toBe(3);
|
|
161
|
-
expect(target).toEqual({ x: 1, y: 2, z: 3 });
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test("all lists no files", async () => {
|
|
165
|
-
process.env[SKIP_PATCHES_ENV] = "all";
|
|
166
|
-
expect(await listRfc6902PatchFiles(patchDir())).toEqual([]);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test("a basename or a path suffix drops that file", async () => {
|
|
170
|
-
const dir = patchDir();
|
|
171
|
-
process.env[SKIP_PATCHES_ENV] = "a.json";
|
|
172
|
-
expect((await listRfc6902PatchFiles(dir)).map((f) => f.split("/").pop())).toEqual(["b.json"]);
|
|
173
|
-
process.env[SKIP_PATCHES_ENV] = "svc/b.json";
|
|
174
|
-
expect((await listRfc6902PatchFiles(dir)).map((f) => f.split("/").pop())).toEqual(["a.json"]);
|
|
175
|
-
process.env[SKIP_PATCHES_ENV] = "other/b.json";
|
|
176
|
-
expect((await listRfc6902PatchFiles(dir)).length).toBe(2);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test("<file>:<index> drops one op and keeps the rest of the file", async () => {
|
|
180
|
-
const dir = patchDir();
|
|
181
|
-
const files = await listRfc6902PatchFiles(dir);
|
|
182
|
-
process.env[SKIP_PATCHES_ENV] = "a.json:1";
|
|
183
|
-
const target: Record<string, unknown> = {};
|
|
184
|
-
const result = await applyRfc6902Files(target, files);
|
|
185
|
-
expect(result.applied).toBe(2);
|
|
186
|
-
expect(target).toEqual({ x: 1, z: 3 });
|
|
187
|
-
});
|
|
188
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "vitest";
|
|
2
|
-
import { generateService } from "./generator.ts";
|
|
3
|
-
|
|
4
|
-
test("imports only the pagination protocol when every operation uses it", () => {
|
|
5
|
-
const { code } = generateService(
|
|
6
|
-
{
|
|
7
|
-
smithy: "2.0",
|
|
8
|
-
shapes: {
|
|
9
|
-
"example#Service": {
|
|
10
|
-
type: "service",
|
|
11
|
-
version: "1",
|
|
12
|
-
operations: [{ target: "example#List" }],
|
|
13
|
-
},
|
|
14
|
-
"example#List": {
|
|
15
|
-
type: "operation",
|
|
16
|
-
input: { target: "example#Request" },
|
|
17
|
-
output: { target: "example#Response" },
|
|
18
|
-
traits: { "smithy.api#paginated": { mode: "single", items: "items" } },
|
|
19
|
-
},
|
|
20
|
-
"example#Request": { type: "structure", members: {} },
|
|
21
|
-
"example#Response": { type: "structure", members: { items: { target: "example#Items" } } },
|
|
22
|
-
"example#Items": { type: "list", member: { target: "smithy.api#String" } },
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
operationDecl: {
|
|
27
|
-
contextType: "OpContext",
|
|
28
|
-
commonErrorType: "OpError",
|
|
29
|
-
commonErrorClasses: [],
|
|
30
|
-
protocol: "DefaultProtocol",
|
|
31
|
-
retry: "Retry.Retry",
|
|
32
|
-
},
|
|
33
|
-
paginationProfiles: { default: { protocol: "PaginatedProtocol", itemsFallback: "items" } },
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
expect(code).toContain("protocol: PaginatedProtocol");
|
|
37
|
-
expect(code).toContain(" PaginatedProtocol,");
|
|
38
|
-
expect(code).not.toContain("DefaultProtocol");
|
|
39
|
-
});
|