@blue-labs/language 1.21.1 → 1.22.0

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";var At=Object.defineProperty;var St=(n,e,t)=>e in n?At(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var h=(n,e,t)=>St(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@blue-labs/shared-utils"),l=require("zod"),Ct=require("bs58"),R=require("big.js"),w=require("radash"),Ot=require("js-sha256"),Dt=require("crypto"),Ft=require("base32.js"),M=require("js-yaml"),Je=n=>n&&n.__esModule?n:{default:n},X=Je(Ct),Le=Je(Dt);class Vt{static get(e,t,r,s=!0){if(d.isNullable(t)||!t.startsWith("/"))throw new Error(`Invalid path: ${t}`);if(t==="/"){const o=e.getValue();return s&&o!==void 0?o:e}const i=t.substring(1).split("/");return this.getRecursive(e,i,0,r,s)}static getRecursive(e,t,r,s,i){if(r===t.length-1&&!i)return this.getNodeForSegment(e,t[r],s,!1);if(r===t.length){const u=e.getValue();return i&&u!==void 0?u:e}const o=t[r],c=this.getNodeForSegment(e,o,s,!0);if(c)return this.getRecursive(c,t,r+1,s,i)}static getNodeForSegment(e,t,r,s){let i;const o=e.getProperties();if(o&&t in o)i=o[t];else switch(t){case"name":{const c=e.getName();i=d.isNonNullable(c)?new a().setValue(c):new a;break}case"description":{const c=e.getDescription();i=d.isNonNullable(c)?new a().setValue(c):new a;break}case"type":i=e.getType()??new a;break;case"itemType":i=e.getItemType()??new a;break;case"keyType":i=e.getKeyType()??new a;break;case"valueType":i=e.getValueType()??new a;break;case"value":{const c=e.getValue();i=new a().setValue(c??null);break}case"blueId":{const c=e.getBlueId();i=d.isNonNullable(c)?new a().setValue(c):new a;break}case"blue":i=e.getBlue();break;case"items":{const c=e.getItems();i=new a().setItems(c);break}case"properties":{const c=e.getProperties();i=new a().setProperties(c);break}case"contracts":{const c=e.getContracts();i=new a().setContracts(c);break}default:{if(/^\d+$/.test(t)){const c=parseInt(t,10),u=e.getItems();u&&c>=0&&c<u.length?i=u[c]:i=void 0}else i=void 0;break}}if(i)return s&&r?this.link(i,r):i}static link(e,t){const r=t(e);return d.isNonNullable(r)?r:e}}class v extends R{constructor(e){super(e)}}class P extends R{constructor(e){super(e)}}const $="name",L="description",oe="type",De="itemType",Fe="keyType",Ve="valueType",fe="value",je="items",U="blueId",Re="blue",pe="contracts",jt=[$,L,oe,De,Fe,Ve,fe,je,U,Re,pe],Rt="Text",zt="Double",Zt="Integer",xt="Boolean",Ut="List",Mt="Dictionary",$t=[Rt,zt,Zt,xt],He=[...$t,Ut,Mt],ee="F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP",te="68ryJtnmui4j5rCZWUnkZ3DChtmEb7Z9F8atn1mBSM3L",ne="DHmxTkFbXePZHCHCYmQr2dSzcNLcryFVjXVHkdQrrZr8",re="EL6AjrbJsxTWRTPzY8WR8Y2zAMXRbydQj83PcZwuAHbo",Lt="G8wmfjEqugPEEXByMYWJXiEdbLToPRWNQEekNxrxfQWB",_t="294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA",kt=[ee,te,ne,re],ze=[...kt,Lt,_t];Object.fromEntries(He.map((n,e)=>[n,ze[e]]));Object.fromEntries(ze.map((n,e)=>[n,He[e]]));const F=class F{constructor(e){h(this,"name");h(this,"description");h(this,"type");h(this,"itemType");h(this,"keyType");h(this,"valueType");h(this,"value");h(this,"items");h(this,"properties");h(this,"contracts");h(this,"blueId");h(this,"blue");h(this,"inlineValue",!1);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 F().setValue(e).setInlineValue(!0):this.type=e,this}getItemType(){return this.itemType}setItemType(e){return typeof e=="string"?this.itemType=new F().setValue(e).setInlineValue(!0):this.itemType=e,this}getKeyType(){return this.keyType}setKeyType(e){return typeof e=="string"?this.keyType=new F().setValue(e).setInlineValue(!0):this.keyType=e,this}getValueType(){return this.valueType}setValueType(e){return typeof e=="string"?this.valueType=new F().setValue(e).setInlineValue(!0):this.valueType=e,this}getValue(){var t;const e=(t=this.type)==null?void 0:t.getBlueId();if(d.isNonNullable(e)&&d.isNonNullable(this.value)){if(e===ne&&typeof this.value=="string")return new v(this.value);if(e===te&&typeof this.value=="string"){const r=new P(this.value),s=parseFloat(r.toString());return new P(s.toString())}else if(e===re&&typeof this.value=="string")return this.value.toLowerCase()==="true"}return this.value}setValue(e){return typeof e=="number"?e%1===0?this.value=new v(e.toString()):this.value=new P(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}getContracts(){return this.contracts}setContracts(e){return this.contracts=e,this}addContract(e,t){return this.contracts||(this.contracts={}),this.contracts[e]=t,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}get(e,t){return Vt.get(this,e,t)}clone(){var t,r,s,i,o,c;const e=new F(this.name);return e.description=this.description,e.type=(t=this.type)==null?void 0:t.clone(),e.itemType=(r=this.itemType)==null?void 0:r.clone(),e.keyType=(s=this.keyType)==null?void 0:s.clone(),e.valueType=(i=this.valueType)==null?void 0:i.clone(),e.value=this.value,e.items=(o=this.items)==null?void 0:o.map(u=>u.clone()),this.properties&&(e.properties=Object.fromEntries(Object.entries(this.properties).map(([u,f])=>[u,f.clone()]))),this.contracts&&(e.contracts=Object.fromEntries(Object.entries(this.contracts).map(([u,f])=>[u,f.clone()]))),e.blueId=this.blueId,e.blue=(c=this.blue)==null?void 0:c.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}, contracts=${this.contracts}, blueId='${this.blueId}', blue=${this.blue}, inlineValue=${this.inlineValue}}`}};h(F,"INTEGER",new F("Integer"));let a=F;class x{static isPotentialBlueId(e){if(!e||e.length===0||!this.BLUE_ID_PATTERN.test(e))return!1;const t=e.split("#"),r=t[0],s=r.length;if(s<this.MIN_BLUE_ID_LENGTH||s>this.MAX_BLUE_ID_LENGTH)return!1;try{if(X.default.decode(r).length!==32)return!1}catch{return!1}if(t.length>1)try{if(Number(t[1])<0)return!1}catch{return!1}return!0}}h(x,"MIN_BLUE_ID_LENGTH",41),h(x,"MAX_BLUE_ID_LENGTH",45),h(x,"BLUE_ID_PATTERN",/^[1-9A-HJ-NP-Za-km-z]{41,45}(?:#\d+)?$/);const Yt=l.z.string().max(x.MAX_BLUE_ID_LENGTH,{message:"Blue Id has a maximum length of 45 characters"}).min(x.MIN_BLUE_ID_LENGTH,{message:"Blue Id has a minimum length of 41 characters"}).refine(n=>{try{return X.default.decode(n),!0}catch{return!1}},{message:"Blue Id must be a valid Base58 string"}),_=l.z.lazy(()=>l.z.record(l.z.unknown()).and(l.z.object({blueId:l.z.string().optional(),name:l.z.string().optional(),description:l.z.string().optional(),type:_.optional(),value:l.z.union([l.z.string(),l.z.number(),l.z.boolean()]).optional().nullable(),items:l.z.array(_).optional()}))),se=l.z.object({blueId:l.z.string().optional(),name:l.z.string().optional(),description:l.z.string().optional(),type:_.optional()}),Gt=se.extend({value:l.z.string().optional()}),Jt=se.extend({value:l.z.number().optional()}),Ht=se.extend({value:l.z.boolean().optional()}),Wt=se.extend({items:l.z.array(l.z.string()).optional()}),Kt=n=>_.safeParse(n).success,We=n=>d.isNonNullable(n)&&"blueId"in n&&d.isNonNullable(n.blueId),qt=n=>d.isNonNullable(n)&&"name"in n&&d.isNonNullable(n.name),Ke=n=>d.isNonNullable(n)&&"items"in n&&d.isNonNullable(n.items),qe=n=>d.isNonNullable(n)&&"type"in n&&d.isNonNullable(n.type),Xe=n=>d.isNonNullable(n)&&"value"in n&&d.isNonNullable(n.value),Xt=(n,e)=>n.required({type:!0}).safeParse(e).success,A=n=>n instanceof R,k=n=>A(n)&&n instanceof v,Qe=n=>A(n)&&n instanceof P,Qt=l.z.lazy(()=>l.z.record(Q)),en=l.z.lazy(()=>l.z.union([l.z.array(Q),l.z.array(Q).readonly()])),Q=l.z.lazy(()=>l.z.union([d.jsonPrimitiveSchema,Qt,en,l.z.instanceof(R)])),Ze=n=>w.isObject(n)&&!w.isArray(n)&&!d.isReadonlyArray(n)&&!A(n),xe=n=>w.isArray(n)||d.isReadonlyArray(n),tn=n=>xe(n)||Ze(n)||A(n)||d.isJsonPrimitive(n);class y{static deserialize(e){return y.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 a,r={},s={};return Object.entries(e).forEach(([i,o])=>{switch(i){case $:if(o==null)t.setName(void 0);else{if(typeof o!="string")throw new Error(`The ${$} field must be a string.`);t.setName(o)}break;case L:if(o==null)t.setDescription(void 0);else{if(typeof o!="string")throw new Error(`The ${L} field must be a string.`);t.setDescription(o)}break;case oe:t.setType(y.handleNode(o));break;case De:t.setItemType(y.handleNode(o));break;case Fe:t.setKeyType(y.handleNode(o));break;case Ve:t.setValueType(y.handleNode(o));break;case fe:t.setValue(y.handleValue(o));break;case U:if(typeof o!="string")throw new Error(`The ${U} field must be a string.`);t.setBlueId(o);break;case je:t.setItems(y.handleArray(o));break;case Re:t.setBlue(y.handleNode(o));break;case pe:w.isObject(o)&&!w.isArray(o)&&!d.isReadonlyArray(o)&&Object.entries(o).forEach(([c,u])=>{s[c]=y.handleNode(u)});break;default:r[i]=y.handleNode(o);break}}),Object.keys(r).length>0&&t.setProperties(r),Object.keys(s).length>0&&t.setContracts(s),t}else{if(xe(e))return new a().setItems(y.handleArray(e));{const t=e;return new a().setValue(y.handleValue(t)).setInlineValue(!0)}}}static handleValue(e){if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="number"||A(e))if(k(e)||Number.isSafeInteger(e)){const t=new v(e.toString()),r=Number.MIN_SAFE_INTEGER,s=Number.MAX_SAFE_INTEGER;return t.lt(r)?new v(r.toString()):t.gt(s)?new v(s.toString()):t}else{const t=parseFloat(e.toString());return new P(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(w.isObject(e)&&!Array.isArray(e))return[y.handleNode(e)];if(Array.isArray(e))return e.map(y.handleNode);throw new Error("Expected an array node")}}}function nn(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var be,_e;function rn(){return _e||(_e=1,be=function n(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?n(e.toJSON()):Array.isArray(e)?`[${e.reduce((s,i,o)=>`${s}${o===0?"":","}${n(i===void 0||typeof i=="symbol"?null:i)}`,"")}]`:`{${Object.keys(e).sort().reduce((r,s)=>{if(e[s]===void 0||typeof e[s]=="symbol")return r;const i=r.length===0?"":",";return`${r}${i}${n(s)}:${n(e[s])}`},"")}}`}),be}var sn=rn();const on=nn(sn);class et{static canonicalize(e){return on(e)}}const ln=typeof process<"u"&&process.versions!=null&&process.versions.node!=null,ue=class ue{constructor(){h(this,"browserCrypto");this.browserCrypto=this.initBrowserCrypto()}static getInstance(){return this.instance||(this.instance=new ue),this.instance}initBrowserCrypto(){return ln?null:"crypto"in globalThis?globalThis.crypto:null}hasNodeCrypto(){return!!Le.default.createHash}getBrowserCrypto(){return this.browserCrypto}getNodeCrypto(){return Le.default}};h(ue,"instance");let Te=ue;class tt{constructor(){h(this,"cryptoEnv",Te.getInstance())}applySync(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):this.sha256SyncBrowser(t);return X.default.encode(new Uint8Array(r))}async apply(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):await this.sha256Async(t);return X.default.encode(new Uint8Array(r))}canonicalizeInput(e){const t=et.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");return t.createHash("sha256").update(e).digest()}sha256SyncBrowser(e){return Ot.sha256.arrayBuffer(e)}async sha256Async(e){if(this.cryptoEnv.hasNodeCrypto())return this.sha256Sync(e);const t=this.cryptoEnv.getBrowserCrypto();if(!t)throw new Error("crypto is not available in this environment");const s=new TextEncoder().encode(e);return t.subtle.digest("SHA-256",s)}}class B{static get(e,t="official"){var ie;const r=e.getValue(),s=this.handleValue(r);if(s!==void 0&&t==="simple")return s;const i=(ie=e.getItems())==null?void 0:ie.map(D=>B.get(D,t));if(i!==void 0&&t==="simple")return i;const o=e.getName(),c=e.getDescription();if(t==="original"&&o===void 0&&c===void 0){if(s!==void 0)return s;if(i!==void 0)return i}const u={};o!==void 0&&(u[$]=o),c!==void 0&&(u[L]=c);const f=e.getType();if(t==="official"&&r!==void 0&&f===void 0){const D=this.inferTypeBlueId(r);D!==null&&(u[oe]={[U]:D})}else f!==void 0&&(u[oe]=B.get(f,t));const I=e.getItemType();I!==void 0&&(u[De]=B.get(I,t));const b=e.getKeyType();b!==void 0&&(u[Fe]=B.get(b,t));const m=e.getValueType();m!==void 0&&(u[Ve]=B.get(m,t)),s!==void 0&&(u[fe]=s),i!==void 0&&(u[je]=i);const g=e.getBlueId();g!==void 0&&(u[U]=g);const p=e.getBlue();p!==void 0&&(u[Re]=p);const T=e.getContracts();if(T!==void 0){const D={};Object.entries(T).forEach(([me,Pt])=>{D[me]=B.get(Pt,t)}),u[pe]=D}const O=e.getProperties();return O!==void 0&&Object.entries(O).forEach(([D,me])=>{u[D]=B.get(me,t)}),u}static handleValue(e){if(A(e)){if(k(e)){const t=new R(Number.MIN_SAFE_INTEGER.toString()),r=new R(Number.MAX_SAFE_INTEGER.toString());if(e.lt(t)||e.gt(r))return e.toString()}return e.toNumber()}return e}static inferTypeBlueId(e){return typeof e=="string"?ee:A(e)?k(e)?ne:te:typeof e=="boolean"?re:null}}const cn=n=>d.isJsonPrimitive(n)&&d.isNonNullable(n),j=class j{constructor(e){h(this,"hashProvider");this.hashProvider=e}static calculateBlueId(e){if(Array.isArray(e)){const r=e.map(s=>B.get(s));return j.INSTANCE.calculate(r)}const t=B.get(e);return j.INSTANCE.calculate(t)}static calculateBlueIdSync(e){if(Array.isArray(e)){const r=e.map(s=>B.get(s));return j.INSTANCE.calculateSync(r)}const t=B.get(e);return j.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 cn(e)||A(e)?this.applyHash(e.toString(),t):Array.isArray(e)||d.isReadonlyArray(e)?this.calculateList(e,t):this.calculateMap(e,t)}calculateMap(e,t){if(e[U]!==void 0)return e[U];const s=Object.keys(e).map(o=>{const c=e[o];if([$,fe,L].includes(o))return t?[o,c]:Promise.resolve([o,c]);{const u=this.internalCalculate(c,t);return t?[o,{blueId:u}]:Promise.resolve(u).then(f=>[o,{blueId:f}])}}),i=o=>{const c={};for(const[u,f]of o)c[u]=f;return this.applyHash(c,t)};return t?i(s):Promise.all(s).then(i)}calculateList(e,t){if(e.length===0)throw new Error("Cannot calculate BlueId for an empty list.");let r=this.internalCalculate(e[0],t);const s=(i,o)=>t?this.applyHash([{blueId:i},{blueId:o}],!0):Promise.all([i,o]).then(([c,u])=>this.applyHash([{blueId:c},{blueId:u}],!1));for(let i=1;i<e.length;i++){const o=this.internalCalculate(e[i],t);r=s(r,o)}return r}applyHash(e,t){return t?this.hashProvider.applySync(e):this.hashProvider.apply(e)}cleanStructure(e){if(e!=null){if(d.isJsonPrimitive(e)||A(e))return e;if(Array.isArray(e)||d.isReadonlyArray(e)){const t=e.map(r=>this.cleanStructure(r)).filter(d.isNonNullable);return t.length>0?t:void 0}else if(typeof e=="object"){const t={};for(const r in e){const s=this.cleanStructure(e[r]);s!=null&&(t[r]=s)}return Object.keys(t).length>0?t:void 0}else return e}}};h(j,"INSTANCE",new j(new tt));let S=j;class an{static convert(e){const t=X.default.decode(e),r=new Uint8Array(2+t.length);r[0]=18,r[1]=32,r.set(t,2);const s=new Uint8Array(2+r.length);return s[0]=1,s[1]=85,s.set(r,2),"b"+new Ft.Encoder({type:"rfc4648",lc:!0}).write(s).finalize().replace(/=/g,"")}}class C{static transform(e,t){const r=t(e.clone()),s=r.getType();s!==void 0&&r.setType(C.transform(s,t));const i=r.getItemType();i!==void 0&&r.setItemType(C.transform(i,t));const o=r.getKeyType();o!==void 0&&r.setKeyType(C.transform(o,t));const c=r.getValueType();c!==void 0&&r.setValueType(C.transform(c,t));const u=r.getItems();if(u!==void 0){const b=u.map(m=>C.transform(m,t));r.setItems(b)}const f=r.getProperties();if(f!==void 0){const b=Object.keys(f).reduce((m,g)=>(m[g]=C.transform(f[g],t),m),{});r.setProperties(b)}const I=r.getContracts();if(I!==void 0){const b=Object.keys(I).reduce((m,g)=>(m[g]=C.transform(I[g],t),m),{});r.setContracts(b)}return r}}const z=n=>!!n&&typeof n=="object"&&!Array.isArray(n)&&!(n instanceof a),V=n=>n instanceof v||n instanceof P,un=n=>n.replace(/~1/g,"/").replace(/~0/g,"~");function J(n){if(n==="/")return[];if(!n.startsWith("/"))throw new Error(`Path must start with '/': ${n}`);return n.split("/").slice(1).map(un)}function Y(n){if(n==="-")return-1;const e=typeof n=="number"?n:parseInt(n,10);if(isNaN(e))throw new Error(`Invalid array index (NaN) from '${n}'`);if(!Number.isFinite(e))throw new Error(`Invalid array index '${n}' results in non-finite number ${e}`);return e}function nt(n,e,t,r=!0){switch(e){case"name":return t?r?n.getName()??null:n:n.getName();case"description":return t?r?n.getDescription():n:n.getDescription();case"type":return n.getType();case"itemType":return n.getItemType();case"keyType":return n.getKeyType();case"valueType":return n.getValueType();case"value":return t?r?n.getValue()??null:n:n.getValue();case"blueId":return t?r?n.getBlueId()??null:n:n.getBlueId();case"blue":return n.getBlue();case"items":return n.getItems();case"properties":return n.getProperties();case"contracts":return n.getContracts();default:return}}function ke(n,e,t=!0){if(n instanceof a){const r=nt(n,e,!0,t);if(r!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(e))return r;if(/^-?\d+$/.test(e)&&e!=="-"){const i=n.getItems(),o=parseInt(e,10);return i&&o>=0&&o<i.length?i[o]:void 0}const s=n.getProperties();return s&&e in s?s[e]:void 0}if(Array.isArray(n)){if(e==="-")return;const r=Y(e);return r>=0&&r<n.length?n[r]:void 0}if(z(n))return n[e]}function H(n,e){if(e.length===0)return{parent:n,key:"value",actualTarget:n.getValue()??n};let t=n;for(let s=0;s<e.length-1;++s){const i=e[s],o=ke(t,i);if(o===void 0)throw new Error(`Cannot resolve '/${e.slice(0,s+1).join("/")}'`);t=o}const r=e[e.length-1];if(t instanceof a){const s=ke(t,r,!1);if((typeof s!="object"||s===null||V(s))&&!(s instanceof a)&&!Array.isArray(s)&&["name","description","value","blueId"].includes(r))return{parent:t,key:r,actualTarget:s}}return Array.isArray(t)&&r==="-"?{parent:t,key:"-"}:t instanceof a&&t.getItems()&&r==="-"?{parent:t,key:"-"}:{parent:t,key:Array.isArray(t)?Y(r):r}}function Ue(n,e){var t;if(n instanceof a){const r=e,s=nt(n,r,!1);if(s!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(r))return s;if(typeof e=="number"||typeof e=="string"&&/^\d+$/.test(e)){const i=n.getItems(),o=typeof e=="number"?e:parseInt(e,10);if(i&&o>=0&&o<i.length)return i[o]}return(t=n.getProperties())==null?void 0:t[r]}return Array.isArray(n)||z(n)?n[e]:n}function N(n){if(n instanceof a)return n;if(n===null||typeof n=="string"||typeof n=="number"||typeof n=="boolean"||V(n))return y.deserialize(n);const e=Ne(n);return y.deserialize(e)}function Ne(n){if(n===void 0)return null;if(n===null||typeof n!="object")return n;if(Array.isArray(n))return n.map(Ne);const e={};for(const[t,r]of Object.entries(n))e[t]=Ne(r);return e}function Me(n,e,t){if(n instanceof a){const r=e;switch(r){case"name":n.setName(t);return;case"description":n.setDescription(t);return;case"type":n.setType(t instanceof a||typeof t=="string"||t===void 0?t:N(t));return;case"itemType":n.setItemType(t instanceof a||typeof t=="string"||t===void 0?t:N(t));return;case"keyType":n.setKeyType(t instanceof a||typeof t=="string"||t===void 0?t:N(t));return;case"valueType":n.setValueType(t instanceof a||typeof t=="string"||t===void 0?t:N(t));return;case"value":{const s=t;n.setValue(s===void 0?null:s);return}case"blueId":n.setBlueId(t);return;case"blue":n.setBlue(t instanceof a||t===void 0?t:N(t));return;case"items":n.setItems(t);return;case"properties":n.setProperties(t);return;case"contracts":n.setContracts(t);return;default:{if(t===void 0){const s=n.getProperties();s&&r in s&&delete s[r]}else n.getProperties()||n.setProperties({}),n.addProperty(r,t instanceof a?t:N(t));return}}}Array.isArray(n)?n.splice(Y(e),1):z(n)&&(t===void 0?delete n[e]:n[e]=t)}function dn(n,e,t,r){let s=-1;if(e!=="-"&&(s=typeof e=="number"?e:parseInt(e,10),isNaN(s)))throw new Error(`Invalid numeric key for BlueNode item operation: ${e}`);if(s<-1)throw new Error(`Invalid array index for BlueNode items: ${s}`);let i=n.getItems();if(i||(i=[],n.setItems(i)),!r&&s!==-1&&s>i.length)throw new Error(`ADD operation failed: Target array index '${s}' is greater than array length ${i.length}.`);if(e==="-")i.push(t);else if(r){if(s>=0)if(s<i.length)i[s]=t;else{for(let o=i.length;o<s;o++)i.push(y.deserialize(null));i.push(t)}}else i.splice(s,0,t)}function le(n,e,t,r){if(Array.isArray(n)){const s=e==="-"?n.length:Y(e);if(!r&&s>n.length)throw new Error(`ADD operation failed: Target array index '${s}' is greater than array length ${n.length}. Path involving key '${e}'.`);if(s<0&&e!=="-")throw new Error(`Invalid negative array index: ${e}`);const i=N(t);if(r){if(s>=0&&s<n.length)n[s]=i;else if(s>=n.length){for(let o=n.length;o<s;o++)n.push(y.deserialize(null));n.push(i)}}else n.splice(s,0,i);return}if(n instanceof a){e==="-"||typeof e=="number"&&!isNaN(e)||typeof e=="string"&&/^\d+$/.test(e)?dn(n,e,N(t),r):Me(n,e,t);return}if(z(n)){n[e]=N(t);return}throw new Error(`Cannot insert into parent of type ${typeof n}`)}function hn(n,e){if(Array.isArray(n)){const t=Y(e);t===-1&&e==="-"?n.length>0&&n.pop():t>=0&&t<n.length&&n.splice(t,1);return}if(n instanceof a){if(typeof e=="number"||typeof e=="string"&&/^-?\d+$/.test(e)){const t=n.getItems();if(t){const r=Y(e);r===-1&&e==="-"?t.length>0&&t.pop():r>=0&&r<t.length&&t.splice(r,1),t.length===0&&n.setItems(void 0);return}}Me(n,e,void 0)}else z(n)&&delete n[e]}function we(n){if(n instanceof a)return n.clone();if(Array.isArray(n))return n.map(t=>we(t));if(z(n)){const e={};return Object.keys(n).forEach(t=>{e[t]=we(n[t])}),e}return n}function Z(n,e){if(n===e||n instanceof a&&(n.isInlineValue()||n.getValue()!==void 0)&&Z(n.getValue()??null,e)||e instanceof a&&(e.isInlineValue()||e.getValue()!==void 0)&&Z(n,e.getValue()??null))return!0;if(n instanceof a&&e instanceof a||V(n)&&V(e)||V(n)&&typeof e=="number"||typeof n=="number"&&V(e))return n.toString()===e.toString();if(Array.isArray(n)&&Array.isArray(e))return n.length===e.length&&n.every((t,r)=>Z(t,e[r]));if(z(n)&&z(e)){const t=Object.keys(n),r=Object.keys(e);return t.length===r.length&&t.every(s=>Z(n[s],e[s]))}return!1}function rt(n,e){const{parent:t,key:r}=H(n,J(e));return Ue(t,r)}function st(n,e,t){const r=J(e);if(r.length===0&&e==="/"){const o=N(t);n.setValue(o.getValue()??null),o.getItems()?n.setItems(o.getItems()):n.setItems(void 0);return}const{parent:s,key:i}=H(n,r);le(s,i,t,!0)}function fn(n,e,t){const r=J(e);if(r.length===0&&e==="/"){if(n.getItems()&&Array.isArray(t)){const o=N(t);o.getItems()?(n.setItems(o.getItems()),n.setValue(null)):(n.setValue(o.getValue()??null),n.setItems(void 0))}else{const o=N(t);n.setValue(o.getValue()??null),o.getItems()&&n.setItems(o.getItems())}return!0}const{parent:s,key:i}=H(n,r);return le(s,i,t,!1),!0}function pn(n,e,t){const r=J(e);if(r.length===0&&e==="/"){const c=N(t);return n.setValue(c.getValue()??null),c.getItems()?n.setItems(c.getItems()):n.setItems(void 0),!0}const{parent:s,key:i,actualTarget:o}=H(n,r);if(o!==void 0&&s instanceof a)Me(s,i,t);else{const c=Ue(s,i),u=Array.isArray(s)||s instanceof a&&s.getItems()&&(typeof i=="number"||typeof i=="string"&&/^\d+$/.test(i));if(c===void 0){if(u)throw new Error(`REPLACE failed: Target array index '${i.toString()}' is out of bounds or does not exist at path '${e}'.`);le(s,i,t,!0)}else le(s,i,t,!0)}return!0}function it(n,e){const t=J(e);if(t.length===0&&e==="/")return n.setValue(null),n.setItems(void 0),n.setProperties(void 0),!0;const{parent:r,key:s}=H(n,t);return hn(r,s),!0}function yn(n,e,t){const r=we(rt(n,e));return st(n,t,r),!0}function gn(n,e,t){const r=J(e),{parent:s,key:i}=H(n,r),o=Ue(s,i);if(o===void 0)throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);return it(n,e)?(st(n,t,o),!0):!1}function mn(n,e,t){const r=rt(n,e);let s=t;if(r instanceof a)if((t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||V(t))&&(r.isInlineValue()||r.getValue()!==void 0)){if(!Z(r.getValue()??null,t))throw new Error(`TEST failed at '${e}': Expected ${JSON.stringify(t)}, got ${JSON.stringify(r.getValue()??null)}`);return!0}else typeof t=="object"&&!(t instanceof a)&&(s=N(t));else if(V(r)&&typeof t=="number")r instanceof v?s=new v(t.toString()):r instanceof P&&(s=new P(t.toString()));else if((r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&V(t)){const i=t;!Z(r,i.toString())&&(typeof r=="number"&&parseFloat(i.toString()))}if(!Z(r,s)){const i=r instanceof a?r.toString():JSON.stringify(r),o=s instanceof a?s.toString():JSON.stringify(s);throw new Error(`TEST failed at '${e}': Expected ${o}, got ${i}`)}return!0}function bn(n,e){switch(e.op){case"add":return fn(n,e.path,e.val);case"replace":return pn(n,e.path,e.val);case"remove":return it(n,e.path);case"copy":return yn(n,e.from,e.path);case"move":return gn(n,e.from,e.path);case"test":return mn(n,e.path,e.val)}}function In(n,e,t=!1){const r=t?n:n.clone();return bn(r,e),r}const ve=new WeakMap;function W(n,e){const t=ve.get(n)||{};return ve.set(n,{...t,...e}),n}const E=n=>ve.get(n),ot=n=>e=>{const t=E(e);return W(e,{...t,blueDescription:n})},lt=n=>{const e=E(n);return d.isNonNullable(e)&&w.isString(e.blueDescription)?e.blueDescription:null},Bn=n=>ot(n)(l.z.string().optional()),Tn=l.z.union([l.z.string(),l.z.boolean()]),ct=n=>e=>{const t=E(e);return W(e,{...t,blueId:n})},at=n=>{const e=E(n),t=Tn.safeParse(e==null?void 0:e.blueId);return t.success?t.data:null},Nn=n=>ct(n??!0)(l.z.string()),ut=n=>e=>{const t=E(e);return W(e,{...t,blueName:n})},dt=n=>{const e=E(n);return d.isNonNullable(e)&&w.isString(e.blueName)?e.blueName:null},wn=n=>{const e=l.z.string().optional();return ut(n)(e)},ht=()=>n=>{const e=E(n);return W(n,{...e,blueNode:!0})},ft=n=>{const e=E(n);return d.isNonNullable(e)&&d.isNonNullable(e.blueNode)&&e.blueNode===!0?e.blueNode:null},Ee=n=>!!ft(n),vn=()=>{const n=l.z.instanceof(a);return ht()(n)},Pe="extendedFrom",pt=({schema:n,baseSchema:e})=>{const t=E(n)||{};return W(n,{...t,[Pe]:e})},yt=n=>{const e=E(n);return d.isNonNullable(e)&&e[Pe]?e[Pe]:null},$e=(n,e)=>{const t=yt(n);return d.isNullable(t)?!1:(t==null?void 0:t._def)===(e==null?void 0:e._def)?!0:$e(t,e)},En=n=>new Proxy(n,{get(e,t,r){return t==="extend"?function(...s){const i=e.extend(...s);return pt({schema:i,baseSchema:e})}:Reflect.get(e,t,r)}}),Pn=l.z.object({value:l.z.array(l.z.string()).optional(),defaultValue:l.z.string().optional()}),gt=n=>{const e=E(n),t=Pn.passthrough().safeParse(e==null?void 0:e.typeBlueId);return t.success?t.data:null},An=n=>e=>{const t=E(e),r=typeof n=="string"?{value:[n]}:n,s=En(e);return W(s,{...t,typeBlueId:{...(t==null?void 0:t.typeBlueId)||{},...r}})};class ye{static resolveBlueId(e){var i;const t=gt(e);if(d.isNullable(t))return null;const r=t.defaultValue;if(d.isNonNullable(r))return r;const s=(i=t.value)==null?void 0:i[0];return d.isNonNullable(s)?s:ye.getRepositoryBlueId(t,e)}static getRepositoryBlueId(e,t){throw new Error("Not implemented")}}class Sn{static isTypeOf(e,t){var i;const r=ye.resolveBlueId(t),s=(i=e.getType())==null?void 0:i.getBlueId();return d.isNullable(r)||d.isNullable(s)?!1:r===s}}class mt{constructor(e){h(this,"blueIdMap",new Map);for(const t of e)this.registerSchema(t)}registerSchema(e){const t=ye.resolveBlueId(e);if(d.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 d.isNullable(t)?null:this.blueIdMap.get(t)}getEffectiveBlueId(e){const t=e.getType();return d.isNonNullable(t)&&d.isNonNullable(t.getBlueId())?t.getBlueId():d.isNonNullable(t)?S.calculateBlueIdSync(t):null}getBlueIdMap(){return new Map(this.blueIdMap)}}class bt{static convertValue(e,t){var i;const r=(i=e.getType())==null?void 0:i.getBlueId(),s=e.getValue();return d.isNullable(s)?this.isPrimitive(t)?this.getDefaultPrimitiveValue(t):s:ee===r?this.convertFromString(String(s),t):te===r||s instanceof P?this.convertFromBigDecimal(new P(s==null?void 0:s.toString()),t):ne===r||s instanceof v?this.convertFromBigInteger(new v(s==null?void 0:s.toString()),t):re===r||typeof s=="boolean"?this.convertFromBoolean(!!s,t):this.convertFromString(String(s),t)}static convertFromString(e,t){if(!t||t instanceof l.ZodString||t instanceof l.ZodEnum||t instanceof l.ZodNativeEnum)return e;if(t instanceof l.ZodNumber)return Number(e);if(t instanceof l.ZodBoolean)return e.toLowerCase()==="true";if(t instanceof l.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert String to ${t.constructor.name}`)}static convertFromBigDecimal(e,t){if(t instanceof l.ZodNumber)return e.toNumber();if(t instanceof l.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t.constructor.name}`)}static convertFromBigInteger(e,t){if(t instanceof l.ZodNumber)return e.toNumber();if(t instanceof l.ZodBigInt)return BigInt(e.toString());if(t instanceof l.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t.constructor.name}`)}static convertFromBoolean(e,t){if(!t||t instanceof l.ZodBoolean)return e;if(t instanceof l.ZodString)return e.toString();if(t instanceof l.ZodNumber)return Number(e);if(t instanceof l.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert Boolean to ${t.constructor.name}`)}static isPrimitive(e){return e?e instanceof l.ZodString||e instanceof l.ZodNumber||e instanceof l.ZodBoolean||e instanceof l.ZodBigInt:!1}static getDefaultPrimitiveValue(e){if(!e)return null;if(e instanceof l.ZodNumber)return 0;if(e instanceof l.ZodBoolean)return!1;if(e instanceof l.ZodString)return"";throw new Error(`Unsupported primitive type: ${e.constructor.name}`)}}class Cn{convert(e,t){return bt.convertValue(e,t)}}class On{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof l.ZodAny||e instanceof l.ZodObject||e instanceof l.ZodRecord||e instanceof l.ZodMap||e instanceof l.ZodUnknown}convert(e,t){return this.convertFields(e,t)}convertFields(e,t){if(t instanceof l.ZodIntersection){const r=t._def.left,s=t._def.right,i=this.convert(e,r),o=this.convert(e,s);return{...i,...o}}if(t instanceof l.ZodUnion)throw new Error("Union not supported");if(t instanceof l.ZodObject)return Object.keys(t.shape).reduce((s,i)=>{const o=e.getProperties(),c=t.shape[i],u=at(c);if(d.isNonNullable(u)){const p=w.isString(u)?u:i,T=o==null?void 0:o[p],O=T?S.calculateBlueIdSync(T):void 0;return s[i]=O,s}const f=dt(c);if(d.isNonNullable(f)){const p=o==null?void 0:o[f];return s[i]=p==null?void 0:p.getName(),s}const I=lt(c);if(d.isNonNullable(I)){const p=o==null?void 0:o[I];return s[i]=p==null?void 0:p.getDescription(),s}if(i==="name"){const p=e.getName();return s[i]=p,s}if(i==="description"){const p=e.getDescription();return s[i]=p,s}const b=e.getContracts();if(i==="contracts"&&d.isNonNullable(b)&&this.canHandleStructuredData(c)){const p=Object.fromEntries(Object.entries(b).map(([O,ie])=>[O,B.get(ie)])),T=y.deserialize(p);s[i]=this.nodeToObjectConverter.convert(T,c)}const m=o==null?void 0:o[i];if(d.isNullable(m))return s;const g=this.nodeToObjectConverter.convert(m,c);return s[i]=g,s},{});throw new Error("Unknown schema type, "+t.constructor.name)}}class Dn{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t.element;return r.map(o=>this.nodeToObjectConverter.convert(o,s))}}class Fn{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t._def.valueType,i=r.map(o=>this.nodeToObjectConverter.convert(o,s));return new Set(i)}}class Vn{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof l.ZodAny||e instanceof l.ZodObject||e instanceof l.ZodRecord||e instanceof l.ZodMap||e instanceof l.ZodUnknown}convert(e,t){const r=t.keySchema,s=t.valueSchema,i=new Map,o=e.getName();d.isNonNullable(o)&&i.set($,o);const c=e.getDescription();d.isNonNullable(c)&&i.set(L,c);const u=e.getContracts();if(d.isNonNullable(u)&&this.canHandleStructuredData(s)){let I=!1;const b=Object.entries(u).reduce((m,[g,p])=>{try{const T=this.nodeToObjectConverter.convert(p,s);T!=null&&!Number.isNaN(T)&&(m[g]=T,I=!0)}catch{}return m},{});I&&i.set(pe,b)}const f=e.getProperties();return d.isNonNullable(f)&&Object.entries(f).forEach(([I,b])=>{const m=new a().setValue(I);m.setType(new a().setBlueId(ee));const g=bt.convertValue(m,r),p=this.nodeToObjectConverter.convert(b,s);i.set(g,p)}),t instanceof l.ZodRecord?Object.fromEntries(i):i}}class jn{convert(e){return B.get(e)}}class Rn{convert(e){return B.get(e)}}class zn{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t.items;return r.map((o,c)=>this.nodeToObjectConverter.convert(o,s[c]))}}const Zn=l.z.union([l.z.literal("ZodString"),l.z.literal("ZodNumber"),l.z.literal("ZodBoolean"),l.z.literal("ZodBigInt"),l.z.literal("ZodArray"),l.z.literal("ZodSet"),l.z.literal("ZodMap"),l.z.literal("ZodRecord"),l.z.literal("ZodObject"),l.z.literal("ZodEnum"),l.z.literal("ZodNativeEnum"),l.z.literal("ZodUnknown"),l.z.literal("ZodAny"),l.z.literal("ZodTuple")]);class xn{constructor(e){h(this,"converters",new Map);h(this,"complexObjectConverter");this.nodeToObjectConverter=e,this.registerConverters(),this.complexObjectConverter=new On(this.nodeToObjectConverter)}registerConverters(){const e=new Cn,t=new Dn(this.nodeToObjectConverter),r=new zn(this.nodeToObjectConverter),s=new Fn(this.nodeToObjectConverter),i=new Vn(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 jn),this.converters.set("ZodAny",new Rn),this.converters.set("ZodArray",t),this.converters.set("ZodTuple",r),this.converters.set("ZodSet",s),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}isWrapperType(e){return e instanceof l.ZodOptional||e instanceof l.ZodNullable||e instanceof l.ZodReadonly||e instanceof l.ZodBranded||e instanceof l.ZodEffects||e instanceof l.ZodLazy}getSchemaTypeName(e){if(this.isWrapperType(e))return e instanceof l.ZodEffects?this.getSchemaTypeName(e.innerType()):e instanceof l.ZodLazy?this.getSchemaTypeName(e.schema):this.getSchemaTypeName(e.unwrap());const t=e.constructor.name;try{return Zn.parse(t)}catch{throw new Error(`Schema type name ${t} is not supported`)}}}class Un{constructor(e){h(this,"converterFactory");this.typeSchemaResolver=e,this.converterFactory=new xn(this)}convert(e,t){var o;const r=(o=this.typeSchemaResolver)==null?void 0:o.resolveSchema(e),s=this.unwrapSchema(t);if(Ee(s))return e;let i=s;return d.isNonNullable(r)&&$e(r,s)&&(i=r),this.convertWithType(e,i)}convertWithType(e,t){return this.converterFactory.getConverter(t).convert(e,t)}isWrapperType(e){return e instanceof l.ZodOptional||e instanceof l.ZodNullable||e instanceof l.ZodReadonly||e instanceof l.ZodBranded||e instanceof l.ZodEffects||e instanceof l.ZodLazy}unwrapSchema(e){return Ee(e)?e:this.isWrapperType(e)?e instanceof l.ZodEffects?this.unwrapSchema(e.innerType()):e instanceof l.ZodLazy?this.unwrapSchema(e.schema):this.unwrapSchema(e.unwrap()):e}}class ge{fetchFirstByBlueId(e){const t=this.fetchByBlueId(e);return t&&t.length>0?t[0]:null}}function Mn(n){return new class extends ge{fetchByBlueId(e){return n(e)}}}class $n extends ge{constructor(t){super();h(this,"nodeProviders");this.nodeProviders=t}fetchByBlueId(t){for(const r of this.nodeProviders){const s=r.fetchByBlueId(t);if(s&&s.length>0)return s}return[]}fetchFirstByBlueId(t){for(const r of this.nodeProviders){const s=r.fetchFirstByBlueId(t);if(s)return s}return null}getNodeProviders(){return this.nodeProviders}}const Ie=M.types.float.options,Ln={...Ie,construct:n=>{const e=n.replace(/_/g,"").toLowerCase();if(!d.isPreciseNumberString(e))return new P(e);if(Ie.construct)return Ie.construct(n)}},_n=new M.Type("tag:yaml.org,2002:float",Ln),Be=M.types.int.options,kn={...Be,construct:n=>{let e=n;if(e.indexOf("_")!==-1&&(e=e.replace(/_/g,"")),!d.isPreciseNumberString(e))return new v(e);if(Be.construct)return Be.construct(n)}},Yn=new M.Type("tag:yaml.org,2002:int",kn),It=M.CORE_SCHEMA.extend({implicit:[_n,Yn]}),G=n=>{const e=M.load(n,{schema:It});return e===void 0?void 0:e},Gn=n=>M.dump(n,{schema:It,replacer:(e,t)=>{if(A(t)){if(k(t)){const r=new R(Number.MIN_SAFE_INTEGER.toString()),s=new R(Number.MAX_SAFE_INTEGER.toString());if(t.lt(r)||t.gt(s))return t.toString()}return t.toNumber()}return t}}),Bt=`- type:
1
+ "use strict";var At=Object.defineProperty;var Ct=(n,e,t)=>e in n?At(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var h=(n,e,t)=>Ct(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@blue-labs/shared-utils"),l=require("zod"),Ot=require("bs58"),R=require("big.js"),w=require("radash"),Dt=require("js-sha256"),Ft=require("crypto"),Vt=require("base32.js"),M=require("js-yaml"),Je=n=>n&&n.__esModule?n:{default:n},X=Je(Ot),Le=Je(Ft);class jt{static get(e,t,r,s=!0){if(d.isNullable(t)||!t.startsWith("/"))throw new Error(`Invalid path: ${t}`);if(t==="/"){const o=e.getValue();return s&&o!==void 0?o:e}const i=t.substring(1).split("/");return this.getRecursive(e,i,0,r,s)}static getRecursive(e,t,r,s,i){if(r===t.length-1&&!i)return this.getNodeForSegment(e,t[r],s,!1);if(r===t.length){const u=e.getValue();return i&&u!==void 0?u:e}const o=t[r],c=this.getNodeForSegment(e,o,s,!0);if(c)return this.getRecursive(c,t,r+1,s,i)}static getNodeForSegment(e,t,r,s){let i;const o=e.getProperties();if(o&&t in o)i=o[t];else switch(t){case"name":{const c=e.getName();i=d.isNonNullable(c)?new a().setValue(c):new a;break}case"description":{const c=e.getDescription();i=d.isNonNullable(c)?new a().setValue(c):new a;break}case"type":i=e.getType()??new a;break;case"itemType":i=e.getItemType()??new a;break;case"keyType":i=e.getKeyType()??new a;break;case"valueType":i=e.getValueType()??new a;break;case"value":{const c=e.getValue();i=new a().setValue(c??null);break}case"blueId":{const c=e.getBlueId();i=d.isNonNullable(c)?new a().setValue(c):new a;break}case"blue":i=e.getBlue();break;case"items":{const c=e.getItems();i=new a().setItems(c);break}case"properties":{const c=e.getProperties();i=new a().setProperties(c);break}case"contracts":{const c=e.getContracts();i=new a().setContracts(c);break}default:{if(/^\d+$/.test(t)){const c=parseInt(t,10),u=e.getItems();u&&c>=0&&c<u.length?i=u[c]:i=void 0}else i=void 0;break}}if(i)return s&&r?this.link(i,r):i}static link(e,t){const r=t(e);return d.isNonNullable(r)?r:e}}class v extends R{constructor(e){super(e)}}class S extends R{constructor(e){super(e)}}const $="name",L="description",oe="type",De="itemType",Fe="keyType",Ve="valueType",fe="value",je="items",U="blueId",Re="blue",pe="contracts",Rt=[$,L,oe,De,Fe,Ve,fe,je,U,Re,pe],zt="Text",Zt="Double",xt="Integer",Ut="Boolean",Mt="List",$t="Dictionary",Lt=[zt,Zt,xt,Ut],He=[...Lt,Mt,$t],ee="F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP",te="68ryJtnmui4j5rCZWUnkZ3DChtmEb7Z9F8atn1mBSM3L",ne="DHmxTkFbXePZHCHCYmQr2dSzcNLcryFVjXVHkdQrrZr8",re="EL6AjrbJsxTWRTPzY8WR8Y2zAMXRbydQj83PcZwuAHbo",_t="G8wmfjEqugPEEXByMYWJXiEdbLToPRWNQEekNxrxfQWB",kt="294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA",Gt=[ee,te,ne,re],ze=[...Gt,_t,kt];Object.fromEntries(He.map((n,e)=>[n,ze[e]]));Object.fromEntries(ze.map((n,e)=>[n,He[e]]));const F=class F{constructor(e){h(this,"name");h(this,"description");h(this,"type");h(this,"itemType");h(this,"keyType");h(this,"valueType");h(this,"value");h(this,"items");h(this,"properties");h(this,"contracts");h(this,"blueId");h(this,"blue");h(this,"inlineValue",!1);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 F().setValue(e).setInlineValue(!0):this.type=e,this}getItemType(){return this.itemType}setItemType(e){return typeof e=="string"?this.itemType=new F().setValue(e).setInlineValue(!0):this.itemType=e,this}getKeyType(){return this.keyType}setKeyType(e){return typeof e=="string"?this.keyType=new F().setValue(e).setInlineValue(!0):this.keyType=e,this}getValueType(){return this.valueType}setValueType(e){return typeof e=="string"?this.valueType=new F().setValue(e).setInlineValue(!0):this.valueType=e,this}getValue(){var t;const e=(t=this.type)==null?void 0:t.getBlueId();if(d.isNonNullable(e)&&d.isNonNullable(this.value)){if(e===ne&&typeof this.value=="string")return new v(this.value);if(e===te&&typeof this.value=="string"){const r=new S(this.value),s=parseFloat(r.toString());return new S(s.toString())}else if(e===re&&typeof this.value=="string")return this.value.toLowerCase()==="true"}return this.value}setValue(e){return typeof e=="number"?e%1===0?this.value=new v(e.toString()):this.value=new S(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}getContracts(){return this.contracts}setContracts(e){return this.contracts=e,this}addContract(e,t){return this.contracts||(this.contracts={}),this.contracts[e]=t,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}get(e,t){return jt.get(this,e,t)}clone(){var t,r,s,i,o,c;const e=new F(this.name);return e.description=this.description,e.type=(t=this.type)==null?void 0:t.clone(),e.itemType=(r=this.itemType)==null?void 0:r.clone(),e.keyType=(s=this.keyType)==null?void 0:s.clone(),e.valueType=(i=this.valueType)==null?void 0:i.clone(),e.value=this.value,e.items=(o=this.items)==null?void 0:o.map(u=>u.clone()),this.properties&&(e.properties=Object.fromEntries(Object.entries(this.properties).map(([u,g])=>[u,g.clone()]))),this.contracts&&(e.contracts=Object.fromEntries(Object.entries(this.contracts).map(([u,g])=>[u,g.clone()]))),e.blueId=this.blueId,e.blue=(c=this.blue)==null?void 0:c.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}, contracts=${this.contracts}, blueId='${this.blueId}', blue=${this.blue}, inlineValue=${this.inlineValue}}`}};h(F,"INTEGER",new F("Integer"));let a=F;class x{static isPotentialBlueId(e){if(!e||e.length===0||!this.BLUE_ID_PATTERN.test(e))return!1;const t=e.split("#"),r=t[0],s=r.length;if(s<this.MIN_BLUE_ID_LENGTH||s>this.MAX_BLUE_ID_LENGTH)return!1;try{if(X.default.decode(r).length!==32)return!1}catch{return!1}if(t.length>1)try{if(Number(t[1])<0)return!1}catch{return!1}return!0}}h(x,"MIN_BLUE_ID_LENGTH",41),h(x,"MAX_BLUE_ID_LENGTH",45),h(x,"BLUE_ID_PATTERN",/^[1-9A-HJ-NP-Za-km-z]{41,45}(?:#\d+)?$/);const Yt=l.z.string().max(x.MAX_BLUE_ID_LENGTH,{message:"Blue Id has a maximum length of 45 characters"}).min(x.MIN_BLUE_ID_LENGTH,{message:"Blue Id has a minimum length of 41 characters"}).refine(n=>{try{return X.default.decode(n),!0}catch{return!1}},{message:"Blue Id must be a valid Base58 string"}),_=l.z.lazy(()=>l.z.record(l.z.unknown()).and(l.z.object({blueId:l.z.string().optional(),name:l.z.string().optional(),description:l.z.string().optional(),type:_.optional(),value:l.z.union([l.z.string(),l.z.number(),l.z.boolean()]).optional().nullable(),items:l.z.array(_).optional()}))),se=l.z.object({blueId:l.z.string().optional(),name:l.z.string().optional(),description:l.z.string().optional(),type:_.optional()}),Jt=se.extend({value:l.z.string().optional()}),Ht=se.extend({value:l.z.number().optional()}),Wt=se.extend({value:l.z.boolean().optional()}),Kt=se.extend({items:l.z.array(l.z.string()).optional()}),qt=n=>_.safeParse(n).success,We=n=>d.isNonNullable(n)&&"blueId"in n&&d.isNonNullable(n.blueId),Xt=n=>d.isNonNullable(n)&&"name"in n&&d.isNonNullable(n.name),Ke=n=>d.isNonNullable(n)&&"items"in n&&d.isNonNullable(n.items),qe=n=>d.isNonNullable(n)&&"type"in n&&d.isNonNullable(n.type),Xe=n=>d.isNonNullable(n)&&"value"in n&&d.isNonNullable(n.value),Qt=(n,e)=>n.required({type:!0}).safeParse(e).success,P=n=>n instanceof R,k=n=>P(n)&&n instanceof v,Qe=n=>P(n)&&n instanceof S,en=l.z.lazy(()=>l.z.record(Q)),tn=l.z.lazy(()=>l.z.union([l.z.array(Q),l.z.array(Q).readonly()])),Q=l.z.lazy(()=>l.z.union([d.jsonPrimitiveSchema,en,tn,l.z.instanceof(R)])),Ze=n=>w.isObject(n)&&!w.isArray(n)&&!d.isReadonlyArray(n)&&!P(n),xe=n=>w.isArray(n)||d.isReadonlyArray(n),nn=n=>xe(n)||Ze(n)||P(n)||d.isJsonPrimitive(n);class p{static deserialize(e){return p.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 a,r={},s={};return Object.entries(e).forEach(([i,o])=>{switch(i){case $:if(o==null)t.setName(void 0);else{if(typeof o!="string")throw new Error(`The ${$} field must be a string.`);t.setName(o)}break;case L:if(o==null)t.setDescription(void 0);else{if(typeof o!="string")throw new Error(`The ${L} field must be a string.`);t.setDescription(o)}break;case oe:t.setType(p.handleNode(o));break;case De:t.setItemType(p.handleNode(o));break;case Fe:t.setKeyType(p.handleNode(o));break;case Ve:t.setValueType(p.handleNode(o));break;case fe:t.setValue(p.handleValue(o));break;case U:if(typeof o!="string")throw new Error(`The ${U} field must be a string.`);t.setBlueId(o);break;case je:t.setItems(p.handleArray(o));break;case Re:t.setBlue(p.handleNode(o));break;case pe:w.isObject(o)&&!w.isArray(o)&&!d.isReadonlyArray(o)&&Object.entries(o).forEach(([c,u])=>{s[c]=p.handleNode(u)});break;default:r[i]=p.handleNode(o);break}}),Object.keys(r).length>0&&t.setProperties(r),Object.keys(s).length>0&&t.setContracts(s),t}else{if(xe(e))return new a().setItems(p.handleArray(e));{const t=e;return new a().setValue(p.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(k(e)||Number.isSafeInteger(e)){const t=new v(e.toString()),r=Number.MIN_SAFE_INTEGER,s=Number.MAX_SAFE_INTEGER;return t.lt(r)?new v(r.toString()):t.gt(s)?new v(s.toString()):t}else{const t=parseFloat(e.toString());return new S(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(w.isObject(e)&&!Array.isArray(e))return[p.handleNode(e)];if(Array.isArray(e))return e.map(p.handleNode);throw new Error("Expected an array node")}}}function rn(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var be,_e;function sn(){return _e||(_e=1,be=function n(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?n(e.toJSON()):Array.isArray(e)?`[${e.reduce((s,i,o)=>`${s}${o===0?"":","}${n(i===void 0||typeof i=="symbol"?null:i)}`,"")}]`:`{${Object.keys(e).sort().reduce((r,s)=>{if(e[s]===void 0||typeof e[s]=="symbol")return r;const i=r.length===0?"":",";return`${r}${i}${n(s)}:${n(e[s])}`},"")}}`}),be}var on=sn();const ln=rn(on);class et{static canonicalize(e){return ln(e)}}const cn=typeof process<"u"&&process.versions!=null&&process.versions.node!=null,ue=class ue{constructor(){h(this,"browserCrypto");this.browserCrypto=this.initBrowserCrypto()}static getInstance(){return this.instance||(this.instance=new ue),this.instance}initBrowserCrypto(){return cn?null:"crypto"in globalThis?globalThis.crypto:null}hasNodeCrypto(){return!!Le.default.createHash}getBrowserCrypto(){return this.browserCrypto}getNodeCrypto(){return Le.default}};h(ue,"instance");let Ne=ue;class tt{constructor(){h(this,"cryptoEnv",Ne.getInstance())}applySync(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):this.sha256SyncBrowser(t);return X.default.encode(new Uint8Array(r))}async apply(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):await this.sha256Async(t);return X.default.encode(new Uint8Array(r))}canonicalizeInput(e){const t=et.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");return t.createHash("sha256").update(e).digest()}sha256SyncBrowser(e){return Dt.sha256.arrayBuffer(e)}async sha256Async(e){if(this.cryptoEnv.hasNodeCrypto())return this.sha256Sync(e);const t=this.cryptoEnv.getBrowserCrypto();if(!t)throw new Error("crypto is not available in this environment");const s=new TextEncoder().encode(e);return t.subtle.digest("SHA-256",s)}}class T{static get(e,t="official"){var ie;const r=e.getValue(),s=this.handleValue(r);if(s!==void 0&&t==="simple")return s;const i=(ie=e.getItems())==null?void 0:ie.map(D=>T.get(D,t));if(i!==void 0&&t==="simple")return i;const o=e.getName(),c=e.getDescription();if(t==="original"&&o===void 0&&c===void 0){if(s!==void 0)return s;if(i!==void 0)return i}const u={};o!==void 0&&(u[$]=o),c!==void 0&&(u[L]=c);const g=e.getType();if(t==="official"&&r!==void 0&&g===void 0){const D=this.inferTypeBlueId(r);D!==null&&(u[oe]={[U]:D})}else g!==void 0&&(u[oe]=T.get(g,t));const I=e.getItemType();I!==void 0&&(u[De]=T.get(I,t));const b=e.getKeyType();b!==void 0&&(u[Fe]=T.get(b,t));const m=e.getValueType();m!==void 0&&(u[Ve]=T.get(m,t)),s!==void 0&&(u[fe]=s),i!==void 0&&(u[je]=i);const y=e.getBlueId();y!==void 0&&(u[U]=y);const f=e.getBlue();f!==void 0&&(u[Re]=f);const B=e.getContracts();if(B!==void 0){const D={};Object.entries(B).forEach(([me,Pt])=>{D[me]=T.get(Pt,t)}),u[pe]=D}const O=e.getProperties();return O!==void 0&&Object.entries(O).forEach(([D,me])=>{u[D]=T.get(me,t)}),u}static handleValue(e){if(P(e)){if(k(e)){const t=new R(Number.MIN_SAFE_INTEGER.toString()),r=new R(Number.MAX_SAFE_INTEGER.toString());if(e.lt(t)||e.gt(r))return e.toString()}return e.toNumber()}return e}static inferTypeBlueId(e){return typeof e=="string"?ee:P(e)?k(e)?ne:te:typeof e=="boolean"?re:null}}const an=n=>d.isJsonPrimitive(n)&&d.isNonNullable(n),j=class j{constructor(e){h(this,"hashProvider");this.hashProvider=e}static calculateBlueId(e){if(Array.isArray(e)){const r=e.map(s=>T.get(s));return j.INSTANCE.calculate(r)}const t=T.get(e);return j.INSTANCE.calculate(t)}static calculateBlueIdSync(e){if(Array.isArray(e)){const r=e.map(s=>T.get(s));return j.INSTANCE.calculateSync(r)}const t=T.get(e);return j.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 an(e)||P(e)?this.applyHash(e.toString(),t):Array.isArray(e)||d.isReadonlyArray(e)?this.calculateList(e,t):this.calculateMap(e,t)}calculateMap(e,t){if(e[U]!==void 0)return e[U];const s=Object.keys(e).map(o=>{const c=e[o];if([$,fe,L].includes(o))return t?[o,c]:Promise.resolve([o,c]);{const u=this.internalCalculate(c,t);return t?[o,{blueId:u}]:Promise.resolve(u).then(g=>[o,{blueId:g}])}}),i=o=>{const c={};for(const[u,g]of o)c[u]=g;return this.applyHash(c,t)};return t?i(s):Promise.all(s).then(i)}calculateList(e,t){if(e.length===0)throw new Error("Cannot calculate BlueId for an empty list.");let r=this.internalCalculate(e[0],t);const s=(i,o)=>t?this.applyHash([{blueId:i},{blueId:o}],!0):Promise.all([i,o]).then(([c,u])=>this.applyHash([{blueId:c},{blueId:u}],!1));for(let i=1;i<e.length;i++){const o=this.internalCalculate(e[i],t);r=s(r,o)}return r}applyHash(e,t){return t?this.hashProvider.applySync(e):this.hashProvider.apply(e)}cleanStructure(e){if(e!=null){if(d.isJsonPrimitive(e)||P(e))return e;if(Array.isArray(e)||d.isReadonlyArray(e)){const t=e.map(r=>this.cleanStructure(r)).filter(d.isNonNullable);return t.length>0?t:void 0}else if(typeof e=="object"){const t={};for(const r in e){const s=this.cleanStructure(e[r]);s!=null&&(t[r]=s)}return Object.keys(t).length>0?t:void 0}else return e}}};h(j,"INSTANCE",new j(new tt));let A=j;class un{static convert(e){const t=X.default.decode(e),r=new Uint8Array(2+t.length);r[0]=18,r[1]=32,r.set(t,2);const s=new Uint8Array(2+r.length);return s[0]=1,s[1]=85,s.set(r,2),"b"+new Vt.Encoder({type:"rfc4648",lc:!0}).write(s).finalize().replace(/=/g,"")}}class C{static transform(e,t){const r=t(e.clone()),s=r.getType();s!==void 0&&r.setType(C.transform(s,t));const i=r.getItemType();i!==void 0&&r.setItemType(C.transform(i,t));const o=r.getKeyType();o!==void 0&&r.setKeyType(C.transform(o,t));const c=r.getValueType();c!==void 0&&r.setValueType(C.transform(c,t));const u=r.getItems();if(u!==void 0){const b=u.map(m=>C.transform(m,t));r.setItems(b)}const g=r.getProperties();if(g!==void 0){const b=Object.keys(g).reduce((m,y)=>(m[y]=C.transform(g[y],t),m),{});r.setProperties(b)}const I=r.getContracts();if(I!==void 0){const b=Object.keys(I).reduce((m,y)=>(m[y]=C.transform(I[y],t),m),{});r.setContracts(b)}return r}}const z=n=>!!n&&typeof n=="object"&&!Array.isArray(n)&&!(n instanceof a),V=n=>n instanceof v||n instanceof S,dn=n=>n.replace(/~1/g,"/").replace(/~0/g,"~");function J(n){if(n==="/")return[];if(!n.startsWith("/"))throw new Error(`Path must start with '/': ${n}`);return n.split("/").slice(1).map(dn)}function G(n){if(n==="-")return-1;const e=typeof n=="number"?n:parseInt(n,10);if(isNaN(e))throw new Error(`Invalid array index (NaN) from '${n}'`);if(!Number.isFinite(e))throw new Error(`Invalid array index '${n}' results in non-finite number ${e}`);return e}function nt(n,e,t,r=!0){switch(e){case"name":return t?r?n.getName()??null:n:n.getName();case"description":return t?r?n.getDescription():n:n.getDescription();case"type":return n.getType();case"itemType":return n.getItemType();case"keyType":return n.getKeyType();case"valueType":return n.getValueType();case"value":return t?r?n.getValue()??null:n:n.getValue();case"blueId":return t?r?n.getBlueId()??null:n:n.getBlueId();case"blue":return n.getBlue();case"items":return n.getItems();case"properties":return n.getProperties();case"contracts":return n.getContracts();default:return}}function ke(n,e,t=!0){if(n instanceof a){const r=nt(n,e,!0,t);if(r!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(e))return r;if(/^-?\d+$/.test(e)&&e!=="-"){const i=n.getItems(),o=parseInt(e,10);return i&&o>=0&&o<i.length?i[o]:void 0}const s=n.getProperties();return s&&e in s?s[e]:void 0}if(Array.isArray(n)){if(e==="-")return;const r=G(e);return r>=0&&r<n.length?n[r]:void 0}if(z(n))return n[e]}function H(n,e){if(e.length===0)return{parent:n,key:"value",actualTarget:n.getValue()??n};let t=n;for(let s=0;s<e.length-1;++s){const i=e[s],o=ke(t,i);if(o===void 0)throw new Error(`Cannot resolve '/${e.slice(0,s+1).join("/")}'`);t=o}const r=e[e.length-1];if(t instanceof a){const s=ke(t,r,!1);if((typeof s!="object"||s===null||V(s))&&!(s instanceof a)&&!Array.isArray(s)&&["name","description","value","blueId"].includes(r))return{parent:t,key:r,actualTarget:s}}return Array.isArray(t)&&r==="-"?{parent:t,key:"-"}:t instanceof a&&t.getItems()&&r==="-"?{parent:t,key:"-"}:{parent:t,key:Array.isArray(t)?G(r):r}}function Ue(n,e){var t;if(n instanceof a){const r=e,s=nt(n,r,!1);if(s!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(r))return s;if(typeof e=="number"||typeof e=="string"&&/^\d+$/.test(e)){const i=n.getItems(),o=typeof e=="number"?e:parseInt(e,10);if(i&&o>=0&&o<i.length)return i[o]}return(t=n.getProperties())==null?void 0:t[r]}return Array.isArray(n)||z(n)?n[e]:n}function N(n){if(n instanceof a)return n;if(n===null||typeof n=="string"||typeof n=="number"||typeof n=="boolean"||V(n))return p.deserialize(n);const e=we(n);return p.deserialize(e)}function we(n){if(n===void 0)return null;if(n===null||typeof n!="object")return n;if(Array.isArray(n))return n.map(we);const e={};for(const[t,r]of Object.entries(n))e[t]=we(r);return e}function Me(n,e,t){if(n instanceof a){const r=e;switch(r){case"name":n.setName(t);return;case"description":n.setDescription(t);return;case"type":n.setType(t instanceof a||typeof t=="string"||t===void 0?t:N(t));return;case"itemType":n.setItemType(t instanceof a||typeof t=="string"||t===void 0?t:N(t));return;case"keyType":n.setKeyType(t instanceof a||typeof t=="string"||t===void 0?t:N(t));return;case"valueType":n.setValueType(t instanceof a||typeof t=="string"||t===void 0?t:N(t));return;case"value":{const s=t;n.setValue(s===void 0?null:s);return}case"blueId":n.setBlueId(t);return;case"blue":n.setBlue(t instanceof a||t===void 0?t:N(t));return;case"items":n.setItems(t);return;case"properties":n.setProperties(t);return;case"contracts":n.setContracts(t);return;default:{if(t===void 0){const s=n.getProperties();s&&r in s&&delete s[r]}else n.getProperties()||n.setProperties({}),n.addProperty(r,t instanceof a?t:N(t));return}}}Array.isArray(n)?n.splice(G(e),1):z(n)&&(t===void 0?delete n[e]:n[e]=t)}function hn(n,e,t,r){let s=-1;if(e!=="-"&&(s=typeof e=="number"?e:parseInt(e,10),isNaN(s)))throw new Error(`Invalid numeric key for BlueNode item operation: ${e}`);if(s<-1)throw new Error(`Invalid array index for BlueNode items: ${s}`);let i=n.getItems();if(i||(i=[],n.setItems(i)),!r&&s!==-1&&s>i.length)throw new Error(`ADD operation failed: Target array index '${s}' is greater than array length ${i.length}.`);if(e==="-")i.push(t);else if(r){if(s>=0)if(s<i.length)i[s]=t;else{for(let o=i.length;o<s;o++)i.push(p.deserialize(null));i.push(t)}}else i.splice(s,0,t)}function le(n,e,t,r){if(Array.isArray(n)){const s=e==="-"?n.length:G(e);if(!r&&s>n.length)throw new Error(`ADD operation failed: Target array index '${s}' is greater than array length ${n.length}. Path involving key '${e}'.`);if(s<0&&e!=="-")throw new Error(`Invalid negative array index: ${e}`);const i=N(t);if(r){if(s>=0&&s<n.length)n[s]=i;else if(s>=n.length){for(let o=n.length;o<s;o++)n.push(p.deserialize(null));n.push(i)}}else n.splice(s,0,i);return}if(n instanceof a){e==="-"||typeof e=="number"&&!isNaN(e)||typeof e=="string"&&/^\d+$/.test(e)?hn(n,e,N(t),r):Me(n,e,t);return}if(z(n)){n[e]=N(t);return}throw new Error(`Cannot insert into parent of type ${typeof n}`)}function fn(n,e){if(Array.isArray(n)){const t=G(e);t===-1&&e==="-"?n.length>0&&n.pop():t>=0&&t<n.length&&n.splice(t,1);return}if(n instanceof a){if(typeof e=="number"||typeof e=="string"&&/^-?\d+$/.test(e)){const t=n.getItems();if(t){const r=G(e);r===-1&&e==="-"?t.length>0&&t.pop():r>=0&&r<t.length&&t.splice(r,1),t.length===0&&n.setItems(void 0);return}}Me(n,e,void 0)}else z(n)&&delete n[e]}function ve(n){if(n instanceof a)return n.clone();if(Array.isArray(n))return n.map(t=>ve(t));if(z(n)){const e={};return Object.keys(n).forEach(t=>{e[t]=ve(n[t])}),e}return n}function Z(n,e){if(n===e||n instanceof a&&(n.isInlineValue()||n.getValue()!==void 0)&&Z(n.getValue()??null,e)||e instanceof a&&(e.isInlineValue()||e.getValue()!==void 0)&&Z(n,e.getValue()??null))return!0;if(n instanceof a&&e instanceof a||V(n)&&V(e)||V(n)&&typeof e=="number"||typeof n=="number"&&V(e))return n.toString()===e.toString();if(Array.isArray(n)&&Array.isArray(e))return n.length===e.length&&n.every((t,r)=>Z(t,e[r]));if(z(n)&&z(e)){const t=Object.keys(n),r=Object.keys(e);return t.length===r.length&&t.every(s=>Z(n[s],e[s]))}return!1}function rt(n,e){const{parent:t,key:r}=H(n,J(e));return Ue(t,r)}function st(n,e,t){const r=J(e);if(r.length===0&&e==="/"){const o=N(t);n.setValue(o.getValue()??null),o.getItems()?n.setItems(o.getItems()):n.setItems(void 0);return}const{parent:s,key:i}=H(n,r);le(s,i,t,!0)}function pn(n,e,t){const r=J(e);if(r.length===0&&e==="/"){if(n.getItems()&&Array.isArray(t)){const o=N(t);o.getItems()?(n.setItems(o.getItems()),n.setValue(null)):(n.setValue(o.getValue()??null),n.setItems(void 0))}else{const o=N(t);n.setValue(o.getValue()??null),o.getItems()&&n.setItems(o.getItems())}return!0}const{parent:s,key:i}=H(n,r);return le(s,i,t,!1),!0}function gn(n,e,t){const r=J(e);if(r.length===0&&e==="/"){const c=N(t);return n.setValue(c.getValue()??null),c.getItems()?n.setItems(c.getItems()):n.setItems(void 0),!0}const{parent:s,key:i,actualTarget:o}=H(n,r);if(o!==void 0&&s instanceof a)Me(s,i,t);else{const c=Ue(s,i),u=Array.isArray(s)||s instanceof a&&s.getItems()&&(typeof i=="number"||typeof i=="string"&&/^\d+$/.test(i));if(c===void 0){if(u)throw new Error(`REPLACE failed: Target array index '${i.toString()}' is out of bounds or does not exist at path '${e}'.`);le(s,i,t,!0)}else le(s,i,t,!0)}return!0}function it(n,e){const t=J(e);if(t.length===0&&e==="/")return n.setValue(null),n.setItems(void 0),n.setProperties(void 0),!0;const{parent:r,key:s}=H(n,t);return fn(r,s),!0}function yn(n,e,t){const r=ve(rt(n,e));return st(n,t,r),!0}function mn(n,e,t){const r=J(e),{parent:s,key:i}=H(n,r),o=Ue(s,i);if(o===void 0)throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);return it(n,e)?(st(n,t,o),!0):!1}function bn(n,e,t){const r=rt(n,e);let s=t;if(r instanceof a)if((t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||V(t))&&(r.isInlineValue()||r.getValue()!==void 0)){if(!Z(r.getValue()??null,t))throw new Error(`TEST failed at '${e}': Expected ${JSON.stringify(t)}, got ${JSON.stringify(r.getValue()??null)}`);return!0}else typeof t=="object"&&!(t instanceof a)&&(s=N(t));else if(V(r)&&typeof t=="number")r instanceof v?s=new v(t.toString()):r instanceof S&&(s=new S(t.toString()));else if((r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&V(t)){const i=t;!Z(r,i.toString())&&(typeof r=="number"&&parseFloat(i.toString()))}if(!Z(r,s)){const i=r instanceof a?r.toString():JSON.stringify(r),o=s instanceof a?s.toString():JSON.stringify(s);throw new Error(`TEST failed at '${e}': Expected ${o}, got ${i}`)}return!0}function In(n,e){switch(e.op){case"add":return pn(n,e.path,e.val);case"replace":return gn(n,e.path,e.val);case"remove":return it(n,e.path);case"copy":return yn(n,e.from,e.path);case"move":return mn(n,e.from,e.path);case"test":return bn(n,e.path,e.val)}}function Tn(n,e,t=!1){const r=t?n:n.clone();return In(r,e),r}const Ie=Symbol.for("zod-schema-annotations");function Bn(){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 ot(){const n=Bn();return Ie in n||(n[Ie]=new WeakMap),n[Ie]}function W(n,e){const t=ot(),r=t.get(n)||{};return t.set(n,{...r,...e}),n}const E=n=>ot().get(n),lt=n=>e=>{const t=E(e);return W(e,{...t,blueDescription:n})},ct=n=>{const e=E(n);return d.isNonNullable(e)&&w.isString(e.blueDescription)?e.blueDescription:null},Nn=n=>lt(n)(l.z.string().optional()),wn=l.z.union([l.z.string(),l.z.boolean()]),at=n=>e=>{const t=E(e);return W(e,{...t,blueId:n})},ut=n=>{const e=E(n),t=wn.safeParse(e==null?void 0:e.blueId);return t.success?t.data:null},vn=n=>at(n??!0)(l.z.string()),dt=n=>e=>{const t=E(e);return W(e,{...t,blueName:n})},ht=n=>{const e=E(n);return d.isNonNullable(e)&&w.isString(e.blueName)?e.blueName:null},En=n=>{const e=l.z.string().optional();return dt(n)(e)},ft=()=>n=>{const e=E(n);return W(n,{...e,blueNode:!0})},pt=n=>{const e=E(n);return d.isNonNullable(e)&&d.isNonNullable(e.blueNode)&&e.blueNode===!0?e.blueNode:null},Ee=n=>!!pt(n),Sn=()=>{const n=l.z.instanceof(a);return ft()(n)},Se="extendedFrom",gt=({schema:n,baseSchema:e})=>{const t=E(n)||{};return W(n,{...t,[Se]:e})},yt=n=>{const e=E(n);return d.isNonNullable(e)&&e[Se]?e[Se]:null},$e=(n,e)=>{const t=yt(n);return d.isNullable(t)?!1:(t==null?void 0:t._def)===(e==null?void 0:e._def)?!0:$e(t,e)},Pn=n=>new Proxy(n,{get(e,t,r){return t==="extend"?function(...s){const i=e.extend(...s);return gt({schema:i,baseSchema:e})}:Reflect.get(e,t,r)}}),An=l.z.object({value:l.z.array(l.z.string()).optional(),defaultValue:l.z.string().optional()}),mt=n=>{const e=E(n),t=An.passthrough().safeParse(e==null?void 0:e.typeBlueId);return t.success?t.data:null},Cn=n=>e=>{const t=E(e),r=typeof n=="string"?{value:[n]}:n,s=Pn(e);return W(s,{...t,typeBlueId:{...(t==null?void 0:t.typeBlueId)||{},...r}})};class ge{static resolveBlueId(e){var i;const t=mt(e);if(d.isNullable(t))return null;const r=t.defaultValue;if(d.isNonNullable(r))return r;const s=(i=t.value)==null?void 0:i[0];return d.isNonNullable(s)?s:ge.getRepositoryBlueId(t,e)}static getRepositoryBlueId(e,t){throw new Error("Not implemented")}}class On{static isTypeOf(e,t){var i;const r=ge.resolveBlueId(t),s=(i=e.getType())==null?void 0:i.getBlueId();return d.isNullable(r)||d.isNullable(s)?!1:r===s}}class bt{constructor(e){h(this,"blueIdMap",new Map);this.registerSchemas(e)}registerSchemas(e){for(const t of e)this.registerSchema(t)}registerSchema(e){const t=ge.resolveBlueId(e);if(d.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 d.isNullable(t)?null:this.blueIdMap.get(t)}getEffectiveBlueId(e){const t=e.getType();return d.isNonNullable(t)&&d.isNonNullable(t.getBlueId())?t.getBlueId():d.isNonNullable(t)?A.calculateBlueIdSync(t):null}getBlueIdMap(){return new Map(this.blueIdMap)}}class It{static convertValue(e,t){var i;const r=(i=e.getType())==null?void 0:i.getBlueId(),s=e.getValue();return d.isNullable(s)?this.isPrimitive(t)?this.getDefaultPrimitiveValue(t):s:ee===r?this.convertFromString(String(s),t):te===r||s instanceof S?this.convertFromBigDecimal(new S(s==null?void 0:s.toString()),t):ne===r||s instanceof v?this.convertFromBigInteger(new v(s==null?void 0:s.toString()),t):re===r||typeof s=="boolean"?this.convertFromBoolean(!!s,t):this.convertFromString(String(s),t)}static convertFromString(e,t){if(!t||t instanceof l.ZodString||t instanceof l.ZodEnum||t instanceof l.ZodNativeEnum)return e;if(t instanceof l.ZodNumber)return Number(e);if(t instanceof l.ZodBoolean)return e.toLowerCase()==="true";if(t instanceof l.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert String to ${t.constructor.name}`)}static convertFromBigDecimal(e,t){if(t instanceof l.ZodNumber)return e.toNumber();if(t instanceof l.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t.constructor.name}`)}static convertFromBigInteger(e,t){if(t instanceof l.ZodNumber)return e.toNumber();if(t instanceof l.ZodBigInt)return BigInt(e.toString());if(t instanceof l.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t.constructor.name}`)}static convertFromBoolean(e,t){if(!t||t instanceof l.ZodBoolean)return e;if(t instanceof l.ZodString)return e.toString();if(t instanceof l.ZodNumber)return Number(e);if(t instanceof l.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert Boolean to ${t.constructor.name}`)}static isPrimitive(e){return e?e instanceof l.ZodString||e instanceof l.ZodNumber||e instanceof l.ZodBoolean||e instanceof l.ZodBigInt:!1}static getDefaultPrimitiveValue(e){if(!e)return null;if(e instanceof l.ZodNumber)return 0;if(e instanceof l.ZodBoolean)return!1;if(e instanceof l.ZodString)return"";throw new Error(`Unsupported primitive type: ${e.constructor.name}`)}}class Dn{convert(e,t){return It.convertValue(e,t)}}class Fn{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof l.ZodAny||e instanceof l.ZodObject||e instanceof l.ZodRecord||e instanceof l.ZodMap||e instanceof l.ZodUnknown}convert(e,t){return this.convertFields(e,t)}convertFields(e,t){if(t instanceof l.ZodIntersection){const r=t._def.left,s=t._def.right,i=this.convert(e,r),o=this.convert(e,s);return{...i,...o}}if(t instanceof l.ZodUnion)throw new Error("Union not supported");if(t instanceof l.ZodObject)return Object.keys(t.shape).reduce((s,i)=>{const o=e.getProperties(),c=t.shape[i],u=ut(c);if(d.isNonNullable(u)){const f=w.isString(u)?u:i,B=o==null?void 0:o[f],O=B?A.calculateBlueIdSync(B):void 0;return s[i]=O,s}const g=ht(c);if(d.isNonNullable(g)){const f=o==null?void 0:o[g];return s[i]=f==null?void 0:f.getName(),s}const I=ct(c);if(d.isNonNullable(I)){const f=o==null?void 0:o[I];return s[i]=f==null?void 0:f.getDescription(),s}if(i==="name"){const f=e.getName();return s[i]=f,s}if(i==="description"){const f=e.getDescription();return s[i]=f,s}const b=e.getContracts();if(i==="contracts"&&d.isNonNullable(b)&&this.canHandleStructuredData(c)){const f=Object.fromEntries(Object.entries(b).map(([O,ie])=>[O,T.get(ie)])),B=p.deserialize(f);s[i]=this.nodeToObjectConverter.convert(B,c)}const m=o==null?void 0:o[i];if(d.isNullable(m))return s;const y=this.nodeToObjectConverter.convert(m,c);return s[i]=y,s},{});throw new Error("Unknown schema type, "+t.constructor.name)}}class Vn{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t.element;return r.map(o=>this.nodeToObjectConverter.convert(o,s))}}class jn{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t._def.valueType,i=r.map(o=>this.nodeToObjectConverter.convert(o,s));return new Set(i)}}class Rn{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof l.ZodAny||e instanceof l.ZodObject||e instanceof l.ZodRecord||e instanceof l.ZodMap||e instanceof l.ZodUnknown}convert(e,t){const r=t.keySchema,s=t.valueSchema,i=new Map,o=e.getName();d.isNonNullable(o)&&i.set($,o);const c=e.getDescription();d.isNonNullable(c)&&i.set(L,c);const u=e.getContracts();if(d.isNonNullable(u)&&this.canHandleStructuredData(s)){let I=!1;const b=Object.entries(u).reduce((m,[y,f])=>{try{const B=this.nodeToObjectConverter.convert(f,s);B!=null&&!Number.isNaN(B)&&(m[y]=B,I=!0)}catch{}return m},{});I&&i.set(pe,b)}const g=e.getProperties();return d.isNonNullable(g)&&Object.entries(g).forEach(([I,b])=>{const m=new a().setValue(I);m.setType(new a().setBlueId(ee));const y=It.convertValue(m,r),f=this.nodeToObjectConverter.convert(b,s);i.set(y,f)}),t instanceof l.ZodRecord?Object.fromEntries(i):i}}class zn{convert(e){return T.get(e)}}class Zn{convert(e){return T.get(e)}}class xn{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t.items;return r.map((o,c)=>this.nodeToObjectConverter.convert(o,s[c]))}}const Un=l.z.union([l.z.literal("ZodString"),l.z.literal("ZodNumber"),l.z.literal("ZodBoolean"),l.z.literal("ZodBigInt"),l.z.literal("ZodArray"),l.z.literal("ZodSet"),l.z.literal("ZodMap"),l.z.literal("ZodRecord"),l.z.literal("ZodObject"),l.z.literal("ZodEnum"),l.z.literal("ZodNativeEnum"),l.z.literal("ZodUnknown"),l.z.literal("ZodAny"),l.z.literal("ZodTuple")]);class Mn{constructor(e){h(this,"converters",new Map);h(this,"complexObjectConverter");this.nodeToObjectConverter=e,this.registerConverters(),this.complexObjectConverter=new Fn(this.nodeToObjectConverter)}registerConverters(){const e=new Dn,t=new Vn(this.nodeToObjectConverter),r=new xn(this.nodeToObjectConverter),s=new jn(this.nodeToObjectConverter),i=new Rn(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 zn),this.converters.set("ZodAny",new Zn),this.converters.set("ZodArray",t),this.converters.set("ZodTuple",r),this.converters.set("ZodSet",s),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}isWrapperType(e){return e instanceof l.ZodOptional||e instanceof l.ZodNullable||e instanceof l.ZodReadonly||e instanceof l.ZodBranded||e instanceof l.ZodEffects||e instanceof l.ZodLazy}getSchemaTypeName(e){if(this.isWrapperType(e))return e instanceof l.ZodEffects?this.getSchemaTypeName(e.innerType()):e instanceof l.ZodLazy?this.getSchemaTypeName(e.schema):this.getSchemaTypeName(e.unwrap());const t=e.constructor.name;try{return Un.parse(t)}catch{throw new Error(`Schema type name ${t} is not supported`)}}}class $n{constructor(e){h(this,"converterFactory");this.typeSchemaResolver=e,this.converterFactory=new Mn(this)}convert(e,t){var o;const r=(o=this.typeSchemaResolver)==null?void 0:o.resolveSchema(e),s=this.unwrapSchema(t);if(Ee(s))return e;let i=s;return d.isNonNullable(r)&&$e(r,s)&&(i=r),this.convertWithType(e,i)}convertWithType(e,t){return this.converterFactory.getConverter(t).convert(e,t)}isWrapperType(e){return e instanceof l.ZodOptional||e instanceof l.ZodNullable||e instanceof l.ZodReadonly||e instanceof l.ZodBranded||e instanceof l.ZodEffects||e instanceof l.ZodLazy}unwrapSchema(e){return Ee(e)?e:this.isWrapperType(e)?e instanceof l.ZodEffects?this.unwrapSchema(e.innerType()):e instanceof l.ZodLazy?this.unwrapSchema(e.schema):this.unwrapSchema(e.unwrap()):e}}class ye{fetchFirstByBlueId(e){const t=this.fetchByBlueId(e);return t&&t.length>0?t[0]:null}}function Ln(n){return new class extends ye{fetchByBlueId(e){return n(e)}}}class _n extends ye{constructor(t){super();h(this,"nodeProviders");this.nodeProviders=t}fetchByBlueId(t){for(const r of this.nodeProviders){const s=r.fetchByBlueId(t);if(s&&s.length>0)return s}return[]}fetchFirstByBlueId(t){for(const r of this.nodeProviders){const s=r.fetchFirstByBlueId(t);if(s)return s}return null}getNodeProviders(){return this.nodeProviders}}const Te=M.types.float.options,kn={...Te,construct:n=>{const e=n.replace(/_/g,"").toLowerCase();if(!d.isPreciseNumberString(e))return new S(e);if(Te.construct)return Te.construct(n)}},Gn=new M.Type("tag:yaml.org,2002:float",kn),Be=M.types.int.options,Yn={...Be,construct:n=>{let e=n;if(e.indexOf("_")!==-1&&(e=e.replace(/_/g,"")),!d.isPreciseNumberString(e))return new v(e);if(Be.construct)return Be.construct(n)}},Jn=new M.Type("tag:yaml.org,2002:int",Yn),Tt=M.CORE_SCHEMA.extend({implicit:[Gn,Jn]}),Y=n=>{const e=M.load(n,{schema:Tt});return e===void 0?void 0:e},Hn=n=>M.dump(n,{schema:Tt,replacer:(e,t)=>{if(P(t)){if(k(t)){const r=new R(Number.MIN_SAFE_INTEGER.toString()),s=new R(Number.MAX_SAFE_INTEGER.toString());if(t.lt(r)||t.gt(s))return t.toString()}return t.toNumber()}return t}}),Bt=`- type:
2
2
  blueId: 27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo
3
3
  mappings:
4
4
  Text: F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP
@@ -9,19 +9,19 @@
9
9
  Dictionary: 294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA
10
10
  - type:
11
11
  blueId: FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4
12
- `,Jn=`name: Transformation
13
- description: TODO`,Hn=`name: Infer Basic Types For Untyped Values
12
+ `,Wn=`name: Transformation
13
+ description: TODO`,Kn=`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.`,Wn=`name: Replace Inline Types with BlueIds
16
+ description: This transformation infers type details for Text, Integer, Number and Boolean.`,qn=`name: Replace Inline Types with BlueIds
17
17
  type:
18
18
  blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
19
- description: This transformation replaces`,Kn=[Bt,Jn,Hn,Wn];class qn extends ge{constructor(){super();h(this,"blueIdToNodesMap",new Map);this.load()}fetchByBlueId(t){return this.blueIdToNodesMap.get(t)||[]}load(){for(const t of Kn){const r=G(t);if(r===void 0){console.error(`This content file is not valid YAML: ${t}`);continue}if(Array.isArray(r)){const s=r.map(o=>y.deserialize(o)),i=S.calculateBlueIdSync(s);this.blueIdToNodesMap.set(i,s)}else{const s=y.deserialize(r),i=S.calculateBlueIdSync(s);this.blueIdToNodesMap.set(i,[s])}}}}const de=class de extends ge{constructor(){super();h(this,"nodeProvider");this.nodeProvider=new qn}fetchByBlueId(t){return this.nodeProvider.fetchByBlueId(t)}};h(de,"INSTANCE",new de);let Ae=de;class ce{static wrap(e){return new $n([Ae.INSTANCE,e])}}const Tt=n=>n instanceof a||Array.isArray(n)&&n.every(e=>e instanceof a)?n:w.isArray(n)?n.map(e=>y.deserialize(e)):y.deserialize(n),Nt=async n=>{const e=Tt(n);return S.calculateBlueId(e)},Xn=n=>{const e=Tt(n);return S.calculateBlueIdSync(e)},Se=async n=>{if(We(n))return n;try{const e=Q.parse(n),t=await Nt(e);return{...n,blueId:t}}catch(e){throw new Error(`Failed enriching object with Blue ID: ${e}`)}},Qn=n=>n==null?void 0:n.items,er=n=>n==null?void 0:n.value,tr=n=>d.isNullable(n)?{}:w.omit(n,jt),nr=n=>qe(n)?n.type.name??null:Xe(n)?w.pascal(typeof n.value):Ke(n)?"List":null,wt=n=>d.isNonNullable(n)&&Object.keys(w.omit(n,["blueId"])).length>0,rr=n=>{try{const e=y.deserialize(n),t=B.get(e);return _.parse(t)}catch(e){throw new Error(`Failed transforming JSON-like value to BlueObject: ${e}`)}},Ce=async n=>{const{resolveFunction:e,signal:t=new AbortController().signal,omitItems:r}=n,s=n.count??n.items.length;let i=await w.map(n.items,async c=>await Se(c));const o=Math.max((i==null?void 0:i.length)-s,0);for(let c=i.length-1;c>=o;c--)if(!wt(i[c])){const u=await e(i[c],{signal:t});if(Array.isArray(u))return Ce({...n,items:[...i.slice(0,c),...u,...i.slice(c+1)]});const f=await Se(u);if(r!=null&&r.includes(f.blueId))return Ce({...n,items:[...i.slice(0,c),...i.slice(c+1)]});i=[...i.slice(0,c),f,...i.slice(c+1)]}return i};function K(n){try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}class sr{process(e){return C.transform(e,this.inferType.bind(this))}inferType(e){const t=e.getType(),r=e.getValue();return d.isNullable(t)&&d.isNonNullable(r)&&(typeof r=="string"?e.setType(new a().setBlueId(ee)):typeof r=="bigint"||k(r)?e.setType(new a().setBlueId(ne)):Qe(r)?e.setType(new a().setBlueId(te)):typeof r=="boolean"&&e.setType(new a().setBlueId(re))),e}}const q=class q{constructor(e){h(this,"mappings",new Map);if(e instanceof a){const r=e.getProperties();if(r&&r[q.MAPPINGS]){const i=r[q.MAPPINGS].getProperties();i&&Object.entries(i).forEach(([o,c])=>{const u=c.getValue();typeof u=="string"&&this.mappings.set(o,u)})}}else this.mappings=e}process(e){return C.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 r=String(t.getValue());if(this.mappings.has(r)){const s=this.mappings.get(r);if(s){const i=new a().setBlueId(s);t===e.getType()?e.setType(i):t===e.getItemType()?e.setItemType(i):t===e.getKeyType()?e.setKeyType(i):t===e.getValueType()&&e.setValueType(i)}}}}};h(q,"MAPPINGS","mappings");let Oe=q;class ir{constructor(e,t){h(this,"nodeProvider");h(this,"strategy");this.nodeProvider=ce.wrap(e),this.strategy=t||"THROW_EXCEPTION"}extend(e,t){this.extendNode(e,t,"")}extendNode(e,t,r,s=!1){if(!s){if(!t.shouldExtendPathSegment(r,e))return;t.enterPathSegment(r,e)}try{const i=e.getBlueId();if(i&&!(i in ze)){const g=this.fetchNode(e);if(g&&g.length>0)if(g.length===1){const p=g[0];this.mergeNodes(e,p)}else{const p=g.map(O=>O.clone()),T=new a().setItems(p);this.mergeNodes(e,T)}}const o=e.getType();o&&this.extendNode(o,t,"type",!0);const c=e.getItemType();c&&this.extendNode(c,t,"itemType",!0);const u=e.getKeyType();u&&this.extendNode(u,t,"keyType",!0);const f=e.getValueType();f&&this.extendNode(f,t,"valueType",!0);const I=e.getProperties();I&&Object.entries(I).forEach(([g,p])=>{this.extendNode(p,t,g,!1)});const b=e.getContracts();b&&Object.entries(b).forEach(([g,p])=>{this.extendNode(p,t,g,!1)});const m=e.getItems();if(m&&m.length>0){this.reconstructList(m);for(let g=0;g<m.length;g++)this.extendNode(m[g],t,String(g),!1)}}finally{s||t.exitPathSegment()}}reconstructList(e){for(;e.length>0;){const t=e[0],r=t==null?void 0:t.getBlueId();if(!r)break;const s=this.nodeProvider.fetchByBlueId(r);if(!s||s.length===1)break;e.shift(),e.unshift(...s)}}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 r=this.nodeProvider.fetchByBlueId(t);if(!r||r.length===0){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No content found for blueId: ${e.getBlueId()}`)}return r}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()),e.setValue(t.getValue()??null),e.setItems(t.getItems()),e.setProperties(t.getProperties()),e.setContracts(t.getContracts())}}class or{}function Ye(n,e){const t=n.split(e),r=[...t].reverse().findIndex(i=>i!==""),s=r===-1?0:t.length-r;return t.slice(0,s)}class vt extends or{constructor(t,r){super();h(this,"allowedPaths");h(this,"maxDepth");h(this,"currentPath",[]);this.allowedPaths=t,this.maxDepth=r}shouldExtendPathSegment(t){if(this.currentPath.length>=this.maxDepth)return!1;const r=this.normalizePath(this.getCurrentFullPath()+"/"+t);return this.isAllowedPath(r)}shouldMergePathSegment(t){return this.shouldExtendPathSegment(t)}isAllowedPath(t){for(const r of this.allowedPaths)if(this.matchesAllowedPath(r,t))return!0;return!1}matchesAllowedPath(t,r){const s=Ye(t,"/"),i=Ye(r,"/");if(i.length>s.length)return!1;for(let o=1;o<i.length;o++)if(s[o]!=="*"&&s[o]!==i[o])return!1;return!0}enterPathSegment(t){this.currentPath.push(t)}exitPathSegment(){this.currentPath.length>0&&this.currentPath.pop()}getCurrentFullPath(){return"/"+this.currentPath.join("/")}normalizePath(t){return"/"+t.split("/").filter(r=>r!=="").join("/")}static withMaxDepth(t){return new Ge().setMaxDepth(t).addPath("*").build()}static withSinglePath(t){return new Ge().addPath(t).build()}}class Ge{constructor(){h(this,"allowedPaths",new Set);h(this,"maxDepth",Number.MAX_SAFE_INTEGER)}addPath(e){return this.allowedPaths.add(e),this}setMaxDepth(e){return this.maxDepth=e,this}build(){return new vt(this.allowedPaths,this.maxDepth)}}class Et{constructor(){h(this,"blueIdsCollections",[])}initialize(...e){this.blueIdsCollections=[...e]}registerBlueIds(...e){this.blueIdsCollections.push(...e)}generateMappingsYaml(e="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo"){const t={};for(const s of this.blueIdsCollections)Object.assign(t,s);const r=Object.entries(t).map(([s,i])=>` ${s}: ${i}`).join(`
19
+ description: This transformation replaces`,Xn=[Bt,Wn,Kn,qn];class Qn extends ye{constructor(){super();h(this,"blueIdToNodesMap",new Map);this.load()}fetchByBlueId(t){return this.blueIdToNodesMap.get(t)||[]}load(){for(const t of Xn){const r=Y(t);if(r===void 0){console.error(`This content file is not valid YAML: ${t}`);continue}if(Array.isArray(r)){const s=r.map(o=>p.deserialize(o)),i=A.calculateBlueIdSync(s);this.blueIdToNodesMap.set(i,s)}else{const s=p.deserialize(r),i=A.calculateBlueIdSync(s);this.blueIdToNodesMap.set(i,[s])}}}}const de=class de extends ye{constructor(){super();h(this,"nodeProvider");this.nodeProvider=new Qn}fetchByBlueId(t){return this.nodeProvider.fetchByBlueId(t)}};h(de,"INSTANCE",new de);let Pe=de;class ce{static wrap(e){return new _n([Pe.INSTANCE,e])}}const Nt=n=>n instanceof a||Array.isArray(n)&&n.every(e=>e instanceof a)?n:w.isArray(n)?n.map(e=>p.deserialize(e)):p.deserialize(n),wt=async n=>{const e=Nt(n);return A.calculateBlueId(e)},er=n=>{const e=Nt(n);return A.calculateBlueIdSync(e)},Ae=async n=>{if(We(n))return n;try{const e=Q.parse(n),t=await wt(e);return{...n,blueId:t}}catch(e){throw new Error(`Failed enriching object with Blue ID: ${e}`)}},tr=n=>n==null?void 0:n.items,nr=n=>n==null?void 0:n.value,rr=n=>d.isNullable(n)?{}:w.omit(n,Rt),sr=n=>qe(n)?n.type.name??null:Xe(n)?w.pascal(typeof n.value):Ke(n)?"List":null,vt=n=>d.isNonNullable(n)&&Object.keys(w.omit(n,["blueId"])).length>0,ir=n=>{try{const e=p.deserialize(n),t=T.get(e);return _.parse(t)}catch(e){throw new Error(`Failed transforming JSON-like value to BlueObject: ${e}`)}},Ce=async n=>{const{resolveFunction:e,signal:t=new AbortController().signal,omitItems:r}=n,s=n.count??n.items.length;let i=await w.map(n.items,async c=>await Ae(c));const o=Math.max((i==null?void 0:i.length)-s,0);for(let c=i.length-1;c>=o;c--)if(!vt(i[c])){const u=await e(i[c],{signal:t});if(Array.isArray(u))return Ce({...n,items:[...i.slice(0,c),...u,...i.slice(c+1)]});const g=await Ae(u);if(r!=null&&r.includes(g.blueId))return Ce({...n,items:[...i.slice(0,c),...i.slice(c+1)]});i=[...i.slice(0,c),g,...i.slice(c+1)]}return i};function K(n){try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}class or{process(e){return C.transform(e,this.inferType.bind(this))}inferType(e){const t=e.getType(),r=e.getValue();return d.isNullable(t)&&d.isNonNullable(r)&&(typeof r=="string"?e.setType(new a().setBlueId(ee)):typeof r=="bigint"||k(r)?e.setType(new a().setBlueId(ne)):Qe(r)?e.setType(new a().setBlueId(te)):typeof r=="boolean"&&e.setType(new a().setBlueId(re))),e}}const q=class q{constructor(e){h(this,"mappings",new Map);if(e instanceof a){const r=e.getProperties();if(r&&r[q.MAPPINGS]){const i=r[q.MAPPINGS].getProperties();i&&Object.entries(i).forEach(([o,c])=>{const u=c.getValue();typeof u=="string"&&this.mappings.set(o,u)})}}else this.mappings=e}process(e){return C.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 r=String(t.getValue());if(this.mappings.has(r)){const s=this.mappings.get(r);if(s){const i=new a().setBlueId(s);t===e.getType()?e.setType(i):t===e.getItemType()?e.setItemType(i):t===e.getKeyType()?e.setKeyType(i):t===e.getValueType()&&e.setValueType(i)}}}}};h(q,"MAPPINGS","mappings");let Oe=q;class lr{constructor(e,t){h(this,"nodeProvider");h(this,"strategy");this.nodeProvider=ce.wrap(e),this.strategy=t||"THROW_EXCEPTION"}extend(e,t){this.extendNode(e,t,"")}extendNode(e,t,r,s=!1){if(!s){if(!t.shouldExtendPathSegment(r,e))return;t.enterPathSegment(r,e)}try{const i=e.getBlueId();if(i&&!(i in ze)){const y=this.fetchNode(e);if(y&&y.length>0)if(y.length===1){const f=y[0];this.mergeNodes(e,f)}else{const f=y.map(O=>O.clone()),B=new a().setItems(f);this.mergeNodes(e,B)}}const o=e.getType();o&&this.extendNode(o,t,"type",!0);const c=e.getItemType();c&&this.extendNode(c,t,"itemType",!0);const u=e.getKeyType();u&&this.extendNode(u,t,"keyType",!0);const g=e.getValueType();g&&this.extendNode(g,t,"valueType",!0);const I=e.getProperties();I&&Object.entries(I).forEach(([y,f])=>{this.extendNode(f,t,y,!1)});const b=e.getContracts();b&&Object.entries(b).forEach(([y,f])=>{this.extendNode(f,t,y,!1)});const m=e.getItems();if(m&&m.length>0){this.reconstructList(m);for(let y=0;y<m.length;y++)this.extendNode(m[y],t,String(y),!1)}}finally{s||t.exitPathSegment()}}reconstructList(e){for(;e.length>0;){const t=e[0],r=t==null?void 0:t.getBlueId();if(!r)break;const s=this.nodeProvider.fetchByBlueId(r);if(!s||s.length===1)break;e.shift(),e.unshift(...s)}}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 r=this.nodeProvider.fetchByBlueId(t);if(!r||r.length===0){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No content found for blueId: ${e.getBlueId()}`)}return r}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()),e.setValue(t.getValue()??null),e.setItems(t.getItems()),e.setProperties(t.getProperties()),e.setContracts(t.getContracts())}}class cr{}function Ge(n,e){const t=n.split(e),r=[...t].reverse().findIndex(i=>i!==""),s=r===-1?0:t.length-r;return t.slice(0,s)}class Et extends cr{constructor(t,r){super();h(this,"allowedPaths");h(this,"maxDepth");h(this,"currentPath",[]);this.allowedPaths=t,this.maxDepth=r}shouldExtendPathSegment(t){if(this.currentPath.length>=this.maxDepth)return!1;const r=this.normalizePath(this.getCurrentFullPath()+"/"+t);return this.isAllowedPath(r)}shouldMergePathSegment(t){return this.shouldExtendPathSegment(t)}isAllowedPath(t){for(const r of this.allowedPaths)if(this.matchesAllowedPath(r,t))return!0;return!1}matchesAllowedPath(t,r){const s=Ge(t,"/"),i=Ge(r,"/");if(i.length>s.length)return!1;for(let o=1;o<i.length;o++)if(s[o]!=="*"&&s[o]!==i[o])return!1;return!0}enterPathSegment(t){this.currentPath.push(t)}exitPathSegment(){this.currentPath.length>0&&this.currentPath.pop()}getCurrentFullPath(){return"/"+this.currentPath.join("/")}normalizePath(t){return"/"+t.split("/").filter(r=>r!=="").join("/")}static withMaxDepth(t){return new Ye().setMaxDepth(t).addPath("*").build()}static withSinglePath(t){return new Ye().addPath(t).build()}}class Ye{constructor(){h(this,"allowedPaths",new Set);h(this,"maxDepth",Number.MAX_SAFE_INTEGER)}addPath(e){return this.allowedPaths.add(e),this}setMaxDepth(e){return this.maxDepth=e,this}build(){return new Et(this.allowedPaths,this.maxDepth)}}class St{constructor(){h(this,"blueIdsCollections",[])}initialize(...e){this.blueIdsCollections=[...e]}registerBlueIds(...e){this.blueIdsCollections.push(...e)}generateMappingsYaml(e="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo"){const t={};for(const s of this.blueIdsCollections)Object.assign(t,s);const r=Object.entries(t).map(([s,i])=>` ${s}: ${i}`).join(`
20
20
  `);return`- type:
21
21
  blueId: ${e}
22
22
  mappings:
23
- ${r}`}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}}const he=class he{constructor(e={}){h(this,"processorProvider");h(this,"nodeProvider");h(this,"defaultSimpleBlue",null);h(this,"blueIdsMappingGenerator");const{nodeProvider:t,processorProvider:r,blueIdsMappingGenerator:s}=e;if(!t)throw new Error("NodeProvider is required");this.nodeProvider=ce.wrap(t),this.processorProvider=r||he.getStandardProvider(),this.blueIdsMappingGenerator=s||new Et,this.loadDefaultSimpleBlue()}preprocess(e){return this.preprocessWithOptions(e,null)}preprocessWithDefaultBlue(e){return this.preprocessWithOptions(e,this.defaultSimpleBlue)}preprocessWithOptions(e,t){let r=e.clone(),s=r.getBlue();if(!s&&t&&(s=t.clone()),s){new ir(this.nodeProvider).extend(s,vt.withSinglePath("/*"));const i=s.getItems();if(i&&i.length>0){for(const o of i){const c=this.processorProvider.getProcessor(o);if(c)r=c.process(r);else throw new Error(`No processor found for transformation: ${o}`)}r.setBlue(void 0)}}return r}static getStandardProvider(){return{getProcessor(e){var i;const t="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo",r="FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4",s=(i=e.getType())==null?void 0:i.getBlueId();if(t===s)return new Oe(e);if(r===s)return new sr}}}enrichDefaultBlue(e){const t=this.blueIdsMappingGenerator.generateMappingsYaml();return`
23
+ ${r}`}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}}const he=class he{constructor(e={}){h(this,"processorProvider");h(this,"nodeProvider");h(this,"defaultSimpleBlue",null);h(this,"blueIdsMappingGenerator");const{nodeProvider:t,processorProvider:r,blueIdsMappingGenerator:s}=e;if(!t)throw new Error("NodeProvider is required");this.nodeProvider=ce.wrap(t),this.processorProvider=r||he.getStandardProvider(),this.blueIdsMappingGenerator=s||new St,this.loadDefaultSimpleBlue()}preprocess(e){return this.preprocessWithOptions(e,null)}preprocessWithDefaultBlue(e){return this.preprocessWithOptions(e,this.defaultSimpleBlue)}preprocessWithOptions(e,t){let r=e.clone(),s=r.getBlue();if(!s&&t&&(s=t.clone()),s){new lr(this.nodeProvider).extend(s,Et.withSinglePath("/*"));const i=s.getItems();if(i&&i.length>0){for(const o of i){const c=this.processorProvider.getProcessor(o);if(c)r=c.process(r);else throw new Error(`No processor found for transformation: ${o}`)}r.setBlue(void 0)}}return r}static getStandardProvider(){return{getProcessor(e){var i;const t="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo",r="FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4",s=(i=e.getType())==null?void 0:i.getBlueId();if(t===s)return new Oe(e);if(r===s)return new or}}}enrichDefaultBlue(e){const t=this.blueIdsMappingGenerator.generateMappingsYaml();return`
24
24
  ${e}
25
25
  ${t}
26
- `}loadDefaultSimpleBlue(){const e=this.enrichDefaultBlue(Bt);try{const t=G(e);if(t)this.defaultSimpleBlue=y.deserialize(t);else throw new Error("Failed to parse default Blue content")}catch(t){throw new Error(`Error loading default Blue: ${t}`)}}};h(he,"DEFAULT_BLUE_BLUE_ID","FREHAAGDZSzpnoTUoCQ86bBmxbVCULMjvx9JZM6fyqT1");let ae=he;class lr{constructor(e,t){h(this,"preprocessingAliases",new Map);h(this,"urlContentFetcher");e&&(this.preprocessingAliases=new Map(e)),this.urlContentFetcher=t}process(e){const t=this.getBlueNodeValue(e);if(t){const r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(x.isPotentialBlueId(t))return this.handleBlueId(r,t);throw K(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 r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(x.isPotentialBlueId(t))return this.handleBlueId(r,t);if(K(t)&&this.urlContentFetcher)try{const s=await this.fetchFromUrl(t);return s&&r.setBlue(new a().setItems(s)),r}catch(s){throw s instanceof Error?new Error(`Failed to fetch from URL '${t}'.
27
- ${s.message}`):s}else throw K(t)?new Error(`UrlContentFetcher not provided for URL: ${t}`):new Error(`Invalid blue value: ${t}`)}return e}getBlueNodeValue(e){const t=e.getBlue(),r=t==null?void 0:t.getValue();return r&&typeof r=="string"?r:null}handleAliasValue(e,t){return e.setBlue(new a().setBlueId(this.preprocessingAliases.get(t))),e}handleBlueId(e,t){return e.setBlue(new a().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,r)=>{this.preprocessingAliases.set(r,t)}),this}setUrlContentFetcher(e){return this.urlContentFetcher=e,this}getUrlContentFetcher(){return this.urlContentFetcher}}const cr={fetchUrl:async n=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${n}`)}};class ar{constructor(e){h(this,"cache",new Map);h(this,"fetchStrategy");h(this,"enabled",!1);h(this,"allowedDomains",[]);this.fetchStrategy=e||cr}validateUrl(e){if(!K(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(r=>t.hostname===r||t.hostname.endsWith(`.${r}`))}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(c){throw new Error(`Error fetching from URL: ${e}`,{cause:c})}const{data:r,contentType:s}=t;let i;if(s.includes("application/json")||s.includes("text/yaml")||s.includes("application/yaml")||s.includes("text/plain"))i=G(r);else throw new Error(`Unsupported content type from URL: ${s}`);if(i===void 0)throw new Error(`Failed to parse content from URL: ${e}`);let o;return Array.isArray(i)?o=i.map(c=>y.deserialize(c)):o=[y.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 ur{constructor(e={}){h(this,"nodeProvider");h(this,"typeSchemaResolver");h(this,"blueDirectivePreprocessor");h(this,"urlContentFetcher");h(this,"blueIdsMappingGenerator");h(this,"prepareForBlueIdCalculation",async e=>e instanceof a||Array.isArray(e)&&e.every(t=>t instanceof a)?e:Array.isArray(e)?await Promise.all(e.map(r=>this.jsonValueToNodeAsync(r))):this.jsonValueToNodeAsync(e));h(this,"calculateBlueId",async e=>{const t=await this.prepareForBlueIdCalculation(e);return S.calculateBlueId(t)});h(this,"prepareForBlueIdCalculationSync",e=>e instanceof a||Array.isArray(e)&&e.every(t=>t instanceof a)?e:Array.isArray(e)?e.map(t=>this.jsonValueToNode(t)):this.jsonValueToNode(e));const{nodeProvider:t,typeSchemaResolver:r=null,urlFetchStrategy:s,repositories:i}=e,o=Mn(()=>[]);if(this.nodeProvider=ce.wrap(t||o),this.typeSchemaResolver=r,this.urlContentFetcher=new ar(s),this.blueDirectivePreprocessor=new lr(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new Et,i){const c=i.reduce((u,f)=>(u.blueIds={...u.blueIds,...f.blueIds},u.schemas=[...u.schemas,...f.schemas],u),{blueIds:{},schemas:[]});this.blueIdsMappingGenerator.initialize(c.blueIds),this.typeSchemaResolver||(this.typeSchemaResolver=new mt(c.schemas))}}nodeToJson(e,t="official"){return B.get(e,t)}nodeToSchemaOutput(e,t){return new Un(this.typeSchemaResolver).convert(e,t)}jsonValueToNode(e){return this.preprocess(y.deserialize(e))}async jsonValueToNodeAsync(e){return this.preprocessAsync(y.deserialize(e))}yamlToNode(e){const t=G(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=G(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return S.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new ae({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new ae({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=ce.wrap(e),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}}exports.Base58Sha256Provider=tt;exports.Blue=ur;exports.BlueIdCalculator=S;exports.BlueIdToCid=an;exports.BlueNode=a;exports.BlueNodeTypeSchema=Sn;exports.JsonCanonicalizer=et;exports.TypeSchemaResolver=mt;exports.applyBlueNodePatch=In;exports.baseBlueObjectSchema=se;exports.blueDescriptionField=Bn;exports.blueIdField=Nn;exports.blueIdSchema=Yt;exports.blueNameField=wn;exports.blueNodeField=vn;exports.blueObjectBooleanValueSchema=Ht;exports.blueObjectNumberValueSchema=Jt;exports.blueObjectSchema=_;exports.blueObjectStringListItemsSchema=Wt;exports.blueObjectStringValueSchema=Gt;exports.calculateBlueId=Nt;exports.calculateBlueIdSync=Xn;exports.enrichWithBlueId=Se;exports.getBlueDescriptionAnnotation=lt;exports.getBlueIdAnnotation=at;exports.getBlueNameAnnotation=dt;exports.getBlueNodeAnnotation=ft;exports.getBlueObjectItems=Qn;exports.getBlueObjectProperties=tr;exports.getBlueObjectTypeLabel=nr;exports.getBlueObjectValue=er;exports.getExtendedFromSchemaAnnotation=yt;exports.getTypeBlueIdAnnotation=gt;exports.hasBlueObjectBlueIdDefined=We;exports.hasBlueObjectItemsDefined=Ke;exports.hasBlueObjectNameDefined=qt;exports.hasBlueObjectTypeDefined=qe;exports.hasBlueObjectValueDefined=Xe;exports.isBigDecimalNumber=Qe;exports.isBigIntegerNumber=k;exports.isBigNumber=A;exports.isBlueNodeSchema=Ee;exports.isBlueObject=Kt;exports.isBlueObjectResolved=wt;exports.isGivenBlueObjectTypeSchema=Xt;exports.isJsonBlueArray=xe;exports.isJsonBlueObject=Ze;exports.isJsonBlueValue=tn;exports.isSchemaExtendedFrom=$e;exports.isUrl=K;exports.jsonBlueValueSchema=Q;exports.normalizeToBlueObject=rr;exports.resolveBlueObjectItems=Ce;exports.withBlueDescription=ot;exports.withBlueId=ct;exports.withBlueName=ut;exports.withBlueNode=ht;exports.withExtendedFromSchema=pt;exports.withTypeBlueId=An;exports.yamlBlueDump=Gn;exports.yamlBlueParse=G;
26
+ `}loadDefaultSimpleBlue(){const e=this.enrichDefaultBlue(Bt);try{const t=Y(e);if(t)this.defaultSimpleBlue=p.deserialize(t);else throw new Error("Failed to parse default Blue content")}catch(t){throw new Error(`Error loading default Blue: ${t}`)}}};h(he,"DEFAULT_BLUE_BLUE_ID","FREHAAGDZSzpnoTUoCQ86bBmxbVCULMjvx9JZM6fyqT1");let ae=he;class ar{constructor(e,t){h(this,"preprocessingAliases",new Map);h(this,"urlContentFetcher");e&&(this.preprocessingAliases=new Map(e)),this.urlContentFetcher=t}process(e){const t=this.getBlueNodeValue(e);if(t){const r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(x.isPotentialBlueId(t))return this.handleBlueId(r,t);throw K(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 r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(x.isPotentialBlueId(t))return this.handleBlueId(r,t);if(K(t)&&this.urlContentFetcher)try{const s=await this.fetchFromUrl(t);return s&&r.setBlue(new a().setItems(s)),r}catch(s){throw s instanceof Error?new Error(`Failed to fetch from URL '${t}'.
27
+ ${s.message}`):s}else throw K(t)?new Error(`UrlContentFetcher not provided for URL: ${t}`):new Error(`Invalid blue value: ${t}`)}return e}getBlueNodeValue(e){const t=e.getBlue(),r=t==null?void 0:t.getValue();return r&&typeof r=="string"?r:null}handleAliasValue(e,t){return e.setBlue(new a().setBlueId(this.preprocessingAliases.get(t))),e}handleBlueId(e,t){return e.setBlue(new a().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,r)=>{this.preprocessingAliases.set(r,t)}),this}setUrlContentFetcher(e){return this.urlContentFetcher=e,this}getUrlContentFetcher(){return this.urlContentFetcher}}const ur={fetchUrl:async n=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${n}`)}};class dr{constructor(e){h(this,"cache",new Map);h(this,"fetchStrategy");h(this,"enabled",!1);h(this,"allowedDomains",[]);this.fetchStrategy=e||ur}validateUrl(e){if(!K(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(r=>t.hostname===r||t.hostname.endsWith(`.${r}`))}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(c){throw new Error(`Error fetching from URL: ${e}`,{cause:c})}const{data:r,contentType:s}=t;let i;if(s.includes("application/json")||s.includes("text/yaml")||s.includes("application/yaml")||s.includes("text/plain"))i=Y(r);else throw new Error(`Unsupported content type from URL: ${s}`);if(i===void 0)throw new Error(`Failed to parse content from URL: ${e}`);let o;return Array.isArray(i)?o=i.map(c=>p.deserialize(c)):o=[p.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 hr{constructor(e={}){h(this,"nodeProvider");h(this,"typeSchemaResolver");h(this,"blueDirectivePreprocessor");h(this,"urlContentFetcher");h(this,"blueIdsMappingGenerator");h(this,"prepareForBlueIdCalculation",async e=>e instanceof a||Array.isArray(e)&&e.every(t=>t instanceof a)?e:Array.isArray(e)?await Promise.all(e.map(r=>this.jsonValueToNodeAsync(r))):this.jsonValueToNodeAsync(e));h(this,"calculateBlueId",async e=>{const t=await this.prepareForBlueIdCalculation(e);return A.calculateBlueId(t)});h(this,"prepareForBlueIdCalculationSync",e=>e instanceof a||Array.isArray(e)&&e.every(t=>t instanceof a)?e:Array.isArray(e)?e.map(t=>this.jsonValueToNode(t)):this.jsonValueToNode(e));var c;const{nodeProvider:t,typeSchemaResolver:r=null,urlFetchStrategy:s,repositories:i}=e,o=Ln(()=>[]);if(this.nodeProvider=ce.wrap(t||o),this.typeSchemaResolver=r??new bt([]),this.urlContentFetcher=new dr(s),this.blueDirectivePreprocessor=new ar(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new St,i)for(const{schemas:u,blueIds:g}of i)(c=this.typeSchemaResolver)==null||c.registerSchemas(u),this.blueIdsMappingGenerator.registerBlueIds(g)}nodeToJson(e,t="official"){return T.get(e,t)}nodeToSchemaOutput(e,t){return new $n(this.typeSchemaResolver).convert(e,t)}jsonValueToNode(e){return this.preprocess(p.deserialize(e))}async jsonValueToNodeAsync(e){return this.preprocessAsync(p.deserialize(e))}yamlToNode(e){const t=Y(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=Y(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return A.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new ae({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new ae({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=ce.wrap(e),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}}exports.Base58Sha256Provider=tt;exports.Blue=hr;exports.BlueIdCalculator=A;exports.BlueIdToCid=un;exports.BlueNode=a;exports.BlueNodeTypeSchema=On;exports.JsonCanonicalizer=et;exports.TypeSchemaResolver=bt;exports.applyBlueNodePatch=Tn;exports.baseBlueObjectSchema=se;exports.blueDescriptionField=Nn;exports.blueIdField=vn;exports.blueIdSchema=Yt;exports.blueNameField=En;exports.blueNodeField=Sn;exports.blueObjectBooleanValueSchema=Wt;exports.blueObjectNumberValueSchema=Ht;exports.blueObjectSchema=_;exports.blueObjectStringListItemsSchema=Kt;exports.blueObjectStringValueSchema=Jt;exports.calculateBlueId=wt;exports.calculateBlueIdSync=er;exports.enrichWithBlueId=Ae;exports.getBlueDescriptionAnnotation=ct;exports.getBlueIdAnnotation=ut;exports.getBlueNameAnnotation=ht;exports.getBlueNodeAnnotation=pt;exports.getBlueObjectItems=tr;exports.getBlueObjectProperties=rr;exports.getBlueObjectTypeLabel=sr;exports.getBlueObjectValue=nr;exports.getExtendedFromSchemaAnnotation=yt;exports.getTypeBlueIdAnnotation=mt;exports.hasBlueObjectBlueIdDefined=We;exports.hasBlueObjectItemsDefined=Ke;exports.hasBlueObjectNameDefined=Xt;exports.hasBlueObjectTypeDefined=qe;exports.hasBlueObjectValueDefined=Xe;exports.isBigDecimalNumber=Qe;exports.isBigIntegerNumber=k;exports.isBigNumber=P;exports.isBlueNodeSchema=Ee;exports.isBlueObject=qt;exports.isBlueObjectResolved=vt;exports.isGivenBlueObjectTypeSchema=Qt;exports.isJsonBlueArray=xe;exports.isJsonBlueObject=Ze;exports.isJsonBlueValue=nn;exports.isSchemaExtendedFrom=$e;exports.isUrl=K;exports.jsonBlueValueSchema=Q;exports.normalizeToBlueObject=ir;exports.resolveBlueObjectItems=Ce;exports.withBlueDescription=lt;exports.withBlueId=at;exports.withBlueName=dt;exports.withBlueNode=ft;exports.withExtendedFromSchema=gt;exports.withTypeBlueId=Cn;exports.yamlBlueDump=Hn;exports.yamlBlueParse=Y;