@smithy/core 3.3.3 → 3.5.0
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 +212 -2
- 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 +680 -2
- 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/cbor/parseCborBody.js +3 -2
- 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/date-utils.js +190 -0
- package/dist-es/submodules/serde/index.js +7 -0
- package/dist-es/submodules/serde/lazy-json.js +24 -0
- package/dist-es/submodules/serde/parse-utils.js +230 -0
- package/dist-es/submodules/serde/quote-header.js +6 -0
- package/dist-es/submodules/serde/split-every.js +27 -0
- package/dist-es/submodules/serde/split-header.js +37 -0
- 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/date-utils.d.ts +73 -0
- package/dist-types/submodules/serde/index.d.ts +7 -0
- package/dist-types/submodules/serde/lazy-json.d.ts +45 -0
- package/dist-types/submodules/serde/parse-utils.d.ts +270 -0
- package/dist-types/submodules/serde/quote-header.d.ts +6 -0
- package/dist-types/submodules/serde/split-every.d.ts +11 -0
- package/dist-types/submodules/serde/split-header.d.ts +5 -0
- 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/date-utils.d.ts +73 -0
- package/dist-types/ts3.4/submodules/serde/index.d.ts +7 -0
- package/dist-types/ts3.4/submodules/serde/lazy-json.d.ts +45 -0
- package/dist-types/ts3.4/submodules/serde/parse-utils.d.ts +270 -0
- package/dist-types/ts3.4/submodules/serde/quote-header.d.ts +6 -0
- package/dist-types/ts3.4/submodules/serde/split-every.d.ts +11 -0
- package/dist-types/ts3.4/submodules/serde/split-header.d.ts +5 -0
- package/package.json +18 -7
- package/schema.d.ts +7 -0
- package/schema.js +6 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
export const parseBoolean = (value) => {
|
|
2
|
+
switch (value) {
|
|
3
|
+
case "true":
|
|
4
|
+
return true;
|
|
5
|
+
case "false":
|
|
6
|
+
return false;
|
|
7
|
+
default:
|
|
8
|
+
throw new Error(`Unable to parse boolean value "${value}"`);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export const expectBoolean = (value) => {
|
|
12
|
+
if (value === null || value === undefined) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === "number") {
|
|
16
|
+
if (value === 0 || value === 1) {
|
|
17
|
+
logger.warn(stackTraceWarning(`Expected boolean, got ${typeof value}: ${value}`));
|
|
18
|
+
}
|
|
19
|
+
if (value === 0) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (value === 1) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "string") {
|
|
27
|
+
const lower = value.toLowerCase();
|
|
28
|
+
if (lower === "false" || lower === "true") {
|
|
29
|
+
logger.warn(stackTraceWarning(`Expected boolean, got ${typeof value}: ${value}`));
|
|
30
|
+
}
|
|
31
|
+
if (lower === "false") {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (lower === "true") {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (typeof value === "boolean") {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
throw new TypeError(`Expected boolean, got ${typeof value}: ${value}`);
|
|
42
|
+
};
|
|
43
|
+
export const expectNumber = (value) => {
|
|
44
|
+
if (value === null || value === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === "string") {
|
|
48
|
+
const parsed = parseFloat(value);
|
|
49
|
+
if (!Number.isNaN(parsed)) {
|
|
50
|
+
if (String(parsed) !== String(value)) {
|
|
51
|
+
logger.warn(stackTraceWarning(`Expected number but observed string: ${value}`));
|
|
52
|
+
}
|
|
53
|
+
return parsed;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (typeof value === "number") {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
throw new TypeError(`Expected number, got ${typeof value}: ${value}`);
|
|
60
|
+
};
|
|
61
|
+
const MAX_FLOAT = Math.ceil(2 ** 127 * (2 - 2 ** -23));
|
|
62
|
+
export const expectFloat32 = (value) => {
|
|
63
|
+
const expected = expectNumber(value);
|
|
64
|
+
if (expected !== undefined && !Number.isNaN(expected) && expected !== Infinity && expected !== -Infinity) {
|
|
65
|
+
if (Math.abs(expected) > MAX_FLOAT) {
|
|
66
|
+
throw new TypeError(`Expected 32-bit float, got ${value}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return expected;
|
|
70
|
+
};
|
|
71
|
+
export const expectLong = (value) => {
|
|
72
|
+
if (value === null || value === undefined) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
if (Number.isInteger(value) && !Number.isNaN(value)) {
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
throw new TypeError(`Expected integer, got ${typeof value}: ${value}`);
|
|
79
|
+
};
|
|
80
|
+
export const expectInt = expectLong;
|
|
81
|
+
export const expectInt32 = (value) => expectSizedInt(value, 32);
|
|
82
|
+
export const expectShort = (value) => expectSizedInt(value, 16);
|
|
83
|
+
export const expectByte = (value) => expectSizedInt(value, 8);
|
|
84
|
+
const expectSizedInt = (value, size) => {
|
|
85
|
+
const expected = expectLong(value);
|
|
86
|
+
if (expected !== undefined && castInt(expected, size) !== expected) {
|
|
87
|
+
throw new TypeError(`Expected ${size}-bit integer, got ${value}`);
|
|
88
|
+
}
|
|
89
|
+
return expected;
|
|
90
|
+
};
|
|
91
|
+
const castInt = (value, size) => {
|
|
92
|
+
switch (size) {
|
|
93
|
+
case 32:
|
|
94
|
+
return Int32Array.of(value)[0];
|
|
95
|
+
case 16:
|
|
96
|
+
return Int16Array.of(value)[0];
|
|
97
|
+
case 8:
|
|
98
|
+
return Int8Array.of(value)[0];
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
export const expectNonNull = (value, location) => {
|
|
102
|
+
if (value === null || value === undefined) {
|
|
103
|
+
if (location) {
|
|
104
|
+
throw new TypeError(`Expected a non-null value for ${location}`);
|
|
105
|
+
}
|
|
106
|
+
throw new TypeError("Expected a non-null value");
|
|
107
|
+
}
|
|
108
|
+
return value;
|
|
109
|
+
};
|
|
110
|
+
export const expectObject = (value) => {
|
|
111
|
+
if (value === null || value === undefined) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
const receivedType = Array.isArray(value) ? "array" : typeof value;
|
|
118
|
+
throw new TypeError(`Expected object, got ${receivedType}: ${value}`);
|
|
119
|
+
};
|
|
120
|
+
export const expectString = (value) => {
|
|
121
|
+
if (value === null || value === undefined) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
if (typeof value === "string") {
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
if (["boolean", "number", "bigint"].includes(typeof value)) {
|
|
128
|
+
logger.warn(stackTraceWarning(`Expected string, got ${typeof value}: ${value}`));
|
|
129
|
+
return String(value);
|
|
130
|
+
}
|
|
131
|
+
throw new TypeError(`Expected string, got ${typeof value}: ${value}`);
|
|
132
|
+
};
|
|
133
|
+
export const expectUnion = (value) => {
|
|
134
|
+
if (value === null || value === undefined) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const asObject = expectObject(value);
|
|
138
|
+
const setKeys = Object.entries(asObject)
|
|
139
|
+
.filter(([, v]) => v != null)
|
|
140
|
+
.map(([k]) => k);
|
|
141
|
+
if (setKeys.length === 0) {
|
|
142
|
+
throw new TypeError(`Unions must have exactly one non-null member. None were found.`);
|
|
143
|
+
}
|
|
144
|
+
if (setKeys.length > 1) {
|
|
145
|
+
throw new TypeError(`Unions must have exactly one non-null member. Keys ${setKeys} were not null.`);
|
|
146
|
+
}
|
|
147
|
+
return asObject;
|
|
148
|
+
};
|
|
149
|
+
export const strictParseDouble = (value) => {
|
|
150
|
+
if (typeof value == "string") {
|
|
151
|
+
return expectNumber(parseNumber(value));
|
|
152
|
+
}
|
|
153
|
+
return expectNumber(value);
|
|
154
|
+
};
|
|
155
|
+
export const strictParseFloat = strictParseDouble;
|
|
156
|
+
export const strictParseFloat32 = (value) => {
|
|
157
|
+
if (typeof value == "string") {
|
|
158
|
+
return expectFloat32(parseNumber(value));
|
|
159
|
+
}
|
|
160
|
+
return expectFloat32(value);
|
|
161
|
+
};
|
|
162
|
+
const NUMBER_REGEX = /(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)|(-?Infinity)|(NaN)/g;
|
|
163
|
+
const parseNumber = (value) => {
|
|
164
|
+
const matches = value.match(NUMBER_REGEX);
|
|
165
|
+
if (matches === null || matches[0].length !== value.length) {
|
|
166
|
+
throw new TypeError(`Expected real number, got implicit NaN`);
|
|
167
|
+
}
|
|
168
|
+
return parseFloat(value);
|
|
169
|
+
};
|
|
170
|
+
export const limitedParseDouble = (value) => {
|
|
171
|
+
if (typeof value == "string") {
|
|
172
|
+
return parseFloatString(value);
|
|
173
|
+
}
|
|
174
|
+
return expectNumber(value);
|
|
175
|
+
};
|
|
176
|
+
export const handleFloat = limitedParseDouble;
|
|
177
|
+
export const limitedParseFloat = limitedParseDouble;
|
|
178
|
+
export const limitedParseFloat32 = (value) => {
|
|
179
|
+
if (typeof value == "string") {
|
|
180
|
+
return parseFloatString(value);
|
|
181
|
+
}
|
|
182
|
+
return expectFloat32(value);
|
|
183
|
+
};
|
|
184
|
+
const parseFloatString = (value) => {
|
|
185
|
+
switch (value) {
|
|
186
|
+
case "NaN":
|
|
187
|
+
return NaN;
|
|
188
|
+
case "Infinity":
|
|
189
|
+
return Infinity;
|
|
190
|
+
case "-Infinity":
|
|
191
|
+
return -Infinity;
|
|
192
|
+
default:
|
|
193
|
+
throw new Error(`Unable to parse float value: ${value}`);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
export const strictParseLong = (value) => {
|
|
197
|
+
if (typeof value === "string") {
|
|
198
|
+
return expectLong(parseNumber(value));
|
|
199
|
+
}
|
|
200
|
+
return expectLong(value);
|
|
201
|
+
};
|
|
202
|
+
export const strictParseInt = strictParseLong;
|
|
203
|
+
export const strictParseInt32 = (value) => {
|
|
204
|
+
if (typeof value === "string") {
|
|
205
|
+
return expectInt32(parseNumber(value));
|
|
206
|
+
}
|
|
207
|
+
return expectInt32(value);
|
|
208
|
+
};
|
|
209
|
+
export const strictParseShort = (value) => {
|
|
210
|
+
if (typeof value === "string") {
|
|
211
|
+
return expectShort(parseNumber(value));
|
|
212
|
+
}
|
|
213
|
+
return expectShort(value);
|
|
214
|
+
};
|
|
215
|
+
export const strictParseByte = (value) => {
|
|
216
|
+
if (typeof value === "string") {
|
|
217
|
+
return expectByte(parseNumber(value));
|
|
218
|
+
}
|
|
219
|
+
return expectByte(value);
|
|
220
|
+
};
|
|
221
|
+
const stackTraceWarning = (message) => {
|
|
222
|
+
return String(new TypeError(message).stack || message)
|
|
223
|
+
.split("\n")
|
|
224
|
+
.slice(0, 5)
|
|
225
|
+
.filter((s) => !s.includes("stackTraceWarning"))
|
|
226
|
+
.join("\n");
|
|
227
|
+
};
|
|
228
|
+
export const logger = {
|
|
229
|
+
warn: console.warn,
|
|
230
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function splitEvery(value, delimiter, numDelimiters) {
|
|
2
|
+
if (numDelimiters <= 0 || !Number.isInteger(numDelimiters)) {
|
|
3
|
+
throw new Error("Invalid number of delimiters (" + numDelimiters + ") for splitEvery.");
|
|
4
|
+
}
|
|
5
|
+
const segments = value.split(delimiter);
|
|
6
|
+
if (numDelimiters === 1) {
|
|
7
|
+
return segments;
|
|
8
|
+
}
|
|
9
|
+
const compoundSegments = [];
|
|
10
|
+
let currentSegment = "";
|
|
11
|
+
for (let i = 0; i < segments.length; i++) {
|
|
12
|
+
if (currentSegment === "") {
|
|
13
|
+
currentSegment = segments[i];
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
currentSegment += delimiter + segments[i];
|
|
17
|
+
}
|
|
18
|
+
if ((i + 1) % numDelimiters === 0) {
|
|
19
|
+
compoundSegments.push(currentSegment);
|
|
20
|
+
currentSegment = "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (currentSegment !== "") {
|
|
24
|
+
compoundSegments.push(currentSegment);
|
|
25
|
+
}
|
|
26
|
+
return compoundSegments;
|
|
27
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const splitHeader = (value) => {
|
|
2
|
+
const z = value.length;
|
|
3
|
+
const values = [];
|
|
4
|
+
let withinQuotes = false;
|
|
5
|
+
let prevChar = undefined;
|
|
6
|
+
let anchor = 0;
|
|
7
|
+
for (let i = 0; i < z; ++i) {
|
|
8
|
+
const char = value[i];
|
|
9
|
+
switch (char) {
|
|
10
|
+
case `"`:
|
|
11
|
+
if (prevChar !== "\\") {
|
|
12
|
+
withinQuotes = !withinQuotes;
|
|
13
|
+
}
|
|
14
|
+
break;
|
|
15
|
+
case ",":
|
|
16
|
+
if (!withinQuotes) {
|
|
17
|
+
values.push(value.slice(anchor, i));
|
|
18
|
+
anchor = i + 1;
|
|
19
|
+
}
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
}
|
|
23
|
+
prevChar = char;
|
|
24
|
+
}
|
|
25
|
+
values.push(value.slice(anchor));
|
|
26
|
+
return values.map((v) => {
|
|
27
|
+
v = v.trim();
|
|
28
|
+
const z = v.length;
|
|
29
|
+
if (z < 2) {
|
|
30
|
+
return v;
|
|
31
|
+
}
|
|
32
|
+
if (v[0] === `"` && v[z - 1] === `"`) {
|
|
33
|
+
v = v.slice(1, z - 1);
|
|
34
|
+
}
|
|
35
|
+
return v.replace(/\\"/g, '"');
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Codec, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
|
|
2
|
+
/**
|
|
3
|
+
* @alpha
|
|
4
|
+
*/
|
|
5
|
+
export declare class CborCodec implements Codec<Uint8Array, Uint8Array> {
|
|
6
|
+
private serdeContext?;
|
|
7
|
+
createSerializer(): CborShapeSerializer;
|
|
8
|
+
createDeserializer(): CborShapeDeserializer;
|
|
9
|
+
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
export declare class CborShapeSerializer implements ShapeSerializer {
|
|
15
|
+
private serdeContext?;
|
|
16
|
+
private value;
|
|
17
|
+
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
18
|
+
write(schema: Schema, value: unknown): void;
|
|
19
|
+
flush(): Uint8Array;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @alpha
|
|
23
|
+
*/
|
|
24
|
+
export declare class CborShapeDeserializer implements ShapeDeserializer {
|
|
25
|
+
private serdeContext?;
|
|
26
|
+
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
27
|
+
read(schema: Schema, bytes: Uint8Array): any;
|
|
28
|
+
private readValue;
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RpcProtocol } from "@smithy/core/protocols";
|
|
2
|
+
import { OperationSchema } from "@smithy/core/schema";
|
|
3
|
+
import type { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, ResponseMetadata, SerdeFunctions } from "@smithy/types";
|
|
4
|
+
import { CborCodec } from "./CborCodec";
|
|
5
|
+
/**
|
|
6
|
+
* Client protocol for Smithy RPCv2 CBOR.
|
|
7
|
+
*
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
10
|
+
export declare class SmithyRpcV2CborProtocol extends RpcProtocol {
|
|
11
|
+
private codec;
|
|
12
|
+
protected serializer: import("./CborCodec").CborShapeSerializer;
|
|
13
|
+
protected deserializer: import("./CborCodec").CborShapeDeserializer;
|
|
14
|
+
constructor({ defaultNamespace }: {
|
|
15
|
+
defaultNamespace: string;
|
|
16
|
+
});
|
|
17
|
+
getShapeId(): string;
|
|
18
|
+
getPayloadCodec(): CborCodec;
|
|
19
|
+
serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
|
|
20
|
+
deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
|
|
21
|
+
protected handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
2
|
+
import { HttpRequest } from "@smithy/protocol-http";
|
|
3
|
+
import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, SerdeFunctions } from "@smithy/types";
|
|
4
|
+
import { HttpProtocol } from "./HttpProtocol";
|
|
5
|
+
/**
|
|
6
|
+
* Base for HTTP-binding protocols. Downstream examples
|
|
7
|
+
* include AWS REST JSON and AWS REST XML.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class HttpBindingProtocol extends HttpProtocol {
|
|
12
|
+
serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
|
|
13
|
+
protected serializeQuery(ns: NormalizedSchema, data: any, query: HttpRequest["query"]): void;
|
|
14
|
+
deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ClientProtocol, Codec, Endpoint, EndpointBearer, EndpointV2, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base for HTTP-based client protocols.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class HttpProtocol implements ClientProtocol<IHttpRequest, IHttpResponse> {
|
|
8
|
+
readonly options: {
|
|
9
|
+
defaultNamespace: string;
|
|
10
|
+
};
|
|
11
|
+
protected abstract serializer: ShapeSerializer<string | Uint8Array>;
|
|
12
|
+
protected abstract deserializer: ShapeDeserializer<string | Uint8Array>;
|
|
13
|
+
protected serdeContext?: SerdeFunctions;
|
|
14
|
+
protected constructor(options: {
|
|
15
|
+
defaultNamespace: string;
|
|
16
|
+
});
|
|
17
|
+
abstract getShapeId(): string;
|
|
18
|
+
abstract getPayloadCodec(): Codec<any, any>;
|
|
19
|
+
getRequestType(): new (...args: any[]) => IHttpRequest;
|
|
20
|
+
getResponseType(): new (...args: any[]) => IHttpResponse;
|
|
21
|
+
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
22
|
+
abstract serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
|
|
23
|
+
updateServiceEndpoint(request: IHttpRequest, endpoint: EndpointV2 | Endpoint): IHttpRequest;
|
|
24
|
+
abstract deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
|
|
25
|
+
protected setHostPrefix<Input extends object>(request: IHttpRequest, operationSchema: OperationSchema, input: Input): void;
|
|
26
|
+
protected abstract handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
|
|
27
|
+
protected deserializeMetadata(output: IHttpResponse): ResponseMetadata;
|
|
28
|
+
protected deserializeHttpMessage(schema: Schema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse, headerBindings: Set<string>, dataObject: any): Promise<string[]>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EndpointBearer, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, SerdeFunctions } from "@smithy/types";
|
|
2
|
+
import { HttpProtocol } from "./HttpProtocol";
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base for RPC-over-HTTP protocols.
|
|
5
|
+
*
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class RpcProtocol extends HttpProtocol {
|
|
9
|
+
serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
|
|
10
|
+
deserializeResponse<Output extends MetadataBearer>(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: IHttpResponse): Promise<Output>;
|
|
11
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export * from "./collect-stream-body";
|
|
2
2
|
export * from "./extended-encode-uri-component";
|
|
3
|
+
export * from "./HttpBindingProtocol";
|
|
4
|
+
export * from "./RpcProtocol";
|
|
3
5
|
export * from "./requestBuilder";
|
|
4
6
|
export * from "./resolve-path";
|
|
7
|
+
export * from "./serde/FromStringShapeDeserializer";
|
|
8
|
+
export * from "./serde/HttpInterceptingShapeDeserializer";
|
|
9
|
+
export * from "./serde/HttpInterceptingShapeSerializer";
|
|
10
|
+
export * from "./serde/ToStringShapeSerializer";
|
|
11
|
+
export * from "./serde/determineTimestampFormat";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CodecSettings, Schema, SerdeFunctions, ShapeDeserializer } from "@smithy/types";
|
|
2
|
+
/**
|
|
3
|
+
* This deserializer reads strings.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export declare class FromStringShapeDeserializer implements ShapeDeserializer<string> {
|
|
8
|
+
private settings;
|
|
9
|
+
private serdeContext;
|
|
10
|
+
constructor(settings: CodecSettings);
|
|
11
|
+
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
12
|
+
read(_schema: Schema, data: string): any;
|
|
13
|
+
private base64ToUtf8;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CodecSettings, Schema, SerdeFunctions, ShapeDeserializer } from "@smithy/types";
|
|
2
|
+
/**
|
|
3
|
+
* This deserializer is a dispatcher that decides whether to use a string deserializer
|
|
4
|
+
* or a codec deserializer based on HTTP traits.
|
|
5
|
+
*
|
|
6
|
+
* For example, in a JSON HTTP message, the deserialization of a field will differ depending on whether
|
|
7
|
+
* it is bound to the HTTP header (string) or body (JSON).
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export declare class HttpInterceptingShapeDeserializer<CodecShapeDeserializer extends ShapeDeserializer<any>> implements ShapeDeserializer<string | Uint8Array> {
|
|
12
|
+
private codecDeserializer;
|
|
13
|
+
private stringDeserializer;
|
|
14
|
+
private serdeContext;
|
|
15
|
+
constructor(codecDeserializer: CodecShapeDeserializer, codecSettings: CodecSettings);
|
|
16
|
+
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
17
|
+
read(schema: Schema, data: string | Uint8Array): any | Promise<any>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CodecSettings, Schema as ISchema, SerdeFunctions, ShapeSerializer } from "@smithy/types";
|
|
2
|
+
import { ToStringShapeSerializer } from "./ToStringShapeSerializer";
|
|
3
|
+
/**
|
|
4
|
+
* This serializer decides whether to dispatch to a string serializer or a codec serializer
|
|
5
|
+
* depending on HTTP binding traits within the given schema.
|
|
6
|
+
*
|
|
7
|
+
* For example, a JavaScript array is serialized differently when being written
|
|
8
|
+
* to a REST JSON HTTP header (comma-delimited string) and a REST JSON HTTP body (JSON array).
|
|
9
|
+
*
|
|
10
|
+
* @alpha
|
|
11
|
+
*/
|
|
12
|
+
export declare class HttpInterceptingShapeSerializer<CodecShapeSerializer extends ShapeSerializer<string | Uint8Array>> implements ShapeSerializer<string | Uint8Array> {
|
|
13
|
+
private codecSerializer;
|
|
14
|
+
private stringSerializer;
|
|
15
|
+
private buffer;
|
|
16
|
+
constructor(codecSerializer: CodecShapeSerializer, codecSettings: CodecSettings, stringSerializer?: ToStringShapeSerializer);
|
|
17
|
+
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
18
|
+
write(schema: ISchema, value: unknown): void;
|
|
19
|
+
flush(): string | Uint8Array;
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CodecSettings, Schema, SerdeFunctions, ShapeSerializer } from "@smithy/types";
|
|
2
|
+
/**
|
|
3
|
+
* Serializes a shape to string.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
*/
|
|
7
|
+
export declare class ToStringShapeSerializer implements ShapeSerializer<string> {
|
|
8
|
+
private settings;
|
|
9
|
+
private stringBuffer;
|
|
10
|
+
private serdeContext;
|
|
11
|
+
constructor(settings: CodecSettings);
|
|
12
|
+
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
13
|
+
write(schema: Schema, value: unknown): void;
|
|
14
|
+
flush(): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
2
|
+
import { type TimestampDateTimeSchema, type TimestampEpochSecondsSchema, type TimestampHttpDateSchema, CodecSettings } from "@smithy/types";
|
|
3
|
+
/**
|
|
4
|
+
* Assuming the schema is a timestamp type, the function resolves the format using
|
|
5
|
+
* either the timestamp's own traits, or the default timestamp format from the CodecSettings.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function determineTimestampFormat(ns: NormalizedSchema, settings: CodecSettings): TimestampDateTimeSchema | TimestampHttpDateSchema | TimestampEpochSecondsSchema;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Schema as ISchema } from "@smithy/types";
|
|
2
|
+
import { ErrorSchema } from "./schemas/ErrorSchema";
|
|
3
|
+
/**
|
|
4
|
+
* A way to look up schema by their ShapeId values.
|
|
5
|
+
*
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
8
|
+
export declare class TypeRegistry {
|
|
9
|
+
readonly namespace: string;
|
|
10
|
+
private schemas;
|
|
11
|
+
static readonly registries: Map<string, TypeRegistry>;
|
|
12
|
+
private constructor();
|
|
13
|
+
/**
|
|
14
|
+
* @param namespace - specifier.
|
|
15
|
+
* @returns the schema for that namespace, creating it if necessary.
|
|
16
|
+
*/
|
|
17
|
+
static for(namespace: string): TypeRegistry;
|
|
18
|
+
/**
|
|
19
|
+
* Adds the given schema to a type registry with the same namespace.
|
|
20
|
+
*
|
|
21
|
+
* @param shapeId - to be registered.
|
|
22
|
+
* @param schema - to be registered.
|
|
23
|
+
*/
|
|
24
|
+
register(shapeId: string, schema: ISchema): void;
|
|
25
|
+
/**
|
|
26
|
+
* @param shapeId - query.
|
|
27
|
+
* @returns the schema.
|
|
28
|
+
*/
|
|
29
|
+
getSchema(shapeId: string): ISchema;
|
|
30
|
+
/**
|
|
31
|
+
* The smithy-typescript code generator generates a synthetic (i.e. unmodeled) base exception,
|
|
32
|
+
* because generated SDKs before the introduction of schemas have the notion of a ServiceBaseException, which
|
|
33
|
+
* is unique per service/model.
|
|
34
|
+
*
|
|
35
|
+
* This is generated under a unique prefix that is combined with the service namespace, and this
|
|
36
|
+
* method is used to retrieve it.
|
|
37
|
+
*
|
|
38
|
+
* The base exception synthetic schema is used when an error is returned by a service, but we cannot
|
|
39
|
+
* determine what existing schema to use to deserialize it.
|
|
40
|
+
*
|
|
41
|
+
* @returns the synthetic base exception of the service namespace associated with this registry instance.
|
|
42
|
+
*/
|
|
43
|
+
getBaseException(): ErrorSchema | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* @param predicate - criterion.
|
|
46
|
+
* @returns a schema in this registry matching the predicate.
|
|
47
|
+
*/
|
|
48
|
+
find(predicate: (schema: ISchema) => boolean): ISchema | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Unloads the current TypeRegistry.
|
|
51
|
+
*/
|
|
52
|
+
destroy(): void;
|
|
53
|
+
private normalizeShapeId;
|
|
54
|
+
private getNamespace;
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./deref";
|
|
2
|
+
export * from "./middleware/getSchemaSerdePlugin";
|
|
3
|
+
export * from "./schemas/ListSchema";
|
|
4
|
+
export * from "./schemas/MapSchema";
|
|
5
|
+
export * from "./schemas/OperationSchema";
|
|
6
|
+
export * from "./schemas/ErrorSchema";
|
|
7
|
+
export * from "./schemas/NormalizedSchema";
|
|
8
|
+
export * from "./schemas/Schema";
|
|
9
|
+
export * from "./schemas/SimpleSchema";
|
|
10
|
+
export * from "./schemas/StructureSchema";
|
|
11
|
+
export * from "./schemas/sentinels";
|
|
12
|
+
export * from "./TypeRegistry";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DeserializeHandlerOptions, MetadataBearer, Pluggable, SerializeHandlerOptions } from "@smithy/types";
|
|
2
|
+
import { PreviouslyResolved } from "./schema-middleware-types";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const deserializerMiddlewareOption: DeserializeHandlerOptions;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const serializerMiddlewareOption: SerializeHandlerOptions;
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare function getSchemaSerdePlugin<InputType extends object = any, OutputType extends MetadataBearer = any>(config: PreviouslyResolved): Pluggable<InputType, OutputType>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DeserializeHandler, DeserializeHandlerArguments, HandlerExecutionContext } from "@smithy/types";
|
|
2
|
+
import { PreviouslyResolved } from "./schema-middleware-types";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const schemaDeserializationMiddleware: <O>(config: PreviouslyResolved) => (next: DeserializeHandler<any, any>, context: HandlerExecutionContext) => (args: DeserializeHandlerArguments<any>) => Promise<{
|
|
7
|
+
response: unknown;
|
|
8
|
+
output: O;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HandlerExecutionContext, SerializeHandler, SerializeHandlerArguments } from "@smithy/types";
|
|
2
|
+
import { PreviouslyResolved } from "./schema-middleware-types";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const schemaSerializationMiddleware: (config: PreviouslyResolved) => (next: SerializeHandler<any, any>, context: HandlerExecutionContext) => (args: SerializeHandlerArguments<any>) => Promise<import("@smithy/types").SerializeHandlerOutput<any>>;
|