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

@stoplight/json-ref-resolver

Package Overview
Dependencies
Maintainers
15
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/json-ref-resolver - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

2

package.json
{
"name": "@stoplight/json-ref-resolver",
"version": "2.0.3",
"version": "2.1.0",
"description": "Recursively resolve JSON pointers and remote authorities.",

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

@@ -14,4 +14,5 @@ /// <reference types="urijs" />

protected parseResolveResult?: (opts: Types.IUriParser) => Promise<Types.IUriParserResult>;
protected transformDereferenceResult?: (opts: Types.IDereferenceTransformer) => Promise<Types.ITransformerResult>;
constructor(opts?: Types.IResolverOpts);
resolve(source: any, opts?: Types.IResolveOpts): Promise<Types.IResolveResult>;
}

@@ -15,6 +15,7 @@ "use strict";

this.parseResolveResult = opts.parseResolveResult;
this.transformDereferenceResult = opts.transformDereferenceResult;
this.ctx = opts.ctx;
}
resolve(source, opts = {}) {
const runner = new runner_1.ResolveRunner(source, Object.assign({ uriCache: this.uriCache, resolvers: this.resolvers, getRef: this.getRef, transformRef: this.transformRef, dereferenceInline: this.dereferenceInline, dereferenceRemote: this.dereferenceRemote, parseResolveResult: this.parseResolveResult }, opts, { ctx: Object.assign({}, this.ctx || {}, opts.ctx || {}) }));
const runner = new runner_1.ResolveRunner(source, Object.assign({ uriCache: this.uriCache, resolvers: this.resolvers, getRef: this.getRef, transformRef: this.transformRef, dereferenceInline: this.dereferenceInline, dereferenceRemote: this.dereferenceRemote, parseResolveResult: this.parseResolveResult, transformDereferenceResult: this.transformDereferenceResult }, opts, { ctx: Object.assign({}, this.ctx || {}, opts.ctx || {}) }));
return runner.resolve(opts.jsonPointer);

@@ -21,0 +22,0 @@ }

@@ -19,2 +19,3 @@ /// <reference types="urijs" />

readonly parseResolveResult?: (opts: Types.IUriParser) => Promise<Types.IUriParserResult>;
readonly transformDereferenceResult?: (opts: Types.IDereferenceTransformer) => Promise<Types.ITransformerResult>;
private _source;

@@ -21,0 +22,0 @@ constructor(source: any, opts?: Types.IResolveRunnerOpts);

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

parseResolveResult: this.parseResolveResult,
transformDereferenceResult: this.transformDereferenceResult,
dereferenceRemote: this.dereferenceRemote,

@@ -191,2 +192,3 @@ dereferenceInline: this.dereferenceInline,

this.parseResolveResult = opts.parseResolveResult;
this.transformDereferenceResult = opts.transformDereferenceResult;
this.ctx = opts.ctx;

@@ -318,2 +320,29 @@ this.lookupUri = memoize(this.lookupUri, {

}
if (this.transformDereferenceResult) {
const ref = new URI(jsonPointer || '');
try {
const { result, error } = yield this.transformDereferenceResult({
source: this.source,
result: resolved.result,
targetAuthority: ref,
parentAuthority: this.baseUri,
parentPath: targetPath,
fragment: ref.fragment(),
});
resolved.result = result;
if (error) {
throw new Error(`Could not transform dereferenced result for '${ref.toString()}' - ${String(error)}`);
}
}
catch (e) {
resolved.errors.push({
code: 'TRANSFORM_DEREFERENCED',
message: `Error: Could not transform dereferenced result for '${this.baseUri.toString()}${ref.fragment() !== '' ? `#${ref.fragment()}` : ``}' - ${String(e)}`,
uri: ref,
uriStack: this.uriStack,
pointerStack: [],
path: targetPath,
});
}
}
return resolved;

@@ -320,0 +349,0 @@ });

@@ -12,2 +12,3 @@ /// <reference types="urijs" />

parseResolveResult?: (opts: IUriParser) => Promise<IUriParserResult>;
transformDereferenceResult?: (opts: IDereferenceTransformer) => Promise<ITransformerResult>;
dereferenceInline?: boolean;

@@ -44,2 +45,14 @@ dereferenceRemote?: boolean;

}
export interface IDereferenceTransformer {
result: any;
source: any;
fragment: string;
targetAuthority: uri.URI;
parentAuthority: uri.URI;
parentPath: string[];
}
export interface ITransformerResult {
result?: any;
error?: Error;
}
export interface IUriResult {

@@ -62,3 +75,3 @@ pointerStack: string[];

}
export declare type ResolverErrorCode = 'POINTER_MISSING' | 'RESOLVE_URI' | 'PARSE_URI' | 'RESOLVE_POINTER';
export declare type ResolverErrorCode = 'POINTER_MISSING' | 'RESOLVE_URI' | 'PARSE_URI' | 'RESOLVE_POINTER' | 'TRANSFORM_DEREFERENCED';
export interface IResolveError {

@@ -65,0 +78,0 @@ code: ResolverErrorCode;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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