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