@aws-sdk/util-dynamodb 3.902.0 → 3.906.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/dist-cjs/index.js +296 -337
- package/package.json +3 -3
package/dist-cjs/index.js
CHANGED
|
@@ -1,350 +1,309 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class NumberValue {
|
|
4
|
+
value;
|
|
5
|
+
constructor(value) {
|
|
6
|
+
if (typeof value === "object" && "N" in value) {
|
|
7
|
+
this.value = String(value.N);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
this.value = String(value);
|
|
11
|
+
}
|
|
12
|
+
const valueOf = typeof value.valueOf() === "number" ? value.valueOf() : 0;
|
|
13
|
+
const imprecise = valueOf > Number.MAX_SAFE_INTEGER ||
|
|
14
|
+
valueOf < Number.MIN_SAFE_INTEGER ||
|
|
15
|
+
Math.abs(valueOf) === Infinity ||
|
|
16
|
+
Number.isNaN(valueOf);
|
|
17
|
+
if (imprecise) {
|
|
18
|
+
throw new Error(`NumberValue should not be initialized with an imprecise number=${valueOf}. Use a string instead.`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
static from(value) {
|
|
22
|
+
return new NumberValue(value);
|
|
23
|
+
}
|
|
24
|
+
toAttributeValue() {
|
|
25
|
+
return {
|
|
26
|
+
N: this.toString(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
toBigInt() {
|
|
30
|
+
const stringValue = this.toString();
|
|
31
|
+
return BigInt(stringValue);
|
|
32
|
+
}
|
|
33
|
+
toString() {
|
|
34
|
+
return String(this.value);
|
|
35
|
+
}
|
|
36
|
+
valueOf() {
|
|
37
|
+
return this.toString();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const convertToAttr = (data, options) => {
|
|
42
|
+
if (data === undefined) {
|
|
43
|
+
throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`);
|
|
44
|
+
}
|
|
45
|
+
else if (data === null && typeof data === "object") {
|
|
46
|
+
return convertToNullAttr();
|
|
47
|
+
}
|
|
48
|
+
else if (Array.isArray(data)) {
|
|
49
|
+
return convertToListAttr(data, options);
|
|
50
|
+
}
|
|
51
|
+
else if (data?.constructor?.name === "Set") {
|
|
52
|
+
return convertToSetAttr(data, options);
|
|
53
|
+
}
|
|
54
|
+
else if (data?.constructor?.name === "Map") {
|
|
55
|
+
return convertToMapAttrFromIterable(data, options);
|
|
56
|
+
}
|
|
57
|
+
else if (data?.constructor?.name === "Object" ||
|
|
58
|
+
(!data.constructor && typeof data === "object")) {
|
|
59
|
+
return convertToMapAttrFromEnumerableProps(data, options);
|
|
60
|
+
}
|
|
61
|
+
else if (isBinary(data)) {
|
|
62
|
+
if (data.length === 0 && options?.convertEmptyValues) {
|
|
63
|
+
return convertToNullAttr();
|
|
64
|
+
}
|
|
65
|
+
return convertToBinaryAttr(data);
|
|
66
|
+
}
|
|
67
|
+
else if (typeof data === "boolean" || data?.constructor?.name === "Boolean") {
|
|
68
|
+
return { BOOL: data.valueOf() };
|
|
69
|
+
}
|
|
70
|
+
else if (typeof data === "number" || data?.constructor?.name === "Number") {
|
|
71
|
+
return convertToNumberAttr(data, options);
|
|
72
|
+
}
|
|
73
|
+
else if (data instanceof NumberValue) {
|
|
74
|
+
return data.toAttributeValue();
|
|
75
|
+
}
|
|
76
|
+
else if (typeof data === "bigint") {
|
|
77
|
+
return convertToBigIntAttr(data);
|
|
78
|
+
}
|
|
79
|
+
else if (typeof data === "string" || data?.constructor?.name === "String") {
|
|
80
|
+
if (data.length === 0 && options?.convertEmptyValues) {
|
|
81
|
+
return convertToNullAttr();
|
|
82
|
+
}
|
|
83
|
+
return convertToStringAttr(data);
|
|
84
|
+
}
|
|
85
|
+
else if (options?.convertClassInstanceToMap && typeof data === "object") {
|
|
86
|
+
return convertToMapAttrFromEnumerableProps(data, options);
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`Unsupported type passed: ${data}. Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.`);
|
|
10
89
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
90
|
+
const convertToListAttr = (data, options) => ({
|
|
91
|
+
L: data
|
|
92
|
+
.filter((item) => typeof item !== "function" &&
|
|
93
|
+
(!options?.removeUndefinedValues || (options?.removeUndefinedValues && item !== undefined)))
|
|
94
|
+
.map((item) => convertToAttr(item, options)),
|
|
95
|
+
});
|
|
96
|
+
const convertToSetAttr = (set, options) => {
|
|
97
|
+
const setToOperate = options?.removeUndefinedValues ? new Set([...set].filter((value) => value !== undefined)) : set;
|
|
98
|
+
if (!options?.removeUndefinedValues && setToOperate.has(undefined)) {
|
|
99
|
+
throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`);
|
|
100
|
+
}
|
|
101
|
+
if (setToOperate.size === 0) {
|
|
102
|
+
if (options?.convertEmptyValues) {
|
|
103
|
+
return convertToNullAttr();
|
|
104
|
+
}
|
|
105
|
+
throw new Error(`Pass a non-empty set, or options.convertEmptyValues=true.`);
|
|
106
|
+
}
|
|
107
|
+
const item = setToOperate.values().next().value;
|
|
108
|
+
if (item instanceof NumberValue) {
|
|
109
|
+
return {
|
|
110
|
+
NS: Array.from(setToOperate).map((_) => _.toString()),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
else if (typeof item === "number") {
|
|
114
|
+
return {
|
|
115
|
+
NS: Array.from(setToOperate)
|
|
116
|
+
.map((num) => convertToNumberAttr(num, options))
|
|
117
|
+
.map((item) => item.N),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
else if (typeof item === "bigint") {
|
|
121
|
+
return {
|
|
122
|
+
NS: Array.from(setToOperate)
|
|
123
|
+
.map(convertToBigIntAttr)
|
|
124
|
+
.map((item) => item.N),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else if (typeof item === "string") {
|
|
128
|
+
return {
|
|
129
|
+
SS: Array.from(setToOperate)
|
|
130
|
+
.map(convertToStringAttr)
|
|
131
|
+
.map((item) => item.S),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
else if (isBinary(item)) {
|
|
135
|
+
return {
|
|
136
|
+
BS: Array.from(setToOperate)
|
|
137
|
+
.map(convertToBinaryAttr)
|
|
138
|
+
.map((item) => item.B),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
throw new Error(`Only Number Set (NS), Binary Set (BS) or String Set (SS) are allowed.`);
|
|
143
|
+
}
|
|
18
144
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
145
|
+
const convertToMapAttrFromIterable = (data, options) => ({
|
|
146
|
+
M: ((data) => {
|
|
147
|
+
const map = {};
|
|
148
|
+
for (const [key, value] of data) {
|
|
149
|
+
if (typeof value !== "function" && (value !== undefined || !options?.removeUndefinedValues)) {
|
|
150
|
+
map[key] = convertToAttr(value, options);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return map;
|
|
154
|
+
})(data),
|
|
29
155
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return String(this.value);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* @override
|
|
92
|
-
*/
|
|
93
|
-
valueOf() {
|
|
94
|
-
return this.toString();
|
|
95
|
-
}
|
|
156
|
+
const convertToMapAttrFromEnumerableProps = (data, options) => ({
|
|
157
|
+
M: ((data) => {
|
|
158
|
+
const map = {};
|
|
159
|
+
for (const key in data) {
|
|
160
|
+
const value = data[key];
|
|
161
|
+
if (typeof value !== "function" && (value !== undefined || !options?.removeUndefinedValues)) {
|
|
162
|
+
map[key] = convertToAttr(value, options);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return map;
|
|
166
|
+
})(data),
|
|
167
|
+
});
|
|
168
|
+
const convertToNullAttr = () => ({ NULL: true });
|
|
169
|
+
const convertToBinaryAttr = (data) => ({ B: data });
|
|
170
|
+
const convertToStringAttr = (data) => ({ S: data.toString() });
|
|
171
|
+
const convertToBigIntAttr = (data) => ({ N: data.toString() });
|
|
172
|
+
const validateBigIntAndThrow = (errorPrefix) => {
|
|
173
|
+
throw new Error(`${errorPrefix} Use NumberValue from @aws-sdk/lib-dynamodb.`);
|
|
174
|
+
};
|
|
175
|
+
const convertToNumberAttr = (num, options) => {
|
|
176
|
+
if ([Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]
|
|
177
|
+
.map((val) => val.toString())
|
|
178
|
+
.includes(num.toString())) {
|
|
179
|
+
throw new Error(`Special numeric value ${num.toString()} is not allowed`);
|
|
180
|
+
}
|
|
181
|
+
else if (!options?.allowImpreciseNumbers) {
|
|
182
|
+
if (Number(num) > Number.MAX_SAFE_INTEGER) {
|
|
183
|
+
validateBigIntAndThrow(`Number ${num.toString()} is greater than Number.MAX_SAFE_INTEGER.`);
|
|
184
|
+
}
|
|
185
|
+
else if (Number(num) < Number.MIN_SAFE_INTEGER) {
|
|
186
|
+
validateBigIntAndThrow(`Number ${num.toString()} is lesser than Number.MIN_SAFE_INTEGER.`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { N: num.toString() };
|
|
190
|
+
};
|
|
191
|
+
const isBinary = (data) => {
|
|
192
|
+
const binaryTypes = [
|
|
193
|
+
"ArrayBuffer",
|
|
194
|
+
"Blob",
|
|
195
|
+
"Buffer",
|
|
196
|
+
"DataView",
|
|
197
|
+
"File",
|
|
198
|
+
"Int8Array",
|
|
199
|
+
"Uint8Array",
|
|
200
|
+
"Uint8ClampedArray",
|
|
201
|
+
"Int16Array",
|
|
202
|
+
"Uint16Array",
|
|
203
|
+
"Int32Array",
|
|
204
|
+
"Uint32Array",
|
|
205
|
+
"Float32Array",
|
|
206
|
+
"Float64Array",
|
|
207
|
+
"BigInt64Array",
|
|
208
|
+
"BigUint64Array",
|
|
209
|
+
];
|
|
210
|
+
if (data?.constructor) {
|
|
211
|
+
return binaryTypes.includes(data.constructor.name);
|
|
212
|
+
}
|
|
213
|
+
return false;
|
|
96
214
|
};
|
|
97
215
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
};
|
|
159
|
-
} else if (typeof item === "number") {
|
|
160
|
-
return {
|
|
161
|
-
NS: Array.from(setToOperate).map((num) => convertToNumberAttr(num, options)).map((item2) => item2.N)
|
|
162
|
-
};
|
|
163
|
-
} else if (typeof item === "bigint") {
|
|
164
|
-
return {
|
|
165
|
-
NS: Array.from(setToOperate).map(convertToBigIntAttr).map((item2) => item2.N)
|
|
166
|
-
};
|
|
167
|
-
} else if (typeof item === "string") {
|
|
168
|
-
return {
|
|
169
|
-
SS: Array.from(setToOperate).map(convertToStringAttr).map((item2) => item2.S)
|
|
170
|
-
};
|
|
171
|
-
} else if (isBinary(item)) {
|
|
172
|
-
return {
|
|
173
|
-
// Do not alter binary data passed https://github.com/aws/aws-sdk-js-v3/issues/1530
|
|
174
|
-
// @ts-expect-error Type 'ArrayBuffer' is not assignable to type 'Uint8Array'
|
|
175
|
-
BS: Array.from(setToOperate).map(convertToBinaryAttr).map((item2) => item2.B)
|
|
176
|
-
};
|
|
177
|
-
} else {
|
|
178
|
-
throw new Error(`Only Number Set (NS), Binary Set (BS) or String Set (SS) are allowed.`);
|
|
179
|
-
}
|
|
180
|
-
}, "convertToSetAttr");
|
|
181
|
-
var convertToMapAttrFromIterable = /* @__PURE__ */ __name((data, options) => ({
|
|
182
|
-
M: ((data2) => {
|
|
183
|
-
const map = {};
|
|
184
|
-
for (const [key, value] of data2) {
|
|
185
|
-
if (typeof value !== "function" && (value !== void 0 || !options?.removeUndefinedValues)) {
|
|
186
|
-
map[key] = convertToAttr(value, options);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return map;
|
|
190
|
-
})(data)
|
|
191
|
-
}), "convertToMapAttrFromIterable");
|
|
192
|
-
var convertToMapAttrFromEnumerableProps = /* @__PURE__ */ __name((data, options) => ({
|
|
193
|
-
M: ((data2) => {
|
|
194
|
-
const map = {};
|
|
195
|
-
for (const key in data2) {
|
|
196
|
-
const value = data2[key];
|
|
197
|
-
if (typeof value !== "function" && (value !== void 0 || !options?.removeUndefinedValues)) {
|
|
198
|
-
map[key] = convertToAttr(value, options);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return map;
|
|
202
|
-
})(data)
|
|
203
|
-
}), "convertToMapAttrFromEnumerableProps");
|
|
204
|
-
var convertToNullAttr = /* @__PURE__ */ __name(() => ({ NULL: true }), "convertToNullAttr");
|
|
205
|
-
var convertToBinaryAttr = /* @__PURE__ */ __name((data) => ({ B: data }), "convertToBinaryAttr");
|
|
206
|
-
var convertToStringAttr = /* @__PURE__ */ __name((data) => ({ S: data.toString() }), "convertToStringAttr");
|
|
207
|
-
var convertToBigIntAttr = /* @__PURE__ */ __name((data) => ({ N: data.toString() }), "convertToBigIntAttr");
|
|
208
|
-
var validateBigIntAndThrow = /* @__PURE__ */ __name((errorPrefix) => {
|
|
209
|
-
throw new Error(`${errorPrefix} Use NumberValue from @aws-sdk/lib-dynamodb.`);
|
|
210
|
-
}, "validateBigIntAndThrow");
|
|
211
|
-
var convertToNumberAttr = /* @__PURE__ */ __name((num, options) => {
|
|
212
|
-
if ([Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY].map((val) => val.toString()).includes(num.toString())) {
|
|
213
|
-
throw new Error(`Special numeric value ${num.toString()} is not allowed`);
|
|
214
|
-
} else if (!options?.allowImpreciseNumbers) {
|
|
215
|
-
if (Number(num) > Number.MAX_SAFE_INTEGER) {
|
|
216
|
-
validateBigIntAndThrow(`Number ${num.toString()} is greater than Number.MAX_SAFE_INTEGER.`);
|
|
217
|
-
} else if (Number(num) < Number.MIN_SAFE_INTEGER) {
|
|
218
|
-
validateBigIntAndThrow(`Number ${num.toString()} is lesser than Number.MIN_SAFE_INTEGER.`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return { N: num.toString() };
|
|
222
|
-
}, "convertToNumberAttr");
|
|
223
|
-
var isBinary = /* @__PURE__ */ __name((data) => {
|
|
224
|
-
const binaryTypes = [
|
|
225
|
-
"ArrayBuffer",
|
|
226
|
-
"Blob",
|
|
227
|
-
"Buffer",
|
|
228
|
-
"DataView",
|
|
229
|
-
"File",
|
|
230
|
-
"Int8Array",
|
|
231
|
-
"Uint8Array",
|
|
232
|
-
"Uint8ClampedArray",
|
|
233
|
-
"Int16Array",
|
|
234
|
-
"Uint16Array",
|
|
235
|
-
"Int32Array",
|
|
236
|
-
"Uint32Array",
|
|
237
|
-
"Float32Array",
|
|
238
|
-
"Float64Array",
|
|
239
|
-
"BigInt64Array",
|
|
240
|
-
"BigUint64Array"
|
|
241
|
-
];
|
|
242
|
-
if (data?.constructor) {
|
|
243
|
-
return binaryTypes.includes(data.constructor.name);
|
|
244
|
-
}
|
|
245
|
-
return false;
|
|
246
|
-
}, "isBinary");
|
|
216
|
+
const convertToNative = (data, options) => {
|
|
217
|
+
for (const [key, value] of Object.entries(data)) {
|
|
218
|
+
if (value !== undefined) {
|
|
219
|
+
switch (key) {
|
|
220
|
+
case "NULL":
|
|
221
|
+
return null;
|
|
222
|
+
case "BOOL":
|
|
223
|
+
return Boolean(value);
|
|
224
|
+
case "N":
|
|
225
|
+
return convertNumber(value, options);
|
|
226
|
+
case "B":
|
|
227
|
+
return convertBinary(value);
|
|
228
|
+
case "S":
|
|
229
|
+
return convertString(value);
|
|
230
|
+
case "L":
|
|
231
|
+
return convertList(value, options);
|
|
232
|
+
case "M":
|
|
233
|
+
return convertMap(value, options);
|
|
234
|
+
case "NS":
|
|
235
|
+
return new Set(value.map((item) => convertNumber(item, options)));
|
|
236
|
+
case "BS":
|
|
237
|
+
return new Set(value.map(convertBinary));
|
|
238
|
+
case "SS":
|
|
239
|
+
return new Set(value.map(convertString));
|
|
240
|
+
default:
|
|
241
|
+
throw new Error(`Unsupported type passed: ${key}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
throw new Error(`No value defined: ${JSON.stringify(data)}`);
|
|
246
|
+
};
|
|
247
|
+
const convertNumber = (numString, options) => {
|
|
248
|
+
if (typeof options?.wrapNumbers === "function") {
|
|
249
|
+
return options?.wrapNumbers(numString);
|
|
250
|
+
}
|
|
251
|
+
if (options?.wrapNumbers) {
|
|
252
|
+
return NumberValue.from(numString);
|
|
253
|
+
}
|
|
254
|
+
const num = Number(numString);
|
|
255
|
+
const infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];
|
|
256
|
+
const isLargeFiniteNumber = (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) && !infinityValues.includes(num);
|
|
257
|
+
if (isLargeFiniteNumber) {
|
|
258
|
+
if (typeof BigInt === "function") {
|
|
259
|
+
try {
|
|
260
|
+
return BigInt(numString);
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
throw new Error(`${numString} can't be converted to BigInt. Set options.wrapNumbers to get string value.`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return num;
|
|
271
|
+
};
|
|
272
|
+
const convertString = (stringValue) => stringValue;
|
|
273
|
+
const convertBinary = (binaryValue) => binaryValue;
|
|
274
|
+
const convertList = (list, options) => list.map((item) => convertToNative(item, options));
|
|
275
|
+
const convertMap = (map, options) => Object.entries(map).reduce((acc, [key, value]) => ((acc[key] = convertToNative(value, options)), acc), {});
|
|
247
276
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
switch (key) {
|
|
253
|
-
case "NULL":
|
|
254
|
-
return null;
|
|
255
|
-
case "BOOL":
|
|
256
|
-
return Boolean(value);
|
|
257
|
-
case "N":
|
|
258
|
-
return convertNumber(value, options);
|
|
259
|
-
case "B":
|
|
260
|
-
return convertBinary(value);
|
|
261
|
-
case "S":
|
|
262
|
-
return convertString(value);
|
|
263
|
-
case "L":
|
|
264
|
-
return convertList(value, options);
|
|
277
|
+
function marshall(data, options) {
|
|
278
|
+
const attributeValue = convertToAttr(data, options);
|
|
279
|
+
const [key, value] = Object.entries(attributeValue)[0];
|
|
280
|
+
switch (key) {
|
|
265
281
|
case "M":
|
|
266
|
-
|
|
282
|
+
case "L":
|
|
283
|
+
return options?.convertTopLevelContainer ? attributeValue : value;
|
|
284
|
+
case "SS":
|
|
267
285
|
case "NS":
|
|
268
|
-
return new Set(value.map((item) => convertNumber(item, options)));
|
|
269
286
|
case "BS":
|
|
270
|
-
|
|
271
|
-
case "
|
|
272
|
-
|
|
287
|
+
case "S":
|
|
288
|
+
case "N":
|
|
289
|
+
case "B":
|
|
290
|
+
case "NULL":
|
|
291
|
+
case "BOOL":
|
|
292
|
+
case "$unknown":
|
|
273
293
|
default:
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
throw new Error(`No value defined: ${JSON.stringify(data)}`);
|
|
279
|
-
}, "convertToNative");
|
|
280
|
-
var convertNumber = /* @__PURE__ */ __name((numString, options) => {
|
|
281
|
-
if (typeof options?.wrapNumbers === "function") {
|
|
282
|
-
return options?.wrapNumbers(numString);
|
|
283
|
-
}
|
|
284
|
-
if (options?.wrapNumbers) {
|
|
285
|
-
return NumberValue.from(numString);
|
|
286
|
-
}
|
|
287
|
-
const num = Number(numString);
|
|
288
|
-
const infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];
|
|
289
|
-
const isLargeFiniteNumber = (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) && !infinityValues.includes(num);
|
|
290
|
-
if (isLargeFiniteNumber) {
|
|
291
|
-
if (typeof BigInt === "function") {
|
|
292
|
-
try {
|
|
293
|
-
return BigInt(numString);
|
|
294
|
-
} catch (error) {
|
|
295
|
-
throw new Error(`${numString} can't be converted to BigInt. Set options.wrapNumbers to get string value.`);
|
|
296
|
-
}
|
|
297
|
-
} else {
|
|
298
|
-
throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return num;
|
|
302
|
-
}, "convertNumber");
|
|
303
|
-
var convertString = /* @__PURE__ */ __name((stringValue) => stringValue, "convertString");
|
|
304
|
-
var convertBinary = /* @__PURE__ */ __name((binaryValue) => binaryValue, "convertBinary");
|
|
305
|
-
var convertList = /* @__PURE__ */ __name((list, options) => list.map((item) => convertToNative(item, options)), "convertList");
|
|
306
|
-
var convertMap = /* @__PURE__ */ __name((map, options) => Object.entries(map).reduce(
|
|
307
|
-
(acc, [key, value]) => (acc[key] = convertToNative(value, options), acc),
|
|
308
|
-
{}
|
|
309
|
-
), "convertMap");
|
|
310
|
-
|
|
311
|
-
// src/marshall.ts
|
|
312
|
-
function marshall(data, options) {
|
|
313
|
-
const attributeValue = convertToAttr(data, options);
|
|
314
|
-
const [key, value] = Object.entries(attributeValue)[0];
|
|
315
|
-
switch (key) {
|
|
316
|
-
case "M":
|
|
317
|
-
case "L":
|
|
318
|
-
return options?.convertTopLevelContainer ? attributeValue : value;
|
|
319
|
-
case "SS":
|
|
320
|
-
case "NS":
|
|
321
|
-
case "BS":
|
|
322
|
-
case "S":
|
|
323
|
-
case "N":
|
|
324
|
-
case "B":
|
|
325
|
-
case "NULL":
|
|
326
|
-
case "BOOL":
|
|
327
|
-
case "$unknown":
|
|
328
|
-
default:
|
|
329
|
-
return attributeValue;
|
|
330
|
-
}
|
|
294
|
+
return attributeValue;
|
|
295
|
+
}
|
|
331
296
|
}
|
|
332
|
-
__name(marshall, "marshall");
|
|
333
297
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}, "unmarshall");
|
|
341
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
342
|
-
|
|
343
|
-
0 && (module.exports = {
|
|
344
|
-
NumberValueImpl,
|
|
345
|
-
convertToAttr,
|
|
346
|
-
convertToNative,
|
|
347
|
-
marshall,
|
|
348
|
-
unmarshall
|
|
349
|
-
});
|
|
298
|
+
const unmarshall = (data, options) => {
|
|
299
|
+
if (options?.convertWithoutMapWrapper) {
|
|
300
|
+
return convertToNative(data, options);
|
|
301
|
+
}
|
|
302
|
+
return convertToNative({ M: data }, options);
|
|
303
|
+
};
|
|
350
304
|
|
|
305
|
+
exports.NumberValueImpl = NumberValue;
|
|
306
|
+
exports.convertToAttr = convertToAttr;
|
|
307
|
+
exports.convertToNative = convertToNative;
|
|
308
|
+
exports.marshall = marshall;
|
|
309
|
+
exports.unmarshall = unmarshall;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/util-dynamodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.906.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline util-dynamodb",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"tslib": "^2.6.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
29
|
+
"@aws-sdk/client-dynamodb": "3.906.0",
|
|
30
30
|
"@tsconfig/recommended": "1.0.1",
|
|
31
31
|
"concurrently": "7.0.0",
|
|
32
32
|
"downlevel-dts": "0.10.1",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typescript": "~5.8.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
37
|
+
"@aws-sdk/client-dynamodb": "^3.906.0"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=18.0.0"
|