@smithy/core 3.16.0 → 3.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/submodules/schema/index.js +74 -61
- package/dist-es/submodules/schema/TypeRegistry.js +16 -9
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +2 -2
- package/dist-es/submodules/schema/schemas/Schema.js +0 -2
- package/dist-es/submodules/schema/schemas/SimpleSchema.js +6 -0
- package/dist-types/submodules/schema/TypeRegistry.d.ts +1 -2
- package/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +5 -0
- package/dist-types/ts3.4/submodules/schema/TypeRegistry.d.ts +1 -2
- package/dist-types/ts3.4/submodules/schema/schemas/SimpleSchema.d.ts +5 -0
- package/package.json +7 -7
|
@@ -10,72 +10,12 @@ const deref = (schemaRef) => {
|
|
|
10
10
|
return schemaRef;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
class TypeRegistry {
|
|
14
|
-
namespace;
|
|
15
|
-
schemas;
|
|
16
|
-
exceptions;
|
|
17
|
-
static registries = new Map();
|
|
18
|
-
constructor(namespace, schemas = new Map(), exceptions = new Map()) {
|
|
19
|
-
this.namespace = namespace;
|
|
20
|
-
this.schemas = schemas;
|
|
21
|
-
this.exceptions = exceptions;
|
|
22
|
-
}
|
|
23
|
-
static for(namespace) {
|
|
24
|
-
if (!TypeRegistry.registries.has(namespace)) {
|
|
25
|
-
TypeRegistry.registries.set(namespace, new TypeRegistry(namespace));
|
|
26
|
-
}
|
|
27
|
-
return TypeRegistry.registries.get(namespace);
|
|
28
|
-
}
|
|
29
|
-
register(shapeId, schema) {
|
|
30
|
-
const qualifiedName = this.normalizeShapeId(shapeId);
|
|
31
|
-
this.schemas.set(qualifiedName, schema);
|
|
32
|
-
}
|
|
33
|
-
getSchema(shapeId) {
|
|
34
|
-
const id = this.normalizeShapeId(shapeId);
|
|
35
|
-
if (!this.schemas.has(id)) {
|
|
36
|
-
throw new Error(`@smithy/core/schema - schema not found for ${id}`);
|
|
37
|
-
}
|
|
38
|
-
return this.schemas.get(id);
|
|
39
|
-
}
|
|
40
|
-
registerError(es, ctor) {
|
|
41
|
-
this.exceptions.set(es, ctor);
|
|
42
|
-
}
|
|
43
|
-
getErrorCtor(es) {
|
|
44
|
-
return this.exceptions.get(es);
|
|
45
|
-
}
|
|
46
|
-
getBaseException() {
|
|
47
|
-
for (const [id, schema] of this.schemas.entries()) {
|
|
48
|
-
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
|
|
49
|
-
return schema;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
find(predicate) {
|
|
55
|
-
return [...this.schemas.values()].find(predicate);
|
|
56
|
-
}
|
|
57
|
-
clear() {
|
|
58
|
-
this.schemas.clear();
|
|
59
|
-
this.exceptions.clear();
|
|
60
|
-
}
|
|
61
|
-
normalizeShapeId(shapeId) {
|
|
62
|
-
if (shapeId.includes("#")) {
|
|
63
|
-
return shapeId;
|
|
64
|
-
}
|
|
65
|
-
return this.namespace + "#" + shapeId;
|
|
66
|
-
}
|
|
67
|
-
getNamespace(shapeId) {
|
|
68
|
-
return this.normalizeShapeId(shapeId).split("#")[0];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
13
|
class Schema {
|
|
73
14
|
name;
|
|
74
15
|
namespace;
|
|
75
16
|
traits;
|
|
76
17
|
static assign(instance, values) {
|
|
77
18
|
const schema = Object.assign(instance, values);
|
|
78
|
-
TypeRegistry.for(schema.namespace).register(schema.name, schema);
|
|
79
19
|
return schema;
|
|
80
20
|
}
|
|
81
21
|
static [Symbol.hasInstance](lhs) {
|
|
@@ -180,6 +120,12 @@ const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSche
|
|
|
180
120
|
traits,
|
|
181
121
|
schemaRef,
|
|
182
122
|
});
|
|
123
|
+
const simAdapter = (namespace, name, traits, schemaRef) => Schema.assign(new SimpleSchema(), {
|
|
124
|
+
name,
|
|
125
|
+
namespace,
|
|
126
|
+
traits,
|
|
127
|
+
schemaRef,
|
|
128
|
+
});
|
|
183
129
|
|
|
184
130
|
function translateTraits(indicator) {
|
|
185
131
|
if (typeof indicator === "object") {
|
|
@@ -446,7 +392,7 @@ function member(memberSchema, memberName) {
|
|
|
446
392
|
function hydrate(ss) {
|
|
447
393
|
const [id, ...rest] = ss;
|
|
448
394
|
return {
|
|
449
|
-
[0]:
|
|
395
|
+
[0]: simAdapter,
|
|
450
396
|
[1]: list,
|
|
451
397
|
[2]: map,
|
|
452
398
|
[3]: struct,
|
|
@@ -577,6 +523,72 @@ const SCHEMA = {
|
|
|
577
523
|
MAP_MODIFIER: 0b1000_0000,
|
|
578
524
|
};
|
|
579
525
|
|
|
526
|
+
class TypeRegistry {
|
|
527
|
+
namespace;
|
|
528
|
+
schemas;
|
|
529
|
+
exceptions;
|
|
530
|
+
static registries = new Map();
|
|
531
|
+
constructor(namespace, schemas = new Map(), exceptions = new Map()) {
|
|
532
|
+
this.namespace = namespace;
|
|
533
|
+
this.schemas = schemas;
|
|
534
|
+
this.exceptions = exceptions;
|
|
535
|
+
}
|
|
536
|
+
static for(namespace) {
|
|
537
|
+
if (!TypeRegistry.registries.has(namespace)) {
|
|
538
|
+
TypeRegistry.registries.set(namespace, new TypeRegistry(namespace));
|
|
539
|
+
}
|
|
540
|
+
return TypeRegistry.registries.get(namespace);
|
|
541
|
+
}
|
|
542
|
+
register(shapeId, schema) {
|
|
543
|
+
const qualifiedName = this.normalizeShapeId(shapeId);
|
|
544
|
+
const registry = TypeRegistry.for(qualifiedName.split("#")[0]);
|
|
545
|
+
registry.schemas.set(qualifiedName, schema);
|
|
546
|
+
}
|
|
547
|
+
getSchema(shapeId) {
|
|
548
|
+
const id = this.normalizeShapeId(shapeId);
|
|
549
|
+
if (!this.schemas.has(id)) {
|
|
550
|
+
throw new Error(`@smithy/core/schema - schema not found for ${id}`);
|
|
551
|
+
}
|
|
552
|
+
return this.schemas.get(id);
|
|
553
|
+
}
|
|
554
|
+
registerError(es, ctor) {
|
|
555
|
+
const $error = es;
|
|
556
|
+
const registry = TypeRegistry.for($error[1]);
|
|
557
|
+
registry.schemas.set($error[1] + "#" + $error[2], $error);
|
|
558
|
+
registry.exceptions.set($error, ctor);
|
|
559
|
+
}
|
|
560
|
+
getErrorCtor(es) {
|
|
561
|
+
const $error = es;
|
|
562
|
+
const registry = TypeRegistry.for($error[1]);
|
|
563
|
+
return registry.exceptions.get(es);
|
|
564
|
+
}
|
|
565
|
+
getBaseException() {
|
|
566
|
+
for (const exceptionKey of this.exceptions.keys()) {
|
|
567
|
+
if (Array.isArray(exceptionKey)) {
|
|
568
|
+
const [, ns, name] = exceptionKey;
|
|
569
|
+
const id = ns + "#" + name;
|
|
570
|
+
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
|
|
571
|
+
return exceptionKey;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
577
|
+
find(predicate) {
|
|
578
|
+
return [...this.schemas.values()].find(predicate);
|
|
579
|
+
}
|
|
580
|
+
clear() {
|
|
581
|
+
this.schemas.clear();
|
|
582
|
+
this.exceptions.clear();
|
|
583
|
+
}
|
|
584
|
+
normalizeShapeId(shapeId) {
|
|
585
|
+
if (shapeId.includes("#")) {
|
|
586
|
+
return shapeId;
|
|
587
|
+
}
|
|
588
|
+
return this.namespace + "#" + shapeId;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
580
592
|
exports.ErrorSchema = ErrorSchema;
|
|
581
593
|
exports.ListSchema = ListSchema;
|
|
582
594
|
exports.MapSchema = MapSchema;
|
|
@@ -598,5 +610,6 @@ exports.map = map;
|
|
|
598
610
|
exports.op = op;
|
|
599
611
|
exports.serializerMiddlewareOption = serializerMiddlewareOption;
|
|
600
612
|
exports.sim = sim;
|
|
613
|
+
exports.simAdapter = simAdapter;
|
|
601
614
|
exports.struct = struct;
|
|
602
615
|
exports.translateTraits = translateTraits;
|
|
@@ -16,7 +16,8 @@ export class TypeRegistry {
|
|
|
16
16
|
}
|
|
17
17
|
register(shapeId, schema) {
|
|
18
18
|
const qualifiedName = this.normalizeShapeId(shapeId);
|
|
19
|
-
|
|
19
|
+
const registry = TypeRegistry.for(qualifiedName.split("#")[0]);
|
|
20
|
+
registry.schemas.set(qualifiedName, schema);
|
|
20
21
|
}
|
|
21
22
|
getSchema(shapeId) {
|
|
22
23
|
const id = this.normalizeShapeId(shapeId);
|
|
@@ -26,15 +27,24 @@ export class TypeRegistry {
|
|
|
26
27
|
return this.schemas.get(id);
|
|
27
28
|
}
|
|
28
29
|
registerError(es, ctor) {
|
|
29
|
-
|
|
30
|
+
const $error = es;
|
|
31
|
+
const registry = TypeRegistry.for($error[1]);
|
|
32
|
+
registry.schemas.set($error[1] + "#" + $error[2], $error);
|
|
33
|
+
registry.exceptions.set($error, ctor);
|
|
30
34
|
}
|
|
31
35
|
getErrorCtor(es) {
|
|
32
|
-
|
|
36
|
+
const $error = es;
|
|
37
|
+
const registry = TypeRegistry.for($error[1]);
|
|
38
|
+
return registry.exceptions.get(es);
|
|
33
39
|
}
|
|
34
40
|
getBaseException() {
|
|
35
|
-
for (const
|
|
36
|
-
if (
|
|
37
|
-
|
|
41
|
+
for (const exceptionKey of this.exceptions.keys()) {
|
|
42
|
+
if (Array.isArray(exceptionKey)) {
|
|
43
|
+
const [, ns, name] = exceptionKey;
|
|
44
|
+
const id = ns + "#" + name;
|
|
45
|
+
if (id.startsWith("smithy.ts.sdk.synthetic.") && id.endsWith("ServiceException")) {
|
|
46
|
+
return exceptionKey;
|
|
47
|
+
}
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
50
|
return undefined;
|
|
@@ -52,7 +62,4 @@ export class TypeRegistry {
|
|
|
52
62
|
}
|
|
53
63
|
return this.namespace + "#" + shapeId;
|
|
54
64
|
}
|
|
55
|
-
getNamespace(shapeId) {
|
|
56
|
-
return this.normalizeShapeId(shapeId).split("#")[0];
|
|
57
|
-
}
|
|
58
65
|
}
|
|
@@ -4,7 +4,7 @@ import { list, ListSchema } from "./ListSchema";
|
|
|
4
4
|
import { map, MapSchema } from "./MapSchema";
|
|
5
5
|
import { op } from "./OperationSchema";
|
|
6
6
|
import { Schema } from "./Schema";
|
|
7
|
-
import {
|
|
7
|
+
import { simAdapter } from "./SimpleSchema";
|
|
8
8
|
import { struct, StructureSchema } from "./StructureSchema";
|
|
9
9
|
import { translateTraits } from "./translateTraits";
|
|
10
10
|
export class NormalizedSchema {
|
|
@@ -249,7 +249,7 @@ function member(memberSchema, memberName) {
|
|
|
249
249
|
export function hydrate(ss) {
|
|
250
250
|
const [id, ...rest] = ss;
|
|
251
251
|
return {
|
|
252
|
-
[0]:
|
|
252
|
+
[0]: simAdapter,
|
|
253
253
|
[1]: list,
|
|
254
254
|
[2]: map,
|
|
255
255
|
[3]: struct,
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { TypeRegistry } from "../TypeRegistry";
|
|
2
1
|
export class Schema {
|
|
3
2
|
name;
|
|
4
3
|
namespace;
|
|
5
4
|
traits;
|
|
6
5
|
static assign(instance, values) {
|
|
7
6
|
const schema = Object.assign(instance, values);
|
|
8
|
-
TypeRegistry.for(schema.namespace).register(schema.name, schema);
|
|
9
7
|
return schema;
|
|
10
8
|
}
|
|
11
9
|
static [Symbol.hasInstance](lhs) {
|
|
@@ -12,3 +12,9 @@ export const sim = (namespace, name, schemaRef, traits) => Schema.assign(new Sim
|
|
|
12
12
|
traits,
|
|
13
13
|
schemaRef,
|
|
14
14
|
});
|
|
15
|
+
export const simAdapter = (namespace, name, traits, schemaRef) => Schema.assign(new SimpleSchema(), {
|
|
16
|
+
name,
|
|
17
|
+
namespace,
|
|
18
|
+
traits,
|
|
19
|
+
schemaRef,
|
|
20
|
+
});
|
|
@@ -50,7 +50,7 @@ export declare class TypeRegistry {
|
|
|
50
50
|
*
|
|
51
51
|
* @returns the synthetic base exception of the service namespace associated with this registry instance.
|
|
52
52
|
*/
|
|
53
|
-
getBaseException():
|
|
53
|
+
getBaseException(): StaticErrorSchema | undefined;
|
|
54
54
|
/**
|
|
55
55
|
* @param predicate - criterion.
|
|
56
56
|
* @returns a schema in this registry matching the predicate.
|
|
@@ -61,5 +61,4 @@ export declare class TypeRegistry {
|
|
|
61
61
|
*/
|
|
62
62
|
clear(): void;
|
|
63
63
|
private normalizeShapeId;
|
|
64
|
-
private getNamespace;
|
|
65
64
|
}
|
|
@@ -19,3 +19,8 @@ export declare class SimpleSchema extends Schema implements TraitsSchema {
|
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
21
|
export declare const sim: (namespace: string, name: string, schemaRef: SchemaRef, traits: SchemaTraits) => SimpleSchema;
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
* @deprecated
|
|
25
|
+
*/
|
|
26
|
+
export declare const simAdapter: (namespace: string, name: string, traits: SchemaTraits, schemaRef: SchemaRef) => SimpleSchema;
|
|
@@ -50,7 +50,7 @@ export declare class TypeRegistry {
|
|
|
50
50
|
*
|
|
51
51
|
* @returns the synthetic base exception of the service namespace associated with this registry instance.
|
|
52
52
|
*/
|
|
53
|
-
getBaseException():
|
|
53
|
+
getBaseException(): StaticErrorSchema | undefined;
|
|
54
54
|
/**
|
|
55
55
|
* @param predicate - criterion.
|
|
56
56
|
* @returns a schema in this registry matching the predicate.
|
|
@@ -61,5 +61,4 @@ export declare class TypeRegistry {
|
|
|
61
61
|
*/
|
|
62
62
|
clear(): void;
|
|
63
63
|
private normalizeShapeId;
|
|
64
|
-
private getNamespace;
|
|
65
64
|
}
|
|
@@ -19,3 +19,8 @@ export declare class SimpleSchema extends Schema implements TraitsSchema {
|
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
21
|
export declare const sim: (namespace: string, name: string, schemaRef: SchemaRef, traits: SchemaTraits) => SimpleSchema;
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
* @deprecated
|
|
25
|
+
*/
|
|
26
|
+
export declare const simAdapter: (namespace: string, name: string, traits: SchemaTraits, schemaRef: SchemaRef) => SimpleSchema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/core",
|
|
3
|
-
"version": "3.16.
|
|
3
|
+
"version": "3.16.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "yarn lint && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
6
6
|
"build:cjs": "node ../../scripts/inline core",
|
|
@@ -77,13 +77,13 @@
|
|
|
77
77
|
"license": "Apache-2.0",
|
|
78
78
|
"sideEffects": false,
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@smithy/middleware-serde": "^4.2.
|
|
81
|
-
"@smithy/protocol-http": "^5.3.
|
|
82
|
-
"@smithy/types": "^4.7.
|
|
80
|
+
"@smithy/middleware-serde": "^4.2.2",
|
|
81
|
+
"@smithy/protocol-http": "^5.3.2",
|
|
82
|
+
"@smithy/types": "^4.7.1",
|
|
83
83
|
"@smithy/util-base64": "^4.3.0",
|
|
84
84
|
"@smithy/util-body-length-browser": "^4.2.0",
|
|
85
|
-
"@smithy/util-middleware": "^4.2.
|
|
86
|
-
"@smithy/util-stream": "^4.5.
|
|
85
|
+
"@smithy/util-middleware": "^4.2.2",
|
|
86
|
+
"@smithy/util-stream": "^4.5.2",
|
|
87
87
|
"@smithy/util-utf8": "^4.2.0",
|
|
88
88
|
"@smithy/uuid": "^1.1.0",
|
|
89
89
|
"tslib": "^2.6.2"
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"directory": "packages/core"
|
|
119
119
|
},
|
|
120
120
|
"devDependencies": {
|
|
121
|
-
"@smithy/eventstream-serde-node": "^4.2.
|
|
121
|
+
"@smithy/eventstream-serde-node": "^4.2.2",
|
|
122
122
|
"@types/node": "^18.11.9",
|
|
123
123
|
"concurrently": "7.0.0",
|
|
124
124
|
"downlevel-dts": "0.10.1",
|