@stacksjs/validation 0.63.1 → 0.64.1
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/dist/index.js +4 -4
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
- package/src/validator.ts +12 -11
package/package.json
CHANGED
package/src/validator.ts
CHANGED
|
@@ -6,23 +6,22 @@ import type { SchemaTypes } from '@vinejs/vine/types'
|
|
|
6
6
|
import { SimpleMessagesProvider, VineError, reportError, schema } from './'
|
|
7
7
|
|
|
8
8
|
interface RequestData {
|
|
9
|
-
[key: string]:
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface ValidationType {
|
|
13
|
-
rule: VineType
|
|
14
|
-
message: { [key: string]: string }
|
|
9
|
+
[key: string]: any
|
|
15
10
|
}
|
|
16
11
|
|
|
17
12
|
interface ValidationField {
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
rule: VineType
|
|
14
|
+
message: Record<string, string>
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
interface CustomAttributes {
|
|
23
18
|
[key: string]: ValidationField
|
|
24
19
|
}
|
|
25
20
|
|
|
21
|
+
export function isObjectNotEmpty(obj: object): boolean {
|
|
22
|
+
return Object.keys(obj).length > 0
|
|
23
|
+
}
|
|
24
|
+
|
|
26
25
|
export async function validateField(modelFile: string, params: RequestData): Promise<any> {
|
|
27
26
|
const model = (await import(/* @vite-ignore */ path.userModelsPath(`${modelFile}.ts`))).default as Model
|
|
28
27
|
const attributes = model.attributes
|
|
@@ -61,12 +60,14 @@ export async function customValidate(attributes: CustomAttributes, params: Reque
|
|
|
61
60
|
|
|
62
61
|
for (const key in attributes) {
|
|
63
62
|
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const rule = attributes[key]?.rule
|
|
64
|
+
if (rule) ruleObject[key] = rule as SchemaTypes
|
|
65
|
+
|
|
66
|
+
const validatorMessages = attributes[key]?.message
|
|
66
67
|
|
|
67
68
|
for (const validatorMessageKey in validatorMessages) {
|
|
68
69
|
const validatorMessageString = `${key}.${validatorMessageKey}`
|
|
69
|
-
messageObject[validatorMessageString] = attributes[key]?.
|
|
70
|
+
messageObject[validatorMessageString] = attributes[key]?.message[validatorMessageKey] || ''
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
}
|