Skip to content

Commit 9661d39

Browse files
committed
codegen: use service closure to cache shape queries in schema generation
1 parent 7b82c53 commit 9661d39

File tree

13 files changed

+245
-488
lines changed

13 files changed

+245
-488
lines changed

private/my-local-model-schema/src/schemas/schemas_0.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const _fWMi = "fieldWithMessage";
2323
const _g = "gamma";
2424
const _hE = "httpError";
2525
const _i = "id";
26-
const _s = "smithy.ts.sdk.synthetic.org.xyz.v1";
27-
const _st = "streaming";
26+
const _s = "streaming";
27+
const _sm = "smithy.ts.sdk.synthetic.org.xyz.v1";
2828
const _t = "timestamp";
2929
const n0 = "org.xyz.v1";
3030

@@ -100,13 +100,13 @@ export var XYZServiceServiceException: StaticErrorSchema = [-3, n0, _XYZSSE,
100100
];
101101
TypeRegistry.for(n0).registerError(XYZServiceServiceException, __XYZServiceServiceException);
102102
export var __Unit = "unit" as const;
103-
export var XYZServiceSyntheticServiceException: StaticErrorSchema = [-3, _s, "XYZServiceSyntheticServiceException", 0, [], []];
104-
TypeRegistry.for(_s).registerError(XYZServiceSyntheticServiceException, __XYZServiceSyntheticServiceException);
105103
export var TradeEvents: StaticStructureSchema = [3, n0, _TE,
106-
{ [_st]: 1 },
104+
{ [_s]: 1 },
107105
[_a, _b, _g],
108106
[() => Alpha, () => __Unit, () => __Unit]
109107
];
108+
export var XYZServiceSyntheticServiceException: StaticErrorSchema = [-3, _sm, "XYZServiceSyntheticServiceException", 0, [], []];
109+
TypeRegistry.for(_sm).registerError(XYZServiceSyntheticServiceException, __XYZServiceSyntheticServiceException);
110110
export var GetNumbers: StaticOperationSchema = [9, n0, _GN,
111111
0, () => GetNumbersRequest, () => GetNumbersResponse
112112
];

private/my-local-model-schema/test/index-objects.spec.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import {
2+
CodedThrottlingError,
23
GetNumbersCommand,
4+
HaltError,
5+
MysteryThrottlingError,
6+
RetryableError,
37
TradeEventStreamCommand,
48
XYZService,
59
XYZServiceClient,
@@ -13,5 +17,10 @@ assert(typeof XYZService === "function");
1317
assert(typeof GetNumbersCommand === "function");
1418
assert(typeof TradeEventStreamCommand === "function");
1519
// errors
20+
assert(CodedThrottlingError.prototype instanceof XYZServiceServiceException);
21+
assert(HaltError.prototype instanceof XYZServiceServiceException);
22+
assert(MysteryThrottlingError.prototype instanceof XYZServiceServiceException);
23+
assert(RetryableError.prototype instanceof XYZServiceServiceException);
24+
assert(XYZServiceServiceException.prototype instanceof XYZServiceServiceException);
1625
assert(XYZServiceServiceException.prototype instanceof Error);
1726
console.log(`XYZService index test passed.`);

private/my-local-model-schema/test/index-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ export type {
1515
TradeEventStreamRequest,
1616
TradeEventStreamResponse,
1717
Unit,
18+
CodedThrottlingError,
19+
HaltError,
20+
MysteryThrottlingError,
21+
RetryableError,
22+
XYZServiceServiceException,
1823
XYZServiceServiceException,
1924
} from "../dist-types/index.d";

private/smithy-rpcv2-cbor-schema/test/index-objects.spec.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2+
ComplexError,
23
EmptyInputOutputCommand,
34
Float16Command,
45
FooEnum,
56
FractionalSecondsCommand,
67
GreetingWithErrorsCommand,
78
IntegerEnum,
9+
InvalidGreeting,
810
NoInputOutputCommand,
911
OperationWithDefaultsCommand,
1012
OptionalInputOutputCommand,
@@ -19,6 +21,7 @@ import {
1921
SparseNullsOperationCommand,
2022
TestEnum,
2123
TestIntEnum,
24+
ValidationException,
2225
} from "../dist-cjs/index.js";
2326
import assert from "node:assert";
2427
// clients
@@ -44,5 +47,8 @@ assert(typeof TestIntEnum === "object");
4447
assert(typeof FooEnum === "object");
4548
assert(typeof IntegerEnum === "object");
4649
// errors
50+
assert(ValidationException.prototype instanceof RpcV2ProtocolServiceException);
51+
assert(ComplexError.prototype instanceof RpcV2ProtocolServiceException);
52+
assert(InvalidGreeting.prototype instanceof RpcV2ProtocolServiceException);
4753
assert(RpcV2ProtocolServiceException.prototype instanceof Error);
4854
console.log(`RpcV2Protocol index test passed.`);

private/smithy-rpcv2-cbor-schema/test/index-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export type {
4545
TestIntEnum,
4646
FooEnum,
4747
IntegerEnum,
48+
Unit,
49+
ValidationExceptionField,
4850
ClientOptionalDefaults,
51+
ComplexNestedErrorData,
4952
Defaults,
5053
EmptyStructure,
5154
Float16Output,
@@ -64,5 +67,8 @@ export type {
6467
SparseNullsOperationInputOutput,
6568
StructureListMember,
6669
GreetingStruct,
70+
ValidationException,
71+
ComplexError,
72+
InvalidGreeting,
6773
RpcV2ProtocolServiceException,
6874
} from "../dist-types/index.d";

private/smithy-rpcv2-cbor/test/index-objects.spec.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2+
ComplexError,
23
EmptyInputOutputCommand,
34
Float16Command,
45
FooEnum,
56
FractionalSecondsCommand,
67
GreetingWithErrorsCommand,
78
IntegerEnum,
9+
InvalidGreeting,
810
NoInputOutputCommand,
911
OperationWithDefaultsCommand,
1012
OptionalInputOutputCommand,
@@ -19,6 +21,7 @@ import {
1921
SparseNullsOperationCommand,
2022
TestEnum,
2123
TestIntEnum,
24+
ValidationException,
2225
} from "../dist-cjs/index.js";
2326
import assert from "node:assert";
2427
// clients
@@ -44,5 +47,8 @@ assert(typeof TestIntEnum === "object");
4447
assert(typeof FooEnum === "object");
4548
assert(typeof IntegerEnum === "object");
4649
// errors
50+
assert(ValidationException.prototype instanceof RpcV2ProtocolServiceException);
51+
assert(ComplexError.prototype instanceof RpcV2ProtocolServiceException);
52+
assert(InvalidGreeting.prototype instanceof RpcV2ProtocolServiceException);
4753
assert(RpcV2ProtocolServiceException.prototype instanceof Error);
4854
console.log(`RpcV2Protocol index test passed.`);

private/smithy-rpcv2-cbor/test/index-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export type {
4545
TestIntEnum,
4646
FooEnum,
4747
IntegerEnum,
48+
Unit,
49+
ValidationExceptionField,
4850
ClientOptionalDefaults,
51+
ComplexNestedErrorData,
4952
Defaults,
5053
EmptyStructure,
5154
Float16Output,
@@ -64,5 +67,8 @@ export type {
6467
SparseNullsOperationInputOutput,
6568
StructureListMember,
6669
GreetingStruct,
70+
ValidationException,
71+
ComplexError,
72+
InvalidGreeting,
6773
RpcV2ProtocolServiceException,
6874
} from "../dist-types/index.d";

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PackageApiValidationGenerator.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public final class PackageApiValidationGenerator {
3030
private final TypeScriptSettings settings;
3131
private final Model model;
3232
private final SymbolProvider symbolProvider;
33-
private final ServiceClosure serviceClosure;
33+
private final ServiceClosure closure;
3434

3535
public PackageApiValidationGenerator(
3636
TypeScriptWriter writer,
@@ -42,7 +42,7 @@ public PackageApiValidationGenerator(
4242
this.settings = settings;
4343
this.model = model;
4444
this.symbolProvider = symbolProvider;
45-
serviceClosure = ServiceClosure.of(model, settings.getService(model));
45+
closure = ServiceClosure.of(model, settings.getService(model));
4646
}
4747

4848
/**
@@ -75,18 +75,18 @@ public void writeTypeIndexTest() {
7575
}
7676

7777
// enums
78-
TreeSet<Shape> enumShapes = serviceClosure.getEnums();
78+
TreeSet<Shape> enumShapes = closure.getEnums();
7979
for (Shape enumShape : enumShapes) {
8080
writer.write("$L,", symbolProvider.toSymbol(enumShape).getName());
8181
}
8282

8383
// structure & union types & modeled errors
84-
TreeSet<Shape> structuralShapes = serviceClosure.getStructuralNonErrorShapes();
84+
TreeSet<Shape> structuralShapes = closure.getStructuralNonErrorShapes();
8585
for (Shape structuralShape : structuralShapes) {
8686
writer.write("$L,", symbolProvider.toSymbol(structuralShape).getName());
8787
}
8888

89-
TreeSet<Shape> errorShapes = serviceClosure.getErrorShapes();
89+
TreeSet<Shape> errorShapes = closure.getErrorShapes();
9090
for (Shape errorShape : errorShapes) {
9191
writer.write("$L,", symbolProvider.toSymbol(errorShape).getName());
9292
}
@@ -95,11 +95,11 @@ public void writeTypeIndexTest() {
9595
writer.write("$L,", aggregateClientName + "ServiceException");
9696

9797
// waiters
98-
serviceClosure.getWaiterNames().forEach(waiter -> {
98+
closure.getWaiterNames().forEach(waiter -> {
9999
writer.write("$L,", waiter);
100100
});
101101
// paginators
102-
serviceClosure.getPaginatorNames().forEach(paginator -> {
102+
closure.getPaginatorNames().forEach(paginator -> {
103103
writer.write("$L,", paginator);
104104
});
105105
}
@@ -150,7 +150,7 @@ public void writeRuntimeIndexTest() {
150150

151151
// string shapes with enum trait do not generate anything if
152152
// any enum value does not have a name.
153-
TreeSet<Shape> enumShapes = serviceClosure.getEnums().stream()
153+
TreeSet<Shape> enumShapes = closure.getEnums().stream()
154154
.filter(shape -> shape
155155
.getTrait(EnumTrait.class)
156156
.map(EnumTrait::hasNames)
@@ -173,7 +173,7 @@ public void writeRuntimeIndexTest() {
173173

174174
// modeled errors and synthetic base error
175175
writer.write("// errors");
176-
TreeSet<Shape> errors = serviceClosure.getErrorShapes();
176+
TreeSet<Shape> errors = closure.getErrorShapes();
177177
for (Shape error : errors) {
178178
Symbol errorSymbol = symbolProvider.toSymbol(error);
179179
writer.addRelativeImport(errorSymbol.getName(), null, cjsIndex);
@@ -187,7 +187,7 @@ public void writeRuntimeIndexTest() {
187187
writer.write("assert($L.prototype instanceof Error);", baseExceptionName);
188188

189189
// waiters & paginators
190-
TreeSet<String> waiterNames = serviceClosure.getWaiterNames();
190+
TreeSet<String> waiterNames = closure.getWaiterNames();
191191
if (!waiterNames.isEmpty()) {
192192
writer.write("// waiters");
193193
}
@@ -198,7 +198,7 @@ public void writeRuntimeIndexTest() {
198198
waiter
199199
);
200200
});
201-
TreeSet<String> paginatorNames = serviceClosure.getPaginatorNames();
201+
TreeSet<String> paginatorNames = closure.getPaginatorNames();
202202
if (!paginatorNames.isEmpty()) {
203203
writer.write("// paginators");
204204
}

0 commit comments

Comments
 (0)