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

@stoplight/json

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/json - npm Package Compare versions

Comparing version 3.19.0 to 3.20.0

9

bundle.d.ts

@@ -0,4 +1,9 @@

import { JsonPath } from '@stoplight/types';
export declare const BUNDLE_ROOT = "#/__bundled__";
export declare const ERRORS_ROOT = "#/__errors__";
export declare const bundleTarget: <T = unknown>({ document, path, bundleRoot, errorsRoot, cloneDocument, }: {
declare type KeyProviderFn = (props: {
document: unknown;
path: JsonPath;
}) => string | void | undefined | null;
export declare const bundleTarget: <T = unknown>({ document, path, bundleRoot, errorsRoot, cloneDocument, keyProvider, }: {
document: T;

@@ -9,2 +14,4 @@ path: string;

cloneDocument?: boolean | undefined;
keyProvider?: KeyProviderFn | undefined;
}, cur?: unknown) => any;
export {};

2

index.cjs.js

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

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var lodash=require("lodash"),path=require("@stoplight/path"),jsoncParser=require("jsonc-parser"),createOrderedObject=require("@stoplight/ordered-object-literal"),createOrderedObject__default=_interopDefault(createOrderedObject),types=require("@stoplight/types"),fastStringify=_interopDefault(require("safe-stable-stringify"));function isPlainObject(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype||"function"==typeof e.constructor&&Function.toString.call(Object)===Function.toString.call(e.constructor)}function assertResolvableInput(e,t,r){if(!isPlainObject(e)&&!Array.isArray(e)||!(t in e))throw new ReferenceError(`Could not resolve '${r}'`)}function assertObjectWithValidRef(e){if("string"!=typeof e.$ref)throw new TypeError("$ref should be a string")}const hasSomeRef=e=>isPlainObject(e)&&"$ref"in e,hasRef=e=>hasSomeRef(e)&&"string"==typeof e.$ref,isLocalRef=e=>e.length>0&&("#"===e||/^#\S*$/.test(e)),replaceInString=(e,t,r)=>{const n=e.toString();let o="",a=n,i=0,s=a.indexOf(t);for(;s>-1;)o+=n.substring(i,i+s)+r,a=a.substring(s+t.length,a.length),i+=s+t.length,s=a.indexOf(t);return a.length>0&&(o+=n.substring(n.length-a.length,n.length)),o},encodePointerFragment=e=>"number"==typeof e?e:replaceInString(replaceInString(e,"~","~0"),"/","~1"),pathToPointer=e=>encodeUriFragmentIdentifier(e),encodeUriFragmentIdentifier=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map(encodePointerFragment).join("/")}`};function safeDecodeURIComponent(e){try{return decodeURIComponent(e)}catch(t){return e}}const PERCENT_ENCODING_OCTET=/%[0-9a-f]+/gi,decodePointer=e=>{let t;try{t=decodeURIComponent(e)}catch(r){t=e.replace(PERCENT_ENCODING_OCTET,safeDecodeURIComponent)}return replaceInString(replaceInString(t,"~1","/"),"~0","~")},pointerToPath=e=>decodeUriFragmentIdentifier(e),decodeFragmentSegments=e=>{const t=e.length,r=[];let n=-1;for(;++n<t;)r.push(decodePointer(e[n]));return r},decodeUriFragmentIdentifier=e=>{if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new URIError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new URIError("Invalid JSON Pointer syntax.");return decodeFragmentSegments(e.substring(2).split("/"))},extractSourceFromRef=e=>{if("string"!=typeof e||0===e.length||isLocalRef(e))return null;const t=e.indexOf("#");return-1===t?e:e.slice(0,t)};function applyOverrides(e,t){return isPlainObject(t)&&isPlainObject(e)&&("summary"in e||"description"in e)?Object.assign(Object.assign(Object.assign({},t),"description"in e?{description:e.description}:null),"summary"in e?{summary:e.summary}:null):t}function resolveSource(e,t){const r=extractSourceFromRef(t);return null===r?e:path.isAbsolute(r)?r:path.join(path.dirname(e),r)}function*traverse(e,t,r){hasSomeRef(e.value)&&(assertObjectWithValidRef(e.value),yield[-1,e.value]);for(const[n,o]of t.entries())assertResolvableInput(e.value,o,r),e.value=e.value[o],hasSomeRef(e.value)&&(assertObjectWithValidRef(e.value),yield[n,e.value])}function _resolveInlineRefWithLocation(e,t,r,n){if(null!==extractSourceFromRef(t))throw new ReferenceError("Cannot resolve external references");const o=pointerToPath(t);let a=[...o];"#"===t&&hasSomeRef(e)&&(assertObjectWithValidRef(e),o.unshift(...pointerToPath(e.$ref)));const i={value:e};for(const[s,c]of traverse(i,o,t)){if(r.includes(c))return{source:null,location:null!=n?n:a,value:r[r.length-1]};r.push(c);const t=_resolveInlineRefWithLocation(e,c.$ref,r,a);i.value=t.value,(a=t.location).push(...o.slice(s+1))}return{source:null,location:a,value:r.length>0?applyOverrides(r[r.length-1],i.value):i.value}}function resolveInlineRef(e,t){return resolveInlineRefWithLocation(e,t).value}function resolveInlineRefWithLocation(e,t){return _resolveInlineRefWithLocation(e,t,[])}const _traverse=(e,t,r)=>{const n={value:e,path:r};t.onEnter&&t.onEnter(n);for(const n of Object.keys(e)){const o=e[n];t.onProperty&&t.onProperty({parent:e,parentPath:r,property:n,propertyValue:o}),"object"==typeof o&&null!==o&&_traverse(o,t,r.concat(n))}t.onLeave&&t.onLeave(n)},traverse$1=(e,t)=>{"object"==typeof e&&null!==e&&_traverse(e,"function"==typeof t?{onProperty:t}:t,[])},BUNDLE_ROOT="#/__bundled__",ERRORS_ROOT="#/__errors__",bundleTarget=({document:e,path:t,bundleRoot:r=BUNDLE_ROOT,errorsRoot:n=ERRORS_ROOT,cloneDocument:o=!0},a)=>{if(t===r||t===n)throw new Error("Roots do not make any sense");const i=o?lodash.cloneDeep(e):e;return bundle(i,pointerToPath(r),pointerToPath(n))(t,{[t]:!0},a)},bundle=(e,t,r)=>{const n=new Set,o=(a,i,s,c={},l={},f={})=>{const u=pointerToPath(a),p=lodash.get(e,u);traverse$1(s||p,({parent:r})=>{if(hasRef(r)&&isLocalRef(r.$ref)){const s=r.$ref;if(f[s])return;if(c[s])return void(r.$ref=c[s]);let u,p,h,d,g;try{let r;if(u=pointerToPath(s),Array.isArray(lodash.get(e,u.slice(0,-1)))){r=`${u[u.length-2]}_${u[u.length-1]}`}else r=u[u.length-1];h=r;let o=1;for(;n.has(h);)if(h=`${r}_${++o}`,o>20)throw new Error(`Keys ${r}_2 through ${r}_20 already taken.`);n.add(h),p=[...t,h],d=pathToPointer(p)}catch(e){f[s]=e instanceof Error?e.message:String(e)}if(!u||!p||!d)return;if("object"==typeof e&&null!==e)try{g=resolveInlineRef(Object(e),s)}catch(t){g=lodash.get(e,u)}void 0!==g&&(c[s]=d,r.$ref=d,lodash.has(l,p)||(Array.isArray(g)?lodash.set(l,p,new Array(g.length).fill(null)):"object"==typeof g&&lodash.setWith(l,p,{},Object),lodash.set(l,p,g),i[s]||(i[s]=!0,o(a,i,g,c,l,f),i[s]=!1)))}});const h=lodash.get(l,t);return h&&Object.keys(h).length&&lodash.set(p,t,h),(Object.keys(f).length||lodash.has(e,r))&&lodash.set(p,r,lodash.has(e,r)?lodash.get(e,r):f),p};return o},decodePointerFragment=e=>replaceInString(replaceInString(e,"~1","/"),"~0","~"),decycle=(e,t)=>{const r=new WeakMap;return function e(n,o){let a;if(t&&(n=t(n)),isPlainObject(n)||Array.isArray(n)){const t=r.get(n);return t?{$ref:t}:(r.set(n,pathToPointer(o)),Array.isArray(n)?a=n.map((t,r)=>e(t,[...o,String(r)])):(a={},Object.keys(n).forEach(t=>{a[t]=e(n[t],[...o,t])})),r.delete(n),a)}return n}(e,[])},encodePointer=e=>replaceInString(replaceInString(e,"~","~0"),"//","/~1"),extractPointerFromRef=e=>{if("string"!=typeof e||0===e.length)return null;const t=e.indexOf("#");return-1===t?null:e.slice(t)},getFirstPrimitiveProperty=e=>{const t=jsoncParser.createScanner(e,!0);if(t.scan(),1!==t.getToken())return;if(t.scan(),2===t.getToken())return;if(10!==t.getToken())throw new SyntaxError("Unexpected character");const r=t.getTokenValue();if(t.scan(),6!==t.getToken())throw new SyntaxError("Colon expected");switch(t.scan(),t.getToken()){case 10:return[r,t.getTokenValue()];case 11:return[r,Number(t.getTokenValue())];case 8:return[r,!0];case 9:return[r,!1];case 7:return[r,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},getJsonPathForPosition=({lineMap:e,ast:t},r)=>{const n=e[r.line],o=e[r.line+1];if(void 0===n)return;const a=jsoncParser.findNodeAtOffset(t,void 0===o?n+r.character:Math.min(o,n+r.character),!0);if(void 0===a)return;const i=jsoncParser.getNodePath(a);return 0!==i.length?i:void 0};function getLastPathSegment(e){return decodePointerFragment(e.split("/").pop()||"")}const getLocationForJsonPath=({ast:e},t,r=!1)=>{const n=findNodeAtPath(e,t,r);if(void 0!==n&&void 0!==n.range)return{range:n.range}};function findNodeAtPath(e,t,r){e:for(const n of t){const t=Number.isInteger(Number(n))?Number(n):n;if("string"==typeof t||"number"==typeof t&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return r?e:void 0;for(const r of e.children)if(Array.isArray(r.children)&&r.children[0].value===String(t)&&2===r.children.length){e=r.children[1];continue e}return r?e:void 0}if("array"!==e.type||t<0||!Array.isArray(e.children)||t>=e.children.length)return r?e:void 0;e=e.children[t]}return e}const parseWithPointers=(e,t={disallowComments:!0})=>{const r=[],{ast:n,data:o,lineMap:a}=parseTree(e,r,t);return{data:o,diagnostics:r,ast:n,lineMap:a}};function parseTree(e,t=[],r){const n=computeLineMap(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},a=null,i=[];const s=new WeakMap,c=[];function l(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function f(e,t,r){return{start:{line:e,character:t},end:{line:e,character:t+r}}}function u(e){return o.children.push(e),e}function p(e){Array.isArray(i)?i.push(e):null!==a&&(i[a]=e)}function h(e){p(e),c.push(i),i=e,a=null}function d(){i=c.pop()}const g={onObjectBegin:(e,t,n,a)=>{o=u({type:"object",offset:e,length:-1,parent:o,children:[],range:f(n,a,t)}),!1===r.ignoreDuplicateKeys&&s.set(o,[]),h(createObjectLiteral(!0===r.preserveKeyOrder))},onObjectProperty:(e,n,c,l,p)=>{if((o=u({type:"property",offset:n,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:n,length:c,parent:o}),!1===r.ignoreDuplicateKeys){const r=s.get(o.parent);r&&(0!==r.length&&r.includes(e)?t.push({range:f(l,p,c),message:"DuplicateKey",severity:types.DiagnosticSeverity.Error,path:getJsonPath(o),code:20}):r.push(e))}!0===r.preserveKeyOrder&&swapKey(i,e),a=e},onObjectEnd:(e,t,n,a)=>{!1===r.ignoreDuplicateKeys&&s.delete(o),o.length=e+t-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=a+t),o=o.parent,l(e+t),d()},onArrayBegin:(e,t,r,n)=>{o=u({type:"array",offset:e,length:-1,parent:o,children:[],range:f(r,n,t)}),h([])},onArrayEnd:(e,t,r,n)=>{o.length=e+t-o.offset,o.range&&(o.range.end.line=r,o.range.end.character=n+t),o=o.parent,l(e+t),d()},onLiteralValue:(e,t,r,n,a)=>{u({type:getLiteralNodeType(e),offset:t,length:r,parent:o,value:e,range:f(n,a,r)}),l(t+r),p(e)},onSeparator:(e,t)=>{"property"===o.type&&(":"===e?o.colonOffset=t:","===e&&l(t))},onError:(e,r,n,o,a)=>{t.push({range:f(o,a,n),message:jsoncParser.printParseErrorCode(e),severity:types.DiagnosticSeverity.Error,code:e})}};jsoncParser.visit(e,g,r);const y=o.children[0];return y&&delete y.parent,{ast:y,data:i[0],lineMap:n}}function getLiteralNodeType(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const computeLineMap=e=>{const t=[0];let r=0;for(;r<e.length;r++)"\n"===e[r]&&t.push(r+1);return t.push(r+1),t};function getJsonPath(e,t=[]){return"property"===e.type&&t.unshift(e.children[0].value),void 0!==e.parent?("array"===e.parent.type&&void 0!==e.parent.parent&&t.unshift(e.parent.children.indexOf(e)),getJsonPath(e.parent,t)):t}function createObjectLiteral(e){return e?createOrderedObject__default({}):{}}function swapKey(e,t){if(!(t in e))return;const r=createOrderedObject.getOrder(e),n=r.indexOf(t);-1!==n&&(r.splice(n,1),r.push(t))}const renameObjectKey=(e,t,r)=>{if(!e||!Object.hasOwnProperty.call(e,t)||t===r)return e;const n={};for(const[o,a]of Object.entries(e))o===t?n[r]=a:o in n||(n[o]=a);return n};function isObject(e){return isPlainObject(e)||Array.isArray(e)}function reparentBundleTarget(e,t,r){if(r.length<=1||t.length<=1)throw Error("Source/target path must not be empty and point at root");if(0===t.indexOf(r))throw Error("Target path cannot be contained within source");const n=pointerToPath(t);let o=e;for(const e of n){if(!isObject(o))return;o=o[e]}if(!isObject(o))return;const a=pointerToPath(r);let i=e;for(const[e,t]of a.entries()){if(!isObject(i)||t in i)return;const r=e===a.length-1?o:{};i[t]=r,i=r}delete e[n[0]],_reparentBundleTarget(e,t,r)}function _reparentBundleTarget(e,t,r){for(const n of Object.keys(e)){const o=e[n];if("$ref"!==n)isObject(o)&&_reparentBundleTarget(o,t,r);else{if("string"!=typeof o||!isLocalRef(o))continue;0===o.indexOf(t)&&(e[n]=o.replace(t,r))}}}async function _resolveExternalRefWithLocation(e,t,r,n,o){let a=resolveSource(t,r);const i=extractPointerFromRef(r)||"#",s=await e[a],c=pointerToPath(i);let l=[...c];const f={value:s};for(const[r,s]of traverse(f,c,i)){if(n.includes(s))return{source:t,location:null!=o?o:l,value:n[n.length-1]};n.push(s);const i=await _resolveExternalRefWithLocation(e,a,s.$ref,n,l);({source:a,location:l}=i),f.value=i.value,l.push(...c.slice(r+1))}return{source:a,location:l,value:n.length>0?applyOverrides(n[n.length-1],f.value):f.value}}async function resolveExternalRef(e,t,r){return(await resolveExternalRefWithLocation(e,t,r)).value}function resolveExternalRefWithLocation(e,t,r){return _resolveExternalRefWithLocation(e,t,r,[])}const safeParse=(e,t)=>{if("string"!=typeof e)return e;try{const r=parseNumber(e);return"string"==typeof r?r:JSON.parse(e,t)}catch(e){return}},parseNumber=e=>{const t=Number(e);return Number.isFinite(t)?String(t)===e?t:e:NaN},safeStringify=(e,t,r)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,t,r)}catch(n){return fastStringify(e,t,r)}},startsWith=(e,t)=>{if(e instanceof Array){if(t instanceof Array){if(t.length>e.length)return!1;for(const r in t){if(!t.hasOwnProperty(r))continue;const n=parseInt(e[r]),o=parseInt(t[r]);if(isNaN(n)&&isNaN(o)){if(e[r]!==t[r])return!1}else if(n!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof t)return e.startsWith(t)}return!0},stringify=(e,t,r)=>{const n=safeStringify(e,t,r);if(void 0===n)throw new Error("The value could not be stringified");return n};function toPropertyPath(e){return e.replace(/^(\/|#\/)/,"").split("/").map(decodePointerFragment).map(sanitize).join(".")}function sanitize(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const KEYS=Symbol.for(createOrderedObject.ORDER_KEY_ID),traps={ownKeys:e=>KEYS in e?e[KEYS]:Reflect.ownKeys(e)},trapAccess=e=>new Proxy(e,traps);function trimStart(e,t){if("string"==typeof e&&"string"==typeof t)return lodash.trimStart(e,t);if(!(e&&Array.isArray(e)&&e.length&&t&&Array.isArray(t)&&t.length))return e;let r=0;for(const n in e)if(e.hasOwnProperty(n)){if(e[n]!==t[n])break;r++}return e.slice(r)}exports.BUNDLE_ROOT=BUNDLE_ROOT,exports.ERRORS_ROOT=ERRORS_ROOT,exports.KEYS=KEYS,exports.bundleTarget=bundleTarget,exports.decodePointer=decodePointer,exports.decodePointerFragment=decodePointerFragment,exports.decycle=decycle,exports.encodePointer=encodePointer,exports.encodePointerFragment=encodePointerFragment,exports.extractPointerFromRef=extractPointerFromRef,exports.extractSourceFromRef=extractSourceFromRef,exports.getFirstPrimitiveProperty=getFirstPrimitiveProperty,exports.getJsonPathForPosition=getJsonPathForPosition,exports.getLastPathSegment=getLastPathSegment,exports.getLocationForJsonPath=getLocationForJsonPath,exports.hasRef=hasRef,exports.isLocalRef=isLocalRef,exports.isPlainObject=isPlainObject,exports.parseTree=parseTree,exports.parseWithPointers=parseWithPointers,exports.pathToPointer=pathToPointer,exports.pointerToPath=pointerToPath,exports.renameObjectKey=renameObjectKey,exports.reparentBundleTarget=reparentBundleTarget,exports.resolveExternalRef=resolveExternalRef,exports.resolveExternalRefWithLocation=resolveExternalRefWithLocation,exports.resolveInlineRef=resolveInlineRef,exports.resolveInlineRefWithLocation=resolveInlineRefWithLocation,exports.safeParse=safeParse,exports.safeStringify=safeStringify,exports.startsWith=startsWith,exports.stringify=stringify,exports.toPropertyPath=toPropertyPath,exports.trapAccess=trapAccess,exports.traverse=traverse$1,exports.trimStart=trimStart;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var lodash=require("lodash"),path=require("@stoplight/path"),jsoncParser=require("jsonc-parser"),createOrderedObject=require("@stoplight/ordered-object-literal"),createOrderedObject__default=_interopDefault(createOrderedObject),types=require("@stoplight/types"),fastStringify=_interopDefault(require("safe-stable-stringify"));function isPlainObject(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype||"function"==typeof e.constructor&&Function.toString.call(Object)===Function.toString.call(e.constructor)}function assertResolvableInput(e,t,r){if(!isPlainObject(e)&&!Array.isArray(e)||!(t in e))throw new ReferenceError(`Could not resolve '${r}'`)}function assertObjectWithValidRef(e){if("string"!=typeof e.$ref)throw new TypeError("$ref should be a string")}const hasSomeRef=e=>isPlainObject(e)&&"$ref"in e,hasRef=e=>hasSomeRef(e)&&"string"==typeof e.$ref,isLocalRef=e=>e.length>0&&("#"===e||/^#\S*$/.test(e)),replaceInString=(e,t,r)=>{const n=e.toString();let o="",a=n,i=0,s=a.indexOf(t);for(;s>-1;)o+=n.substring(i,i+s)+r,a=a.substring(s+t.length,a.length),i+=s+t.length,s=a.indexOf(t);return a.length>0&&(o+=n.substring(n.length-a.length,n.length)),o},encodePointerFragment=e=>"number"==typeof e?e:replaceInString(replaceInString(e,"~","~0"),"/","~1"),pathToPointer=e=>encodeUriFragmentIdentifier(e),encodeUriFragmentIdentifier=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map(encodePointerFragment).join("/")}`};function safeDecodeURIComponent(e){try{return decodeURIComponent(e)}catch(t){return e}}const PERCENT_ENCODING_OCTET=/%[0-9a-f]+/gi,decodePointer=e=>{let t;try{t=decodeURIComponent(e)}catch(r){t=e.replace(PERCENT_ENCODING_OCTET,safeDecodeURIComponent)}return replaceInString(replaceInString(t,"~1","/"),"~0","~")},pointerToPath=e=>decodeUriFragmentIdentifier(e),decodeFragmentSegments=e=>{const t=e.length,r=[];let n=-1;for(;++n<t;)r.push(decodePointer(e[n]));return r},decodeUriFragmentIdentifier=e=>{if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new URIError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new URIError("Invalid JSON Pointer syntax.");return decodeFragmentSegments(e.substring(2).split("/"))},extractSourceFromRef=e=>{if("string"!=typeof e||0===e.length||isLocalRef(e))return null;const t=e.indexOf("#");return-1===t?e:e.slice(0,t)};function applyOverrides(e,t){return isPlainObject(t)&&isPlainObject(e)&&("summary"in e||"description"in e)?Object.assign(Object.assign(Object.assign({},t),"description"in e?{description:e.description}:null),"summary"in e?{summary:e.summary}:null):t}function resolveSource(e,t){const r=extractSourceFromRef(t);return null===r?e:path.isAbsolute(r)?r:path.join(path.dirname(e),r)}function*traverse(e,t,r){hasSomeRef(e.value)&&(assertObjectWithValidRef(e.value),yield[-1,e.value]);for(const[n,o]of t.entries())assertResolvableInput(e.value,o,r),e.value=e.value[o],hasSomeRef(e.value)&&(assertObjectWithValidRef(e.value),yield[n,e.value])}function _resolveInlineRefWithLocation(e,t,r,n){if(null!==extractSourceFromRef(t))throw new ReferenceError("Cannot resolve external references");const o=pointerToPath(t);let a=[...o];"#"===t&&hasSomeRef(e)&&(assertObjectWithValidRef(e),o.unshift(...pointerToPath(e.$ref)));const i={value:e};for(const[s,c]of traverse(i,o,t)){if(r.includes(c))return{source:null,location:null!=n?n:a,value:r[r.length-1]};r.push(c);const t=_resolveInlineRefWithLocation(e,c.$ref,r,a);i.value=t.value,(a=t.location).push(...o.slice(s+1))}return{source:null,location:a,value:r.length>0?applyOverrides(r[r.length-1],i.value):i.value}}function resolveInlineRef(e,t){return resolveInlineRefWithLocation(e,t).value}function resolveInlineRefWithLocation(e,t){return _resolveInlineRefWithLocation(e,t,[])}const _traverse=(e,t,r)=>{const n={value:e,path:r};t.onEnter&&t.onEnter(n);for(const n of Object.keys(e)){const o=e[n];t.onProperty&&t.onProperty({parent:e,parentPath:r,property:n,propertyValue:o}),"object"==typeof o&&null!==o&&_traverse(o,t,r.concat(n))}t.onLeave&&t.onLeave(n)},traverse$1=(e,t)=>{"object"==typeof e&&null!==e&&_traverse(e,"function"==typeof t?{onProperty:t}:t,[])},BUNDLE_ROOT="#/__bundled__",ERRORS_ROOT="#/__errors__",bundleTarget=({document:e,path:t,bundleRoot:r=BUNDLE_ROOT,errorsRoot:n=ERRORS_ROOT,cloneDocument:o=!0,keyProvider:a},i)=>{if(t===r||t===n)throw new Error("Roots do not make any sense");const s=o?lodash.cloneDeep(e):e;return bundle(s,pointerToPath(r),pointerToPath(n),a)(t,{[t]:!0},i)},defaultKeyProvider=({document:e,path:t})=>{if(Array.isArray(lodash.get(e,t.slice(0,-1)))){return`${t[t.length-2]}_${t[t.length-1]}`}return String(t[t.length-1])},bundle=(e,t,r,n)=>{const o=new Set,a=(i,s,c,l={},f={},u={})=>{const p=pointerToPath(i),h=lodash.get(e,p);traverse$1(c||h,({parent:r})=>{if(hasRef(r)&&isLocalRef(r.$ref)){const c=r.$ref;if(u[c])return;if(l[c])return void(r.$ref=l[c]);let p,h,d,g,y;try{let r;p=pointerToPath(c),n&&(r=n({document:e,path:p})),r||(r=defaultKeyProvider({document:e,path:p})),d=r;let a=1;for(;o.has(d);)if(d=`${r}_${++a}`,a>20)throw new Error(`Keys ${r}_2 through ${r}_20 already taken.`);o.add(d),h=[...t,d],g=pathToPointer(h)}catch(e){u[c]=e instanceof Error?e.message:String(e)}if(!p||!h||!g)return;if("object"==typeof e&&null!==e)try{y=resolveInlineRef(Object(e),c)}catch(t){y=lodash.get(e,p)}void 0!==y&&(l[c]=g,r.$ref=g,lodash.has(f,h)||(Array.isArray(y)?lodash.set(f,h,new Array(y.length).fill(null)):"object"==typeof y&&lodash.setWith(f,h,{},Object),lodash.set(f,h,y),s[c]||(s[c]=!0,a(i,s,y,l,f,u),s[c]=!1)))}});const d=lodash.get(f,t);return d&&Object.keys(d).length&&lodash.set(h,t,d),(Object.keys(u).length||lodash.has(e,r))&&lodash.set(h,r,lodash.has(e,r)?lodash.get(e,r):u),h};return a},decodePointerFragment=e=>replaceInString(replaceInString(e,"~1","/"),"~0","~"),decycle=(e,t)=>{const r=new WeakMap;return function e(n,o){let a;if(t&&(n=t(n)),isPlainObject(n)||Array.isArray(n)){const t=r.get(n);return t?{$ref:t}:(r.set(n,pathToPointer(o)),Array.isArray(n)?a=n.map((t,r)=>e(t,[...o,String(r)])):(a={},Object.keys(n).forEach(t=>{a[t]=e(n[t],[...o,t])})),r.delete(n),a)}return n}(e,[])},encodePointer=e=>replaceInString(replaceInString(e,"~","~0"),"//","/~1"),extractPointerFromRef=e=>{if("string"!=typeof e||0===e.length)return null;const t=e.indexOf("#");return-1===t?null:e.slice(t)},getFirstPrimitiveProperty=e=>{const t=jsoncParser.createScanner(e,!0);if(t.scan(),1!==t.getToken())return;if(t.scan(),2===t.getToken())return;if(10!==t.getToken())throw new SyntaxError("Unexpected character");const r=t.getTokenValue();if(t.scan(),6!==t.getToken())throw new SyntaxError("Colon expected");switch(t.scan(),t.getToken()){case 10:return[r,t.getTokenValue()];case 11:return[r,Number(t.getTokenValue())];case 8:return[r,!0];case 9:return[r,!1];case 7:return[r,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},getJsonPathForPosition=({lineMap:e,ast:t},r)=>{const n=e[r.line],o=e[r.line+1];if(void 0===n)return;const a=jsoncParser.findNodeAtOffset(t,void 0===o?n+r.character:Math.min(o,n+r.character),!0);if(void 0===a)return;const i=jsoncParser.getNodePath(a);return 0!==i.length?i:void 0};function getLastPathSegment(e){return decodePointerFragment(e.split("/").pop()||"")}const getLocationForJsonPath=({ast:e},t,r=!1)=>{const n=findNodeAtPath(e,t,r);if(void 0!==n&&void 0!==n.range)return{range:n.range}};function findNodeAtPath(e,t,r){e:for(const n of t){const t=Number.isInteger(Number(n))?Number(n):n;if("string"==typeof t||"number"==typeof t&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return r?e:void 0;for(const r of e.children)if(Array.isArray(r.children)&&r.children[0].value===String(t)&&2===r.children.length){e=r.children[1];continue e}return r?e:void 0}if("array"!==e.type||t<0||!Array.isArray(e.children)||t>=e.children.length)return r?e:void 0;e=e.children[t]}return e}const parseWithPointers=(e,t={disallowComments:!0})=>{const r=[],{ast:n,data:o,lineMap:a}=parseTree(e,r,t);return{data:o,diagnostics:r,ast:n,lineMap:a}};function parseTree(e,t=[],r){const n=computeLineMap(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},a=null,i=[];const s=new WeakMap,c=[];function l(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function f(e,t,r){return{start:{line:e,character:t},end:{line:e,character:t+r}}}function u(e){return o.children.push(e),e}function p(e){Array.isArray(i)?i.push(e):null!==a&&(i[a]=e)}function h(e){p(e),c.push(i),i=e,a=null}function d(){i=c.pop()}const g={onObjectBegin:(e,t,n,a)=>{o=u({type:"object",offset:e,length:-1,parent:o,children:[],range:f(n,a,t)}),!1===r.ignoreDuplicateKeys&&s.set(o,[]),h(createObjectLiteral(!0===r.preserveKeyOrder))},onObjectProperty:(e,n,c,l,p)=>{if((o=u({type:"property",offset:n,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:n,length:c,parent:o}),!1===r.ignoreDuplicateKeys){const r=s.get(o.parent);r&&(0!==r.length&&r.includes(e)?t.push({range:f(l,p,c),message:"DuplicateKey",severity:types.DiagnosticSeverity.Error,path:getJsonPath(o),code:20}):r.push(e))}!0===r.preserveKeyOrder&&swapKey(i,e),a=e},onObjectEnd:(e,t,n,a)=>{!1===r.ignoreDuplicateKeys&&s.delete(o),o.length=e+t-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=a+t),o=o.parent,l(e+t),d()},onArrayBegin:(e,t,r,n)=>{o=u({type:"array",offset:e,length:-1,parent:o,children:[],range:f(r,n,t)}),h([])},onArrayEnd:(e,t,r,n)=>{o.length=e+t-o.offset,o.range&&(o.range.end.line=r,o.range.end.character=n+t),o=o.parent,l(e+t),d()},onLiteralValue:(e,t,r,n,a)=>{u({type:getLiteralNodeType(e),offset:t,length:r,parent:o,value:e,range:f(n,a,r)}),l(t+r),p(e)},onSeparator:(e,t)=>{"property"===o.type&&(":"===e?o.colonOffset=t:","===e&&l(t))},onError:(e,r,n,o,a)=>{t.push({range:f(o,a,n),message:jsoncParser.printParseErrorCode(e),severity:types.DiagnosticSeverity.Error,code:e})}};jsoncParser.visit(e,g,r);const y=o.children[0];return y&&delete y.parent,{ast:y,data:i[0],lineMap:n}}function getLiteralNodeType(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const computeLineMap=e=>{const t=[0];let r=0;for(;r<e.length;r++)"\n"===e[r]&&t.push(r+1);return t.push(r+1),t};function getJsonPath(e,t=[]){return"property"===e.type&&t.unshift(e.children[0].value),void 0!==e.parent?("array"===e.parent.type&&void 0!==e.parent.parent&&t.unshift(e.parent.children.indexOf(e)),getJsonPath(e.parent,t)):t}function createObjectLiteral(e){return e?createOrderedObject__default({}):{}}function swapKey(e,t){if(!(t in e))return;const r=createOrderedObject.getOrder(e),n=r.indexOf(t);-1!==n&&(r.splice(n,1),r.push(t))}const renameObjectKey=(e,t,r)=>{if(!e||!Object.hasOwnProperty.call(e,t)||t===r)return e;const n={};for(const[o,a]of Object.entries(e))o===t?n[r]=a:o in n||(n[o]=a);return n};function isObject(e){return isPlainObject(e)||Array.isArray(e)}function reparentBundleTarget(e,t,r){if(r.length<=1||t.length<=1)throw Error("Source/target path must not be empty and point at root");if(0===t.indexOf(r))throw Error("Target path cannot be contained within source");const n=pointerToPath(t);let o=e;for(const e of n){if(!isObject(o))return;o=o[e]}if(!isObject(o))return;const a=pointerToPath(r);let i=e;for(const[e,t]of a.entries()){if(!isObject(i)||t in i)return;const r=e===a.length-1?o:{};i[t]=r,i=r}delete e[n[0]],_reparentBundleTarget(e,t,r)}function _reparentBundleTarget(e,t,r){for(const n of Object.keys(e)){const o=e[n];if("$ref"!==n)isObject(o)&&_reparentBundleTarget(o,t,r);else{if("string"!=typeof o||!isLocalRef(o))continue;0===o.indexOf(t)&&(e[n]=o.replace(t,r))}}}async function _resolveExternalRefWithLocation(e,t,r,n,o){let a=resolveSource(t,r);const i=extractPointerFromRef(r)||"#",s=await e[a],c=pointerToPath(i);let l=[...c];const f={value:s};for(const[r,s]of traverse(f,c,i)){if(n.includes(s))return{source:t,location:null!=o?o:l,value:n[n.length-1]};n.push(s);const i=await _resolveExternalRefWithLocation(e,a,s.$ref,n,l);({source:a,location:l}=i),f.value=i.value,l.push(...c.slice(r+1))}return{source:a,location:l,value:n.length>0?applyOverrides(n[n.length-1],f.value):f.value}}async function resolveExternalRef(e,t,r){return(await resolveExternalRefWithLocation(e,t,r)).value}function resolveExternalRefWithLocation(e,t,r){return _resolveExternalRefWithLocation(e,t,r,[])}const safeParse=(e,t)=>{if("string"!=typeof e)return e;try{const r=parseNumber(e);return"string"==typeof r?r:JSON.parse(e,t)}catch(e){return}},parseNumber=e=>{const t=Number(e);return Number.isFinite(t)?String(t)===e?t:e:NaN},safeStringify=(e,t,r)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,t,r)}catch(n){return fastStringify(e,t,r)}},startsWith=(e,t)=>{if(e instanceof Array){if(t instanceof Array){if(t.length>e.length)return!1;for(const r in t){if(!t.hasOwnProperty(r))continue;const n=parseInt(e[r]),o=parseInt(t[r]);if(isNaN(n)&&isNaN(o)){if(e[r]!==t[r])return!1}else if(n!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof t)return e.startsWith(t)}return!0},stringify=(e,t,r)=>{const n=safeStringify(e,t,r);if(void 0===n)throw new Error("The value could not be stringified");return n};function toPropertyPath(e){return e.replace(/^(\/|#\/)/,"").split("/").map(decodePointerFragment).map(sanitize).join(".")}function sanitize(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const KEYS=Symbol.for(createOrderedObject.ORDER_KEY_ID),traps={ownKeys:e=>KEYS in e?e[KEYS]:Reflect.ownKeys(e)},trapAccess=e=>new Proxy(e,traps);function trimStart(e,t){if("string"==typeof e&&"string"==typeof t)return lodash.trimStart(e,t);if(!(e&&Array.isArray(e)&&e.length&&t&&Array.isArray(t)&&t.length))return e;let r=0;for(const n in e)if(e.hasOwnProperty(n)){if(e[n]!==t[n])break;r++}return e.slice(r)}exports.BUNDLE_ROOT=BUNDLE_ROOT,exports.ERRORS_ROOT=ERRORS_ROOT,exports.KEYS=KEYS,exports.bundleTarget=bundleTarget,exports.decodePointer=decodePointer,exports.decodePointerFragment=decodePointerFragment,exports.decycle=decycle,exports.encodePointer=encodePointer,exports.encodePointerFragment=encodePointerFragment,exports.extractPointerFromRef=extractPointerFromRef,exports.extractSourceFromRef=extractSourceFromRef,exports.getFirstPrimitiveProperty=getFirstPrimitiveProperty,exports.getJsonPathForPosition=getJsonPathForPosition,exports.getLastPathSegment=getLastPathSegment,exports.getLocationForJsonPath=getLocationForJsonPath,exports.hasRef=hasRef,exports.isLocalRef=isLocalRef,exports.isPlainObject=isPlainObject,exports.parseTree=parseTree,exports.parseWithPointers=parseWithPointers,exports.pathToPointer=pathToPointer,exports.pointerToPath=pointerToPath,exports.renameObjectKey=renameObjectKey,exports.reparentBundleTarget=reparentBundleTarget,exports.resolveExternalRef=resolveExternalRef,exports.resolveExternalRefWithLocation=resolveExternalRefWithLocation,exports.resolveInlineRef=resolveInlineRef,exports.resolveInlineRefWithLocation=resolveInlineRefWithLocation,exports.safeParse=safeParse,exports.safeStringify=safeStringify,exports.startsWith=startsWith,exports.stringify=stringify,exports.toPropertyPath=toPropertyPath,exports.trapAccess=trapAccess,exports.traverse=traverse$1,exports.trimStart=trimStart;

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

import{cloneDeep as e,get as r,set as t,has as n,setWith as o,trimStart as i}from"lodash";import{isAbsolute as a,join as s,dirname as c}from"@stoplight/path";import{createScanner as u,findNodeAtOffset as l,getNodePath as f,visit as p,printParseErrorCode as h}from"jsonc-parser";import y,{getOrder as g,ORDER_KEY_ID as d}from"@stoplight/ordered-object-literal";import{DiagnosticSeverity as v}from"@stoplight/types";import b from"safe-stable-stringify";function m(e){if("object"!=typeof e||null===e)return!1;const r=Object.getPrototypeOf(e);return null===r||r===Object.prototype||"function"==typeof e.constructor&&Function.toString.call(Object)===Function.toString.call(e.constructor)}function w(e,r,t){if(!m(e)&&!Array.isArray(e)||!(r in e))throw new ReferenceError(`Could not resolve '${t}'`)}function O(e){if("string"!=typeof e.$ref)throw new TypeError("$ref should be a string")}const j=e=>m(e)&&"$ref"in e,A=e=>j(e)&&"string"==typeof e.$ref,E=e=>e.length>0&&("#"===e||/^#\S*$/.test(e)),$=(e,r,t)=>{const n=e.toString();let o="",i=n,a=0,s=i.indexOf(r);for(;s>-1;)o+=n.substring(a,a+s)+t,i=i.substring(s+r.length,i.length),a+=s+r.length,s=i.indexOf(r);return i.length>0&&(o+=n.substring(n.length-i.length,n.length)),o},S=e=>"number"==typeof e?e:$($(e,"~","~0"),"/","~1"),x=e=>_(e),_=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map(S).join("/")}`};function k(e){try{return decodeURIComponent(e)}catch(r){return e}}const N=/%[0-9a-f]+/gi,P=e=>{let r;try{r=decodeURIComponent(e)}catch(t){r=e.replace(N,k)}return $($(r,"~1","/"),"~0","~")},T=e=>I(e),I=e=>{if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new URIError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new URIError("Invalid JSON Pointer syntax.");return(e=>{const r=e.length,t=[];let n=-1;for(;++n<r;)t.push(P(e[n]));return t})(e.substring(2).split("/"))},R=e=>{if("string"!=typeof e||0===e.length||E(e))return null;const r=e.indexOf("#");return-1===r?e:e.slice(0,r)};function K(e,r){return m(r)&&m(e)&&("summary"in e||"description"in e)?Object.assign(Object.assign(Object.assign({},r),"description"in e?{description:e.description}:null),"summary"in e?{summary:e.summary}:null):r}function*U(e,r,t){j(e.value)&&(O(e.value),yield[-1,e.value]);for(const[n,o]of r.entries())w(e.value,o,t),e.value=e.value[o],j(e.value)&&(O(e.value),yield[n,e.value])}function M(e,r){return C(e,r).value}function C(e,r){return function e(r,t,n,o){if(null!==R(t))throw new ReferenceError("Cannot resolve external references");const i=T(t);let a=[...i];"#"===t&&j(r)&&(O(r),i.unshift(...T(r.$ref)));const s={value:r};for(const[c,u]of U(s,i,t)){if(n.includes(u))return{source:null,location:null!=o?o:a,value:n[n.length-1]};n.push(u);const t=e(r,u.$ref,n,a);s.value=t.value,(a=t.location).push(...i.slice(c+1))}return{source:null,location:a,value:n.length>0?K(n[n.length-1],s.value):s.value}}(e,r,[])}const D=(e,r,t)=>{const n={value:e,path:t};r.onEnter&&r.onEnter(n);for(const n of Object.keys(e)){const o=e[n];r.onProperty&&r.onProperty({parent:e,parentPath:t,property:n,propertyValue:o}),"object"==typeof o&&null!==o&&D(o,r,t.concat(n))}r.onLeave&&r.onLeave(n)},J=(e,r)=>{"object"==typeof e&&null!==e&&D(e,"function"==typeof r?{onProperty:r}:r,[])},V="#/__bundled__",F="#/__errors__",L=({document:r,path:t,bundleRoot:n="#/__bundled__",errorsRoot:o="#/__errors__",cloneDocument:i=!0},a)=>{if(t===n||t===o)throw new Error("Roots do not make any sense");const s=i?e(r):r;return W(s,T(n),T(o))(t,{[t]:!0},a)},W=(e,i,a)=>{const s=new Set,c=(u,l,f,p={},h={},y={})=>{const g=T(u),d=r(e,g);J(f||d,({parent:a})=>{if(A(a)&&E(a.$ref)){const f=a.$ref;if(y[f])return;if(p[f])return void(a.$ref=p[f]);let g,d,v,b,m;try{let t;if(g=T(f),Array.isArray(r(e,g.slice(0,-1)))){t=`${g[g.length-2]}_${g[g.length-1]}`}else t=g[g.length-1];v=t;let n=1;for(;s.has(v);)if(v=`${t}_${++n}`,n>20)throw new Error(`Keys ${t}_2 through ${t}_20 already taken.`);s.add(v),d=[...i,v],b=x(d)}catch(e){y[f]=e instanceof Error?e.message:String(e)}if(!g||!d||!b)return;if("object"==typeof e&&null!==e)try{m=M(Object(e),f)}catch(t){m=r(e,g)}void 0!==m&&(p[f]=b,a.$ref=b,n(h,d)||(Array.isArray(m)?t(h,d,new Array(m.length).fill(null)):"object"==typeof m&&o(h,d,{},Object),t(h,d,m),l[f]||(l[f]=!0,c(u,l,m,p,h,y),l[f]=!1)))}});const v=r(h,i);return v&&Object.keys(v).length&&t(d,i,v),(Object.keys(y).length||n(e,a))&&t(d,a,n(e,a)?r(e,a):y),d};return c},B=e=>$($(e,"~1","/"),"~0","~"),q=(e,r)=>{const t=new WeakMap;return function e(n,o){let i;if(r&&(n=r(n)),m(n)||Array.isArray(n)){const r=t.get(n);return r?{$ref:r}:(t.set(n,x(o)),Array.isArray(n)?i=n.map((r,t)=>e(r,[...o,String(t)])):(i={},Object.keys(n).forEach(r=>{i[r]=e(n[r],[...o,r])})),t.delete(n),i)}return n}(e,[])},z=e=>$($(e,"~","~0"),"//","/~1"),G=e=>{if("string"!=typeof e||0===e.length)return null;const r=e.indexOf("#");return-1===r?null:e.slice(r)},H=e=>{const r=u(e,!0);if(r.scan(),1!==r.getToken())return;if(r.scan(),2===r.getToken())return;if(10!==r.getToken())throw new SyntaxError("Unexpected character");const t=r.getTokenValue();if(r.scan(),6!==r.getToken())throw new SyntaxError("Colon expected");switch(r.scan(),r.getToken()){case 10:return[t,r.getTokenValue()];case 11:return[t,Number(r.getTokenValue())];case 8:return[t,!0];case 9:return[t,!1];case 7:return[t,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},Q=({lineMap:e,ast:r},t)=>{const n=e[t.line],o=e[t.line+1];if(void 0===n)return;const i=l(r,void 0===o?n+t.character:Math.min(o,n+t.character),!0);if(void 0===i)return;const a=f(i);return 0!==a.length?a:void 0};function X(e){return B(e.split("/").pop()||"")}const Y=({ast:e},r,t=!1)=>{const n=function(e,r,t){e:for(const n of r){const r=Number.isInteger(Number(n))?Number(n):n;if("string"==typeof r||"number"==typeof r&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return t?e:void 0;for(const t of e.children)if(Array.isArray(t.children)&&t.children[0].value===String(r)&&2===t.children.length){e=t.children[1];continue e}return t?e:void 0}if("array"!==e.type||r<0||!Array.isArray(e.children)||r>=e.children.length)return t?e:void 0;e=e.children[r]}return e}(e,r,t);if(void 0!==n&&void 0!==n.range)return{range:n.range}};const Z=(e,r={disallowComments:!0})=>{const t=[],{ast:n,data:o,lineMap:i}=ee(e,t,r);return{data:o,diagnostics:t,ast:n,lineMap:i}};function ee(e,r=[],t){const n=te(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,a=[];const s=new WeakMap,c=[];function u(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function l(e,r,t){return{start:{line:e,character:r},end:{line:e,character:r+t}}}function f(e){return o.children.push(e),e}function d(e){Array.isArray(a)?a.push(e):null!==i&&(a[i]=e)}function b(e){d(e),c.push(a),a=e,i=null}function m(){a=c.pop()}p(e,{onObjectBegin:(e,r,n,i)=>{o=f({type:"object",offset:e,length:-1,parent:o,children:[],range:l(n,i,r)}),!1===t.ignoreDuplicateKeys&&s.set(o,[]),b(function(e){return e?y({}):{}}(!0===t.preserveKeyOrder))},onObjectProperty:(e,n,c,u,p)=>{if((o=f({type:"property",offset:n,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:n,length:c,parent:o}),!1===t.ignoreDuplicateKeys){const t=s.get(o.parent);t&&(0!==t.length&&t.includes(e)?r.push({range:l(u,p,c),message:"DuplicateKey",severity:v.Error,path:ne(o),code:20}):t.push(e))}!0===t.preserveKeyOrder&&function(e,r){if(!(r in e))return;const t=g(e),n=t.indexOf(r);-1!==n&&(t.splice(n,1),t.push(r))}(a,e),i=e},onObjectEnd:(e,r,n,i)=>{!1===t.ignoreDuplicateKeys&&s.delete(o),o.length=e+r-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=i+r),o=o.parent,u(e+r),m()},onArrayBegin:(e,r,t,n)=>{o=f({type:"array",offset:e,length:-1,parent:o,children:[],range:l(t,n,r)}),b([])},onArrayEnd:(e,r,t,n)=>{o.length=e+r-o.offset,o.range&&(o.range.end.line=t,o.range.end.character=n+r),o=o.parent,u(e+r),m()},onLiteralValue:(e,r,t,n,i)=>{f({type:re(e),offset:r,length:t,parent:o,value:e,range:l(n,i,t)}),u(r+t),d(e)},onSeparator:(e,r)=>{"property"===o.type&&(":"===e?o.colonOffset=r:","===e&&u(r))},onError:(e,t,n,o,i)=>{r.push({range:l(o,i,n),message:h(e),severity:v.Error,code:e})}},t);const w=o.children[0];return w&&delete w.parent,{ast:w,data:a[0],lineMap:n}}function re(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const te=e=>{const r=[0];let t=0;for(;t<e.length;t++)"\n"===e[t]&&r.push(t+1);return r.push(t+1),r};function ne(e,r=[]){return"property"===e.type&&r.unshift(e.children[0].value),void 0!==e.parent?("array"===e.parent.type&&void 0!==e.parent.parent&&r.unshift(e.parent.children.indexOf(e)),ne(e.parent,r)):r}const oe=(e,r,t)=>{if(!e||!Object.hasOwnProperty.call(e,r)||r===t)return e;const n={};for(const[o,i]of Object.entries(e))o===r?n[t]=i:o in n||(n[o]=i);return n};function ie(e){return m(e)||Array.isArray(e)}function ae(e,r,t){if(t.length<=1||r.length<=1)throw Error("Source/target path must not be empty and point at root");if(0===r.indexOf(t))throw Error("Target path cannot be contained within source");const n=T(r);let o=e;for(const e of n){if(!ie(o))return;o=o[e]}if(!ie(o))return;const i=T(t);let a=e;for(const[e,r]of i.entries()){if(!ie(a)||r in a)return;const t=e===i.length-1?o:{};a[r]=t,a=t}delete e[n[0]],function e(r,t,n){for(const o of Object.keys(r)){const i=r[o];if("$ref"!==o)ie(i)&&e(i,t,n);else{if("string"!=typeof i||!E(i))continue;0===i.indexOf(t)&&(r[o]=i.replace(t,n))}}}(e,r,t)}async function se(e,r,t,n,o){let i=function(e,r){const t=R(r);return null===t?e:a(t)?t:s(c(e),t)}(r,t);const u=G(t)||"#",l=await e[i],f=T(u);let p=[...f];const h={value:l};for(const[t,a]of U(h,f,u)){if(n.includes(a))return{source:r,location:null!=o?o:p,value:n[n.length-1]};n.push(a);const s=await se(e,i,a.$ref,n,p);({source:i,location:p}=s),h.value=s.value,p.push(...f.slice(t+1))}return{source:i,location:p,value:n.length>0?K(n[n.length-1],h.value):h.value}}async function ce(e,r,t){return(await ue(e,r,t)).value}function ue(e,r,t){return se(e,r,t,[])}const le=(e,r)=>{if("string"!=typeof e)return e;try{const t=fe(e);return"string"==typeof t?t:JSON.parse(e,r)}catch(e){return}},fe=e=>{const r=Number(e);return Number.isFinite(r)?String(r)===e?r:e:NaN},pe=(e,r,t)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,r,t)}catch(n){return b(e,r,t)}},he=(e,r)=>{if(e instanceof Array){if(r instanceof Array){if(r.length>e.length)return!1;for(const t in r){if(!r.hasOwnProperty(t))continue;const n=parseInt(e[t]),o=parseInt(r[t]);if(isNaN(n)&&isNaN(o)){if(e[t]!==r[t])return!1}else if(n!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof r)return e.startsWith(r)}return!0},ye=(e,r,t)=>{const n=pe(e,r,t);if(void 0===n)throw new Error("The value could not be stringified");return n};function ge(e){return e.replace(/^(\/|#\/)/,"").split("/").map(B).map(de).join(".")}function de(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const ve=Symbol.for(d),be={ownKeys:e=>ve in e?e[ve]:Reflect.ownKeys(e)},me=e=>new Proxy(e,be);function we(e,r){if("string"==typeof e&&"string"==typeof r)return i(e,r);if(!(e&&Array.isArray(e)&&e.length&&r&&Array.isArray(r)&&r.length))return e;let t=0;for(const n in e)if(e.hasOwnProperty(n)){if(e[n]!==r[n])break;t++}return e.slice(t)}export{V as BUNDLE_ROOT,F as ERRORS_ROOT,ve as KEYS,L as bundleTarget,P as decodePointer,B as decodePointerFragment,q as decycle,z as encodePointer,S as encodePointerFragment,G as extractPointerFromRef,R as extractSourceFromRef,H as getFirstPrimitiveProperty,Q as getJsonPathForPosition,X as getLastPathSegment,Y as getLocationForJsonPath,A as hasRef,E as isLocalRef,m as isPlainObject,ee as parseTree,Z as parseWithPointers,x as pathToPointer,T as pointerToPath,oe as renameObjectKey,ae as reparentBundleTarget,ce as resolveExternalRef,ue as resolveExternalRefWithLocation,M as resolveInlineRef,C as resolveInlineRefWithLocation,le as safeParse,pe as safeStringify,he as startsWith,ye as stringify,ge as toPropertyPath,me as trapAccess,J as traverse,we as trimStart};
import{cloneDeep as e,get as t,set as r,has as n,setWith as o,trimStart as i}from"lodash";import{isAbsolute as a,join as s,dirname as c}from"@stoplight/path";import{createScanner as u,findNodeAtOffset as l,getNodePath as f,visit as p,printParseErrorCode as h}from"jsonc-parser";import y,{getOrder as g,ORDER_KEY_ID as d}from"@stoplight/ordered-object-literal";import{DiagnosticSeverity as v}from"@stoplight/types";import m from"safe-stable-stringify";function b(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype||"function"==typeof e.constructor&&Function.toString.call(Object)===Function.toString.call(e.constructor)}function w(e,t,r){if(!b(e)&&!Array.isArray(e)||!(t in e))throw new ReferenceError(`Could not resolve '${r}'`)}function O(e){if("string"!=typeof e.$ref)throw new TypeError("$ref should be a string")}const j=e=>b(e)&&"$ref"in e,A=e=>j(e)&&"string"==typeof e.$ref,E=e=>e.length>0&&("#"===e||/^#\S*$/.test(e)),S=(e,t,r)=>{const n=e.toString();let o="",i=n,a=0,s=i.indexOf(t);for(;s>-1;)o+=n.substring(a,a+s)+r,i=i.substring(s+t.length,i.length),a+=s+t.length,s=i.indexOf(t);return i.length>0&&(o+=n.substring(n.length-i.length,n.length)),o},$=e=>"number"==typeof e?e:S(S(e,"~","~0"),"/","~1"),x=e=>_(e),_=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map($).join("/")}`};function k(e){try{return decodeURIComponent(e)}catch(t){return e}}const N=/%[0-9a-f]+/gi,P=e=>{let t;try{t=decodeURIComponent(e)}catch(r){t=e.replace(N,k)}return S(S(t,"~1","/"),"~0","~")},T=e=>I(e),I=e=>{if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new URIError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new URIError("Invalid JSON Pointer syntax.");return(e=>{const t=e.length,r=[];let n=-1;for(;++n<t;)r.push(P(e[n]));return r})(e.substring(2).split("/"))},R=e=>{if("string"!=typeof e||0===e.length||E(e))return null;const t=e.indexOf("#");return-1===t?e:e.slice(0,t)};function K(e,t){return b(t)&&b(e)&&("summary"in e||"description"in e)?Object.assign(Object.assign(Object.assign({},t),"description"in e?{description:e.description}:null),"summary"in e?{summary:e.summary}:null):t}function*U(e,t,r){j(e.value)&&(O(e.value),yield[-1,e.value]);for(const[n,o]of t.entries())w(e.value,o,r),e.value=e.value[o],j(e.value)&&(O(e.value),yield[n,e.value])}function M(e,t){return C(e,t).value}function C(e,t){return function e(t,r,n,o){if(null!==R(r))throw new ReferenceError("Cannot resolve external references");const i=T(r);let a=[...i];"#"===r&&j(t)&&(O(t),i.unshift(...T(t.$ref)));const s={value:t};for(const[c,u]of U(s,i,r)){if(n.includes(u))return{source:null,location:null!=o?o:a,value:n[n.length-1]};n.push(u);const r=e(t,u.$ref,n,a);s.value=r.value,(a=r.location).push(...i.slice(c+1))}return{source:null,location:a,value:n.length>0?K(n[n.length-1],s.value):s.value}}(e,t,[])}const D=(e,t,r)=>{const n={value:e,path:r};t.onEnter&&t.onEnter(n);for(const n of Object.keys(e)){const o=e[n];t.onProperty&&t.onProperty({parent:e,parentPath:r,property:n,propertyValue:o}),"object"==typeof o&&null!==o&&D(o,t,r.concat(n))}t.onLeave&&t.onLeave(n)},J=(e,t)=>{"object"==typeof e&&null!==e&&D(e,"function"==typeof t?{onProperty:t}:t,[])},V="#/__bundled__",F="#/__errors__",L=({document:t,path:r,bundleRoot:n="#/__bundled__",errorsRoot:o="#/__errors__",cloneDocument:i=!0,keyProvider:a},s)=>{if(r===n||r===o)throw new Error("Roots do not make any sense");const c=i?e(t):t;return W(c,T(n),T(o),a)(r,{[r]:!0},s)},W=(e,i,a,s)=>{const c=new Set,u=(l,f,p,h={},y={},g={})=>{const d=T(l),v=t(e,d);J(p||v,({parent:a})=>{if(A(a)&&E(a.$ref)){const p=a.$ref;if(g[p])return;if(h[p])return void(a.$ref=h[p]);let d,v,m,b,w;try{let r;d=T(p),s&&(r=s({document:e,path:d})),r||(r=(({document:e,path:r})=>{if(Array.isArray(t(e,r.slice(0,-1))))return`${r[r.length-2]}_${r[r.length-1]}`;return String(r[r.length-1])})({document:e,path:d})),m=r;let n=1;for(;c.has(m);)if(m=`${r}_${++n}`,n>20)throw new Error(`Keys ${r}_2 through ${r}_20 already taken.`);c.add(m),v=[...i,m],b=x(v)}catch(e){g[p]=e instanceof Error?e.message:String(e)}if(!d||!v||!b)return;if("object"==typeof e&&null!==e)try{w=M(Object(e),p)}catch(r){w=t(e,d)}void 0!==w&&(h[p]=b,a.$ref=b,n(y,v)||(Array.isArray(w)?r(y,v,new Array(w.length).fill(null)):"object"==typeof w&&o(y,v,{},Object),r(y,v,w),f[p]||(f[p]=!0,u(l,f,w,h,y,g),f[p]=!1)))}});const m=t(y,i);return m&&Object.keys(m).length&&r(v,i,m),(Object.keys(g).length||n(e,a))&&r(v,a,n(e,a)?t(e,a):g),v};return u},B=e=>S(S(e,"~1","/"),"~0","~"),q=(e,t)=>{const r=new WeakMap;return function e(n,o){let i;if(t&&(n=t(n)),b(n)||Array.isArray(n)){const t=r.get(n);return t?{$ref:t}:(r.set(n,x(o)),Array.isArray(n)?i=n.map((t,r)=>e(t,[...o,String(r)])):(i={},Object.keys(n).forEach(t=>{i[t]=e(n[t],[...o,t])})),r.delete(n),i)}return n}(e,[])},z=e=>S(S(e,"~","~0"),"//","/~1"),G=e=>{if("string"!=typeof e||0===e.length)return null;const t=e.indexOf("#");return-1===t?null:e.slice(t)},H=e=>{const t=u(e,!0);if(t.scan(),1!==t.getToken())return;if(t.scan(),2===t.getToken())return;if(10!==t.getToken())throw new SyntaxError("Unexpected character");const r=t.getTokenValue();if(t.scan(),6!==t.getToken())throw new SyntaxError("Colon expected");switch(t.scan(),t.getToken()){case 10:return[r,t.getTokenValue()];case 11:return[r,Number(t.getTokenValue())];case 8:return[r,!0];case 9:return[r,!1];case 7:return[r,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},Q=({lineMap:e,ast:t},r)=>{const n=e[r.line],o=e[r.line+1];if(void 0===n)return;const i=l(t,void 0===o?n+r.character:Math.min(o,n+r.character),!0);if(void 0===i)return;const a=f(i);return 0!==a.length?a:void 0};function X(e){return B(e.split("/").pop()||"")}const Y=({ast:e},t,r=!1)=>{const n=function(e,t,r){e:for(const n of t){const t=Number.isInteger(Number(n))?Number(n):n;if("string"==typeof t||"number"==typeof t&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return r?e:void 0;for(const r of e.children)if(Array.isArray(r.children)&&r.children[0].value===String(t)&&2===r.children.length){e=r.children[1];continue e}return r?e:void 0}if("array"!==e.type||t<0||!Array.isArray(e.children)||t>=e.children.length)return r?e:void 0;e=e.children[t]}return e}(e,t,r);if(void 0!==n&&void 0!==n.range)return{range:n.range}};const Z=(e,t={disallowComments:!0})=>{const r=[],{ast:n,data:o,lineMap:i}=ee(e,r,t);return{data:o,diagnostics:r,ast:n,lineMap:i}};function ee(e,t=[],r){const n=re(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,a=[];const s=new WeakMap,c=[];function u(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function l(e,t,r){return{start:{line:e,character:t},end:{line:e,character:t+r}}}function f(e){return o.children.push(e),e}function d(e){Array.isArray(a)?a.push(e):null!==i&&(a[i]=e)}function m(e){d(e),c.push(a),a=e,i=null}function b(){a=c.pop()}p(e,{onObjectBegin:(e,t,n,i)=>{o=f({type:"object",offset:e,length:-1,parent:o,children:[],range:l(n,i,t)}),!1===r.ignoreDuplicateKeys&&s.set(o,[]),m(function(e){return e?y({}):{}}(!0===r.preserveKeyOrder))},onObjectProperty:(e,n,c,u,p)=>{if((o=f({type:"property",offset:n,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:n,length:c,parent:o}),!1===r.ignoreDuplicateKeys){const r=s.get(o.parent);r&&(0!==r.length&&r.includes(e)?t.push({range:l(u,p,c),message:"DuplicateKey",severity:v.Error,path:ne(o),code:20}):r.push(e))}!0===r.preserveKeyOrder&&function(e,t){if(!(t in e))return;const r=g(e),n=r.indexOf(t);-1!==n&&(r.splice(n,1),r.push(t))}(a,e),i=e},onObjectEnd:(e,t,n,i)=>{!1===r.ignoreDuplicateKeys&&s.delete(o),o.length=e+t-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=i+t),o=o.parent,u(e+t),b()},onArrayBegin:(e,t,r,n)=>{o=f({type:"array",offset:e,length:-1,parent:o,children:[],range:l(r,n,t)}),m([])},onArrayEnd:(e,t,r,n)=>{o.length=e+t-o.offset,o.range&&(o.range.end.line=r,o.range.end.character=n+t),o=o.parent,u(e+t),b()},onLiteralValue:(e,t,r,n,i)=>{f({type:te(e),offset:t,length:r,parent:o,value:e,range:l(n,i,r)}),u(t+r),d(e)},onSeparator:(e,t)=>{"property"===o.type&&(":"===e?o.colonOffset=t:","===e&&u(t))},onError:(e,r,n,o,i)=>{t.push({range:l(o,i,n),message:h(e),severity:v.Error,code:e})}},r);const w=o.children[0];return w&&delete w.parent,{ast:w,data:a[0],lineMap:n}}function te(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const re=e=>{const t=[0];let r=0;for(;r<e.length;r++)"\n"===e[r]&&t.push(r+1);return t.push(r+1),t};function ne(e,t=[]){return"property"===e.type&&t.unshift(e.children[0].value),void 0!==e.parent?("array"===e.parent.type&&void 0!==e.parent.parent&&t.unshift(e.parent.children.indexOf(e)),ne(e.parent,t)):t}const oe=(e,t,r)=>{if(!e||!Object.hasOwnProperty.call(e,t)||t===r)return e;const n={};for(const[o,i]of Object.entries(e))o===t?n[r]=i:o in n||(n[o]=i);return n};function ie(e){return b(e)||Array.isArray(e)}function ae(e,t,r){if(r.length<=1||t.length<=1)throw Error("Source/target path must not be empty and point at root");if(0===t.indexOf(r))throw Error("Target path cannot be contained within source");const n=T(t);let o=e;for(const e of n){if(!ie(o))return;o=o[e]}if(!ie(o))return;const i=T(r);let a=e;for(const[e,t]of i.entries()){if(!ie(a)||t in a)return;const r=e===i.length-1?o:{};a[t]=r,a=r}delete e[n[0]],function e(t,r,n){for(const o of Object.keys(t)){const i=t[o];if("$ref"!==o)ie(i)&&e(i,r,n);else{if("string"!=typeof i||!E(i))continue;0===i.indexOf(r)&&(t[o]=i.replace(r,n))}}}(e,t,r)}async function se(e,t,r,n,o){let i=function(e,t){const r=R(t);return null===r?e:a(r)?r:s(c(e),r)}(t,r);const u=G(r)||"#",l=await e[i],f=T(u);let p=[...f];const h={value:l};for(const[r,a]of U(h,f,u)){if(n.includes(a))return{source:t,location:null!=o?o:p,value:n[n.length-1]};n.push(a);const s=await se(e,i,a.$ref,n,p);({source:i,location:p}=s),h.value=s.value,p.push(...f.slice(r+1))}return{source:i,location:p,value:n.length>0?K(n[n.length-1],h.value):h.value}}async function ce(e,t,r){return(await ue(e,t,r)).value}function ue(e,t,r){return se(e,t,r,[])}const le=(e,t)=>{if("string"!=typeof e)return e;try{const r=fe(e);return"string"==typeof r?r:JSON.parse(e,t)}catch(e){return}},fe=e=>{const t=Number(e);return Number.isFinite(t)?String(t)===e?t:e:NaN},pe=(e,t,r)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,t,r)}catch(n){return m(e,t,r)}},he=(e,t)=>{if(e instanceof Array){if(t instanceof Array){if(t.length>e.length)return!1;for(const r in t){if(!t.hasOwnProperty(r))continue;const n=parseInt(e[r]),o=parseInt(t[r]);if(isNaN(n)&&isNaN(o)){if(e[r]!==t[r])return!1}else if(n!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof t)return e.startsWith(t)}return!0},ye=(e,t,r)=>{const n=pe(e,t,r);if(void 0===n)throw new Error("The value could not be stringified");return n};function ge(e){return e.replace(/^(\/|#\/)/,"").split("/").map(B).map(de).join(".")}function de(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const ve=Symbol.for(d),me={ownKeys:e=>ve in e?e[ve]:Reflect.ownKeys(e)},be=e=>new Proxy(e,me);function we(e,t){if("string"==typeof e&&"string"==typeof t)return i(e,t);if(!(e&&Array.isArray(e)&&e.length&&t&&Array.isArray(t)&&t.length))return e;let r=0;for(const n in e)if(e.hasOwnProperty(n)){if(e[n]!==t[n])break;r++}return e.slice(r)}export{V as BUNDLE_ROOT,F as ERRORS_ROOT,ve as KEYS,L as bundleTarget,P as decodePointer,B as decodePointerFragment,q as decycle,z as encodePointer,$ as encodePointerFragment,G as extractPointerFromRef,R as extractSourceFromRef,H as getFirstPrimitiveProperty,Q as getJsonPathForPosition,X as getLastPathSegment,Y as getLocationForJsonPath,A as hasRef,E as isLocalRef,b as isPlainObject,ee as parseTree,Z as parseWithPointers,x as pathToPointer,T as pointerToPath,oe as renameObjectKey,ae as reparentBundleTarget,ce as resolveExternalRef,ue as resolveExternalRefWithLocation,M as resolveInlineRef,C as resolveInlineRefWithLocation,le as safeParse,pe as safeStringify,he as startsWith,ye as stringify,ge as toPropertyPath,be as trapAccess,J as traverse,we as trimStart};
{
"name": "@stoplight/json",
"version": "3.19.0",
"version": "3.20.0",
"description": "Useful functions when working with JSON.",

@@ -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