@h3ravel/validation 1.29.0-alpha.14 → 1.29.0-alpha.15

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +338 -0
  2. package/package.json +8 -8
package/dist/index.d.ts CHANGED
@@ -1 +1,339 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
+ import { BaseValidationRuleClass, DotPaths, IMessageBag, IRequest, IValidationRule, IValidator, MessagesForRules, MessagesForRules as MessagesForRules$1, RulesForData, RulesForData as RulesForData$1, ValidationMessageProvider, ValidationRuleCallable, ValidationRuleSet } from "@h3ravel/contracts";
3
+ import { ImplicitRule as ImplicitRule$1, Rule } from "simple-body-validator";
4
+ import { UnprocessableEntityHttpException } from "@h3ravel/foundation";
5
+
6
+ //#region src/utilities/MessageBag.d.ts
7
+ declare class MessageBag implements IMessageBag {
8
+ /**
9
+ * All of the registered messages.
10
+ */
11
+ protected messages: Record<string, string[]>;
12
+ /**
13
+ * Default format for message output.
14
+ */
15
+ protected format: string;
16
+ /**
17
+ * Create a new message bag instance.
18
+ */
19
+ constructor(messages?: Record<string, string[] | string>);
20
+ /**
21
+ * Get all message keys.
22
+ */
23
+ keys(): string[];
24
+ /**
25
+ * Add a message.
26
+ */
27
+ add(key: string, message: string): this;
28
+ /**
29
+ * Add a message conditionally.
30
+ */
31
+ addIf(condition: boolean, key: string, message: string): this;
32
+ /**
33
+ * Check uniqueness of key/message pair.
34
+ */
35
+ protected isUnique(key: string, message: string): boolean;
36
+ /**
37
+ * Merge another message source into this one.
38
+ */
39
+ merge(messages: Record<string, string[]> | ValidationMessageProvider): this;
40
+ /**
41
+ * Determine if messages exist for all given keys.
42
+ */
43
+ has(key: string | string[] | null): boolean;
44
+ /**
45
+ * Determine if messages exist for any given key.
46
+ */
47
+ hasAny(keys?: string | string[]): boolean;
48
+ /**
49
+ * Determine if messages don't exist for given keys.
50
+ */
51
+ missing(key: string | string[]): boolean;
52
+ /**
53
+ * Get the first message for a given key.
54
+ */
55
+ first(key?: string | null, format?: string | null): string;
56
+ /**
57
+ * Get all messages for a given key.
58
+ */
59
+ get(key: string, format?: string | null): string[] | Record<string, string[]>;
60
+ /**
61
+ * Wildcard key match.
62
+ */
63
+ protected getMessagesForWildcardKey(key: string, format: string | null): Record<string, string[]>;
64
+ /**
65
+ * Get all messages.
66
+ */
67
+ all(format?: string | null): string[];
68
+ /**
69
+ * Get unique messages.
70
+ */
71
+ unique(format?: string | null): string[];
72
+ /**
73
+ * Remove messages for a key.
74
+ */
75
+ forget(key: string): this;
76
+ /**
77
+ * Format an array of messages.
78
+ */
79
+ protected transform(messages: string[], format: string, messageKey: string): string[];
80
+ /**
81
+ * Get proper format string.
82
+ */
83
+ protected checkFormat(format?: string | null): string;
84
+ /**
85
+ * Get raw messages.
86
+ */
87
+ messagesRaw(): Record<string, string[]>;
88
+ /**
89
+ * Alias for messagesRaw().
90
+ */
91
+ getMessages(): Record<string, string[]>;
92
+ /**
93
+ * Return message bag instance.
94
+ */
95
+ getMessageBag(): MessageBag;
96
+ /**
97
+ * Get format string.
98
+ */
99
+ getFormat(): string;
100
+ /**
101
+ * Set default message format.
102
+ */
103
+ setFormat(format?: string): this;
104
+ /**
105
+ * Empty checks.
106
+ */
107
+ isEmpty(): boolean;
108
+ isNotEmpty(): boolean;
109
+ any(): boolean;
110
+ /**
111
+ * Count total messages.
112
+ */
113
+ count(): number;
114
+ /**
115
+ * Array & JSON conversions.
116
+ */
117
+ toArray(): Record<string, string[]>;
118
+ jsonSerialize(): any;
119
+ toJson(options?: number): string;
120
+ toPrettyJson(): string;
121
+ /**
122
+ * String representation.
123
+ */
124
+ toString(): string;
125
+ }
126
+ //#endregion
127
+ //#region src/Validator.d.ts
128
+ declare class Validator<D extends Record<string, any> = any, R extends RulesForData$1<D> = RulesForData$1<D>> implements IValidator<D, R> {
129
+ #private;
130
+ private data;
131
+ private rules;
132
+ private _errors;
133
+ private passing;
134
+ private executed;
135
+ private instance?;
136
+ private errorBagName;
137
+ private registeredCustomRules;
138
+ private shouldStopOnFirstFailure;
139
+ constructor(data: D, rules: R, messages?: Partial<Record<MessagesForRules$1<R>, string>>);
140
+ /**
141
+ * Validate the data and return the instance
142
+ */
143
+ static make<D extends Record<string, any>, R extends RulesForData$1<D>>(data: D, rules: R, messages?: Partial<Record<MessagesForRules$1<R>, string>>): Validator<D, R>;
144
+ /**
145
+ * Run the validator and store results.
146
+ */
147
+ passes(): Promise<boolean>;
148
+ /**
149
+ * Opposite of passes()
150
+ */
151
+ fails(): Promise<boolean>;
152
+ /**
153
+ * Throw if validation fails, else return executed data
154
+ *
155
+ * @throws ValidationException if validation fails
156
+ */
157
+ validate(): Promise<Record<string, any>>;
158
+ /**
159
+ * Run the validator's rules against its data.
160
+ * @param bagName
161
+ * @returns
162
+ */
163
+ validateWithBag(bagName: string): Promise<Record<string, any>>;
164
+ /**
165
+ * Stop validation on first failure.
166
+ */
167
+ stopOnFirstFailure(): this;
168
+ /**
169
+ * Get the data that passed validation.
170
+ */
171
+ validatedData(): Record<string, any>;
172
+ /**
173
+ * Return all validated input.
174
+ */
175
+ validated(): Partial<D>;
176
+ /**
177
+ * Return a portion of validated input
178
+ */
179
+ safe(): {
180
+ only: (keys: string[]) => Partial<D>;
181
+ except: (keys: string[]) => Partial<D>;
182
+ };
183
+ /**
184
+ * Get the message container for the validator.
185
+ */
186
+ messages(): Promise<Partial<Record<MessagesForRules$1<R>, string>>>;
187
+ /**
188
+ * Add an after validation callback.
189
+ *
190
+ * @param callback
191
+ */
192
+ after<C extends ((validator: Validator<D, R>) => void) | BaseValidationRuleClass>(callback: C | C[]): this;
193
+ /**
194
+ * Get all errors.
195
+ */
196
+ errors(): MessageBag;
197
+ errorBag(): string;
198
+ /**
199
+ * Reset validator with new data.
200
+ */
201
+ setData(data: D): this;
202
+ /**
203
+ * Set validation rules.
204
+ */
205
+ setRules(rules: R): this;
206
+ /**
207
+ * Add a single rule to existing rules.
208
+ */
209
+ addRule(key: DotPaths<D>, rule: ValidationRuleSet): this;
210
+ /**
211
+ * Merge additional rules.
212
+ */
213
+ mergeRules(rules: Record<string, string>): this;
214
+ /**
215
+ * Get current data.
216
+ */
217
+ getData(): Record<string, any>;
218
+ /**
219
+ * Get current rules.
220
+ */
221
+ getRules(): R;
222
+ /**
223
+ * Bind all required services here.
224
+ */
225
+ private bindServices;
226
+ private execute;
227
+ }
228
+ //#endregion
229
+ //#region src/ImplicitRule.d.ts
230
+ declare abstract class ImplicitRule extends ImplicitRule$1 {
231
+ rules: ValidationRuleCallable[];
232
+ /**
233
+ * Run the validation rule.
234
+ */
235
+ abstract validate(attribute: string, value: any, fail: (msg: string) => any): void;
236
+ /**
237
+ * Set the current validator.
238
+ */
239
+ setValidator?(validator: Validator<any, any>): this;
240
+ }
241
+ //#endregion
242
+ //#region src/Providers/ValidationServiceProvider.d.ts
243
+ /**
244
+ * Service provider for Validation utilities
245
+ */
246
+ declare class ValidationServiceProvider {
247
+ private app;
248
+ registeredCommands?: (new (app: any, kernel: any) => any)[];
249
+ static priority: number;
250
+ constructor(app: any);
251
+ /**
252
+ * Register URL services in the container
253
+ */
254
+ register(): void;
255
+ /**
256
+ * Boot URL services
257
+ */
258
+ boot(): void;
259
+ }
260
+ //#endregion
261
+ //#region src/ValidationRule.d.ts
262
+ declare abstract class ValidationRule<D extends Record<string, any> = any, R extends RulesForData$1<D> = any> extends Rule implements IValidationRule {
263
+ rules: ValidationRuleCallable[];
264
+ private passing;
265
+ /**
266
+ * Run the validation rule.
267
+ */
268
+ abstract validate(attribute: string, value: any, fail: (msg: string) => any): void;
269
+ /**
270
+ * Set the current validator.
271
+ */
272
+ setValidator?(validator: Validator<D, R>): this;
273
+ /**
274
+ * Set the data under validation.
275
+ */
276
+ setData(_data: Record<string, any>): this;
277
+ passes(value: any, attribute: string): boolean | Promise<boolean>;
278
+ }
279
+ //#endregion
280
+ //#region src/Rules/ExtendedRules.d.ts
281
+ declare class ExtendedRules extends ValidationRule {
282
+ /**
283
+ * The validator instance.
284
+ */
285
+ protected validator: Validator<any, any>;
286
+ setValidator(validator: Validator<any, any>): this;
287
+ rules: ValidationRuleCallable[];
288
+ validate(): void;
289
+ }
290
+ //#endregion
291
+ //#region src/ValidationException.d.ts
292
+ declare class ValidationException extends UnprocessableEntityHttpException {
293
+ validator: Validator<any, any>;
294
+ response?: any;
295
+ status: number;
296
+ errorBag: string;
297
+ redirectTo?: string;
298
+ constructor(validator: Validator<any, any>, response?: any, errorBag?: string);
299
+ /**
300
+ * Send a custom response body for this exception
301
+ *
302
+ * @param request
303
+ * @returns
304
+ */
305
+ toResponse(request: IRequest): import("@h3ravel/contracts").IResponse | {
306
+ message: string;
307
+ errors: Record<string, string[]>;
308
+ };
309
+ /**
310
+ * Create a new validation exception from a plain array of messages.
311
+ */
312
+ static withMessages(messages: Record<string, string[] | string>): ValidationException;
313
+ /**
314
+ * Create a readable summary message from the validation errors.
315
+ */
316
+ protected static summarize(validator: Validator<any, any>): string;
317
+ /**
318
+ * Get all of the validation error messages.
319
+ */
320
+ errors(): Record<string, string[]>;
321
+ /**
322
+ * Set the HTTP status code to be used for the response.
323
+ */
324
+ setStatus(status: number): this;
325
+ /**
326
+ * Set the error bag on the exception.
327
+ */
328
+ setErrorBag(errorBag: string): this;
329
+ /**
330
+ * Set the URL to redirect to on a validation error.
331
+ */
332
+ setRedirectTo(url: string): this;
333
+ /**
334
+ * Get the underlying response instance.
335
+ */
336
+ getResponse(): any;
337
+ }
338
+ //#endregion
339
+ export { ExtendedRules, ImplicitRule, MessageBag, type MessagesForRules, type RulesForData, ValidationException, ValidationRule, ValidationServiceProvider, Validator };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/validation",
3
- "version": "1.29.0-alpha.14",
3
+ "version": "1.29.0-alpha.15",
4
4
  "description": "Lightweight validation library providing expressive rule-based validation for requests, data objects, and custom logic for H3ravel applications.",
5
5
  "h3ravel": {
6
6
  "providers": [
@@ -46,16 +46,16 @@
46
46
  "builder"
47
47
  ],
48
48
  "dependencies": {
49
- "@h3ravel/shared": "^1.29.0-alpha.14",
50
- "@h3ravel/support": "^1.29.0-alpha.14",
49
+ "@h3ravel/shared": "^1.29.0-alpha.15",
50
+ "@h3ravel/support": "^1.29.0-alpha.15",
51
51
  "simple-body-validator": "^1.3.9",
52
- "@h3ravel/foundation": "^1.29.0-alpha.14"
52
+ "@h3ravel/foundation": "^1.29.0-alpha.15"
53
53
  },
54
54
  "peerDependencies": {
55
- "@h3ravel/core": "^1.29.0-alpha.14",
56
- "@h3ravel/config": "^1.29.0-alpha.14",
57
- "@h3ravel/database": "^11.15.0-alpha.14",
58
- "@h3ravel/contracts": "^1.29.0-alpha.14"
55
+ "@h3ravel/core": "^1.29.0-alpha.15",
56
+ "@h3ravel/config": "^1.29.0-alpha.15",
57
+ "@h3ravel/database": "^11.15.0-alpha.15",
58
+ "@h3ravel/contracts": "^1.29.0-alpha.15"
59
59
  },
60
60
  "devDependencies": {
61
61
  "typescript": "^6.0.0"