check-rule-mate 0.5.6 → 0.5.8
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.
|
@@ -265,17 +265,31 @@ function renderSchemas(schemas) {
|
|
|
265
265
|
`}).join("")}
|
|
266
266
|
<div style="display: flex; flex-direction: column;">
|
|
267
267
|
<label for="check-rule-mate-validators">VALIDATORS</label>
|
|
268
|
-
<
|
|
268
|
+
<select name="check-rule-mate-validators" required>
|
|
269
|
+
${
|
|
270
|
+
OPTIONS?.validators ? Object.keys(OPTIONS.validators).map((key) => `
|
|
271
|
+
<option value=${key}>${key}</option>
|
|
272
|
+
`)
|
|
273
|
+
: ''
|
|
274
|
+
}
|
|
275
|
+
</select>
|
|
269
276
|
</div>
|
|
270
277
|
<div style="display: flex; flex-direction: column;">
|
|
271
278
|
<label for="check-rule-mate-rules">RULES</label>
|
|
272
|
-
<
|
|
279
|
+
<select name="check-rule-mate-rules" required>
|
|
280
|
+
${
|
|
281
|
+
rulesFiles ? rulesFiles.map((rulesFile) => `
|
|
282
|
+
<option value=${rulesFile.name}>${rulesFile.name}</option>
|
|
283
|
+
`)
|
|
284
|
+
: ''
|
|
285
|
+
}
|
|
286
|
+
</select>
|
|
273
287
|
</div>
|
|
274
288
|
<button type="submit">Validate Schema</button>
|
|
275
289
|
</form>
|
|
276
290
|
<div class="schema-test-result">
|
|
277
291
|
<span>Result:</span>
|
|
278
|
-
<textarea id="textarea-schema-${schema.name}"></textarea>
|
|
292
|
+
<textarea id="textarea-schema-${schema.name}" readonly></textarea>
|
|
279
293
|
</div>
|
|
280
294
|
</div>
|
|
281
295
|
</details>
|
|
@@ -554,7 +568,8 @@ function generateCSS() {
|
|
|
554
568
|
color: #e5e7eb;
|
|
555
569
|
}
|
|
556
570
|
|
|
557
|
-
.schema-test input
|
|
571
|
+
.schema-test input,
|
|
572
|
+
.schema-test select {
|
|
558
573
|
min-height: 28px;
|
|
559
574
|
padding: 4px 8px 4px 8px;
|
|
560
575
|
margin-bottom: 16px;
|
|
@@ -564,6 +579,11 @@ function generateCSS() {
|
|
|
564
579
|
border: none;
|
|
565
580
|
border-bottom: 1px solid white;
|
|
566
581
|
}
|
|
582
|
+
|
|
583
|
+
.schema-test select option {
|
|
584
|
+
background-color: #020617;
|
|
585
|
+
color: #e5e7eb;
|
|
586
|
+
}
|
|
567
587
|
`;
|
|
568
588
|
}
|
|
569
589
|
|
|
@@ -591,7 +611,7 @@ function generateClientJS() {
|
|
|
591
611
|
formElements.forEach((formElement) => {
|
|
592
612
|
formElement.addEventListener('submit', async (e) => {
|
|
593
613
|
e.preventDefault();
|
|
594
|
-
const inputElements = formElement.querySelectorAll('input');
|
|
614
|
+
const inputElements = formElement.querySelectorAll('input, select');
|
|
595
615
|
const formName = formElement.dataset.form.split('--')[1];
|
|
596
616
|
const formData = {};
|
|
597
617
|
inputElements.forEach((inputElement) => {
|
|
@@ -153,37 +153,35 @@ export interface ValidatorHooks {
|
|
|
153
153
|
onValidateEnd?: onValidateEnd
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
export
|
|
157
|
-
/** Returns the payload of hook */
|
|
156
|
+
export type onValidateStart = (
|
|
158
157
|
payload: onValidateStartPayload
|
|
159
|
-
|
|
158
|
+
) => void | Promise<void>
|
|
160
159
|
|
|
161
|
-
export
|
|
162
|
-
/** Returns the payload of hook */
|
|
160
|
+
export type onValidateFieldStart = (
|
|
163
161
|
payload: onValidateFieldStartPayload
|
|
164
|
-
|
|
162
|
+
) => void | Promise<void>
|
|
165
163
|
|
|
166
|
-
export
|
|
167
|
-
/** Returns the payload of hook */
|
|
164
|
+
export type onValidateFieldError = (
|
|
168
165
|
payload: onValidateFieldErrorPayload
|
|
169
|
-
|
|
166
|
+
) => void | Promise<void>
|
|
170
167
|
|
|
171
|
-
export
|
|
172
|
-
/** Returns the payload of hook */
|
|
168
|
+
export type onValidateFieldSuccess = (
|
|
173
169
|
payload: onValidateFieldSuccessPayload
|
|
174
|
-
|
|
170
|
+
) => void | Promise<void>
|
|
175
171
|
|
|
176
|
-
export
|
|
177
|
-
/** Returns the payload of hook */
|
|
172
|
+
export type onValidateEnd = (
|
|
178
173
|
payload: onValidateEndPayload
|
|
179
|
-
|
|
174
|
+
) => void | Promise<void>
|
|
180
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Hook payloads
|
|
178
|
+
*/
|
|
181
179
|
export interface onValidateStartPayload {
|
|
182
180
|
/** Form data object */
|
|
183
181
|
data: Object
|
|
184
182
|
}
|
|
185
183
|
|
|
186
|
-
export interface
|
|
184
|
+
export interface onValidateFieldStartPayload {
|
|
187
185
|
/** Field name */
|
|
188
186
|
field: string
|
|
189
187
|
|
|
@@ -194,7 +192,7 @@ export interface onValidateFieldStart {
|
|
|
194
192
|
schemaField: SchemaRuleField
|
|
195
193
|
}
|
|
196
194
|
|
|
197
|
-
export interface
|
|
195
|
+
export interface onValidateFieldErrorPayload {
|
|
198
196
|
/** Field name */
|
|
199
197
|
field: string
|
|
200
198
|
|
|
@@ -208,7 +206,7 @@ export interface onValidateFieldError {
|
|
|
208
206
|
error: CheckError
|
|
209
207
|
}
|
|
210
208
|
|
|
211
|
-
export interface
|
|
209
|
+
export interface onValidateFieldSuccessPayload {
|
|
212
210
|
/** Field name */
|
|
213
211
|
field: string
|
|
214
212
|
|
|
@@ -226,3 +224,23 @@ export interface onValidateEndPayload {
|
|
|
226
224
|
/** Form errors */
|
|
227
225
|
errors?: Record<string, CheckError>
|
|
228
226
|
}
|
|
227
|
+
|
|
228
|
+
export function createValidator(
|
|
229
|
+
data: Record<string, any>,
|
|
230
|
+
options: {
|
|
231
|
+
validationHelpers?: Record<string, any>
|
|
232
|
+
rules: Record<string, any>
|
|
233
|
+
schema: Record<string, any>
|
|
234
|
+
errorMessages?: Record<string, string>
|
|
235
|
+
hooks?: ValidatorHooks
|
|
236
|
+
options?: {
|
|
237
|
+
propertiesMustMatch?: boolean
|
|
238
|
+
abortEarly?: boolean
|
|
239
|
+
cache?: boolean
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
): {
|
|
243
|
+
validate(): Promise<{ ok?: true; error?: true; errors?: any }>
|
|
244
|
+
validateField(field: string): Promise<any>
|
|
245
|
+
setData(data: Record<string, any>): void
|
|
246
|
+
}
|
package/package.json
CHANGED
|
File without changes
|