@aws-sdk/util-dynamodb
Advanced tools
Comparing version
@@ -33,3 +33,7 @@ "use strict"; | ||
// src/NumberValue.ts | ||
var _NumberValue = class _NumberValue { | ||
var NumberValue = class _NumberValue { | ||
static { | ||
__name(this, "NumberValue"); | ||
} | ||
value; | ||
/** | ||
@@ -94,8 +98,5 @@ * This class does not validate that your string input is a valid number. | ||
}; | ||
__name(_NumberValue, "NumberValue"); | ||
var NumberValue = _NumberValue; | ||
// src/convertToAttr.ts | ||
var convertToAttr = /* @__PURE__ */ __name((data, options) => { | ||
var _a, _b, _c, _d, _e, _f; | ||
if (data === void 0) { | ||
@@ -107,17 +108,17 @@ throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`); | ||
return convertToListAttr(data, options); | ||
} else if (((_a = data == null ? void 0 : data.constructor) == null ? void 0 : _a.name) === "Set") { | ||
} else if (data?.constructor?.name === "Set") { | ||
return convertToSetAttr(data, options); | ||
} else if (((_b = data == null ? void 0 : data.constructor) == null ? void 0 : _b.name) === "Map") { | ||
} else if (data?.constructor?.name === "Map") { | ||
return convertToMapAttrFromIterable(data, options); | ||
} 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 | ||
} else if (data?.constructor?.name === "Object" || // for object which is result of Object.create(null), which doesn't have constructor defined | ||
!data.constructor && typeof data === "object") { | ||
return convertToMapAttrFromEnumerableProps(data, options); | ||
} else if (isBinary(data)) { | ||
if (data.length === 0 && (options == null ? void 0 : options.convertEmptyValues)) { | ||
if (data.length === 0 && options?.convertEmptyValues) { | ||
return convertToNullAttr(); | ||
} | ||
return convertToBinaryAttr(data); | ||
} else if (typeof data === "boolean" || ((_d = data == null ? void 0 : data.constructor) == null ? void 0 : _d.name) === "Boolean") { | ||
} else if (typeof data === "boolean" || data?.constructor?.name === "Boolean") { | ||
return { BOOL: data.valueOf() }; | ||
} else if (typeof data === "number" || ((_e = data == null ? void 0 : data.constructor) == null ? void 0 : _e.name) === "Number") { | ||
} else if (typeof data === "number" || data?.constructor?.name === "Number") { | ||
return convertToNumberAttr(data, options); | ||
@@ -128,8 +129,8 @@ } else if (data instanceof NumberValue) { | ||
return convertToBigIntAttr(data); | ||
} else if (typeof data === "string" || ((_f = data == null ? void 0 : data.constructor) == null ? void 0 : _f.name) === "String") { | ||
if (data.length === 0 && (options == null ? void 0 : options.convertEmptyValues)) { | ||
} else if (typeof data === "string" || data?.constructor?.name === "String") { | ||
if (data.length === 0 && options?.convertEmptyValues) { | ||
return convertToNullAttr(); | ||
} | ||
return convertToStringAttr(data); | ||
} else if ((options == null ? void 0 : options.convertClassInstanceToMap) && typeof data === "object") { | ||
} else if (options?.convertClassInstanceToMap && typeof data === "object") { | ||
return convertToMapAttrFromEnumerableProps(data, options); | ||
@@ -143,12 +144,12 @@ } | ||
L: data.filter( | ||
(item) => typeof item !== "function" && (!(options == null ? void 0 : options.removeUndefinedValues) || (options == null ? void 0 : options.removeUndefinedValues) && item !== void 0) | ||
(item) => typeof item !== "function" && (!options?.removeUndefinedValues || options?.removeUndefinedValues && item !== void 0) | ||
).map((item) => convertToAttr(item, options)) | ||
}), "convertToListAttr"); | ||
var convertToSetAttr = /* @__PURE__ */ __name((set, options) => { | ||
const setToOperate = (options == null ? void 0 : options.removeUndefinedValues) ? new Set([...set].filter((value) => value !== void 0)) : set; | ||
if (!(options == null ? void 0 : options.removeUndefinedValues) && setToOperate.has(void 0)) { | ||
const setToOperate = options?.removeUndefinedValues ? new Set([...set].filter((value) => value !== void 0)) : set; | ||
if (!options?.removeUndefinedValues && setToOperate.has(void 0)) { | ||
throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`); | ||
} | ||
if (setToOperate.size === 0) { | ||
if (options == null ? void 0 : options.convertEmptyValues) { | ||
if (options?.convertEmptyValues) { | ||
return convertToNullAttr(); | ||
@@ -189,3 +190,3 @@ } | ||
for (const [key, value] of data2) { | ||
if (typeof value !== "function" && (value !== void 0 || !(options == null ? void 0 : options.removeUndefinedValues))) { | ||
if (typeof value !== "function" && (value !== void 0 || !options?.removeUndefinedValues)) { | ||
map[key] = convertToAttr(value, options); | ||
@@ -202,3 +203,3 @@ } | ||
const value = data2[key]; | ||
if (typeof value !== "function" && (value !== void 0 || !(options == null ? void 0 : options.removeUndefinedValues))) { | ||
if (typeof value !== "function" && (value !== void 0 || !options?.removeUndefinedValues)) { | ||
map[key] = convertToAttr(value, options); | ||
@@ -220,6 +221,6 @@ } | ||
throw new Error(`Special numeric value ${num.toString()} is not allowed`); | ||
} else if (!(options == null ? void 0 : options.allowImpreciseNumbers)) { | ||
if (num > Number.MAX_SAFE_INTEGER) { | ||
} else if (!options?.allowImpreciseNumbers) { | ||
if (Number(num) > Number.MAX_SAFE_INTEGER) { | ||
validateBigIntAndThrow(`Number ${num.toString()} is greater than Number.MAX_SAFE_INTEGER.`); | ||
} else if (num < Number.MIN_SAFE_INTEGER) { | ||
} else if (Number(num) < Number.MIN_SAFE_INTEGER) { | ||
validateBigIntAndThrow(`Number ${num.toString()} is lesser than Number.MIN_SAFE_INTEGER.`); | ||
@@ -249,3 +250,3 @@ } | ||
]; | ||
if (data == null ? void 0 : data.constructor) { | ||
if (data?.constructor) { | ||
return binaryTypes.includes(data.constructor.name); | ||
@@ -289,6 +290,6 @@ } | ||
var convertNumber = /* @__PURE__ */ __name((numString, options) => { | ||
if (typeof (options == null ? void 0 : options.wrapNumbers) === "function") { | ||
return options == null ? void 0 : options.wrapNumbers(numString); | ||
if (typeof options?.wrapNumbers === "function") { | ||
return options?.wrapNumbers(numString); | ||
} | ||
if (options == null ? void 0 : options.wrapNumbers) { | ||
if (options?.wrapNumbers) { | ||
return NumberValue.from(numString); | ||
@@ -327,3 +328,3 @@ } | ||
case "L": | ||
return (options == null ? void 0 : options.convertTopLevelContainer) ? attributeValue : value; | ||
return options?.convertTopLevelContainer ? attributeValue : value; | ||
case "SS": | ||
@@ -346,3 +347,3 @@ case "NS": | ||
var unmarshall = /* @__PURE__ */ __name((data, options) => { | ||
if (options == null ? void 0 : options.convertWithoutMapWrapper) { | ||
if (options?.convertWithoutMapWrapper) { | ||
return convertToNative(data, options); | ||
@@ -349,0 +350,0 @@ } |
@@ -143,6 +143,6 @@ import { NumberValue } from "./NumberValue"; | ||
else if (!options?.allowImpreciseNumbers) { | ||
if (num > Number.MAX_SAFE_INTEGER) { | ||
if (Number(num) > Number.MAX_SAFE_INTEGER) { | ||
validateBigIntAndThrow(`Number ${num.toString()} is greater than Number.MAX_SAFE_INTEGER.`); | ||
} | ||
else if (num < Number.MIN_SAFE_INTEGER) { | ||
else if (Number(num) < Number.MIN_SAFE_INTEGER) { | ||
validateBigIntAndThrow(`Number ${num.toString()} is lesser than Number.MIN_SAFE_INTEGER.`); | ||
@@ -149,0 +149,0 @@ } |
export class NumberValue { | ||
value; | ||
constructor(value) { | ||
@@ -3,0 +4,0 @@ if (typeof value === "object" && "N" in value) { |
{ | ||
"name": "@aws-sdk/util-dynamodb", | ||
"version": "3.721.0", | ||
"version": "3.723.0", | ||
"scripts": { | ||
@@ -28,3 +28,3 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"devDependencies": { | ||
"@aws-sdk/client-dynamodb": "3.721.0", | ||
"@aws-sdk/client-dynamodb": "3.723.0", | ||
"@tsconfig/recommended": "1.0.1", | ||
@@ -34,9 +34,9 @@ "concurrently": "7.0.0", | ||
"rimraf": "3.0.2", | ||
"typescript": "~4.9.5" | ||
"typescript": "~5.2.2" | ||
}, | ||
"peerDependencies": { | ||
"@aws-sdk/client-dynamodb": "^3.721.0" | ||
"@aws-sdk/client-dynamodb": "^3.723.0" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0" | ||
"node": ">=18.0.0" | ||
}, | ||
@@ -43,0 +43,0 @@ "typesVersions": { |
1104
0.18%54482
-1.41%