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: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ test-protocols:
(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)

# "build generate test"
bgt:
make build generate-protocol-tests test-protocols

test-unit:
yarn g:vitest run -c vitest.config.mts

Expand Down
32 changes: 15 additions & 17 deletions private/my-local-model-schema/src/schemas/schemas_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ import { TypeRegistry } from "@smithy/core/schema";
import type { StaticErrorSchema, StaticOperationSchema, StaticStructureSchema } from "@smithy/types";

import {
CodedThrottlingError as __CodedThrottlingError,
HaltError as __HaltError,
MainServiceLinkedError as __MainServiceLinkedError,
MysteryThrottlingError as __MysteryThrottlingError,
RetryableError as __RetryableError,
XYZServiceServiceException as __XYZServiceServiceException,
CodedThrottlingError,
HaltError,
MainServiceLinkedError,
MysteryThrottlingError,
RetryableError,
XYZServiceServiceException,
} from "../models/errors";
import {
XYZServiceSyntheticServiceException as __XYZServiceSyntheticServiceException,
} from "../models/XYZServiceSyntheticServiceException";
import { XYZServiceSyntheticServiceException } from "../models/XYZServiceSyntheticServiceException";

/* eslint no-var: 0 */
export var Alpha$: StaticStructureSchema = [3, n0, _A,
Expand All @@ -56,7 +54,7 @@ export var CodedThrottlingError$: StaticErrorSchema = [-3, n0, _CTE,
[],
[]
];
TypeRegistry.for(n0).registerError(CodedThrottlingError$, __CodedThrottlingError);
TypeRegistry.for(n0).registerError(CodedThrottlingError$, CodedThrottlingError);
export var GetNumbersRequest$: StaticStructureSchema = [3, n0, _GNR,
0,
[_bD, _bI, _fWM, _fWMi],
Expand All @@ -72,25 +70,25 @@ export var HaltError$: StaticErrorSchema = [-3, n0, _HE,
[],
[]
];
TypeRegistry.for(n0).registerError(HaltError$, __HaltError);
TypeRegistry.for(n0).registerError(HaltError$, HaltError);
export var MainServiceLinkedError$: StaticErrorSchema = [-3, n0, _MSLE,
{ [_e]: _c, [_hE]: 400 },
[],
[]
];
TypeRegistry.for(n0).registerError(MainServiceLinkedError$, __MainServiceLinkedError);
TypeRegistry.for(n0).registerError(MainServiceLinkedError$, MainServiceLinkedError);
export var MysteryThrottlingError$: StaticErrorSchema = [-3, n0, _MTE,
{ [_e]: _c },
[],
[]
];
TypeRegistry.for(n0).registerError(MysteryThrottlingError$, __MysteryThrottlingError);
TypeRegistry.for(n0).registerError(MysteryThrottlingError$, MysteryThrottlingError);
export var RetryableError$: StaticErrorSchema = [-3, n0, _RE,
{ [_e]: _c },
[],
[]
];
TypeRegistry.for(n0).registerError(RetryableError$, __RetryableError);
TypeRegistry.for(n0).registerError(RetryableError$, RetryableError);
export var TradeEventStreamRequest$: StaticStructureSchema = [3, n0, _TESR,
0,
[_eS],
Expand All @@ -106,10 +104,10 @@ export var XYZServiceServiceException$: StaticErrorSchema = [-3, n0, _XYZSSE,
[],
[]
];
TypeRegistry.for(n0).registerError(XYZServiceServiceException$, __XYZServiceServiceException);
TypeRegistry.for(n0).registerError(XYZServiceServiceException$, XYZServiceServiceException);
var __Unit = "unit" as const;
export var XYZServiceSyntheticServiceException: StaticErrorSchema = [-3, _s, "XYZServiceSyntheticServiceException", 0, [], []];
TypeRegistry.for(_s).registerError(XYZServiceSyntheticServiceException, __XYZServiceSyntheticServiceException);
export var XYZServiceSyntheticServiceException$: StaticErrorSchema = [-3, _s, "XYZServiceSyntheticServiceException", 0, [], []];
TypeRegistry.for(_s).registerError(XYZServiceSyntheticServiceException$, XYZServiceSyntheticServiceException);
export var TradeEvents$: StaticStructureSchema = [3, n0, _TE,
{ [_st]: 1 },
[_a, _b, _g],
Expand Down
78 changes: 36 additions & 42 deletions private/smithy-rpcv2-cbor-schema/src/schemas/schemas_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,17 @@ import type {
StaticStructureSchema,
} from "@smithy/types";

import {
ComplexError as __ComplexError,
InvalidGreeting as __InvalidGreeting,
ValidationException as __ValidationException,
} from "../models/errors";
import {
RpcV2ProtocolServiceException as __RpcV2ProtocolServiceException,
} from "../models/RpcV2ProtocolServiceException";
import { ComplexError, InvalidGreeting, ValidationException } from "../models/errors";
import { RpcV2ProtocolServiceException } from "../models/RpcV2ProtocolServiceException";

/* eslint no-var: 0 */
var __Unit = "unit" as const;
export var ValidationException$: StaticErrorSchema = [-3, n0, _VE,
{ [_e]: _c },
[_m, _fL],
[0, () => ValidationExceptionFieldList$]
[0, () => ValidationExceptionFieldList]
];
TypeRegistry.for(n0).registerError(ValidationException$, __ValidationException);
TypeRegistry.for(n0).registerError(ValidationException$, ValidationException);
export var ValidationExceptionField$: StaticStructureSchema = [3, n0, _VEF,
0,
[_p, _m],
Expand All @@ -172,7 +166,7 @@ export var ComplexError$: StaticErrorSchema = [-3, n1, _CE,
[_TL, _N],
[0, () => ComplexNestedErrorData$]
];
TypeRegistry.for(n1).registerError(ComplexError$, __ComplexError);
TypeRegistry.for(n1).registerError(ComplexError$, ComplexError);
export var ComplexNestedErrorData$: StaticStructureSchema = [3, n1, _CNED,
0,
[_F],
Expand Down Expand Up @@ -208,7 +202,7 @@ export var InvalidGreeting$: StaticErrorSchema = [-3, n1, _IG,
[_M],
[0]
];
TypeRegistry.for(n1).registerError(InvalidGreeting$, __InvalidGreeting);
TypeRegistry.for(n1).registerError(InvalidGreeting$, InvalidGreeting);
export var OperationWithDefaultsInput$: StaticStructureSchema = [3, n1, _OWDI,
0,
[_de, _cOD, _tLD, _oTLD],
Expand Down Expand Up @@ -237,17 +231,17 @@ export var RecursiveShapesInputOutputNested2$: StaticStructureSchema = [3, n1, _
export var RpcV2CborDenseMapsInputOutput$: StaticStructureSchema = [3, n1, _RVCDMIO,
0,
[_dSM, _dNM, _dBM, _dSMe, _dSMen],
[() => DenseStructMap$, 128 | 1, 128 | 2, 128 | 0, [2, n1, _DSM, 0, 0, 64 | 0]]
[() => DenseStructMap, 128 | 1, 128 | 2, 128 | 0, [2, n1, _DSM, 0, 0, 64 | 0]]
];
export var RpcV2CborListInputOutput$: StaticStructureSchema = [3, n1, _RVCLIO,
0,
[_sL, _sS, _iL, _bL, _tL, _eL, _iEL, _nSL, _sLt, _bLl],
[64 | 0, 64 | 0, 64 | 1, 64 | 2, 64 | 4, 64 | 0, 64 | 1, [1, n2, _NSL, 0, 64 | 0], () => StructureList$, 64 | 21]
[64 | 0, 64 | 0, 64 | 1, 64 | 2, 64 | 4, 64 | 0, 64 | 1, [1, n2, _NSL, 0, 64 | 0], () => StructureList, 64 | 21]
];
export var RpcV2CborSparseMapsInputOutput$: StaticStructureSchema = [3, n1, _RVCSMIO,
0,
[_sSM, _sNM, _sBM, _sSMp, _sSMpa],
[[() => SparseStructMap$, 0], [() => SparseNumberMap$, 0], [() => SparseBooleanMap$, 0], [() => SparseStringMap$, 0], [() => SparseSetMap$, 0]]
[[() => SparseStructMap, 0], [() => SparseNumberMap, 0], [() => SparseBooleanMap, 0], [() => SparseStringMap, 0], [() => SparseSetMap, 0]]
];
export var SimpleScalarStructure$: StaticStructureSchema = [3, n1, _SSS,
0,
Expand All @@ -262,7 +256,7 @@ export var SimpleStructure$: StaticStructureSchema = [3, n1, _SS,
export var SparseNullsOperationInputOutput$: StaticStructureSchema = [3, n1, _SNOIO,
0,
[_sSL, _sSMp],
[[() => SparseStringList$, 0], [() => SparseStringMap$, 0]]
[[() => SparseStringList, 0], [() => SparseStringMap, 0]]
];
export var StructureListMember$: StaticStructureSchema = [3, n1, _SLM,
0,
Expand All @@ -274,52 +268,52 @@ export var GreetingStruct$: StaticStructureSchema = [3, n2, _GS,
[_h],
[0]
];
export var RpcV2ProtocolServiceException: StaticErrorSchema = [-3, _sC, "RpcV2ProtocolServiceException", 0, [], []];
TypeRegistry.for(_sC).registerError(RpcV2ProtocolServiceException, __RpcV2ProtocolServiceException);
var ValidationExceptionFieldList$: StaticListSchema = [1, n0, _VEFL,
export var RpcV2ProtocolServiceException$: StaticErrorSchema = [-3, _sC, "RpcV2ProtocolServiceException", 0, [], []];
TypeRegistry.for(_sC).registerError(RpcV2ProtocolServiceException$, RpcV2ProtocolServiceException);
var ValidationExceptionFieldList: StaticListSchema = [1, n0, _VEFL,
0, () => ValidationExceptionField$
];
var StructureList$: StaticListSchema = [1, n1, _SL,
var StructureList: StaticListSchema = [1, n1, _SL,
0, () => StructureListMember$
];
var TestStringList$ = 64 | 0;
var BlobList$ = 64 | 21;
var BooleanList$ = 64 | 2;
var FooEnumList$ = 64 | 0;
var IntegerEnumList$ = 64 | 1;
var IntegerList$ = 64 | 1;
var NestedStringList$: StaticListSchema = [1, n2, _NSL,
var TestStringList = 64 | 0;
var BlobList = 64 | 21;
var BooleanList = 64 | 2;
var FooEnumList = 64 | 0;
var IntegerEnumList = 64 | 1;
var IntegerList = 64 | 1;
var NestedStringList: StaticListSchema = [1, n2, _NSL,
0, 64 | 0
];
var SparseStringList$: StaticListSchema = [1, n2, _SSL,
var SparseStringList: StaticListSchema = [1, n2, _SSL,
{ [_s]: 1 }, 0
];
var StringList$ = 64 | 0;
var StringSet$ = 64 | 0;
var TimestampList$ = 64 | 4;
var DenseBooleanMap$ = 128 | 2;
var DenseNumberMap$ = 128 | 1;
var DenseSetMap$: StaticMapSchema = [2, n1, _DSM,
var StringList = 64 | 0;
var StringSet = 64 | 0;
var TimestampList = 64 | 4;
var DenseBooleanMap = 128 | 2;
var DenseNumberMap = 128 | 1;
var DenseSetMap: StaticMapSchema = [2, n1, _DSM,
0, 0, 64 | 0
];
var DenseStringMap$ = 128 | 0;
var DenseStructMap$: StaticMapSchema = [2, n1, _DSMe,
var DenseStringMap = 128 | 0;
var DenseStructMap: StaticMapSchema = [2, n1, _DSMe,
0, 0, () => GreetingStruct$
];
var SparseBooleanMap$: StaticMapSchema = [2, n1, _SBM,
var SparseBooleanMap: StaticMapSchema = [2, n1, _SBM,
{ [_s]: 1 }, 0, 2
];
var SparseNumberMap$: StaticMapSchema = [2, n1, _SNM,
var SparseNumberMap: StaticMapSchema = [2, n1, _SNM,
{ [_s]: 1 }, 0, 1
];
var SparseSetMap$: StaticMapSchema = [2, n1, _SSM,
var SparseSetMap: StaticMapSchema = [2, n1, _SSM,
{ [_s]: 1 }, 0, 64 | 0
];
var SparseStructMap$: StaticMapSchema = [2, n1, _SSMp,
var SparseStructMap: StaticMapSchema = [2, n1, _SSMp,
{ [_s]: 1 }, 0, () => GreetingStruct$
];
var TestStringMap$ = 128 | 0;
var SparseStringMap$: StaticMapSchema = [2, n2, _SSMpa,
var TestStringMap = 128 | 0;
var SparseStringMap: StaticMapSchema = [2, n2, _SSMpa,
{ [_s]: 1 }, 0, 0
];
export var EmptyInputOutput$: StaticOperationSchema = [9, n1, _EIO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,18 @@ public String getShapeSchemaVariableName(Shape shape, StringStore store) {
symbolName += "_" + store.var(shape.getId().getNamespace(), "n");
}
/*
* The schema suffix allows what would otherwise conflict with the
* shape's interface symbol name to be exported at the top level of the same package.
* Although exporting a type and value with the same name is allowed by TS, we
* do not want to do this because the structure's interface is not that
* of the schema object.
*
* The name transform deconflicts the interface and structure variable names.
* for export at the top level of the same package.
*/
String schemaSuffix = "$";
return symbolName + schemaSuffix;
String suffix = "";
if (shape.isStructureShape() || shape.isUnionShape() || shape.isOperationShape()) {
suffix = "$";
}
return symbolName + suffix;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ private void writeSimpleSchema(Shape shape) {

private void writeStructureSchema(StructureShape shape) {
checkedWriteSchema(shape, () -> {
String symbolName = ServiceClosure.RESERVED_WORDS.escape(shape.getId().getName());
String exceptionCtorSymbolName = ServiceClosure.RESERVED_WORDS.escape(shape.getId().getName());
if (shape.hasTrait(ErrorTrait.class)) {
String exceptionCtorSymbolName = "__" + symbolName;
writer.addTypeImport("StaticErrorSchema", null, TypeScriptDependency.SMITHY_TYPES);
writer.addRelativeImport(symbolName, exceptionCtorSymbolName, Paths.get("..", "models", "errors"));
writer.addRelativeImport(exceptionCtorSymbolName, null, Paths.get("..", "models", "errors"));
writer.openBlock(
"""
export var $L: StaticErrorSchema = [-3, $L, $L,""",
Expand Down Expand Up @@ -167,33 +166,33 @@ private void writeStructureSchema(StructureShape shape) {
*/
private void writeBaseError() {
String serviceName = CodegenUtils.getServiceName(settings, model, symbolProvider);
String serviceExceptionName = CodegenUtils.getSyntheticBaseExceptionName(serviceName, model);
String syntheticBaseExceptionName = CodegenUtils.getSyntheticBaseExceptionName(serviceName, model);
String schemaSymbolName = syntheticBaseExceptionName + "$";

String namespace = settings.getService(model).getId().getNamespace();

String exceptionCtorSymbolName = "__" + serviceExceptionName;
writer.addTypeImport("StaticErrorSchema", null, TypeScriptDependency.SMITHY_TYPES);
writer.addRelativeImport(
serviceExceptionName,
exceptionCtorSymbolName,
Paths.get("..", "models", serviceExceptionName)
syntheticBaseExceptionName,
null,
Paths.get("..", "models", syntheticBaseExceptionName)
);

String syntheticNamespace = store.var("smithy.ts.sdk.synthetic." + namespace);
writer.write(
"""
export var $L: StaticErrorSchema = [-3, $L, $S, 0, [], []];""",
serviceExceptionName,
schemaSymbolName,
syntheticNamespace,
serviceExceptionName
syntheticBaseExceptionName
);
writer.addImportSubmodule("TypeRegistry", null, TypeScriptDependency.SMITHY_CORE, "/schema");
writer.write(
"""
TypeRegistry.for($L).registerError($L, $L);""",
syntheticNamespace,
serviceExceptionName,
exceptionCtorSymbolName
schemaSymbolName,
syntheticBaseExceptionName
);
}

Expand Down