@aws-sdk/util-dynamodb 3.181.0 → 3.185.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 CHANGED
@@ -3,6 +3,22 @@
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.185.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.184.0...v3.185.0) (2022-10-05)
7
+
8
+ **Note:** Version bump only for package @aws-sdk/util-dynamodb
9
+
10
+
11
+
12
+
13
+
14
+ # [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
15
+
16
+ **Note:** Version bump only for package @aws-sdk/util-dynamodb
17
+
18
+
19
+
20
+
21
+
6
22
  # [3.181.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.180.0...v3.181.0) (2022-09-29)
7
23
 
8
24
  **Note:** Version bump only for package @aws-sdk/util-dynamodb
@@ -1,8 +1,6 @@
1
- import { __read, __spreadArray, __values } from "tslib";
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("Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.");
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 (((_a = data === null || data === void 0 ? void 0 : data.constructor) === null || _a === void 0 ? void 0 : _a.name) === "Set") {
11
+ else if (data?.constructor?.name === "Set") {
14
12
  return convertToSetAttr(data, options);
15
13
  }
16
- else if (((_b = data === null || data === void 0 ? void 0 : data.constructor) === null || _b === void 0 ? void 0 : _b.name) === "Map") {
14
+ else if (data?.constructor?.name === "Map") {
17
15
  return convertToMapAttrFromIterable(data, options);
18
16
  }
19
- else if (((_c = data === null || data === void 0 ? void 0 : data.constructor) === null || _c === void 0 ? void 0 : _c.name) === "Object" ||
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 && (options === null || options === void 0 ? void 0 : options.convertEmptyValues)) {
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" || ((_d = data === null || data === void 0 ? void 0 : data.constructor) === null || _d === void 0 ? void 0 : _d.name) === "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" || ((_e = data === null || data === void 0 ? void 0 : data.constructor) === null || _e === void 0 ? void 0 : _e.name) === "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" || ((_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)) {
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 ((options === null || options === void 0 ? void 0 : options.convertClassInstanceToMap) && typeof data === "object") {
42
+ else if (options?.convertClassInstanceToMap && typeof data === "object") {
45
43
  return convertToMapAttrFromEnumerableProps(data, options);
46
44
  }
47
- throw new Error("Unsupported type passed: ".concat(data, ". Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute."));
45
+ throw new Error(`Unsupported type passed: ${data}. Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.`);
48
46
  };
49
- var convertToListAttr = function (data, options) { return ({
47
+ const convertToListAttr = (data, options) => ({
50
48
  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), false).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.");
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 === null || options === void 0 ? void 0 : options.convertEmptyValues) {
58
+ if (options?.convertEmptyValues) {
61
59
  return convertToNullAttr();
62
60
  }
63
- throw new Error("Pass a non-empty set, or options.convertEmptyValues=true.");
61
+ throw new Error(`Pass a non-empty set, or options.convertEmptyValues=true.`);
64
62
  }
65
- var item = setToOperate.values().next().value;
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(function (item) { return item.N; }),
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(function (item) { return item.N; }),
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(function (item) { return item.S; }),
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(function (item) { return item.B; }),
89
+ .map((item) => item.B),
92
90
  };
93
91
  }
94
92
  else {
95
- throw new Error("Only Number Set (NS), Binary Set (BS) or String Set (SS) are allowed.");
93
+ throw new Error(`Only Number Set (NS), Binary Set (BS) or String Set (SS) are allowed.`);
96
94
  }
97
95
  };
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);
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
- 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))) {
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
- 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("".concat(errorPrefix, " ").concat(typeof BigInt === "function" ? "Use BigInt." : "Pass string value instead.", " "));
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
- var convertToNumberAttr = function (num) {
126
+ const convertToNumberAttr = (num) => {
140
127
  if ([Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]
141
- .map(function (val) { return val.toString(); })
128
+ .map((val) => val.toString())
142
129
  .includes(num.toString())) {
143
- throw new Error("Special numeric value ".concat(num.toString(), " is not allowed"));
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("Number ".concat(num.toString(), " is greater than Number.MAX_SAFE_INTEGER."));
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("Number ".concat(num.toString(), " is lesser than Number.MIN_SAFE_INTEGER."));
136
+ validateBigIntAndThrow(`Number ${num.toString()} is lesser than Number.MIN_SAFE_INTEGER.`);
150
137
  }
151
138
  return { N: num.toString() };
152
139
  };
153
- var isBinary = function (data) {
154
- var binaryTypes = [
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 === null || data === void 0 ? void 0 : data.constructor) {
159
+ if (data?.constructor) {
173
160
  return binaryTypes.includes(data.constructor.name);
174
161
  }
175
162
  return false;
@@ -1,76 +1,59 @@
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: ".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
- 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: ".concat(JSON.stringify(data)));
30
+ throw new Error(`No value defined: ${JSON.stringify(data)}`);
43
31
  };
44
- var convertNumber = function (numString, options) {
45
- if (options === null || options === void 0 ? void 0 : options.wrapNumbers) {
32
+ const convertNumber = (numString, options) => {
33
+ if (options?.wrapNumbers) {
46
34
  return { value: numString };
47
35
  }
48
- var num = Number(numString);
49
- var infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];
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("".concat(numString, " can't be converted to BigInt. Set options.wrapNumbers to get string value."));
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("".concat(numString, " is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value."));
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
- 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
- };
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
+ }), {});
@@ -1,8 +1,7 @@
1
- import { __read } from "tslib";
2
1
  import { convertToAttr } from "./convertToAttr";
3
2
  export function marshall(data, options) {
4
- var attributeValue = convertToAttr(data, options);
5
- var _a = __read(Object.entries(attributeValue)[0], 2), key = _a[0], value = _a[1];
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":
@@ -1,4 +1,2 @@
1
1
  import { convertToNative } from "./convertToNative";
2
- export var unmarshall = function (data, options) {
3
- return convertToNative({ M: data }, options);
4
- };
2
+ export const unmarshall = (data, options) => convertToNative({ M: data }, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/util-dynamodb",
3
- "version": "3.181.0",
3
+ "version": "3.185.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.181.0",
26
+ "@aws-sdk/client-dynamodb": "3.185.0",
27
27
  "@tsconfig/recommended": "1.0.1",
28
28
  "concurrently": "7.0.0",
29
29
  "downlevel-dts": "0.10.1",