Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apidevtools/json-schema-ref-parser

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apidevtools/json-schema-ref-parser - npm Package Compare versions

Comparing version 11.5.2 to 11.5.3

2

dist/lib/bundle.d.ts

@@ -12,3 +12,3 @@ import type $RefParser from "./index";

*/
declare function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>, options: O): void;
declare function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): void;
export default bundle;

@@ -12,2 +12,2 @@ import type { ParserOptions } from "./options.js";

*/
declare function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>, options: O): void;
declare function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): void;

@@ -12,3 +12,3 @@ import $Refs from "./refs.js";

*/
export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
export declare class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**

@@ -27,3 +27,3 @@ * The parsed (and possibly dereferenced) JSON schema object

*/
$refs: $Refs<S>;
$refs: $Refs<S, O>;
/**

@@ -46,8 +46,8 @@ * Parses the given JSON schema.

parse(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static parse<S extends JSONSchema = JSONSchema>(schema: S | string): Promise<S>;
static parse<S extends JSONSchema = JSONSchema>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O): Promise<S>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O): Promise<S>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
/**

@@ -64,8 +64,8 @@ * *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*

*/
resolve(schema: S | string): Promise<$Refs<S>>;
resolve(schema: S | string, callback: $RefsCallback<S>): Promise<void>;
resolve(schema: S | string, options: O): Promise<$Refs<S>>;
resolve(schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S>>;
resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
resolve(schema: S | string): Promise<$Refs<S, O>>;
resolve(schema: S | string, callback: $RefsCallback<S, O>): Promise<void>;
resolve(schema: S | string, options: O): Promise<$Refs<S, O>>;
resolve(schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S, O>>;
resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
/**

@@ -82,8 +82,8 @@ * *This method is used internally by other methods, such as `bundle` and `dereference`. You probably won't need to call this method yourself.*

*/
static resolve<S extends JSONSchema = JSONSchema>(schema: S | string): Promise<$Refs<S>>;
static resolve<S extends JSONSchema = JSONSchema>(schema: S | string, callback: $RefsCallback<S>): Promise<void>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O): Promise<$Refs<S>>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S>>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<$Refs<S, O>>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: $RefsCallback<S, O>): Promise<void>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<$Refs<S, O>>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S, O>>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
/**

@@ -100,8 +100,8 @@ * Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.

*/
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<S>;
/**

@@ -135,8 +135,8 @@ * Bundles all referenced files/URLs into a single schema that only has internal `$ref` pointers. This lets you split-up your schema however you want while you're building it, but easily combine all those files together when it's time to package or distribute the schema to other people. The resulting schema size will be small, since it will still contain internal JSON references rather than being fully-dereferenced.

*/
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string): Promise<S>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O): Promise<S>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O): Promise<S>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string): Promise<S>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, callback: SchemaCallback<S>): Promise<void>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O): Promise<S>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O): Promise<S>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback<S>): Promise<void>;
/**

@@ -143,0 +143,0 @@ * Dereferences all `$ref` pointers in the JSON Schema, replacing each reference with its resolved value. This results in a schema object that does not contain any `$ref` pointers. Instead, it's a normal JavaScript object tree that can easily be crawled and used just like any other JavaScript object. This is great for programmatic usage, especially when using tools that don't understand JSON references.

import type { Options, ParserOptions } from "./options.js";
import type { JSONSchema, SchemaCallback } from "./types";
export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
path: string;
schema: S;
options: O & Options;
options: O & Options<S>;
callback: SchemaCallback<S>;

@@ -12,3 +12,3 @@ }

*/
export declare function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(_args: Partial<IArguments>): NormalizedArguments<S, O>;
export declare function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(_args: Partial<IArguments>): NormalizedArguments<S, O>;
export default normalizeArgs;

@@ -654,4 +654,4 @@ /// <reference types="node" />

}>(options: O | undefined) => O & $RefParserOptions<S>;
export type Options = $RefParserOptions<JSONSchema>;
export type ParserOptions = DeepPartial<$RefParserOptions<JSONSchema>>;
export type Options<S extends JSONSchema = JSONSchema> = $RefParserOptions<S>;
export type ParserOptions<S extends JSONSchema = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
export default $RefParserOptions;
/// <reference types="node" />
import type $Refs from "./refs.js";
import type { Options } from "./options.js";
import type { ParserOptions } from "./options.js";
import type { JSONSchema } from "./types/index.js";

@@ -8,3 +8,3 @@ /**

*/
declare function parse<S extends JSONSchema = JSONSchema, O extends Options = Options>(path: string, $refs: $Refs<S>, options: O): Promise<string | Buffer | S | undefined>;
declare function parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(path: string, $refs: $Refs<S, O>, options: O): Promise<string | Buffer | S | undefined>;
export default parse;

@@ -1,2 +0,2 @@

import type $RefParserOptions from "./options.js";
import type { ParserOptions } from "./options.js";
import $Ref from "./ref.js";

@@ -12,7 +12,7 @@ import type { JSONSchema } from "./types";

*/
declare class Pointer<S extends JSONSchema = JSONSchema> {
declare class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**
* The {@link $Ref} object that contains this {@link Pointer} object.
*/
$ref: $Ref<S>;
$ref: $Ref<S, O>;
/**

@@ -41,3 +41,3 @@ * The file path or URL, containing the JSON pointer in the hash.

indirections: number;
constructor($ref: $Ref<S>, path: string, friendlyPath?: string);
constructor($ref: $Ref<S, O>, path: string, friendlyPath?: string);
/**

@@ -56,3 +56,3 @@ * Resolves the value of a nested property within the given object.

*/
resolve(obj: any, options?: $RefParserOptions<S>, pathFromRoot?: string): this;
resolve(obj: any, options?: O, pathFromRoot?: string): this;
/**

@@ -68,3 +68,3 @@ * Sets the value of a nested property within the given object.

*/
set(obj: any, value: any, options?: $RefParserOptions<S>): any;
set(obj: any, value: any, options?: O): any;
/**

@@ -71,0 +71,0 @@ * Parses a JSON pointer (or a path containing a JSON pointer in the hash)

import Pointer from "./pointer.js";
import type { JSONParserError, MissingPointerError, ParserError, ResolverError } from "./util/errors.js";
import type $Refs from "./refs.js";
import type $RefParserOptions from "./options.js";
import type { ParserOptions } from "./options.js";

@@ -13,3 +12,3 @@ import type { JSONSchema } from "./types";

*/
declare class $Ref<S extends JSONSchema = JSONSchema> {
declare class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**

@@ -38,3 +37,3 @@ * The file path or URL of the referenced file.

*/
$refs: $Refs<S>;
$refs: $Refs<S, O>;
/**

@@ -48,3 +47,3 @@ * Indicates the type of {@link $Ref#path} (e.g. "file", "http", etc.)

errors: Array<$RefError>;
constructor($refs: $Refs<S>);
constructor($refs: $Refs<S, O>);
/**

@@ -64,3 +63,3 @@ * Pushes an error to errors array.

*/
exists(path: string, options?: $RefParserOptions<S>): boolean;
exists(path: string, options?: O): boolean;
/**

@@ -73,3 +72,3 @@ * Resolves the given JSON reference within this {@link $Ref#value} and returns the resolved value.

*/
get(path: string, options?: $RefParserOptions<S>): any;
get(path: string, options?: O): any;
/**

@@ -84,3 +83,3 @@ * Resolves the given JSON reference within this {@link $Ref#value}.

*/
resolve(path: string, options?: $RefParserOptions<S>, friendlyPath?: string, pathFromRoot?: string): Pointer<S> | null;
resolve(path: string, options?: O, friendlyPath?: string, pathFromRoot?: string): Pointer<S, O> | null;
/**

@@ -119,3 +118,3 @@ * Sets the value of a nested property within this {@link $Ref#value}.

*/
static isAllowed$Ref(value: unknown, options?: ParserOptions): true | undefined;
static isAllowed$Ref<S extends JSONSchema = JSONSchema>(value: unknown, options?: ParserOptions<S>): true | undefined;
/**

@@ -187,4 +186,4 @@ * Determines whether the given value is a JSON reference that "extends" its resolved value.

*/
static dereference<S extends JSONSchema = JSONSchema>($ref: $Ref<S>, resolvedValue: S): S;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>($ref: $Ref<S, O>, resolvedValue: S): S;
}
export default $Ref;
import $Ref from "./ref.js";
import type { JSONSchema4Type, JSONSchema6Type, JSONSchema7Type } from "json-schema";
import type $RefParserOptions from "./options.js";
import type { ParserOptions } from "./options.js";
import type { JSONSchema } from "./types";
interface $RefsMap<S extends JSONSchema = JSONSchema> {
[url: string]: $Ref<S>;
interface $RefsMap<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
[url: string]: $Ref<S, O>;
}

@@ -15,3 +15,3 @@ /**

*/
export default class $Refs<S extends JSONSchema = JSONSchema> {
export default class $Refs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**

@@ -61,3 +61,3 @@ * This property is true if the schema contains any circular references. You may want to check this property before serializing the dereferenced schema as JSON, since JSON.stringify() does not support circular references by default.

*/
get(path: string, options?: $RefParserOptions<S>): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type;
get(path: string, options?: O): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type;
/**

@@ -77,3 +77,3 @@ * Sets the value at the given path in the schema. If the property, or any of its parents, don't exist, they will be created.

*/
_get$Ref(path: any): $Ref<S>;
_get$Ref(path: string): $Ref<S, O>;
/**

@@ -84,3 +84,3 @@ * Creates a new {@link $Ref} object and adds it to this {@link $Refs} object.

*/
_add(path: string): $Ref<S>;
_add(path: string): $Ref<S, O>;
/**

@@ -95,3 +95,3 @@ * Resolves the given JSON reference.

*/
_resolve(path: string, pathFromRoot: string, options?: any): import("./pointer.js").default<S> | null;
_resolve(path: string, pathFromRoot: string, options?: O): import("./pointer.js").default<S, O> | null;
/**

@@ -103,3 +103,3 @@ * A map of paths/urls to {@link $Ref} objects

*/
_$refs: $RefsMap<S>;
_$refs: $RefsMap<S, O>;
/**

@@ -111,3 +111,3 @@ * The {@link $Ref} object that is the root of the JSON schema.

*/
_root$Ref: $Ref<S>;
_root$Ref: $Ref<S, O>;
constructor();

@@ -114,0 +114,0 @@ /**

@@ -1,2 +0,2 @@

import type { Options, ParserOptions } from "./options.js";
import type { ParserOptions } from "./options.js";
import type { JSONSchema } from "./types/index.js";

@@ -14,3 +14,3 @@ import type $RefParser from "./index.js";

*/
declare function resolveExternal<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>, options: Options): Promise<void> | Promise<any[]>;
declare function resolveExternal<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>, options: O): Promise<void> | Promise<any[]>;
export default resolveExternal;

@@ -45,3 +45,3 @@ "use strict";

function resolveExternal(parser, options) {
if (!options.resolve.external) {
if (!options.resolve?.external) {
// Nothing to resolve, so exit early

@@ -105,3 +105,3 @@ return Promise.resolve();

async function resolve$Ref($ref, path, $refs, options) {
const shouldResolveOnCwd = options.dereference.externalReferenceResolution === "root";
const shouldResolveOnCwd = options.dereference?.externalReferenceResolution === "root";
const resolvedPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref);

@@ -108,0 +108,0 @@ const withoutHash = url.stripHash(resolvedPath);

/// <reference types="node" />
import type { JSONSchema4, JSONSchema4Object, JSONSchema6, JSONSchema6Object, JSONSchema7, JSONSchema7Object } from "json-schema";
import type $Refs from "../refs.js";
import type { ParserOptions } from "../options";
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
export type JSONSchemaObject = JSONSchema4Object | JSONSchema6Object | JSONSchema7Object;
export type SchemaCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
export type $RefsCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, $refs?: $Refs<S>) => any;
export type $RefsCallback<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> = (err: Error | null, $refs?: $Refs<S, O>) => any;
/**

@@ -9,0 +10,0 @@ * See https://apitools.dev/json-schema-ref-parser/docs/options.html

@@ -14,6 +14,6 @@ import type $RefParser from "../index.js";

}
export declare class JSONParserErrorGroup<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> extends Error {
export declare class JSONParserErrorGroup<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> extends Error {
files: $RefParser<S, O>;
constructor(parser: $RefParser<S, O>);
static getParserErrors<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(parser: $RefParser<S, O>): JSONParserError[];
static getParserErrors<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(parser: $RefParser<S, O>): JSONParserError[];
get errors(): Array<JSONParserError | InvalidPointerError | ResolverError | ParserError | MissingPointerError | UnmatchedParserError | UnmatchedResolverError>;

@@ -20,0 +20,0 @@ }

/// <reference types="node" />
import type { FileInfo, JSONSchema } from "../types/index.js";
import type $RefParserOptions from "../options.js";
import type { ParserOptions } from "../options.js";
import type { ResolverOptions } from "../types/index.js";

@@ -13,3 +13,3 @@ import type $Refs from "../refs.js";

*/
export declare function all<S extends JSONSchema = JSONSchema>(plugins: $RefParserOptions<S>["resolve"]): Plugin[];
export declare function all<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(plugins: O["resolve"]): Plugin[];
/**

@@ -23,3 +23,3 @@ * Filters the given plugins, returning only the ones return `true` for the given method.

export declare function sort(plugins: Plugin[]): Plugin[];
export interface PluginResult<S extends JSONSchema = JSONSchema> {
export interface PluginResult<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
plugin: Plugin;

@@ -37,2 +37,2 @@ result?: string | Buffer | S;

*/
export declare function run<S extends JSONSchema = JSONSchema>(plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions<S>, file: FileInfo, $refs: $Refs<S>): Promise<PluginResult<S>>;
export declare function run<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(plugins: Plugin[], method: keyof Plugin | keyof ResolverOptions<S>, file: FileInfo, $refs: $Refs<S, O>): Promise<PluginResult<S, O>>;

@@ -11,3 +11,3 @@ "use strict";

function all(plugins) {
return Object.keys(plugins)
return Object.keys(plugins || {})
.filter((key) => {

@@ -14,0 +14,0 @@ return typeof plugins[key] === "object";

@@ -17,3 +17,3 @@ import $Ref from "./ref.js";

*/
function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,

@@ -44,3 +44,3 @@ options: O,

*/
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parent: any,

@@ -52,3 +52,3 @@ key: string | null,

inventory: unknown[],
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,

@@ -108,3 +108,3 @@ ) {

*/
function inventory$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function inventory$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$refParent: any,

@@ -116,3 +116,3 @@ $refKey: any,

inventory: any,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,

@@ -119,0 +119,0 @@ ) {

@@ -19,3 +19,3 @@ import $Ref from "./ref.js";

*/
function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,

@@ -52,3 +52,3 @@ options: O,

*/
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
obj: any,

@@ -60,3 +60,3 @@ path: string,

dereferencedCache: any,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,

@@ -167,3 +167,3 @@ ) {

*/
function dereference$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function dereference$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$ref: any,

@@ -175,3 +175,3 @@ path: string,

dereferencedCache: any,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,

@@ -178,0 +178,0 @@ ) {

@@ -40,3 +40,3 @@ import $Refs from "./refs.js";

*/
export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
export class $RefParser<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**

@@ -56,3 +56,3 @@ * The parsed (and possibly dereferenced) JSON schema object

*/
$refs = new $Refs<S>();
$refs = new $Refs<S, O>();

@@ -148,12 +148,14 @@ /**

public static parse<S extends JSONSchema = JSONSchema>(schema: S | string): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
callback: SchemaCallback<S>,
): Promise<void>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,

@@ -163,3 +165,3 @@ options: O,

): Promise<void>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,

@@ -169,3 +171,3 @@ schema: S | string,

): Promise<S>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,

@@ -176,3 +178,3 @@ schema: S | string,

): Promise<void>;
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>():
public static parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>

@@ -195,8 +197,8 @@ | Promise<void> {

*/
public resolve(schema: S | string): Promise<$Refs<S>>;
public resolve(schema: S | string, callback: $RefsCallback<S>): Promise<void>;
public resolve(schema: S | string, options: O): Promise<$Refs<S>>;
public resolve(schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
public resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S>>;
public resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S>): Promise<void>;
public resolve(schema: S | string): Promise<$Refs<S, O>>;
public resolve(schema: S | string, callback: $RefsCallback<S, O>): Promise<void>;
public resolve(schema: S | string, options: O): Promise<$Refs<S, O>>;
public resolve(schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
public resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs<S, O>>;
public resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback<S, O>): Promise<void>;
async resolve() {

@@ -226,28 +228,30 @@ const args = normalizeArgs<S, O>(arguments);

*/
public static resolve<S extends JSONSchema = JSONSchema>(schema: S | string): Promise<$Refs<S>>;
public static resolve<S extends JSONSchema = JSONSchema>(
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
callback: $RefsCallback<S>,
): Promise<$Refs<S, O>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
callback: $RefsCallback<S, O>,
): Promise<void>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<$Refs<S>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
): Promise<$Refs<S, O>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
callback: $RefsCallback<S>,
callback: $RefsCallback<S, O>,
): Promise<void>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
): Promise<$Refs<S>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
): Promise<$Refs<S, O>>;
public static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,
schema: S | string,
options: O,
callback: $RefsCallback<S>,
callback: $RefsCallback<S, O>,
): Promise<void>;
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>():
static resolve<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>

@@ -270,14 +274,14 @@ | Promise<void> {

*/
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
): Promise<S>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
callback: SchemaCallback<S>,
): Promise<void>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,

@@ -287,3 +291,3 @@ options: O,

): Promise<void>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,

@@ -293,3 +297,3 @@ schema: S | string,

): Promise<S>;
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,

@@ -300,3 +304,3 @@ schema: S | string,

): Promise<S>;
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>():
static bundle<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>

@@ -348,14 +352,14 @@ | Promise<void> {

*/
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
): Promise<S>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
callback: SchemaCallback<S>,
): Promise<void>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,
options: O,
): Promise<S>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
schema: S | string,

@@ -365,3 +369,3 @@ options: O,

): Promise<void>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,

@@ -371,3 +375,3 @@ schema: S | string,

): Promise<S>;
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
public static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
baseUrl: string,

@@ -378,3 +382,3 @@ schema: S | string,

): Promise<void>;
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>():
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>():
| Promise<S>

@@ -419,3 +423,3 @@ | Promise<void> {

function finalize<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function finalize<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,

@@ -422,0 +426,0 @@ ) {

@@ -7,6 +7,6 @@ import type { Options, ParserOptions } from "./options.js";

// In the future, I'd like to deprecate the api and accept only named parameters in index.ts
export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions> {
export interface NormalizedArguments<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
path: string;
schema: S;
options: O & Options;
options: O & Options<S>;
callback: SchemaCallback<S>;

@@ -17,3 +17,3 @@ }

*/
export function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
export function normalizeArgs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
_args: Partial<IArguments>,

@@ -23,3 +23,3 @@ ): NormalizedArguments<S, O> {

let schema;
let options: Options & O;
let options: Options<S> & O;
let callback;

@@ -26,0 +26,0 @@ const args = Array.prototype.slice.call(_args) as any[];

@@ -177,3 +177,3 @@ import jsonParser from "./parsers/json.js";

export const getNewOptions = <S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
export const getNewOptions = <S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
options: O | undefined,

@@ -187,4 +187,5 @@ ): O & $RefParserOptions<S> => {

};
export type Options = $RefParserOptions<JSONSchema>;
export type ParserOptions = DeepPartial<$RefParserOptions<JSONSchema>>;
export type Options<S extends JSONSchema = JSONSchema> = $RefParserOptions<S>;
export type ParserOptions<S extends JSONSchema = JSONSchema> = DeepPartial<$RefParserOptions<S>>;
/**

@@ -191,0 +192,0 @@ * Merges the properties of the source object into the target object.

@@ -12,3 +12,3 @@ import { ono } from "@jsdevtools/ono";

import type $Refs from "./refs.js";
import type { Options } from "./options.js";
import type { ParserOptions } from "./options.js";
import type { FileInfo, JSONSchema } from "./types/index.js";

@@ -19,5 +19,5 @@

*/
async function parse<S extends JSONSchema = JSONSchema, O extends Options = Options>(
async function parse<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
path: string,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
options: O,

@@ -75,6 +75,6 @@ ) {

*/
async function readFile<S extends JSONSchema = JSONSchema, O extends Options = Options>(
async function readFile<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
file: FileInfo,
options: O,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
): Promise<any> {

@@ -122,6 +122,6 @@ // console.log('Reading %s', file.url);

*/
async function parseFile<S extends JSONSchema = JSONSchema, O extends Options = Options>(
async function parseFile<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
file: FileInfo,
options: O,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
) {

@@ -138,3 +138,3 @@ // Find the parsers that can read this file type.

try {
const parser = await plugins.run<S>(parsers, "parse", file, $refs);
const parser = await plugins.run<S, O>(parsers, "parse", file, $refs);
if (!parser.plugin.allowEmpty && isEmpty(parser.result)) {

@@ -141,0 +141,0 @@ throw ono.syntax(`Error parsing "${file.url}" as ${parser.plugin.name}. \nParsed value is empty`);

@@ -1,2 +0,2 @@

import type $RefParserOptions from "./options.js";
import type { ParserOptions } from "./options.js";

@@ -29,7 +29,7 @@ import $Ref from "./ref.js";

*/
class Pointer<S extends JSONSchema = JSONSchema> {
class Pointer<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**
* The {@link $Ref} object that contains this {@link Pointer} object.
*/
$ref: $Ref<S>;
$ref: $Ref<S, O>;

@@ -63,3 +63,3 @@ /**

constructor($ref: $Ref<S>, path: string, friendlyPath?: string) {
constructor($ref: $Ref<S, O>, path: string, friendlyPath?: string) {
this.$ref = $ref;

@@ -91,3 +91,3 @@

*/
resolve(obj: any, options?: $RefParserOptions<S>, pathFromRoot?: string) {
resolve(obj: any, options?: O, pathFromRoot?: string) {
const tokens = Pointer.parse(this.path, this.originalPath);

@@ -150,3 +150,3 @@

*/
set(obj: any, value: any, options?: $RefParserOptions<S>) {
set(obj: any, value: any, options?: O) {
const tokens = Pointer.parse(this.path);

@@ -153,0 +153,0 @@ let token;

@@ -6,3 +6,2 @@ import Pointer from "./pointer.js";

import type $Refs from "./refs.js";
import type $RefParserOptions from "./options.js";
import type { ParserOptions } from "./options.js";

@@ -18,3 +17,3 @@ import type { JSONSchema } from "./types";

*/
class $Ref<S extends JSONSchema = JSONSchema> {
class $Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**

@@ -45,3 +44,3 @@ * The file path or URL of the referenced file.

*/
$refs: $Refs<S>;
$refs: $Refs<S, O>;

@@ -58,3 +57,3 @@ /**

constructor($refs: $Refs<S>) {
constructor($refs: $Refs<S, O>) {
this.$refs = $refs;

@@ -95,3 +94,3 @@ }

*/
exists(path: string, options?: $RefParserOptions<S>) {
exists(path: string, options?: O) {
try {

@@ -112,3 +111,3 @@ this.resolve(path, options);

*/
get(path: string, options?: $RefParserOptions<S>) {
get(path: string, options?: O) {
return this.resolve(path, options)?.value;

@@ -126,4 +125,4 @@ }

*/
resolve(path: string, options?: $RefParserOptions<S>, friendlyPath?: string, pathFromRoot?: string) {
const pointer = new Pointer<S>(this, path, friendlyPath);
resolve(path: string, options?: O, friendlyPath?: string, pathFromRoot?: string) {
const pointer = new Pointer<S, O>(this, path, friendlyPath);
try {

@@ -196,3 +195,3 @@ return pointer.resolve(this.value, options, pathFromRoot);

*/
static isAllowed$Ref(value: unknown, options?: ParserOptions) {
static isAllowed$Ref<S extends JSONSchema = JSONSchema>(value: unknown, options?: ParserOptions<S>) {
if (this.is$Ref(value)) {

@@ -278,3 +277,6 @@ if (value.$ref.substring(0, 2) === "#/" || value.$ref === "#") {

*/
static dereference<S extends JSONSchema = JSONSchema>($ref: $Ref<S>, resolvedValue: S): S {
static dereference<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$ref: $Ref<S, O>,
resolvedValue: S,
): S {
if (resolvedValue && typeof resolvedValue === "object" && $Ref.isExtended$Ref($ref)) {

@@ -281,0 +283,0 @@ const merged = {};

@@ -5,8 +5,8 @@ import { ono } from "@jsdevtools/ono";

import type { JSONSchema4Type, JSONSchema6Type, JSONSchema7Type } from "json-schema";
import type $RefParserOptions from "./options.js";
import type { ParserOptions } from "./options.js";
import convertPathToPosix from "./util/convert-path-to-posix";
import type { JSONSchema } from "./types";
interface $RefsMap<S extends JSONSchema = JSONSchema> {
[url: string]: $Ref<S>;
interface $RefsMap<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
[url: string]: $Ref<S, O>;
}

@@ -20,3 +20,3 @@ /**

*/
export default class $Refs<S extends JSONSchema = JSONSchema> {
export default class $Refs<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
/**

@@ -89,3 +89,3 @@ * This property is true if the schema contains any circular references. You may want to check this property before serializing the dereferenced schema as JSON, since JSON.stringify() does not support circular references by default.

*/
get(path: string, options?: $RefParserOptions<S>): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type {
get(path: string, options?: O): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type {
return this._resolve(path, "", options)!.value;

@@ -118,3 +118,3 @@ }

*/
_get$Ref(path: any) {
_get$Ref(path: string) {
path = url.resolve(this._root$Ref.path!, path);

@@ -133,3 +133,3 @@ const withoutHash = url.stripHash(path);

const $ref = new $Ref<S>(this);
const $ref = new $Ref<S, O>(this);
$ref.path = withoutHash;

@@ -152,3 +152,3 @@

*/
_resolve(path: string, pathFromRoot: string, options?: any) {
_resolve(path: string, pathFromRoot: string, options?: O) {
const absPath = url.resolve(this._root$Ref.path!, path);

@@ -171,3 +171,3 @@ const withoutHash = url.stripHash(absPath);

*/
_$refs: $RefsMap<S> = {};
_$refs: $RefsMap<S, O> = {};

@@ -180,3 +180,3 @@ /**

*/
_root$Ref: $Ref<S>;
_root$Ref: $Ref<S, O>;

@@ -226,3 +226,6 @@ constructor() {

*/
function getPaths<S extends JSONSchema = JSONSchema>($refs: $RefsMap<S>, types: string[]) {
function getPaths<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$refs: $RefsMap<S, O>,
types: string[],
) {
let paths = Object.keys($refs);

@@ -229,0 +232,0 @@

@@ -7,3 +7,3 @@ import $Ref from "./ref.js";

import type $Refs from "./refs.js";
import type { Options, ParserOptions } from "./options.js";
import type { ParserOptions } from "./options.js";
import type { JSONSchema } from "./types/index.js";

@@ -22,7 +22,7 @@ import type $RefParser from "./index.js";

*/
function resolveExternal<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
function resolveExternal<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,
options: Options,
options: O,
) {
if (!options.resolve.external) {
if (!options.resolve?.external) {
// Nothing to resolve, so exit early

@@ -57,7 +57,7 @@ return Promise.resolve();

*/
function crawl<S extends JSONSchema = JSONSchema>(
function crawl<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
obj: string | Buffer | S | undefined | null,
path: string,
$refs: $Refs<S>,
options: Options,
$refs: $Refs<S, O>,
options: O,
seen?: Set<any>,

@@ -72,3 +72,3 @@ external?: boolean,

if ($Ref.isExternal$Ref(obj)) {
promises.push(resolve$Ref<S>(obj, path, $refs, options));
promises.push(resolve$Ref<S, O>(obj, path, $refs, options));
}

@@ -99,9 +99,9 @@

*/
async function resolve$Ref<S extends JSONSchema = JSONSchema>(
async function resolve$Ref<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
$ref: S,
path: string,
$refs: $Refs<S>,
options: Options,
$refs: $Refs<S, O>,
options: O,
) {
const shouldResolveOnCwd = options.dereference.externalReferenceResolution === "root";
const shouldResolveOnCwd = options.dereference?.externalReferenceResolution === "root";
const resolvedPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref!);

@@ -108,0 +108,0 @@ const withoutHash = url.stripHash(resolvedPath);

@@ -10,2 +10,3 @@ import type {

import type $Refs from "../refs.js";
import type { ParserOptions } from "../options";

@@ -15,3 +16,6 @@ export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;

export type SchemaCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, schema?: S | object | null) => any;
export type $RefsCallback<S extends JSONSchema = JSONSchema> = (err: Error | null, $refs?: $Refs<S>) => any;
export type $RefsCallback<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> = (
err: Error | null,
$refs?: $Refs<S, O>,
) => any;

@@ -18,0 +22,0 @@ /**

@@ -42,3 +42,3 @@ import { Ono } from "@jsdevtools/ono";

S extends JSONSchema = JSONSchema,
O extends ParserOptions = ParserOptions,
O extends ParserOptions<S> = ParserOptions<S>,
> extends Error {

@@ -59,3 +59,3 @@ files: $RefParser<S, O>;

static getParserErrors<S extends JSONSchema = JSONSchema, O extends ParserOptions = ParserOptions>(
static getParserErrors<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
parser: $RefParser<S, O>,

@@ -65,3 +65,3 @@ ) {

for (const $ref of Object.values(parser.$refs._$refs) as $Ref<S>[]) {
for (const $ref of Object.values(parser.$refs._$refs) as $Ref<S, O>[]) {
if ($ref.errors) {

@@ -84,3 +84,3 @@ errors.push(...$ref.errors);

> {
return JSONParserErrorGroup.getParserErrors<S>(this.files);
return JSONParserErrorGroup.getParserErrors<S, O>(this.files);
}

@@ -87,0 +87,0 @@ }

import type { FileInfo, JSONSchema } from "../types/index.js";
import type $RefParserOptions from "../options.js";
import type { ParserOptions } from "../options.js";
import type { ResolverOptions } from "../types/index.js";

@@ -13,10 +13,12 @@ import type $Refs from "../refs.js";

*/
export function all<S extends JSONSchema = JSONSchema>(plugins: $RefParserOptions<S>["resolve"]): Plugin[] {
return Object.keys(plugins)
export function all<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
plugins: O["resolve"],
): Plugin[] {
return (Object.keys(plugins || {}) as (keyof ResolverOptions<S>)[])
.filter((key) => {
return typeof plugins[key] === "object";
return typeof plugins![key] === "object";
})
.map((key) => {
(plugins[key] as ResolverOptions<S>)!.name = key;
return plugins[key] as Plugin;
(plugins![key] as ResolverOptions<S>)!.name = key;
return plugins![key] as Plugin;
});

@@ -47,3 +49,3 @@ }

export interface PluginResult<S extends JSONSchema = JSONSchema> {
export interface PluginResult<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>> {
plugin: Plugin;

@@ -62,13 +64,13 @@ result?: string | Buffer | S;

*/
export async function run<S extends JSONSchema = JSONSchema>(
export async function run<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
plugins: Plugin[],
method: keyof Plugin | keyof ResolverOptions<S>,
file: FileInfo,
$refs: $Refs<S>,
$refs: $Refs<S, O>,
) {
let plugin: Plugin;
let lastError: PluginResult<S>;
let lastError: PluginResult<S, O>;
let index = 0;
return new Promise<PluginResult<S>>((resolve, reject) => {
return new Promise<PluginResult<S, O>>((resolve, reject) => {
runNextPlugin();

@@ -100,3 +102,3 @@

function callback(err: PluginResult<S>["error"], result: PluginResult<S>["result"]) {
function callback(err: PluginResult<S, O>["error"], result: PluginResult<S, O>["result"]) {
if (err) {

@@ -109,3 +111,3 @@ onError(err);

function onSuccess(result: PluginResult<S>["result"]) {
function onSuccess(result: PluginResult<S, O>["result"]) {
// console.log(' success');

@@ -118,3 +120,3 @@ resolve({

function onError(error: PluginResult<S>["error"]) {
function onError(error: PluginResult<S, O>["error"]) {
// console.log(' %s', err.message || err);

@@ -136,3 +138,3 @@ lastError = {

*/
function getResult<S extends JSONSchema = JSONSchema>(
function getResult<S extends JSONSchema = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
obj: Plugin,

@@ -142,3 +144,3 @@ prop: keyof Plugin | keyof ResolverOptions<S>,

callback?: (err?: Error, result?: any) => void,
$refs?: any,
$refs?: $Refs<S, O>,
) {

@@ -145,0 +147,0 @@ const value = obj[prop as keyof typeof obj] as unknown;

{
"name": "@apidevtools/json-schema-ref-parser",
"version": "11.5.2",
"version": "11.5.3",
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc