UNPKG

@opra/common

Version:
87 lines (86 loc) 2.91 kB
import { type StrictOmit, type Type } from 'ts-gems'; import { type IsObject, type Validator } from 'valgen'; import { FieldsProjection, ResponsiveMap } from '../../helpers/index.js'; import { OpraSchema } from '../../schema/index.js'; import type { DocumentElement } from '../common/document-element.js'; import { DocumentInitContext } from '../common/document-init-context.js'; import type { ApiField } from './api-field.js'; import type { ComplexType } from './complex-type.js'; import { DataType } from './data-type.js'; export declare const FIELD_PATH_PATTERN: RegExp; /** * Type definition of class constructor for ComplexTypeBase * @class ComplexTypeBase */ interface ComplexTypeBaseStatic { /** * Class constructor of MappedType * * @param owner * @param initArgs * @param context * @constructor */ new (owner: DocumentElement, initArgs: DataType.InitArguments, context?: DocumentInitContext): ComplexTypeBase; prototype: ComplexTypeBase; } /** * Type definition of ComplexTypeBase prototype * @interface ComplexTypeBase */ export interface ComplexTypeBase extends ComplexTypeBaseClass { } /** * * @constructor */ export declare const ComplexTypeBase: ComplexTypeBaseStatic; /** * */ declare abstract class ComplexTypeBaseClass extends DataType { readonly ctor?: Type; protected _fields: ResponsiveMap<ApiField>; readonly additionalFields?: boolean | DataType | ['error'] | ['error', string]; readonly keyField?: OpraSchema.Field.Name; fieldCount(scope?: string): number; fieldEntries(scope?: string): IterableIterator<[string, ApiField]>; fields(scope?: string): IterableIterator<ApiField>; fieldNames(scope?: string): IterableIterator<string>; /** * */ findField(nameOrPath: string, scope?: string | '*'): ApiField | undefined; /** * */ getField(nameOrPath: string, scope?: string): ApiField; /** * */ parseFieldPath(fieldPath: string, options?: { allowSigns?: 'first' | 'each'; scope?: string | '*'; }): ComplexType.ParsedFieldPath[]; /** * */ normalizeFieldPath(fieldPath: string, options?: { allowSigns?: 'first' | 'each'; scope?: string; }): string; /** * */ generateCodec(codec: 'encode' | 'decode', options?: DataType.GenerateCodecOptions): Validator; protected _generateSchema(codec: 'encode' | 'decode', context: GenerateCodecContext): IsObject.Schema; protected _generateFieldCodec(codec: 'encode' | 'decode', field: ApiField, context: GenerateCodecContext): Validator; } type GenerateCodecContext = StrictOmit<DataType.GenerateCodecOptions, 'projection'> & { currentPath: string; projection?: FieldsProjection | '*'; level?: number; fieldCache?: Map<ApiField, Record<string, Validator | null>>; forwardCallbacks?: Set<Function>; }; export {};