@blue-labs/language 1.37.1 → 1.37.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("big.js"),u=require("@blue-labs/shared-utils"),c=require("zod"),Ht=require("bs58"),A=require("radash"),Wt=require("js-sha256"),qt=require("crypto"),Xt=require("base32.js"),z=require("js-yaml"),Qe=r=>r&&r.__esModule?r:{default:r},ne=Qe(Ht),Ne=Qe(qt);class w extends D{constructor(e){super(e)}}class N extends D{constructor(e){super(e)}}class Qt{static get(e,t,s,n=!0){if(u.isNullable(t)||!t.startsWith("/"))throw new Error(`Invalid path: ${t}`);if(t==="/"){const o=e.getValue();return n&&o!==void 0?o:e}const i=t.substring(1).split("/");return this.getRecursive(e,i,0,s,n)}static getRecursive(e,t,s,n,i){if(s===t.length-1&&!i)return this.getNodeForSegment(e,t[s],n,!1);if(s===t.length){const a=e.getValue();return i&&a!==void 0?a:e}const o=t[s],l=this.getNodeForSegment(e,o,n,!0);if(l)return this.getRecursive(l,t,s+1,n,i)}static getNodeForSegment(e,t,s,n){let i;const o=e.getProperties();if(o&&t in o)i=o[t];else switch(t){case"name":{const l=e.getName();i=new d().setValue(l??null);break}case"description":{const l=e.getDescription();i=new d().setValue(l??null);break}case"type":i=e.getType();break;case"itemType":i=e.getItemType();break;case"keyType":i=e.getKeyType();break;case"valueType":i=e.getValueType();break;case"value":{const l=e.getValue();i=new d().setValue(l??null);break}case"blueId":{const l=e.getBlueId();i=new d().setValue(l??null);break}case"blue":i=e.getBlue();break;case"items":{const l=e.getItems();i=new d().setItems(l);break}case"properties":{const l=e.getProperties();i=new d().setProperties(l);break}case"contracts":{const l=e.getContracts();i=new d().setContracts(l);break}default:{if(/^\d+$/.test(t)){const l=parseInt(t,10),a=e.getItems();a&&l>=0&&l<a.length?i=a[l]:i=void 0}else i=void 0;break}}if(i)return n&&s?this.link(i,s):i}static link(e,t){const s=t(e);return u.isNonNullable(s)?s:e}}const J="name",k="description",ce="type",Fe="itemType",Re="keyType",je="valueType",ge="value",xe="items",L="blueId",$e="blue",es=[J,k,ce,Fe,Re,je,ge,xe,L,$e],ts="Text",ss="Double",rs="Integer",ns="Boolean",is="List",os="Dictionary",Le=[ts,ss,rs,ns],et=[...Le,is,os],U="DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K",_="7pwXmXYCJtWnd348c2JQGBkm9C4renmZRwxbfaypsx5y",Z="5WNMiV9Knz63B4dVY5JtMyh3FB4FSGqv7ceScvuapdE1",K="4EzhSubEimSQD3zrYHRtobfPPWntUuhEz8YcdxHsi12u",tt="6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY",st="G7fBT9PSod1RfHLHkpafAGBDVAJMrMhAMY51ERcyXNrj",rt=[U,_,Z,K],le=[...rt,tt,st];Object.fromEntries(et.map((r,e)=>[r,le[e]]));const nt=Object.fromEntries(le.map((r,e)=>[r,et[e]]));class d{static INTEGER=new d("Integer");name;description;type;itemType;keyType;valueType;value;items;properties;blueId;blue;inlineValue=!1;constructor(e){this.name=e}getName(){return this.name}setName(e){return this.name=e,this}getDescription(){return this.description}setDescription(e){return this.description=e,this}getType(){return this.type}setType(e){return typeof e=="string"?this.type=new d().setValue(e).setInlineValue(!0):this.type=e,this}getItemType(){return this.itemType}setItemType(e){return typeof e=="string"?this.itemType=new d().setValue(e).setInlineValue(!0):this.itemType=e,this}getKeyType(){return this.keyType}setKeyType(e){return typeof e=="string"?this.keyType=new d().setValue(e).setInlineValue(!0):this.keyType=e,this}getValueType(){return this.valueType}setValueType(e){return typeof e=="string"?this.valueType=new d().setValue(e).setInlineValue(!0):this.valueType=e,this}getValue(){const e=this.type?.getBlueId();if(u.isNonNullable(e)&&u.isNonNullable(this.value)){if(e===Z&&typeof this.value=="string")return new N(this.value);if(e===_&&typeof this.value=="string"){const t=new w(this.value),s=parseFloat(t.toString());return new w(s.toString())}else if(e===K&&typeof this.value=="string")return this.value.toLowerCase()==="true"}return this.value}setValue(e){return typeof e=="number"?e%1===0?this.value=new N(e.toString()):this.value=new w(e.toString()):this.value=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}addItems(...e){return this.items||(this.items=[]),this.items.push(...e),this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}addProperty(e,t){return this.properties||(this.properties={}),this.properties[e]=t,this}removeProperty(e){return this.properties&&delete this.properties[e],this}getContractsProperty(){return this.properties?.contracts}getContracts(){return this.getContractsProperty()?.getProperties()}setContracts(e){return u.isNullable(e)?this.removeProperty("contracts"):this.addProperty("contracts",new d().setProperties(e)),this}addContract(e,t){const s=this.getContractsProperty();return u.isNullable(s)?this.addProperty("contracts",new d().addProperty(e,t)):s.addProperty(e,t),this}removeContract(e){const t=this.getContractsProperty();if(t){t.removeProperty(e);const s=t.getProperties();s&&Object.keys(s).length===0&&this.removeProperty("contracts")}return this}getBlueId(){return this.blueId}setBlueId(e){return this.blueId=e,this}getBlue(){return this.blue}setBlue(e){return this.blue=e,this}isInlineValue(){return this.inlineValue}setInlineValue(e){return this.inlineValue=e,this}isResolved(){return!1}get(e,t){return Qt.get(this,e,t)}getAsNode(e){const t=this.get(e);if(t instanceof d)return t;throw new Error(`Value at path ${e} is not a BlueNode: ${t}`)}getAsInteger(e){const t=this.get(e);if(t instanceof N||t instanceof w)return t.toNumber();throw new Error(`Value at path ${e} is not a BigInteger or BigDecimal: ${t}`)}clone(){const e=new d(this.name);return e.description=this.description,e.type=this.type?.clone(),e.itemType=this.itemType?.clone(),e.keyType=this.keyType?.clone(),e.valueType=this.valueType?.clone(),e.value=this.value,e.items=this.items?.map(t=>t.clone()),this.properties&&(e.properties=Object.fromEntries(Object.entries(this.properties).map(([t,s])=>[t,s.clone()]))),e.blueId=this.blueId,e.blue=this.blue?.clone(),e.inlineValue=this.inlineValue,e}toString(){return`BlueNode{name='${this.name}', description='${this.description}', type=${this.type}, itemType=${this.itemType}, keyType=${this.keyType}, valueType=${this.valueType}, value=${this.value}, items=${this.items}, properties=${this.properties}, blueId='${this.blueId}', blue=${this.blue}, inlineValue=${this.inlineValue}}`}}class de{static MIN_BLUE_ID_LENGTH=41;static MAX_BLUE_ID_LENGTH=45;static BLUE_ID_PATTERN=/^[1-9A-HJ-NP-Za-km-z]{41,45}(?:#\d+)?$/;static isPotentialBlueId(e){if(!e||e.length===0||!this.BLUE_ID_PATTERN.test(e))return!1;const t=e.split("#"),s=t[0],n=s.length;if(n<this.MIN_BLUE_ID_LENGTH||n>this.MAX_BLUE_ID_LENGTH)return!1;try{if(ne.default.decode(s).length!==32)return!1}catch{return!1}if(t.length>1)try{if(Number(t[1])<0)return!1}catch{return!1}return!0}}const ls=c.z.string().max(de.MAX_BLUE_ID_LENGTH,{message:"Blue Id has a maximum length of 45 characters"}).min(de.MIN_BLUE_ID_LENGTH,{message:"Blue Id has a minimum length of 41 characters"}).refine(r=>{try{return ne.default.decode(r),!0}catch{return!1}},{message:"Blue Id must be a valid Base58 string"}),H=c.z.lazy(()=>c.z.record(c.z.unknown()).and(c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:H.optional(),value:c.z.union([c.z.string(),c.z.number(),c.z.boolean()]).optional().nullable(),items:c.z.array(H).optional()}))),ae=c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:H.optional()}),as=ae.extend({value:c.z.string().optional()}),us=ae.extend({value:c.z.number().optional()}),cs=ae.extend({value:c.z.boolean().optional()}),ds=ae.extend({items:c.z.array(c.z.string()).optional()}),ps=r=>H.safeParse(r).success,it=r=>u.isNonNullable(r)&&"blueId"in r&&u.isNonNullable(r.blueId),hs=r=>u.isNonNullable(r)&&"name"in r&&u.isNonNullable(r.name),ot=r=>u.isNonNullable(r)&&"items"in r&&u.isNonNullable(r.items),lt=r=>u.isNonNullable(r)&&"type"in r&&u.isNonNullable(r.type),at=r=>u.isNonNullable(r)&&"value"in r&&u.isNonNullable(r.value),fs=(r,e)=>r.required({type:!0}).safeParse(e).success,P=r=>r instanceof D,O=r=>P(r)&&r instanceof N,pe=r=>P(r)&&r instanceof w,gs=c.z.lazy(()=>c.z.record(ie)),ys=c.z.lazy(()=>c.z.union([c.z.array(ie),c.z.array(ie).readonly()])),ie=c.z.lazy(()=>c.z.union([u.jsonPrimitiveSchema,gs,ys,c.z.instanceof(D)])),ze=r=>A.isObject(r)&&!A.isArray(r)&&!u.isReadonlyArray(r)&&!P(r),Ue=r=>A.isArray(r)||u.isReadonlyArray(r),ms=r=>Ue(r)||ze(r)||P(r)||u.isJsonPrimitive(r);class g{static deserialize(e){return g.handleNode(e)}static handleNode(e){if(e===void 0)throw new Error("This is not a valid JSON-like value. Found 'undefined' as a value.");if(ze(e)){const t=new d,s={};return Object.entries(e).forEach(([n,i])=>{switch(n){case J:if(i==null)t.setName(void 0);else{if(typeof i!="string")throw new Error(`The ${J} field must be a string.`);t.setName(i)}break;case k:if(i==null)t.setDescription(void 0);else{if(typeof i!="string")throw new Error(`The ${k} field must be a string.`);t.setDescription(i)}break;case ce:t.setType(g.handleNode(i));break;case Fe:t.setItemType(g.handleNode(i));break;case Re:t.setKeyType(g.handleNode(i));break;case je:t.setValueType(g.handleNode(i));break;case ge:t.setValue(g.handleValue(i));break;case L:if(typeof i!="string")throw new Error(`The ${L} field must be a string.`);t.setBlueId(i);break;case xe:t.setItems(g.handleArray(i));break;case $e:t.setBlue(g.handleNode(i));break;default:s[n]=g.handleNode(i);break}}),Object.keys(s).length>0&&t.setProperties(s),t}else{if(Ue(e))return new d().setItems(g.handleArray(e));{const t=e;return new d().setValue(g.handleValue(t)).setInlineValue(!0)}}}static handleValue(e){if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="number"||P(e))if(O(e)||Number.isSafeInteger(e)){const t=new N(e.toString()),s=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER;return t.lt(s)?new N(s.toString()):t.gt(n)?new N(n.toString()):t}else{const t=parseFloat(e.toString());return new w(t.toString())}else if(typeof e=="boolean")return e;throw new Error(`Can't handle node: ${JSON.stringify(e)}`)}static handleArray(e){if(e!=null){if(A.isObject(e)&&!Array.isArray(e))return[g.handleNode(e)];if(Array.isArray(e))return e.map(g.handleNode);throw new Error("Expected an array node")}}}function Is(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var ve,He;function bs(){return He||(He=1,ve=function r(e){if(typeof e=="number"&&isNaN(e))throw new Error("NaN is not allowed");if(typeof e=="number"&&!isFinite(e))throw new Error("Infinity is not allowed");return e===null||typeof e!="object"?JSON.stringify(e):e.toJSON instanceof Function?r(e.toJSON()):Array.isArray(e)?`[${e.reduce((n,i,o)=>`${n}${o===0?"":","}${r(i===void 0||typeof i=="symbol"?null:i)}`,"")}]`:`{${Object.keys(e).sort().reduce((s,n)=>{if(e[n]===void 0||typeof e[n]=="symbol")return s;const i=s.length===0?"":",";return`${s}${i}${r(n)}:${r(e[n])}`},"")}}`}),ve}var Ts=bs();const Ns=Is(Ts);class ut{static canonicalize(e){return Ns(e)}}const Be=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;class _e{static instance;browserCrypto;constructor(){this.browserCrypto=this.initBrowserCrypto()}static getInstance(){return this.instance||(this.instance=new _e),this.instance}initBrowserCrypto(){return Be?null:"crypto"in globalThis?globalThis.crypto:null}hasNodeCrypto(){return Be&&!!Ne.default&&typeof Ne.default.createHash=="function"}getBrowserCrypto(){return this.browserCrypto}getNodeCrypto(){return Be?Ne.default:null}}class ct{cryptoEnv=_e.getInstance();applySync(e){const t=this.canonicalizeInput(e),s=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):this.sha256SyncBrowser(t);return ne.default.encode(s)}async apply(e){const t=this.canonicalizeInput(e),s=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):await this.sha256Async(t);return ne.default.encode(s)}canonicalizeInput(e){const t=ut.canonicalize(e);if(typeof t!="string")throw new Error("Canonized value must be a string");return t}sha256Sync(e){const t=this.cryptoEnv.getNodeCrypto();if(!t)throw new Error("Synchronous SHA-256 is not available in this environment");const s=t.createHash("sha256").update(e).digest();return new Uint8Array(s)}sha256SyncBrowser(e){return new Uint8Array(Wt.sha256.arrayBuffer(e))}async sha256Async(e){if(this.cryptoEnv.hasNodeCrypto())return Promise.resolve(this.sha256Sync(e));const t=this.cryptoEnv.getBrowserCrypto();if(!t)throw new Error("crypto is not available in this environment");const n=new TextEncoder().encode(e),i=await t.subtle.digest("SHA-256",n);return new Uint8Array(i)}}class m{static get(e,t="official"){const s=e.getValue(),n=this.handleValue(s);if(n!==void 0&&t==="simple")return n;const i=e.getItems()?.map(G=>m.get(G,t));if(i!==void 0&&t==="simple")return i;const o=e.getName(),l=e.getDescription();if(t==="original"&&o===void 0&&l===void 0){if(n!==void 0)return n;if(i!==void 0)return i}const a={};o!==void 0&&(a[J]=o),l!==void 0&&(a[k]=l);const p=e.getType();if(t==="official"&&s!==void 0&&p===void 0){const G=this.inferTypeBlueId(s);G!==null&&(a[ce]={[L]:G})}else p!==void 0&&(a[ce]=m.get(p,t));const y=e.getItemType();y!==void 0&&(a[Fe]=m.get(y,t));const h=e.getKeyType();h!==void 0&&(a[Re]=m.get(h,t));const f=e.getValueType();f!==void 0&&(a[je]=m.get(f,t)),n!==void 0&&(a[ge]=n),i!==void 0&&(a[xe]=i);const b=e.getBlueId();b!==void 0&&(a[L]=b);const R=e.getBlue();R!==void 0&&(a[$e]=R);const Y=e.getProperties();return Y!==void 0&&Object.entries(Y).forEach(([G,kt])=>{a[G]=m.get(kt,t)}),a}static handleValue(e){if(P(e)){if(O(e)){const t=new D(Number.MIN_SAFE_INTEGER.toString()),s=new D(Number.MAX_SAFE_INTEGER.toString());if(e.lt(t)||e.gt(s))return e.toString()}return e.toNumber()}return e}static inferTypeBlueId(e){return typeof e=="string"?U:P(e)?O(e)?Z:_:typeof e=="boolean"?K:null}}const vs=r=>u.isJsonPrimitive(r)&&u.isNonNullable(r);class I{static INSTANCE=new I(new ct);hashProvider;constructor(e){this.hashProvider=e}static calculateBlueId(e){if(Array.isArray(e)){const s=e.map(n=>m.get(n));return I.INSTANCE.calculate(s)}const t=m.get(e);return I.INSTANCE.calculate(t)}static calculateBlueIdSync(e){if(Array.isArray(e)){const s=e.map(n=>m.get(n));return I.INSTANCE.calculateSync(s)}const t=m.get(e);return I.INSTANCE.calculateSync(t)}calculate(e){const t=this.cleanStructure(e);if(t===void 0)throw new Error("Object after cleaning cannot be null or undefined.");return this.internalCalculate(t,!1)}calculateSync(e){const t=this.cleanStructure(e);if(t===void 0)throw new Error("Object after cleaning cannot be null or undefined.");return this.internalCalculate(t,!0)}internalCalculate(e,t){return vs(e)||P(e)?this.applyHash(e.toString(),t):Array.isArray(e)||u.isReadonlyArray(e)?this.calculateList(e,t):this.calculateMap(e,t)}calculateMap(e,t){if(e[L]!==void 0)return e[L];const n=Object.keys(e).map(o=>{const l=e[o];if([J,ge,k].includes(o))return t?[o,l]:Promise.resolve([o,l]);{const a=this.internalCalculate(l,t);return t?[o,{blueId:a}]:Promise.resolve(a).then(p=>[o,{blueId:p}])}}),i=o=>{const l={};for(const[a,p]of o)l[a]=p;return this.applyHash(l,t)};return t?i(n):Promise.all(n).then(i)}calculateList(e,t){if(e.length===0)throw new Error("Cannot calculate BlueId for an empty list.");let s=this.internalCalculate(e[0],t);const n=(i,o)=>t?this.applyHash([{blueId:i},{blueId:o}],!0):Promise.all([i,o]).then(([l,a])=>this.applyHash([{blueId:l},{blueId:a}],!1));for(let i=1;i<e.length;i++){const o=this.internalCalculate(e[i],t);s=n(s,o)}return s}applyHash(e,t){return t?this.hashProvider.applySync(e):this.hashProvider.apply(e)}cleanStructure(e){if(e!=null){if(u.isJsonPrimitive(e)||P(e))return e;if(Array.isArray(e)||u.isReadonlyArray(e)){const t=e.map(s=>this.cleanStructure(s)).filter(u.isNonNullable);return t.length>0?t:void 0}else if(typeof e=="object"){const t={};for(const s in e){const n=this.cleanStructure(e[s]);n!=null&&(t[s]=n)}return Object.keys(t).length>0?t:void 0}else return e}}}class Bs{static convert(e){const t=ne.default.decode(e),s=new Uint8Array(2+t.length);s[0]=18,s[1]=32,s.set(t,2);const n=new Uint8Array(2+s.length);return n[0]=1,n[1]=85,n.set(s,2),"b"+new Xt.Encoder({type:"rfc4648",lc:!0}).write(n).finalize().replace(/=/g,"")}}class E{static transform(e,t){const s=t(e.clone()),n=s.getType();n!==void 0&&s.setType(E.transform(n,t));const i=s.getItemType();i!==void 0&&s.setItemType(E.transform(i,t));const o=s.getKeyType();o!==void 0&&s.setKeyType(E.transform(o,t));const l=s.getValueType();l!==void 0&&s.setValueType(E.transform(l,t));const a=s.getItems();if(a!==void 0){const y=a.map(h=>E.transform(h,t));s.setItems(y)}const p=s.getProperties();if(p!==void 0){const y=Object.keys(p).reduce((h,f)=>(h[f]=E.transform(p[f],t),h),{});s.setProperties(y)}return s}}const F=r=>!!r&&typeof r=="object"&&!Array.isArray(r)&&!(r instanceof d),C=r=>r instanceof N||r instanceof w,ws=r=>r.replace(/~1/g,"/").replace(/~0/g,"~");function Q(r){if(r==="/")return[];if(!r.startsWith("/"))throw new Error(`Path must start with '/': ${r}`);return r.split("/").slice(1).map(ws)}function W(r){if(r==="-")return-1;const e=typeof r=="number"?r:parseInt(r,10);if(isNaN(e))throw new Error(`Invalid array index (NaN) from '${r}'`);if(!Number.isFinite(e))throw new Error(`Invalid array index '${r}' results in non-finite number ${e}`);return e}function dt(r,e,t,s=!0){switch(e){case"name":return t?s?r.getName()??null:r:r.getName();case"description":return t?s?r.getDescription():r:r.getDescription();case"type":return r.getType();case"itemType":return r.getItemType();case"keyType":return r.getKeyType();case"valueType":return r.getValueType();case"value":return t?s?r.getValue()??null:r:r.getValue();case"blueId":return t?s?r.getBlueId()??null:r:r.getBlueId();case"blue":return r.getBlue();case"items":return r.getItems();case"properties":return r.getProperties();case"contracts":return r.getContracts();default:return}}function We(r,e,t=!0){if(r instanceof d){const s=dt(r,e,!0,t);if(s!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(e))return s;if(/^-?\d+$/.test(e)&&e!=="-"){const i=r.getItems(),o=parseInt(e,10);return i&&o>=0&&o<i.length?i[o]:void 0}const n=r.getProperties();return n&&e in n?n[e]:void 0}if(Array.isArray(r)){if(e==="-")return;const s=W(e);return s>=0&&s<r.length?r[s]:void 0}if(F(r))return r[e]}function ee(r,e){if(e.length===0)return{parent:r,key:"value",actualTarget:r.getValue()??r};let t=r;for(let n=0;n<e.length-1;++n){const i=e[n],o=We(t,i);if(o===void 0)throw new Error(`Cannot resolve '/${e.slice(0,n+1).join("/")}'`);t=o}const s=e[e.length-1];if(t instanceof d){const n=We(t,s,!1);if((typeof n!="object"||n===null||C(n))&&!(n instanceof d)&&!Array.isArray(n)&&["name","description","value","blueId"].includes(s))return{parent:t,key:s,actualTarget:n}}return Array.isArray(t)&&s==="-"?{parent:t,key:"-"}:t instanceof d&&t.getItems()&&s==="-"?{parent:t,key:"-"}:{parent:t,key:Array.isArray(t)?W(s):s}}function Ze(r,e){if(r instanceof d){const t=e,s=dt(r,t,!1);if(s!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(t))return s;if(typeof e=="number"||typeof e=="string"&&/^\d+$/.test(e)){const n=r.getItems(),i=typeof e=="number"?e:parseInt(e,10);if(n&&i>=0&&i<n.length)return n[i]}return r.getProperties()?.[t]}return Array.isArray(r)||F(r)?r[e]:r}function B(r){if(r instanceof d)return r;if(r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean"||C(r))return g.deserialize(r);const e=Ae(r);return g.deserialize(e)}function Ae(r){if(r===void 0)return null;if(r===null||typeof r!="object")return r;if(Array.isArray(r))return r.map(Ae);const e={};for(const[t,s]of Object.entries(r))e[t]=Ae(s);return e}function Ke(r,e,t){if(r instanceof d){const s=e;switch(s){case"name":r.setName(t);return;case"description":r.setDescription(t);return;case"type":r.setType(t instanceof d||typeof t=="string"||t===void 0?t:B(t));return;case"itemType":r.setItemType(t instanceof d||typeof t=="string"||t===void 0?t:B(t));return;case"keyType":r.setKeyType(t instanceof d||typeof t=="string"||t===void 0?t:B(t));return;case"valueType":r.setValueType(t instanceof d||typeof t=="string"||t===void 0?t:B(t));return;case"value":{const n=t;r.setValue(n===void 0?null:n);return}case"blueId":r.setBlueId(t);return;case"blue":r.setBlue(t instanceof d||t===void 0?t:B(t));return;case"items":r.setItems(t);return;case"properties":r.setProperties(t);return;case"contracts":r.setContracts(t);return;default:{if(t===void 0){const n=r.getProperties();n&&s in n&&delete n[s]}else r.getProperties()||r.setProperties({}),r.addProperty(s,t instanceof d?t:B(t));return}}}Array.isArray(r)?r.splice(W(e),1):F(r)&&(t===void 0?delete r[e]:r[e]=t)}function Ps(r,e,t,s){let n=-1;if(e!=="-"&&(n=typeof e=="number"?e:parseInt(e,10),isNaN(n)))throw new Error(`Invalid numeric key for BlueNode item operation: ${e}`);if(n<-1)throw new Error(`Invalid array index for BlueNode items: ${n}`);let i=r.getItems();if(i||(i=[],r.setItems(i)),!s&&n!==-1&&n>i.length)throw new Error(`ADD operation failed: Target array index '${n}' is greater than array length ${i.length}.`);if(e==="-")i.push(t);else if(s){if(n>=0)if(n<i.length)i[n]=t;else{for(let o=i.length;o<n;o++)i.push(g.deserialize(null));i.push(t)}}else i.splice(n,0,t)}function he(r,e,t,s){if(Array.isArray(r)){const n=e==="-"?r.length:W(e);if(!s&&n>r.length)throw new Error(`ADD operation failed: Target array index '${n}' is greater than array length ${r.length}. Path involving key '${e}'.`);if(n<0&&e!=="-")throw new Error(`Invalid negative array index: ${e}`);const i=B(t);if(s){if(n>=0&&n<r.length)r[n]=i;else if(n>=r.length){for(let o=r.length;o<n;o++)r.push(g.deserialize(null));r.push(i)}}else r.splice(n,0,i);return}if(r instanceof d){e==="-"||typeof e=="number"&&!isNaN(e)||typeof e=="string"&&/^\d+$/.test(e)?Ps(r,e,B(t),s):Ke(r,e,t);return}if(F(r)){r[e]=B(t);return}throw new Error(`Cannot insert into parent of type ${typeof r}`)}function Ss(r,e){if(Array.isArray(r)){const t=W(e);t===-1&&e==="-"?r.length>0&&r.pop():t>=0&&t<r.length&&r.splice(t,1);return}if(r instanceof d){if(typeof e=="number"||typeof e=="string"&&/^-?\d+$/.test(e)){const t=r.getItems();if(t){const s=W(e);s===-1&&e==="-"?t.length>0&&t.pop():s>=0&&s<t.length&&t.splice(s,1),t.length===0&&r.setItems(void 0);return}}Ke(r,e,void 0)}else F(r)&&delete r[e]}function Ve(r){if(r instanceof d)return r.clone();if(Array.isArray(r))return r.map(t=>Ve(t));if(F(r)){const e={};return Object.keys(r).forEach(t=>{e[t]=Ve(r[t])}),e}return r}function x(r,e){if(r===e||r instanceof d&&(r.isInlineValue()||r.getValue()!==void 0)&&x(r.getValue()??null,e)||e instanceof d&&(e.isInlineValue()||e.getValue()!==void 0)&&x(r,e.getValue()??null))return!0;if(r instanceof d&&e instanceof d||C(r)&&C(e)||C(r)&&typeof e=="number"||typeof r=="number"&&C(e))return r.toString()===e.toString();if(Array.isArray(r)&&Array.isArray(e))return r.length===e.length&&r.every((t,s)=>x(t,e[s]));if(F(r)&&F(e)){const t=Object.keys(r),s=Object.keys(e);return t.length===s.length&&t.every(n=>x(r[n],e[n]))}return!1}function pt(r,e){const{parent:t,key:s}=ee(r,Q(e));return Ze(t,s)}function ht(r,e,t){const s=Q(e);if(s.length===0&&e==="/"){const o=B(t);r.setValue(o.getValue()??null),o.getItems()?r.setItems(o.getItems()):r.setItems(void 0);return}const{parent:n,key:i}=ee(r,s);he(n,i,t,!0)}function Es(r,e,t){const s=Q(e);if(s.length===0&&e==="/"){if(r.getItems()&&Array.isArray(t)){const o=B(t);o.getItems()?(r.setItems(o.getItems()),r.setValue(null)):(r.setValue(o.getValue()??null),r.setItems(void 0))}else{const o=B(t);r.setValue(o.getValue()??null),o.getItems()&&r.setItems(o.getItems())}return!0}const{parent:n,key:i}=ee(r,s);return he(n,i,t,!1),!0}function As(r,e,t){const s=Q(e);if(s.length===0&&e==="/"){const l=B(t);return r.setValue(l.getValue()??null),l.getItems()?r.setItems(l.getItems()):r.setItems(void 0),!0}const{parent:n,key:i,actualTarget:o}=ee(r,s);if(o!==void 0&&n instanceof d)Ke(n,i,t);else{const l=Ze(n,i),a=Array.isArray(n)||n instanceof d&&n.getItems()&&(typeof i=="number"||typeof i=="string"&&/^\d+$/.test(i));if(l===void 0){if(a)throw new Error(`REPLACE failed: Target array index '${i.toString()}' is out of bounds or does not exist at path '${e}'.`);he(n,i,t,!0)}else he(n,i,t,!0)}return!0}function ft(r,e){const t=Q(e);if(t.length===0&&e==="/")return r.setValue(null),r.setItems(void 0),r.setProperties(void 0),!0;const{parent:s,key:n}=ee(r,t);return Ss(s,n),!0}function Vs(r,e,t){const s=Ve(pt(r,e));return ht(r,t,s),!0}function Cs(r,e,t){const s=Q(e),{parent:n,key:i}=ee(r,s),o=Ze(n,i);if(o===void 0)throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);return ft(r,e)?(ht(r,t,o),!0):!1}function Ms(r,e,t){const s=pt(r,e);let n=t;if(s instanceof d)if((t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||C(t))&&(s.isInlineValue()||s.getValue()!==void 0)){if(!x(s.getValue()??null,t))throw new Error(`TEST failed at '${e}': Expected ${JSON.stringify(t)}, got ${JSON.stringify(s.getValue()??null)}`);return!0}else typeof t=="object"&&!(t instanceof d)&&(n=B(t));else if(C(s)&&typeof t=="number")s instanceof N?n=new N(t.toString()):s instanceof w&&(n=new w(t.toString()));else if((s===null||typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&C(t)){const i=t;!x(s,i.toString())&&(typeof s=="number"&&parseFloat(i.toString()))}if(!x(s,n)){const i=s instanceof d?s.toString():JSON.stringify(s),o=n instanceof d?n.toString():JSON.stringify(n);throw new Error(`TEST failed at '${e}': Expected ${o}, got ${i}`)}return!0}function Ds(r,e){switch(e.op){case"add":return Es(r,e.path,e.val);case"replace":return As(r,e.path,e.val);case"remove":return ft(r,e.path);case"copy":return Vs(r,e.from,e.path);case"move":return Cs(r,e.from,e.path);case"test":return Ms(r,e.path,e.val)}}function Os(r,e,t=!1){const s=t?r:r.clone();return Ds(s,e),s}const we=Symbol.for("zod-schema-annotations");function Fs(){if(typeof globalThis<"u")return globalThis;if(typeof global<"u")return global;if(typeof window<"u")return window;if(typeof self<"u")return self;throw new Error("Unable to locate global object")}function gt(){const r=Fs();return we in r||(r[we]=new WeakMap),r[we]}function te(r,e){const t=gt(),s=t.get(r)||{};return t.set(r,{...s,...e}),r}const V=r=>gt().get(r),yt=r=>e=>{const t=V(e);return te(e,{...t,blueDescription:r})},mt=r=>{const e=V(r);return u.isNonNullable(e)&&A.isString(e.blueDescription)?e.blueDescription:null},Rs=r=>yt(r)(c.z.string().optional()),js=c.z.union([c.z.string(),c.z.boolean()]),It=r=>e=>{const t=V(e);return te(e,{...t,blueId:r})},bt=r=>{const e=V(r),t=js.safeParse(e?.blueId);return t.success?t.data:null},xs=r=>It(r??!0)(c.z.string()),Tt=r=>e=>{const t=V(e);return te(e,{...t,blueName:r})},Nt=r=>{const e=V(r);return u.isNonNullable(e)&&A.isString(e.blueName)?e.blueName:null},$s=r=>{const e=c.z.string().optional();return Tt(r)(e)},vt=()=>r=>{const e=V(r);return te(r,{...e,blueNode:!0})},Bt=r=>{const e=V(r);return u.isNonNullable(e)&&u.isNonNullable(e.blueNode)&&e.blueNode===!0?e.blueNode:null},Ye=r=>!!Bt(r),Ls=()=>{const r=c.z.instanceof(d);return vt()(r)},Ce="extendedFrom",wt=({schema:r,baseSchema:e})=>{const t=V(r)||{};return te(r,{...t,[Ce]:e})},Pt=r=>{const e=V(r);return u.isNonNullable(e)&&e[Ce]?e[Ce]:null},Ge=(r,e)=>{const t=Pt(r);return u.isNullable(t)?!1:t?._def===e?._def?!0:Ge(t,e)},zs=r=>new Proxy(r,{get(e,t,s){return t==="extend"?function(...n){const i=e.extend(...n);return wt({schema:i,baseSchema:e})}:Reflect.get(e,t,s)}}),Us=c.z.object({value:c.z.array(c.z.string()).optional(),defaultValue:c.z.string().optional()}),St=r=>{const e=V(r),t=Us.passthrough().safeParse(e?.typeBlueId);return t.success?t.data:null},_s=r=>e=>{const t=V(e),s=typeof r=="string"?{value:[r]}:r,n=zs(e);return te(n,{...t,typeBlueId:{...t?.typeBlueId||{},...s}})};class ye{static resolveBlueId(e){const t=St(e);if(u.isNullable(t))return null;const s=t.defaultValue;if(u.isNonNullable(s))return s;const n=t.value?.[0];return u.isNonNullable(n)?n:ye.getRepositoryBlueId(t,e)}static getRepositoryBlueId(e,t){throw new Error("Not implemented")}}class S{static isTypeOf(e,t,s){const n=ye.resolveBlueId(t),i=e.getType()?.getBlueId();if(u.isNullable(n)||u.isNullable(i))return!1;if(n===i)return!0;if(s?.checkSchemaExtensions&&u.isNonNullable(s.typeSchemaResolver)){const o=s.typeSchemaResolver.resolveSchema(e);return S.checkSchemaExtension(o,t)}return!1}static checkSchemaExtension(e,t){if(!u.isNonNullable(e))return!1;const s=S.unwrapSchema(e),n=S.unwrapSchema(t);return Ge(s,n)}static isWrapperType(e){return e instanceof c.ZodOptional||e instanceof c.ZodNullable||e instanceof c.ZodReadonly||e instanceof c.ZodBranded||e instanceof c.ZodEffects||e instanceof c.ZodLazy}static unwrapSchema(e){return Ye(e)?e:S.isWrapperType(e)?e instanceof c.ZodEffects?S.unwrapSchema(e.innerType()):e instanceof c.ZodLazy?S.unwrapSchema(e.schema):S.unwrapSchema(e.unwrap()):e}}class Et{blueIdMap=new Map;constructor(e){this.registerSchemas(e)}registerSchemas(e){for(const t of e)this.registerSchema(t)}registerSchema(e){const t=ye.resolveBlueId(e);if(u.isNonNullable(t)){if(this.blueIdMap.has(t))throw new Error(`Duplicate BlueId value: ${t}`);this.blueIdMap.set(t,e)}}resolveSchema(e){const t=this.getEffectiveBlueId(e);return u.isNullable(t)?null:this.blueIdMap.get(t)}getEffectiveBlueId(e){const t=e.getType();return u.isNonNullable(t)&&u.isNonNullable(t.getBlueId())?t.getBlueId():u.isNonNullable(t)?I.calculateBlueIdSync(t):null}getBlueIdMap(){return new Map(this.blueIdMap)}}const v={NAME:"name",DESCRIPTION:"description",TYPE:"type",BLUE_ID:"blue_id",KEY_TYPE:"key_type",VALUE_TYPE:"value_type",ITEM_TYPE:"item_type",VALUE:"value",PROPERTIES:"properties",BLUE:"blue",ITEMS:"items"};class me{static isEmptyNode(e){return this.hasFieldsAndMayHaveFields(e)}static hasBlueIdOnly(e){return this.hasFieldsAndMayHaveFields(e,new Set([v.BLUE_ID]))}static hasItemsOnly(e){return this.hasFieldsAndMayHaveFields(e,new Set([v.ITEMS]))}static isValidValueNode(e){const t=e.getValue(),s=e.getProperties(),n=e.getItems();return u.isNonNullable(t)&&u.isNullable(s)&&u.isNullable(n)}static textNode(e){return new d().setType(new d().setBlueId(U)).setValue(e)}static integerNode(e){const t=e instanceof N?e:new N(e.toString());return new d().setType(new d().setBlueId(Z)).setValue(t)}static doubleNode(e){const t=e instanceof w?e:new w(e.toString());return new d().setType(new d().setBlueId(_)).setValue(t)}static booleanNode(e){return new d().setType(new d().setBlueId(K)).setValue(e)}static hasFieldsAndMayHaveFields(e,t=new Set,s=new Set){for(const n of Object.values(v)){const i=u.isNonNullable(this.getFieldValue(e,n));if(t.has(n)){if(!i)return!1}else if(!s.has(n)){if(i)return!1}}return!0}static getFieldValue(e,t){switch(t){case v.NAME:return e.getName();case v.TYPE:return e.getType();case v.VALUE:return e.getValue();case v.DESCRIPTION:return e.getDescription();case v.PROPERTIES:return e.getProperties();case v.BLUE:return e.getBlue();case v.ITEMS:return e.getItems();case v.KEY_TYPE:return e.getKeyType();case v.VALUE_TYPE:return e.getValueType();case v.ITEM_TYPE:return e.getItemType();case v.BLUE_ID:return e.getBlueId();default:throw new Error(`Unknown field: ${t}`)}}}class Ie{}class se{static convert(e){const t=new Me;return se.traverseNode(e,"",t),t.build()}static traverseNode(e,t,s){if(!e)return;const n=e.getProperties(),i=e.getItems(),o=n!==void 0&&Object.keys(n).length>0,l=i!==void 0&&i.length>0;if(!o&&!l){s.addPath(t===""?"/":t);return}if(n)for(const[a,p]of Object.entries(n)){const y=`${t}/${a}`;se.traverseNode(p,y,s)}if(i)for(let a=0;a<i.length;a++){const p=`${t}/${a}`;se.traverseNode(i[a],p,s)}}}function qe(r,e){const t=r.split(e),s=[...t].reverse().findIndex(i=>i!==""),n=s===-1?0:t.length-s;return t.slice(0,n)}class be extends Ie{allowedPaths;maxDepth;currentPath=[];constructor(e,t){super(),this.allowedPaths=e,this.maxDepth=t}shouldExtendPathSegment(e){if(this.currentPath.length>=this.maxDepth)return!1;const t=this.normalizePath(this.getCurrentFullPath()+"/"+e);return this.isAllowedPath(t)}shouldMergePathSegment(e){return this.shouldExtendPathSegment(e)}isAllowedPath(e){for(const t of this.allowedPaths)if(this.matchesAllowedPath(t,e))return!0;return!1}matchesAllowedPath(e,t){const s=qe(e,"/"),n=qe(t,"/");if(n.length>s.length)return!1;for(let i=1;i<n.length;i++)if(s[i]!=="*"&&s[i]!==n[i])return!1;return!0}enterPathSegment(e){this.currentPath.push(e)}exitPathSegment(){this.currentPath.length>0&&this.currentPath.pop()}getCurrentFullPath(){return"/"+this.currentPath.join("/")}normalizePath(e){return"/"+e.split("/").filter(t=>t!=="").join("/")}static withMaxDepth(e){const t=new Me().setMaxDepth(e);for(let s=1;s<=e;s++){const n="/"+Array(s).fill("*").join("/");t.addPath(n)}return t.build()}static withSinglePath(e){return new Me().addPath(e).build()}static fromNode(e){return se.convert(e)}}class Me{allowedPaths=new Set;maxDepth=Number.MAX_SAFE_INTEGER;addPath(e){return this.allowedPaths.add(e),this}setMaxDepth(e){return this.maxDepth=e,this}build(){return new be(this.allowedPaths,this.maxDepth)}}class Zs extends Ie{shouldExtendPathSegment(){return!0}shouldMergePathSegment(){return!0}enterPathSegment(){}exitPathSegment(){}}class Te extends Ie{limits;constructor(e){super(),this.limits=e}shouldExtendPathSegment(e,t){return this.limits.every(s=>s.shouldExtendPathSegment(e,t))}shouldMergePathSegment(e,t){return this.limits.every(s=>s.shouldMergePathSegment(e,t))}enterPathSegment(e,t){this.limits.forEach(s=>{s.enterPathSegment(e,t)})}exitPathSegment(){this.limits.forEach(e=>{e.exitPathSegment()})}static of(...e){return new Te(e)}}const j=new Zs;function Xe(r,e){const t=r.getType();if(t===void 0)return;const s=t.getBlueId();if(s!==void 0){if(le.includes(s)){const i=nt[s];return new d().setBlueId(s).setName(i)}const n=e.fetchByBlueId(s);if(!n||n.length===0)return;if(n.length>1)throw new Error(`Expected a single node for type with blueId '${s}', but found multiple.`);return n[0]}return t}function T(r,e,t){const s=I.calculateBlueIdSync(r),n=I.calculateBlueIdSync(e);if(s===n)return!0;if(s&&le.includes(s)){let a=e;for(;a!==void 0;){if(I.calculateBlueIdSync(a)===s)return!0;a=Xe(a,t)}return!1}let i=r;const o=r.getBlueId();if(o){const a=t.fetchByBlueId(o);a&&a.length===1&&(i=a[0])}let l=i;for(;l!==void 0;){if(I.calculateBlueIdSync(l)===n)return!0;l=Xe(l,t)}return!1}function Ks(r,e){return rt.some(t=>{const s=new d().setBlueId(t);return T(r,s,e)})}function Ys(r,e){const t=new d().setBlueId(U);return T(r,t,e)}function Gs(r,e){const t=new d().setBlueId(Z);return T(r,t,e)}function Js(r,e){const t=new d().setBlueId(_);return T(r,t,e)}function ks(r,e){const t=new d().setBlueId(K);return T(r,t,e)}function At(r,e){const t=new d().setBlueId(tt);return T(r,t,e)}function Vt(r,e){const t=new d().setBlueId(st);return T(r,t,e)}function Hs(r,e){return Le.some(t=>{const s=new d().setName(t);return T(r,s,e)})}function Ws(r,e){for(const t of Le){const s=new d().setName(t);if(T(r,s,e))return t}throw new Error(`Cannot determine the basic type for node of type "${r.getName()||"unknown"}".`)}class qs{blue;constructor(e){this.blue=e}matchesType(e,t,s=j){const n=t.getType();if(this.matchesImplicitStructure(e,n))return!0;const i=be.fromNode(t),o=Te.of(s,i),l=this.extendAndResolve(e,o),a=this.blue.resolve(t,o);return this.verifyMatch(l,t,o)&&this.recursiveValueComparison(l,a)}extendAndResolve(e,t){const s=e.clone(),n=s.clone();this.blue.extend(n,t);const i=this.blue.resolve(n,t);return this.restoreMissingStructure(i,s),i}restoreMissingStructure(e,t){const s=t.getItems(),n=e.getItems();if(s&&s.length>0)if(!n||n.length===0)e.setItems(s.map(a=>a.clone()));else for(let a=0;a<Math.min(n.length,s.length);a++)this.restoreMissingStructure(n[a],s[a]);const i=t.getProperties();if(i){let a=e.getProperties();a||(a={},e.setProperties(a));for(const[p,y]of Object.entries(i)){const h=a[p];h===void 0?a[p]=y.clone():this.restoreMissingStructure(h,y)}}const o=t.getBlueId();e.getBlueId()===void 0&&o!==void 0&&e.setBlueId(o);const l=t.getValue();e.getValue()===void 0&&l!==void 0&&e.setValue(l)}verifyMatch(e,t,s){const n=t.getType();if(this.matchesImplicitStructure(e,n))return!0;const i=e.clone().setType(t.clone());try{this.blue.resolve(i,s)}catch{return!1}return!0}recursiveValueComparison(e,t){const s=t.getType(),n=this.matchesImplicitStructure(e,s);if(s&&!n){const h=e.getType();if(!h||!T(h,s,this.blue.getNodeProvider()))return!1}const i=t.getBlueId();if(!n&&i!==void 0){const h=e.getBlueId(),f=e.getType()?.getBlueId();if(h!==void 0){if(i!==h)return!1}else if(f===void 0||i!==f)return!1}const o=t.getValue();if(o!==void 0){const h=e.getValue();if(h===void 0)return!1;if(P(h)&&P(o)){if(!h.eq(o))return!1}else if(h!==o)return!1}const l=t.getItems();if(l!==void 0){const h=e.getItems()??[];for(let f=0;f<l.length;f++)if(f<h.length){if(!this.recursiveValueComparison(h[f],l[f]))return!1}else if(this.hasValueInNestedStructure(l[f]))return!1}const a=t.getItemType();if(a!==void 0){const h=e.getItems()??[];for(const f of h)if(!this.recursiveValueComparison(f,a))return!1}const p=t.getProperties();if(p!==void 0){const h=e.getProperties()??{};for(const[f,b]of Object.entries(p))if(f in h){if(!this.recursiveValueComparison(h[f],b))return!1}else if(this.hasValueInNestedStructure(b))return!1}const y=t.getValueType();if(y!==void 0){const h=Object.values(e.getProperties()??{});for(const f of h)if(!this.recursiveValueComparison(f,y))return!1}return!0}hasValueInNestedStructure(e){if(e.getValue()!==void 0)return!0;const t=e.getItems();if(t!==void 0){for(const n of t)if(this.hasValueInNestedStructure(n))return!0}const s=e.getProperties();if(s!==void 0){for(const n of Object.values(s))if(this.hasValueInNestedStructure(n))return!0}return!1}matchesImplicitStructure(e,t){return t===void 0||e.getType()!==void 0?!1:At(t,this.blue.getNodeProvider())?this.isImplicitListStructure(e):Vt(t,this.blue.getNodeProvider())?this.isImplicitDictionaryStructure(e):!1}isImplicitListStructure(e){return e.getItems()!==void 0&&e.getValue()===void 0}isImplicitDictionaryStructure(e){return e.getProperties()!==void 0&&e.getValue()===void 0}}const Xs=r=>r instanceof c.ZodOptional||r instanceof c.ZodNullable||r instanceof c.ZodReadonly||r instanceof c.ZodBranded||r instanceof c.ZodEffects||r instanceof c.ZodLazy,Qs=r=>r instanceof c.ZodString||r instanceof c.ZodNumber||r instanceof c.ZodBoolean||r instanceof c.ZodBigInt;class Ct{static convertValue(e,t){const s=e.getType()?.getBlueId(),n=e.getValue();return u.isNullable(n)?Qs(t)&&me.isValidValueNode(e)?this.getDefaultPrimitiveValue(t):n:U===s?this.convertFromString(String(n),t):_===s||n instanceof w?this.convertFromBigDecimal(new w(n?.toString()),t):Z===s||n instanceof N?this.convertFromBigInteger(new N(n?.toString()),t):K===s||typeof n=="boolean"?this.convertFromBoolean(!!n,t):this.convertFromString(String(n),t)}static convertFromString(e,t){if(!t||t instanceof c.ZodString||t instanceof c.ZodEnum||t instanceof c.ZodNativeEnum)return e;if(t instanceof c.ZodNumber)return Number(e);if(t instanceof c.ZodBoolean)return e.toLowerCase()==="true";if(t instanceof c.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert String to ${t._def.typeName}`)}static convertFromBigDecimal(e,t){if(t instanceof c.ZodNumber)return e.toNumber();if(t instanceof c.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t._def.typeName}`)}static convertFromBigInteger(e,t){if(t instanceof c.ZodNumber)return e.toNumber();if(t instanceof c.ZodBigInt)return BigInt(e.toString());if(t instanceof c.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t._def.typeName}`)}static convertFromBoolean(e,t){if(!t||t instanceof c.ZodBoolean)return e;if(t instanceof c.ZodString)return e.toString();if(t instanceof c.ZodNumber)return Number(e);if(t instanceof c.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert Boolean to ${t._def.typeName}`)}static getDefaultPrimitiveValue(e){if(!e)return null;if(e instanceof c.ZodNumber)return 0;if(e instanceof c.ZodBoolean)return!1;if(e instanceof c.ZodString)return"";throw new Error(`Unsupported primitive type: ${e._def.typeName}`)}}class er{convert(e,t){return Ct.convertValue(e,t)}}class tr{constructor(e){this.nodeToObjectConverter=e}convert(e,t){return this.convertFields(e,t)}convertFields(e,t){if(t instanceof c.ZodIntersection){const s=t._def.left,n=t._def.right,i=this.convert(e,s),o=this.convert(e,n);return{...i,...o}}if(t instanceof c.ZodUnion)throw new Error("Union not supported");if(t instanceof c.ZodObject)return Object.keys(t.shape).reduce((n,i)=>{const o=e.getProperties(),l=t.shape[i],a=bt(l);if(u.isNonNullable(a)){const b=A.isString(a)?a:i,R=o?.[b],Y=R?I.calculateBlueIdSync(R):void 0;return n[i]=Y,n}const p=Nt(l);if(u.isNonNullable(p)){const b=o?.[p];return n[i]=b?.getName(),n}const y=mt(l);if(u.isNonNullable(y)){const b=o?.[y];return n[i]=b?.getDescription(),n}if(i==="name"){const b=e.getName();return n[i]=b,n}if(i==="description"){const b=e.getDescription();return n[i]=b,n}const h=o?.[i];if(u.isNullable(h))return n;const f=this.nodeToObjectConverter.convert(h,l);return n[i]=f,n},{});throw new Error("Unknown schema type, "+t._def.typeName)}}class sr{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const s=e.getItems();if(!s)return;const n=t.element;return s.map(o=>this.nodeToObjectConverter.convert(o,n))}}class rr{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const s=e.getItems();if(!s)return;const n=t._def.valueType,i=s.map(o=>this.nodeToObjectConverter.convert(o,n));return new Set(i)}}class nr{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const s=t.keySchema,n=t.valueSchema,i=new Map,o=e.getName();u.isNonNullable(o)&&i.set(J,o);const l=e.getDescription();u.isNonNullable(l)&&i.set(k,l);const a=e.getProperties();return u.isNonNullable(a)&&Object.entries(a).forEach(([p,y])=>{const h=new d().setValue(p);h.setType(new d().setBlueId(U));const f=Ct.convertValue(h,s),b=this.nodeToObjectConverter.convert(y,n);i.set(f,b)}),t instanceof c.ZodRecord?Object.fromEntries(i):i}}class ir{convert(e){return m.get(e)}}class or{convert(e){return m.get(e)}}class lr{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const s=e.getItems();if(!s)return;const n=t.items;return s.map((o,l)=>this.nodeToObjectConverter.convert(o,n[l]))}}const ar=c.z.union([c.z.literal("ZodString"),c.z.literal("ZodNumber"),c.z.literal("ZodBoolean"),c.z.literal("ZodBigInt"),c.z.literal("ZodArray"),c.z.literal("ZodSet"),c.z.literal("ZodMap"),c.z.literal("ZodRecord"),c.z.literal("ZodObject"),c.z.literal("ZodEnum"),c.z.literal("ZodNativeEnum"),c.z.literal("ZodUnknown"),c.z.literal("ZodAny"),c.z.literal("ZodTuple")]);class ur{constructor(e){this.nodeToObjectConverter=e,this.registerConverters(),this.complexObjectConverter=new tr(this.nodeToObjectConverter)}converters=new Map;complexObjectConverter;registerConverters(){const e=new er,t=new sr(this.nodeToObjectConverter),s=new lr(this.nodeToObjectConverter),n=new rr(this.nodeToObjectConverter),i=new nr(this.nodeToObjectConverter);this.converters.set("ZodString",e),this.converters.set("ZodNumber",e),this.converters.set("ZodBoolean",e),this.converters.set("ZodBigInt",e),this.converters.set("ZodEnum",e),this.converters.set("ZodNativeEnum",e),this.converters.set("ZodUnknown",new ir),this.converters.set("ZodAny",new or),this.converters.set("ZodArray",t),this.converters.set("ZodTuple",s),this.converters.set("ZodSet",n),this.converters.set("ZodMap",i),this.converters.set("ZodRecord",i),this.converters.set("ZodObject",this.complexObjectConverter)}getConverter(e){const t=this.getSchemaTypeName(e);return this.converters.get(t)??this.complexObjectConverter}getSchemaTypeName(e){if(Xs(e))return e instanceof c.ZodEffects?this.getSchemaTypeName(e.innerType()):e instanceof c.ZodLazy?this.getSchemaTypeName(e.schema):this.getSchemaTypeName(e.unwrap());const t=e._def.typeName;try{return ar.parse(t)}catch{throw new Error(`Schema type name ${t} is not supported`)}}}class cr{constructor(e){this.typeSchemaResolver=e,this.converterFactory=new ur(this)}converterFactory;convert(e,t){const s=this.typeSchemaResolver?.resolveSchema(e),n=S.unwrapSchema(t);if(Ye(n))return e;let i=n;return S.checkSchemaExtension(s,n)&&u.isNonNullable(s)&&(i=s),this.convertWithType(e,i)}convertWithType(e,t){return this.converterFactory.getConverter(t).convert(e,t)}}class Mt{reverse(e){const t=new d;return this.reverseNode(t,e,e.getType()),t}reverseNode(e,t,s){this.isIdenticalToType(t,s)||(this.reverseBasicProperties(e,t,s),this.reverseTypeReferences(e,t,s),this.reverseItems(e,t,s),this.reverseProperties(e,t,s))}isIdenticalToType(e,t){return u.isNonNullable(e.getBlueId())&&u.isNonNullable(t?.getBlueId())&&e.getBlueId()===t.getBlueId()}reverseBasicProperties(e,t,s){const n=t.getValue();u.isNonNullable(n)&&(u.isNullable(s)||u.isNullable(s.getValue()))&&e.setValue(n),u.isNonNullable(t.getName())&&(u.isNullable(s)||t.getName()!==s.getName())&&e.setName(t.getName()),u.isNonNullable(t.getDescription())&&(u.isNullable(s)||t.getDescription()!==s.getDescription())&&e.setDescription(t.getDescription()),u.isNonNullable(t.getBlueId())&&(u.isNullable(s)||t.getBlueId()!==s.getBlueId())&&e.setBlueId(t.getBlueId())}reverseTypeReferences(e,t,s){const n=(i,o)=>{const l=i(t),a=s?i(s):void 0,p=l?.getBlueId();u.isNonNullable(p)&&(u.isNullable(a?.getBlueId())||p!==a.getBlueId())&&o(e,new d().setBlueId(p))};n(i=>i.getType(),(i,o)=>i.setType(o)),n(i=>i.getItemType(),(i,o)=>i.setItemType(o)),n(i=>i.getKeyType(),(i,o)=>i.setKeyType(o)),n(i=>i.getValueType(),(i,o)=>i.setValueType(o))}reverseItems(e,t,s){const n=t.getItems();if(u.isNullable(n))return;const i=s?.getItems(),o=[];if(u.isNonNullable(i)&&i.length>0){const a=I.calculateBlueIdSync(i);o.push(new d().setBlueId(a))}const l=i?.length||0;for(let a=l;a<n.length;a++){const p=new d;this.reverseNode(p,n[a],void 0),o.push(p)}o.length>0&&e.setItems(o)}reverseProperties(e,t,s){const n=t.getProperties();if(u.isNullable(n))return;const i={};for(const[o,l]of Object.entries(n)){const a=this.getInheritedProperty(o,t,s),p=new d;this.reverseNode(p,l,a),me.isEmptyNode(p)||(i[o]=p)}Object.keys(i).length>0&&e.setProperties(i)}getInheritedProperty(e,t,s){const n=s?.getProperties()?.[e],i=t.getType()?.getProperties()?.[e];if(!(u.isNullable(n)&&u.isNullable(i)))return u.isNullable(n)?i:u.isNullable(i)?n:this.mergeNodes(n,i)}mergeNodes(e,t){const s=e.clone(),n=t.getValue();u.isNonNullable(n)&&s.setValue(n);const i=t.getType();u.isNonNullable(i)&&s.setType(i.clone());const o=t.getItemType();u.isNonNullable(o)&&s.setItemType(o.clone());const l=t.getKeyType();u.isNonNullable(l)&&s.setKeyType(l.clone());const a=t.getValueType();u.isNonNullable(a)&&s.setValueType(a.clone());const p=t.getProperties();if(u.isNonNullable(p)){const h=s.getProperties()||{};for(const[f,b]of Object.entries(p))h[f]=b.clone();s.setProperties(h)}const y=t.getItems();return u.isNonNullable(y)&&s.setItems(y.map(h=>h.clone())),s}}class q extends d{constructor(e){super(e.getName()),this.createFrom(e)}isResolved(){return!0}getMinimalNode(){return new Mt().reverse(this)}getMinimalBlueId(){const e=this.getMinimalNode();return I.calculateBlueIdSync(e)}clone(){const e=super.clone();return new q(e)}createFrom(e){e.getName()!==this.getName()&&this.setName(e.getName()),this.setDescription(e.getDescription()).setType(e.getType()).setItemType(e.getItemType()).setKeyType(e.getKeyType()).setValueType(e.getValueType()).setItems(e.getItems()).setProperties(e.getProperties()).setBlueId(e.getBlueId()).setBlue(e.getBlue()).setInlineValue(e.isInlineValue());const t=e.getValue();t!==void 0&&this.setValue(t)}}class ue{fetchFirstByBlueId(e){const t=this.fetchByBlueId(e);return t&&t.length>0?t[0]:null}}function dr(r){return new class extends ue{fetchByBlueId(e){return r(e)}}}class pr extends ue{nodeProviders;constructor(e){super(),this.nodeProviders=e}fetchByBlueId(e){for(const t of this.nodeProviders){const s=t.fetchByBlueId(e);if(s&&s.length>0)return s}return[]}fetchFirstByBlueId(e){for(const t of this.nodeProviders){const s=t.fetchFirstByBlueId(e);if(s)return s}return null}getNodeProviders(){return this.nodeProviders}}const Pe=z.types.float.options,hr={...Pe,construct:r=>{const e=r.replace(/_/g,"").toLowerCase();if(!u.isPreciseNumberString(e))return new w(e);if(Pe.construct)return Pe.construct(r)}},fr=new z.Type("tag:yaml.org,2002:float",hr),Se=z.types.int.options,gr={...Se,construct:r=>{let e=r;if(e.indexOf("_")!==-1&&(e=e.replace(/_/g,"")),!u.isPreciseNumberString(e))return new N(e);if(Se.construct)return Se.construct(r)}},yr=new z.Type("tag:yaml.org,2002:int",gr),Dt=z.CORE_SCHEMA.extend({implicit:[fr,yr]}),M=r=>{const e=z.load(r,{schema:Dt});return e===void 0?void 0:e},mr=r=>z.dump(r,{schema:Dt,replacer:(e,t)=>{if(P(t)){if(O(t)){const s=new D(Number.MIN_SAFE_INTEGER.toString()),n=new D(Number.MAX_SAFE_INTEGER.toString());if(t.lt(s)||t.gt(n))return t.toString()}return t.toNumber()}return t}}),Ot=`- type:
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("big.js"),u=require("@blue-labs/shared-utils"),c=require("zod"),Yt=require("bs58"),A=require("radash"),Gt=require("js-sha256"),Jt=require("crypto"),kt=require("base32.js"),z=require("js-yaml"),qe=r=>r&&r.__esModule?r:{default:r},re=qe(Yt),Te=qe(Jt);class w extends D{constructor(e){super(e)}}class T extends D{constructor(e){super(e)}}class Ht{static get(e,t,s,n=!0){if(u.isNullable(t)||!t.startsWith("/"))throw new Error(`Invalid path: ${t}`);if(t==="/"){const o=e.getValue();return n&&o!==void 0?o:e}const i=t.substring(1).split("/");return this.getRecursive(e,i,0,s,n)}static getRecursive(e,t,s,n,i){if(s===t.length-1&&!i)return this.getNodeForSegment(e,t[s],n,!1);if(s===t.length){const a=e.getValue();return i&&a!==void 0?a:e}const o=t[s],l=this.getNodeForSegment(e,o,n,!0);if(l)return this.getRecursive(l,t,s+1,n,i)}static getNodeForSegment(e,t,s,n){let i;const o=e.getProperties();if(o&&t in o)i=o[t];else switch(t){case"name":{const l=e.getName();i=new d().setValue(l??null);break}case"description":{const l=e.getDescription();i=new d().setValue(l??null);break}case"type":i=e.getType();break;case"itemType":i=e.getItemType();break;case"keyType":i=e.getKeyType();break;case"valueType":i=e.getValueType();break;case"value":{const l=e.getValue();i=new d().setValue(l??null);break}case"blueId":{const l=e.getBlueId();i=new d().setValue(l??null);break}case"blue":i=e.getBlue();break;case"items":{const l=e.getItems();i=new d().setItems(l);break}case"properties":{const l=e.getProperties();i=new d().setProperties(l);break}case"contracts":{const l=e.getContracts();i=new d().setContracts(l);break}default:{if(/^\d+$/.test(t)){const l=parseInt(t,10),a=e.getItems();a&&l>=0&&l<a.length?i=a[l]:i=void 0}else i=void 0;break}}if(i)return n&&s?this.link(i,s):i}static link(e,t){const s=t(e);return u.isNonNullable(s)?s:e}}const J="name",k="description",de="type",Oe="itemType",Fe="keyType",Re="valueType",ye="value",je="items",L="blueId",$e="blue",Wt=[J,k,de,Oe,Fe,Re,ye,je,L,$e],qt="Text",Xt="Double",Qt="Integer",es="Boolean",ts="List",ss="Dictionary",xe=[qt,Xt,Qt,es],Xe=[...xe,ts,ss],U="DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K",_="7pwXmXYCJtWnd348c2JQGBkm9C4renmZRwxbfaypsx5y",Z="5WNMiV9Knz63B4dVY5JtMyh3FB4FSGqv7ceScvuapdE1",K="4EzhSubEimSQD3zrYHRtobfPPWntUuhEz8YcdxHsi12u",Qe="6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY",et="G7fBT9PSod1RfHLHkpafAGBDVAJMrMhAMY51ERcyXNrj",tt=[U,_,Z,K],le=[...tt,Qe,et];Object.fromEntries(Xe.map((r,e)=>[r,le[e]]));const st=Object.fromEntries(le.map((r,e)=>[r,Xe[e]]));class d{static INTEGER=new d("Integer");name;description;type;itemType;keyType;valueType;value;items;properties;blueId;blue;inlineValue=!1;constructor(e){this.name=e}getName(){return this.name}setName(e){return this.name=e,this}getDescription(){return this.description}setDescription(e){return this.description=e,this}getType(){return this.type}setType(e){return typeof e=="string"?this.type=new d().setValue(e).setInlineValue(!0):this.type=e,this}getItemType(){return this.itemType}setItemType(e){return typeof e=="string"?this.itemType=new d().setValue(e).setInlineValue(!0):this.itemType=e,this}getKeyType(){return this.keyType}setKeyType(e){return typeof e=="string"?this.keyType=new d().setValue(e).setInlineValue(!0):this.keyType=e,this}getValueType(){return this.valueType}setValueType(e){return typeof e=="string"?this.valueType=new d().setValue(e).setInlineValue(!0):this.valueType=e,this}getValue(){const e=this.type?.getBlueId();if(u.isNonNullable(e)&&u.isNonNullable(this.value)){if(e===Z&&typeof this.value=="string")return new T(this.value);if(e===_&&typeof this.value=="string"){const t=new w(this.value),s=parseFloat(t.toString());return new w(s.toString())}else if(e===K&&typeof this.value=="string")return this.value.toLowerCase()==="true"}return this.value}setValue(e){return typeof e=="number"?e%1===0?this.value=new T(e.toString()):this.value=new w(e.toString()):this.value=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}addItems(...e){return this.items||(this.items=[]),this.items.push(...e),this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}addProperty(e,t){return this.properties||(this.properties={}),this.properties[e]=t,this}removeProperty(e){return this.properties&&delete this.properties[e],this}getContractsProperty(){return this.properties?.contracts}getContracts(){return this.getContractsProperty()?.getProperties()}setContracts(e){return u.isNullable(e)?this.removeProperty("contracts"):this.addProperty("contracts",new d().setProperties(e)),this}addContract(e,t){const s=this.getContractsProperty();return u.isNullable(s)?this.addProperty("contracts",new d().addProperty(e,t)):s.addProperty(e,t),this}removeContract(e){const t=this.getContractsProperty();if(t){t.removeProperty(e);const s=t.getProperties();s&&Object.keys(s).length===0&&this.removeProperty("contracts")}return this}getBlueId(){return this.blueId}setBlueId(e){return this.blueId=e,this}getBlue(){return this.blue}setBlue(e){return this.blue=e,this}isInlineValue(){return this.inlineValue}setInlineValue(e){return this.inlineValue=e,this}isResolved(){return!1}get(e,t){return Ht.get(this,e,t)}getAsNode(e){const t=this.get(e);if(t instanceof d)return t;throw new Error(`Value at path ${e} is not a BlueNode: ${t}`)}getAsInteger(e){const t=this.get(e);if(t instanceof T||t instanceof w)return t.toNumber();throw new Error(`Value at path ${e} is not a BigInteger or BigDecimal: ${t}`)}clone(){const e=new d(this.name);return e.description=this.description,e.type=this.type?.clone(),e.itemType=this.itemType?.clone(),e.keyType=this.keyType?.clone(),e.valueType=this.valueType?.clone(),e.value=this.value,e.items=this.items?.map(t=>t.clone()),this.properties&&(e.properties=Object.fromEntries(Object.entries(this.properties).map(([t,s])=>[t,s.clone()]))),e.blueId=this.blueId,e.blue=this.blue?.clone(),e.inlineValue=this.inlineValue,e}toString(){return`BlueNode{name='${this.name}', description='${this.description}', type=${this.type}, itemType=${this.itemType}, keyType=${this.keyType}, valueType=${this.valueType}, value=${this.value}, items=${this.items}, properties=${this.properties}, blueId='${this.blueId}', blue=${this.blue}, inlineValue=${this.inlineValue}}`}}class pe{static MIN_BLUE_ID_LENGTH=41;static MAX_BLUE_ID_LENGTH=45;static BLUE_ID_PATTERN=/^[1-9A-HJ-NP-Za-km-z]{41,45}(?:#\d+)?$/;static isPotentialBlueId(e){if(!e||e.length===0||!this.BLUE_ID_PATTERN.test(e))return!1;const t=e.split("#"),s=t[0],n=s.length;if(n<this.MIN_BLUE_ID_LENGTH||n>this.MAX_BLUE_ID_LENGTH)return!1;try{if(re.default.decode(s).length!==32)return!1}catch{return!1}if(t.length>1)try{if(Number(t[1])<0)return!1}catch{return!1}return!0}}const rs=c.z.string().max(pe.MAX_BLUE_ID_LENGTH,{message:"Blue Id has a maximum length of 45 characters"}).min(pe.MIN_BLUE_ID_LENGTH,{message:"Blue Id has a minimum length of 41 characters"}).refine(r=>{try{return re.default.decode(r),!0}catch{return!1}},{message:"Blue Id must be a valid Base58 string"}),H=c.z.lazy(()=>c.z.record(c.z.unknown()).and(c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:H.optional(),value:c.z.union([c.z.string(),c.z.number(),c.z.boolean()]).optional().nullable(),items:c.z.array(H).optional()}))),ae=c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:H.optional()}),ns=ae.extend({value:c.z.string().optional()}),is=ae.extend({value:c.z.number().optional()}),os=ae.extend({value:c.z.boolean().optional()}),ls=ae.extend({items:c.z.array(c.z.string()).optional()}),as=r=>H.safeParse(r).success,rt=r=>u.isNonNullable(r)&&"blueId"in r&&u.isNonNullable(r.blueId),us=r=>u.isNonNullable(r)&&"name"in r&&u.isNonNullable(r.name),nt=r=>u.isNonNullable(r)&&"items"in r&&u.isNonNullable(r.items),it=r=>u.isNonNullable(r)&&"type"in r&&u.isNonNullable(r.type),ot=r=>u.isNonNullable(r)&&"value"in r&&u.isNonNullable(r.value),cs=(r,e)=>r.required({type:!0}).safeParse(e).success,P=r=>r instanceof D,O=r=>P(r)&&r instanceof T,he=r=>P(r)&&r instanceof w,ds=c.z.lazy(()=>c.z.record(ne)),ps=c.z.lazy(()=>c.z.union([c.z.array(ne),c.z.array(ne).readonly()])),ne=c.z.lazy(()=>c.z.union([u.jsonPrimitiveSchema,ds,ps,c.z.instanceof(D)])),Le=r=>A.isObject(r)&&!A.isArray(r)&&!u.isReadonlyArray(r)&&!P(r),ze=r=>A.isArray(r)||u.isReadonlyArray(r),hs=r=>ze(r)||Le(r)||P(r)||u.isJsonPrimitive(r);class g{static deserialize(e){return g.handleNode(e)}static handleNode(e){if(e===void 0)throw new Error("This is not a valid JSON-like value. Found 'undefined' as a value.");if(Le(e)){const t=new d,s={};return Object.entries(e).forEach(([n,i])=>{switch(n){case J:if(i==null)t.setName(void 0);else{if(typeof i!="string")throw new Error(`The ${J} field must be a string.`);t.setName(i)}break;case k:if(i==null)t.setDescription(void 0);else{if(typeof i!="string")throw new Error(`The ${k} field must be a string.`);t.setDescription(i)}break;case de:t.setType(g.handleNode(i));break;case Oe:t.setItemType(g.handleNode(i));break;case Fe:t.setKeyType(g.handleNode(i));break;case Re:t.setValueType(g.handleNode(i));break;case ye:t.setValue(g.handleValue(i));break;case L:if(typeof i!="string")throw new Error(`The ${L} field must be a string.`);t.setBlueId(i);break;case je:t.setItems(g.handleArray(i));break;case $e:t.setBlue(g.handleNode(i));break;default:s[n]=g.handleNode(i);break}}),Object.keys(s).length>0&&t.setProperties(s),t}else{if(ze(e))return new d().setItems(g.handleArray(e));{const t=e;return new d().setValue(g.handleValue(t)).setInlineValue(!0)}}}static handleValue(e){if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="number"||P(e))if(O(e)||Number.isSafeInteger(e)){const t=new T(e.toString()),s=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER;return t.lt(s)?new T(s.toString()):t.gt(n)?new T(n.toString()):t}else{const t=parseFloat(e.toString());return new w(t.toString())}else if(typeof e=="boolean")return e;throw new Error(`Can't handle node: ${JSON.stringify(e)}`)}static handleArray(e){if(e!=null){if(A.isObject(e)&&!Array.isArray(e))return[g.handleNode(e)];if(Array.isArray(e))return e.map(g.handleNode);throw new Error("Expected an array node")}}}function fs(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var ve,Je;function gs(){return Je||(Je=1,ve=function r(e){if(typeof e=="number"&&isNaN(e))throw new Error("NaN is not allowed");if(typeof e=="number"&&!isFinite(e))throw new Error("Infinity is not allowed");return e===null||typeof e!="object"?JSON.stringify(e):e.toJSON instanceof Function?r(e.toJSON()):Array.isArray(e)?`[${e.reduce((n,i,o)=>`${n}${o===0?"":","}${r(i===void 0||typeof i=="symbol"?null:i)}`,"")}]`:`{${Object.keys(e).sort().reduce((s,n)=>{if(e[n]===void 0||typeof e[n]=="symbol")return s;const i=s.length===0?"":",";return`${s}${i}${r(n)}:${r(e[n])}`},"")}}`}),ve}var ys=gs();const ms=fs(ys);class lt{static canonicalize(e){return ms(e)}}const Be=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;class Ue{static instance;browserCrypto;constructor(){this.browserCrypto=this.initBrowserCrypto()}static getInstance(){return this.instance||(this.instance=new Ue),this.instance}initBrowserCrypto(){return Be?null:"crypto"in globalThis?globalThis.crypto:null}hasNodeCrypto(){return Be&&!!Te.default&&typeof Te.default.createHash=="function"}getBrowserCrypto(){return this.browserCrypto}getNodeCrypto(){return Be?Te.default:null}}class at{cryptoEnv=Ue.getInstance();applySync(e){const t=this.canonicalizeInput(e),s=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):this.sha256SyncBrowser(t);return re.default.encode(s)}async apply(e){const t=this.canonicalizeInput(e),s=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):await this.sha256Async(t);return re.default.encode(s)}canonicalizeInput(e){const t=lt.canonicalize(e);if(typeof t!="string")throw new Error("Canonized value must be a string");return t}sha256Sync(e){const t=this.cryptoEnv.getNodeCrypto();if(!t)throw new Error("Synchronous SHA-256 is not available in this environment");const s=t.createHash("sha256").update(e).digest();return new Uint8Array(s)}sha256SyncBrowser(e){return new Uint8Array(Gt.sha256.arrayBuffer(e))}async sha256Async(e){if(this.cryptoEnv.hasNodeCrypto())return Promise.resolve(this.sha256Sync(e));const t=this.cryptoEnv.getBrowserCrypto();if(!t)throw new Error("crypto is not available in this environment");const n=new TextEncoder().encode(e),i=await t.subtle.digest("SHA-256",n);return new Uint8Array(i)}}class m{static get(e,t="official"){const s=e.getValue(),n=this.handleValue(s);if(n!==void 0&&t==="simple")return n;const i=e.getItems()?.map(G=>m.get(G,t));if(i!==void 0&&t==="simple")return i;const o=e.getName(),l=e.getDescription();if(t==="original"&&o===void 0&&l===void 0){if(n!==void 0)return n;if(i!==void 0)return i}const a={};o!==void 0&&(a[J]=o),l!==void 0&&(a[k]=l);const p=e.getType();if(t==="official"&&s!==void 0&&p===void 0){const G=this.inferTypeBlueId(s);G!==null&&(a[de]={[L]:G})}else p!==void 0&&(a[de]=m.get(p,t));const y=e.getItemType();y!==void 0&&(a[Oe]=m.get(y,t));const h=e.getKeyType();h!==void 0&&(a[Fe]=m.get(h,t));const f=e.getValueType();f!==void 0&&(a[Re]=m.get(f,t)),n!==void 0&&(a[ye]=n),i!==void 0&&(a[je]=i);const b=e.getBlueId();b!==void 0&&(a[L]=b);const R=e.getBlue();R!==void 0&&(a[$e]=R);const Y=e.getProperties();return Y!==void 0&&Object.entries(Y).forEach(([G,Kt])=>{a[G]=m.get(Kt,t)}),a}static handleValue(e){if(P(e)){if(O(e)){const t=new D(Number.MIN_SAFE_INTEGER.toString()),s=new D(Number.MAX_SAFE_INTEGER.toString());if(e.lt(t)||e.gt(s))return e.toString()}return e.toNumber()}return e}static inferTypeBlueId(e){return typeof e=="string"?U:P(e)?O(e)?Z:_:typeof e=="boolean"?K:null}}const Is=r=>u.isJsonPrimitive(r)&&u.isNonNullable(r);class I{static INSTANCE=new I(new at);hashProvider;constructor(e){this.hashProvider=e}static calculateBlueId(e){if(Array.isArray(e)){const s=e.map(n=>m.get(n));return I.INSTANCE.calculate(s)}const t=m.get(e);return I.INSTANCE.calculate(t)}static calculateBlueIdSync(e){if(Array.isArray(e)){const s=e.map(n=>m.get(n));return I.INSTANCE.calculateSync(s)}const t=m.get(e);return I.INSTANCE.calculateSync(t)}calculate(e){const t=this.cleanStructure(e);if(t===void 0)throw new Error("Object after cleaning cannot be null or undefined.");return this.internalCalculate(t,!1)}calculateSync(e){const t=this.cleanStructure(e);if(t===void 0)throw new Error("Object after cleaning cannot be null or undefined.");return this.internalCalculate(t,!0)}internalCalculate(e,t){return Is(e)||P(e)?this.applyHash(e.toString(),t):Array.isArray(e)||u.isReadonlyArray(e)?this.calculateList(e,t):this.calculateMap(e,t)}calculateMap(e,t){if(e[L]!==void 0)return e[L];const n=Object.keys(e).map(o=>{const l=e[o];if([J,ye,k].includes(o))return t?[o,l]:Promise.resolve([o,l]);{const a=this.internalCalculate(l,t);return t?[o,{blueId:a}]:Promise.resolve(a).then(p=>[o,{blueId:p}])}}),i=o=>{const l={};for(const[a,p]of o)l[a]=p;return this.applyHash(l,t)};return t?i(n):Promise.all(n).then(i)}calculateList(e,t){if(e.length===0)throw new Error("Cannot calculate BlueId for an empty list.");let s=this.internalCalculate(e[0],t);const n=(i,o)=>t?this.applyHash([{blueId:i},{blueId:o}],!0):Promise.all([i,o]).then(([l,a])=>this.applyHash([{blueId:l},{blueId:a}],!1));for(let i=1;i<e.length;i++){const o=this.internalCalculate(e[i],t);s=n(s,o)}return s}applyHash(e,t){return t?this.hashProvider.applySync(e):this.hashProvider.apply(e)}cleanStructure(e){if(e!=null){if(u.isJsonPrimitive(e)||P(e))return e;if(Array.isArray(e)||u.isReadonlyArray(e)){const t=e.map(s=>this.cleanStructure(s)).filter(u.isNonNullable);return t.length>0?t:void 0}else if(typeof e=="object"){const t={};for(const s in e){const n=this.cleanStructure(e[s]);n!=null&&(t[s]=n)}return Object.keys(t).length>0?t:void 0}else return e}}}class bs{static convert(e){const t=re.default.decode(e),s=new Uint8Array(2+t.length);s[0]=18,s[1]=32,s.set(t,2);const n=new Uint8Array(2+s.length);return n[0]=1,n[1]=85,n.set(s,2),"b"+new kt.Encoder({type:"rfc4648",lc:!0}).write(n).finalize().replace(/=/g,"")}}class E{static transform(e,t){const s=t(e.clone()),n=s.getType();n!==void 0&&s.setType(E.transform(n,t));const i=s.getItemType();i!==void 0&&s.setItemType(E.transform(i,t));const o=s.getKeyType();o!==void 0&&s.setKeyType(E.transform(o,t));const l=s.getValueType();l!==void 0&&s.setValueType(E.transform(l,t));const a=s.getItems();if(a!==void 0){const y=a.map(h=>E.transform(h,t));s.setItems(y)}const p=s.getProperties();if(p!==void 0){const y=Object.keys(p).reduce((h,f)=>(h[f]=E.transform(p[f],t),h),{});s.setProperties(y)}return s}}const F=r=>!!r&&typeof r=="object"&&!Array.isArray(r)&&!(r instanceof d),C=r=>r instanceof T||r instanceof w,Ns=r=>r.replace(/~1/g,"/").replace(/~0/g,"~");function Q(r){if(r==="/")return[];if(!r.startsWith("/"))throw new Error(`Path must start with '/': ${r}`);return r.split("/").slice(1).map(Ns)}function W(r){if(r==="-")return-1;const e=typeof r=="number"?r:parseInt(r,10);if(isNaN(e))throw new Error(`Invalid array index (NaN) from '${r}'`);if(!Number.isFinite(e))throw new Error(`Invalid array index '${r}' results in non-finite number ${e}`);return e}function ut(r,e,t,s=!0){switch(e){case"name":return t?s?r.getName()??null:r:r.getName();case"description":return t?s?r.getDescription():r:r.getDescription();case"type":return r.getType();case"itemType":return r.getItemType();case"keyType":return r.getKeyType();case"valueType":return r.getValueType();case"value":return t?s?r.getValue()??null:r:r.getValue();case"blueId":return t?s?r.getBlueId()??null:r:r.getBlueId();case"blue":return r.getBlue();case"items":return r.getItems();case"properties":return r.getProperties();case"contracts":return r.getContracts();default:return}}function ke(r,e,t=!0){if(r instanceof d){const s=ut(r,e,!0,t);if(s!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(e))return s;if(/^-?\d+$/.test(e)&&e!=="-"){const i=r.getItems(),o=parseInt(e,10);return i&&o>=0&&o<i.length?i[o]:void 0}const n=r.getProperties();return n&&e in n?n[e]:void 0}if(Array.isArray(r)){if(e==="-")return;const s=W(e);return s>=0&&s<r.length?r[s]:void 0}if(F(r))return r[e]}function ee(r,e){if(e.length===0)return{parent:r,key:"value",actualTarget:r.getValue()??r};let t=r;for(let n=0;n<e.length-1;++n){const i=e[n],o=ke(t,i);if(o===void 0)throw new Error(`Cannot resolve '/${e.slice(0,n+1).join("/")}'`);t=o}const s=e[e.length-1];if(t instanceof d){const n=ke(t,s,!1);if((typeof n!="object"||n===null||C(n))&&!(n instanceof d)&&!Array.isArray(n)&&["name","description","value","blueId"].includes(s))return{parent:t,key:s,actualTarget:n}}return Array.isArray(t)&&s==="-"?{parent:t,key:"-"}:t instanceof d&&t.getItems()&&s==="-"?{parent:t,key:"-"}:{parent:t,key:Array.isArray(t)?W(s):s}}function _e(r,e){if(r instanceof d){const t=e,s=ut(r,t,!1);if(s!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(t))return s;if(typeof e=="number"||typeof e=="string"&&/^\d+$/.test(e)){const n=r.getItems(),i=typeof e=="number"?e:parseInt(e,10);if(n&&i>=0&&i<n.length)return n[i]}return r.getProperties()?.[t]}return Array.isArray(r)||F(r)?r[e]:r}function B(r){if(r instanceof d)return r;if(r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean"||C(r))return g.deserialize(r);const e=Ae(r);return g.deserialize(e)}function Ae(r){if(r===void 0)return null;if(r===null||typeof r!="object")return r;if(Array.isArray(r))return r.map(Ae);const e={};for(const[t,s]of Object.entries(r))e[t]=Ae(s);return e}function Ze(r,e,t){if(r instanceof d){const s=e;switch(s){case"name":r.setName(t);return;case"description":r.setDescription(t);return;case"type":r.setType(t instanceof d||typeof t=="string"||t===void 0?t:B(t));return;case"itemType":r.setItemType(t instanceof d||typeof t=="string"||t===void 0?t:B(t));return;case"keyType":r.setKeyType(t instanceof d||typeof t=="string"||t===void 0?t:B(t));return;case"valueType":r.setValueType(t instanceof d||typeof t=="string"||t===void 0?t:B(t));return;case"value":{const n=t;r.setValue(n===void 0?null:n);return}case"blueId":r.setBlueId(t);return;case"blue":r.setBlue(t instanceof d||t===void 0?t:B(t));return;case"items":r.setItems(t);return;case"properties":r.setProperties(t);return;case"contracts":r.setContracts(t);return;default:{if(t===void 0){const n=r.getProperties();n&&s in n&&delete n[s]}else r.getProperties()||r.setProperties({}),r.addProperty(s,t instanceof d?t:B(t));return}}}Array.isArray(r)?r.splice(W(e),1):F(r)&&(t===void 0?delete r[e]:r[e]=t)}function Ts(r,e,t,s){let n=-1;if(e!=="-"&&(n=typeof e=="number"?e:parseInt(e,10),isNaN(n)))throw new Error(`Invalid numeric key for BlueNode item operation: ${e}`);if(n<-1)throw new Error(`Invalid array index for BlueNode items: ${n}`);let i=r.getItems();if(i||(i=[],r.setItems(i)),!s&&n!==-1&&n>i.length)throw new Error(`ADD operation failed: Target array index '${n}' is greater than array length ${i.length}.`);if(e==="-")i.push(t);else if(s){if(n>=0)if(n<i.length)i[n]=t;else{for(let o=i.length;o<n;o++)i.push(g.deserialize(null));i.push(t)}}else i.splice(n,0,t)}function fe(r,e,t,s){if(Array.isArray(r)){const n=e==="-"?r.length:W(e);if(!s&&n>r.length)throw new Error(`ADD operation failed: Target array index '${n}' is greater than array length ${r.length}. Path involving key '${e}'.`);if(n<0&&e!=="-")throw new Error(`Invalid negative array index: ${e}`);const i=B(t);if(s){if(n>=0&&n<r.length)r[n]=i;else if(n>=r.length){for(let o=r.length;o<n;o++)r.push(g.deserialize(null));r.push(i)}}else r.splice(n,0,i);return}if(r instanceof d){e==="-"||typeof e=="number"&&!isNaN(e)||typeof e=="string"&&/^\d+$/.test(e)?Ts(r,e,B(t),s):Ze(r,e,t);return}if(F(r)){r[e]=B(t);return}throw new Error(`Cannot insert into parent of type ${typeof r}`)}function vs(r,e){if(Array.isArray(r)){const t=W(e);t===-1&&e==="-"?r.length>0&&r.pop():t>=0&&t<r.length&&r.splice(t,1);return}if(r instanceof d){if(typeof e=="number"||typeof e=="string"&&/^-?\d+$/.test(e)){const t=r.getItems();if(t){const s=W(e);s===-1&&e==="-"?t.length>0&&t.pop():s>=0&&s<t.length&&t.splice(s,1),t.length===0&&r.setItems(void 0);return}}Ze(r,e,void 0)}else F(r)&&delete r[e]}function Ve(r){if(r instanceof d)return r.clone();if(Array.isArray(r))return r.map(t=>Ve(t));if(F(r)){const e={};return Object.keys(r).forEach(t=>{e[t]=Ve(r[t])}),e}return r}function $(r,e){if(r===e||r instanceof d&&(r.isInlineValue()||r.getValue()!==void 0)&&$(r.getValue()??null,e)||e instanceof d&&(e.isInlineValue()||e.getValue()!==void 0)&&$(r,e.getValue()??null))return!0;if(r instanceof d&&e instanceof d||C(r)&&C(e)||C(r)&&typeof e=="number"||typeof r=="number"&&C(e))return r.toString()===e.toString();if(Array.isArray(r)&&Array.isArray(e))return r.length===e.length&&r.every((t,s)=>$(t,e[s]));if(F(r)&&F(e)){const t=Object.keys(r),s=Object.keys(e);return t.length===s.length&&t.every(n=>$(r[n],e[n]))}return!1}function ct(r,e){const{parent:t,key:s}=ee(r,Q(e));return _e(t,s)}function dt(r,e,t){const s=Q(e);if(s.length===0&&e==="/"){const o=B(t);r.setValue(o.getValue()??null),o.getItems()?r.setItems(o.getItems()):r.setItems(void 0);return}const{parent:n,key:i}=ee(r,s);fe(n,i,t,!0)}function Bs(r,e,t){const s=Q(e);if(s.length===0&&e==="/"){if(r.getItems()&&Array.isArray(t)){const o=B(t);o.getItems()?(r.setItems(o.getItems()),r.setValue(null)):(r.setValue(o.getValue()??null),r.setItems(void 0))}else{const o=B(t);r.setValue(o.getValue()??null),o.getItems()&&r.setItems(o.getItems())}return!0}const{parent:n,key:i}=ee(r,s);return fe(n,i,t,!1),!0}function ws(r,e,t){const s=Q(e);if(s.length===0&&e==="/"){const l=B(t);return r.setValue(l.getValue()??null),l.getItems()?r.setItems(l.getItems()):r.setItems(void 0),!0}const{parent:n,key:i,actualTarget:o}=ee(r,s);if(o!==void 0&&n instanceof d)Ze(n,i,t);else{const l=_e(n,i),a=Array.isArray(n)||n instanceof d&&n.getItems()&&(typeof i=="number"||typeof i=="string"&&/^\d+$/.test(i));if(l===void 0){if(a)throw new Error(`REPLACE failed: Target array index '${i.toString()}' is out of bounds or does not exist at path '${e}'.`);fe(n,i,t,!0)}else fe(n,i,t,!0)}return!0}function pt(r,e){const t=Q(e);if(t.length===0&&e==="/")return r.setValue(null),r.setItems(void 0),r.setProperties(void 0),!0;const{parent:s,key:n}=ee(r,t);return vs(s,n),!0}function Ps(r,e,t){const s=Ve(ct(r,e));return dt(r,t,s),!0}function Ss(r,e,t){const s=Q(e),{parent:n,key:i}=ee(r,s),o=_e(n,i);if(o===void 0)throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);return pt(r,e)?(dt(r,t,o),!0):!1}function Es(r,e,t){const s=ct(r,e);let n=t;if(s instanceof d)if((t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||C(t))&&(s.isInlineValue()||s.getValue()!==void 0)){if(!$(s.getValue()??null,t))throw new Error(`TEST failed at '${e}': Expected ${JSON.stringify(t)}, got ${JSON.stringify(s.getValue()??null)}`);return!0}else typeof t=="object"&&!(t instanceof d)&&(n=B(t));else if(C(s)&&typeof t=="number")s instanceof T?n=new T(t.toString()):s instanceof w&&(n=new w(t.toString()));else if((s===null||typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&C(t)){const i=t;!$(s,i.toString())&&(typeof s=="number"&&parseFloat(i.toString()))}if(!$(s,n)){const i=s instanceof d?s.toString():JSON.stringify(s),o=n instanceof d?n.toString():JSON.stringify(n);throw new Error(`TEST failed at '${e}': Expected ${o}, got ${i}`)}return!0}function As(r,e){switch(e.op){case"add":return Bs(r,e.path,e.val);case"replace":return ws(r,e.path,e.val);case"remove":return pt(r,e.path);case"copy":return Ps(r,e.from,e.path);case"move":return Ss(r,e.from,e.path);case"test":return Es(r,e.path,e.val)}}function Vs(r,e,t=!1){const s=t?r:r.clone();return As(s,e),s}const we=Symbol.for("zod-schema-annotations");function Cs(){if(typeof globalThis<"u")return globalThis;if(typeof global<"u")return global;if(typeof window<"u")return window;if(typeof self<"u")return self;throw new Error("Unable to locate global object")}function ht(){const r=Cs();return we in r||(r[we]=new WeakMap),r[we]}function ue(r,e){const t=ht(),s=t.get(r)||{};return t.set(r,{...s,...e}),r}const V=r=>ht().get(r),ft=r=>e=>{const t=V(e);return ue(e,{...t,blueDescription:r})},gt=r=>{const e=V(r);return u.isNonNullable(e)&&A.isString(e.blueDescription)?e.blueDescription:null},Ms=r=>ft(r)(c.z.string().optional()),Ds=c.z.union([c.z.string(),c.z.boolean()]),yt=r=>e=>{const t=V(e);return ue(e,{...t,blueId:r})},mt=r=>{const e=V(r),t=Ds.safeParse(e?.blueId);return t.success?t.data:null},Os=r=>yt(r??!0)(c.z.string()),It=r=>e=>{const t=V(e);return ue(e,{...t,blueName:r})},bt=r=>{const e=V(r);return u.isNonNullable(e)&&A.isString(e.blueName)?e.blueName:null},Fs=r=>{const e=c.z.string().optional();return It(r)(e)},Nt=()=>r=>{const e=V(r);return ue(r,{...e,blueNode:!0})},Tt=r=>{const e=V(r);return u.isNonNullable(e)&&u.isNonNullable(e.blueNode)&&e.blueNode===!0?e.blueNode:null},Ke=r=>!!Tt(r),Rs=()=>{const r=c.z.instanceof(d);return Nt()(r)},js=c.z.object({value:c.z.array(c.z.string()).optional(),defaultValue:c.z.string().optional()}),vt=r=>{const e=V(r),t=js.passthrough().safeParse(e?.typeBlueId);return t.success?t.data:null},$s=r=>e=>{const t=V(e),s=typeof r=="string"?{value:[r]}:r;return ue(e,{...t,typeBlueId:{...t?.typeBlueId||{},...s}})};class ie{static resolveBlueId(e){const t=vt(e);if(u.isNullable(t))return null;const s=t.defaultValue;if(u.isNonNullable(s))return s;const n=t.value?.[0];return u.isNonNullable(n)?n:ie.getRepositoryBlueId(t,e)}static getRepositoryBlueId(e,t){throw new Error("Not implemented")}}class S{static isTypeOf(e,t,s){const n=ie.resolveBlueId(t),i=e.getType()?.getBlueId();if(u.isNullable(n)||u.isNullable(i))return!1;if(n===i)return!0;if(s?.checkSchemaExtensions&&u.isNonNullable(s.typeSchemaResolver)){const o=s.typeSchemaResolver.resolveSchema(e);return S.checkSchemaExtension(o,t,{typeSchemaResolver:s.typeSchemaResolver})}return!1}static checkSchemaExtension(e,t,s){if(!u.isNonNullable(e))return!1;const n=S.unwrapSchema(e),i=S.unwrapSchema(t);return u.isNonNullable(s?.typeSchemaResolver)?s.typeSchemaResolver.isSchemaExtendedFrom(n,i):!1}static isWrapperType(e){return e instanceof c.ZodOptional||e instanceof c.ZodNullable||e instanceof c.ZodReadonly||e instanceof c.ZodBranded||e instanceof c.ZodEffects||e instanceof c.ZodLazy}static unwrapSchema(e){return Ke(e)?e:S.isWrapperType(e)?e instanceof c.ZodEffects?S.unwrapSchema(e.innerType()):e instanceof c.ZodLazy?S.unwrapSchema(e.schema):S.unwrapSchema(e.unwrap()):e}}function He(r,e){const t=r.getType();if(t===void 0)return;const s=t.getBlueId();if(s!==void 0){if(le.includes(s)){const i=st[s];return new d().setBlueId(s).setName(i)}const n=e.fetchByBlueId(s);if(!n||n.length===0)return;if(n.length>1)throw new Error(`Expected a single node for type with blueId '${s}', but found multiple.`);return n[0]}return t}function N(r,e,t){const s=I.calculateBlueIdSync(r),n=I.calculateBlueIdSync(e);if(s===n)return!0;if(s&&le.includes(s)){let a=e;for(;a!==void 0;){if(I.calculateBlueIdSync(a)===s)return!0;a=He(a,t)}return!1}let i=r;const o=r.getBlueId();if(o){const a=t.fetchByBlueId(o);a&&a.length===1&&(i=a[0])}let l=i;for(;l!==void 0;){if(I.calculateBlueIdSync(l)===n)return!0;l=He(l,t)}return!1}function xs(r,e){return tt.some(t=>{const s=new d().setBlueId(t);return N(r,s,e)})}function Ls(r,e){const t=new d().setBlueId(U);return N(r,t,e)}function zs(r,e){const t=new d().setBlueId(Z);return N(r,t,e)}function Us(r,e){const t=new d().setBlueId(_);return N(r,t,e)}function _s(r,e){const t=new d().setBlueId(K);return N(r,t,e)}function Bt(r,e){const t=new d().setBlueId(Qe);return N(r,t,e)}function wt(r,e){const t=new d().setBlueId(et);return N(r,t,e)}function Zs(r,e){return xe.some(t=>{const s=new d().setName(t);return N(r,s,e)})}function Ks(r,e){for(const t of xe){const s=new d().setName(t);if(N(r,s,e))return t}throw new Error(`Cannot determine the basic type for node of type "${r.getName()||"unknown"}".`)}class Pt{blueIdMap=new Map;nodeProvider;constructor(e=[],t){this.nodeProvider=t?.nodeProvider??null,this.registerSchemas(e)}registerSchemas(e){for(const t of e)this.registerSchema(t)}registerSchema(e){const t=ie.resolveBlueId(e);if(u.isNonNullable(t)){if(this.blueIdMap.has(t))throw new Error(`Duplicate BlueId value: ${t}`);this.blueIdMap.set(t,e)}}setNodeProvider(e){this.nodeProvider=e}resolveSchema(e){const t=this.getEffectiveBlueId(e);return u.isNullable(t)?null:this.blueIdMap.get(t)}isSchemaExtendedFrom(e,t){if(u.isNullable(e))return!1;const s=this.getBlueIdForSchema(e),n=this.getBlueIdForSchema(t);if(u.isNullable(s)||u.isNullable(n))return!1;if(s===n)return!0;if(u.isNonNullable(this.nodeProvider))try{const i=new d().setBlueId(s),o=new d().setBlueId(n);if(N(i,o,this.nodeProvider))return!0}catch{}return!1}getBlueIdForSchema(e){if(u.isNullable(e))return null;const t=ie.resolveBlueId(e);if(u.isNonNullable(t))return t;for(const[s,n]of this.blueIdMap)if(n===e||n._def===e._def)return s;return null}getEffectiveBlueId(e){const t=e.getType();return u.isNonNullable(t)&&u.isNonNullable(t.getBlueId())?t.getBlueId():u.isNonNullable(t)?I.calculateBlueIdSync(t):null}getBlueIdMap(){return new Map(this.blueIdMap)}}const v={NAME:"name",DESCRIPTION:"description",TYPE:"type",BLUE_ID:"blue_id",KEY_TYPE:"key_type",VALUE_TYPE:"value_type",ITEM_TYPE:"item_type",VALUE:"value",PROPERTIES:"properties",BLUE:"blue",ITEMS:"items"};class me{static isEmptyNode(e){return this.hasFieldsAndMayHaveFields(e)}static hasBlueIdOnly(e){return this.hasFieldsAndMayHaveFields(e,new Set([v.BLUE_ID]))}static hasItemsOnly(e){return this.hasFieldsAndMayHaveFields(e,new Set([v.ITEMS]))}static isValidValueNode(e){const t=e.getValue(),s=e.getProperties(),n=e.getItems();return u.isNonNullable(t)&&u.isNullable(s)&&u.isNullable(n)}static textNode(e){return new d().setType(new d().setBlueId(U)).setValue(e)}static integerNode(e){const t=e instanceof T?e:new T(e.toString());return new d().setType(new d().setBlueId(Z)).setValue(t)}static doubleNode(e){const t=e instanceof w?e:new w(e.toString());return new d().setType(new d().setBlueId(_)).setValue(t)}static booleanNode(e){return new d().setType(new d().setBlueId(K)).setValue(e)}static hasFieldsAndMayHaveFields(e,t=new Set,s=new Set){for(const n of Object.values(v)){const i=u.isNonNullable(this.getFieldValue(e,n));if(t.has(n)){if(!i)return!1}else if(!s.has(n)){if(i)return!1}}return!0}static getFieldValue(e,t){switch(t){case v.NAME:return e.getName();case v.TYPE:return e.getType();case v.VALUE:return e.getValue();case v.DESCRIPTION:return e.getDescription();case v.PROPERTIES:return e.getProperties();case v.BLUE:return e.getBlue();case v.ITEMS:return e.getItems();case v.KEY_TYPE:return e.getKeyType();case v.VALUE_TYPE:return e.getValueType();case v.ITEM_TYPE:return e.getItemType();case v.BLUE_ID:return e.getBlueId();default:throw new Error(`Unknown field: ${t}`)}}}class Ie{}class te{static convert(e){const t=new Ce;return te.traverseNode(e,"",t),t.build()}static traverseNode(e,t,s){if(!e)return;const n=e.getProperties(),i=e.getItems(),o=n!==void 0&&Object.keys(n).length>0,l=i!==void 0&&i.length>0;if(!o&&!l){s.addPath(t===""?"/":t);return}if(n)for(const[a,p]of Object.entries(n)){const y=`${t}/${a}`;te.traverseNode(p,y,s)}if(i)for(let a=0;a<i.length;a++){const p=`${t}/${a}`;te.traverseNode(i[a],p,s)}}}function We(r,e){const t=r.split(e),s=[...t].reverse().findIndex(i=>i!==""),n=s===-1?0:t.length-s;return t.slice(0,n)}class be extends Ie{allowedPaths;maxDepth;currentPath=[];constructor(e,t){super(),this.allowedPaths=e,this.maxDepth=t}shouldExtendPathSegment(e){if(this.currentPath.length>=this.maxDepth)return!1;const t=this.normalizePath(this.getCurrentFullPath()+"/"+e);return this.isAllowedPath(t)}shouldMergePathSegment(e){return this.shouldExtendPathSegment(e)}isAllowedPath(e){for(const t of this.allowedPaths)if(this.matchesAllowedPath(t,e))return!0;return!1}matchesAllowedPath(e,t){const s=We(e,"/"),n=We(t,"/");if(n.length>s.length)return!1;for(let i=1;i<n.length;i++)if(s[i]!=="*"&&s[i]!==n[i])return!1;return!0}enterPathSegment(e){this.currentPath.push(e)}exitPathSegment(){this.currentPath.length>0&&this.currentPath.pop()}getCurrentFullPath(){return"/"+this.currentPath.join("/")}normalizePath(e){return"/"+e.split("/").filter(t=>t!=="").join("/")}static withMaxDepth(e){const t=new Ce().setMaxDepth(e);for(let s=1;s<=e;s++){const n="/"+Array(s).fill("*").join("/");t.addPath(n)}return t.build()}static withSinglePath(e){return new Ce().addPath(e).build()}static fromNode(e){return te.convert(e)}}class Ce{allowedPaths=new Set;maxDepth=Number.MAX_SAFE_INTEGER;addPath(e){return this.allowedPaths.add(e),this}setMaxDepth(e){return this.maxDepth=e,this}build(){return new be(this.allowedPaths,this.maxDepth)}}class Ys extends Ie{shouldExtendPathSegment(){return!0}shouldMergePathSegment(){return!0}enterPathSegment(){}exitPathSegment(){}}class Ne extends Ie{limits;constructor(e){super(),this.limits=e}shouldExtendPathSegment(e,t){return this.limits.every(s=>s.shouldExtendPathSegment(e,t))}shouldMergePathSegment(e,t){return this.limits.every(s=>s.shouldMergePathSegment(e,t))}enterPathSegment(e,t){this.limits.forEach(s=>{s.enterPathSegment(e,t)})}exitPathSegment(){this.limits.forEach(e=>{e.exitPathSegment()})}static of(...e){return new Ne(e)}}const j=new Ys;class Gs{blue;constructor(e){this.blue=e}matchesType(e,t,s=j){const n=t.getType();if(this.matchesImplicitStructure(e,n))return!0;const i=be.fromNode(t),o=Ne.of(s,i),l=this.extendAndResolve(e,o),a=this.blue.resolve(t,o);return this.verifyMatch(l,t,o)&&this.recursiveValueComparison(l,a)}extendAndResolve(e,t){const s=e.clone(),n=s.clone();this.blue.extend(n,t);const i=this.blue.resolve(n,t);return this.restoreMissingStructure(i,s),i}restoreMissingStructure(e,t){const s=t.getItems(),n=e.getItems();if(s&&s.length>0)if(!n||n.length===0)e.setItems(s.map(a=>a.clone()));else for(let a=0;a<Math.min(n.length,s.length);a++)this.restoreMissingStructure(n[a],s[a]);const i=t.getProperties();if(i){let a=e.getProperties();a||(a={},e.setProperties(a));for(const[p,y]of Object.entries(i)){const h=a[p];h===void 0?a[p]=y.clone():this.restoreMissingStructure(h,y)}}const o=t.getBlueId();e.getBlueId()===void 0&&o!==void 0&&e.setBlueId(o);const l=t.getValue();e.getValue()===void 0&&l!==void 0&&e.setValue(l)}verifyMatch(e,t,s){const n=t.getType();if(this.matchesImplicitStructure(e,n))return!0;const i=e.clone().setType(t.clone());try{this.blue.resolve(i,s)}catch{return!1}return!0}recursiveValueComparison(e,t){const s=t.getType(),n=this.matchesImplicitStructure(e,s);if(s&&!n){const h=e.getType();if(!h||!N(h,s,this.blue.getNodeProvider()))return!1}const i=t.getBlueId();if(!n&&i!==void 0){const h=e.getBlueId(),f=e.getType()?.getBlueId();if(h!==void 0){if(i!==h)return!1}else if(f===void 0||i!==f)return!1}const o=t.getValue();if(o!==void 0){const h=e.getValue();if(h===void 0)return!1;if(P(h)&&P(o)){if(!h.eq(o))return!1}else if(h!==o)return!1}const l=t.getItems();if(l!==void 0){const h=e.getItems()??[];for(let f=0;f<l.length;f++)if(f<h.length){if(!this.recursiveValueComparison(h[f],l[f]))return!1}else if(this.hasValueInNestedStructure(l[f]))return!1}const a=t.getItemType();if(a!==void 0){const h=e.getItems()??[];for(const f of h)if(!this.recursiveValueComparison(f,a))return!1}const p=t.getProperties();if(p!==void 0){const h=e.getProperties()??{};for(const[f,b]of Object.entries(p))if(f in h){if(!this.recursiveValueComparison(h[f],b))return!1}else if(this.hasValueInNestedStructure(b))return!1}const y=t.getValueType();if(y!==void 0){const h=Object.values(e.getProperties()??{});for(const f of h)if(!this.recursiveValueComparison(f,y))return!1}return!0}hasValueInNestedStructure(e){if(e.getValue()!==void 0)return!0;const t=e.getItems();if(t!==void 0){for(const n of t)if(this.hasValueInNestedStructure(n))return!0}const s=e.getProperties();if(s!==void 0){for(const n of Object.values(s))if(this.hasValueInNestedStructure(n))return!0}return!1}matchesImplicitStructure(e,t){return t===void 0||e.getType()!==void 0?!1:Bt(t,this.blue.getNodeProvider())?this.isImplicitListStructure(e):wt(t,this.blue.getNodeProvider())?this.isImplicitDictionaryStructure(e):!1}isImplicitListStructure(e){return e.getItems()!==void 0&&e.getValue()===void 0}isImplicitDictionaryStructure(e){return e.getProperties()!==void 0&&e.getValue()===void 0}}const Js=r=>r instanceof c.ZodOptional||r instanceof c.ZodNullable||r instanceof c.ZodReadonly||r instanceof c.ZodBranded||r instanceof c.ZodEffects||r instanceof c.ZodLazy,ks=r=>r instanceof c.ZodString||r instanceof c.ZodNumber||r instanceof c.ZodBoolean||r instanceof c.ZodBigInt;class St{static convertValue(e,t){const s=e.getType()?.getBlueId(),n=e.getValue();return u.isNullable(n)?ks(t)&&me.isValidValueNode(e)?this.getDefaultPrimitiveValue(t):n:U===s?this.convertFromString(String(n),t):_===s||n instanceof w?this.convertFromBigDecimal(new w(n?.toString()),t):Z===s||n instanceof T?this.convertFromBigInteger(new T(n?.toString()),t):K===s||typeof n=="boolean"?this.convertFromBoolean(!!n,t):this.convertFromString(String(n),t)}static convertFromString(e,t){if(!t||t instanceof c.ZodString||t instanceof c.ZodEnum||t instanceof c.ZodNativeEnum)return e;if(t instanceof c.ZodNumber)return Number(e);if(t instanceof c.ZodBoolean)return e.toLowerCase()==="true";if(t instanceof c.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert String to ${t._def.typeName}`)}static convertFromBigDecimal(e,t){if(t instanceof c.ZodNumber)return e.toNumber();if(t instanceof c.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t._def.typeName}`)}static convertFromBigInteger(e,t){if(t instanceof c.ZodNumber)return e.toNumber();if(t instanceof c.ZodBigInt)return BigInt(e.toString());if(t instanceof c.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t._def.typeName}`)}static convertFromBoolean(e,t){if(!t||t instanceof c.ZodBoolean)return e;if(t instanceof c.ZodString)return e.toString();if(t instanceof c.ZodNumber)return Number(e);if(t instanceof c.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert Boolean to ${t._def.typeName}`)}static getDefaultPrimitiveValue(e){if(!e)return null;if(e instanceof c.ZodNumber)return 0;if(e instanceof c.ZodBoolean)return!1;if(e instanceof c.ZodString)return"";throw new Error(`Unsupported primitive type: ${e._def.typeName}`)}}class Hs{convert(e,t){return St.convertValue(e,t)}}class Ws{constructor(e){this.nodeToObjectConverter=e}convert(e,t){return this.convertFields(e,t)}convertFields(e,t){if(t instanceof c.ZodIntersection){const s=t._def.left,n=t._def.right,i=this.convert(e,s),o=this.convert(e,n);return{...i,...o}}if(t instanceof c.ZodUnion)throw new Error("Union not supported");if(t instanceof c.ZodObject)return Object.keys(t.shape).reduce((n,i)=>{const o=e.getProperties(),l=t.shape[i],a=mt(l);if(u.isNonNullable(a)){const b=A.isString(a)?a:i,R=o?.[b],Y=R?I.calculateBlueIdSync(R):void 0;return n[i]=Y,n}const p=bt(l);if(u.isNonNullable(p)){const b=o?.[p];return n[i]=b?.getName(),n}const y=gt(l);if(u.isNonNullable(y)){const b=o?.[y];return n[i]=b?.getDescription(),n}if(i==="name"){const b=e.getName();return n[i]=b,n}if(i==="description"){const b=e.getDescription();return n[i]=b,n}const h=o?.[i];if(u.isNullable(h))return n;const f=this.nodeToObjectConverter.convert(h,l);return n[i]=f,n},{});throw new Error("Unknown schema type, "+t._def.typeName)}}class qs{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const s=e.getItems();if(!s)return;const n=t.element;return s.map(o=>this.nodeToObjectConverter.convert(o,n))}}class Xs{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const s=e.getItems();if(!s)return;const n=t._def.valueType,i=s.map(o=>this.nodeToObjectConverter.convert(o,n));return new Set(i)}}class Qs{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const s=t.keySchema,n=t.valueSchema,i=new Map,o=e.getName();u.isNonNullable(o)&&i.set(J,o);const l=e.getDescription();u.isNonNullable(l)&&i.set(k,l);const a=e.getProperties();return u.isNonNullable(a)&&Object.entries(a).forEach(([p,y])=>{const h=new d().setValue(p);h.setType(new d().setBlueId(U));const f=St.convertValue(h,s),b=this.nodeToObjectConverter.convert(y,n);i.set(f,b)}),t instanceof c.ZodRecord?Object.fromEntries(i):i}}class er{convert(e){return m.get(e)}}class tr{convert(e){return m.get(e)}}class sr{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const s=e.getItems();if(!s)return;const n=t.items;return s.map((o,l)=>this.nodeToObjectConverter.convert(o,n[l]))}}const rr=c.z.union([c.z.literal("ZodString"),c.z.literal("ZodNumber"),c.z.literal("ZodBoolean"),c.z.literal("ZodBigInt"),c.z.literal("ZodArray"),c.z.literal("ZodSet"),c.z.literal("ZodMap"),c.z.literal("ZodRecord"),c.z.literal("ZodObject"),c.z.literal("ZodEnum"),c.z.literal("ZodNativeEnum"),c.z.literal("ZodUnknown"),c.z.literal("ZodAny"),c.z.literal("ZodTuple")]);class nr{constructor(e){this.nodeToObjectConverter=e,this.registerConverters(),this.complexObjectConverter=new Ws(this.nodeToObjectConverter)}converters=new Map;complexObjectConverter;registerConverters(){const e=new Hs,t=new qs(this.nodeToObjectConverter),s=new sr(this.nodeToObjectConverter),n=new Xs(this.nodeToObjectConverter),i=new Qs(this.nodeToObjectConverter);this.converters.set("ZodString",e),this.converters.set("ZodNumber",e),this.converters.set("ZodBoolean",e),this.converters.set("ZodBigInt",e),this.converters.set("ZodEnum",e),this.converters.set("ZodNativeEnum",e),this.converters.set("ZodUnknown",new er),this.converters.set("ZodAny",new tr),this.converters.set("ZodArray",t),this.converters.set("ZodTuple",s),this.converters.set("ZodSet",n),this.converters.set("ZodMap",i),this.converters.set("ZodRecord",i),this.converters.set("ZodObject",this.complexObjectConverter)}getConverter(e){const t=this.getSchemaTypeName(e);return this.converters.get(t)??this.complexObjectConverter}getSchemaTypeName(e){if(Js(e))return e instanceof c.ZodEffects?this.getSchemaTypeName(e.innerType()):e instanceof c.ZodLazy?this.getSchemaTypeName(e.schema):this.getSchemaTypeName(e.unwrap());const t=e._def.typeName;try{return rr.parse(t)}catch{throw new Error(`Schema type name ${t} is not supported`)}}}class ir{constructor(e){this.typeSchemaResolver=e,this.converterFactory=new nr(this)}converterFactory;convert(e,t){const s=this.typeSchemaResolver?.resolveSchema(e),n=S.unwrapSchema(t);if(Ke(n))return e;let i=n;return S.checkSchemaExtension(s,n,{typeSchemaResolver:this.typeSchemaResolver})&&u.isNonNullable(s)&&(i=s),this.convertWithType(e,i)}convertWithType(e,t){return this.converterFactory.getConverter(t).convert(e,t)}}class Et{reverse(e){const t=new d;return this.reverseNode(t,e,e.getType()),t}reverseNode(e,t,s){this.isIdenticalToType(t,s)||(this.reverseBasicProperties(e,t,s),this.reverseTypeReferences(e,t,s),this.reverseItems(e,t,s),this.reverseProperties(e,t,s))}isIdenticalToType(e,t){return u.isNonNullable(e.getBlueId())&&u.isNonNullable(t?.getBlueId())&&e.getBlueId()===t.getBlueId()}reverseBasicProperties(e,t,s){const n=t.getValue();u.isNonNullable(n)&&(u.isNullable(s)||u.isNullable(s.getValue()))&&e.setValue(n),u.isNonNullable(t.getName())&&(u.isNullable(s)||t.getName()!==s.getName())&&e.setName(t.getName()),u.isNonNullable(t.getDescription())&&(u.isNullable(s)||t.getDescription()!==s.getDescription())&&e.setDescription(t.getDescription()),u.isNonNullable(t.getBlueId())&&(u.isNullable(s)||t.getBlueId()!==s.getBlueId())&&e.setBlueId(t.getBlueId())}reverseTypeReferences(e,t,s){const n=(i,o)=>{const l=i(t),a=s?i(s):void 0,p=l?.getBlueId();u.isNonNullable(p)&&(u.isNullable(a?.getBlueId())||p!==a.getBlueId())&&o(e,new d().setBlueId(p))};n(i=>i.getType(),(i,o)=>i.setType(o)),n(i=>i.getItemType(),(i,o)=>i.setItemType(o)),n(i=>i.getKeyType(),(i,o)=>i.setKeyType(o)),n(i=>i.getValueType(),(i,o)=>i.setValueType(o))}reverseItems(e,t,s){const n=t.getItems();if(u.isNullable(n))return;const i=s?.getItems(),o=[];if(u.isNonNullable(i)&&i.length>0){const a=I.calculateBlueIdSync(i);o.push(new d().setBlueId(a))}const l=i?.length||0;for(let a=l;a<n.length;a++){const p=new d;this.reverseNode(p,n[a],void 0),o.push(p)}o.length>0&&e.setItems(o)}reverseProperties(e,t,s){const n=t.getProperties();if(u.isNullable(n))return;const i={};for(const[o,l]of Object.entries(n)){const a=this.getInheritedProperty(o,t,s),p=new d;this.reverseNode(p,l,a),me.isEmptyNode(p)||(i[o]=p)}Object.keys(i).length>0&&e.setProperties(i)}getInheritedProperty(e,t,s){const n=s?.getProperties()?.[e],i=t.getType()?.getProperties()?.[e];if(!(u.isNullable(n)&&u.isNullable(i)))return u.isNullable(n)?i:u.isNullable(i)?n:this.mergeNodes(n,i)}mergeNodes(e,t){const s=e.clone(),n=t.getValue();u.isNonNullable(n)&&s.setValue(n);const i=t.getType();u.isNonNullable(i)&&s.setType(i.clone());const o=t.getItemType();u.isNonNullable(o)&&s.setItemType(o.clone());const l=t.getKeyType();u.isNonNullable(l)&&s.setKeyType(l.clone());const a=t.getValueType();u.isNonNullable(a)&&s.setValueType(a.clone());const p=t.getProperties();if(u.isNonNullable(p)){const h=s.getProperties()||{};for(const[f,b]of Object.entries(p))h[f]=b.clone();s.setProperties(h)}const y=t.getItems();return u.isNonNullable(y)&&s.setItems(y.map(h=>h.clone())),s}}class q extends d{constructor(e){super(e.getName()),this.createFrom(e)}isResolved(){return!0}getMinimalNode(){return new Et().reverse(this)}getMinimalBlueId(){const e=this.getMinimalNode();return I.calculateBlueIdSync(e)}clone(){const e=super.clone();return new q(e)}createFrom(e){e.getName()!==this.getName()&&this.setName(e.getName()),this.setDescription(e.getDescription()).setType(e.getType()).setItemType(e.getItemType()).setKeyType(e.getKeyType()).setValueType(e.getValueType()).setItems(e.getItems()).setProperties(e.getProperties()).setBlueId(e.getBlueId()).setBlue(e.getBlue()).setInlineValue(e.isInlineValue());const t=e.getValue();t!==void 0&&this.setValue(t)}}class ce{fetchFirstByBlueId(e){const t=this.fetchByBlueId(e);return t&&t.length>0?t[0]:null}}function or(r){return new class extends ce{fetchByBlueId(e){return r(e)}}}class lr extends ce{nodeProviders;constructor(e){super(),this.nodeProviders=e}fetchByBlueId(e){for(const t of this.nodeProviders){const s=t.fetchByBlueId(e);if(s&&s.length>0)return s}return[]}fetchFirstByBlueId(e){for(const t of this.nodeProviders){const s=t.fetchFirstByBlueId(e);if(s)return s}return null}getNodeProviders(){return this.nodeProviders}}const Pe=z.types.float.options,ar={...Pe,construct:r=>{const e=r.replace(/_/g,"").toLowerCase();if(!u.isPreciseNumberString(e))return new w(e);if(Pe.construct)return Pe.construct(r)}},ur=new z.Type("tag:yaml.org,2002:float",ar),Se=z.types.int.options,cr={...Se,construct:r=>{let e=r;if(e.indexOf("_")!==-1&&(e=e.replace(/_/g,"")),!u.isPreciseNumberString(e))return new T(e);if(Se.construct)return Se.construct(r)}},dr=new z.Type("tag:yaml.org,2002:int",cr),At=z.CORE_SCHEMA.extend({implicit:[ur,dr]}),M=r=>{const e=z.load(r,{schema:At});return e===void 0?void 0:e},pr=r=>z.dump(r,{schema:At,replacer:(e,t)=>{if(P(t)){if(O(t)){const s=new D(Number.MIN_SAFE_INTEGER.toString()),n=new D(Number.MAX_SAFE_INTEGER.toString());if(t.lt(s)||t.gt(n))return t.toString()}return t.toNumber()}return t}}),Vt=`- type:
2
2
  blueId: 27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo
3
3
  mappings:
4
4
  Text: DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K
@@ -9,19 +9,19 @@
9
9
  Dictionary: G7fBT9PSod1RfHLHkpafAGBDVAJMrMhAMY51ERcyXNrj
10
10
  - type:
11
11
  blueId: FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4
12
- `,Ir=`name: Transformation
13
- description: TODO`,br=`name: Infer Basic Types For Untyped Values
12
+ `,hr=`name: Transformation
13
+ description: TODO`,fr=`name: Infer Basic Types For Untyped Values
14
14
  type:
15
15
  blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
16
- description: This transformation infers type details for Text, Integer, Number and Boolean.`,Tr=`name: Replace Inline Types with BlueIds
16
+ description: This transformation infers type details for Text, Integer, Number and Boolean.`,gr=`name: Replace Inline Types with BlueIds
17
17
  type:
18
18
  blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
19
- description: This transformation replaces`,Nr=[Ot,Ir,br,Tr];class vr extends ue{blueIdToNodesMap=new Map;constructor(){super(),this.load()}fetchByBlueId(e){return this.blueIdToNodesMap.get(e)||[]}load(){for(const e of Nr){const t=M(e);if(t===void 0){console.error(`This content file is not valid YAML: ${e}`);continue}if(Array.isArray(t)){const s=t.map(i=>g.deserialize(i)),n=I.calculateBlueIdSync(s);this.blueIdToNodesMap.set(n,s)}else{const s=g.deserialize(t),n=I.calculateBlueIdSync(s);this.blueIdToNodesMap.set(n,[s])}}}}class Je extends ue{static INSTANCE=new Je;nodeProvider;constructor(){super(),this.nodeProvider=new vr}fetchByBlueId(e){return this.nodeProvider.fetchByBlueId(e)}}class Ee{constructor(e,t,s){this.blueId=e,this.content=t,this.isMultipleDocuments=s}}class ${static THIS_REFERENCE_PATTERN=/^this(#\d+)?$/;static parseAndCalculateBlueId(e,t){let s;try{const l=M(e);if(l===void 0)throw new Error;s=l}catch{throw new Error("Failed to parse content as YAML or JSON")}let n,i;const o=Array.isArray(s)&&s.length>1;if(o){const l=s.map(a=>{const p=g.deserialize(a);return t(p)});n=I.calculateBlueIdSync(l),i=l.map(a=>m.get(a))}else{const l=g.deserialize(s),a=t(l);n=I.calculateBlueIdSync(a),i=m.get(a)}return new Ee(n,i,o)}static parseAndCalculateBlueIdForNode(e,t){const s=t(e),n=I.calculateBlueIdSync(s),i=m.get(s);return new Ee(n,i,!1)}static parseAndCalculateBlueIdForNodeList(e,t){if(!e||e.length===0)throw new Error("List of nodes cannot be null or empty");const s=e.map(t),n=I.calculateBlueIdSync(s),i=s.map(l=>m.get(l)),o=e.length>1;return new Ee(n,i,o)}static resolveThisReferences(e,t,s){return this.resolveThisReferencesRecursive(e,t,s)}static resolveThisReferencesRecursive(e,t,s){if(e&&typeof e=="object"&&!Array.isArray(e)){const n={};for(const[i,o]of Object.entries(e))typeof o=="string"?this.THIS_REFERENCE_PATTERN.test(o)?n[i]=this.resolveThisReference(o,t,s):n[i]=o:o&&typeof o=="object"?n[i]=this.resolveThisReferencesRecursive(o,t,s):n[i]=o;return n}else if(Array.isArray(e))return e.map(n=>typeof n=="string"?this.THIS_REFERENCE_PATTERN.test(n)?this.resolveThisReference(n,t,s):n:n&&typeof n=="object"?this.resolveThisReferencesRecursive(n,t,s):n);return e}static resolveThisReference(e,t,s){if(s){if(!e.startsWith("this#"))throw new Error("For multiple documents, 'this' references must include an index (e.g., 'this#0')");return t+e.substring(4)}else{if(e==="this")return t;throw new Error("For a single document, only 'this' is allowed as a reference, not 'this#<id>'")}}}class Br extends ue{fetchByBlueId(e){const t=e.split("#")[0],s=this.fetchContentByBlueId(t);if(s==null)return null;const n=Array.isArray(s)&&s.length>1,i=$.resolveThisReferences(s,t,n);if(e.includes("#")){const o=e.split("#");if(o.length>1){const l=parseInt(o[1]);if(Array.isArray(i)&&l<i.length){const a=i[l],p=g.deserialize(a);return p.setBlueId(e),[p]}else if(l===0){const a=g.deserialize(i);return a.setBlueId(e),[a]}else return null}}if(Array.isArray(i))return i.map(o=>g.deserialize(o));{const o=g.deserialize(i);return o.setBlueId(t),[o]}}}class Ft extends Br{nameToBlueIdsMap=new Map;findNodeByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t)return;if(t.length>1)throw new Error(`Multiple nodes found with name: ${e}`);const s=this.fetchByBlueId(t[0]);return s&&s.length>0?s[0]:void 0}findAllNodesByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t)return[];const s=[];for(const n of t){const i=this.fetchByBlueId(n);i&&s.push(...i)}return s}addToNameMap(e,t){this.nameToBlueIdsMap.set(e,[...this.nameToBlueIdsMap.get(e)||[],t])}}const Rt=r=>r instanceof d||Array.isArray(r)&&r.every(e=>e instanceof d)?r:A.isArray(r)?r.map(e=>g.deserialize(e)):g.deserialize(r),jt=async r=>{const e=Rt(r);return I.calculateBlueId(e)},wr=r=>{const e=Rt(r);return I.calculateBlueIdSync(e)},De=async r=>{if(it(r))return r;try{const e=ie.parse(r),t=await jt(e);return{...r,blueId:t}}catch(e){throw new Error(`Failed enriching object with Blue ID: ${e}`)}},Pr=r=>r?.items,Sr=r=>r?.value,Er=r=>u.isNullable(r)?{}:A.omit(r,es),Ar=r=>lt(r)?r.type.name??null:at(r)?A.pascal(typeof r.value):ot(r)?"List":null,xt=r=>u.isNonNullable(r)&&Object.keys(A.omit(r,["blueId"])).length>0,Vr=r=>{try{const e=g.deserialize(r),t=m.get(e);return H.parse(t)}catch(e){throw new Error(`Failed transforming JSON-like value to BlueObject: ${e}`)}},Oe=async r=>{const{resolveFunction:e,signal:t=new AbortController().signal,omitItems:s}=r,n=r.count??r.items.length;let i=await A.map(r.items,async l=>await De(l));const o=Math.max(i?.length-n,0);for(let l=i.length-1;l>=o;l--)if(!xt(i[l])){const a=await e(i[l],{signal:t});if(Array.isArray(a))return Oe({...r,items:[...i.slice(0,l),...a,...i.slice(l+1)]});const p=await De(a);if(s?.includes(p.blueId))return Oe({...r,items:[...i.slice(0,l),...i.slice(l+1)]});i=[...i.slice(0,l),p,...i.slice(l+1)]}return i};function re(r){try{const e=new URL(r);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}class Cr{process(e){return E.transform(e,this.inferType.bind(this))}inferType(e){const t=e.getType(),s=e.getValue();return u.isNullable(t)&&u.isNonNullable(s)&&(typeof s=="string"?e.setType(new d().setBlueId(U)):typeof s=="bigint"||O(s)?e.setType(new d().setBlueId(Z)):pe(s)?e.setType(new d().setBlueId(_)):typeof s=="boolean"&&e.setType(new d().setBlueId(K))),e}}class fe{static MAPPINGS="mappings";mappings=new Map;constructor(e){if(e instanceof d){const s=e.getProperties();if(s&&s[fe.MAPPINGS]){const i=s[fe.MAPPINGS].getProperties();i&&Object.entries(i).forEach(([o,l])=>{const a=l.getValue();typeof a=="string"&&this.mappings.set(o,a)})}}else this.mappings=e}process(e){return E.transform(e,this.transformNode.bind(this))}transformNode(e){const t=e.clone();return this.transformTypeField(t,t.getType()),this.transformTypeField(t,t.getItemType()),this.transformTypeField(t,t.getKeyType()),this.transformTypeField(t,t.getValueType()),t}transformTypeField(e,t){if(t&&t.isInlineValue()&&t.getValue()!==void 0){const s=String(t.getValue());if(this.mappings.has(s)){const n=this.mappings.get(s);if(n){const i=new d().setBlueId(n);t===e.getType()?e.setType(i):t===e.getItemType()?e.setItemType(i):t===e.getKeyType()?e.setKeyType(i):t===e.getValueType()&&e.setValueType(i)}}}}}class Mr{process(e){return E.transform(e,this.validateNode.bind(this)),e}validateNode(e){return this.validateTypeField(e,e.getType(),"type"),this.validateTypeField(e,e.getItemType(),"itemType"),this.validateTypeField(e,e.getKeyType(),"keyType"),this.validateTypeField(e,e.getValueType(),"valueType"),e}validateTypeField(e,t,s){if(t&&t.isInlineValue()&&t.getValue()!==void 0){const n=String(t.getValue());throw new Error(`Unknown type "${n}" found in ${s} field. No BlueId mapping exists for this type.`)}}}class ke{nodeProvider;strategy;constructor(e,t){this.nodeProvider=oe.wrap(e),this.strategy=t||"THROW_EXCEPTION"}extend(e,t){this.extendNode(e,t,"")}extendNode(e,t,s,n=!1){if(!n){if(!t.shouldExtendPathSegment(s,e))return;t.enterPathSegment(s,e)}try{const i=e.getBlueId();if(i&&!le.includes(i)){const f=this.fetchNode(e);if(f&&f.length>0)if(f.length===1){const b=f[0];this.mergeNodes(e,b)}else{const b=f.map(Y=>Y.clone()),R=new d().setItems(b);this.mergeNodes(e,R)}}const o=e.getType();o&&this.extendNode(o,t,"type",!0);const l=e.getItemType();l&&this.extendNode(l,t,"itemType",!0);const a=e.getKeyType();a&&this.extendNode(a,t,"keyType",!0);const p=e.getValueType();p&&this.extendNode(p,t,"valueType",!0);const y=e.getProperties();y&&Object.entries(y).forEach(([f,b])=>{this.extendNode(b,t,f,!1)});const h=e.getItems();if(h&&h.length>0){this.reconstructList(h);for(let f=0;f<h.length;f++)this.extendNode(h[f],t,String(f),!1)}}finally{n||t.exitPathSegment()}}reconstructList(e){for(;e.length>0;){const s=e[0]?.getBlueId();if(!s)break;const n=this.nodeProvider.fetchByBlueId(s);if(!n||n.length===1)break;e.shift(),e.unshift(...n)}}fetchNode(e){const t=e.getBlueId();if(!t){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No blueId found for node: ${e.getName()}`)}const s=this.nodeProvider.fetchByBlueId(t);if(!s||s.length===0){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No content found for blueId: ${e.getBlueId()}`)}return s}mergeNodes(e,t){e.setName(t.getName()),e.setDescription(t.getDescription()),e.setType(t.getType()),e.setItemType(t.getItemType()),e.setKeyType(t.getKeyType()),e.setValueType(t.getValueType());const s=t.getValue();u.isNonNullable(s)&&e.setValue(s),e.setItems(t.getItems()),e.setProperties(t.getProperties())}}class $t{blueIdsCollections=[];initialize(...e){this.blueIdsCollections=[...e]}registerBlueIds(...e){this.blueIdsCollections.push(...e)}generateMappingsYaml(e="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo"){const t={};for(const n of this.blueIdsCollections)Object.assign(t,n);const s=Object.entries(t).map(([n,i])=>` ${n}: ${i}`).join(`
19
+ description: This transformation replaces`,yr=[Vt,hr,fr,gr];class mr extends ce{blueIdToNodesMap=new Map;constructor(){super(),this.load()}fetchByBlueId(e){return this.blueIdToNodesMap.get(e)||[]}load(){for(const e of yr){const t=M(e);if(t===void 0){console.error(`This content file is not valid YAML: ${e}`);continue}if(Array.isArray(t)){const s=t.map(i=>g.deserialize(i)),n=I.calculateBlueIdSync(s);this.blueIdToNodesMap.set(n,s)}else{const s=g.deserialize(t),n=I.calculateBlueIdSync(s);this.blueIdToNodesMap.set(n,[s])}}}}class Ye extends ce{static INSTANCE=new Ye;nodeProvider;constructor(){super(),this.nodeProvider=new mr}fetchByBlueId(e){return this.nodeProvider.fetchByBlueId(e)}}class Ee{constructor(e,t,s){this.blueId=e,this.content=t,this.isMultipleDocuments=s}}class x{static THIS_REFERENCE_PATTERN=/^this(#\d+)?$/;static parseAndCalculateBlueId(e,t){let s;try{const l=M(e);if(l===void 0)throw new Error;s=l}catch{throw new Error("Failed to parse content as YAML or JSON")}let n,i;const o=Array.isArray(s)&&s.length>1;if(o){const l=s.map(a=>{const p=g.deserialize(a);return t(p)});n=I.calculateBlueIdSync(l),i=l.map(a=>m.get(a))}else{const l=g.deserialize(s),a=t(l);n=I.calculateBlueIdSync(a),i=m.get(a)}return new Ee(n,i,o)}static parseAndCalculateBlueIdForNode(e,t){const s=t(e),n=I.calculateBlueIdSync(s),i=m.get(s);return new Ee(n,i,!1)}static parseAndCalculateBlueIdForNodeList(e,t){if(!e||e.length===0)throw new Error("List of nodes cannot be null or empty");const s=e.map(t),n=I.calculateBlueIdSync(s),i=s.map(l=>m.get(l)),o=e.length>1;return new Ee(n,i,o)}static resolveThisReferences(e,t,s){return this.resolveThisReferencesRecursive(e,t,s)}static resolveThisReferencesRecursive(e,t,s){if(e&&typeof e=="object"&&!Array.isArray(e)){const n={};for(const[i,o]of Object.entries(e))typeof o=="string"?this.THIS_REFERENCE_PATTERN.test(o)?n[i]=this.resolveThisReference(o,t,s):n[i]=o:o&&typeof o=="object"?n[i]=this.resolveThisReferencesRecursive(o,t,s):n[i]=o;return n}else if(Array.isArray(e))return e.map(n=>typeof n=="string"?this.THIS_REFERENCE_PATTERN.test(n)?this.resolveThisReference(n,t,s):n:n&&typeof n=="object"?this.resolveThisReferencesRecursive(n,t,s):n);return e}static resolveThisReference(e,t,s){if(s){if(!e.startsWith("this#"))throw new Error("For multiple documents, 'this' references must include an index (e.g., 'this#0')");return t+e.substring(4)}else{if(e==="this")return t;throw new Error("For a single document, only 'this' is allowed as a reference, not 'this#<id>'")}}}class Ir extends ce{fetchByBlueId(e){const t=e.split("#")[0],s=this.fetchContentByBlueId(t);if(s==null)return null;const n=Array.isArray(s)&&s.length>1,i=x.resolveThisReferences(s,t,n);if(e.includes("#")){const o=e.split("#");if(o.length>1){const l=parseInt(o[1]);if(Array.isArray(i)&&l<i.length){const a=i[l],p=g.deserialize(a);return p.setBlueId(e),[p]}else if(l===0){const a=g.deserialize(i);return a.setBlueId(e),[a]}else return null}}if(Array.isArray(i))return i.map(o=>g.deserialize(o));{const o=g.deserialize(i);return o.setBlueId(t),[o]}}}class Ct extends Ir{nameToBlueIdsMap=new Map;findNodeByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t)return;if(t.length>1)throw new Error(`Multiple nodes found with name: ${e}`);const s=this.fetchByBlueId(t[0]);return s&&s.length>0?s[0]:void 0}findAllNodesByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t)return[];const s=[];for(const n of t){const i=this.fetchByBlueId(n);i&&s.push(...i)}return s}addToNameMap(e,t){this.nameToBlueIdsMap.set(e,[...this.nameToBlueIdsMap.get(e)||[],t])}}const Mt=r=>r instanceof d||Array.isArray(r)&&r.every(e=>e instanceof d)?r:A.isArray(r)?r.map(e=>g.deserialize(e)):g.deserialize(r),Dt=async r=>{const e=Mt(r);return I.calculateBlueId(e)},br=r=>{const e=Mt(r);return I.calculateBlueIdSync(e)},Me=async r=>{if(rt(r))return r;try{const e=ne.parse(r),t=await Dt(e);return{...r,blueId:t}}catch(e){throw new Error(`Failed enriching object with Blue ID: ${e}`)}},Nr=r=>r?.items,Tr=r=>r?.value,vr=r=>u.isNullable(r)?{}:A.omit(r,Wt),Br=r=>it(r)?r.type.name??null:ot(r)?A.pascal(typeof r.value):nt(r)?"List":null,Ot=r=>u.isNonNullable(r)&&Object.keys(A.omit(r,["blueId"])).length>0,wr=r=>{try{const e=g.deserialize(r),t=m.get(e);return H.parse(t)}catch(e){throw new Error(`Failed transforming JSON-like value to BlueObject: ${e}`)}},De=async r=>{const{resolveFunction:e,signal:t=new AbortController().signal,omitItems:s}=r,n=r.count??r.items.length;let i=await A.map(r.items,async l=>await Me(l));const o=Math.max(i?.length-n,0);for(let l=i.length-1;l>=o;l--)if(!Ot(i[l])){const a=await e(i[l],{signal:t});if(Array.isArray(a))return De({...r,items:[...i.slice(0,l),...a,...i.slice(l+1)]});const p=await Me(a);if(s?.includes(p.blueId))return De({...r,items:[...i.slice(0,l),...i.slice(l+1)]});i=[...i.slice(0,l),p,...i.slice(l+1)]}return i};function se(r){try{const e=new URL(r);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}class Pr{process(e){return E.transform(e,this.inferType.bind(this))}inferType(e){const t=e.getType(),s=e.getValue();return u.isNullable(t)&&u.isNonNullable(s)&&(typeof s=="string"?e.setType(new d().setBlueId(U)):typeof s=="bigint"||O(s)?e.setType(new d().setBlueId(Z)):he(s)?e.setType(new d().setBlueId(_)):typeof s=="boolean"&&e.setType(new d().setBlueId(K))),e}}class ge{static MAPPINGS="mappings";mappings=new Map;constructor(e){if(e instanceof d){const s=e.getProperties();if(s&&s[ge.MAPPINGS]){const i=s[ge.MAPPINGS].getProperties();i&&Object.entries(i).forEach(([o,l])=>{const a=l.getValue();typeof a=="string"&&this.mappings.set(o,a)})}}else this.mappings=e}process(e){return E.transform(e,this.transformNode.bind(this))}transformNode(e){const t=e.clone();return this.transformTypeField(t,t.getType()),this.transformTypeField(t,t.getItemType()),this.transformTypeField(t,t.getKeyType()),this.transformTypeField(t,t.getValueType()),t}transformTypeField(e,t){if(t&&t.isInlineValue()&&t.getValue()!==void 0){const s=String(t.getValue());if(this.mappings.has(s)){const n=this.mappings.get(s);if(n){const i=new d().setBlueId(n);t===e.getType()?e.setType(i):t===e.getItemType()?e.setItemType(i):t===e.getKeyType()?e.setKeyType(i):t===e.getValueType()&&e.setValueType(i)}}}}}class Sr{process(e){return E.transform(e,this.validateNode.bind(this)),e}validateNode(e){return this.validateTypeField(e,e.getType(),"type"),this.validateTypeField(e,e.getItemType(),"itemType"),this.validateTypeField(e,e.getKeyType(),"keyType"),this.validateTypeField(e,e.getValueType(),"valueType"),e}validateTypeField(e,t,s){if(t&&t.isInlineValue()&&t.getValue()!==void 0){const n=String(t.getValue());throw new Error(`Unknown type "${n}" found in ${s} field. No BlueId mapping exists for this type.`)}}}class Ge{nodeProvider;strategy;constructor(e,t){this.nodeProvider=oe.wrap(e),this.strategy=t||"THROW_EXCEPTION"}extend(e,t){this.extendNode(e,t,"")}extendNode(e,t,s,n=!1){if(!n){if(!t.shouldExtendPathSegment(s,e))return;t.enterPathSegment(s,e)}try{const i=e.getBlueId();if(i&&!le.includes(i)){const f=this.fetchNode(e);if(f&&f.length>0)if(f.length===1){const b=f[0];this.mergeNodes(e,b)}else{const b=f.map(Y=>Y.clone()),R=new d().setItems(b);this.mergeNodes(e,R)}}const o=e.getType();o&&this.extendNode(o,t,"type",!0);const l=e.getItemType();l&&this.extendNode(l,t,"itemType",!0);const a=e.getKeyType();a&&this.extendNode(a,t,"keyType",!0);const p=e.getValueType();p&&this.extendNode(p,t,"valueType",!0);const y=e.getProperties();y&&Object.entries(y).forEach(([f,b])=>{this.extendNode(b,t,f,!1)});const h=e.getItems();if(h&&h.length>0){this.reconstructList(h);for(let f=0;f<h.length;f++)this.extendNode(h[f],t,String(f),!1)}}finally{n||t.exitPathSegment()}}reconstructList(e){for(;e.length>0;){const s=e[0]?.getBlueId();if(!s)break;const n=this.nodeProvider.fetchByBlueId(s);if(!n||n.length===1)break;e.shift(),e.unshift(...n)}}fetchNode(e){const t=e.getBlueId();if(!t){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No blueId found for node: ${e.getName()}`)}const s=this.nodeProvider.fetchByBlueId(t);if(!s||s.length===0){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No content found for blueId: ${e.getBlueId()}`)}return s}mergeNodes(e,t){e.setName(t.getName()),e.setDescription(t.getDescription()),e.setType(t.getType()),e.setItemType(t.getItemType()),e.setKeyType(t.getKeyType()),e.setValueType(t.getValueType());const s=t.getValue();u.isNonNullable(s)&&e.setValue(s),e.setItems(t.getItems()),e.setProperties(t.getProperties())}}class Ft{blueIdsCollections=[];initialize(...e){this.blueIdsCollections=[...e]}registerBlueIds(...e){this.blueIdsCollections.push(...e)}generateMappingsYaml(e="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo"){const t={};for(const n of this.blueIdsCollections)Object.assign(t,n);const s=Object.entries(t).map(([n,i])=>` ${n}: ${i}`).join(`
20
20
  `);return`- type:
21
21
  blueId: ${e}
22
22
  mappings:
23
- ${s}`}getAllBlueIds(){const e={};for(const t of this.blueIdsCollections)Object.assign(e,t);return e}getAllBlueIdNames(){return Object.keys(this.getAllBlueIds())}clear(){this.blueIdsCollections=[]}getCollectionCount(){return this.blueIdsCollections.length}getTotalBlueIdCount(){return Object.keys(this.getAllBlueIds()).length}}class X{static DEFAULT_BLUE_BLUE_ID="6sqUywMoBRyj9hgQxSu2nDPnqcyiSM7xu9AB9sN98YJK";processorProvider;nodeProvider;defaultSimpleBlue=null;blueIdsMappingGenerator;constructor(e={}){const{nodeProvider:t,processorProvider:s,blueIdsMappingGenerator:n}=e;if(!t)throw new Error("NodeProvider is required");this.nodeProvider=oe.wrap(t),this.processorProvider=s||X.getStandardProvider(),this.blueIdsMappingGenerator=n||new $t,this.loadDefaultSimpleBlue()}preprocess(e){return this.preprocessWithOptions(e,null)}preprocessWithDefaultBlue(e){return this.preprocessWithOptions(e,this.defaultSimpleBlue)}preprocessWithOptions(e,t){let s=e.clone(),n=s.getBlue();if(!n&&t&&(n=t.clone()),n){new ke(this.nodeProvider).extend(n,be.withSinglePath("/*"));const i=n.getItems();if(i&&i.length>0){for(const o of i){const l=this.processorProvider.getProcessor(o);if(l)s=l.process(s);else throw new Error(`No processor found for transformation: ${o}`)}s.setBlue(void 0)}s=new Mr().process(s)}return s}static getStandardProvider(){return{getProcessor(e){const t="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo",s="FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4",n=e.getType()?.getBlueId();if(t===n)return new fe(e);if(s===n)return new Cr}}}enrichDefaultBlue(e){const t=this.blueIdsMappingGenerator.generateMappingsYaml();return`
23
+ ${s}`}getAllBlueIds(){const e={};for(const t of this.blueIdsCollections)Object.assign(e,t);return e}getAllBlueIdNames(){return Object.keys(this.getAllBlueIds())}clear(){this.blueIdsCollections=[]}getCollectionCount(){return this.blueIdsCollections.length}getTotalBlueIdCount(){return Object.keys(this.getAllBlueIds()).length}}class X{static DEFAULT_BLUE_BLUE_ID="6sqUywMoBRyj9hgQxSu2nDPnqcyiSM7xu9AB9sN98YJK";processorProvider;nodeProvider;defaultSimpleBlue=null;blueIdsMappingGenerator;constructor(e={}){const{nodeProvider:t,processorProvider:s,blueIdsMappingGenerator:n}=e;if(!t)throw new Error("NodeProvider is required");this.nodeProvider=oe.wrap(t),this.processorProvider=s||X.getStandardProvider(),this.blueIdsMappingGenerator=n||new Ft,this.loadDefaultSimpleBlue()}preprocess(e){return this.preprocessWithOptions(e,null)}preprocessWithDefaultBlue(e){return this.preprocessWithOptions(e,this.defaultSimpleBlue)}preprocessWithOptions(e,t){let s=e.clone(),n=s.getBlue();if(!n&&t&&(n=t.clone()),n){new Ge(this.nodeProvider).extend(n,be.withSinglePath("/*"));const i=n.getItems();if(i&&i.length>0){for(const o of i){const l=this.processorProvider.getProcessor(o);if(l)s=l.process(s);else throw new Error(`No processor found for transformation: ${o}`)}s.setBlue(void 0)}s=new Sr().process(s)}return s}static getStandardProvider(){return{getProcessor(e){const t="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo",s="FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4",n=e.getType()?.getBlueId();if(t===n)return new ge(e);if(s===n)return new Pr}}}enrichDefaultBlue(e){const t=this.blueIdsMappingGenerator.generateMappingsYaml();return`
24
24
  ${e}
25
25
  ${t}
26
- `}loadDefaultSimpleBlue(){const e=this.enrichDefaultBlue(Ot);try{const t=M(e);if(t)this.defaultSimpleBlue=g.deserialize(t);else throw new Error("Failed to parse default Blue content")}catch(t){throw new Error(`Error loading default Blue: ${t}`)}}}class Dr extends Ft{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;preprocessor;constructor(e){super();const t=new X({nodeProvider:this});this.preprocessor=s=>t.preprocessWithDefaultBlue(s),this.loadRepositories(e)}loadRepositories(e){for(const t of e)if(t.contents)for(const[s,n]of Object.entries(t.contents))this.processContent(n,s)}processContent(e,t){Array.isArray(e)?this.processMultipleDocuments(e,t):this.processSingleDocument(e,t)}processSingleDocument(e,t){const s=g.deserialize(e),n=$.parseAndCalculateBlueIdForNode(s,this.preprocessor),i=t||n.blueId;this.blueIdToContentMap.set(i,n.content),this.blueIdToMultipleDocumentsMap.set(i,!1);const o=s.getName();o&&this.addToNameMap(o,i)}processMultipleDocuments(e,t){const s=e.map(o=>{const l=g.deserialize(o);return this.preprocessor(l)}),n=$.parseAndCalculateBlueIdForNodeList(s,o=>o),i=t||n.blueId;this.blueIdToContentMap.set(i,n.content),this.blueIdToMultipleDocumentsMap.set(i,!0),s.forEach((o,l)=>{const a=`${i}#${l}`,p=m.get(o),y=I.calculateBlueIdSync(o);this.blueIdToContentMap.set(y,p),this.blueIdToMultipleDocumentsMap.set(y,!1);const h=o.getName();h&&this.addToNameMap(h,a)})}fetchContentByBlueId(e){const t=this.blueIdToContentMap.get(e),s=this.blueIdToMultipleDocumentsMap.get(e);return t!==void 0&&s!==void 0?$.resolveThisReferences(t,e,s):null}getBlueIds(){return Array.from(this.blueIdToContentMap.keys())}hasBlueId(e){const t=e.split("#")[0];return this.blueIdToContentMap.has(t)}}class oe{static wrap(e,t){const s=[Je.INSTANCE];if(t&&t.length>0){const n=new Dr(t);s.push(n)}return s.push(e),new pr(s)}}class Or{preprocessingAliases=new Map;urlContentFetcher;constructor(e,t){e&&(this.preprocessingAliases=new Map(e)),this.urlContentFetcher=t}process(e){const t=this.getBlueNodeValue(e);if(t){const s=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(s,t);if(de.isPotentialBlueId(t))return this.handleBlueId(s,t);throw re(t)?new Error(`URL '${t}' detected. Use the async version of this method to fetch the content.`):new Error(`Invalid blue value: ${t}`)}return e}async processAsync(e){const t=this.getBlueNodeValue(e);if(t){const s=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(s,t);if(de.isPotentialBlueId(t))return this.handleBlueId(s,t);if(re(t)&&this.urlContentFetcher)try{const n=await this.fetchFromUrl(t);return n&&s.setBlue(new d().setItems(n)),s}catch(n){throw n instanceof Error?new Error(`Failed to fetch from URL '${t}'.
27
- ${n.message}`):n}else throw re(t)?new Error(`UrlContentFetcher not provided for URL: ${t}`):new Error(`Invalid blue value: ${t}`)}return e}getBlueNodeValue(e){const s=e.getBlue()?.getValue();return s&&typeof s=="string"?s:null}handleAliasValue(e,t){return e.setBlue(new d().setBlueId(this.preprocessingAliases.get(t))),e}handleBlueId(e,t){return e.setBlue(new d().setBlueId(t)),e}async fetchFromUrl(e){if(!this.urlContentFetcher)throw new Error(`UrlContentFetcher not provided for URL: ${e}`);return await this.urlContentFetcher.fetchAndCache(e)}getPreprocessingAliases(){return new Map(this.preprocessingAliases)}setPreprocessingAliases(e){return this.preprocessingAliases=new Map(e),this}addPreprocessingAliases(e){return e.forEach((t,s)=>{this.preprocessingAliases.set(s,t)}),this}setUrlContentFetcher(e){return this.urlContentFetcher=e,this}getUrlContentFetcher(){return this.urlContentFetcher}}const Fr={fetchUrl:async r=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${r}`)}};class Rr{cache=new Map;fetchStrategy;enabled=!1;allowedDomains=[];constructor(e){this.fetchStrategy=e||Fr}validateUrl(e){if(!re(e))throw new Error(`Invalid URL: ${e}`);return!0}isDomainAllowed(e){if(this.allowedDomains.length===0)return!0;try{const t=new URL(e);return this.allowedDomains.some(s=>t.hostname===s||t.hostname.endsWith(`.${s}`))}catch{return!1}}getFromCache(e){try{return this.validateUrl(e),this.cache.get(e)||[]}catch{return[]}}async fetchAndCache(e){if(this.validateUrl(e),!this.enabled)throw new Error("URL fetching is disabled. Enable it using the enableFetching method.");if(!this.isDomainAllowed(e))throw new Error(`Domain not allowed for URL: ${e}.`);let t;try{t=await this.fetchStrategy.fetchUrl(e)}catch(l){throw new Error(`Error fetching from URL: ${e}`,{cause:l})}const{data:s,contentType:n}=t;let i;if(n.includes("application/json")||n.includes("text/yaml")||n.includes("application/yaml")||n.includes("text/plain"))i=M(s);else throw new Error(`Unsupported content type from URL: ${n}`);if(i===void 0)throw new Error(`Failed to parse content from URL: ${e}`);let o;return Array.isArray(i)?o=i.map(l=>g.deserialize(l)):o=[g.deserialize(i)],this.cache.set(e,o),o}prefetchUrl(e,t){try{this.validateUrl(e),this.cache.set(e,t)}catch{}}clearCache(){this.cache.clear()}setFetchStrategy(e){return this.fetchStrategy=e,this}getFetchStrategy(){return this.fetchStrategy}enableFetching(){return this.enabled=!0,this.allowedDomains=[],this}enableFetchingForDomains(e){return this.enabled=!0,this.allowedDomains=[...e],this}disableFetching(){return this.enabled=!1,this}isFetchingEnabled(){return this.enabled}getAllowedDomains(){return[...this.allowedDomains]}allowDomain(e){return this.allowedDomains.includes(e)||this.allowedDomains.push(e),this}disallowDomain(e){return this.allowedDomains=this.allowedDomains.filter(t=>t!==e),this}clearAllowedDomains(){return this.allowedDomains=[],this}}class Lt{resolveWithoutLimits(e){return this.resolve(e,j)}}class zt extends Lt{mergingProcessor;nodeProvider;constructor(e,t){super(),this.mergingProcessor=e,this.nodeProvider=oe.wrap(t)}merge(e,t,s){if(u.isNonNullable(t.getBlue()))throw new Error('Document contains "blue" attribute. Preprocess document before merging.');let n=e;const i=t.getType();if(u.isNonNullable(i)){const o=i.clone();u.isNonNullable(o.getBlueId())&&new ke(this.nodeProvider).extend(o,be.withSinglePath("/"));const l=this.resolve(o,s),a=t.clone().setType(l);return n=this.merge(n,o,s),this.mergeObject(n,a,s)}return this.mergeObject(n,t,s)}mergeObject(e,t,s){let n=this.mergingProcessor.process(e,t,this.nodeProvider);const i=t.getItems();u.isNonNullable(i)&&(n=this.mergeChildren(n,i,s));const o=t.getProperties();return u.isNonNullable(o)&&Object.entries(o).forEach(([l,a])=>{s.shouldMergePathSegment(l,a)&&(s.enterPathSegment(l,a),n=this.mergeProperty(n,l,a,s),s.exitPathSegment())}),u.isNonNullable(t.getBlueId())&&(n=n.clone().setBlueId(t.getBlueId())),this.mergingProcessor.postProcess&&(n=this.mergingProcessor.postProcess(n,t,this.nodeProvider)),n}mergeChildren(e,t,s){const n=e.getItems();if(u.isNullable(n)){const o=t.filter((l,a)=>s.shouldMergePathSegment(String(a),l)).map(l=>{s.enterPathSegment(String(t.indexOf(l)),l);const a=this.resolve(l,s);return s.exitPathSegment(),a});return e.clone().setItems(o)}else if(t.length<n.length)throw new Error(`Subtype of element must not have more items (${n.length}) than the element itself (${t.length}).`);const i=[...n];for(let o=0;o<t.length;o++){if(!s.shouldMergePathSegment(String(o),t[o]))continue;if(s.enterPathSegment(String(o),t[o]),o>=i.length){i.push(t[o]),s.exitPathSegment();continue}const l=I.calculateBlueIdSync(t[o]),a=I.calculateBlueIdSync(i[o]);if(l!==a)throw new Error(`Mismatched items at index ${o}: source item has blueId '${l}', but target item has blueId '${a}'.`);s.exitPathSegment()}return e.clone().setItems(i)}mergeProperty(e,t,s,n){const i=this.resolve(s,n),o=e.clone();u.isNullable(o.getProperties())&&o.setProperties({});const l=o.getProperties()[t];return l===void 0?o.getProperties()[t]=i:o.getProperties()[t]=this.mergeObject(l,i,n),o}resolve(e,t){const s=new d,i=this.merge(s,e,t).clone().setName(e.getName()).setDescription(e.getDescription()).setBlueId(e.getBlueId());return new q(i)}}class Ut{mergingProcessors;constructor(e){this.mergingProcessors=e}process(e,t,s){return this.mergingProcessors.reduce((n,i)=>i.process(n,t,s),e)}postProcess(e,t,s){return this.mergingProcessors.reduce((n,i)=>i.postProcess?i.postProcess(n,t,s):n,e)}}class _t{process(e,t){const s=t.getValue();if(u.isNonNullable(s)){const n=e.getValue();if(u.isNullable(n))return e.clone().setValue(s);if(!jr(s,n))throw new Error(`Node values conflict. Source node value: ${s}, target node value: ${n}`)}return e}}const jr=(r,e)=>O(r)&&O(e)||pe(r)&&pe(e)?r.eq(e):r===e;class Zt{process(e,t,s){const n=e.getType(),i=t.getType();let o=e;if(n===void 0)o=e.clone().setType(i);else if(i!==void 0){if(!T(i,n,s)){const a=m.get(i),p=m.get(n);throw new Error(`The source type '${JSON.stringify(a)}' is not a subtype of the target type '${JSON.stringify(p)}'.`)}o=e.clone().setType(i)}return o}}class Kt{process(e,t,s){const n=t.getItemType(),i=t.getType();if(n!==void 0&&i!==void 0&&!At(i,s))throw new Error("Source node with itemType must have a List type");const o=e.getItemType();let l=e;if(o===void 0)n!==void 0&&(l=e.clone().setItemType(n));else if(n!==void 0){if(!T(n,o,s)){const h=m.get(n),f=m.get(o);throw new Error(`The source item type '${JSON.stringify(h)}' is not a subtype of the target item type '${JSON.stringify(f)}'.`)}l=e.clone().setItemType(n)}const a=l.getItemType(),p=t.getItems();if(a!==void 0&&p!==void 0)for(const y of p){const h=y.getType();if(h!==void 0&&!T(h,a,s)){const f=m.get(h),b=m.get(a);throw new Error(`Item of type '${JSON.stringify(f)}' is not a subtype of the list's item type '${JSON.stringify(b)}'.`)}}return l}}class Yt{process(e,t,s){const n=t.getKeyType(),i=t.getValueType(),o=t.getType();if((n!==void 0||i!==void 0)&&o!==void 0&&!Vt(o,s))throw new Error("Source node with keyType or valueType must have a Dictionary type");let l=this.processKeyType(e,t,s);l=this.processValueType(l,t,s);const a=l.getKeyType(),p=l.getValueType(),y=t.getProperties();return(a!==void 0||p!==void 0)&&y!==void 0&&Object.entries(y).forEach(([h,f])=>{a!==void 0&&this.validateKeyType(h,a,s),p!==void 0&&this.validateValueType(f,p,s)}),l}processKeyType(e,t,s){const n=e.getKeyType(),i=t.getKeyType();if(n===void 0){if(i!==void 0)return this.validateBasicKeyType(i,s),e.clone().setKeyType(i)}else if(i!==void 0){if(this.validateBasicKeyType(i,s),!T(i,n,s)){const l=m.get(i),a=m.get(n);throw new Error(`The source key type '${JSON.stringify(l)}' is not a subtype of the target key type '${JSON.stringify(a)}'.`)}return e.clone().setKeyType(i)}return e}processValueType(e,t,s){const n=e.getValueType(),i=t.getValueType();if(n===void 0){if(i!==void 0)return e.clone().setValueType(i)}else if(i!==void 0){if(!T(i,n,s)){const l=m.get(i),a=m.get(n);throw new Error(`The source value type '${JSON.stringify(l)}' is not a subtype of the target value type '${JSON.stringify(a)}'.`)}return e.clone().setValueType(i)}return e}validateBasicKeyType(e,t){if(!Ks(e,t))throw new Error("Dictionary key type must be a basic type")}validateKeyType(e,t,s){if(!Ys(t,s))if(Gs(t,s)){const n=Number.parseInt(e,10);if(Number.isNaN(n)||n.toString()!==e)throw new Error(`Key '${e}' is not a valid Integer.`)}else if(Js(t,s)){const n=Number.parseFloat(e);if(Number.isNaN(n))throw new Error(`Key '${e}' is not a valid Number.`)}else if(ks(t,s)){if(e.toLowerCase()!=="true"&&e.toLowerCase()!=="false")throw new Error(`Key '${e}' is not a valid Boolean.`)}else throw new Error(`Unsupported key type: ${t.getName()||"unknown"}`)}validateValueType(e,t,s){const n=e.getType();if(n!==void 0&&!T(n,t,s)){const i=m.get(n),o=m.get(t);throw new Error(`Value of type '${JSON.stringify(i)}' is not a subtype of the dictionary's value type '${JSON.stringify(o)}'.`)}}}class Gt{process(e){return e}postProcess(e,t,s){const n=e.getType();if(n!==void 0&&Hs(n,s)){const i=e.getItems(),o=e.getProperties();if(i!==void 0&&i.length>0||o!==void 0&&Object.keys(o).length>0){const l=Ws(n,s),a=n.getName()||"unknown";throw new Error(`Node of type "${a}" (which extends basic type "${l}") must not have items, properties or contracts.`)}}return e}}class Jt{process(e,t){let s=e;const n=t.getName(),i=e.getName();n!==void 0&&i===void 0&&(s=s.clone().setName(n));const o=t.getDescription(),l=s.getDescription();return o!==void 0&&l===void 0&&(s=s.clone().setDescription(o)),s}}const xr=Object.freeze(Object.defineProperty({__proto__:null,BasicTypesVerifier:Gt,DictionaryProcessor:Yt,ListProcessor:Kt,MetadataPropagator:Jt,SequentialMergingProcessor:Ut,TypeAssigner:Zt,ValuePropagator:_t},Symbol.toStringTag,{value:"Module"}));function $r(){return new Ut([new _t,new Zt,new Kt,new Yt,new Jt,new Gt])}class Lr{nodeProvider;blueIdToInlineValue=new Map;constructor(e){const{nodeProvider:t,blueIdsMappingGenerator:s}=e;this.nodeProvider=t,Object.entries(nt).forEach(([i,o])=>{this.blueIdToInlineValue.set(i,o)});const n=s.getAllBlueIds();Object.entries(n).forEach(([i,o])=>{this.blueIdToInlineValue.has(o)||this.blueIdToInlineValue.set(o,i)})}restore(e){return E.transform(e,t=>this.restoreNode(t))}restoreNode(e){return this.restoreTypeField(e,()=>e.getType(),t=>e.setType(t)),this.restoreTypeField(e,()=>e.getItemType(),t=>e.setItemType(t)),this.restoreTypeField(e,()=>e.getKeyType(),t=>e.setKeyType(t)),this.restoreTypeField(e,()=>e.getValueType(),t=>e.setValueType(t)),e}restoreTypeField(e,t,s){const n=t();if(!n||n.isInlineValue()&&n.getValue()!==void 0)return;const i=n.getBlueId();if(!i)return;const o=this.resolveInlineValue(i,n);if(!o)return;const l=new d().setValue(o).setInlineValue(!0);s(l)}resolveInlineValue(e,t){const s=this.blueIdToInlineValue.get(e);if(s)return s;const n=t.getName();if(n)return this.blueIdToInlineValue.set(e,n),n;const o=this.nodeProvider.fetchFirstByBlueId(e)?.getName();if(o)return this.blueIdToInlineValue.set(e,o),o}}class zr{nodeProvider;typeSchemaResolver;blueDirectivePreprocessor;urlContentFetcher;blueIdsMappingGenerator;globalLimits=j;mergingProcessor;repositories;constructor(e={}){const{nodeProvider:t,typeSchemaResolver:s=null,urlFetchStrategy:n,repositories:i,mergingProcessor:o}=e;this.repositories=i;const l=dr(()=>[]);if(this.nodeProvider=oe.wrap(t||l,i),this.typeSchemaResolver=s??new Et([]),this.mergingProcessor=o??$r(),this.urlContentFetcher=new Rr(n),this.blueDirectivePreprocessor=new Or(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new $t,i)for(const{schemas:a,blueIds:p}of i)this.typeSchemaResolver?.registerSchemas(a),this.blueIdsMappingGenerator.registerBlueIds(p)}nodeToJson(e,t="official"){return m.get(e,t)}nodeToSchemaOutput(e,t){return new cr(this.typeSchemaResolver).convert(e,t)}resolve(e,t=j){const s=this.combineWithGlobalLimits(t);return new zt(this.mergingProcessor,this.nodeProvider).resolve(e,s)}createResolvedNode(e){return e instanceof q?e:new q(e)}reverse(e){return new Mt().reverse(e)}restoreInlineTypes(e){return new Lr({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).restore(e)}extend(e,t){const s=this.combineWithGlobalLimits(t);new ke(this.nodeProvider).extend(e,s)}jsonValueToNode(e){return this.preprocess(g.deserialize(e))}async jsonValueToNodeAsync(e){return this.preprocessAsync(g.deserialize(e))}yamlToNode(e){const t=M(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=M(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}prepareForBlueIdCalculation=async e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?await Promise.all(e.map(s=>this.jsonValueToNodeAsync(s))):this.jsonValueToNodeAsync(e);calculateBlueId=async e=>{const t=await this.prepareForBlueIdCalculation(e);return I.calculateBlueId(t)};prepareForBlueIdCalculationSync=e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?e.map(t=>this.jsonValueToNode(t)):this.jsonValueToNode(e);calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return I.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new X({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new X({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}transform(e,t){return E.transform(e,t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=oe.wrap(e,this.repositories),this}getTypeSchemaResolver(){return this.typeSchemaResolver}setTypeSchemaResolver(e){return this.typeSchemaResolver=e,this}getUrlContentFetcher(){return this.urlContentFetcher}setUrlFetchStrategy(e){return this.urlContentFetcher.setFetchStrategy(e),this}enablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.enableFetching(),this}enablePreprocessingDirectivesFetchForDomains(e){return this.urlContentFetcher.enableFetchingForDomains(e),this}allowUrlFetchingForDomain(e){return this.urlContentFetcher.allowDomain(e),this}disallowUrlFetchingForDomain(e){return this.urlContentFetcher.disallowDomain(e),this}getAllowedUrlFetchingDomains(){return this.urlContentFetcher.getAllowedDomains()}disablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.disableFetching(),this}isPreprocessingDirectivesFetchForUrlsEnabled(){return this.urlContentFetcher.isFetchingEnabled()}getPreprocessingAliases(){return this.blueDirectivePreprocessor.getPreprocessingAliases()}setPreprocessingAliases(e){return this.blueDirectivePreprocessor.setPreprocessingAliases(e),this}registerBlueIds(...e){return this.blueIdsMappingGenerator.registerBlueIds(...e),this}getAllRegisteredBlueIds(){return this.blueIdsMappingGenerator.getAllBlueIds()}getAllBlueIdNames(){return this.blueIdsMappingGenerator.getAllBlueIdNames()}getBlueIdsMappingGenerator(){return this.blueIdsMappingGenerator}isTypeOf(e,t,s){return S.isTypeOf(e,t,{checkSchemaExtensions:s?.checkSchemaExtensions,typeSchemaResolver:this.typeSchemaResolver})}isTypeOfNode(e,t){return new qs(this).matchesType(e,t,this.globalLimits)}setGlobalLimits(e){return this.globalLimits=e??j,this}getGlobalLimits(){return this.globalLimits}combineWithGlobalLimits(e){return this.globalLimits==j?e:e==j?this.globalLimits:Te.of(this.globalLimits,e)}}class Ur extends Ft{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;preprocessor;constructor(e=[]){super();const t=new X({nodeProvider:this});this.preprocessor=s=>t.preprocessWithDefaultBlue(s),e.forEach(s=>this.processNode(s))}processNode(e){me.hasItemsOnly(e)?this.processNodeWithItems(e):this.processSingleNode(e)}processSingleNode(e){const t=$.parseAndCalculateBlueIdForNode(e,this.preprocessor);this.blueIdToContentMap.set(t.blueId,t.content),this.blueIdToMultipleDocumentsMap.set(t.blueId,t.isMultipleDocuments);const s=e.getName();s&&this.addToNameMap(s,t.blueId)}processNodeWithItems(e){const t=e.getItems();if(!t)return;this.processNodeList(t);const s=$.parseAndCalculateBlueIdForNodeList(t,this.preprocessor);this.blueIdToContentMap.set(s.blueId,s.content),this.blueIdToMultipleDocumentsMap.set(s.blueId,!0),t.forEach((n,i)=>{const o=n.getName();o&&this.addToNameMap(o,`${s.blueId}#${i}`)})}processNodeList(e){const t=I.calculateBlueIdSync(e),s=e.map(n=>m.get(n));this.blueIdToContentMap.set(t,s),this.blueIdToMultipleDocumentsMap.set(t,!0)}fetchContentByBlueId(e){const t=this.blueIdToContentMap.get(e),s=this.blueIdToMultipleDocumentsMap.get(e);return t!==void 0&&s!==void 0?$.resolveThisReferences(t,e,s):null}addSingleNodes(...e){e.forEach(t=>this.processNode(t))}addSingleDocs(...e){e.forEach(t=>{const s=M(t);if(s!==void 0){const n=g.deserialize(s);this.processNode(n)}})}getBlueIdByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t||t.length===0)throw new Error(`No node with name "${e}"`);return t[0]}getNodeByName(e){const t=this.findNodeByName(e);if(!t)throw new Error(`No node with name "${e}"`);return t}addListAndItsItemsFromNodes(e){this.processNodeList(e),e.forEach(t=>this.processNode(t))}addListAndItsItemsFromDoc(e){const t=M(e);if(t!==void 0){const n=g.deserialize(t).getItems();n&&this.addListAndItsItems(n)}}addListAndItsItems(e){Array.isArray(e)?this.addListAndItsItemsFromNodes(e):this.addListAndItsItemsFromDoc(e)}addList(e){this.processNodeList(e)}}exports.Base58Sha256Provider=ct;exports.BasicNodeProvider=Ur;exports.Blue=zr;exports.BlueIdCalculator=I;exports.BlueIdToCid=Bs;exports.BlueNode=d;exports.BlueNodeTypeSchema=S;exports.JsonCanonicalizer=ut;exports.Limits=Ie;exports.Merger=zt;exports.MergingProcessors=xr;exports.NodeResolver=Lt;exports.Nodes=me;exports.ResolvedBlueNode=q;exports.TypeSchemaResolver=Et;exports.applyBlueNodePatch=Os;exports.baseBlueObjectSchema=ae;exports.blueDescriptionField=Rs;exports.blueIdField=xs;exports.blueIdSchema=ls;exports.blueNameField=$s;exports.blueNodeField=Ls;exports.blueObjectBooleanValueSchema=cs;exports.blueObjectNumberValueSchema=us;exports.blueObjectSchema=H;exports.blueObjectStringListItemsSchema=ds;exports.blueObjectStringValueSchema=as;exports.calculateBlueId=jt;exports.calculateBlueIdSync=wr;exports.enrichWithBlueId=De;exports.getBlueDescriptionAnnotation=mt;exports.getBlueIdAnnotation=bt;exports.getBlueNameAnnotation=Nt;exports.getBlueNodeAnnotation=Bt;exports.getBlueObjectItems=Pr;exports.getBlueObjectProperties=Er;exports.getBlueObjectTypeLabel=Ar;exports.getBlueObjectValue=Sr;exports.getExtendedFromSchemaAnnotation=Pt;exports.getTypeBlueIdAnnotation=St;exports.hasBlueObjectBlueIdDefined=it;exports.hasBlueObjectItemsDefined=ot;exports.hasBlueObjectNameDefined=hs;exports.hasBlueObjectTypeDefined=lt;exports.hasBlueObjectValueDefined=at;exports.isBigDecimalNumber=pe;exports.isBigIntegerNumber=O;exports.isBigNumber=P;exports.isBlueNodeSchema=Ye;exports.isBlueObject=ps;exports.isBlueObjectResolved=xt;exports.isGivenBlueObjectTypeSchema=fs;exports.isJsonBlueArray=Ue;exports.isJsonBlueObject=ze;exports.isJsonBlueValue=ms;exports.isSchemaExtendedFrom=Ge;exports.isUrl=re;exports.jsonBlueValueSchema=ie;exports.normalizeToBlueObject=Vr;exports.resolveBlueObjectItems=Oe;exports.withBlueDescription=yt;exports.withBlueId=It;exports.withBlueName=Tt;exports.withBlueNode=vt;exports.withExtendedFromSchema=wt;exports.withTypeBlueId=_s;exports.yamlBlueDump=mr;exports.yamlBlueParse=M;
26
+ `}loadDefaultSimpleBlue(){const e=this.enrichDefaultBlue(Vt);try{const t=M(e);if(t)this.defaultSimpleBlue=g.deserialize(t);else throw new Error("Failed to parse default Blue content")}catch(t){throw new Error(`Error loading default Blue: ${t}`)}}}class Er extends Ct{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;preprocessor;constructor(e){super();const t=new X({nodeProvider:this});this.preprocessor=s=>t.preprocessWithDefaultBlue(s),this.loadRepositories(e)}loadRepositories(e){for(const t of e)if(t.contents)for(const[s,n]of Object.entries(t.contents))this.processContent(n,s)}processContent(e,t){Array.isArray(e)?this.processMultipleDocuments(e,t):this.processSingleDocument(e,t)}processSingleDocument(e,t){const s=g.deserialize(e),n=x.parseAndCalculateBlueIdForNode(s,this.preprocessor),i=t||n.blueId;this.blueIdToContentMap.set(i,n.content),this.blueIdToMultipleDocumentsMap.set(i,!1);const o=s.getName();o&&this.addToNameMap(o,i)}processMultipleDocuments(e,t){const s=e.map(o=>{const l=g.deserialize(o);return this.preprocessor(l)}),n=x.parseAndCalculateBlueIdForNodeList(s,o=>o),i=t||n.blueId;this.blueIdToContentMap.set(i,n.content),this.blueIdToMultipleDocumentsMap.set(i,!0),s.forEach((o,l)=>{const a=`${i}#${l}`,p=m.get(o),y=I.calculateBlueIdSync(o);this.blueIdToContentMap.set(y,p),this.blueIdToMultipleDocumentsMap.set(y,!1);const h=o.getName();h&&this.addToNameMap(h,a)})}fetchContentByBlueId(e){const t=this.blueIdToContentMap.get(e),s=this.blueIdToMultipleDocumentsMap.get(e);return t!==void 0&&s!==void 0?x.resolveThisReferences(t,e,s):null}getBlueIds(){return Array.from(this.blueIdToContentMap.keys())}hasBlueId(e){const t=e.split("#")[0];return this.blueIdToContentMap.has(t)}}class oe{static wrap(e,t){const s=[Ye.INSTANCE];if(t&&t.length>0){const n=new Er(t);s.push(n)}return s.push(e),new lr(s)}}class Ar{preprocessingAliases=new Map;urlContentFetcher;constructor(e,t){e&&(this.preprocessingAliases=new Map(e)),this.urlContentFetcher=t}process(e){const t=this.getBlueNodeValue(e);if(t){const s=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(s,t);if(pe.isPotentialBlueId(t))return this.handleBlueId(s,t);throw se(t)?new Error(`URL '${t}' detected. Use the async version of this method to fetch the content.`):new Error(`Invalid blue value: ${t}`)}return e}async processAsync(e){const t=this.getBlueNodeValue(e);if(t){const s=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(s,t);if(pe.isPotentialBlueId(t))return this.handleBlueId(s,t);if(se(t)&&this.urlContentFetcher)try{const n=await this.fetchFromUrl(t);return n&&s.setBlue(new d().setItems(n)),s}catch(n){throw n instanceof Error?new Error(`Failed to fetch from URL '${t}'.
27
+ ${n.message}`):n}else throw se(t)?new Error(`UrlContentFetcher not provided for URL: ${t}`):new Error(`Invalid blue value: ${t}`)}return e}getBlueNodeValue(e){const s=e.getBlue()?.getValue();return s&&typeof s=="string"?s:null}handleAliasValue(e,t){return e.setBlue(new d().setBlueId(this.preprocessingAliases.get(t))),e}handleBlueId(e,t){return e.setBlue(new d().setBlueId(t)),e}async fetchFromUrl(e){if(!this.urlContentFetcher)throw new Error(`UrlContentFetcher not provided for URL: ${e}`);return await this.urlContentFetcher.fetchAndCache(e)}getPreprocessingAliases(){return new Map(this.preprocessingAliases)}setPreprocessingAliases(e){return this.preprocessingAliases=new Map(e),this}addPreprocessingAliases(e){return e.forEach((t,s)=>{this.preprocessingAliases.set(s,t)}),this}setUrlContentFetcher(e){return this.urlContentFetcher=e,this}getUrlContentFetcher(){return this.urlContentFetcher}}const Vr={fetchUrl:async r=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${r}`)}};class Cr{cache=new Map;fetchStrategy;enabled=!1;allowedDomains=[];constructor(e){this.fetchStrategy=e||Vr}validateUrl(e){if(!se(e))throw new Error(`Invalid URL: ${e}`);return!0}isDomainAllowed(e){if(this.allowedDomains.length===0)return!0;try{const t=new URL(e);return this.allowedDomains.some(s=>t.hostname===s||t.hostname.endsWith(`.${s}`))}catch{return!1}}getFromCache(e){try{return this.validateUrl(e),this.cache.get(e)||[]}catch{return[]}}async fetchAndCache(e){if(this.validateUrl(e),!this.enabled)throw new Error("URL fetching is disabled. Enable it using the enableFetching method.");if(!this.isDomainAllowed(e))throw new Error(`Domain not allowed for URL: ${e}.`);let t;try{t=await this.fetchStrategy.fetchUrl(e)}catch(l){throw new Error(`Error fetching from URL: ${e}`,{cause:l})}const{data:s,contentType:n}=t;let i;if(n.includes("application/json")||n.includes("text/yaml")||n.includes("application/yaml")||n.includes("text/plain"))i=M(s);else throw new Error(`Unsupported content type from URL: ${n}`);if(i===void 0)throw new Error(`Failed to parse content from URL: ${e}`);let o;return Array.isArray(i)?o=i.map(l=>g.deserialize(l)):o=[g.deserialize(i)],this.cache.set(e,o),o}prefetchUrl(e,t){try{this.validateUrl(e),this.cache.set(e,t)}catch{}}clearCache(){this.cache.clear()}setFetchStrategy(e){return this.fetchStrategy=e,this}getFetchStrategy(){return this.fetchStrategy}enableFetching(){return this.enabled=!0,this.allowedDomains=[],this}enableFetchingForDomains(e){return this.enabled=!0,this.allowedDomains=[...e],this}disableFetching(){return this.enabled=!1,this}isFetchingEnabled(){return this.enabled}getAllowedDomains(){return[...this.allowedDomains]}allowDomain(e){return this.allowedDomains.includes(e)||this.allowedDomains.push(e),this}disallowDomain(e){return this.allowedDomains=this.allowedDomains.filter(t=>t!==e),this}clearAllowedDomains(){return this.allowedDomains=[],this}}class Rt{resolveWithoutLimits(e){return this.resolve(e,j)}}class jt extends Rt{mergingProcessor;nodeProvider;constructor(e,t){super(),this.mergingProcessor=e,this.nodeProvider=oe.wrap(t)}merge(e,t,s){if(u.isNonNullable(t.getBlue()))throw new Error('Document contains "blue" attribute. Preprocess document before merging.');let n=e;const i=t.getType();if(u.isNonNullable(i)){const o=i.clone();u.isNonNullable(o.getBlueId())&&new Ge(this.nodeProvider).extend(o,be.withSinglePath("/"));const l=this.resolve(o,s),a=t.clone().setType(l);return n=this.merge(n,o,s),this.mergeObject(n,a,s)}return this.mergeObject(n,t,s)}mergeObject(e,t,s){let n=this.mergingProcessor.process(e,t,this.nodeProvider);const i=t.getItems();u.isNonNullable(i)&&(n=this.mergeChildren(n,i,s));const o=t.getProperties();return u.isNonNullable(o)&&Object.entries(o).forEach(([l,a])=>{s.shouldMergePathSegment(l,a)&&(s.enterPathSegment(l,a),n=this.mergeProperty(n,l,a,s),s.exitPathSegment())}),u.isNonNullable(t.getBlueId())&&(n=n.clone().setBlueId(t.getBlueId())),this.mergingProcessor.postProcess&&(n=this.mergingProcessor.postProcess(n,t,this.nodeProvider)),n}mergeChildren(e,t,s){const n=e.getItems();if(u.isNullable(n)){const o=t.filter((l,a)=>s.shouldMergePathSegment(String(a),l)).map(l=>{s.enterPathSegment(String(t.indexOf(l)),l);const a=this.resolve(l,s);return s.exitPathSegment(),a});return e.clone().setItems(o)}else if(t.length<n.length)throw new Error(`Subtype of element must not have more items (${n.length}) than the element itself (${t.length}).`);const i=[...n];for(let o=0;o<t.length;o++){if(!s.shouldMergePathSegment(String(o),t[o]))continue;if(s.enterPathSegment(String(o),t[o]),o>=i.length){i.push(t[o]),s.exitPathSegment();continue}const l=I.calculateBlueIdSync(t[o]),a=I.calculateBlueIdSync(i[o]);if(l!==a)throw new Error(`Mismatched items at index ${o}: source item has blueId '${l}', but target item has blueId '${a}'.`);s.exitPathSegment()}return e.clone().setItems(i)}mergeProperty(e,t,s,n){const i=this.resolve(s,n),o=e.clone();u.isNullable(o.getProperties())&&o.setProperties({});const l=o.getProperties()[t];return l===void 0?o.getProperties()[t]=i:o.getProperties()[t]=this.mergeObject(l,i,n),o}resolve(e,t){const s=new d,i=this.merge(s,e,t).clone().setName(e.getName()).setDescription(e.getDescription()).setBlueId(e.getBlueId());return new q(i)}}class $t{mergingProcessors;constructor(e){this.mergingProcessors=e}process(e,t,s){return this.mergingProcessors.reduce((n,i)=>i.process(n,t,s),e)}postProcess(e,t,s){return this.mergingProcessors.reduce((n,i)=>i.postProcess?i.postProcess(n,t,s):n,e)}}class xt{process(e,t){const s=t.getValue();if(u.isNonNullable(s)){const n=e.getValue();if(u.isNullable(n))return e.clone().setValue(s);if(!Mr(s,n))throw new Error(`Node values conflict. Source node value: ${s}, target node value: ${n}`)}return e}}const Mr=(r,e)=>O(r)&&O(e)||he(r)&&he(e)?r.eq(e):r===e;class Lt{process(e,t,s){const n=e.getType(),i=t.getType();let o=e;if(n===void 0)o=e.clone().setType(i);else if(i!==void 0){if(!N(i,n,s)){const a=m.get(i),p=m.get(n);throw new Error(`The source type '${JSON.stringify(a)}' is not a subtype of the target type '${JSON.stringify(p)}'.`)}o=e.clone().setType(i)}return o}}class zt{process(e,t,s){const n=t.getItemType(),i=t.getType();if(n!==void 0&&i!==void 0&&!Bt(i,s))throw new Error("Source node with itemType must have a List type");const o=e.getItemType();let l=e;if(o===void 0)n!==void 0&&(l=e.clone().setItemType(n));else if(n!==void 0){if(!N(n,o,s)){const h=m.get(n),f=m.get(o);throw new Error(`The source item type '${JSON.stringify(h)}' is not a subtype of the target item type '${JSON.stringify(f)}'.`)}l=e.clone().setItemType(n)}const a=l.getItemType(),p=t.getItems();if(a!==void 0&&p!==void 0)for(const y of p){const h=y.getType();if(h!==void 0&&!N(h,a,s)){const f=m.get(h),b=m.get(a);throw new Error(`Item of type '${JSON.stringify(f)}' is not a subtype of the list's item type '${JSON.stringify(b)}'.`)}}return l}}class Ut{process(e,t,s){const n=t.getKeyType(),i=t.getValueType(),o=t.getType();if((n!==void 0||i!==void 0)&&o!==void 0&&!wt(o,s))throw new Error("Source node with keyType or valueType must have a Dictionary type");let l=this.processKeyType(e,t,s);l=this.processValueType(l,t,s);const a=l.getKeyType(),p=l.getValueType(),y=t.getProperties();return(a!==void 0||p!==void 0)&&y!==void 0&&Object.entries(y).forEach(([h,f])=>{a!==void 0&&this.validateKeyType(h,a,s),p!==void 0&&this.validateValueType(f,p,s)}),l}processKeyType(e,t,s){const n=e.getKeyType(),i=t.getKeyType();if(n===void 0){if(i!==void 0)return this.validateBasicKeyType(i,s),e.clone().setKeyType(i)}else if(i!==void 0){if(this.validateBasicKeyType(i,s),!N(i,n,s)){const l=m.get(i),a=m.get(n);throw new Error(`The source key type '${JSON.stringify(l)}' is not a subtype of the target key type '${JSON.stringify(a)}'.`)}return e.clone().setKeyType(i)}return e}processValueType(e,t,s){const n=e.getValueType(),i=t.getValueType();if(n===void 0){if(i!==void 0)return e.clone().setValueType(i)}else if(i!==void 0){if(!N(i,n,s)){const l=m.get(i),a=m.get(n);throw new Error(`The source value type '${JSON.stringify(l)}' is not a subtype of the target value type '${JSON.stringify(a)}'.`)}return e.clone().setValueType(i)}return e}validateBasicKeyType(e,t){if(!xs(e,t))throw new Error("Dictionary key type must be a basic type")}validateKeyType(e,t,s){if(!Ls(t,s))if(zs(t,s)){const n=Number.parseInt(e,10);if(Number.isNaN(n)||n.toString()!==e)throw new Error(`Key '${e}' is not a valid Integer.`)}else if(Us(t,s)){const n=Number.parseFloat(e);if(Number.isNaN(n))throw new Error(`Key '${e}' is not a valid Number.`)}else if(_s(t,s)){if(e.toLowerCase()!=="true"&&e.toLowerCase()!=="false")throw new Error(`Key '${e}' is not a valid Boolean.`)}else throw new Error(`Unsupported key type: ${t.getName()||"unknown"}`)}validateValueType(e,t,s){const n=e.getType();if(n!==void 0&&!N(n,t,s)){const i=m.get(n),o=m.get(t);throw new Error(`Value of type '${JSON.stringify(i)}' is not a subtype of the dictionary's value type '${JSON.stringify(o)}'.`)}}}class _t{process(e){return e}postProcess(e,t,s){const n=e.getType();if(n!==void 0&&Zs(n,s)){const i=e.getItems(),o=e.getProperties();if(i!==void 0&&i.length>0||o!==void 0&&Object.keys(o).length>0){const l=Ks(n,s),a=n.getName()||"unknown";throw new Error(`Node of type "${a}" (which extends basic type "${l}") must not have items, properties or contracts.`)}}return e}}class Zt{process(e,t){let s=e;const n=t.getName(),i=e.getName();n!==void 0&&i===void 0&&(s=s.clone().setName(n));const o=t.getDescription(),l=s.getDescription();return o!==void 0&&l===void 0&&(s=s.clone().setDescription(o)),s}}const Dr=Object.freeze(Object.defineProperty({__proto__:null,BasicTypesVerifier:_t,DictionaryProcessor:Ut,ListProcessor:zt,MetadataPropagator:Zt,SequentialMergingProcessor:$t,TypeAssigner:Lt,ValuePropagator:xt},Symbol.toStringTag,{value:"Module"}));function Or(){return new $t([new xt,new Lt,new zt,new Ut,new Zt,new _t])}class Fr{nodeProvider;blueIdToInlineValue=new Map;constructor(e){const{nodeProvider:t,blueIdsMappingGenerator:s}=e;this.nodeProvider=t,Object.entries(st).forEach(([i,o])=>{this.blueIdToInlineValue.set(i,o)});const n=s.getAllBlueIds();Object.entries(n).forEach(([i,o])=>{this.blueIdToInlineValue.has(o)||this.blueIdToInlineValue.set(o,i)})}restore(e){return E.transform(e,t=>this.restoreNode(t))}restoreNode(e){return this.restoreTypeField(e,()=>e.getType(),t=>e.setType(t)),this.restoreTypeField(e,()=>e.getItemType(),t=>e.setItemType(t)),this.restoreTypeField(e,()=>e.getKeyType(),t=>e.setKeyType(t)),this.restoreTypeField(e,()=>e.getValueType(),t=>e.setValueType(t)),e}restoreTypeField(e,t,s){const n=t();if(!n||n.isInlineValue()&&n.getValue()!==void 0)return;const i=n.getBlueId();if(!i)return;const o=this.resolveInlineValue(i,n);if(!o)return;const l=new d().setValue(o).setInlineValue(!0);s(l)}resolveInlineValue(e,t){const s=this.blueIdToInlineValue.get(e);if(s)return s;const n=t.getName();if(n)return this.blueIdToInlineValue.set(e,n),n;const o=this.nodeProvider.fetchFirstByBlueId(e)?.getName();if(o)return this.blueIdToInlineValue.set(e,o),o}}class Rr{nodeProvider;typeSchemaResolver;blueDirectivePreprocessor;urlContentFetcher;blueIdsMappingGenerator;globalLimits=j;mergingProcessor;repositories;constructor(e={}){const{nodeProvider:t,typeSchemaResolver:s=null,urlFetchStrategy:n,repositories:i,mergingProcessor:o}=e;this.repositories=i;const l=or(()=>[]);if(this.nodeProvider=oe.wrap(t||l,i),this.typeSchemaResolver=s??new Pt([],{nodeProvider:this.nodeProvider}),this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this.mergingProcessor=o??Or(),this.urlContentFetcher=new Cr(n),this.blueDirectivePreprocessor=new Ar(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new Ft,i)for(const{schemas:a,blueIds:p}of i)this.typeSchemaResolver?.registerSchemas(a),this.blueIdsMappingGenerator.registerBlueIds(p)}nodeToJson(e,t="official"){return m.get(e,t)}nodeToSchemaOutput(e,t){return new ir(this.typeSchemaResolver).convert(e,t)}resolve(e,t=j){const s=this.combineWithGlobalLimits(t);return new jt(this.mergingProcessor,this.nodeProvider).resolve(e,s)}createResolvedNode(e){return e instanceof q?e:new q(e)}reverse(e){return new Et().reverse(e)}restoreInlineTypes(e){return new Fr({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).restore(e)}extend(e,t){const s=this.combineWithGlobalLimits(t);new Ge(this.nodeProvider).extend(e,s)}jsonValueToNode(e){return this.preprocess(g.deserialize(e))}async jsonValueToNodeAsync(e){return this.preprocessAsync(g.deserialize(e))}yamlToNode(e){const t=M(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=M(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}prepareForBlueIdCalculation=async e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?await Promise.all(e.map(s=>this.jsonValueToNodeAsync(s))):this.jsonValueToNodeAsync(e);calculateBlueId=async e=>{const t=await this.prepareForBlueIdCalculation(e);return I.calculateBlueId(t)};prepareForBlueIdCalculationSync=e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?e.map(t=>this.jsonValueToNode(t)):this.jsonValueToNode(e);calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return I.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new X({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new X({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}transform(e,t){return E.transform(e,t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=oe.wrap(e,this.repositories),this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this}getTypeSchemaResolver(){return this.typeSchemaResolver}setTypeSchemaResolver(e){return this.typeSchemaResolver=e,this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this}getUrlContentFetcher(){return this.urlContentFetcher}setUrlFetchStrategy(e){return this.urlContentFetcher.setFetchStrategy(e),this}enablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.enableFetching(),this}enablePreprocessingDirectivesFetchForDomains(e){return this.urlContentFetcher.enableFetchingForDomains(e),this}allowUrlFetchingForDomain(e){return this.urlContentFetcher.allowDomain(e),this}disallowUrlFetchingForDomain(e){return this.urlContentFetcher.disallowDomain(e),this}getAllowedUrlFetchingDomains(){return this.urlContentFetcher.getAllowedDomains()}disablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.disableFetching(),this}isPreprocessingDirectivesFetchForUrlsEnabled(){return this.urlContentFetcher.isFetchingEnabled()}getPreprocessingAliases(){return this.blueDirectivePreprocessor.getPreprocessingAliases()}setPreprocessingAliases(e){return this.blueDirectivePreprocessor.setPreprocessingAliases(e),this}registerBlueIds(...e){return this.blueIdsMappingGenerator.registerBlueIds(...e),this}getAllRegisteredBlueIds(){return this.blueIdsMappingGenerator.getAllBlueIds()}getAllBlueIdNames(){return this.blueIdsMappingGenerator.getAllBlueIdNames()}getBlueIdsMappingGenerator(){return this.blueIdsMappingGenerator}isTypeOf(e,t,s){return S.isTypeOf(e,t,{checkSchemaExtensions:s?.checkSchemaExtensions,typeSchemaResolver:this.typeSchemaResolver})}isTypeOfNode(e,t){return new Gs(this).matchesType(e,t,this.globalLimits)}setGlobalLimits(e){return this.globalLimits=e??j,this}getGlobalLimits(){return this.globalLimits}combineWithGlobalLimits(e){return this.globalLimits==j?e:e==j?this.globalLimits:Ne.of(this.globalLimits,e)}}class jr extends Ct{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;preprocessor;constructor(e=[]){super();const t=new X({nodeProvider:this});this.preprocessor=s=>t.preprocessWithDefaultBlue(s),e.forEach(s=>this.processNode(s))}processNode(e){me.hasItemsOnly(e)?this.processNodeWithItems(e):this.processSingleNode(e)}processSingleNode(e){const t=x.parseAndCalculateBlueIdForNode(e,this.preprocessor);this.blueIdToContentMap.set(t.blueId,t.content),this.blueIdToMultipleDocumentsMap.set(t.blueId,t.isMultipleDocuments);const s=e.getName();s&&this.addToNameMap(s,t.blueId)}processNodeWithItems(e){const t=e.getItems();if(!t)return;this.processNodeList(t);const s=x.parseAndCalculateBlueIdForNodeList(t,this.preprocessor);this.blueIdToContentMap.set(s.blueId,s.content),this.blueIdToMultipleDocumentsMap.set(s.blueId,!0),t.forEach((n,i)=>{const o=n.getName();o&&this.addToNameMap(o,`${s.blueId}#${i}`)})}processNodeList(e){const t=I.calculateBlueIdSync(e),s=e.map(n=>m.get(n));this.blueIdToContentMap.set(t,s),this.blueIdToMultipleDocumentsMap.set(t,!0)}fetchContentByBlueId(e){const t=this.blueIdToContentMap.get(e),s=this.blueIdToMultipleDocumentsMap.get(e);return t!==void 0&&s!==void 0?x.resolveThisReferences(t,e,s):null}addSingleNodes(...e){e.forEach(t=>this.processNode(t))}addSingleDocs(...e){e.forEach(t=>{const s=M(t);if(s!==void 0){const n=g.deserialize(s);this.processNode(n)}})}getBlueIdByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t||t.length===0)throw new Error(`No node with name "${e}"`);return t[0]}getNodeByName(e){const t=this.findNodeByName(e);if(!t)throw new Error(`No node with name "${e}"`);return t}addListAndItsItemsFromNodes(e){this.processNodeList(e),e.forEach(t=>this.processNode(t))}addListAndItsItemsFromDoc(e){const t=M(e);if(t!==void 0){const n=g.deserialize(t).getItems();n&&this.addListAndItsItems(n)}}addListAndItsItems(e){Array.isArray(e)?this.addListAndItsItemsFromNodes(e):this.addListAndItsItemsFromDoc(e)}addList(e){this.processNodeList(e)}}exports.Base58Sha256Provider=at;exports.BasicNodeProvider=jr;exports.Blue=Rr;exports.BlueIdCalculator=I;exports.BlueIdToCid=bs;exports.BlueNode=d;exports.BlueNodeTypeSchema=S;exports.JsonCanonicalizer=lt;exports.Limits=Ie;exports.Merger=jt;exports.MergingProcessors=Dr;exports.NodeResolver=Rt;exports.Nodes=me;exports.ResolvedBlueNode=q;exports.TypeSchemaResolver=Pt;exports.applyBlueNodePatch=Vs;exports.baseBlueObjectSchema=ae;exports.blueDescriptionField=Ms;exports.blueIdField=Os;exports.blueIdSchema=rs;exports.blueNameField=Fs;exports.blueNodeField=Rs;exports.blueObjectBooleanValueSchema=os;exports.blueObjectNumberValueSchema=is;exports.blueObjectSchema=H;exports.blueObjectStringListItemsSchema=ls;exports.blueObjectStringValueSchema=ns;exports.calculateBlueId=Dt;exports.calculateBlueIdSync=br;exports.enrichWithBlueId=Me;exports.getBlueDescriptionAnnotation=gt;exports.getBlueIdAnnotation=mt;exports.getBlueNameAnnotation=bt;exports.getBlueNodeAnnotation=Tt;exports.getBlueObjectItems=Nr;exports.getBlueObjectProperties=vr;exports.getBlueObjectTypeLabel=Br;exports.getBlueObjectValue=Tr;exports.getTypeBlueIdAnnotation=vt;exports.hasBlueObjectBlueIdDefined=rt;exports.hasBlueObjectItemsDefined=nt;exports.hasBlueObjectNameDefined=us;exports.hasBlueObjectTypeDefined=it;exports.hasBlueObjectValueDefined=ot;exports.isBigDecimalNumber=he;exports.isBigIntegerNumber=O;exports.isBigNumber=P;exports.isBlueNodeSchema=Ke;exports.isBlueObject=as;exports.isBlueObjectResolved=Ot;exports.isGivenBlueObjectTypeSchema=cs;exports.isJsonBlueArray=ze;exports.isJsonBlueObject=Le;exports.isJsonBlueValue=hs;exports.isUrl=se;exports.jsonBlueValueSchema=ne;exports.normalizeToBlueObject=wr;exports.resolveBlueObjectItems=De;exports.withBlueDescription=ft;exports.withBlueId=yt;exports.withBlueName=It;exports.withBlueNode=Nt;exports.withTypeBlueId=$s;exports.yamlBlueDump=pr;exports.yamlBlueParse=M;