@naturalcycles/nodejs-lib 15.122.4 → 15.123.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,6 +1,6 @@
|
|
|
1
1
|
import type { ValidationFunction, ValidationFunctionResult } from '@naturalcycles/js-lib';
|
|
2
2
|
import type { Set2 } from '@naturalcycles/js-lib/object';
|
|
3
|
-
import type { AnyObject, BaseDBEntity, IANATimezone, Inclusiveness, IsoDate, IsoDateTime, IsoMonth, NumberEnum, StringEnum, StringMap, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
|
|
3
|
+
import type { AnyObject, BaseDBEntity, IANATimezone, Inclusiveness, IsoDate, IsoDateTime, IsoMonth, Enum, NumberEnum, StringEnum, StringMap, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
|
|
4
4
|
import type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
|
|
5
5
|
import type { Ajv, ValidateFunction } from 'ajv';
|
|
6
6
|
import { AjvValidationError } from './ajvValidationError.js';
|
|
@@ -66,7 +66,9 @@ export declare const j: {
|
|
|
66
66
|
tuple<const S extends JSchema<any, any>[]>(items: S): JTuple<S>;
|
|
67
67
|
set<OUT, Opt>(itemSchema: JSchema<OUT, Opt>): JSet2Builder<OUT, Opt>;
|
|
68
68
|
buffer(): JBuilder<Buffer, false>;
|
|
69
|
-
enum<const T extends readonly (string | number | boolean | null)[] | StringEnum | NumberEnum
|
|
69
|
+
enum<const T extends readonly (string | number | boolean | null)[] | StringEnum | NumberEnum | {
|
|
70
|
+
readonly values: readonly (string | number | boolean | null)[];
|
|
71
|
+
}>(input: T, opt?: JsonBuilderRuleOpt): JEnum<T extends readonly (infer U)[] ? U : Enum<T>>;
|
|
70
72
|
/**
|
|
71
73
|
* Use only with primitive values, otherwise this function will throw to avoid bugs.
|
|
72
74
|
* To validate objects, use `anyOfBy`.
|
package/package.json
CHANGED
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
IsoDate,
|
|
20
20
|
IsoDateTime,
|
|
21
21
|
IsoMonth,
|
|
22
|
+
Enum,
|
|
22
23
|
NumberEnum,
|
|
23
24
|
StringEnum,
|
|
24
25
|
StringMap,
|
|
@@ -172,18 +173,14 @@ export const j = {
|
|
|
172
173
|
})
|
|
173
174
|
},
|
|
174
175
|
|
|
175
|
-
enum<
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
:
|
|
182
|
-
|
|
183
|
-
: T extends NumberEnum
|
|
184
|
-
? T[keyof T]
|
|
185
|
-
: never
|
|
186
|
-
> {
|
|
176
|
+
enum<
|
|
177
|
+
const T extends
|
|
178
|
+
| readonly (string | number | boolean | null)[]
|
|
179
|
+
| StringEnum
|
|
180
|
+
| NumberEnum
|
|
181
|
+
// an `_enum()` object, which carries helpers and so satisfies neither of the two above
|
|
182
|
+
| { readonly values: readonly (string | number | boolean | null)[] },
|
|
183
|
+
>(input: T, opt?: JsonBuilderRuleOpt): JEnum<T extends readonly (infer U)[] ? U : Enum<T>> {
|
|
187
184
|
let enumValues: readonly (string | number | boolean | null)[] | undefined
|
|
188
185
|
let baseType: EnumBaseType = 'other'
|
|
189
186
|
|