@bedrockio/model 0.11.2 → 0.11.3
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 +4 -0
- package/dist/cjs/soft-delete.js +11 -2
- package/package.json +1 -1
- package/src/soft-delete.js +9 -2
- package/types/soft-delete.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/soft-delete.js
CHANGED
|
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.applySoftDelete = applySoftDelete;
|
|
7
7
|
exports.assertUnique = assertUnique;
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
|
+
var _warn = _interopRequireDefault(require("./warn"));
|
|
9
10
|
var _query = require("./query");
|
|
10
11
|
var _errors = require("./errors");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
13
|
function applySoftDelete(schema) {
|
|
12
14
|
applyQueries(schema);
|
|
13
15
|
applyUniqueConstraints(schema);
|
|
@@ -32,7 +34,7 @@ async function assertUnique(options) {
|
|
|
32
34
|
};
|
|
33
35
|
const exists = await model.exists(query);
|
|
34
36
|
if (exists) {
|
|
35
|
-
const message = getUniqueErrorMessage(
|
|
37
|
+
const message = getUniqueErrorMessage(field, options);
|
|
36
38
|
throw new _errors.UniqueConstraintError(message, {
|
|
37
39
|
model,
|
|
38
40
|
field,
|
|
@@ -40,7 +42,11 @@ async function assertUnique(options) {
|
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
|
-
function getUniqueErrorMessage(
|
|
45
|
+
function getUniqueErrorMessage(field, options) {
|
|
46
|
+
const {
|
|
47
|
+
id,
|
|
48
|
+
model
|
|
49
|
+
} = options;
|
|
44
50
|
const {
|
|
45
51
|
modelName
|
|
46
52
|
} = model;
|
|
@@ -48,6 +54,9 @@ function getUniqueErrorMessage(model, field) {
|
|
|
48
54
|
const name = field === 'phone' ? 'phone number' : field;
|
|
49
55
|
return `A user with that ${name} already exists.`;
|
|
50
56
|
} else {
|
|
57
|
+
if (!id) {
|
|
58
|
+
(0, _warn.default)('Note "id" field was not passed to exclude self for unique check.');
|
|
59
|
+
}
|
|
51
60
|
return `"${field}" already exists.`;
|
|
52
61
|
}
|
|
53
62
|
}
|
package/package.json
CHANGED
package/src/soft-delete.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { isEqual } from 'lodash';
|
|
2
2
|
|
|
3
|
+
import warn from './warn';
|
|
4
|
+
|
|
3
5
|
import { wrapQuery } from './query';
|
|
4
6
|
import { UniqueConstraintError } from './errors';
|
|
5
7
|
|
|
@@ -24,8 +26,9 @@ export async function assertUnique(options) {
|
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
const exists = await model.exists(query);
|
|
29
|
+
|
|
27
30
|
if (exists) {
|
|
28
|
-
const message = getUniqueErrorMessage(
|
|
31
|
+
const message = getUniqueErrorMessage(field, options);
|
|
29
32
|
throw new UniqueConstraintError(message, {
|
|
30
33
|
model,
|
|
31
34
|
field,
|
|
@@ -34,12 +37,16 @@ export async function assertUnique(options) {
|
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
function getUniqueErrorMessage(
|
|
40
|
+
function getUniqueErrorMessage(field, options) {
|
|
41
|
+
const { id, model } = options;
|
|
38
42
|
const { modelName } = model;
|
|
39
43
|
if (modelName === 'User' && !field.includes('.')) {
|
|
40
44
|
const name = field === 'phone' ? 'phone number' : field;
|
|
41
45
|
return `A user with that ${name} already exists.`;
|
|
42
46
|
} else {
|
|
47
|
+
if (!id) {
|
|
48
|
+
warn('Note "id" field was not passed to exclude self for unique check.');
|
|
49
|
+
}
|
|
43
50
|
return `"${field}" already exists.`;
|
|
44
51
|
}
|
|
45
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../src/soft-delete.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../src/soft-delete.js"],"names":[],"mappings":"AAOA,mDAIC;AAED,0DAwBC"}
|