Контекст для MetaFor - v1.0.3
    Preparing search index...

    Type Alias Types

    Типы для описания контекста.

    Является фабрикой для создания схемы контекста.

    Декларация всех типов однообразна, за небольшим исключением в enum.


    Опциональные поля могут принимать значения null.

    Имеет возможность определения в 3 вариантах:

    1. В виде ключа типа (опциональный)
    new Context((types) => ({
    string: types.string,
    number: types.number,
    boolean: types.boolean,
    array: types.array,
    enum: types.enum,
    }))

    Вариант удобен на этапе проектирования - без передачи значений по умолчанию и опциональных параметров.

    1. Вызов как функции (опциональный)
    new Context((types) => ({
    string: types.string(),
    number: types.number(),
    boolean: types.boolean(),
    array: types.array(),
    enum: types.enum(),
    }))

    Вариант удобен на этапе проектирования с возможностью передачи значений по умолчанию и опциональных параметров.

    1. Опциональный
    new Context((types) => ({
    string: types.string.optional(),
    number: types.number.optional(),
    boolean: types.boolean.optional(),
    array: types.array.optional(),
    enum: types.enum().optional(),
    }))

    Для удобного визуального восприятия, поддерживая однообразие с required вариантом, .optional() и .required() имеют одинаковую сигнатуру.

    new Context((types) => ({
    string: types.string.required("default"),
    number: types.number.required(1),
    boolean: types.boolean.required(true),
    array: types.array.required([1, 2, 3]),
    enum: types.enum("a", "b", "c").required("a"),
    }))

    Поддерживается возможность передачи значения по умолчанию для опционального и обязательного поля.

    new Context((types) => ({
    string: types.string("default"),
    stringWithoutDefault: types.string(),
    number: types.number(1),
    numberWithoutDefault: types.number(),
    boolean: types.boolean(true),
    booleanWithoutDefault: types.boolean(),
    array: types.array([1, 2, 3]),
    arrayWithoutDefault: types.array(),
    enum: types.enum("a", "b", "c")("a"),
    }))
    new Context((types) => ({
    string: types.string.required("default"),
    number: types.number.required(1),
    boolean: types.boolean.required(true),
    array: types.array.required([1, 2, 3]),
    enum: types.enum("a", "b", "c").required("a"),
    }))

    Обязательное поле должно иметь значение по умолчанию.

    new Context((types) => ({
    // @ts-expect-error - TypeScript запрещает null для required string
    string: types.string.required(),
    // @ts-expect-error - TypeScript запрещает null для required number
    number: types.number.required(),
    // @ts-expect-error - TypeScript запрещает null для required boolean
    boolean: types.boolean.required(),
    // @ts-expect-error - TypeScript запрещает null для required array
    array: types.array.required(),
    // @ts-expect-error - TypeScript запрещает null для required enum
    enum: types.enum("a", "b", "c").required(),
    }))

    new Context((types) => ({
    string: types.string()({ title: "string" }),
    number: types.number()({ title: "number" }),
    boolean: types.boolean()({ title: "boolean" }),
    array: types.array()({ title: "array" }),
    enum: types.enum()()({ title: "enum" }),
    }))
    type Types = {
        string: TypePrimitive<string, "string">;
        number: TypePrimitive<number, "number">;
        boolean: TypePrimitive<boolean, "boolean">;
        array: TypeArray;
        enum: TypeEnum;
    }
    Index

    Properties

    string: TypePrimitive<string, "string">

    Строковый тип.

    new Context((types) => ({
    short: types.string,

    callable: types.string(),
    callableOptions: types.string()({ title: "title" }),
    callableDefault: types.string("default"),

    optional: types.string.optional(),
    optionalOptions: types.string.optional()({ title: "title" }),
    optionalDefault: types.string.optional("default"),

    required: types.string.required("default"),
    requiredOptions: types.string.required("default")({ title: "title" }),
    requiredDefault: types.string.required("default"),
    }))
    number: TypePrimitive<number, "number">

    Числовой тип.

    new Context((types) => ({
    number: types.number,
    callable: types.number(),
    callableOptions: types.number()({ title: "number" }),
    callableDefault: types.number(4),

    optional: types.number.optional(),
    optionalOptions: types.number.optional()({ title: "number" }),
    optionalDefault: types.number.optional(4),

    required: types.number.required(4),
    requiredOptions: types.number.required(4)({ title: "number" }),
    }))
    boolean: TypePrimitive<boolean, "boolean">

    Логический тип.

    new Context((types) => ({
    short: types.boolean,

    callable: types.boolean(),
    callableOptions: types.boolean()({ title: "boolean" }),
    callableDefault: types.boolean(true),

    optional: types.boolean.optional(),
    optionalOptions: types.boolean.optional()({ title: "boolean" }),
    optionalDefault: types.boolean.optional(true),

    required: types.boolean.required(true),
    requiredOptions: types.boolean.required(true)({ title: "boolean" }),
    }))
    array: TypeArray

    Массив примитивов. Массив плоский и однородный.

    new Context(
    (types) => ({
    short: types.array,

    callable: types.array(),
    callableOptions: types.array()({ title: "array" }),
    callableDefault: types.array([1, 2, 3]),

    optional: types.array.optional(),
    optionalOptions: types.array.optional()({ title: "array" }),
    optionalDefault: types.array.optional([1, 2, 3]),

    required: types.array.required([1, 2, 3]),
    requiredOptions: types.array.required([1, 2, 3])({ title: "array" }),
    })
    enum: TypeEnum

    Перечисления.

    Перечисления однородные.

    Значения для enum могут отсутствовать. (схема)

    new Context((types) => ({
    short: types.enum,
    callable: types.enum(),
    optional: types.enum().optional(),
    }))

    Варианты декларации.

    new Context((types) => ({
    short: types.enum,

    callable: types.enum(),
    callableOptions: types.enum(1, 2)()({ title: "enum" }),
    callableDefault: types.enum("user", "admin")("user"),

    optional: types.enum().optional(),
    optionalOptions: types.enum().optional()({ title: "enum" }),
    optionalDefault: types.enum("user", "admin").optional("user"),

    required: types.enum("user", "admin").required("user"),
    requiredOptions: types.enum(1, 2, 3, 4).required(4)({ title: "числовые значения" }),
    })