@smithy/core 3.15.0 → 3.16.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.
Files changed (41) 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 +161 -138
  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 +4 -4
  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-types/index.d.ts +1 -1
  17. package/dist-types/submodules/cbor/CborCodec.d.ts +5 -10
  18. package/dist-types/submodules/protocols/HttpProtocol.d.ts +5 -2
  19. package/dist-types/submodules/protocols/SerdeContext.d.ts +8 -0
  20. package/dist-types/submodules/protocols/index.d.ts +1 -0
  21. package/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +3 -4
  22. package/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +5 -2
  23. package/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +5 -2
  24. package/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +3 -4
  25. package/dist-types/submodules/schema/TypeRegistry.d.ts +4 -4
  26. package/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +22 -1
  27. package/dist-types/ts3.4/index.d.ts +1 -1
  28. package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +5 -10
  29. package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +5 -2
  30. package/dist-types/ts3.4/submodules/protocols/SerdeContext.d.ts +8 -0
  31. package/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
  32. package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +3 -4
  33. package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +5 -2
  34. package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +5 -2
  35. package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +3 -4
  36. package/dist-types/ts3.4/submodules/schema/TypeRegistry.d.ts +4 -4
  37. package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +22 -1
  38. package/package.json +7 -7
  39. /package/dist-es/{protocols → request-builder}/requestBuilder.js +0 -0
  40. /package/dist-types/{protocols → request-builder}/requestBuilder.d.ts +0 -0
  41. /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,103 +10,6 @@ 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
13
  class TypeRegistry {
111
14
  namespace;
112
15
  schemas;
@@ -134,11 +37,11 @@ class TypeRegistry {
134
37
  }
135
38
  return this.schemas.get(id);
136
39
  }
137
- registerError(errorSchema, ctor) {
138
- this.exceptions.set(errorSchema, ctor);
40
+ registerError(es, ctor) {
41
+ this.exceptions.set(es, ctor);
139
42
  }
140
- getErrorCtor(errorSchema) {
141
- return this.exceptions.get(errorSchema);
43
+ getErrorCtor(es) {
44
+ return this.exceptions.get(es);
142
45
  }
143
46
  getBaseException() {
144
47
  for (const [id, schema] of this.schemas.entries()) {
@@ -188,6 +91,36 @@ class Schema {
188
91
  }
189
92
  }
190
93
 
94
+ class StructureSchema extends Schema {
95
+ static symbol = Symbol.for("@smithy/str");
96
+ name;
97
+ traits;
98
+ memberNames;
99
+ memberList;
100
+ symbol = StructureSchema.symbol;
101
+ }
102
+ const struct = (namespace, name, traits, memberNames, memberList) => Schema.assign(new StructureSchema(), {
103
+ name,
104
+ namespace,
105
+ traits,
106
+ memberNames,
107
+ memberList,
108
+ });
109
+
110
+ class ErrorSchema extends StructureSchema {
111
+ static symbol = Symbol.for("@smithy/err");
112
+ ctor;
113
+ symbol = ErrorSchema.symbol;
114
+ }
115
+ const error = (namespace, name, traits, memberNames, memberList, ctor) => Schema.assign(new ErrorSchema(), {
116
+ name,
117
+ namespace,
118
+ traits,
119
+ memberNames,
120
+ memberList,
121
+ ctor: null,
122
+ });
123
+
191
124
  class ListSchema extends Schema {
192
125
  static symbol = Symbol.for("@smithy/lis");
193
126
  name;
@@ -234,34 +167,18 @@ const op = (namespace, name, traits, input, output) => Schema.assign(new Operati
234
167
  output,
235
168
  });
236
169
 
237
- class StructureSchema extends Schema {
238
- static symbol = Symbol.for("@smithy/str");
170
+ class SimpleSchema extends Schema {
171
+ static symbol = Symbol.for("@smithy/sim");
239
172
  name;
173
+ schemaRef;
240
174
  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,
251
- });
252
-
253
- class ErrorSchema extends StructureSchema {
254
- static symbol = Symbol.for("@smithy/err");
255
- ctor;
256
- symbol = ErrorSchema.symbol;
175
+ symbol = SimpleSchema.symbol;
257
176
  }
258
- const error = (namespace, name, traits, memberNames, memberList, ctor) => Schema.assign(new ErrorSchema(), {
177
+ const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSchema(), {
259
178
  name,
260
179
  namespace,
261
180
  traits,
262
- memberNames,
263
- memberList,
264
- ctor: null,
181
+ schemaRef,
265
182
  });
266
183
 
267
184
  function translateTraits(indicator) {
@@ -305,12 +222,14 @@ class NormalizedSchema {
305
222
  let _ref = ref;
306
223
  let schema = ref;
307
224
  this._isMemberSchema = false;
308
- while (Array.isArray(_ref)) {
225
+ while (isMemberSchema(_ref)) {
309
226
  traitStack.push(_ref[1]);
310
227
  _ref = _ref[0];
311
228
  schema = deref(_ref);
312
229
  this._isMemberSchema = true;
313
230
  }
231
+ if (isStaticSchema(schema))
232
+ schema = hydrate(schema);
314
233
  if (traitStack.length > 0) {
315
234
  this.memberTraits = {};
316
235
  for (let i = traitStack.length - 1; i >= 0; --i) {
@@ -349,7 +268,7 @@ class NormalizedSchema {
349
268
  if (sc instanceof NormalizedSchema) {
350
269
  return sc;
351
270
  }
352
- if (Array.isArray(sc)) {
271
+ if (isMemberSchema(sc)) {
353
272
  const [ns, traits] = sc;
354
273
  if (ns instanceof NormalizedSchema) {
355
274
  Object.assign(ns.getMergedTraits(), translateTraits(traits));
@@ -474,7 +393,7 @@ class NormalizedSchema {
474
393
  if (this.isStructSchema() && struct.memberNames.includes(memberName)) {
475
394
  const i = struct.memberNames.indexOf(memberName);
476
395
  const memberSchema = struct.memberList[i];
477
- return member(Array.isArray(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
396
+ return member(isMemberSchema(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
478
397
  }
479
398
  if (this.isDocumentSchema()) {
480
399
  return member([15, 0], memberName);
@@ -524,20 +443,122 @@ function member(memberSchema, memberName) {
524
443
  const internalCtorAccess = NormalizedSchema;
525
444
  return new internalCtorAccess(memberSchema, memberName);
526
445
  }
446
+ function hydrate(ss) {
447
+ const [id, ...rest] = ss;
448
+ return {
449
+ [0]: sim,
450
+ [1]: list,
451
+ [2]: map,
452
+ [3]: struct,
453
+ [-3]: error,
454
+ [9]: op,
455
+ }[id].call(null, ...rest);
456
+ }
457
+ const isMemberSchema = (sc) => Array.isArray(sc) && sc.length === 2;
458
+ const isStaticSchema = (sc) => Array.isArray(sc) && sc.length >= 5;
527
459
 
528
- class SimpleSchema extends Schema {
529
- static symbol = Symbol.for("@smithy/sim");
530
- name;
531
- schemaRef;
532
- traits;
533
- symbol = SimpleSchema.symbol;
460
+ const schemaDeserializationMiddleware = (config) => (next, context) => async (args) => {
461
+ const { response } = await next(args);
462
+ let { operationSchema } = utilMiddleware.getSmithyContext(context);
463
+ if (isStaticSchema(operationSchema)) {
464
+ operationSchema = hydrate(operationSchema);
465
+ }
466
+ try {
467
+ const parsed = await config.protocol.deserializeResponse(operationSchema, {
468
+ ...config,
469
+ ...context,
470
+ }, response);
471
+ return {
472
+ response,
473
+ output: parsed,
474
+ };
475
+ }
476
+ catch (error) {
477
+ Object.defineProperty(error, "$response", {
478
+ value: response,
479
+ });
480
+ if (!("$metadata" in error)) {
481
+ const hint = `Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object.`;
482
+ try {
483
+ error.message += "\n " + hint;
484
+ }
485
+ catch (e) {
486
+ if (!context.logger || context.logger?.constructor?.name === "NoOpLogger") {
487
+ console.warn(hint);
488
+ }
489
+ else {
490
+ context.logger?.warn?.(hint);
491
+ }
492
+ }
493
+ if (typeof error.$responseBodyText !== "undefined") {
494
+ if (error.$response) {
495
+ error.$response.body = error.$responseBodyText;
496
+ }
497
+ }
498
+ try {
499
+ if (protocolHttp.HttpResponse.isInstance(response)) {
500
+ const { headers = {} } = response;
501
+ const headerEntries = Object.entries(headers);
502
+ error.$metadata = {
503
+ httpStatusCode: response.statusCode,
504
+ requestId: findHeader(/^x-[\w-]+-request-?id$/, headerEntries),
505
+ extendedRequestId: findHeader(/^x-[\w-]+-id-2$/, headerEntries),
506
+ cfId: findHeader(/^x-[\w-]+-cf-id$/, headerEntries),
507
+ };
508
+ }
509
+ }
510
+ catch (e) {
511
+ }
512
+ }
513
+ throw error;
514
+ }
515
+ };
516
+ const findHeader = (pattern, headers) => {
517
+ return (headers.find(([k]) => {
518
+ return k.match(pattern);
519
+ }) || [void 0, void 0])[1];
520
+ };
521
+
522
+ const schemaSerializationMiddleware = (config) => (next, context) => async (args) => {
523
+ let { operationSchema } = utilMiddleware.getSmithyContext(context);
524
+ if (isStaticSchema(operationSchema)) {
525
+ operationSchema = hydrate(operationSchema);
526
+ }
527
+ const endpoint = context.endpointV2?.url && config.urlParser
528
+ ? async () => config.urlParser(context.endpointV2.url)
529
+ : config.endpoint;
530
+ const request = await config.protocol.serializeRequest(operationSchema, args.input, {
531
+ ...config,
532
+ ...context,
533
+ endpoint,
534
+ });
535
+ return next({
536
+ ...args,
537
+ request,
538
+ });
539
+ };
540
+
541
+ const deserializerMiddlewareOption = {
542
+ name: "deserializerMiddleware",
543
+ step: "deserialize",
544
+ tags: ["DESERIALIZER"],
545
+ override: true,
546
+ };
547
+ const serializerMiddlewareOption = {
548
+ name: "serializerMiddleware",
549
+ step: "serialize",
550
+ tags: ["SERIALIZER"],
551
+ override: true,
552
+ };
553
+ function getSchemaSerdePlugin(config) {
554
+ return {
555
+ applyToStack: (commandStack) => {
556
+ commandStack.add(schemaSerializationMiddleware(config), serializerMiddlewareOption);
557
+ commandStack.add(schemaDeserializationMiddleware(config), deserializerMiddlewareOption);
558
+ config.protocol.setSerdeContext(config);
559
+ },
560
+ };
534
561
  }
535
- const sim = (namespace, name, schemaRef, traits) => Schema.assign(new SimpleSchema(), {
536
- name,
537
- namespace,
538
- traits,
539
- schemaRef,
540
- });
541
562
 
542
563
  const SCHEMA = {
543
564
  BLOB: 0b0001_0101,
@@ -570,6 +591,8 @@ exports.deref = deref;
570
591
  exports.deserializerMiddlewareOption = deserializerMiddlewareOption;
571
592
  exports.error = error;
572
593
  exports.getSchemaSerdePlugin = getSchemaSerdePlugin;
594
+ exports.hydrate = hydrate;
595
+ exports.isStaticSchema = isStaticSchema;
573
596
  exports.list = list;
574
597
  exports.map = map;
575
598
  exports.op = op;
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";
@@ -2,16 +2,14 @@ import { NormalizedSchema } from "@smithy/core/schema";
2
2
  import { _parseEpochTimestamp, _parseRfc3339DateTimeWithOffset, _parseRfc7231DateTime, LazyJsonString, NumericValue, splitHeader, } from "@smithy/core/serde";
3
3
  import { fromBase64 } from "@smithy/util-base64";
4
4
  import { toUtf8 } from "@smithy/util-utf8";
5
+ import { SerdeContext } from "../SerdeContext";
5
6
  import { determineTimestampFormat } from "./determineTimestampFormat";
6
- export class FromStringShapeDeserializer {
7
+ export class FromStringShapeDeserializer extends SerdeContext {
7
8
  settings;
8
- serdeContext;
9
9
  constructor(settings) {
10
+ super();
10
11
  this.settings = settings;
11
12
  }
12
- setSerdeContext(serdeContext) {
13
- this.serdeContext = serdeContext;
14
- }
15
13
  read(_schema, data) {
16
14
  const ns = NormalizedSchema.of(_schema);
17
15
  if (ns.isListSchema()) {
@@ -1,11 +1,12 @@
1
1
  import { NormalizedSchema } from "@smithy/core/schema";
2
2
  import { fromUtf8, toUtf8 } from "@smithy/util-utf8";
3
+ import { SerdeContext } from "../SerdeContext";
3
4
  import { FromStringShapeDeserializer } from "./FromStringShapeDeserializer";
4
- export class HttpInterceptingShapeDeserializer {
5
+ export class HttpInterceptingShapeDeserializer extends SerdeContext {
5
6
  codecDeserializer;
6
7
  stringDeserializer;
7
- serdeContext;
8
8
  constructor(codecDeserializer, codecSettings) {
9
+ super();
9
10
  this.codecDeserializer = codecDeserializer;
10
11
  this.stringDeserializer = new FromStringShapeDeserializer(codecSettings);
11
12
  }
@@ -1,17 +1,15 @@
1
1
  import { NormalizedSchema } from "@smithy/core/schema";
2
2
  import { dateToUtcString, LazyJsonString, quoteHeader } from "@smithy/core/serde";
3
3
  import { toBase64 } from "@smithy/util-base64";
4
+ import { SerdeContext } from "../SerdeContext";
4
5
  import { determineTimestampFormat } from "./determineTimestampFormat";
5
- export class ToStringShapeSerializer {
6
+ export class ToStringShapeSerializer extends SerdeContext {
6
7
  settings;
7
8
  stringBuffer = "";
8
- serdeContext = undefined;
9
9
  constructor(settings) {
10
+ super();
10
11
  this.settings = settings;
11
12
  }
12
- setSerdeContext(serdeContext) {
13
- this.serdeContext = serdeContext;
14
- }
15
13
  write(schema, value) {
16
14
  const ns = NormalizedSchema.of(schema);
17
15
  switch (typeof value) {
@@ -25,11 +25,11 @@ export class TypeRegistry {
25
25
  }
26
26
  return this.schemas.get(id);
27
27
  }
28
- registerError(errorSchema, ctor) {
29
- this.exceptions.set(errorSchema, ctor);
28
+ registerError(es, ctor) {
29
+ this.exceptions.set(es, ctor);
30
30
  }
31
- getErrorCtor(errorSchema) {
32
- return this.exceptions.get(errorSchema);
31
+ getErrorCtor(es) {
32
+ return this.exceptions.get(es);
33
33
  }
34
34
  getBaseException() {
35
35
  for (const [id, schema] of this.schemas.entries()) {
@@ -1,8 +1,12 @@
1
1
  import { HttpResponse } from "@smithy/protocol-http";
2
2
  import { getSmithyContext } from "@smithy/util-middleware";
3
+ import { hydrate, isStaticSchema } from "../schemas/NormalizedSchema";
3
4
  export const schemaDeserializationMiddleware = (config) => (next, context) => async (args) => {
4
5
  const { response } = await next(args);
5
- const { operationSchema } = getSmithyContext(context);
6
+ let { operationSchema } = getSmithyContext(context);
7
+ if (isStaticSchema(operationSchema)) {
8
+ operationSchema = hydrate(operationSchema);
9
+ }
6
10
  try {
7
11
  const parsed = await config.protocol.deserializeResponse(operationSchema, {
8
12
  ...config,
@@ -1,6 +1,10 @@
1
1
  import { getSmithyContext } from "@smithy/util-middleware";
2
+ import { hydrate, isStaticSchema } from "../schemas/NormalizedSchema";
2
3
  export const schemaSerializationMiddleware = (config) => (next, context) => async (args) => {
3
- const { operationSchema } = getSmithyContext(context);
4
+ let { operationSchema } = getSmithyContext(context);
5
+ if (isStaticSchema(operationSchema)) {
6
+ operationSchema = hydrate(operationSchema);
7
+ }
4
8
  const endpoint = context.endpointV2?.url && config.urlParser
5
9
  ? async () => config.urlParser(context.endpointV2.url)
6
10
  : config.endpoint;
@@ -1,8 +1,11 @@
1
1
  import { deref } from "../deref";
2
- import { ListSchema } from "./ListSchema";
3
- import { MapSchema } from "./MapSchema";
2
+ import { error } from "./ErrorSchema";
3
+ import { list, ListSchema } from "./ListSchema";
4
+ import { map, MapSchema } from "./MapSchema";
5
+ import { op } from "./OperationSchema";
4
6
  import { Schema } from "./Schema";
5
- import { StructureSchema } from "./StructureSchema";
7
+ import { sim } from "./SimpleSchema";
8
+ import { struct, StructureSchema } from "./StructureSchema";
6
9
  import { translateTraits } from "./translateTraits";
7
10
  export class NormalizedSchema {
8
11
  ref;
@@ -22,12 +25,14 @@ export class NormalizedSchema {
22
25
  let _ref = ref;
23
26
  let schema = ref;
24
27
  this._isMemberSchema = false;
25
- while (Array.isArray(_ref)) {
28
+ while (isMemberSchema(_ref)) {
26
29
  traitStack.push(_ref[1]);
27
30
  _ref = _ref[0];
28
31
  schema = deref(_ref);
29
32
  this._isMemberSchema = true;
30
33
  }
34
+ if (isStaticSchema(schema))
35
+ schema = hydrate(schema);
31
36
  if (traitStack.length > 0) {
32
37
  this.memberTraits = {};
33
38
  for (let i = traitStack.length - 1; i >= 0; --i) {
@@ -66,7 +71,7 @@ export class NormalizedSchema {
66
71
  if (sc instanceof NormalizedSchema) {
67
72
  return sc;
68
73
  }
69
- if (Array.isArray(sc)) {
74
+ if (isMemberSchema(sc)) {
70
75
  const [ns, traits] = sc;
71
76
  if (ns instanceof NormalizedSchema) {
72
77
  Object.assign(ns.getMergedTraits(), translateTraits(traits));
@@ -191,7 +196,7 @@ export class NormalizedSchema {
191
196
  if (this.isStructSchema() && struct.memberNames.includes(memberName)) {
192
197
  const i = struct.memberNames.indexOf(memberName);
193
198
  const memberSchema = struct.memberList[i];
194
- return member(Array.isArray(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
199
+ return member(isMemberSchema(memberSchema) ? memberSchema : [memberSchema, 0], memberName);
195
200
  }
196
201
  if (this.isDocumentSchema()) {
197
202
  return member([15, 0], memberName);
@@ -241,3 +246,16 @@ function member(memberSchema, memberName) {
241
246
  const internalCtorAccess = NormalizedSchema;
242
247
  return new internalCtorAccess(memberSchema, memberName);
243
248
  }
249
+ export function hydrate(ss) {
250
+ const [id, ...rest] = ss;
251
+ return {
252
+ [0]: sim,
253
+ [1]: list,
254
+ [2]: map,
255
+ [3]: struct,
256
+ [-3]: error,
257
+ [9]: op,
258
+ }[id].call(null, ...rest);
259
+ }
260
+ const isMemberSchema = (sc) => Array.isArray(sc) && sc.length === 2;
261
+ export const isStaticSchema = (sc) => Array.isArray(sc) && sc.length >= 5;
@@ -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,20 +1,17 @@
1
- import type { Codec, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
1
+ import { SerdeContext } from "@smithy/core/protocols";
2
+ import type { Codec, Schema, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
2
3
  /**
3
4
  * @alpha
4
5
  */
5
- export declare class CborCodec implements Codec<Uint8Array, Uint8Array> {
6
- private serdeContext?;
6
+ export declare class CborCodec extends SerdeContext implements Codec<Uint8Array, Uint8Array> {
7
7
  createSerializer(): CborShapeSerializer;
8
8
  createDeserializer(): CborShapeDeserializer;
9
- setSerdeContext(serdeContext: SerdeFunctions): void;
10
9
  }
11
10
  /**
12
11
  * @alpha
13
12
  */
14
- export declare class CborShapeSerializer implements ShapeSerializer {
15
- private serdeContext?;
13
+ export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer {
16
14
  private value;
17
- setSerdeContext(serdeContext: SerdeFunctions): void;
18
15
  write(schema: Schema, value: unknown): void;
19
16
  /**
20
17
  * Recursive serializer transform that copies and prepares the user input object
@@ -26,9 +23,7 @@ export declare class CborShapeSerializer implements ShapeSerializer {
26
23
  /**
27
24
  * @alpha
28
25
  */
29
- export declare class CborShapeDeserializer implements ShapeDeserializer {
30
- private serdeContext?;
31
- setSerdeContext(serdeContext: SerdeFunctions): void;
26
+ export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer {
32
27
  read(schema: Schema, bytes: Uint8Array): any;
33
28
  /**
34
29
  * Public because it's called by the protocol implementation to deserialize errors.
@@ -1,18 +1,18 @@
1
1
  import type { EventStreamSerde } from "@smithy/core/event-streams";
2
2
  import { NormalizedSchema } from "@smithy/core/schema";
3
3
  import type { ClientProtocol, Codec, Endpoint, EndpointBearer, EndpointV2, EventStreamMarshaller, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
4
+ import { SerdeContext } from "./SerdeContext";
4
5
  /**
5
6
  * Abstract base for HTTP-based client protocols.
6
7
  *
7
8
  * @alpha
8
9
  */
9
- export declare abstract class HttpProtocol implements ClientProtocol<IHttpRequest, IHttpResponse> {
10
+ export declare abstract class HttpProtocol extends SerdeContext implements ClientProtocol<IHttpRequest, IHttpResponse> {
10
11
  readonly options: {
11
12
  defaultNamespace: string;
12
13
  };
13
14
  protected abstract serializer: ShapeSerializer<string | Uint8Array>;
14
15
  protected abstract deserializer: ShapeDeserializer<string | Uint8Array>;
15
- protected serdeContext?: SerdeFunctions;
16
16
  protected constructor(options: {
17
17
  defaultNamespace: string;
18
18
  });
@@ -20,6 +20,9 @@ export declare abstract class HttpProtocol implements ClientProtocol<IHttpReques
20
20
  abstract getPayloadCodec(): Codec<any, any>;
21
21
  getRequestType(): new (...args: any[]) => IHttpRequest;
22
22
  getResponseType(): new (...args: any[]) => IHttpResponse;
23
+ /**
24
+ * @override
25
+ */
23
26
  setSerdeContext(serdeContext: SerdeFunctions): void;
24
27
  abstract serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
25
28
  updateServiceEndpoint(request: IHttpRequest, endpoint: EndpointV2 | Endpoint): IHttpRequest;
@@ -0,0 +1,8 @@
1
+ import type { ConfigurableSerdeContext, SerdeFunctions } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare abstract class SerdeContext implements ConfigurableSerdeContext {
6
+ protected serdeContext?: SerdeFunctions;
7
+ setSerdeContext(serdeContext: SerdeFunctions): void;
8
+ }
@@ -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";
@@ -1,14 +1,13 @@
1
- import type { CodecSettings, Schema, SerdeFunctions, ShapeDeserializer } from "@smithy/types";
1
+ import type { CodecSettings, Schema, ShapeDeserializer } from "@smithy/types";
2
+ import { SerdeContext } from "../SerdeContext";
2
3
  /**
3
4
  * This deserializer reads strings.
4
5
  *
5
6
  * @alpha
6
7
  */
7
- export declare class FromStringShapeDeserializer implements ShapeDeserializer<string> {
8
+ export declare class FromStringShapeDeserializer extends SerdeContext implements ShapeDeserializer<string> {
8
9
  private settings;
9
- private serdeContext;
10
10
  constructor(settings: CodecSettings);
11
- setSerdeContext(serdeContext: SerdeFunctions): void;
12
11
  read(_schema: Schema, data: string): any;
13
12
  private base64ToUtf8;
14
13
  }
@@ -1,4 +1,5 @@
1
1
  import type { CodecSettings, Schema, SerdeFunctions, ShapeDeserializer } from "@smithy/types";
2
+ import { SerdeContext } from "../SerdeContext";
2
3
  /**
3
4
  * This deserializer is a dispatcher that decides whether to use a string deserializer
4
5
  * or a codec deserializer based on HTTP traits.
@@ -8,11 +9,13 @@ import type { CodecSettings, Schema, SerdeFunctions, ShapeDeserializer } from "@
8
9
  *
9
10
  * @alpha
10
11
  */
11
- export declare class HttpInterceptingShapeDeserializer<CodecShapeDeserializer extends ShapeDeserializer<any>> implements ShapeDeserializer<string | Uint8Array> {
12
+ export declare class HttpInterceptingShapeDeserializer<CodecShapeDeserializer extends ShapeDeserializer<any>> extends SerdeContext implements ShapeDeserializer<string | Uint8Array> {
12
13
  private codecDeserializer;
13
14
  private stringDeserializer;
14
- private serdeContext;
15
15
  constructor(codecDeserializer: CodecShapeDeserializer, codecSettings: CodecSettings);
16
+ /**
17
+ * @override
18
+ */
16
19
  setSerdeContext(serdeContext: SerdeFunctions): void;
17
20
  read(schema: Schema, data: string | Uint8Array): any | Promise<any>;
18
21
  }
@@ -1,4 +1,4 @@
1
- import type { CodecSettings, Schema as ISchema, SerdeFunctions, ShapeSerializer } from "@smithy/types";
1
+ import type { CodecSettings, ConfigurableSerdeContext, Schema as ISchema, SerdeFunctions, ShapeSerializer } from "@smithy/types";
2
2
  import { ToStringShapeSerializer } from "./ToStringShapeSerializer";
3
3
  /**
4
4
  * This serializer decides whether to dispatch to a string serializer or a codec serializer
@@ -9,11 +9,14 @@ import { ToStringShapeSerializer } from "./ToStringShapeSerializer";
9
9
  *
10
10
  * @alpha
11
11
  */
12
- export declare class HttpInterceptingShapeSerializer<CodecShapeSerializer extends ShapeSerializer<string | Uint8Array>> implements ShapeSerializer<string | Uint8Array> {
12
+ export declare class HttpInterceptingShapeSerializer<CodecShapeSerializer extends ShapeSerializer<string | Uint8Array>> implements ShapeSerializer<string | Uint8Array>, ConfigurableSerdeContext {
13
13
  private codecSerializer;
14
14
  private stringSerializer;
15
15
  private buffer;
16
16
  constructor(codecSerializer: CodecShapeSerializer, codecSettings: CodecSettings, stringSerializer?: ToStringShapeSerializer);
17
+ /**
18
+ * @override
19
+ */
17
20
  setSerdeContext(serdeContext: SerdeFunctions): void;
18
21
  write(schema: ISchema, value: unknown): void;
19
22
  flush(): string | Uint8Array;
@@ -1,15 +1,14 @@
1
- import type { CodecSettings, Schema, SerdeFunctions, ShapeSerializer } from "@smithy/types";
1
+ import type { CodecSettings, Schema, ShapeSerializer } from "@smithy/types";
2
+ import { SerdeContext } from "../SerdeContext";
2
3
  /**
3
4
  * Serializes a shape to string.
4
5
  *
5
6
  * @alpha
6
7
  */
7
- export declare class ToStringShapeSerializer implements ShapeSerializer<string> {
8
+ export declare class ToStringShapeSerializer extends SerdeContext implements ShapeSerializer<string> {
8
9
  private settings;
9
10
  private stringBuffer;
10
- private serdeContext;
11
11
  constructor(settings: CodecSettings);
12
- setSerdeContext(serdeContext: SerdeFunctions): void;
13
12
  write(schema: Schema, value: unknown): void;
14
13
  flush(): string;
15
14
  }
@@ -1,4 +1,4 @@
1
- import type { Schema as ISchema } from "@smithy/types";
1
+ import type { Schema as ISchema, StaticErrorSchema } from "@smithy/types";
2
2
  import type { ErrorSchema } from "./schemas/ErrorSchema";
3
3
  /**
4
4
  * A way to look up schema by their ShapeId values.
@@ -31,12 +31,12 @@ export declare class TypeRegistry {
31
31
  /**
32
32
  * Associates an error schema with its constructor.
33
33
  */
34
- registerError(errorSchema: ErrorSchema, ctor: any): void;
34
+ registerError(es: ErrorSchema | StaticErrorSchema, ctor: any): void;
35
35
  /**
36
- * @param errorSchema - query.
36
+ * @param es - query.
37
37
  * @returns Error constructor that extends the service's base exception.
38
38
  */
39
- getErrorCtor(errorSchema: ErrorSchema): any;
39
+ getErrorCtor(es: ErrorSchema | StaticErrorSchema): any;
40
40
  /**
41
41
  * The smithy-typescript code generator generates a synthetic (i.e. unmodeled) base exception,
42
42
  * because generated SDKs before the introduction of schemas have the notion of a ServiceBaseException, which
@@ -1,4 +1,10 @@
1
- import type { MemberSchema, NormalizedSchema as INormalizedSchema, Schema as ISchema, SchemaRef, SchemaTraitsObject } from "@smithy/types";
1
+ import type { MemberSchema, NormalizedSchema as INormalizedSchema, Schema as ISchema, SchemaRef, SchemaTraitsObject, StaticErrorSchema, StaticListSchema, StaticMapSchema, StaticOperationSchema, StaticSchema, StaticSimpleSchema, StaticStructureSchema } from "@smithy/types";
2
+ import type { ErrorSchema } from "./ErrorSchema";
3
+ import { ListSchema } from "./ListSchema";
4
+ import { MapSchema } from "./MapSchema";
5
+ import type { OperationSchema } from "./OperationSchema";
6
+ import type { SimpleSchema } from "./SimpleSchema";
7
+ import { StructureSchema } from "./StructureSchema";
2
8
  /**
3
9
  * Wraps both class instances, numeric sentinel values, and member schema pairs.
4
10
  * Presents a consistent interface for interacting with polymorphic schema representations.
@@ -121,3 +127,18 @@ export declare class NormalizedSchema implements INormalizedSchema {
121
127
  */
122
128
  structIterator(): Generator<[string, NormalizedSchema], undefined, undefined>;
123
129
  }
130
+ /**
131
+ * @internal
132
+ * @returns a class instance version of a static schema.
133
+ */
134
+ export declare function hydrate(ss: StaticSimpleSchema): SimpleSchema;
135
+ export declare function hydrate(ss: StaticListSchema): ListSchema;
136
+ export declare function hydrate(ss: StaticMapSchema): MapSchema;
137
+ export declare function hydrate(ss: StaticStructureSchema): StructureSchema;
138
+ export declare function hydrate(ss: StaticErrorSchema): ErrorSchema;
139
+ export declare function hydrate(ss: StaticOperationSchema): OperationSchema;
140
+ export declare function hydrate(ss: StaticSchema): SimpleSchema | ListSchema | MapSchema | StructureSchema | ErrorSchema | OperationSchema;
141
+ /**
142
+ * @internal
143
+ */
144
+ export declare const isStaticSchema: (sc: SchemaRef) => sc is StaticSchema;
@@ -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,20 +1,17 @@
1
- import { Codec, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
1
+ import { SerdeContext } from "@smithy/core/protocols";
2
+ import { Codec, Schema, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
2
3
  /**
3
4
  * @alpha
4
5
  */
5
- export declare class CborCodec implements Codec<Uint8Array, Uint8Array> {
6
- private serdeContext?;
6
+ export declare class CborCodec extends SerdeContext implements Codec<Uint8Array, Uint8Array> {
7
7
  createSerializer(): CborShapeSerializer;
8
8
  createDeserializer(): CborShapeDeserializer;
9
- setSerdeContext(serdeContext: SerdeFunctions): void;
10
9
  }
11
10
  /**
12
11
  * @alpha
13
12
  */
14
- export declare class CborShapeSerializer implements ShapeSerializer {
15
- private serdeContext?;
13
+ export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer {
16
14
  private value;
17
- setSerdeContext(serdeContext: SerdeFunctions): void;
18
15
  write(schema: Schema, value: unknown): void;
19
16
  /**
20
17
  * Recursive serializer transform that copies and prepares the user input object
@@ -26,9 +23,7 @@ export declare class CborShapeSerializer implements ShapeSerializer {
26
23
  /**
27
24
  * @alpha
28
25
  */
29
- export declare class CborShapeDeserializer implements ShapeDeserializer {
30
- private serdeContext?;
31
- setSerdeContext(serdeContext: SerdeFunctions): void;
26
+ export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer {
32
27
  read(schema: Schema, bytes: Uint8Array): any;
33
28
  /**
34
29
  * Public because it's called by the protocol implementation to deserialize errors.
@@ -1,18 +1,18 @@
1
1
  import { EventStreamSerde } from "@smithy/core/event-streams";
2
2
  import { NormalizedSchema } from "@smithy/core/schema";
3
3
  import { ClientProtocol, Codec, Endpoint, EndpointBearer, EndpointV2, EventStreamMarshaller, HandlerExecutionContext, HttpRequest as IHttpRequest, HttpResponse as IHttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, Schema, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
4
+ import { SerdeContext } from "./SerdeContext";
4
5
  /**
5
6
  * Abstract base for HTTP-based client protocols.
6
7
  *
7
8
  * @alpha
8
9
  */
9
- export declare abstract class HttpProtocol implements ClientProtocol<IHttpRequest, IHttpResponse> {
10
+ export declare abstract class HttpProtocol extends SerdeContext implements ClientProtocol<IHttpRequest, IHttpResponse> {
10
11
  readonly options: {
11
12
  defaultNamespace: string;
12
13
  };
13
14
  protected abstract serializer: ShapeSerializer<string | Uint8Array>;
14
15
  protected abstract deserializer: ShapeDeserializer<string | Uint8Array>;
15
- protected serdeContext?: SerdeFunctions;
16
16
  protected constructor(options: {
17
17
  defaultNamespace: string;
18
18
  });
@@ -20,6 +20,9 @@ export declare abstract class HttpProtocol implements ClientProtocol<IHttpReques
20
20
  abstract getPayloadCodec(): Codec<any, any>;
21
21
  getRequestType(): new (...args: any[]) => IHttpRequest;
22
22
  getResponseType(): new (...args: any[]) => IHttpResponse;
23
+ /**
24
+ * @override
25
+ */
23
26
  setSerdeContext(serdeContext: SerdeFunctions): void;
24
27
  abstract serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<IHttpRequest>;
25
28
  updateServiceEndpoint(request: IHttpRequest, endpoint: EndpointV2 | Endpoint): IHttpRequest;
@@ -0,0 +1,8 @@
1
+ import { ConfigurableSerdeContext, SerdeFunctions } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare abstract class SerdeContext implements ConfigurableSerdeContext {
6
+ protected serdeContext?: SerdeFunctions;
7
+ setSerdeContext(serdeContext: SerdeFunctions): void;
8
+ }
@@ -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";
@@ -1,14 +1,13 @@
1
- import { CodecSettings, Schema, SerdeFunctions, ShapeDeserializer } from "@smithy/types";
1
+ import { CodecSettings, Schema, ShapeDeserializer } from "@smithy/types";
2
+ import { SerdeContext } from "../SerdeContext";
2
3
  /**
3
4
  * This deserializer reads strings.
4
5
  *
5
6
  * @alpha
6
7
  */
7
- export declare class FromStringShapeDeserializer implements ShapeDeserializer<string> {
8
+ export declare class FromStringShapeDeserializer extends SerdeContext implements ShapeDeserializer<string> {
8
9
  private settings;
9
- private serdeContext;
10
10
  constructor(settings: CodecSettings);
11
- setSerdeContext(serdeContext: SerdeFunctions): void;
12
11
  read(_schema: Schema, data: string): any;
13
12
  private base64ToUtf8;
14
13
  }
@@ -1,4 +1,5 @@
1
1
  import { CodecSettings, Schema, SerdeFunctions, ShapeDeserializer } from "@smithy/types";
2
+ import { SerdeContext } from "../SerdeContext";
2
3
  /**
3
4
  * This deserializer is a dispatcher that decides whether to use a string deserializer
4
5
  * or a codec deserializer based on HTTP traits.
@@ -8,11 +9,13 @@ import { CodecSettings, Schema, SerdeFunctions, ShapeDeserializer } from "@smith
8
9
  *
9
10
  * @alpha
10
11
  */
11
- export declare class HttpInterceptingShapeDeserializer<CodecShapeDeserializer extends ShapeDeserializer<any>> implements ShapeDeserializer<string | Uint8Array> {
12
+ export declare class HttpInterceptingShapeDeserializer<CodecShapeDeserializer extends ShapeDeserializer<any>> extends SerdeContext implements ShapeDeserializer<string | Uint8Array> {
12
13
  private codecDeserializer;
13
14
  private stringDeserializer;
14
- private serdeContext;
15
15
  constructor(codecDeserializer: CodecShapeDeserializer, codecSettings: CodecSettings);
16
+ /**
17
+ * @override
18
+ */
16
19
  setSerdeContext(serdeContext: SerdeFunctions): void;
17
20
  read(schema: Schema, data: string | Uint8Array): any | Promise<any>;
18
21
  }
@@ -1,4 +1,4 @@
1
- import { CodecSettings, Schema as ISchema, SerdeFunctions, ShapeSerializer } from "@smithy/types";
1
+ import { CodecSettings, ConfigurableSerdeContext, Schema as ISchema, SerdeFunctions, ShapeSerializer } from "@smithy/types";
2
2
  import { ToStringShapeSerializer } from "./ToStringShapeSerializer";
3
3
  /**
4
4
  * This serializer decides whether to dispatch to a string serializer or a codec serializer
@@ -9,11 +9,14 @@ import { ToStringShapeSerializer } from "./ToStringShapeSerializer";
9
9
  *
10
10
  * @alpha
11
11
  */
12
- export declare class HttpInterceptingShapeSerializer<CodecShapeSerializer extends ShapeSerializer<string | Uint8Array>> implements ShapeSerializer<string | Uint8Array> {
12
+ export declare class HttpInterceptingShapeSerializer<CodecShapeSerializer extends ShapeSerializer<string | Uint8Array>> implements ShapeSerializer<string | Uint8Array>, ConfigurableSerdeContext {
13
13
  private codecSerializer;
14
14
  private stringSerializer;
15
15
  private buffer;
16
16
  constructor(codecSerializer: CodecShapeSerializer, codecSettings: CodecSettings, stringSerializer?: ToStringShapeSerializer);
17
+ /**
18
+ * @override
19
+ */
17
20
  setSerdeContext(serdeContext: SerdeFunctions): void;
18
21
  write(schema: ISchema, value: unknown): void;
19
22
  flush(): string | Uint8Array;
@@ -1,15 +1,14 @@
1
- import { CodecSettings, Schema, SerdeFunctions, ShapeSerializer } from "@smithy/types";
1
+ import { CodecSettings, Schema, ShapeSerializer } from "@smithy/types";
2
+ import { SerdeContext } from "../SerdeContext";
2
3
  /**
3
4
  * Serializes a shape to string.
4
5
  *
5
6
  * @alpha
6
7
  */
7
- export declare class ToStringShapeSerializer implements ShapeSerializer<string> {
8
+ export declare class ToStringShapeSerializer extends SerdeContext implements ShapeSerializer<string> {
8
9
  private settings;
9
10
  private stringBuffer;
10
- private serdeContext;
11
11
  constructor(settings: CodecSettings);
12
- setSerdeContext(serdeContext: SerdeFunctions): void;
13
12
  write(schema: Schema, value: unknown): void;
14
13
  flush(): string;
15
14
  }
@@ -1,4 +1,4 @@
1
- import { Schema as ISchema } from "@smithy/types";
1
+ import { Schema as ISchema, StaticErrorSchema } from "@smithy/types";
2
2
  import { ErrorSchema } from "./schemas/ErrorSchema";
3
3
  /**
4
4
  * A way to look up schema by their ShapeId values.
@@ -31,12 +31,12 @@ export declare class TypeRegistry {
31
31
  /**
32
32
  * Associates an error schema with its constructor.
33
33
  */
34
- registerError(errorSchema: ErrorSchema, ctor: any): void;
34
+ registerError(es: ErrorSchema | StaticErrorSchema, ctor: any): void;
35
35
  /**
36
- * @param errorSchema - query.
36
+ * @param es - query.
37
37
  * @returns Error constructor that extends the service's base exception.
38
38
  */
39
- getErrorCtor(errorSchema: ErrorSchema): any;
39
+ getErrorCtor(es: ErrorSchema | StaticErrorSchema): any;
40
40
  /**
41
41
  * The smithy-typescript code generator generates a synthetic (i.e. unmodeled) base exception,
42
42
  * because generated SDKs before the introduction of schemas have the notion of a ServiceBaseException, which
@@ -1,4 +1,10 @@
1
- import { MemberSchema, NormalizedSchema as INormalizedSchema, Schema as ISchema, SchemaRef, SchemaTraitsObject } from "@smithy/types";
1
+ import { MemberSchema, NormalizedSchema as INormalizedSchema, Schema as ISchema, SchemaRef, SchemaTraitsObject, StaticErrorSchema, StaticListSchema, StaticMapSchema, StaticOperationSchema, StaticSchema, StaticSimpleSchema, StaticStructureSchema } from "@smithy/types";
2
+ import { ErrorSchema } from "./ErrorSchema";
3
+ import { ListSchema } from "./ListSchema";
4
+ import { MapSchema } from "./MapSchema";
5
+ import { OperationSchema } from "./OperationSchema";
6
+ import { SimpleSchema } from "./SimpleSchema";
7
+ import { StructureSchema } from "./StructureSchema";
2
8
  /**
3
9
  * Wraps both class instances, numeric sentinel values, and member schema pairs.
4
10
  * Presents a consistent interface for interacting with polymorphic schema representations.
@@ -124,3 +130,18 @@ export declare class NormalizedSchema implements INormalizedSchema {
124
130
  NormalizedSchema
125
131
  ], undefined, undefined>;
126
132
  }
133
+ /**
134
+ * @internal
135
+ * @returns a class instance version of a static schema.
136
+ */
137
+ export declare function hydrate(ss: StaticSimpleSchema): SimpleSchema;
138
+ export declare function hydrate(ss: StaticListSchema): ListSchema;
139
+ export declare function hydrate(ss: StaticMapSchema): MapSchema;
140
+ export declare function hydrate(ss: StaticStructureSchema): StructureSchema;
141
+ export declare function hydrate(ss: StaticErrorSchema): ErrorSchema;
142
+ export declare function hydrate(ss: StaticOperationSchema): OperationSchema;
143
+ export declare function hydrate(ss: StaticSchema): SimpleSchema | ListSchema | MapSchema | StructureSchema | ErrorSchema | OperationSchema;
144
+ /**
145
+ * @internal
146
+ */
147
+ export declare const isStaticSchema: (sc: SchemaRef) => sc is StaticSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.15.0",
3
+ "version": "3.16.0",
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.0",
81
- "@smithy/protocol-http": "^5.3.0",
82
- "@smithy/types": "^4.6.0",
80
+ "@smithy/middleware-serde": "^4.2.1",
81
+ "@smithy/protocol-http": "^5.3.1",
82
+ "@smithy/types": "^4.7.0",
83
83
  "@smithy/util-base64": "^4.3.0",
84
84
  "@smithy/util-body-length-browser": "^4.2.0",
85
- "@smithy/util-middleware": "^4.2.0",
86
- "@smithy/util-stream": "^4.5.0",
85
+ "@smithy/util-middleware": "^4.2.1",
86
+ "@smithy/util-stream": "^4.5.1",
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.0",
121
+ "@smithy/eventstream-serde-node": "^4.2.1",
122
122
  "@types/node": "^18.11.9",
123
123
  "concurrently": "7.0.0",
124
124
  "downlevel-dts": "0.10.1",