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.2.2 to 11.2.3

2

dist/lib/bundle.js

@@ -63,3 +63,2 @@ "use strict";

if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
// @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
if (ref_js_1.default.isAllowed$Ref(obj)) {

@@ -92,3 +91,2 @@ inventory$Ref(parent, key, path, pathFromRoot, indirections, inventory, $refs, options);

const value = obj[key];
// @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
if (ref_js_1.default.isAllowed$Ref(value)) {

@@ -95,0 +93,0 @@ inventory$Ref(obj, key, path, keyPathFromRoot, indirections, inventory, $refs, options);

12

dist/lib/index.d.ts
import $Refs from "./refs.js";
import { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError } from "./util/errors.js";
import type { ParserOptions } from "./options.js";
import type { $RefsCallback, JSONSchema, SchemaCallback } from "./types/index.js";
export { JSONParserError };
export { InvalidPointerError };
export { MissingPointerError };
export { ResolverError };
export { ParserError };
export { UnmatchedParserError };
export { UnmatchedResolverError };
type RefParserSchema = string | JSONSchema;
import type { Plugin, $RefsCallback, JSONSchema, SchemaCallback, HTTPResolverOptions, FileInfo, ResolverOptions, JSONSchemaObject } from "./types/index.js";
export { JSONSchemaObject, ResolverOptions, ParserError, UnmatchedResolverError, ResolverError, HTTPResolverOptions, FileInfo, UnmatchedParserError, ParserOptions, MissingPointerError, InvalidPointerError, JSONParserError, Plugin, };
export type RefParserSchema = string | JSONSchema;
/**

@@ -14,0 +8,0 @@ * This class parses a JSON schema, builds a map of its JSON references and their resolved values,

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.dereference = exports.bundle = exports.resolve = exports.parse = exports.$RefParser = exports.UnmatchedResolverError = exports.UnmatchedParserError = exports.ParserError = exports.ResolverError = exports.MissingPointerError = exports.InvalidPointerError = exports.JSONParserError = void 0;
exports.dereference = exports.bundle = exports.resolve = exports.parse = exports.$RefParser = exports.JSONParserError = exports.InvalidPointerError = exports.MissingPointerError = exports.UnmatchedParserError = exports.ResolverError = exports.UnmatchedResolverError = exports.ParserError = void 0;
const refs_js_1 = __importDefault(require("./refs.js"));

@@ -32,0 +32,0 @@ const parse_js_1 = __importDefault(require("./parse.js"));

@@ -44,4 +44,3 @@ "use strict";

catch (e) {
// @ts-expect-error TS(2571): Object is of type 'unknown'.
throw new errors_js_1.ParserError(e.message, file.url);
throw new errors_js_1.ParserError(e?.message || "Parser Error", file.url);
}

@@ -48,0 +47,0 @@ }

@@ -39,3 +39,3 @@ import type $RefParserOptions from "./options.js";

indirections: number;
constructor($ref: any, path: any, friendlyPath: any);
constructor($ref: any, path: any, friendlyPath?: string);
/**

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

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

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

*/
static join(base: any, tokens: any): any;
static join(base: string, tokens: string | string[]): string;
}
export default Pointer;

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

const token = tokens[i];
if (this.value[token] === undefined || this.value[token] === null) {
if (this.value[token] === undefined || (this.value[token] === null && i === tokens.length - 1)) {
this.value = null;

@@ -82,0 +82,0 @@ throw new errors_js_1.MissingPointerError(token, decodeURI(this.originalPath));

@@ -5,3 +5,4 @@ import Pointer from "./pointer.js";

import type $RefParserOptions from "./options.js";
type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
import type { JSONSchema } from "./types";
export type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
/**

@@ -60,3 +61,3 @@ * This class represents a single JSON reference and its resolved value.

*/
exists(path: string, options: any): boolean;
exists(path: string, options?: $RefParserOptions): boolean;
/**

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

*/
get(path: any, options: any): any;
get(path: any, options: $RefParserOptions): any;
/**

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

*/
set(path: any, value: any): void;
set(path: string, value: any): void;
/**

@@ -96,3 +97,3 @@ * Determines whether the given value is a JSON reference.

*/
static is$Ref(value: any): value is {
static is$Ref(value: unknown): value is {
$ref: string;

@@ -107,3 +108,3 @@ length?: number;

*/
static isExternal$Ref(value: any): boolean;
static isExternal$Ref(value: unknown): boolean;
/**

@@ -117,3 +118,3 @@ * Determines whether the given value is a JSON reference, and whether it is allowed by the options.

*/
static isAllowed$Ref(value: any, options: any): true | undefined;
static isAllowed$Ref(value: unknown, options?: $RefParserOptions): true | undefined;
/**

@@ -153,3 +154,3 @@ * Determines whether the given value is a JSON reference that "extends" its resolved value.

*/
static isExtended$Ref(value: any): boolean;
static isExtended$Ref(value: unknown): boolean;
/**

@@ -186,4 +187,4 @@ * Returns the resolved value of a JSON Reference.

*/
static dereference($ref: $Ref, resolvedValue: any): any;
static dereference($ref: $Ref, resolvedValue: JSONSchema): JSONSchema;
}
export default $Ref;

@@ -105,3 +105,2 @@ "use strict";

set(path, value) {
// @ts-expect-error TS(2554): Expected 3 arguments, but got 2.
const pointer = new pointer_js_1.default(this, path);

@@ -117,3 +116,8 @@ this.value = pointer.set(this.value, value);

static is$Ref(value) {
return value && typeof value === "object" && typeof value.$ref === "string" && value.$ref.length > 0;
return (Boolean(value) &&
typeof value === "object" &&
value !== null &&
"$ref" in value &&
typeof value.$ref === "string" &&
value.$ref.length > 0);
}

@@ -120,0 +124,0 @@ /**

@@ -25,4 +25,7 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const fs_1 = __importDefault(require("fs"));
const ono_1 = require("@jsdevtools/ono");

@@ -56,4 +59,3 @@ const url = __importStar(require("../util/url.js"));

try {
const data = await fs_1.promises.readFile(path);
return data;
return await fs_1.default.promises.readFile(path);
}

@@ -60,0 +62,0 @@ catch (err) {

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

constructor(parser: $RefParser);
static getParserErrors(parser: any): any[];
static getParserErrors(parser: any): JSONParserError[];
get errors(): Array<JSONParserError | InvalidPointerError | ResolverError | ParserError | MissingPointerError | UnmatchedParserError | UnmatchedResolverError>;

@@ -18,0 +18,0 @@ }

@@ -32,5 +32,3 @@ "use strict";

for (const $ref of Object.values(parser.$refs._$refs)) {
// @ts-expect-error TS(2571): Object is of type 'unknown'.
if ($ref.errors) {
// @ts-expect-error TS(2571): Object is of type 'unknown'.
errors.push(...$ref.errors);

@@ -37,0 +35,0 @@ }

@@ -82,3 +82,3 @@ export declare const parse: (u: string | URL) => URL;

*/
export declare function fromFileSystemPath(path: any): any;
export declare function fromFileSystemPath(path: string): string;
/**

@@ -85,0 +85,0 @@ * Converts a URL to a local filesystem path.

@@ -38,5 +38,7 @@ "use strict";

const is_windows_1 = require("./is-windows");
const projectDir = (0, path_2.join)(__dirname, "..", "..");
// RegExp patterns to URL-encode special characters in local filesystem paths
const urlEncodePatterns = [/\?/g, "%3F", /#/g, "%23"];
const urlEncodePatterns = [
[/\?/g, "%3F"],
[/#/g, "%23"],
];
// RegExp patterns to URL-decode special characters for local filesystem paths

@@ -211,2 +213,3 @@ const urlDecodePatterns = [/%23/g, "#", /%24/g, "$", /%26/g, "&", /%2C/g, ",", /%40/g, "@"];

if ((0, is_windows_1.isWindows)()) {
const projectDir = cwd();
const upperPath = path.toUpperCase();

@@ -217,3 +220,3 @@ const projectDirPosixPath = (0, convert_path_to_posix_1.default)(projectDir);

const hasProjectUri = upperPath.includes(posixUpper);
const isAbsolutePath = path_1.win32.isAbsolute(path);
const isAbsolutePath = path_1.win32?.isAbsolute(path);
if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {

@@ -229,4 +232,4 @@ path = (0, path_2.join)(projectDir, path);

// but are just normal characters in a filesystem path.
for (let i = 0; i < urlEncodePatterns.length; i += 2) {
path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
for (const pattern of urlEncodePatterns) {
path = path.replace(pattern[0], pattern[1]);
}

@@ -233,0 +236,0 @@ return path;

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

if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
// @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
if ($Ref.isAllowed$Ref(obj)) {

@@ -80,3 +79,2 @@ inventory$Ref(parent, key, path, pathFromRoot, indirections, inventory, $refs, options);

// @ts-expect-error TS(2554): Expected 2 arguments, but got 1.
if ($Ref.isAllowed$Ref(value)) {

@@ -83,0 +81,0 @@ inventory$Ref(obj, key, path, keyPathFromRoot, indirections, inventory, $refs, options);

@@ -22,13 +22,30 @@ import $Refs from "./refs.js";

import type { ParserOptions } from "./options.js";
import type { $RefsCallback, JSONSchema, SchemaCallback } from "./types/index.js";
import type {
Plugin,
$RefsCallback,
JSONSchema,
SchemaCallback,
HTTPResolverOptions,
FileInfo,
ResolverOptions,
JSONSchemaObject,
} from "./types/index.js";
export { JSONParserError };
export { InvalidPointerError };
export { MissingPointerError };
export { ResolverError };
export { ParserError };
export { UnmatchedParserError };
export { UnmatchedResolverError };
export {
JSONSchemaObject,
ResolverOptions,
ParserError,
UnmatchedResolverError,
ResolverError,
HTTPResolverOptions,
FileInfo,
UnmatchedParserError,
ParserOptions,
MissingPointerError,
InvalidPointerError,
JSONParserError,
Plugin,
};
type RefParserSchema = string | JSONSchema;
export type RefParserSchema = string | JSONSchema;

@@ -35,0 +52,0 @@ /**

@@ -44,5 +44,4 @@ import { ParserError } from "../util/errors.js";

return yaml.load(data, { schema: JSON_SCHEMA });
} catch (e) {
// @ts-expect-error TS(2571): Object is of type 'unknown'.
throw new ParserError(e.message, file.url);
} catch (e: any) {
throw new ParserError(e?.message || "Parser Error", file.url);
}

@@ -49,0 +48,0 @@ } else {

@@ -52,3 +52,3 @@ import type $RefParserOptions from "./options.js";

constructor($ref: any, path: any, friendlyPath: any) {
constructor($ref: any, path: any, friendlyPath?: string) {
this.$ref = $ref;

@@ -80,3 +80,3 @@

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

@@ -98,3 +98,3 @@

const token = tokens[i];
if (this.value[token] === undefined || this.value[token] === null) {
if (this.value[token] === undefined || (this.value[token] === null && i === tokens.length - 1)) {
this.value = null;

@@ -204,3 +204,3 @@ throw new MissingPointerError(token, decodeURI(this.originalPath));

*/
static join(base: any, tokens: any) {
static join(base: string, tokens: string | string[]) {
// Ensure that the base path contains a hash

@@ -207,0 +207,0 @@ if (base.indexOf("#") === -1) {

@@ -7,4 +7,5 @@ import Pointer from "./pointer.js";

import type $RefParserOptions from "./options.js";
import type { JSONSchema } from "./types";
type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
export type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;

@@ -90,3 +91,3 @@ /**

*/
exists(path: string, options: any) {
exists(path: string, options?: $RefParserOptions) {
try {

@@ -107,3 +108,3 @@ this.resolve(path, options);

*/
get(path: any, options: any) {
get(path: any, options: $RefParserOptions) {
return this.resolve(path, options)?.value;

@@ -150,4 +151,3 @@ }

*/
set(path: any, value: any) {
// @ts-expect-error TS(2554): Expected 3 arguments, but got 2.
set(path: string, value: any) {
const pointer = new Pointer(this, path);

@@ -163,4 +163,11 @@ this.value = pointer.set(this.value, value);

*/
static is$Ref(value: any): value is { $ref: string; length?: number } {
return value && typeof value === "object" && typeof value.$ref === "string" && value.$ref.length > 0;
static is$Ref(value: unknown): value is { $ref: string; length?: number } {
return (
Boolean(value) &&
typeof value === "object" &&
value !== null &&
"$ref" in value &&
typeof value.$ref === "string" &&
value.$ref.length > 0
);
}

@@ -174,3 +181,3 @@

*/
static isExternal$Ref(value: any): boolean {
static isExternal$Ref(value: unknown): boolean {
return $Ref.is$Ref(value) && value.$ref![0] !== "#";

@@ -187,3 +194,3 @@ }

*/
static isAllowed$Ref(value: any, options: any) {
static isAllowed$Ref(value: unknown, options?: $RefParserOptions) {
if (this.is$Ref(value)) {

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

*/
static isExtended$Ref(value: any) {
static isExtended$Ref(value: unknown) {
return $Ref.is$Ref(value) && Object.keys(value).length > 1;

@@ -270,3 +277,3 @@ }

*/
static dereference($ref: $Ref, resolvedValue: any) {
static dereference($ref: $Ref, resolvedValue: JSONSchema): JSONSchema {
if (resolvedValue && typeof resolvedValue === "object" && $Ref.isExtended$Ref($ref)) {

@@ -273,0 +280,0 @@ const merged = {};

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

import { promises as fs } from "fs";
import fs from "fs";
import { ono } from "@jsdevtools/ono";

@@ -34,4 +34,3 @@ import * as url from "../util/url.js";

try {
const data = await fs.readFile(path);
return data;
return await fs.promises.readFile(path);
} catch (err: any) {

@@ -38,0 +37,0 @@ throw new ResolverError(ono(err, `Error opening file "${path}"`), path);

import { Ono } from "@jsdevtools/ono";
import { stripHash, toFileSystemPath } from "./url.js";
import type $RefParser from "../index.js";
import type $Ref from "../ref";

@@ -54,6 +55,4 @@ export type JSONParserErrorType =

for (const $ref of Object.values(parser.$refs._$refs)) {
// @ts-expect-error TS(2571): Object is of type 'unknown'.
for (const $ref of Object.values(parser.$refs._$refs) as $Ref[]) {
if ($ref.errors) {
// @ts-expect-error TS(2571): Object is of type 'unknown'.
errors.push(...$ref.errors);

@@ -60,0 +59,0 @@ }

@@ -12,5 +12,7 @@ import convertPathToPosix from "./convert-path-to-posix";

const projectDir = join(__dirname, "..", "..");
// RegExp patterns to URL-encode special characters in local filesystem paths
const urlEncodePatterns = [/\?/g, "%3F", /#/g, "%23"];
const urlEncodePatterns = [
[/\?/g, "%3F"],
[/#/g, "%23"],
] as [RegExp, string][];

@@ -183,6 +185,7 @@ // RegExp patterns to URL-decode special characters for local filesystem paths

*/
export function fromFileSystemPath(path: any) {
export function fromFileSystemPath(path: string) {
// Step 1: On Windows, replace backslashes with forward slashes,
// rather than encoding them as "%5C"
if (isWindows()) {
const projectDir = cwd();
const upperPath = path.toUpperCase();

@@ -193,3 +196,3 @@ const projectDirPosixPath = convertPathToPosix(projectDir);

const hasProjectUri = upperPath.includes(posixUpper);
const isAbsolutePath = win32.isAbsolute(path);
const isAbsolutePath = win32?.isAbsolute(path);

@@ -208,4 +211,4 @@ if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {

// but are just normal characters in a filesystem path.
for (let i = 0; i < urlEncodePatterns.length; i += 2) {
path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
for (const pattern of urlEncodePatterns) {
path = path.replace(pattern[0], pattern[1]);
}

@@ -212,0 +215,0 @@

{
"name": "@apidevtools/json-schema-ref-parser",
"version": "11.2.2",
"version": "11.2.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