import type { JSONSchema } from '@squiz/json-schema-library'; import * as t from 'ts-brand'; type MaybePromise = T | Promise; type JsonResolutionSchema = JSONSchema & { title: TITLE; }; /** * This type allows the TypeScript type to be encoded onto the JSON schema object */ type SchemaWithShape<TITLE extends string, SHAPE> = JsonResolutionSchema<TITLE> & { __shape__: SHAPE; }; /** * A JSON schema which represents a primitive type which can be a resolve target * * The brand ensures that TypeScript can differentiate between a primitive type and a resolvable type */ export type PrimitiveType<TITLE extends string, SHAPE> = t.Brand<SchemaWithShape<TITLE, SHAPE>, 'primitive'>; export declare function PrimitiveType<SHAPE, TITLE extends string>(jsonSchema: JsonResolutionSchema<TITLE>): PrimitiveType<TITLE, SHAPE>; export type AnyPrimitiveType = PrimitiveType<string, any>; /** * A JSON schema which represents a type which can be resolved into a primitive type * * The brand ensures that TypeScript can differentiate between a primitive type and a resolvable type */ export type ResolvableType<TITLE extends string, SHAPE> = t.Brand<SchemaWithShape<TITLE, SHAPE>, 'resolvable'>; export declare function ResolvableType<SHAPE, TITLE extends string>(jsonSchema: JsonResolutionSchema<TITLE>): ResolvableType<TITLE, SHAPE>; export type AnyResolvableType = ResolvableType<string, any>; export type ResolverContext = { baseUrl?: string; matrix?: { context?: string; }; }; export type Resolver<INPUT, OUTPUT> = (input: INPUT, ctx?: ResolverContext) => MaybePromise<OUTPUT>; /** * A JSON Type Resolver class which stores the primitive and resolvable JSON Schema types and their resolvers * * No serious logic is required here. The class should only provide data access methods and type safety */ export declare class TypeResolver<P extends AnyPrimitiveType, R extends AnyResolvableType> { resolvers: { [PT in P as PT['title']]?: { [RT in R as RT['title']]?: Resolver<RT['__shape__'], PT['__shape__']>; }; }; private primitives; private resolvables; constructor(primitives: P[], resolvables?: R[], resolvers?: { [PT in P as PT['title']]?: { [RT in R as RT['title']]?: Resolver<RT['__shape__'], PT['__shape__']>; }; }); get validationSchemaDefinitions(): (P | R)[]; isPrimitiveType(type: string): type is P['title']; isResolvableSchema(schema: JSONSchema): schema is R; getValidationSchemaForPrimitive(type: P['title']): JsonResolutionSchema<string>[]; private fetchResolvableSchemasForPrimitive; tryGetResolver(primitiveSchemaTitle: string, resolvableSchema: R): Resolver<R['__shape__'], P['__shape__']> | undefined; } export {};