@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
|
@@ -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
|
-
});
|
|
@@ -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
|
-
});
|