UNPKG

@jsonjoy.com/json-type

Version:

High-performance JSON Pointer implementation

66 lines (65 loc) 4.22 kB
import { JsExpression } from '@jsonjoy.com/util/lib/codegen/util/JsExpression'; import * as schema from '../../schema'; import type { ValidatorCodegenContext } from '../../codegen/validator/ValidatorCodegenContext'; import type { ValidationPath } from '../../codegen/validator/types'; import type { JsonTextEncoderCodegenContext } from '../../codegen/json/JsonTextEncoderCodegenContext'; import type { CborEncoderCodegenContext } from '../../codegen/binary/CborEncoderCodegenContext'; import type { JsonEncoderCodegenContext } from '../../codegen/binary/JsonEncoderCodegenContext'; import type { MessagePackEncoderCodegenContext } from '../../codegen/binary/MessagePackEncoderCodegenContext'; import { AbsType } from './AbsType'; import type { SchemaOf, SchemaOfObjectFields, Type } from '../types'; import type { TypeSystem } from '../../system/TypeSystem'; import type { json_string } from '@jsonjoy.com/util/lib/json-brand'; import type { ExcludeFromTuple, PickFromTuple } from '../../util/types'; export declare class ObjectFieldType<K extends string, V extends Type> extends AbsType<schema.ObjectFieldSchema<K, SchemaOf<V>>> { readonly key: K; readonly value: V; protected schema: schema.ObjectFieldSchema<K, any>; constructor(key: K, value: V); getSchema(): schema.ObjectFieldSchema<K, SchemaOf<V>>; getOptions(): schema.Optional<schema.ObjectFieldSchema<K, SchemaOf<V>>>; protected toStringTitle(): string; toString(tab?: string): string; } export declare class ObjectOptionalFieldType<K extends string, V extends Type> extends ObjectFieldType<K, V> { readonly key: K; readonly value: V; optional: boolean; constructor(key: K, value: V); protected toStringTitle(): string; } export declare class ObjType<F extends ObjectFieldType<any, any>[] = ObjectFieldType<any, any>[]> extends AbsType<schema.ObjectSchema<SchemaOfObjectFields<F>>> { readonly fields: F; protected schema: schema.ObjectSchema<any>; constructor(fields: F); private _field; /** * Adds a property to the object type. * @param key The key of the property. * @param value The value type of the property. * @param options Optional schema options for the property. * @returns A new object type with the added property. */ prop<K extends string, V extends Type>(key: K, value: V, options?: schema.Optional<schema.ObjectFieldSchema<K, SchemaOf<V>>>): ObjType<[...F, ObjectFieldType<K, V>]>; /** * Adds an optional property to the object type. * @param key The key of the property. * @param value The value type of the property. * @param options Optional schema options for the property. * @returns A new object type with the added property. */ opt<K extends string, V extends Type>(key: K, value: V, options?: schema.Optional<schema.ObjectFieldSchema<K, SchemaOf<V>>>): ObjType<[...F, ObjectOptionalFieldType<K, V>]>; getSchema(): schema.ObjectSchema<SchemaOfObjectFields<F>>; getOptions(): schema.Optional<schema.ObjectSchema<SchemaOfObjectFields<F>>>; getField<K extends keyof schema.TypeOf<schema.ObjectSchema<SchemaOfObjectFields<F>>>>(key: K): ObjectFieldType<string, Type> | undefined; extend<F2 extends ObjectFieldType<any, any>[]>(o: ObjType<F2>): ObjType<[...F, ...F2]>; omit<K extends keyof schema.TypeOf<schema.ObjectSchema<SchemaOfObjectFields<F>>>>(key: K): ObjType<ExcludeFromTuple<F, ObjectFieldType<K extends string ? K : never, any>>>; pick<K extends keyof schema.TypeOf<schema.ObjectSchema<SchemaOfObjectFields<F>>>>(key: K): ObjType<PickFromTuple<F, ObjectFieldType<K extends string ? K : never, any>>>; codegenValidator(ctx: ValidatorCodegenContext, path: ValidationPath, r: string): void; codegenJsonTextEncoder(ctx: JsonTextEncoderCodegenContext, value: JsExpression): void; codegenCborEncoder(ctx: CborEncoderCodegenContext, value: JsExpression): void; codegenMessagePackEncoder(ctx: MessagePackEncoderCodegenContext, value: JsExpression): void; codegenJsonEncoder(ctx: JsonEncoderCodegenContext, value: JsExpression): void; toJson(value: unknown, system?: TypeSystem | undefined): json_string<unknown>; toString(tab?: string): string; }