@aws-sdk/util-dynamodb 3.186.0 → 3.188.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/CHANGELOG.md +8 -0
- package/dist-es/convertToAttr.js +56 -69
- package/dist-es/convertToNative.js +40 -57
- package/dist-es/marshall.js +2 -3
- package/dist-es/unmarshall.js +1 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.188.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.187.0...v3.188.0) (2022-10-13)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aws-sdk/util-dynamodb
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @aws-sdk/util-dynamodb
|
package/dist-es/convertToAttr.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export var convertToAttr = function (data, options) {
|
|
3
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1
|
+
export const convertToAttr = (data, options) => {
|
|
4
2
|
if (data === undefined) {
|
|
5
|
-
throw new Error(
|
|
3
|
+
throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`);
|
|
6
4
|
}
|
|
7
5
|
else if (data === null && typeof data === "object") {
|
|
8
6
|
return convertToNullAttr();
|
|
@@ -10,148 +8,137 @@ export var convertToAttr = function (data, options) {
|
|
|
10
8
|
else if (Array.isArray(data)) {
|
|
11
9
|
return convertToListAttr(data, options);
|
|
12
10
|
}
|
|
13
|
-
else if (
|
|
11
|
+
else if (data?.constructor?.name === "Set") {
|
|
14
12
|
return convertToSetAttr(data, options);
|
|
15
13
|
}
|
|
16
|
-
else if (
|
|
14
|
+
else if (data?.constructor?.name === "Map") {
|
|
17
15
|
return convertToMapAttrFromIterable(data, options);
|
|
18
16
|
}
|
|
19
|
-
else if (
|
|
17
|
+
else if (data?.constructor?.name === "Object" ||
|
|
20
18
|
(!data.constructor && typeof data === "object")) {
|
|
21
19
|
return convertToMapAttrFromEnumerableProps(data, options);
|
|
22
20
|
}
|
|
23
21
|
else if (isBinary(data)) {
|
|
24
|
-
if (data.length === 0 &&
|
|
22
|
+
if (data.length === 0 && options?.convertEmptyValues) {
|
|
25
23
|
return convertToNullAttr();
|
|
26
24
|
}
|
|
27
25
|
return convertToBinaryAttr(data);
|
|
28
26
|
}
|
|
29
|
-
else if (typeof data === "boolean" ||
|
|
27
|
+
else if (typeof data === "boolean" || data?.constructor?.name === "Boolean") {
|
|
30
28
|
return { BOOL: data.valueOf() };
|
|
31
29
|
}
|
|
32
|
-
else if (typeof data === "number" ||
|
|
30
|
+
else if (typeof data === "number" || data?.constructor?.name === "Number") {
|
|
33
31
|
return convertToNumberAttr(data);
|
|
34
32
|
}
|
|
35
33
|
else if (typeof data === "bigint") {
|
|
36
34
|
return convertToBigIntAttr(data);
|
|
37
35
|
}
|
|
38
|
-
else if (typeof data === "string" ||
|
|
39
|
-
if (data.length === 0 &&
|
|
36
|
+
else if (typeof data === "string" || data?.constructor?.name === "String") {
|
|
37
|
+
if (data.length === 0 && options?.convertEmptyValues) {
|
|
40
38
|
return convertToNullAttr();
|
|
41
39
|
}
|
|
42
40
|
return convertToStringAttr(data);
|
|
43
41
|
}
|
|
44
|
-
else if (
|
|
42
|
+
else if (options?.convertClassInstanceToMap && typeof data === "object") {
|
|
45
43
|
return convertToMapAttrFromEnumerableProps(data, options);
|
|
46
44
|
}
|
|
47
|
-
throw new Error(
|
|
45
|
+
throw new Error(`Unsupported type passed: ${data}. Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.`);
|
|
48
46
|
};
|
|
49
|
-
|
|
47
|
+
const convertToListAttr = (data, options) => ({
|
|
50
48
|
L: data
|
|
51
|
-
.filter(
|
|
52
|
-
.map(
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!
|
|
57
|
-
throw new Error(
|
|
49
|
+
.filter((item) => !options?.removeUndefinedValues || (options?.removeUndefinedValues && item !== undefined))
|
|
50
|
+
.map((item) => convertToAttr(item, options)),
|
|
51
|
+
});
|
|
52
|
+
const convertToSetAttr = (set, options) => {
|
|
53
|
+
const setToOperate = options?.removeUndefinedValues ? new Set([...set].filter((value) => value !== undefined)) : set;
|
|
54
|
+
if (!options?.removeUndefinedValues && setToOperate.has(undefined)) {
|
|
55
|
+
throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`);
|
|
58
56
|
}
|
|
59
57
|
if (setToOperate.size === 0) {
|
|
60
|
-
if (options
|
|
58
|
+
if (options?.convertEmptyValues) {
|
|
61
59
|
return convertToNullAttr();
|
|
62
60
|
}
|
|
63
|
-
throw new Error(
|
|
61
|
+
throw new Error(`Pass a non-empty set, or options.convertEmptyValues=true.`);
|
|
64
62
|
}
|
|
65
|
-
|
|
63
|
+
const item = setToOperate.values().next().value;
|
|
66
64
|
if (typeof item === "number") {
|
|
67
65
|
return {
|
|
68
66
|
NS: Array.from(setToOperate)
|
|
69
67
|
.map(convertToNumberAttr)
|
|
70
|
-
.map(
|
|
68
|
+
.map((item) => item.N),
|
|
71
69
|
};
|
|
72
70
|
}
|
|
73
71
|
else if (typeof item === "bigint") {
|
|
74
72
|
return {
|
|
75
73
|
NS: Array.from(setToOperate)
|
|
76
74
|
.map(convertToBigIntAttr)
|
|
77
|
-
.map(
|
|
75
|
+
.map((item) => item.N),
|
|
78
76
|
};
|
|
79
77
|
}
|
|
80
78
|
else if (typeof item === "string") {
|
|
81
79
|
return {
|
|
82
80
|
SS: Array.from(setToOperate)
|
|
83
81
|
.map(convertToStringAttr)
|
|
84
|
-
.map(
|
|
82
|
+
.map((item) => item.S),
|
|
85
83
|
};
|
|
86
84
|
}
|
|
87
85
|
else if (isBinary(item)) {
|
|
88
86
|
return {
|
|
89
87
|
BS: Array.from(setToOperate)
|
|
90
88
|
.map(convertToBinaryAttr)
|
|
91
|
-
.map(
|
|
89
|
+
.map((item) => item.B),
|
|
92
90
|
};
|
|
93
91
|
}
|
|
94
92
|
else {
|
|
95
|
-
throw new Error(
|
|
93
|
+
throw new Error(`Only Number Set (NS), Binary Set (BS) or String Set (SS) are allowed.`);
|
|
96
94
|
}
|
|
97
95
|
};
|
|
98
|
-
|
|
99
|
-
M: (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var _b = __read(data_1_1.value, 2), key = _b[0], value = _b[1];
|
|
105
|
-
if (typeof value !== "function" && (value !== undefined || !(options === null || options === void 0 ? void 0 : options.removeUndefinedValues))) {
|
|
106
|
-
map[key] = convertToAttr(value, options);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
111
|
-
finally {
|
|
112
|
-
try {
|
|
113
|
-
if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
|
|
96
|
+
const convertToMapAttrFromIterable = (data, options) => ({
|
|
97
|
+
M: ((data) => {
|
|
98
|
+
const map = {};
|
|
99
|
+
for (const [key, value] of data) {
|
|
100
|
+
if (typeof value !== "function" && (value !== undefined || !options?.removeUndefinedValues)) {
|
|
101
|
+
map[key] = convertToAttr(value, options);
|
|
114
102
|
}
|
|
115
|
-
finally { if (e_1) throw e_1.error; }
|
|
116
103
|
}
|
|
117
104
|
return map;
|
|
118
105
|
})(data),
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
M: (
|
|
122
|
-
|
|
123
|
-
for (
|
|
124
|
-
|
|
125
|
-
if (typeof value !== "function" && (value !== undefined || !
|
|
106
|
+
});
|
|
107
|
+
const convertToMapAttrFromEnumerableProps = (data, options) => ({
|
|
108
|
+
M: ((data) => {
|
|
109
|
+
const map = {};
|
|
110
|
+
for (const key in data) {
|
|
111
|
+
const value = data[key];
|
|
112
|
+
if (typeof value !== "function" && (value !== undefined || !options?.removeUndefinedValues)) {
|
|
126
113
|
map[key] = convertToAttr(value, options);
|
|
127
114
|
}
|
|
128
115
|
}
|
|
129
116
|
return map;
|
|
130
117
|
})(data),
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
throw new Error(
|
|
118
|
+
});
|
|
119
|
+
const convertToNullAttr = () => ({ NULL: true });
|
|
120
|
+
const convertToBinaryAttr = (data) => ({ B: data });
|
|
121
|
+
const convertToStringAttr = (data) => ({ S: data.toString() });
|
|
122
|
+
const convertToBigIntAttr = (data) => ({ N: data.toString() });
|
|
123
|
+
const validateBigIntAndThrow = (errorPrefix) => {
|
|
124
|
+
throw new Error(`${errorPrefix} ${typeof BigInt === "function" ? "Use BigInt." : "Pass string value instead."} `);
|
|
138
125
|
};
|
|
139
|
-
|
|
126
|
+
const convertToNumberAttr = (num) => {
|
|
140
127
|
if ([Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]
|
|
141
|
-
.map(
|
|
128
|
+
.map((val) => val.toString())
|
|
142
129
|
.includes(num.toString())) {
|
|
143
|
-
throw new Error(
|
|
130
|
+
throw new Error(`Special numeric value ${num.toString()} is not allowed`);
|
|
144
131
|
}
|
|
145
132
|
else if (num > Number.MAX_SAFE_INTEGER) {
|
|
146
|
-
validateBigIntAndThrow(
|
|
133
|
+
validateBigIntAndThrow(`Number ${num.toString()} is greater than Number.MAX_SAFE_INTEGER.`);
|
|
147
134
|
}
|
|
148
135
|
else if (num < Number.MIN_SAFE_INTEGER) {
|
|
149
|
-
validateBigIntAndThrow(
|
|
136
|
+
validateBigIntAndThrow(`Number ${num.toString()} is lesser than Number.MIN_SAFE_INTEGER.`);
|
|
150
137
|
}
|
|
151
138
|
return { N: num.toString() };
|
|
152
139
|
};
|
|
153
|
-
|
|
154
|
-
|
|
140
|
+
const isBinary = (data) => {
|
|
141
|
+
const binaryTypes = [
|
|
155
142
|
"ArrayBuffer",
|
|
156
143
|
"Blob",
|
|
157
144
|
"Buffer",
|
|
@@ -169,7 +156,7 @@ var isBinary = function (data) {
|
|
|
169
156
|
"BigInt64Array",
|
|
170
157
|
"BigUint64Array",
|
|
171
158
|
];
|
|
172
|
-
if (data
|
|
159
|
+
if (data?.constructor) {
|
|
173
160
|
return binaryTypes.includes(data.constructor.name);
|
|
174
161
|
}
|
|
175
162
|
return false;
|
|
@@ -1,76 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
case "SS":
|
|
28
|
-
return new Set(value.map(convertString));
|
|
29
|
-
default:
|
|
30
|
-
throw new Error("Unsupported type passed: ".concat(key));
|
|
31
|
-
}
|
|
1
|
+
export const convertToNative = (data, options) => {
|
|
2
|
+
for (const [key, value] of Object.entries(data)) {
|
|
3
|
+
if (value !== undefined) {
|
|
4
|
+
switch (key) {
|
|
5
|
+
case "NULL":
|
|
6
|
+
return null;
|
|
7
|
+
case "BOOL":
|
|
8
|
+
return Boolean(value);
|
|
9
|
+
case "N":
|
|
10
|
+
return convertNumber(value, options);
|
|
11
|
+
case "B":
|
|
12
|
+
return convertBinary(value);
|
|
13
|
+
case "S":
|
|
14
|
+
return convertString(value);
|
|
15
|
+
case "L":
|
|
16
|
+
return convertList(value, options);
|
|
17
|
+
case "M":
|
|
18
|
+
return convertMap(value, options);
|
|
19
|
+
case "NS":
|
|
20
|
+
return new Set(value.map((item) => convertNumber(item, options)));
|
|
21
|
+
case "BS":
|
|
22
|
+
return new Set(value.map(convertBinary));
|
|
23
|
+
case "SS":
|
|
24
|
+
return new Set(value.map(convertString));
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Unsupported type passed: ${key}`);
|
|
32
27
|
}
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
|
-
|
|
36
|
-
finally {
|
|
37
|
-
try {
|
|
38
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
39
|
-
}
|
|
40
|
-
finally { if (e_1) throw e_1.error; }
|
|
41
|
-
}
|
|
42
|
-
throw new Error("No value defined: ".concat(JSON.stringify(data)));
|
|
30
|
+
throw new Error(`No value defined: ${JSON.stringify(data)}`);
|
|
43
31
|
};
|
|
44
|
-
|
|
45
|
-
if (options
|
|
32
|
+
const convertNumber = (numString, options) => {
|
|
33
|
+
if (options?.wrapNumbers) {
|
|
46
34
|
return { value: numString };
|
|
47
35
|
}
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
const num = Number(numString);
|
|
37
|
+
const infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];
|
|
50
38
|
if ((num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) && !infinityValues.includes(num)) {
|
|
51
39
|
if (typeof BigInt === "function") {
|
|
52
40
|
try {
|
|
53
41
|
return BigInt(numString);
|
|
54
42
|
}
|
|
55
43
|
catch (error) {
|
|
56
|
-
throw new Error(
|
|
44
|
+
throw new Error(`${numString} can't be converted to BigInt. Set options.wrapNumbers to get string value.`);
|
|
57
45
|
}
|
|
58
46
|
}
|
|
59
47
|
else {
|
|
60
|
-
throw new Error(
|
|
48
|
+
throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`);
|
|
61
49
|
}
|
|
62
50
|
}
|
|
63
51
|
return num;
|
|
64
52
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var _b;
|
|
73
|
-
var _c = __read(_a, 2), key = _c[0], value = _c[1];
|
|
74
|
-
return (__assign(__assign({}, acc), (_b = {}, _b[key] = convertToNative(value, options), _b)));
|
|
75
|
-
}, {});
|
|
76
|
-
};
|
|
53
|
+
const convertString = (stringValue) => stringValue;
|
|
54
|
+
const convertBinary = (binaryValue) => binaryValue;
|
|
55
|
+
const convertList = (list, options) => list.map((item) => convertToNative(item, options));
|
|
56
|
+
const convertMap = (map, options) => Object.entries(map).reduce((acc, [key, value]) => ({
|
|
57
|
+
...acc,
|
|
58
|
+
[key]: convertToNative(value, options),
|
|
59
|
+
}), {});
|
package/dist-es/marshall.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { __read } from "tslib";
|
|
2
1
|
import { convertToAttr } from "./convertToAttr";
|
|
3
2
|
export function marshall(data, options) {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const attributeValue = convertToAttr(data, options);
|
|
4
|
+
const [key, value] = Object.entries(attributeValue)[0];
|
|
6
5
|
switch (key) {
|
|
7
6
|
case "M":
|
|
8
7
|
case "L":
|
package/dist-es/unmarshall.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/util-dynamodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.188.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"tslib": "^2.3.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
26
|
+
"@aws-sdk/client-dynamodb": "3.188.0",
|
|
27
27
|
"@tsconfig/recommended": "1.0.1",
|
|
28
28
|
"concurrently": "7.0.0",
|
|
29
29
|
"downlevel-dts": "0.10.1",
|