electrodb 2.10.0 → 2.10.2

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/src/util.js CHANGED
@@ -8,7 +8,7 @@ function parseJSONPath(path = "") {
8
8
  }
9
9
  path = path.replace(/\[/g, ".");
10
10
  path = path.replace(/\]/g, "");
11
- return path.split(".").filter(part => part !== '');
11
+ return path.split(".").filter((part) => part !== "");
12
12
  }
13
13
 
14
14
  function genericizeJSONPath(path = "") {
@@ -34,9 +34,10 @@ function getInstanceType(instance = {}) {
34
34
 
35
35
  function getModelVersion(model = {}) {
36
36
  let nameOnRoot = model && v.isStringHasLength(model.entity);
37
- let nameInModelNamespace = model && model.model && v.isStringHasLength(model.model.entity);
37
+ let nameInModelNamespace =
38
+ model && model.model && v.isStringHasLength(model.model.entity);
38
39
  if (nameInModelNamespace) {
39
- return t.ModelVersions.v1
40
+ return t.ModelVersions.v1;
40
41
  } else if (nameOnRoot) {
41
42
  return t.ModelVersions.beta;
42
43
  } else {
@@ -44,7 +45,10 @@ function getModelVersion(model = {}) {
44
45
  }
45
46
  }
46
47
 
47
- function applyBetaModelOverrides(model = {}, {service = "", version = "", table = ""} = {}) {
48
+ function applyBetaModelOverrides(
49
+ model = {},
50
+ { service = "", version = "", table = "" } = {},
51
+ ) {
48
52
  let type = getModelVersion(model);
49
53
  if (type !== t.ModelVersions.beta) {
50
54
  throw new Error("Invalid model");
@@ -76,7 +80,7 @@ function batchItems(arr = [], size) {
76
80
  }
77
81
 
78
82
  function commaSeparatedString(array = [], prefix = '"', postfix = '"') {
79
- return array.map(value => `${prefix}${value}${postfix}`).join(", ");
83
+ return array.map((value) => `${prefix}${value}${postfix}`).join(", ");
80
84
  }
81
85
 
82
86
  function formatStringCasing(str, casing, defaultCase) {
@@ -85,9 +89,8 @@ function formatStringCasing(str, casing, defaultCase) {
85
89
  }
86
90
  let strCase = defaultCase;
87
91
  if (v.isStringHasLength(casing) && typeof t.KeyCasing[casing] === "string") {
88
- strCase = t.KeyCasing.default === casing
89
- ? defaultCase
90
- : t.KeyCasing[casing];
92
+ strCase =
93
+ t.KeyCasing.default === casing ? defaultCase : t.KeyCasing[casing];
91
94
  }
92
95
  switch (strCase) {
93
96
  case t.KeyCasing.upper:
@@ -144,7 +147,12 @@ class BatchGetOrderMaintainer {
144
147
  if (this.enabled) {
145
148
  for (let i = 0; i < parameters.length; i++) {
146
149
  const batchParams = parameters[i];
147
- const recordKeys = (batchParams && batchParams.RequestItems && batchParams.RequestItems[this.table] && batchParams.RequestItems[this.table].Keys) || [];
150
+ const recordKeys =
151
+ (batchParams &&
152
+ batchParams.RequestItems &&
153
+ batchParams.RequestItems[this.table] &&
154
+ batchParams.RequestItems[this.table].Keys) ||
155
+ [];
148
156
  for (const recordKey of recordKeys) {
149
157
  const indexMapKey = this.keyFormatter(recordKey);
150
158
  this.batchIndexMap.set(indexMapKey, this.currentSlot++);
@@ -155,40 +163,45 @@ class BatchGetOrderMaintainer {
155
163
  }
156
164
 
157
165
  function getUnique(arr1, arr2) {
158
- return Array.from(new Set([
159
- ...arr1,
160
- ...arr2
161
- ]));
166
+ return Array.from(new Set([...arr1, ...arr2]));
162
167
  }
163
168
 
164
169
  const cursorFormatter = {
165
170
  serialize: (key) => {
166
171
  if (!key) {
167
172
  return null;
168
- } else if (typeof val !== 'string') {
173
+ } else if (typeof val !== "string") {
169
174
  key = JSON.stringify(key);
170
175
  }
171
- return Buffer.from(key).toString('base64url');
176
+ return Buffer.from(key).toString("base64url");
172
177
  },
173
178
  deserialize: (cursor) => {
174
179
  if (!cursor) {
175
180
  return undefined;
176
- } else if (typeof cursor !== 'string') {
177
- throw new Error(`Invalid cursor provided, expected type 'string' recieved: ${JSON.stringify(cursor)}`);
181
+ } else if (typeof cursor !== "string") {
182
+ throw new Error(
183
+ `Invalid cursor provided, expected type 'string' recieved: ${JSON.stringify(
184
+ cursor,
185
+ )}`,
186
+ );
178
187
  }
179
188
  try {
180
- return JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
181
- } catch(err) {
182
- throw new Error('Unable to parse cursor');
189
+ return JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
190
+ } catch (err) {
191
+ throw new Error("Unable to parse cursor");
183
192
  }
184
- }
185
- }
193
+ },
194
+ };
186
195
 
187
- function removeFixings({prefix = '', postfix = '', value = ''} = {}) {
188
- const start = value.toLowerCase().startsWith(prefix.toLowerCase()) ? prefix.length : 0;
189
- const end = value.length - (value.toLowerCase().endsWith(postfix.toLowerCase()) ? postfix.length : 0);
196
+ function removeFixings({ prefix = "", postfix = "", value = "" } = {}) {
197
+ const start = value.toLowerCase().startsWith(prefix.toLowerCase())
198
+ ? prefix.length
199
+ : 0;
200
+ const end =
201
+ value.length -
202
+ (value.toLowerCase().endsWith(postfix.toLowerCase()) ? postfix.length : 0);
190
203
 
191
- let formatted = '';
204
+ let formatted = "";
192
205
  for (let i = start; i < end; i++) {
193
206
  formatted += value[i];
194
207
  }
@@ -196,16 +209,16 @@ function removeFixings({prefix = '', postfix = '', value = ''} = {}) {
196
209
  return formatted;
197
210
  }
198
211
 
199
- function addPadding({padding = {}, value = ''} = {}) {
212
+ function addPadding({ padding = {}, value = "" } = {}) {
200
213
  return value.padStart(padding.length, padding.char);
201
214
  }
202
215
 
203
- function removePadding({padding = {}, value = ''} = {}) {
216
+ function removePadding({ padding = {}, value = "" } = {}) {
204
217
  if (!padding.length || value.length >= padding.length) {
205
218
  return value;
206
219
  }
207
220
 
208
- let formatted = '';
221
+ let formatted = "";
209
222
  let useRemaining = false;
210
223
  for (let i = 0; i < value.length; i++) {
211
224
  const char = value[i];
@@ -220,8 +233,8 @@ function removePadding({padding = {}, value = ''} = {}) {
220
233
  return formatted;
221
234
  }
222
235
 
223
- function shiftSortOrder(str = '', codePoint) {
224
- let newString = '';
236
+ function shiftSortOrder(str = "", codePoint) {
237
+ let newString = "";
225
238
  for (let i = 0; i < str.length; i++) {
226
239
  const isLast = i === str.length - 1;
227
240
  let char = str[i];
@@ -234,7 +247,7 @@ function shiftSortOrder(str = '', codePoint) {
234
247
  }
235
248
 
236
249
  function getFirstDefined(...params) {
237
- return params.find(val => val !== undefined);
250
+ return params.find((val) => val !== undefined);
238
251
  }
239
252
 
240
253
  function regexpEscape(str) {