@lara-node/validator 0.1.2 → 0.1.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.
@@ -0,0 +1,28 @@
1
+ export declare class ValidationError extends Error {
2
+ errors: Record<string, string[]>;
3
+ messages: Record<string, string[]>;
4
+ message: string;
5
+ constructor(errors: Record<string, string[]>, messages?: Record<string, string[]>);
6
+ }
7
+ export type RuleFn = (value: any, field: string, payload?: any) => true | {
8
+ ok: boolean;
9
+ message?: string;
10
+ value?: any;
11
+ } | false | Promise<any>;
12
+ export type RuleSpec = string | RuleFn | {
13
+ rule: string | RuleFn;
14
+ messages?: Record<string, string>;
15
+ };
16
+ export declare function formatMessage(template: string, ctx: Record<string, any>): string;
17
+ export declare function resolveMessage(field: string, code: string, meta: Record<string, any>, custom?: Record<string, string>): string;
18
+ export declare function validate<T extends Record<string, any>>(payload: any, rules: Record<string, RuleSpec>, customMessages?: Record<string, string>): Promise<T>;
19
+ export declare const requiredIf: (otherField: string, value: any) => RuleFn;
20
+ export declare const requiredUnless: (otherField: string, value: any) => RuleFn;
21
+ export declare const fileRule: RuleFn;
22
+ export declare const mimes: (allowedTypes: string[]) => RuleFn;
23
+ export declare const maxFileSize: (maxSizeInMB: number) => RuleFn;
24
+ export declare const phoneRule: RuleFn;
25
+ export declare const creditCardRule: RuleFn;
26
+ export declare const nestedRule: (rules: Record<string, RuleSpec>) => RuleFn;
27
+ export declare const arrayOfObjectsRule: (rules: Record<string, RuleSpec>) => RuleFn;
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,OAA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AE,OAAO,GAAG,KAAG,MAM/B,CAAC;AAEN,eAAO,MAAM,cAAc,GACxB,YAAY,MAAM,EAAE,OAAO,GAAG,KAAG,MAM/B,CAAC;AAEN,eAAO,MAAM,QAAQ,EAAE,MAItB,CAAC;AAEF,eAAO,MAAM,KAAK,GACf,cAAc,MAAM,EAAE,KAAG,MAiBvB,CAAC;AAEN,eAAO,MAAM,WAAW,GACrB,aAAa,MAAM,KAAG,MAMpB,CAAC;AAEN,eAAO,MAAM,SAAS,EAAE,MAOvB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,MAY5B,CAAC;AAEF,eAAO,MAAM,UAAU,GACpB,OAAO,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAG,MAMhC,CAAC;AAEN,eAAO,MAAM,kBAAkB,GAC5B,OAAO,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAG,MAehC,CAAC"}
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@lara-node/validator",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Laravel-inspired validation engine for Lara-Node",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
7
8
  "exports": {
8
- ".": "./dist/index.js"
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
9
13
  },
10
14
  "files": [
11
15
  "dist",
@@ -24,8 +28,8 @@
24
28
  "typescript": "^5.9.3"
25
29
  },
26
30
  "scripts": {
27
- "build": "tsdown src/index.ts --format esm --out-dir dist --dts",
28
- "dev": "tsdown src/index.ts --format esm --out-dir dist --dts --watch",
31
+ "build": "tsdown src/index.ts --format esm --out-dir dist && tsc --emitDeclarationOnly",
32
+ "dev": "tsdown src/index.ts --format esm --out-dir dist --watch",
29
33
  "clean": "rimraf dist",
30
34
  "typecheck": "tsc --noEmit"
31
35
  }