perfect-payload 2.0.0-beta.0 → 2.0.0-beta.2

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,5 @@
1
+ export interface ValidationError {
2
+ path: string;
3
+ code: string;
4
+ message: string;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { ValidationRules } from "./rules.js";
2
+ import type { PerfectPayloadOptions } from "./options.js";
3
+ import type { ValidationError } from "./errors.js";
4
+ export type RequestSource = "headers" | "params" | "query" | "body";
5
+ export type FrameworkRule = Partial<Record<RequestSource, ValidationRules>>;
6
+ export type FrameworkData = Partial<Record<RequestSource, Record<string, unknown>>>;
7
+ export interface FrameworkConfig {
8
+ rule?: FrameworkRule;
9
+ options?: PerfectPayloadOptions;
10
+ }
11
+ export interface FrameworkValidationInput extends FrameworkConfig {
12
+ data?: FrameworkData;
13
+ }
14
+ export type FrameworkValidatedPayload = Partial<Record<RequestSource, Record<string, unknown>>>;
15
+ export interface FrameworkValidationSuccess {
16
+ valid: true;
17
+ validatedPayload: FrameworkValidatedPayload;
18
+ }
19
+ export interface FrameworkValidationFailure {
20
+ statusCode?: number;
21
+ valid: false;
22
+ message?: string;
23
+ errors: Array<string | ValidationError>;
24
+ [key: string]: unknown;
25
+ }
26
+ export type FrameworkValidationResult = FrameworkValidationSuccess | FrameworkValidationFailure;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { InvalidPayloadResponse, ValidPayloadResponse } from "./results.js";
2
+ export type UnknownFieldsMode = "strip" | "allow" | "reject";
3
+ export interface PerfectPayloadOptions {
4
+ unknownFields?: UnknownFieldsMode;
5
+ prettyErrors?: boolean;
6
+ validPayloadResponse?: ValidPayloadResponse;
7
+ inValidPayloadResponse?: InvalidPayloadResponse;
8
+ }
9
+ export interface StructuredErrorOptions extends PerfectPayloadOptions {
10
+ prettyErrors?: false;
11
+ }
12
+ export interface PrettyErrorOptions extends PerfectPayloadOptions {
13
+ prettyErrors: true;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { ValidationError } from "./errors.js";
2
+ export interface ValidPayloadResponse {
3
+ statusCode: number;
4
+ valid: true;
5
+ [key: string]: unknown;
6
+ }
7
+ export interface InvalidPayloadResponse {
8
+ statusCode: number;
9
+ valid: false;
10
+ message: string;
11
+ [key: string]: unknown;
12
+ }
13
+ export interface ValidationSuccess<T = Record<string, unknown>> extends ValidPayloadResponse {
14
+ validatedPayload: T;
15
+ }
16
+ export interface ValidationFailure<E = ValidationError> extends InvalidPayloadResponse {
17
+ errors: E[];
18
+ }
19
+ export type ValidationResult<T = Record<string, unknown>, E = ValidationError> = ValidationSuccess<T> | ValidationFailure<E>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ export type ValidationValueType = "number" | "string" | "boolean" | "email" | "url" | "enum" | "uuid" | "uuidv1" | "uuidv3" | "uuidv4" | "uuidv5" | "objectId" | "array" | "object";
2
+ export type TransformFunction = (value: unknown, payload: Record<string, unknown>) => unknown;
3
+ export type CustomValidator = (value: unknown, payload: Record<string, unknown>) => boolean | Promise<boolean>;
4
+ export interface DependencyRule {
5
+ setDependencyRule: (value: unknown, dependencyValue: unknown) => AttributeValidationRules;
6
+ }
7
+ export type DependencyRules = Record<string, DependencyRule>;
8
+ export interface AttributeValidationRules {
9
+ mandatory?: boolean;
10
+ allowNull?: boolean;
11
+ allowEmptyObject?: boolean;
12
+ allowEmptyArray?: boolean;
13
+ type?: ValidationValueType;
14
+ enumValues?: unknown[];
15
+ path?: string;
16
+ mandatoryError?: string;
17
+ allowNullError?: string;
18
+ emptyObjectError?: string;
19
+ emptyArrayError?: string;
20
+ elementConstraintsError?: string;
21
+ regexError?: string;
22
+ typeError?: string;
23
+ minLengthError?: string;
24
+ maxLengthError?: string;
25
+ preventDecimalError?: string;
26
+ minError?: string;
27
+ maxError?: string;
28
+ rangeError?: string;
29
+ customValidatorError?: string;
30
+ customValidatorCode?: string;
31
+ minLength?: number;
32
+ maxLength?: number;
33
+ min?: number;
34
+ max?: number;
35
+ range?: string;
36
+ preventDecimal?: boolean;
37
+ minItems?: number;
38
+ maxItems?: number;
39
+ regex?: RegExp;
40
+ objectAttr?: ValidationRules;
41
+ elementConstraints?: AttributeValidationRules;
42
+ dependency?: DependencyRules;
43
+ customValidator?: CustomValidator;
44
+ transform?: TransformFunction;
45
+ trim?: boolean;
46
+ lowercase?: boolean;
47
+ uppercase?: boolean;
48
+ }
49
+ export type ValidationRules = Record<string, AttributeValidationRules>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perfect-payload",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.2",
4
4
  "type": "module",
5
5
  "description": "Lightweight JSON payload validation library with structured errors, nested validation, field paths, and customizable validation rules.",
6
6
  "main": "./dist/index.js",
@@ -8,15 +8,18 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
12
13
  },
13
14
  "./express": {
14
15
  "types": "./dist/express.d.ts",
15
- "import": "./dist/express.js"
16
+ "import": "./dist/express.js",
17
+ "default": "./dist/express.js"
16
18
  },
17
19
  "./fastify": {
18
20
  "types": "./dist/fastify.d.ts",
19
- "import": "./dist/fastify.js"
21
+ "import": "./dist/fastify.js",
22
+ "default": "./dist/fastify.js"
20
23
  }
21
24
  },
22
25
  "scripts": {