@smithy/core 3.4.0 → 3.5.1
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/dist-cjs/submodules/cbor/index.js +209 -0
- package/dist-cjs/submodules/protocols/index.js +667 -2
- package/dist-cjs/submodules/schema/index.js +771 -0
- package/dist-cjs/submodules/serde/index.js +108 -53
- package/dist-es/submodules/cbor/CborCodec.js +136 -0
- package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +74 -0
- package/dist-es/submodules/cbor/index.js +3 -1
- package/dist-es/submodules/protocols/HttpBindingProtocol.js +183 -0
- package/dist-es/submodules/protocols/HttpProtocol.js +164 -0
- package/dist-es/submodules/protocols/RpcProtocol.js +68 -0
- package/dist-es/submodules/protocols/index.js +7 -0
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +64 -0
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +38 -0
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +30 -0
- package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +87 -0
- package/dist-es/submodules/protocols/serde/determineTimestampFormat.js +20 -0
- package/dist-es/submodules/schema/TypeRegistry.js +49 -0
- package/dist-es/submodules/schema/deref.js +6 -0
- package/dist-es/submodules/schema/index.js +12 -0
- package/dist-es/submodules/schema/middleware/getSchemaSerdePlugin.js +23 -0
- package/dist-es/submodules/schema/middleware/schema-middleware-types.js +1 -0
- package/dist-es/submodules/schema/middleware/schemaDeserializationMiddleware.js +60 -0
- package/dist-es/submodules/schema/middleware/schemaSerializationMiddleware.js +16 -0
- package/dist-es/submodules/schema/schemas/ErrorSchema.js +17 -0
- package/dist-es/submodules/schema/schemas/ListSchema.js +15 -0
- package/dist-es/submodules/schema/schemas/MapSchema.js +16 -0
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +291 -0
- package/dist-es/submodules/schema/schemas/OperationSchema.js +16 -0
- package/dist-es/submodules/schema/schemas/Schema.js +6 -0
- package/dist-es/submodules/schema/schemas/SimpleSchema.js +15 -0
- package/dist-es/submodules/schema/schemas/StructureSchema.js +22 -0
- package/dist-es/submodules/schema/schemas/sentinels.js +16 -0
- package/dist-es/submodules/serde/copyDocumentWithTransform.js +53 -0
- package/dist-es/submodules/serde/index.js +4 -3
- package/dist-types/submodules/cbor/CborCodec.d.ts +29 -0
- package/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +22 -0
- package/dist-types/submodules/cbor/index.d.ts +3 -1
- package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +15 -0
- package/dist-types/submodules/protocols/HttpProtocol.d.ts +29 -0
- package/dist-types/submodules/protocols/RpcProtocol.d.ts +11 -0
- package/dist-types/submodules/protocols/index.d.ts +7 -0
- package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +14 -0
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +18 -0
- package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +20 -0
- package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +15 -0
- package/dist-types/submodules/protocols/serde/determineTimestampFormat.d.ts +9 -0
- package/dist-types/submodules/schema/TypeRegistry.d.ts +55 -0
- package/dist-types/submodules/schema/deref.d.ts +6 -0
- package/dist-types/submodules/schema/index.d.ts +12 -0
- package/dist-types/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +14 -0
- package/dist-types/submodules/schema/middleware/schema-middleware-types.d.ts +8 -0
- package/dist-types/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +9 -0
- package/dist-types/submodules/schema/middleware/schemaSerializationMiddleware.d.ts +6 -0
- package/dist-types/submodules/schema/schemas/ErrorSchema.d.ts +38 -0
- package/dist-types/submodules/schema/schemas/ListSchema.d.ts +20 -0
- package/dist-types/submodules/schema/schemas/MapSchema.d.ts +25 -0
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +122 -0
- package/dist-types/submodules/schema/schemas/OperationSchema.d.ts +20 -0
- package/dist-types/submodules/schema/schemas/Schema.d.ts +11 -0
- package/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +20 -0
- package/dist-types/submodules/schema/schemas/StructureSchema.d.ts +21 -0
- package/dist-types/submodules/schema/schemas/sentinels.d.ts +21 -0
- package/dist-types/submodules/serde/copyDocumentWithTransform.d.ts +5 -0
- package/dist-types/submodules/serde/index.d.ts +4 -3
- package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +29 -0
- package/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +22 -0
- package/dist-types/ts3.4/submodules/cbor/index.d.ts +3 -1
- package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +15 -0
- package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +29 -0
- package/dist-types/ts3.4/submodules/protocols/RpcProtocol.d.ts +11 -0
- package/dist-types/ts3.4/submodules/protocols/index.d.ts +7 -0
- package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +14 -0
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +18 -0
- package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +20 -0
- package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +15 -0
- package/dist-types/ts3.4/submodules/protocols/serde/determineTimestampFormat.d.ts +9 -0
- package/dist-types/ts3.4/submodules/schema/TypeRegistry.d.ts +55 -0
- package/dist-types/ts3.4/submodules/schema/deref.d.ts +6 -0
- package/dist-types/ts3.4/submodules/schema/index.d.ts +12 -0
- package/dist-types/ts3.4/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +14 -0
- package/dist-types/ts3.4/submodules/schema/middleware/schema-middleware-types.d.ts +11 -0
- package/dist-types/ts3.4/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +9 -0
- package/dist-types/ts3.4/submodules/schema/middleware/schemaSerializationMiddleware.d.ts +6 -0
- package/dist-types/ts3.4/submodules/schema/schemas/ErrorSchema.d.ts +38 -0
- package/dist-types/ts3.4/submodules/schema/schemas/ListSchema.d.ts +20 -0
- package/dist-types/ts3.4/submodules/schema/schemas/MapSchema.d.ts +25 -0
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +125 -0
- package/dist-types/ts3.4/submodules/schema/schemas/OperationSchema.d.ts +20 -0
- package/dist-types/ts3.4/submodules/schema/schemas/Schema.d.ts +11 -0
- package/dist-types/ts3.4/submodules/schema/schemas/SimpleSchema.d.ts +20 -0
- package/dist-types/ts3.4/submodules/schema/schemas/StructureSchema.d.ts +24 -0
- package/dist-types/ts3.4/submodules/schema/schemas/sentinels.d.ts +21 -0
- package/dist-types/ts3.4/submodules/serde/copyDocumentWithTransform.d.ts +5 -0
- package/dist-types/ts3.4/submodules/serde/index.d.ts +4 -3
- package/package.json +17 -7
- package/schema.d.ts +7 -0
- package/schema.js +6 -0
|
@@ -19,6 +19,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/submodules/cbor/index.ts
|
|
20
20
|
var cbor_exports = {};
|
|
21
21
|
__export(cbor_exports, {
|
|
22
|
+
CborCodec: () => CborCodec,
|
|
23
|
+
CborShapeDeserializer: () => CborShapeDeserializer,
|
|
24
|
+
CborShapeSerializer: () => CborShapeSerializer,
|
|
25
|
+
SmithyRpcV2CborProtocol: () => SmithyRpcV2CborProtocol,
|
|
22
26
|
buildHttpRpcRequest: () => buildHttpRpcRequest,
|
|
23
27
|
cbor: () => cbor,
|
|
24
28
|
checkCborResponse: () => checkCborResponse,
|
|
@@ -720,8 +724,213 @@ var buildHttpRpcRequest = async (context, headers, path, resolvedHostname, body)
|
|
|
720
724
|
}
|
|
721
725
|
return new import_protocol_http.HttpRequest(contents);
|
|
722
726
|
};
|
|
727
|
+
|
|
728
|
+
// src/submodules/cbor/SmithyRpcV2CborProtocol.ts
|
|
729
|
+
var import_protocols2 = require("@smithy/core/protocols");
|
|
730
|
+
var import_schema2 = require("@smithy/core/schema");
|
|
731
|
+
var import_util_middleware = require("@smithy/util-middleware");
|
|
732
|
+
|
|
733
|
+
// src/submodules/cbor/CborCodec.ts
|
|
734
|
+
var import_schema = require("@smithy/core/schema");
|
|
735
|
+
var import_serde = require("@smithy/core/serde");
|
|
736
|
+
var CborCodec = class {
|
|
737
|
+
createSerializer() {
|
|
738
|
+
const serializer = new CborShapeSerializer();
|
|
739
|
+
serializer.setSerdeContext(this.serdeContext);
|
|
740
|
+
return serializer;
|
|
741
|
+
}
|
|
742
|
+
createDeserializer() {
|
|
743
|
+
const deserializer = new CborShapeDeserializer();
|
|
744
|
+
deserializer.setSerdeContext(this.serdeContext);
|
|
745
|
+
return deserializer;
|
|
746
|
+
}
|
|
747
|
+
setSerdeContext(serdeContext) {
|
|
748
|
+
this.serdeContext = serdeContext;
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
var CborShapeSerializer = class {
|
|
752
|
+
setSerdeContext(serdeContext) {
|
|
753
|
+
this.serdeContext = serdeContext;
|
|
754
|
+
}
|
|
755
|
+
write(schema, value) {
|
|
756
|
+
this.value = (0, import_serde.copyDocumentWithTransform)(value, schema, (_, schemaRef) => {
|
|
757
|
+
if (_ instanceof Date) {
|
|
758
|
+
return dateToTag(_);
|
|
759
|
+
}
|
|
760
|
+
if (_ instanceof Uint8Array) {
|
|
761
|
+
return _;
|
|
762
|
+
}
|
|
763
|
+
const ns = import_schema.NormalizedSchema.of(schemaRef);
|
|
764
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
765
|
+
if (ns.isListSchema() && Array.isArray(_)) {
|
|
766
|
+
if (!sparse) {
|
|
767
|
+
return _.filter((item) => item != null);
|
|
768
|
+
}
|
|
769
|
+
} else if (_ && typeof _ === "object") {
|
|
770
|
+
const members = ns.getMemberSchemas();
|
|
771
|
+
const isStruct = ns.isStructSchema();
|
|
772
|
+
if (!sparse || isStruct) {
|
|
773
|
+
for (const [k, v] of Object.entries(_)) {
|
|
774
|
+
const filteredOutByNonSparse = !sparse && v == null;
|
|
775
|
+
const filteredOutByUnrecognizedMember = isStruct && !(k in members);
|
|
776
|
+
if (filteredOutByNonSparse || filteredOutByUnrecognizedMember) {
|
|
777
|
+
delete _[k];
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return _;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return _;
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
flush() {
|
|
787
|
+
const buffer = cbor.serialize(this.value);
|
|
788
|
+
this.value = void 0;
|
|
789
|
+
return buffer;
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
var CborShapeDeserializer = class {
|
|
793
|
+
setSerdeContext(serdeContext) {
|
|
794
|
+
this.serdeContext = serdeContext;
|
|
795
|
+
}
|
|
796
|
+
read(schema, bytes) {
|
|
797
|
+
const data2 = cbor.deserialize(bytes);
|
|
798
|
+
return this.readValue(schema, data2);
|
|
799
|
+
}
|
|
800
|
+
readValue(_schema, value) {
|
|
801
|
+
const ns = import_schema.NormalizedSchema.of(_schema);
|
|
802
|
+
const schema = ns.getSchema();
|
|
803
|
+
if (typeof schema === "number") {
|
|
804
|
+
if (ns.isTimestampSchema()) {
|
|
805
|
+
return (0, import_serde.parseEpochTimestamp)(value);
|
|
806
|
+
}
|
|
807
|
+
if (ns.isBlobSchema()) {
|
|
808
|
+
return value;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (typeof value === "undefined" || typeof value === "boolean" || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || typeof value === "symbol") {
|
|
812
|
+
return value;
|
|
813
|
+
} else if (typeof value === "function" || typeof value === "object") {
|
|
814
|
+
if (value === null) {
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
if ("byteLength" in value) {
|
|
818
|
+
return value;
|
|
819
|
+
}
|
|
820
|
+
if (value instanceof Date) {
|
|
821
|
+
return value;
|
|
822
|
+
}
|
|
823
|
+
if (ns.isDocumentSchema()) {
|
|
824
|
+
return value;
|
|
825
|
+
}
|
|
826
|
+
if (ns.isListSchema()) {
|
|
827
|
+
const newArray = [];
|
|
828
|
+
const memberSchema = ns.getValueSchema();
|
|
829
|
+
const sparse = ns.isListSchema() && !!ns.getMergedTraits().sparse;
|
|
830
|
+
for (const item of value) {
|
|
831
|
+
newArray.push(this.readValue(memberSchema, item));
|
|
832
|
+
if (!sparse && newArray[newArray.length - 1] == null) {
|
|
833
|
+
newArray.pop();
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return newArray;
|
|
837
|
+
}
|
|
838
|
+
const newObject = {};
|
|
839
|
+
if (ns.isMapSchema()) {
|
|
840
|
+
const sparse = ns.getMergedTraits().sparse;
|
|
841
|
+
const targetSchema = ns.getValueSchema();
|
|
842
|
+
for (const key of Object.keys(value)) {
|
|
843
|
+
newObject[key] = this.readValue(targetSchema, value[key]);
|
|
844
|
+
if (newObject[key] == null && !sparse) {
|
|
845
|
+
delete newObject[key];
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
} else if (ns.isStructSchema()) {
|
|
849
|
+
for (const [key, memberSchema] of ns.structIterator()) {
|
|
850
|
+
newObject[key] = this.readValue(memberSchema, value[key]);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return newObject;
|
|
854
|
+
} else {
|
|
855
|
+
return value;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
// src/submodules/cbor/SmithyRpcV2CborProtocol.ts
|
|
861
|
+
var SmithyRpcV2CborProtocol = class extends import_protocols2.RpcProtocol {
|
|
862
|
+
constructor({ defaultNamespace }) {
|
|
863
|
+
super({ defaultNamespace });
|
|
864
|
+
this.codec = new CborCodec();
|
|
865
|
+
this.serializer = this.codec.createSerializer();
|
|
866
|
+
this.deserializer = this.codec.createDeserializer();
|
|
867
|
+
}
|
|
868
|
+
getShapeId() {
|
|
869
|
+
return "smithy.protocols#rpcv2Cbor";
|
|
870
|
+
}
|
|
871
|
+
getPayloadCodec() {
|
|
872
|
+
return this.codec;
|
|
873
|
+
}
|
|
874
|
+
async serializeRequest(operationSchema, input, context) {
|
|
875
|
+
const request = await super.serializeRequest(operationSchema, input, context);
|
|
876
|
+
Object.assign(request.headers, {
|
|
877
|
+
"content-type": "application/cbor",
|
|
878
|
+
"smithy-protocol": "rpc-v2-cbor",
|
|
879
|
+
accept: "application/cbor"
|
|
880
|
+
});
|
|
881
|
+
if ((0, import_schema2.deref)(operationSchema.input) === "unit") {
|
|
882
|
+
delete request.body;
|
|
883
|
+
delete request.headers["content-type"];
|
|
884
|
+
} else {
|
|
885
|
+
if (!request.body) {
|
|
886
|
+
this.serializer.write(15, {});
|
|
887
|
+
request.body = this.serializer.flush();
|
|
888
|
+
}
|
|
889
|
+
try {
|
|
890
|
+
request.headers["content-length"] = String(request.body.byteLength);
|
|
891
|
+
} catch (e) {
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
const { service, operation } = (0, import_util_middleware.getSmithyContext)(context);
|
|
895
|
+
const path = `/service/${service}/operation/${operation}`;
|
|
896
|
+
if (request.path.endsWith("/")) {
|
|
897
|
+
request.path += path.slice(1);
|
|
898
|
+
} else {
|
|
899
|
+
request.path += path;
|
|
900
|
+
}
|
|
901
|
+
return request;
|
|
902
|
+
}
|
|
903
|
+
async deserializeResponse(operationSchema, context, response) {
|
|
904
|
+
return super.deserializeResponse(operationSchema, context, response);
|
|
905
|
+
}
|
|
906
|
+
async handleError(operationSchema, context, response, dataObject, metadata) {
|
|
907
|
+
const error = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
|
|
908
|
+
let namespace = this.options.defaultNamespace;
|
|
909
|
+
if (error.includes("#")) {
|
|
910
|
+
[namespace] = error.split("#");
|
|
911
|
+
}
|
|
912
|
+
const registry = import_schema2.TypeRegistry.for(namespace);
|
|
913
|
+
const errorSchema = registry.getSchema(error);
|
|
914
|
+
if (!errorSchema) {
|
|
915
|
+
throw new Error("schema not found for " + error);
|
|
916
|
+
}
|
|
917
|
+
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
918
|
+
const exception = new errorSchema.ctor(message);
|
|
919
|
+
Object.assign(exception, {
|
|
920
|
+
$metadata: metadata,
|
|
921
|
+
$response: response,
|
|
922
|
+
message,
|
|
923
|
+
...dataObject
|
|
924
|
+
});
|
|
925
|
+
throw exception;
|
|
926
|
+
}
|
|
927
|
+
};
|
|
723
928
|
// Annotate the CommonJS export names for ESM import in node:
|
|
724
929
|
0 && (module.exports = {
|
|
930
|
+
CborCodec,
|
|
931
|
+
CborShapeDeserializer,
|
|
932
|
+
CborShapeSerializer,
|
|
933
|
+
SmithyRpcV2CborProtocol,
|
|
725
934
|
buildHttpRpcRequest,
|
|
726
935
|
cbor,
|
|
727
936
|
checkCborResponse,
|