@stacksjs/validation 0.63.0 → 0.64.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/validation",
3
3
  "type": "module",
4
- "version": "0.63.0",
4
+ "version": "0.64.0",
5
5
  "description": "The Stacks Validation ways.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
@@ -47,11 +47,6 @@
47
47
  "typecheck": "bun --bun tsc --noEmit",
48
48
  "prepublishOnly": "bun run build"
49
49
  },
50
- "peerDependencies": {
51
- "@stacksjs/strings": "latest",
52
- "@stacksjs/types": "latest",
53
- "@vinejs/vine": "^2.1.0"
54
- },
55
50
  "dependencies": {
56
51
  "@stacksjs/strings": "latest",
57
52
  "@stacksjs/types": "latest",
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]: string | number | null | undefined | boolean
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
- [key: string]: string | ValidationType
19
- validation: ValidationType
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
- ruleObject[key] = attributes[key]?.validation?.rule
65
- const validatorMessages = attributes[key]?.validation?.message
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]?.validation?.message[validatorMessageKey] || ''
70
+ messageObject[validatorMessageString] = attributes[key]?.message[validatorMessageKey] || ''
70
71
  }
71
72
  }
72
73
  }