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/.prettierignore +112 -0
- package/.prettierrc +11 -0
- package/README.md +55 -47
- package/index.d.ts +5288 -2409
- package/index.js +24 -12
- package/package.json +19 -11
- package/src/clauses.js +1557 -1310
- package/src/client.js +255 -235
- package/src/entity.js +4512 -3737
- package/src/errors.js +39 -28
- package/src/events.js +26 -16
- package/src/filterOperations.js +120 -122
- package/src/filters.js +99 -101
- package/src/operations.js +326 -263
- package/src/schema.js +1825 -1473
- package/src/service.js +1081 -852
- package/src/set.js +22 -26
- package/src/transaction.js +179 -153
- package/src/types.js +260 -264
- package/src/update.js +94 -90
- package/src/updateOperations.js +179 -160
- package/src/util.js +45 -32
- package/src/validations.js +337 -325
- package/src/where.js +146 -124
- package/tsconfig.json +12 -11
package/src/errors.js
CHANGED
|
@@ -65,31 +65,31 @@ const ErrorCodes = {
|
|
|
65
65
|
code: 1009,
|
|
66
66
|
section: "invalid-model",
|
|
67
67
|
name: "InvalidModel",
|
|
68
|
-
sym: ErrorCode
|
|
68
|
+
sym: ErrorCode,
|
|
69
69
|
},
|
|
70
70
|
InvalidOptions: {
|
|
71
71
|
code: 1010,
|
|
72
72
|
section: "invalid-options",
|
|
73
73
|
name: "InvalidOptions",
|
|
74
|
-
sym: ErrorCode
|
|
74
|
+
sym: ErrorCode,
|
|
75
75
|
},
|
|
76
76
|
InvalidFilter: {
|
|
77
77
|
code: 1011,
|
|
78
78
|
section: "filters",
|
|
79
79
|
name: "InvalidFilter",
|
|
80
|
-
sym: ErrorCode
|
|
80
|
+
sym: ErrorCode,
|
|
81
81
|
},
|
|
82
82
|
InvalidWhere: {
|
|
83
83
|
code: 1012,
|
|
84
84
|
section: "where",
|
|
85
85
|
name: "InvalidWhere",
|
|
86
|
-
sym: ErrorCode
|
|
86
|
+
sym: ErrorCode,
|
|
87
87
|
},
|
|
88
88
|
InvalidJoin: {
|
|
89
89
|
code: 1013,
|
|
90
90
|
section: "join",
|
|
91
91
|
name: "InvalidJoin",
|
|
92
|
-
sym: ErrorCode
|
|
92
|
+
sym: ErrorCode,
|
|
93
93
|
},
|
|
94
94
|
DuplicateIndexFields: {
|
|
95
95
|
code: 1014,
|
|
@@ -107,7 +107,7 @@ const ErrorCodes = {
|
|
|
107
107
|
code: 1016,
|
|
108
108
|
section: "invalid-attribute-watch-definition",
|
|
109
109
|
name: "InvalidAttributeWatchDefinition",
|
|
110
|
-
sym: ErrorCode
|
|
110
|
+
sym: ErrorCode,
|
|
111
111
|
},
|
|
112
112
|
IncompatibleKeyCompositeAttributeTemplate: {
|
|
113
113
|
code: 1017,
|
|
@@ -167,13 +167,13 @@ const ErrorCodes = {
|
|
|
167
167
|
code: 2003,
|
|
168
168
|
section: "missing-table",
|
|
169
169
|
name: "MissingTable",
|
|
170
|
-
sym: ErrorCode
|
|
170
|
+
sym: ErrorCode,
|
|
171
171
|
},
|
|
172
172
|
InvalidConcurrencyOption: {
|
|
173
173
|
code: 2004,
|
|
174
174
|
section: "invalid-concurrency-option",
|
|
175
175
|
name: "InvalidConcurrencyOption",
|
|
176
|
-
sym: ErrorCode
|
|
176
|
+
sym: ErrorCode,
|
|
177
177
|
},
|
|
178
178
|
InvalidPagesOption: {
|
|
179
179
|
code: 2005,
|
|
@@ -215,7 +215,7 @@ const ErrorCodes = {
|
|
|
215
215
|
code: 3001,
|
|
216
216
|
section: "invalid-attribute",
|
|
217
217
|
name: "InvalidAttribute",
|
|
218
|
-
sym: ErrorCode
|
|
218
|
+
sym: ErrorCode,
|
|
219
219
|
},
|
|
220
220
|
AWSError: {
|
|
221
221
|
code: 4001,
|
|
@@ -233,7 +233,7 @@ const ErrorCodes = {
|
|
|
233
233
|
code: 5002,
|
|
234
234
|
section: "",
|
|
235
235
|
name: "GeneralError",
|
|
236
|
-
sym: ErrorCode
|
|
236
|
+
sym: ErrorCode,
|
|
237
237
|
},
|
|
238
238
|
LastEvaluatedKey: {
|
|
239
239
|
code: 5003,
|
|
@@ -258,19 +258,21 @@ const ErrorCodes = {
|
|
|
258
258
|
section: "pager-not-unique",
|
|
259
259
|
name: "NoOwnerForPager",
|
|
260
260
|
sym: ErrorCode,
|
|
261
|
-
}
|
|
261
|
+
},
|
|
262
262
|
};
|
|
263
263
|
|
|
264
264
|
function makeMessage(message, section) {
|
|
265
|
-
return `${message} - For more detail on this error reference: ${getHelpLink(
|
|
265
|
+
return `${message} - For more detail on this error reference: ${getHelpLink(
|
|
266
|
+
section,
|
|
267
|
+
)}`;
|
|
266
268
|
}
|
|
267
269
|
|
|
268
270
|
class ElectroError extends Error {
|
|
269
|
-
constructor(code, message) {
|
|
270
|
-
super(message);
|
|
271
|
+
constructor(code, message, cause) {
|
|
272
|
+
super(message, { cause });
|
|
271
273
|
let detail = ErrorCodes.UnknownError;
|
|
272
274
|
if (code && code.sym === ErrorCode) {
|
|
273
|
-
detail = code
|
|
275
|
+
detail = code;
|
|
274
276
|
}
|
|
275
277
|
this._message = message;
|
|
276
278
|
// this.message = `${message} - For more detail on this error reference: ${getHelpLink(detail.section)}`;
|
|
@@ -279,7 +281,7 @@ class ElectroError extends Error {
|
|
|
279
281
|
Error.captureStackTrace(this, ElectroError);
|
|
280
282
|
}
|
|
281
283
|
|
|
282
|
-
this.name =
|
|
284
|
+
this.name = "ElectroError";
|
|
283
285
|
this.ref = code;
|
|
284
286
|
this.code = detail.code;
|
|
285
287
|
this.date = Date.now();
|
|
@@ -293,7 +295,7 @@ class ElectroValidationError extends ElectroError {
|
|
|
293
295
|
const messages = [];
|
|
294
296
|
for (let i = 0; i < errors.length; i++) {
|
|
295
297
|
const error = errors[i];
|
|
296
|
-
const message = error ?
|
|
298
|
+
const message = error ? error._message || error.message : undefined;
|
|
297
299
|
messages.push(message);
|
|
298
300
|
if (error instanceof ElectroUserValidationError) {
|
|
299
301
|
fields.push({
|
|
@@ -301,7 +303,7 @@ class ElectroValidationError extends ElectroError {
|
|
|
301
303
|
index: error.index,
|
|
302
304
|
reason: message,
|
|
303
305
|
cause: error.cause,
|
|
304
|
-
type:
|
|
306
|
+
type: "validation",
|
|
305
307
|
});
|
|
306
308
|
} else if (error instanceof ElectroAttributeValidationError) {
|
|
307
309
|
fields.push({
|
|
@@ -309,22 +311,23 @@ class ElectroValidationError extends ElectroError {
|
|
|
309
311
|
index: error.index,
|
|
310
312
|
reason: message,
|
|
311
313
|
cause: error.cause || error, // error | undefined
|
|
312
|
-
type:
|
|
314
|
+
type: "validation",
|
|
313
315
|
});
|
|
314
316
|
} else if (message) {
|
|
315
317
|
fields.push({
|
|
316
|
-
field:
|
|
318
|
+
field: "",
|
|
317
319
|
index: error.index,
|
|
318
320
|
reason: message,
|
|
319
321
|
cause: error !== undefined ? error.cause || error : undefined,
|
|
320
|
-
type:
|
|
322
|
+
type: "fatal",
|
|
321
323
|
});
|
|
322
324
|
}
|
|
323
325
|
}
|
|
324
326
|
|
|
325
|
-
const message =
|
|
326
|
-
|
|
327
|
-
.
|
|
327
|
+
const message =
|
|
328
|
+
messages
|
|
329
|
+
.filter((message) => typeof message === "string" && message.length)
|
|
330
|
+
.join(", ") || `Invalid value(s) provided`;
|
|
328
331
|
|
|
329
332
|
super(ErrorCodes.InvalidAttribute, message);
|
|
330
333
|
this.fields = fields;
|
|
@@ -338,14 +341,22 @@ class ElectroUserValidationError extends ElectroError {
|
|
|
338
341
|
let hasCause = false;
|
|
339
342
|
if (typeof cause === "string") {
|
|
340
343
|
message = cause;
|
|
341
|
-
} else if (
|
|
344
|
+
} else if (
|
|
345
|
+
cause !== undefined &&
|
|
346
|
+
typeof cause._message === "string" &&
|
|
347
|
+
cause._message.length
|
|
348
|
+
) {
|
|
342
349
|
message = cause._message;
|
|
343
350
|
hasCause = true;
|
|
344
|
-
} else if (
|
|
351
|
+
} else if (
|
|
352
|
+
cause !== undefined &&
|
|
353
|
+
typeof cause.message === "string" &&
|
|
354
|
+
cause.message.length
|
|
355
|
+
) {
|
|
345
356
|
message = cause.message;
|
|
346
357
|
hasCause = true;
|
|
347
358
|
} else {
|
|
348
|
-
|
|
359
|
+
message = "Invalid value provided";
|
|
349
360
|
}
|
|
350
361
|
super(ErrorCodes.InvalidAttribute, message);
|
|
351
362
|
this.field = field;
|
|
@@ -368,5 +379,5 @@ module.exports = {
|
|
|
368
379
|
ElectroError,
|
|
369
380
|
ElectroValidationError,
|
|
370
381
|
ElectroUserValidationError,
|
|
371
|
-
ElectroAttributeValidationError
|
|
382
|
+
ElectroAttributeValidationError,
|
|
372
383
|
};
|
package/src/events.js
CHANGED
|
@@ -1,42 +1,52 @@
|
|
|
1
1
|
const e = require("./errors");
|
|
2
|
-
const v = require(
|
|
2
|
+
const v = require("./validations");
|
|
3
3
|
|
|
4
4
|
class EventManager {
|
|
5
5
|
static createSafeListener(listener) {
|
|
6
6
|
if (listener === undefined) {
|
|
7
7
|
return undefined;
|
|
8
|
-
}
|
|
9
|
-
|
|
8
|
+
}
|
|
9
|
+
if (!v.isFunction(listener)) {
|
|
10
|
+
throw new e.ElectroError(
|
|
11
|
+
e.ErrorCodes.InvalidListenerProvided,
|
|
12
|
+
`Provided listener is not of type 'function'`,
|
|
13
|
+
);
|
|
10
14
|
} else {
|
|
11
15
|
return (...params) => {
|
|
12
16
|
try {
|
|
13
17
|
listener(...params);
|
|
14
|
-
} catch(err) {
|
|
18
|
+
} catch (err) {
|
|
15
19
|
console.error(`Error invoking user supplied listener`, err);
|
|
16
20
|
}
|
|
17
|
-
}
|
|
21
|
+
};
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
static normalizeListeners(listeners = []) {
|
|
22
26
|
if (!Array.isArray(listeners)) {
|
|
23
|
-
throw new e.ElectroError(
|
|
27
|
+
throw new e.ElectroError(
|
|
28
|
+
e.ErrorCodes.InvalidListenerProvided,
|
|
29
|
+
`Listeners must be provided as an array of functions`,
|
|
30
|
+
);
|
|
24
31
|
}
|
|
25
32
|
return listeners
|
|
26
|
-
.map(listener => EventManager.createSafeListener(listener))
|
|
27
|
-
.filter(listener => {
|
|
33
|
+
.map((listener) => EventManager.createSafeListener(listener))
|
|
34
|
+
.filter((listener) => {
|
|
28
35
|
switch (typeof listener) {
|
|
29
|
-
case
|
|
36
|
+
case "function":
|
|
30
37
|
return true;
|
|
31
|
-
case
|
|
38
|
+
case "undefined":
|
|
32
39
|
return false;
|
|
33
40
|
default:
|
|
34
|
-
throw new e.ElectroError(
|
|
41
|
+
throw new e.ElectroError(
|
|
42
|
+
e.ErrorCodes.InvalidListenerProvided,
|
|
43
|
+
`Provided listener is not of type 'function`,
|
|
44
|
+
);
|
|
35
45
|
}
|
|
36
46
|
});
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
constructor({listeners = []} = {}) {
|
|
49
|
+
constructor({ listeners = [] } = {}) {
|
|
40
50
|
this.listeners = EventManager.normalizeListeners(listeners);
|
|
41
51
|
}
|
|
42
52
|
|
|
@@ -46,14 +56,14 @@ class EventManager {
|
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
this.listeners = this.listeners.concat(
|
|
49
|
-
EventManager.normalizeListeners(listeners)
|
|
59
|
+
EventManager.normalizeListeners(listeners),
|
|
50
60
|
);
|
|
51
61
|
}
|
|
52
62
|
|
|
53
63
|
trigger(event, adHocListeners = []) {
|
|
54
64
|
const allListeners = [
|
|
55
65
|
...this.listeners,
|
|
56
|
-
...EventManager.normalizeListeners(adHocListeners)
|
|
66
|
+
...EventManager.normalizeListeners(adHocListeners),
|
|
57
67
|
];
|
|
58
68
|
|
|
59
69
|
for (const listener of allListeners) {
|
|
@@ -63,5 +73,5 @@ class EventManager {
|
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
module.exports = {
|
|
66
|
-
EventManager
|
|
67
|
-
};
|
|
76
|
+
EventManager,
|
|
77
|
+
};
|
package/src/filterOperations.js
CHANGED
|
@@ -1,126 +1,124 @@
|
|
|
1
1
|
const FilterOperations = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
rawField: true,
|
|
121
|
-
}
|
|
2
|
+
escape: {
|
|
3
|
+
template: function escape(options, attr) {
|
|
4
|
+
return `${attr}`;
|
|
5
|
+
},
|
|
6
|
+
rawValue: true,
|
|
7
|
+
},
|
|
8
|
+
size: {
|
|
9
|
+
template: function size(options, attr, name) {
|
|
10
|
+
return `size(${name})`;
|
|
11
|
+
},
|
|
12
|
+
strict: false,
|
|
13
|
+
},
|
|
14
|
+
type: {
|
|
15
|
+
template: function attributeType(options, attr, name, value) {
|
|
16
|
+
return `attribute_type(${name}, ${value})`;
|
|
17
|
+
},
|
|
18
|
+
strict: false,
|
|
19
|
+
},
|
|
20
|
+
ne: {
|
|
21
|
+
template: function ne(options, attr, name, value) {
|
|
22
|
+
return `${name} <> ${value}`;
|
|
23
|
+
},
|
|
24
|
+
strict: false,
|
|
25
|
+
},
|
|
26
|
+
eq: {
|
|
27
|
+
template: function eq(options, attr, name, value) {
|
|
28
|
+
return `${name} = ${value}`;
|
|
29
|
+
},
|
|
30
|
+
strict: false,
|
|
31
|
+
},
|
|
32
|
+
gt: {
|
|
33
|
+
template: function gt(options, attr, name, value) {
|
|
34
|
+
return `${name} > ${value}`;
|
|
35
|
+
},
|
|
36
|
+
strict: false,
|
|
37
|
+
},
|
|
38
|
+
lt: {
|
|
39
|
+
template: function lt(options, attr, name, value) {
|
|
40
|
+
return `${name} < ${value}`;
|
|
41
|
+
},
|
|
42
|
+
strict: false,
|
|
43
|
+
},
|
|
44
|
+
gte: {
|
|
45
|
+
template: function gte(options, attr, name, value) {
|
|
46
|
+
return `${name} >= ${value}`;
|
|
47
|
+
},
|
|
48
|
+
strict: false,
|
|
49
|
+
},
|
|
50
|
+
lte: {
|
|
51
|
+
template: function lte(options, attr, name, value) {
|
|
52
|
+
return `${name} <= ${value}`;
|
|
53
|
+
},
|
|
54
|
+
strict: false,
|
|
55
|
+
},
|
|
56
|
+
between: {
|
|
57
|
+
template: function between(options, attr, name, value1, value2) {
|
|
58
|
+
return `(${name} between ${value1} and ${value2})`;
|
|
59
|
+
},
|
|
60
|
+
strict: false,
|
|
61
|
+
},
|
|
62
|
+
begins: {
|
|
63
|
+
template: function begins(options, attr, name, value) {
|
|
64
|
+
return `begins_with(${name}, ${value})`;
|
|
65
|
+
},
|
|
66
|
+
strict: false,
|
|
67
|
+
},
|
|
68
|
+
exists: {
|
|
69
|
+
template: function exists(options, attr, name) {
|
|
70
|
+
return `attribute_exists(${name})`;
|
|
71
|
+
},
|
|
72
|
+
strict: false,
|
|
73
|
+
},
|
|
74
|
+
notExists: {
|
|
75
|
+
template: function notExists(options, attr, name) {
|
|
76
|
+
return `attribute_not_exists(${name})`;
|
|
77
|
+
},
|
|
78
|
+
strict: false,
|
|
79
|
+
},
|
|
80
|
+
contains: {
|
|
81
|
+
template: function contains(options, attr, name, value) {
|
|
82
|
+
return `contains(${name}, ${value})`;
|
|
83
|
+
},
|
|
84
|
+
strict: false,
|
|
85
|
+
},
|
|
86
|
+
notContains: {
|
|
87
|
+
template: function notContains(options, attr, name, value) {
|
|
88
|
+
return `not contains(${name}, ${value})`;
|
|
89
|
+
},
|
|
90
|
+
strict: false,
|
|
91
|
+
},
|
|
92
|
+
value: {
|
|
93
|
+
template: function (options, attr, name, value) {
|
|
94
|
+
return value;
|
|
95
|
+
},
|
|
96
|
+
strict: false,
|
|
97
|
+
canNest: true,
|
|
98
|
+
},
|
|
99
|
+
name: {
|
|
100
|
+
template: function (options, attr, name) {
|
|
101
|
+
return name;
|
|
102
|
+
},
|
|
103
|
+
strict: false,
|
|
104
|
+
canNest: true,
|
|
105
|
+
},
|
|
106
|
+
eqOrNotExists: {
|
|
107
|
+
template: function eq(options, attr, name, value) {
|
|
108
|
+
return `(${name} = ${value} OR attribute_not_exists(${name}))`;
|
|
109
|
+
},
|
|
110
|
+
strict: false,
|
|
111
|
+
},
|
|
112
|
+
field: {
|
|
113
|
+
template: function (options, _, fieldName) {
|
|
114
|
+
return fieldName !== undefined ? `${fieldName}` : "";
|
|
115
|
+
},
|
|
116
|
+
strict: false,
|
|
117
|
+
canNest: true,
|
|
118
|
+
rawField: true,
|
|
119
|
+
},
|
|
122
120
|
};
|
|
123
121
|
|
|
124
122
|
module.exports = {
|
|
125
|
-
|
|
126
|
-
}
|
|
123
|
+
FilterOperations,
|
|
124
|
+
};
|