@aws-sdk/lib-dynamodb 3.686.0 → 3.689.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.
- package/README.md +63 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -120,15 +120,26 @@ export interface marshallOptions {
|
|
|
120
120
|
* but false if directly using the marshall function (backwards compatibility).
|
|
121
121
|
*/
|
|
122
122
|
convertTopLevelContainer?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Whether to allow numbers beyond Number.MAX_SAFE_INTEGER during marshalling.
|
|
125
|
+
* When set to true, allows numbers that may lose precision when converted to JavaScript numbers.
|
|
126
|
+
* When false (default), throws an error if a number exceeds Number.MAX_SAFE_INTEGER to prevent
|
|
127
|
+
* unintended loss of precision. Consider using the NumberValue type from @aws-sdk/lib-dynamodb
|
|
128
|
+
* for precise handling of large numbers.
|
|
129
|
+
*/
|
|
130
|
+
allowImpreciseNumbers?: boolean;
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
export interface unmarshallOptions {
|
|
126
134
|
/**
|
|
127
|
-
* Whether to
|
|
135
|
+
* Whether to modify how numbers are unmarshalled from DynamoDB.
|
|
136
|
+
* When set to true, returns numbers as NumberValue instances instead of native JavaScript numbers.
|
|
128
137
|
* This allows for the safe round-trip transport of numbers of arbitrary size.
|
|
138
|
+
*
|
|
139
|
+
* If a function is provided, it will be called with the string representation of numbers to handle
|
|
140
|
+
* custom conversions (e.g., using BigInt or decimal libraries).
|
|
129
141
|
*/
|
|
130
|
-
wrapNumbers?: boolean;
|
|
131
|
-
|
|
142
|
+
wrapNumbers?: boolean | ((value: string) => number | bigint | NumberValue | any);
|
|
132
143
|
/**
|
|
133
144
|
* When true, skip wrapping the data in `{ M: data }` before converting.
|
|
134
145
|
*
|
|
@@ -235,10 +246,59 @@ const response = await client.get({
|
|
|
235
246
|
const value = response.Item.bigNumber;
|
|
236
247
|
```
|
|
237
248
|
|
|
249
|
+
You can also provide a custom function to handle number conversion during unmarshalling:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
const client = DynamoDBDocument.from(new DynamoDB({}), {
|
|
253
|
+
unmarshallOptions: {
|
|
254
|
+
// Use BigInt for all numbers
|
|
255
|
+
wrapNumbers: (str) => BigInt(str),
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const response = await client.get({
|
|
260
|
+
Key: { id: 1 },
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Numbers in response will be BigInt instead of NumberValue or regular numbers
|
|
264
|
+
```
|
|
265
|
+
|
|
238
266
|
`NumberValue` does not provide a way to do mathematical operations on itself.
|
|
239
267
|
To do mathematical operations, take the string value of `NumberValue` by calling
|
|
240
268
|
`.toString()` and supply it to your chosen big number implementation.
|
|
241
269
|
|
|
270
|
+
The client protects against precision loss by throwing an error on large numbers, but you can either
|
|
271
|
+
allow imprecise values with `allowImpreciseNumbers` or maintain exact precision using `NumberValue`.
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
const preciseValue = "34567890123456789012345678901234567890";
|
|
275
|
+
|
|
276
|
+
// 1. Default behavior - will throw error
|
|
277
|
+
await client.send(
|
|
278
|
+
new PutCommand({
|
|
279
|
+
TableName: "Table",
|
|
280
|
+
Item: {
|
|
281
|
+
id: "1",
|
|
282
|
+
number: Number(preciseValue), // Throws error: Number is greater than Number.MAX_SAFE_INTEGER
|
|
283
|
+
},
|
|
284
|
+
})
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
// 2. Using allowImpreciseNumbers - will store but loses precision (mimics the v2 implicit behavior)
|
|
288
|
+
const impreciseClient = DynamoDBDocumentClient.from(new DynamoDBClient({}), {
|
|
289
|
+
marshallOptions: { allowImpreciseNumbers: true },
|
|
290
|
+
});
|
|
291
|
+
await impreciseClient.send(
|
|
292
|
+
new PutCommand({
|
|
293
|
+
TableName: "Table",
|
|
294
|
+
Item: {
|
|
295
|
+
id: "2",
|
|
296
|
+
number: Number(preciseValue), // Loses precision 34567890123456790000000000000000000000n
|
|
297
|
+
},
|
|
298
|
+
})
|
|
299
|
+
);
|
|
300
|
+
```
|
|
301
|
+
|
|
242
302
|
### Client and Command middleware stacks
|
|
243
303
|
|
|
244
304
|
As with other AWS SDK for JavaScript v3 clients, you can apply middleware functions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/lib-dynamodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.689.0",
|
|
4
4
|
"description": "The document client simplifies working with items in Amazon DynamoDB by abstracting away the notion of attribute values.",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"license": "Apache-2.0",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@aws-sdk/core": "3.686.0",
|
|
32
|
-
"@aws-sdk/util-dynamodb": "3.
|
|
32
|
+
"@aws-sdk/util-dynamodb": "3.689.0",
|
|
33
33
|
"@smithy/core": "^2.5.1",
|
|
34
34
|
"@smithy/smithy-client": "^3.4.2",
|
|
35
35
|
"@smithy/types": "^3.6.0",
|
|
36
36
|
"tslib": "^2.6.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
39
|
+
"@aws-sdk/client-dynamodb": "^3.687.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
42
|
+
"@aws-sdk/client-dynamodb": "3.687.0",
|
|
43
43
|
"@tsconfig/recommended": "1.0.1",
|
|
44
44
|
"@types/node": "^16.18.96",
|
|
45
45
|
"concurrently": "7.0.0",
|