@beseif-solutions/prow-core 1.0.0 → 1.0.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.
@@ -1,617 +1,2 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extract = exports.validate = exports.alter = exports.fieldsSchema = exports.fieldSchema = void 0;
7
- const joi_1 = __importDefault(require("joi"));
8
- const lodash_1 = __importDefault(require("lodash"));
9
- const moment_timezone_1 = __importDefault(require("moment-timezone"));
10
- const context_1 = __importDefault(require("./context"));
11
- const where_1 = require("./where");
12
- const conditionSchema = () => joi_1.default.object({
13
- condition: joi_1.default.object().required(),
14
- overrides: joi_1.default.object().required(),
15
- });
16
- const commonFieldSchema = () => joi_1.default.object({
17
- key: joi_1.default.string().required(),
18
- altered_by: joi_1.default.array().items(conditionSchema()),
19
- disabled: joi_1.default.bool(),
20
- required: joi_1.default.bool(),
21
- as_password: joi_1.default.bool(),
22
- show: joi_1.default.bool(),
23
- t: joi_1.default.string(),
24
- as_array: joi_1.default.bool(),
25
- array_min: joi_1.default.when(`as_array`, {
26
- is: true,
27
- then: joi_1.default.number(),
28
- otherwise: joi_1.default.forbidden(),
29
- }),
30
- array_max: joi_1.default.when(`as_array`, {
31
- is: true,
32
- then: joi_1.default.number(),
33
- otherwise: joi_1.default.forbidden(),
34
- }),
35
- array_length: joi_1.default.when(`as_array`, {
36
- is: true,
37
- then: joi_1.default.number(),
38
- otherwise: joi_1.default.forbidden(),
39
- }),
40
- }).concat(joi_1.default.object()
41
- .pattern(joi_1.default.string().regex(/^experimental_/), joi_1.default.any()));
42
- const types = [`any`, `string`, `number`, `boolean`, `date`, `datetime`, `time`, `dict`, `file`];
43
- const inputFieldBaseSchema = () => joi_1.default.object({
44
- type: joi_1.default.string().required()
45
- .valid(...types),
46
- })
47
- .concat(commonFieldSchema())
48
- .unknown();
49
- const choiceSchema = (type) => joi_1.default.object({
50
- key: joi_1.default.string().required(),
51
- value: type.required(),
52
- group: joi_1.default.string(),
53
- }).unknown();
54
- const choicesSchema = (type) => joi_1.default.alternatives(joi_1.default.string(), joi_1.default.array().min(1)
55
- .items(choiceSchema(type)));
56
- const defaultSchema = (type) => joi_1.default.when(`as_array`, {
57
- is: true,
58
- then: joi_1.default.array().items(type),
59
- otherwise: type,
60
- });
61
- const anySchema = (nullish = true) => {
62
- const randId = Math.random().toString(36).substring(2, 15);
63
- return joi_1.default.alternatives(joi_1.default.string(), joi_1.default.bool(), joi_1.default.number(), joi_1.default.array().items(joi_1.default.link(`#${randId}`)), joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.link(`#${randId}`)), ...nullish ? [joi_1.default.valid(null, ``)] : [])
64
- .id(randId);
65
- };
66
- const anyInputFieldSchema = () => joi_1.default.object({
67
- default: defaultSchema(anySchema()),
68
- allow_nullish: joi_1.default.bool().default(true),
69
- })
70
- .concat(joi_1.default.object({
71
- format: joi_1.default.string().valid(`select`),
72
- choices: joi_1.default.when(`format`, {
73
- is: `select`,
74
- then: choicesSchema(anySchema()).required(),
75
- otherwise: joi_1.default.forbidden(),
76
- }),
77
- }));
78
- const stringInputFieldSchema = () => joi_1.default.object({
79
- default: defaultSchema(joi_1.default.string()),
80
- length: joi_1.default.number(),
81
- min: joi_1.default.number(),
82
- max: joi_1.default.number(),
83
- regexp: joi_1.default.string(),
84
- pattern: joi_1.default.string().valid(`email`, `uri`),
85
- allow_empty: joi_1.default.bool().default(false),
86
- })
87
- .concat(joi_1.default.object({
88
- format: joi_1.default.string().valid(`select`, `textarea`, `rich-text`, `markdown`, `code`),
89
- choices: joi_1.default.when(`format`, {
90
- is: `select`,
91
- then: choicesSchema(joi_1.default.string()).required(),
92
- otherwise: joi_1.default.forbidden(),
93
- }),
94
- language: joi_1.default.when(`format`, {
95
- is: `code`,
96
- then: joi_1.default.string(),
97
- otherwise: joi_1.default.forbidden(),
98
- }),
99
- }));
100
- const numberInputFieldSchema = () => joi_1.default.object({
101
- default: defaultSchema(joi_1.default.number()),
102
- min: joi_1.default.number(),
103
- max: joi_1.default.number(),
104
- float: joi_1.default.bool(),
105
- decimals: joi_1.default.when(`float`, {
106
- is: true,
107
- then: joi_1.default.number(),
108
- otherwise: joi_1.default.forbidden(),
109
- }),
110
- })
111
- .concat(joi_1.default.object({
112
- format: joi_1.default.string().valid(`select`),
113
- choices: joi_1.default.when(`format`, {
114
- is: `select`,
115
- then: choicesSchema(joi_1.default.number()).required(),
116
- otherwise: joi_1.default.forbidden(),
117
- }),
118
- }));
119
- const booleanInputFieldSchema = () => joi_1.default.object({
120
- default: defaultSchema(joi_1.default.bool()),
121
- })
122
- .concat(joi_1.default.object({
123
- format: joi_1.default.string().valid(`select`, `checkbox`, `switch`),
124
- choices: joi_1.default.when(`format`, {
125
- is: `select`,
126
- then: choicesSchema(joi_1.default.bool()).required(),
127
- otherwise: joi_1.default.forbidden(),
128
- }),
129
- }));
130
- const dateInputFieldSchema = () => joi_1.default.object({
131
- default: defaultSchema(joi_1.default.alternatives(joi_1.default.string(), joi_1.default.number())),
132
- min: joi_1.default.alternatives(joi_1.default.string(), joi_1.default.number()),
133
- max: joi_1.default.alternatives(joi_1.default.string(), joi_1.default.number()),
134
- })
135
- .concat(joi_1.default.object({
136
- format: joi_1.default.string().valid(`select`),
137
- choices: joi_1.default.when(`format`, {
138
- is: `select`,
139
- then: choicesSchema(joi_1.default.alternatives(joi_1.default.string(), joi_1.default.number())).required(),
140
- otherwise: joi_1.default.forbidden(),
141
- }),
142
- }));
143
- const timeInputFieldSchema = () => joi_1.default.object({
144
- default: defaultSchema(joi_1.default.alternatives(joi_1.default.string(), joi_1.default.number())),
145
- })
146
- .concat(joi_1.default.object({
147
- format: joi_1.default.string().valid(`select`),
148
- choices: joi_1.default.when(`format`, {
149
- is: `select`,
150
- then: choicesSchema(joi_1.default.alternatives(joi_1.default.string(), joi_1.default.number())).required(),
151
- otherwise: joi_1.default.forbidden(),
152
- }),
153
- }));
154
- const dictInputFieldSchema = () => joi_1.default.object({
155
- default: defaultSchema(joi_1.default.object()),
156
- items: joi_1.default.array().items(joi_1.default.link(`#field`)).min(1),
157
- unknown: joi_1.default.when(`items`, {
158
- is: joi_1.default.exist(),
159
- then: joi_1.default.bool(),
160
- otherwise: joi_1.default.forbidden(),
161
- }),
162
- });
163
- const fileSchema = () => joi_1.default.object({
164
- name: joi_1.default.string().required(),
165
- type: joi_1.default.string().required(),
166
- content: joi_1.default.string().required(),
167
- });
168
- const fileReplacer = (field) => ({
169
- key: field.key,
170
- type: `dict`,
171
- unknown: true,
172
- items: [
173
- {
174
- key: `name`,
175
- type: `string`,
176
- required: true,
177
- },
178
- {
179
- key: `type`,
180
- type: `string`,
181
- required: true,
182
- },
183
- {
184
- key: `content`,
185
- type: `string`,
186
- required: true,
187
- },
188
- ],
189
- default: field.default,
190
- ...lodash_1.default.pick(field, [`altered_by`, `disabled`, `required`, `as_password`, `show`, `as_array`, `array_min`, `array_max`, `array_length`]),
191
- ...Object.assign({}, ...Object.entries(field).map(([k, v]) => k.startsWith(`experimental_`) ? { [k]: v } : {})),
192
- });
193
- const fileInputFieldSchema = () => joi_1.default.object({
194
- default: defaultSchema(fileSchema()),
195
- accept: joi_1.default.alternatives(joi_1.default.string(), joi_1.default.array().items(joi_1.default.string())).optional(),
196
- })
197
- .concat(joi_1.default.object({
198
- format: joi_1.default.string().valid(`select`),
199
- choices: joi_1.default.when(`format`, {
200
- is: `select`,
201
- then: choicesSchema(fileSchema()).required(),
202
- otherwise: joi_1.default.forbidden(),
203
- }),
204
- }));
205
- const fieldSchema = () => inputFieldBaseSchema()
206
- .id(`field`)
207
- .when(joi_1.default.object({ type: joi_1.default.valid(`any`) }).unknown(), {
208
- then: inputFieldBaseSchema()
209
- .concat(anyInputFieldSchema()),
210
- })
211
- .when(joi_1.default.object({ type: joi_1.default.valid(`string`) }).unknown(), {
212
- then: inputFieldBaseSchema()
213
- .concat(stringInputFieldSchema()),
214
- })
215
- .when(joi_1.default.object({ type: joi_1.default.valid(`number`) }).unknown(), {
216
- then: inputFieldBaseSchema()
217
- .concat(numberInputFieldSchema()),
218
- })
219
- .when(joi_1.default.object({ type: joi_1.default.valid(`boolean`) }).unknown(), {
220
- then: inputFieldBaseSchema()
221
- .concat(booleanInputFieldSchema()),
222
- })
223
- .when(joi_1.default.object({ type: joi_1.default.valid(`date`, `datetime`) }).unknown(), {
224
- then: inputFieldBaseSchema()
225
- .concat(dateInputFieldSchema()),
226
- })
227
- .when(joi_1.default.object({ type: joi_1.default.valid(`time`) }).unknown(), {
228
- then: inputFieldBaseSchema()
229
- .concat(timeInputFieldSchema()),
230
- })
231
- .when(joi_1.default.object({ type: joi_1.default.valid(`dict`) }).unknown(), {
232
- then: inputFieldBaseSchema()
233
- .concat(dictInputFieldSchema()),
234
- })
235
- .when(joi_1.default.object({ type: joi_1.default.valid(`file`) }).unknown(), {
236
- then: inputFieldBaseSchema()
237
- .concat(fileInputFieldSchema()),
238
- })
239
- .when(joi_1.default.object({ type: joi_1.default.invalid(...types) }).unknown(), {
240
- then: joi_1.default.forbidden(),
241
- });
242
- exports.fieldSchema = fieldSchema;
243
- const fieldsSchema = () => joi_1.default.array().items((0, exports.fieldSchema)());
244
- exports.fieldsSchema = fieldsSchema;
245
- const getSimpleFieldSchema = (field) => {
246
- if (field.as_array) {
247
- throw new Error(`Cannot use as_array with simple field schema generator`);
248
- }
249
- let typeSchema;
250
- switch (field.type) {
251
- case `any`:
252
- typeSchema = anySchema(field.allow_nullish);
253
- break;
254
- case `boolean`:
255
- typeSchema = joi_1.default.bool();
256
- break;
257
- case `string`:
258
- typeSchema = joi_1.default.string();
259
- if (field.length) {
260
- typeSchema = typeSchema.length(field.length);
261
- }
262
- if (field.min > 0) {
263
- typeSchema = typeSchema.min(field.min);
264
- }
265
- else if (field.allow_empty) {
266
- typeSchema = typeSchema.allow(``);
267
- }
268
- if (field.max) {
269
- typeSchema = typeSchema.max(field.max);
270
- }
271
- if (field.regexp) {
272
- typeSchema = typeSchema.regex(new RegExp(field.regexp));
273
- }
274
- if (field.pattern === `email`) {
275
- typeSchema = typeSchema.email();
276
- }
277
- if (field.pattern === `uri`) {
278
- typeSchema = typeSchema.uri();
279
- }
280
- break;
281
- case `date`:
282
- case `datetime`:
283
- case `time`:
284
- if (field.type === `time`) {
285
- typeSchema = joi_1.default.string();
286
- }
287
- else {
288
- typeSchema = joi_1.default.date().strict(false);
289
- if (field.min) {
290
- typeSchema = typeSchema.min(field.min);
291
- }
292
- if (field.max) {
293
- typeSchema = typeSchema.max(field.max);
294
- }
295
- }
296
- typeSchema = typeSchema.external(async (value, helpers) => {
297
- if (!helpers.original && !field.required) {
298
- return helpers.original;
299
- }
300
- const format = field.type === `date` ? `YYYY-MM-DD` :
301
- field.type === `time` ? `HH:mmZ` :
302
- `YYYY-MM-DDTHH:mm:ssZ`;
303
- const d = (field.type === `datetime` && typeof helpers.original === `number`) ?
304
- moment_timezone_1.default.unix(helpers.original).tz(`UTC`)
305
- : moment_timezone_1.default.tz(helpers.original, format, `UTC`);
306
- if (!d.isValid()) {
307
- return helpers.message({ external: `invalid format, expected ${format}` });
308
- }
309
- const timezone = (field.type === `date` ? `UTC` : field.timezone) || `UTC`;
310
- return d.tz(timezone).format(format);
311
- });
312
- break;
313
- case `number`:
314
- typeSchema = joi_1.default.number();
315
- if (field.min) {
316
- typeSchema = typeSchema.min(field.min);
317
- }
318
- if (field.max) {
319
- typeSchema = typeSchema.max(field.max);
320
- }
321
- if (typeof field.float === `boolean`) {
322
- if (!field.float) {
323
- typeSchema = typeSchema.precision(0);
324
- }
325
- else if (field.decimals) {
326
- typeSchema = typeSchema.precision(field.decimals);
327
- }
328
- }
329
- break;
330
- case `dict`:
331
- if (field.items) {
332
- throw new Error(`No simple field`);
333
- }
334
- typeSchema = joi_1.default.object().unknown(true);
335
- break;
336
- case `file`:
337
- typeSchema = fileSchema();
338
- break;
339
- }
340
- if (`format` in field && field.format === `select`) {
341
- if (!field.unknown) {
342
- if (lodash_1.default.isArray(field.choices)) {
343
- typeSchema = typeSchema.valid(...field.choices.map((c) => c.value));
344
- }
345
- else {
346
- }
347
- }
348
- }
349
- return getGeneralSchema(field, typeSchema);
350
- };
351
- const getGeneralArraySchema = (field, schema) => {
352
- if (!field.as_array) {
353
- throw new Error(`as_array required for array schema generator`);
354
- }
355
- if (field.array_length) {
356
- schema = schema.length(field.array_length);
357
- }
358
- if (field.array_min) {
359
- schema = schema.min(field.array_min);
360
- }
361
- if (field.array_max) {
362
- schema = schema.max(field.array_max);
363
- }
364
- return getGeneralSchema(field, schema);
365
- };
366
- const getItemsArrayFieldSchema = (field, alternatives) => {
367
- if (!field.as_array) {
368
- throw new Error(`as_array required for array schema generator`);
369
- }
370
- const schema = joi_1.default.array().items(...alternatives);
371
- return getGeneralArraySchema(field, schema);
372
- };
373
- const getOrderedArrayFieldSchema = (field, items) => {
374
- if (!field.as_array) {
375
- throw new Error(`as_array required for array schema generator`);
376
- }
377
- const schema = joi_1.default.array().ordered(...items);
378
- return getGeneralArraySchema(field, schema);
379
- };
380
- const getObjectFieldSchema = (field, items) => {
381
- if (field.type !== `dict`) {
382
- throw new Error(`type must be dict for object schema generator`);
383
- }
384
- if (!field.items) {
385
- throw new Error(`items required for object schema generator`);
386
- }
387
- let schema = joi_1.default.object();
388
- for (const item of items) {
389
- schema = schema.concat(joi_1.default.object({
390
- [item.key]: item.schema,
391
- }));
392
- }
393
- if (field.unknown) {
394
- schema = schema.unknown(field.unknown);
395
- }
396
- return getGeneralSchema(field, schema);
397
- };
398
- const getGeneralSchema = (field, schema) => {
399
- if (field.required) {
400
- schema = schema.required();
401
- }
402
- if (field.disabled) {
403
- schema = schema.forbidden();
404
- }
405
- return schema;
406
- };
407
- const convertPath = (parts) => parts.map((p, i) => typeof p === `string` ? (i === 0 ? p : `.${p}`) : `[${p}]`).join(``);
408
- const secure = async (field, validation) => field.as_password ? lodash_1.default.omit(validation, [`value`, `original`]) : validation;
409
- const relative_condition = (condition, relative) => {
410
- try {
411
- const newCondition = lodash_1.default.cloneDeep(condition);
412
- for (const key of Object.keys(newCondition)) {
413
- if (key.startsWith(`@relative`)) {
414
- const newKey = key.replace(`@relative`, relative ? relative : ``);
415
- newCondition[newKey] = newCondition[key];
416
- delete newCondition[key];
417
- }
418
- }
419
- return newCondition;
420
- }
421
- catch (e) {
422
- throw e;
423
- }
424
- };
425
- const alter = (field, relative, data) => {
426
- const cloned = lodash_1.default.cloneDeep(field);
427
- for (const alteration of cloned.altered_by) {
428
- const condition = relative_condition(alteration.condition, relative);
429
- const matches = (0, where_1.where)(data, [condition]);
430
- if (matches) {
431
- lodash_1.default.assign(cloned, alteration.overrides);
432
- }
433
- }
434
- return cloned;
435
- };
436
- exports.alter = alter;
437
- const recursive_schema = async (field, data, options) => {
438
- try {
439
- let newField = lodash_1.default.cloneDeep(field);
440
- if (newField.altered_by?.length > 0) {
441
- newField = (0, exports.alter)(newField, options.relative, data);
442
- if (options.alter) {
443
- delete newField.altered_by;
444
- }
445
- if (typeof newField.show === `boolean` && !newField.show) {
446
- return;
447
- }
448
- }
449
- const alteredField = lodash_1.default.cloneDeep(newField);
450
- if (newField.type === `file`) {
451
- newField = fileReplacer(newField);
452
- }
453
- const relativeKey = options.relative ?
454
- options.relative.endsWith(`]`) ?
455
- options.array ? options.relative : `${options.relative}.${newField.key}`
456
- : `${options.relative}.${newField.key}`
457
- : newField.key;
458
- const value = lodash_1.default.get(data, relativeKey, newField.default);
459
- const resolved = context_1.default.resolve(newField, value, options.context);
460
- if (typeof resolved !== `undefined`) {
461
- lodash_1.default.set(data, relativeKey, resolved);
462
- }
463
- let calculatedSchema;
464
- if (newField.as_array) {
465
- const noArrayField = lodash_1.default.omit(newField, [`as_array`, `array_min`, `array_max`, `array_length`]);
466
- if (resolved) {
467
- const itemSchemas = [];
468
- if (lodash_1.default.isArray(resolved)) {
469
- for (let i = 0; i < (resolved || []).length; i++) {
470
- const { schema: itemSchema } = await recursive_schema(noArrayField, data, { alter: false, relative: `${relativeKey}[${i}]`, array: true, context: options.context });
471
- if (itemSchema) {
472
- itemSchemas.push(itemSchema);
473
- }
474
- }
475
- }
476
- calculatedSchema = getOrderedArrayFieldSchema(newField, itemSchemas);
477
- }
478
- else {
479
- let genericItemSchema;
480
- if (noArrayField.type === `dict` && noArrayField.items) {
481
- const items = [];
482
- for (const item of noArrayField.items) {
483
- const recursive = await recursive_schema(item, data, { alter: options.alter && true, relative: `${relativeKey}[0]`, context: options.context });
484
- if (recursive) {
485
- items.push({ key: item.key, schema: recursive.schema, field: recursive.field });
486
- }
487
- }
488
- genericItemSchema = getObjectFieldSchema(noArrayField, items);
489
- noArrayField.items = items.map((i) => i.field);
490
- }
491
- else {
492
- genericItemSchema = getSimpleFieldSchema(noArrayField);
493
- }
494
- calculatedSchema = getItemsArrayFieldSchema(newField, [genericItemSchema]);
495
- }
496
- }
497
- else if (newField.type === `dict` && newField.items) {
498
- const items = [];
499
- for (const item of newField.items) {
500
- const recursive = await recursive_schema(item, data, { alter: options.alter && true, relative: relativeKey, context: options.context });
501
- if (recursive) {
502
- items.push({ key: item.key, schema: recursive.schema, field: recursive.field });
503
- }
504
- }
505
- calculatedSchema = getObjectFieldSchema(newField, items);
506
- newField.items = items.map((i) => i.field);
507
- }
508
- else {
509
- calculatedSchema = getSimpleFieldSchema(newField);
510
- }
511
- if (!calculatedSchema) {
512
- throw new Error(`Could not resolve schema for field ${newField.key}`);
513
- }
514
- if (newField.disabled) {
515
- lodash_1.default.unset(data, relativeKey);
516
- }
517
- return { schema: calculatedSchema, field: field.type === `file` ? alteredField : newField };
518
- }
519
- catch (e) {
520
- throw e;
521
- }
522
- };
523
- const validate_internal = async (fields, data, options) => {
524
- try {
525
- const response = { valid: true, fields: [] };
526
- for (const field of fields) {
527
- const value = lodash_1.default.get(data, field.key, field.default);
528
- const cloned = lodash_1.default.cloneDeep(data);
529
- const recursive = await recursive_schema(field, cloned, { alter: true, context: options.context });
530
- if (!recursive) {
531
- continue;
532
- }
533
- const resolved = lodash_1.default.get(cloned, field.key, field.default);
534
- let validation;
535
- let error;
536
- try {
537
- validation = await recursive.schema.validateAsync(resolved, { abortEarly: false });
538
- }
539
- catch (e) {
540
- error = e;
541
- }
542
- let extended;
543
- if (error) {
544
- extended = {
545
- valid: false,
546
- errors: error.details ? error.details.map((d) => ({
547
- type: d.type,
548
- path: convertPath([field.key, ...d.path]),
549
- message: d.message,
550
- })) : [
551
- {
552
- type: `unknown`,
553
- path: field.key,
554
- message: error.message,
555
- },
556
- ],
557
- original: value,
558
- value: null,
559
- };
560
- }
561
- else {
562
- lodash_1.default.set(data, field.key, validation);
563
- extended = {
564
- valid: true,
565
- original: value,
566
- value: validation,
567
- };
568
- }
569
- response.valid && (response.valid = error ? false : true);
570
- response.fields.push({
571
- ...recursive.field,
572
- ...options.secure ? await secure(field, extended) : extended,
573
- });
574
- }
575
- return response;
576
- }
577
- catch (e) {
578
- throw e;
579
- }
580
- };
581
- const validate = async (fields, data, options = {}) => {
582
- try {
583
- const { error } = (0, exports.fieldsSchema)().validate(fields);
584
- if (error) {
585
- throw new Error(`Invalid fields definition: ${error.message}`);
586
- }
587
- const defaultOptions = lodash_1.default.assign({ secure: true, break: false, context: {} }, options);
588
- const response = await validate_internal(fields, data, defaultOptions);
589
- return response;
590
- }
591
- catch (e) {
592
- throw e;
593
- }
594
- };
595
- exports.validate = validate;
596
- const extract_recursive = async (validation, options, path = ``) => {
597
- try {
598
- const response = {};
599
- for (const field of validation) {
600
- const key = lodash_1.default.compact([path, field.key]).join(`.`);
601
- lodash_1.default.set(response, key, options.original ? field.original : field.value);
602
- }
603
- return response;
604
- }
605
- catch (e) {
606
- throw e;
607
- }
608
- };
609
- const extract = async (validation, options = {}) => {
610
- try {
611
- return await extract_recursive(validation, options);
612
- }
613
- catch (e) {
614
- throw e;
615
- }
616
- };
617
- exports.extract = extract;
@@ -0,0 +1,31 @@
1
+ import Joi from "joi";
2
+ import { Field } from "./fields";
3
+ type ValidationExtended = {
4
+ original: any;
5
+ value: any;
6
+ } & ({
7
+ valid: true;
8
+ } | {
9
+ valid: false;
10
+ errors: {
11
+ path: string;
12
+ message: string;
13
+ type: string;
14
+ }[];
15
+ });
16
+ export declare const fieldSchema: () => Joi.ObjectSchema<any>;
17
+ export declare const fieldsSchema: () => Joi.ArraySchema<any[]>;
18
+ export type ValidationResult<Extended = Record<string, never>> = {
19
+ valid: boolean;
20
+ fields: Field<Extended & ValidationExtended>[];
21
+ };
22
+ export declare const alter: (field: Field, relative: string, data: Record<string, any>) => Field;
23
+ export declare const validate: <I>(fields: Field<I>[], data: Record<string, any>, options?: {
24
+ secure?: boolean;
25
+ break?: boolean;
26
+ context?: Record<string, any>;
27
+ }) => Promise<ValidationResult<I>>;
28
+ export declare const extract: (validation: Field<ValidationExtended>[], options?: {
29
+ original?: boolean;
30
+ }) => Promise<Record<string, any>>;
31
+ export {};