@blue-labs/language 1.26.0 → 1.27.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 Ut=Object.defineProperty;var Lt=(r,e,t)=>e in r?Ut(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var h=(r,e,t)=>Lt(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@blue-labs/shared-utils"),c=require("zod"),_t=require("bs58"),x=require("big.js"),v=require("radash"),kt=require("js-sha256"),Jt=require("crypto"),Gt=require("base32.js"),_=require("js-yaml"),nt=r=>r&&r.__esModule?r:{default:r},oe=nt(_t),we=nt(Jt);class Yt{static get(e,t,n,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,n,s)}static getRecursive(e,t,n,s,i){if(n===t.length-1&&!i)return this.getNodeForSegment(e,t[n],s,!1);if(n===t.length){const a=e.getValue();return i&&a!==void 0?a:e}const o=t[n],l=this.getNodeForSegment(e,o,s,!0);if(l)return this.getRecursive(l,t,n+1,s,i)}static getNodeForSegment(e,t,n,s){let i;const o=e.getProperties();if(o&&t in o)i=o[t];else switch(t){case"name":{const l=e.getName();i=d.isNonNullable(l)?new u().setValue(l):new u;break}case"description":{const l=e.getDescription();i=d.isNonNullable(l)?new u().setValue(l):new u;break}case"type":i=e.getType()??new u;break;case"itemType":i=e.getItemType()??new u;break;case"keyType":i=e.getKeyType()??new u;break;case"valueType":i=e.getValueType()??new u;break;case"value":{const l=e.getValue();i=new u().setValue(l??null);break}case"blueId":{const l=e.getBlueId();i=d.isNonNullable(l)?new u().setValue(l):new u;break}case"blue":i=e.getBlue();break;case"items":{const l=e.getItems();i=new u().setItems(l);break}case"properties":{const l=e.getProperties();i=new u().setProperties(l);break}case"contracts":{const l=e.getContracts();i=new u().setContracts(l);break}default:{if(/^\d+$/.test(t)){const l=parseInt(t,10),a=e.getItems();a&&l>=0&&l<a.length?i=a[l]:i=void 0}else i=void 0;break}}if(i)return s&&n?this.link(i,n):i}static link(e,t){const n=t(e);return d.isNonNullable(n)?n:e}}class P extends x{constructor(e){super(e)}}class C extends x{constructor(e){super(e)}}const J="name",G="description",pe="type",ze="itemType",Ze="keyType",Ue="valueType",Ie="value",Le="items",U="blueId",_e="blue",Te="contracts",Kt=[J,G,pe,ze,Ze,Ue,Ie,Le,U,_e,Te],Wt="Text",Ht="Double",qt="Integer",Xt="Boolean",Qt="List",er="Dictionary",ke=[Wt,Ht,qt,Xt],st=[...ke,Qt,er],H="F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP",q="68ryJtnmui4j5rCZWUnkZ3DChtmEb7Z9F8atn1mBSM3L",X="DHmxTkFbXePZHCHCYmQr2dSzcNLcryFVjXVHkdQrrZr8",Q="EL6AjrbJsxTWRTPzY8WR8Y2zAMXRbydQj83PcZwuAHbo",it="G8wmfjEqugPEEXByMYWJXiEdbLToPRWNQEekNxrxfQWB",ot="294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA",lt=[H,q,X,Q],ue=[...lt,it,ot];Object.fromEntries(st.map((r,e)=>[r,ue[e]]));const tr=Object.fromEntries(ue.map((r,e)=>[r,st[e]])),j=class j{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 j().setValue(e).setInlineValue(!0):this.type=e,this}getItemType(){return this.itemType}setItemType(e){return typeof e=="string"?this.itemType=new j().setValue(e).setInlineValue(!0):this.itemType=e,this}getKeyType(){return this.keyType}setKeyType(e){return typeof e=="string"?this.keyType=new j().setValue(e).setInlineValue(!0):this.keyType=e,this}getValueType(){return this.valueType}setValueType(e){return typeof e=="string"?this.valueType=new j().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===X&&typeof this.value=="string")return new P(this.value);if(e===q&&typeof this.value=="string"){const n=new C(this.value),s=parseFloat(n.toString());return new C(s.toString())}else if(e===Q&&typeof this.value=="string")return this.value.toLowerCase()==="true"}return this.value}setValue(e){return typeof e=="number"?e%1===0?this.value=new P(e.toString()):this.value=new C(e.toString()):this.value=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}addItems(...e){return this.items||(this.items=[]),this.items.push(...e),this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}addProperty(e,t){return this.properties||(this.properties={}),this.properties[e]=t,this}removeProperty(e){return this.properties&&delete this.properties[e],this}getContracts(){return this.contracts}setContracts(e){return this.contracts=e,this}addContract(e,t){return this.contracts||(this.contracts={}),this.contracts[e]=t,this}removeContract(e){return this.contracts&&delete this.contracts[e],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 Yt.get(this,e,t)}clone(){var t,n,s,i,o,l;const e=new j(this.name);return e.description=this.description,e.type=(t=this.type)==null?void 0:t.clone(),e.itemType=(n=this.itemType)==null?void 0:n.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(a=>a.clone()),this.properties&&(e.properties=Object.fromEntries(Object.entries(this.properties).map(([a,f])=>[a,f.clone()]))),this.contracts&&(e.contracts=Object.fromEntries(Object.entries(this.contracts).map(([a,f])=>[a,f.clone()]))),e.blueId=this.blueId,e.blue=(l=this.blue)==null?void 0:l.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(j,"INTEGER",new j("Integer"));let u=j;class Z{static isPotentialBlueId(e){if(!e||e.length===0||!this.BLUE_ID_PATTERN.test(e))return!1;const t=e.split("#"),n=t[0],s=n.length;if(s<this.MIN_BLUE_ID_LENGTH||s>this.MAX_BLUE_ID_LENGTH)return!1;try{if(oe.default.decode(n).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(Z,"MIN_BLUE_ID_LENGTH",41),h(Z,"MAX_BLUE_ID_LENGTH",45),h(Z,"BLUE_ID_PATTERN",/^[1-9A-HJ-NP-Za-km-z]{41,45}(?:#\d+)?$/);const rr=c.z.string().max(Z.MAX_BLUE_ID_LENGTH,{message:"Blue Id has a maximum length of 45 characters"}).min(Z.MIN_BLUE_ID_LENGTH,{message:"Blue Id has a minimum length of 41 characters"}).refine(r=>{try{return oe.default.decode(r),!0}catch{return!1}},{message:"Blue Id must be a valid Base58 string"}),Y=c.z.lazy(()=>c.z.record(c.z.unknown()).and(c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:Y.optional(),value:c.z.union([c.z.string(),c.z.number(),c.z.boolean()]).optional().nullable(),items:c.z.array(Y).optional()}))),de=c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:Y.optional()}),nr=de.extend({value:c.z.string().optional()}),sr=de.extend({value:c.z.number().optional()}),ir=de.extend({value:c.z.boolean().optional()}),or=de.extend({items:c.z.array(c.z.string()).optional()}),lr=r=>Y.safeParse(r).success,ct=r=>d.isNonNullable(r)&&"blueId"in r&&d.isNonNullable(r.blueId),cr=r=>d.isNonNullable(r)&&"name"in r&&d.isNonNullable(r.name),at=r=>d.isNonNullable(r)&&"items"in r&&d.isNonNullable(r.items),ut=r=>d.isNonNullable(r)&&"type"in r&&d.isNonNullable(r.type),dt=r=>d.isNonNullable(r)&&"value"in r&&d.isNonNullable(r.value),ar=(r,e)=>r.required({type:!0}).safeParse(e).success,O=r=>r instanceof x,K=r=>O(r)&&r instanceof P,ht=r=>O(r)&&r instanceof C,ur=c.z.lazy(()=>c.z.record(le)),dr=c.z.lazy(()=>c.z.union([c.z.array(le),c.z.array(le).readonly()])),le=c.z.lazy(()=>c.z.union([d.jsonPrimitiveSchema,ur,dr,c.z.instanceof(x)])),Je=r=>v.isObject(r)&&!v.isArray(r)&&!d.isReadonlyArray(r)&&!O(r),Ge=r=>v.isArray(r)||d.isReadonlyArray(r),hr=r=>Ge(r)||Je(r)||O(r)||d.isJsonPrimitive(r);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(Je(e)){const t=new u,n={},s={};return Object.entries(e).forEach(([i,o])=>{switch(i){case J:if(o==null)t.setName(void 0);else{if(typeof o!="string")throw new Error(`The ${J} field must be a string.`);t.setName(o)}break;case G:if(o==null)t.setDescription(void 0);else{if(typeof o!="string")throw new Error(`The ${G} field must be a string.`);t.setDescription(o)}break;case pe:t.setType(p.handleNode(o));break;case ze:t.setItemType(p.handleNode(o));break;case Ze:t.setKeyType(p.handleNode(o));break;case Ue:t.setValueType(p.handleNode(o));break;case Ie: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 Le:t.setItems(p.handleArray(o));break;case _e:t.setBlue(p.handleNode(o));break;case Te:v.isObject(o)&&!v.isArray(o)&&!d.isReadonlyArray(o)&&Object.entries(o).forEach(([l,a])=>{s[l]=p.handleNode(a)});break;default:n[i]=p.handleNode(o);break}}),Object.keys(n).length>0&&t.setProperties(n),Object.keys(s).length>0&&t.setContracts(s),t}else{if(Ge(e))return new u().setItems(p.handleArray(e));{const t=e;return new u().setValue(p.handleValue(t)).setInlineValue(!0)}}}static handleValue(e){if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="number"||O(e))if(K(e)||Number.isSafeInteger(e)){const t=new P(e.toString()),n=Number.MIN_SAFE_INTEGER,s=Number.MAX_SAFE_INTEGER;return t.lt(n)?new P(n.toString()):t.gt(s)?new P(s.toString()):t}else{const t=parseFloat(e.toString());return new C(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(v.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 fr(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var ve,Qe;function pr(){return Qe||(Qe=1,ve=function r(e){if(typeof e=="number"&&isNaN(e))throw new Error("NaN is not allowed");if(typeof e=="number"&&!isFinite(e))throw new Error("Infinity is not allowed");return e===null||typeof e!="object"?JSON.stringify(e):e.toJSON instanceof Function?r(e.toJSON()):Array.isArray(e)?`[${e.reduce((s,i,o)=>`${s}${o===0?"":","}${r(i===void 0||typeof i=="symbol"?null:i)}`,"")}]`:`{${Object.keys(e).sort().reduce((n,s)=>{if(e[s]===void 0||typeof e[s]=="symbol")return n;const i=n.length===0?"":",";return`${n}${i}${r(s)}:${r(e[s])}`},"")}}`}),ve}var yr=pr();const gr=fr(yr);class ft{static canonicalize(e){return gr(e)}}const Ee=typeof process<"u"&&process.versions!=null&&process.versions.node!=null,ge=class ge{constructor(){h(this,"browserCrypto");this.browserCrypto=this.initBrowserCrypto()}static getInstance(){return this.instance||(this.instance=new ge),this.instance}initBrowserCrypto(){return Ee?null:"crypto"in globalThis?globalThis.crypto:null}hasNodeCrypto(){return Ee&&!!we.default&&typeof we.default.createHash=="function"}getBrowserCrypto(){return this.browserCrypto}getNodeCrypto(){return Ee?we.default:null}};h(ge,"instance");let Ve=ge;class pt{constructor(){h(this,"cryptoEnv",Ve.getInstance())}applySync(e){const t=this.canonicalizeInput(e),n=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):this.sha256SyncBrowser(t);return oe.default.encode(new Uint8Array(n))}async apply(e){const t=this.canonicalizeInput(e),n=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):await this.sha256Async(t);return oe.default.encode(new Uint8Array(n))}canonicalizeInput(e){const t=ft.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 kt.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 y{static get(e,t="official"){var fe;const n=e.getValue(),s=this.handleValue(n);if(s!==void 0&&t==="simple")return s;const i=(fe=e.getItems())==null?void 0:fe.map(F=>y.get(F,t));if(i!==void 0&&t==="simple")return i;const o=e.getName(),l=e.getDescription();if(t==="original"&&o===void 0&&l===void 0){if(s!==void 0)return s;if(i!==void 0)return i}const a={};o!==void 0&&(a[J]=o),l!==void 0&&(a[G]=l);const f=e.getType();if(t==="official"&&n!==void 0&&f===void 0){const F=this.inferTypeBlueId(n);F!==null&&(a[pe]={[U]:F})}else f!==void 0&&(a[pe]=y.get(f,t));const I=e.getItemType();I!==void 0&&(a[ze]=y.get(I,t));const T=e.getKeyType();T!==void 0&&(a[Ze]=y.get(T,t));const b=e.getValueType();b!==void 0&&(a[Ue]=y.get(b,t)),s!==void 0&&(a[Ie]=s),i!==void 0&&(a[Le]=i);const m=e.getBlueId();m!==void 0&&(a[U]=m);const g=e.getBlue();g!==void 0&&(a[_e]=g);const B=e.getContracts();if(B!==void 0){const F={};Object.entries(B).forEach(([Be,Zt])=>{F[Be]=y.get(Zt,t)}),a[Te]=F}const D=e.getProperties();return D!==void 0&&Object.entries(D).forEach(([F,Be])=>{a[F]=y.get(Be,t)}),a}static handleValue(e){if(O(e)){if(K(e)){const t=new x(Number.MIN_SAFE_INTEGER.toString()),n=new x(Number.MAX_SAFE_INTEGER.toString());if(e.lt(t)||e.gt(n))return e.toString()}return e.toNumber()}return e}static inferTypeBlueId(e){return typeof e=="string"?H:O(e)?K(e)?X:q:typeof e=="boolean"?Q:null}}const mr=r=>d.isJsonPrimitive(r)&&d.isNonNullable(r),M=class M{constructor(e){h(this,"hashProvider");this.hashProvider=e}static calculateBlueId(e){if(Array.isArray(e)){const n=e.map(s=>y.get(s));return M.INSTANCE.calculate(n)}const t=y.get(e);return M.INSTANCE.calculate(t)}static calculateBlueIdSync(e){if(Array.isArray(e)){const n=e.map(s=>y.get(s));return M.INSTANCE.calculateSync(n)}const t=y.get(e);return M.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 mr(e)||O(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 l=e[o];if([J,Ie,G].includes(o))return t?[o,l]:Promise.resolve([o,l]);{const a=this.internalCalculate(l,t);return t?[o,{blueId:a}]:Promise.resolve(a).then(f=>[o,{blueId:f}])}}),i=o=>{const l={};for(const[a,f]of o)l[a]=f;return this.applyHash(l,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 n=this.internalCalculate(e[0],t);const s=(i,o)=>t?this.applyHash([{blueId:i},{blueId:o}],!0):Promise.all([i,o]).then(([l,a])=>this.applyHash([{blueId:l},{blueId:a}],!1));for(let i=1;i<e.length;i++){const o=this.internalCalculate(e[i],t);n=s(n,o)}return n}applyHash(e,t){return t?this.hashProvider.applySync(e):this.hashProvider.apply(e)}cleanStructure(e){if(e!=null){if(d.isJsonPrimitive(e)||O(e))return e;if(Array.isArray(e)||d.isReadonlyArray(e)){const t=e.map(n=>this.cleanStructure(n)).filter(d.isNonNullable);return t.length>0?t:void 0}else if(typeof e=="object"){const t={};for(const n in e){const s=this.cleanStructure(e[n]);s!=null&&(t[n]=s)}return Object.keys(t).length>0?t:void 0}else return e}}};h(M,"INSTANCE",new M(new pt));let N=M;class br{static convert(e){const t=oe.default.decode(e),n=new Uint8Array(2+t.length);n[0]=18,n[1]=32,n.set(t,2);const s=new Uint8Array(2+n.length);return s[0]=1,s[1]=85,s.set(n,2),"b"+new Gt.Encoder({type:"rfc4648",lc:!0}).write(s).finalize().replace(/=/g,"")}}class V{static transform(e,t){const n=t(e.clone()),s=n.getType();s!==void 0&&n.setType(V.transform(s,t));const i=n.getItemType();i!==void 0&&n.setItemType(V.transform(i,t));const o=n.getKeyType();o!==void 0&&n.setKeyType(V.transform(o,t));const l=n.getValueType();l!==void 0&&n.setValueType(V.transform(l,t));const a=n.getItems();if(a!==void 0){const T=a.map(b=>V.transform(b,t));n.setItems(T)}const f=n.getProperties();if(f!==void 0){const T=Object.keys(f).reduce((b,m)=>(b[m]=V.transform(f[m],t),b),{});n.setProperties(T)}const I=n.getContracts();if(I!==void 0){const T=Object.keys(I).reduce((b,m)=>(b[m]=V.transform(I[m],t),b),{});n.setContracts(T)}return n}}const $=r=>!!r&&typeof r=="object"&&!Array.isArray(r)&&!(r instanceof u),R=r=>r instanceof P||r instanceof C,Ir=r=>r.replace(/~1/g,"/").replace(/~0/g,"~");function ee(r){if(r==="/")return[];if(!r.startsWith("/"))throw new Error(`Path must start with '/': ${r}`);return r.split("/").slice(1).map(Ir)}function W(r){if(r==="-")return-1;const e=typeof r=="number"?r:parseInt(r,10);if(isNaN(e))throw new Error(`Invalid array index (NaN) from '${r}'`);if(!Number.isFinite(e))throw new Error(`Invalid array index '${r}' results in non-finite number ${e}`);return e}function yt(r,e,t,n=!0){switch(e){case"name":return t?n?r.getName()??null:r:r.getName();case"description":return t?n?r.getDescription():r:r.getDescription();case"type":return r.getType();case"itemType":return r.getItemType();case"keyType":return r.getKeyType();case"valueType":return r.getValueType();case"value":return t?n?r.getValue()??null:r:r.getValue();case"blueId":return t?n?r.getBlueId()??null:r:r.getBlueId();case"blue":return r.getBlue();case"items":return r.getItems();case"properties":return r.getProperties();case"contracts":return r.getContracts();default:return}}function et(r,e,t=!0){if(r instanceof u){const n=yt(r,e,!0,t);if(n!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(e))return n;if(/^-?\d+$/.test(e)&&e!=="-"){const i=r.getItems(),o=parseInt(e,10);return i&&o>=0&&o<i.length?i[o]:void 0}const s=r.getProperties();return s&&e in s?s[e]:void 0}if(Array.isArray(r)){if(e==="-")return;const n=W(e);return n>=0&&n<r.length?r[n]:void 0}if($(r))return r[e]}function te(r,e){if(e.length===0)return{parent:r,key:"value",actualTarget:r.getValue()??r};let t=r;for(let s=0;s<e.length-1;++s){const i=e[s],o=et(t,i);if(o===void 0)throw new Error(`Cannot resolve '/${e.slice(0,s+1).join("/")}'`);t=o}const n=e[e.length-1];if(t instanceof u){const s=et(t,n,!1);if((typeof s!="object"||s===null||R(s))&&!(s instanceof u)&&!Array.isArray(s)&&["name","description","value","blueId"].includes(n))return{parent:t,key:n,actualTarget:s}}return Array.isArray(t)&&n==="-"?{parent:t,key:"-"}:t instanceof u&&t.getItems()&&n==="-"?{parent:t,key:"-"}:{parent:t,key:Array.isArray(t)?W(n):n}}function Ye(r,e){var t;if(r instanceof u){const n=e,s=yt(r,n,!1);if(s!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(n))return s;if(typeof e=="number"||typeof e=="string"&&/^\d+$/.test(e)){const i=r.getItems(),o=typeof e=="number"?e:parseInt(e,10);if(i&&o>=0&&o<i.length)return i[o]}return(t=r.getProperties())==null?void 0:t[n]}return Array.isArray(r)||$(r)?r[e]:r}function w(r){if(r instanceof u)return r;if(r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean"||R(r))return p.deserialize(r);const e=De(r);return p.deserialize(e)}function De(r){if(r===void 0)return null;if(r===null||typeof r!="object")return r;if(Array.isArray(r))return r.map(De);const e={};for(const[t,n]of Object.entries(r))e[t]=De(n);return e}function Ke(r,e,t){if(r instanceof u){const n=e;switch(n){case"name":r.setName(t);return;case"description":r.setDescription(t);return;case"type":r.setType(t instanceof u||typeof t=="string"||t===void 0?t:w(t));return;case"itemType":r.setItemType(t instanceof u||typeof t=="string"||t===void 0?t:w(t));return;case"keyType":r.setKeyType(t instanceof u||typeof t=="string"||t===void 0?t:w(t));return;case"valueType":r.setValueType(t instanceof u||typeof t=="string"||t===void 0?t:w(t));return;case"value":{const s=t;r.setValue(s===void 0?null:s);return}case"blueId":r.setBlueId(t);return;case"blue":r.setBlue(t instanceof u||t===void 0?t:w(t));return;case"items":r.setItems(t);return;case"properties":r.setProperties(t);return;case"contracts":r.setContracts(t);return;default:{if(t===void 0){const s=r.getProperties();s&&n in s&&delete s[n]}else r.getProperties()||r.setProperties({}),r.addProperty(n,t instanceof u?t:w(t));return}}}Array.isArray(r)?r.splice(W(e),1):$(r)&&(t===void 0?delete r[e]:r[e]=t)}function Tr(r,e,t,n){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=r.getItems();if(i||(i=[],r.setItems(i)),!n&&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(n){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 ye(r,e,t,n){if(Array.isArray(r)){const s=e==="-"?r.length:W(e);if(!n&&s>r.length)throw new Error(`ADD operation failed: Target array index '${s}' is greater than array length ${r.length}. Path involving key '${e}'.`);if(s<0&&e!=="-")throw new Error(`Invalid negative array index: ${e}`);const i=w(t);if(n){if(s>=0&&s<r.length)r[s]=i;else if(s>=r.length){for(let o=r.length;o<s;o++)r.push(p.deserialize(null));r.push(i)}}else r.splice(s,0,i);return}if(r instanceof u){e==="-"||typeof e=="number"&&!isNaN(e)||typeof e=="string"&&/^\d+$/.test(e)?Tr(r,e,w(t),n):Ke(r,e,t);return}if($(r)){r[e]=w(t);return}throw new Error(`Cannot insert into parent of type ${typeof r}`)}function Nr(r,e){if(Array.isArray(r)){const t=W(e);t===-1&&e==="-"?r.length>0&&r.pop():t>=0&&t<r.length&&r.splice(t,1);return}if(r instanceof u){if(typeof e=="number"||typeof e=="string"&&/^-?\d+$/.test(e)){const t=r.getItems();if(t){const n=W(e);n===-1&&e==="-"?t.length>0&&t.pop():n>=0&&n<t.length&&t.splice(n,1),t.length===0&&r.setItems(void 0);return}}Ke(r,e,void 0)}else $(r)&&delete r[e]}function Fe(r){if(r instanceof u)return r.clone();if(Array.isArray(r))return r.map(t=>Fe(t));if($(r)){const e={};return Object.keys(r).forEach(t=>{e[t]=Fe(r[t])}),e}return r}function z(r,e){if(r===e||r instanceof u&&(r.isInlineValue()||r.getValue()!==void 0)&&z(r.getValue()??null,e)||e instanceof u&&(e.isInlineValue()||e.getValue()!==void 0)&&z(r,e.getValue()??null))return!0;if(r instanceof u&&e instanceof u||R(r)&&R(e)||R(r)&&typeof e=="number"||typeof r=="number"&&R(e))return r.toString()===e.toString();if(Array.isArray(r)&&Array.isArray(e))return r.length===e.length&&r.every((t,n)=>z(t,e[n]));if($(r)&&$(e)){const t=Object.keys(r),n=Object.keys(e);return t.length===n.length&&t.every(s=>z(r[s],e[s]))}return!1}function gt(r,e){const{parent:t,key:n}=te(r,ee(e));return Ye(t,n)}function mt(r,e,t){const n=ee(e);if(n.length===0&&e==="/"){const o=w(t);r.setValue(o.getValue()??null),o.getItems()?r.setItems(o.getItems()):r.setItems(void 0);return}const{parent:s,key:i}=te(r,n);ye(s,i,t,!0)}function Br(r,e,t){const n=ee(e);if(n.length===0&&e==="/"){if(r.getItems()&&Array.isArray(t)){const o=w(t);o.getItems()?(r.setItems(o.getItems()),r.setValue(null)):(r.setValue(o.getValue()??null),r.setItems(void 0))}else{const o=w(t);r.setValue(o.getValue()??null),o.getItems()&&r.setItems(o.getItems())}return!0}const{parent:s,key:i}=te(r,n);return ye(s,i,t,!1),!0}function wr(r,e,t){const n=ee(e);if(n.length===0&&e==="/"){const l=w(t);return r.setValue(l.getValue()??null),l.getItems()?r.setItems(l.getItems()):r.setItems(void 0),!0}const{parent:s,key:i,actualTarget:o}=te(r,n);if(o!==void 0&&s instanceof u)Ke(s,i,t);else{const l=Ye(s,i),a=Array.isArray(s)||s instanceof u&&s.getItems()&&(typeof i=="number"||typeof i=="string"&&/^\d+$/.test(i));if(l===void 0){if(a)throw new Error(`REPLACE failed: Target array index '${i.toString()}' is out of bounds or does not exist at path '${e}'.`);ye(s,i,t,!0)}else ye(s,i,t,!0)}return!0}function bt(r,e){const t=ee(e);if(t.length===0&&e==="/")return r.setValue(null),r.setItems(void 0),r.setProperties(void 0),!0;const{parent:n,key:s}=te(r,t);return Nr(n,s),!0}function vr(r,e,t){const n=Fe(gt(r,e));return mt(r,t,n),!0}function Er(r,e,t){const n=ee(e),{parent:s,key:i}=te(r,n),o=Ye(s,i);if(o===void 0)throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);return bt(r,e)?(mt(r,t,o),!0):!1}function Sr(r,e,t){const n=gt(r,e);let s=t;if(n instanceof u)if((t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||R(t))&&(n.isInlineValue()||n.getValue()!==void 0)){if(!z(n.getValue()??null,t))throw new Error(`TEST failed at '${e}': Expected ${JSON.stringify(t)}, got ${JSON.stringify(n.getValue()??null)}`);return!0}else typeof t=="object"&&!(t instanceof u)&&(s=w(t));else if(R(n)&&typeof t=="number")n instanceof P?s=new P(t.toString()):n instanceof C&&(s=new C(t.toString()));else if((n===null||typeof n=="string"||typeof n=="number"||typeof n=="boolean")&&R(t)){const i=t;!z(n,i.toString())&&(typeof n=="number"&&parseFloat(i.toString()))}if(!z(n,s)){const i=n instanceof u?n.toString():JSON.stringify(n),o=s instanceof u?s.toString():JSON.stringify(s);throw new Error(`TEST failed at '${e}': Expected ${o}, got ${i}`)}return!0}function Pr(r,e){switch(e.op){case"add":return Br(r,e.path,e.val);case"replace":return wr(r,e.path,e.val);case"remove":return bt(r,e.path);case"copy":return vr(r,e.from,e.path);case"move":return Er(r,e.from,e.path);case"test":return Sr(r,e.path,e.val)}}function Ar(r,e,t=!1){const n=t?r:r.clone();return Pr(n,e),n}const Se=Symbol.for("zod-schema-annotations");function Cr(){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 It(){const r=Cr();return Se in r||(r[Se]=new WeakMap),r[Se]}function re(r,e){const t=It(),n=t.get(r)||{};return t.set(r,{...n,...e}),r}const A=r=>It().get(r),Tt=r=>e=>{const t=A(e);return re(e,{...t,blueDescription:r})},Nt=r=>{const e=A(r);return d.isNonNullable(e)&&v.isString(e.blueDescription)?e.blueDescription:null},Or=r=>Tt(r)(c.z.string().optional()),Vr=c.z.union([c.z.string(),c.z.boolean()]),Bt=r=>e=>{const t=A(e);return re(e,{...t,blueId:r})},wt=r=>{const e=A(r),t=Vr.safeParse(e==null?void 0:e.blueId);return t.success?t.data:null},Dr=r=>Bt(r??!0)(c.z.string()),vt=r=>e=>{const t=A(e);return re(e,{...t,blueName:r})},Et=r=>{const e=A(r);return d.isNonNullable(e)&&v.isString(e.blueName)?e.blueName:null},Fr=r=>{const e=c.z.string().optional();return vt(r)(e)},St=()=>r=>{const e=A(r);return re(r,{...e,blueNode:!0})},Pt=r=>{const e=A(r);return d.isNonNullable(e)&&d.isNonNullable(e.blueNode)&&e.blueNode===!0?e.blueNode:null},We=r=>!!Pt(r),jr=()=>{const r=c.z.instanceof(u);return St()(r)},je="extendedFrom",At=({schema:r,baseSchema:e})=>{const t=A(r)||{};return re(r,{...t,[je]:e})},Ct=r=>{const e=A(r);return d.isNonNullable(e)&&e[je]?e[je]:null},He=(r,e)=>{const t=Ct(r);return d.isNullable(t)?!1:(t==null?void 0:t._def)===(e==null?void 0:e._def)?!0:He(t,e)},Rr=r=>new Proxy(r,{get(e,t,n){return t==="extend"?function(...s){const i=e.extend(...s);return At({schema:i,baseSchema:e})}:Reflect.get(e,t,n)}}),Mr=c.z.object({value:c.z.array(c.z.string()).optional(),defaultValue:c.z.string().optional()}),Ot=r=>{const e=A(r),t=Mr.passthrough().safeParse(e==null?void 0:e.typeBlueId);return t.success?t.data:null},xr=r=>e=>{const t=A(e),n=typeof r=="string"?{value:[r]}:r,s=Rr(e);return re(s,{...t,typeBlueId:{...(t==null?void 0:t.typeBlueId)||{},...n}})};class Ne{static resolveBlueId(e){var i;const t=Ot(e);if(d.isNullable(t))return null;const n=t.defaultValue;if(d.isNonNullable(n))return n;const s=(i=t.value)==null?void 0:i[0];return d.isNonNullable(s)?s:Ne.getRepositoryBlueId(t,e)}static getRepositoryBlueId(e,t){throw new Error("Not implemented")}}class S{static isTypeOf(e,t,n){var o;const s=Ne.resolveBlueId(t),i=(o=e.getType())==null?void 0:o.getBlueId();if(d.isNullable(s)||d.isNullable(i))return!1;if(s===i)return!0;if(n!=null&&n.checkSchemaExtensions&&d.isNonNullable(n.typeSchemaResolver)){const l=n.typeSchemaResolver.resolveSchema(e);return S.checkSchemaExtension(l,t)}return!1}static checkSchemaExtension(e,t){if(!d.isNonNullable(e))return!1;const n=S.unwrapSchema(e),s=S.unwrapSchema(t);return He(n,s)}static isWrapperType(e){return e instanceof c.ZodOptional||e instanceof c.ZodNullable||e instanceof c.ZodReadonly||e instanceof c.ZodBranded||e instanceof c.ZodEffects||e instanceof c.ZodLazy}static unwrapSchema(e){return We(e)?e:S.isWrapperType(e)?e instanceof c.ZodEffects?S.unwrapSchema(e.innerType()):e instanceof c.ZodLazy?S.unwrapSchema(e.schema):S.unwrapSchema(e.unwrap()):e}}class Vt{constructor(e){h(this,"blueIdMap",new Map);this.registerSchemas(e)}registerSchemas(e){for(const t of e)this.registerSchema(t)}registerSchema(e){const t=Ne.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)?N.calculateBlueIdSync(t):null}getBlueIdMap(){return new Map(this.blueIdMap)}}class Dt{static convertValue(e,t){var i;const n=(i=e.getType())==null?void 0:i.getBlueId(),s=e.getValue();return d.isNullable(s)?this.isPrimitive(t)?this.getDefaultPrimitiveValue(t):s:H===n?this.convertFromString(String(s),t):q===n||s instanceof C?this.convertFromBigDecimal(new C(s==null?void 0:s.toString()),t):X===n||s instanceof P?this.convertFromBigInteger(new P(s==null?void 0:s.toString()),t):Q===n||typeof s=="boolean"?this.convertFromBoolean(!!s,t):this.convertFromString(String(s),t)}static convertFromString(e,t){if(!t||t instanceof c.ZodString||t instanceof c.ZodEnum||t instanceof c.ZodNativeEnum)return e;if(t instanceof c.ZodNumber)return Number(e);if(t instanceof c.ZodBoolean)return e.toLowerCase()==="true";if(t instanceof c.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert String to ${t._def.typeName}`)}static convertFromBigDecimal(e,t){if(t instanceof c.ZodNumber)return e.toNumber();if(t instanceof c.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t._def.typeName}`)}static convertFromBigInteger(e,t){if(t instanceof c.ZodNumber)return e.toNumber();if(t instanceof c.ZodBigInt)return BigInt(e.toString());if(t instanceof c.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t._def.typeName}`)}static convertFromBoolean(e,t){if(!t||t instanceof c.ZodBoolean)return e;if(t instanceof c.ZodString)return e.toString();if(t instanceof c.ZodNumber)return Number(e);if(t instanceof c.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert Boolean to ${t._def.typeName}`)}static isPrimitive(e){return e?e instanceof c.ZodString||e instanceof c.ZodNumber||e instanceof c.ZodBoolean||e instanceof c.ZodBigInt:!1}static getDefaultPrimitiveValue(e){if(!e)return null;if(e instanceof c.ZodNumber)return 0;if(e instanceof c.ZodBoolean)return!1;if(e instanceof c.ZodString)return"";throw new Error(`Unsupported primitive type: ${e._def.typeName}`)}}class $r{convert(e,t){return Dt.convertValue(e,t)}}class zr{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof c.ZodAny||e instanceof c.ZodObject||e instanceof c.ZodRecord||e instanceof c.ZodMap||e instanceof c.ZodUnknown}convert(e,t){return this.convertFields(e,t)}convertFields(e,t){if(t instanceof c.ZodIntersection){const n=t._def.left,s=t._def.right,i=this.convert(e,n),o=this.convert(e,s);return{...i,...o}}if(t instanceof c.ZodUnion)throw new Error("Union not supported");if(t instanceof c.ZodObject)return Object.keys(t.shape).reduce((s,i)=>{const o=e.getProperties(),l=t.shape[i],a=wt(l);if(d.isNonNullable(a)){const g=v.isString(a)?a:i,B=o==null?void 0:o[g],D=B?N.calculateBlueIdSync(B):void 0;return s[i]=D,s}const f=Et(l);if(d.isNonNullable(f)){const g=o==null?void 0:o[f];return s[i]=g==null?void 0:g.getName(),s}const I=Nt(l);if(d.isNonNullable(I)){const g=o==null?void 0:o[I];return s[i]=g==null?void 0:g.getDescription(),s}if(i==="name"){const g=e.getName();return s[i]=g,s}if(i==="description"){const g=e.getDescription();return s[i]=g,s}const T=e.getContracts();if(i==="contracts"&&d.isNonNullable(T)&&this.canHandleStructuredData(l)){const g=Object.fromEntries(Object.entries(T).map(([D,fe])=>[D,y.get(fe)])),B=p.deserialize(g);s[i]=this.nodeToObjectConverter.convert(B,l)}const b=o==null?void 0:o[i];if(d.isNullable(b))return s;const m=this.nodeToObjectConverter.convert(b,l);return s[i]=m,s},{});throw new Error("Unknown schema type, "+t._def.typeName)}}class Zr{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const n=e.getItems();if(!n)return;const s=t.element;return n.map(o=>this.nodeToObjectConverter.convert(o,s))}}class Ur{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const n=e.getItems();if(!n)return;const s=t._def.valueType,i=n.map(o=>this.nodeToObjectConverter.convert(o,s));return new Set(i)}}class Lr{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof c.ZodAny||e instanceof c.ZodObject||e instanceof c.ZodRecord||e instanceof c.ZodMap||e instanceof c.ZodUnknown}convert(e,t){const n=t.keySchema,s=t.valueSchema,i=new Map,o=e.getName();d.isNonNullable(o)&&i.set(J,o);const l=e.getDescription();d.isNonNullable(l)&&i.set(G,l);const a=e.getContracts();if(d.isNonNullable(a)&&this.canHandleStructuredData(s)){let I=!1;const T=Object.entries(a).reduce((b,[m,g])=>{try{const B=this.nodeToObjectConverter.convert(g,s);B!=null&&!Number.isNaN(B)&&(b[m]=B,I=!0)}catch{}return b},{});I&&i.set(Te,T)}const f=e.getProperties();return d.isNonNullable(f)&&Object.entries(f).forEach(([I,T])=>{const b=new u().setValue(I);b.setType(new u().setBlueId(H));const m=Dt.convertValue(b,n),g=this.nodeToObjectConverter.convert(T,s);i.set(m,g)}),t instanceof c.ZodRecord?Object.fromEntries(i):i}}class _r{convert(e){return y.get(e)}}class kr{convert(e){return y.get(e)}}class Jr{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const n=e.getItems();if(!n)return;const s=t.items;return n.map((o,l)=>this.nodeToObjectConverter.convert(o,s[l]))}}const Gr=c.z.union([c.z.literal("ZodString"),c.z.literal("ZodNumber"),c.z.literal("ZodBoolean"),c.z.literal("ZodBigInt"),c.z.literal("ZodArray"),c.z.literal("ZodSet"),c.z.literal("ZodMap"),c.z.literal("ZodRecord"),c.z.literal("ZodObject"),c.z.literal("ZodEnum"),c.z.literal("ZodNativeEnum"),c.z.literal("ZodUnknown"),c.z.literal("ZodAny"),c.z.literal("ZodTuple")]);class Yr{constructor(e){h(this,"converters",new Map);h(this,"complexObjectConverter");this.nodeToObjectConverter=e,this.registerConverters(),this.complexObjectConverter=new zr(this.nodeToObjectConverter)}registerConverters(){const e=new $r,t=new Zr(this.nodeToObjectConverter),n=new Jr(this.nodeToObjectConverter),s=new Ur(this.nodeToObjectConverter),i=new Lr(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 _r),this.converters.set("ZodAny",new kr),this.converters.set("ZodArray",t),this.converters.set("ZodTuple",n),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 c.ZodOptional||e instanceof c.ZodNullable||e instanceof c.ZodReadonly||e instanceof c.ZodBranded||e instanceof c.ZodEffects||e instanceof c.ZodLazy}getSchemaTypeName(e){if(this.isWrapperType(e))return e instanceof c.ZodEffects?this.getSchemaTypeName(e.innerType()):e instanceof c.ZodLazy?this.getSchemaTypeName(e.schema):this.getSchemaTypeName(e.unwrap());const t=e._def.typeName;try{return Gr.parse(t)}catch{throw new Error(`Schema type name ${t} is not supported`)}}}class Kr{constructor(e){h(this,"converterFactory");this.typeSchemaResolver=e,this.converterFactory=new Yr(this)}convert(e,t){var o;const n=(o=this.typeSchemaResolver)==null?void 0:o.resolveSchema(e),s=S.unwrapSchema(t);if(We(s))return e;let i=s;return S.checkSchemaExtension(n,s)&&d.isNonNullable(n)&&(i=n),this.convertWithType(e,i)}convertWithType(e,t){return this.converterFactory.getConverter(t).convert(e,t)}}class he{fetchFirstByBlueId(e){const t=this.fetchByBlueId(e);return t&&t.length>0?t[0]:null}}function Wr(r){return new class extends he{fetchByBlueId(e){return r(e)}}}class Hr extends he{constructor(t){super();h(this,"nodeProviders");this.nodeProviders=t}fetchByBlueId(t){for(const n of this.nodeProviders){const s=n.fetchByBlueId(t);if(s&&s.length>0)return s}return[]}fetchFirstByBlueId(t){for(const n of this.nodeProviders){const s=n.fetchFirstByBlueId(t);if(s)return s}return null}getNodeProviders(){return this.nodeProviders}}const Pe=_.types.float.options,qr={...Pe,construct:r=>{const e=r.replace(/_/g,"").toLowerCase();if(!d.isPreciseNumberString(e))return new C(e);if(Pe.construct)return Pe.construct(r)}},Xr=new _.Type("tag:yaml.org,2002:float",qr),Ae=_.types.int.options,Qr={...Ae,construct:r=>{let e=r;if(e.indexOf("_")!==-1&&(e=e.replace(/_/g,"")),!d.isPreciseNumberString(e))return new P(e);if(Ae.construct)return Ae.construct(r)}},en=new _.Type("tag:yaml.org,2002:int",Qr),Ft=_.CORE_SCHEMA.extend({implicit:[Xr,en]}),L=r=>{const e=_.load(r,{schema:Ft});return e===void 0?void 0:e},tn=r=>_.dump(r,{schema:Ft,replacer:(e,t)=>{if(O(t)){if(K(t)){const n=new x(Number.MIN_SAFE_INTEGER.toString()),s=new x(Number.MAX_SAFE_INTEGER.toString());if(t.lt(n)||t.gt(s))return t.toString()}return t.toNumber()}return t}}),jt=`- type:
1
+ "use strict";var Ut=Object.defineProperty;var Lt=(n,e,t)=>e in n?Ut(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var h=(n,e,t)=>Lt(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@blue-labs/shared-utils"),c=require("zod"),_t=require("bs58"),x=require("big.js"),v=require("radash"),Jt=require("js-sha256"),kt=require("crypto"),Gt=require("base32.js"),_=require("js-yaml"),rt=n=>n&&n.__esModule?n:{default:n},oe=rt(_t),we=rt(kt);class Yt{static get(e,t,r,s=!0){if(u.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 a=e.getValue();return i&&a!==void 0?a:e}const o=t[r],l=this.getNodeForSegment(e,o,s,!0);if(l)return this.getRecursive(l,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 l=e.getName();i=u.isNonNullable(l)?new d().setValue(l):new d;break}case"description":{const l=e.getDescription();i=u.isNonNullable(l)?new d().setValue(l):new d;break}case"type":i=e.getType()??new d;break;case"itemType":i=e.getItemType()??new d;break;case"keyType":i=e.getKeyType()??new d;break;case"valueType":i=e.getValueType()??new d;break;case"value":{const l=e.getValue();i=new d().setValue(l??null);break}case"blueId":{const l=e.getBlueId();i=u.isNonNullable(l)?new d().setValue(l):new d;break}case"blue":i=e.getBlue();break;case"items":{const l=e.getItems();i=new d().setItems(l);break}case"properties":{const l=e.getProperties();i=new d().setProperties(l);break}case"contracts":{const l=e.getContracts();i=new d().setContracts(l);break}default:{if(/^\d+$/.test(t)){const l=parseInt(t,10),a=e.getItems();a&&l>=0&&l<a.length?i=a[l]:i=void 0}else i=void 0;break}}if(i)return s&&r?this.link(i,r):i}static link(e,t){const r=t(e);return u.isNonNullable(r)?r:e}}class P extends x{constructor(e){super(e)}}class C extends x{constructor(e){super(e)}}const k="name",G="description",pe="type",ze="itemType",Ze="keyType",Ue="valueType",Ie="value",Le="items",U="blueId",_e="blue",Te="contracts",Kt=[k,G,pe,ze,Ze,Ue,Ie,Le,U,_e,Te],Wt="Text",Ht="Double",qt="Integer",Xt="Boolean",Qt="List",en="Dictionary",Je=[Wt,Ht,qt,Xt],st=[...Je,Qt,en],H="F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP",q="68ryJtnmui4j5rCZWUnkZ3DChtmEb7Z9F8atn1mBSM3L",X="DHmxTkFbXePZHCHCYmQr2dSzcNLcryFVjXVHkdQrrZr8",Q="EL6AjrbJsxTWRTPzY8WR8Y2zAMXRbydQj83PcZwuAHbo",it="G8wmfjEqugPEEXByMYWJXiEdbLToPRWNQEekNxrxfQWB",ot="294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA",lt=[H,q,X,Q],ue=[...lt,it,ot];Object.fromEntries(st.map((n,e)=>[n,ue[e]]));const tn=Object.fromEntries(ue.map((n,e)=>[n,st[e]])),j=class j{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 j().setValue(e).setInlineValue(!0):this.type=e,this}getItemType(){return this.itemType}setItemType(e){return typeof e=="string"?this.itemType=new j().setValue(e).setInlineValue(!0):this.itemType=e,this}getKeyType(){return this.keyType}setKeyType(e){return typeof e=="string"?this.keyType=new j().setValue(e).setInlineValue(!0):this.keyType=e,this}getValueType(){return this.valueType}setValueType(e){return typeof e=="string"?this.valueType=new j().setValue(e).setInlineValue(!0):this.valueType=e,this}getValue(){var t;const e=(t=this.type)==null?void 0:t.getBlueId();if(u.isNonNullable(e)&&u.isNonNullable(this.value)){if(e===X&&typeof this.value=="string")return new P(this.value);if(e===q&&typeof this.value=="string"){const r=new C(this.value),s=parseFloat(r.toString());return new C(s.toString())}else if(e===Q&&typeof this.value=="string")return this.value.toLowerCase()==="true"}return this.value}setValue(e){return typeof e=="number"?e%1===0?this.value=new P(e.toString()):this.value=new C(e.toString()):this.value=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}addItems(...e){return this.items||(this.items=[]),this.items.push(...e),this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}addProperty(e,t){return this.properties||(this.properties={}),this.properties[e]=t,this}removeProperty(e){return this.properties&&delete this.properties[e],this}getContracts(){return this.contracts}setContracts(e){return this.contracts=e,this}addContract(e,t){return this.contracts||(this.contracts={}),this.contracts[e]=t,this}removeContract(e){return this.contracts&&delete this.contracts[e],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 Yt.get(this,e,t)}clone(){var t,r,s,i,o,l;const e=new j(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(a=>a.clone()),this.properties&&(e.properties=Object.fromEntries(Object.entries(this.properties).map(([a,f])=>[a,f.clone()]))),this.contracts&&(e.contracts=Object.fromEntries(Object.entries(this.contracts).map(([a,f])=>[a,f.clone()]))),e.blueId=this.blueId,e.blue=(l=this.blue)==null?void 0:l.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(j,"INTEGER",new j("Integer"));let d=j;class Z{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(oe.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(Z,"MIN_BLUE_ID_LENGTH",41),h(Z,"MAX_BLUE_ID_LENGTH",45),h(Z,"BLUE_ID_PATTERN",/^[1-9A-HJ-NP-Za-km-z]{41,45}(?:#\d+)?$/);const nn=c.z.string().max(Z.MAX_BLUE_ID_LENGTH,{message:"Blue Id has a maximum length of 45 characters"}).min(Z.MIN_BLUE_ID_LENGTH,{message:"Blue Id has a minimum length of 41 characters"}).refine(n=>{try{return oe.default.decode(n),!0}catch{return!1}},{message:"Blue Id must be a valid Base58 string"}),Y=c.z.lazy(()=>c.z.record(c.z.unknown()).and(c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:Y.optional(),value:c.z.union([c.z.string(),c.z.number(),c.z.boolean()]).optional().nullable(),items:c.z.array(Y).optional()}))),de=c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:Y.optional()}),rn=de.extend({value:c.z.string().optional()}),sn=de.extend({value:c.z.number().optional()}),on=de.extend({value:c.z.boolean().optional()}),ln=de.extend({items:c.z.array(c.z.string()).optional()}),cn=n=>Y.safeParse(n).success,ct=n=>u.isNonNullable(n)&&"blueId"in n&&u.isNonNullable(n.blueId),an=n=>u.isNonNullable(n)&&"name"in n&&u.isNonNullable(n.name),at=n=>u.isNonNullable(n)&&"items"in n&&u.isNonNullable(n.items),ut=n=>u.isNonNullable(n)&&"type"in n&&u.isNonNullable(n.type),dt=n=>u.isNonNullable(n)&&"value"in n&&u.isNonNullable(n.value),un=(n,e)=>n.required({type:!0}).safeParse(e).success,O=n=>n instanceof x,K=n=>O(n)&&n instanceof P,ht=n=>O(n)&&n instanceof C,dn=c.z.lazy(()=>c.z.record(le)),hn=c.z.lazy(()=>c.z.union([c.z.array(le),c.z.array(le).readonly()])),le=c.z.lazy(()=>c.z.union([u.jsonPrimitiveSchema,dn,hn,c.z.instanceof(x)])),ke=n=>v.isObject(n)&&!v.isArray(n)&&!u.isReadonlyArray(n)&&!O(n),Ge=n=>v.isArray(n)||u.isReadonlyArray(n),fn=n=>Ge(n)||ke(n)||O(n)||u.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(ke(e)){const t=new d,r={},s={};return Object.entries(e).forEach(([i,o])=>{switch(i){case k:if(o==null)t.setName(void 0);else{if(typeof o!="string")throw new Error(`The ${k} field must be a string.`);t.setName(o)}break;case G:if(o==null)t.setDescription(void 0);else{if(typeof o!="string")throw new Error(`The ${G} field must be a string.`);t.setDescription(o)}break;case pe:t.setType(p.handleNode(o));break;case ze:t.setItemType(p.handleNode(o));break;case Ze:t.setKeyType(p.handleNode(o));break;case Ue:t.setValueType(p.handleNode(o));break;case Ie: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 Le:t.setItems(p.handleArray(o));break;case _e:t.setBlue(p.handleNode(o));break;case Te:v.isObject(o)&&!v.isArray(o)&&!u.isReadonlyArray(o)&&Object.entries(o).forEach(([l,a])=>{s[l]=p.handleNode(a)});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(Ge(e))return new d().setItems(p.handleArray(e));{const t=e;return new d().setValue(p.handleValue(t)).setInlineValue(!0)}}}static handleValue(e){if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="number"||O(e))if(K(e)||Number.isSafeInteger(e)){const t=new P(e.toString()),r=Number.MIN_SAFE_INTEGER,s=Number.MAX_SAFE_INTEGER;return t.lt(r)?new P(r.toString()):t.gt(s)?new P(s.toString()):t}else{const t=parseFloat(e.toString());return new C(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(v.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 pn(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var ve,Qe;function yn(){return Qe||(Qe=1,ve=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])}`},"")}}`}),ve}var gn=yn();const mn=pn(gn);class ft{static canonicalize(e){return mn(e)}}const Ee=typeof process<"u"&&process.versions!=null&&process.versions.node!=null,ge=class ge{constructor(){h(this,"browserCrypto");this.browserCrypto=this.initBrowserCrypto()}static getInstance(){return this.instance||(this.instance=new ge),this.instance}initBrowserCrypto(){return Ee?null:"crypto"in globalThis?globalThis.crypto:null}hasNodeCrypto(){return Ee&&!!we.default&&typeof we.default.createHash=="function"}getBrowserCrypto(){return this.browserCrypto}getNodeCrypto(){return Ee?we.default:null}};h(ge,"instance");let Ve=ge;class pt{constructor(){h(this,"cryptoEnv",Ve.getInstance())}applySync(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):this.sha256SyncBrowser(t);return oe.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 oe.default.encode(new Uint8Array(r))}canonicalizeInput(e){const t=ft.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 Jt.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 y{static get(e,t="official"){var fe;const r=e.getValue(),s=this.handleValue(r);if(s!==void 0&&t==="simple")return s;const i=(fe=e.getItems())==null?void 0:fe.map(F=>y.get(F,t));if(i!==void 0&&t==="simple")return i;const o=e.getName(),l=e.getDescription();if(t==="original"&&o===void 0&&l===void 0){if(s!==void 0)return s;if(i!==void 0)return i}const a={};o!==void 0&&(a[k]=o),l!==void 0&&(a[G]=l);const f=e.getType();if(t==="official"&&r!==void 0&&f===void 0){const F=this.inferTypeBlueId(r);F!==null&&(a[pe]={[U]:F})}else f!==void 0&&(a[pe]=y.get(f,t));const I=e.getItemType();I!==void 0&&(a[ze]=y.get(I,t));const T=e.getKeyType();T!==void 0&&(a[Ze]=y.get(T,t));const b=e.getValueType();b!==void 0&&(a[Ue]=y.get(b,t)),s!==void 0&&(a[Ie]=s),i!==void 0&&(a[Le]=i);const m=e.getBlueId();m!==void 0&&(a[U]=m);const g=e.getBlue();g!==void 0&&(a[_e]=g);const B=e.getContracts();if(B!==void 0){const F={};Object.entries(B).forEach(([Be,Zt])=>{F[Be]=y.get(Zt,t)}),a[Te]=F}const D=e.getProperties();return D!==void 0&&Object.entries(D).forEach(([F,Be])=>{a[F]=y.get(Be,t)}),a}static handleValue(e){if(O(e)){if(K(e)){const t=new x(Number.MIN_SAFE_INTEGER.toString()),r=new x(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"?H:O(e)?K(e)?X:q:typeof e=="boolean"?Q:null}}const bn=n=>u.isJsonPrimitive(n)&&u.isNonNullable(n),M=class M{constructor(e){h(this,"hashProvider");this.hashProvider=e}static calculateBlueId(e){if(Array.isArray(e)){const r=e.map(s=>y.get(s));return M.INSTANCE.calculate(r)}const t=y.get(e);return M.INSTANCE.calculate(t)}static calculateBlueIdSync(e){if(Array.isArray(e)){const r=e.map(s=>y.get(s));return M.INSTANCE.calculateSync(r)}const t=y.get(e);return M.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 bn(e)||O(e)?this.applyHash(e.toString(),t):Array.isArray(e)||u.isReadonlyArray(e)?this.calculateList(e,t):this.calculateMap(e,t)}calculateMap(e,t){if(e[U]!==void 0)return e[U];const s=Object.keys(e).map(o=>{const l=e[o];if([k,Ie,G].includes(o))return t?[o,l]:Promise.resolve([o,l]);{const a=this.internalCalculate(l,t);return t?[o,{blueId:a}]:Promise.resolve(a).then(f=>[o,{blueId:f}])}}),i=o=>{const l={};for(const[a,f]of o)l[a]=f;return this.applyHash(l,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(([l,a])=>this.applyHash([{blueId:l},{blueId:a}],!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(u.isJsonPrimitive(e)||O(e))return e;if(Array.isArray(e)||u.isReadonlyArray(e)){const t=e.map(r=>this.cleanStructure(r)).filter(u.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(M,"INSTANCE",new M(new pt));let N=M;class In{static convert(e){const t=oe.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 Gt.Encoder({type:"rfc4648",lc:!0}).write(s).finalize().replace(/=/g,"")}}class V{static transform(e,t){const r=t(e.clone()),s=r.getType();s!==void 0&&r.setType(V.transform(s,t));const i=r.getItemType();i!==void 0&&r.setItemType(V.transform(i,t));const o=r.getKeyType();o!==void 0&&r.setKeyType(V.transform(o,t));const l=r.getValueType();l!==void 0&&r.setValueType(V.transform(l,t));const a=r.getItems();if(a!==void 0){const T=a.map(b=>V.transform(b,t));r.setItems(T)}const f=r.getProperties();if(f!==void 0){const T=Object.keys(f).reduce((b,m)=>(b[m]=V.transform(f[m],t),b),{});r.setProperties(T)}const I=r.getContracts();if(I!==void 0){const T=Object.keys(I).reduce((b,m)=>(b[m]=V.transform(I[m],t),b),{});r.setContracts(T)}return r}}const $=n=>!!n&&typeof n=="object"&&!Array.isArray(n)&&!(n instanceof d),R=n=>n instanceof P||n instanceof C,Tn=n=>n.replace(/~1/g,"/").replace(/~0/g,"~");function ee(n){if(n==="/")return[];if(!n.startsWith("/"))throw new Error(`Path must start with '/': ${n}`);return n.split("/").slice(1).map(Tn)}function W(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 yt(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 et(n,e,t=!0){if(n instanceof d){const r=yt(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=W(e);return r>=0&&r<n.length?n[r]:void 0}if($(n))return n[e]}function te(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=et(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 d){const s=et(t,r,!1);if((typeof s!="object"||s===null||R(s))&&!(s instanceof d)&&!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 d&&t.getItems()&&r==="-"?{parent:t,key:"-"}:{parent:t,key:Array.isArray(t)?W(r):r}}function Ye(n,e){var t;if(n instanceof d){const r=e,s=yt(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)||$(n)?n[e]:n}function w(n){if(n instanceof d)return n;if(n===null||typeof n=="string"||typeof n=="number"||typeof n=="boolean"||R(n))return p.deserialize(n);const e=De(n);return p.deserialize(e)}function De(n){if(n===void 0)return null;if(n===null||typeof n!="object")return n;if(Array.isArray(n))return n.map(De);const e={};for(const[t,r]of Object.entries(n))e[t]=De(r);return e}function Ke(n,e,t){if(n instanceof d){const r=e;switch(r){case"name":n.setName(t);return;case"description":n.setDescription(t);return;case"type":n.setType(t instanceof d||typeof t=="string"||t===void 0?t:w(t));return;case"itemType":n.setItemType(t instanceof d||typeof t=="string"||t===void 0?t:w(t));return;case"keyType":n.setKeyType(t instanceof d||typeof t=="string"||t===void 0?t:w(t));return;case"valueType":n.setValueType(t instanceof d||typeof t=="string"||t===void 0?t:w(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 d||t===void 0?t:w(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 d?t:w(t));return}}}Array.isArray(n)?n.splice(W(e),1):$(n)&&(t===void 0?delete n[e]:n[e]=t)}function Nn(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 ye(n,e,t,r){if(Array.isArray(n)){const s=e==="-"?n.length:W(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=w(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 d){e==="-"||typeof e=="number"&&!isNaN(e)||typeof e=="string"&&/^\d+$/.test(e)?Nn(n,e,w(t),r):Ke(n,e,t);return}if($(n)){n[e]=w(t);return}throw new Error(`Cannot insert into parent of type ${typeof n}`)}function Bn(n,e){if(Array.isArray(n)){const t=W(e);t===-1&&e==="-"?n.length>0&&n.pop():t>=0&&t<n.length&&n.splice(t,1);return}if(n instanceof d){if(typeof e=="number"||typeof e=="string"&&/^-?\d+$/.test(e)){const t=n.getItems();if(t){const r=W(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}}Ke(n,e,void 0)}else $(n)&&delete n[e]}function Fe(n){if(n instanceof d)return n.clone();if(Array.isArray(n))return n.map(t=>Fe(t));if($(n)){const e={};return Object.keys(n).forEach(t=>{e[t]=Fe(n[t])}),e}return n}function z(n,e){if(n===e||n instanceof d&&(n.isInlineValue()||n.getValue()!==void 0)&&z(n.getValue()??null,e)||e instanceof d&&(e.isInlineValue()||e.getValue()!==void 0)&&z(n,e.getValue()??null))return!0;if(n instanceof d&&e instanceof d||R(n)&&R(e)||R(n)&&typeof e=="number"||typeof n=="number"&&R(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($(n)&&$(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 gt(n,e){const{parent:t,key:r}=te(n,ee(e));return Ye(t,r)}function mt(n,e,t){const r=ee(e);if(r.length===0&&e==="/"){const o=w(t);n.setValue(o.getValue()??null),o.getItems()?n.setItems(o.getItems()):n.setItems(void 0);return}const{parent:s,key:i}=te(n,r);ye(s,i,t,!0)}function wn(n,e,t){const r=ee(e);if(r.length===0&&e==="/"){if(n.getItems()&&Array.isArray(t)){const o=w(t);o.getItems()?(n.setItems(o.getItems()),n.setValue(null)):(n.setValue(o.getValue()??null),n.setItems(void 0))}else{const o=w(t);n.setValue(o.getValue()??null),o.getItems()&&n.setItems(o.getItems())}return!0}const{parent:s,key:i}=te(n,r);return ye(s,i,t,!1),!0}function vn(n,e,t){const r=ee(e);if(r.length===0&&e==="/"){const l=w(t);return n.setValue(l.getValue()??null),l.getItems()?n.setItems(l.getItems()):n.setItems(void 0),!0}const{parent:s,key:i,actualTarget:o}=te(n,r);if(o!==void 0&&s instanceof d)Ke(s,i,t);else{const l=Ye(s,i),a=Array.isArray(s)||s instanceof d&&s.getItems()&&(typeof i=="number"||typeof i=="string"&&/^\d+$/.test(i));if(l===void 0){if(a)throw new Error(`REPLACE failed: Target array index '${i.toString()}' is out of bounds or does not exist at path '${e}'.`);ye(s,i,t,!0)}else ye(s,i,t,!0)}return!0}function bt(n,e){const t=ee(e);if(t.length===0&&e==="/")return n.setValue(null),n.setItems(void 0),n.setProperties(void 0),!0;const{parent:r,key:s}=te(n,t);return Bn(r,s),!0}function En(n,e,t){const r=Fe(gt(n,e));return mt(n,t,r),!0}function Sn(n,e,t){const r=ee(e),{parent:s,key:i}=te(n,r),o=Ye(s,i);if(o===void 0)throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);return bt(n,e)?(mt(n,t,o),!0):!1}function Pn(n,e,t){const r=gt(n,e);let s=t;if(r instanceof d)if((t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||R(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 d)&&(s=w(t));else if(R(r)&&typeof t=="number")r instanceof P?s=new P(t.toString()):r instanceof C&&(s=new C(t.toString()));else if((r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&R(t)){const i=t;!z(r,i.toString())&&(typeof r=="number"&&parseFloat(i.toString()))}if(!z(r,s)){const i=r instanceof d?r.toString():JSON.stringify(r),o=s instanceof d?s.toString():JSON.stringify(s);throw new Error(`TEST failed at '${e}': Expected ${o}, got ${i}`)}return!0}function An(n,e){switch(e.op){case"add":return wn(n,e.path,e.val);case"replace":return vn(n,e.path,e.val);case"remove":return bt(n,e.path);case"copy":return En(n,e.from,e.path);case"move":return Sn(n,e.from,e.path);case"test":return Pn(n,e.path,e.val)}}function Cn(n,e,t=!1){const r=t?n:n.clone();return An(r,e),r}const Se=Symbol.for("zod-schema-annotations");function On(){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 It(){const n=On();return Se in n||(n[Se]=new WeakMap),n[Se]}function ne(n,e){const t=It(),r=t.get(n)||{};return t.set(n,{...r,...e}),n}const A=n=>It().get(n),Tt=n=>e=>{const t=A(e);return ne(e,{...t,blueDescription:n})},Nt=n=>{const e=A(n);return u.isNonNullable(e)&&v.isString(e.blueDescription)?e.blueDescription:null},Vn=n=>Tt(n)(c.z.string().optional()),Dn=c.z.union([c.z.string(),c.z.boolean()]),Bt=n=>e=>{const t=A(e);return ne(e,{...t,blueId:n})},wt=n=>{const e=A(n),t=Dn.safeParse(e==null?void 0:e.blueId);return t.success?t.data:null},Fn=n=>Bt(n??!0)(c.z.string()),vt=n=>e=>{const t=A(e);return ne(e,{...t,blueName:n})},Et=n=>{const e=A(n);return u.isNonNullable(e)&&v.isString(e.blueName)?e.blueName:null},jn=n=>{const e=c.z.string().optional();return vt(n)(e)},St=()=>n=>{const e=A(n);return ne(n,{...e,blueNode:!0})},Pt=n=>{const e=A(n);return u.isNonNullable(e)&&u.isNonNullable(e.blueNode)&&e.blueNode===!0?e.blueNode:null},We=n=>!!Pt(n),Rn=()=>{const n=c.z.instanceof(d);return St()(n)},je="extendedFrom",At=({schema:n,baseSchema:e})=>{const t=A(n)||{};return ne(n,{...t,[je]:e})},Ct=n=>{const e=A(n);return u.isNonNullable(e)&&e[je]?e[je]:null},He=(n,e)=>{const t=Ct(n);return u.isNullable(t)?!1:(t==null?void 0:t._def)===(e==null?void 0:e._def)?!0:He(t,e)},Mn=n=>new Proxy(n,{get(e,t,r){return t==="extend"?function(...s){const i=e.extend(...s);return At({schema:i,baseSchema:e})}:Reflect.get(e,t,r)}}),xn=c.z.object({value:c.z.array(c.z.string()).optional(),defaultValue:c.z.string().optional()}),Ot=n=>{const e=A(n),t=xn.passthrough().safeParse(e==null?void 0:e.typeBlueId);return t.success?t.data:null},$n=n=>e=>{const t=A(e),r=typeof n=="string"?{value:[n]}:n,s=Mn(e);return ne(s,{...t,typeBlueId:{...(t==null?void 0:t.typeBlueId)||{},...r}})};class Ne{static resolveBlueId(e){var i;const t=Ot(e);if(u.isNullable(t))return null;const r=t.defaultValue;if(u.isNonNullable(r))return r;const s=(i=t.value)==null?void 0:i[0];return u.isNonNullable(s)?s:Ne.getRepositoryBlueId(t,e)}static getRepositoryBlueId(e,t){throw new Error("Not implemented")}}class S{static isTypeOf(e,t,r){var o;const s=Ne.resolveBlueId(t),i=(o=e.getType())==null?void 0:o.getBlueId();if(u.isNullable(s)||u.isNullable(i))return!1;if(s===i)return!0;if(r!=null&&r.checkSchemaExtensions&&u.isNonNullable(r.typeSchemaResolver)){const l=r.typeSchemaResolver.resolveSchema(e);return S.checkSchemaExtension(l,t)}return!1}static checkSchemaExtension(e,t){if(!u.isNonNullable(e))return!1;const r=S.unwrapSchema(e),s=S.unwrapSchema(t);return He(r,s)}static isWrapperType(e){return e instanceof c.ZodOptional||e instanceof c.ZodNullable||e instanceof c.ZodReadonly||e instanceof c.ZodBranded||e instanceof c.ZodEffects||e instanceof c.ZodLazy}static unwrapSchema(e){return We(e)?e:S.isWrapperType(e)?e instanceof c.ZodEffects?S.unwrapSchema(e.innerType()):e instanceof c.ZodLazy?S.unwrapSchema(e.schema):S.unwrapSchema(e.unwrap()):e}}class Vt{constructor(e){h(this,"blueIdMap",new Map);this.registerSchemas(e)}registerSchemas(e){for(const t of e)this.registerSchema(t)}registerSchema(e){const t=Ne.resolveBlueId(e);if(u.isNonNullable(t)){if(this.blueIdMap.has(t))throw new Error(`Duplicate BlueId value: ${t}`);this.blueIdMap.set(t,e)}}resolveSchema(e){const t=this.getEffectiveBlueId(e);return u.isNullable(t)?null:this.blueIdMap.get(t)}getEffectiveBlueId(e){const t=e.getType();return u.isNonNullable(t)&&u.isNonNullable(t.getBlueId())?t.getBlueId():u.isNonNullable(t)?N.calculateBlueIdSync(t):null}getBlueIdMap(){return new Map(this.blueIdMap)}}class Dt{static convertValue(e,t){var i;const r=(i=e.getType())==null?void 0:i.getBlueId(),s=e.getValue();return u.isNullable(s)?this.isPrimitive(t)?this.getDefaultPrimitiveValue(t):s:H===r?this.convertFromString(String(s),t):q===r||s instanceof C?this.convertFromBigDecimal(new C(s==null?void 0:s.toString()),t):X===r||s instanceof P?this.convertFromBigInteger(new P(s==null?void 0:s.toString()),t):Q===r||typeof s=="boolean"?this.convertFromBoolean(!!s,t):this.convertFromString(String(s),t)}static convertFromString(e,t){if(!t||t instanceof c.ZodString||t instanceof c.ZodEnum||t instanceof c.ZodNativeEnum)return e;if(t instanceof c.ZodNumber)return Number(e);if(t instanceof c.ZodBoolean)return e.toLowerCase()==="true";if(t instanceof c.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert String to ${t._def.typeName}`)}static convertFromBigDecimal(e,t){if(t instanceof c.ZodNumber)return e.toNumber();if(t instanceof c.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t._def.typeName}`)}static convertFromBigInteger(e,t){if(t instanceof c.ZodNumber)return e.toNumber();if(t instanceof c.ZodBigInt)return BigInt(e.toString());if(t instanceof c.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t._def.typeName}`)}static convertFromBoolean(e,t){if(!t||t instanceof c.ZodBoolean)return e;if(t instanceof c.ZodString)return e.toString();if(t instanceof c.ZodNumber)return Number(e);if(t instanceof c.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert Boolean to ${t._def.typeName}`)}static isPrimitive(e){return e?e instanceof c.ZodString||e instanceof c.ZodNumber||e instanceof c.ZodBoolean||e instanceof c.ZodBigInt:!1}static getDefaultPrimitiveValue(e){if(!e)return null;if(e instanceof c.ZodNumber)return 0;if(e instanceof c.ZodBoolean)return!1;if(e instanceof c.ZodString)return"";throw new Error(`Unsupported primitive type: ${e._def.typeName}`)}}class zn{convert(e,t){return Dt.convertValue(e,t)}}class Zn{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof c.ZodAny||e instanceof c.ZodObject||e instanceof c.ZodRecord||e instanceof c.ZodMap||e instanceof c.ZodUnknown}convert(e,t){return this.convertFields(e,t)}convertFields(e,t){if(t instanceof c.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 c.ZodUnion)throw new Error("Union not supported");if(t instanceof c.ZodObject)return Object.keys(t.shape).reduce((s,i)=>{const o=e.getProperties(),l=t.shape[i],a=wt(l);if(u.isNonNullable(a)){const g=v.isString(a)?a:i,B=o==null?void 0:o[g],D=B?N.calculateBlueIdSync(B):void 0;return s[i]=D,s}const f=Et(l);if(u.isNonNullable(f)){const g=o==null?void 0:o[f];return s[i]=g==null?void 0:g.getName(),s}const I=Nt(l);if(u.isNonNullable(I)){const g=o==null?void 0:o[I];return s[i]=g==null?void 0:g.getDescription(),s}if(i==="name"){const g=e.getName();return s[i]=g,s}if(i==="description"){const g=e.getDescription();return s[i]=g,s}const T=e.getContracts();if(i==="contracts"&&u.isNonNullable(T)&&this.canHandleStructuredData(l)){const g=Object.fromEntries(Object.entries(T).map(([D,fe])=>[D,y.get(fe)])),B=p.deserialize(g);s[i]=this.nodeToObjectConverter.convert(B,l)}const b=o==null?void 0:o[i];if(u.isNullable(b))return s;const m=this.nodeToObjectConverter.convert(b,l);return s[i]=m,s},{});throw new Error("Unknown schema type, "+t._def.typeName)}}class Un{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 Ln{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 _n{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof c.ZodAny||e instanceof c.ZodObject||e instanceof c.ZodRecord||e instanceof c.ZodMap||e instanceof c.ZodUnknown}convert(e,t){const r=t.keySchema,s=t.valueSchema,i=new Map,o=e.getName();u.isNonNullable(o)&&i.set(k,o);const l=e.getDescription();u.isNonNullable(l)&&i.set(G,l);const a=e.getContracts();if(u.isNonNullable(a)&&this.canHandleStructuredData(s)){let I=!1;const T=Object.entries(a).reduce((b,[m,g])=>{try{const B=this.nodeToObjectConverter.convert(g,s);B!=null&&!Number.isNaN(B)&&(b[m]=B,I=!0)}catch{}return b},{});I&&i.set(Te,T)}const f=e.getProperties();return u.isNonNullable(f)&&Object.entries(f).forEach(([I,T])=>{const b=new d().setValue(I);b.setType(new d().setBlueId(H));const m=Dt.convertValue(b,r),g=this.nodeToObjectConverter.convert(T,s);i.set(m,g)}),t instanceof c.ZodRecord?Object.fromEntries(i):i}}class Jn{convert(e){return y.get(e)}}class kn{convert(e){return y.get(e)}}class Gn{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t.items;return r.map((o,l)=>this.nodeToObjectConverter.convert(o,s[l]))}}const Yn=c.z.union([c.z.literal("ZodString"),c.z.literal("ZodNumber"),c.z.literal("ZodBoolean"),c.z.literal("ZodBigInt"),c.z.literal("ZodArray"),c.z.literal("ZodSet"),c.z.literal("ZodMap"),c.z.literal("ZodRecord"),c.z.literal("ZodObject"),c.z.literal("ZodEnum"),c.z.literal("ZodNativeEnum"),c.z.literal("ZodUnknown"),c.z.literal("ZodAny"),c.z.literal("ZodTuple")]);class Kn{constructor(e){h(this,"converters",new Map);h(this,"complexObjectConverter");this.nodeToObjectConverter=e,this.registerConverters(),this.complexObjectConverter=new Zn(this.nodeToObjectConverter)}registerConverters(){const e=new zn,t=new Un(this.nodeToObjectConverter),r=new Gn(this.nodeToObjectConverter),s=new Ln(this.nodeToObjectConverter),i=new _n(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 kn),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 c.ZodOptional||e instanceof c.ZodNullable||e instanceof c.ZodReadonly||e instanceof c.ZodBranded||e instanceof c.ZodEffects||e instanceof c.ZodLazy}getSchemaTypeName(e){if(this.isWrapperType(e))return e instanceof c.ZodEffects?this.getSchemaTypeName(e.innerType()):e instanceof c.ZodLazy?this.getSchemaTypeName(e.schema):this.getSchemaTypeName(e.unwrap());const t=e._def.typeName;try{return Yn.parse(t)}catch{throw new Error(`Schema type name ${t} is not supported`)}}}class Wn{constructor(e){h(this,"converterFactory");this.typeSchemaResolver=e,this.converterFactory=new Kn(this)}convert(e,t){var o;const r=(o=this.typeSchemaResolver)==null?void 0:o.resolveSchema(e),s=S.unwrapSchema(t);if(We(s))return e;let i=s;return S.checkSchemaExtension(r,s)&&u.isNonNullable(r)&&(i=r),this.convertWithType(e,i)}convertWithType(e,t){return this.converterFactory.getConverter(t).convert(e,t)}}class he{fetchFirstByBlueId(e){const t=this.fetchByBlueId(e);return t&&t.length>0?t[0]:null}}function Hn(n){return new class extends he{fetchByBlueId(e){return n(e)}}}class qn extends he{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 Pe=_.types.float.options,Xn={...Pe,construct:n=>{const e=n.replace(/_/g,"").toLowerCase();if(!u.isPreciseNumberString(e))return new C(e);if(Pe.construct)return Pe.construct(n)}},Qn=new _.Type("tag:yaml.org,2002:float",Xn),Ae=_.types.int.options,er={...Ae,construct:n=>{let e=n;if(e.indexOf("_")!==-1&&(e=e.replace(/_/g,"")),!u.isPreciseNumberString(e))return new P(e);if(Ae.construct)return Ae.construct(n)}},tr=new _.Type("tag:yaml.org,2002:int",er),Ft=_.CORE_SCHEMA.extend({implicit:[Qn,tr]}),L=n=>{const e=_.load(n,{schema:Ft});return e===void 0?void 0:e},nr=n=>_.dump(n,{schema:Ft,replacer:(e,t)=>{if(O(t)){if(K(t)){const r=new x(Number.MIN_SAFE_INTEGER.toString()),s=new x(Number.MAX_SAFE_INTEGER.toString());if(t.lt(r)||t.gt(s))return t.toString()}return t.toNumber()}return t}}),jt=`- 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
- `,rn=`name: Transformation
13
- description: TODO`,nn=`name: Infer Basic Types For Untyped Values
12
+ `,rr=`name: Transformation
13
+ description: TODO`,sr=`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.`,sn=`name: Replace Inline Types with BlueIds
16
+ description: This transformation infers type details for Text, Integer, Number and Boolean.`,ir=`name: Replace Inline Types with BlueIds
17
17
  type:
18
18
  blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
19
- description: This transformation replaces`,on=[jt,rn,nn,sn];class ln extends he{constructor(){super();h(this,"blueIdToNodesMap",new Map);this.load()}fetchByBlueId(t){return this.blueIdToNodesMap.get(t)||[]}load(){for(const t of on){const n=L(t);if(n===void 0){console.error(`This content file is not valid YAML: ${t}`);continue}if(Array.isArray(n)){const s=n.map(o=>p.deserialize(o)),i=N.calculateBlueIdSync(s);this.blueIdToNodesMap.set(i,s)}else{const s=p.deserialize(n),i=N.calculateBlueIdSync(s);this.blueIdToNodesMap.set(i,[s])}}}}const me=class me extends he{constructor(){super();h(this,"nodeProvider");this.nodeProvider=new ln}fetchByBlueId(t){return this.nodeProvider.fetchByBlueId(t)}};h(me,"INSTANCE",new me);let Re=me;class Ce{constructor(e,t,n){this.blueId=e,this.content=t,this.isMultipleDocuments=n}}class ne{static parseAndCalculateBlueId(e,t){let n;try{const l=L(e);if(l===void 0)throw new Error;n=l}catch{throw new Error("Failed to parse content as YAML or JSON")}let s,i;const o=Array.isArray(n)&&n.length>1;if(o){const l=n.map(a=>{const f=p.deserialize(a);return t(f)});s=N.calculateBlueIdSync(l),i=l.map(a=>y.get(a))}else{const l=p.deserialize(n),a=t(l);s=N.calculateBlueIdSync(a),i=y.get(a)}return new Ce(s,i,o)}static parseAndCalculateBlueIdForNode(e,t){const n=t(e),s=N.calculateBlueIdSync(n),i=y.get(n);return new Ce(s,i,!1)}static parseAndCalculateBlueIdForNodeList(e,t){if(!e||e.length===0)throw new Error("List of nodes cannot be null or empty");const n=e.map(t),s=N.calculateBlueIdSync(n),i=n.map(l=>y.get(l)),o=e.length>1;return new Ce(s,i,o)}static resolveThisReferences(e,t,n){return this.resolveThisReferencesRecursive(e,t,n)}static resolveThisReferencesRecursive(e,t,n){if(e&&typeof e=="object"&&!Array.isArray(e)){const s={};for(const[i,o]of Object.entries(e))typeof o=="string"?this.THIS_REFERENCE_PATTERN.test(o)?s[i]=this.resolveThisReference(o,t,n):s[i]=o:o&&typeof o=="object"?s[i]=this.resolveThisReferencesRecursive(o,t,n):s[i]=o;return s}else if(Array.isArray(e))return e.map(s=>typeof s=="string"?this.THIS_REFERENCE_PATTERN.test(s)?this.resolveThisReference(s,t,n):s:s&&typeof s=="object"?this.resolveThisReferencesRecursive(s,t,n):s);return e}static resolveThisReference(e,t,n){if(n){if(!e.startsWith("this#"))throw new Error("For multiple documents, 'this' references must include an index (e.g., 'this#0')");return t+e.substring(4)}else{if(e==="this")return t;throw new Error("For a single document, only 'this' is allowed as a reference, not 'this#<id>'")}}}h(ne,"THIS_REFERENCE_PATTERN",/^this(#\d+)?$/);class cn extends he{fetchByBlueId(e){const t=e.split("#")[0],n=this.fetchContentByBlueId(t);if(n==null)return null;const s=Array.isArray(n)&&n.length>1,i=ne.resolveThisReferences(n,t,s);if(e.includes("#")){const o=e.split("#");if(o.length>1){const l=parseInt(o[1]);if(Array.isArray(i)&&l<i.length){const a=i[l],f=p.deserialize(a);return f.setBlueId(e),[f]}else if(l===0){const a=p.deserialize(i);return a.setBlueId(e),[a]}else return null}}if(Array.isArray(i))return i.map(o=>p.deserialize(o));{const o=p.deserialize(i);return o.setBlueId(t),[o]}}}class an extends cn{constructor(){super(...arguments);h(this,"nameToBlueIdsMap",new Map)}findNodeByName(t){const n=this.nameToBlueIdsMap.get(t);if(!n)return;if(n.length>1)throw new Error(`Multiple nodes found with name: ${t}`);const s=this.fetchByBlueId(n[0]);return s&&s.length>0?s[0]:void 0}findAllNodesByName(t){const n=this.nameToBlueIdsMap.get(t);if(!n)return[];const s=[];for(const i of n){const o=this.fetchByBlueId(i);o&&s.push(...o)}return s}addToNameMap(t,n){this.nameToBlueIdsMap.set(t,[...this.nameToBlueIdsMap.get(t)||[],n])}}const Rt=r=>r instanceof u||Array.isArray(r)&&r.every(e=>e instanceof u)?r:v.isArray(r)?r.map(e=>p.deserialize(e)):p.deserialize(r),Mt=async r=>{const e=Rt(r);return N.calculateBlueId(e)},un=r=>{const e=Rt(r);return N.calculateBlueIdSync(e)},Me=async r=>{if(ct(r))return r;try{const e=le.parse(r),t=await Mt(e);return{...r,blueId:t}}catch(e){throw new Error(`Failed enriching object with Blue ID: ${e}`)}},dn=r=>r==null?void 0:r.items,hn=r=>r==null?void 0:r.value,fn=r=>d.isNullable(r)?{}:v.omit(r,Kt),pn=r=>ut(r)?r.type.name??null:dt(r)?v.pascal(typeof r.value):at(r)?"List":null,xt=r=>d.isNonNullable(r)&&Object.keys(v.omit(r,["blueId"])).length>0,yn=r=>{try{const e=p.deserialize(r),t=y.get(e);return Y.parse(t)}catch(e){throw new Error(`Failed transforming JSON-like value to BlueObject: ${e}`)}},xe=async r=>{const{resolveFunction:e,signal:t=new AbortController().signal,omitItems:n}=r,s=r.count??r.items.length;let i=await v.map(r.items,async l=>await Me(l));const o=Math.max((i==null?void 0:i.length)-s,0);for(let l=i.length-1;l>=o;l--)if(!xt(i[l])){const a=await e(i[l],{signal:t});if(Array.isArray(a))return xe({...r,items:[...i.slice(0,l),...a,...i.slice(l+1)]});const f=await Me(a);if(n!=null&&n.includes(f.blueId))return xe({...r,items:[...i.slice(0,l),...i.slice(l+1)]});i=[...i.slice(0,l),f,...i.slice(l+1)]}return i};function se(r){try{const e=new URL(r);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}class gn{process(e){return V.transform(e,this.inferType.bind(this))}inferType(e){const t=e.getType(),n=e.getValue();return d.isNullable(t)&&d.isNonNullable(n)&&(typeof n=="string"?e.setType(new u().setBlueId(H)):typeof n=="bigint"||K(n)?e.setType(new u().setBlueId(X)):ht(n)?e.setType(new u().setBlueId(q)):typeof n=="boolean"&&e.setType(new u().setBlueId(Q))),e}}const ie=class ie{constructor(e){h(this,"mappings",new Map);if(e instanceof u){const n=e.getProperties();if(n&&n[ie.MAPPINGS]){const i=n[ie.MAPPINGS].getProperties();i&&Object.entries(i).forEach(([o,l])=>{const a=l.getValue();typeof a=="string"&&this.mappings.set(o,a)})}}else this.mappings=e}process(e){return V.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 n=String(t.getValue());if(this.mappings.has(n)){const s=this.mappings.get(n);if(s){const i=new u().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(ie,"MAPPINGS","mappings");let $e=ie;class qe{constructor(e,t){h(this,"nodeProvider");h(this,"strategy");this.nodeProvider=ae.wrap(e),this.strategy=t||"THROW_EXCEPTION"}extend(e,t){this.extendNode(e,t,"")}extendNode(e,t,n,s=!1){if(!s){if(!t.shouldExtendPathSegment(n,e))return;t.enterPathSegment(n,e)}try{const i=e.getBlueId();if(i&&!ue.includes(i)){const m=this.fetchNode(e);if(m&&m.length>0)if(m.length===1){const g=m[0];this.mergeNodes(e,g)}else{const g=m.map(D=>D.clone()),B=new u().setItems(g);this.mergeNodes(e,B)}}const o=e.getType();o&&this.extendNode(o,t,"type",!0);const l=e.getItemType();l&&this.extendNode(l,t,"itemType",!0);const a=e.getKeyType();a&&this.extendNode(a,t,"keyType",!0);const f=e.getValueType();f&&this.extendNode(f,t,"valueType",!0);const I=e.getProperties();I&&Object.entries(I).forEach(([m,g])=>{this.extendNode(g,t,m,!1)});const T=e.getContracts();T&&Object.entries(T).forEach(([m,g])=>{this.extendNode(g,t,m,!1)});const b=e.getItems();if(b&&b.length>0){this.reconstructList(b);for(let m=0;m<b.length;m++)this.extendNode(b[m],t,String(m),!1)}}finally{s||t.exitPathSegment()}}reconstructList(e){for(;e.length>0;){const t=e[0],n=t==null?void 0:t.getBlueId();if(!n)break;const s=this.nodeProvider.fetchByBlueId(n);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 n=this.nodeProvider.fetchByBlueId(t);if(!n||n.length===0){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No content found for blueId: ${e.getBlueId()}`)}return n}mergeNodes(e,t){e.setName(t.getName()),e.setDescription(t.getDescription()),e.setType(t.getType()),e.setItemType(t.getItemType()),e.setKeyType(t.getKeyType()),e.setValueType(t.getValueType());const n=t.getValue();d.isNonNullable(n)&&e.setValue(n),e.setItems(t.getItems()),e.setProperties(t.getProperties()),e.setContracts(t.getContracts())}}class $t{}function tt(r,e){const t=r.split(e),n=[...t].reverse().findIndex(i=>i!==""),s=n===-1?0:t.length-n;return t.slice(0,s)}class Xe extends $t{constructor(t,n){super();h(this,"allowedPaths");h(this,"maxDepth");h(this,"currentPath",[]);this.allowedPaths=t,this.maxDepth=n}shouldExtendPathSegment(t){if(this.currentPath.length>=this.maxDepth)return!1;const n=this.normalizePath(this.getCurrentFullPath()+"/"+t);return this.isAllowedPath(n)}shouldMergePathSegment(t){return this.shouldExtendPathSegment(t)}isAllowedPath(t){for(const n of this.allowedPaths)if(this.matchesAllowedPath(n,t))return!0;return!1}matchesAllowedPath(t,n){const s=tt(t,"/"),i=tt(n,"/");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(n=>n!=="").join("/")}static withMaxDepth(t){return new rt().setMaxDepth(t).addPath("*").build()}static withSinglePath(t){return new rt().addPath(t).build()}}class rt{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 Xe(this.allowedPaths,this.maxDepth)}}class mn extends $t{shouldExtendPathSegment(){return!0}shouldMergePathSegment(){return!0}enterPathSegment(){}exitPathSegment(){}}const k=new mn;class zt{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 n=Object.entries(t).map(([s,i])=>` ${s}: ${i}`).join(`
19
+ description: This transformation replaces`,or=[jt,rr,sr,ir];class lr extends he{constructor(){super();h(this,"blueIdToNodesMap",new Map);this.load()}fetchByBlueId(t){return this.blueIdToNodesMap.get(t)||[]}load(){for(const t of or){const r=L(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=N.calculateBlueIdSync(s);this.blueIdToNodesMap.set(i,s)}else{const s=p.deserialize(r),i=N.calculateBlueIdSync(s);this.blueIdToNodesMap.set(i,[s])}}}}const me=class me extends he{constructor(){super();h(this,"nodeProvider");this.nodeProvider=new lr}fetchByBlueId(t){return this.nodeProvider.fetchByBlueId(t)}};h(me,"INSTANCE",new me);let Re=me;class Ce{constructor(e,t,r){this.blueId=e,this.content=t,this.isMultipleDocuments=r}}class re{static parseAndCalculateBlueId(e,t){let r;try{const l=L(e);if(l===void 0)throw new Error;r=l}catch{throw new Error("Failed to parse content as YAML or JSON")}let s,i;const o=Array.isArray(r)&&r.length>1;if(o){const l=r.map(a=>{const f=p.deserialize(a);return t(f)});s=N.calculateBlueIdSync(l),i=l.map(a=>y.get(a))}else{const l=p.deserialize(r),a=t(l);s=N.calculateBlueIdSync(a),i=y.get(a)}return new Ce(s,i,o)}static parseAndCalculateBlueIdForNode(e,t){const r=t(e),s=N.calculateBlueIdSync(r),i=y.get(r);return new Ce(s,i,!1)}static parseAndCalculateBlueIdForNodeList(e,t){if(!e||e.length===0)throw new Error("List of nodes cannot be null or empty");const r=e.map(t),s=N.calculateBlueIdSync(r),i=r.map(l=>y.get(l)),o=e.length>1;return new Ce(s,i,o)}static resolveThisReferences(e,t,r){return this.resolveThisReferencesRecursive(e,t,r)}static resolveThisReferencesRecursive(e,t,r){if(e&&typeof e=="object"&&!Array.isArray(e)){const s={};for(const[i,o]of Object.entries(e))typeof o=="string"?this.THIS_REFERENCE_PATTERN.test(o)?s[i]=this.resolveThisReference(o,t,r):s[i]=o:o&&typeof o=="object"?s[i]=this.resolveThisReferencesRecursive(o,t,r):s[i]=o;return s}else if(Array.isArray(e))return e.map(s=>typeof s=="string"?this.THIS_REFERENCE_PATTERN.test(s)?this.resolveThisReference(s,t,r):s:s&&typeof s=="object"?this.resolveThisReferencesRecursive(s,t,r):s);return e}static resolveThisReference(e,t,r){if(r){if(!e.startsWith("this#"))throw new Error("For multiple documents, 'this' references must include an index (e.g., 'this#0')");return t+e.substring(4)}else{if(e==="this")return t;throw new Error("For a single document, only 'this' is allowed as a reference, not 'this#<id>'")}}}h(re,"THIS_REFERENCE_PATTERN",/^this(#\d+)?$/);class cr extends he{fetchByBlueId(e){const t=e.split("#")[0],r=this.fetchContentByBlueId(t);if(r==null)return null;const s=Array.isArray(r)&&r.length>1,i=re.resolveThisReferences(r,t,s);if(e.includes("#")){const o=e.split("#");if(o.length>1){const l=parseInt(o[1]);if(Array.isArray(i)&&l<i.length){const a=i[l],f=p.deserialize(a);return f.setBlueId(e),[f]}else if(l===0){const a=p.deserialize(i);return a.setBlueId(e),[a]}else return null}}if(Array.isArray(i))return i.map(o=>p.deserialize(o));{const o=p.deserialize(i);return o.setBlueId(t),[o]}}}class ar extends cr{constructor(){super(...arguments);h(this,"nameToBlueIdsMap",new Map)}findNodeByName(t){const r=this.nameToBlueIdsMap.get(t);if(!r)return;if(r.length>1)throw new Error(`Multiple nodes found with name: ${t}`);const s=this.fetchByBlueId(r[0]);return s&&s.length>0?s[0]:void 0}findAllNodesByName(t){const r=this.nameToBlueIdsMap.get(t);if(!r)return[];const s=[];for(const i of r){const o=this.fetchByBlueId(i);o&&s.push(...o)}return s}addToNameMap(t,r){this.nameToBlueIdsMap.set(t,[...this.nameToBlueIdsMap.get(t)||[],r])}}const Rt=n=>n instanceof d||Array.isArray(n)&&n.every(e=>e instanceof d)?n:v.isArray(n)?n.map(e=>p.deserialize(e)):p.deserialize(n),Mt=async n=>{const e=Rt(n);return N.calculateBlueId(e)},ur=n=>{const e=Rt(n);return N.calculateBlueIdSync(e)},Me=async n=>{if(ct(n))return n;try{const e=le.parse(n),t=await Mt(e);return{...n,blueId:t}}catch(e){throw new Error(`Failed enriching object with Blue ID: ${e}`)}},dr=n=>n==null?void 0:n.items,hr=n=>n==null?void 0:n.value,fr=n=>u.isNullable(n)?{}:v.omit(n,Kt),pr=n=>ut(n)?n.type.name??null:dt(n)?v.pascal(typeof n.value):at(n)?"List":null,xt=n=>u.isNonNullable(n)&&Object.keys(v.omit(n,["blueId"])).length>0,yr=n=>{try{const e=p.deserialize(n),t=y.get(e);return Y.parse(t)}catch(e){throw new Error(`Failed transforming JSON-like value to BlueObject: ${e}`)}},xe=async n=>{const{resolveFunction:e,signal:t=new AbortController().signal,omitItems:r}=n,s=n.count??n.items.length;let i=await v.map(n.items,async l=>await Me(l));const o=Math.max((i==null?void 0:i.length)-s,0);for(let l=i.length-1;l>=o;l--)if(!xt(i[l])){const a=await e(i[l],{signal:t});if(Array.isArray(a))return xe({...n,items:[...i.slice(0,l),...a,...i.slice(l+1)]});const f=await Me(a);if(r!=null&&r.includes(f.blueId))return xe({...n,items:[...i.slice(0,l),...i.slice(l+1)]});i=[...i.slice(0,l),f,...i.slice(l+1)]}return i};function se(n){try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}class gr{process(e){return V.transform(e,this.inferType.bind(this))}inferType(e){const t=e.getType(),r=e.getValue();return u.isNullable(t)&&u.isNonNullable(r)&&(typeof r=="string"?e.setType(new d().setBlueId(H)):typeof r=="bigint"||K(r)?e.setType(new d().setBlueId(X)):ht(r)?e.setType(new d().setBlueId(q)):typeof r=="boolean"&&e.setType(new d().setBlueId(Q))),e}}const ie=class ie{constructor(e){h(this,"mappings",new Map);if(e instanceof d){const r=e.getProperties();if(r&&r[ie.MAPPINGS]){const i=r[ie.MAPPINGS].getProperties();i&&Object.entries(i).forEach(([o,l])=>{const a=l.getValue();typeof a=="string"&&this.mappings.set(o,a)})}}else this.mappings=e}process(e){return V.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 d().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(ie,"MAPPINGS","mappings");let $e=ie;class qe{constructor(e,t){h(this,"nodeProvider");h(this,"strategy");this.nodeProvider=ae.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&&!ue.includes(i)){const m=this.fetchNode(e);if(m&&m.length>0)if(m.length===1){const g=m[0];this.mergeNodes(e,g)}else{const g=m.map(D=>D.clone()),B=new d().setItems(g);this.mergeNodes(e,B)}}const o=e.getType();o&&this.extendNode(o,t,"type",!0);const l=e.getItemType();l&&this.extendNode(l,t,"itemType",!0);const a=e.getKeyType();a&&this.extendNode(a,t,"keyType",!0);const f=e.getValueType();f&&this.extendNode(f,t,"valueType",!0);const I=e.getProperties();I&&Object.entries(I).forEach(([m,g])=>{this.extendNode(g,t,m,!1)});const T=e.getContracts();T&&Object.entries(T).forEach(([m,g])=>{this.extendNode(g,t,m,!1)});const b=e.getItems();if(b&&b.length>0){this.reconstructList(b);for(let m=0;m<b.length;m++)this.extendNode(b[m],t,String(m),!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());const r=t.getValue();u.isNonNullable(r)&&e.setValue(r),e.setItems(t.getItems()),e.setProperties(t.getProperties()),e.setContracts(t.getContracts())}}class $t{}function tt(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 Xe extends $t{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=tt(t,"/"),i=tt(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 nt().setMaxDepth(t).addPath("*").build()}static withSinglePath(t){return new nt().addPath(t).build()}}class nt{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 Xe(this.allowedPaths,this.maxDepth)}}class mr extends $t{shouldExtendPathSegment(){return!0}shouldMergePathSegment(){return!0}enterPathSegment(){}exitPathSegment(){}}const J=new mr;class zt{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
- ${n}`}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 be=class be{constructor(e={}){h(this,"processorProvider");h(this,"nodeProvider");h(this,"defaultSimpleBlue",null);h(this,"blueIdsMappingGenerator");const{nodeProvider:t,processorProvider:n,blueIdsMappingGenerator:s}=e;if(!t)throw new Error("NodeProvider is required");this.nodeProvider=ae.wrap(t),this.processorProvider=n||be.getStandardProvider(),this.blueIdsMappingGenerator=s||new zt,this.loadDefaultSimpleBlue()}preprocess(e){return this.preprocessWithOptions(e,null)}preprocessWithDefaultBlue(e){return this.preprocessWithOptions(e,this.defaultSimpleBlue)}preprocessWithOptions(e,t){let n=e.clone(),s=n.getBlue();if(!s&&t&&(s=t.clone()),s){new qe(this.nodeProvider).extend(s,Xe.withSinglePath("/*"));const i=s.getItems();if(i&&i.length>0){for(const o of i){const l=this.processorProvider.getProcessor(o);if(l)n=l.process(n);else throw new Error(`No processor found for transformation: ${o}`)}n.setBlue(void 0)}}return n}static getStandardProvider(){return{getProcessor(e){var i;const t="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo",n="FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4",s=(i=e.getType())==null?void 0:i.getBlueId();if(t===s)return new $e(e);if(n===s)return new gn}}}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 be=class be{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=ae.wrap(t),this.processorProvider=r||be.getStandardProvider(),this.blueIdsMappingGenerator=s||new zt,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 qe(this.nodeProvider).extend(s,Xe.withSinglePath("/*"));const i=s.getItems();if(i&&i.length>0){for(const o of i){const l=this.processorProvider.getProcessor(o);if(l)r=l.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 $e(e);if(r===s)return new gr}}}enrichDefaultBlue(e){const t=this.blueIdsMappingGenerator.generateMappingsYaml();return`
24
24
  ${e}
25
25
  ${t}
26
- `}loadDefaultSimpleBlue(){const e=this.enrichDefaultBlue(jt);try{const t=L(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(be,"DEFAULT_BLUE_BLUE_ID","FREHAAGDZSzpnoTUoCQ86bBmxbVCULMjvx9JZM6fyqT1");let ce=be;class bn extends an{constructor(t){super();h(this,"blueIdToContentMap",new Map);h(this,"blueIdToMultipleDocumentsMap",new Map);h(this,"preprocessor");const n=new ce({nodeProvider:this});this.preprocessor=s=>n.preprocessWithDefaultBlue(s),this.loadRepositories(t)}loadRepositories(t){for(const n of t)if(n.contents)for(const[s,i]of Object.entries(n.contents))this.processContent(i,s)}processContent(t,n){Array.isArray(t)?this.processMultipleDocuments(t,n):this.processSingleDocument(t,n)}processSingleDocument(t,n){const s=p.deserialize(t),i=ne.parseAndCalculateBlueIdForNode(s,this.preprocessor),o=n||i.blueId;this.blueIdToContentMap.set(o,i.content),this.blueIdToMultipleDocumentsMap.set(o,!1);const l=s.getName();l&&this.addToNameMap(l,o)}processMultipleDocuments(t,n){const s=t.map(l=>{const a=p.deserialize(l);return this.preprocessor(a)}),i=ne.parseAndCalculateBlueIdForNodeList(s,l=>l),o=n||i.blueId;this.blueIdToContentMap.set(o,i.content),this.blueIdToMultipleDocumentsMap.set(o,!0),s.forEach((l,a)=>{const f=`${o}#${a}`,I=y.get(l),T=N.calculateBlueIdSync(l);this.blueIdToContentMap.set(T,I),this.blueIdToMultipleDocumentsMap.set(T,!1);const b=l.getName();b&&this.addToNameMap(b,f)})}fetchContentByBlueId(t){const n=this.blueIdToContentMap.get(t),s=this.blueIdToMultipleDocumentsMap.get(t);return n!==void 0&&s!==void 0?ne.resolveThisReferences(n,t,s):null}getBlueIds(){return Array.from(this.blueIdToContentMap.keys())}hasBlueId(t){const n=t.split("#")[0];return this.blueIdToContentMap.has(n)}}class ae{static wrap(e,t){const n=[Re.INSTANCE];if(t&&t.length>0){const s=new bn(t);n.push(s)}return n.push(e),new Hr(n)}}class In{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 n=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(n,t);if(Z.isPotentialBlueId(t))return this.handleBlueId(n,t);throw se(t)?new Error(`URL '${t}' detected. Use the async version of this method to fetch the content.`):new Error(`Invalid blue value: ${t}`)}return e}async processAsync(e){const t=this.getBlueNodeValue(e);if(t){const n=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(n,t);if(Z.isPotentialBlueId(t))return this.handleBlueId(n,t);if(se(t)&&this.urlContentFetcher)try{const s=await this.fetchFromUrl(t);return s&&n.setBlue(new u().setItems(s)),n}catch(s){throw s instanceof Error?new Error(`Failed to fetch from URL '${t}'.
27
- ${s.message}`):s}else throw se(t)?new Error(`UrlContentFetcher not provided for URL: ${t}`):new Error(`Invalid blue value: ${t}`)}return e}getBlueNodeValue(e){const t=e.getBlue(),n=t==null?void 0:t.getValue();return n&&typeof n=="string"?n:null}handleAliasValue(e,t){return e.setBlue(new u().setBlueId(this.preprocessingAliases.get(t))),e}handleBlueId(e,t){return e.setBlue(new u().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,n)=>{this.preprocessingAliases.set(n,t)}),this}setUrlContentFetcher(e){return this.urlContentFetcher=e,this}getUrlContentFetcher(){return this.urlContentFetcher}}const Tn={fetchUrl:async r=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${r}`)}};class Nn{constructor(e){h(this,"cache",new Map);h(this,"fetchStrategy");h(this,"enabled",!1);h(this,"allowedDomains",[]);this.fetchStrategy=e||Tn}validateUrl(e){if(!se(e))throw new Error(`Invalid URL: ${e}`);return!0}isDomainAllowed(e){if(this.allowedDomains.length===0)return!0;try{const t=new URL(e);return this.allowedDomains.some(n=>t.hostname===n||t.hostname.endsWith(`.${n}`))}catch{return!1}}getFromCache(e){try{return this.validateUrl(e),this.cache.get(e)||[]}catch{return[]}}async fetchAndCache(e){if(this.validateUrl(e),!this.enabled)throw new Error("URL fetching is disabled. Enable it using the enableFetching method.");if(!this.isDomainAllowed(e))throw new Error(`Domain not allowed for URL: ${e}.`);let t;try{t=await this.fetchStrategy.fetchUrl(e)}catch(l){throw new Error(`Error fetching from URL: ${e}`,{cause:l})}const{data:n,contentType:s}=t;let i;if(s.includes("application/json")||s.includes("text/yaml")||s.includes("application/yaml")||s.includes("text/plain"))i=L(n);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(l=>p.deserialize(l)):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 Bn{resolveWithoutLimits(e){return this.resolve(e,k)}}class wn extends Bn{constructor(t,n){super();h(this,"mergingProcessor");h(this,"nodeProvider");this.mergingProcessor=t,this.nodeProvider=ae.wrap(n)}merge(t,n,s){if(d.isNonNullable(n.getBlue()))throw new Error('Document contains "blue" attribute. Preprocess document before merging.');const i=n.getType();if(d.isNonNullable(i)){d.isNonNullable(i.getBlueId())&&new qe(this.nodeProvider).extend(i,Xe.withSinglePath("/"));const o=this.resolve(i,s);n.setType(o),this.merge(t,i,s)}this.mergeObject(t,n,s)}mergeObject(t,n,s){this.mergingProcessor.process(t,n,this.nodeProvider,this);const i=n.getItems();d.isNonNullable(i)&&this.mergeChildren(t,i,s);const o=n.getProperties();d.isNonNullable(o)&&Object.entries(o).forEach(([l,a])=>{s.shouldMergePathSegment(l,a)&&(s.enterPathSegment(l,a),this.mergeProperty(t,l,a,s),s.exitPathSegment())}),d.isNonNullable(n.getBlueId())&&t.setBlueId(n.getBlueId()),this.mergingProcessor.postProcess&&this.mergingProcessor.postProcess(t,n,this.nodeProvider,this)}mergeChildren(t,n,s){const i=t.getItems();if(d.isNullable(i)){const o=n.filter((l,a)=>s.shouldMergePathSegment(String(a),t)).map(l=>{s.enterPathSegment(String(n.indexOf(l)),t);const a=this.resolve(l,s);return s.exitPathSegment(),a});t.setItems(o);return}else if(n.length<i.length)throw new Error(`Subtype of element must not have more items (${i.length}) than the element itself (${n.length}).`);for(let o=0;o<n.length;o++){if(!s.shouldMergePathSegment(String(o),n[o]))continue;if(s.enterPathSegment(String(o),n[o]),o>=i.length){i.push(n[o]),s.exitPathSegment();continue}const l=N.calculateBlueIdSync(n[o]),a=N.calculateBlueIdSync(i[o]);if(l!==a)throw new Error(`Mismatched items at index ${o}: source item has blueId '${l}', but target item has blueId '${a}'.`);s.exitPathSegment()}}mergeProperty(t,n,s,i){const o=this.resolve(s,i);d.isNullable(t.getProperties())&&t.setProperties({});const l=t.getProperties()[n];l===void 0?t.getProperties()[n]=o:this.mergeObject(l,o,i)}resolve(t,n){const s=new u;return this.merge(s,t,n),s.setName(t.getName()),s.setDescription(t.getDescription()),s.setBlueId(t.getBlueId()),s}}class vn{constructor(e){h(this,"mergingProcessors");this.mergingProcessors=e}process(e,t,n,s){this.mergingProcessors.forEach(i=>i.process(e,t,n,s))}postProcess(e,t,n,s){this.mergingProcessors.forEach(i=>{i.postProcess&&i.postProcess(e,t,n,s)})}}class En{process(e,t){const n=t.getValue();if(d.isNonNullable(n)){const s=e.getValue();if(d.isNullable(s))e.setValue(n);else if(n!==s)throw new Error(`Node values conflict. Source node value: ${n}, target node value: ${s}`)}}}function Oe(r,e){const t=r.getType();if(t===void 0)return;const n=t.getBlueId();if(n!==void 0){if(ue.includes(n)){const i=tr[n];return new u().setBlueId(n).setName(i)}const s=e.fetchByBlueId(n);if(!s||s.length===0)return;if(s.length>1)throw new Error(`Expected a single node for type with blueId '${n}', but found multiple.`);return s[0]}return t}function E(r,e,t){const n=N.calculateBlueIdSync(r),s=N.calculateBlueIdSync(e);if(n===s)return!0;if(n&&ue.includes(n)){let o=e;for(;o!==void 0;){if(N.calculateBlueIdSync(o)===n)return!0;o=Oe(o,t)}return!1}let i=Oe(r,t);for(;i!==void 0;){if(N.calculateBlueIdSync(i)===s)return!0;i=Oe(i,t)}return!1}function Sn(r,e){return lt.some(t=>{const n=new u().setBlueId(t);return E(r,n,e)})}function Pn(r,e){const t=new u().setBlueId(H);return E(r,t,e)}function An(r,e){const t=new u().setBlueId(X);return E(r,t,e)}function Cn(r,e){const t=new u().setBlueId(q);return E(r,t,e)}function On(r,e){const t=new u().setBlueId(Q);return E(r,t,e)}function Vn(r){return(r==null?void 0:r.getBlueId())===it}function Dn(r){return(r==null?void 0:r.getBlueId())===ot}function Fn(r,e){return ke.some(t=>{const n=new u().setName(t);return E(r,n,e)})}function jn(r,e){for(const t of ke){const n=new u().setName(t);if(E(r,n,e))return t}throw new Error(`Cannot determine the basic type for node of type "${r.getName()||"unknown"}".`)}class Rn{process(e,t,n){const s=e.getType(),i=t.getType();if(s===void 0)e.setType(i);else if(i!==void 0){if(!E(i,s,n)){const l=y.get(i),a=y.get(s);throw new Error(`The source type '${JSON.stringify(l)}' is not a subtype of the target type '${JSON.stringify(a)}'.`)}e.setType(i)}}}class Mn{process(e,t,n){if(t.getItemType()!==void 0&&!Vn(t.getType()))throw new Error("Source node with itemType must have a List type");const s=e.getItemType(),i=t.getItemType();if(s===void 0)i!==void 0&&e.setItemType(i);else if(i!==void 0){if(!E(i,s,n)){const f=y.get(i),I=y.get(s);throw new Error(`The source item type '${JSON.stringify(f)}' is not a subtype of the target item type '${JSON.stringify(I)}'.`)}e.setItemType(i)}const o=e.getItemType(),l=t.getItems();if(o!==void 0&&l!==void 0)for(const a of l){const f=a.getType();if(f!==void 0&&!E(f,o,n)){const I=y.get(f),T=y.get(o);throw new Error(`Item of type '${JSON.stringify(I)}' is not a subtype of the list's item type '${JSON.stringify(T)}'.`)}}}}class xn{process(e,t,n){if((t.getKeyType()!==void 0||t.getValueType()!==void 0)&&!Dn(t.getType()))throw new Error("Source node with keyType or valueType must have a Dictionary type");this.processKeyType(e,t,n),this.processValueType(e,t,n);const s=e.getKeyType(),i=e.getValueType(),o=t.getProperties();(s!==void 0||i!==void 0)&&o!==void 0&&Object.entries(o).forEach(([l,a])=>{s!==void 0&&this.validateKeyType(l,s,n),i!==void 0&&this.validateValueType(a,i,n)})}processKeyType(e,t,n){const s=e.getKeyType(),i=t.getKeyType();if(s===void 0)i!==void 0&&(this.validateBasicKeyType(i,n),e.setKeyType(i));else if(i!==void 0){if(this.validateBasicKeyType(i,n),!E(i,s,n)){const l=y.get(i),a=y.get(s);throw new Error(`The source key type '${JSON.stringify(l)}' is not a subtype of the target key type '${JSON.stringify(a)}'.`)}e.setKeyType(i)}}processValueType(e,t,n){const s=e.getValueType(),i=t.getValueType();if(s===void 0)i!==void 0&&e.setValueType(i);else if(i!==void 0){if(!E(i,s,n)){const l=y.get(i),a=y.get(s);throw new Error(`The source value type '${JSON.stringify(l)}' is not a subtype of the target value type '${JSON.stringify(a)}'.`)}e.setValueType(i)}}validateBasicKeyType(e,t){if(!Sn(e,t))throw new Error("Dictionary key type must be a basic type")}validateKeyType(e,t,n){if(!Pn(t,n))if(An(t,n)){const s=Number.parseInt(e,10);if(Number.isNaN(s)||s.toString()!==e)throw new Error(`Key '${e}' is not a valid Integer.`)}else if(Cn(t,n)){const s=Number.parseFloat(e);if(Number.isNaN(s))throw new Error(`Key '${e}' is not a valid Number.`)}else if(On(t,n)){if(e.toLowerCase()!=="true"&&e.toLowerCase()!=="false")throw new Error(`Key '${e}' is not a valid Boolean.`)}else throw new Error(`Unsupported key type: ${t.getName()||"unknown"}`)}validateValueType(e,t,n){const s=e.getType();if(s!==void 0&&!E(s,t,n)){const i=y.get(s),o=y.get(t);throw new Error(`Value of type '${JSON.stringify(i)}' is not a subtype of the dictionary's value type '${JSON.stringify(o)}'.`)}}}class $n{process(){}postProcess(e,t,n){const s=e.getType();if(s!==void 0&&Fn(s,n)){const i=e.getItems(),o=e.getProperties();if(i!==void 0&&i.length>0||o!==void 0&&Object.keys(o).length>0){const l=jn(s,n),a=s.getName()||"unknown";throw new Error(`Node of type "${a}" (which extends basic type "${l}") must not have items or properties.`)}}}}function zn(){return new vn([new En,new Rn,new Mn,new xn,new $n])}class Zn{constructor(e={}){h(this,"nodeProvider");h(this,"typeSchemaResolver");h(this,"blueDirectivePreprocessor");h(this,"urlContentFetcher");h(this,"blueIdsMappingGenerator");h(this,"globalLimits",k);h(this,"mergingProcessor");h(this,"repositories");h(this,"prepareForBlueIdCalculation",async e=>e instanceof u||Array.isArray(e)&&e.every(t=>t instanceof u)?e:Array.isArray(e)?await Promise.all(e.map(n=>this.jsonValueToNodeAsync(n))):this.jsonValueToNodeAsync(e));h(this,"calculateBlueId",async e=>{const t=await this.prepareForBlueIdCalculation(e);return N.calculateBlueId(t)});h(this,"prepareForBlueIdCalculationSync",e=>e instanceof u||Array.isArray(e)&&e.every(t=>t instanceof u)?e:Array.isArray(e)?e.map(t=>this.jsonValueToNode(t)):this.jsonValueToNode(e));var a;const{nodeProvider:t,typeSchemaResolver:n=null,urlFetchStrategy:s,repositories:i,mergingProcessor:o}=e;this.repositories=i;const l=Wr(()=>[]);if(this.nodeProvider=ae.wrap(t||l,i),this.typeSchemaResolver=n??new Vt([]),this.mergingProcessor=o??zn(),this.urlContentFetcher=new Nn(s),this.blueDirectivePreprocessor=new In(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new zt,i)for(const{schemas:f,blueIds:I}of i)(a=this.typeSchemaResolver)==null||a.registerSchemas(f),this.blueIdsMappingGenerator.registerBlueIds(I)}nodeToJson(e,t="official"){return y.get(e,t)}nodeToSchemaOutput(e,t){return new Kr(this.typeSchemaResolver).convert(e,t)}resolve(e,t=k){const n=this.combineWithGlobalLimits(t);return new wn(this.mergingProcessor,this.nodeProvider).resolve(e,n)}extend(e,t){const n=this.combineWithGlobalLimits(t);new qe(this.nodeProvider).extend(e,n)}jsonValueToNode(e){return this.preprocess(p.deserialize(e))}async jsonValueToNodeAsync(e){return this.preprocessAsync(p.deserialize(e))}yamlToNode(e){const t=L(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=L(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return N.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new ce({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new ce({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=ae.wrap(e,this.repositories),this}getTypeSchemaResolver(){return this.typeSchemaResolver}setTypeSchemaResolver(e){return this.typeSchemaResolver=e,this}getUrlContentFetcher(){return this.urlContentFetcher}setUrlFetchStrategy(e){return this.urlContentFetcher.setFetchStrategy(e),this}enablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.enableFetching(),this}enablePreprocessingDirectivesFetchForDomains(e){return this.urlContentFetcher.enableFetchingForDomains(e),this}allowUrlFetchingForDomain(e){return this.urlContentFetcher.allowDomain(e),this}disallowUrlFetchingForDomain(e){return this.urlContentFetcher.disallowDomain(e),this}getAllowedUrlFetchingDomains(){return this.urlContentFetcher.getAllowedDomains()}disablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.disableFetching(),this}isPreprocessingDirectivesFetchForUrlsEnabled(){return this.urlContentFetcher.isFetchingEnabled()}getPreprocessingAliases(){return this.blueDirectivePreprocessor.getPreprocessingAliases()}setPreprocessingAliases(e){return this.blueDirectivePreprocessor.setPreprocessingAliases(e),this}registerBlueIds(...e){return this.blueIdsMappingGenerator.registerBlueIds(...e),this}getAllRegisteredBlueIds(){return this.blueIdsMappingGenerator.getAllBlueIds()}getAllBlueIdNames(){return this.blueIdsMappingGenerator.getAllBlueIdNames()}getBlueIdsMappingGenerator(){return this.blueIdsMappingGenerator}isTypeOf(e,t,n){return S.isTypeOf(e,t,{checkSchemaExtensions:n==null?void 0:n.checkSchemaExtensions,typeSchemaResolver:this.typeSchemaResolver})}combineWithGlobalLimits(e){return this.globalLimits==k?e:e==k?this.globalLimits:k}}exports.Base58Sha256Provider=pt;exports.Blue=Zn;exports.BlueIdCalculator=N;exports.BlueIdToCid=br;exports.BlueNode=u;exports.BlueNodeTypeSchema=S;exports.JsonCanonicalizer=ft;exports.TypeSchemaResolver=Vt;exports.applyBlueNodePatch=Ar;exports.baseBlueObjectSchema=de;exports.blueDescriptionField=Or;exports.blueIdField=Dr;exports.blueIdSchema=rr;exports.blueNameField=Fr;exports.blueNodeField=jr;exports.blueObjectBooleanValueSchema=ir;exports.blueObjectNumberValueSchema=sr;exports.blueObjectSchema=Y;exports.blueObjectStringListItemsSchema=or;exports.blueObjectStringValueSchema=nr;exports.calculateBlueId=Mt;exports.calculateBlueIdSync=un;exports.enrichWithBlueId=Me;exports.getBlueDescriptionAnnotation=Nt;exports.getBlueIdAnnotation=wt;exports.getBlueNameAnnotation=Et;exports.getBlueNodeAnnotation=Pt;exports.getBlueObjectItems=dn;exports.getBlueObjectProperties=fn;exports.getBlueObjectTypeLabel=pn;exports.getBlueObjectValue=hn;exports.getExtendedFromSchemaAnnotation=Ct;exports.getTypeBlueIdAnnotation=Ot;exports.hasBlueObjectBlueIdDefined=ct;exports.hasBlueObjectItemsDefined=at;exports.hasBlueObjectNameDefined=cr;exports.hasBlueObjectTypeDefined=ut;exports.hasBlueObjectValueDefined=dt;exports.isBigDecimalNumber=ht;exports.isBigIntegerNumber=K;exports.isBigNumber=O;exports.isBlueNodeSchema=We;exports.isBlueObject=lr;exports.isBlueObjectResolved=xt;exports.isGivenBlueObjectTypeSchema=ar;exports.isJsonBlueArray=Ge;exports.isJsonBlueObject=Je;exports.isJsonBlueValue=hr;exports.isSchemaExtendedFrom=He;exports.isUrl=se;exports.jsonBlueValueSchema=le;exports.normalizeToBlueObject=yn;exports.resolveBlueObjectItems=xe;exports.withBlueDescription=Tt;exports.withBlueId=Bt;exports.withBlueName=vt;exports.withBlueNode=St;exports.withExtendedFromSchema=At;exports.withTypeBlueId=xr;exports.yamlBlueDump=tn;exports.yamlBlueParse=L;
26
+ `}loadDefaultSimpleBlue(){const e=this.enrichDefaultBlue(jt);try{const t=L(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(be,"DEFAULT_BLUE_BLUE_ID","FREHAAGDZSzpnoTUoCQ86bBmxbVCULMjvx9JZM6fyqT1");let ce=be;class br extends ar{constructor(t){super();h(this,"blueIdToContentMap",new Map);h(this,"blueIdToMultipleDocumentsMap",new Map);h(this,"preprocessor");const r=new ce({nodeProvider:this});this.preprocessor=s=>r.preprocessWithDefaultBlue(s),this.loadRepositories(t)}loadRepositories(t){for(const r of t)if(r.contents)for(const[s,i]of Object.entries(r.contents))this.processContent(i,s)}processContent(t,r){Array.isArray(t)?this.processMultipleDocuments(t,r):this.processSingleDocument(t,r)}processSingleDocument(t,r){const s=p.deserialize(t),i=re.parseAndCalculateBlueIdForNode(s,this.preprocessor),o=r||i.blueId;this.blueIdToContentMap.set(o,i.content),this.blueIdToMultipleDocumentsMap.set(o,!1);const l=s.getName();l&&this.addToNameMap(l,o)}processMultipleDocuments(t,r){const s=t.map(l=>{const a=p.deserialize(l);return this.preprocessor(a)}),i=re.parseAndCalculateBlueIdForNodeList(s,l=>l),o=r||i.blueId;this.blueIdToContentMap.set(o,i.content),this.blueIdToMultipleDocumentsMap.set(o,!0),s.forEach((l,a)=>{const f=`${o}#${a}`,I=y.get(l),T=N.calculateBlueIdSync(l);this.blueIdToContentMap.set(T,I),this.blueIdToMultipleDocumentsMap.set(T,!1);const b=l.getName();b&&this.addToNameMap(b,f)})}fetchContentByBlueId(t){const r=this.blueIdToContentMap.get(t),s=this.blueIdToMultipleDocumentsMap.get(t);return r!==void 0&&s!==void 0?re.resolveThisReferences(r,t,s):null}getBlueIds(){return Array.from(this.blueIdToContentMap.keys())}hasBlueId(t){const r=t.split("#")[0];return this.blueIdToContentMap.has(r)}}class ae{static wrap(e,t){const r=[Re.INSTANCE];if(t&&t.length>0){const s=new br(t);r.push(s)}return r.push(e),new qn(r)}}class Ir{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(Z.isPotentialBlueId(t))return this.handleBlueId(r,t);throw se(t)?new Error(`URL '${t}' detected. Use the async version of this method to fetch the content.`):new Error(`Invalid blue value: ${t}`)}return e}async processAsync(e){const t=this.getBlueNodeValue(e);if(t){const r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(Z.isPotentialBlueId(t))return this.handleBlueId(r,t);if(se(t)&&this.urlContentFetcher)try{const s=await this.fetchFromUrl(t);return s&&r.setBlue(new d().setItems(s)),r}catch(s){throw s instanceof Error?new Error(`Failed to fetch from URL '${t}'.
27
+ ${s.message}`):s}else throw se(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 d().setBlueId(this.preprocessingAliases.get(t))),e}handleBlueId(e,t){return e.setBlue(new d().setBlueId(t)),e}async fetchFromUrl(e){if(!this.urlContentFetcher)throw new Error(`UrlContentFetcher not provided for URL: ${e}`);return await this.urlContentFetcher.fetchAndCache(e)}getPreprocessingAliases(){return new Map(this.preprocessingAliases)}setPreprocessingAliases(e){return this.preprocessingAliases=new Map(e),this}addPreprocessingAliases(e){return e.forEach((t,r)=>{this.preprocessingAliases.set(r,t)}),this}setUrlContentFetcher(e){return this.urlContentFetcher=e,this}getUrlContentFetcher(){return this.urlContentFetcher}}const Tr={fetchUrl:async n=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${n}`)}};class Nr{constructor(e){h(this,"cache",new Map);h(this,"fetchStrategy");h(this,"enabled",!1);h(this,"allowedDomains",[]);this.fetchStrategy=e||Tr}validateUrl(e){if(!se(e))throw new Error(`Invalid URL: ${e}`);return!0}isDomainAllowed(e){if(this.allowedDomains.length===0)return!0;try{const t=new URL(e);return this.allowedDomains.some(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(l){throw new Error(`Error fetching from URL: ${e}`,{cause:l})}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=L(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(l=>p.deserialize(l)):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 Br{resolveWithoutLimits(e){return this.resolve(e,J)}}class wr extends Br{constructor(t,r){super();h(this,"mergingProcessor");h(this,"nodeProvider");this.mergingProcessor=t,this.nodeProvider=ae.wrap(r)}merge(t,r,s){if(u.isNonNullable(r.getBlue()))throw new Error('Document contains "blue" attribute. Preprocess document before merging.');const i=r.getType();if(u.isNonNullable(i)){u.isNonNullable(i.getBlueId())&&new qe(this.nodeProvider).extend(i,Xe.withSinglePath("/"));const o=this.resolve(i,s);r.setType(o),this.merge(t,i,s)}this.mergeObject(t,r,s)}mergeObject(t,r,s){this.mergingProcessor.process(t,r,this.nodeProvider,this);const i=r.getItems();u.isNonNullable(i)&&this.mergeChildren(t,i,s);const o=r.getProperties();u.isNonNullable(o)&&Object.entries(o).forEach(([a,f])=>{s.shouldMergePathSegment(a,f)&&(s.enterPathSegment(a,f),this.mergeProperty(t,a,f,s),s.exitPathSegment())});const l=r.getContracts();u.isNonNullable(l)&&Object.entries(l).forEach(([a,f])=>{s.shouldMergePathSegment(a,f)&&(s.enterPathSegment(a,f),this.mergeContract(t,a,f,s),s.exitPathSegment())}),u.isNonNullable(r.getBlueId())&&t.setBlueId(r.getBlueId()),this.mergingProcessor.postProcess&&this.mergingProcessor.postProcess(t,r,this.nodeProvider,this)}mergeChildren(t,r,s){const i=t.getItems();if(u.isNullable(i)){const o=r.filter((l,a)=>s.shouldMergePathSegment(String(a),t)).map(l=>{s.enterPathSegment(String(r.indexOf(l)),t);const a=this.resolve(l,s);return s.exitPathSegment(),a});t.setItems(o);return}else if(r.length<i.length)throw new Error(`Subtype of element must not have more items (${i.length}) than the element itself (${r.length}).`);for(let o=0;o<r.length;o++){if(!s.shouldMergePathSegment(String(o),r[o]))continue;if(s.enterPathSegment(String(o),r[o]),o>=i.length){i.push(r[o]),s.exitPathSegment();continue}const l=N.calculateBlueIdSync(r[o]),a=N.calculateBlueIdSync(i[o]);if(l!==a)throw new Error(`Mismatched items at index ${o}: source item has blueId '${l}', but target item has blueId '${a}'.`);s.exitPathSegment()}}mergeProperty(t,r,s,i){const o=this.resolve(s,i);u.isNullable(t.getProperties())&&t.setProperties({});const l=t.getProperties()[r];l===void 0?t.getProperties()[r]=o:this.mergeObject(l,o,i)}mergeContract(t,r,s,i){const o=this.resolve(s,i);u.isNullable(t.getContracts())&&t.setContracts({});const l=t.getContracts()[r];l===void 0?t.getContracts()[r]=o:this.mergeObject(l,o,i)}resolve(t,r){const s=new d;return this.merge(s,t,r),s.setName(t.getName()),s.setDescription(t.getDescription()),s.setBlueId(t.getBlueId()),s}}class vr{constructor(e){h(this,"mergingProcessors");this.mergingProcessors=e}process(e,t,r,s){this.mergingProcessors.forEach(i=>i.process(e,t,r,s))}postProcess(e,t,r,s){this.mergingProcessors.forEach(i=>{i.postProcess&&i.postProcess(e,t,r,s)})}}class Er{process(e,t){const r=t.getValue();if(u.isNonNullable(r)){const s=e.getValue();if(u.isNullable(s))e.setValue(r);else if(r!==s)throw new Error(`Node values conflict. Source node value: ${r}, target node value: ${s}`)}}}function Oe(n,e){const t=n.getType();if(t===void 0)return;const r=t.getBlueId();if(r!==void 0){if(ue.includes(r)){const i=tn[r];return new d().setBlueId(r).setName(i)}const s=e.fetchByBlueId(r);if(!s||s.length===0)return;if(s.length>1)throw new Error(`Expected a single node for type with blueId '${r}', but found multiple.`);return s[0]}return t}function E(n,e,t){const r=N.calculateBlueIdSync(n),s=N.calculateBlueIdSync(e);if(r===s)return!0;if(r&&ue.includes(r)){let o=e;for(;o!==void 0;){if(N.calculateBlueIdSync(o)===r)return!0;o=Oe(o,t)}return!1}let i=Oe(n,t);for(;i!==void 0;){if(N.calculateBlueIdSync(i)===s)return!0;i=Oe(i,t)}return!1}function Sr(n,e){return lt.some(t=>{const r=new d().setBlueId(t);return E(n,r,e)})}function Pr(n,e){const t=new d().setBlueId(H);return E(n,t,e)}function Ar(n,e){const t=new d().setBlueId(X);return E(n,t,e)}function Cr(n,e){const t=new d().setBlueId(q);return E(n,t,e)}function Or(n,e){const t=new d().setBlueId(Q);return E(n,t,e)}function Vr(n){return(n==null?void 0:n.getBlueId())===it}function Dr(n){return(n==null?void 0:n.getBlueId())===ot}function Fr(n,e){return Je.some(t=>{const r=new d().setName(t);return E(n,r,e)})}function jr(n,e){for(const t of Je){const r=new d().setName(t);if(E(n,r,e))return t}throw new Error(`Cannot determine the basic type for node of type "${n.getName()||"unknown"}".`)}class Rr{process(e,t,r){const s=e.getType(),i=t.getType();if(s===void 0)e.setType(i);else if(i!==void 0){if(!E(i,s,r)){const l=y.get(i),a=y.get(s);throw new Error(`The source type '${JSON.stringify(l)}' is not a subtype of the target type '${JSON.stringify(a)}'.`)}e.setType(i)}}}class Mr{process(e,t,r){if(t.getItemType()!==void 0&&!Vr(t.getType()))throw new Error("Source node with itemType must have a List type");const s=e.getItemType(),i=t.getItemType();if(s===void 0)i!==void 0&&e.setItemType(i);else if(i!==void 0){if(!E(i,s,r)){const f=y.get(i),I=y.get(s);throw new Error(`The source item type '${JSON.stringify(f)}' is not a subtype of the target item type '${JSON.stringify(I)}'.`)}e.setItemType(i)}const o=e.getItemType(),l=t.getItems();if(o!==void 0&&l!==void 0)for(const a of l){const f=a.getType();if(f!==void 0&&!E(f,o,r)){const I=y.get(f),T=y.get(o);throw new Error(`Item of type '${JSON.stringify(I)}' is not a subtype of the list's item type '${JSON.stringify(T)}'.`)}}}}class xr{process(e,t,r){if((t.getKeyType()!==void 0||t.getValueType()!==void 0)&&!Dr(t.getType()))throw new Error("Source node with keyType or valueType must have a Dictionary type");this.processKeyType(e,t,r),this.processValueType(e,t,r);const s=e.getKeyType(),i=e.getValueType(),o=t.getProperties();(s!==void 0||i!==void 0)&&o!==void 0&&Object.entries(o).forEach(([l,a])=>{s!==void 0&&this.validateKeyType(l,s,r),i!==void 0&&this.validateValueType(a,i,r)})}processKeyType(e,t,r){const s=e.getKeyType(),i=t.getKeyType();if(s===void 0)i!==void 0&&(this.validateBasicKeyType(i,r),e.setKeyType(i));else if(i!==void 0){if(this.validateBasicKeyType(i,r),!E(i,s,r)){const l=y.get(i),a=y.get(s);throw new Error(`The source key type '${JSON.stringify(l)}' is not a subtype of the target key type '${JSON.stringify(a)}'.`)}e.setKeyType(i)}}processValueType(e,t,r){const s=e.getValueType(),i=t.getValueType();if(s===void 0)i!==void 0&&e.setValueType(i);else if(i!==void 0){if(!E(i,s,r)){const l=y.get(i),a=y.get(s);throw new Error(`The source value type '${JSON.stringify(l)}' is not a subtype of the target value type '${JSON.stringify(a)}'.`)}e.setValueType(i)}}validateBasicKeyType(e,t){if(!Sr(e,t))throw new Error("Dictionary key type must be a basic type")}validateKeyType(e,t,r){if(!Pr(t,r))if(Ar(t,r)){const s=Number.parseInt(e,10);if(Number.isNaN(s)||s.toString()!==e)throw new Error(`Key '${e}' is not a valid Integer.`)}else if(Cr(t,r)){const s=Number.parseFloat(e);if(Number.isNaN(s))throw new Error(`Key '${e}' is not a valid Number.`)}else if(Or(t,r)){if(e.toLowerCase()!=="true"&&e.toLowerCase()!=="false")throw new Error(`Key '${e}' is not a valid Boolean.`)}else throw new Error(`Unsupported key type: ${t.getName()||"unknown"}`)}validateValueType(e,t,r){const s=e.getType();if(s!==void 0&&!E(s,t,r)){const i=y.get(s),o=y.get(t);throw new Error(`Value of type '${JSON.stringify(i)}' is not a subtype of the dictionary's value type '${JSON.stringify(o)}'.`)}}}class $r{process(){}postProcess(e,t,r){const s=e.getType();if(s!==void 0&&Fr(s,r)){const i=e.getItems(),o=e.getProperties(),l=e.getContracts();if(i!==void 0&&i.length>0||o!==void 0&&Object.keys(o).length>0||l!==void 0&&Object.keys(l).length>0){const a=jr(s,r),f=s.getName()||"unknown";throw new Error(`Node of type "${f}" (which extends basic type "${a}") must not have items, properties or contracts.`)}}}}function zr(){return new vr([new Er,new Rr,new Mr,new xr,new $r])}class Zr{constructor(e={}){h(this,"nodeProvider");h(this,"typeSchemaResolver");h(this,"blueDirectivePreprocessor");h(this,"urlContentFetcher");h(this,"blueIdsMappingGenerator");h(this,"globalLimits",J);h(this,"mergingProcessor");h(this,"repositories");h(this,"prepareForBlueIdCalculation",async e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?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 N.calculateBlueId(t)});h(this,"prepareForBlueIdCalculationSync",e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?e.map(t=>this.jsonValueToNode(t)):this.jsonValueToNode(e));var a;const{nodeProvider:t,typeSchemaResolver:r=null,urlFetchStrategy:s,repositories:i,mergingProcessor:o}=e;this.repositories=i;const l=Hn(()=>[]);if(this.nodeProvider=ae.wrap(t||l,i),this.typeSchemaResolver=r??new Vt([]),this.mergingProcessor=o??zr(),this.urlContentFetcher=new Nr(s),this.blueDirectivePreprocessor=new Ir(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new zt,i)for(const{schemas:f,blueIds:I}of i)(a=this.typeSchemaResolver)==null||a.registerSchemas(f),this.blueIdsMappingGenerator.registerBlueIds(I)}nodeToJson(e,t="official"){return y.get(e,t)}nodeToSchemaOutput(e,t){return new Wn(this.typeSchemaResolver).convert(e,t)}resolve(e,t=J){const r=this.combineWithGlobalLimits(t);return new wr(this.mergingProcessor,this.nodeProvider).resolve(e,r)}extend(e,t){const r=this.combineWithGlobalLimits(t);new qe(this.nodeProvider).extend(e,r)}jsonValueToNode(e){return this.preprocess(p.deserialize(e))}async jsonValueToNodeAsync(e){return this.preprocessAsync(p.deserialize(e))}yamlToNode(e){const t=L(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=L(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return N.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new ce({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new ce({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=ae.wrap(e,this.repositories),this}getTypeSchemaResolver(){return this.typeSchemaResolver}setTypeSchemaResolver(e){return this.typeSchemaResolver=e,this}getUrlContentFetcher(){return this.urlContentFetcher}setUrlFetchStrategy(e){return this.urlContentFetcher.setFetchStrategy(e),this}enablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.enableFetching(),this}enablePreprocessingDirectivesFetchForDomains(e){return this.urlContentFetcher.enableFetchingForDomains(e),this}allowUrlFetchingForDomain(e){return this.urlContentFetcher.allowDomain(e),this}disallowUrlFetchingForDomain(e){return this.urlContentFetcher.disallowDomain(e),this}getAllowedUrlFetchingDomains(){return this.urlContentFetcher.getAllowedDomains()}disablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.disableFetching(),this}isPreprocessingDirectivesFetchForUrlsEnabled(){return this.urlContentFetcher.isFetchingEnabled()}getPreprocessingAliases(){return this.blueDirectivePreprocessor.getPreprocessingAliases()}setPreprocessingAliases(e){return this.blueDirectivePreprocessor.setPreprocessingAliases(e),this}registerBlueIds(...e){return this.blueIdsMappingGenerator.registerBlueIds(...e),this}getAllRegisteredBlueIds(){return this.blueIdsMappingGenerator.getAllBlueIds()}getAllBlueIdNames(){return this.blueIdsMappingGenerator.getAllBlueIdNames()}getBlueIdsMappingGenerator(){return this.blueIdsMappingGenerator}isTypeOf(e,t,r){return S.isTypeOf(e,t,{checkSchemaExtensions:r==null?void 0:r.checkSchemaExtensions,typeSchemaResolver:this.typeSchemaResolver})}combineWithGlobalLimits(e){return this.globalLimits==J?e:e==J?this.globalLimits:J}}exports.Base58Sha256Provider=pt;exports.Blue=Zr;exports.BlueIdCalculator=N;exports.BlueIdToCid=In;exports.BlueNode=d;exports.BlueNodeTypeSchema=S;exports.JsonCanonicalizer=ft;exports.TypeSchemaResolver=Vt;exports.applyBlueNodePatch=Cn;exports.baseBlueObjectSchema=de;exports.blueDescriptionField=Vn;exports.blueIdField=Fn;exports.blueIdSchema=nn;exports.blueNameField=jn;exports.blueNodeField=Rn;exports.blueObjectBooleanValueSchema=on;exports.blueObjectNumberValueSchema=sn;exports.blueObjectSchema=Y;exports.blueObjectStringListItemsSchema=ln;exports.blueObjectStringValueSchema=rn;exports.calculateBlueId=Mt;exports.calculateBlueIdSync=ur;exports.enrichWithBlueId=Me;exports.getBlueDescriptionAnnotation=Nt;exports.getBlueIdAnnotation=wt;exports.getBlueNameAnnotation=Et;exports.getBlueNodeAnnotation=Pt;exports.getBlueObjectItems=dr;exports.getBlueObjectProperties=fr;exports.getBlueObjectTypeLabel=pr;exports.getBlueObjectValue=hr;exports.getExtendedFromSchemaAnnotation=Ct;exports.getTypeBlueIdAnnotation=Ot;exports.hasBlueObjectBlueIdDefined=ct;exports.hasBlueObjectItemsDefined=at;exports.hasBlueObjectNameDefined=an;exports.hasBlueObjectTypeDefined=ut;exports.hasBlueObjectValueDefined=dt;exports.isBigDecimalNumber=ht;exports.isBigIntegerNumber=K;exports.isBigNumber=O;exports.isBlueNodeSchema=We;exports.isBlueObject=cn;exports.isBlueObjectResolved=xt;exports.isGivenBlueObjectTypeSchema=un;exports.isJsonBlueArray=Ge;exports.isJsonBlueObject=ke;exports.isJsonBlueValue=fn;exports.isSchemaExtendedFrom=He;exports.isUrl=se;exports.jsonBlueValueSchema=le;exports.normalizeToBlueObject=yr;exports.resolveBlueObjectItems=xe;exports.withBlueDescription=Tt;exports.withBlueId=Bt;exports.withBlueName=vt;exports.withBlueNode=St;exports.withExtendedFromSchema=At;exports.withTypeBlueId=$n;exports.yamlBlueDump=nr;exports.yamlBlueParse=L;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  var _t = Object.defineProperty;
2
2
  var Zt = (r, e, t) => e in r ? _t(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
3
  var u = (r, e, t) => Zt(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { isNullable as N, isNonNullable as f, jsonPrimitiveSchema as kt, isReadonlyArray as ie, isJsonPrimitive as Ke, isPreciseNumberString as ft } from "@blue-labs/shared-utils";
4
+ import { isNullable as E, isNonNullable as h, jsonPrimitiveSchema as kt, isReadonlyArray as ie, isJsonPrimitive as Ke, isPreciseNumberString as ft } from "@blue-labs/shared-utils";
5
5
  import { z as d, ZodOptional as ht, ZodNullable as pt, ZodReadonly as yt, ZodBranded as gt, ZodEffects as me, ZodLazy as Ie, ZodString as k, ZodEnum as Jt, ZodNativeEnum as Gt, ZodNumber as J, ZodBoolean as pe, ZodBigInt as ye, ZodAny as mt, ZodObject as Ue, ZodRecord as Le, ZodMap as It, ZodUnknown as Tt, ZodIntersection as Yt, ZodUnion as zt } from "zod";
6
6
  import oe from "bs58";
7
7
  import x from "big.js";
@@ -12,7 +12,7 @@ import Xt from "base32.js";
12
12
  import Z from "js-yaml";
13
13
  class qt {
14
14
  static get(e, t, n, s = !0) {
15
- if (N(t) || !t.startsWith("/"))
15
+ if (E(t) || !t.startsWith("/"))
16
16
  throw new Error(`Invalid path: ${t}`);
17
17
  if (t === "/") {
18
18
  const o = e.getValue();
@@ -63,12 +63,12 @@ class qt {
63
63
  switch (t) {
64
64
  case "name": {
65
65
  const c = e.getName();
66
- i = f(c) ? new a().setValue(c) : new a();
66
+ i = h(c) ? new a().setValue(c) : new a();
67
67
  break;
68
68
  }
69
69
  case "description": {
70
70
  const c = e.getDescription();
71
- i = f(c) ? new a().setValue(c) : new a();
71
+ i = h(c) ? new a().setValue(c) : new a();
72
72
  break;
73
73
  }
74
74
  case "type":
@@ -90,7 +90,7 @@ class qt {
90
90
  }
91
91
  case "blueId": {
92
92
  const c = e.getBlueId();
93
- i = f(c) ? new a().setValue(c) : new a();
93
+ i = h(c) ? new a().setValue(c) : new a();
94
94
  break;
95
95
  }
96
96
  case "blue":
@@ -125,7 +125,7 @@ class qt {
125
125
  }
126
126
  static link(e, t) {
127
127
  const n = t(e);
128
- return f(n) ? n : e;
128
+ return h(n) ? n : e;
129
129
  }
130
130
  }
131
131
  class S extends x {
@@ -226,7 +226,7 @@ const or = Object.fromEntries(
226
226
  getValue() {
227
227
  var t;
228
228
  const e = (t = this.type) == null ? void 0 : t.getBlueId();
229
- if (f(e) && f(this.value)) {
229
+ if (h(e) && h(this.value)) {
230
230
  if (e === q && typeof this.value == "string")
231
231
  return new S(this.value);
232
232
  if (e === X && typeof this.value == "string") {
@@ -298,9 +298,9 @@ const or = Object.fromEntries(
298
298
  var t, n, s, i, o, c;
299
299
  const e = new R(this.name);
300
300
  return e.description = this.description, e.type = (t = this.type) == null ? void 0 : t.clone(), e.itemType = (n = this.itemType) == null ? void 0 : n.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((l) => l.clone()), this.properties && (e.properties = Object.fromEntries(
301
- Object.entries(this.properties).map(([l, h]) => [l, h.clone()])
301
+ Object.entries(this.properties).map(([l, f]) => [l, f.clone()])
302
302
  )), this.contracts && (e.contracts = Object.fromEntries(
303
- Object.entries(this.contracts).map(([l, h]) => [l, h.clone()])
303
+ Object.entries(this.contracts).map(([l, f]) => [l, f.clone()])
304
304
  )), e.blueId = this.blueId, e.blue = (c = this.blue) == null ? void 0 : c.clone(), e.inlineValue = this.inlineValue, e;
305
305
  }
306
306
  toString() {
@@ -372,7 +372,7 @@ const Qn = d.string().max(L.MAX_BLUE_ID_LENGTH, {
372
372
  value: d.boolean().optional()
373
373
  }), ns = Ae.extend({
374
374
  items: d.array(d.string()).optional()
375
- }), ss = (r) => ce.safeParse(r).success, cr = (r) => f(r) && "blueId" in r && f(r.blueId), is = (r) => f(r) && "name" in r && f(r.name), lr = (r) => f(r) && "items" in r && f(r.items), ar = (r) => f(r) && "type" in r && f(r.type), ur = (r) => f(r) && "value" in r && f(r.value), os = (r, e) => r.required({ type: !0 }).safeParse(e).success, O = (r) => r instanceof x, le = (r) => O(r) && r instanceof S, dr = (r) => O(r) && r instanceof C, fr = d.lazy(
375
+ }), ss = (r) => ce.safeParse(r).success, cr = (r) => h(r) && "blueId" in r && h(r.blueId), is = (r) => h(r) && "name" in r && h(r.name), lr = (r) => h(r) && "items" in r && h(r.items), ar = (r) => h(r) && "type" in r && h(r.type), ur = (r) => h(r) && "value" in r && h(r.value), os = (r, e) => r.required({ type: !0 }).safeParse(e).success, O = (r) => r instanceof x, le = (r) => O(r) && r instanceof S, dr = (r) => O(r) && r instanceof C, fr = d.lazy(
376
376
  () => d.record(be)
377
377
  ), hr = d.lazy(
378
378
  () => d.union([
@@ -607,11 +607,11 @@ class y {
607
607
  }
608
608
  const l = {};
609
609
  o !== void 0 && (l[Y] = o), c !== void 0 && (l[z] = c);
610
- const h = e.getType();
611
- if (t === "official" && n !== void 0 && h === void 0) {
610
+ const f = e.getType();
611
+ if (t === "official" && n !== void 0 && f === void 0) {
612
612
  const F = this.inferTypeBlueId(n);
613
613
  F !== null && (l[Te] = { [_]: F });
614
- } else h !== void 0 && (l[Te] = y.get(h, t));
614
+ } else f !== void 0 && (l[Te] = y.get(f, t));
615
615
  const T = e.getItemType();
616
616
  T !== void 0 && (l[He] = y.get(T, t));
617
617
  const b = e.getKeyType();
@@ -649,7 +649,7 @@ class y {
649
649
  return typeof e == "string" ? H : O(e) ? le(e) ? q : X : typeof e == "boolean" ? Q : null;
650
650
  }
651
651
  }
652
- const br = (r) => Ke(r) && f(r), j = class j {
652
+ const br = (r) => Ke(r) && h(r), j = class j {
653
653
  constructor(e) {
654
654
  u(this, "hashProvider");
655
655
  this.hashProvider = e;
@@ -703,15 +703,15 @@ const br = (r) => Ke(r) && f(r), j = class j {
703
703
  return t ? [o, c] : Promise.resolve([o, c]);
704
704
  {
705
705
  const l = this.internalCalculate(c, t);
706
- return t ? [o, { blueId: l }] : Promise.resolve(l).then((h) => [
706
+ return t ? [o, { blueId: l }] : Promise.resolve(l).then((f) => [
707
707
  o,
708
- { blueId: h }
708
+ { blueId: f }
709
709
  ]);
710
710
  }
711
711
  }), i = (o) => {
712
712
  const c = {};
713
- for (const [l, h] of o)
714
- c[l] = h;
713
+ for (const [l, f] of o)
714
+ c[l] = f;
715
715
  return this.applyHash(c, t);
716
716
  };
717
717
  return t ? i(s) : Promise.all(s).then(i);
@@ -745,7 +745,7 @@ const br = (r) => Ke(r) && f(r), j = class j {
745
745
  if (Ke(e) || O(e))
746
746
  return e;
747
747
  if (Array.isArray(e) || ie(e)) {
748
- const t = e.map((n) => this.cleanStructure(n)).filter(f);
748
+ const t = e.map((n) => this.cleanStructure(n)).filter(h);
749
749
  return t.length > 0 ? t : void 0;
750
750
  } else if (typeof e == "object") {
751
751
  const t = {};
@@ -798,10 +798,10 @@ class V {
798
798
  );
799
799
  n.setItems(b);
800
800
  }
801
- const h = n.getProperties();
802
- if (h !== void 0) {
803
- const b = Object.keys(h).reduce(
804
- (I, m) => (I[m] = V.transform(h[m], t), I),
801
+ const f = n.getProperties();
802
+ if (f !== void 0) {
803
+ const b = Object.keys(f).reduce(
804
+ (I, m) => (I[m] = V.transform(f[m], t), I),
805
805
  {}
806
806
  );
807
807
  n.setProperties(b);
@@ -1274,7 +1274,7 @@ const P = (r) => Ot().get(r), Or = (r) => (e) => {
1274
1274
  });
1275
1275
  }, Dr = (r) => {
1276
1276
  const e = P(r);
1277
- return f(e) && We(e.blueDescription) ? e.blueDescription : null;
1277
+ return h(e) && We(e.blueDescription) ? e.blueDescription : null;
1278
1278
  }, us = (r) => Or(r)(d.string().optional()), Fr = d.union([d.string(), d.boolean()]), Rr = (r) => (e) => {
1279
1279
  const t = P(e);
1280
1280
  return re(e, {
@@ -1292,7 +1292,7 @@ const P = (r) => Ot().get(r), Or = (r) => (e) => {
1292
1292
  });
1293
1293
  }, xr = (r) => {
1294
1294
  const e = P(r);
1295
- return f(e) && We(e.blueName) ? e.blueName : null;
1295
+ return h(e) && We(e.blueName) ? e.blueName : null;
1296
1296
  }, fs = (r) => {
1297
1297
  const e = d.string().optional();
1298
1298
  return jr(r)(e);
@@ -1304,7 +1304,7 @@ const P = (r) => Ot().get(r), Or = (r) => (e) => {
1304
1304
  });
1305
1305
  }, Ur = (r) => {
1306
1306
  const e = P(r);
1307
- return f(e) && f(e.blueNode) && e.blueNode === !0 ? e.blueNode : null;
1307
+ return h(e) && h(e.blueNode) && e.blueNode === !0 ? e.blueNode : null;
1308
1308
  }, Dt = (r) => !!Ur(r), hs = () => {
1309
1309
  const r = d.instanceof(a);
1310
1310
  return $r()(r);
@@ -1319,10 +1319,10 @@ const P = (r) => Ot().get(r), Or = (r) => (e) => {
1319
1319
  });
1320
1320
  }, _r = (r) => {
1321
1321
  const e = P(r);
1322
- return f(e) && e[Ge] ? e[Ge] : null;
1322
+ return h(e) && e[Ge] ? e[Ge] : null;
1323
1323
  }, Ft = (r, e) => {
1324
1324
  const t = _r(r);
1325
- return N(t) ? !1 : (t == null ? void 0 : t._def) === (e == null ? void 0 : e._def) ? !0 : Ft(t, e);
1325
+ return E(t) ? !1 : (t == null ? void 0 : t._def) === (e == null ? void 0 : e._def) ? !0 : Ft(t, e);
1326
1326
  }, Zr = (r) => new Proxy(r, {
1327
1327
  get(e, t, n) {
1328
1328
  return t === "extend" ? function(...s) {
@@ -1353,13 +1353,13 @@ class Ce {
1353
1353
  static resolveBlueId(e) {
1354
1354
  var i;
1355
1355
  const t = Jr(e);
1356
- if (N(t))
1356
+ if (E(t))
1357
1357
  return null;
1358
1358
  const n = t.defaultValue;
1359
- if (f(n))
1359
+ if (h(n))
1360
1360
  return n;
1361
1361
  const s = (i = t.value) == null ? void 0 : i[0];
1362
- return f(s) ? s : Ce.getRepositoryBlueId(t, e);
1362
+ return h(s) ? s : Ce.getRepositoryBlueId(t, e);
1363
1363
  }
1364
1364
  static getRepositoryBlueId(e, t) {
1365
1365
  throw new Error("Not implemented");
@@ -1370,11 +1370,11 @@ class A {
1370
1370
  static isTypeOf(e, t, n) {
1371
1371
  var o;
1372
1372
  const s = Ce.resolveBlueId(t), i = (o = e.getType()) == null ? void 0 : o.getBlueId();
1373
- if (N(s) || N(i))
1373
+ if (E(s) || E(i))
1374
1374
  return !1;
1375
1375
  if (s === i)
1376
1376
  return !0;
1377
- if (n != null && n.checkSchemaExtensions && f(n.typeSchemaResolver)) {
1377
+ if (n != null && n.checkSchemaExtensions && h(n.typeSchemaResolver)) {
1378
1378
  const c = n.typeSchemaResolver.resolveSchema(e);
1379
1379
  return A.checkSchemaExtension(c, t);
1380
1380
  }
@@ -1384,7 +1384,7 @@ class A {
1384
1384
  * Checks if a schema extends a base schema.
1385
1385
  */
1386
1386
  static checkSchemaExtension(e, t) {
1387
- if (!f(e))
1387
+ if (!h(e))
1388
1388
  return !1;
1389
1389
  const n = A.unwrapSchema(e), s = A.unwrapSchema(t);
1390
1390
  return Ft(n, s);
@@ -1407,7 +1407,7 @@ class Gr {
1407
1407
  }
1408
1408
  registerSchema(e) {
1409
1409
  const t = Ce.resolveBlueId(e);
1410
- if (f(t)) {
1410
+ if (h(t)) {
1411
1411
  if (this.blueIdMap.has(t))
1412
1412
  throw new Error(`Duplicate BlueId value: ${t}`);
1413
1413
  this.blueIdMap.set(t, e);
@@ -1415,11 +1415,11 @@ class Gr {
1415
1415
  }
1416
1416
  resolveSchema(e) {
1417
1417
  const t = this.getEffectiveBlueId(e);
1418
- return N(t) ? null : this.blueIdMap.get(t);
1418
+ return E(t) ? null : this.blueIdMap.get(t);
1419
1419
  }
1420
1420
  getEffectiveBlueId(e) {
1421
1421
  const t = e.getType();
1422
- return f(t) && f(t.getBlueId()) ? t.getBlueId() : f(t) ? w.calculateBlueIdSync(t) : null;
1422
+ return h(t) && h(t.getBlueId()) ? t.getBlueId() : h(t) ? w.calculateBlueIdSync(t) : null;
1423
1423
  }
1424
1424
  getBlueIdMap() {
1425
1425
  return new Map(this.blueIdMap);
@@ -1429,7 +1429,7 @@ class Rt {
1429
1429
  static convertValue(e, t) {
1430
1430
  var i;
1431
1431
  const n = (i = e.getType()) == null ? void 0 : i.getBlueId(), s = e.getValue();
1432
- return N(s) ? this.isPrimitive(t) ? this.getDefaultPrimitiveValue(t) : s : H === n ? this.convertFromString(String(s), t) : X === n || s instanceof C ? this.convertFromBigDecimal(
1432
+ return E(s) ? this.isPrimitive(t) ? this.getDefaultPrimitiveValue(t) : s : H === n ? this.convertFromString(String(s), t) : X === n || s instanceof C ? this.convertFromBigDecimal(
1433
1433
  new C(s == null ? void 0 : s.toString()),
1434
1434
  t
1435
1435
  ) : q === n || s instanceof S ? this.convertFromBigInteger(
@@ -1519,17 +1519,17 @@ class zr {
1519
1519
  if (t instanceof Ue)
1520
1520
  return Object.keys(t.shape).reduce((s, i) => {
1521
1521
  const o = e.getProperties(), c = t.shape[i], l = Mr(c);
1522
- if (f(l)) {
1522
+ if (h(l)) {
1523
1523
  const g = We(l) ? l : i, v = o == null ? void 0 : o[g], D = v ? w.calculateBlueIdSync(v) : void 0;
1524
1524
  return s[i] = D, s;
1525
1525
  }
1526
- const h = xr(c);
1527
- if (f(h)) {
1528
- const g = o == null ? void 0 : o[h];
1526
+ const f = xr(c);
1527
+ if (h(f)) {
1528
+ const g = o == null ? void 0 : o[f];
1529
1529
  return s[i] = g == null ? void 0 : g.getName(), s;
1530
1530
  }
1531
1531
  const T = Dr(c);
1532
- if (f(T)) {
1532
+ if (h(T)) {
1533
1533
  const g = o == null ? void 0 : o[T];
1534
1534
  return s[i] = g == null ? void 0 : g.getDescription(), s;
1535
1535
  }
@@ -1542,7 +1542,7 @@ class zr {
1542
1542
  return s[i] = g, s;
1543
1543
  }
1544
1544
  const b = e.getContracts();
1545
- if (i === "contracts" && f(b) && this.canHandleStructuredData(c)) {
1545
+ if (i === "contracts" && h(b) && this.canHandleStructuredData(c)) {
1546
1546
  const g = Object.fromEntries(
1547
1547
  Object.entries(b).map(([D, he]) => [
1548
1548
  D,
@@ -1555,7 +1555,7 @@ class zr {
1555
1555
  );
1556
1556
  }
1557
1557
  const I = o == null ? void 0 : o[i];
1558
- if (N(I))
1558
+ if (E(I))
1559
1559
  return s;
1560
1560
  const m = this.nodeToObjectConverter.convert(
1561
1561
  I,
@@ -1606,11 +1606,11 @@ class Hr {
1606
1606
  }
1607
1607
  convert(e, t) {
1608
1608
  const n = t.keySchema, s = t.valueSchema, i = /* @__PURE__ */ new Map(), o = e.getName();
1609
- f(o) && i.set(Y, o);
1609
+ h(o) && i.set(Y, o);
1610
1610
  const c = e.getDescription();
1611
- f(c) && i.set(z, c);
1611
+ h(c) && i.set(z, c);
1612
1612
  const l = e.getContracts();
1613
- if (f(l) && this.canHandleStructuredData(s)) {
1613
+ if (h(l) && this.canHandleStructuredData(s)) {
1614
1614
  let T = !1;
1615
1615
  const b = Object.entries(l).reduce(
1616
1616
  (I, [m, g]) => {
@@ -1628,8 +1628,8 @@ class Hr {
1628
1628
  );
1629
1629
  T && i.set(Pe, b);
1630
1630
  }
1631
- const h = e.getProperties();
1632
- return f(h) && Object.entries(h).forEach(([T, b]) => {
1631
+ const f = e.getProperties();
1632
+ return h(f) && Object.entries(f).forEach(([T, b]) => {
1633
1633
  const I = new a().setValue(T);
1634
1634
  I.setType(new a().setBlueId(H));
1635
1635
  const m = Rt.convertValue(I, n), g = this.nodeToObjectConverter.convert(b, s);
@@ -1721,7 +1721,7 @@ class rn {
1721
1721
  return A.checkSchemaExtension(
1722
1722
  n,
1723
1723
  s
1724
- ) && f(n) && (i = n), this.convertWithType(e, i);
1724
+ ) && h(n) && (i = n), this.convertWithType(e, i);
1725
1725
  }
1726
1726
  convertWithType(e, t) {
1727
1727
  return this.converterFactory.getConverter(t).convert(e, t);
@@ -1895,8 +1895,8 @@ class ne {
1895
1895
  const o = Array.isArray(n) && n.length > 1;
1896
1896
  if (o) {
1897
1897
  const c = n.map((l) => {
1898
- const h = p.deserialize(l);
1899
- return t(h);
1898
+ const f = p.deserialize(l);
1899
+ return t(f);
1900
1900
  });
1901
1901
  s = w.calculateBlueIdSync(c), i = c.map((l) => y.get(l));
1902
1902
  } else {
@@ -1982,8 +1982,8 @@ class yn extends fe {
1982
1982
  if (o.length > 1) {
1983
1983
  const c = parseInt(o[1]);
1984
1984
  if (Array.isArray(i) && c < i.length) {
1985
- const l = i[c], h = p.deserialize(l);
1986
- return h.setBlueId(e), [h];
1985
+ const l = i[c], f = p.deserialize(l);
1986
+ return f.setBlueId(e), [f];
1987
1987
  } else if (c === 0) {
1988
1988
  const l = p.deserialize(i);
1989
1989
  return l.setBlueId(e), [l];
@@ -2064,10 +2064,10 @@ const xt = (r) => r instanceof a || Array.isArray(r) && r.every((e) => e instanc
2064
2064
  } catch (e) {
2065
2065
  throw new Error(`Failed enriching object with Blue ID: ${e}`);
2066
2066
  }
2067
- }, ms = (r) => r == null ? void 0 : r.items, Is = (r) => r == null ? void 0 : r.value, Ts = (r) => N(r) ? {} : bt(
2067
+ }, ms = (r) => r == null ? void 0 : r.items, Is = (r) => r == null ? void 0 : r.value, Ts = (r) => E(r) ? {} : bt(
2068
2068
  r,
2069
2069
  Qt
2070
- ), bs = (r) => ar(r) ? r.type.name ?? null : ur(r) ? Kt(typeof r.value) : lr(r) ? "List" : null, In = (r) => f(r) && Object.keys(bt(r, ["blueId"])).length > 0, ws = (r) => {
2070
+ ), bs = (r) => ar(r) ? r.type.name ?? null : ur(r) ? Kt(typeof r.value) : lr(r) ? "List" : null, In = (r) => h(r) && Object.keys(bt(r, ["blueId"])).length > 0, ws = (r) => {
2071
2071
  try {
2072
2072
  const e = p.deserialize(r), t = y.get(e);
2073
2073
  return ce.parse(t);
@@ -2096,15 +2096,15 @@ const xt = (r) => r instanceof a || Array.isArray(r) && r.every((e) => e instanc
2096
2096
  ...i.slice(c + 1)
2097
2097
  ]
2098
2098
  });
2099
- const h = await lt(l);
2100
- if (n != null && n.includes(h.blueId))
2099
+ const f = await lt(l);
2100
+ if (n != null && n.includes(f.blueId))
2101
2101
  return at({
2102
2102
  ...r,
2103
2103
  items: [...i.slice(0, c), ...i.slice(c + 1)]
2104
2104
  });
2105
2105
  i = [
2106
2106
  ...i.slice(0, c),
2107
- h,
2107
+ f,
2108
2108
  ...i.slice(c + 1)
2109
2109
  ];
2110
2110
  }
@@ -2134,7 +2134,7 @@ class Tn {
2134
2134
  */
2135
2135
  inferType(e) {
2136
2136
  const t = e.getType(), n = e.getValue();
2137
- return N(t) && f(n) && (typeof n == "string" ? e.setType(new a().setBlueId(H)) : typeof n == "bigint" || le(n) ? e.setType(new a().setBlueId(q)) : dr(n) ? e.setType(new a().setBlueId(X)) : typeof n == "boolean" && e.setType(new a().setBlueId(Q))), e;
2137
+ return E(t) && h(n) && (typeof n == "string" ? e.setType(new a().setBlueId(H)) : typeof n == "bigint" || le(n) ? e.setType(new a().setBlueId(q)) : dr(n) ? e.setType(new a().setBlueId(X)) : typeof n == "boolean" && e.setType(new a().setBlueId(Q))), e;
2138
2138
  }
2139
2139
  }
2140
2140
  const se = class se {
@@ -2229,8 +2229,8 @@ class st {
2229
2229
  c && this.extendNode(c, t, "itemType", !0);
2230
2230
  const l = e.getKeyType();
2231
2231
  l && this.extendNode(l, t, "keyType", !0);
2232
- const h = e.getValueType();
2233
- h && this.extendNode(h, t, "valueType", !0);
2232
+ const f = e.getValueType();
2233
+ f && this.extendNode(f, t, "valueType", !0);
2234
2234
  const T = e.getProperties();
2235
2235
  T && Object.entries(T).forEach(([m, g]) => {
2236
2236
  this.extendNode(g, t, m, !1);
@@ -2278,7 +2278,7 @@ class st {
2278
2278
  mergeNodes(e, t) {
2279
2279
  e.setName(t.getName()), e.setDescription(t.getDescription()), e.setType(t.getType()), e.setItemType(t.getItemType()), e.setKeyType(t.getKeyType()), e.setValueType(t.getValueType());
2280
2280
  const n = t.getValue();
2281
- f(n) && e.setValue(n), e.setItems(t.getItems()), e.setProperties(t.getProperties()), e.setContracts(t.getContracts());
2281
+ h(n) && e.setValue(n), e.setItems(t.getItems()), e.setProperties(t.getProperties()), e.setContracts(t.getContracts());
2282
2282
  }
2283
2283
  }
2284
2284
  class $t {
@@ -2667,10 +2667,10 @@ class wn extends gn {
2667
2667
  // Already preprocessed above
2668
2668
  ), o = n || i.blueId;
2669
2669
  this.blueIdToContentMap.set(o, i.content), this.blueIdToMultipleDocumentsMap.set(o, !0), s.forEach((c, l) => {
2670
- const h = `${o}#${l}`, T = y.get(c), b = w.calculateBlueIdSync(c);
2670
+ const f = `${o}#${l}`, T = y.get(c), b = w.calculateBlueIdSync(c);
2671
2671
  this.blueIdToContentMap.set(b, T), this.blueIdToMultipleDocumentsMap.set(b, !1);
2672
2672
  const I = c.getName();
2673
- I && this.addToNameMap(I, h);
2673
+ I && this.addToNameMap(I, f);
2674
2674
  });
2675
2675
  }
2676
2676
  fetchContentByBlueId(t) {
@@ -3020,13 +3020,13 @@ class Sn extends Nn {
3020
3020
  * @param limits - The limits to apply during merging
3021
3021
  */
3022
3022
  merge(t, n, s) {
3023
- if (f(n.getBlue()))
3023
+ if (h(n.getBlue()))
3024
3024
  throw new Error(
3025
3025
  'Document contains "blue" attribute. Preprocess document before merging.'
3026
3026
  );
3027
3027
  const i = n.getType();
3028
- if (f(i)) {
3029
- f(i.getBlueId()) && new st(this.nodeProvider).extend(
3028
+ if (h(i)) {
3029
+ h(i.getBlueId()) && new st(this.nodeProvider).extend(
3030
3030
  i,
3031
3031
  it.withSinglePath("/")
3032
3032
  );
@@ -3044,11 +3044,15 @@ class Sn extends Nn {
3044
3044
  mergeObject(t, n, s) {
3045
3045
  this.mergingProcessor.process(t, n, this.nodeProvider, this);
3046
3046
  const i = n.getItems();
3047
- f(i) && this.mergeChildren(t, i, s);
3047
+ h(i) && this.mergeChildren(t, i, s);
3048
3048
  const o = n.getProperties();
3049
- f(o) && Object.entries(o).forEach(([c, l]) => {
3050
- s.shouldMergePathSegment(c, l) && (s.enterPathSegment(c, l), this.mergeProperty(t, c, l, s), s.exitPathSegment());
3051
- }), f(n.getBlueId()) && t.setBlueId(n.getBlueId()), this.mergingProcessor.postProcess && this.mergingProcessor.postProcess(
3049
+ h(o) && Object.entries(o).forEach(([l, f]) => {
3050
+ s.shouldMergePathSegment(l, f) && (s.enterPathSegment(l, f), this.mergeProperty(t, l, f, s), s.exitPathSegment());
3051
+ });
3052
+ const c = n.getContracts();
3053
+ h(c) && Object.entries(c).forEach(([l, f]) => {
3054
+ s.shouldMergePathSegment(l, f) && (s.enterPathSegment(l, f), this.mergeContract(t, l, f, s), s.exitPathSegment());
3055
+ }), h(n.getBlueId()) && t.setBlueId(n.getBlueId()), this.mergingProcessor.postProcess && this.mergingProcessor.postProcess(
3052
3056
  t,
3053
3057
  n,
3054
3058
  this.nodeProvider,
@@ -3063,7 +3067,7 @@ class Sn extends Nn {
3063
3067
  */
3064
3068
  mergeChildren(t, n, s) {
3065
3069
  const i = t.getItems();
3066
- if (N(i)) {
3070
+ if (E(i)) {
3067
3071
  const o = n.filter(
3068
3072
  (c, l) => s.shouldMergePathSegment(String(l), t)
3069
3073
  ).map((c) => {
@@ -3108,10 +3112,23 @@ class Sn extends Nn {
3108
3112
  */
3109
3113
  mergeProperty(t, n, s, i) {
3110
3114
  const o = this.resolve(s, i);
3111
- N(t.getProperties()) && t.setProperties({});
3115
+ E(t.getProperties()) && t.setProperties({});
3112
3116
  const c = t.getProperties()[n];
3113
3117
  c === void 0 ? t.getProperties()[n] = o : this.mergeObject(c, o, i);
3114
3118
  }
3119
+ /**
3120
+ * Merges a contract from source into target
3121
+ * @param target - The target node
3122
+ * @param sourceKey - The contract key
3123
+ * @param sourceValue - The contract value to merge
3124
+ * @param limits - The limits to apply
3125
+ */
3126
+ mergeContract(t, n, s, i) {
3127
+ const o = this.resolve(s, i);
3128
+ E(t.getContracts()) && t.setContracts({});
3129
+ const c = t.getContracts()[n];
3130
+ c === void 0 ? t.getContracts()[n] = o : this.mergeObject(c, o, i);
3131
+ }
3115
3132
  /**
3116
3133
  * Resolves a node by creating a new node and merging the source into it
3117
3134
  * @param node - The node to resolve
@@ -3152,9 +3169,9 @@ class Pn {
3152
3169
  class An {
3153
3170
  process(e, t) {
3154
3171
  const n = t.getValue();
3155
- if (f(n)) {
3172
+ if (h(n)) {
3156
3173
  const s = e.getValue();
3157
- if (N(s))
3174
+ if (E(s))
3158
3175
  e.setValue(n);
3159
3176
  else if (n !== s)
3160
3177
  throw new Error(
@@ -3186,7 +3203,7 @@ function $e(r, e) {
3186
3203
  }
3187
3204
  return t;
3188
3205
  }
3189
- function E(r, e, t) {
3206
+ function N(r, e, t) {
3190
3207
  const n = w.calculateBlueIdSync(r), s = w.calculateBlueIdSync(e);
3191
3208
  if (n === s)
3192
3209
  return !0;
@@ -3212,24 +3229,24 @@ function E(r, e, t) {
3212
3229
  function Cn(r, e) {
3213
3230
  return Et.some((t) => {
3214
3231
  const n = new a().setBlueId(t);
3215
- return E(r, n, e);
3232
+ return N(r, n, e);
3216
3233
  });
3217
3234
  }
3218
3235
  function Vn(r, e) {
3219
3236
  const t = new a().setBlueId(H);
3220
- return E(r, t, e);
3237
+ return N(r, t, e);
3221
3238
  }
3222
3239
  function On(r, e) {
3223
3240
  const t = new a().setBlueId(q);
3224
- return E(r, t, e);
3241
+ return N(r, t, e);
3225
3242
  }
3226
3243
  function Dn(r, e) {
3227
3244
  const t = new a().setBlueId(X);
3228
- return E(r, t, e);
3245
+ return N(r, t, e);
3229
3246
  }
3230
3247
  function Fn(r, e) {
3231
3248
  const t = new a().setBlueId(Q);
3232
- return E(r, t, e);
3249
+ return N(r, t, e);
3233
3250
  }
3234
3251
  function Rn(r) {
3235
3252
  return (r == null ? void 0 : r.getBlueId()) === vt;
@@ -3240,13 +3257,13 @@ function Mn(r) {
3240
3257
  function jn(r, e) {
3241
3258
  return tt.some((t) => {
3242
3259
  const n = new a().setName(t);
3243
- return E(r, n, e);
3260
+ return N(r, n, e);
3244
3261
  });
3245
3262
  }
3246
3263
  function xn(r, e) {
3247
3264
  for (const t of tt) {
3248
3265
  const n = new a().setName(t);
3249
- if (E(r, n, e))
3266
+ if (N(r, n, e))
3250
3267
  return t;
3251
3268
  }
3252
3269
  throw new Error(
@@ -3259,7 +3276,7 @@ class $n {
3259
3276
  if (s === void 0)
3260
3277
  e.setType(i);
3261
3278
  else if (i !== void 0) {
3262
- if (!E(i, s, n)) {
3279
+ if (!N(i, s, n)) {
3263
3280
  const c = y.get(i), l = y.get(s);
3264
3281
  throw new Error(
3265
3282
  `The source type '${JSON.stringify(
@@ -3281,15 +3298,15 @@ class Un {
3281
3298
  if (s === void 0)
3282
3299
  i !== void 0 && e.setItemType(i);
3283
3300
  else if (i !== void 0) {
3284
- if (!E(
3301
+ if (!N(
3285
3302
  i,
3286
3303
  s,
3287
3304
  n
3288
3305
  )) {
3289
- const h = y.get(i), T = y.get(s);
3306
+ const f = y.get(i), T = y.get(s);
3290
3307
  throw new Error(
3291
3308
  `The source item type '${JSON.stringify(
3292
- h
3309
+ f
3293
3310
  )}' is not a subtype of the target item type '${JSON.stringify(
3294
3311
  T
3295
3312
  )}'.`
@@ -3300,9 +3317,9 @@ class Un {
3300
3317
  const o = e.getItemType(), c = t.getItems();
3301
3318
  if (o !== void 0 && c !== void 0)
3302
3319
  for (const l of c) {
3303
- const h = l.getType();
3304
- if (h !== void 0 && !E(h, o, n)) {
3305
- const T = y.get(h), b = y.get(
3320
+ const f = l.getType();
3321
+ if (f !== void 0 && !N(f, o, n)) {
3322
+ const T = y.get(f), b = y.get(
3306
3323
  o
3307
3324
  );
3308
3325
  throw new Error(
@@ -3333,7 +3350,7 @@ class Ln {
3333
3350
  if (s === void 0)
3334
3351
  i !== void 0 && (this.validateBasicKeyType(i, n), e.setKeyType(i));
3335
3352
  else if (i !== void 0) {
3336
- if (this.validateBasicKeyType(i, n), !E(
3353
+ if (this.validateBasicKeyType(i, n), !N(
3337
3354
  i,
3338
3355
  s,
3339
3356
  n
@@ -3355,7 +3372,7 @@ class Ln {
3355
3372
  if (s === void 0)
3356
3373
  i !== void 0 && e.setValueType(i);
3357
3374
  else if (i !== void 0) {
3358
- if (!E(
3375
+ if (!N(
3359
3376
  i,
3360
3377
  s,
3361
3378
  n
@@ -3396,7 +3413,7 @@ class Ln {
3396
3413
  }
3397
3414
  validateValueType(e, t, n) {
3398
3415
  const s = e.getType();
3399
- if (s !== void 0 && !E(s, t, n)) {
3416
+ if (s !== void 0 && !N(s, t, n)) {
3400
3417
  const i = y.get(s), o = y.get(t);
3401
3418
  throw new Error(
3402
3419
  `Value of type '${JSON.stringify(
@@ -3414,11 +3431,11 @@ class _n {
3414
3431
  postProcess(e, t, n) {
3415
3432
  const s = e.getType();
3416
3433
  if (s !== void 0 && jn(s, n)) {
3417
- const i = e.getItems(), o = e.getProperties();
3418
- if (i !== void 0 && i.length > 0 || o !== void 0 && Object.keys(o).length > 0) {
3419
- const c = xn(s, n), l = s.getName() || "unknown";
3434
+ const i = e.getItems(), o = e.getProperties(), c = e.getContracts();
3435
+ if (i !== void 0 && i.length > 0 || o !== void 0 && Object.keys(o).length > 0 || c !== void 0 && Object.keys(c).length > 0) {
3436
+ const l = xn(s, n), f = s.getName() || "unknown";
3420
3437
  throw new Error(
3421
- `Node of type "${l}" (which extends basic type "${c}") must not have items or properties.`
3438
+ `Node of type "${f}" (which extends basic type "${l}") must not have items, properties or contracts.`
3422
3439
  );
3423
3440
  }
3424
3441
  }
@@ -3468,8 +3485,8 @@ class vs {
3468
3485
  void 0,
3469
3486
  this.urlContentFetcher
3470
3487
  ), this.blueIdsMappingGenerator = new Ut(), i)
3471
- for (const { schemas: h, blueIds: T } of i)
3472
- (l = this.typeSchemaResolver) == null || l.registerSchemas(h), this.blueIdsMappingGenerator.registerBlueIds(T);
3488
+ for (const { schemas: f, blueIds: T } of i)
3489
+ (l = this.typeSchemaResolver) == null || l.registerSchemas(f), this.blueIdsMappingGenerator.registerBlueIds(T);
3473
3490
  }
3474
3491
  /**
3475
3492
  * Converts a BlueNode to a JSON representation based on the specified strategy.
@@ -44,6 +44,14 @@ export declare class Merger extends NodeResolver {
44
44
  * @param limits - The limits to apply
45
45
  */
46
46
  private mergeProperty;
47
+ /**
48
+ * Merges a contract from source into target
49
+ * @param target - The target node
50
+ * @param sourceKey - The contract key
51
+ * @param sourceValue - The contract value to merge
52
+ * @param limits - The limits to apply
53
+ */
54
+ private mergeContract;
47
55
  /**
48
56
  * Resolves a node by creating a new node and merging the source into it
49
57
  * @param node - The node to resolve
@@ -1 +1 @@
1
- {"version":3,"file":"Merger.d.ts","sourceRoot":"","sources":["../../../src/lib/merge/Merger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAKhD;;GAEG;AACH,qBAAa,MAAO,SAAQ,YAAY;IACtC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,YAAY,CAAe;IAEnC;;;;OAIG;gBACS,gBAAgB,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY;IAM1E;;;;;OAKG;IACI,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAuBtE;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAqCnB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAqDrB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAqBrB;;;;;OAKG;IACI,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ;CAQzD"}
1
+ {"version":3,"file":"Merger.d.ts","sourceRoot":"","sources":["../../../src/lib/merge/Merger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAKhD;;GAEG;AACH,qBAAa,MAAO,SAAQ,YAAY;IACtC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,YAAY,CAAe;IAEnC;;;;OAIG;gBACS,gBAAgB,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY;IAM1E;;;;;OAKG;IACI,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAuBtE;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAgDnB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAqDrB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAqBrB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAqBrB;;;;;OAKG;IACI,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ;CAQzD"}
@@ -1 +1 @@
1
- {"version":3,"file":"BasicTypesVerifier.d.ts","sourceRoot":"","sources":["../../../../src/lib/merge/processors/BasicTypesVerifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,gBAAgB;IACzD,OAAO,IAAI,IAAI;IAIf,WAAW,CACT,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,QAAQ,EAChB,YAAY,EAAE,YAAY,GACzB,IAAI;CAqBR"}
1
+ {"version":3,"file":"BasicTypesVerifier.d.ts","sourceRoot":"","sources":["../../../../src/lib/merge/processors/BasicTypesVerifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,gBAAgB;IACzD,OAAO,IAAI,IAAI;IAIf,WAAW,CACT,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,QAAQ,EAChB,YAAY,EAAE,YAAY,GACzB,IAAI;CAuBR"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@blue-labs/language",
3
- "version": "1.26.0",
3
+ "version": "1.27.0",
4
4
  "dependencies": {
5
- "@blue-labs/shared-utils": "1.26.0",
5
+ "@blue-labs/shared-utils": "1.27.0",
6
6
  "@types/big.js": "^6.2.2",
7
7
  "@types/js-yaml": "^4.0.9",
8
8
  "base32.js": "^0.1.0",