import { JSONSchema } from "@json-schema-tools/meta-schema"; import { ProtocolHandlerMap } from "@json-schema-tools/reference-resolver/build/reference-resolver"; export interface RefCache { [k: string]: JSONSchema; } /** * Options that can be passed to the derefencer constructor. */ export interface DereferencerOptions { /** * If true, resolved non-local references will also be dereferenced using the same options. */ recursive?: boolean; /** * If true, the schema passed in will be dereferenced in-place, mutating the original. Default is false. */ mutate?: boolean; /** * Preseed the dereferencer with resolved refs */ refCache?: RefCache; rootSchema?: JSONSchema; /** * Setup custom protocol handlers. See https://github.com/json-schema-tools/reference-resolver for details */ protocolHandlerMap?: ProtocolHandlerMap; } /** * Error thrown by the constructor when given a ref that isn't a string * * * @example * ```typescript * * import Dereferencer, { NonStringRefError } from "@json-schema-tools/dereferencer"; * * try { const dereffer = new Dereferencer({}); } * catch(e) { * if (e instanceof NonStringRefError) { ... } * } * ``` * */ export declare class NonStringRefError implements Error { message: string; name: string; constructor(s: JSONSchema); } /** * When instantiated, represents a fully configured dereferencer. When constructed, references are pulled out. * No references are fetched until .resolve is called. */ export default class Dereferencer { private options; refs: string[]; private schema; refCache: RefCache; constructor(schema: JSONSchema, options?: DereferencerOptions); /** * Fetches the schemas for all the refs in the configured input schema(s) * * @returns a promise that will resolve a fully dereferenced schema, where all the * promises for each ref has been resolved as well. * * */ resolve(): Promise; /** * Synchronously dereferences all internal references in the configured input schema(s). * * Only references that can be resolved without I/O are supported: JSON pointers * into the root schema (e.g. "#/properties/foo") and "#" (the root schema itself). * Remote, file-system, and custom-protocol references require asynchronous * fetching and will throw; use `await resolve()` for those. * * @returns a fully dereferenced schema, where all internal refs have been resolved. */ resolveSync(): JSONSchema; private _resolveSync; _resolve(): Promise; /** * First-pass traversal to collect all the refs that we can find. This allows us to * optimize the async work required as well. */ collectRefs(): string[]; }