@aws-sdk/core 3.977.4 → 3.977.6

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.
@@ -1,7 +1,7 @@
1
1
  import { RpcProtocol } from "@smithy/core/protocols";
2
2
  import { deref, NormalizedSchema } from "@smithy/core/schema";
3
3
  import { ProtocolLib } from "../ProtocolLib";
4
- import { JsonCodec } from "./codec-v1/JsonCodec";
4
+ import { JsonCodec2 } from "./codec-v2/JsonCodec2";
5
5
  import { loadJsonRpcErrorCode } from "./parseJsonBody";
6
6
  export class AwsJsonRpcProtocol extends RpcProtocol {
7
7
  serializer;
@@ -18,7 +18,7 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
18
18
  this.serviceTarget = serviceTarget;
19
19
  this.codec =
20
20
  jsonCodec ??
21
- new JsonCodec({
21
+ new JsonCodec2({
22
22
  timestampFormat: {
23
23
  useTrait: true,
24
24
  default: 7,
@@ -1,14 +1,14 @@
1
1
  import { HttpBindingProtocol, HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer, } from "@smithy/core/protocols";
2
2
  import { NormalizedSchema } from "@smithy/core/schema";
3
3
  import { ProtocolLib } from "../ProtocolLib";
4
- import { JsonCodec } from "./codec-v1/JsonCodec";
4
+ import { JsonCodec2 } from "./codec-v2/JsonCodec2";
5
5
  import { loadRestJsonErrorCode } from "./parseJsonBody";
6
6
  export class AwsRestJsonProtocol extends HttpBindingProtocol {
7
7
  serializer;
8
8
  deserializer;
9
9
  codec;
10
10
  mixin = new ProtocolLib();
11
- constructor({ defaultNamespace, errorTypeRegistries, }) {
11
+ constructor({ defaultNamespace, errorTypeRegistries, jsonCodec, }) {
12
12
  super({
13
13
  defaultNamespace,
14
14
  errorTypeRegistries,
@@ -21,7 +21,7 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
21
21
  httpBindings: true,
22
22
  jsonName: true,
23
23
  };
24
- this.codec = new JsonCodec(settings);
24
+ this.codec = jsonCodec ?? new JsonCodec2(settings);
25
25
  this.serializer = new HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
26
26
  this.deserializer = new HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
27
27
  }
@@ -108,7 +108,7 @@ export class JsonShapeSerializer extends SerdeContextConfig {
108
108
  }
109
109
  return out;
110
110
  }
111
- if (value instanceof Uint8Array && (ns.isBlobSchema() || ns.isDocumentSchema())) {
111
+ if (value instanceof Uint8Array && ns.isBlobSchema()) {
112
112
  if (ns === this.rootSchema) {
113
113
  return value;
114
114
  }
@@ -148,7 +148,7 @@ export class JsonShapeSerializer extends SerdeContextConfig {
148
148
  }
149
149
  return value;
150
150
  }
151
- if (typeof value === "number" && ns.isNumericSchema()) {
151
+ if (typeof value === "number") {
152
152
  if (Math.abs(value) === Infinity || isNaN(value)) {
153
153
  return String(value);
154
154
  }
@@ -165,6 +165,9 @@ export class JsonShapeSerializer extends SerdeContextConfig {
165
165
  }
166
166
  if (ns.isDocumentSchema()) {
167
167
  if (isObject) {
168
+ if (value instanceof Uint8Array) {
169
+ return (this.serdeContext?.base64Encoder ?? toBase64)(value);
170
+ }
168
171
  const out = Array.isArray(value) ? [] : {};
169
172
  for (const k in value) {
170
173
  const v = value[k];
@@ -2,7 +2,6 @@ import { determineTimestampFormat } from "@smithy/core/protocols";
2
2
  import { NormalizedSchema } from "@smithy/core/schema";
3
3
  import { dateToUtcString, generateIdempotencyToken, LazyJsonString, NumericValue, toBase64 } from "@smithy/core/serde";
4
4
  import { SerdeContextConfig } from "../../ConfigurableSerdeContext";
5
- import { writeKey } from "../../writeKey";
6
5
  import { JsonBytesStringAdapter } from "./JsonBytesStringAdapter";
7
6
  const encoder = new TextEncoder();
8
7
  const OPEN_BRACE = 0x7b;
@@ -304,7 +303,7 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
304
303
  return;
305
304
  }
306
305
  if (typeof value === "number") {
307
- if (ns.isNumericSchema() && (Math.abs(value) === Infinity || isNaN(value))) {
306
+ if (Math.abs(value) === Infinity || Number.isNaN(value)) {
308
307
  this.writeAsciiQuoted(String(value));
309
308
  return;
310
309
  }
@@ -396,7 +395,33 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
396
395
  const valueSchema = ns.getValueSchema();
397
396
  if (!isDocument) {
398
397
  if (valueSchema.isStringSchema() || valueSchema.isNumericSchema() || valueSchema.isBooleanSchema()) {
399
- const json = sparse ? JSON.stringify(value) : JSON.stringify(value.filter((_) => _ != null));
398
+ let hasSpecials = false;
399
+ for (let i = 0; i < value.length; ++i) {
400
+ const v = value[i];
401
+ if (Number.isNaN(v) || v === Infinity || v === -Infinity || (v == null && !sparse)) {
402
+ hasSpecials = true;
403
+ break;
404
+ }
405
+ }
406
+ let json;
407
+ if (!hasSpecials) {
408
+ json = JSON.stringify(value);
409
+ }
410
+ else {
411
+ const out = [];
412
+ for (let i = 0; i < value.length; ++i) {
413
+ const v = value[i];
414
+ if (v == null && !sparse)
415
+ continue;
416
+ if (Number.isNaN(v) || v === Infinity || v === -Infinity) {
417
+ out.push(String(v));
418
+ }
419
+ else {
420
+ out.push(v);
421
+ }
422
+ }
423
+ json = JSON.stringify(out);
424
+ }
400
425
  this.ensure(json.length * 3);
401
426
  this.i += encoder.encodeInto(json, this.json.subarray(this.i)).written;
402
427
  return;
@@ -425,17 +450,22 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
425
450
  const valueSchema = ns.getValueSchema();
426
451
  if (!isDocument) {
427
452
  if (valueSchema.isStringSchema() || valueSchema.isNumericSchema() || valueSchema.isBooleanSchema()) {
428
- let input = value;
429
- if (sparse) {
430
- input = {};
431
- for (const k in value) {
432
- if (k === "__proto__") {
433
- writeKey(input);
434
- }
435
- input[k] = value[k] ?? null;
453
+ let modifications;
454
+ for (const k in value) {
455
+ const v = value[k];
456
+ if (Number.isNaN(v) || v === Infinity || v === -Infinity) {
457
+ (modifications ??= {})[k] = v;
458
+ value[k] = String(v);
436
459
  }
460
+ else if (v === null && !sparse) {
461
+ (modifications ??= {})[k] = null;
462
+ value[k] = undefined;
463
+ }
464
+ }
465
+ const json = JSON.stringify(value);
466
+ if (modifications) {
467
+ Object.assign(value, modifications);
437
468
  }
438
- const json = JSON.stringify(input);
439
469
  this.ensure(json.length * 3);
440
470
  this.i += encoder.encodeInto(json, this.json.subarray(this.i)).written;
441
471
  return;
@@ -4,25 +4,26 @@ export function jsonReviver(key, value, context) {
4
4
  const numericString = context.source;
5
5
  if (typeof value === "number") {
6
6
  const inSafeRange = value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER;
7
- if (!inSafeRange || numericString !== String(value)) {
8
- if (inSafeRange && /[eE]/.test(numericString) && String(Number(numericString)) === String(value)) {
7
+ if (inSafeRange) {
8
+ if (isRepresentable(numericString, value)) {
9
9
  return value;
10
10
  }
11
- if (isFractionalNumeric(numericString)) {
11
+ return new NumericValue(numericString, "bigDecimal");
12
+ }
13
+ else {
14
+ if (isFractionalBigNumeric(numericString)) {
12
15
  return new NumericValue(numericString, "bigDecimal");
13
16
  }
14
- else {
15
- if (/[eE]/.test(numericString)) {
16
- return BigInt(Number(numericString));
17
- }
18
- return BigInt(numericString);
17
+ if (/[eE]/.test(numericString)) {
18
+ return expandExponentToBigInt(numericString);
19
19
  }
20
+ return BigInt(numericString);
20
21
  }
21
22
  }
22
23
  }
23
24
  return value;
24
25
  }
25
- function isFractionalNumeric(s) {
26
+ function isFractionalBigNumeric(s) {
26
27
  const dotIndex = s.indexOf(".");
27
28
  if (dotIndex === -1) {
28
29
  return false;
@@ -35,3 +36,86 @@ function isFractionalNumeric(s) {
35
36
  const exp = parseInt(s.slice(eIndex + 1), 10);
36
37
  return exp < fracDigits;
37
38
  }
39
+ function isRepresentable(numericString, value) {
40
+ if (numericString === String(value)) {
41
+ return true;
42
+ }
43
+ if (Object.is(value, -0)) {
44
+ return true;
45
+ }
46
+ if (/[eE]/.test(numericString)) {
47
+ return expandToDecimal(numericString) === expandToDecimal(String(value));
48
+ }
49
+ const normalized = numericString.replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
50
+ const canonical = String(value);
51
+ if (normalized === canonical) {
52
+ return true;
53
+ }
54
+ if (/[eE]/.test(canonical)) {
55
+ return normalized === expandToDecimal(canonical);
56
+ }
57
+ return false;
58
+ }
59
+ function expandToDecimal(s) {
60
+ const negative = s.startsWith("-");
61
+ const abs = negative ? s.slice(1) : s;
62
+ const eIndex = abs.search(/[eE]/);
63
+ let result;
64
+ if (eIndex === -1) {
65
+ result = abs;
66
+ }
67
+ else {
68
+ const exp = parseInt(abs.slice(eIndex + 1), 10);
69
+ const mantissa = abs.slice(0, eIndex);
70
+ const dotIndex = mantissa.indexOf(".");
71
+ let digits;
72
+ let intLen;
73
+ if (dotIndex === -1) {
74
+ digits = mantissa;
75
+ intLen = mantissa.length;
76
+ }
77
+ else {
78
+ digits = mantissa.slice(0, dotIndex) + mantissa.slice(dotIndex + 1);
79
+ intLen = dotIndex;
80
+ }
81
+ digits = digits.replace(/0+$/, "") || "0";
82
+ const newDotPos = intLen + exp;
83
+ if (digits === "0") {
84
+ result = "0";
85
+ }
86
+ else if (newDotPos <= 0) {
87
+ result = "0." + "0".repeat(-newDotPos) + digits;
88
+ }
89
+ else if (newDotPos >= digits.length) {
90
+ result = digits + "0".repeat(newDotPos - digits.length);
91
+ }
92
+ else {
93
+ result = digits.slice(0, newDotPos) + "." + digits.slice(newDotPos);
94
+ }
95
+ }
96
+ if (result.includes(".")) {
97
+ result = result.replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
98
+ }
99
+ return (negative ? "-" : "") + result;
100
+ }
101
+ function expandExponentToBigInt(s) {
102
+ const eIndex = s.search(/[eE]/);
103
+ const exp = parseInt(s.slice(eIndex + 1), 10);
104
+ const negative = s.startsWith("-");
105
+ const mantissa = s.slice(negative ? 1 : 0, eIndex);
106
+ const dotIndex = mantissa.indexOf(".");
107
+ let digits;
108
+ let shift;
109
+ if (dotIndex === -1) {
110
+ digits = mantissa;
111
+ shift = exp;
112
+ }
113
+ else {
114
+ digits = mantissa.slice(0, dotIndex) + mantissa.slice(dotIndex + 1);
115
+ const fracDigits = mantissa.length - dotIndex - 1;
116
+ shift = exp - fracDigits;
117
+ }
118
+ digits = digits.replace(/0+$/, "") || "0";
119
+ const result = BigInt(digits) * 10n ** BigInt(shift + (mantissa.replace(".", "").length - digits.length));
120
+ return negative ? -result : result;
121
+ }
@@ -1,6 +1,7 @@
1
1
  import type { TypeRegistry } from "@smithy/core/schema";
2
2
  import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
3
3
  import type { JsonCodec } from "./codec-v1/JsonCodec";
4
+ import type { JsonCodec2 } from "./codec-v2/JsonCodec2";
4
5
  /**
5
6
  * @public
6
7
  * @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
@@ -11,7 +12,7 @@ export declare class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
11
12
  errorTypeRegistries?: TypeRegistry[];
12
13
  serviceTarget: string;
13
14
  awsQueryCompatible?: boolean;
14
- jsonCodec?: JsonCodec;
15
+ jsonCodec?: JsonCodec | JsonCodec2;
15
16
  });
16
17
  getShapeId(): string;
17
18
  protected getJsonRpcVersion(): "1.0";
@@ -1,6 +1,7 @@
1
1
  import type { TypeRegistry } from "@smithy/core/schema";
2
2
  import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
3
3
  import type { JsonCodec } from "./codec-v1/JsonCodec";
4
+ import type { JsonCodec2 } from "./codec-v2/JsonCodec2";
4
5
  /**
5
6
  * @public
6
7
  * @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
@@ -11,7 +12,7 @@ export declare class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
11
12
  errorTypeRegistries?: TypeRegistry[];
12
13
  serviceTarget: string;
13
14
  awsQueryCompatible?: boolean;
14
- jsonCodec?: JsonCodec;
15
+ jsonCodec?: JsonCodec | JsonCodec2;
15
16
  });
16
17
  getShapeId(): string;
17
18
  protected getJsonRpcVersion(): "1.1";
@@ -1,7 +1,8 @@
1
1
  import { RpcProtocol } from "@smithy/core/protocols";
2
2
  import type { TypeRegistry } from "@smithy/core/schema";
3
3
  import type { EndpointBearer, HandlerExecutionContext, HttpRequest, HttpResponse, OperationSchema, ResponseMetadata, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
4
- import { JsonCodec } from "./codec-v1/JsonCodec";
4
+ import type { JsonCodec } from "./codec-v1/JsonCodec";
5
+ import { JsonCodec2 } from "./codec-v2/JsonCodec2";
5
6
  /**
6
7
  * @public
7
8
  */
@@ -17,10 +18,10 @@ export declare abstract class AwsJsonRpcProtocol extends RpcProtocol {
17
18
  errorTypeRegistries?: TypeRegistry[];
18
19
  serviceTarget: string;
19
20
  awsQueryCompatible?: boolean;
20
- jsonCodec?: JsonCodec;
21
+ jsonCodec?: JsonCodec | JsonCodec2;
21
22
  });
22
23
  serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<HttpRequest>;
23
- getPayloadCodec(): JsonCodec;
24
+ getPayloadCodec(): JsonCodec | JsonCodec2;
24
25
  protected abstract getJsonRpcVersion(): "1.1" | "1.0";
25
26
  /**
26
27
  * @override
@@ -1,7 +1,8 @@
1
1
  import { HttpBindingProtocol } from "@smithy/core/protocols";
2
2
  import type { TypeRegistry } from "@smithy/core/schema";
3
3
  import type { EndpointBearer, HandlerExecutionContext, HttpRequest, HttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
4
- import { JsonCodec } from "./codec-v1/JsonCodec";
4
+ import type { JsonCodec } from "./codec-v1/JsonCodec";
5
+ import { JsonCodec2 } from "./codec-v2/JsonCodec2";
5
6
  /**
6
7
  * @public
7
8
  */
@@ -10,12 +11,13 @@ export declare class AwsRestJsonProtocol extends HttpBindingProtocol {
10
11
  protected deserializer: ShapeDeserializer<string | Uint8Array>;
11
12
  private readonly codec;
12
13
  private readonly mixin;
13
- constructor({ defaultNamespace, errorTypeRegistries, }: {
14
+ constructor({ defaultNamespace, errorTypeRegistries, jsonCodec, }: {
14
15
  defaultNamespace: string;
15
16
  errorTypeRegistries?: TypeRegistry[];
17
+ jsonCodec?: JsonCodec | JsonCodec2;
16
18
  });
17
19
  getShapeId(): string;
18
- getPayloadCodec(): JsonCodec;
20
+ getPayloadCodec(): JsonCodec | JsonCodec2;
19
21
  setSerdeContext(serdeContext: SerdeFunctions): void;
20
22
  /**
21
23
  * @override
@@ -1,6 +1,7 @@
1
1
  import { TypeRegistry } from "@smithy/core/schema";
2
2
  import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
3
3
  import { JsonCodec } from "./codec-v1/JsonCodec";
4
+ import { JsonCodec2 } from "./codec-v2/JsonCodec2";
4
5
  export declare class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
5
6
  constructor({
6
7
  defaultNamespace,
@@ -13,7 +14,7 @@ export declare class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
13
14
  errorTypeRegistries?: TypeRegistry[];
14
15
  serviceTarget: string;
15
16
  awsQueryCompatible?: boolean;
16
- jsonCodec?: JsonCodec;
17
+ jsonCodec?: JsonCodec | JsonCodec2;
17
18
  });
18
19
  getShapeId(): string;
19
20
  protected getJsonRpcVersion(): "1.0";
@@ -1,6 +1,7 @@
1
1
  import { TypeRegistry } from "@smithy/core/schema";
2
2
  import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
3
3
  import { JsonCodec } from "./codec-v1/JsonCodec";
4
+ import { JsonCodec2 } from "./codec-v2/JsonCodec2";
4
5
  export declare class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
5
6
  constructor({
6
7
  defaultNamespace,
@@ -13,7 +14,7 @@ export declare class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
13
14
  errorTypeRegistries?: TypeRegistry[];
14
15
  serviceTarget: string;
15
16
  awsQueryCompatible?: boolean;
16
- jsonCodec?: JsonCodec;
17
+ jsonCodec?: JsonCodec | JsonCodec2;
17
18
  });
18
19
  getShapeId(): string;
19
20
  protected getJsonRpcVersion(): "1.1";
@@ -12,6 +12,7 @@ import {
12
12
  ShapeSerializer,
13
13
  } from "@smithy/types";
14
14
  import { JsonCodec } from "./codec-v1/JsonCodec";
15
+ import { JsonCodec2 } from "./codec-v2/JsonCodec2";
15
16
  export declare abstract class AwsJsonRpcProtocol extends RpcProtocol {
16
17
  protected serializer: ShapeSerializer<string | Uint8Array>;
17
18
  protected deserializer: ShapeDeserializer<string | Uint8Array>;
@@ -30,14 +31,14 @@ export declare abstract class AwsJsonRpcProtocol extends RpcProtocol {
30
31
  errorTypeRegistries?: TypeRegistry[];
31
32
  serviceTarget: string;
32
33
  awsQueryCompatible?: boolean;
33
- jsonCodec?: JsonCodec;
34
+ jsonCodec?: JsonCodec | JsonCodec2;
34
35
  });
35
36
  serializeRequest<Input extends object>(
36
37
  operationSchema: OperationSchema,
37
38
  input: Input,
38
39
  context: HandlerExecutionContext & SerdeFunctions & EndpointBearer,
39
40
  ): Promise<HttpRequest>;
40
- getPayloadCodec(): JsonCodec;
41
+ getPayloadCodec(): JsonCodec | JsonCodec2;
41
42
  protected abstract getJsonRpcVersion(): "1.1" | "1.0";
42
43
  protected handleError(
43
44
  operationSchema: OperationSchema,
@@ -13,6 +13,7 @@ import {
13
13
  ShapeSerializer,
14
14
  } from "@smithy/types";
15
15
  import { JsonCodec } from "./codec-v1/JsonCodec";
16
+ import { JsonCodec2 } from "./codec-v2/JsonCodec2";
16
17
  export declare class AwsRestJsonProtocol extends HttpBindingProtocol {
17
18
  protected serializer: ShapeSerializer<string | Uint8Array>;
18
19
  protected deserializer: ShapeDeserializer<string | Uint8Array>;
@@ -21,12 +22,14 @@ export declare class AwsRestJsonProtocol extends HttpBindingProtocol {
21
22
  constructor({
22
23
  defaultNamespace,
23
24
  errorTypeRegistries,
25
+ jsonCodec,
24
26
  }: {
25
27
  defaultNamespace: string;
26
28
  errorTypeRegistries?: TypeRegistry[];
29
+ jsonCodec?: JsonCodec | JsonCodec2;
27
30
  });
28
31
  getShapeId(): string;
29
- getPayloadCodec(): JsonCodec;
32
+ getPayloadCodec(): JsonCodec | JsonCodec2;
30
33
  setSerdeContext(serdeContext: SerdeFunctions): void;
31
34
  serializeRequest<Input extends object>(
32
35
  operationSchema: OperationSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/core",
3
- "version": "3.977.4",
3
+ "version": "3.977.6",
4
4
  "description": "Core functions & classes shared by multiple AWS SDK clients.",
5
5
  "homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages-internal/core",
6
6
  "license": "Apache-2.0",