@orieljs/validation 0.1.0-alpha.1
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/LICENSE +202 -0
- package/NOTICE +9 -0
- package/dist/index.d.ts +242 -0
- package/dist/index.js +870 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Oriel
|
|
2
|
+
Copyright 2026 meeeet-dev and Oriel contributors
|
|
3
|
+
|
|
4
|
+
This product includes software developed by the Oriel project
|
|
5
|
+
(https://orieljs.vercel.app, https://github.com/orieljs).
|
|
6
|
+
|
|
7
|
+
Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
8
|
+
The Oriel name and logo are not covered by that license; see TRADEMARKS.md
|
|
9
|
+
(https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { OrielError, ValidationError, Rules, MessageBag, ValidationRule, Validator as Validator$1, ValidationFactory, RuleCallback } from '@orieljs/contracts';
|
|
2
|
+
import * as _orieljs_support from '@orieljs/support';
|
|
3
|
+
import { ServiceProvider } from '@orieljs/support';
|
|
4
|
+
|
|
5
|
+
declare class ValidationErrorImpl extends Error implements ValidationError {
|
|
6
|
+
readonly errors: Record<string, string[]>;
|
|
7
|
+
readonly errorBag: string;
|
|
8
|
+
readonly redirectTo?: string | undefined;
|
|
9
|
+
readonly kind: "Validation";
|
|
10
|
+
readonly status = 422;
|
|
11
|
+
readonly name = "ValidationError";
|
|
12
|
+
constructor(errors: Record<string, string[]>, errorBag?: string, redirectTo?: string | undefined);
|
|
13
|
+
}
|
|
14
|
+
declare class AuthorizationErrorImpl extends Error implements OrielError {
|
|
15
|
+
readonly kind: "Authorization";
|
|
16
|
+
readonly status = 403;
|
|
17
|
+
readonly name = "AuthorizationError";
|
|
18
|
+
constructor(message?: string);
|
|
19
|
+
}
|
|
20
|
+
declare class UnknownValidationRuleError extends Error implements OrielError {
|
|
21
|
+
readonly kind: "Server";
|
|
22
|
+
readonly status = 500;
|
|
23
|
+
readonly name = "UnknownValidationRuleError";
|
|
24
|
+
constructor(name: string);
|
|
25
|
+
}
|
|
26
|
+
/** A rule was written with a parameter it can't use (a bad regex, an unparseable date). A developer error, not a user one. */
|
|
27
|
+
declare class InvalidRuleParameterError extends Error implements OrielError {
|
|
28
|
+
readonly kind: "Server";
|
|
29
|
+
readonly status = 500;
|
|
30
|
+
readonly name = "InvalidRuleParameterError";
|
|
31
|
+
constructor(rule: string, parameter: string, reason: string);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Mirrors Illuminate\Foundation\Http\FormRequest, minus dependency injection by type (Oriel resolves the current
|
|
36
|
+
* request and the ValidationFactory through inject(), never through constructor parameters — see spec §3 rule 5).
|
|
37
|
+
* A subclass only has to implement rules(); authorize()/messages()/attributes() default to Laravel's own defaults.
|
|
38
|
+
*/
|
|
39
|
+
declare abstract class FormRequest {
|
|
40
|
+
abstract rules(): Rules;
|
|
41
|
+
authorize(): boolean | Promise<boolean>;
|
|
42
|
+
messages(): Record<string, string>;
|
|
43
|
+
attributes(): Record<string, string>;
|
|
44
|
+
/**
|
|
45
|
+
* `const data = await StorePostRequest.validate()` (spec §4.3). Resolves the current request and the
|
|
46
|
+
* ValidationFactory from the active container, runs authorize() first (throwing AuthorizationErrorImpl if it
|
|
47
|
+
* returns false), then validates request.all() against rules()/messages()/attributes() and returns the typed
|
|
48
|
+
* validated data (or throws the 422 ValidationError — see ValidatorImpl.validated()).
|
|
49
|
+
*/
|
|
50
|
+
static validate<T = Record<string, unknown>>(this: new () => FormRequest): Promise<T>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Humanizes a (possibly dotted) attribute key, e.g. "items.0.product_name" -> "items.0.product name". */
|
|
54
|
+
declare function defaultAttributeName(key: string): string;
|
|
55
|
+
declare function applyReplacements(template: string, replacements: Record<string, string>): string;
|
|
56
|
+
/** Laravel's English lang/en/validation.php, reproduced as closely as possible (see plan Notes/assumptions). */
|
|
57
|
+
declare const DEFAULT_MESSAGES: Record<string, string>;
|
|
58
|
+
|
|
59
|
+
declare class MessageBagImpl implements MessageBag {
|
|
60
|
+
private readonly items;
|
|
61
|
+
/** Not part of the MessageBag contract — used internally by ValidatorImpl and by after() hooks. */
|
|
62
|
+
add(key: string, message: string): void;
|
|
63
|
+
has(key: string): boolean;
|
|
64
|
+
first(key?: string): string | undefined;
|
|
65
|
+
get(key: string): string[];
|
|
66
|
+
all(): string[];
|
|
67
|
+
isEmpty(): boolean;
|
|
68
|
+
count(): number;
|
|
69
|
+
toObject(): Record<string, string[]>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Everything a single rule needs to validate one concrete field. */
|
|
73
|
+
interface RuleContext {
|
|
74
|
+
/** The concrete, wildcard-expanded field path, e.g. "items.1.name". */
|
|
75
|
+
attribute: string;
|
|
76
|
+
/** True when `attribute` came from expanding a wildcard pattern such as "items.*.email". */
|
|
77
|
+
expandedFromWildcard?: boolean;
|
|
78
|
+
value: unknown;
|
|
79
|
+
parameters: string[];
|
|
80
|
+
data: Record<string, unknown>;
|
|
81
|
+
/** Every named rule attached to this field (for size-type resolution: numeric/array/file/string). */
|
|
82
|
+
ruleNames: string[];
|
|
83
|
+
}
|
|
84
|
+
interface BuiltinRule {
|
|
85
|
+
validate(ctx: RuleContext): boolean | Promise<boolean>;
|
|
86
|
+
/** Which DEFAULT_MESSAGES key to use, e.g. `max.${sizeType}`. Most rules return a constant name. */
|
|
87
|
+
messageKey(ctx: RuleContext): string;
|
|
88
|
+
/** Extra :placeholder substitutions beyond :attribute (e.g. :max, :other, :values). */
|
|
89
|
+
replacements?(ctx: RuleContext): Record<string, string>;
|
|
90
|
+
/** Used when messageKey() isn't in DEFAULT_MESSAGES (e.g. an extend()ed rule with a custom message). */
|
|
91
|
+
defaultMessage?: string;
|
|
92
|
+
/** Runs even when the value is missing, blank, or null under nullable (the required* family, and accepted); a failure stops the field. */
|
|
93
|
+
implicit?: boolean;
|
|
94
|
+
}
|
|
95
|
+
type ParsedRule = {
|
|
96
|
+
kind: 'named';
|
|
97
|
+
name: string;
|
|
98
|
+
parameters: string[];
|
|
99
|
+
} | {
|
|
100
|
+
kind: 'object';
|
|
101
|
+
rule: ValidationRule;
|
|
102
|
+
};
|
|
103
|
+
declare function parseRuleSpec(spec: string | ReadonlyArray<string | ValidationRule>): ParsedRule[];
|
|
104
|
+
/** Laravel's definition of "empty" for the required family: null, undefined, '' and []. false and 0 are NOT empty. */
|
|
105
|
+
declare function isEmptyValue(value: unknown): boolean;
|
|
106
|
+
/** Duck-types Contracts/Http's UploadedFile without importing @orieljs/http. */
|
|
107
|
+
declare function isUploadedFileLike(value: unknown): value is {
|
|
108
|
+
clientName: string;
|
|
109
|
+
mimeType: string;
|
|
110
|
+
size: number;
|
|
111
|
+
extension(): string;
|
|
112
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Expands a `*`-wildcard rule pattern (e.g. "items.*.name") into every concrete path present in `data`
|
|
116
|
+
* (e.g. ["items.0.name", "items.1.name"]). A pattern with no `*` is returned unchanged. A `*` segment whose
|
|
117
|
+
* container is missing, not an array and not a plain object expands to nothing for that branch (Review Focus #4:
|
|
118
|
+
* every reported error is keyed by a concrete path, never the literal pattern). Object keys in UNSAFE_KEYS are
|
|
119
|
+
* treated as absent, so a JSON body like {"items":{"__proto__":{...}}} never yields a path through the prototype.
|
|
120
|
+
*/
|
|
121
|
+
declare function expandWildcardKeys(pattern: string, data: Record<string, unknown>): string[];
|
|
122
|
+
|
|
123
|
+
/** Every built-in rule, merged. Later tasks (database rules) add their own spread here. */
|
|
124
|
+
declare const builtinRules: Record<string, BuiltinRule>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Base for the fluent builders. Each one reports under a built-in rule name (`in`, `unique`, `exists`), so when it
|
|
128
|
+
* runs inside a Validator its failure goes through exactly the same lookup as the string rule: custom messages
|
|
129
|
+
* ("email.unique", "items.*.email.unique", "unique"), custom attributes, then the default text. Called directly
|
|
130
|
+
* as a plain ValidationRule, validate() fails with the default English message.
|
|
131
|
+
*/
|
|
132
|
+
declare abstract class BuiltinRuleObject implements ValidationRule {
|
|
133
|
+
abstract readonly ruleName: string;
|
|
134
|
+
abstract passes(attribute: string, value: unknown, data: Record<string, unknown>, expandedFromWildcard?: boolean): boolean | Promise<boolean>;
|
|
135
|
+
validate(attribute: string, value: unknown, fail: (message: string) => void, data: Record<string, unknown>, expandedFromWildcard?: boolean): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
declare class InRule extends BuiltinRuleObject {
|
|
138
|
+
private readonly values;
|
|
139
|
+
readonly ruleName = "in";
|
|
140
|
+
constructor(values: readonly unknown[]);
|
|
141
|
+
passes(_attribute: string, value: unknown): boolean;
|
|
142
|
+
}
|
|
143
|
+
declare class UniqueRule extends BuiltinRuleObject {
|
|
144
|
+
private readonly table;
|
|
145
|
+
private readonly column?;
|
|
146
|
+
readonly ruleName = "unique";
|
|
147
|
+
private exceptId;
|
|
148
|
+
private idColumnName;
|
|
149
|
+
constructor(table: string, column?: string | undefined);
|
|
150
|
+
/**
|
|
151
|
+
* Excludes the current record from the uniqueness check. Laravel's `Rule::unique('users')->ignore($user)` accepts
|
|
152
|
+
* a model directly (the common case: "update your profile without changing your email"), so a model instance is
|
|
153
|
+
* bound by its key (`getKey()`/`getKeyName()`), not the object itself — the object would reach the query builder
|
|
154
|
+
* as an opaque value and either be rejected by the driver or stringified (B27). A plain id still works as before;
|
|
155
|
+
* null (or "NULL") excludes nothing.
|
|
156
|
+
*/
|
|
157
|
+
ignore(id: unknown, idColumn?: string): this;
|
|
158
|
+
passes(attribute: string, value: unknown, _data?: Record<string, unknown>, expandedFromWildcard?: boolean): Promise<boolean>;
|
|
159
|
+
}
|
|
160
|
+
declare class ExistsRule extends BuiltinRuleObject {
|
|
161
|
+
private readonly table;
|
|
162
|
+
private readonly column?;
|
|
163
|
+
readonly ruleName = "exists";
|
|
164
|
+
constructor(table: string, column?: string | undefined);
|
|
165
|
+
passes(attribute: string, value: unknown, _data?: Record<string, unknown>, expandedFromWildcard?: boolean): Promise<boolean>;
|
|
166
|
+
}
|
|
167
|
+
/** Fluent rule-object builders, for when a plain string rule can't express what's needed (e.g. .ignore()). */
|
|
168
|
+
declare const Rule: {
|
|
169
|
+
in: (values: readonly unknown[]) => InRule;
|
|
170
|
+
unique: (table: string, column?: string) => UniqueRule;
|
|
171
|
+
exists: (table: string, column?: string) => ExistsRule;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** See Task 9's writeup in the plan for exactly what this does and doesn't infer. */
|
|
175
|
+
type SplitPipe<S extends string> = S extends `${infer Head}|${infer Tail}` ? Head | SplitPipe<Tail> : S;
|
|
176
|
+
type RuleName<T extends string> = T extends `${infer Name}:${string}` ? Name : T;
|
|
177
|
+
type Names<S extends string> = RuleName<SplitPipe<S>>;
|
|
178
|
+
type BaseType<S extends string> = 'array' extends Names<S> ? unknown[] : 'boolean' extends Names<S> ? boolean : 'integer' extends Names<S> ? number : 'numeric' extends Names<S> ? number : 'email' extends Names<S> ? string : 'url' extends Names<S> ? string : 'uuid' extends Names<S> ? string : 'date' extends Names<S> ? string : 'string' extends Names<S> ? string : unknown;
|
|
179
|
+
/**
|
|
180
|
+
* The inferred type for one rule string, e.g. 'nullable|integer' -> number | null. A non-literal `string` (a rules
|
|
181
|
+
* object declared without `as const`) carries no rule names to read, so it infers unknown: without this guard every
|
|
182
|
+
* `'x' extends string` check would match and the result would wrongly be `unknown[] | null`.
|
|
183
|
+
*/
|
|
184
|
+
type InferRuleType<S extends string> = string extends S ? unknown : 'nullable' extends Names<S> ? BaseType<S> | null : BaseType<S>;
|
|
185
|
+
/**
|
|
186
|
+
* Best-effort: applies InferRuleType to every string-valued rule; array-form (mixed string/object) rules -> unknown.
|
|
187
|
+
* Strips `readonly` (via `-readonly`) so a `Rules` object declared `as const` (the common way to get literal rule
|
|
188
|
+
* strings for inference — see the Task 9 type test) still produces a plain, mutable validated-data shape, not a
|
|
189
|
+
* readonly one; a mapped type otherwise carries the source's readonly modifier over by default.
|
|
190
|
+
*/
|
|
191
|
+
type InferValidatedType<R> = {
|
|
192
|
+
-readonly [K in keyof R]: R[K] extends string ? InferRuleType<R[K]> : unknown;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Runs each field's rules the way Laravel's Validator does:
|
|
197
|
+
* - a missing key, or a string that is blank after trimming, only runs implicit rules (the required* family and
|
|
198
|
+
* accepted); every other rule, including ValidationRule objects, is skipped for it;
|
|
199
|
+
* - an explicit null runs every rule unless the field is `nullable` (then only implicit rules run), so
|
|
200
|
+
* `{ age: null }` still fails `integer`;
|
|
201
|
+
* - `sometimes` skips a missing field entirely;
|
|
202
|
+
* - a field stops validating after its first failure under `bail`, or after any implicit rule fails.
|
|
203
|
+
*/
|
|
204
|
+
declare class ValidatorImpl implements Validator$1 {
|
|
205
|
+
private readonly data;
|
|
206
|
+
private readonly rules;
|
|
207
|
+
private readonly customMessages;
|
|
208
|
+
private readonly customAttributes;
|
|
209
|
+
private readonly registry;
|
|
210
|
+
private readonly errorBagName;
|
|
211
|
+
private bag;
|
|
212
|
+
private ranPromise;
|
|
213
|
+
private readonly afterCallbacks;
|
|
214
|
+
constructor(data: Record<string, unknown>, rules: Rules, customMessages: Record<string, string>, customAttributes: Record<string, string>, registry: Record<string, BuiltinRule>, errorBagName?: string);
|
|
215
|
+
after(callback: (validator: Validator$1) => void | Promise<void>): this;
|
|
216
|
+
/** Not part of the Validator contract — lets an after() hook add a failure (MessageBag itself is read-only). */
|
|
217
|
+
fail(field: string, message: string): void;
|
|
218
|
+
passes(): Promise<boolean>;
|
|
219
|
+
fails(): Promise<boolean>;
|
|
220
|
+
errors(): MessageBagImpl;
|
|
221
|
+
validated<T = Record<string, unknown>>(): Promise<T>;
|
|
222
|
+
private fieldsFor;
|
|
223
|
+
private run;
|
|
224
|
+
private runRule;
|
|
225
|
+
/** Custom message (concrete field, then wildcard pattern, then rule name) or the default, with :attribute filled. */
|
|
226
|
+
private failureMessage;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
declare class ValidationFactoryImpl implements ValidationFactory {
|
|
230
|
+
private readonly extended;
|
|
231
|
+
make(data: Record<string, unknown>, rules: Rules, messages?: Record<string, string>, attributes?: Record<string, string>): ValidatorImpl;
|
|
232
|
+
extend(name: string, callback: RuleCallback, message?: string): void;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Laravel's Validator facade: Validator.make(...)/Validator.extend(...), proxied to the resolved ValidationFactory. */
|
|
236
|
+
declare const Validator: _orieljs_support.Facade<ValidationFactory, object>;
|
|
237
|
+
|
|
238
|
+
declare class ValidationServiceProvider extends ServiceProvider {
|
|
239
|
+
register(): void;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export { AuthorizationErrorImpl, type BuiltinRule, BuiltinRuleObject, DEFAULT_MESSAGES, FormRequest, type InferRuleType, type InferValidatedType, InvalidRuleParameterError, MessageBagImpl, type ParsedRule, Rule, type RuleContext, UnknownValidationRuleError, ValidationErrorImpl, ValidationFactoryImpl, ValidationServiceProvider, Validator, ValidatorImpl, applyReplacements, builtinRules, defaultAttributeName, expandWildcardKeys, isEmptyValue, isUploadedFileLike, parseRuleSpec };
|