@naturalcycles/nodejs-lib 12.102.0 → 12.103.0
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/dist/index.d.ts +2 -2
- package/dist/validation/joi/joi.extensions.d.ts +4 -4
- package/dist/validation/joi/joi.model.js +4 -0
- package/dist/validation/joi/joi.shared.schemas.d.ts +48 -29
- package/dist/validation/joi/joi.shared.schemas.js +26 -1
- package/dist/validation/joi/number.extensions.d.ts +2 -2
- package/dist/validation/joi/string.extensions.d.ts +2 -2
- package/package.json +1 -1
- package/src/index.ts +3 -4
- package/src/validation/joi/joi.extensions.ts +4 -5
- package/src/validation/joi/joi.model.ts +5 -0
- package/src/validation/joi/joi.shared.schemas.ts +43 -5
- package/src/validation/joi/number.extensions.ts +2 -2
- package/src/validation/joi/string.extensions.ts +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as globby from 'globby';
|
|
|
5
5
|
import type { GlobbyOptions } from 'globby';
|
|
6
6
|
import { RequestError, TimeoutError } from 'got';
|
|
7
7
|
import type { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Got } from 'got';
|
|
8
|
-
import type { AnySchema, ValidationErrorItem, AlternativesSchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema,
|
|
8
|
+
import type { AnySchema, ValidationErrorItem, AlternativesSchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, ObjectSchema } from 'joi';
|
|
9
9
|
export * from './buffer/buffer.util';
|
|
10
10
|
export * from './diff/tableDiff';
|
|
11
11
|
export * from './got/getGot';
|
|
@@ -81,5 +81,5 @@ export * from './validation/joi/joi.validation.util';
|
|
|
81
81
|
export * from './script';
|
|
82
82
|
export * from './jwt/jwt.service';
|
|
83
83
|
export * from './fs/fs.util';
|
|
84
|
-
export type { GlobbyOptions, FastGlobOptions, ValidationErrorItem, Got, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema,
|
|
84
|
+
export type { GlobbyOptions, FastGlobOptions, ValidationErrorItem, Got, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, ObjectSchema, };
|
|
85
85
|
export { globby, fastGlob, RequestError, TimeoutError, Ajv };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as JoiLib from 'joi';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { NumberSchema } from './number.extensions';
|
|
3
|
+
import { StringSchema } from './string.extensions';
|
|
4
4
|
export interface ExtendedJoi extends JoiLib.Root {
|
|
5
|
-
string: <TSchema = string>() =>
|
|
6
|
-
number: <TSchema = number>() =>
|
|
5
|
+
string: <TSchema = string>() => StringSchema<TSchema>;
|
|
6
|
+
number: <TSchema = number>() => NumberSchema<TSchema>;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* This is the only right place to import Joi from
|
|
@@ -1,40 +1,59 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { SavedDBEntity } from '@naturalcycles/js-lib';
|
|
2
|
+
import { BaseDBEntity, NumberEnum, SavedDBEntity, StringEnum } from '@naturalcycles/js-lib';
|
|
3
3
|
import { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi';
|
|
4
|
-
import {
|
|
4
|
+
import { NumberSchema } from './number.extensions';
|
|
5
|
+
import { StringSchema } from './string.extensions';
|
|
5
6
|
export declare const booleanSchema: import("joi").BooleanSchema<boolean>;
|
|
6
7
|
export declare const booleanDefaultToFalseSchema: import("joi").BooleanSchema<boolean>;
|
|
7
|
-
export declare const stringSchema:
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
8
|
+
export declare const stringSchema: StringSchema<string>;
|
|
9
|
+
export declare const stringSchemaTyped: <T>() => StringSchema<T>;
|
|
10
|
+
export declare const numberSchema: NumberSchema<number>;
|
|
11
|
+
export declare const numberSchemaTyped: <T>() => NumberSchema<T>;
|
|
12
|
+
export declare const integerSchema: NumberSchema<number>;
|
|
13
|
+
export declare const percentageSchema: NumberSchema<number>;
|
|
14
|
+
export declare const dateStringSchema: StringSchema<string>;
|
|
12
15
|
export declare const binarySchema: import("joi").BinarySchema<Buffer>;
|
|
13
16
|
export declare const dateObjectSchema: ObjectSchema<any>;
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Allows all values of a String Enum.
|
|
19
|
+
*/
|
|
20
|
+
export declare const stringEnumValuesSchema: <ENUM extends StringEnum>(en: ENUM) => StringSchema<ENUM[keyof ENUM]>;
|
|
21
|
+
/**
|
|
22
|
+
* Allows all keys of a String Enum.
|
|
23
|
+
*/
|
|
24
|
+
export declare const stringEnumKeysSchema: <ENUM extends StringEnum>(en: ENUM) => StringSchema;
|
|
25
|
+
/**
|
|
26
|
+
* Allows all values of a String Enum.
|
|
27
|
+
*/
|
|
28
|
+
export declare const numberEnumValuesSchema: <ENUM extends NumberEnum>(en: ENUM) => NumberSchema<ENUM[keyof ENUM]>;
|
|
29
|
+
/**
|
|
30
|
+
* Allows all keys of a Number Enum.
|
|
31
|
+
*/
|
|
32
|
+
export declare const numberEnumKeysSchema: <ENUM extends NumberEnum>(en: ENUM) => StringSchema;
|
|
33
|
+
export declare const urlSchema: (scheme?: string | string[]) => StringSchema;
|
|
15
34
|
export declare function arraySchema<T>(items?: AnySchema<T>): ArraySchema<T[]>;
|
|
16
35
|
export declare function objectSchema<T>(schema?: {
|
|
17
36
|
[key in keyof Partial<T>]: AnySchema<T[key]>;
|
|
18
37
|
}): ObjectSchema<T>;
|
|
19
38
|
export declare function oneOfSchema<T = any>(...schemas: AnySchema[]): AlternativesSchema<T>;
|
|
20
39
|
export declare const anySchema: AnySchema<any>;
|
|
21
|
-
export declare const anyObjectSchema: ObjectSchema
|
|
40
|
+
export declare const anyObjectSchema: ObjectSchema;
|
|
22
41
|
export declare const BASE62_REGEX: RegExp;
|
|
23
42
|
export declare const BASE64_REGEX: RegExp;
|
|
24
43
|
export declare const BASE64URL_REGEX: RegExp;
|
|
25
|
-
export declare const base62Schema:
|
|
26
|
-
export declare const base64Schema:
|
|
27
|
-
export declare const base64UrlSchema:
|
|
44
|
+
export declare const base62Schema: StringSchema<string>;
|
|
45
|
+
export declare const base64Schema: StringSchema<string>;
|
|
46
|
+
export declare const base64UrlSchema: StringSchema<string>;
|
|
28
47
|
export declare const JWT_REGEX: RegExp;
|
|
29
|
-
export declare const jwtSchema:
|
|
48
|
+
export declare const jwtSchema: StringSchema<string>;
|
|
30
49
|
/**
|
|
31
50
|
* [a-zA-Z0-9_]*
|
|
32
51
|
* 6-64 length
|
|
33
52
|
*/
|
|
34
|
-
export declare const idSchema:
|
|
35
|
-
export declare const idBase62Schema:
|
|
36
|
-
export declare const idBase64Schema:
|
|
37
|
-
export declare const idBase64UrlSchema:
|
|
53
|
+
export declare const idSchema: StringSchema<string>;
|
|
54
|
+
export declare const idBase62Schema: StringSchema<string>;
|
|
55
|
+
export declare const idBase64Schema: StringSchema<string>;
|
|
56
|
+
export declare const idBase64UrlSchema: StringSchema<string>;
|
|
38
57
|
/**
|
|
39
58
|
* `_` should NOT be allowed to be able to use slug-ids as part of natural ids with `_` separator.
|
|
40
59
|
*/
|
|
@@ -42,35 +61,35 @@ export declare const SLUG_REGEX: RegExp;
|
|
|
42
61
|
/**
|
|
43
62
|
* "Slug" - a valid URL, filename, etc.
|
|
44
63
|
*/
|
|
45
|
-
export declare const slugSchema:
|
|
64
|
+
export declare const slugSchema: StringSchema<string>;
|
|
46
65
|
/**
|
|
47
66
|
* Between years 1970 and 2050
|
|
48
67
|
*/
|
|
49
|
-
export declare const unixTimestampSchema:
|
|
68
|
+
export declare const unixTimestampSchema: NumberSchema<number>;
|
|
50
69
|
/**
|
|
51
70
|
* Between years 2000 and 2050
|
|
52
71
|
*/
|
|
53
|
-
export declare const unixTimestamp2000Schema:
|
|
72
|
+
export declare const unixTimestamp2000Schema: NumberSchema<number>;
|
|
54
73
|
/**
|
|
55
74
|
* Between years 1970 and 2050
|
|
56
75
|
*/
|
|
57
|
-
export declare const unixTimestampMillisSchema:
|
|
76
|
+
export declare const unixTimestampMillisSchema: NumberSchema<number>;
|
|
58
77
|
/**
|
|
59
78
|
* Between years 2000 and 2050
|
|
60
79
|
*/
|
|
61
|
-
export declare const unixTimestampMillis2000Schema:
|
|
62
|
-
export declare const verSchema:
|
|
80
|
+
export declare const unixTimestampMillis2000Schema: NumberSchema<number>;
|
|
81
|
+
export declare const verSchema: NumberSchema<number>;
|
|
63
82
|
/**
|
|
64
83
|
* Be careful, by default emailSchema does TLD validation. To disable it - use `stringSchema.email({tld: false}).lowercase()`
|
|
65
84
|
*/
|
|
66
|
-
export declare const emailSchema:
|
|
85
|
+
export declare const emailSchema: StringSchema<string>;
|
|
67
86
|
/**
|
|
68
87
|
* Pattern is simplified for our use, it's not a canonical SemVer.
|
|
69
88
|
*/
|
|
70
89
|
export declare const SEM_VER_REGEX: RegExp;
|
|
71
|
-
export declare const semVerSchema:
|
|
72
|
-
export declare const userAgentSchema:
|
|
73
|
-
export declare const utcOffsetSchema:
|
|
74
|
-
export declare const ipAddressSchema:
|
|
75
|
-
export declare const baseDBEntitySchema: ObjectSchema<
|
|
90
|
+
export declare const semVerSchema: StringSchema<string>;
|
|
91
|
+
export declare const userAgentSchema: StringSchema<string>;
|
|
92
|
+
export declare const utcOffsetSchema: NumberSchema<number>;
|
|
93
|
+
export declare const ipAddressSchema: StringSchema<string>;
|
|
94
|
+
export declare const baseDBEntitySchema: ObjectSchema<BaseDBEntity>;
|
|
76
95
|
export declare const savedDBEntitySchema: ObjectSchema<SavedDBEntity<string>>;
|
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.savedDBEntitySchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.arraySchema = exports.urlSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchema = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
|
|
3
|
+
exports.savedDBEntitySchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.arraySchema = exports.urlSchema = exports.numberEnumKeysSchema = exports.numberEnumValuesSchema = exports.stringEnumKeysSchema = exports.stringEnumValuesSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchemaTyped = exports.numberSchema = exports.stringSchemaTyped = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
|
|
4
|
+
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
4
5
|
const joi_extensions_1 = require("./joi.extensions");
|
|
5
6
|
exports.booleanSchema = joi_extensions_1.Joi.boolean();
|
|
6
7
|
exports.booleanDefaultToFalseSchema = joi_extensions_1.Joi.boolean().default(false);
|
|
7
8
|
exports.stringSchema = joi_extensions_1.Joi.string();
|
|
9
|
+
const stringSchemaTyped = () => joi_extensions_1.Joi.string();
|
|
10
|
+
exports.stringSchemaTyped = stringSchemaTyped;
|
|
8
11
|
exports.numberSchema = joi_extensions_1.Joi.number();
|
|
12
|
+
const numberSchemaTyped = () => joi_extensions_1.Joi.number();
|
|
13
|
+
exports.numberSchemaTyped = numberSchemaTyped;
|
|
9
14
|
exports.integerSchema = joi_extensions_1.Joi.number().integer();
|
|
10
15
|
exports.percentageSchema = joi_extensions_1.Joi.number().integer().min(0).max(100);
|
|
11
16
|
exports.dateStringSchema = exports.stringSchema.dateString();
|
|
12
17
|
exports.binarySchema = joi_extensions_1.Joi.binary();
|
|
13
18
|
exports.dateObjectSchema = joi_extensions_1.Joi.object().instance(Date);
|
|
19
|
+
/**
|
|
20
|
+
* Allows all values of a String Enum.
|
|
21
|
+
*/
|
|
22
|
+
const stringEnumValuesSchema = (en) => joi_extensions_1.Joi.string().allow(...(0, js_lib_1._stringEnumValues)(en));
|
|
23
|
+
exports.stringEnumValuesSchema = stringEnumValuesSchema;
|
|
24
|
+
/**
|
|
25
|
+
* Allows all keys of a String Enum.
|
|
26
|
+
*/
|
|
27
|
+
const stringEnumKeysSchema = (en) => joi_extensions_1.Joi.string().allow(...(0, js_lib_1._stringEnumKeys)(en));
|
|
28
|
+
exports.stringEnumKeysSchema = stringEnumKeysSchema;
|
|
29
|
+
/**
|
|
30
|
+
* Allows all values of a String Enum.
|
|
31
|
+
*/
|
|
32
|
+
const numberEnumValuesSchema = (en) => joi_extensions_1.Joi.number().allow(...(0, js_lib_1._numberEnumValues)(en));
|
|
33
|
+
exports.numberEnumValuesSchema = numberEnumValuesSchema;
|
|
34
|
+
/**
|
|
35
|
+
* Allows all keys of a Number Enum.
|
|
36
|
+
*/
|
|
37
|
+
const numberEnumKeysSchema = (en) => joi_extensions_1.Joi.string().allow(...(0, js_lib_1._numberEnumKeys)(en));
|
|
38
|
+
exports.numberEnumKeysSchema = numberEnumKeysSchema;
|
|
14
39
|
const urlSchema = (scheme = 'https') => joi_extensions_1.Joi.string().uri({ scheme });
|
|
15
40
|
exports.urlSchema = urlSchema;
|
|
16
41
|
function arraySchema(items) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Joi from 'joi';
|
|
2
|
-
import { Extension, NumberSchema } from 'joi';
|
|
3
|
-
export interface
|
|
2
|
+
import { Extension, NumberSchema as JoiNumberSchema } from 'joi';
|
|
3
|
+
export interface NumberSchema<TSchema = number> extends JoiNumberSchema<TSchema> {
|
|
4
4
|
dividable: (q: number) => this;
|
|
5
5
|
}
|
|
6
6
|
export declare function numberExtensions(joi: typeof Joi): Extension;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Extension, StringSchema } from 'joi';
|
|
1
|
+
import { Extension, StringSchema as JoiStringSchema } from 'joi';
|
|
2
2
|
import * as Joi from 'joi';
|
|
3
|
-
export interface
|
|
3
|
+
export interface StringSchema<TSchema = string> extends JoiStringSchema<TSchema> {
|
|
4
4
|
dateString: (min?: string, max?: string) => this;
|
|
5
5
|
}
|
|
6
6
|
export interface JoiDateStringOptions {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,9 +14,7 @@ import type {
|
|
|
14
14
|
BooleanSchema,
|
|
15
15
|
DateSchema,
|
|
16
16
|
FunctionSchema,
|
|
17
|
-
NumberSchema,
|
|
18
17
|
ObjectSchema,
|
|
19
|
-
StringSchema,
|
|
20
18
|
} from 'joi'
|
|
21
19
|
export * from './buffer/buffer.util'
|
|
22
20
|
export * from './diff/tableDiff'
|
|
@@ -109,9 +107,10 @@ export type {
|
|
|
109
107
|
BooleanSchema,
|
|
110
108
|
DateSchema,
|
|
111
109
|
FunctionSchema,
|
|
112
|
-
NumberSchema,
|
|
113
110
|
ObjectSchema,
|
|
114
|
-
|
|
111
|
+
// extended
|
|
112
|
+
// NumberSchema,
|
|
113
|
+
// StringSchema,
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
export { globby, fastGlob, RequestError, TimeoutError, Ajv }
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { StringSchema } from 'joi'
|
|
2
1
|
import * as JoiLib from 'joi'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { NumberSchema, numberExtensions } from './number.extensions'
|
|
3
|
+
import { StringSchema, stringExtensions } from './string.extensions'
|
|
5
4
|
|
|
6
5
|
export interface ExtendedJoi extends JoiLib.Root {
|
|
7
6
|
// eslint-disable-next-line id-blacklist
|
|
8
|
-
string: <TSchema = string>() =>
|
|
7
|
+
string: <TSchema = string>() => StringSchema<TSchema>
|
|
9
8
|
// eslint-disable-next-line id-blacklist
|
|
10
|
-
number: <TSchema = number>() =>
|
|
9
|
+
number: <TSchema = number>() => NumberSchema<TSchema>
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// export interface ObjectSchema<T = any> extends JoiObjectSchema<T> {
|
|
2
|
+
// // Open-ended index signature to allow for easier .concat(baseDBEntitySchema)
|
|
3
|
+
// [k: string]: any
|
|
4
|
+
// }
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* This type is useful to allow "joi schema merging".
|
|
3
8
|
* Because by default Joi doesn't allow normal merging.
|
|
@@ -1,19 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
_numberEnumKeys,
|
|
3
|
+
_numberEnumValues,
|
|
4
|
+
_stringEnumKeys,
|
|
5
|
+
_stringEnumValues,
|
|
6
|
+
BaseDBEntity,
|
|
7
|
+
NumberEnum,
|
|
8
|
+
SavedDBEntity,
|
|
9
|
+
StringEnum,
|
|
10
|
+
} from '@naturalcycles/js-lib'
|
|
2
11
|
import { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi'
|
|
3
12
|
import { Joi } from './joi.extensions'
|
|
4
|
-
import {
|
|
13
|
+
import { NumberSchema } from './number.extensions'
|
|
14
|
+
import { StringSchema } from './string.extensions'
|
|
5
15
|
|
|
6
16
|
export const booleanSchema = Joi.boolean()
|
|
7
17
|
export const booleanDefaultToFalseSchema = Joi.boolean().default(false)
|
|
8
18
|
export const stringSchema = Joi.string()
|
|
19
|
+
export const stringSchemaTyped = <T>(): StringSchema<T> => Joi.string<T>()
|
|
9
20
|
export const numberSchema = Joi.number()
|
|
21
|
+
export const numberSchemaTyped = <T>(): NumberSchema<T> => Joi.number<T>()
|
|
10
22
|
export const integerSchema = Joi.number().integer()
|
|
11
23
|
export const percentageSchema = Joi.number().integer().min(0).max(100)
|
|
12
24
|
export const dateStringSchema = stringSchema.dateString()
|
|
13
25
|
export const binarySchema = Joi.binary()
|
|
14
26
|
export const dateObjectSchema = Joi.object().instance(Date)
|
|
15
27
|
|
|
16
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Allows all values of a String Enum.
|
|
30
|
+
*/
|
|
31
|
+
export const stringEnumValuesSchema = <ENUM extends StringEnum>(
|
|
32
|
+
en: ENUM,
|
|
33
|
+
): StringSchema<ENUM[keyof ENUM]> => Joi.string<ENUM[keyof ENUM]>().allow(..._stringEnumValues(en))
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Allows all keys of a String Enum.
|
|
37
|
+
*/
|
|
38
|
+
export const stringEnumKeysSchema = <ENUM extends StringEnum>(en: ENUM): StringSchema =>
|
|
39
|
+
Joi.string().allow(..._stringEnumKeys(en))
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Allows all values of a String Enum.
|
|
43
|
+
*/
|
|
44
|
+
export const numberEnumValuesSchema = <ENUM extends NumberEnum>(
|
|
45
|
+
en: ENUM,
|
|
46
|
+
): NumberSchema<ENUM[keyof ENUM]> => Joi.number<ENUM[keyof ENUM]>().allow(..._numberEnumValues(en))
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Allows all keys of a Number Enum.
|
|
50
|
+
*/
|
|
51
|
+
export const numberEnumKeysSchema = <ENUM extends NumberEnum>(en: ENUM): StringSchema =>
|
|
52
|
+
Joi.string().allow(..._numberEnumKeys(en))
|
|
53
|
+
|
|
54
|
+
export const urlSchema = (scheme: string | string[] = 'https'): StringSchema =>
|
|
17
55
|
Joi.string().uri({ scheme })
|
|
18
56
|
|
|
19
57
|
export function arraySchema<T>(items?: AnySchema<T>): ArraySchema<T[]> {
|
|
@@ -31,7 +69,7 @@ export function oneOfSchema<T = any>(...schemas: AnySchema[]): AlternativesSchem
|
|
|
31
69
|
}
|
|
32
70
|
|
|
33
71
|
export const anySchema = Joi.any()
|
|
34
|
-
export const anyObjectSchema = Joi.object().options({ stripUnknown: false })
|
|
72
|
+
export const anyObjectSchema: ObjectSchema = Joi.object().options({ stripUnknown: false })
|
|
35
73
|
|
|
36
74
|
export const BASE62_REGEX = /^[a-zA-Z0-9]+$/
|
|
37
75
|
export const BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/
|
|
@@ -116,7 +154,7 @@ export const utcOffsetSchema = numberSchema
|
|
|
116
154
|
|
|
117
155
|
export const ipAddressSchema = stringSchema.ip()
|
|
118
156
|
|
|
119
|
-
export const baseDBEntitySchema = objectSchema<BaseDBEntity>({
|
|
157
|
+
export const baseDBEntitySchema: ObjectSchema<BaseDBEntity> = objectSchema<BaseDBEntity>({
|
|
120
158
|
id: stringSchema.optional(),
|
|
121
159
|
created: unixTimestamp2000Schema.optional(),
|
|
122
160
|
updated: unixTimestamp2000Schema.optional(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Joi from 'joi'
|
|
2
|
-
import { Extension, NumberSchema } from 'joi'
|
|
2
|
+
import { Extension, NumberSchema as JoiNumberSchema } from 'joi'
|
|
3
3
|
|
|
4
|
-
export interface
|
|
4
|
+
export interface NumberSchema<TSchema = number> extends JoiNumberSchema<TSchema> {
|
|
5
5
|
dividable: (q: number) => this
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LocalDate, localTime } from '@naturalcycles/js-lib'
|
|
2
|
-
import { Extension, StringSchema } from 'joi'
|
|
2
|
+
import { Extension, StringSchema as JoiStringSchema } from 'joi'
|
|
3
3
|
import * as Joi from 'joi'
|
|
4
4
|
|
|
5
|
-
export interface
|
|
5
|
+
export interface StringSchema<TSchema = string> extends JoiStringSchema<TSchema> {
|
|
6
6
|
dateString: (min?: string, max?: string) => this
|
|
7
7
|
}
|
|
8
8
|
|