UNPKG

juniper

Version:

ESM JSON Schema builder for static Typescript inference.

92 lines 2.64 kB
import { AbstractSchema, type SchemaGenerics, type SchemaParams, type SerializationParams } from '../lib/schema.js'; import type { JsonSchema, SchemaType } from '../lib/types.js'; interface EnumParams<T> extends SchemaParams<T> { enum?: readonly T[]; } interface EnumGenerics<T> extends SchemaGenerics<T> { params: EnumParams<T>; } /** * Schema for defining enum types. * * To ensure best type inference, it is recommended to pass parameters `as const`. * * @example * const schema = EnumSchema.create({ enums: [1, 2] as const }).enum(3 as const); * * @template T */ export declare class EnumSchema<T = never> extends AbstractSchema<EnumGenerics<T>> { #private; /** * Enums aren't conditional. */ allOf: never; /** * Enums aren't conditional. */ anyOf: never; /** * Enums aren't conditional. */ if: never; /** * Enums aren't conditional. */ not: never; /** * Not applicable. */ nullable: never; /** * Enums aren't conditional. */ oneOf: never; /** * @override */ constructor(options?: EnumParams<T>); /** * Create a new instance of EnumSchema. * * @param [options] - optional * @param [options.enums] - initial enum values. * @param [options.title] - Add title to schema * @param [options.description] - Add description to schema * @param [options.deprecated] - flag schema as deprecated * @param [options.readOnly] - value should not be modified * @param [options.writeOnly] - value should be hidden * @returns new enum schema */ static create<T = never>(this: void, options?: EnumParams<T>): EnumSchema<T>; /** * Append a possible `enum` value to the schema. * * Convenience method for calling `enums([val])`. * * @param this - this instance * @param val - enum literal * @returns cloned schema */ enum<EVal>(this: this, val: EVal): EnumSchema<EVal | T>; /** * Append multiple possible `enum` values to the schema. * * @see {@link https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.1.2} * * @param this - this instance * @param enums - enum literal array * @returns cloned schema */ enums<EVal>(this: this, enums: readonly EVal[]): EnumSchema<EVal | T>; /** * @override */ protected getCloneParams(): Required<EnumParams<T>>; /** * @override */ protected toSchema(params: SerializationParams): JsonSchema<SchemaType<this>>; } export {}; //# sourceMappingURL=enum.d.ts.map