UNPKG

@opra/common

Version:
90 lines (89 loc) 3.75 kB
import type { Combine, StrictOmit, TypeThunkAsync } from 'ts-gems'; import { OpraSchema } from '../../schema/index.js'; import type { ApiDocument } from '../api-document.js'; import { DocumentElement } from '../common/document-element.js'; import { ApiFieldDecoratorFactory } from '../decorators/api-field-decorator.js'; import type { ComplexType } from './complex-type.js'; import type { DataType } from './data-type.js'; import type { EnumType } from './enum-type.js'; import type { MappedType } from './mapped-type.js'; import type { MixinType } from './mixin-type.js'; /** * Type definition of ComplexType constructor type * @type ApiFieldConstructor */ export interface ApiFieldConstructor extends ApiFieldDecoratorFactory { prototype: ApiField; new (owner: ComplexType | MappedType | MixinType, args: ApiField.InitArguments): ApiField; } /** * The ApiField represents a descriptive metadata structure for API fields, * supporting features like data type definition, scoping, localization, and constraints. * This class extends DocumentElement, inheriting base document structure capabilities. * * @class ApiField */ export interface ApiField extends ApiFieldClass { } /** * @decorator ApiField */ export declare const ApiField: ApiFieldConstructor; /** * The ApiFieldClass represents a descriptive metadata structure for API fields, * supporting features like data type definition, scoping, localization, and constraints. * This class extends DocumentElement, inheriting base document structure capabilities. */ declare class ApiFieldClass extends DocumentElement { protected _overrideCache?: Record<string, this>; readonly owner: ComplexType | MappedType | MixinType; readonly origin?: ComplexType | MappedType | MixinType; readonly scopePattern?: (string | RegExp)[]; readonly name: string; readonly type: DataType; readonly description?: string; readonly isArray?: boolean; readonly isNestedEntity?: boolean; readonly default?: any; readonly fixed?: any; readonly required?: boolean; readonly exclusive?: boolean; readonly localization?: boolean; readonly keyField?: string; readonly deprecated?: boolean | string; readonly readonly?: boolean; readonly writeonly?: boolean; readonly examples?: any[] | Record<string, any>; readonly override: ApiField.InitArguments['override']; inScope(scope?: string | '*'): boolean; forScope(scope?: string): this; toJSON(options?: ApiDocument.ExportOptions): OpraSchema.Field; } /** * @namespace ApiField */ export declare namespace ApiField { interface Metadata extends Combine<{ type?: string | OpraSchema.DataType | TypeThunkAsync | EnumType.EnumObject | EnumType.EnumArray | object; }, OpraSchema.Field> { scopePattern?: (string | RegExp) | (string | RegExp)[]; override?: StrictOmit<Metadata, 'override' | 'type' | 'isArray' | 'isNestedEntity'>[]; } interface Options extends Partial<StrictOmit<Metadata, 'override' | 'scopePattern'>> { /** * A variable that defines the pattern or patterns used to determine scope. * This can either be a single string or regular expression, or an array containing multiple strings or regular expressions. * * - If a single string or RegExp is provided, it is directly used as the scope pattern. * - If an array is provided, each element within the array is used as a valid scope pattern. */ scopePattern?: (string | RegExp) | (string | RegExp)[]; } interface InitArguments extends Combine<{ name: string; origin?: ComplexType | MappedType | MixinType; type?: DataType; }, Metadata> { } } export {};