Socket
Socket
Sign inDemoInstall

@stoplight/json

Package Overview
Dependencies
Maintainers
22
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.10.3 to 3.11.0

8

bundle.d.ts

@@ -1,6 +0,8 @@

export declare const BUNDLE_ROOT = "__bundled__";
export declare const ERRORS_ROOT = "__errors__";
export declare const bundleTarget: <T = unknown>({ document, path }: {
export declare const BUNDLE_ROOT = "#/__bundled__";
export declare const ERRORS_ROOT = "#/__errors__";
export declare const bundleTarget: <T = unknown>({ document, path, bundleRoot, errorsRoot, }: {
document: T;
path: string;
bundleRoot?: string | undefined;
errorsRoot?: string | undefined;
}, cur?: unknown) => any;

@@ -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"),jsoncParser=require("jsonc-parser"),createOrderedObject=require("@stoplight/ordered-object-literal"),createOrderedObject__default=_interopDefault(createOrderedObject),types=require("@stoplight/types"),fastStringify=_interopDefault(require("safe-stable-stringify"));const hasRef=e=>lodash.isObject(e)&&"$ref"in e&&"string"==typeof e.$ref,isLocalRef=e=>e.length>0&&"#"===e[0],replaceInString=(e,r,t)=>{const n=e.toString();let o="",i=n,s=0,a=i.indexOf(r);for(;a>-1;)o+=n.substring(s,s+a)+t,i=i.substring(a+r.length,i.length),s+=a+r.length,a=i.indexOf(r);return i.length>0&&(o+=n.substring(n.length-i.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("/")}`},decodePointer=e=>replaceInString(replaceInString(decodeURIComponent(""+e),"~1","/"),"~0","~"),pointerToPath=e=>decodeUriFragmentIdentifier(e),decodeFragmentSegments=e=>{const r=e.length,t=[];let n=-1;for(;++n<r;)t.push(decodePointer(e[n]));return t},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("/"))},traverse=(e,r,t=[])=>{if(e&&"object"==typeof e)for(const n in e)e.hasOwnProperty(n)&&(r({parent:e,parentPath:t,property:n,propertyValue:e[n]}),e[n]&&"object"==typeof e[n]&&traverse(e[n],r,t.concat(n)))},BUNDLE_ROOT="__bundled__",ERRORS_ROOT="__errors__",bundleTarget=({document:e,path:r},t)=>_bundle(lodash.cloneDeep(e),r,{[r]:!0},t),_bundle=(e,r,t,n,o={},i={},s={})=>{const a=lodash.get(e,pointerToPath(r));return traverse(n||a,({parent:n})=>{if(hasRef(n)&&isLocalRef(n.$ref)){const a=n.$ref;if(s[a])return;if(o[a])return void(n.$ref=o[a]);let c,f,p;try{c=pointerToPath(a),f=[BUNDLE_ROOT,...c],p=pathToPointer(f)}catch(e){s[a]=e.message}if(!c||!f||!p)return;const l=lodash.get(e,c);if(void 0!==l){const u=[];o[a]=p,n.$ref=p;for(const r of c){u.push(r);const t=[BUNDLE_ROOT,...u];if(lodash.has(i,t))continue;const n=lodash.get(e,u);Array.isArray(n)?lodash.set(i,t,new Array(n.length).fill(null)):"object"==typeof n&&lodash.set(i,t,{})}lodash.set(i,f,l),t[a]||(t[a]=!0,_bundle(e,r,t,l,o,i,s),t[a]=!1)}}}),lodash.set(a,BUNDLE_ROOT,i.__bundled__),Object.keys(s).length&&lodash.set(a,ERRORS_ROOT,s),a},decodePointerFragment=e=>replaceInString(replaceInString(e,"~1","/"),"~0","~"),encodePointer=e=>replaceInString(replaceInString(e,"~","~0"),"//","/~1"),extractPointerFromRef=e=>{if("string"!=typeof e||0===e.length)return null;const r=e.indexOf("#");return-1===r?null:e.slice(r)},extractSourceFromRef=e=>{if("string"!=typeof e||0===e.length||isLocalRef(e))return null;const r=e.indexOf("#");return-1===r?e:e.slice(0,r)},getFirstPrimitiveProperty=e=>{const r=jsoncParser.createScanner(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}},getJsonPathForPosition=({lineMap:e,ast:r},t)=>{const n=e[t.line],o=e[t.line+1];if(void 0===n)return;const i=jsoncParser.findNodeAtOffset(r,void 0===o?n+t.character:Math.min(o,n+t.character),!0);if(void 0===i)return;const s=jsoncParser.getNodePath(i);return 0!==s.length?s:void 0};function getLastPathSegment(e){return decodePointerFragment(e.split("/").pop()||"")}const getLocationForJsonPath=({lineMap:e,ast:r},t,n=!1)=>{const o=findNodeAtPath(r,t,n);if(void 0!==o&&void 0!==o.range)return{range:o.range}};function findNodeAtPath(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}const parseWithPointers=(e,r={disallowComments:!0})=>{const t=[],{ast:n,data:o,lineMap:i}=parseTree(e,t,r);return{data:o,diagnostics:t,ast:n,lineMap:i}};function parseTree(e,r=[],t){const n=computeLineMap(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,s=[];const a=new WeakMap,c=[];function f(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function p(e,r,t){return{start:{line:e,character:r},end:{line:e,character:r+t}}}function l(e){return o.children.push(e),e}function u(e){Array.isArray(s)?s.push(e):null!==i&&(s[i]=e)}function d(e){u(e),c.push(s),s=e,i=null}function g(){s=c.pop()}const h={onObjectBegin:(e,r,n,i)=>{o=l({type:"object",offset:e,length:-1,parent:o,children:[],range:p(n,i,r)}),!1===t.ignoreDuplicateKeys&&a.set(o,[]),d(createObjectLiteral(!0===t.preserveKeyOrder))},onObjectProperty:(e,n,c,f,u)=>{if((o=l({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=a.get(o.parent);t&&(0!==t.length&&t.includes(e)?r.push({range:p(f,u,c),message:"DuplicateKey",severity:types.DiagnosticSeverity.Error,path:getJsonPath(o),code:20}):t.push(e))}!0===t.preserveKeyOrder&&swapKey(s,e),i=e},onObjectEnd:(e,r,n,i)=>{!1===t.ignoreDuplicateKeys&&a.delete(o),o.length=e+r-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=i+r),o=o.parent,f(e+r),g()},onArrayBegin:(e,r,t,n)=>{o=l({type:"array",offset:e,length:-1,parent:o,children:[],range:p(t,n,r)}),d([])},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,f(e+r),g()},onLiteralValue:(e,r,t,n,i)=>{l({type:getLiteralNodeType(e),offset:r,length:t,parent:o,value:e,range:p(n,i,t)}),f(r+t),u(e)},onSeparator:(e,r,t)=>{"property"===o.type&&(":"===e?o.colonOffset=r:","===e&&f(r))},onError:(e,t,n,o,i)=>{r.push({range:p(o,i,n),message:jsoncParser.printParseErrorCode(e),severity:types.DiagnosticSeverity.Error,code:e})}};jsoncParser.visit(e,h,t);const y=o.children[0];return y&&delete y.parent,{ast:y,data:s[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 r=[0];let t=0;for(;t<e.length;t++)"\n"===e[t]&&r.push(t+1);return r.push(t+1),r};function getJsonPath(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)),getJsonPath(e.parent,r)):r}function createObjectLiteral(e){return e?createOrderedObject__default({}):{}}function swapKey(e,r){if(!(r in e))return;const t=createOrderedObject.getOrder(e),n=t.indexOf(r);-1!==n&&(t.splice(n,1),t.push(r))}const renameObjectKey=(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 isObject(e){return"object"==typeof e&&null!==e}function _resolveInlineRef(e,r,t){if(null!==extractSourceFromRef(r))throw new ReferenceError("Cannot resolve external references");const n=pointerToPath(r);let o=e;for(const i of n){if(!(isObject(o)&&i in o))throw new ReferenceError(`Could not resolve '${r}'`);if(isObject(o=o[i])&&"$ref"in o){if(t.includes(o))return t[t.length-1];if(t.push(o),"string"!=typeof o.$ref)throw new TypeError("$ref should be a string");o=_resolveInlineRef(e,o.$ref,t)}}return o}function resolveInlineRef(e,r){return _resolveInlineRef(e,r,[])}const safeParse=(e,r)=>{if("string"!=typeof e)return e;try{const t=parseNumber(e);return"string"==typeof t?t:JSON.parse(e,r)}catch(e){return}},parseNumber=e=>{const r=Number(e);return Number.isFinite(r)?String(r)===e?r:e:NaN},safeStringify=(e,r,t)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,r,t)}catch(n){return fastStringify(e,r,t)}},startsWith=(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},stringify=(e,r,t)=>{const n=safeStringify(e,r,t);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,r){if("string"==typeof e&&"string"==typeof r)return lodash.trimStart(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)}exports.BUNDLE_ROOT=BUNDLE_ROOT,exports.ERRORS_ROOT=ERRORS_ROOT,exports.KEYS=KEYS,exports.bundleTarget=bundleTarget,exports.decodePointer=decodePointer,exports.decodePointerFragment=decodePointerFragment,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.parseTree=parseTree,exports.parseWithPointers=parseWithPointers,exports.pathToPointer=pathToPointer,exports.pointerToPath=pointerToPath,exports.renameObjectKey=renameObjectKey,exports.resolveInlineRef=resolveInlineRef,exports.safeParse=safeParse,exports.safeStringify=safeStringify,exports.startsWith=startsWith,exports.stringify=stringify,exports.toPropertyPath=toPropertyPath,exports.trapAccess=trapAccess,exports.traverse=traverse,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"),jsoncParser=require("jsonc-parser"),createOrderedObject=require("@stoplight/ordered-object-literal"),createOrderedObject__default=_interopDefault(createOrderedObject),types=require("@stoplight/types"),fastStringify=_interopDefault(require("safe-stable-stringify"));const hasRef=e=>lodash.isObject(e)&&"$ref"in e&&"string"==typeof e.$ref,isLocalRef=e=>e.length>0&&"#"===e[0],replaceInString=(e,t,r)=>{const n=e.toString();let o="",s=n,i=0,a=s.indexOf(t);for(;a>-1;)o+=n.substring(i,i+a)+r,s=s.substring(a+t.length,s.length),i+=a+t.length,a=s.indexOf(t);return s.length>0&&(o+=n.substring(n.length-s.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("/")}`},decodePointer=e=>replaceInString(replaceInString(decodeURIComponent(""+e),"~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("/"))},traverse=(e,t,r=[])=>{if(e&&"object"==typeof e)for(const n in e)e.hasOwnProperty(n)&&(t({parent:e,parentPath:r,property:n,propertyValue:e[n]}),e[n]&&"object"==typeof e[n]&&traverse(e[n],t,r.concat(n)))},BUNDLE_ROOT="#/__bundled__",ERRORS_ROOT="#/__errors__",bundleTarget=({document:e,path:t,bundleRoot:r=BUNDLE_ROOT,errorsRoot:n=ERRORS_ROOT},o)=>{if(`${t}/`.startsWith(`${r}/`)||`${t}/`.startsWith(`${n}/`))throw new Error("Roots do not make any sense");return bundle(lodash.cloneDeep(e),r,n)(t,{[t]:!0},o)},bundle=(e,t,r)=>{const n=pointerToPath(t),o=pointerToPath(r),s=lodash.get(e,n),i=new Set("object"==typeof s&&null!==s?[...Object.keys(s)]:[]),a=(r,c,l,f={},p={},u={})=>{const h=pointerToPath(r),d=lodash.get(e,h);traverse(l||d,({parent:o})=>{if(hasRef(o)&&isLocalRef(o.$ref)){const s=o.$ref;if(u[s])return;if(f[s])return void(o.$ref=f[s]);let l,h,d,g;try{let r;if(l=pointerToPath(s),Array.isArray(lodash.get(e,l.slice(0,-1)))){r=`${l[l.length-2]}_${l[l.length-1]}`}else r=l[l.length-1];if(d=r,!s.startsWith(t)){let e=1;for(;i.has(d);)if(d=`${r}_${++e}`,e>20)throw new Error(`Keys ${r}_2 through ${r}_20 already taken.`);i.add(d)}h=[...n,d],g=pathToPointer(h)}catch(e){u[s]=e.message}if(!l||!h||!g)return;const y=lodash.get(e,l);if(void 0!==y&&(f[s]=g,o.$ref=g,!lodash.has(p,h))){const t=lodash.get(e,l);Array.isArray(t)?lodash.set(p,h,new Array(t.length).fill(null)):"object"==typeof t&&lodash.set(p,h,{}),lodash.set(p,h,y),c[s]||(c[s]=!0,a(r,c,y,f,p,u),c[s]=!1)}}});const g=Object.assign(Object.assign({},s),lodash.get(p,n));return Object.keys(g).length&&lodash.set(d,n,g),(Object.keys(u).length||lodash.has(e,o))&&lodash.set(d,o,lodash.has(e,o)?lodash.get(e,o):u),d};return a},decodePointerFragment=e=>replaceInString(replaceInString(e,"~1","/"),"~0","~"),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)},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)},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 s=jsoncParser.findNodeAtOffset(t,void 0===o?n+r.character:Math.min(o,n+r.character),!0);if(void 0===s)return;const i=jsoncParser.getNodePath(s);return 0!==i.length?i:void 0};function getLastPathSegment(e){return decodePointerFragment(e.split("/").pop()||"")}const getLocationForJsonPath=({lineMap:e,ast:t},r,n=!1)=>{const o=findNodeAtPath(t,r,n);if(void 0!==o&&void 0!==o.range)return{range:o.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:s}=parseTree(e,r,t);return{data:o,diagnostics:r,ast:n,lineMap:s}};function parseTree(e,t=[],r){const n=computeLineMap(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},s=null,i=[];const a=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 p(e){return o.children.push(e),e}function u(e){Array.isArray(i)?i.push(e):null!==s&&(i[s]=e)}function h(e){u(e),c.push(i),i=e,s=null}function d(){i=c.pop()}const g={onObjectBegin:(e,t,n,s)=>{o=p({type:"object",offset:e,length:-1,parent:o,children:[],range:f(n,s,t)}),!1===r.ignoreDuplicateKeys&&a.set(o,[]),h(createObjectLiteral(!0===r.preserveKeyOrder))},onObjectProperty:(e,n,c,l,u)=>{if((o=p({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=a.get(o.parent);r&&(0!==r.length&&r.includes(e)?t.push({range:f(l,u,c),message:"DuplicateKey",severity:types.DiagnosticSeverity.Error,path:getJsonPath(o),code:20}):r.push(e))}!0===r.preserveKeyOrder&&swapKey(i,e),s=e},onObjectEnd:(e,t,n,s)=>{!1===r.ignoreDuplicateKeys&&a.delete(o),o.length=e+t-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=s+t),o=o.parent,l(e+t),d()},onArrayBegin:(e,t,r,n)=>{o=p({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,s)=>{p({type:getLiteralNodeType(e),offset:t,length:r,parent:o,value:e,range:f(n,s,r)}),l(t+r),u(e)},onSeparator:(e,t,r)=>{"property"===o.type&&(":"===e?o.colonOffset=t:","===e&&l(t))},onError:(e,r,n,o,s)=>{t.push({range:f(o,s,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,s]of Object.entries(e))o===t?n[r]=s:o in n||(n[o]=s);return n};function isObject(e){return"object"==typeof e&&null!==e}function _resolveInlineRef(e,t,r){if(null!==extractSourceFromRef(t))throw new ReferenceError("Cannot resolve external references");const n=pointerToPath(t);let o=e;for(const s of n){if(!(isObject(o)&&s in o))throw new ReferenceError(`Could not resolve '${t}'`);if(isObject(o=o[s])&&"$ref"in o){if(r.includes(o))return r[r.length-1];if(r.push(o),"string"!=typeof o.$ref)throw new TypeError("$ref should be a string");o=_resolveInlineRef(e,o.$ref,r)}}return o}function resolveInlineRef(e,t){return _resolveInlineRef(e,t,[])}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.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.parseTree=parseTree,exports.parseWithPointers=parseWithPointers,exports.pathToPointer=pathToPointer,exports.pointerToPath=pointerToPath,exports.renameObjectKey=renameObjectKey,exports.resolveInlineRef=resolveInlineRef,exports.safeParse=safeParse,exports.safeStringify=safeStringify,exports.startsWith=startsWith,exports.stringify=stringify,exports.toPropertyPath=toPropertyPath,exports.trapAccess=trapAccess,exports.traverse=traverse,exports.trimStart=trimStart;

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

import{isObject as e,cloneDeep as r,get as n,has as t,set as o,trimStart as i}from"lodash";import{createScanner as s,findNodeAtOffset as a,getNodePath as c,visit as f,printParseErrorCode as l}from"jsonc-parser";import u,{getOrder as p,ORDER_KEY_ID as h}from"@stoplight/ordered-object-literal";import{DiagnosticSeverity as g}from"@stoplight/types";import y from"safe-stable-stringify";const d=r=>e(r)&&"$ref"in r&&"string"==typeof r.$ref,b=e=>e.length>0&&"#"===e[0],m=(e,r,n)=>{const t=e.toString();let o="",i=t,s=0,a=i.indexOf(r);for(;a>-1;)o+=t.substring(s,s+a)+n,i=i.substring(a+r.length,i.length),s+=a+r.length,a=i.indexOf(r);return i.length>0&&(o+=t.substring(t.length-i.length,t.length)),o},w=e=>"number"==typeof e?e:m(m(e,"~","~0"),"/","~1"),v=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(w).join("/")}`},O=e=>m(m(decodeURIComponent(""+e),"~1","/"),"~0","~"),x=e=>A(e),A=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,n=[];let t=-1;for(;++t<r;)n.push(O(e[t]));return n})(e.substring(2).split("/"))},j=(e,r,n=[])=>{if(e&&"object"==typeof e)for(const t in e)e.hasOwnProperty(t)&&(r({parent:e,parentPath:n,property:t,propertyValue:e[t]}),e[t]&&"object"==typeof e[t]&&j(e[t],r,n.concat(t)))},E="__bundled__",N="__errors__",S=({document:e,path:n},t)=>$(r(e),n,{[n]:!0},t),$=(e,r,i,s,a={},c={},f={})=>{const l=n(e,x(r));return j(s||l,({parent:s})=>{if(d(s)&&b(s.$ref)){const l=s.$ref;if(f[l])return;if(a[l])return void(s.$ref=a[l]);let u,p,h;try{u=x(l),p=["__bundled__",...u],h=v(p)}catch(e){f[l]=e.message}if(!u||!p||!h)return;const g=n(e,u);if(void 0!==g){const y=[];a[l]=h,s.$ref=h;for(const r of u){y.push(r);const i=["__bundled__",...y];if(t(c,i))continue;const s=n(e,y);Array.isArray(s)?o(c,i,new Array(s.length).fill(null)):"object"==typeof s&&o(c,i,{})}o(c,p,g),i[l]||(i[l]=!0,$(e,r,i,g,a,c,f),i[l]=!1)}}}),o(l,"__bundled__",c.__bundled__),Object.keys(f).length&&o(l,"__errors__",f),l},T=e=>m(m(e,"~1","/"),"~0","~"),k=e=>m(m(e,"~","~0"),"//","/~1"),I=e=>{if("string"!=typeof e||0===e.length)return null;const r=e.indexOf("#");return-1===r?null:e.slice(r)},P=e=>{if("string"!=typeof e||0===e.length||b(e))return null;const r=e.indexOf("#");return-1===r?e:e.slice(0,r)},K=e=>{const r=s(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 n=r.getTokenValue();if(r.scan(),6!==r.getToken())throw new SyntaxError("Colon expected");switch(r.scan(),r.getToken()){case 10:return[n,r.getTokenValue()];case 11:return[n,Number(r.getTokenValue())];case 8:return[n,!0];case 9:return[n,!1];case 7:return[n,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},M=({lineMap:e,ast:r},n)=>{const t=e[n.line],o=e[n.line+1];if(void 0===t)return;const i=a(r,void 0===o?t+n.character:Math.min(o,t+n.character),!0);if(void 0===i)return;const s=c(i);return 0!==s.length?s:void 0};function R(e){return T(e.split("/").pop()||"")}const U=({lineMap:e,ast:r},n,t=!1)=>{const o=function(e,r,n){e:for(const t of r){const r=Number.isInteger(Number(t))?Number(t):t;if("string"==typeof r||"number"==typeof r&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return n?e:void 0;for(const n of e.children)if(Array.isArray(n.children)&&n.children[0].value===String(r)&&2===n.children.length){e=n.children[1];continue e}return n?e:void 0}if("array"!==e.type||r<0||!Array.isArray(e.children)||r>=e.children.length)return n?e:void 0;e=e.children[r]}return e}(r,n,t);if(void 0!==o&&void 0!==o.range)return{range:o.range}};const C=(e,r={disallowComments:!0})=>{const n=[],{ast:t,data:o,lineMap:i}=J(e,n,r);return{data:o,diagnostics:n,ast:t,lineMap:i}};function J(e,r=[],n){const t=D(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,s=[];const a=new WeakMap,c=[];function h(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function y(e,r,n){return{start:{line:e,character:r},end:{line:e,character:r+n}}}function d(e){return o.children.push(e),e}function b(e){Array.isArray(s)?s.push(e):null!==i&&(s[i]=e)}function m(e){b(e),c.push(s),s=e,i=null}function w(){s=c.pop()}f(e,{onObjectBegin:(e,r,t,i)=>{o=d({type:"object",offset:e,length:-1,parent:o,children:[],range:y(t,i,r)}),!1===n.ignoreDuplicateKeys&&a.set(o,[]),m(function(e){return e?u({}):{}}(!0===n.preserveKeyOrder))},onObjectProperty:(e,t,c,f,l)=>{if((o=d({type:"property",offset:t,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:t,length:c,parent:o}),!1===n.ignoreDuplicateKeys){const n=a.get(o.parent);n&&(0!==n.length&&n.includes(e)?r.push({range:y(f,l,c),message:"DuplicateKey",severity:g.Error,path:B(o),code:20}):n.push(e))}!0===n.preserveKeyOrder&&function(e,r){if(!(r in e))return;const n=p(e),t=n.indexOf(r);-1!==t&&(n.splice(t,1),n.push(r))}(s,e),i=e},onObjectEnd:(e,r,t,i)=>{!1===n.ignoreDuplicateKeys&&a.delete(o),o.length=e+r-o.offset,o.range&&(o.range.end.line=t,o.range.end.character=i+r),o=o.parent,h(e+r),w()},onArrayBegin:(e,r,n,t)=>{o=d({type:"array",offset:e,length:-1,parent:o,children:[],range:y(n,t,r)}),m([])},onArrayEnd:(e,r,n,t)=>{o.length=e+r-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=t+r),o=o.parent,h(e+r),w()},onLiteralValue:(e,r,n,t,i)=>{d({type:V(e),offset:r,length:n,parent:o,value:e,range:y(t,i,n)}),h(r+n),b(e)},onSeparator:(e,r,n)=>{"property"===o.type&&(":"===e?o.colonOffset=r:","===e&&h(r))},onError:(e,n,t,o,i)=>{r.push({range:y(o,i,t),message:l(e),severity:g.Error,code:e})}},n);const v=o.children[0];return v&&delete v.parent,{ast:v,data:s[0],lineMap:t}}function V(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const D=e=>{const r=[0];let n=0;for(;n<e.length;n++)"\n"===e[n]&&r.push(n+1);return r.push(n+1),r};function B(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)),B(e.parent,r)):r}const W=(e,r,n)=>{if(!e||!Object.hasOwnProperty.call(e,r)||r===n)return e;const t={};for(const[o,i]of Object.entries(e))o===r?t[n]=i:o in t||(t[o]=i);return t};function F(e){return"object"==typeof e&&null!==e}function L(e,r){return function e(r,n,t){if(null!==P(n))throw new ReferenceError("Cannot resolve external references");const o=x(n);let i=r;for(const s of o){if(!(F(i)&&s in i))throw new ReferenceError(`Could not resolve '${n}'`);if(F(i=i[s])&&"$ref"in i){if(t.includes(i))return t[t.length-1];if(t.push(i),"string"!=typeof i.$ref)throw new TypeError("$ref should be a string");i=e(r,i.$ref,t)}}return i}(e,r,[])}const q=(e,r)=>{if("string"!=typeof e)return e;try{const n=z(e);return"string"==typeof n?n:JSON.parse(e,r)}catch(e){return}},z=e=>{const r=Number(e);return Number.isFinite(r)?String(r)===e?r:e:NaN},G=(e,r,n)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,r,n)}catch(t){return y(e,r,n)}},H=(e,r)=>{if(e instanceof Array){if(r instanceof Array){if(r.length>e.length)return!1;for(const n in r){if(!r.hasOwnProperty(n))continue;const t=parseInt(e[n]),o=parseInt(r[n]);if(isNaN(t)&&isNaN(o)){if(e[n]!==r[n])return!1}else if(t!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof r)return e.startsWith(r)}return!0},Q=(e,r,n)=>{const t=G(e,r,n);if(void 0===t)throw new Error("The value could not be stringified");return t};function X(e){return e.replace(/^(\/|#\/)/,"").split("/").map(T).map(Y).join(".")}function Y(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const Z=Symbol.for(h),ee={ownKeys:e=>Z in e?e[Z]:Reflect.ownKeys(e)},re=e=>new Proxy(e,ee);function ne(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 n=0;for(const t in e)if(e.hasOwnProperty(t)){if(e[t]!==r[t])break;n++}return e.slice(n)}export{E as BUNDLE_ROOT,N as ERRORS_ROOT,Z as KEYS,S as bundleTarget,O as decodePointer,T as decodePointerFragment,k as encodePointer,w as encodePointerFragment,I as extractPointerFromRef,P as extractSourceFromRef,K as getFirstPrimitiveProperty,M as getJsonPathForPosition,R as getLastPathSegment,U as getLocationForJsonPath,d as hasRef,b as isLocalRef,J as parseTree,C as parseWithPointers,v as pathToPointer,x as pointerToPath,W as renameObjectKey,L as resolveInlineRef,q as safeParse,G as safeStringify,H as startsWith,Q as stringify,X as toPropertyPath,re as trapAccess,j as traverse,ne as trimStart};
import{isObject as e,cloneDeep as r,get as t,has as n,set as o,trimStart as i}from"lodash";import{createScanner as s,findNodeAtOffset as a,getNodePath as c,visit as f,printParseErrorCode as l}from"jsonc-parser";import u,{getOrder as p,ORDER_KEY_ID as h}from"@stoplight/ordered-object-literal";import{DiagnosticSeverity as g}from"@stoplight/types";import y from"safe-stable-stringify";const d=r=>e(r)&&"$ref"in r&&"string"==typeof r.$ref,b=e=>e.length>0&&"#"===e[0],w=(e,r,t)=>{const n=e.toString();let o="",i=n,s=0,a=i.indexOf(r);for(;a>-1;)o+=n.substring(s,s+a)+t,i=i.substring(a+r.length,i.length),s+=a+r.length,a=i.indexOf(r);return i.length>0&&(o+=n.substring(n.length-i.length,n.length)),o},m=e=>"number"==typeof e?e:w(w(e,"~","~0"),"/","~1"),v=e=>O(e),O=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map(m).join("/")}`},j=e=>w(w(decodeURIComponent(""+e),"~1","/"),"~0","~"),$=e=>A(e),A=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(j(e[n]));return t})(e.substring(2).split("/"))},_=(e,r,t=[])=>{if(e&&"object"==typeof e)for(const n in e)e.hasOwnProperty(n)&&(r({parent:e,parentPath:t,property:n,propertyValue:e[n]}),e[n]&&"object"==typeof e[n]&&_(e[n],r,t.concat(n)))},x="#/__bundled__",E="#/__errors__",N=({document:e,path:t,bundleRoot:n="#/__bundled__",errorsRoot:o="#/__errors__"},i)=>{if(`${t}/`.startsWith(`${n}/`)||`${t}/`.startsWith(`${o}/`))throw new Error("Roots do not make any sense");return S(r(e),n,o)(t,{[t]:!0},i)},S=(e,r,i)=>{const s=$(r),a=$(i),c=t(e,s),f=new Set("object"==typeof c&&null!==c?[...Object.keys(c)]:[]),l=(i,u,p,h={},g={},y={})=>{const w=$(i),m=t(e,w);_(p||m,({parent:a})=>{if(d(a)&&b(a.$ref)){const c=a.$ref;if(y[c])return;if(h[c])return void(a.$ref=h[c]);let p,d,b,w;try{let n;if(p=$(c),Array.isArray(t(e,p.slice(0,-1)))){n=`${p[p.length-2]}_${p[p.length-1]}`}else n=p[p.length-1];if(b=n,!c.startsWith(r)){let e=1;for(;f.has(b);)if(b=`${n}_${++e}`,e>20)throw new Error(`Keys ${n}_2 through ${n}_20 already taken.`);f.add(b)}d=[...s,b],w=v(d)}catch(e){y[c]=e.message}if(!p||!d||!w)return;const m=t(e,p);if(void 0!==m&&(h[c]=w,a.$ref=w,!n(g,d))){const r=t(e,p);Array.isArray(r)?o(g,d,new Array(r.length).fill(null)):"object"==typeof r&&o(g,d,{}),o(g,d,m),u[c]||(u[c]=!0,l(i,u,m,h,g,y),u[c]=!1)}}});const O=Object.assign(Object.assign({},c),t(g,s));return Object.keys(O).length&&o(m,s,O),(Object.keys(y).length||n(e,a))&&o(m,a,n(e,a)?t(e,a):y),m};return l},k=e=>w(w(e,"~1","/"),"~0","~"),T=e=>w(w(e,"~","~0"),"//","/~1"),I=e=>{if("string"!=typeof e||0===e.length)return null;const r=e.indexOf("#");return-1===r?null:e.slice(r)},P=e=>{if("string"!=typeof e||0===e.length||b(e))return null;const r=e.indexOf("#");return-1===r?e:e.slice(0,r)},R=e=>{const r=s(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}},K=({lineMap:e,ast:r},t)=>{const n=e[t.line],o=e[t.line+1];if(void 0===n)return;const i=a(r,void 0===o?n+t.character:Math.min(o,n+t.character),!0);if(void 0===i)return;const s=c(i);return 0!==s.length?s:void 0};function M(e){return k(e.split("/").pop()||"")}const U=({lineMap:e,ast:r},t,n=!1)=>{const o=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}(r,t,n);if(void 0!==o&&void 0!==o.range)return{range:o.range}};const C=(e,r={disallowComments:!0})=>{const t=[],{ast:n,data:o,lineMap:i}=J(e,t,r);return{data:o,diagnostics:t,ast:n,lineMap:i}};function J(e,r=[],t){const n=W(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,s=[];const a=new WeakMap,c=[];function h(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function y(e,r,t){return{start:{line:e,character:r},end:{line:e,character:r+t}}}function d(e){return o.children.push(e),e}function b(e){Array.isArray(s)?s.push(e):null!==i&&(s[i]=e)}function w(e){b(e),c.push(s),s=e,i=null}function m(){s=c.pop()}f(e,{onObjectBegin:(e,r,n,i)=>{o=d({type:"object",offset:e,length:-1,parent:o,children:[],range:y(n,i,r)}),!1===t.ignoreDuplicateKeys&&a.set(o,[]),w(function(e){return e?u({}):{}}(!0===t.preserveKeyOrder))},onObjectProperty:(e,n,c,f,l)=>{if((o=d({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=a.get(o.parent);t&&(0!==t.length&&t.includes(e)?r.push({range:y(f,l,c),message:"DuplicateKey",severity:g.Error,path:D(o),code:20}):t.push(e))}!0===t.preserveKeyOrder&&function(e,r){if(!(r in e))return;const t=p(e),n=t.indexOf(r);-1!==n&&(t.splice(n,1),t.push(r))}(s,e),i=e},onObjectEnd:(e,r,n,i)=>{!1===t.ignoreDuplicateKeys&&a.delete(o),o.length=e+r-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=i+r),o=o.parent,h(e+r),m()},onArrayBegin:(e,r,t,n)=>{o=d({type:"array",offset:e,length:-1,parent:o,children:[],range:y(t,n,r)}),w([])},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,h(e+r),m()},onLiteralValue:(e,r,t,n,i)=>{d({type:V(e),offset:r,length:t,parent:o,value:e,range:y(n,i,t)}),h(r+t),b(e)},onSeparator:(e,r,t)=>{"property"===o.type&&(":"===e?o.colonOffset=r:","===e&&h(r))},onError:(e,t,n,o,i)=>{r.push({range:y(o,i,n),message:l(e),severity:g.Error,code:e})}},t);const v=o.children[0];return v&&delete v.parent,{ast:v,data:s[0],lineMap:n}}function V(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const W=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 D(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)),D(e.parent,r)):r}const B=(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 F(e){return"object"==typeof e&&null!==e}function L(e,r){return function e(r,t,n){if(null!==P(t))throw new ReferenceError("Cannot resolve external references");const o=$(t);let i=r;for(const s of o){if(!(F(i)&&s in i))throw new ReferenceError(`Could not resolve '${t}'`);if(F(i=i[s])&&"$ref"in i){if(n.includes(i))return n[n.length-1];if(n.push(i),"string"!=typeof i.$ref)throw new TypeError("$ref should be a string");i=e(r,i.$ref,n)}}return i}(e,r,[])}const q=(e,r)=>{if("string"!=typeof e)return e;try{const t=z(e);return"string"==typeof t?t:JSON.parse(e,r)}catch(e){return}},z=e=>{const r=Number(e);return Number.isFinite(r)?String(r)===e?r:e:NaN},G=(e,r,t)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,r,t)}catch(n){return y(e,r,t)}},H=(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},Q=(e,r,t)=>{const n=G(e,r,t);if(void 0===n)throw new Error("The value could not be stringified");return n};function X(e){return e.replace(/^(\/|#\/)/,"").split("/").map(k).map(Y).join(".")}function Y(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const Z=Symbol.for(h),ee={ownKeys:e=>Z in e?e[Z]:Reflect.ownKeys(e)},re=e=>new Proxy(e,ee);function te(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{x as BUNDLE_ROOT,E as ERRORS_ROOT,Z as KEYS,N as bundleTarget,j as decodePointer,k as decodePointerFragment,T as encodePointer,m as encodePointerFragment,I as extractPointerFromRef,P as extractSourceFromRef,R as getFirstPrimitiveProperty,K as getJsonPathForPosition,M as getLastPathSegment,U as getLocationForJsonPath,d as hasRef,b as isLocalRef,J as parseTree,C as parseWithPointers,v as pathToPointer,$ as pointerToPath,B as renameObjectKey,L as resolveInlineRef,q as safeParse,G as safeStringify,H as startsWith,Q as stringify,X as toPropertyPath,re as trapAccess,_ as traverse,te as trimStart};
{
"name": "@stoplight/json",
"version": "3.10.3",
"version": "3.11.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