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