@bejibun/core 0.1.55 → 0.1.56
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/package.json +1 -1
- package/utils/vines/exists.js +4 -2
- package/utils/vines/unique.js +4 -2
package/package.json
CHANGED
package/utils/vines/exists.js
CHANGED
|
@@ -4,6 +4,8 @@ import BaseModel from "../../bases/BaseModel";
|
|
|
4
4
|
const exists = async (value, options, field) => {
|
|
5
5
|
if (!field.isValid)
|
|
6
6
|
return;
|
|
7
|
+
if (options.nullable)
|
|
8
|
+
return;
|
|
7
9
|
const column = defineValue(options.column, field.name);
|
|
8
10
|
let query = options.table;
|
|
9
11
|
if (options.withTrashed)
|
|
@@ -16,10 +18,10 @@ const exists = async (value, options, field) => {
|
|
|
16
18
|
};
|
|
17
19
|
const existsRule = vine.createRule(exists, { isAsync: true });
|
|
18
20
|
const registerExistsMacro = (Type) => {
|
|
19
|
-
Type.macro("exists", function (tableOrOptions, column, withTrashed) {
|
|
21
|
+
Type.macro("exists", function (tableOrOptions, column, withTrashed, nullable) {
|
|
20
22
|
const isModel = typeof tableOrOptions === "function" && Object.prototype.isPrototypeOf.call(BaseModel, tableOrOptions);
|
|
21
23
|
const options = isModel
|
|
22
|
-
? { table: tableOrOptions, column, withTrashed }
|
|
24
|
+
? { table: tableOrOptions, column, withTrashed, nullable }
|
|
23
25
|
: tableOrOptions;
|
|
24
26
|
return this.use(existsRule(options));
|
|
25
27
|
});
|
package/utils/vines/unique.js
CHANGED
|
@@ -4,6 +4,8 @@ import BaseModel from "../../bases/BaseModel";
|
|
|
4
4
|
const unique = async (value, options, field) => {
|
|
5
5
|
if (!field.isValid)
|
|
6
6
|
return;
|
|
7
|
+
if (options.nullable)
|
|
8
|
+
return;
|
|
7
9
|
const column = defineValue(options.column, field.name);
|
|
8
10
|
let query = options.table;
|
|
9
11
|
if (options.withTrashed)
|
|
@@ -16,10 +18,10 @@ const unique = async (value, options, field) => {
|
|
|
16
18
|
};
|
|
17
19
|
const uniqueRule = vine.createRule(unique, { isAsync: true });
|
|
18
20
|
const registerUniqueMacro = (Type) => {
|
|
19
|
-
Type.macro("unique", function (tableOrOptions, column, withTrashed) {
|
|
21
|
+
Type.macro("unique", function (tableOrOptions, column, withTrashed, nullable) {
|
|
20
22
|
const isModel = typeof tableOrOptions === "function" && Object.prototype.isPrototypeOf.call(BaseModel, tableOrOptions);
|
|
21
23
|
const options = isModel
|
|
22
|
-
? { table: tableOrOptions, column, withTrashed }
|
|
24
|
+
? { table: tableOrOptions, column, withTrashed, nullable }
|
|
23
25
|
: tableOrOptions;
|
|
24
26
|
return this.use(uniqueRule(options));
|
|
25
27
|
});
|