@smithy/core 3.15.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.
Files changed (45) hide show
  1. package/dist-cjs/submodules/cbor/index.js +3 -15
  2. package/dist-cjs/submodules/protocols/index.js +16 -14
  3. package/dist-cjs/submodules/schema/index.js +226 -190
  4. package/dist-es/index.js +1 -1
  5. package/dist-es/submodules/cbor/CborCodec.js +4 -15
  6. package/dist-es/submodules/protocols/HttpProtocol.js +3 -2
  7. package/dist-es/submodules/protocols/SerdeContext.js +6 -0
  8. package/dist-es/submodules/protocols/index.js +1 -0
  9. package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +3 -5
  10. package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +3 -2
  11. package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +3 -5
  12. package/dist-es/submodules/schema/TypeRegistry.js +18 -11
  13. package/dist-es/submodules/schema/middleware/schemaDeserializationMiddleware.js +5 -1
  14. package/dist-es/submodules/schema/middleware/schemaSerializationMiddleware.js +5 -1
  15. package/dist-es/submodules/schema/schemas/NormalizedSchema.js +24 -6
  16. package/dist-es/submodules/schema/schemas/Schema.js +0 -2
  17. package/dist-es/submodules/schema/schemas/SimpleSchema.js +6 -0
  18. package/dist-types/index.d.ts +1 -1
  19. package/dist-types/submodules/cbor/CborCodec.d.ts +5 -10
  20. package/dist-types/submodules/protocols/HttpProtocol.d.ts +5 -2
  21. package/dist-types/submodules/protocols/SerdeContext.d.ts +8 -0
  22. package/dist-types/submodules/protocols/index.d.ts +1 -0
  23. package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +3 -4
  24. package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +5 -2
  25. package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +5 -2
  26. package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +3 -4
  27. package/dist-types/submodules/schema/TypeRegistry.d.ts +5 -6
  28. package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +22 -1
  29. package/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +5 -0
  30. package/dist-types/ts3.4/index.d.ts +1 -1
  31. package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +5 -10
  32. package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +5 -2
  33. package/dist-types/ts3.4/submodules/protocols/SerdeContext.d.ts +8 -0
  34. package/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
  35. package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +3 -4
  36. package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +5 -2
  37. package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +5 -2
  38. package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +3 -4
  39. package/dist-types/ts3.4/submodules/schema/TypeRegistry.d.ts +5 -6
  40. package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +22 -1
  41. package/dist-types/ts3.4/submodules/schema/schemas/SimpleSchema.d.ts +5 -0
  42. package/package.json +7 -7
  43. /package/dist-es/{protocols → request-builder}/requestBuilder.js +0 -0
  44. /package/dist-types/{protocols → request-builder}/requestBuilder.d.ts +0 -0
  45. /package/dist-types/ts3.4/{protocols → request-builder}/requestBuilder.d.ts +0 -0
@@ -780,8 +780,7 @@ const buildHttpRpcRequest = async (context, headers, path, resolvedHostname, bod
780
780
  return new protocolHttp.HttpRequest(contents);
781
781
  };
782
782
 
783
- class CborCodec {
784
- serdeContext;
783
+ class CborCodec extends protocols.SerdeContext {
785
784
  createSerializer() {
786
785
  const serializer = new CborShapeSerializer();
787
786
  serializer.setSerdeContext(this.serdeContext);
@@ -792,16 +791,9 @@ class CborCodec {
792
791
  deserializer.setSerdeContext(this.serdeContext);
793
792
  return deserializer;
794
793
  }
795
- setSerdeContext(serdeContext) {
796
- this.serdeContext = serdeContext;
797
- }
798
794
  }
799
- class CborShapeSerializer {
800
- serdeContext;
795
+ class CborShapeSerializer extends protocols.SerdeContext {
801
796
  value;
802
- setSerdeContext(serdeContext) {
803
- this.serdeContext = serdeContext;
804
- }
805
797
  write(schema, value) {
806
798
  this.value = this.serialize(schema, value);
807
799
  }
@@ -875,11 +867,7 @@ class CborShapeSerializer {
875
867
  return buffer;
876
868
  }
877
869
  }
878
- class CborShapeDeserializer {
879
- serdeContext;
880
- setSerdeContext(serdeContext) {
881
- this.serdeContext = serdeContext;
882
- }
870
+ class CborShapeDeserializer extends protocols.SerdeContext {
883
871
  read(schema, bytes) {
884
872
  const data = cbor.deserialize(bytes);
885
873
  return this.readValue(schema, data);
@@ -24,10 +24,17 @@ function extendedEncodeURIComponent(str) {
24
24
  });
25
25
  }
26
26
 
27
- class HttpProtocol {
28
- options;
27
+ class SerdeContext {
29
28
  serdeContext;
29
+ setSerdeContext(serdeContext) {
30
+ this.serdeContext = serdeContext;
31
+ }
32
+ }
33
+
34
+ class HttpProtocol extends SerdeContext {
35
+ options;
30
36
  constructor(options) {
37
+ super();
31
38
  this.options = options;
32
39
  }
33
40
  getRequestType() {
@@ -591,15 +598,12 @@ function determineTimestampFormat(ns, settings) {
591
598
  return bindingFormat ?? settings.timestampFormat.default;
592
599
  }
593
600
 
594
- class FromStringShapeDeserializer {
601
+ class FromStringShapeDeserializer extends SerdeContext {
595
602
  settings;
596
- serdeContext;
597
603
  constructor(settings) {
604
+ super();
598
605
  this.settings = settings;
599
606
  }
600
- setSerdeContext(serdeContext) {
601
- this.serdeContext = serdeContext;
602
- }
603
607
  read(_schema, data) {
604
608
  const ns = schema.NormalizedSchema.of(_schema);
605
609
  if (ns.isListSchema()) {
@@ -655,11 +659,11 @@ class FromStringShapeDeserializer {
655
659
  }
656
660
  }
657
661
 
658
- class HttpInterceptingShapeDeserializer {
662
+ class HttpInterceptingShapeDeserializer extends SerdeContext {
659
663
  codecDeserializer;
660
664
  stringDeserializer;
661
- serdeContext;
662
665
  constructor(codecDeserializer, codecSettings) {
666
+ super();
663
667
  this.codecDeserializer = codecDeserializer;
664
668
  this.stringDeserializer = new FromStringShapeDeserializer(codecSettings);
665
669
  }
@@ -694,16 +698,13 @@ class HttpInterceptingShapeDeserializer {
694
698
  }
695
699
  }
696
700
 
697
- class ToStringShapeSerializer {
701
+ class ToStringShapeSerializer extends SerdeContext {
698
702
  settings;
699
703
  stringBuffer = "";
700
- serdeContext = undefined;
701
704
  constructor(settings) {
705
+ super();
702
706
  this.settings = settings;
703
707
  }
704
- setSerdeContext(serdeContext) {
705
- this.serdeContext = serdeContext;
706
- }
707
708
  write(schema$1, value) {
708
709
  const ns = schema.NormalizedSchema.of(schema$1);
709
710
  switch (typeof value) {
@@ -818,6 +819,7 @@ exports.HttpInterceptingShapeSerializer = HttpInterceptingShapeSerializer;
818
819
  exports.HttpProtocol = HttpProtocol;
819
820
  exports.RequestBuilder = RequestBuilder;
820
821
  exports.RpcProtocol = RpcProtocol;
822
+ exports.SerdeContext = SerdeContext;
821
823
  exports.ToStringShapeSerializer = ToStringShapeSerializer;
822
824
  exports.collectBody = collectBody;
823
825
  exports.determineTimestampFormat = determineTimestampFormat;
@@ -10,169 +10,12 @@ const deref = (schemaRef) => {
10
10
  return schemaRef;
11
11
  };
12
12
 
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
- }
65
- };
66
- const findHeader = (pattern, headers) => {
67
- return (headers.find(([k]) => {
68
- return k.match(pattern);
69
- }) || [void 0, void 0])[1];
70
- };
71
-
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
- });
86
- };
87
-
88
- const deserializerMiddlewareOption = {
89
- name: "deserializerMiddleware",
90
- step: "deserialize",
91
- tags: ["DESERIALIZER"],
92
- override: true,
93
- };
94
- const serializerMiddlewareOption = {
95
- name: "serializerMiddleware",
96
- step: "serialize",
97
- tags: ["SERIALIZER"],
98
- override: true,
99
- };
100
- function getSchemaSerdePlugin(config) {
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];
166
- }
167
- }
168
-
169
13
  class Schema {
170
14
  name;
171
15
  namespace;
172
16
  traits;
173
17
  static assign(instance, values) {
174
18
  const schema = Object.assign(instance, values);
175
- TypeRegistry.for(schema.namespace).register(schema.name, schema);
176
19
  return schema;
177
20
  }
178
21
  static [Symbol.hasInstance](lhs) {
@@ -188,6 +31,36 @@ class Schema {
188
31
  }
189
32
  }
190
33
 
34
+ class StructureSchema extends Schema {
35
+ static symbol = Symbol.for("@smithy/str");
36
+ name;
37
+ traits;
38
+ memberNames;
39
+ memberList;
40
+ symbol = StructureSchema.symbol;
41
+ }
42
+ const struct = (namespace, name, traits, memberNames, memberList) => Schema.assign(new StructureSchema(), {
43
+ name,
44
+ namespace,
45
+ traits,
46
+ memberNames,
47
+ memberList,
48
+ });
49
+
50
+ class ErrorSchema extends StructureSchema {
51
+ static symbol = Symbol.for("@smithy/err");
52
+ ctor;
53
+ symbol = ErrorSchema.symbol;
54
+ }
55
+ const error = (namespace, name, traits, memberNames, memberList, ctor) => Schema.assign(new ErrorSchema(), {
56
+ name,
57
+ namespace,
58
+ traits,
59
+ memberNames,
60
+ memberList,
61
+ ctor: null,
62
+ });
63
+
191
64
  class ListSchema extends Schema {
192
65
  static symbol = Symbol.for("@smithy/lis");
193
66
  name;
@@ -234,34 +107,24 @@ const op = (namespace, name, traits, input, output) => Schema.assign(new Operati
234
107
  output,
235
108
  });
236
109
 
237
- class StructureSchema extends Schema {
238
- static symbol = Symbol.for("@smithy/str");
110
+ class SimpleSchema extends Schema {
111
+ static symbol = Symbol.for("@smithy/sim");
239
112
  name;
113
+ schemaRef;
240
114
  traits;
241
- memberNames;
242
- memberList;
243
- symbol = StructureSchema.symbol;
115
+ symbol = SimpleSchema.symbol;
244
116
  }
245
- const struct = (namespace, name, traits, memberNames, memberList) => Schema.assign(new StructureSchema(), {
117
+ const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSchema(), {
246
118
  name,
247
119
  namespace,
248
120
  traits,
249
- memberNames,
250
- memberList,
121
+ schemaRef,
251
122
  });
252
-
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(), {
123
+ const simAdapter = (namespace, name, traits, schemaRef) => Schema.assign(new SimpleSchema(), {
259
124
  name,
260
125
  namespace,
261
126
  traits,
262
- memberNames,
263
- memberList,
264
- ctor: null,
127
+ schemaRef,
265
128
  });
266
129
 
267
130
  function translateTraits(indicator) {
@@ -305,12 +168,14 @@ class NormalizedSchema {
305
168
  let _ref = ref;
306
169
  let schema = ref;
307
170
  this._isMemberSchema = false;
308
- while (Array.isArray(_ref)) {
171
+ while (isMemberSchema(_ref)) {
309
172
  traitStack.push(_ref[1]);
310
173
  _ref = _ref[0];
311
174
  schema = deref(_ref);
312
175
  this._isMemberSchema = true;
313
176
  }
177
+ if (isStaticSchema(schema))
178
+ schema = hydrate(schema);
314
179
  if (traitStack.length > 0) {
315
180
  this.memberTraits = {};
316
181
  for (let i = traitStack.length - 1; i >= 0; --i) {
@@ -349,7 +214,7 @@ class NormalizedSchema {
349
214
  if (sc instanceof NormalizedSchema) {
350
215
  return sc;
351
216
  }
352
- if (Array.isArray(sc)) {
217
+ if (isMemberSchema(sc)) {
353
218
  const [ns, traits] = sc;
354
219
  if (ns instanceof NormalizedSchema) {
355
220
  Object.assign(ns.getMergedTraits(), translateTraits(traits));
@@ -474,7 +339,7 @@ class NormalizedSchema {
474
339
  if (this.isStructSchema() && struct.memberNames.includes(memberName)) {
475
340
  const i = struct.memberNames.indexOf(memberName);
476
341
  const memberSchema = struct.memberList[i];
477
- return member(Array.isArray(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
342
+ return member(isMemberSchema(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
478
343
  }
479
344
  if (this.isDocumentSchema()) {
480
345
  return member([15, 0], memberName);
@@ -524,20 +389,122 @@ function member(memberSchema, memberName) {
524
389
  const internalCtorAccess = NormalizedSchema;
525
390
  return new internalCtorAccess(memberSchema, memberName);
526
391
  }
392
+ function hydrate(ss) {
393
+ const [id, ...rest] = ss;
394
+ return {
395
+ [0]: simAdapter,
396
+ [1]: list,
397
+ [2]: map,
398
+ [3]: struct,
399
+ [-3]: error,
400
+ [9]: op,
401
+ }[id].call(null, ...rest);
402
+ }
403
+ const isMemberSchema = (sc) => Array.isArray(sc) && sc.length === 2;
404
+ const isStaticSchema = (sc) => Array.isArray(sc) && sc.length >= 5;
527
405
 
528
- class SimpleSchema extends Schema {
529
- static symbol = Symbol.for("@smithy/sim");
530
- name;
531
- schemaRef;
532
- traits;
533
- symbol = SimpleSchema.symbol;
406
+ const schemaDeserializationMiddleware = (config) => (next, context) => async (args) => {
407
+ const { response } = await next(args);
408
+ let { operationSchema } = utilMiddleware.getSmithyContext(context);
409
+ if (isStaticSchema(operationSchema)) {
410
+ operationSchema = hydrate(operationSchema);
411
+ }
412
+ try {
413
+ const parsed = await config.protocol.deserializeResponse(operationSchema, {
414
+ ...config,
415
+ ...context,
416
+ }, response);
417
+ return {
418
+ response,
419
+ output: parsed,
420
+ };
421
+ }
422
+ catch (error) {
423
+ Object.defineProperty(error, "$response", {
424
+ value: response,
425
+ });
426
+ if (!("$metadata" in error)) {
427
+ const hint = `Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object.`;
428
+ try {
429
+ error.message += "\n " + hint;
430
+ }
431
+ catch (e) {
432
+ if (!context.logger || context.logger?.constructor?.name === "NoOpLogger") {
433
+ console.warn(hint);
434
+ }
435
+ else {
436
+ context.logger?.warn?.(hint);
437
+ }
438
+ }
439
+ if (typeof error.$responseBodyText !== "undefined") {
440
+ if (error.$response) {
441
+ error.$response.body = error.$responseBodyText;
442
+ }
443
+ }
444
+ try {
445
+ if (protocolHttp.HttpResponse.isInstance(response)) {
446
+ const { headers = {} } = response;
447
+ const headerEntries = Object.entries(headers);
448
+ error.$metadata = {
449
+ httpStatusCode: response.statusCode,
450
+ requestId: findHeader(/^x-[\w-]+-request-?id$/, headerEntries),
451
+ extendedRequestId: findHeader(/^x-[\w-]+-id-2$/, headerEntries),
452
+ cfId: findHeader(/^x-[\w-]+-cf-id$/, headerEntries),
453
+ };
454
+ }
455
+ }
456
+ catch (e) {
457
+ }
458
+ }
459
+ throw error;
460
+ }
461
+ };
462
+ const findHeader = (pattern, headers) => {
463
+ return (headers.find(([k]) => {
464
+ return k.match(pattern);
465
+ }) || [void 0, void 0])[1];
466
+ };
467
+
468
+ const schemaSerializationMiddleware = (config) => (next, context) => async (args) => {
469
+ let { operationSchema } = utilMiddleware.getSmithyContext(context);
470
+ if (isStaticSchema(operationSchema)) {
471
+ operationSchema = hydrate(operationSchema);
472
+ }
473
+ const endpoint = context.endpointV2?.url && config.urlParser
474
+ ? async () => config.urlParser(context.endpointV2.url)
475
+ : config.endpoint;
476
+ const request = await config.protocol.serializeRequest(operationSchema, args.input, {
477
+ ...config,
478
+ ...context,
479
+ endpoint,
480
+ });
481
+ return next({
482
+ ...args,
483
+ request,
484
+ });
485
+ };
486
+
487
+ const deserializerMiddlewareOption = {
488
+ name: "deserializerMiddleware",
489
+ step: "deserialize",
490
+ tags: ["DESERIALIZER"],
491
+ override: true,
492
+ };
493
+ const serializerMiddlewareOption = {
494
+ name: "serializerMiddleware",
495
+ step: "serialize",
496
+ tags: ["SERIALIZER"],
497
+ override: true,
498
+ };
499
+ function getSchemaSerdePlugin(config) {
500
+ return {
501
+ applyToStack: (commandStack) => {
502
+ commandStack.add(schemaSerializationMiddleware(config), serializerMiddlewareOption);
503
+ commandStack.add(schemaDeserializationMiddleware(config), deserializerMiddlewareOption);
504
+ config.protocol.setSerdeContext(config);
505
+ },
506
+ };
534
507
  }
535
- const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSchema(), {
536
- name,
537
- namespace,
538
- traits,
539
- schemaRef,
540
- });
541
508
 
542
509
  const SCHEMA = {
543
510
  BLOB: 0b0001_0101,
@@ -556,6 +523,72 @@ const SCHEMA = {
556
523
  MAP_MODIFIER: 0b1000_0000,
557
524
  };
558
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
+
559
592
  exports.ErrorSchema = ErrorSchema;
560
593
  exports.ListSchema = ListSchema;
561
594
  exports.MapSchema = MapSchema;
@@ -570,10 +603,13 @@ exports.deref = deref;
570
603
  exports.deserializerMiddlewareOption = deserializerMiddlewareOption;
571
604
  exports.error = error;
572
605
  exports.getSchemaSerdePlugin = getSchemaSerdePlugin;
606
+ exports.hydrate = hydrate;
607
+ exports.isStaticSchema = isStaticSchema;
573
608
  exports.list = list;
574
609
  exports.map = map;
575
610
  exports.op = op;
576
611
  exports.serializerMiddlewareOption = serializerMiddlewareOption;
577
612
  exports.sim = sim;
613
+ exports.simAdapter = simAdapter;
578
614
  exports.struct = struct;
579
615
  exports.translateTraits = translateTraits;
package/dist-es/index.js CHANGED
@@ -3,6 +3,6 @@ export * from "./middleware-http-auth-scheme";
3
3
  export * from "./middleware-http-signing";
4
4
  export * from "./normalizeProvider";
5
5
  export { createPaginator } from "./pagination/createPaginator";
6
- export * from "./protocols/requestBuilder";
6
+ export * from "./request-builder/requestBuilder";
7
7
  export * from "./setFeature";
8
8
  export * from "./util-identity-and-auth";
@@ -1,10 +1,10 @@
1
+ import { SerdeContext } from "@smithy/core/protocols";
1
2
  import { NormalizedSchema } from "@smithy/core/schema";
2
3
  import { _parseEpochTimestamp, generateIdempotencyToken } from "@smithy/core/serde";
3
4
  import { fromBase64 } from "@smithy/util-base64";
4
5
  import { cbor } from "./cbor";
5
6
  import { dateToTag } from "./parseCborBody";
6
- export class CborCodec {
7
- serdeContext;
7
+ export class CborCodec extends SerdeContext {
8
8
  createSerializer() {
9
9
  const serializer = new CborShapeSerializer();
10
10
  serializer.setSerdeContext(this.serdeContext);
@@ -15,16 +15,9 @@ export class CborCodec {
15
15
  deserializer.setSerdeContext(this.serdeContext);
16
16
  return deserializer;
17
17
  }
18
- setSerdeContext(serdeContext) {
19
- this.serdeContext = serdeContext;
20
- }
21
18
  }
22
- export class CborShapeSerializer {
23
- serdeContext;
19
+ export class CborShapeSerializer extends SerdeContext {
24
20
  value;
25
- setSerdeContext(serdeContext) {
26
- this.serdeContext = serdeContext;
27
- }
28
21
  write(schema, value) {
29
22
  this.value = this.serialize(schema, value);
30
23
  }
@@ -98,11 +91,7 @@ export class CborShapeSerializer {
98
91
  return buffer;
99
92
  }
100
93
  }
101
- export class CborShapeDeserializer {
102
- serdeContext;
103
- setSerdeContext(serdeContext) {
104
- this.serdeContext = serdeContext;
105
- }
94
+ export class CborShapeDeserializer extends SerdeContext {
106
95
  read(schema, bytes) {
107
96
  const data = cbor.deserialize(bytes);
108
97
  return this.readValue(schema, data);
@@ -1,9 +1,10 @@
1
1
  import { NormalizedSchema } from "@smithy/core/schema";
2
2
  import { HttpRequest, HttpResponse } from "@smithy/protocol-http";
3
- export class HttpProtocol {
3
+ import { SerdeContext } from "./SerdeContext";
4
+ export class HttpProtocol extends SerdeContext {
4
5
  options;
5
- serdeContext;
6
6
  constructor(options) {
7
+ super();
7
8
  this.options = options;
8
9
  }
9
10
  getRequestType() {
@@ -0,0 +1,6 @@
1
+ export class SerdeContext {
2
+ serdeContext;
3
+ setSerdeContext(serdeContext) {
4
+ this.serdeContext = serdeContext;
5
+ }
6
+ }
@@ -10,3 +10,4 @@ export * from "./serde/HttpInterceptingShapeDeserializer";
10
10
  export * from "./serde/HttpInterceptingShapeSerializer";
11
11
  export * from "./serde/ToStringShapeSerializer";
12
12
  export * from "./serde/determineTimestampFormat";
13
+ export * from "./SerdeContext";