@aws-sdk/dynamodb-codec 3.972.28 → 3.973.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  var protocols = require('@aws-sdk/core/protocols');
4
4
  var schema = require('@smithy/core/schema');
5
- var smithyClient = require('@smithy/smithy-client');
6
5
  var utilBase64 = require('@smithy/util-base64');
7
6
 
8
7
  class DynamoDBJsonCodec extends protocols.JsonCodec {
@@ -33,7 +32,7 @@ class DynamoDBJsonShapeSerializer extends protocols.JsonShapeSerializer {
33
32
  if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
34
33
  if (value && typeof value === "object") {
35
34
  const av = value;
36
- const out = smithyClient._json(av);
35
+ const out = this.copyRemoveNulls(av);
37
36
  const base64Encode = this.serdeContext?.base64Encoder ?? utilBase64.toBase64;
38
37
  if (av.B instanceof Uint8Array) {
39
38
  out.B = base64Encode(av.B);
@@ -42,7 +41,13 @@ class DynamoDBJsonShapeSerializer extends protocols.JsonShapeSerializer {
42
41
  out.BS = av.BS.map(base64Encode);
43
42
  }
44
43
  if (Array.isArray(av.L)) {
45
- out.L = av.L.filter((v) => v != null).map((v) => this._write(ns, v, container));
44
+ const list = [];
45
+ for (const v of av.L) {
46
+ if (v != null) {
47
+ list.push(this._write(ns, v, container));
48
+ }
49
+ }
50
+ out.L = list;
46
51
  }
47
52
  if (av.M && typeof av.M === "object") {
48
53
  out.M = {};
@@ -57,6 +62,33 @@ class DynamoDBJsonShapeSerializer extends protocols.JsonShapeSerializer {
57
62
  }
58
63
  return super._write(ns, value, container);
59
64
  }
65
+ copyRemoveNulls(v) {
66
+ if (typeof v !== "object") {
67
+ return v;
68
+ }
69
+ if (v === null) {
70
+ return {};
71
+ }
72
+ if (Array.isArray(v)) {
73
+ const out = [];
74
+ for (const item of v) {
75
+ if (item != null) {
76
+ out.push(this.copyRemoveNulls(item));
77
+ }
78
+ }
79
+ return out;
80
+ }
81
+ const out = {};
82
+ for (const [k, _v] of Object.entries(v)) {
83
+ if (_v != null) {
84
+ if (["B", "BS", "L", "M"].includes(k)) {
85
+ continue;
86
+ }
87
+ out[k] = this.copyRemoveNulls(_v);
88
+ }
89
+ }
90
+ return out;
91
+ }
60
92
  }
61
93
  class DynamoDBJsonShapeDeserializer extends protocols.JsonShapeDeserializer {
62
94
  _read(schema$1, value) {
@@ -64,7 +96,7 @@ class DynamoDBJsonShapeDeserializer extends protocols.JsonShapeDeserializer {
64
96
  if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
65
97
  if (value && typeof value === "object") {
66
98
  const av = value;
67
- const out = smithyClient._json(av);
99
+ const out = av;
68
100
  const base64Decoder = this.serdeContext?.base64Decoder ?? utilBase64.fromBase64;
69
101
  if (typeof av.B === "string") {
70
102
  out.B = base64Decoder(av.B);
@@ -76,7 +108,6 @@ class DynamoDBJsonShapeDeserializer extends protocols.JsonShapeDeserializer {
76
108
  out.L = av.L.map((v) => this._read(ns, v));
77
109
  }
78
110
  if (av.M && typeof av.M === "object") {
79
- out.M = {};
80
111
  for (const [k, v] of Object.entries(av.M)) {
81
112
  out.M[k] = this._read(ns, v);
82
113
  }
@@ -1,6 +1,5 @@
1
1
  import { JsonCodec, JsonShapeDeserializer, JsonShapeSerializer } from "@aws-sdk/core/protocols";
2
2
  import { NormalizedSchema } from "@smithy/core/schema";
3
- import { _json } from "@smithy/smithy-client";
4
3
  import { fromBase64, toBase64 } from "@smithy/util-base64";
5
4
  export class DynamoDBJsonCodec extends JsonCodec {
6
5
  constructor() {
@@ -30,7 +29,7 @@ class DynamoDBJsonShapeSerializer extends JsonShapeSerializer {
30
29
  if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
31
30
  if (value && typeof value === "object") {
32
31
  const av = value;
33
- const out = _json(av);
32
+ const out = this.copyRemoveNulls(av);
34
33
  const base64Encode = this.serdeContext?.base64Encoder ?? toBase64;
35
34
  if (av.B instanceof Uint8Array) {
36
35
  out.B = base64Encode(av.B);
@@ -39,7 +38,13 @@ class DynamoDBJsonShapeSerializer extends JsonShapeSerializer {
39
38
  out.BS = av.BS.map(base64Encode);
40
39
  }
41
40
  if (Array.isArray(av.L)) {
42
- out.L = av.L.filter((v) => v != null).map((v) => this._write(ns, v, container));
41
+ const list = [];
42
+ for (const v of av.L) {
43
+ if (v != null) {
44
+ list.push(this._write(ns, v, container));
45
+ }
46
+ }
47
+ out.L = list;
43
48
  }
44
49
  if (av.M && typeof av.M === "object") {
45
50
  out.M = {};
@@ -54,6 +59,33 @@ class DynamoDBJsonShapeSerializer extends JsonShapeSerializer {
54
59
  }
55
60
  return super._write(ns, value, container);
56
61
  }
62
+ copyRemoveNulls(v) {
63
+ if (typeof v !== "object") {
64
+ return v;
65
+ }
66
+ if (v === null) {
67
+ return {};
68
+ }
69
+ if (Array.isArray(v)) {
70
+ const out = [];
71
+ for (const item of v) {
72
+ if (item != null) {
73
+ out.push(this.copyRemoveNulls(item));
74
+ }
75
+ }
76
+ return out;
77
+ }
78
+ const out = {};
79
+ for (const [k, _v] of Object.entries(v)) {
80
+ if (_v != null) {
81
+ if (["B", "BS", "L", "M"].includes(k)) {
82
+ continue;
83
+ }
84
+ out[k] = this.copyRemoveNulls(_v);
85
+ }
86
+ }
87
+ return out;
88
+ }
57
89
  }
58
90
  class DynamoDBJsonShapeDeserializer extends JsonShapeDeserializer {
59
91
  _read(schema, value) {
@@ -61,7 +93,7 @@ class DynamoDBJsonShapeDeserializer extends JsonShapeDeserializer {
61
93
  if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
62
94
  if (value && typeof value === "object") {
63
95
  const av = value;
64
- const out = _json(av);
96
+ const out = av;
65
97
  const base64Decoder = this.serdeContext?.base64Decoder ?? fromBase64;
66
98
  if (typeof av.B === "string") {
67
99
  out.B = base64Decoder(av.B);
@@ -73,7 +105,6 @@ class DynamoDBJsonShapeDeserializer extends JsonShapeDeserializer {
73
105
  out.L = av.L.map((v) => this._read(ns, v));
74
106
  }
75
107
  if (av.M && typeof av.M === "object") {
76
- out.M = {};
77
108
  for (const [k, v] of Object.entries(av.M)) {
78
109
  out.M[k] = this._read(ns, v);
79
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/dynamodb-codec",
3
- "version": "3.972.28",
3
+ "version": "3.973.1",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
6
6
  "build:cjs": "node ../../scripts/compilation/inline dynamodb-codec",
@@ -22,10 +22,9 @@
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@aws-sdk/core": "^3.973.27",
26
- "@smithy/core": "^3.23.14",
27
- "@smithy/smithy-client": "^4.12.9",
28
- "@smithy/types": "^4.14.0",
25
+ "@aws-sdk/core": "^3.974.1",
26
+ "@smithy/core": "^3.23.15",
27
+ "@smithy/types": "^4.14.1",
29
28
  "@smithy/util-base64": "^4.3.2",
30
29
  "tslib": "^2.6.2"
31
30
  },