@stacksjs/validation 0.64.6 → 0.67.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/dist/is.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ export declare function isDef<T = any>(val?: T): val is T;
2
+ export declare function isBoolean(val: any): val is boolean;
3
+ export declare function isFunction<T extends Function>(val: any): val is T;
4
+ export declare function isNumber(val: any): val is number;
5
+ export declare function isString(val: unknown): val is string;
6
+ export declare function isObject(val: any): val is object;
7
+ export declare function isWindow(val: any): boolean;
8
+ export declare const isBrowser: boolean;
9
+ export declare const isServer: boolean;
10
+ export declare function isMap(val: any): val is Map<any, any>;
11
+ export declare function isSet(val: any): val is Set<any>;
12
+ export declare function isPromise<T = any>(val: any): val is Promise<T>;
13
+ export declare function isUndefined(v: any): boolean;
14
+ export declare function isNull(v: any): boolean;
15
+ export declare function isSymbol(v: any): boolean;
16
+ export declare function isDate(v: any): boolean;
17
+ export declare function isRegExp(v: any): boolean;
18
+ export declare function isArray(v: any): boolean;
19
+ export declare function isPrimitive(v: any): boolean;
20
+ export declare function isInteger(v: any): boolean;
21
+ export declare function isFloat(v: any): boolean;
22
+ export declare function isPositive(v: any): boolean;
23
+ export declare function isNegative(v: any): boolean;
24
+ export declare function isEven(v: any): boolean;
25
+ export declare function isOdd(v: any): boolean;
26
+ export declare function isEvenOrOdd(v: any): "even" | "odd";
27
+ export declare function isPositiveOrNegative(v: any): "positive" | "negative";
28
+ export declare function isIntegerOrFloat(v: any): "integer" | "float";
@@ -0,0 +1,8 @@
1
+ interface MessageObject {
2
+ message: string;
3
+ rule: string;
4
+ field: string;
5
+ }
6
+ export declare function reportError(errors: MessageObject[]): void;
7
+ export declare function getErrors(): MessageObject[];
8
+ export {};
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Thanks to VineJS for the following types:
3
+ *
4
+ * The context shared with the entire validation pipeline.
5
+ * Each field gets its own context object.
6
+ */
7
+ export interface FieldContext {
8
+ /**
9
+ * Field value
10
+ */
11
+ value: unknown;
12
+ /**
13
+ * The data property is the top-level object under validation.
14
+ */
15
+ data: any;
16
+ /**
17
+ * Shared metadata across the entire validation lifecycle. It can be
18
+ * used to pass data between validation rules
19
+ */
20
+ meta: Record<string, any>;
21
+ /**
22
+ * Mutate the value of field under validation.
23
+ */
24
+ mutate: (newValue: any, field: FieldContext) => void;
25
+ /**
26
+ * Report error to the error reporter
27
+ */
28
+ report: ErrorReporterContract["report"];
29
+ /**
30
+ * Is this field valid. Default: true
31
+ */
32
+ isValid: boolean;
33
+ /**
34
+ * Is this field has value defined.
35
+ */
36
+ isDefined: boolean;
37
+ /**
38
+ * Wildcard path for the field. The value is a nested
39
+ * pointer to the field under validation.
40
+ *
41
+ * In case of arrays, the `*` wildcard is used.
42
+ */
43
+ wildCardPath: string;
44
+ /**
45
+ * The parent property is the parent of the field. It could be an
46
+ * array or an object.
47
+ */
48
+ parent: any;
49
+ /**
50
+ * Name of the field under validation. In case of an array, the field
51
+ * name will be a number
52
+ */
53
+ name: string | number;
54
+ /**
55
+ * Is this field an array member
56
+ */
57
+ isArrayMember: boolean;
58
+ }
59
+ /**
60
+ * Thanks to VineJS for the following types:
61
+ *
62
+ * The error reporter is used to report errors during the validation
63
+ * process.
64
+ */
65
+ export interface ErrorReporterContract {
66
+ /**
67
+ * A boolean to known if there are one or more
68
+ * errors.
69
+ */
70
+ hasErrors: boolean;
71
+ /**
72
+ * Creates an instance of an exception to throw
73
+ */
74
+ createError: () => Error;
75
+ /**
76
+ * Report error for a field
77
+ */
78
+ report: (message: string, rule: string, field: FieldContext, args?: Record<string, any>) => any;
79
+ }
@@ -0,0 +1,16 @@
1
+ import schema, { SimpleMessagesProvider, errors as VineError } from "@vinejs/vine";
2
+ import rule from "validator";
3
+ export { rule, schema, SimpleMessagesProvider, VineError };
4
+ type SchemaString = string;
5
+ type SchemaNumber = number;
6
+ type SchemaBoolean = boolean;
7
+ type SchemaEnum = string[];
8
+ export type SchemaType = SchemaString | SchemaNumber | SchemaBoolean | SchemaEnum;
9
+ export { VineBoolean, VineDate, VineEnum, VineNumber, VineString } from "@vinejs/vine";
10
+ export type { Infer } from "@vinejs/vine/types";
11
+ export declare const validate: {
12
+ string: (defaultValue?: string) => SchemaString;
13
+ number: (defaultValue?: number) => SchemaNumber;
14
+ boolean: (defaultValue?: boolean) => SchemaBoolean;
15
+ enum: (values: string[]) => SchemaEnum;
16
+ };
@@ -0,0 +1 @@
1
+ export { VineBoolean as ValidationBoolean, VineEnum as ValidationEnum, VineNumber as ValidationNumber, VineString as ValidationString } from "@vinejs/vine";
@@ -0,0 +1,15 @@
1
+ import type { VineType } from "@stacksjs/types";
2
+ interface RequestData {
3
+ [key: string]: any;
4
+ }
5
+ interface ValidationField {
6
+ rule: VineType;
7
+ message: Record<string, string>;
8
+ }
9
+ interface CustomAttributes {
10
+ [key: string]: ValidationField;
11
+ }
12
+ export declare function isObjectNotEmpty(obj: object | undefined): boolean;
13
+ export declare function validateField(modelFile: string, params: RequestData): Promise<any>;
14
+ export declare function customValidate(attributes: CustomAttributes, params: RequestData): Promise<any>;
15
+ export {};
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@stacksjs/validation",
3
3
  "type": "module",
4
- "version": "0.64.6",
4
+ "version": "0.67.0",
5
5
  "description": "The Stacks Validation ways.",
6
6
  "author": "Chris Breuer",
7
+ "contributors": ["Chris Breuer <chris@stacksjs.org>"],
7
8
  "license": "MIT",
8
9
  "funding": "https://github.com/sponsors/chrisbbreuer",
9
10
  "homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/validation#readme",
@@ -15,16 +16,10 @@
15
16
  "bugs": {
16
17
  "url": "https://github.com/stacksjs/stacks/issues"
17
18
  },
18
- "keywords": [
19
- "vinejs",
20
- "validation",
21
- "utilities",
22
- "functions",
23
- "stacks"
24
- ],
19
+ "keywords": ["vinejs", "validation", "utilities", "functions", "stacks"],
25
20
  "exports": {
26
21
  ".": {
27
- "bun": "./src/index.ts",
22
+ "types": "./dist/index.d.ts",
28
23
  "import": "./dist/index.js"
29
24
  },
30
25
  "./*": {
@@ -34,25 +29,19 @@
34
29
  },
35
30
  "main": "dist/index.cjs",
36
31
  "module": "dist/index.js",
37
- "contributors": [
38
- "Chris Breuer <chris@stacksjs.org>"
39
- ],
40
- "files": [
41
- "README.md",
42
- "dist",
43
- "src"
44
- ],
32
+ "types": "dist/index.d.ts",
33
+ "files": ["README.md", "dist"],
45
34
  "scripts": {
46
- "build": "bun --bun build.ts",
47
- "typecheck": "bun --bun tsc --noEmit",
35
+ "build": "bun build.ts",
36
+ "typecheck": "bun tsc --noEmit",
48
37
  "prepublishOnly": "bun run build"
49
38
  },
50
39
  "dependencies": {
51
- "@stacksjs/strings": "latest",
52
- "@stacksjs/types": "latest",
40
+ "@stacksjs/strings": "0.67.0",
41
+ "@stacksjs/types": "0.67.0",
53
42
  "@vinejs/vine": "^2.1.0"
54
43
  },
55
44
  "devDependencies": {
56
- "@stacksjs/development": "latest"
45
+ "@stacksjs/development": "0.67.0"
57
46
  }
58
47
  }