Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ generate-protocol-tests:
yarn turbo run build -F="./private/*" --only

test-protocols:
(cd ./private/smithy-rpcv2-cbor && npx vitest run --globals)
(cd ./private/smithy-rpcv2-cbor-schema && npx vitest run --globals)
(cd ./private/smithy-rpcv2-cbor && npx vitest run --globals && yarn test:index)
(cd ./private/smithy-rpcv2-cbor-schema && npx vitest run --globals && yarn test:index)

test-unit:
yarn g:vitest run -c vitest.config.mts
Expand Down
12 changes: 11 additions & 1 deletion private/my-local-model-schema/test/index-objects.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import {
CodedThrottlingError,
GetNumbersCommand,
HaltError,
MysteryThrottlingError,
RetryableError,
TradeEventStreamCommand,
XYZService,
XYZServiceClient,
XYZServiceServiceException,
XYZServiceSyntheticServiceException,
} from "../dist-cjs/index.js";
import assert from "node:assert";
// clients
Expand All @@ -13,5 +18,10 @@ assert(typeof XYZService === "function");
assert(typeof GetNumbersCommand === "function");
assert(typeof TradeEventStreamCommand === "function");
// errors
assert(XYZServiceServiceException.prototype instanceof Error);
assert(CodedThrottlingError.prototype instanceof XYZServiceSyntheticServiceException);
assert(HaltError.prototype instanceof XYZServiceSyntheticServiceException);
assert(MysteryThrottlingError.prototype instanceof XYZServiceSyntheticServiceException);
assert(RetryableError.prototype instanceof XYZServiceSyntheticServiceException);
assert(XYZServiceServiceException.prototype instanceof XYZServiceSyntheticServiceException);
assert(XYZServiceSyntheticServiceException.prototype instanceof Error);
console.log(`XYZService index test passed.`);
6 changes: 5 additions & 1 deletion private/my-local-model-schema/test/index-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export type {
TradeEvents,
TradeEventStreamRequest,
TradeEventStreamResponse,
Unit,
CodedThrottlingError,
HaltError,
MysteryThrottlingError,
RetryableError,
XYZServiceServiceException,
XYZServiceSyntheticServiceException,
} from "../dist-types/index.d";
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
ComplexError,
EmptyInputOutputCommand,
Float16Command,
FooEnum,
FractionalSecondsCommand,
GreetingWithErrorsCommand,
IntegerEnum,
InvalidGreeting,
NoInputOutputCommand,
OperationWithDefaultsCommand,
OptionalInputOutputCommand,
Expand All @@ -19,6 +21,7 @@ import {
SparseNullsOperationCommand,
TestEnum,
TestIntEnum,
ValidationException,
} from "../dist-cjs/index.js";
import assert from "node:assert";
// clients
Expand All @@ -44,5 +47,8 @@ assert(typeof TestIntEnum === "object");
assert(typeof FooEnum === "object");
assert(typeof IntegerEnum === "object");
// errors
assert(ValidationException.prototype instanceof RpcV2ProtocolServiceException);
assert(ComplexError.prototype instanceof RpcV2ProtocolServiceException);
assert(InvalidGreeting.prototype instanceof RpcV2ProtocolServiceException);
assert(RpcV2ProtocolServiceException.prototype instanceof Error);
console.log(`RpcV2Protocol index test passed.`);
5 changes: 5 additions & 0 deletions private/smithy-rpcv2-cbor-schema/test/index-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export type {
TestIntEnum,
FooEnum,
IntegerEnum,
ValidationExceptionField,
ClientOptionalDefaults,
ComplexNestedErrorData,
Defaults,
EmptyStructure,
Float16Output,
Expand All @@ -64,5 +66,8 @@ export type {
SparseNullsOperationInputOutput,
StructureListMember,
GreetingStruct,
ValidationException,
ComplexError,
InvalidGreeting,
RpcV2ProtocolServiceException,
} from "../dist-types/index.d";
6 changes: 6 additions & 0 deletions private/smithy-rpcv2-cbor/test/index-objects.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
ComplexError,
EmptyInputOutputCommand,
Float16Command,
FooEnum,
FractionalSecondsCommand,
GreetingWithErrorsCommand,
IntegerEnum,
InvalidGreeting,
NoInputOutputCommand,
OperationWithDefaultsCommand,
OptionalInputOutputCommand,
Expand All @@ -19,6 +21,7 @@ import {
SparseNullsOperationCommand,
TestEnum,
TestIntEnum,
ValidationException,
} from "../dist-cjs/index.js";
import assert from "node:assert";
// clients
Expand All @@ -44,5 +47,8 @@ assert(typeof TestIntEnum === "object");
assert(typeof FooEnum === "object");
assert(typeof IntegerEnum === "object");
// errors
assert(ValidationException.prototype instanceof RpcV2ProtocolServiceException);
assert(ComplexError.prototype instanceof RpcV2ProtocolServiceException);
assert(InvalidGreeting.prototype instanceof RpcV2ProtocolServiceException);
assert(RpcV2ProtocolServiceException.prototype instanceof Error);
console.log(`RpcV2Protocol index test passed.`);
5 changes: 5 additions & 0 deletions private/smithy-rpcv2-cbor/test/index-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export type {
TestIntEnum,
FooEnum,
IntegerEnum,
ValidationExceptionField,
ClientOptionalDefaults,
ComplexNestedErrorData,
Defaults,
EmptyStructure,
Float16Output,
Expand All @@ -64,5 +66,8 @@ export type {
SparseNullsOperationInputOutput,
StructureListMember,
GreetingStruct,
ValidationException,
ComplexError,
InvalidGreeting,
RpcV2ProtocolServiceException,
} from "../dist-types/index.d";
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class PackageApiValidationGenerator {
private final TypeScriptSettings settings;
private final Model model;
private final SymbolProvider symbolProvider;
private final ServiceClosure serviceClosure;
private final ServiceClosure closure;

public PackageApiValidationGenerator(
TypeScriptWriter writer,
Expand All @@ -42,7 +42,7 @@ public PackageApiValidationGenerator(
this.settings = settings;
this.model = model;
this.symbolProvider = symbolProvider;
serviceClosure = ServiceClosure.of(model, settings.getService(model));
closure = ServiceClosure.of(model, settings.getService(model));
}

/**
Expand Down Expand Up @@ -75,31 +75,32 @@ public void writeTypeIndexTest() {
}

// enums
TreeSet<Shape> enumShapes = serviceClosure.getEnums();
TreeSet<Shape> enumShapes = closure.getEnums();
for (Shape enumShape : enumShapes) {
writer.write("$L,", symbolProvider.toSymbol(enumShape).getName());
}

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

TreeSet<Shape> errorShapes = serviceClosure.getErrorShapes();
TreeSet<Shape> errorShapes = closure.getErrorShapes();
for (Shape errorShape : errorShapes) {
writer.write("$L,", symbolProvider.toSymbol(errorShape).getName());
}

// synthetic base exception
writer.write("$L,", aggregateClientName + "ServiceException");
String baseExceptionName = CodegenUtils.getSyntheticBaseExceptionName(aggregateClientName, model);
writer.write("$L,", baseExceptionName);

// waiters
serviceClosure.getWaiterNames().forEach(waiter -> {
closure.getWaiterNames().forEach(waiter -> {
writer.write("$L,", waiter);
});
// paginators
serviceClosure.getPaginatorNames().forEach(paginator -> {
closure.getPaginatorNames().forEach(paginator -> {
writer.write("$L,", paginator);
});
}
Expand Down Expand Up @@ -150,7 +151,7 @@ public void writeRuntimeIndexTest() {

// string shapes with enum trait do not generate anything if
// any enum value does not have a name.
TreeSet<Shape> enumShapes = serviceClosure.getEnums().stream()
TreeSet<Shape> enumShapes = closure.getEnums().stream()
.filter(shape -> shape
.getTrait(EnumTrait.class)
.map(EnumTrait::hasNames)
Expand All @@ -169,11 +170,11 @@ public void writeRuntimeIndexTest() {
);
}

String baseExceptionName = aggregateClientName + "ServiceException";
String baseExceptionName = CodegenUtils.getSyntheticBaseExceptionName(aggregateClientName, model);

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

// waiters & paginators
TreeSet<String> waiterNames = serviceClosure.getWaiterNames();
TreeSet<String> waiterNames = closure.getWaiterNames();
if (!waiterNames.isEmpty()) {
writer.write("// waiters");
}
Expand All @@ -198,7 +199,7 @@ public void writeRuntimeIndexTest() {
waiter
);
});
TreeSet<String> paginatorNames = serviceClosure.getPaginatorNames();
TreeSet<String> paginatorNames = closure.getPaginatorNames();
if (!paginatorNames.isEmpty()) {
writer.write("// paginators");
}
Expand Down
Loading