@aws-sdk/util-dynamodb 3.32.0 → 3.36.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 +38 -0
- package/dist-cjs/convertToAttr.js +168 -0
- package/dist-cjs/convertToNative.js +63 -0
- package/dist-cjs/index.js +8 -0
- package/dist-cjs/marshall.js +6 -0
- package/dist-cjs/models.js +2 -0
- package/dist-cjs/unmarshall.js +6 -0
- package/dist-es/convertToAttr.js +176 -0
- package/dist-es/convertToNative.js +76 -0
- package/{dist/types/index.d.ts → dist-es/index.js} +0 -0
- package/dist-es/marshall.js +2 -0
- package/dist-es/models.js +1 -0
- package/dist-es/unmarshall.js +4 -0
- package/{dist/types → dist-types}/convertToAttr.d.ts +0 -0
- package/{dist/types → dist-types}/convertToNative.d.ts +0 -0
- package/{src/index.ts → dist-types/index.d.ts} +0 -0
- package/{dist/types → dist-types}/marshall.d.ts +0 -0
- package/{dist/types → dist-types}/models.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/convertToAttr.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/convertToNative.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/index.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/marshall.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/models.d.ts +0 -0
- package/{dist/types → dist-types}/ts3.4/unmarshall.d.ts +0 -0
- package/{dist/types → dist-types}/unmarshall.d.ts +0 -0
- package/package.json +13 -9
- package/dist/cjs/convertToAttr.js +0 -181
- package/dist/cjs/convertToNative.js +0 -71
- package/dist/cjs/index.js +0 -9
- package/dist/cjs/marshall.js +0 -13
- package/dist/cjs/models.js +0 -3
- package/dist/cjs/unmarshall.js +0 -13
- package/dist/es/convertToAttr.js +0 -189
- package/dist/es/convertToNative.js +0 -84
- package/dist/es/index.js +0 -6
- package/dist/es/marshall.js +0 -9
- package/dist/es/models.js +0 -2
- package/dist/es/unmarshall.js +0 -11
- package/src/convertToAttr.ts +0 -190
- package/src/convertToNative.ts +0 -82
- package/src/marshall.ts +0 -33
- package/src/models.ts +0 -46
- package/src/unmarshall.ts +0 -27
- package/tsconfig.cjs.json +0 -10
- package/tsconfig.es.json +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,44 @@
|
|
|
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.36.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.35.0...v3.36.0) (2021-10-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* publish files in dist-* only ([#2873](https://github.com/aws/aws-sdk-js-v3/issues/2873)) ([53b4243](https://github.com/aws/aws-sdk-js-v3/commit/53b4243b066f25ff2412d5f0dea1036054b2df32))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [3.35.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.34.0...v3.35.0) (2021-10-04)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @aws-sdk/util-dynamodb
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [3.34.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.33.0...v3.34.0) (2021-09-24)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **non-clients:** remove comments from transpiled JS files ([#2813](https://github.com/aws/aws-sdk-js-v3/issues/2813)) ([e6fc7f3](https://github.com/aws/aws-sdk-js-v3/commit/e6fc7f3e0fa74785590ac19e7ed143c916bb9b6e))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# [3.33.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.32.0...v3.33.0) (2021-09-21)
|
|
37
|
+
|
|
38
|
+
**Note:** Version bump only for package @aws-sdk/util-dynamodb
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
6
44
|
# [3.32.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.31.0...v3.32.0) (2021-09-17)
|
|
7
45
|
|
|
8
46
|
**Note:** Version bump only for package @aws-sdk/util-dynamodb
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToAttr = void 0;
|
|
4
|
+
const convertToAttr = (data, options) => {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6
|
+
if (data === undefined) {
|
|
7
|
+
throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`);
|
|
8
|
+
}
|
|
9
|
+
else if (data === null && typeof data === "object") {
|
|
10
|
+
return convertToNullAttr();
|
|
11
|
+
}
|
|
12
|
+
else if (Array.isArray(data)) {
|
|
13
|
+
return convertToListAttr(data, options);
|
|
14
|
+
}
|
|
15
|
+
else if (((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === "Set") {
|
|
16
|
+
return convertToSetAttr(data, options);
|
|
17
|
+
}
|
|
18
|
+
else if (((_b = data === null || data === void 0 ? void 0 : data.constructor) === null || _b === void 0 ? void 0 : _b.name) === "Map") {
|
|
19
|
+
return convertToMapAttrFromIterable(data, options);
|
|
20
|
+
}
|
|
21
|
+
else if (((_c = data === null || data === void 0 ? void 0 : data.constructor) === null || _c === void 0 ? void 0 : _c.name) === "Object" ||
|
|
22
|
+
(!data.constructor && typeof data === "object")) {
|
|
23
|
+
return convertToMapAttrFromEnumerableProps(data, options);
|
|
24
|
+
}
|
|
25
|
+
else if (isBinary(data)) {
|
|
26
|
+
if (data.length === 0 && (options === null || options === void 0 ? void 0 : options.convertEmptyValues)) {
|
|
27
|
+
return convertToNullAttr();
|
|
28
|
+
}
|
|
29
|
+
return convertToBinaryAttr(data);
|
|
30
|
+
}
|
|
31
|
+
else if (typeof data === "boolean" || ((_d = data === null || data === void 0 ? void 0 : data.constructor) === null || _d === void 0 ? void 0 : _d.name) === "Boolean") {
|
|
32
|
+
return { BOOL: data.valueOf() };
|
|
33
|
+
}
|
|
34
|
+
else if (typeof data === "number" || ((_e = data === null || data === void 0 ? void 0 : data.constructor) === null || _e === void 0 ? void 0 : _e.name) === "Number") {
|
|
35
|
+
return convertToNumberAttr(data);
|
|
36
|
+
}
|
|
37
|
+
else if (typeof data === "bigint") {
|
|
38
|
+
return convertToBigIntAttr(data);
|
|
39
|
+
}
|
|
40
|
+
else if (typeof data === "string" || ((_f = data === null || data === void 0 ? void 0 : data.constructor) === null || _f === void 0 ? void 0 : _f.name) === "String") {
|
|
41
|
+
if (data.length === 0 && (options === null || options === void 0 ? void 0 : options.convertEmptyValues)) {
|
|
42
|
+
return convertToNullAttr();
|
|
43
|
+
}
|
|
44
|
+
return convertToStringAttr(data);
|
|
45
|
+
}
|
|
46
|
+
else if ((options === null || options === void 0 ? void 0 : options.convertClassInstanceToMap) && typeof data === "object") {
|
|
47
|
+
return convertToMapAttrFromEnumerableProps(data, options);
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Unsupported type passed: ${data}. Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.`);
|
|
50
|
+
};
|
|
51
|
+
exports.convertToAttr = convertToAttr;
|
|
52
|
+
const convertToListAttr = (data, options) => ({
|
|
53
|
+
L: data
|
|
54
|
+
.filter((item) => !(options === null || options === void 0 ? void 0 : options.removeUndefinedValues) || ((options === null || options === void 0 ? void 0 : options.removeUndefinedValues) && item !== undefined))
|
|
55
|
+
.map((item) => exports.convertToAttr(item, options)),
|
|
56
|
+
});
|
|
57
|
+
const convertToSetAttr = (set, options) => {
|
|
58
|
+
const setToOperate = (options === null || options === void 0 ? void 0 : options.removeUndefinedValues) ? new Set([...set].filter((value) => value !== undefined)) : set;
|
|
59
|
+
if (!(options === null || options === void 0 ? void 0 : options.removeUndefinedValues) && setToOperate.has(undefined)) {
|
|
60
|
+
throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`);
|
|
61
|
+
}
|
|
62
|
+
if (setToOperate.size === 0) {
|
|
63
|
+
if (options === null || options === void 0 ? void 0 : options.convertEmptyValues) {
|
|
64
|
+
return convertToNullAttr();
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Pass a non-empty set, or options.convertEmptyValues=true.`);
|
|
67
|
+
}
|
|
68
|
+
const item = setToOperate.values().next().value;
|
|
69
|
+
if (typeof item === "number") {
|
|
70
|
+
return {
|
|
71
|
+
NS: Array.from(setToOperate)
|
|
72
|
+
.map(convertToNumberAttr)
|
|
73
|
+
.map((item) => item.N),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
else if (typeof item === "bigint") {
|
|
77
|
+
return {
|
|
78
|
+
NS: Array.from(setToOperate)
|
|
79
|
+
.map(convertToBigIntAttr)
|
|
80
|
+
.map((item) => item.N),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
else if (typeof item === "string") {
|
|
84
|
+
return {
|
|
85
|
+
SS: Array.from(setToOperate)
|
|
86
|
+
.map(convertToStringAttr)
|
|
87
|
+
.map((item) => item.S),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else if (isBinary(item)) {
|
|
91
|
+
return {
|
|
92
|
+
BS: Array.from(setToOperate)
|
|
93
|
+
.map(convertToBinaryAttr)
|
|
94
|
+
.map((item) => item.B),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error(`Only Number Set (NS), Binary Set (BS) or String Set (SS) are allowed.`);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const convertToMapAttrFromIterable = (data, options) => ({
|
|
102
|
+
M: ((data) => {
|
|
103
|
+
const map = {};
|
|
104
|
+
for (const [key, value] of data) {
|
|
105
|
+
if (typeof value !== "function" && (value !== undefined || !(options === null || options === void 0 ? void 0 : options.removeUndefinedValues))) {
|
|
106
|
+
map[key] = exports.convertToAttr(value, options);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return map;
|
|
110
|
+
})(data),
|
|
111
|
+
});
|
|
112
|
+
const convertToMapAttrFromEnumerableProps = (data, options) => ({
|
|
113
|
+
M: ((data) => {
|
|
114
|
+
const map = {};
|
|
115
|
+
for (const key in data) {
|
|
116
|
+
const value = data[key];
|
|
117
|
+
if (typeof value !== "function" && (value !== undefined || !(options === null || options === void 0 ? void 0 : options.removeUndefinedValues))) {
|
|
118
|
+
map[key] = exports.convertToAttr(value, options);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return map;
|
|
122
|
+
})(data),
|
|
123
|
+
});
|
|
124
|
+
const convertToNullAttr = () => ({ NULL: true });
|
|
125
|
+
const convertToBinaryAttr = (data) => ({ B: data });
|
|
126
|
+
const convertToStringAttr = (data) => ({ S: data.toString() });
|
|
127
|
+
const convertToBigIntAttr = (data) => ({ N: data.toString() });
|
|
128
|
+
const validateBigIntAndThrow = (errorPrefix) => {
|
|
129
|
+
throw new Error(`${errorPrefix} ${typeof BigInt === "function" ? "Use BigInt." : "Pass string value instead."} `);
|
|
130
|
+
};
|
|
131
|
+
const convertToNumberAttr = (num) => {
|
|
132
|
+
if ([Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]
|
|
133
|
+
.map((val) => val.toString())
|
|
134
|
+
.includes(num.toString())) {
|
|
135
|
+
throw new Error(`Special numeric value ${num.toString()} is not allowed`);
|
|
136
|
+
}
|
|
137
|
+
else if (num > Number.MAX_SAFE_INTEGER) {
|
|
138
|
+
validateBigIntAndThrow(`Number ${num.toString()} is greater than Number.MAX_SAFE_INTEGER.`);
|
|
139
|
+
}
|
|
140
|
+
else if (num < Number.MIN_SAFE_INTEGER) {
|
|
141
|
+
validateBigIntAndThrow(`Number ${num.toString()} is lesser than Number.MIN_SAFE_INTEGER.`);
|
|
142
|
+
}
|
|
143
|
+
return { N: num.toString() };
|
|
144
|
+
};
|
|
145
|
+
const isBinary = (data) => {
|
|
146
|
+
const binaryTypes = [
|
|
147
|
+
"ArrayBuffer",
|
|
148
|
+
"Blob",
|
|
149
|
+
"Buffer",
|
|
150
|
+
"DataView",
|
|
151
|
+
"File",
|
|
152
|
+
"Int8Array",
|
|
153
|
+
"Uint8Array",
|
|
154
|
+
"Uint8ClampedArray",
|
|
155
|
+
"Int16Array",
|
|
156
|
+
"Uint16Array",
|
|
157
|
+
"Int32Array",
|
|
158
|
+
"Uint32Array",
|
|
159
|
+
"Float32Array",
|
|
160
|
+
"Float64Array",
|
|
161
|
+
"BigInt64Array",
|
|
162
|
+
"BigUint64Array",
|
|
163
|
+
];
|
|
164
|
+
if (data === null || data === void 0 ? void 0 : data.constructor) {
|
|
165
|
+
return binaryTypes.includes(data.constructor.name);
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToNative = void 0;
|
|
4
|
+
const convertToNative = (data, options) => {
|
|
5
|
+
for (const [key, value] of Object.entries(data)) {
|
|
6
|
+
if (value !== undefined) {
|
|
7
|
+
switch (key) {
|
|
8
|
+
case "NULL":
|
|
9
|
+
return null;
|
|
10
|
+
case "BOOL":
|
|
11
|
+
return Boolean(value);
|
|
12
|
+
case "N":
|
|
13
|
+
return convertNumber(value, options);
|
|
14
|
+
case "B":
|
|
15
|
+
return convertBinary(value);
|
|
16
|
+
case "S":
|
|
17
|
+
return convertString(value);
|
|
18
|
+
case "L":
|
|
19
|
+
return convertList(value, options);
|
|
20
|
+
case "M":
|
|
21
|
+
return convertMap(value, options);
|
|
22
|
+
case "NS":
|
|
23
|
+
return new Set(value.map((item) => convertNumber(item, options)));
|
|
24
|
+
case "BS":
|
|
25
|
+
return new Set(value.map(convertBinary));
|
|
26
|
+
case "SS":
|
|
27
|
+
return new Set(value.map(convertString));
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(`Unsupported type passed: ${key}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`No value defined: ${JSON.stringify(data)}`);
|
|
34
|
+
};
|
|
35
|
+
exports.convertToNative = convertToNative;
|
|
36
|
+
const convertNumber = (numString, options) => {
|
|
37
|
+
if (options === null || options === void 0 ? void 0 : options.wrapNumbers) {
|
|
38
|
+
return { value: numString };
|
|
39
|
+
}
|
|
40
|
+
const num = Number(numString);
|
|
41
|
+
const infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];
|
|
42
|
+
if ((num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) && !infinityValues.includes(num)) {
|
|
43
|
+
if (typeof BigInt === "function") {
|
|
44
|
+
try {
|
|
45
|
+
return BigInt(numString);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new Error(`${numString} can't be converted to BigInt. Set options.wrapNumbers to get string value.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return num;
|
|
56
|
+
};
|
|
57
|
+
const convertString = (stringValue) => stringValue;
|
|
58
|
+
const convertBinary = (binaryValue) => binaryValue;
|
|
59
|
+
const convertList = (list, options) => list.map((item) => exports.convertToNative(item, options));
|
|
60
|
+
const convertMap = (map, options) => Object.entries(map).reduce((acc, [key, value]) => ({
|
|
61
|
+
...acc,
|
|
62
|
+
[key]: exports.convertToNative(value, options),
|
|
63
|
+
}), {});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./convertToAttr"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./convertToNative"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./marshall"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./models"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./unmarshall"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.marshall = void 0;
|
|
4
|
+
const convertToAttr_1 = require("./convertToAttr");
|
|
5
|
+
const marshall = (data, options) => convertToAttr_1.convertToAttr(data, options).M;
|
|
6
|
+
exports.marshall = marshall;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unmarshall = void 0;
|
|
4
|
+
const convertToNative_1 = require("./convertToNative");
|
|
5
|
+
const unmarshall = (data, options) => convertToNative_1.convertToNative({ M: data }, options);
|
|
6
|
+
exports.unmarshall = unmarshall;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { __read, __spreadArray, __values } from "tslib";
|
|
2
|
+
export var convertToAttr = function (data, options) {
|
|
3
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4
|
+
if (data === undefined) {
|
|
5
|
+
throw new Error("Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.");
|
|
6
|
+
}
|
|
7
|
+
else if (data === null && typeof data === "object") {
|
|
8
|
+
return convertToNullAttr();
|
|
9
|
+
}
|
|
10
|
+
else if (Array.isArray(data)) {
|
|
11
|
+
return convertToListAttr(data, options);
|
|
12
|
+
}
|
|
13
|
+
else if (((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === "Set") {
|
|
14
|
+
return convertToSetAttr(data, options);
|
|
15
|
+
}
|
|
16
|
+
else if (((_b = data === null || data === void 0 ? void 0 : data.constructor) === null || _b === void 0 ? void 0 : _b.name) === "Map") {
|
|
17
|
+
return convertToMapAttrFromIterable(data, options);
|
|
18
|
+
}
|
|
19
|
+
else if (((_c = data === null || data === void 0 ? void 0 : data.constructor) === null || _c === void 0 ? void 0 : _c.name) === "Object" ||
|
|
20
|
+
(!data.constructor && typeof data === "object")) {
|
|
21
|
+
return convertToMapAttrFromEnumerableProps(data, options);
|
|
22
|
+
}
|
|
23
|
+
else if (isBinary(data)) {
|
|
24
|
+
if (data.length === 0 && (options === null || options === void 0 ? void 0 : options.convertEmptyValues)) {
|
|
25
|
+
return convertToNullAttr();
|
|
26
|
+
}
|
|
27
|
+
return convertToBinaryAttr(data);
|
|
28
|
+
}
|
|
29
|
+
else if (typeof data === "boolean" || ((_d = data === null || data === void 0 ? void 0 : data.constructor) === null || _d === void 0 ? void 0 : _d.name) === "Boolean") {
|
|
30
|
+
return { BOOL: data.valueOf() };
|
|
31
|
+
}
|
|
32
|
+
else if (typeof data === "number" || ((_e = data === null || data === void 0 ? void 0 : data.constructor) === null || _e === void 0 ? void 0 : _e.name) === "Number") {
|
|
33
|
+
return convertToNumberAttr(data);
|
|
34
|
+
}
|
|
35
|
+
else if (typeof data === "bigint") {
|
|
36
|
+
return convertToBigIntAttr(data);
|
|
37
|
+
}
|
|
38
|
+
else if (typeof data === "string" || ((_f = data === null || data === void 0 ? void 0 : data.constructor) === null || _f === void 0 ? void 0 : _f.name) === "String") {
|
|
39
|
+
if (data.length === 0 && (options === null || options === void 0 ? void 0 : options.convertEmptyValues)) {
|
|
40
|
+
return convertToNullAttr();
|
|
41
|
+
}
|
|
42
|
+
return convertToStringAttr(data);
|
|
43
|
+
}
|
|
44
|
+
else if ((options === null || options === void 0 ? void 0 : options.convertClassInstanceToMap) && typeof data === "object") {
|
|
45
|
+
return convertToMapAttrFromEnumerableProps(data, options);
|
|
46
|
+
}
|
|
47
|
+
throw new Error("Unsupported type passed: " + data + ". Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.");
|
|
48
|
+
};
|
|
49
|
+
var convertToListAttr = function (data, options) { return ({
|
|
50
|
+
L: data
|
|
51
|
+
.filter(function (item) { return !(options === null || options === void 0 ? void 0 : options.removeUndefinedValues) || ((options === null || options === void 0 ? void 0 : options.removeUndefinedValues) && item !== undefined); })
|
|
52
|
+
.map(function (item) { return convertToAttr(item, options); }),
|
|
53
|
+
}); };
|
|
54
|
+
var convertToSetAttr = function (set, options) {
|
|
55
|
+
var setToOperate = (options === null || options === void 0 ? void 0 : options.removeUndefinedValues) ? new Set(__spreadArray([], __read(set)).filter(function (value) { return value !== undefined; })) : set;
|
|
56
|
+
if (!(options === null || options === void 0 ? void 0 : options.removeUndefinedValues) && setToOperate.has(undefined)) {
|
|
57
|
+
throw new Error("Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.");
|
|
58
|
+
}
|
|
59
|
+
if (setToOperate.size === 0) {
|
|
60
|
+
if (options === null || options === void 0 ? void 0 : options.convertEmptyValues) {
|
|
61
|
+
return convertToNullAttr();
|
|
62
|
+
}
|
|
63
|
+
throw new Error("Pass a non-empty set, or options.convertEmptyValues=true.");
|
|
64
|
+
}
|
|
65
|
+
var item = setToOperate.values().next().value;
|
|
66
|
+
if (typeof item === "number") {
|
|
67
|
+
return {
|
|
68
|
+
NS: Array.from(setToOperate)
|
|
69
|
+
.map(convertToNumberAttr)
|
|
70
|
+
.map(function (item) { return item.N; }),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
else if (typeof item === "bigint") {
|
|
74
|
+
return {
|
|
75
|
+
NS: Array.from(setToOperate)
|
|
76
|
+
.map(convertToBigIntAttr)
|
|
77
|
+
.map(function (item) { return item.N; }),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
else if (typeof item === "string") {
|
|
81
|
+
return {
|
|
82
|
+
SS: Array.from(setToOperate)
|
|
83
|
+
.map(convertToStringAttr)
|
|
84
|
+
.map(function (item) { return item.S; }),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else if (isBinary(item)) {
|
|
88
|
+
return {
|
|
89
|
+
BS: Array.from(setToOperate)
|
|
90
|
+
.map(convertToBinaryAttr)
|
|
91
|
+
.map(function (item) { return item.B; }),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw new Error("Only Number Set (NS), Binary Set (BS) or String Set (SS) are allowed.");
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var convertToMapAttrFromIterable = function (data, options) { return ({
|
|
99
|
+
M: (function (data) {
|
|
100
|
+
var e_1, _a;
|
|
101
|
+
var map = {};
|
|
102
|
+
try {
|
|
103
|
+
for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
|
|
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);
|
|
114
|
+
}
|
|
115
|
+
finally { if (e_1) throw e_1.error; }
|
|
116
|
+
}
|
|
117
|
+
return map;
|
|
118
|
+
})(data),
|
|
119
|
+
}); };
|
|
120
|
+
var convertToMapAttrFromEnumerableProps = function (data, options) { return ({
|
|
121
|
+
M: (function (data) {
|
|
122
|
+
var map = {};
|
|
123
|
+
for (var key in data) {
|
|
124
|
+
var value = data[key];
|
|
125
|
+
if (typeof value !== "function" && (value !== undefined || !(options === null || options === void 0 ? void 0 : options.removeUndefinedValues))) {
|
|
126
|
+
map[key] = convertToAttr(value, options);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return map;
|
|
130
|
+
})(data),
|
|
131
|
+
}); };
|
|
132
|
+
var convertToNullAttr = function () { return ({ NULL: true }); };
|
|
133
|
+
var convertToBinaryAttr = function (data) { return ({ B: data }); };
|
|
134
|
+
var convertToStringAttr = function (data) { return ({ S: data.toString() }); };
|
|
135
|
+
var convertToBigIntAttr = function (data) { return ({ N: data.toString() }); };
|
|
136
|
+
var validateBigIntAndThrow = function (errorPrefix) {
|
|
137
|
+
throw new Error(errorPrefix + " " + (typeof BigInt === "function" ? "Use BigInt." : "Pass string value instead.") + " ");
|
|
138
|
+
};
|
|
139
|
+
var convertToNumberAttr = function (num) {
|
|
140
|
+
if ([Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]
|
|
141
|
+
.map(function (val) { return val.toString(); })
|
|
142
|
+
.includes(num.toString())) {
|
|
143
|
+
throw new Error("Special numeric value " + num.toString() + " is not allowed");
|
|
144
|
+
}
|
|
145
|
+
else if (num > Number.MAX_SAFE_INTEGER) {
|
|
146
|
+
validateBigIntAndThrow("Number " + num.toString() + " is greater than Number.MAX_SAFE_INTEGER.");
|
|
147
|
+
}
|
|
148
|
+
else if (num < Number.MIN_SAFE_INTEGER) {
|
|
149
|
+
validateBigIntAndThrow("Number " + num.toString() + " is lesser than Number.MIN_SAFE_INTEGER.");
|
|
150
|
+
}
|
|
151
|
+
return { N: num.toString() };
|
|
152
|
+
};
|
|
153
|
+
var isBinary = function (data) {
|
|
154
|
+
var binaryTypes = [
|
|
155
|
+
"ArrayBuffer",
|
|
156
|
+
"Blob",
|
|
157
|
+
"Buffer",
|
|
158
|
+
"DataView",
|
|
159
|
+
"File",
|
|
160
|
+
"Int8Array",
|
|
161
|
+
"Uint8Array",
|
|
162
|
+
"Uint8ClampedArray",
|
|
163
|
+
"Int16Array",
|
|
164
|
+
"Uint16Array",
|
|
165
|
+
"Int32Array",
|
|
166
|
+
"Uint32Array",
|
|
167
|
+
"Float32Array",
|
|
168
|
+
"Float64Array",
|
|
169
|
+
"BigInt64Array",
|
|
170
|
+
"BigUint64Array",
|
|
171
|
+
];
|
|
172
|
+
if (data === null || data === void 0 ? void 0 : data.constructor) {
|
|
173
|
+
return binaryTypes.includes(data.constructor.name);
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { __assign, __read, __values } from "tslib";
|
|
2
|
+
export var convertToNative = function (data, options) {
|
|
3
|
+
var e_1, _a;
|
|
4
|
+
try {
|
|
5
|
+
for (var _b = __values(Object.entries(data)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
6
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
7
|
+
if (value !== undefined) {
|
|
8
|
+
switch (key) {
|
|
9
|
+
case "NULL":
|
|
10
|
+
return null;
|
|
11
|
+
case "BOOL":
|
|
12
|
+
return Boolean(value);
|
|
13
|
+
case "N":
|
|
14
|
+
return convertNumber(value, options);
|
|
15
|
+
case "B":
|
|
16
|
+
return convertBinary(value);
|
|
17
|
+
case "S":
|
|
18
|
+
return convertString(value);
|
|
19
|
+
case "L":
|
|
20
|
+
return convertList(value, options);
|
|
21
|
+
case "M":
|
|
22
|
+
return convertMap(value, options);
|
|
23
|
+
case "NS":
|
|
24
|
+
return new Set(value.map(function (item) { return convertNumber(item, options); }));
|
|
25
|
+
case "BS":
|
|
26
|
+
return new Set(value.map(convertBinary));
|
|
27
|
+
case "SS":
|
|
28
|
+
return new Set(value.map(convertString));
|
|
29
|
+
default:
|
|
30
|
+
throw new Error("Unsupported type passed: " + key);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
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: " + JSON.stringify(data));
|
|
43
|
+
};
|
|
44
|
+
var convertNumber = function (numString, options) {
|
|
45
|
+
if (options === null || options === void 0 ? void 0 : options.wrapNumbers) {
|
|
46
|
+
return { value: numString };
|
|
47
|
+
}
|
|
48
|
+
var num = Number(numString);
|
|
49
|
+
var infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];
|
|
50
|
+
if ((num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) && !infinityValues.includes(num)) {
|
|
51
|
+
if (typeof BigInt === "function") {
|
|
52
|
+
try {
|
|
53
|
+
return BigInt(numString);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new Error(numString + " can't be converted to BigInt. Set options.wrapNumbers to get string value.");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new Error(numString + " is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return num;
|
|
64
|
+
};
|
|
65
|
+
var convertString = function (stringValue) { return stringValue; };
|
|
66
|
+
var convertBinary = function (binaryValue) { return binaryValue; };
|
|
67
|
+
var convertList = function (list, options) {
|
|
68
|
+
return list.map(function (item) { return convertToNative(item, options); });
|
|
69
|
+
};
|
|
70
|
+
var convertMap = function (map, options) {
|
|
71
|
+
return Object.entries(map).reduce(function (acc, _a) {
|
|
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
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/util-dynamodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.36.0",
|
|
4
4
|
"scripts": {
|
|
5
|
+
"build": "yarn build:cjs && yarn build:es && yarn build:types",
|
|
5
6
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
6
7
|
"build:es": "tsc -p tsconfig.es.json",
|
|
7
|
-
"build": "
|
|
8
|
-
"downlevel-dts": "downlevel-dts dist
|
|
8
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
9
|
+
"downlevel-dts": "downlevel-dts dist-types dist-types/ts3.4",
|
|
9
10
|
"test": "jest"
|
|
10
11
|
},
|
|
11
|
-
"main": "./dist
|
|
12
|
-
"module": "./dist
|
|
13
|
-
"types": "./dist
|
|
12
|
+
"main": "./dist-cjs/index.js",
|
|
13
|
+
"module": "./dist-es/index.js",
|
|
14
|
+
"types": "./dist-types/index.d.ts",
|
|
14
15
|
"author": {
|
|
15
16
|
"name": "AWS SDK for JavaScript Team",
|
|
16
17
|
"url": "https://aws.amazon.com/javascript/"
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"tslib": "^2.3.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
24
|
+
"@aws-sdk/client-dynamodb": "3.36.0",
|
|
24
25
|
"@types/jest": "^26.0.4",
|
|
25
26
|
"jest": "^26.1.0",
|
|
26
27
|
"typescript": "~4.3.5"
|
|
@@ -30,11 +31,14 @@
|
|
|
30
31
|
},
|
|
31
32
|
"typesVersions": {
|
|
32
33
|
"<4.0": {
|
|
33
|
-
"dist
|
|
34
|
-
"dist
|
|
34
|
+
"dist-types/*": [
|
|
35
|
+
"dist-types/ts3.4/*"
|
|
35
36
|
]
|
|
36
37
|
}
|
|
37
38
|
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist-*"
|
|
41
|
+
],
|
|
38
42
|
"homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages/util-dynamodb",
|
|
39
43
|
"repository": {
|
|
40
44
|
"type": "git",
|