@aws-sdk/lib-dynamodb 3.438.0 → 3.441.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 +105 -26
- package/dist-cjs/index.js +3 -0
- package/dist-es/index.js +1 -0
- package/dist-types/index.d.ts +1 -0
- package/dist-types/ts3.4/index.d.ts +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -20,18 +20,18 @@ Responses from DynamoDB are unmarshalled into plain JavaScript objects
|
|
|
20
20
|
by the `DocumentClient`. The `DocumentClient` does not accept
|
|
21
21
|
`AttributeValue`s in favor of native JavaScript types.
|
|
22
22
|
|
|
23
|
-
| JavaScript Type
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
| Boolean
|
|
28
|
-
|
|
|
29
|
-
| Array
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
| Set\<String\>
|
|
34
|
-
| Uint8Array, Buffer, File, Blob...
|
|
23
|
+
| JavaScript Type | DynamoDB AttributeValue |
|
|
24
|
+
| :--------------------------------: | ----------------------- |
|
|
25
|
+
| String | S |
|
|
26
|
+
| Number / BigInt / NumberValue | N |
|
|
27
|
+
| Boolean | BOOL |
|
|
28
|
+
| null | NULL |
|
|
29
|
+
| Array | L |
|
|
30
|
+
| Object | M |
|
|
31
|
+
| Set\<Uint8Array, Blob, ...\> | BS |
|
|
32
|
+
| Set\<Number, BigInt, NumberValue\> | NS |
|
|
33
|
+
| Set\<String\> | SS |
|
|
34
|
+
| Uint8Array, Buffer, File, Blob... | B |
|
|
35
35
|
|
|
36
36
|
### Example
|
|
37
37
|
|
|
@@ -98,20 +98,48 @@ const ddbDocClient = DynamoDBDocument.from(client); // client is DynamoDB client
|
|
|
98
98
|
The configuration for marshalling and unmarshalling can be sent as an optional
|
|
99
99
|
second parameter during creation of document client as follows:
|
|
100
100
|
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
```ts
|
|
102
|
+
export interface marshallOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Whether to automatically convert empty strings, blobs, and sets to `null`
|
|
105
|
+
*/
|
|
106
|
+
convertEmptyValues?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Whether to remove undefined values while marshalling.
|
|
109
|
+
*/
|
|
110
|
+
removeUndefinedValues?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Whether to convert typeof object to map attribute.
|
|
113
|
+
*/
|
|
114
|
+
convertClassInstanceToMap?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Whether to convert the top level container
|
|
117
|
+
* if it is a map or list.
|
|
118
|
+
*
|
|
119
|
+
* Default is true when using the DynamoDBDocumentClient,
|
|
120
|
+
* but false if directly using the marshall function (backwards compatibility).
|
|
121
|
+
*/
|
|
122
|
+
convertTopLevelContainer?: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface unmarshallOptions {
|
|
126
|
+
/**
|
|
127
|
+
* Whether to return numbers as a string instead of converting them to native JavaScript numbers.
|
|
128
|
+
* This allows for the safe round-trip transport of numbers of arbitrary size.
|
|
129
|
+
*/
|
|
130
|
+
wrapNumbers?: boolean;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* When true, skip wrapping the data in `{ M: data }` before converting.
|
|
134
|
+
*
|
|
135
|
+
* Default is true when using the DynamoDBDocumentClient,
|
|
136
|
+
* but false if directly using the unmarshall function (backwards compatibility).
|
|
137
|
+
*/
|
|
138
|
+
convertWithoutMapWrapper?: boolean;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const marshallOptions: marshallOptions = {};
|
|
142
|
+
const unmarshallOptions: unmarshallOptions = {};
|
|
115
143
|
|
|
116
144
|
const translateConfig = { marshallOptions, unmarshallOptions };
|
|
117
145
|
|
|
@@ -160,6 +188,57 @@ await ddbDocClient.put({
|
|
|
160
188
|
});
|
|
161
189
|
```
|
|
162
190
|
|
|
191
|
+
### Large Numbers and `NumberValue`.
|
|
192
|
+
|
|
193
|
+
On the input or marshalling side, the class `NumberValue` can be used
|
|
194
|
+
anywhere to represent a DynamoDB number value, even small numbers.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { DynamoDB } from "@aws-sdk/client-dynamodb";
|
|
198
|
+
import { NumberValue, DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
|
|
199
|
+
|
|
200
|
+
// Note, the client will not validate the acceptability of the number
|
|
201
|
+
// in terms of size or format.
|
|
202
|
+
// It is only here to preserve your precise representation.
|
|
203
|
+
const client = DynamoDBDocument.from(new DynamoDB({}));
|
|
204
|
+
|
|
205
|
+
await client.put({
|
|
206
|
+
Item: {
|
|
207
|
+
id: 1,
|
|
208
|
+
smallNumber: NumberValue.from("123"),
|
|
209
|
+
bigNumber: NumberValue.from("1000000000000000000000.000000000001"),
|
|
210
|
+
nSet: new Set([123, NumberValue.from("456"), 789]),
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
On the output or unmarshalling side, the class `NumberValue` is used
|
|
216
|
+
depending on your setting for the `unmarshallOptions` flag `wrapnumbers`,
|
|
217
|
+
shown above.
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import { DynamoDB } from "@aws-sdk/client-dynamodb";
|
|
221
|
+
import { NumberValue, DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
|
|
222
|
+
|
|
223
|
+
const client = DynamoDBDocument.from(new DynamoDB({}));
|
|
224
|
+
|
|
225
|
+
const response = await client.get({
|
|
226
|
+
Key: {
|
|
227
|
+
id: 1,
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Numbers in the response may be a number, a BigInt, or a NumberValue depending
|
|
233
|
+
* on how you set `wrapNumbers`.
|
|
234
|
+
*/
|
|
235
|
+
const value = response.Item.bigNumber;
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
`NumberValue` does not provide a way to do mathematical operations on itself.
|
|
239
|
+
To do mathematical operations, take the string value of `NumberValue` by calling
|
|
240
|
+
`.toString()` and supply it to your chosen big number implementation.
|
|
241
|
+
|
|
163
242
|
### Client and Command middleware stacks
|
|
164
243
|
|
|
165
244
|
As with other AWS SDK for JavaScript v3 clients, you can apply middleware functions
|
package/dist-cjs/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberValue = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
tslib_1.__exportStar(require("./DynamoDBDocument"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./DynamoDBDocumentClient"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./commands"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./pagination"), exports);
|
|
9
|
+
var util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
|
|
10
|
+
Object.defineProperty(exports, "NumberValue", { enumerable: true, get: function () { return util_dynamodb_1.NumberValueImpl; } });
|
package/dist-es/index.js
CHANGED
package/dist-types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/lib-dynamodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.441.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",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@aws-sdk/util-dynamodb": "3.
|
|
29
|
+
"@aws-sdk/util-dynamodb": "3.441.0",
|
|
30
30
|
"tslib": "^2.5.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@aws-sdk/client-dynamodb": "^3.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
36
|
+
"@aws-sdk/client-dynamodb": "3.441.0",
|
|
37
37
|
"@smithy/smithy-client": "^2.1.12",
|
|
38
38
|
"@smithy/types": "^2.4.0",
|
|
39
39
|
"@tsconfig/recommended": "1.0.1",
|