@aws-sdk/dynamodb-codec 3.973.37 → 3.973.39

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
@@ -1,4 +1,4 @@
1
- const { JsonCodec, JsonShapeSerializer, JsonShapeDeserializer } = require("@aws-sdk/core/protocols");
1
+ const { JsonCodec, JsonShapeSerializer, JsonShapeDeserializer, JsonCodec2, JsonShapeSerializer2, JsonShapeDeserializer2 } = require("@aws-sdk/core/protocols");
2
2
  const { NormalizedSchema } = require("@smithy/core/schema");
3
3
  const { toBase64, fromBase64 } = require("@smithy/core/serde");
4
4
 
@@ -23,11 +23,11 @@ class DynamoDBJsonCodec extends JsonCodec {
23
23
  return deserializer;
24
24
  }
25
25
  }
26
- const ATTRIBUTE_VALUE = "com.amazonaws.dynamodb#AttributeValue";
26
+ const ATTRIBUTE_VALUE$1 = "com.amazonaws.dynamodb#AttributeValue";
27
27
  class DynamoDBJsonShapeSerializer extends JsonShapeSerializer {
28
28
  _write(schema, value, container) {
29
29
  const ns = NormalizedSchema.of(schema);
30
- if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
30
+ if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE$1) {
31
31
  if (value && typeof value === "object") {
32
32
  const av = value;
33
33
  const out = this.copyRemoveNulls(av);
@@ -91,7 +91,7 @@ class DynamoDBJsonShapeSerializer extends JsonShapeSerializer {
91
91
  class DynamoDBJsonShapeDeserializer extends JsonShapeDeserializer {
92
92
  _read(schema, value) {
93
93
  const ns = NormalizedSchema.of(schema);
94
- if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
94
+ if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE$1) {
95
95
  if (value && typeof value === "object") {
96
96
  const av = value;
97
97
  const out = av;
@@ -117,4 +117,177 @@ class DynamoDBJsonShapeDeserializer extends JsonShapeDeserializer {
117
117
  }
118
118
  }
119
119
 
120
+ const ATTRIBUTE_VALUE = "com.amazonaws.dynamodb#AttributeValue";
121
+ class DynamoDBJsonShapeSerializer2 extends JsonShapeSerializer2 {
122
+ writeValue(schema, value, container) {
123
+ if (value != null && typeof value === "object") {
124
+ const ns = NormalizedSchema.of(schema);
125
+ if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
126
+ this.writeAttributeValue(value);
127
+ return;
128
+ }
129
+ }
130
+ super.writeValue(schema, value, container);
131
+ }
132
+ writeAttributeValue(av) {
133
+ const base64Encode = this.serdeContext?.base64Encoder ?? toBase64;
134
+ this.writeAscii("{");
135
+ let first = true;
136
+ for (const key in av) {
137
+ const val = av[key];
138
+ if (val == null)
139
+ continue;
140
+ if (!first) {
141
+ this.writeAscii(",");
142
+ }
143
+ first = false;
144
+ this.writeAsciiQuoted(key);
145
+ this.writeAscii(":");
146
+ switch (key) {
147
+ case "B":
148
+ if (val instanceof Uint8Array) {
149
+ this.writeBase64(val);
150
+ }
151
+ else {
152
+ this.writeJsonString(val);
153
+ }
154
+ break;
155
+ case "BS":
156
+ this.writeAscii("[");
157
+ {
158
+ const arr = val;
159
+ for (let i = 0; i < arr.length; i++) {
160
+ if (i > 0)
161
+ this.writeAscii(",");
162
+ const item = arr[i];
163
+ if (item instanceof Uint8Array) {
164
+ this.writeBase64(item);
165
+ }
166
+ else {
167
+ this.writeJsonString(base64Encode(item));
168
+ }
169
+ }
170
+ }
171
+ this.writeAscii("]");
172
+ break;
173
+ case "L":
174
+ this.writeAscii("[");
175
+ {
176
+ const arr = val;
177
+ for (let i = 0; i < arr.length; i++) {
178
+ if (i > 0)
179
+ this.writeAscii(",");
180
+ if (arr[i] != null) {
181
+ this.writeAttributeValue(arr[i]);
182
+ }
183
+ else {
184
+ this.writeAscii("null");
185
+ }
186
+ }
187
+ }
188
+ this.writeAscii("]");
189
+ break;
190
+ case "M":
191
+ this.writeAscii("{");
192
+ {
193
+ const map = val;
194
+ let mapFirst = true;
195
+ for (const k in map) {
196
+ if (map[k] == null)
197
+ continue;
198
+ if (!mapFirst)
199
+ this.writeAscii(",");
200
+ mapFirst = false;
201
+ this.writeJsonString(k);
202
+ this.writeAscii(":");
203
+ this.writeAttributeValue(map[k]);
204
+ }
205
+ }
206
+ this.writeAscii("}");
207
+ break;
208
+ case "SS":
209
+ case "NS":
210
+ this.writeAscii("[");
211
+ {
212
+ const arr = val;
213
+ for (let i = 0; i < arr.length; i++) {
214
+ if (i > 0)
215
+ this.writeAscii(",");
216
+ this.writeJsonString(arr[i]);
217
+ }
218
+ }
219
+ this.writeAscii("]");
220
+ break;
221
+ case "S":
222
+ case "N":
223
+ this.writeJsonString(val);
224
+ break;
225
+ case "BOOL":
226
+ this.writeAscii(val ? "true" : "false");
227
+ break;
228
+ case "NULL":
229
+ this.writeAscii(val ? "true" : "false");
230
+ break;
231
+ default:
232
+ this.writeAscii(JSON.stringify(val));
233
+ break;
234
+ }
235
+ }
236
+ this.writeAscii("}");
237
+ }
238
+ }
239
+ class DynamoDBJsonShapeDeserializer2 extends JsonShapeDeserializer2 {
240
+ _read(schema, value) {
241
+ const ns = NormalizedSchema.of(schema);
242
+ if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
243
+ if (value && typeof value === "object") {
244
+ return this.readAttributeValue(value);
245
+ }
246
+ }
247
+ return super._read(ns, value);
248
+ }
249
+ readAttributeValue(av) {
250
+ const base64Decode = this.serdeContext?.base64Decoder ?? fromBase64;
251
+ const out = av;
252
+ if (typeof av.B === "string") {
253
+ out.B = base64Decode(av.B);
254
+ }
255
+ if (Array.isArray(av.BS)) {
256
+ out.BS = av.BS.map(base64Decode);
257
+ }
258
+ if (Array.isArray(av.L)) {
259
+ out.L = av.L.map((v) => this.readAttributeValue(v));
260
+ }
261
+ if (av.M && typeof av.M === "object") {
262
+ const m = av.M;
263
+ for (const k in m) {
264
+ m[k] = this.readAttributeValue(m[k]);
265
+ }
266
+ }
267
+ return out;
268
+ }
269
+ }
270
+ class DynamoDBJsonCodec2 extends JsonCodec2 {
271
+ constructor() {
272
+ super({
273
+ timestampFormat: {
274
+ useTrait: true,
275
+ default: 7,
276
+ },
277
+ jsonName: false,
278
+ });
279
+ }
280
+ createSerializer() {
281
+ const serializer = new DynamoDBJsonShapeSerializer2(this.settings);
282
+ serializer.setSerdeContext(this.serdeContext);
283
+ return serializer;
284
+ }
285
+ createDeserializer() {
286
+ const deserializer = new DynamoDBJsonShapeDeserializer2(this.settings);
287
+ deserializer.setSerdeContext(this.serdeContext);
288
+ return deserializer;
289
+ }
290
+ }
291
+
120
292
  exports.DynamoDBJsonCodec = DynamoDBJsonCodec;
293
+ exports.DynamoDBJsonCodec2 = DynamoDBJsonCodec2;
@@ -0,0 +1,174 @@
1
+ import { JsonCodec2, JsonShapeDeserializer2, JsonShapeSerializer2 } from "@aws-sdk/core/protocols";
2
+ import { NormalizedSchema } from "@smithy/core/schema";
3
+ import { fromBase64, toBase64 } from "@smithy/core/serde";
4
+ const ATTRIBUTE_VALUE = "com.amazonaws.dynamodb#AttributeValue";
5
+ class DynamoDBJsonShapeSerializer2 extends JsonShapeSerializer2 {
6
+ writeValue(schema, value, container) {
7
+ if (value != null && typeof value === "object") {
8
+ const ns = NormalizedSchema.of(schema);
9
+ if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
10
+ this.writeAttributeValue(value);
11
+ return;
12
+ }
13
+ }
14
+ super.writeValue(schema, value, container);
15
+ }
16
+ writeAttributeValue(av) {
17
+ const base64Encode = this.serdeContext?.base64Encoder ?? toBase64;
18
+ this.writeAscii("{");
19
+ let first = true;
20
+ for (const key in av) {
21
+ const val = av[key];
22
+ if (val == null)
23
+ continue;
24
+ if (!first) {
25
+ this.writeAscii(",");
26
+ }
27
+ first = false;
28
+ this.writeAsciiQuoted(key);
29
+ this.writeAscii(":");
30
+ switch (key) {
31
+ case "B":
32
+ if (val instanceof Uint8Array) {
33
+ this.writeBase64(val);
34
+ }
35
+ else {
36
+ this.writeJsonString(val);
37
+ }
38
+ break;
39
+ case "BS":
40
+ this.writeAscii("[");
41
+ {
42
+ const arr = val;
43
+ for (let i = 0; i < arr.length; i++) {
44
+ if (i > 0)
45
+ this.writeAscii(",");
46
+ const item = arr[i];
47
+ if (item instanceof Uint8Array) {
48
+ this.writeBase64(item);
49
+ }
50
+ else {
51
+ this.writeJsonString(base64Encode(item));
52
+ }
53
+ }
54
+ }
55
+ this.writeAscii("]");
56
+ break;
57
+ case "L":
58
+ this.writeAscii("[");
59
+ {
60
+ const arr = val;
61
+ for (let i = 0; i < arr.length; i++) {
62
+ if (i > 0)
63
+ this.writeAscii(",");
64
+ if (arr[i] != null) {
65
+ this.writeAttributeValue(arr[i]);
66
+ }
67
+ else {
68
+ this.writeAscii("null");
69
+ }
70
+ }
71
+ }
72
+ this.writeAscii("]");
73
+ break;
74
+ case "M":
75
+ this.writeAscii("{");
76
+ {
77
+ const map = val;
78
+ let mapFirst = true;
79
+ for (const k in map) {
80
+ if (map[k] == null)
81
+ continue;
82
+ if (!mapFirst)
83
+ this.writeAscii(",");
84
+ mapFirst = false;
85
+ this.writeJsonString(k);
86
+ this.writeAscii(":");
87
+ this.writeAttributeValue(map[k]);
88
+ }
89
+ }
90
+ this.writeAscii("}");
91
+ break;
92
+ case "SS":
93
+ case "NS":
94
+ this.writeAscii("[");
95
+ {
96
+ const arr = val;
97
+ for (let i = 0; i < arr.length; i++) {
98
+ if (i > 0)
99
+ this.writeAscii(",");
100
+ this.writeJsonString(arr[i]);
101
+ }
102
+ }
103
+ this.writeAscii("]");
104
+ break;
105
+ case "S":
106
+ case "N":
107
+ this.writeJsonString(val);
108
+ break;
109
+ case "BOOL":
110
+ this.writeAscii(val ? "true" : "false");
111
+ break;
112
+ case "NULL":
113
+ this.writeAscii(val ? "true" : "false");
114
+ break;
115
+ default:
116
+ this.writeAscii(JSON.stringify(val));
117
+ break;
118
+ }
119
+ }
120
+ this.writeAscii("}");
121
+ }
122
+ }
123
+ class DynamoDBJsonShapeDeserializer2 extends JsonShapeDeserializer2 {
124
+ _read(schema, value) {
125
+ const ns = NormalizedSchema.of(schema);
126
+ if (ns.isStructSchema() && ns.getName(true) === ATTRIBUTE_VALUE) {
127
+ if (value && typeof value === "object") {
128
+ return this.readAttributeValue(value);
129
+ }
130
+ }
131
+ return super._read(ns, value);
132
+ }
133
+ readAttributeValue(av) {
134
+ const base64Decode = this.serdeContext?.base64Decoder ?? fromBase64;
135
+ const out = av;
136
+ if (typeof av.B === "string") {
137
+ out.B = base64Decode(av.B);
138
+ }
139
+ if (Array.isArray(av.BS)) {
140
+ out.BS = av.BS.map(base64Decode);
141
+ }
142
+ if (Array.isArray(av.L)) {
143
+ out.L = av.L.map((v) => this.readAttributeValue(v));
144
+ }
145
+ if (av.M && typeof av.M === "object") {
146
+ const m = av.M;
147
+ for (const k in m) {
148
+ m[k] = this.readAttributeValue(m[k]);
149
+ }
150
+ }
151
+ return out;
152
+ }
153
+ }
154
+ export class DynamoDBJsonCodec2 extends JsonCodec2 {
155
+ constructor() {
156
+ super({
157
+ timestampFormat: {
158
+ useTrait: true,
159
+ default: 7,
160
+ },
161
+ jsonName: false,
162
+ });
163
+ }
164
+ createSerializer() {
165
+ const serializer = new DynamoDBJsonShapeSerializer2(this.settings);
166
+ serializer.setSerdeContext(this.serdeContext);
167
+ return serializer;
168
+ }
169
+ createDeserializer() {
170
+ const deserializer = new DynamoDBJsonShapeDeserializer2(this.settings);
171
+ deserializer.setSerdeContext(this.serdeContext);
172
+ return deserializer;
173
+ }
174
+ }
package/dist-es/index.js CHANGED
@@ -1 +1,2 @@
1
- export { DynamoDBJsonCodec } from "./codec/DynamoDBJsonCodec";
1
+ export { DynamoDBJsonCodec } from "./codec-v1/DynamoDBJsonCodec";
2
+ export { DynamoDBJsonCodec2 } from "./codec-v2/DynamoDBJsonCodec2";
@@ -4,6 +4,7 @@ import { JsonCodec, JsonShapeDeserializer, JsonShapeSerializer } from "@aws-sdk/
4
4
  * for use with Amazon DynamoDB in JSON RPC mode.
5
5
  *
6
6
  * @internal
7
+ * @deprecated use CodecV2
7
8
  */
8
9
  export declare class DynamoDBJsonCodec extends JsonCodec {
9
10
  constructor();
@@ -0,0 +1,13 @@
1
+ import { JsonCodec2 } from "@aws-sdk/core/protocols";
2
+ import type { $ShapeDeserializer, $ShapeSerializer } from "@smithy/types";
3
+ /**
4
+ * A throughput optimized version of the AWS JSON Codec
5
+ * for use with Amazon DynamoDB in JSON RPC mode.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class DynamoDBJsonCodec2 extends JsonCodec2 {
10
+ constructor();
11
+ createSerializer(): $ShapeSerializer<Uint8Array>;
12
+ createDeserializer(): $ShapeDeserializer<string>;
13
+ }
@@ -1 +1,2 @@
1
- export { DynamoDBJsonCodec } from "./codec/DynamoDBJsonCodec";
1
+ export { DynamoDBJsonCodec } from "./codec-v1/DynamoDBJsonCodec";
2
+ export { DynamoDBJsonCodec2 } from "./codec-v2/DynamoDBJsonCodec2";
@@ -0,0 +1,7 @@
1
+ import { JsonCodec2 } from "@aws-sdk/core/protocols";
2
+ import { $ShapeDeserializer, $ShapeSerializer } from "@smithy/types";
3
+ export declare class DynamoDBJsonCodec2 extends JsonCodec2 {
4
+ constructor();
5
+ createSerializer(): $ShapeSerializer<Uint8Array>;
6
+ createDeserializer(): $ShapeDeserializer<string>;
7
+ }
@@ -1 +1,2 @@
1
- export { DynamoDBJsonCodec } from "./codec/DynamoDBJsonCodec";
1
+ export { DynamoDBJsonCodec } from "./codec-v1/DynamoDBJsonCodec";
2
+ export { DynamoDBJsonCodec2 } from "./codec-v2/DynamoDBJsonCodec2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/dynamodb-codec",
3
- "version": "3.973.37",
3
+ "version": "3.973.39",
4
4
  "homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages-internal/dynamodb-codec",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -38,8 +38,8 @@
38
38
  "test:watch": "yarn g:vitest watch"
39
39
  },
40
40
  "dependencies": {
41
- "@aws-sdk/core": "^3.977.2",
42
- "@smithy/core": "^3.29.8",
41
+ "@aws-sdk/core": "^3.977.4",
42
+ "@smithy/core": "^3.31.1",
43
43
  "@smithy/types": "^4.16.1",
44
44
  "tslib": "^2.6.2"
45
45
  },