@blue-labs/language 2.0.0-rc.1 → 2.0.0-rc.14
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 +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -10
- package/dist/index.mjs +1873 -1138
- package/dist/lib/Blue.d.ts +20 -5
- package/dist/lib/Blue.d.ts.map +1 -1
- package/dist/lib/errors/BlueError.d.ts +20 -0
- package/dist/lib/errors/BlueError.d.ts.map +1 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/preprocess/Preprocessor.d.ts +0 -9
- package/dist/lib/preprocess/Preprocessor.d.ts.map +1 -1
- package/dist/lib/provider/RepositoryBasedNodeProvider.d.ts +7 -6
- package/dist/lib/provider/RepositoryBasedNodeProvider.d.ts.map +1 -1
- package/dist/lib/repository/RepositoryRuntime.d.ts +34 -0
- package/dist/lib/repository/RepositoryRuntime.d.ts.map +1 -0
- package/dist/lib/types/BlueContext.d.ts +11 -0
- package/dist/lib/types/BlueContext.d.ts.map +1 -0
- package/dist/lib/types/BlueRepository.d.ts +6 -6
- package/dist/lib/types/BlueRepository.d.ts.map +1 -1
- package/dist/lib/types/index.d.ts +2 -1
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/lib/utils/BlueContextRepositoriesParser.d.ts +4 -0
- package/dist/lib/utils/BlueContextRepositoriesParser.d.ts.map +1 -0
- package/dist/lib/utils/NodeProviderWrapper.d.ts +5 -2
- package/dist/lib/utils/NodeProviderWrapper.d.ts.map +1 -1
- package/dist/lib/utils/NodeToYaml.d.ts +9 -0
- package/dist/lib/utils/NodeToYaml.d.ts.map +1 -0
- package/dist/lib/utils/RepositoryVersionSerializer.d.ts +28 -0
- package/dist/lib/utils/RepositoryVersionSerializer.d.ts.map +1 -0
- package/dist/lib/utils/TypeSchemaResolver.d.ts +3 -0
- package/dist/lib/utils/TypeSchemaResolver.d.ts.map +1 -1
- package/dist/lib/utils/repositoryVersioning/dropPointers.d.ts +5 -0
- package/dist/lib/utils/repositoryVersioning/dropPointers.d.ts.map +1 -0
- package/package.json +3 -2
- package/dist/lib/mapping/__tests__/schema/contract.d.ts +0 -364
- package/dist/lib/mapping/__tests__/schema/contract.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/doctor.d.ts +0 -19
- package/dist/lib/mapping/__tests__/schema/doctor.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/index.d.ts +0 -3389
- package/dist/lib/mapping/__tests__/schema/index.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/nurse.d.ts +0 -19
- package/dist/lib/mapping/__tests__/schema/nurse.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/person.d.ts +0 -15
- package/dist/lib/mapping/__tests__/schema/person.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/personDictionaryExample.d.ts +0 -75
- package/dist/lib/mapping/__tests__/schema/personDictionaryExample.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/personListExample.d.ts +0 -61
- package/dist/lib/mapping/__tests__/schema/personListExample.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/personObjectExample.d.ts +0 -61
- package/dist/lib/mapping/__tests__/schema/personObjectExample.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/personValueExample.d.ts +0 -25
- package/dist/lib/mapping/__tests__/schema/personValueExample.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/x.d.ts +0 -67
- package/dist/lib/mapping/__tests__/schema/x.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/x1.d.ts +0 -73
- package/dist/lib/mapping/__tests__/schema/x1.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/x11.d.ts +0 -80
- package/dist/lib/mapping/__tests__/schema/x11.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/x12.d.ts +0 -80
- package/dist/lib/mapping/__tests__/schema/x12.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/x2.d.ts +0 -67
- package/dist/lib/mapping/__tests__/schema/x2.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/x3.d.ts +0 -77
- package/dist/lib/mapping/__tests__/schema/x3.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/xSubscription.d.ts +0 -10
- package/dist/lib/mapping/__tests__/schema/xSubscription.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/y.d.ts +0 -990
- package/dist/lib/mapping/__tests__/schema/y.d.ts.map +0 -1
- package/dist/lib/mapping/__tests__/schema/y1.d.ts +0 -1381
- package/dist/lib/mapping/__tests__/schema/y1.d.ts.map +0 -1
- package/dist/lib/utils/__tests__/calculateCID.d.ts +0 -3
- package/dist/lib/utils/__tests__/calculateCID.d.ts.map +0 -1
- package/dist/lib/utils/limits/__tests__/TestLimits.d.ts +0 -39
- package/dist/lib/utils/limits/__tests__/TestLimits.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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';
|
|
2
3
|
export * from './schema';
|
|
3
4
|
export * from './schema/annotations';
|
|
4
5
|
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,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
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,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,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 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:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("big.js"),u=require("@blue-labs/shared-utils"),c=require("zod"),lr=require("bs58"),V=require("radash"),ar=require("js-sha256"),ur=require("crypto"),cr=require("base32.js"),G=require("js-yaml"),pt=require("@blue-labs/repository-contract"),ft=s=>s&&s.__esModule?s:{default:s},ie=ft(lr),Re=ft(ur);class P extends x{constructor(e){super(e)}}class B extends x{constructor(e){super(e)}}class dr{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",J="description",oe="type",Ne="itemType",ve="keyType",Be="valueType",pe="value",we="items",$="blueId",Ee="blue",Ke=[Y,J,oe,Ne,ve,Be,pe,we,$,Ee],ht="Text",yt="Double",gt="Integer",mt="Boolean",It="List",Tt="Dictionary",Pe=[ht,yt,gt,mt],Ze=[...Pe,It,Tt],z="DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K",L="7pwXmXYCJtWnd348c2JQGBkm9C4renmZRwxbfaypsx5y",U="5WNMiV9Knz63B4dVY5JtMyh3FB4FSGqv7ceScvuapdE1",k="4EzhSubEimSQD3zrYHRtobfPPWntUuhEz8YcdxHsi12u",Ye="6aehfNAxHLC1PHHoDr3tYtFH3RWNbiWdFancJ1bypXEY",Je="G7fBT9PSod1RfHLHkpafAGBDVAJMrMhAMY51ERcyXNrj",Ge=[z,L,U,k],H=[...Ge,Ye,Je],pr=Object.fromEntries(Ze.map((s,e)=>[s,H[e]])),He=Object.fromEntries(H.map((s,e)=>[s,Ze[e]])),fr=Object.freeze(Object.defineProperty({__proto__:null,BASIC_TYPES:Pe,BASIC_TYPE_BLUE_IDS:Ge,BOOLEAN_TYPE:mt,BOOLEAN_TYPE_BLUE_ID:k,CORE_TYPES:Ze,CORE_TYPE_BLUE_IDS:H,CORE_TYPE_BLUE_ID_TO_NAME_MAP:He,CORE_TYPE_NAME_TO_BLUE_ID_MAP:pr,DICTIONARY_TYPE:Tt,DICTIONARY_TYPE_BLUE_ID:Je,DOUBLE_TYPE:yt,DOUBLE_TYPE_BLUE_ID:L,INTEGER_TYPE:gt,INTEGER_TYPE_BLUE_ID:U,LIST_TYPE:It,LIST_TYPE_BLUE_ID:Ye,OBJECT_BLUE:Ee,OBJECT_BLUE_ID:$,OBJECT_DESCRIPTION:J,OBJECT_ITEMS:we,OBJECT_ITEM_TYPE:Ne,OBJECT_KEY_TYPE:ve,OBJECT_NAME:Y,OBJECT_SPECIFIC_KEYS:Ke,OBJECT_TYPE:oe,OBJECT_VALUE:pe,OBJECT_VALUE_TYPE:Be,TEXT_TYPE:ht,TEXT_TYPE_BLUE_ID:z},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===U&&typeof this.value=="string")return new B(this.value);if(e===L&&typeof this.value=="string"){const t=new P(this.value),r=parseFloat(t.toString());return new P(r.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 B(e.toString()):this.value=new P(e.toString()):this.value=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}addItems(...e){return this.items||(this.items=[]),this.items.push(...e),this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}addProperty(e,t){return this.properties||(this.properties={}),this.properties[e]=t,this}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 dr.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 B||t instanceof P)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 me{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(ie.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 hr=c.z.string().max(me.MAX_BLUE_ID_LENGTH,{message:"Blue Id has a maximum length of 45 characters"}).min(me.MIN_BLUE_ID_LENGTH,{message:"Blue Id has a minimum length of 41 characters"}).refine(s=>{try{return ie.default.decode(s),!0}catch{return!1}},{message:"Blue Id must be a valid Base58 string"}),q=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:q.optional(),value:c.z.union([c.z.string(),c.z.number(),c.z.boolean()]).optional().nullable(),items:c.z.array(q).optional()}))),fe=c.z.object({blueId:c.z.string().optional(),name:c.z.string().optional(),description:c.z.string().optional(),type:q.optional()}),yr=fe.extend({value:c.z.string().optional()}),gr=fe.extend({value:c.z.number().optional()}),mr=fe.extend({value:c.z.boolean().optional()}),Ir=fe.extend({items:c.z.array(c.z.string()).optional()}),Tr=s=>q.safeParse(s).success,bt=s=>u.isNonNullable(s)&&"blueId"in s&&u.isNonNullable(s.blueId),br=s=>u.isNonNullable(s)&&"name"in s&&u.isNonNullable(s.name),Nt=s=>u.isNonNullable(s)&&"items"in s&&u.isNonNullable(s.items),vt=s=>u.isNonNullable(s)&&"type"in s&&u.isNonNullable(s.type),Bt=s=>u.isNonNullable(s)&&"value"in s&&u.isNonNullable(s.value),Nr=(s,e)=>s.required({type:!0}).safeParse(e).success,S=s=>s instanceof x,_=s=>S(s)&&s instanceof B,Ie=s=>S(s)&&s instanceof P,vr=c.z.lazy(()=>c.z.record(le)),Br=c.z.lazy(()=>c.z.union([c.z.array(le),c.z.array(le).readonly()])),le=c.z.lazy(()=>c.z.union([u.jsonPrimitiveSchema,vr,Br,c.z.instanceof(x)])),We=s=>V.isObject(s)&&!V.isArray(s)&&!u.isReadonlyArray(s)&&!S(s),qe=s=>V.isArray(s)||u.isReadonlyArray(s),wr=s=>qe(s)||We(s)||S(s)||u.isJsonPrimitive(s);class m{static deserialize(e){return m.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(We(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 J:if(i==null)t.setDescription(void 0);else{if(typeof i!="string")throw new Error(`The ${J} field must be a string.`);t.setDescription(i)}break;case oe:t.setType(m.handleNode(i));break;case Ne:t.setItemType(m.handleNode(i));break;case ve:t.setKeyType(m.handleNode(i));break;case Be:t.setValueType(m.handleNode(i));break;case pe:t.setValue(m.handleValue(i));break;case $:if(typeof i!="string")throw new Error(`The ${$} field must be a string.`);t.setBlueId(i);break;case we:t.setItems(m.handleArray(i));break;case Ee:t.setBlue(m.handleNode(i));break;default:r[n]=m.handleNode(i);break}}),Object.keys(r).length>0&&t.setProperties(r),t}else{if(qe(e))return new d().setItems(m.handleArray(e));{const t=e;return new d().setValue(m.handleValue(t)).setInlineValue(!0)}}}static handleValue(e){if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="number"||S(e))if(_(e)||Number.isSafeInteger(e)){const t=new B(e.toString()),r=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER;return t.lt(r)?new B(r.toString()):t.gt(n)?new B(n.toString()):t}else{const t=parseFloat(e.toString());return new P(t.toString())}else if(typeof e=="boolean")return e;throw new Error(`Can't handle node: ${JSON.stringify(e)}`)}static handleArray(e){if(e!=null){if(V.isObject(e)&&!Array.isArray(e))return[m.handleNode(e)];if(Array.isArray(e))return e.map(m.handleNode);throw new Error("Expected an array node")}}}function Er(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var Oe,nt;function Pr(){return nt||(nt=1,Oe=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])}`},"")}}`}),Oe}var Sr=Pr();const Ar=Er(Sr);class wt{static canonicalize(e){return Ar(e)}}const De=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;class Xe{static instance;browserCrypto;constructor(){this.browserCrypto=this.initBrowserCrypto()}static getInstance(){return this.instance||(this.instance=new Xe),this.instance}initBrowserCrypto(){return De?null:"crypto"in globalThis?globalThis.crypto:null}hasNodeCrypto(){return De&&!!Re.default&&typeof Re.default.createHash=="function"}getBrowserCrypto(){return this.browserCrypto}getNodeCrypto(){return De?Re.default:null}}class Et{cryptoEnv=Xe.getInstance();applySync(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):this.sha256SyncBrowser(t);return ie.default.encode(r)}async apply(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):await this.sha256Async(t);return ie.default.encode(r)}canonicalizeInput(e){const t=wt.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(ar.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 I{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(R=>I.get(R,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[J]=l);const p=e.getType();if(t==="official"&&r!==void 0&&p===void 0){const R=this.inferTypeBlueId(r);R!==null&&(a[oe]={[$]:R})}else p!==void 0&&(a[oe]=I.get(p,t));const g=e.getItemType();g!==void 0&&(a[Ne]=I.get(g,t));const f=e.getKeyType();f!==void 0&&(a[ve]=I.get(f,t));const h=e.getValueType();h!==void 0&&(a[Be]=I.get(h,t)),n!==void 0&&(a[pe]=n),i!==void 0&&(a[we]=i);const y=e.getBlueId();y!==void 0&&(a[$]=y);const N=e.getBlue();N!==void 0&&(a[Ee]=N);const C=e.getProperties();return C!==void 0&&Object.entries(C).forEach(([R,ge])=>{a[R]=I.get(ge,t)}),a}static handleValue(e){if(S(e)){if(_(e)){const t=new x(Number.MIN_SAFE_INTEGER.toString()),r=new x(Number.MAX_SAFE_INTEGER.toString());if(e.lt(t)||e.gt(r))return e.toString()}return e.toNumber()}return e}static inferTypeBlueId(e){return typeof e=="string"?z:S(e)?_(e)?U:L:typeof e=="boolean"?k:null}}const Vr=s=>u.isJsonPrimitive(s)&&u.isNonNullable(s);class T{static INSTANCE=new T(new Et);hashProvider;constructor(e){this.hashProvider=e}static calculateBlueId(e){if(Array.isArray(e)){const r=e.map(n=>I.get(n));return T.INSTANCE.calculate(r)}const t=I.get(e);return T.INSTANCE.calculate(t)}static calculateBlueIdSync(e){if(Array.isArray(e)){const r=e.map(n=>I.get(n));return T.INSTANCE.calculateSync(r)}const t=I.get(e);return T.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 Vr(e)||S(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[$]!==void 0)return e[$];const n=Object.keys(e).map(o=>{const l=e[o];if([Y,pe,J].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)||S(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 Cr{static convert(e){const t=ie.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 cr.Encoder({type:"rfc4648",lc:!0}).write(n).finalize().replace(/=/g,"")}}class v{static transform(e,t){const r=t(e.clone()),n=r.getType();n!==void 0&&r.setType(v.transform(n,t));const i=r.getItemType();i!==void 0&&r.setItemType(v.transform(i,t));const o=r.getKeyType();o!==void 0&&r.setKeyType(v.transform(o,t));const l=r.getValueType();l!==void 0&&r.setValueType(v.transform(l,t));const a=r.getItems();if(a!==void 0){const g=a.map(f=>v.transform(f,t));r.setItems(g)}const p=r.getProperties();if(p!==void 0){const g=Object.keys(p).reduce((f,h)=>(f[h]=v.transform(p[h],t),f),{});r.setProperties(g)}return r}}const j=s=>!!s&&typeof s=="object"&&!Array.isArray(s)&&!(s instanceof d),D=s=>s instanceof B||s instanceof P,Rr=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(Rr)}function X(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 Pt(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 it(s,e,t=!0){if(s instanceof d){const r=Pt(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=X(e);return r>=0&&r<s.length?s[r]:void 0}if(j(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=it(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=it(t,r,!1);if((typeof n!="object"||n===null||D(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)?X(r):r}}function Qe(s,e){if(s instanceof d){const t=e,r=Pt(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)||j(s)?s[e]:s}function E(s){if(s instanceof d)return s;if(s===null||typeof s=="string"||typeof s=="number"||typeof s=="boolean"||D(s))return m.deserialize(s);const e=_e(s);return m.deserialize(e)}function _e(s){if(s===void 0)return null;if(s===null||typeof s!="object")return s;if(Array.isArray(s))return s.map(_e);const e={};for(const[t,r]of Object.entries(s))e[t]=_e(r);return e}function et(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:E(t));return;case"itemType":s.setItemType(t instanceof d||typeof t=="string"||t===void 0?t:E(t));return;case"keyType":s.setKeyType(t instanceof d||typeof t=="string"||t===void 0?t:E(t));return;case"valueType":s.setValueType(t instanceof d||typeof t=="string"||t===void 0?t:E(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:E(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:E(t));return}}}Array.isArray(s)?s.splice(X(e),1):j(s)&&(t===void 0?delete s[e]:s[e]=t)}function Or(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(m.deserialize(null));i.push(t)}}else i.splice(n,0,t)}function Te(s,e,t,r){if(Array.isArray(s)){const n=e==="-"?s.length:X(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=E(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(m.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)?Or(s,e,E(t),r):et(s,e,t);return}if(j(s)){s[e]=E(t);return}throw new Error(`Cannot insert into parent of type ${typeof s}`)}function Dr(s,e){if(Array.isArray(s)){const t=X(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=X(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}}et(s,e,void 0)}else j(s)&&delete s[e]}function je(s){if(s instanceof d)return s.clone();if(Array.isArray(s))return s.map(t=>je(t));if(j(s)){const e={};return Object.keys(s).forEach(t=>{e[t]=je(s[t])}),e}return s}function Z(s,e){if(s===e||s instanceof d&&(s.isInlineValue()||s.getValue()!==void 0)&&Z(s.getValue()??null,e)||e instanceof d&&(e.isInlineValue()||e.getValue()!==void 0)&&Z(s,e.getValue()??null))return!0;if(s instanceof d&&e instanceof d||D(s)&&D(e)||D(s)&&typeof e=="number"||typeof s=="number"&&D(e))return s.toString()===e.toString();if(Array.isArray(s)&&Array.isArray(e))return s.length===e.length&&s.every((t,r)=>Z(t,e[r]));if(j(s)&&j(e)){const t=Object.keys(s),r=Object.keys(e);return t.length===r.length&&t.every(n=>Z(s[n],e[n]))}return!1}function St(s,e){const{parent:t,key:r}=te(s,ee(e));return Qe(t,r)}function At(s,e,t){const r=ee(e);if(r.length===0&&e==="/"){const o=E(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);Te(n,i,t,!0)}function Mr(s,e,t){const r=ee(e);if(r.length===0&&e==="/"){if(s.getItems()&&Array.isArray(t)){const o=E(t);o.getItems()?(s.setItems(o.getItems()),s.setValue(null)):(s.setValue(o.getValue()??null),s.setItems(void 0))}else{const o=E(t);s.setValue(o.getValue()??null),o.getItems()&&s.setItems(o.getItems())}return!0}const{parent:n,key:i}=te(s,r);return Te(n,i,t,!1),!0}function Fr(s,e,t){const r=ee(e);if(r.length===0&&e==="/"){const l=E(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)et(n,i,t);else{const l=Qe(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}'.`);Te(n,i,t,!0)}else Te(n,i,t,!0)}return!0}function Vt(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 Dr(r,n),!0}function xr(s,e,t){const r=je(St(s,e));return At(s,t,r),!0}function $r(s,e,t){const r=ee(e),{parent:n,key:i}=te(s,r),o=Qe(n,i);if(o===void 0)throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);return Vt(s,e)?(At(s,t,o),!0):!1}function _r(s,e,t){const r=St(s,e);let n=t;if(r instanceof d)if((t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||D(t))&&(r.isInlineValue()||r.getValue()!==void 0)){if(!Z(r.getValue()??null,t))throw new Error(`TEST failed at '${e}': Expected ${JSON.stringify(t)}, got ${JSON.stringify(r.getValue()??null)}`);return!0}else typeof t=="object"&&!(t instanceof d)&&(n=E(t));else if(D(r)&&typeof t=="number")r instanceof B?n=new B(t.toString()):r instanceof P&&(n=new P(t.toString()));else if((r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&D(t)){const i=t;!Z(r,i.toString())&&(typeof r=="number"&&parseFloat(i.toString()))}if(!Z(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 jr(s,e){switch(e.op){case"add":return Mr(s,e.path,e.val);case"replace":return Fr(s,e.path,e.val);case"remove":return Vt(s,e.path);case"copy":return xr(s,e.from,e.path);case"move":return $r(s,e.from,e.path);case"test":return _r(s,e.path,e.val)}}function zr(s,e,t=!1){const r=t?s:s.clone();return jr(r,e),r}const Me=Symbol.for("zod-schema-annotations");function Lr(){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 Ct(){const s=Lr();return Me in s||(s[Me]=new WeakMap),s[Me]}function he(s,e){const t=Ct(),r=t.get(s)||{};return t.set(s,{...r,...e}),s}const O=s=>Ct().get(s),Rt=s=>e=>{const t=O(e);return he(e,{...t,blueDescription:s})},Ot=s=>{const e=O(s);return u.isNonNullable(e)&&V.isString(e.blueDescription)?e.blueDescription:null},Ur=s=>Rt(s)(c.z.string().optional()),kr=c.z.union([c.z.string(),c.z.boolean()]),Dt=s=>e=>{const t=O(e);return he(e,{...t,blueId:s})},Mt=s=>{const e=O(s),t=kr.safeParse(e?.blueId);return t.success?t.data:null},Kr=s=>Dt(s??!0)(c.z.string()),Ft=s=>e=>{const t=O(e);return he(e,{...t,blueName:s})},xt=s=>{const e=O(s);return u.isNonNullable(e)&&V.isString(e.blueName)?e.blueName:null},Zr=s=>{const e=c.z.string().optional();return Ft(s)(e)},$t=()=>s=>{const e=O(s);return he(s,{...e,blueNode:!0})},_t=s=>{const e=O(s);return u.isNonNullable(e)&&u.isNonNullable(e.blueNode)&&e.blueNode===!0?e.blueNode:null},tt=s=>!!_t(s),Yr=()=>{const s=c.z.instanceof(d);return $t()(s)},Jr=c.z.object({value:c.z.array(c.z.string()).optional(),defaultValue:c.z.string().optional()}),jt=s=>{const e=O(s),t=Jr.passthrough().safeParse(e?.typeBlueId);return t.success?t.data:null},Gr=s=>e=>{const t=O(e),r=typeof s=="string"?{value:[s]}:s;return he(e,{...t,typeBlueId:{...t?.typeBlueId||{},...r}})};class ae{static resolveBlueId(e){const t=jt(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:ae.getRepositoryBlueId(t,e)}static getRepositoryBlueId(e,t){throw new Error("Not implemented")}}class A{static isTypeOf(e,t,r){const n=ae.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 A.checkSchemaExtension(o,t,{typeSchemaResolver:r.typeSchemaResolver})}return!1}static checkSchemaExtension(e,t,r){if(!u.isNonNullable(e))return!1;const n=A.unwrapSchema(e),i=A.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 tt(e)?e:A.isWrapperType(e)?e instanceof c.ZodEffects?A.unwrapSchema(e.innerType()):e instanceof c.ZodLazy?A.unwrapSchema(e.schema):A.unwrapSchema(e.unwrap()):e}}function ot(s,e){const t=s.getType();if(t===void 0)return;const r=t.getBlueId();if(r!==void 0){if(H.includes(r)){const i=He[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 b(s,e,t){const r=T.calculateBlueIdSync(s),n=T.calculateBlueIdSync(e);if(r===n)return!0;if(r&&H.includes(r)){let a=e;for(;a!==void 0;){if(T.calculateBlueIdSync(a)===r)return!0;a=ot(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(T.calculateBlueIdSync(l)===n)return!0;l=ot(l,t)}return!1}function Hr(s,e){return Ge.some(t=>{const r=new d().setBlueId(t);return b(s,r,e)})}function Wr(s,e){const t=new d().setBlueId(z);return b(s,t,e)}function qr(s,e){const t=new d().setBlueId(U);return b(s,t,e)}function Xr(s,e){const t=new d().setBlueId(L);return b(s,t,e)}function Qr(s,e){const t=new d().setBlueId(k);return b(s,t,e)}function zt(s,e){const t=new d().setBlueId(Ye);return b(s,t,e)}function Lt(s,e){const t=new d().setBlueId(Je);return b(s,t,e)}function es(s,e){return Pe.some(t=>{const r=new d().setName(t);return b(s,r,e)})}function ts(s,e){for(const t of Pe){const r=new d().setName(t);if(b(s,r,e))return t}throw new Error(`Cannot determine the basic type for node of type "${s.getName()||"unknown"}".`)}class Ut{blueIdMap=new Map;nodeProvider;toCurrentBlueIdFn;constructor(e=[],t){this.nodeProvider=t?.nodeProvider??null,this.toCurrentBlueIdFn=t?.toCurrentBlueId,this.registerSchemas(e)}registerSchemas(e){for(const t of e)this.registerSchema(t)}registerSchema(e){const t=ae.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(b(i,o,this.nodeProvider))return!0}catch{}return!1}getBlueIdForSchema(e){if(u.isNullable(e))return null;const t=ae.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())?this.mapToCurrent(t.getBlueId()):u.isNonNullable(t)?this.mapToCurrent(T.calculateBlueIdSync(t)):null}mapToCurrent(e){return u.isNullable(e)?null:this.toCurrentBlueIdFn?this.toCurrentBlueIdFn(e):e}getBlueIdMap(){return new Map(this.blueIdMap)}}const w={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 Se{static isEmptyNode(e){return this.hasFieldsAndMayHaveFields(e)}static hasBlueIdOnly(e){return this.hasFieldsAndMayHaveFields(e,new Set([w.BLUE_ID]))}static hasItemsOnly(e){return this.hasFieldsAndMayHaveFields(e,new Set([w.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(z)).setValue(e)}static integerNode(e){const t=e instanceof B?e:new B(e.toString());return new d().setType(new d().setBlueId(U)).setValue(t)}static doubleNode(e){const t=e instanceof P?e:new P(e.toString());return new d().setType(new d().setBlueId(L)).setValue(t)}static booleanNode(e){return new d().setType(new d().setBlueId(k)).setValue(e)}static hasFieldsAndMayHaveFields(e,t=new Set,r=new Set){for(const n of Object.values(w)){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 w.NAME:return e.getName();case w.TYPE:return e.getType();case w.VALUE:return e.getValue();case w.DESCRIPTION:return e.getDescription();case w.PROPERTIES:return e.getProperties();case w.BLUE:return e.getBlue();case w.ITEMS:return e.getItems();case w.KEY_TYPE:return e.getKeyType();case w.VALUE_TYPE:return e.getValueType();case w.ITEM_TYPE:return e.getItemType();case w.BLUE_ID:return e.getBlueId();default:throw new Error(`Unknown field: ${t}`)}}}class Ae{}class re{static convert(e){const t=new ze;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 g=`${t}/${a}`;re.traverseNode(p,g,r)}if(i)for(let a=0;a<i.length;a++){const p=`${t}/${a}`;re.traverseNode(i[a],p,r)}}}function lt(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 Ve extends Ae{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=lt(e,"/"),n=lt(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 ze().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 ze().addPath(e).build()}static fromNode(e){return re.convert(e)}}class ze{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 Ve(this.allowedPaths,this.maxDepth)}}class rs extends Ae{shouldExtendPathSegment(){return!0}shouldMergePathSegment(){return!0}enterPathSegment(){}exitPathSegment(){}}class Ce extends Ae{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 Ce(e)}}const K=new rs;class ss{blue;constructor(e){this.blue=e}matchesType(e,t,r=K){const n=t.getType();if(this.matchesImplicitStructure(e,n))return!0;const i=Ve.fromNode(t),o=Ce.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,g]of Object.entries(i)){const f=a[p];f===void 0?a[p]=g.clone():this.restoreMissingStructure(f,g)}}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 f=e.getType();if(!f||!b(f,r,this.blue.getNodeProvider()))return!1}const i=t.getBlueId();if(!n&&i!==void 0){const f=e.getBlueId(),h=e.getType()?.getBlueId();if(f!==void 0){if(i!==f)return!1}else if(h===void 0||i!==h)return!1}const o=t.getValue();if(o!==void 0){const f=e.getValue();if(f===void 0)return!1;if(S(f)&&S(o)){if(!f.eq(o))return!1}else if(f!==o)return!1}const l=t.getItems();if(l!==void 0){const f=e.getItems()??[];for(let h=0;h<l.length;h++)if(h<f.length){if(!this.recursiveValueComparison(f[h],l[h]))return!1}else if(this.hasValueInNestedStructure(l[h]))return!1}const a=t.getItemType();if(a!==void 0){const f=e.getItems()??[];for(const h of f)if(!this.recursiveValueComparison(h,a))return!1}const p=t.getProperties();if(p!==void 0){const f=e.getProperties()??{};for(const[h,y]of Object.entries(p))if(h in f){if(!this.recursiveValueComparison(f[h],y))return!1}else if(this.hasValueInNestedStructure(y))return!1}const g=t.getValueType();if(g!==void 0){const f=Object.values(e.getProperties()??{});for(const h of f)if(!this.recursiveValueComparison(h,g))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:zt(t,this.blue.getNodeProvider())?this.isImplicitListStructure(e):Lt(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 ns=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,is=s=>s instanceof c.ZodString||s instanceof c.ZodNumber||s instanceof c.ZodBoolean||s instanceof c.ZodBigInt;class kt{static convertValue(e,t){const r=e.getType()?.getBlueId(),n=e.getValue();return u.isNullable(n)?is(t)&&Se.isValidValueNode(e)?this.getDefaultPrimitiveValue(t):n:z===r?this.convertFromString(String(n),t):L===r||n instanceof P?this.convertFromBigDecimal(new P(n?.toString()),t):U===r||n instanceof B?this.convertFromBigInteger(new B(n?.toString()),t):k===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 os{convert(e,t){return kt.convertValue(e,t)}}class ls{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=Mt(l);if(u.isNonNullable(a)){const y=V.isString(a)?a:i,N=o?.[y],C=N?T.calculateBlueIdSync(N):void 0;return n[i]=C,n}const p=xt(l);if(u.isNonNullable(p)){const y=o?.[p];return n[i]=y?.getName(),n}const g=Ot(l);if(u.isNonNullable(g)){const y=o?.[g];return n[i]=y?.getDescription(),n}if(i==="name"){const y=e.getName();return n[i]=y,n}if(i==="description"){const y=e.getDescription();return n[i]=y,n}const f=o?.[i];if(u.isNullable(f))return n;const h=this.nodeToObjectConverter.convert(f,l);return n[i]=h,n},{});throw new Error("Unknown schema type, "+t._def.typeName)}}class as{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 us{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 cs{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(J,l);const a=e.getProperties();return u.isNonNullable(a)&&Object.entries(a).forEach(([p,g])=>{const f=new d().setValue(p);f.setType(new d().setBlueId(z));const h=kt.convertValue(f,r),y=this.nodeToObjectConverter.convert(g,n);i.set(h,y)}),t instanceof c.ZodRecord?Object.fromEntries(i):i}}class ds{convert(e){return I.get(e)}}class ps{convert(e){return I.get(e)}}class fs{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 hs=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 ys{constructor(e){this.nodeToObjectConverter=e,this.registerConverters(),this.complexObjectConverter=new ls(this.nodeToObjectConverter)}converters=new Map;complexObjectConverter;registerConverters(){const e=new os,t=new as(this.nodeToObjectConverter),r=new fs(this.nodeToObjectConverter),n=new us(this.nodeToObjectConverter),i=new cs(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 ds),this.converters.set("ZodAny",new ps),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(ns(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 hs.parse(t)}catch{throw new Error(`Schema type name ${t} is not supported`)}}}class gs{constructor(e){this.typeSchemaResolver=e,this.converterFactory=new ys(this)}converterFactory;convert(e,t){const r=this.typeSchemaResolver?.resolveSchema(e),n=A.unwrapSchema(t);if(tt(n))return e;let i=n;return A.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 Kt{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=T.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),Se.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 f=r.getProperties()||{};for(const[h,y]of Object.entries(p))f[h]=y.clone();r.setProperties(f)}const g=t.getItems();return u.isNonNullable(g)&&r.setItems(g.map(f=>f.clone())),r}}class Q extends d{constructor(e){super(e.getName()),this.createFrom(e)}isResolved(){return!0}getMinimalNode(){return new Kt().reverse(this)}getMinimalBlueId(){const e=this.getMinimalNode();return T.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 ye{fetchFirstByBlueId(e){const t=this.fetchByBlueId(e);return t&&t.length>0?t[0]:null}}function ms(s){return new class extends ye{fetchByBlueId(e){return s(e)}}}const Fe=G.types.float.options,Is={...Fe,construct:s=>{const e=s.replace(/_/g,"").toLowerCase();if(!u.isPreciseNumberString(e))return new P(e);if(Fe.construct)return Fe.construct(s)}},Ts=new G.Type("tag:yaml.org,2002:float",Is),xe=G.types.int.options,bs={...xe,construct:s=>{let e=s;if(e.indexOf("_")!==-1&&(e=e.replace(/_/g,"")),!u.isPreciseNumberString(e))return new B(e);if(xe.construct)return xe.construct(s)}},Ns=new G.Type("tag:yaml.org,2002:int",bs),Zt=G.CORE_SCHEMA.extend({implicit:[Ts,Ns]}),M=s=>{const e=G.load(s,{schema:Zt});return e===void 0?void 0:e},Yt=s=>G.dump(s,{schema:Zt,replacer:(e,t)=>{if(S(t)){if(_(t)){const r=new x(Number.MIN_SAFE_INTEGER.toString()),n=new x(Number.MAX_SAFE_INTEGER.toString());if(t.lt(r)||t.gt(n))return t.toString()}return t.toNumber()}return t}});class vs{static get(e,t={}){const{strategy:r="official"}=t,n=I.get(e,r);return Yt(n)}}class Bs extends ye{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 Jt=`- type:
|
|
2
2
|
blueId: 27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo
|
|
3
3
|
mappings:
|
|
4
4
|
Text: DLRQwz7MQeCrzjy9bohPNwtCxKEBbKaMK65KBrwjfG6K
|
|
@@ -9,19 +9,16 @@
|
|
|
9
9
|
Dictionary: G7fBT9PSod1RfHLHkpafAGBDVAJMrMhAMY51ERcyXNrj
|
|
10
10
|
- type:
|
|
11
11
|
blueId: FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4
|
|
12
|
-
`,
|
|
13
|
-
description: TODO`,
|
|
12
|
+
`,ws=`name: Transformation
|
|
13
|
+
description: TODO`,Es=`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.`,Ps=`name: Replace Inline Types with BlueIds
|
|
17
17
|
type:
|
|
18
18
|
blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
|
|
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(`
|
|
19
|
+
description: This transformation replaces`,Ss=[Jt,ws,Es,Ps];class As extends ye{blueIdToNodesMap=new Map;constructor(){super(),this.load()}fetchByBlueId(e){return this.blueIdToNodesMap.get(e)||[]}load(){for(const e of Ss){const t=M(e);if(t===void 0){console.error(`This content file is not valid YAML: ${e}`);continue}if(Array.isArray(t)){const r=t.map(i=>m.deserialize(i)),n=T.calculateBlueIdSync(r);this.blueIdToNodesMap.set(n,r)}else{const r=m.deserialize(t),n=T.calculateBlueIdSync(r);this.blueIdToNodesMap.set(n,[r])}}}}class rt extends ye{static INSTANCE=new rt;nodeProvider;constructor(){super(),this.nodeProvider=new As}fetchByBlueId(e){return this.nodeProvider.fetchByBlueId(e)}}class $e{constructor(e,t,r){this.blueId=e,this.content=t,this.isMultipleDocuments=r}}class W{static THIS_REFERENCE_PATTERN=/^this(#\d+)?$/;static parseAndCalculateBlueId(e,t){let r;try{const l=M(e);if(l===void 0)throw new Error;r=l}catch{throw new Error("Failed to parse content as YAML or JSON")}let n,i;const o=Array.isArray(r)&&r.length>1;if(o){const l=r.map(a=>{const p=m.deserialize(a);return t(p)});n=T.calculateBlueIdSync(l),i=l.map(a=>I.get(a))}else{const l=m.deserialize(r),a=t(l);n=T.calculateBlueIdSync(a),i=I.get(a)}return new $e(n,i,o)}static parseAndCalculateBlueIdForNode(e,t){const r=t(e),n=T.calculateBlueIdSync(r),i=I.get(r);return new $e(n,i,!1)}static parseAndCalculateBlueIdForNodeList(e,t){if(!e||e.length===0)throw new Error("List of nodes cannot be null or empty");const r=e.map(t),n=T.calculateBlueIdSync(r),i=r.map(l=>I.get(l)),o=e.length>1;return new $e(n,i,o)}static resolveThisReferences(e,t,r){return this.resolveThisReferencesRecursive(e,t,r)}static resolveThisReferencesRecursive(e,t,r){if(e&&typeof e=="object"&&!Array.isArray(e)){const n={};for(const[i,o]of Object.entries(e))typeof o=="string"?this.THIS_REFERENCE_PATTERN.test(o)?n[i]=this.resolveThisReference(o,t,r):n[i]=o:o&&typeof o=="object"?n[i]=this.resolveThisReferencesRecursive(o,t,r):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,r):n:n&&typeof n=="object"?this.resolveThisReferencesRecursive(n,t,r):n);return e}static resolveThisReference(e,t,r){if(r){if(!e.startsWith("this#"))throw new Error("For multiple documents, 'this' references must include an index (e.g., 'this#0')");return t+e.substring(4)}else{if(e==="this")return t;throw new Error("For a single document, only 'this' is allowed as a reference, not 'this#<id>'")}}}class Vs extends ye{fetchByBlueId(e){const t=e.split("#")[0],r=this.fetchContentByBlueId(t);if(r==null)return null;const n=Array.isArray(r)&&r.length>1,i=W.resolveThisReferences(r,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=m.deserialize(a);return p.setBlueId(e),[p]}else if(l===0){const a=m.deserialize(i);return a.setBlueId(e),[a]}else return null}}if(Array.isArray(i))return i.map(o=>m.deserialize(o));{const o=m.deserialize(i);return o.setBlueId(t),[o]}}}class Gt extends Vs{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 r=this.fetchByBlueId(t[0]);return r&&r.length>0?r[0]:void 0}findAllNodesByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t)return[];const r=[];for(const n of t){const i=this.fetchByBlueId(n);i&&r.push(...i)}return r}addToNameMap(e,t){this.nameToBlueIdsMap.set(e,[...this.nameToBlueIdsMap.get(e)||[],t])}}class Cs extends Gt{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;toCurrentBlueId;constructor(e,t){super(),this.toCurrentBlueId=t,this.loadRepositories(e)}loadRepositories(e){for(const t of e)Object.values(t.packages).forEach(r=>{for(const[n,i]of Object.entries(r.contents))this.storeContent(n,i),this.indexNameMappings(n,i)})}storeContent(e,t){this.blueIdToContentMap.set(e,t),this.blueIdToMultipleDocumentsMap.set(e,Array.isArray(t))}indexNameMappings(e,t){if(Array.isArray(t)){t.forEach((i,o)=>{const a=m.deserialize(i).getName();a&&this.addToNameMap(a,`${e}#${o}`)});return}const n=m.deserialize(t).getName();n&&this.addToNameMap(n,e)}fetchContentByBlueId(e){const t=this.toCurrentBlueId?.(e)??e,r=this.blueIdToContentMap.get(t),n=this.blueIdToMultipleDocumentsMap.get(t);return r!==void 0&&n!==void 0?W.resolveThisReferences(r,t,n):null}fetchByBlueId(e){const t=e.split("#")[0],r=this.toCurrentBlueId?.(t)??t,n=this.blueIdToContentMap.get(r),i=this.blueIdToMultipleDocumentsMap.get(r);if(n===void 0||i===void 0)return null;const o=W.resolveThisReferences(n,r,i);if(e.includes("#")){const l=e.split("#");if(l.length>1){const a=parseInt(l[1]);if(Array.isArray(o)&&a<o.length){const p=o[a],g=m.deserialize(p);return g.setBlueId(e),[g]}else if(a===0){const p=m.deserialize(o);return p.setBlueId(e),[p]}return null}}if(Array.isArray(o))return o.map((l,a)=>{const p=m.deserialize(l);return p.setBlueId(`${t}#${a}`),p});{const l=m.deserialize(o);return l.setBlueId(t),[l]}}getBlueIds(){return Array.from(this.blueIdToContentMap.keys())}hasBlueId(e){const t=e.split("#")[0],r=this.toCurrentBlueId?.(t)??t;return this.blueIdToContentMap.has(r)}}class ue{static wrap(e,t,r){const n=[rt.INSTANCE];if(t&&t.length>0){const i=new Cs(t,r?.toCurrentBlueId);n.push(i)}return n.push(e),new Bs(n)}}const Ht=s=>s instanceof d||Array.isArray(s)&&s.every(e=>e instanceof d)?s:V.isArray(s)?s.map(e=>m.deserialize(e)):m.deserialize(s),Wt=async s=>{const e=Ht(s);return T.calculateBlueId(e)},Rs=s=>{const e=Ht(s);return T.calculateBlueIdSync(e)},Le=async s=>{if(bt(s))return s;try{const e=le.parse(s),t=await Wt(e);return{...s,blueId:t}}catch(e){throw new Error(`Failed enriching object with Blue ID: ${e}`)}},Os=s=>s?.items,Ds=s=>s?.value,Ms=s=>u.isNullable(s)?{}:V.omit(s,Ke),Fs=s=>vt(s)?s.type.name??null:Bt(s)?V.pascal(typeof s.value):Nt(s)?"List":null,qt=s=>u.isNonNullable(s)&&Object.keys(V.omit(s,["blueId"])).length>0,xs=s=>{try{const e=m.deserialize(s),t=I.get(e);return q.parse(t)}catch(e){throw new Error(`Failed transforming JSON-like value to BlueObject: ${e}`)}},Ue=async s=>{const{resolveFunction:e,signal:t=new AbortController().signal,omitItems:r}=s,n=s.count??s.items.length;let i=await V.map(s.items,async l=>await Le(l));const o=Math.max(i?.length-n,0);for(let l=i.length-1;l>=o;l--)if(!qt(i[l])){const a=await e(i[l],{signal:t});if(Array.isArray(a))return Ue({...s,items:[...i.slice(0,l),...a,...i.slice(l+1)]});const p=await Le(a);if(r?.includes(p.blueId))return Ue({...s,items:[...i.slice(0,l),...i.slice(l+1)]});i=[...i.slice(0,l),p,...i.slice(l+1)]}return i};function se(s){try{const e=new URL(s);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}class $s{process(e){return v.transform(e,this.inferType.bind(this))}inferType(e){const t=e.getType(),r=e.getValue();return u.isNullable(t)&&u.isNonNullable(r)&&(typeof r=="string"?e.setType(new d().setBlueId(z)):typeof r=="bigint"||_(r)?e.setType(new d().setBlueId(U)):Ie(r)?e.setType(new d().setBlueId(L)):typeof r=="boolean"&&e.setType(new d().setBlueId(k))),e}}class ce{static MAPPINGS="mappings";mappings=new Map;constructor(e){if(e instanceof d){const r=e.getProperties();if(r&&r[ce.MAPPINGS]){const i=r[ce.MAPPINGS].getProperties();i&&Object.entries(i).forEach(([o,l])=>{const a=l.getValue();typeof a=="string"&&this.mappings.set(o,a)})}}else this.mappings=e}process(e){return v.transform(e,this.transformNode.bind(this))}transformNode(e){const t=e.clone();return this.transformTypeField(t,t.getType()),this.transformTypeField(t,t.getItemType()),this.transformTypeField(t,t.getKeyType()),this.transformTypeField(t,t.getValueType()),t}transformTypeField(e,t){if(t&&t.isInlineValue()&&t.getValue()!==void 0){const r=String(t.getValue());if(this.mappings.has(r)){const n=this.mappings.get(r);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 _s{process(e){return v.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,r){if(t&&t.isInlineValue()&&t.getValue()!==void 0){const n=String(t.getValue());throw new Error(`Unknown type "${n}" found in ${r} field. No BlueId mapping exists for this type.`)}}}class st{nodeProvider;strategy;constructor(e,t){this.nodeProvider=ue.wrap(e),this.strategy=t||"THROW_EXCEPTION"}extend(e,t){this.extendNode(e,t,"")}extendNode(e,t,r,n=!1){if(!n){if(!t.shouldExtendPathSegment(r,e))return;t.enterPathSegment(r,e)}try{const i=e.getBlueId();if(i&&!H.includes(i)){const h=this.fetchNode(e);if(h&&h.length>0)if(h.length===1){const y=h[0];this.mergeNodes(e,y)}else{const y=h.map(C=>C.clone()),N=new d().setItems(y);this.mergeNodes(e,N)}}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 g=e.getProperties();g&&Object.entries(g).forEach(([h,y])=>{this.extendNode(y,t,h,!1)});const f=e.getItems();if(f&&f.length>0){this.reconstructList(f);for(let h=0;h<f.length;h++)this.extendNode(f[h],t,String(h),!1)}}finally{n||t.exitPathSegment()}}reconstructList(e){for(;e.length>0;){const r=e[0]?.getBlueId();if(!r)break;const n=this.nodeProvider.fetchByBlueId(r);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 r=this.nodeProvider.fetchByBlueId(t);if(!r||r.length===0){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No content found for blueId: ${e.getBlueId()}`)}return r}mergeNodes(e,t){e.setName(t.getName()),e.setDescription(t.getDescription()),e.setType(t.getType()),e.setItemType(t.getItemType()),e.setKeyType(t.getKeyType()),e.setValueType(t.getValueType());const r=t.getValue();u.isNonNullable(r)&&e.setValue(r),e.setItems(t.getItems()),e.setProperties(t.getProperties())}}class de{static DEFAULT_BLUE_BLUE_ID="6sqUywMoBRyj9hgQxSu2nDPnqcyiSM7xu9AB9sN98YJK";processorProvider;nodeProvider;defaultSimpleBlue=null;constructor(e={}){const{nodeProvider:t,processorProvider:r}=e;if(!t)throw new Error("NodeProvider is required");this.nodeProvider=ue.wrap(t),this.processorProvider=r||de.getStandardProvider(),this.loadDefaultSimpleBlue()}preprocess(e){return this.preprocessWithOptions(e,null)}preprocessWithDefaultBlue(e){return this.preprocessWithOptions(e,this.defaultSimpleBlue)}preprocessWithOptions(e,t){let r=e.clone(),n=r.getBlue();if(!n&&t&&(n=t.clone()),n){new st(this.nodeProvider).extend(n,Ve.withSinglePath("/*"));const i=n.getItems();if(i&&i.length>0){for(const o of i){const l=this.processorProvider.getProcessor(o);if(l)r=l.process(r);else throw new Error(`No processor found for transformation: ${o}`)}r.setBlue(void 0)}r=new _s().process(r)}return r}static getStandardProvider(){return{getProcessor(e){const t="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo",r="FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4",n=e.getType()?.getBlueId();if(t===n)return new ce(e);if(r===n)return new $s}}}loadDefaultSimpleBlue(){try{const e=M(Jt);if(e)this.defaultSimpleBlue=m.deserialize(e);else throw new Error("Failed to parse default Blue content")}catch(e){throw new Error(`Error loading default Blue: ${e}`)}}}class js{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 r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(me.isPotentialBlueId(t))return this.handleBlueId(r,t);throw se(t)?new Error(`URL '${t}' detected. Use the async version of this method to fetch the content.`):new Error(`Invalid blue value: ${t}`)}return e}async processAsync(e){const t=this.getBlueNodeValue(e);if(t){const r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(me.isPotentialBlueId(t))return this.handleBlueId(r,t);if(se(t)&&this.urlContentFetcher)try{const n=await this.fetchFromUrl(t);return n&&r.setBlue(new d().setItems(n)),r}catch(n){throw n instanceof Error?new Error(`Failed to fetch from URL '${t}'.
|
|
20
|
+
${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 zs={fetchUrl:async s=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${s}`)}};class Ls{cache=new Map;fetchStrategy;enabled=!1;allowedDomains=[];constructor(e){this.fetchStrategy=e||zs}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=>m.deserialize(l)):o=[m.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 Us{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 r=Object.entries(t).map(([n,i])=>` ${n}: ${i}`).join(`
|
|
20
21
|
`);return`- type:
|
|
21
22
|
blueId: ${e}
|
|
22
23
|
mappings:
|
|
23
|
-
${s}`}getAllBlueIds(){const e={};for(const t of this.blueIdsCollections)Object.assign(e,t);return e}getAllBlueIdNames(){return Object.keys(this.getAllBlueIds())}clear(){this.blueIdsCollections=[]}getCollectionCount(){return this.blueIdsCollections.length}getTotalBlueIdCount(){return Object.keys(this.getAllBlueIds()).length}}class X{static DEFAULT_BLUE_BLUE_ID="6sqUywMoBRyj9hgQxSu2nDPnqcyiSM7xu9AB9sN98YJK";processorProvider;nodeProvider;defaultSimpleBlue=null;blueIdsMappingGenerator;constructor(e={}){const{nodeProvider:t,processorProvider:s,blueIdsMappingGenerator:n}=e;if(!t)throw new Error("NodeProvider is required");this.nodeProvider=oe.wrap(t),this.processorProvider=s||X.getStandardProvider(),this.blueIdsMappingGenerator=n||new 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
|
-
${e}
|
|
25
|
-
${t}
|
|
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;
|
|
24
|
+
${r}`}getAllBlueIds(){const e={};for(const t of this.blueIdsCollections)Object.assign(e,t);return e}getAllBlueIdNames(){return Object.keys(this.getAllBlueIds())}clear(){this.blueIdsCollections=[]}getCollectionCount(){return this.blueIdsCollections.length}getTotalBlueIdCount(){return Object.keys(this.getAllBlueIds()).length}}class Xt{resolveWithoutLimits(e){return this.resolve(e,K)}}class Qt extends Xt{mergingProcessor;nodeProvider;constructor(e,t){super(),this.mergingProcessor=e,this.nodeProvider=ue.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 st(this.nodeProvider).extend(o,Ve.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=T.calculateBlueIdSync(t[o]),a=T.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 er{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 tr{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(!ks(r,n))throw new Error(`Node values conflict. Source node value: ${r}, target node value: ${n}`)}return e}}const ks=(s,e)=>_(s)&&_(e)||Ie(s)&&Ie(e)?s.eq(e):s===e;class rr{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(!b(i,n,r)){const a=I.get(i),p=I.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 sr{process(e,t,r){const n=t.getItemType(),i=t.getType();if(n!==void 0&&i!==void 0&&!zt(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(!b(n,o,r)){const f=I.get(n),h=I.get(o);throw new Error(`The source item type '${JSON.stringify(f)}' is not a subtype of the target item type '${JSON.stringify(h)}'.`)}l=e.clone().setItemType(n)}const a=l.getItemType(),p=t.getItems();if(a!==void 0&&p!==void 0)for(const g of p){const f=g.getType();if(f!==void 0&&!b(f,a,r)){const h=I.get(f),y=I.get(a);throw new Error(`Item of type '${JSON.stringify(h)}' is not a subtype of the list's item type '${JSON.stringify(y)}'.`)}}return l}}class nr{process(e,t,r){const n=t.getKeyType(),i=t.getValueType(),o=t.getType();if((n!==void 0||i!==void 0)&&o!==void 0&&!Lt(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(),g=t.getProperties();return(a!==void 0||p!==void 0)&&g!==void 0&&Object.entries(g).forEach(([f,h])=>{a!==void 0&&this.validateKeyType(f,a,r),p!==void 0&&this.validateValueType(h,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),!b(i,n,r)){const l=I.get(i),a=I.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(!b(i,n,r)){const l=I.get(i),a=I.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(!Hr(e,t))throw new Error("Dictionary key type must be a basic type")}validateKeyType(e,t,r){if(!Wr(t,r))if(qr(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(Xr(t,r)){const n=Number.parseFloat(e);if(Number.isNaN(n))throw new Error(`Key '${e}' is not a valid Number.`)}else if(Qr(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&&!b(n,t,r)){const i=I.get(n),o=I.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 ir{process(e){return e}postProcess(e,t,r){const n=e.getType();if(n!==void 0&&es(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=ts(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 or{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 Ks=Object.freeze(Object.defineProperty({__proto__:null,BasicTypesVerifier:ir,DictionaryProcessor:nr,ListProcessor:sr,MetadataPropagator:or,SequentialMergingProcessor:er,TypeAssigner:rr,ValuePropagator:tr},Symbol.toStringTag,{value:"Module"}));function Zs(){return new er([new tr,new rr,new sr,new nr,new or,new ir])}class Ys{nodeProvider;blueIdToInlineValue=new Map;constructor(e){const{nodeProvider:t,blueIdsMappingGenerator:r}=e;this.nodeProvider=t,Object.entries(He).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 v.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 Js{runtimes;contents;aliases;constructor(e){const t=[];for(const r of e)t.push(Gs(r));this.runtimes=t,this.contents={},this.aliases={};for(const r of this.runtimes)Qs(this.contents,r.contents,r.name),Xs(this.aliases,r.aliases,r.name)}getRuntimes(){return this.runtimes}getAliases(){return this.aliases}getContents(){return this.contents}findRuntimeByName(e){return this.runtimes.find(t=>t.name===e)}toCurrentBlueId(e){for(const t of this.runtimes){const r=t.toCurrentBlueIdIndex[e];if(r)return r}return e}findRuntimeByBlueId(e){const t=this.toCurrentBlueId(e);for(const r of this.runtimes){const n=r.types[t];if(n)return{runtime:r,currentBlueId:t,typeMeta:n,typeAlias:r.typeAliasByCurrentBlueId[t]}}}}function Gs(s){const e={},t={},r={},n={},i=[],o={},l={},a=new Set,p=Object.fromEntries(s.repositoryVersions.map((f,h)=>[f,h]));Object.values(s.packages).forEach(f=>{if(a.has(f.name))throw new Error(`Duplicate package name detected: ${f.name}`);a.add(f.name),Object.entries(f.aliases).forEach(([y,N])=>{if(e[y]&&e[y]!==N)throw new Error(`Conflicting alias mapping for ${y}`);e[y]=N});const h=f.typesMeta;Object.entries(h).forEach(([y,N])=>{if(t[y])throw new Error(`Duplicate type mapping for BlueId ${y}`);const C=Hs(N,s,y,f.name);if(t[y]=C,l[y]=f.name,o[y]=`${f.name}/${N.name}`,C.status==="stable"&&!r[y]&&(r[y]=y),C.status==="stable")for(const R of C.versions){const ge=r[R.typeBlueId];if(ge&&ge!==y)throw new Error(`Conflicting toCurrentBlueIdIndex mapping for ${R.typeBlueId}`);r[R.typeBlueId]=y}}),Object.entries(f.contents).forEach(([y,N])=>{n[y]=N}),i.push(...Object.values(f.schemas))});const g=s.repositoryVersions[s.repositoryVersions.length-1];return{name:s.name,repositoryVersions:s.repositoryVersions,repoVersionIndexById:p,aliases:e,types:t,toCurrentBlueIdIndex:r,contents:n,schemas:i,currentRepoBlueId:g,typeAliasByCurrentBlueId:o,typePackageByCurrentBlueId:l}}function Hs(s,e,t,r){if(s.status==="dev")return Ws(s,e,t,r),{...s,versions:s.versions?[...s.versions]:s.versions};const n=[...s.versions??[]].sort((o,l)=>o.repositoryVersionIndex-l.repositoryVersionIndex);if(n.length===0)throw new Error(`Stable type ${r}/${s.name} (${t}) must have at least one version entry`);const i=new Set;return n.forEach(o=>{if(o.repositoryVersionIndex<0||o.repositoryVersionIndex>=e.repositoryVersions.length)throw new Error(`Invalid repositoryVersionIndex ${o.repositoryVersionIndex} for ${r}/${s.name}`);if(i.has(o.repositoryVersionIndex))throw new Error(`Duplicate repositoryVersionIndex ${o.repositoryVersionIndex} for ${r}/${s.name}`);i.add(o.repositoryVersionIndex);for(const l of o.attributesAdded??[])qs(l,e.name,t,o.repositoryVersionIndex)}),{...s,versions:n}}function Ws(s,e,t,r){if(s.status==="dev"){if(s.versions&&s.versions.length>1)throw new Error(`Dev type ${r}/${s.name} (${t}) must not declare multiple versions`);if(s.versions&&s.versions.length===1){const n=s.versions[0];if(n.repositoryVersionIndex<0||n.repositoryVersionIndex>=e.repositoryVersions.length)throw new Error(`Invalid repositoryVersionIndex ${n.repositoryVersionIndex} for dev type ${r}/${s.name}`)}}}function qs(s,e,t,r){try{pt.validateAttributesAddedPointer(s)}catch(n){const i=n instanceof Error?n.message:"Unknown error";throw new Error(`Invalid attributesAdded pointer '${s}' for type ${t} in repository ${e} at index ${r}: ${i}`)}}function Xs(s,e,t){for(const[r,n]of Object.entries(e)){const i=s[r];if(i&&i!==n)throw new Error(`Conflicting alias '${r}' across repositories: '${i}' vs '${n}' (from ${t})`);s[r]=n}}function Qs(s,e,t){for(const[r,n]of Object.entries(e)){if(r in s){const i=s[r];if(!ke(i,n))throw new Error(`Conflicting content for BlueId '${r}' across repositories (from ${t})`);continue}s[r]=n}}function ke(s,e){if(s===e)return!0;if(Array.isArray(s)&&Array.isArray(e))return s.length===e.length&&s.every((t,r)=>ke(t,e[r]));if(typeof s=="object"&&s!==null&&typeof e=="object"&&e!==null&&!Array.isArray(s)&&!Array.isArray(e)){const t=Object.keys(s),r=Object.keys(e);if(t.length!==r.length)return!1;t.sort(),r.sort();for(let n=0;n<t.length;n++)if(t[n]!==r[n])return!1;for(const n of t){const i=s[n],o=e[n];if(!ke(i,o))return!1}return!0}return!1}class be extends Error{code;details;constructor(e,t,r){super(t),this.code=e,this.details=r&&r.length>0?r:[],this.name="BlueError"}}const F={REPO_UNKNOWN_REPO_BLUE_ID:"REPO_UNKNOWN_REPO_BLUE_ID",REPO_UNREPRESENTABLE_IN_TARGET_VERSION:"REPO_UNREPRESENTABLE_IN_TARGET_VERSION",INVALID_BLUE_CONTEXT_REPOSITORIES:"INVALID_BLUE_CONTEXT_REPOSITORIES",INVALID_REPOSITORY_POINTER:"INVALID_REPOSITORY_POINTER"};function en(s,e){const t=s.filter(n=>n.repositoryVersionIndex>e).sort((n,i)=>i.repositoryVersionIndex-n.repositoryVersionIndex),r=[];for(const n of t){const i=[...n.attributesAdded].sort((o,l)=>at(l)-at(o));r.push(...i)}return r}function at(s){return s.startsWith("/")?s.split("/").slice(1).map(e=>e.replace(/~1/g,"/").replace(/~0/g,"~")).length:0}class tn{registry;targetRepoVersionIndexes;fallbackToCurrentInlineDefinitions;inliningStack=new Set;constructor(e){this.registry=e.registry,this.targetRepoVersionIndexes=e.targetRepoVersionIndexes,this.fallbackToCurrentInlineDefinitions=e.fallbackToCurrentInlineDefinitions}transform(e){return v.transform(e,t=>this.transformNode(t))}transformNode(e){return this.processTypeReference(e,{getter:()=>e.getType(),setter:t=>e.setType(t),dropTargets:[e]}),this.processTypeReference(e,{getter:()=>e.getItemType(),setter:t=>e.setItemType(t),dropTargets:e.getItems()??[]}),this.processTypeReference(e,{getter:()=>e.getKeyType(),setter:t=>e.setKeyType(t),dropTargets:[]}),this.processTypeReference(e,{getter:()=>e.getValueType(),setter:t=>e.setValueType(t),dropTargets:this.getDictionaryValueTargets(e)}),e}processTypeReference(e,t){const r=t.getter(),n=r?.getBlueId();if(!r||!n)return;const i=this.resolveType(n);switch(i.kind){case"core":{r.setBlueId(i.blueId);return}case"representable":{this.applyDropPointers(t.dropTargets,i.dropPointers),r.setBlueId(i.targetBlueId);return}case"no-runtime":case"no-target-context":case"unrepresentable":{if(this.fallbackToCurrentInlineDefinitions){this.inlineDefinition(e,t.setter,n);return}throw i.kind==="unrepresentable"?i.error:this.unrepresentableError(n,i.kind==="no-target-context"?`Repository '${i.runtimeName}' not provided in BlueContext.`:"Type does not belong to any declared repository.",i.kind==="no-target-context"?i.runtime:void 0,i.kind==="no-target-context"?i.meta:void 0,void 0,i.kind==="no-target-context"?i.typeAlias:void 0)}}}resolveType(e){if(H.includes(e))return{kind:"core",blueId:e};const t=this.registry.toCurrentBlueId(e),r=this.registry.findRuntimeByBlueId(t);if(!r||!r.typeMeta)return{kind:"no-runtime"};const n=this.targetRepoVersionIndexes[r.runtime.name];if(n===void 0)return{kind:"no-target-context",currentBlueId:t,runtimeName:r.runtime.name,runtime:r.runtime,meta:r.typeMeta,typeAlias:r.typeAlias};const i=r.typeMeta;if(i.status==="dev"){const g=r.runtime.repositoryVersions.length-1;if(n!==g)return{kind:"unrepresentable",currentBlueId:t,error:this.unrepresentableError(t,`Dev type cannot be represented at repository version index ${n}.`,r.runtime,i,n,r.typeAlias)};const f=i.versions?.[0];return{kind:"representable",currentBlueId:t,targetBlueId:f?.typeBlueId??t,dropPointers:[]}}const o=i.versions||[];if(o.length===0)return{kind:"unrepresentable",currentBlueId:t,error:this.unrepresentableError(t,`Stable type metadata missing versions for ${t}.`,r.runtime,i,n,r.typeAlias)};const l=o[0].repositoryVersionIndex;if(n<l)return{kind:"unrepresentable",currentBlueId:t,error:this.unrepresentableError(t,`Type introduced after target repository version index ${n}.`,r.runtime,i,n,r.typeAlias)};let a=o[0].typeBlueId;for(const g of o)g.repositoryVersionIndex<=n&&(a=g.typeBlueId);const p=i.status==="stable"?this.getDropPointers(i,n):[];return{kind:"representable",currentBlueId:t,targetBlueId:a,dropPointers:p}}getDropPointers(e,t){return e.status!=="stable"?[]:en(e.versions,t)}applyDropPointers(e,t){for(const r of t)for(const n of e)this.deletePropertyAtPointer(n,r)}getDictionaryValueTargets(e){const t=e.getProperties();if(!t)return[];const r=new Set([...Ke,"schema","mergePolicy","contracts"]);return Object.entries(t).filter(([n,i])=>i instanceof d&&!r.has(n)).map(([,n])=>n)}deletePropertyAtPointer(e,t){let r;try{r=pt.parsePointer(t)}catch{throw this.invalidPointerError(t)}this.applyPointerSegments(e,r)}applyPointerSegments(e,t){if(t.length===0)return;const[r,...n]=t;if(r==="itemType"){const l=e.getItemType();l&&this.applyPointerSegments(l,n);const a=e.getItems();a&&a.forEach(p=>this.applyPointerSegments(p,n));return}if(r==="valueType"){const l=e.getValueType();l&&this.applyPointerSegments(l,n),this.getDictionaryValueTargets(e).forEach(p=>this.applyPointerSegments(p,n));return}const i=e.getProperties();if(!i)return;if(n.length===0){if(!(r in i))return;const l={...i};delete l[r],e.setProperties(l);return}const o=i[r];o instanceof d&&this.applyPointerSegments(o,n)}inlineDefinition(e,t,r){const n=this.registry.toCurrentBlueId(r);if(this.inliningStack.has(n))throw this.unrepresentableError(n,"Cycle detected while inlining type.",void 0,void 0,void 0,void 0,{cycle:Array.from(this.inliningStack).concat(n)});const i=this.registry.getContents()[n];if(!i)throw this.unrepresentableError(n,`Missing definition to inline for BlueId ${n}.`);this.inliningStack.add(n);try{const o=m.deserialize(i);o.setBlueId(void 0);const l=v.transform(o,a=>this.transformNode(a));return t(l),e}finally{this.inliningStack.delete(n)}}invalidPointerError(e){const t=`Invalid attributesAdded pointer '${e}'.`;return new be(F.INVALID_REPOSITORY_POINTER,t,[{code:F.INVALID_REPOSITORY_POINTER,severity:"error",message:t,locationPath:[],context:{pointer:e}}])}unrepresentableError(e,t,r,n,i,o,l){const a={currentTypeBlueId:e,targetRepoVersionIndex:i,typeAlias:o,...l};if(r&&(i!==void 0&&(a.requestedRepoBlueId=r.repositoryVersions[i]),a.serverRepoBlueId=r.currentRepoBlueId),n&&n.status==="stable"){const g=n.versions?.[0]?.repositoryVersionIndex;g!==void 0&&(a.typeIntroducedInRepoBlueId=r?.repositoryVersions[g])}const p={code:F.REPO_UNREPRESENTABLE_IN_TARGET_VERSION,severity:"error",message:t,locationPath:["type"],context:a};return new be(F.REPO_UNREPRESENTABLE_IN_TARGET_VERSION,t,[p])}}const rn=new Set(["__proto__","constructor","prototype"]);function ut(s){const e=s.at(0),t=s.at(-1);return!e||!t?s:e==="'"&&t==="'"||e==='"'&&t==='"'?s.slice(1,-1):s}function ct(s,e){const t=s.indexOf("=");if(t===-1)throw ne(e,`Missing '=' in segment '${s.trim()}'`);const r=ut(s.slice(0,t).trim()),n=ut(s.slice(t+1).trim());if(!r)throw ne(e,"Repository name is empty");if(!n)throw ne(e,`Repository BlueId is empty for '${r}'`);return{name:r,value:n}}function sn(s){const e=Object.create(null);let t="",r=null;for(let n=0;n<s.length;n++){const i=s[n];if((i==="'"||i==='"')&&r===null){r=i,t+=i;continue}if(r&&i===r){r=null,t+=i;continue}if(i===","&&r===null){if(t.trim().length>0){const{name:o,value:l}=ct(t,s);dt(o,s),e[o]=l}t="";continue}t+=i}if(t.trim().length>0){const{name:n,value:i}=ct(t,s);dt(n,s),e[n]=i}if(r!==null)throw ne(s,"Unterminated quoted repository name or id");return e}function nn(s){return typeof s=="string"?sn(s):s}function ne(s,e){return new be(F.INVALID_BLUE_CONTEXT_REPOSITORIES,`Invalid BlueContext repositories value: ${e}`,[{code:F.INVALID_BLUE_CONTEXT_REPOSITORIES,severity:"error",message:e,locationPath:[],context:{rawRepositories:s,reason:e}}])}function dt(s,e){if(rn.has(s))throw ne(e,`Forbidden repository name '${s}'`)}class on{nodeProvider;typeSchemaResolver;blueDirectivePreprocessor;urlContentFetcher;blueIdsMappingGenerator;globalLimits=K;mergingProcessor;repositories;repositoryRegistry;constructor(e={}){const{nodeProvider:t,typeSchemaResolver:r=null,urlFetchStrategy:n,repositories:i,mergingProcessor:o}=e;this.repositories=i,this.repositoryRegistry=new Js(i??[]);const l=ms(()=>[]);this.nodeProvider=ue.wrap(t||l,i,{toCurrentBlueId:this.toCurrentBlueId.bind(this)}),this.typeSchemaResolver=r??new Ut([],{nodeProvider:this.nodeProvider,toCurrentBlueId:this.toCurrentBlueId.bind(this)}),this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this.mergingProcessor=o??Zs(),this.urlContentFetcher=new Ls(n),this.blueDirectivePreprocessor=new js(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new Us,this.blueIdsMappingGenerator.registerBlueIds(this.repositoryRegistry.getAliases());const a=this.repositoryRegistry.getRuntimes().flatMap(p=>p.schemas);a.length>0&&this.typeSchemaResolver?.registerSchemas(a)}nodeToJson(e,t="official"){const r=this.normalizeNodeToJsonOptions(t),n=r.blueContext?this.transformForBlueContext(e,r.blueContext):e;return I.get(n,r.format)}nodeToYaml(e,t="official"){const r=this.normalizeNodeToJsonOptions(t),n=r.blueContext?this.transformForBlueContext(e,r.blueContext):e;return vs.get(n,{strategy:r.format})}nodeToSchemaOutput(e,t){return new gs(this.typeSchemaResolver).convert(e,t)}resolve(e,t=K){const r=this.combineWithGlobalLimits(t);return new Qt(this.mergingProcessor,this.nodeProvider).resolve(e,r)}createResolvedNode(e){return e instanceof Q?e:new Q(e)}reverse(e){return new Kt().reverse(e)}restoreInlineTypes(e){return new Ys({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).restore(e)}extend(e,t){const r=this.combineWithGlobalLimits(t);new st(this.nodeProvider).extend(e,r)}jsonValueToNode(e){return this.preprocess(m.deserialize(e))}async jsonValueToNodeAsync(e){return this.preprocessAsync(m.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 T.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 T.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e),r=this.replaceInlineTypeAliases(t),n=new de({nodeProvider:this.nodeProvider}).preprocessWithDefaultBlue(r);return this.normalizeHistoricalBlueIds(n)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e),r=this.replaceInlineTypeAliases(t),n=new de({nodeProvider:this.nodeProvider}).preprocessWithDefaultBlue(r);return this.normalizeHistoricalBlueIds(n)}transform(e,t){return v.transform(e,t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=ue.wrap(e,this.repositories,{toCurrentBlueId:this.toCurrentBlueId.bind(this)}),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 A.isTypeOf(e,t,{checkSchemaExtensions:r?.checkSchemaExtensions,typeSchemaResolver:this.typeSchemaResolver})}isTypeOfNode(e,t){return new ss(this).matchesType(e,t,this.globalLimits)}setGlobalLimits(e){return this.globalLimits=e??K,this}getGlobalLimits(){return this.globalLimits}toCurrentBlueId(e){return this.repositoryRegistry?.toCurrentBlueId(e)??e}normalizeHistoricalBlueIds(e){return v.transform(e,t=>(this.normalizeTypeField(t,()=>t.getType(),r=>t.setType(r)),this.normalizeTypeField(t,()=>t.getItemType(),r=>t.setItemType(r)),this.normalizeTypeField(t,()=>t.getKeyType(),r=>t.setKeyType(r)),this.normalizeTypeField(t,()=>t.getValueType(),r=>t.setValueType(r)),t))}normalizeTypeField(e,t,r){const n=t();if(!n||n.isInlineValue())return;const i=n.getBlueId();if(!i)return;const o=this.toCurrentBlueId(i);o!==i&&r(n.clone().setBlueId(o))}normalizeNodeToJsonOptions(e){return typeof e=="string"?{format:e,blueContext:void 0}:{format:e?.format??"official",blueContext:e?.blueContext}}transformForBlueContext(e,t){const r=this.computeTargetRepoVersionIndexes(t);if(Object.keys(r).length===0)return e;const n=this.normalizeHistoricalBlueIds(e);return new tn({registry:this.repositoryRegistry,targetRepoVersionIndexes:r,fallbackToCurrentInlineDefinitions:t.fallbackToCurrentInlineDefinitions!==!1}).transform(n)}computeTargetRepoVersionIndexes(e){const t={};if(!e?.repositories)return t;const r=typeof e.repositories=="string"?nn(e.repositories):e.repositories;for(const[n,i]of Object.entries(r)){const o=this.repositoryRegistry.findRuntimeByName(n);if(!o)continue;const l=o.repoVersionIndexById[i];if(l===void 0)throw this.unknownRepoBlueIdError(n,i,o.currentRepoBlueId);t[n]=l}return t}unknownRepoBlueIdError(e,t,r){const n=`Unknown RepoBlueId '${t}' for repository '${e}'.`,i={code:F.REPO_UNKNOWN_REPO_BLUE_ID,severity:"error",message:n,locationPath:[],context:{repoName:e,requestedRepoBlueId:t,serverRepoBlueId:r}};return new be(F.REPO_UNKNOWN_REPO_BLUE_ID,n,[i])}combineWithGlobalLimits(e){return this.globalLimits==K?e:e==K?this.globalLimits:Ce.of(this.globalLimits,e)}replaceInlineTypeAliases(e){const t=new Map(Object.entries(this.blueIdsMappingGenerator.getAllBlueIds()));return this.blueDirectivePreprocessor.getPreprocessingAliases().forEach((n,i)=>{t.set(i,n)}),t.size===0?e:new ce(t).process(e)}}class ln extends Gt{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;preprocessor;constructor(e=[]){super();const t=new de({nodeProvider:this});this.preprocessor=r=>t.preprocessWithDefaultBlue(r),e.forEach(r=>this.processNode(r))}processNode(e){Se.hasItemsOnly(e)?this.processNodeWithItems(e):this.processSingleNode(e)}processSingleNode(e){const t=W.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=W.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=T.calculateBlueIdSync(e),r=e.map(n=>I.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?W.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=m.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=m.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=Et;exports.BasicNodeProvider=ln;exports.Blue=on;exports.BlueIdCalculator=T;exports.BlueIdToCid=Cr;exports.BlueNode=d;exports.BlueNodeTypeSchema=A;exports.JsonCanonicalizer=wt;exports.Limits=Ae;exports.Merger=Qt;exports.MergingProcessors=Ks;exports.NodeResolver=Xt;exports.Nodes=Se;exports.Properties=fr;exports.ResolvedBlueNode=Q;exports.TypeSchemaResolver=Ut;exports.applyBlueNodePatch=zr;exports.baseBlueObjectSchema=fe;exports.blueDescriptionField=Ur;exports.blueIdField=Kr;exports.blueIdSchema=hr;exports.blueNameField=Zr;exports.blueNodeField=Yr;exports.blueObjectBooleanValueSchema=mr;exports.blueObjectNumberValueSchema=gr;exports.blueObjectSchema=q;exports.blueObjectStringListItemsSchema=Ir;exports.blueObjectStringValueSchema=yr;exports.calculateBlueId=Wt;exports.calculateBlueIdSync=Rs;exports.enrichWithBlueId=Le;exports.getBlueDescriptionAnnotation=Ot;exports.getBlueIdAnnotation=Mt;exports.getBlueNameAnnotation=xt;exports.getBlueNodeAnnotation=_t;exports.getBlueObjectItems=Os;exports.getBlueObjectProperties=Ms;exports.getBlueObjectTypeLabel=Fs;exports.getBlueObjectValue=Ds;exports.getTypeBlueIdAnnotation=jt;exports.hasBlueObjectBlueIdDefined=bt;exports.hasBlueObjectItemsDefined=Nt;exports.hasBlueObjectNameDefined=br;exports.hasBlueObjectTypeDefined=vt;exports.hasBlueObjectValueDefined=Bt;exports.isBigDecimalNumber=Ie;exports.isBigIntegerNumber=_;exports.isBigNumber=S;exports.isBlueNodeSchema=tt;exports.isBlueObject=Tr;exports.isBlueObjectResolved=qt;exports.isGivenBlueObjectTypeSchema=Nr;exports.isJsonBlueArray=qe;exports.isJsonBlueObject=We;exports.isJsonBlueValue=wr;exports.isUrl=se;exports.jsonBlueValueSchema=le;exports.normalizeToBlueObject=xs;exports.resolveBlueObjectItems=Ue;exports.withBlueDescription=Rt;exports.withBlueId=Dt;exports.withBlueName=Ft;exports.withBlueNode=$t;exports.withTypeBlueId=Gr;exports.yamlBlueDump=Yt;exports.yamlBlueParse=M;
|