@smithy/core 3.12.0 → 3.14.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 -967
- package/dist-cjs/submodules/event-streams/index.js +198 -249
- package/dist-cjs/submodules/protocols/index.js +793 -895
- package/dist-cjs/submodules/schema/index.js +617 -798
- package/dist-cjs/submodules/serde/index.js +584 -680
- package/dist-es/submodules/cbor/CborCodec.js +4 -0
- package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +8 -6
- 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 +5 -0
- package/dist-es/submodules/protocols/HttpProtocol.js +2 -0
- package/dist-es/submodules/protocols/requestBuilder.js +9 -7
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +2 -0
- 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 +3 -2
- package/dist-es/submodules/schema/TypeRegistry.js +15 -6
- package/dist-es/submodules/schema/schemas/ErrorSchema.js +4 -6
- 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 +16 -8
- 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/serde/value/NumericValue.js +2 -0
- 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/TypeRegistry.d.ts +11 -1
- package/dist-types/submodules/schema/schemas/ErrorSchema.d.ts +8 -1
- package/dist-types/ts3.4/submodules/schema/TypeRegistry.d.ts +11 -1
- package/dist-types/ts3.4/submodules/schema/schemas/ErrorSchema.d.ts +8 -1
- package/package.json +11 -11
- package/dist-cjs/getSmithyContext.js +0 -1
- package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.js +0 -1
- package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemePlugin.js +0 -1
- package/dist-cjs/middleware-http-auth-scheme/httpAuthSchemeMiddleware.js +0 -1
- package/dist-cjs/middleware-http-auth-scheme/index.js +0 -1
- package/dist-cjs/middleware-http-auth-scheme/resolveAuthOptions.js +0 -1
- package/dist-cjs/middleware-http-signing/getHttpSigningMiddleware.js +0 -1
- package/dist-cjs/middleware-http-signing/httpSigningMiddleware.js +0 -1
- package/dist-cjs/middleware-http-signing/index.js +0 -1
- package/dist-cjs/normalizeProvider.js +0 -1
- package/dist-cjs/pagination/createPaginator.js +0 -1
- package/dist-cjs/protocols/requestBuilder.js +0 -1
- package/dist-cjs/setFeature.js +0 -1
- package/dist-cjs/util-identity-and-auth/DefaultIdentityProviderConfig.js +0 -1
- package/dist-cjs/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.js +0 -1
- package/dist-cjs/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.js +0 -1
- package/dist-cjs/util-identity-and-auth/httpAuthSchemes/index.js +0 -1
- package/dist-cjs/util-identity-and-auth/httpAuthSchemes/noAuth.js +0 -1
- package/dist-cjs/util-identity-and-auth/index.js +0 -1
- package/dist-cjs/util-identity-and-auth/memoizeIdentityProvider.js +0 -1
|
@@ -1,829 +1,648 @@
|
|
|
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
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
throw error2;
|
|
107
|
-
}
|
|
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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
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
|
-
this.registries = /* @__PURE__ */ new Map();
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* @param namespace - specifier.
|
|
165
|
-
* @returns the schema for that namespace, creating it if necessary.
|
|
166
|
-
*/
|
|
167
|
-
static for(namespace) {
|
|
168
|
-
if (!_TypeRegistry.registries.has(namespace)) {
|
|
169
|
-
_TypeRegistry.registries.set(namespace, new _TypeRegistry(namespace));
|
|
170
|
-
}
|
|
171
|
-
return _TypeRegistry.registries.get(namespace);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Adds the given schema to a type registry with the same namespace.
|
|
175
|
-
*
|
|
176
|
-
* @param shapeId - to be registered.
|
|
177
|
-
* @param schema - to be registered.
|
|
178
|
-
*/
|
|
179
|
-
register(shapeId, schema) {
|
|
180
|
-
const qualifiedName = this.normalizeShapeId(shapeId);
|
|
181
|
-
const registry = _TypeRegistry.for(this.getNamespace(shapeId));
|
|
182
|
-
registry.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
|
-
* The smithy-typescript code generator generates a synthetic (i.e. unmodeled) base exception,
|
|
197
|
-
* because generated SDKs before the introduction of schemas have the notion of a ServiceBaseException, which
|
|
198
|
-
* is unique per service/model.
|
|
199
|
-
*
|
|
200
|
-
* This is generated under a unique prefix that is combined with the service namespace, and this
|
|
201
|
-
* method is used to retrieve it.
|
|
202
|
-
*
|
|
203
|
-
* The base exception synthetic schema is used when an error is returned by a service, but we cannot
|
|
204
|
-
* determine what existing schema to use to deserialize it.
|
|
205
|
-
*
|
|
206
|
-
* @returns the synthetic base exception of the service namespace associated with this registry instance.
|
|
207
|
-
*/
|
|
208
|
-
getBaseException() {
|
|
209
|
-
for (const [id, schema] of this.schemas.entries()) {
|
|
210
|
-
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);
|
|
211
176
|
return schema;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
*/
|
|
226
|
-
destroy() {
|
|
227
|
-
_TypeRegistry.registries.delete(this.namespace);
|
|
228
|
-
this.schemas.clear();
|
|
229
|
-
}
|
|
230
|
-
normalizeShapeId(shapeId) {
|
|
231
|
-
if (shapeId.includes("#")) {
|
|
232
|
-
return shapeId;
|
|
233
|
-
}
|
|
234
|
-
return this.namespace + "#" + shapeId;
|
|
235
|
-
}
|
|
236
|
-
getNamespace(shapeId) {
|
|
237
|
-
return this.normalizeShapeId(shapeId).split("#")[0];
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// src/submodules/schema/schemas/Schema.ts
|
|
242
|
-
var Schema = class {
|
|
243
|
-
static assign(instance, values) {
|
|
244
|
-
const schema = Object.assign(instance, values);
|
|
245
|
-
TypeRegistry.for(schema.namespace).register(schema.name, schema);
|
|
246
|
-
return schema;
|
|
247
|
-
}
|
|
248
|
-
static [Symbol.hasInstance](lhs) {
|
|
249
|
-
const isPrototype = this.prototype.isPrototypeOf(lhs);
|
|
250
|
-
if (!isPrototype && typeof lhs === "object" && lhs !== null) {
|
|
251
|
-
const list2 = lhs;
|
|
252
|
-
return list2.symbol === this.symbol;
|
|
253
|
-
}
|
|
254
|
-
return isPrototype;
|
|
255
|
-
}
|
|
256
|
-
getName() {
|
|
257
|
-
return this.namespace + "#" + this.name;
|
|
258
|
-
}
|
|
259
|
-
};
|
|
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
|
+
}
|
|
260
190
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
namespace,
|
|
274
|
-
traits,
|
|
275
|
-
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,
|
|
276
203
|
});
|
|
277
204
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
keySchema,
|
|
293
|
-
valueSchema
|
|
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,
|
|
294
219
|
});
|
|
295
220
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
input,
|
|
311
|
-
output
|
|
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,
|
|
312
235
|
});
|
|
313
236
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
memberNames,
|
|
329
|
-
memberList
|
|
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,
|
|
330
251
|
});
|
|
331
252
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
namespace,
|
|
345
|
-
traits,
|
|
346
|
-
memberNames,
|
|
347
|
-
memberList,
|
|
348
|
-
ctor
|
|
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,
|
|
349
265
|
});
|
|
350
266
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
// 19
|
|
367
|
-
DOCUMENT: 15,
|
|
368
|
-
// 15
|
|
369
|
-
TIMESTAMP_DEFAULT: 4,
|
|
370
|
-
// 4
|
|
371
|
-
TIMESTAMP_DATE_TIME: 5,
|
|
372
|
-
// 5
|
|
373
|
-
TIMESTAMP_HTTP_DATE: 6,
|
|
374
|
-
// 6
|
|
375
|
-
TIMESTAMP_EPOCH_SECONDS: 7,
|
|
376
|
-
// 7
|
|
377
|
-
LIST_MODIFIER: 64,
|
|
378
|
-
// 64
|
|
379
|
-
MAP_MODIFIER: 128
|
|
380
|
-
// 128
|
|
267
|
+
const SCHEMA = {
|
|
268
|
+
BLOB: 0b0001_0101,
|
|
269
|
+
STREAMING_BLOB: 0b0010_1010,
|
|
270
|
+
BOOLEAN: 0b0000_0010,
|
|
271
|
+
STRING: 0b0000_0000,
|
|
272
|
+
NUMERIC: 0b0000_0001,
|
|
273
|
+
BIG_INTEGER: 0b0001_0001,
|
|
274
|
+
BIG_DECIMAL: 0b0001_0011,
|
|
275
|
+
DOCUMENT: 0b0000_1111,
|
|
276
|
+
TIMESTAMP_DEFAULT: 0b0000_0100,
|
|
277
|
+
TIMESTAMP_DATE_TIME: 0b0000_0101,
|
|
278
|
+
TIMESTAMP_HTTP_DATE: 0b0000_0110,
|
|
279
|
+
TIMESTAMP_EPOCH_SECONDS: 0b0000_0111,
|
|
280
|
+
LIST_MODIFIER: 0b0100_0000,
|
|
281
|
+
MAP_MODIFIER: 0b1000_0000,
|
|
381
282
|
};
|
|
382
283
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
namespace,
|
|
396
|
-
traits,
|
|
397
|
-
schemaRef
|
|
284
|
+
class SimpleSchema extends Schema {
|
|
285
|
+
static symbol = Symbol.for("@smithy/sim");
|
|
286
|
+
name;
|
|
287
|
+
schemaRef;
|
|
288
|
+
traits;
|
|
289
|
+
symbol = SimpleSchema.symbol;
|
|
290
|
+
}
|
|
291
|
+
const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSchema(), {
|
|
292
|
+
name,
|
|
293
|
+
namespace,
|
|
294
|
+
traits,
|
|
295
|
+
schemaRef,
|
|
398
296
|
});
|
|
399
297
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
traits
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
}
|
|
752
|
-
return "";
|
|
753
|
-
}
|
|
754
|
-
/**
|
|
755
|
-
* Allows iteration over members of a structure schema.
|
|
756
|
-
* Each yield is a pair of the member name and member schema.
|
|
757
|
-
*
|
|
758
|
-
* This avoids the overhead of calling Object.entries(ns.getMemberSchemas()).
|
|
759
|
-
*/
|
|
760
|
-
*structIterator() {
|
|
761
|
-
if (this.isUnitSchema()) {
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
if (!this.isStructSchema()) {
|
|
765
|
-
throw new Error("@smithy/core/schema - cannot iterate non-struct schema.");
|
|
766
|
-
}
|
|
767
|
-
const struct2 = this.getSchema();
|
|
768
|
-
for (let i = 0; i < struct2.memberNames.length; ++i) {
|
|
769
|
-
yield [struct2.memberNames[i], this.memberFrom([struct2.memberList[i], 0], struct2.memberNames[i])];
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
/**
|
|
773
|
-
* Creates a normalized member schema from the given schema and member name.
|
|
774
|
-
*/
|
|
775
|
-
memberFrom(memberSchema, memberName) {
|
|
776
|
-
if (memberSchema instanceof _NormalizedSchema) {
|
|
777
|
-
return Object.assign(memberSchema, {
|
|
778
|
-
memberName,
|
|
779
|
-
_isMemberSchema: true
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
return new _NormalizedSchema(memberSchema, memberName);
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* @returns a last-resort human-readable name for the schema if it has no other identifiers.
|
|
786
|
-
*/
|
|
787
|
-
getSchemaName() {
|
|
788
|
-
const schema = this.getSchema();
|
|
789
|
-
if (typeof schema === "number") {
|
|
790
|
-
const _schema = 63 & schema;
|
|
791
|
-
const container = 192 & schema;
|
|
792
|
-
const type = Object.entries(SCHEMA).find(([, value]) => {
|
|
793
|
-
return value === _schema;
|
|
794
|
-
})?.[0] ?? "Unknown";
|
|
795
|
-
switch (container) {
|
|
796
|
-
case SCHEMA.MAP_MODIFIER:
|
|
797
|
-
return `${type}Map`;
|
|
798
|
-
case SCHEMA.LIST_MODIFIER:
|
|
799
|
-
return `${type}List`;
|
|
800
|
-
case 0:
|
|
801
|
-
return type;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return "Unknown";
|
|
805
|
-
}
|
|
806
|
-
};
|
|
807
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
808
|
-
0 && (module.exports = {
|
|
809
|
-
ErrorSchema,
|
|
810
|
-
ListSchema,
|
|
811
|
-
MapSchema,
|
|
812
|
-
NormalizedSchema,
|
|
813
|
-
OperationSchema,
|
|
814
|
-
SCHEMA,
|
|
815
|
-
Schema,
|
|
816
|
-
SimpleSchema,
|
|
817
|
-
StructureSchema,
|
|
818
|
-
TypeRegistry,
|
|
819
|
-
deref,
|
|
820
|
-
deserializerMiddlewareOption,
|
|
821
|
-
error,
|
|
822
|
-
getSchemaSerdePlugin,
|
|
823
|
-
list,
|
|
824
|
-
map,
|
|
825
|
-
op,
|
|
826
|
-
serializerMiddlewareOption,
|
|
827
|
-
sim,
|
|
828
|
-
struct
|
|
829
|
-
});
|
|
298
|
+
class NormalizedSchema {
|
|
299
|
+
ref;
|
|
300
|
+
memberName;
|
|
301
|
+
static symbol = Symbol.for("@smithy/nor");
|
|
302
|
+
symbol = NormalizedSchema.symbol;
|
|
303
|
+
name;
|
|
304
|
+
schema;
|
|
305
|
+
_isMemberSchema;
|
|
306
|
+
traits;
|
|
307
|
+
memberTraits;
|
|
308
|
+
normalizedTraits;
|
|
309
|
+
constructor(ref, memberName) {
|
|
310
|
+
this.ref = ref;
|
|
311
|
+
this.memberName = memberName;
|
|
312
|
+
const traitStack = [];
|
|
313
|
+
let _ref = ref;
|
|
314
|
+
let schema = ref;
|
|
315
|
+
this._isMemberSchema = false;
|
|
316
|
+
while (Array.isArray(_ref)) {
|
|
317
|
+
traitStack.push(_ref[1]);
|
|
318
|
+
_ref = _ref[0];
|
|
319
|
+
schema = deref(_ref);
|
|
320
|
+
this._isMemberSchema = true;
|
|
321
|
+
}
|
|
322
|
+
if (traitStack.length > 0) {
|
|
323
|
+
this.memberTraits = {};
|
|
324
|
+
for (let i = traitStack.length - 1; i >= 0; --i) {
|
|
325
|
+
const traitSet = traitStack[i];
|
|
326
|
+
Object.assign(this.memberTraits, NormalizedSchema.translateTraits(traitSet));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
this.memberTraits = 0;
|
|
331
|
+
}
|
|
332
|
+
if (schema instanceof NormalizedSchema) {
|
|
333
|
+
const computedMemberTraits = this.memberTraits;
|
|
334
|
+
Object.assign(this, schema);
|
|
335
|
+
this.memberTraits = Object.assign({}, computedMemberTraits, schema.getMemberTraits(), this.getMemberTraits());
|
|
336
|
+
this.normalizedTraits = void 0;
|
|
337
|
+
this.memberName = memberName ?? schema.memberName;
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
this.schema = deref(schema);
|
|
341
|
+
if (this.schema && typeof this.schema === "object") {
|
|
342
|
+
this.traits = this.schema?.traits ?? {};
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
this.traits = 0;
|
|
346
|
+
}
|
|
347
|
+
this.name =
|
|
348
|
+
(this.schema instanceof Schema ? this.schema.getName?.() : void 0) ?? this.memberName ?? this.getSchemaName();
|
|
349
|
+
if (this._isMemberSchema && !memberName) {
|
|
350
|
+
throw new Error(`@smithy/core/schema - NormalizedSchema member init ${this.getName(true)} missing member name.`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
static [Symbol.hasInstance](lhs) {
|
|
354
|
+
return Schema[Symbol.hasInstance].bind(this)(lhs);
|
|
355
|
+
}
|
|
356
|
+
static of(ref) {
|
|
357
|
+
if (ref instanceof NormalizedSchema) {
|
|
358
|
+
return ref;
|
|
359
|
+
}
|
|
360
|
+
if (Array.isArray(ref)) {
|
|
361
|
+
const [ns, traits] = ref;
|
|
362
|
+
if (ns instanceof NormalizedSchema) {
|
|
363
|
+
Object.assign(ns.getMergedTraits(), NormalizedSchema.translateTraits(traits));
|
|
364
|
+
return ns;
|
|
365
|
+
}
|
|
366
|
+
throw new Error(`@smithy/core/schema - may not init unwrapped member schema=${JSON.stringify(ref, null, 2)}.`);
|
|
367
|
+
}
|
|
368
|
+
return new NormalizedSchema(ref);
|
|
369
|
+
}
|
|
370
|
+
static translateTraits(indicator) {
|
|
371
|
+
if (typeof indicator === "object") {
|
|
372
|
+
return indicator;
|
|
373
|
+
}
|
|
374
|
+
indicator = indicator | 0;
|
|
375
|
+
const traits = {};
|
|
376
|
+
let i = 0;
|
|
377
|
+
for (const trait of [
|
|
378
|
+
"httpLabel",
|
|
379
|
+
"idempotent",
|
|
380
|
+
"idempotencyToken",
|
|
381
|
+
"sensitive",
|
|
382
|
+
"httpPayload",
|
|
383
|
+
"httpResponseCode",
|
|
384
|
+
"httpQueryParams",
|
|
385
|
+
]) {
|
|
386
|
+
if (((indicator >> i++) & 1) === 1) {
|
|
387
|
+
traits[trait] = 1;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return traits;
|
|
391
|
+
}
|
|
392
|
+
getSchema() {
|
|
393
|
+
if (this.schema instanceof NormalizedSchema) {
|
|
394
|
+
Object.assign(this, { schema: this.schema.getSchema() });
|
|
395
|
+
return this.schema;
|
|
396
|
+
}
|
|
397
|
+
if (this.schema instanceof SimpleSchema) {
|
|
398
|
+
return deref(this.schema.schemaRef);
|
|
399
|
+
}
|
|
400
|
+
return deref(this.schema);
|
|
401
|
+
}
|
|
402
|
+
getName(withNamespace = false) {
|
|
403
|
+
if (!withNamespace) {
|
|
404
|
+
if (this.name && this.name.includes("#")) {
|
|
405
|
+
return this.name.split("#")[1];
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return this.name || undefined;
|
|
409
|
+
}
|
|
410
|
+
getMemberName() {
|
|
411
|
+
if (!this.isMemberSchema()) {
|
|
412
|
+
throw new Error(`@smithy/core/schema - non-member schema: ${this.getName(true)}`);
|
|
413
|
+
}
|
|
414
|
+
return this.memberName;
|
|
415
|
+
}
|
|
416
|
+
isMemberSchema() {
|
|
417
|
+
return this._isMemberSchema;
|
|
418
|
+
}
|
|
419
|
+
isUnitSchema() {
|
|
420
|
+
return this.getSchema() === "unit";
|
|
421
|
+
}
|
|
422
|
+
isListSchema() {
|
|
423
|
+
const inner = this.getSchema();
|
|
424
|
+
if (typeof inner === "number") {
|
|
425
|
+
return inner >= SCHEMA.LIST_MODIFIER && inner < SCHEMA.MAP_MODIFIER;
|
|
426
|
+
}
|
|
427
|
+
return inner instanceof ListSchema;
|
|
428
|
+
}
|
|
429
|
+
isMapSchema() {
|
|
430
|
+
const inner = this.getSchema();
|
|
431
|
+
if (typeof inner === "number") {
|
|
432
|
+
return inner >= SCHEMA.MAP_MODIFIER && inner <= 0b1111_1111;
|
|
433
|
+
}
|
|
434
|
+
return inner instanceof MapSchema;
|
|
435
|
+
}
|
|
436
|
+
isStructSchema() {
|
|
437
|
+
const inner = this.getSchema();
|
|
438
|
+
return (inner !== null && typeof inner === "object" && "members" in inner) || inner instanceof StructureSchema;
|
|
439
|
+
}
|
|
440
|
+
isBlobSchema() {
|
|
441
|
+
return this.getSchema() === SCHEMA.BLOB || this.getSchema() === SCHEMA.STREAMING_BLOB;
|
|
442
|
+
}
|
|
443
|
+
isTimestampSchema() {
|
|
444
|
+
const schema = this.getSchema();
|
|
445
|
+
return typeof schema === "number" && schema >= SCHEMA.TIMESTAMP_DEFAULT && schema <= SCHEMA.TIMESTAMP_EPOCH_SECONDS;
|
|
446
|
+
}
|
|
447
|
+
isDocumentSchema() {
|
|
448
|
+
return this.getSchema() === SCHEMA.DOCUMENT;
|
|
449
|
+
}
|
|
450
|
+
isStringSchema() {
|
|
451
|
+
return this.getSchema() === SCHEMA.STRING;
|
|
452
|
+
}
|
|
453
|
+
isBooleanSchema() {
|
|
454
|
+
return this.getSchema() === SCHEMA.BOOLEAN;
|
|
455
|
+
}
|
|
456
|
+
isNumericSchema() {
|
|
457
|
+
return this.getSchema() === SCHEMA.NUMERIC;
|
|
458
|
+
}
|
|
459
|
+
isBigIntegerSchema() {
|
|
460
|
+
return this.getSchema() === SCHEMA.BIG_INTEGER;
|
|
461
|
+
}
|
|
462
|
+
isBigDecimalSchema() {
|
|
463
|
+
return this.getSchema() === SCHEMA.BIG_DECIMAL;
|
|
464
|
+
}
|
|
465
|
+
isStreaming() {
|
|
466
|
+
const streaming = !!this.getMergedTraits().streaming;
|
|
467
|
+
if (streaming) {
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
return this.getSchema() === SCHEMA.STREAMING_BLOB;
|
|
471
|
+
}
|
|
472
|
+
isIdempotencyToken() {
|
|
473
|
+
if (this.normalizedTraits) {
|
|
474
|
+
return !!this.normalizedTraits.idempotencyToken;
|
|
475
|
+
}
|
|
476
|
+
for (const traits of [this.traits, this.memberTraits]) {
|
|
477
|
+
if (typeof traits === "number") {
|
|
478
|
+
if ((traits & 0b0100) === 0b0100) {
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
else if (typeof traits === "object") {
|
|
483
|
+
if (!!traits.idempotencyToken) {
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
getMergedTraits() {
|
|
491
|
+
return (this.normalizedTraits ??
|
|
492
|
+
(this.normalizedTraits = {
|
|
493
|
+
...this.getOwnTraits(),
|
|
494
|
+
...this.getMemberTraits(),
|
|
495
|
+
}));
|
|
496
|
+
}
|
|
497
|
+
getMemberTraits() {
|
|
498
|
+
return NormalizedSchema.translateTraits(this.memberTraits);
|
|
499
|
+
}
|
|
500
|
+
getOwnTraits() {
|
|
501
|
+
return NormalizedSchema.translateTraits(this.traits);
|
|
502
|
+
}
|
|
503
|
+
getKeySchema() {
|
|
504
|
+
if (this.isDocumentSchema()) {
|
|
505
|
+
return this.memberFrom([SCHEMA.DOCUMENT, 0], "key");
|
|
506
|
+
}
|
|
507
|
+
if (!this.isMapSchema()) {
|
|
508
|
+
throw new Error(`@smithy/core/schema - cannot get key for non-map: ${this.getName(true)}`);
|
|
509
|
+
}
|
|
510
|
+
const schema = this.getSchema();
|
|
511
|
+
if (typeof schema === "number") {
|
|
512
|
+
return this.memberFrom([0b0011_1111 & schema, 0], "key");
|
|
513
|
+
}
|
|
514
|
+
return this.memberFrom([schema.keySchema, 0], "key");
|
|
515
|
+
}
|
|
516
|
+
getValueSchema() {
|
|
517
|
+
const schema = this.getSchema();
|
|
518
|
+
if (typeof schema === "number") {
|
|
519
|
+
if (this.isMapSchema()) {
|
|
520
|
+
return this.memberFrom([0b0011_1111 & schema, 0], "value");
|
|
521
|
+
}
|
|
522
|
+
else if (this.isListSchema()) {
|
|
523
|
+
return this.memberFrom([0b0011_1111 & schema, 0], "member");
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
if (schema && typeof schema === "object") {
|
|
527
|
+
if (this.isStructSchema()) {
|
|
528
|
+
throw new Error(`may not getValueSchema() on structure ${this.getName(true)}`);
|
|
529
|
+
}
|
|
530
|
+
const collection = schema;
|
|
531
|
+
if ("valueSchema" in collection) {
|
|
532
|
+
if (this.isMapSchema()) {
|
|
533
|
+
return this.memberFrom([collection.valueSchema, 0], "value");
|
|
534
|
+
}
|
|
535
|
+
else if (this.isListSchema()) {
|
|
536
|
+
return this.memberFrom([collection.valueSchema, 0], "member");
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (this.isDocumentSchema()) {
|
|
541
|
+
return this.memberFrom([SCHEMA.DOCUMENT, 0], "value");
|
|
542
|
+
}
|
|
543
|
+
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no value member.`);
|
|
544
|
+
}
|
|
545
|
+
hasMemberSchema(member) {
|
|
546
|
+
if (this.isStructSchema()) {
|
|
547
|
+
const struct = this.getSchema();
|
|
548
|
+
return struct.memberNames.includes(member);
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
getMemberSchema(member) {
|
|
553
|
+
if (this.isStructSchema()) {
|
|
554
|
+
const struct = this.getSchema();
|
|
555
|
+
if (!struct.memberNames.includes(member)) {
|
|
556
|
+
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no member=${member}.`);
|
|
557
|
+
}
|
|
558
|
+
const i = struct.memberNames.indexOf(member);
|
|
559
|
+
const memberSchema = struct.memberList[i];
|
|
560
|
+
return this.memberFrom(Array.isArray(memberSchema) ? memberSchema : [memberSchema, 0], member);
|
|
561
|
+
}
|
|
562
|
+
if (this.isDocumentSchema()) {
|
|
563
|
+
return this.memberFrom([SCHEMA.DOCUMENT, 0], member);
|
|
564
|
+
}
|
|
565
|
+
throw new Error(`@smithy/core/schema - ${this.getName(true)} has no members.`);
|
|
566
|
+
}
|
|
567
|
+
getMemberSchemas() {
|
|
568
|
+
const buffer = {};
|
|
569
|
+
try {
|
|
570
|
+
for (const [k, v] of this.structIterator()) {
|
|
571
|
+
buffer[k] = v;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
catch (ignored) { }
|
|
575
|
+
return buffer;
|
|
576
|
+
}
|
|
577
|
+
getEventStreamMember() {
|
|
578
|
+
if (this.isStructSchema()) {
|
|
579
|
+
for (const [memberName, memberSchema] of this.structIterator()) {
|
|
580
|
+
if (memberSchema.isStreaming() && memberSchema.isStructSchema()) {
|
|
581
|
+
return memberName;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return "";
|
|
586
|
+
}
|
|
587
|
+
*structIterator() {
|
|
588
|
+
if (this.isUnitSchema()) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (!this.isStructSchema()) {
|
|
592
|
+
throw new Error("@smithy/core/schema - cannot iterate non-struct schema.");
|
|
593
|
+
}
|
|
594
|
+
const struct = this.getSchema();
|
|
595
|
+
for (let i = 0; i < struct.memberNames.length; ++i) {
|
|
596
|
+
yield [struct.memberNames[i], this.memberFrom([struct.memberList[i], 0], struct.memberNames[i])];
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
memberFrom(memberSchema, memberName) {
|
|
600
|
+
if (memberSchema instanceof NormalizedSchema) {
|
|
601
|
+
return Object.assign(memberSchema, {
|
|
602
|
+
memberName,
|
|
603
|
+
_isMemberSchema: true,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
return new NormalizedSchema(memberSchema, memberName);
|
|
607
|
+
}
|
|
608
|
+
getSchemaName() {
|
|
609
|
+
const schema = this.getSchema();
|
|
610
|
+
if (typeof schema === "number") {
|
|
611
|
+
const _schema = 0b0011_1111 & schema;
|
|
612
|
+
const container = 0b1100_0000 & schema;
|
|
613
|
+
const type = Object.entries(SCHEMA).find(([, value]) => {
|
|
614
|
+
return value === _schema;
|
|
615
|
+
})?.[0] ?? "Unknown";
|
|
616
|
+
switch (container) {
|
|
617
|
+
case SCHEMA.MAP_MODIFIER:
|
|
618
|
+
return `${type}Map`;
|
|
619
|
+
case SCHEMA.LIST_MODIFIER:
|
|
620
|
+
return `${type}List`;
|
|
621
|
+
case 0:
|
|
622
|
+
return type;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return "Unknown";
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
exports.ErrorSchema = ErrorSchema;
|
|
630
|
+
exports.ListSchema = ListSchema;
|
|
631
|
+
exports.MapSchema = MapSchema;
|
|
632
|
+
exports.NormalizedSchema = NormalizedSchema;
|
|
633
|
+
exports.OperationSchema = OperationSchema;
|
|
634
|
+
exports.SCHEMA = SCHEMA;
|
|
635
|
+
exports.Schema = Schema;
|
|
636
|
+
exports.SimpleSchema = SimpleSchema;
|
|
637
|
+
exports.StructureSchema = StructureSchema;
|
|
638
|
+
exports.TypeRegistry = TypeRegistry;
|
|
639
|
+
exports.deref = deref;
|
|
640
|
+
exports.deserializerMiddlewareOption = deserializerMiddlewareOption;
|
|
641
|
+
exports.error = error;
|
|
642
|
+
exports.getSchemaSerdePlugin = getSchemaSerdePlugin;
|
|
643
|
+
exports.list = list;
|
|
644
|
+
exports.map = map;
|
|
645
|
+
exports.op = op;
|
|
646
|
+
exports.serializerMiddlewareOption = serializerMiddlewareOption;
|
|
647
|
+
exports.sim = sim;
|
|
648
|
+
exports.struct = struct;
|