electrodb 3.0.0 → 3.1.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/index.d.ts +3 -2
- package/package.json +1 -1
- package/src/entity.js +15 -7
- package/src/errors.js +14 -1
package/index.d.ts
CHANGED
|
@@ -2935,9 +2935,10 @@ export class ElectroError<E extends Error = Error> extends Error {
|
|
|
2935
2935
|
readonly name: "ElectroError";
|
|
2936
2936
|
readonly code: number;
|
|
2937
2937
|
readonly date: number;
|
|
2938
|
-
readonly isElectroError: boolean;
|
|
2939
2938
|
readonly cause: E | undefined;
|
|
2940
|
-
|
|
2939
|
+
readonly isElectroError: boolean;
|
|
2940
|
+
readonly params: <T = Record<string, unknown>>() => T | null;
|
|
2941
|
+
readonly ref: {
|
|
2941
2942
|
readonly code: number;
|
|
2942
2943
|
readonly section: string;
|
|
2943
2944
|
readonly name: string;
|
package/package.json
CHANGED
package/src/entity.js
CHANGED
|
@@ -466,8 +466,10 @@ class Entity {
|
|
|
466
466
|
if (err.__isAWSError) {
|
|
467
467
|
stackTrace.message = `Error thrown by DynamoDB client: "${err.message}" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error`;
|
|
468
468
|
stackTrace.cause = err;
|
|
469
|
+
e.applyParamsFn(stackTrace, err.__edb_params);
|
|
469
470
|
return Promise.reject(stackTrace);
|
|
470
471
|
} else if (err.isElectroError) {
|
|
472
|
+
e.applyParamsFn(err, err.__edb_params);
|
|
471
473
|
return Promise.reject(err);
|
|
472
474
|
} else {
|
|
473
475
|
stackTrace.message = new e.ElectroError(
|
|
@@ -475,6 +477,7 @@ class Entity {
|
|
|
475
477
|
err.message,
|
|
476
478
|
err,
|
|
477
479
|
).message;
|
|
480
|
+
e.applyParamsFn(stackTrace, err.__edb_params);
|
|
478
481
|
return Promise.reject(stackTrace);
|
|
479
482
|
}
|
|
480
483
|
}
|
|
@@ -516,6 +519,10 @@ class Entity {
|
|
|
516
519
|
.catch((err) => {
|
|
517
520
|
notifyQuery();
|
|
518
521
|
notifyResults(err, false);
|
|
522
|
+
Object.defineProperty(err, '__edb_params', {
|
|
523
|
+
enumerable: false,
|
|
524
|
+
value: params,
|
|
525
|
+
});
|
|
519
526
|
err.__isAWSError = true;
|
|
520
527
|
throw err;
|
|
521
528
|
});
|
|
@@ -935,7 +942,7 @@ class Entity {
|
|
|
935
942
|
response.Item,
|
|
936
943
|
config,
|
|
937
944
|
);
|
|
938
|
-
if (Object.keys(results).length === 0) {
|
|
945
|
+
if (Object.keys(results).length === 0 && !config._objectOnEmpty) {
|
|
939
946
|
results = null;
|
|
940
947
|
}
|
|
941
948
|
} else if (!config._objectOnEmpty) {
|
|
@@ -957,7 +964,7 @@ class Entity {
|
|
|
957
964
|
item,
|
|
958
965
|
config,
|
|
959
966
|
);
|
|
960
|
-
if (Object.keys(record).length > 0) {
|
|
967
|
+
if (Object.keys(record).length > 0 || config._objectOnEmpty) {
|
|
961
968
|
results.push(record);
|
|
962
969
|
}
|
|
963
970
|
}
|
|
@@ -967,7 +974,7 @@ class Entity {
|
|
|
967
974
|
response.Attributes,
|
|
968
975
|
config,
|
|
969
976
|
);
|
|
970
|
-
if (Object.keys(results).length === 0) {
|
|
977
|
+
if (Object.keys(results).length === 0 && !config._objectOnEmpty) {
|
|
971
978
|
results = null;
|
|
972
979
|
}
|
|
973
980
|
} else if (config._objectOnEmpty) {
|
|
@@ -1646,6 +1653,7 @@ class Entity {
|
|
|
1646
1653
|
order: undefined,
|
|
1647
1654
|
hydrate: false,
|
|
1648
1655
|
hydrator: (_entity, _indexName, items) => items,
|
|
1656
|
+
_objectOnEmpty: false,
|
|
1649
1657
|
_includeOnResponseItem: {},
|
|
1650
1658
|
};
|
|
1651
1659
|
|
|
@@ -1727,6 +1735,9 @@ class Entity {
|
|
|
1727
1735
|
|
|
1728
1736
|
if (Array.isArray(option.attributes)) {
|
|
1729
1737
|
config.attributes = config.attributes.concat(option.attributes);
|
|
1738
|
+
if (config.attributes.length > 0) {
|
|
1739
|
+
config._objectOnEmpty = true;
|
|
1740
|
+
}
|
|
1730
1741
|
}
|
|
1731
1742
|
|
|
1732
1743
|
if (option.preserveBatchOrder === true) {
|
|
@@ -2898,10 +2909,7 @@ class Entity {
|
|
|
2898
2909
|
_getComparisonOperator(comparison, skType, comparisonType) {
|
|
2899
2910
|
if (skType === "number") {
|
|
2900
2911
|
return Comparisons[comparison];
|
|
2901
|
-
} else if (
|
|
2902
|
-
comparisonType === ComparisonTypes.attributes ||
|
|
2903
|
-
comparisonType === ComparisonTypes.v2
|
|
2904
|
-
) {
|
|
2912
|
+
} else if (comparisonType === ComparisonTypes.v2) {
|
|
2905
2913
|
return KeyAttributesComparisons[comparison];
|
|
2906
2914
|
} else {
|
|
2907
2915
|
return Comparisons[comparison];
|
package/src/errors.js
CHANGED
|
@@ -280,7 +280,7 @@ function makeMessage(message, section) {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
class ElectroError extends Error {
|
|
283
|
-
constructor(code, message, cause) {
|
|
283
|
+
constructor(code, message, cause, params = null) {
|
|
284
284
|
super(message, { cause });
|
|
285
285
|
let detail = ErrorCodes.UnknownError;
|
|
286
286
|
if (code && code.sym === ErrorCode) {
|
|
@@ -298,9 +298,21 @@ class ElectroError extends Error {
|
|
|
298
298
|
this.code = detail.code;
|
|
299
299
|
this.date = Date.now();
|
|
300
300
|
this.isElectroError = true;
|
|
301
|
+
applyParamsFn(this, params);
|
|
301
302
|
}
|
|
302
303
|
}
|
|
303
304
|
|
|
305
|
+
function applyParamsFn(error, params = null) {
|
|
306
|
+
Object.defineProperty(error, 'params', {
|
|
307
|
+
enumerable: false,
|
|
308
|
+
writable: true,
|
|
309
|
+
configurable: true,
|
|
310
|
+
value: () => {
|
|
311
|
+
return params;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
304
316
|
class ElectroValidationError extends ElectroError {
|
|
305
317
|
constructor(errors = []) {
|
|
306
318
|
const fields = [];
|
|
@@ -389,6 +401,7 @@ class ElectroAttributeValidationError extends ElectroError {
|
|
|
389
401
|
module.exports = {
|
|
390
402
|
ErrorCodes,
|
|
391
403
|
ElectroError,
|
|
404
|
+
applyParamsFn,
|
|
392
405
|
ElectroValidationError,
|
|
393
406
|
ElectroUserValidationError,
|
|
394
407
|
ElectroAttributeValidationError,
|