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