@smithy/core 3.13.0 → 3.15.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/index.js +308 -412
- package/dist-cjs/submodules/cbor/index.js +957 -969
- package/dist-cjs/submodules/event-streams/index.js +200 -249
- package/dist-cjs/submodules/protocols/index.js +795 -895
- package/dist-cjs/submodules/schema/index.js +536 -799
- package/dist-cjs/submodules/serde/index.js +675 -679
- package/dist-es/submodules/cbor/CborCodec.js +6 -2
- package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +3 -3
- package/dist-es/submodules/cbor/cbor-decode.js +18 -18
- package/dist-es/submodules/cbor/cbor-encode.js +5 -5
- package/dist-es/submodules/event-streams/EventStreamSerde.js +10 -3
- package/dist-es/submodules/protocols/HttpBindingProtocol.js +4 -4
- package/dist-es/submodules/protocols/HttpProtocol.js +5 -3
- package/dist-es/submodules/protocols/RpcProtocol.js +2 -2
- package/dist-es/submodules/protocols/requestBuilder.js +9 -7
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +21 -17
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +3 -0
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +3 -0
- package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +7 -6
- package/dist-es/submodules/protocols/serde/determineTimestampFormat.js +5 -6
- package/dist-es/submodules/schema/TypeRegistry.js +4 -1
- package/dist-es/submodules/schema/index.js +1 -0
- package/dist-es/submodules/schema/schemas/ErrorSchema.js +3 -5
- package/dist-es/submodules/schema/schemas/ListSchema.js +5 -5
- package/dist-es/submodules/schema/schemas/MapSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +92 -178
- package/dist-es/submodules/schema/schemas/OperationSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/Schema.js +3 -0
- package/dist-es/submodules/schema/schemas/SimpleSchema.js +5 -5
- package/dist-es/submodules/schema/schemas/StructureSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/sentinels.js +14 -14
- package/dist-es/submodules/schema/schemas/translateTraits.js +22 -0
- package/dist-es/submodules/serde/index.js +1 -0
- package/dist-es/submodules/serde/schema-serde-lib/schema-date-utils.js +110 -0
- package/dist-es/submodules/serde/value/NumericValue.js +6 -26
- package/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +1 -1
- package/dist-es/util-identity-and-auth/memoizeIdentityProvider.js +4 -2
- package/dist-types/submodules/schema/index.d.ts +1 -0
- package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +5 -24
- package/dist-types/submodules/schema/schemas/sentinels.d.ts +2 -0
- package/dist-types/submodules/schema/schemas/translateTraits.d.ts +7 -0
- package/dist-types/submodules/serde/index.d.ts +1 -0
- package/dist-types/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +47 -0
- package/dist-types/ts3.4/submodules/schema/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +5 -24
- package/dist-types/ts3.4/submodules/schema/schemas/sentinels.d.ts +2 -0
- package/dist-types/ts3.4/submodules/schema/schemas/translateTraits.d.ts +7 -0
- package/dist-types/ts3.4/submodules/serde/index.d.ts +1 -0
- package/dist-types/ts3.4/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +47 -0
- package/package.json +11 -11
|
@@ -1,842 +1,579 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
18
2
|
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
__export(index_exports, {
|
|
22
|
-
ErrorSchema: () => ErrorSchema,
|
|
23
|
-
ListSchema: () => ListSchema,
|
|
24
|
-
MapSchema: () => MapSchema,
|
|
25
|
-
NormalizedSchema: () => NormalizedSchema,
|
|
26
|
-
OperationSchema: () => OperationSchema,
|
|
27
|
-
SCHEMA: () => SCHEMA,
|
|
28
|
-
Schema: () => Schema,
|
|
29
|
-
SimpleSchema: () => SimpleSchema,
|
|
30
|
-
StructureSchema: () => StructureSchema,
|
|
31
|
-
TypeRegistry: () => TypeRegistry,
|
|
32
|
-
deref: () => deref,
|
|
33
|
-
deserializerMiddlewareOption: () => deserializerMiddlewareOption,
|
|
34
|
-
error: () => error,
|
|
35
|
-
getSchemaSerdePlugin: () => getSchemaSerdePlugin,
|
|
36
|
-
list: () => list,
|
|
37
|
-
map: () => map,
|
|
38
|
-
op: () => op,
|
|
39
|
-
serializerMiddlewareOption: () => serializerMiddlewareOption,
|
|
40
|
-
sim: () => sim,
|
|
41
|
-
struct: () => struct
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var protocolHttp = require('@smithy/protocol-http');
|
|
4
|
+
var utilMiddleware = require('@smithy/util-middleware');
|
|
44
5
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return schemaRef;
|
|
6
|
+
const deref = (schemaRef) => {
|
|
7
|
+
if (typeof schemaRef === "function") {
|
|
8
|
+
return schemaRef();
|
|
9
|
+
}
|
|
10
|
+
return schemaRef;
|
|
51
11
|
};
|
|
52
12
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
13
|
+
const schemaDeserializationMiddleware = (config) => (next, context) => async (args) => {
|
|
14
|
+
const { response } = await next(args);
|
|
15
|
+
const { operationSchema } = utilMiddleware.getSmithyContext(context);
|
|
16
|
+
try {
|
|
17
|
+
const parsed = await config.protocol.deserializeResponse(operationSchema, {
|
|
18
|
+
...config,
|
|
19
|
+
...context,
|
|
20
|
+
}, response);
|
|
21
|
+
return {
|
|
22
|
+
response,
|
|
23
|
+
output: parsed,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
Object.defineProperty(error, "$response", {
|
|
28
|
+
value: response,
|
|
29
|
+
});
|
|
30
|
+
if (!("$metadata" in error)) {
|
|
31
|
+
const hint = `Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object.`;
|
|
32
|
+
try {
|
|
33
|
+
error.message += "\n " + hint;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
if (!context.logger || context.logger?.constructor?.name === "NoOpLogger") {
|
|
37
|
+
console.warn(hint);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
context.logger?.warn?.(hint);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (typeof error.$responseBodyText !== "undefined") {
|
|
44
|
+
if (error.$response) {
|
|
45
|
+
error.$response.body = error.$responseBodyText;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
if (protocolHttp.HttpResponse.isInstance(response)) {
|
|
50
|
+
const { headers = {} } = response;
|
|
51
|
+
const headerEntries = Object.entries(headers);
|
|
52
|
+
error.$metadata = {
|
|
53
|
+
httpStatusCode: response.statusCode,
|
|
54
|
+
requestId: findHeader(/^x-[\w-]+-request-?id$/, headerEntries),
|
|
55
|
+
extendedRequestId: findHeader(/^x-[\w-]+-id-2$/, headerEntries),
|
|
56
|
+
cfId: findHeader(/^x-[\w-]+-cf-id$/, headerEntries),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
}
|
|
102
62
|
}
|
|
103
|
-
|
|
104
|
-
}
|
|
63
|
+
throw error;
|
|
105
64
|
}
|
|
106
|
-
throw error2;
|
|
107
|
-
}
|
|
108
65
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
66
|
+
const findHeader = (pattern, headers) => {
|
|
67
|
+
return (headers.find(([k]) => {
|
|
68
|
+
return k.match(pattern);
|
|
69
|
+
}) || [void 0, void 0])[1];
|
|
113
70
|
};
|
|
114
71
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
72
|
+
const schemaSerializationMiddleware = (config) => (next, context) => async (args) => {
|
|
73
|
+
const { operationSchema } = utilMiddleware.getSmithyContext(context);
|
|
74
|
+
const endpoint = context.endpointV2?.url && config.urlParser
|
|
75
|
+
? async () => config.urlParser(context.endpointV2.url)
|
|
76
|
+
: config.endpoint;
|
|
77
|
+
const request = await config.protocol.serializeRequest(operationSchema, args.input, {
|
|
78
|
+
...config,
|
|
79
|
+
...context,
|
|
80
|
+
endpoint,
|
|
81
|
+
});
|
|
82
|
+
return next({
|
|
83
|
+
...args,
|
|
84
|
+
request,
|
|
85
|
+
});
|
|
129
86
|
};
|
|
130
87
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
override: true
|
|
88
|
+
const deserializerMiddlewareOption = {
|
|
89
|
+
name: "deserializerMiddleware",
|
|
90
|
+
step: "deserialize",
|
|
91
|
+
tags: ["DESERIALIZER"],
|
|
92
|
+
override: true,
|
|
137
93
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
94
|
+
const serializerMiddlewareOption = {
|
|
95
|
+
name: "serializerMiddleware",
|
|
96
|
+
step: "serialize",
|
|
97
|
+
tags: ["SERIALIZER"],
|
|
98
|
+
override: true,
|
|
143
99
|
};
|
|
144
100
|
function getSchemaSerdePlugin(config) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
101
|
+
return {
|
|
102
|
+
applyToStack: (commandStack) => {
|
|
103
|
+
commandStack.add(schemaSerializationMiddleware(config), serializerMiddlewareOption);
|
|
104
|
+
commandStack.add(schemaDeserializationMiddleware(config), deserializerMiddlewareOption);
|
|
105
|
+
config.protocol.setSerdeContext(config);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
class TypeRegistry {
|
|
111
|
+
namespace;
|
|
112
|
+
schemas;
|
|
113
|
+
exceptions;
|
|
114
|
+
static registries = new Map();
|
|
115
|
+
constructor(namespace, schemas = new Map(), exceptions = new Map()) {
|
|
116
|
+
this.namespace = namespace;
|
|
117
|
+
this.schemas = schemas;
|
|
118
|
+
this.exceptions = exceptions;
|
|
119
|
+
}
|
|
120
|
+
static for(namespace) {
|
|
121
|
+
if (!TypeRegistry.registries.has(namespace)) {
|
|
122
|
+
TypeRegistry.registries.set(namespace, new TypeRegistry(namespace));
|
|
123
|
+
}
|
|
124
|
+
return TypeRegistry.registries.get(namespace);
|
|
125
|
+
}
|
|
126
|
+
register(shapeId, schema) {
|
|
127
|
+
const qualifiedName = this.normalizeShapeId(shapeId);
|
|
128
|
+
this.schemas.set(qualifiedName, schema);
|
|
129
|
+
}
|
|
130
|
+
getSchema(shapeId) {
|
|
131
|
+
const id = this.normalizeShapeId(shapeId);
|
|
132
|
+
if (!this.schemas.has(id)) {
|
|
133
|
+
throw new Error(`@smithy/core/schema - schema not found for ${id}`);
|
|
134
|
+
}
|
|
135
|
+
return this.schemas.get(id);
|
|
136
|
+
}
|
|
137
|
+
registerError(errorSchema, ctor) {
|
|
138
|
+
this.exceptions.set(errorSchema, ctor);
|
|
139
|
+
}
|
|
140
|
+
getErrorCtor(errorSchema) {
|
|
141
|
+
return this.exceptions.get(errorSchema);
|
|
142
|
+
}
|
|
143
|
+
getBaseException() {
|
|
144
|
+
for (const [id, schema] of this.schemas.entries()) {
|
|
145
|
+
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
|
|
146
|
+
return schema;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
find(predicate) {
|
|
152
|
+
return [...this.schemas.values()].find(predicate);
|
|
153
|
+
}
|
|
154
|
+
clear() {
|
|
155
|
+
this.schemas.clear();
|
|
156
|
+
this.exceptions.clear();
|
|
157
|
+
}
|
|
158
|
+
normalizeShapeId(shapeId) {
|
|
159
|
+
if (shapeId.includes("#")) {
|
|
160
|
+
return shapeId;
|
|
161
|
+
}
|
|
162
|
+
return this.namespace + "#" + shapeId;
|
|
163
|
+
}
|
|
164
|
+
getNamespace(shapeId) {
|
|
165
|
+
return this.normalizeShapeId(shapeId).split("#")[0];
|
|
150
166
|
}
|
|
151
|
-
};
|
|
152
167
|
}
|
|
153
168
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
static {
|
|
162
|
-
this.registries = /* @__PURE__ */ new Map();
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* @param namespace - specifier.
|
|
166
|
-
* @returns the schema for that namespace, creating it if necessary.
|
|
167
|
-
*/
|
|
168
|
-
static for(namespace) {
|
|
169
|
-
if (!_TypeRegistry.registries.has(namespace)) {
|
|
170
|
-
_TypeRegistry.registries.set(namespace, new _TypeRegistry(namespace));
|
|
171
|
-
}
|
|
172
|
-
return _TypeRegistry.registries.get(namespace);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Adds the given schema to a type registry with the same namespace.
|
|
176
|
-
*
|
|
177
|
-
* @param shapeId - to be registered.
|
|
178
|
-
* @param schema - to be registered.
|
|
179
|
-
*/
|
|
180
|
-
register(shapeId, schema) {
|
|
181
|
-
const qualifiedName = this.normalizeShapeId(shapeId);
|
|
182
|
-
this.schemas.set(qualifiedName, schema);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* @param shapeId - query.
|
|
186
|
-
* @returns the schema.
|
|
187
|
-
*/
|
|
188
|
-
getSchema(shapeId) {
|
|
189
|
-
const id = this.normalizeShapeId(shapeId);
|
|
190
|
-
if (!this.schemas.has(id)) {
|
|
191
|
-
throw new Error(`@smithy/core/schema - schema not found for ${id}`);
|
|
192
|
-
}
|
|
193
|
-
return this.schemas.get(id);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Associates an error schema with its constructor.
|
|
197
|
-
*/
|
|
198
|
-
registerError(errorSchema, ctor) {
|
|
199
|
-
this.exceptions.set(errorSchema, ctor);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* @param errorSchema - query.
|
|
203
|
-
* @returns Error constructor that extends the service's base exception.
|
|
204
|
-
*/
|
|
205
|
-
getErrorCtor(errorSchema) {
|
|
206
|
-
return this.exceptions.get(errorSchema);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* The smithy-typescript code generator generates a synthetic (i.e. unmodeled) base exception,
|
|
210
|
-
* because generated SDKs before the introduction of schemas have the notion of a ServiceBaseException, which
|
|
211
|
-
* is unique per service/model.
|
|
212
|
-
*
|
|
213
|
-
* This is generated under a unique prefix that is combined with the service namespace, and this
|
|
214
|
-
* method is used to retrieve it.
|
|
215
|
-
*
|
|
216
|
-
* The base exception synthetic schema is used when an error is returned by a service, but we cannot
|
|
217
|
-
* determine what existing schema to use to deserialize it.
|
|
218
|
-
*
|
|
219
|
-
* @returns the synthetic base exception of the service namespace associated with this registry instance.
|
|
220
|
-
*/
|
|
221
|
-
getBaseException() {
|
|
222
|
-
for (const [id, schema] of this.schemas.entries()) {
|
|
223
|
-
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
|
|
169
|
+
class Schema {
|
|
170
|
+
name;
|
|
171
|
+
namespace;
|
|
172
|
+
traits;
|
|
173
|
+
static assign(instance, values) {
|
|
174
|
+
const schema = Object.assign(instance, values);
|
|
175
|
+
TypeRegistry.for(schema.namespace).register(schema.name, schema);
|
|
224
176
|
return schema;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
*/
|
|
239
|
-
clear() {
|
|
240
|
-
this.schemas.clear();
|
|
241
|
-
this.exceptions.clear();
|
|
242
|
-
}
|
|
243
|
-
normalizeShapeId(shapeId) {
|
|
244
|
-
if (shapeId.includes("#")) {
|
|
245
|
-
return shapeId;
|
|
246
|
-
}
|
|
247
|
-
return this.namespace + "#" + shapeId;
|
|
248
|
-
}
|
|
249
|
-
getNamespace(shapeId) {
|
|
250
|
-
return this.normalizeShapeId(shapeId).split("#")[0];
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
// src/submodules/schema/schemas/Schema.ts
|
|
255
|
-
var Schema = class {
|
|
256
|
-
static assign(instance, values) {
|
|
257
|
-
const schema = Object.assign(instance, values);
|
|
258
|
-
TypeRegistry.for(schema.namespace).register(schema.name, schema);
|
|
259
|
-
return schema;
|
|
260
|
-
}
|
|
261
|
-
static [Symbol.hasInstance](lhs) {
|
|
262
|
-
const isPrototype = this.prototype.isPrototypeOf(lhs);
|
|
263
|
-
if (!isPrototype && typeof lhs === "object" && lhs !== null) {
|
|
264
|
-
const list2 = lhs;
|
|
265
|
-
return list2.symbol === this.symbol;
|
|
266
|
-
}
|
|
267
|
-
return isPrototype;
|
|
268
|
-
}
|
|
269
|
-
getName() {
|
|
270
|
-
return this.namespace + "#" + this.name;
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
// src/submodules/schema/schemas/ListSchema.ts
|
|
275
|
-
var ListSchema = class _ListSchema extends Schema {
|
|
276
|
-
constructor() {
|
|
277
|
-
super(...arguments);
|
|
278
|
-
this.symbol = _ListSchema.symbol;
|
|
279
|
-
}
|
|
280
|
-
static {
|
|
281
|
-
this.symbol = Symbol.for("@smithy/lis");
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
var list = (namespace, name, traits, valueSchema) => Schema.assign(new ListSchema(), {
|
|
285
|
-
name,
|
|
286
|
-
namespace,
|
|
287
|
-
traits,
|
|
288
|
-
valueSchema
|
|
289
|
-
});
|
|
177
|
+
}
|
|
178
|
+
static [Symbol.hasInstance](lhs) {
|
|
179
|
+
const isPrototype = this.prototype.isPrototypeOf(lhs);
|
|
180
|
+
if (!isPrototype && typeof lhs === "object" && lhs !== null) {
|
|
181
|
+
const list = lhs;
|
|
182
|
+
return list.symbol === this.symbol;
|
|
183
|
+
}
|
|
184
|
+
return isPrototype;
|
|
185
|
+
}
|
|
186
|
+
getName() {
|
|
187
|
+
return this.namespace + "#" + this.name;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
290
190
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
namespace,
|
|
304
|
-
traits,
|
|
305
|
-
keySchema,
|
|
306
|
-
valueSchema
|
|
191
|
+
class ListSchema extends Schema {
|
|
192
|
+
static symbol = Symbol.for("@smithy/lis");
|
|
193
|
+
name;
|
|
194
|
+
traits;
|
|
195
|
+
valueSchema;
|
|
196
|
+
symbol = ListSchema.symbol;
|
|
197
|
+
}
|
|
198
|
+
const list = (namespace, name, traits, valueSchema) => Schema.assign(new ListSchema(), {
|
|
199
|
+
name,
|
|
200
|
+
namespace,
|
|
201
|
+
traits,
|
|
202
|
+
valueSchema,
|
|
307
203
|
});
|
|
308
204
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
input,
|
|
324
|
-
output
|
|
205
|
+
class MapSchema extends Schema {
|
|
206
|
+
static symbol = Symbol.for("@smithy/map");
|
|
207
|
+
name;
|
|
208
|
+
traits;
|
|
209
|
+
keySchema;
|
|
210
|
+
valueSchema;
|
|
211
|
+
symbol = MapSchema.symbol;
|
|
212
|
+
}
|
|
213
|
+
const map = (namespace, name, traits, keySchema, valueSchema) => Schema.assign(new MapSchema(), {
|
|
214
|
+
name,
|
|
215
|
+
namespace,
|
|
216
|
+
traits,
|
|
217
|
+
keySchema,
|
|
218
|
+
valueSchema,
|
|
325
219
|
});
|
|
326
220
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
memberNames,
|
|
342
|
-
memberList
|
|
221
|
+
class OperationSchema extends Schema {
|
|
222
|
+
static symbol = Symbol.for("@smithy/ope");
|
|
223
|
+
name;
|
|
224
|
+
traits;
|
|
225
|
+
input;
|
|
226
|
+
output;
|
|
227
|
+
symbol = OperationSchema.symbol;
|
|
228
|
+
}
|
|
229
|
+
const op = (namespace, name, traits, input, output) => Schema.assign(new OperationSchema(), {
|
|
230
|
+
name,
|
|
231
|
+
namespace,
|
|
232
|
+
traits,
|
|
233
|
+
input,
|
|
234
|
+
output,
|
|
343
235
|
});
|
|
344
236
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
memberNames,
|
|
360
|
-
memberList,
|
|
361
|
-
ctor: null
|
|
237
|
+
class StructureSchema extends Schema {
|
|
238
|
+
static symbol = Symbol.for("@smithy/str");
|
|
239
|
+
name;
|
|
240
|
+
traits;
|
|
241
|
+
memberNames;
|
|
242
|
+
memberList;
|
|
243
|
+
symbol = StructureSchema.symbol;
|
|
244
|
+
}
|
|
245
|
+
const struct = (namespace, name, traits, memberNames, memberList) => Schema.assign(new StructureSchema(), {
|
|
246
|
+
name,
|
|
247
|
+
namespace,
|
|
248
|
+
traits,
|
|
249
|
+
memberNames,
|
|
250
|
+
memberList,
|
|
362
251
|
});
|
|
363
252
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
BIG_INTEGER: 17,
|
|
377
|
-
// 17
|
|
378
|
-
BIG_DECIMAL: 19,
|
|
379
|
-
// 19
|
|
380
|
-
DOCUMENT: 15,
|
|
381
|
-
// 15
|
|
382
|
-
TIMESTAMP_DEFAULT: 4,
|
|
383
|
-
// 4
|
|
384
|
-
TIMESTAMP_DATE_TIME: 5,
|
|
385
|
-
// 5
|
|
386
|
-
TIMESTAMP_HTTP_DATE: 6,
|
|
387
|
-
// 6
|
|
388
|
-
TIMESTAMP_EPOCH_SECONDS: 7,
|
|
389
|
-
// 7
|
|
390
|
-
LIST_MODIFIER: 64,
|
|
391
|
-
// 64
|
|
392
|
-
MAP_MODIFIER: 128
|
|
393
|
-
// 128
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
// src/submodules/schema/schemas/SimpleSchema.ts
|
|
397
|
-
var SimpleSchema = class _SimpleSchema extends Schema {
|
|
398
|
-
constructor() {
|
|
399
|
-
super(...arguments);
|
|
400
|
-
this.symbol = _SimpleSchema.symbol;
|
|
401
|
-
}
|
|
402
|
-
static {
|
|
403
|
-
this.symbol = Symbol.for("@smithy/sim");
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
var sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSchema(), {
|
|
407
|
-
name,
|
|
408
|
-
namespace,
|
|
409
|
-
traits,
|
|
410
|
-
schemaRef
|
|
253
|
+
class ErrorSchema extends StructureSchema {
|
|
254
|
+
static symbol = Symbol.for("@smithy/err");
|
|
255
|
+
ctor;
|
|
256
|
+
symbol = ErrorSchema.symbol;
|
|
257
|
+
}
|
|
258
|
+
const error = (namespace, name, traits, memberNames, memberList, ctor) => Schema.assign(new ErrorSchema(), {
|
|
259
|
+
name,
|
|
260
|
+
namespace,
|
|
261
|
+
traits,
|
|
262
|
+
memberNames,
|
|
263
|
+
memberList,
|
|
264
|
+
ctor: null,
|
|
411
265
|
});
|
|
412
266
|
|
|
413
|
-
|
|
414
|
-
var NormalizedSchema = class _NormalizedSchema {
|
|
415
|
-
/**
|
|
416
|
-
* @param ref - a polymorphic SchemaRef to be dereferenced/normalized.
|
|
417
|
-
* @param memberName - optional memberName if this NormalizedSchema should be considered a member schema.
|
|
418
|
-
*/
|
|
419
|
-
constructor(ref, memberName) {
|
|
420
|
-
this.ref = ref;
|
|
421
|
-
this.memberName = memberName;
|
|
422
|
-
this.symbol = _NormalizedSchema.symbol;
|
|
423
|
-
const traitStack = [];
|
|
424
|
-
let _ref = ref;
|
|
425
|
-
let schema = ref;
|
|
426
|
-
this._isMemberSchema = false;
|
|
427
|
-
while (Array.isArray(_ref)) {
|
|
428
|
-
traitStack.push(_ref[1]);
|
|
429
|
-
_ref = _ref[0];
|
|
430
|
-
schema = deref(_ref);
|
|
431
|
-
this._isMemberSchema = true;
|
|
432
|
-
}
|
|
433
|
-
if (traitStack.length > 0) {
|
|
434
|
-
this.memberTraits = {};
|
|
435
|
-
for (let i = traitStack.length - 1; i >= 0; --i) {
|
|
436
|
-
const traitSet = traitStack[i];
|
|
437
|
-
Object.assign(this.memberTraits, _NormalizedSchema.translateTraits(traitSet));
|
|
438
|
-
}
|
|
439
|
-
} else {
|
|
440
|
-
this.memberTraits = 0;
|
|
441
|
-
}
|
|
442
|
-
if (schema instanceof _NormalizedSchema) {
|
|
443
|
-
const computedMemberTraits = this.memberTraits;
|
|
444
|
-
Object.assign(this, schema);
|
|
445
|
-
this.memberTraits = Object.assign({}, computedMemberTraits, schema.getMemberTraits(), this.getMemberTraits());
|
|
446
|
-
this.normalizedTraits = void 0;
|
|
447
|
-
this.memberName = memberName ?? schema.memberName;
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
this.schema = deref(schema);
|
|
451
|
-
if (this.schema && typeof this.schema === "object") {
|
|
452
|
-
this.traits = this.schema?.traits ?? {};
|
|
453
|
-
} else {
|
|
454
|
-
this.traits = 0;
|
|
455
|
-
}
|
|
456
|
-
this.name = (this.schema instanceof Schema ? this.schema.getName?.() : void 0) ?? this.memberName ?? this.getSchemaName();
|
|
457
|
-
if (this._isMemberSchema && !memberName) {
|
|
458
|
-
throw new Error(`@smithy/core/schema - NormalizedSchema member init ${this.getName(true)} missing member name.`);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
static {
|
|
462
|
-
this.symbol = Symbol.for("@smithy/nor");
|
|
463
|
-
}
|
|
464
|
-
static [Symbol.hasInstance](lhs) {
|
|
465
|
-
return Schema[Symbol.hasInstance].bind(this)(lhs);
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Static constructor that attempts to avoid wrapping a NormalizedSchema within another.
|
|
469
|
-
*/
|
|
470
|
-
static of(ref) {
|
|
471
|
-
if (ref instanceof _NormalizedSchema) {
|
|
472
|
-
return ref;
|
|
473
|
-
}
|
|
474
|
-
if (Array.isArray(ref)) {
|
|
475
|
-
const [ns, traits] = ref;
|
|
476
|
-
if (ns instanceof _NormalizedSchema) {
|
|
477
|
-
Object.assign(ns.getMergedTraits(), _NormalizedSchema.translateTraits(traits));
|
|
478
|
-
return ns;
|
|
479
|
-
}
|
|
480
|
-
throw new Error(`@smithy/core/schema - may not init unwrapped member schema=${JSON.stringify(ref, null, 2)}.`);
|
|
481
|
-
}
|
|
482
|
-
return new _NormalizedSchema(ref);
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* @param indicator - numeric indicator for preset trait combination.
|
|
486
|
-
* @returns equivalent trait object.
|
|
487
|
-
*/
|
|
488
|
-
static translateTraits(indicator) {
|
|
267
|
+
function translateTraits(indicator) {
|
|
489
268
|
if (typeof indicator === "object") {
|
|
490
|
-
|
|
269
|
+
return indicator;
|
|
491
270
|
}
|
|
492
271
|
indicator = indicator | 0;
|
|
493
272
|
const traits = {};
|
|
494
273
|
let i = 0;
|
|
495
274
|
for (const trait of [
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
275
|
+
"httpLabel",
|
|
276
|
+
"idempotent",
|
|
277
|
+
"idempotencyToken",
|
|
278
|
+
"sensitive",
|
|
279
|
+
"httpPayload",
|
|
280
|
+
"httpResponseCode",
|
|
281
|
+
"httpQueryParams",
|
|
503
282
|
]) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
283
|
+
if (((indicator >> i++) & 1) === 1) {
|
|
284
|
+
traits[trait] = 1;
|
|
285
|
+
}
|
|
507
286
|
}
|
|
508
287
|
return traits;
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* @returns the member name if the schema is a member schema.
|
|
537
|
-
* @throws Error when the schema isn't a member schema.
|
|
538
|
-
*/
|
|
539
|
-
getMemberName() {
|
|
540
|
-
if (!this.isMemberSchema()) {
|
|
541
|
-
throw new Error(`@smithy/core/schema - non-member schema: ${this.getName(true)}`);
|
|
542
|
-
}
|
|
543
|
-
return this.memberName;
|
|
544
|
-
}
|
|
545
|
-
isMemberSchema() {
|
|
546
|
-
return this._isMemberSchema;
|
|
547
|
-
}
|
|
548
|
-
isUnitSchema() {
|
|
549
|
-
return this.getSchema() === "unit";
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* boolean methods on this class help control flow in shape serialization and deserialization.
|
|
553
|
-
*/
|
|
554
|
-
isListSchema() {
|
|
555
|
-
const inner = this.getSchema();
|
|
556
|
-
if (typeof inner === "number") {
|
|
557
|
-
return inner >= SCHEMA.LIST_MODIFIER && inner < SCHEMA.MAP_MODIFIER;
|
|
558
|
-
}
|
|
559
|
-
return inner instanceof ListSchema;
|
|
560
|
-
}
|
|
561
|
-
isMapSchema() {
|
|
562
|
-
const inner = this.getSchema();
|
|
563
|
-
if (typeof inner === "number") {
|
|
564
|
-
return inner >= SCHEMA.MAP_MODIFIER && inner <= 255;
|
|
565
|
-
}
|
|
566
|
-
return inner instanceof MapSchema;
|
|
567
|
-
}
|
|
568
|
-
isStructSchema() {
|
|
569
|
-
const inner = this.getSchema();
|
|
570
|
-
return inner !== null && typeof inner === "object" && "members" in inner || inner instanceof StructureSchema;
|
|
571
|
-
}
|
|
572
|
-
isBlobSchema() {
|
|
573
|
-
return this.getSchema() === SCHEMA.BLOB || this.getSchema() === SCHEMA.STREAMING_BLOB;
|
|
574
|
-
}
|
|
575
|
-
isTimestampSchema() {
|
|
576
|
-
const schema = this.getSchema();
|
|
577
|
-
return typeof schema === "number" && schema >= SCHEMA.TIMESTAMP_DEFAULT && schema <= SCHEMA.TIMESTAMP_EPOCH_SECONDS;
|
|
578
|
-
}
|
|
579
|
-
isDocumentSchema() {
|
|
580
|
-
return this.getSchema() === SCHEMA.DOCUMENT;
|
|
581
|
-
}
|
|
582
|
-
isStringSchema() {
|
|
583
|
-
return this.getSchema() === SCHEMA.STRING;
|
|
584
|
-
}
|
|
585
|
-
isBooleanSchema() {
|
|
586
|
-
return this.getSchema() === SCHEMA.BOOLEAN;
|
|
587
|
-
}
|
|
588
|
-
isNumericSchema() {
|
|
589
|
-
return this.getSchema() === SCHEMA.NUMERIC;
|
|
590
|
-
}
|
|
591
|
-
isBigIntegerSchema() {
|
|
592
|
-
return this.getSchema() === SCHEMA.BIG_INTEGER;
|
|
593
|
-
}
|
|
594
|
-
isBigDecimalSchema() {
|
|
595
|
-
return this.getSchema() === SCHEMA.BIG_DECIMAL;
|
|
596
|
-
}
|
|
597
|
-
isStreaming() {
|
|
598
|
-
const streaming = !!this.getMergedTraits().streaming;
|
|
599
|
-
if (streaming) {
|
|
600
|
-
return true;
|
|
601
|
-
}
|
|
602
|
-
return this.getSchema() === SCHEMA.STREAMING_BLOB;
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* This is a shortcut to avoid calling `getMergedTraits().idempotencyToken` on every string.
|
|
606
|
-
* @returns whether the schema has the idempotencyToken trait.
|
|
607
|
-
*/
|
|
608
|
-
isIdempotencyToken() {
|
|
609
|
-
if (this.normalizedTraits) {
|
|
610
|
-
return !!this.normalizedTraits.idempotencyToken;
|
|
611
|
-
}
|
|
612
|
-
for (const traits of [this.traits, this.memberTraits]) {
|
|
613
|
-
if (typeof traits === "number") {
|
|
614
|
-
if ((traits & 4) === 4) {
|
|
615
|
-
return true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
class NormalizedSchema {
|
|
291
|
+
ref;
|
|
292
|
+
memberName;
|
|
293
|
+
static symbol = Symbol.for("@smithy/nor");
|
|
294
|
+
symbol = NormalizedSchema.symbol;
|
|
295
|
+
name;
|
|
296
|
+
schema;
|
|
297
|
+
_isMemberSchema;
|
|
298
|
+
traits;
|
|
299
|
+
memberTraits;
|
|
300
|
+
normalizedTraits;
|
|
301
|
+
constructor(ref, memberName) {
|
|
302
|
+
this.ref = ref;
|
|
303
|
+
this.memberName = memberName;
|
|
304
|
+
const traitStack = [];
|
|
305
|
+
let _ref = ref;
|
|
306
|
+
let schema = ref;
|
|
307
|
+
this._isMemberSchema = false;
|
|
308
|
+
while (Array.isArray(_ref)) {
|
|
309
|
+
traitStack.push(_ref[1]);
|
|
310
|
+
_ref = _ref[0];
|
|
311
|
+
schema = deref(_ref);
|
|
312
|
+
this._isMemberSchema = true;
|
|
616
313
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
314
|
+
if (traitStack.length > 0) {
|
|
315
|
+
this.memberTraits = {};
|
|
316
|
+
for (let i = traitStack.length - 1; i >= 0; --i) {
|
|
317
|
+
const traitSet = traitStack[i];
|
|
318
|
+
Object.assign(this.memberTraits, translateTraits(traitSet));
|
|
319
|
+
}
|
|
620
320
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
return false;
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* @returns own traits merged with member traits, where member traits of the same trait key take priority.
|
|
627
|
-
* This method is cached.
|
|
628
|
-
*/
|
|
629
|
-
getMergedTraits() {
|
|
630
|
-
return this.normalizedTraits ?? (this.normalizedTraits = {
|
|
631
|
-
...this.getOwnTraits(),
|
|
632
|
-
...this.getMemberTraits()
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* @returns only the member traits. If the schema is not a member, this returns empty.
|
|
637
|
-
*/
|
|
638
|
-
getMemberTraits() {
|
|
639
|
-
return _NormalizedSchema.translateTraits(this.memberTraits);
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* @returns only the traits inherent to the shape or member target shape if this schema is a member.
|
|
643
|
-
* If there are any member traits they are excluded.
|
|
644
|
-
*/
|
|
645
|
-
getOwnTraits() {
|
|
646
|
-
return _NormalizedSchema.translateTraits(this.traits);
|
|
647
|
-
}
|
|
648
|
-
/**
|
|
649
|
-
* @returns the map's key's schema. Returns a dummy Document schema if this schema is a Document.
|
|
650
|
-
*
|
|
651
|
-
* @throws Error if the schema is not a Map or Document.
|
|
652
|
-
*/
|
|
653
|
-
getKeySchema() {
|
|
654
|
-
if (this.isDocumentSchema()) {
|
|
655
|
-
return this.memberFrom([SCHEMA.DOCUMENT, 0], "key");
|
|
656
|
-
}
|
|
657
|
-
if (!this.isMapSchema()) {
|
|
658
|
-
throw new Error(`@smithy/core/schema - cannot get key for non-map: ${this.getName(true)}`);
|
|
659
|
-
}
|
|
660
|
-
const schema = this.getSchema();
|
|
661
|
-
if (typeof schema === "number") {
|
|
662
|
-
return this.memberFrom([63 & schema, 0], "key");
|
|
663
|
-
}
|
|
664
|
-
return this.memberFrom([schema.keySchema, 0], "key");
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* @returns the schema of the map's value or list's member.
|
|
668
|
-
* Returns a dummy Document schema if this schema is a Document.
|
|
669
|
-
*
|
|
670
|
-
* @throws Error if the schema is not a Map, List, nor Document.
|
|
671
|
-
*/
|
|
672
|
-
getValueSchema() {
|
|
673
|
-
const schema = this.getSchema();
|
|
674
|
-
if (typeof schema === "number") {
|
|
675
|
-
if (this.isMapSchema()) {
|
|
676
|
-
return this.memberFrom([63 & schema, 0], "value");
|
|
677
|
-
} else if (this.isListSchema()) {
|
|
678
|
-
return this.memberFrom([63 & schema, 0], "member");
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
if (schema && typeof schema === "object") {
|
|
682
|
-
if (this.isStructSchema()) {
|
|
683
|
-
throw new Error(`may not getValueSchema() on structure ${this.getName(true)}`);
|
|
684
|
-
}
|
|
685
|
-
const collection = schema;
|
|
686
|
-
if ("valueSchema" in collection) {
|
|
687
|
-
if (this.isMapSchema()) {
|
|
688
|
-
return this.memberFrom([collection.valueSchema, 0], "value");
|
|
689
|
-
} else if (this.isListSchema()) {
|
|
690
|
-
return this.memberFrom([collection.valueSchema, 0], "member");
|
|
321
|
+
else {
|
|
322
|
+
this.memberTraits = 0;
|
|
691
323
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* @param member - to query.
|
|
701
|
-
* @returns whether there is a memberSchema with the given member name. False if not a structure (or union).
|
|
702
|
-
*/
|
|
703
|
-
hasMemberSchema(member) {
|
|
704
|
-
if (this.isStructSchema()) {
|
|
705
|
-
const struct2 = this.getSchema();
|
|
706
|
-
return struct2.memberNames.includes(member);
|
|
707
|
-
}
|
|
708
|
-
return false;
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* @returns the NormalizedSchema for the given member name. The returned instance will return true for `isMemberSchema()`
|
|
712
|
-
* and will have the member name given.
|
|
713
|
-
* @param member - which member to retrieve and wrap.
|
|
714
|
-
*
|
|
715
|
-
* @throws Error if member does not exist or the schema is neither a document nor structure.
|
|
716
|
-
* Note that errors are assumed to be structures and unions are considered structures for these purposes.
|
|
717
|
-
*/
|
|
718
|
-
getMemberSchema(member) {
|
|
719
|
-
if (this.isStructSchema()) {
|
|
720
|
-
const struct2 = this.getSchema();
|
|
721
|
-
if (!struct2.memberNames.includes(member)) {
|
|
722
|
-
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no member=${member}.`);
|
|
723
|
-
}
|
|
724
|
-
const i = struct2.memberNames.indexOf(member);
|
|
725
|
-
const memberSchema = struct2.memberList[i];
|
|
726
|
-
return this.memberFrom(Array.isArray(memberSchema) ? memberSchema : [memberSchema, 0], member);
|
|
727
|
-
}
|
|
728
|
-
if (this.isDocumentSchema()) {
|
|
729
|
-
return this.memberFrom([SCHEMA.DOCUMENT, 0], member);
|
|
730
|
-
}
|
|
731
|
-
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no members.`);
|
|
732
|
-
}
|
|
733
|
-
/**
|
|
734
|
-
* This can be used for checking the members as a hashmap.
|
|
735
|
-
* Prefer the structIterator method for iteration.
|
|
736
|
-
*
|
|
737
|
-
* This does NOT return list and map members, it is only for structures.
|
|
738
|
-
*
|
|
739
|
-
* @deprecated use (checked) structIterator instead.
|
|
740
|
-
*
|
|
741
|
-
* @returns a map of member names to member schemas (normalized).
|
|
742
|
-
*/
|
|
743
|
-
getMemberSchemas() {
|
|
744
|
-
const buffer = {};
|
|
745
|
-
try {
|
|
746
|
-
for (const [k, v] of this.structIterator()) {
|
|
747
|
-
buffer[k] = v;
|
|
748
|
-
}
|
|
749
|
-
} catch (ignored) {
|
|
750
|
-
}
|
|
751
|
-
return buffer;
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* @returns member name of event stream or empty string indicating none exists or this
|
|
755
|
-
* isn't a structure schema.
|
|
756
|
-
*/
|
|
757
|
-
getEventStreamMember() {
|
|
758
|
-
if (this.isStructSchema()) {
|
|
759
|
-
for (const [memberName, memberSchema] of this.structIterator()) {
|
|
760
|
-
if (memberSchema.isStreaming() && memberSchema.isStructSchema()) {
|
|
761
|
-
return memberName;
|
|
324
|
+
if (schema instanceof NormalizedSchema) {
|
|
325
|
+
const computedMemberTraits = this.memberTraits;
|
|
326
|
+
Object.assign(this, schema);
|
|
327
|
+
this.memberTraits = Object.assign({}, computedMemberTraits, schema.getMemberTraits(), this.getMemberTraits());
|
|
328
|
+
this.normalizedTraits = void 0;
|
|
329
|
+
this.memberName = memberName ?? schema.memberName;
|
|
330
|
+
return;
|
|
762
331
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
332
|
+
this.schema = deref(schema);
|
|
333
|
+
if (this.schema && typeof this.schema === "object") {
|
|
334
|
+
this.traits = this.schema?.traits ?? {};
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
this.traits = 0;
|
|
338
|
+
}
|
|
339
|
+
this.name = (this.schema instanceof Schema ? this.schema.getName?.() : void 0) ?? this.memberName ?? String(schema);
|
|
340
|
+
if (this._isMemberSchema && !memberName) {
|
|
341
|
+
throw new Error(`@smithy/core/schema - NormalizedSchema member init ${this.getName(true)} missing member name.`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
static [Symbol.hasInstance](lhs) {
|
|
345
|
+
return Schema[Symbol.hasInstance].bind(this)(lhs);
|
|
346
|
+
}
|
|
347
|
+
static of(ref) {
|
|
348
|
+
const sc = deref(ref);
|
|
349
|
+
if (sc instanceof NormalizedSchema) {
|
|
350
|
+
return sc;
|
|
351
|
+
}
|
|
352
|
+
if (Array.isArray(sc)) {
|
|
353
|
+
const [ns, traits] = sc;
|
|
354
|
+
if (ns instanceof NormalizedSchema) {
|
|
355
|
+
Object.assign(ns.getMergedTraits(), translateTraits(traits));
|
|
356
|
+
return ns;
|
|
357
|
+
}
|
|
358
|
+
throw new Error(`@smithy/core/schema - may not init unwrapped member schema=${JSON.stringify(ref, null, 2)}.`);
|
|
359
|
+
}
|
|
360
|
+
return new NormalizedSchema(sc);
|
|
361
|
+
}
|
|
362
|
+
getSchema() {
|
|
363
|
+
return deref(this.schema?.schemaRef ?? this.schema);
|
|
364
|
+
}
|
|
365
|
+
getName(withNamespace = false) {
|
|
366
|
+
const { name } = this;
|
|
367
|
+
const short = !withNamespace && name && name.includes("#");
|
|
368
|
+
return short ? name.split("#")[1] : name || undefined;
|
|
369
|
+
}
|
|
370
|
+
getMemberName() {
|
|
371
|
+
return this.memberName;
|
|
372
|
+
}
|
|
373
|
+
isMemberSchema() {
|
|
374
|
+
return this._isMemberSchema;
|
|
375
|
+
}
|
|
376
|
+
isListSchema() {
|
|
377
|
+
const sc = this.getSchema();
|
|
378
|
+
return typeof sc === "number"
|
|
379
|
+
? sc >= 64 && sc < 128
|
|
380
|
+
: sc instanceof ListSchema;
|
|
381
|
+
}
|
|
382
|
+
isMapSchema() {
|
|
383
|
+
const sc = this.getSchema();
|
|
384
|
+
return typeof sc === "number"
|
|
385
|
+
? sc >= 128 && sc <= 0b1111_1111
|
|
386
|
+
: sc instanceof MapSchema;
|
|
387
|
+
}
|
|
388
|
+
isStructSchema() {
|
|
389
|
+
const sc = this.getSchema();
|
|
390
|
+
return (sc !== null && typeof sc === "object" && "members" in sc) || sc instanceof StructureSchema;
|
|
391
|
+
}
|
|
392
|
+
isBlobSchema() {
|
|
393
|
+
const sc = this.getSchema();
|
|
394
|
+
return sc === 21 || sc === 42;
|
|
395
|
+
}
|
|
396
|
+
isTimestampSchema() {
|
|
397
|
+
const sc = this.getSchema();
|
|
398
|
+
return (typeof sc === "number" &&
|
|
399
|
+
sc >= 4 &&
|
|
400
|
+
sc <= 7);
|
|
401
|
+
}
|
|
402
|
+
isUnitSchema() {
|
|
403
|
+
return this.getSchema() === "unit";
|
|
404
|
+
}
|
|
405
|
+
isDocumentSchema() {
|
|
406
|
+
return this.getSchema() === 15;
|
|
407
|
+
}
|
|
408
|
+
isStringSchema() {
|
|
409
|
+
return this.getSchema() === 0;
|
|
410
|
+
}
|
|
411
|
+
isBooleanSchema() {
|
|
412
|
+
return this.getSchema() === 2;
|
|
413
|
+
}
|
|
414
|
+
isNumericSchema() {
|
|
415
|
+
return this.getSchema() === 1;
|
|
416
|
+
}
|
|
417
|
+
isBigIntegerSchema() {
|
|
418
|
+
return this.getSchema() === 17;
|
|
419
|
+
}
|
|
420
|
+
isBigDecimalSchema() {
|
|
421
|
+
return this.getSchema() === 19;
|
|
422
|
+
}
|
|
423
|
+
isStreaming() {
|
|
424
|
+
const { streaming } = this.getMergedTraits();
|
|
425
|
+
return !!streaming || this.getSchema() === 42;
|
|
426
|
+
}
|
|
427
|
+
isIdempotencyToken() {
|
|
428
|
+
const match = (traits) => (traits & 0b0100) === 0b0100 ||
|
|
429
|
+
!!traits?.idempotencyToken;
|
|
430
|
+
const { normalizedTraits, traits, memberTraits } = this;
|
|
431
|
+
return match(normalizedTraits) || match(traits) || match(memberTraits);
|
|
432
|
+
}
|
|
433
|
+
getMergedTraits() {
|
|
434
|
+
return (this.normalizedTraits ??
|
|
435
|
+
(this.normalizedTraits = {
|
|
436
|
+
...this.getOwnTraits(),
|
|
437
|
+
...this.getMemberTraits(),
|
|
438
|
+
}));
|
|
439
|
+
}
|
|
440
|
+
getMemberTraits() {
|
|
441
|
+
return translateTraits(this.memberTraits);
|
|
442
|
+
}
|
|
443
|
+
getOwnTraits() {
|
|
444
|
+
return translateTraits(this.traits);
|
|
445
|
+
}
|
|
446
|
+
getKeySchema() {
|
|
447
|
+
const [isDoc, isMap] = [this.isDocumentSchema(), this.isMapSchema()];
|
|
448
|
+
if (!isDoc && !isMap) {
|
|
449
|
+
throw new Error(`@smithy/core/schema - cannot get key for non-map: ${this.getName(true)}`);
|
|
450
|
+
}
|
|
451
|
+
const schema = this.getSchema();
|
|
452
|
+
const memberSchema = isDoc
|
|
453
|
+
? 15
|
|
454
|
+
: schema?.keySchema ?? 0;
|
|
455
|
+
return member([memberSchema, 0], "key");
|
|
456
|
+
}
|
|
457
|
+
getValueSchema() {
|
|
458
|
+
const sc = this.getSchema();
|
|
459
|
+
const [isDoc, isMap, isList] = [this.isDocumentSchema(), this.isMapSchema(), this.isListSchema()];
|
|
460
|
+
const memberSchema = typeof sc === "number"
|
|
461
|
+
? 0b0011_1111 & sc
|
|
462
|
+
: sc && typeof sc === "object" && (isMap || isList)
|
|
463
|
+
? sc.valueSchema
|
|
464
|
+
: isDoc
|
|
465
|
+
? 15
|
|
466
|
+
: void 0;
|
|
467
|
+
if (memberSchema != null) {
|
|
468
|
+
return member([memberSchema, 0], isMap ? "value" : "member");
|
|
469
|
+
}
|
|
470
|
+
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no value member.`);
|
|
471
|
+
}
|
|
472
|
+
getMemberSchema(memberName) {
|
|
473
|
+
const struct = this.getSchema();
|
|
474
|
+
if (this.isStructSchema() && struct.memberNames.includes(memberName)) {
|
|
475
|
+
const i = struct.memberNames.indexOf(memberName);
|
|
476
|
+
const memberSchema = struct.memberList[i];
|
|
477
|
+
return member(Array.isArray(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
|
|
478
|
+
}
|
|
479
|
+
if (this.isDocumentSchema()) {
|
|
480
|
+
return member([15, 0], memberName);
|
|
481
|
+
}
|
|
482
|
+
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no no member=${memberName}.`);
|
|
483
|
+
}
|
|
484
|
+
getMemberSchemas() {
|
|
485
|
+
const buffer = {};
|
|
486
|
+
try {
|
|
487
|
+
for (const [k, v] of this.structIterator()) {
|
|
488
|
+
buffer[k] = v;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
catch (ignored) { }
|
|
492
|
+
return buffer;
|
|
493
|
+
}
|
|
494
|
+
getEventStreamMember() {
|
|
495
|
+
if (this.isStructSchema()) {
|
|
496
|
+
for (const [memberName, memberSchema] of this.structIterator()) {
|
|
497
|
+
if (memberSchema.isStreaming() && memberSchema.isStructSchema()) {
|
|
498
|
+
return memberName;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return "";
|
|
503
|
+
}
|
|
504
|
+
*structIterator() {
|
|
505
|
+
if (this.isUnitSchema()) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (!this.isStructSchema()) {
|
|
509
|
+
throw new Error("@smithy/core/schema - cannot iterate non-struct schema.");
|
|
510
|
+
}
|
|
511
|
+
const struct = this.getSchema();
|
|
512
|
+
for (let i = 0; i < struct.memberNames.length; ++i) {
|
|
513
|
+
yield [struct.memberNames[i], member([struct.memberList[i], 0], struct.memberNames[i])];
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function member(memberSchema, memberName) {
|
|
518
|
+
if (memberSchema instanceof NormalizedSchema) {
|
|
519
|
+
return Object.assign(memberSchema, {
|
|
520
|
+
memberName,
|
|
521
|
+
_isMemberSchema: true,
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
const internalCtorAccess = NormalizedSchema;
|
|
525
|
+
return new internalCtorAccess(memberSchema, memberName);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
class SimpleSchema extends Schema {
|
|
529
|
+
static symbol = Symbol.for("@smithy/sim");
|
|
530
|
+
name;
|
|
531
|
+
schemaRef;
|
|
532
|
+
traits;
|
|
533
|
+
symbol = SimpleSchema.symbol;
|
|
534
|
+
}
|
|
535
|
+
const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSchema(), {
|
|
536
|
+
name,
|
|
537
|
+
namespace,
|
|
538
|
+
traits,
|
|
539
|
+
schemaRef,
|
|
842
540
|
});
|
|
541
|
+
|
|
542
|
+
const SCHEMA = {
|
|
543
|
+
BLOB: 0b0001_0101,
|
|
544
|
+
STREAMING_BLOB: 0b0010_1010,
|
|
545
|
+
BOOLEAN: 0b0000_0010,
|
|
546
|
+
STRING: 0b0000_0000,
|
|
547
|
+
NUMERIC: 0b0000_0001,
|
|
548
|
+
BIG_INTEGER: 0b0001_0001,
|
|
549
|
+
BIG_DECIMAL: 0b0001_0011,
|
|
550
|
+
DOCUMENT: 0b0000_1111,
|
|
551
|
+
TIMESTAMP_DEFAULT: 0b0000_0100,
|
|
552
|
+
TIMESTAMP_DATE_TIME: 0b0000_0101,
|
|
553
|
+
TIMESTAMP_HTTP_DATE: 0b0000_0110,
|
|
554
|
+
TIMESTAMP_EPOCH_SECONDS: 0b0000_0111,
|
|
555
|
+
LIST_MODIFIER: 0b0100_0000,
|
|
556
|
+
MAP_MODIFIER: 0b1000_0000,
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
exports.ErrorSchema = ErrorSchema;
|
|
560
|
+
exports.ListSchema = ListSchema;
|
|
561
|
+
exports.MapSchema = MapSchema;
|
|
562
|
+
exports.NormalizedSchema = NormalizedSchema;
|
|
563
|
+
exports.OperationSchema = OperationSchema;
|
|
564
|
+
exports.SCHEMA = SCHEMA;
|
|
565
|
+
exports.Schema = Schema;
|
|
566
|
+
exports.SimpleSchema = SimpleSchema;
|
|
567
|
+
exports.StructureSchema = StructureSchema;
|
|
568
|
+
exports.TypeRegistry = TypeRegistry;
|
|
569
|
+
exports.deref = deref;
|
|
570
|
+
exports.deserializerMiddlewareOption = deserializerMiddlewareOption;
|
|
571
|
+
exports.error = error;
|
|
572
|
+
exports.getSchemaSerdePlugin = getSchemaSerdePlugin;
|
|
573
|
+
exports.list = list;
|
|
574
|
+
exports.map = map;
|
|
575
|
+
exports.op = op;
|
|
576
|
+
exports.serializerMiddlewareOption = serializerMiddlewareOption;
|
|
577
|
+
exports.sim = sim;
|
|
578
|
+
exports.struct = struct;
|
|
579
|
+
exports.translateTraits = translateTraits;
|