@blue-labs/language 3.4.2 → 3.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -24,4 +24,4 @@ ${r}`}getAllBlueIds(){const e={};for(const t of this.blueIdsCollections)Object.a
24
24
  ${e}
25
25
  ${t}
26
26
  `}loadDefaultSimpleBlue(){try{const e=this.enrichDefaultBlue(Wt),t=D(e);if(t)this.defaultSimpleBlue=g.deserialize(t);else throw new Error("Failed to parse default Blue content")}catch(e){throw new Error(`Error loading default Blue: ${e}`)}}}class ut extends Ht{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;preprocessor;constructor(e){super();const t=new at,r=ut.collectAliasMappings(e);Object.keys(r).length>0&&t.registerBlueIds(r);const n=new ne({nodeProvider:this,blueIdsMappingGenerator:t});this.preprocessor=i=>n.preprocessWithDefaultBlue(i),this.loadRepositories(e)}static collectAliasMappings(e){const t={};for(const r of e)for(const n of Object.values(r.packages))for(const[i,o]of Object.entries(n.aliases)){const l=t[i];if(l&&l!==o)throw new Error(`Conflicting alias mapping for ${i}`);t[i]=o}return t}loadRepositories(e){for(const t of e)Object.values(t.packages).forEach(r=>{for(const[n,i]of Object.entries(r.contents))this.processContent(i,n)})}processContent(e,t){Array.isArray(e)?this.processMultipleDocuments(e,t):this.processSingleDocument(e,t)}processSingleDocument(e,t){const r=g.deserialize(e),n=J.parseAndCalculateBlueIdForNode(r,this.preprocessor),i=t||n.blueId;this.blueIdToContentMap.set(i,n.content),this.blueIdToMultipleDocumentsMap.set(i,!1);const o=r.getName();o&&this.addToNameMap(o,i)}processMultipleDocuments(e,t){const r=e.map(o=>{const l=g.deserialize(o);return this.preprocessor(l)}),n=J.parseAndCalculateBlueIdForNodeList(r,o=>o),i=t||n.blueId;this.blueIdToContentMap.set(i,n.content),this.blueIdToMultipleDocumentsMap.set(i,!0),r.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),r=this.blueIdToMultipleDocumentsMap.get(e);return t!==void 0&&r!==void 0?J.resolveThisReferences(t,e,r):null}getBlueIds(){return Array.from(this.blueIdToContentMap.keys())}hasBlueId(e){const t=e.split("#")[0];return this.blueIdToContentMap.has(t)}}class pe{static wrap(e,t){const r=[ot.INSTANCE];if(t&&t.length>0){const n=new ut(t);r.push(n)}return r.push(e),new Es(r)}}class Ls{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(ve.isPotentialBlueId(t))return this.handleBlueId(r,t);throw ae(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(ve.isPotentialBlueId(t))return this.handleBlueId(r,t);if(ae(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}'.
27
- ${n.message}`):n}else throw ae(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 Us={fetchUrl:async s=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${s}`)}};class zs{cache=new Map;fetchStrategy;enabled=!1;allowedDomains=[];constructor(e){this.fetchStrategy=e||Us}validateUrl(e){if(!ae(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=D(r);else throw new Error(`Unsupported content type from URL: ${n}`);if(i===void 0)throw new Error(`Failed to parse content from URL: ${e}`);let o;return Array.isArray(i)?o=i.map(l=>g.deserialize(l)):o=[g.deserialize(i)],this.cache.set(e,o),o}prefetchUrl(e,t){try{this.validateUrl(e),this.cache.set(e,t)}catch{}}clearCache(){this.cache.clear()}setFetchStrategy(e){return this.fetchStrategy=e,this}getFetchStrategy(){return this.fetchStrategy}enableFetching(){return this.enabled=!0,this.allowedDomains=[],this}enableFetchingForDomains(e){return this.enabled=!0,this.allowedDomains=[...e],this}disableFetching(){return this.enabled=!1,this}isFetchingEnabled(){return this.enabled}getAllowedDomains(){return[...this.allowedDomains]}allowDomain(e){return this.allowedDomains.includes(e)||this.allowedDomains.push(e),this}disallowDomain(e){return this.allowedDomains=this.allowedDomains.filter(t=>t!==e),this}clearAllowedDomains(){return this.allowedDomains=[],this}}class er{resolveWithoutLimits(e){return this.resolve(e,Y)}}class tr extends er{mergingProcessor;nodeProvider;constructor(e,t){super(),this.mergingProcessor=e,this.nodeProvider=pe.wrap(t)}merge(e,t,r){return this.mergeWithContext(e,t,this.createResolutionContext(r))}mergeWithContext(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=this.resolveTypeNode(i,r),l=o.cloneShallow().setType(void 0);n=this.mergeObject(n,l,r);const a=t.cloneShallow().setType(o);return this.mergeObject(n,a,r)}return this.mergeObject(n,t,r)}mergeObject(e,t,r){const n=e.cloneShallow();let i=this.mergingProcessor.process(n,t,r.nodeProvider);const o=t.getItems();u.isNonNullable(o)&&(i=this.mergeChildren(i,o,r));const l=t.getProperties();return u.isNonNullable(l)&&(i=this.mergeProperties(i,l,r)),u.isNonNullable(t.getBlueId())&&(i=i.cloneShallow().setBlueId(t.getBlueId())),this.mergingProcessor.postProcess&&(i=this.mergingProcessor.postProcess(i,t,r.nodeProvider)),i}mergeChildren(e,t,r){const n=e.getItems();if(u.isNullable(n)){const o=[];for(let l=0;l<t.length;l++){const a=t[l];if(r.limits.shouldMergePathSegment(String(l),a)){this.enterPathSegment(r,String(l),a);try{const p=a.isResolved()&&this.canReuseResolvedSubtree(r)?a:this.resolveWithContext(a,r);o.push(p)}finally{this.exitPathSegment(r)}}}return e.cloneShallow().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.limits.shouldMergePathSegment(String(o),t[o])){this.enterPathSegment(r,String(o),t[o]);try{if(o>=i.length){i.push(t[o]);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}'.`)}finally{this.exitPathSegment(r)}}return e.cloneShallow().setItems(i)}mergeProperties(e,t,r){const n=e.getProperties()??{};let i=n,o=!1;for(const[l,a]of Object.entries(t))if(r.limits.shouldMergePathSegment(l,a)){this.enterPathSegment(r,l,a);try{const p=a.isResolved()&&this.canReuseResolvedSubtree(r)?a:this.resolveWithContext(a,r),y=i[l],h=y===void 0?p:this.mergeObject(y,p,r);h!==y&&(o||(i={...n},o=!0),i[l]=h)}finally{this.exitPathSegment(r)}}return o?e.cloneShallow().setProperties(i):e}resolve(e,t){return this.resolveWithContext(e,this.createResolutionContext(t))}resolveWithContext(e,t){const r=new d,i=this.mergeWithContext(r,e,t).clone().setName(e.getName()).setDescription(e.getDescription()).setBlueId(e.getBlueId());return new H(i)}createResolutionContext(e){return{limits:e,nodeProvider:this.nodeProvider,resolvedTypeCache:new Map,pathStack:[]}}resolveTypeNode(e,t){const r=e.getBlueId();if(u.isNonNullable(r)){const n=this.createResolvedTypeCacheKey(r,t),i=t.resolvedTypeCache.get(n);if(u.isNonNullable(i))return i;const o=this.resolveAndExtendTypeNode(e,t);return t.resolvedTypeCache.set(n,o),o}return this.resolveAndExtendTypeNode(e,t)}resolveAndExtendTypeNode(e,t){const r=e.clone();return u.isNonNullable(r.getBlueId())&&new lt(t.nodeProvider).extend(r,De.withSinglePath("/")),this.resolveWithContext(r,t)}createResolvedTypeCacheKey(e,t){return t.limits instanceof Ke?e:`${e}|${this.getCurrentPointer(t)}`}canReuseResolvedSubtree(e){return e.limits instanceof Ke}getCurrentPointer(e){return e.pathStack.length===0?"/":`/${e.pathStack.join("/")}`}enterPathSegment(e,t,r){e.pathStack.push(t),e.limits.enterPathSegment(t,r)}exitPathSegment(e){e.pathStack.pop(),e.limits.exitPathSegment()}}class rr{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 sr{process(e,t){const r=t.getValue();if(u.isNonNullable(r)){const n=e.getValue();if(u.isNullable(n))return e.cloneShallow().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)=>F(s)&&F(e)||Ne(s)&&Ne(e)?s.eq(e):s===e;class nr{process(e,t,r){const n=e.getType(),i=t.getType();let o=e;if(n===void 0)o=e.cloneShallow().setType(i);else if(i!==void 0){if(!N(i,n,r)){const a=m.get(i),p=m.get(n);throw new Error(`The source type '${JSON.stringify(a)}' is not a subtype of the target type '${JSON.stringify(p)}'.`)}o=e.cloneShallow().setType(i)}return o}}class ir{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.cloneShallow().setItemType(n));else if(n!==void 0){if(!N(n,o,r)){const h=m.get(n),f=m.get(o);throw new Error(`The source item type '${JSON.stringify(h)}' is not a subtype of the target item type '${JSON.stringify(f)}'.`)}l=e.cloneShallow().setItemType(n)}const a=l.getItemType(),p=t.getItems();if(a!==void 0&&p!==void 0)for(const y of p){const h=y.getType();if(h!==void 0&&!N(h,a,r)){const f=m.get(h),T=m.get(a);throw new Error(`Item of type '${JSON.stringify(f)}' is not a subtype of the list's item type '${JSON.stringify(T)}'.`)}}return l}}class or{process(e,t,r){const n=t.getKeyType(),i=t.getValueType(),o=t.getType();if((n!==void 0||i!==void 0)&&o!==void 0&&!kt(o,r))throw new Error("Source node with keyType or valueType must have a Dictionary type");let l=this.processKeyType(e,t,r);l=this.processValueType(l,t,r);const a=l.getKeyType(),p=l.getValueType(),y=t.getProperties();return(a!==void 0||p!==void 0)&&y!==void 0&&Object.entries(y).forEach(([h,f])=>{a!==void 0&&this.validateKeyType(h,a,r),p!==void 0&&this.validateValueType(f,p,r)}),l}processKeyType(e,t,r){const n=e.getKeyType(),i=t.getKeyType();if(n===void 0){if(i!==void 0)return this.validateBasicKeyType(i,r),e.cloneShallow().setKeyType(i)}else if(i!==void 0){if(this.validateBasicKeyType(i,r),!N(i,n,r)){const l=m.get(i),a=m.get(n);throw new Error(`The source key type '${JSON.stringify(l)}' is not a subtype of the target key type '${JSON.stringify(a)}'.`)}return e.cloneShallow().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.cloneShallow().setValueType(i)}else if(i!==void 0){if(!N(i,n,r)){const l=m.get(i),a=m.get(n);throw new Error(`The source value type '${JSON.stringify(l)}' is not a subtype of the target value type '${JSON.stringify(a)}'.`)}return e.cloneShallow().setValueType(i)}return e}validateBasicKeyType(e,t){if(!Xr(e,t))throw new Error("Dictionary key type must be a basic type")}validateKeyType(e,t,r){if(!Qr(t,r))if(es(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(ts(t,r)){const n=Number.parseFloat(e);if(Number.isNaN(n))throw new Error(`Key '${e}' is not a valid Number.`)}else if(rs(t,r)){if(e.toLowerCase()!=="true"&&e.toLowerCase()!=="false")throw new Error(`Key '${e}' is not a valid Boolean.`)}else throw new Error(`Unsupported key type: ${t.getName()||"unknown"}`)}validateValueType(e,t,r){const n=e.getType();if(n!==void 0&&!N(n,t,r)){const i=m.get(n),o=m.get(t);throw new Error(`Value of type '${JSON.stringify(i)}' is not a subtype of the dictionary's value type '${JSON.stringify(o)}'.`)}}}class lr{process(e){return e}postProcess(e,t,r){const n=e.getType();if(n!==void 0&&ss(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=ns(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 ar{process(e,t){let r=e;const n=t.getName(),i=e.getName();n!==void 0&&i===void 0&&(r=r.cloneShallow().setName(n));const o=t.getDescription(),l=r.getDescription();return o!==void 0&&l===void 0&&(r=r.cloneShallow().setDescription(o)),r}}const Ys=Object.freeze(Object.defineProperty({__proto__:null,BasicTypesVerifier:lr,DictionaryProcessor:or,ListProcessor:ir,MetadataPropagator:ar,SequentialMergingProcessor:rr,TypeAssigner:nr,ValuePropagator:sr},Symbol.toStringTag,{value:"Module"}));function Ks(){return new rr([new sr,new nr,new ir,new or,new ar,new lr])}class Js{nodeProvider;blueIdToInlineValue=new Map;constructor(e){const{nodeProvider:t,blueIdsMappingGenerator:r}=e;this.nodeProvider=t,Object.entries(Ve).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 B.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 Zs{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)on(this.contents,r.contents,r.name),nn(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}getTypeAlias(e){const t=this.toCurrentBlueId(e),r=Ve[t];if(r)return r;for(const n of this.runtimes){const i=n.typeAliasByCurrentBlueId[t];if(i)return i}}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=Ws(s);return Object.values(s.packages).forEach(t=>{Hs(e,s,t)}),{name:s.name,repositoryVersions:s.repositoryVersions,repoVersionIndexById:e.repoVersionIndexById,aliases:e.aliases,types:e.types,toCurrentBlueIdIndex:e.toCurrentBlueIdIndex,contents:e.contents,schemas:e.schemas,currentRepoBlueId:e.currentRepoBlueId,typeAliasByCurrentBlueId:e.typeAliasByCurrentBlueId,typePackageByCurrentBlueId:e.typePackageByCurrentBlueId}}function Ws(s){const e=Object.fromEntries(s.repositoryVersions.map((r,n)=>[r,n])),t=s.repositoryVersions[s.repositoryVersions.length-1];return{aliases:{},types:{},toCurrentBlueIdIndex:{},contents:{},schemas:[],typeAliasByCurrentBlueId:{},typePackageByCurrentBlueId:{},packageNames:new Set,repoVersionIndexById:e,currentRepoBlueId:t}}function Hs(s,e,t){if(s.packageNames.has(t.name))throw new Error(`Duplicate package name detected: ${t.name}`);s.packageNames.add(t.name),qs(s,t),Xs(s,e,t),Qs(s,t),en(s,t)}function qs(s,e){Object.entries(e.aliases).forEach(([t,r])=>{if(s.aliases[t]&&s.aliases[t]!==r)throw new Error(`Conflicting alias mapping for ${t}`);s.aliases[t]=r})}function Xs(s,e,t){Object.entries(t.typesMeta).forEach(([r,n])=>{if(s.types[r])throw new Error(`Duplicate type mapping for BlueId ${r}`);const i=tn(n,e,r,t.name);if(s.types[r]=i,s.typePackageByCurrentBlueId[r]=t.name,s.typeAliasByCurrentBlueId[r]=`${t.name}/${n.name}`,i.status===b.BLUE_REPOSITORY_STATUS_STABLE&&!s.toCurrentBlueIdIndex[r]&&(s.toCurrentBlueIdIndex[r]=r),i.status===b.BLUE_REPOSITORY_STATUS_STABLE)for(const o of i.versions){const l=s.toCurrentBlueIdIndex[o.typeBlueId];if(l&&l!==r)throw new Error(`Conflicting toCurrentBlueIdIndex mapping for ${o.typeBlueId}`);s.toCurrentBlueIdIndex[o.typeBlueId]=r}})}function Qs(s,e){Object.entries(e.contents).forEach(([t,r])=>{s.contents[t]=r})}function en(s,e){s.schemas.push(...Object.values(e.schemas))}function tn(s,e,t,r){if(s.status===b.BLUE_REPOSITORY_STATUS_DEV)return rn(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??[])sn(l,e.name,t,o.repositoryVersionIndex)}),{...s,versions:n}}function rn(s,e,t,r){if(s.status===b.BLUE_REPOSITORY_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 sn(s,e,t,r){try{b.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 nn(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 on(s,e,t){for(const[r,n]of Object.entries(e)){if(r in s){const i=s[r];if(!ln(i,n))throw new Error(`Conflicting content for BlueId '${r}' across repositories (from ${t})`);continue}s[r]=n}}function ln(s,e){if(s===e)return!0;if(s===null||e===null||typeof s!="object"||typeof e!="object")return!1;const t=Be.canonicalize(s),r=Be.canonicalize(e);return t!==void 0&&t===r}class Se extends Error{code;details;constructor(e,t,r){super(t),this.code=e,this.details=r&&r.length>0?r:[],this.name="BlueError"}}const M={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"},an=new Set(["__proto__","constructor","prototype"]);function ft(s){const e=s.at(0),t=s.at(-1);return!e||!t?s:e==="'"&&t==="'"||e==='"'&&t==='"'?s.slice(1,-1):s}function un(s,e){const t=s.indexOf("=");if(t===-1)throw te(e,`Missing '=' in segment '${s.trim()}'`);if(s.indexOf("=",t+1)!==-1)throw te(e,`Unexpected '=' in segment '${s.trim()}'`);const r=ft(s.slice(0,t).trim()),n=ft(s.slice(t+1).trim());if(!r)throw te(e,"Repository name is empty");if(!n)throw te(e,`Repository BlueId is empty for '${r}'`);return{name:r,value:n}}function cn(s){if(s.trim().length===0)return Object.create(null);const e=Object.create(null);for(const t of s.split(",")){const r=t.trim();if(!r)throw te(s,"Empty repository segment");const{name:n,value:i}=un(r,s);pn(n,s),e[n]=i}return e}function dn(s){return typeof s=="string"?cn(s):s}function te(s,e){return new Se(M.INVALID_BLUE_CONTEXT_REPOSITORIES,`Invalid BlueContext repositories value: ${e}`,[{code:M.INVALID_BLUE_CONTEXT_REPOSITORIES,message:e,locationPath:[],context:{rawRepositories:s,reason:e}}])}function pn(s,e){if(an.has(s))throw te(e,`Forbidden repository name '${s}'`)}function hn(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)=>yt(l)-yt(o));r.push(...i)}return r}function yt(s){return b.parsePointer(s).length}const fn=new Set([...We]),v={core:"core",noRuntime:"no-runtime",noTargetContext:"no-target-context",representable:"representable",unrepresentable:"unrepresentable"};class yn{registry;targetRepoVersionIndexes;fallbackToCurrentInlineDefinitions;inliningStack=new Set;constructor(e){this.registry=e.registry,this.targetRepoVersionIndexes=e.targetRepoVersionIndexes,this.fallbackToCurrentInlineDefinitions=e.fallbackToCurrentInlineDefinitions}transform(e){return B.transform(e,t=>this.transformNode(t))}transformNode(e){return this.processTypeReference(e,{getter:()=>e.getType(),setter:t=>e.setType(t),schemaTraversalTargets:[e]}),this.processTypeReference(e,{getter:()=>e.getItemType(),setter:t=>e.setItemType(t),schemaTraversalTargets:e.getItems()??[]}),this.processTypeReference(e,{getter:()=>e.getKeyType(),setter:t=>e.setKeyType(t),schemaTraversalTargets:[]}),this.processTypeReference(e,{getter:()=>e.getValueType(),setter:t=>e.setValueType(t),schemaTraversalTargets: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 v.core:{r.setBlueId(i.blueId);return}case v.representable:{this.applyDropPointers([r],i.dropPointers,{rootIsSchema:!0}),this.applyDropPointers(t.schemaTraversalTargets,i.dropPointers),r.setBlueId(i.targetBlueId);return}case v.noRuntime:case v.noTargetContext:case v.unrepresentable:{if(this.fallbackToCurrentInlineDefinitions){this.inlineDefinition(e,t.setter,n);return}throw i.kind===v.unrepresentable?i.error:this.unrepresentableError(n,i.kind===v.noTargetContext?`Repository '${i.runtimeName}' not provided in BlueContext.`:"Type does not belong to any declared repository.",i.kind===v.noTargetContext?i.runtime:void 0,i.kind===v.noTargetContext?i.meta:void 0,void 0,i.kind===v.noTargetContext?i.typeAlias:void 0)}}}resolveType(e){if(X.includes(e))return{kind:v.core,blueId:e};const t=this.registry.toCurrentBlueId(e),r=this.registry.getTypeAlias(t),n=this.registry.findRuntimeByBlueId(t);if(!n||!n.typeMeta)return{kind:v.noRuntime};const i=this.targetRepoVersionIndexes[n.runtime.name];if(i===void 0)return{kind:v.noTargetContext,currentBlueId:t,runtimeName:n.runtime.name,runtime:n.runtime,meta:n.typeMeta,typeAlias:r};const o=n.typeMeta;if(o.status===b.BLUE_REPOSITORY_STATUS_DEV){const h=n.runtime.repositoryVersions.length-1;if(i!==h)return{kind:v.unrepresentable,currentBlueId:t,error:this.unrepresentableError(t,`Dev type cannot be represented at repository version index ${i}.`,n.runtime,o,i,r)};const f=o.versions?.[0];return{kind:v.representable,currentBlueId:t,targetBlueId:f?.typeBlueId??t,dropPointers:[]}}const l=o.versions||[];if(l.length===0)return{kind:v.unrepresentable,currentBlueId:t,error:this.unrepresentableError(t,`Stable type metadata missing versions for ${t}.`,n.runtime,o,i,r)};const a=l[0].repositoryVersionIndex;if(i<a)return{kind:v.unrepresentable,currentBlueId:t,error:this.unrepresentableError(t,`Type introduced after target repository version index ${i}.`,n.runtime,o,i,r)};let p=l[0].typeBlueId;for(const h of l)h.repositoryVersionIndex<=i&&(p=h.typeBlueId);const y=o.status===b.BLUE_REPOSITORY_STATUS_STABLE?this.getDropPointers(o,i):[];return{kind:v.representable,currentBlueId:t,targetBlueId:p,dropPointers:y}}getDropPointers(e,t){return e.status!==b.BLUE_REPOSITORY_STATUS_STABLE?[]:hn(e.versions,t)}applyDropPointers(e,t,r={}){if(e.length===0||t.length===0)return;const n=r.rootIsSchema??!1;for(const i of t)for(const o of e)this.deletePropertyAtPointer(o,i,n)}getDictionaryValueTargets(e){const t=e.getProperties();return t?Object.entries(t).filter(([r,n])=>n instanceof d&&!fn.has(r)).map(([,r])=>r):[]}deletePropertyAtPointer(e,t,r){let n;try{n=b.parsePointer(t)}catch{throw this.invalidPointerError(t)}this.applyPointerSegments(e,n,r)}applyPointerSegments(e,t,r){if(t.length===0)return;const[n,...i]=t;if(n===W){const a=e.getType();a&&this.applyPointerSegments(a,i,!0);return}if(n===he){const a=e.getItemType();a&&this.applyPointerSegments(a,i,!0);return}if(n===fe){const a=e.getKeyType();a&&this.applyPointerSegments(a,i,!0);return}if(n===ye){const a=e.getValueType();a&&this.applyPointerSegments(a,i,!0);return}const o=e.getProperties();if(!o)return;if(i.length===0){if(!r||!(n in o))return;const a={...o};delete a[n],e.setProperties(a);return}const l=o[n];l instanceof d&&this.applyPointerSegments(l,i,r)}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=g.deserialize(i);o.setBlueId(void 0);const l=B.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 Se(M.INVALID_REPOSITORY_POINTER,t,[{code:M.INVALID_REPOSITORY_POINTER,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===b.BLUE_REPOSITORY_STATUS_STABLE){const y=n.versions?.[0]?.repositoryVersionIndex;y!==void 0&&(a.typeIntroducedInRepoBlueId=r?.repositoryVersions[y])}const p={code:M.REPO_UNREPRESENTABLE_IN_TARGET_VERSION,message:t,locationPath:[W],context:a};return new Se(M.REPO_UNREPRESENTABLE_IN_TARGET_VERSION,t,[p])}}function Ge(s,e){return e?B.transform(s,t=>(be(()=>t.getType(),r=>t.setType(r),e),be(()=>t.getItemType(),r=>t.setItemType(r),e),be(()=>t.getKeyType(),r=>t.setKeyType(r),e),be(()=>t.getValueType(),r=>t.setValueType(r),e),t)):s}function be(s,e,t){const r=s();if(!r||r.isInlineValue())return;const n=r.getBlueId();if(!n)return;const i=t.toCurrentBlueId(n);i!==n&&e(r.clone().setBlueId(i))}class gn{registry;blueIdMapper;constructor(e){this.registry=e.registry,this.blueIdMapper=e.blueIdMapper}transform(e,t){const r=this.computeTargetRepoVersionIndexes(t);if(Object.keys(r).length===0)return e;const n=Ge(e,this.blueIdMapper);return new yn({registry:this.registry,targetRepoVersionIndexes:r,fallbackToCurrentInlineDefinitions:t.fallbackToCurrentInlineDefinitions!==!1}).transform(n)}computeTargetRepoVersionIndexes(e){const t={};if(!e?.repositories)return t;const r=typeof e.repositories=="string"?dn(e.repositories):e.repositories;for(const[n,i]of Object.entries(r)){const o=this.registry.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:M.REPO_UNKNOWN_REPO_BLUE_ID,message:n,locationPath:[],context:{repoName:e,requestedRepoBlueId:t,serverRepoBlueId:r}};return new Se(M.REPO_UNKNOWN_REPO_BLUE_ID,n,[i])}}class mn{nodeProvider;typeSchemaResolver;blueDirectivePreprocessor;urlContentFetcher;blueIdsMappingGenerator;globalLimits=Y;mergingProcessor;repositories;repositoryRegistry;blueContextResolver;constructor(e={}){const{nodeProvider:t,typeSchemaResolver:r=null,urlFetchStrategy:n,repositories:i,mergingProcessor:o}=e;this.repositories=i,this.repositoryRegistry=new Zs(i??[]),this.blueContextResolver=new gn({registry:this.repositoryRegistry,blueIdMapper:this.repositoryRegistry});const l=Ts(()=>[]);this.nodeProvider=pe.wrap(t||l,i),this.typeSchemaResolver=r??new Yt([],{nodeProvider:this.nodeProvider}),this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this.mergingProcessor=o??Ks(),this.urlContentFetcher=new zs(n),this.blueDirectivePreprocessor=new Ls(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new at,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.blueContextResolver.transform(e,r.blueContext):e;return m.get(n,r.format)}nodeToYaml(e,t="official"){const r=this.normalizeNodeToJsonOptions(t),n=r.blueContext?this.blueContextResolver.transform(e,r.blueContext):e;return ws.get(n,{strategy:r.format})}nodeToSchemaOutput(e,t){return new Is(this.typeSchemaResolver).convert(e,t)}resolve(e,t=Y){const r=this.combineWithGlobalLimits(t);return new tr(this.mergingProcessor,this.nodeProvider).resolve(e,r)}createResolvedNode(e){return e instanceof H?e:new H(e)}reverse(e){return new Jt().reverse(e)}restoreInlineTypes(e){return new Js({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).restore(e)}extend(e,t){const r=this.combineWithGlobalLimits(t);new lt(this.nodeProvider).extend(e,r)}jsonValueToNode(e){const t=this.preprocess(g.deserialize(e));return Ge(t,this.repositoryRegistry)}async jsonValueToNodeAsync(e){const t=await this.preprocessAsync(g.deserialize(e));return Ge(t,this.repositoryRegistry)}yamlToNode(e){const t=D(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=D(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}prepareForBlueIdCalculation=async e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?await Promise.all(e.map(r=>this.jsonValueToNodeAsync(r))):this.jsonValueToNodeAsync(e);calculateBlueId=async e=>{const t=await this.prepareForBlueIdCalculation(e);return I.calculateBlueId(t)};prepareForBlueIdCalculationSync=e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?e.map(t=>this.jsonValueToNode(t)):this.jsonValueToNode(e);calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return I.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new ne({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new ne({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}transform(e,t){return B.transform(e,t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=pe.wrap(e,this.repositories),this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this}getTypeSchemaResolver(){return this.typeSchemaResolver}setTypeSchemaResolver(e){return this.typeSchemaResolver=e,this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this}getUrlContentFetcher(){return this.urlContentFetcher}setUrlFetchStrategy(e){return this.urlContentFetcher.setFetchStrategy(e),this}enablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.enableFetching(),this}enablePreprocessingDirectivesFetchForDomains(e){return this.urlContentFetcher.enableFetchingForDomains(e),this}allowUrlFetchingForDomain(e){return this.urlContentFetcher.allowDomain(e),this}disallowUrlFetchingForDomain(e){return this.urlContentFetcher.disallowDomain(e),this}getAllowedUrlFetchingDomains(){return this.urlContentFetcher.getAllowedDomains()}disablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.disableFetching(),this}isPreprocessingDirectivesFetchForUrlsEnabled(){return this.urlContentFetcher.isFetchingEnabled()}getPreprocessingAliases(){return this.blueDirectivePreprocessor.getPreprocessingAliases()}setPreprocessingAliases(e){return this.blueDirectivePreprocessor.setPreprocessingAliases(e),this}registerBlueIds(...e){return this.blueIdsMappingGenerator.registerBlueIds(...e),this}getAllRegisteredBlueIds(){return this.blueIdsMappingGenerator.getAllBlueIds()}getAllBlueIdNames(){return this.blueIdsMappingGenerator.getAllBlueIdNames()}getBlueIdsMappingGenerator(){return this.blueIdsMappingGenerator}isTypeOf(e,t,r){return A.isTypeOf(e,t,{checkSchemaExtensions:r?.checkSchemaExtensions,typeSchemaResolver:this.typeSchemaResolver})}isTypeOfBlueId(e,t){const r=t.trim();if(r.length===0)return!1;const n=e.getType();if(!n)return!1;const i=new d().setBlueId(r);return N(n,i,this.nodeProvider)}isTypeOfNode(e,t){return new is(this).matchesType(e,t,this.globalLimits)}setGlobalLimits(e){return this.globalLimits=e??Y,this}getGlobalLimits(){return this.globalLimits}normalizeNodeToJsonOptions(e){return typeof e=="string"?{format:e,blueContext:void 0}:{format:e?.format??"official",blueContext:e?.blueContext}}combineWithGlobalLimits(e){return this.globalLimits==Y?e:e==Y?this.globalLimits:Me.of(this.globalLimits,e)}}class In extends Ht{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;preprocessor;constructor(e=[]){super();const t=new ne({nodeProvider:this});this.preprocessor=r=>t.preprocessWithDefaultBlue(r),e.forEach(r=>this.processNode(r))}processNode(e){Re.hasItemsOnly(e)?this.processNodeWithItems(e):this.processSingleNode(e)}processSingleNode(e){const t=J.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=J.parseAndCalculateBlueIdForNodeList(t,this.preprocessor);this.blueIdToContentMap.set(r.blueId,r.content),this.blueIdToMultipleDocumentsMap.set(r.blueId,!0),t.forEach((n,i)=>{const o=n.getName();o&&this.addToNameMap(o,`${r.blueId}#${i}`)})}processNodeList(e){const t=I.calculateBlueIdSync(e),r=e.map(n=>m.get(n));this.blueIdToContentMap.set(t,r),this.blueIdToMultipleDocumentsMap.set(t,!0)}fetchContentByBlueId(e){const t=this.blueIdToContentMap.get(e),r=this.blueIdToMultipleDocumentsMap.get(e);return t!==void 0&&r!==void 0?J.resolveThisReferences(t,e,r):null}addSingleNodes(...e){e.forEach(t=>this.processNode(t))}addSingleDocs(...e){e.forEach(t=>{const r=D(t);if(r!==void 0){const n=g.deserialize(r);this.processNode(n)}})}getBlueIdByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t||t.length===0)throw new Error(`No node with name "${e}"`);return t[0]}getNodeByName(e){const t=this.findNodeByName(e);if(!t)throw new Error(`No node with name "${e}"`);return t}addListAndItsItemsFromNodes(e){this.processNodeList(e),e.forEach(t=>this.processNode(t))}addListAndItsItemsFromDoc(e){const t=D(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=Pt;exports.BasicNodeProvider=In;exports.Blue=mn;exports.BlueIdCalculator=I;exports.BlueIdToCid=Dr;exports.BlueNode=d;exports.BlueNodeTypeSchema=A;exports.JsonCanonicalizer=Be;exports.Limits=Oe;exports.Merger=tr;exports.MergingProcessors=Ys;exports.NodeResolver=er;exports.Nodes=Re;exports.Properties=yr;exports.ResolvedBlueNode=H;exports.TypeSchemaResolver=Yt;exports.applyBlueNodePatch=kr;exports.baseBlueObjectSchema=me;exports.blueDescriptionField=Kr;exports.blueIdField=Zr;exports.blueIdSchema=mr;exports.blueNameField=Gr;exports.blueNodeField=Wr;exports.blueObjectBooleanValueSchema=br;exports.blueObjectNumberValueSchema=Tr;exports.blueObjectSchema=re;exports.blueObjectStringListItemsSchema=vr;exports.blueObjectStringValueSchema=Ir;exports.calculateBlueId=Xt;exports.calculateBlueIdSync=Os;exports.enrichWithBlueId=Je;exports.getBlueDescriptionAnnotation=Mt;exports.getBlueIdAnnotation=xt;exports.getBlueNameAnnotation=$t;exports.getBlueNodeAnnotation=Lt;exports.getBlueObjectItems=Ds;exports.getBlueObjectProperties=_s;exports.getBlueObjectTypeLabel=xs;exports.getBlueObjectValue=Ms;exports.getTypeBlueIdAnnotation=Ut;exports.hasBlueObjectBlueIdDefined=Bt;exports.hasBlueObjectItemsDefined=wt;exports.hasBlueObjectNameDefined=Br;exports.hasBlueObjectTypeDefined=Et;exports.hasBlueObjectValueDefined=St;exports.isBigDecimalNumber=Ne;exports.isBigIntegerNumber=F;exports.isBigNumber=C;exports.isBlueNodeSchema=it;exports.isBlueObject=Nr;exports.isBlueObjectResolved=Qt;exports.isGivenBlueObjectTypeSchema=wr;exports.isJsonBlueArray=tt;exports.isJsonBlueObject=et;exports.isJsonBlueValue=Pr;exports.isUrl=ae;exports.jsonBlueValueSchema=ce;exports.normalizeToBlueObject=Fs;exports.resolveBlueObjectItems=Ze;exports.withBlueDescription=Dt;exports.withBlueId=_t;exports.withBlueName=Ft;exports.withBlueNode=jt;exports.withTypeBlueId=qr;exports.yamlBlueDump=Gt;exports.yamlBlueParse=D;
27
+ ${n.message}`):n}else throw ae(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 Us={fetchUrl:async s=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${s}`)}};class zs{cache=new Map;fetchStrategy;enabled=!1;allowedDomains=[];constructor(e){this.fetchStrategy=e||Us}validateUrl(e){if(!ae(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=D(r);else throw new Error(`Unsupported content type from URL: ${n}`);if(i===void 0)throw new Error(`Failed to parse content from URL: ${e}`);let o;return Array.isArray(i)?o=i.map(l=>g.deserialize(l)):o=[g.deserialize(i)],this.cache.set(e,o),o}prefetchUrl(e,t){try{this.validateUrl(e),this.cache.set(e,t)}catch{}}clearCache(){this.cache.clear()}setFetchStrategy(e){return this.fetchStrategy=e,this}getFetchStrategy(){return this.fetchStrategy}enableFetching(){return this.enabled=!0,this.allowedDomains=[],this}enableFetchingForDomains(e){return this.enabled=!0,this.allowedDomains=[...e],this}disableFetching(){return this.enabled=!1,this}isFetchingEnabled(){return this.enabled}getAllowedDomains(){return[...this.allowedDomains]}allowDomain(e){return this.allowedDomains.includes(e)||this.allowedDomains.push(e),this}disallowDomain(e){return this.allowedDomains=this.allowedDomains.filter(t=>t!==e),this}clearAllowedDomains(){return this.allowedDomains=[],this}}class er{resolveWithoutLimits(e){return this.resolve(e,Y)}}class tr extends er{mergingProcessor;nodeProvider;constructor(e,t){super(),this.mergingProcessor=e,this.nodeProvider=pe.wrap(t)}merge(e,t,r){return this.mergeWithContext(e,t,this.createResolutionContext(r))}mergeWithContext(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=this.resolveTypeNode(i,r),l=o.clone().setType(void 0);n=this.mergeObject(n,l,r);const a=t.cloneShallow().setType(o.clone());return this.mergeObject(n,a,r)}return this.mergeObject(n,t,r)}mergeObject(e,t,r){const n=e.cloneShallow();let i=this.mergingProcessor.process(n,t,r.nodeProvider);const o=t.getItems();u.isNonNullable(o)&&(i=this.mergeChildren(i,o,r));const l=t.getProperties();return u.isNonNullable(l)&&(i=this.mergeProperties(i,l,r)),u.isNonNullable(t.getBlueId())&&(i=i.cloneShallow().setBlueId(t.getBlueId())),this.mergingProcessor.postProcess&&(i=this.mergingProcessor.postProcess(i,t,r.nodeProvider)),i}mergeChildren(e,t,r){const n=e.getItems();if(u.isNullable(n)){const o=[];for(let l=0;l<t.length;l++){const a=t[l];if(r.limits.shouldMergePathSegment(String(l),a)){this.enterPathSegment(r,String(l),a);try{const p=a.isResolved()&&this.canReuseResolvedSubtree(r)?a.clone():this.resolveWithContext(a,r);o.push(p)}finally{this.exitPathSegment(r)}}}return e.cloneShallow().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.limits.shouldMergePathSegment(String(o),t[o])){this.enterPathSegment(r,String(o),t[o]);try{if(o>=i.length){i.push(t[o]);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}'.`)}finally{this.exitPathSegment(r)}}return e.cloneShallow().setItems(i)}mergeProperties(e,t,r){const n=e.getProperties()??{};let i=n,o=!1;for(const[l,a]of Object.entries(t))if(r.limits.shouldMergePathSegment(l,a)){this.enterPathSegment(r,l,a);try{const p=a.isResolved()&&this.canReuseResolvedSubtree(r)?a.clone():this.resolveWithContext(a,r),y=i[l],h=y===void 0?p:this.mergeObject(y,p,r);h!==y&&(o||(i={...n},o=!0),i[l]=h)}finally{this.exitPathSegment(r)}}return o?e.cloneShallow().setProperties(i):e}resolve(e,t){return this.resolveWithContext(e,this.createResolutionContext(t))}resolveWithContext(e,t){const r=new d,i=this.mergeWithContext(r,e,t).clone().setName(e.getName()).setDescription(e.getDescription()).setBlueId(e.getBlueId());return new H(i)}createResolutionContext(e){return{limits:e,nodeProvider:this.nodeProvider,resolvedTypeCache:new Map,pathStack:[]}}resolveTypeNode(e,t){const r=e.getBlueId();if(u.isNonNullable(r)){const n=this.createResolvedTypeCacheKey(r,t),i=t.resolvedTypeCache.get(n);if(u.isNonNullable(i))return i;const o=this.resolveAndExtendTypeNode(e,t);return t.resolvedTypeCache.set(n,o),o}return this.resolveAndExtendTypeNode(e,t)}resolveAndExtendTypeNode(e,t){const r=e.clone();return u.isNonNullable(r.getBlueId())&&new lt(t.nodeProvider).extend(r,De.withSinglePath("/")),this.resolveWithContext(r,t)}createResolvedTypeCacheKey(e,t){return t.limits instanceof Ke?e:`${e}|${this.getCurrentPointer(t)}`}canReuseResolvedSubtree(e){return e.limits instanceof Ke}getCurrentPointer(e){return e.pathStack.length===0?"/":`/${e.pathStack.join("/")}`}enterPathSegment(e,t,r){e.pathStack.push(t),e.limits.enterPathSegment(t,r)}exitPathSegment(e){e.pathStack.pop(),e.limits.exitPathSegment()}}class rr{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 sr{process(e,t){const r=t.getValue();if(u.isNonNullable(r)){const n=e.getValue();if(u.isNullable(n))return e.cloneShallow().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)=>F(s)&&F(e)||Ne(s)&&Ne(e)?s.eq(e):s===e;class nr{process(e,t,r){const n=e.getType(),i=t.getType();let o=e;if(n===void 0)o=e.cloneShallow().setType(i);else if(i!==void 0){if(!N(i,n,r)){const a=m.get(i),p=m.get(n);throw new Error(`The source type '${JSON.stringify(a)}' is not a subtype of the target type '${JSON.stringify(p)}'.`)}o=e.cloneShallow().setType(i)}return o}}class ir{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.cloneShallow().setItemType(n));else if(n!==void 0){if(!N(n,o,r)){const h=m.get(n),f=m.get(o);throw new Error(`The source item type '${JSON.stringify(h)}' is not a subtype of the target item type '${JSON.stringify(f)}'.`)}l=e.cloneShallow().setItemType(n)}const a=l.getItemType(),p=t.getItems();if(a!==void 0&&p!==void 0)for(const y of p){const h=y.getType();if(h!==void 0&&!N(h,a,r)){const f=m.get(h),T=m.get(a);throw new Error(`Item of type '${JSON.stringify(f)}' is not a subtype of the list's item type '${JSON.stringify(T)}'.`)}}return l}}class or{process(e,t,r){const n=t.getKeyType(),i=t.getValueType(),o=t.getType();if((n!==void 0||i!==void 0)&&o!==void 0&&!kt(o,r))throw new Error("Source node with keyType or valueType must have a Dictionary type");let l=this.processKeyType(e,t,r);l=this.processValueType(l,t,r);const a=l.getKeyType(),p=l.getValueType(),y=t.getProperties();return(a!==void 0||p!==void 0)&&y!==void 0&&Object.entries(y).forEach(([h,f])=>{a!==void 0&&this.validateKeyType(h,a,r),p!==void 0&&this.validateValueType(f,p,r)}),l}processKeyType(e,t,r){const n=e.getKeyType(),i=t.getKeyType();if(n===void 0){if(i!==void 0)return this.validateBasicKeyType(i,r),e.cloneShallow().setKeyType(i)}else if(i!==void 0){if(this.validateBasicKeyType(i,r),!N(i,n,r)){const l=m.get(i),a=m.get(n);throw new Error(`The source key type '${JSON.stringify(l)}' is not a subtype of the target key type '${JSON.stringify(a)}'.`)}return e.cloneShallow().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.cloneShallow().setValueType(i)}else if(i!==void 0){if(!N(i,n,r)){const l=m.get(i),a=m.get(n);throw new Error(`The source value type '${JSON.stringify(l)}' is not a subtype of the target value type '${JSON.stringify(a)}'.`)}return e.cloneShallow().setValueType(i)}return e}validateBasicKeyType(e,t){if(!Xr(e,t))throw new Error("Dictionary key type must be a basic type")}validateKeyType(e,t,r){if(!Qr(t,r))if(es(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(ts(t,r)){const n=Number.parseFloat(e);if(Number.isNaN(n))throw new Error(`Key '${e}' is not a valid Number.`)}else if(rs(t,r)){if(e.toLowerCase()!=="true"&&e.toLowerCase()!=="false")throw new Error(`Key '${e}' is not a valid Boolean.`)}else throw new Error(`Unsupported key type: ${t.getName()||"unknown"}`)}validateValueType(e,t,r){const n=e.getType();if(n!==void 0&&!N(n,t,r)){const i=m.get(n),o=m.get(t);throw new Error(`Value of type '${JSON.stringify(i)}' is not a subtype of the dictionary's value type '${JSON.stringify(o)}'.`)}}}class lr{process(e){return e}postProcess(e,t,r){const n=e.getType();if(n!==void 0&&ss(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=ns(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 ar{process(e,t){let r=e;const n=t.getName(),i=e.getName();n!==void 0&&i===void 0&&(r=r.cloneShallow().setName(n));const o=t.getDescription(),l=r.getDescription();return o!==void 0&&l===void 0&&(r=r.cloneShallow().setDescription(o)),r}}const Ys=Object.freeze(Object.defineProperty({__proto__:null,BasicTypesVerifier:lr,DictionaryProcessor:or,ListProcessor:ir,MetadataPropagator:ar,SequentialMergingProcessor:rr,TypeAssigner:nr,ValuePropagator:sr},Symbol.toStringTag,{value:"Module"}));function Ks(){return new rr([new sr,new nr,new ir,new or,new ar,new lr])}class Js{nodeProvider;blueIdToInlineValue=new Map;constructor(e){const{nodeProvider:t,blueIdsMappingGenerator:r}=e;this.nodeProvider=t,Object.entries(Ve).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 B.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 Zs{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)on(this.contents,r.contents,r.name),nn(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}getTypeAlias(e){const t=this.toCurrentBlueId(e),r=Ve[t];if(r)return r;for(const n of this.runtimes){const i=n.typeAliasByCurrentBlueId[t];if(i)return i}}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=Ws(s);return Object.values(s.packages).forEach(t=>{Hs(e,s,t)}),{name:s.name,repositoryVersions:s.repositoryVersions,repoVersionIndexById:e.repoVersionIndexById,aliases:e.aliases,types:e.types,toCurrentBlueIdIndex:e.toCurrentBlueIdIndex,contents:e.contents,schemas:e.schemas,currentRepoBlueId:e.currentRepoBlueId,typeAliasByCurrentBlueId:e.typeAliasByCurrentBlueId,typePackageByCurrentBlueId:e.typePackageByCurrentBlueId}}function Ws(s){const e=Object.fromEntries(s.repositoryVersions.map((r,n)=>[r,n])),t=s.repositoryVersions[s.repositoryVersions.length-1];return{aliases:{},types:{},toCurrentBlueIdIndex:{},contents:{},schemas:[],typeAliasByCurrentBlueId:{},typePackageByCurrentBlueId:{},packageNames:new Set,repoVersionIndexById:e,currentRepoBlueId:t}}function Hs(s,e,t){if(s.packageNames.has(t.name))throw new Error(`Duplicate package name detected: ${t.name}`);s.packageNames.add(t.name),qs(s,t),Xs(s,e,t),Qs(s,t),en(s,t)}function qs(s,e){Object.entries(e.aliases).forEach(([t,r])=>{if(s.aliases[t]&&s.aliases[t]!==r)throw new Error(`Conflicting alias mapping for ${t}`);s.aliases[t]=r})}function Xs(s,e,t){Object.entries(t.typesMeta).forEach(([r,n])=>{if(s.types[r])throw new Error(`Duplicate type mapping for BlueId ${r}`);const i=tn(n,e,r,t.name);if(s.types[r]=i,s.typePackageByCurrentBlueId[r]=t.name,s.typeAliasByCurrentBlueId[r]=`${t.name}/${n.name}`,i.status===b.BLUE_REPOSITORY_STATUS_STABLE&&!s.toCurrentBlueIdIndex[r]&&(s.toCurrentBlueIdIndex[r]=r),i.status===b.BLUE_REPOSITORY_STATUS_STABLE)for(const o of i.versions){const l=s.toCurrentBlueIdIndex[o.typeBlueId];if(l&&l!==r)throw new Error(`Conflicting toCurrentBlueIdIndex mapping for ${o.typeBlueId}`);s.toCurrentBlueIdIndex[o.typeBlueId]=r}})}function Qs(s,e){Object.entries(e.contents).forEach(([t,r])=>{s.contents[t]=r})}function en(s,e){s.schemas.push(...Object.values(e.schemas))}function tn(s,e,t,r){if(s.status===b.BLUE_REPOSITORY_STATUS_DEV)return rn(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??[])sn(l,e.name,t,o.repositoryVersionIndex)}),{...s,versions:n}}function rn(s,e,t,r){if(s.status===b.BLUE_REPOSITORY_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 sn(s,e,t,r){try{b.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 nn(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 on(s,e,t){for(const[r,n]of Object.entries(e)){if(r in s){const i=s[r];if(!ln(i,n))throw new Error(`Conflicting content for BlueId '${r}' across repositories (from ${t})`);continue}s[r]=n}}function ln(s,e){if(s===e)return!0;if(s===null||e===null||typeof s!="object"||typeof e!="object")return!1;const t=Be.canonicalize(s),r=Be.canonicalize(e);return t!==void 0&&t===r}class Se extends Error{code;details;constructor(e,t,r){super(t),this.code=e,this.details=r&&r.length>0?r:[],this.name="BlueError"}}const M={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"},an=new Set(["__proto__","constructor","prototype"]);function ft(s){const e=s.at(0),t=s.at(-1);return!e||!t?s:e==="'"&&t==="'"||e==='"'&&t==='"'?s.slice(1,-1):s}function un(s,e){const t=s.indexOf("=");if(t===-1)throw te(e,`Missing '=' in segment '${s.trim()}'`);if(s.indexOf("=",t+1)!==-1)throw te(e,`Unexpected '=' in segment '${s.trim()}'`);const r=ft(s.slice(0,t).trim()),n=ft(s.slice(t+1).trim());if(!r)throw te(e,"Repository name is empty");if(!n)throw te(e,`Repository BlueId is empty for '${r}'`);return{name:r,value:n}}function cn(s){if(s.trim().length===0)return Object.create(null);const e=Object.create(null);for(const t of s.split(",")){const r=t.trim();if(!r)throw te(s,"Empty repository segment");const{name:n,value:i}=un(r,s);pn(n,s),e[n]=i}return e}function dn(s){return typeof s=="string"?cn(s):s}function te(s,e){return new Se(M.INVALID_BLUE_CONTEXT_REPOSITORIES,`Invalid BlueContext repositories value: ${e}`,[{code:M.INVALID_BLUE_CONTEXT_REPOSITORIES,message:e,locationPath:[],context:{rawRepositories:s,reason:e}}])}function pn(s,e){if(an.has(s))throw te(e,`Forbidden repository name '${s}'`)}function hn(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)=>yt(l)-yt(o));r.push(...i)}return r}function yt(s){return b.parsePointer(s).length}const fn=new Set([...We]),v={core:"core",noRuntime:"no-runtime",noTargetContext:"no-target-context",representable:"representable",unrepresentable:"unrepresentable"};class yn{registry;targetRepoVersionIndexes;fallbackToCurrentInlineDefinitions;inliningStack=new Set;constructor(e){this.registry=e.registry,this.targetRepoVersionIndexes=e.targetRepoVersionIndexes,this.fallbackToCurrentInlineDefinitions=e.fallbackToCurrentInlineDefinitions}transform(e){return B.transform(e,t=>this.transformNode(t))}transformNode(e){return this.processTypeReference(e,{getter:()=>e.getType(),setter:t=>e.setType(t),schemaTraversalTargets:[e]}),this.processTypeReference(e,{getter:()=>e.getItemType(),setter:t=>e.setItemType(t),schemaTraversalTargets:e.getItems()??[]}),this.processTypeReference(e,{getter:()=>e.getKeyType(),setter:t=>e.setKeyType(t),schemaTraversalTargets:[]}),this.processTypeReference(e,{getter:()=>e.getValueType(),setter:t=>e.setValueType(t),schemaTraversalTargets: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 v.core:{r.setBlueId(i.blueId);return}case v.representable:{this.applyDropPointers([r],i.dropPointers,{rootIsSchema:!0}),this.applyDropPointers(t.schemaTraversalTargets,i.dropPointers),r.setBlueId(i.targetBlueId);return}case v.noRuntime:case v.noTargetContext:case v.unrepresentable:{if(this.fallbackToCurrentInlineDefinitions){this.inlineDefinition(e,t.setter,n);return}throw i.kind===v.unrepresentable?i.error:this.unrepresentableError(n,i.kind===v.noTargetContext?`Repository '${i.runtimeName}' not provided in BlueContext.`:"Type does not belong to any declared repository.",i.kind===v.noTargetContext?i.runtime:void 0,i.kind===v.noTargetContext?i.meta:void 0,void 0,i.kind===v.noTargetContext?i.typeAlias:void 0)}}}resolveType(e){if(X.includes(e))return{kind:v.core,blueId:e};const t=this.registry.toCurrentBlueId(e),r=this.registry.getTypeAlias(t),n=this.registry.findRuntimeByBlueId(t);if(!n||!n.typeMeta)return{kind:v.noRuntime};const i=this.targetRepoVersionIndexes[n.runtime.name];if(i===void 0)return{kind:v.noTargetContext,currentBlueId:t,runtimeName:n.runtime.name,runtime:n.runtime,meta:n.typeMeta,typeAlias:r};const o=n.typeMeta;if(o.status===b.BLUE_REPOSITORY_STATUS_DEV){const h=n.runtime.repositoryVersions.length-1;if(i!==h)return{kind:v.unrepresentable,currentBlueId:t,error:this.unrepresentableError(t,`Dev type cannot be represented at repository version index ${i}.`,n.runtime,o,i,r)};const f=o.versions?.[0];return{kind:v.representable,currentBlueId:t,targetBlueId:f?.typeBlueId??t,dropPointers:[]}}const l=o.versions||[];if(l.length===0)return{kind:v.unrepresentable,currentBlueId:t,error:this.unrepresentableError(t,`Stable type metadata missing versions for ${t}.`,n.runtime,o,i,r)};const a=l[0].repositoryVersionIndex;if(i<a)return{kind:v.unrepresentable,currentBlueId:t,error:this.unrepresentableError(t,`Type introduced after target repository version index ${i}.`,n.runtime,o,i,r)};let p=l[0].typeBlueId;for(const h of l)h.repositoryVersionIndex<=i&&(p=h.typeBlueId);const y=o.status===b.BLUE_REPOSITORY_STATUS_STABLE?this.getDropPointers(o,i):[];return{kind:v.representable,currentBlueId:t,targetBlueId:p,dropPointers:y}}getDropPointers(e,t){return e.status!==b.BLUE_REPOSITORY_STATUS_STABLE?[]:hn(e.versions,t)}applyDropPointers(e,t,r={}){if(e.length===0||t.length===0)return;const n=r.rootIsSchema??!1;for(const i of t)for(const o of e)this.deletePropertyAtPointer(o,i,n)}getDictionaryValueTargets(e){const t=e.getProperties();return t?Object.entries(t).filter(([r,n])=>n instanceof d&&!fn.has(r)).map(([,r])=>r):[]}deletePropertyAtPointer(e,t,r){let n;try{n=b.parsePointer(t)}catch{throw this.invalidPointerError(t)}this.applyPointerSegments(e,n,r)}applyPointerSegments(e,t,r){if(t.length===0)return;const[n,...i]=t;if(n===W){const a=e.getType();a&&this.applyPointerSegments(a,i,!0);return}if(n===he){const a=e.getItemType();a&&this.applyPointerSegments(a,i,!0);return}if(n===fe){const a=e.getKeyType();a&&this.applyPointerSegments(a,i,!0);return}if(n===ye){const a=e.getValueType();a&&this.applyPointerSegments(a,i,!0);return}const o=e.getProperties();if(!o)return;if(i.length===0){if(!r||!(n in o))return;const a={...o};delete a[n],e.setProperties(a);return}const l=o[n];l instanceof d&&this.applyPointerSegments(l,i,r)}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=g.deserialize(i);o.setBlueId(void 0);const l=B.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 Se(M.INVALID_REPOSITORY_POINTER,t,[{code:M.INVALID_REPOSITORY_POINTER,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===b.BLUE_REPOSITORY_STATUS_STABLE){const y=n.versions?.[0]?.repositoryVersionIndex;y!==void 0&&(a.typeIntroducedInRepoBlueId=r?.repositoryVersions[y])}const p={code:M.REPO_UNREPRESENTABLE_IN_TARGET_VERSION,message:t,locationPath:[W],context:a};return new Se(M.REPO_UNREPRESENTABLE_IN_TARGET_VERSION,t,[p])}}function Ge(s,e){return e?B.transform(s,t=>(be(()=>t.getType(),r=>t.setType(r),e),be(()=>t.getItemType(),r=>t.setItemType(r),e),be(()=>t.getKeyType(),r=>t.setKeyType(r),e),be(()=>t.getValueType(),r=>t.setValueType(r),e),t)):s}function be(s,e,t){const r=s();if(!r||r.isInlineValue())return;const n=r.getBlueId();if(!n)return;const i=t.toCurrentBlueId(n);i!==n&&e(r.clone().setBlueId(i))}class gn{registry;blueIdMapper;constructor(e){this.registry=e.registry,this.blueIdMapper=e.blueIdMapper}transform(e,t){const r=this.computeTargetRepoVersionIndexes(t);if(Object.keys(r).length===0)return e;const n=Ge(e,this.blueIdMapper);return new yn({registry:this.registry,targetRepoVersionIndexes:r,fallbackToCurrentInlineDefinitions:t.fallbackToCurrentInlineDefinitions!==!1}).transform(n)}computeTargetRepoVersionIndexes(e){const t={};if(!e?.repositories)return t;const r=typeof e.repositories=="string"?dn(e.repositories):e.repositories;for(const[n,i]of Object.entries(r)){const o=this.registry.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:M.REPO_UNKNOWN_REPO_BLUE_ID,message:n,locationPath:[],context:{repoName:e,requestedRepoBlueId:t,serverRepoBlueId:r}};return new Se(M.REPO_UNKNOWN_REPO_BLUE_ID,n,[i])}}class mn{nodeProvider;typeSchemaResolver;blueDirectivePreprocessor;urlContentFetcher;blueIdsMappingGenerator;globalLimits=Y;mergingProcessor;repositories;repositoryRegistry;blueContextResolver;constructor(e={}){const{nodeProvider:t,typeSchemaResolver:r=null,urlFetchStrategy:n,repositories:i,mergingProcessor:o}=e;this.repositories=i,this.repositoryRegistry=new Zs(i??[]),this.blueContextResolver=new gn({registry:this.repositoryRegistry,blueIdMapper:this.repositoryRegistry});const l=Ts(()=>[]);this.nodeProvider=pe.wrap(t||l,i),this.typeSchemaResolver=r??new Yt([],{nodeProvider:this.nodeProvider}),this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this.mergingProcessor=o??Ks(),this.urlContentFetcher=new zs(n),this.blueDirectivePreprocessor=new Ls(void 0,this.urlContentFetcher),this.blueIdsMappingGenerator=new at,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.blueContextResolver.transform(e,r.blueContext):e;return m.get(n,r.format)}nodeToYaml(e,t="official"){const r=this.normalizeNodeToJsonOptions(t),n=r.blueContext?this.blueContextResolver.transform(e,r.blueContext):e;return ws.get(n,{strategy:r.format})}nodeToSchemaOutput(e,t){return new Is(this.typeSchemaResolver).convert(e,t)}resolve(e,t=Y){const r=this.combineWithGlobalLimits(t);return new tr(this.mergingProcessor,this.nodeProvider).resolve(e,r)}createResolvedNode(e){return e instanceof H?e:new H(e)}reverse(e){return new Jt().reverse(e)}restoreInlineTypes(e){return new Js({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).restore(e)}extend(e,t){const r=this.combineWithGlobalLimits(t);new lt(this.nodeProvider).extend(e,r)}jsonValueToNode(e){const t=this.preprocess(g.deserialize(e));return Ge(t,this.repositoryRegistry)}async jsonValueToNodeAsync(e){const t=await this.preprocessAsync(g.deserialize(e));return Ge(t,this.repositoryRegistry)}yamlToNode(e){const t=D(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=D(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}prepareForBlueIdCalculation=async e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?await Promise.all(e.map(r=>this.jsonValueToNodeAsync(r))):this.jsonValueToNodeAsync(e);calculateBlueId=async e=>{const t=await this.prepareForBlueIdCalculation(e);return I.calculateBlueId(t)};prepareForBlueIdCalculationSync=e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?e.map(t=>this.jsonValueToNode(t)):this.jsonValueToNode(e);calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return I.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new ne({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new ne({nodeProvider:this.nodeProvider,blueIdsMappingGenerator:this.blueIdsMappingGenerator}).preprocessWithDefaultBlue(t)}transform(e,t){return B.transform(e,t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=pe.wrap(e,this.repositories),this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this}getTypeSchemaResolver(){return this.typeSchemaResolver}setTypeSchemaResolver(e){return this.typeSchemaResolver=e,this.typeSchemaResolver?.setNodeProvider(this.nodeProvider),this}getUrlContentFetcher(){return this.urlContentFetcher}setUrlFetchStrategy(e){return this.urlContentFetcher.setFetchStrategy(e),this}enablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.enableFetching(),this}enablePreprocessingDirectivesFetchForDomains(e){return this.urlContentFetcher.enableFetchingForDomains(e),this}allowUrlFetchingForDomain(e){return this.urlContentFetcher.allowDomain(e),this}disallowUrlFetchingForDomain(e){return this.urlContentFetcher.disallowDomain(e),this}getAllowedUrlFetchingDomains(){return this.urlContentFetcher.getAllowedDomains()}disablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.disableFetching(),this}isPreprocessingDirectivesFetchForUrlsEnabled(){return this.urlContentFetcher.isFetchingEnabled()}getPreprocessingAliases(){return this.blueDirectivePreprocessor.getPreprocessingAliases()}setPreprocessingAliases(e){return this.blueDirectivePreprocessor.setPreprocessingAliases(e),this}registerBlueIds(...e){return this.blueIdsMappingGenerator.registerBlueIds(...e),this}getAllRegisteredBlueIds(){return this.blueIdsMappingGenerator.getAllBlueIds()}getAllBlueIdNames(){return this.blueIdsMappingGenerator.getAllBlueIdNames()}getBlueIdsMappingGenerator(){return this.blueIdsMappingGenerator}isTypeOf(e,t,r){return A.isTypeOf(e,t,{checkSchemaExtensions:r?.checkSchemaExtensions,typeSchemaResolver:this.typeSchemaResolver})}isTypeOfBlueId(e,t){const r=t.trim();if(r.length===0)return!1;const n=e.getType();if(!n)return!1;const i=new d().setBlueId(r);return N(n,i,this.nodeProvider)}isTypeOfNode(e,t){return new is(this).matchesType(e,t,this.globalLimits)}setGlobalLimits(e){return this.globalLimits=e??Y,this}getGlobalLimits(){return this.globalLimits}normalizeNodeToJsonOptions(e){return typeof e=="string"?{format:e,blueContext:void 0}:{format:e?.format??"official",blueContext:e?.blueContext}}combineWithGlobalLimits(e){return this.globalLimits==Y?e:e==Y?this.globalLimits:Me.of(this.globalLimits,e)}}class In extends Ht{blueIdToContentMap=new Map;blueIdToMultipleDocumentsMap=new Map;preprocessor;constructor(e=[]){super();const t=new ne({nodeProvider:this});this.preprocessor=r=>t.preprocessWithDefaultBlue(r),e.forEach(r=>this.processNode(r))}processNode(e){Re.hasItemsOnly(e)?this.processNodeWithItems(e):this.processSingleNode(e)}processSingleNode(e){const t=J.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=J.parseAndCalculateBlueIdForNodeList(t,this.preprocessor);this.blueIdToContentMap.set(r.blueId,r.content),this.blueIdToMultipleDocumentsMap.set(r.blueId,!0),t.forEach((n,i)=>{const o=n.getName();o&&this.addToNameMap(o,`${r.blueId}#${i}`)})}processNodeList(e){const t=I.calculateBlueIdSync(e),r=e.map(n=>m.get(n));this.blueIdToContentMap.set(t,r),this.blueIdToMultipleDocumentsMap.set(t,!0)}fetchContentByBlueId(e){const t=this.blueIdToContentMap.get(e),r=this.blueIdToMultipleDocumentsMap.get(e);return t!==void 0&&r!==void 0?J.resolveThisReferences(t,e,r):null}addSingleNodes(...e){e.forEach(t=>this.processNode(t))}addSingleDocs(...e){e.forEach(t=>{const r=D(t);if(r!==void 0){const n=g.deserialize(r);this.processNode(n)}})}getBlueIdByName(e){const t=this.nameToBlueIdsMap.get(e);if(!t||t.length===0)throw new Error(`No node with name "${e}"`);return t[0]}getNodeByName(e){const t=this.findNodeByName(e);if(!t)throw new Error(`No node with name "${e}"`);return t}addListAndItsItemsFromNodes(e){this.processNodeList(e),e.forEach(t=>this.processNode(t))}addListAndItsItemsFromDoc(e){const t=D(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=Pt;exports.BasicNodeProvider=In;exports.Blue=mn;exports.BlueIdCalculator=I;exports.BlueIdToCid=Dr;exports.BlueNode=d;exports.BlueNodeTypeSchema=A;exports.JsonCanonicalizer=Be;exports.Limits=Oe;exports.Merger=tr;exports.MergingProcessors=Ys;exports.NodeResolver=er;exports.Nodes=Re;exports.Properties=yr;exports.ResolvedBlueNode=H;exports.TypeSchemaResolver=Yt;exports.applyBlueNodePatch=kr;exports.baseBlueObjectSchema=me;exports.blueDescriptionField=Kr;exports.blueIdField=Zr;exports.blueIdSchema=mr;exports.blueNameField=Gr;exports.blueNodeField=Wr;exports.blueObjectBooleanValueSchema=br;exports.blueObjectNumberValueSchema=Tr;exports.blueObjectSchema=re;exports.blueObjectStringListItemsSchema=vr;exports.blueObjectStringValueSchema=Ir;exports.calculateBlueId=Xt;exports.calculateBlueIdSync=Os;exports.enrichWithBlueId=Je;exports.getBlueDescriptionAnnotation=Mt;exports.getBlueIdAnnotation=xt;exports.getBlueNameAnnotation=$t;exports.getBlueNodeAnnotation=Lt;exports.getBlueObjectItems=Ds;exports.getBlueObjectProperties=_s;exports.getBlueObjectTypeLabel=xs;exports.getBlueObjectValue=Ms;exports.getTypeBlueIdAnnotation=Ut;exports.hasBlueObjectBlueIdDefined=Bt;exports.hasBlueObjectItemsDefined=wt;exports.hasBlueObjectNameDefined=Br;exports.hasBlueObjectTypeDefined=Et;exports.hasBlueObjectValueDefined=St;exports.isBigDecimalNumber=Ne;exports.isBigIntegerNumber=F;exports.isBigNumber=C;exports.isBlueNodeSchema=it;exports.isBlueObject=Nr;exports.isBlueObjectResolved=Qt;exports.isGivenBlueObjectTypeSchema=wr;exports.isJsonBlueArray=tt;exports.isJsonBlueObject=et;exports.isJsonBlueValue=Pr;exports.isUrl=ae;exports.jsonBlueValueSchema=ce;exports.normalizeToBlueObject=Fs;exports.resolveBlueObjectItems=Ze;exports.withBlueDescription=Dt;exports.withBlueId=_t;exports.withBlueName=Ft;exports.withBlueNode=jt;exports.withTypeBlueId=qr;exports.yamlBlueDump=Gt;exports.yamlBlueParse=D;
package/dist/index.mjs CHANGED
@@ -3692,9 +3692,9 @@ class Ws extends Js {
3692
3692
  let n = e;
3693
3693
  const i = t.getType();
3694
3694
  if (p(i)) {
3695
- const o = this.resolveTypeNode(i, r), l = o.cloneShallow().setType(void 0);
3695
+ const o = this.resolveTypeNode(i, r), l = o.clone().setType(void 0);
3696
3696
  n = this.mergeObject(n, l, r);
3697
- const a = t.cloneShallow().setType(o);
3697
+ const a = t.cloneShallow().setType(o.clone());
3698
3698
  return this.mergeObject(n, a, r);
3699
3699
  }
3700
3700
  return this.mergeObject(n, t, r);
@@ -3738,7 +3738,7 @@ class Ws extends Js {
3738
3738
  if (r.limits.shouldMergePathSegment(String(l), a)) {
3739
3739
  this.enterPathSegment(r, String(l), a);
3740
3740
  try {
3741
- const u = a.isResolved() && this.canReuseResolvedSubtree(r) ? a : this.resolveWithContext(a, r);
3741
+ const u = a.isResolved() && this.canReuseResolvedSubtree(r) ? a.clone() : this.resolveWithContext(a, r);
3742
3742
  o.push(u);
3743
3743
  } finally {
3744
3744
  this.exitPathSegment(r);
@@ -3788,7 +3788,7 @@ class Ws extends Js {
3788
3788
  if (r.limits.shouldMergePathSegment(l, a)) {
3789
3789
  this.enterPathSegment(r, l, a);
3790
3790
  try {
3791
- const u = a.isResolved() && this.canReuseResolvedSubtree(r) ? a : this.resolveWithContext(a, r), y = i[l], d = y === void 0 ? u : this.mergeObject(y, u, r);
3791
+ const u = a.isResolved() && this.canReuseResolvedSubtree(r) ? a.clone() : this.resolveWithContext(a, r), y = i[l], d = y === void 0 ? u : this.mergeObject(y, u, r);
3792
3792
  d !== y && (o || (i = { ...n }, o = !0), i[l] = d);
3793
3793
  } finally {
3794
3794
  this.exitPathSegment(r);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blue-labs/language",
3
- "version": "3.4.2",
3
+ "version": "3.4.3",
4
4
  "dependencies": {
5
5
  "@blue-labs/repository-contract": "*",
6
6
  "@blue-labs/shared-utils": "*",