UNPKG

3.99 kBTypeScriptView Raw
1import { Context, Struct, Validator } from '../struct.js';
2import { Assign, ObjectSchema, ObjectType, PartialObjectSchema } from '../utils.js';
3/**
4 * Create a new struct that combines the properties properties from multiple
5 * object or type structs. Its return type will match the first parameter's type.
6 *
7 * Like JavaScript's `Object.assign` utility.
8 */
9export declare function assign<A extends ObjectSchema, B extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>): Struct<ObjectType<Assign<A, B>>, Assign<A, B>>;
10export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>): Struct<ObjectType<Assign<Assign<A, B>, C>>, Assign<Assign<A, B>, C>>;
11export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>): Struct<ObjectType<Assign<Assign<Assign<A, B>, C>, D>>, Assign<Assign<Assign<A, B>, C>, D>>;
12export declare function assign<A extends ObjectSchema, B extends ObjectSchema, C extends ObjectSchema, D extends ObjectSchema, E extends ObjectSchema>(A: Struct<ObjectType<A>, A>, B: Struct<ObjectType<B>, B>, C: Struct<ObjectType<C>, C>, D: Struct<ObjectType<D>, D>, E: Struct<ObjectType<E>, E>): Struct<ObjectType<Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>, Assign<Assign<Assign<Assign<A, B>, C>, D>, E>>;
13/**
14 * Define a new struct type with a custom validation function.
15 */
16export declare function define<T>(name: string, validator: Validator): Struct<T, null>;
17/**
18 * Create a new struct based on an existing struct, but the value is allowed to
19 * be `undefined`. `log` will be called if the value is not `undefined`.
20 */
21export declare function deprecated<T>(struct: Struct<T>, log: (value: unknown, ctx: Context) => void): Struct<T>;
22/**
23 * Create a struct with dynamic validation logic.
24 *
25 * The callback will receive the value currently being validated, and must
26 * return a struct object to validate it with. This can be useful to model
27 * validation logic that changes based on its input.
28 */
29export declare function dynamic<T>(fn: (value: unknown, ctx: Context) => Struct<T, any>): Struct<T, null>;
30/**
31 * Create a struct with lazily evaluated validation logic.
32 *
33 * The first time validation is run with the struct, the callback will be called
34 * and must return a struct object to use. This is useful for cases where you
35 * want to have self-referential structs for nested data structures to avoid a
36 * circular definition problem.
37 */
38export declare function lazy<T>(fn: () => Struct<T, any>): Struct<T, null>;
39/**
40 * Create a new struct based on an existing object struct, but excluding
41 * specific properties.
42 *
43 * Like TypeScript's `Omit` utility.
44 */
45export declare function omit<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Omit<S, K>>, Omit<S, K>>;
46/**
47 * Create a new struct based on an existing object struct, but with all of its
48 * properties allowed to be `undefined`.
49 *
50 * Like TypeScript's `Partial` utility.
51 */
52export declare function partial<S extends ObjectSchema>(struct: Struct<ObjectType<S>, S> | S): Struct<ObjectType<PartialObjectSchema<S>>, PartialObjectSchema<S>>;
53/**
54 * Create a new struct based on an existing object struct, but only including
55 * specific properties.
56 *
57 * Like TypeScript's `Pick` utility.
58 */
59export declare function pick<S extends ObjectSchema, K extends keyof S>(struct: Struct<ObjectType<S>, S>, keys: K[]): Struct<ObjectType<Pick<S, K>>, Pick<S, K>>;
60/**
61 * Define a new struct type with a custom validation function.
62 *
63 * @deprecated This function has been renamed to `define`.
64 */
65export declare function struct<T>(name: string, validator: Validator): Struct<T, null>;
66//# sourceMappingURL=utilities.d.ts.map
\No newline at end of file