@naturalcycles/nodejs-lib 15.32.1 → 15.33.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyObject, BaseDBEntity, IANATimezone, IsoDate, IsoDateTime, NumberEnum, StringEnum, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
|
|
1
|
+
import type { AnyObject, BaseDBEntity, IANATimezone, IsoDate, IsoDateTime, NumberEnum, StringEnum, StringMap, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
|
|
2
2
|
import type { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi';
|
|
3
3
|
import type { NumberSchema } from './number.extensions.js';
|
|
4
4
|
import type { StringSchema } from './string.extensions.js';
|
|
@@ -38,6 +38,7 @@ export declare function anyObjectSchema<T extends AnyObject>(): ObjectSchema<T>;
|
|
|
38
38
|
export declare function objectSchema<T extends AnyObject>(schema: {
|
|
39
39
|
[key in keyof Partial<T>]: AnySchema<T[key]>;
|
|
40
40
|
}): ObjectSchema<T>;
|
|
41
|
+
export declare function stringMapSchema<T>(key: AnySchema, value: AnySchema<T>): ObjectSchema<StringMap<T>>;
|
|
41
42
|
export declare function oneOfSchema<T = any>(...schemas: AnySchema[]): AlternativesSchema<T>;
|
|
42
43
|
export declare const anySchema: AnySchema<any>;
|
|
43
44
|
export declare const BASE62_REGEX: RegExp;
|
|
@@ -45,6 +45,9 @@ export function anyObjectSchema() {
|
|
|
45
45
|
export function objectSchema(schema) {
|
|
46
46
|
return Joi.object(schema);
|
|
47
47
|
}
|
|
48
|
+
export function stringMapSchema(key, value) {
|
|
49
|
+
return Joi.object().pattern(key, value);
|
|
50
|
+
}
|
|
48
51
|
export function oneOfSchema(...schemas) {
|
|
49
52
|
return Joi.alternatives(schemas);
|
|
50
53
|
}
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
IsoDateTime,
|
|
13
13
|
NumberEnum,
|
|
14
14
|
StringEnum,
|
|
15
|
+
StringMap,
|
|
15
16
|
UnixTimestamp,
|
|
16
17
|
UnixTimestampMillis,
|
|
17
18
|
} from '@naturalcycles/js-lib/types'
|
|
@@ -87,6 +88,13 @@ export function objectSchema<T extends AnyObject>(schema: {
|
|
|
87
88
|
return Joi.object(schema)
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
export function stringMapSchema<T>(
|
|
92
|
+
key: AnySchema,
|
|
93
|
+
value: AnySchema<T>,
|
|
94
|
+
): ObjectSchema<StringMap<T>> {
|
|
95
|
+
return Joi.object().pattern(key, value)
|
|
96
|
+
}
|
|
97
|
+
|
|
90
98
|
export function oneOfSchema<T = any>(...schemas: AnySchema[]): AlternativesSchema<T> {
|
|
91
99
|
return Joi.alternatives(schemas)
|
|
92
100
|
}
|