UNPKG

@opra/common

Version:
73 lines (72 loc) 2.65 kB
import 'reflect-metadata'; import { type Combine, type Type } from 'ts-gems'; import { type Validator } from 'valgen'; import { OpraSchema } from '../../schema/index.js'; import type { ApiDocument } from '../api-document.js'; import type { DocumentElement } from '../common/document-element.js'; import { DataType } from './data-type.js'; /** * @namespace EnumType */ export declare namespace EnumType { type EnumObject = Record<string, string | number>; type EnumArray = readonly string[]; interface Metadata extends Combine<{ kind: OpraSchema.EnumType.Kind; base?: EnumObject | EnumArray | string; name: string; }, DataType.Metadata, OpraSchema.EnumType> { } interface Options<T, Keys extends string | number | symbol = T extends readonly any[] ? T[number] : keyof T> extends Combine<{ base?: EnumObject | EnumArray | string; meanings?: Record<Keys, string>; }, DataType.Options> { } interface InitArguments extends Combine<{ kind: OpraSchema.EnumType.Kind; base?: EnumType; instance?: object; }, DataType.InitArguments, EnumType.Metadata> { } } /** * Mixin type definition of class constructor and helper method for EnumType */ export interface EnumTypeStatic { /** * Class constructor of EnumType * * @param owner * @param args * @constructor */ new (owner: DocumentElement, args?: EnumType.InitArguments): EnumType; <T extends EnumType.EnumObject, B extends EnumType.EnumObject>(enumSource: T, base?: B, options?: EnumType.Options<T>): B & T; <T extends EnumType.EnumArray, B extends EnumType.EnumArray>(enumSource: T, base?: B, options?: EnumType.Options<T>): B & T; <T extends EnumType.EnumObject | EnumType.EnumArray>(target: T, options?: EnumType.Options<T>): T; } /** * Type definition of EnumType prototype * @interface EnumType */ export interface EnumType extends EnumTypeClass { } /** * @class EnumType */ export declare const EnumType: EnumTypeStatic; /** * @class EnumType */ declare class EnumTypeClass extends DataType { readonly kind: OpraSchema.EnumType.Kind; readonly base?: EnumType; readonly instance?: object; readonly attributes: Record<string | number, OpraSchema.EnumType.ValueInfo>; readonly ownAttributes: Record<string | number, OpraSchema.EnumType.ValueInfo>; extendsFrom(baseType: DataType | string | Type | object): boolean; generateCodec(): Validator; toJSON(options?: ApiDocument.ExportOptions): OpraSchema.EnumType; protected _locateBase(callback: (base: EnumType) => boolean): EnumType | undefined; } export {};