@kanonak-protocol/sdk 5.19.0 → 5.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.d.ts CHANGED
@@ -18,8 +18,8 @@ export { Kanonak, DefinedKanonak, SubjectKanonak, EmbeddedKanonak, ReferenceKano
18
18
  export type { IStatement } from './statements/index.js';
19
19
  export type { MarkdownLink } from './statements/index.js';
20
20
  export { Statement, ScalarStatement, StringStatement, NumberStatement, BooleanStatement, ReferenceStatement, EmbeddedStatement, ListStatement, MarkdownStatement } from './statements/index.js';
21
- export { ResourceResolver, KanonakUri, KanonakUriBuilder, TypeResolver, ResourceTypeClassifier, findInstancesByType, compareVersions, versionsEqual, formatVersion, parseVersionString, createVersion, isCompatibleVersion, isMajorCompatible, pickHighestDocument, } from './resolution/index.js';
22
- export type { ResourceResolutionResult, ILogger, InstanceSearchResult, DocumentVersionPick, } from './resolution/index.js';
21
+ export { ResourceResolver, KanonakUri, KanonakUriBuilder, TypeResolver, ResourceTypeClassifier, compareVersions, versionsEqual, formatVersion, parseVersionString, createVersion, isCompatibleVersion, isMajorCompatible, pickHighestDocument, } from './resolution/index.js';
22
+ export type { ResourceResolutionResult, ILogger, DocumentVersionPick, } from './resolution/index.js';
23
23
  export { InMemoryKanonakDocumentRepository } from './repositories/InMemoryKanonakDocumentRepository.js';
24
24
  export { HttpKanonakDocumentRepository } from './repositories/HttpKanonakDocumentRepository.js';
25
25
  export { PublisherIndex } from './repositories/PublisherIndex.js';
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- import{a as B,b as _,c as q,d as Ie,e as Ke,f as Se,g as be,i as je,j as Oe,k as De,l as Ve,m as Ee}from"./chunk-5TI4E6M7.js";import{a as ve}from"./chunk-LYSCTQC2.js";import"./chunk-QHABFCRC.js";import{a as c,b as m,c as u,e as d,h as y,i as R,j as f,k,l as x,m as P,n as g}from"./chunk-W35FCNM7.js";import{a as p}from"./chunk-4NO7MHS7.js";import{a as w,b as z,c as W}from"./chunk-5NH5XDGO.js";import{a as X,b as Y}from"./chunk-PEUTCG3B.js";import"./chunk-PEJALHXK.js";import"./chunk-SC5M74NM.js";import{A as ge,B as Ce,L as he,a as J,b as Q,c as Z,d as $,f as ee,g as oe,h as te,i as re,k as ne,l as ae,m as ie,n as se,o as pe,p as le,q as ce,r as me,s as ue,t as de,u as ye,v as Re,w as fe,x as ke,y as xe,z as Pe}from"./chunk-UYSEO3OT.js";import"./chunk-M443OYKT.js";import{a as K,c as A,i as U,j as G,m as H}from"./chunk-V6KIDED2.js";import{a as l}from"./chunk-NJ3AZYQD.js";import{a as F,b as L,o as M}from"./chunk-SVUMCLK5.js";import{a as C,b as h,c as I,d as b,e as j,f as O,g as D,h as V,i as v,j as E,k as N,l as T}from"./chunk-YW6P24RF.js";import{a as S}from"./chunk-FUUTGGJS.js";import{c as e,d as o,e as t,f as r,g as n,h as a,i,j as s}from"./chunk-2ACBWC7K.js";export{ye as AmbiguousReferenceRule,v as BooleanStatement,Se as CANONICAL_FORM_VERSION,U as Carrier,ge as ClassDefinitionRule,se as ClassHierarchyCycleRule,h as DefinedKanonak,_ as EdgeType,K as EmbeddedKanonak,ne as EmbeddedKanonakTypeRule,N as EmbeddedStatement,q as GraphBuilder,g as HttpKanonakDocumentRepository,R as INTEGRITY_PREFIX,ae as ImportExistenceRule,p as InMemoryKanonakDocumentRepository,c as KANONAK_USER_AGENT,C as Kanonak,z as KanonakDocumentPositions,H as KanonakObjectParser,he as KanonakObjectValidator,l as KanonakParser,S as KanonakUri,X as KanonakUriBuilder,T as ListStatement,Ce as MarkdownLinkRule,A as MarkdownStatement,ue as NamespaceImportCycleRule,ee as NamespacePrefixRule,B as NodeType,V as NumberStatement,je as OAuthDiscovery,fe as ObjectPropertyValueValidationRule,Z as OntologyValidationError,J as OntologyValidationResult,ke as PropertyDomainRule,pe as PropertyHierarchyCycleRule,xe as PropertyKindRangeConsistencyRule,w as PropertyMetadata,Re as PropertyRangeReferenceRule,le as PropertyRangeRequiredRule,te as PropertyTypeSpecificityRule,y as PublisherConfigResolver,P as PublisherIndex,b as ReferenceKanonak,E as ReferenceStatement,Pe as ReservedNameShadowRule,oe as ResourceNamingRule,F as ResourceResolver,M as ResourceTypeClassifier,O as ScalarStatement,j as Statement,D as StringStatement,ce as SubClassOfReferenceRule,me as SubPropertyOfReferenceRule,I as SubjectKanonak,re as SubjectKanonakTypeRequiredRule,Ve as TokenCredentialProvider,L as TypeResolver,de as UnresolvedPredicateRule,ie as UnresolvedReferenceRule,$ as ValidationContext,Q as ValidationSeverity,Ee as buildOntologyModel,Ie as canonicalForm,Ke as canonicalHash,G as carrierOf,e as compareVersions,x as computeIntegrityAsync,De as createCredentialedFetch,r as createVersion,ve as findDerivation,Y as findInstancesByType,t as formatVersion,u as getKanonakUserAgent,a as isCompatibleVersion,i as isMajorCompatible,d as kanonakFetch,be as normalizeHost,Oe as parseAuthChallenge,f as parseLockFile,n as parseVersionString,W as parseWithPositions,s as pickHighestDocument,k as serializeLockFile,m as setKanonakUserAgent,o as versionsEqual};
1
+ import{a as _,b as q,c as w,d as he,e as Ke,f as Se,g as Ie,i as be,j as je,k as Oe,l as De,m as ve}from"./chunk-LCUTS2KL.js";import{a as Ve}from"./chunk-LYSCTQC2.js";import{a as m,b as c,c as u,e as d,h as R,i as y,j as f,k,l as x,m as P,n as g}from"./chunk-CCVH7TCQ.js";import{a as B,b as z,c as W}from"./chunk-5NH5XDGO.js";import{a as X}from"./chunk-PEB52US5.js";import"./chunk-SC5M74NM.js";import{A as Pe,B as ge,L as Ce,a as Y,b as J,c as Q,d as Z,f as $,g as ee,h as oe,i as te,k as re,l as ne,m as ae,n as ie,o as se,p as pe,q as le,r as me,s as ce,t as ue,u as de,v as Re,w as ye,x as fe,y as ke,z as xe}from"./chunk-AB42RUYY.js";import"./chunk-M443OYKT.js";import"./chunk-SYNN77GG.js";import{a as p}from"./chunk-4NO7MHS7.js";import{a as S,c as A,i as U,j as G,m as H}from"./chunk-V6KIDED2.js";import{a as l}from"./chunk-NJ3AZYQD.js";import"./chunk-PEJALHXK.js";import{a as F,b as L,o as M}from"./chunk-SVUMCLK5.js";import{a as C,b as h,c as K,d as b,e as j,f as O,g as D,h as V,i as v,j as E,k as N,l as T}from"./chunk-YW6P24RF.js";import{a as I}from"./chunk-FUUTGGJS.js";import{c as e,d as o,e as t,f as r,g as n,h as a,i,j as s}from"./chunk-2ACBWC7K.js";export{de as AmbiguousReferenceRule,v as BooleanStatement,Se as CANONICAL_FORM_VERSION,U as Carrier,Pe as ClassDefinitionRule,ie as ClassHierarchyCycleRule,h as DefinedKanonak,q as EdgeType,S as EmbeddedKanonak,re as EmbeddedKanonakTypeRule,N as EmbeddedStatement,w as GraphBuilder,g as HttpKanonakDocumentRepository,y as INTEGRITY_PREFIX,ne as ImportExistenceRule,p as InMemoryKanonakDocumentRepository,m as KANONAK_USER_AGENT,C as Kanonak,z as KanonakDocumentPositions,H as KanonakObjectParser,Ce as KanonakObjectValidator,l as KanonakParser,I as KanonakUri,X as KanonakUriBuilder,T as ListStatement,ge as MarkdownLinkRule,A as MarkdownStatement,ce as NamespaceImportCycleRule,$ as NamespacePrefixRule,_ as NodeType,V as NumberStatement,be as OAuthDiscovery,ye as ObjectPropertyValueValidationRule,Q as OntologyValidationError,Y as OntologyValidationResult,fe as PropertyDomainRule,se as PropertyHierarchyCycleRule,ke as PropertyKindRangeConsistencyRule,B as PropertyMetadata,Re as PropertyRangeReferenceRule,pe as PropertyRangeRequiredRule,oe as PropertyTypeSpecificityRule,R as PublisherConfigResolver,P as PublisherIndex,b as ReferenceKanonak,E as ReferenceStatement,xe as ReservedNameShadowRule,ee as ResourceNamingRule,F as ResourceResolver,M as ResourceTypeClassifier,O as ScalarStatement,j as Statement,D as StringStatement,le as SubClassOfReferenceRule,me as SubPropertyOfReferenceRule,K as SubjectKanonak,te as SubjectKanonakTypeRequiredRule,De as TokenCredentialProvider,L as TypeResolver,ue as UnresolvedPredicateRule,ae as UnresolvedReferenceRule,Z as ValidationContext,J as ValidationSeverity,ve as buildOntologyModel,he as canonicalForm,Ke as canonicalHash,G as carrierOf,e as compareVersions,x as computeIntegrityAsync,Oe as createCredentialedFetch,r as createVersion,Ve as findDerivation,t as formatVersion,u as getKanonakUserAgent,a as isCompatibleVersion,i as isMajorCompatible,d as kanonakFetch,Ie as normalizeHost,je as parseAuthChallenge,f as parseLockFile,n as parseVersionString,W as parseWithPositions,s as pickHighestDocument,k as serializeLockFile,c as setKanonakUserAgent,o as versionsEqual};
@@ -1 +1 @@
1
- import{n as v}from"./chunk-W35FCNM7.js";import{a as w}from"./chunk-4NO7MHS7.js";import{a as f}from"./chunk-NJ3AZYQD.js";import{c as A,d as R,g as b,h as F,i as S}from"./chunk-2ACBWC7K.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as x}from"url";import{VersionOperator as P}from"@kanonak-protocol/types/document/models/enums";var y=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(e,t=!0,n){if(!e||e.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=c.resolve(e),this.recursive=t,this.parser=n??new f,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let e=new Set(this.documentCache.values());return Array.from(e)}async getDocumentAsync(e){await this.ensureCacheInitialized();let t=this.documentCache.get(e);if(t)return t;let n=c.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let o of[".kan.yml",".yml",".yaml"])if(!e.endsWith(o)){let s=e+o;if(t=this.documentCache.get(s),t)return t;let a=c.join(this.rootPath,s);if(t=this.documentCache.get(a),t)return t}return null}async getDocumentsByNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(o=>o.metadata.namespace_?.publisher===e&&o.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),o=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(o.length===0)return null;let s=o.filter(a=>{let r=a.metadata.namespace_.version;switch(t.versionOperator){case P.Exact:return R(r,t.version);case P.Compatible:return F(r,t.version);case P.Major:return S(r,t.version);case P.Any:return A(r,t.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,l=r.metadata.namespace_.version;return A(l,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),l=m[0],h=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,l,h)}else n=c.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=c.dirname(n);await i.mkdir(s,{recursive:!0});let a=this.parser.save(e);await i.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=c.relative(this.rootPath,n);this.documentCache.set(r,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await i.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=c.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=[];for(let[s,a]of this.documentCache.entries()){let r=a.metadata.namespace_?.toString()||"";r.includes(e)&&r.includes(t)&&n.push([s,a])}let o=c.join(this.rootPath,e);try{let s=await i.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await i.unlink(c.join(o,a))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let e=new Set(this.filePathsByIdentifier.values()),t=[];for(let n of e){let o=x(n).toString(),s;for(let[m,l]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&l.metadata.namespace_){s=l.metadata.namespace_.toString();break}let a=s??c.relative(this.rootPath,n),r=this.parsingErrors.has(n);t.push({identifier:a,uri:o,hasParseError:r})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}try{return await i.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}return x(t).toString()}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as g from"fs";var _=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(_||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;g.existsSync(e)||g.mkdirSync(e,{recursive:!0}),g.existsSync(t)||g.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as $}from"os";import{join as B}from"path";function d(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||B($(),".kanonak","packages")}var C=class u{static createComposite(e,t,n){let o=e??d(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=d(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[],t=new Set;for(let n of this.repos)try{for(let o of await n.getAllDocumentsAsync()){let s=o.metadata?.namespace_,a=s?s.version?`${s.publisher}/${s.package_}@${s.version.major}.${s.version.minor}.${s.version.patch}`:`${s.publisher}/${s.package_}`:void 0;if(a!==void 0){if(t.has(a))continue;t.add(a)}e.push(o)}}catch{}return e}async getDocumentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentAsync(e);if(n)return n}catch{}return null}async getDocumentsByNamespaceAsync(e,t){for(let n of this.repos)try{let o=await n.getDocumentsByNamespaceAsync(e,t);if(o.length>0)return o}catch{}return[]}async saveDocumentAsync(e,t){await this.repos[0].saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.repos[0].deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.repos[0].clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){return this.repos[0].getAllDocumentReferencesAsync()}async getDocumentContentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentContentAsync(e);if(n)return n}catch{}return null}async getDocumentUriAsync(e){for(let t of this.repos)try{let n=await t.getDocumentUriAsync(e);if(n)return n}catch{}return null}};import{VersionOperator as H}from"@kanonak-protocol/types/document/models/enums";var K=class{constructor(e,t){this.base=e;this.lock=t}base;lock;pinnedVersion(e,t){return this.lock.packages[`${e}/${t}`]?.version}async getHighestCompatibleVersionAsync(e,t){let n=this.pinnedVersion(e,t.packageName);if(n){let o=b(n);if(o){let s={...t,versionOperator:H.Exact,version:o};return this.base.getHighestCompatibleVersionAsync(e,s)}}return this.base.getHighestCompatibleVersionAsync(e,t)}async getDocumentsByNamespaceAsync(e,t){let n=await this.base.getDocumentsByNamespaceAsync(e,t),o=this.pinnedVersion(e,t);return o?n.filter(s=>{let a=s.metadata.namespace_?.version;return a?`${a.major}.${a.minor}.${a.patch}`===o:!1}):n}getAllDocumentsAsync(){return this.base.getAllDocumentsAsync()}getDocumentAsync(e){return this.base.getDocumentAsync(e)}saveDocumentAsync(e,t){return this.base.saveDocumentAsync(e,t)}deleteDocumentAsync(e){return this.base.deleteDocumentAsync(e)}clearNamespaceAsync(e,t){return this.base.clearNamespaceAsync(e,t)}getAllDocumentReferencesAsync(){return this.base.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.base.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.base.getDocumentUriAsync(e)}};import{readFileSync as V,readdirSync as j}from"fs";import{join as N}from"path";var E=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function I(u,e=[]){for(let t of j(u,{withFileTypes:!0}))t.isDirectory()?E.has(t.name)||I(N(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(N(u,t.name));return e}async function z(u,e=new f,t={}){let n=new w(e);for(let m of I(u))try{let l=e.parse(V(m,"utf-8")),p=l.metadata?.namespace_,h=p?.version;p&&h&&await n.saveDocumentAsync(l,`${p.publisher}/${p.package_}@${h.major}.${h.minor}.${h.patch}`)}catch{}let o=new y(d(),!0,e),s=new Map,a=t.httpCache??{getFromCache:(m,l,p)=>s.get(`${m}|${l}|${p}`)??null,onFetch:(m,l,p,h)=>{s.set(`${m}|${l}|${p}`,h)}},r=new v({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,_ as b,k as c,d,C as e,D as f,K as g,I as h,z as i};
1
+ import{n as v}from"./chunk-CCVH7TCQ.js";import{a as w}from"./chunk-4NO7MHS7.js";import{a as f}from"./chunk-NJ3AZYQD.js";import{c as A,d as R,g as b,h as F,i as S}from"./chunk-2ACBWC7K.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as x}from"url";import{VersionOperator as P}from"@kanonak-protocol/types/document/models/enums";var y=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(e,t=!0,n){if(!e||e.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=c.resolve(e),this.recursive=t,this.parser=n??new f,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let e=new Set(this.documentCache.values());return Array.from(e)}async getDocumentAsync(e){await this.ensureCacheInitialized();let t=this.documentCache.get(e);if(t)return t;let n=c.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let o of[".kan.yml",".yml",".yaml"])if(!e.endsWith(o)){let s=e+o;if(t=this.documentCache.get(s),t)return t;let a=c.join(this.rootPath,s);if(t=this.documentCache.get(a),t)return t}return null}async getDocumentsByNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(o=>o.metadata.namespace_?.publisher===e&&o.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),o=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(o.length===0)return null;let s=o.filter(a=>{let r=a.metadata.namespace_.version;switch(t.versionOperator){case P.Exact:return R(r,t.version);case P.Compatible:return F(r,t.version);case P.Major:return S(r,t.version);case P.Any:return A(r,t.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,l=r.metadata.namespace_.version;return A(l,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),l=m[0],h=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,l,h)}else n=c.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=c.dirname(n);await i.mkdir(s,{recursive:!0});let a=this.parser.save(e);await i.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=c.relative(this.rootPath,n);this.documentCache.set(r,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await i.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=c.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=[];for(let[s,a]of this.documentCache.entries()){let r=a.metadata.namespace_?.toString()||"";r.includes(e)&&r.includes(t)&&n.push([s,a])}let o=c.join(this.rootPath,e);try{let s=await i.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await i.unlink(c.join(o,a))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let e=new Set(this.filePathsByIdentifier.values()),t=[];for(let n of e){let o=x(n).toString(),s;for(let[m,l]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&l.metadata.namespace_){s=l.metadata.namespace_.toString();break}let a=s??c.relative(this.rootPath,n),r=this.parsingErrors.has(n);t.push({identifier:a,uri:o,hasParseError:r})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}try{return await i.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}return x(t).toString()}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as g from"fs";var _=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(_||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;g.existsSync(e)||g.mkdirSync(e,{recursive:!0}),g.existsSync(t)||g.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as $}from"os";import{join as B}from"path";function d(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||B($(),".kanonak","packages")}var C=class u{static createComposite(e,t,n){let o=e??d(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=d(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[],t=new Set;for(let n of this.repos)try{for(let o of await n.getAllDocumentsAsync()){let s=o.metadata?.namespace_,a=s?s.version?`${s.publisher}/${s.package_}@${s.version.major}.${s.version.minor}.${s.version.patch}`:`${s.publisher}/${s.package_}`:void 0;if(a!==void 0){if(t.has(a))continue;t.add(a)}e.push(o)}}catch{}return e}async getDocumentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentAsync(e);if(n)return n}catch{}return null}async getDocumentsByNamespaceAsync(e,t){for(let n of this.repos)try{let o=await n.getDocumentsByNamespaceAsync(e,t);if(o.length>0)return o}catch{}return[]}async saveDocumentAsync(e,t){await this.repos[0].saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.repos[0].deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.repos[0].clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){return this.repos[0].getAllDocumentReferencesAsync()}async getDocumentContentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentContentAsync(e);if(n)return n}catch{}return null}async getDocumentUriAsync(e){for(let t of this.repos)try{let n=await t.getDocumentUriAsync(e);if(n)return n}catch{}return null}};import{VersionOperator as H}from"@kanonak-protocol/types/document/models/enums";var K=class{constructor(e,t){this.base=e;this.lock=t}base;lock;pinnedVersion(e,t){return this.lock.packages[`${e}/${t}`]?.version}async getHighestCompatibleVersionAsync(e,t){let n=this.pinnedVersion(e,t.packageName);if(n){let o=b(n);if(o){let s={...t,versionOperator:H.Exact,version:o};return this.base.getHighestCompatibleVersionAsync(e,s)}}return this.base.getHighestCompatibleVersionAsync(e,t)}async getDocumentsByNamespaceAsync(e,t){let n=await this.base.getDocumentsByNamespaceAsync(e,t),o=this.pinnedVersion(e,t);return o?n.filter(s=>{let a=s.metadata.namespace_?.version;return a?`${a.major}.${a.minor}.${a.patch}`===o:!1}):n}getAllDocumentsAsync(){return this.base.getAllDocumentsAsync()}getDocumentAsync(e){return this.base.getDocumentAsync(e)}saveDocumentAsync(e,t){return this.base.saveDocumentAsync(e,t)}deleteDocumentAsync(e){return this.base.deleteDocumentAsync(e)}clearNamespaceAsync(e,t){return this.base.clearNamespaceAsync(e,t)}getAllDocumentReferencesAsync(){return this.base.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.base.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.base.getDocumentUriAsync(e)}};import{readFileSync as V,readdirSync as j}from"fs";import{join as N}from"path";var E=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function I(u,e=[]){for(let t of j(u,{withFileTypes:!0}))t.isDirectory()?E.has(t.name)||I(N(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(N(u,t.name));return e}async function z(u,e=new f,t={}){let n=new w(e);for(let m of I(u))try{let l=e.parse(V(m,"utf-8")),p=l.metadata?.namespace_,h=p?.version;p&&h&&await n.saveDocumentAsync(l,`${p.publisher}/${p.package_}@${h.major}.${h.minor}.${h.patch}`)}catch{}let o=new y(d(),!0,e),s=new Map,a=t.httpCache??{getFromCache:(m,l,p)=>s.get(`${m}|${l}|${p}`)??null,onFetch:(m,l,p,h)=>{s.set(`${m}|${l}|${p}`,h)}},r=new v({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,_ as b,k as c,d,C as e,D as f,K as g,I as h,z as i};
@@ -1 +1 @@
1
- import{i,j as o,k as r}from"./chunk-W35FCNM7.js";import{readFileSync as c,writeFileSync as l,existsSync as s}from"fs";import{createHash as a}from"crypto";var n="kanonak.lock";function f(e=n){return s(e)?o(c(e,"utf-8")):null}function k(e,t=n){e.lastUpdated=new Date().toISOString(),l(t,r(e),"utf-8")}function L(e){let t=a("sha256").update(e).digest("hex");return`${i}${t}`}export{f as a,k as b,L as c};
1
+ import{i,j as o,k as r}from"./chunk-CCVH7TCQ.js";import{readFileSync as c,writeFileSync as l,existsSync as s}from"fs";import{createHash as a}from"crypto";var n="kanonak.lock";function f(e=n){return s(e)?o(c(e,"utf-8")):null}function k(e,t=n){e.lastUpdated=new Date().toISOString(),l(t,r(e),"utf-8")}function L(e){let t=a("sha256").update(e).digest("hex");return`${i}${t}`}export{f as a,k as b,L as c};
@@ -0,0 +1,63 @@
1
+ import{a as ut}from"./chunk-M443OYKT.js";import{k as dt}from"./chunk-SYNN77GG.js";import{a as D,b as He,c as st,d as G,h as M,k as mt,m as S}from"./chunk-V6KIDED2.js";import{a as at}from"./chunk-NJ3AZYQD.js";import{j as Ye,k as ct,o as v,p as w,q as z,r as W,s as Y,v as pt,w as L,x as lt}from"./chunk-SVUMCLK5.js";import{c as f,d as I,j as We,k as Q,l as q,m as b,n as X,p as O,r as R,t as ee,u as x,v as F,w as y,x as P,y as K,z as H}from"./chunk-YW6P24RF.js";import{a as it}from"./chunk-FUUTGGJS.js";import{e as j}from"./chunk-2ACBWC7K.js";var te=class{isValid=!1;errors=[];warnings=[];infos=[];get totalIssues(){return this.errors.length+this.warnings.length+this.infos.length}get allDiagnostics(){return[...this.errors,...this.warnings,...this.infos]}};var k=(o=>(o.Info="Info",o.Warning="Warning",o.Error="Error",o))(k||{});var u=class{ruleType="";severity="Error";lineNumber;column;entityName;propertyName;propertyPath;message="";suggestion;actualValue;expectedValue;toString(){let e="";return this.lineNumber!==void 0&&(e+=`Line ${this.lineNumber}: `),this.entityName&&(e+=`[${this.entityName}] `),e+=this.message,e}};var Ze=class c{resolvedDocuments=[];currentEntityPath;withPath(e){let t=new c;return t.resolvedDocuments=this.resolvedDocuments,t.currentEntityPath=e,t}};var oe=class{constructor(e){this.underlying=e;this.repository=new Je(e)}underlying;repository;parsePromise=null;getKanonaks(){return this.parseOnce().then(e=>e.merged)}getAuthoredKanonaks(){return this.parseOnce().then(e=>e.authored)}parseOnce(){return this.parsePromise||(this.parsePromise=(async()=>{let e=await this.underlying.getAllDocumentsAsync();await ut(e,this.repository);let t={};return{merged:await new S().parseKanonaks(this.underlying,t),authored:t.authored??[]}})()),this.parsePromise}},Je=class{constructor(e){this.inner=e}inner;highestVersionCache=new Map;byNamespaceCache=new Map;getAllDocumentsAsync(){return this.inner.getAllDocumentsAsync()}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,t){let o=`${e}/${t}`,n=this.byNamespaceCache.get(o);return n||(n=this.inner.getDocumentsByNamespaceAsync(e,t),this.byNamespaceCache.set(o,n),n)}getHighestCompatibleVersionAsync(e,t){let o=t.version,n=o?`${o.major}.${o.minor}.${o.patch}`:"",r=`${e}/${t.packageName}@${t.versionOperator}:${n}`,a=this.highestVersionCache.get(r);return a||(a=this.inner.getHighestCompatibleVersionAsync(e,t),this.highestVersionCache.set(r,a),a)}saveDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}deleteDocumentAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}clearNamespaceAsync(){throw new Error("CachingRepository is read-only during a validation pass.")}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};async function E(c,e,t){return t?t.getKanonaks():new S().parseKanonaks(new ne(c,e))}async function C(c,e,t){let o=await E(c,e,t),n=Ge(c);return n?o.filter(r=>r instanceof f&&r.namespace===n):[]}async function re(c,e,t){let o=Ge(c);if(!o)return[];let n;if(t)n=await t.getAuthoredKanonaks();else{let r={};await new S().parseKanonaks(new ne(c,e),r),n=r.authored??[]}return n.filter(r=>r instanceof f&&r.sourceDoc===o)}function Ge(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var ne=class{constructor(e,t){this.document=e;this.broader=t}document;broader;async getAllDocumentsAsync(){let e=this.document.metadata.namespace_?.toString(),t=(await this.broader.getAllDocumentsAsync()).filter(o=>o.metadata.namespace_?.toString()!==e);return[this.document,...t]}getDocumentAsync(e){return this.broader.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,t){return this.broader.getDocumentsByNamespaceAsync(e,t)}getHighestCompatibleVersionAsync(e,t){return this.broader.getHighestCompatibleVersionAsync(e,t)}getAllDocumentReferencesAsync(){return this.broader.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}saveDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}deleteDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}clearNamespaceAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}};var ae=class c{static NAMESPACE_PREFIX_PATTERN=/^(rdfs|xsd|owl|rdf|dc|foaf|skos|dct|dcterms|geo|time|prov|schema|og|dbo):/i;ruleName="NamespacePrefix";validate(e){let t=[];for(let[o,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(o,n,t);return t}validateEntity(e,t,o){for(let[n,r]of Object.entries(t)){let a=r?.toString()??"";if(a&&c.NAMESPACE_PREFIX_PATTERN.test(a)){let i=this.getSuggestionForPrefixedValue(a),s=e.split(".")[0],p=new u;p.ruleType=this.ruleName,p.severity="Error",p.entityName=s,p.propertyName=e,p.actualValue=n,p.expectedValue=i,p.message=`Invalid namespace prefix '${a}'. Use '${i}' without prefix.`,p.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",o.push(p)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${n}`,r,o)}}getSuggestionForPrefixedValue(e){let t=e.toLowerCase();if(t==="rdfs:class"||t==="owl:class")return"Class";if(t==="rdfs:property"||t==="rdf:property")return"DatatypeProperty or ObjectProperty";if(t.startsWith("xsd:"))return e.substring(4);let o=e.indexOf(":");return o>=0?e.substring(o+1):e}};var ie=class c{static RESERVED_WORDS=new Set(["imports","namespace","type","label","comment","subclassof","domain","range","required","functional"]);static VALID_PROPERTIES=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","required","functional","inverseOf","transitive","symmetric","inverseFunctional"]);static VALID_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_AUGMENTATION_PATTERN=/^[a-zA-Z][a-zA-Z0-9_-]*\.[a-zA-Z][a-zA-Z0-9_-]*$/;static VALID_PROPERTY_NAME_PATTERN=/^[a-zA-Z][a-zA-Z0-9_.]*$/;ruleName="ResourceNaming";validate(e){let t=[],o=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let a=c.VALID_AUGMENTATION_PATTERN.test(n);if(!a&&!o&&c.RESERVED_WORDS.has(n.toLowerCase())){let i=new u;i.ruleType=this.ruleName,i.severity="Error",i.entityName=n,i.message=`Entity name '${n}' is a reserved word and cannot be used.`,i.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",t.push(i);continue}if(!a&&!c.VALID_NAME_PATTERN.test(n)){let i;/^\d/.test(n)?i="Entity names must start with a letter, not a number.":n.includes(" ")?i="Entity names cannot contain spaces. Use camelCase or underscores instead.":i="Entity names must start with a letter and contain only letters, numbers, and underscores.";let s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=n,s.message=`Invalid entity name '${n}'. ${i}`,s.suggestion=i,t.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,t)}return t}validatePropertyNames(e,t,o){for(let n of Object.keys(t))if(!c.VALID_PROPERTIES.has(n)&&!c.VALID_PROPERTY_NAME_PATTERN.test(n)){let r=new u;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=n,r.message=`Property name '${n}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",o.push(r)}}};var se=class c{static XSD_TYPES=new Set(["string","integer","int","long","short","byte","decimal","float","double","boolean","bool","datetime","date","time","duration","anyuri","anysimpletype","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte","base64binary","hexbinary"]);ruleName="PropertyTypeSpecificity";validate(e){let t=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return t;let o=this.isPropertyDefinedAsClass(e);for(let[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,i=a.type;if(i){let s=[];if(Array.isArray(i))for(let p of i){let l=p?.toString();l&&l==="Property"&&!o&&s.push(l)}else{let p=i?.toString();p&&p==="Property"&&!o&&s.push(p)}for(let p of s){let l=this.getPropertyValue(a,"range"),m=this.determinePropertyType(l),d=new u;d.ruleType=this.ruleName,d.severity="Error",d.entityName=n,d.propertyName="type",d.actualValue=p,d.expectedValue=m,d.message=`Invalid property type '${p}'. Use '${m}' instead.`,d.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",t.push(d)}}}return t}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":c.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,t){let o=e[t];return o?o.toString():null}isPropertyDefinedAsClass(e){let t=e.body.Property;if(t&&typeof t=="object"&&!Array.isArray(t)){let n=t.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var ce=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let t=[];for(let[o,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||o.includes("."))continue;let r=n,a="type"in r,i=r.type?.toString().trim();if(!a||!i){let s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=o,s.propertyName="type",s.message=`Subject Kanonak '${o}' must have a 'type' property.`,s.suggestion=`Add a type statement like:
2
+ type: Scene
3
+
4
+ Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,s.expectedValue="A valid class name (Scene, Character, Story, etc.)",t.push(s)}}return t}};var At=new Set(["EphemeralPackage"]),pe=class{get ruleName(){return"PackageHeader"}validate(e){let t=e.metadata;if(!t.type_)return[];let o=[],n=this.packageKey(e,t.type_);return t.namespace_?(!At.has(t.type_)&&!t.namespace_.version&&o.push(this.error(n,"version",`Package resource '${n}' requires a 'version' property \u2014 packages are addressed by name@version.`,`Add a version, e.g.:
5
+ version: 1.0.0`)),o):(o.push(this.error(n,"publisher",`Package resource '${n}' requires a 'publisher' property.`,`Add a publisher, e.g.:
6
+ publisher: example.org`)),o)}packageKey(e,t){for(let[o,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.type===t)return o;return t}error(e,t,o,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.message=o,r.suggestion=n,r}};var xt={publisher:"kanonak.org",package_:"core-rdf",name:"type"},Nt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},_t={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},Tt={publisher:"kanonak.org",package_:"core-rdf",name:"Class"},le=class{ruleName="EmbeddedKanonakType";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await re(e,t,o);for(let i of a)i instanceof f&&this.walk(r,i,i.name,n);return n}walk(e,t,o,n){for(let r of t.statement)if(r instanceof Q){let a=r.predicate?.subject,i=`${o}.${a?.name??"<embedded>"}`;this.check(e,a,r.object,o,i,n),this.walk(e,r.object,i,n)}else if(r instanceof q){let a=r.predicate?.subject,i=0;for(let s of r.object){if(s instanceof D){let p=`${o}.${a?.name??"<embedded>"}[${i}]`;this.check(e,a,s,o,p,n),this.walk(e,s,p,n)}i++}}}check(e,t,o,n,r,a){if(!t)return;let i=y(o,xt);if(!i)return;let s=R(e,t);if(!s)return;let p=y(s,Nt);if(p&&!(X(p,_t)||X(p,Tt))){if(b(i)===b(p)){a.push(this.redundant(n,r,i,p));return}z(e,i).some(l=>b(l)===b(p))||a.push(this.notSubclass(n,r,i,p))}}redundant(e,t,o,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=t,r.actualValue=o.name,r.expectedValue=n.name,r.message=`Embedded object at '${t}' declares 'type: ${o.name}', which equals the parent property's range '${n.name}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,r.suggestion=`Remove the 'type: ${o.name}' line, or keep it if explicitness is preferred over concision.`,r}notSubclass(e,t,o,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.actualValue=o.name,r.expectedValue=n.name,r.message=`Embedded object at '${t}' has 'type: ${o.name}', which is not a subclass of the parent property's range '${n.name}'.`,r.suggestion=`Either remove the 'type: ${o.name}' line (so the type is inferred from the property's range '${n.name}'), or add 'subClassOf: ${n.name}' to the '${o.name}' class definition so the relationship holds.`,r}};import{VersionOperator as qe}from"@kanonak-protocol/types/document/models/enums";var me=class{ruleName="ImportExistence";async validateAsync(e,t){let o=[];if(!e.metadata?.imports)return o;let n=await t.getAllDocumentsAsync();for(let[r,a]of Object.entries(e.metadata.imports))for(let i of a)if(!await t.getHighestCompatibleVersionAsync(r,i)){let p=await this.determineImportErrorAsync(t,r,i,n),l=new u;l.ruleType=this.ruleName,l.severity="Error",l.message=p.message,l.suggestion=p.suggestion,l.entityName=`Import: ${r}/${i.packageName}`,l.actualValue=i.toString(),l.expectedValue=p.expectedValue,o.push(l)}return o}async determineImportErrorAsync(e,t,o,n){let r=await e.getDocumentsByNamespaceAsync(t,o.packageName);if(r.length===0){let p=n.filter(h=>h.metadata.namespace_?.publisher===t).map(h=>h.metadata.namespace_.package_).filter((h,g,_)=>_.indexOf(h)===g),l=this.findSimilarPackages(o.packageName,p),m=`Import '${t}/${o.package_}' not found - package does not exist`,d=l.length>0?`Did you mean: ${l.slice(0,3).join(", ")}?`:p.length>0?`Available packages in ${t}: ${p.slice(0,5).join(", ")}`:`No packages found for publisher '${t}'. Verify the publisher name is correct.`;return{message:m,suggestion:d,expectedValue:"Existing package"}}let i=r.filter(p=>p.metadata.namespace_?.version).map(p=>p.metadata.namespace_.version.toString()).sort().join(", "),s=this.getAcceptableVersionRange(o);return{message:`Import '${t}/${o.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${i}. Required: ${s}`,expectedValue:s}}getAcceptableVersionRange(e){switch(e.versionOperator){case qe.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case qe.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case qe.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case qe.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,t){if(t.length===0)return[];let o=t.filter(a=>a.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(a.toLowerCase()));if(o.length>0)return o.sort((a,i)=>a.length-i.length);let n=t.map(a=>({package:a,distance:this.levenshteinDistance(e.toLowerCase(),a.toLowerCase())})).sort((a,i)=>a.distance-i.distance),r=Math.max(3,Math.floor(e.length*.4));return n.filter(a=>a.distance<=r).map(a=>a.package)}levenshteinDistance(e,t){if(!e||e.length===0)return t?.length??0;if(!t||t.length===0)return e.length;let o=e.length,n=t.length,r=Array(o+1).fill(null).map(()=>Array(n+1).fill(0));for(let a=0;a<=o;a++)r[a][0]=a;for(let a=0;a<=n;a++)r[0][a]=a;for(let a=1;a<=o;a++)for(let i=1;i<=n;i++){let s=e[a-1]===t[i-1]?0:1;r[a][i]=Math.min(Math.min(r[a-1][i]+1,r[a][i-1]+1),r[a-1][i-1]+s)}return r[o][n]}};var Lt="kanonak.org",Mt="core-rdf",Bt=new Set(["type","subClassOf","subPropertyOf","domain","range"].map(c=>b({publisher:Lt,package_:Mt,name:c}))),ue=class{ruleName="UnresolvedReference";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);return G(a,({kanonak:i,path:s})=>{for(let p of i.statement){let l=Ft(p);if(!(!l||Bt.has(b(l)))){if(p instanceof We)this.check(r,s,l,p.object,n);else if(p instanceof q)for(let m of p.object)m instanceof I&&this.check(r,s,l,m,n)}}}),n}check(e,t,o,n,r){R(e,n.subject)||r.push(this.unresolvedError(t,o.name,n.subject))}unresolvedError(e,t,o){let n=`${o.publisher}/${o.package_}/${o.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.actualValue=n,r.expectedValue="A reference that resolves to a defined or imported resource",r.message=`Reference to '${o.name}' in '${t}' could not be resolved`,r.suggestion=`The entity '${n}' is not defined in this namespace or any imported namespace.
7
+ \u2022 Import the package that defines it, or check for a typo in '${o.name}'
8
+ \u2022 If it lives in an imported namespace, alias-qualify the reference`,r}};function Ft(c){return c.predicate?.subject}var ft={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},yt={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"};function Ht(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of K(c,e))n instanceof I&&o.push(n.subject);return o}function ze(c,e,t){let o=[],n=new Set,r=new Set,a=i=>{let s=R(c,i),p=s?`${s.namespace}/${s.name}`:b(i);if(n.has(p)){let l=o.findIndex(d=>d.key===p),m=o.slice(l);return m.length<=1?null:[...m.map(d=>d.uri),i]}if(r.has(p))return null;if(n.add(p),o.push({key:p,uri:i}),s)for(let l of Ht(s,t)){let m=a(l);if(m)return m}return o.pop(),n.delete(p),r.add(p),null};return a(e)}var gt=c=>c,de=class{ruleName="ClassHierarchyCycle";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f)||!(v.isClassType(gt(i))||v.isDatatypeType(gt(i))))continue;let s=w(i);if(!s)continue;let p=ze(r,s,ft);if(p){let l=p.map(d=>d.name).join(" \u2192 "),m=new u;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular class hierarchy detected: ${l}`,m.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",m.entityName=i.name,m.propertyName="subClassOf",m.actualValue=l,n.push(m);break}}return n}};var fe=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f)||!Y(r,i))continue;let s=w(i);if(!s)continue;let p=ze(r,s,yt);if(p){let l=p.map(d=>d.name).join(" \u2192 "),m=new u;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular property hierarchy detected: ${l}`,m.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",m.entityName=i.name,m.propertyName="subPropertyOf",m.actualValue=l,n.push(m);break}}return n}};var Wt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},ye=class{ruleName="PropertyRangeRequired";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f))continue;let s=W(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let p=s==="ObjectProperty";ee(i,Wt)||n.push(this.error(i.name,p))}return n}error(e,t){let o=new u;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName="range",o.message=`Property '${e}' must have a 'range' defined.`,o.suggestion=t?"Add a range like: range: ClassName (the class this property expects)":"Add a range like: range: string (or integer, boolean, etc.)",o.expectedValue=t?"A class name (Character, Scene, Story, etc.)":"A datatype (string, integer, boolean, decimal, etc.)",o}};var Yt={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},kt=c=>c,ge=class{ruleName="SubClassOfReference";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f)||!ht(kt(i)))continue;let s=Gt(i,Yt);for(let p=0;p<s.length;p++)this.resolvesToClassLike(r,s[p])||n.push(this.error(i.name,s[p],s.length>1?`[${p}]`:""))}return n}resolvesToClassLike(e,t){let o=R(e,t);return o?ht(kt(o)):!1}error(e,t,o){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="subClassOf",r.actualValue=n,r.expectedValue="Defined or imported class",r.message=`Class '${t.name}' referenced in subClassOf${o} is not defined or imported`,r.suggestion=`Define '${t.name}' as a Class, or import a namespace that contains it`,r}};function ht(c){return v.isClassType(c)||v.isDatatypeType(c)}function Gt(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of K(c,e))n instanceof I&&o.push(n.subject);return o}var qt={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"},ke=class{ruleName="SubPropertyOfReference";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f)||!Y(r,i))continue;let s=zt(i,qt);for(let p=0;p<s.length;p++)this.resolvesToProperty(r,s[p])||n.push(this.error(i.name,s[p],s.length>1?`[${p}]`:""))}return n}resolvesToProperty(e,t){let o=R(e,t);return o?Y(e,o):!1}error(e,t,o){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="subPropertyOf",r.actualValue=n,r.expectedValue="Defined or imported property",r.message=`Property '${t.name}' referenced in subPropertyOf${o} is not defined or imported`,r.suggestion=`Define '${t.name}' as a property, or import a namespace that contains it`,r}};function zt(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of K(c,e))n instanceof I&&o.push(n.subject);return o}var he=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,t){let o=[],n=e.metadata.namespace_?.toString();if(!n)return o;let r=new Map,a=new Set;await this.buildImportGraph(e,t,r,a);let i=this.detectCycle(n,r);if(i){let s=i.join(" \u2192 "),p=new u;p.ruleType=this.ruleName,p.severity="Error",p.message=`Circular namespace import detected: ${s}`,p.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",p.entityName="imports",p.propertyName="imports",p.actualValue=s,o.push(p)}return o}async buildImportGraph(e,t,o,n){let r=e.metadata.namespace_?.toString()??"";if(!(!r||n.has(r))&&(n.add(r),e.metadata.imports)){let a=[];for(let[i,s]of Object.entries(e.metadata.imports))for(let p of s){let l=`${i}/${p.packageName}@${p.version}`;a.push(l);let m=await t.getHighestCompatibleVersionAsync(i,p);m&&await this.buildImportGraph(m,t,o,n)}a.length>0&&o.set(r,a)}}detectCycle(e,t){let o=[],n=new Set;return this.detectCycleRecursive(e,t,o,n)}detectCycleRecursive(e,t,o,n){let r=o.indexOf(e);if(r>=0){let i=o.slice(r);return i.push(e),i}if(n.has(e))return null;o.push(e),n.add(e);let a=t.get(e);if(a)for(let i of a){let s=this.detectCycleRecursive(i,t,o,n);if(s)return s}return o.pop(),null}};var Re=class{ruleName="UnresolvedPredicate";async validateAsync(e,t,o){let n=[],r=Ge(e);if(!r)return n;let a=await E(e,t,o);return G(a,({kanonak:i,path:s})=>{for(let p of i.unresolvedPredicates)p.sourceDoc===r&&n.push(this.unresolvedPredicateError(s,p.key))}),n}unresolvedPredicateError(e,t){let o=t.lastIndexOf("."),n=o>0?t.slice(0,o):null,r=o>0?t.slice(o+1):t,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=t,a.actualValue=t,a.expectedValue="A defined or imported property",a.message=`Property '${t}' is not defined or imported`,a.suggestion=n?`The property '${r}' was not found in the namespace imported as '${n}'.
9
+ 1. Check '${r}' is spelled correctly
10
+ 2. Verify '${n}' is imported with the right alias and version
11
+ 3. Ensure that namespace version actually defines '${r}'`:`The property '${t}' is not defined in this namespace or any imported namespace.
12
+ 1. Define '${t}' as an ObjectProperty or DatatypeProperty here, OR
13
+ 2. Import the namespace that defines it, OR
14
+ 3. Alias-qualify it if it lives in an imported namespace ('alias.${t}')`,a}};var Ke=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,t){let o=[],{entitySources:n,importPaths:r}=await this.buildEntitySourceMapAsync(e,t),a=await this.buildDatatypePropertyNamesAsync(e,t);for(let[i,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&this.validateEntityReferences(i,s,n,r,a,e,o);return o}async buildEntitySourceMapAsync(e,t){let o=new Map,n=new Set,r=new Map;for(let a of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";o.has(a)||o.set(a,[]),o.get(a).push(`(local:${i})`)}if(e.metadata.imports)for(let[a,i]of Object.entries(e.metadata.imports))for(let s of i){let p=await t.getHighestCompatibleVersionAsync(a,s);if(p){let l=p.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(p,o,n,r,[l],t)}}return{entitySources:o,importPaths:r}}async collectEntitiesRecursivelyAsync(e,t,o,n,r,a){let i=e.metadata.namespace_?.toString()??"";if(!o.has(i)){o.add(i),n.has(i)||n.set(i,r);for(let s of Object.keys(e.body)){t.has(s)||t.set(s,[]);let p=t.get(s);p.includes(i)||p.push(i)}if(e.metadata.imports)for(let[s,p]of Object.entries(e.metadata.imports))for(let l of p){let m=await a.getHighestCompatibleVersionAsync(s,l);if(m){let d=m.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(m,t,o,n,[...r,d],a)}}}}async buildDatatypePropertyNamesAsync(e,t){let o=new Set,n=new Set;if(await this.collectDatatypePropertiesAsync(e,o,n,t),e.metadata.imports)for(let[r,a]of Object.entries(e.metadata.imports))for(let i of a){let s=await t.getHighestCompatibleVersionAsync(r,i);s&&await this.collectDatatypePropertiesAsync(s,o,n,t)}return o}async collectDatatypePropertiesAsync(e,t,o,n){let r=e.metadata.namespace_?.toString()??"";if(!o.has(r)){o.add(r);for(let[a,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let s=i.type;if(typeof s!="string")continue;(s.includes(".")?s.substring(s.lastIndexOf(".")+1):s)==="DatatypeProperty"&&t.add(a)}if(e.metadata.imports)for(let[a,i]of Object.entries(e.metadata.imports))for(let s of i){let p=await n.getHighestCompatibleVersionAsync(a,s);p&&await this.collectDatatypePropertiesAsync(p,t,o,n)}}}validateEntityReferences(e,t,o,n,r,a,i){for(let[s,p]of Object.entries(t)){let l=s;if(l&&!l.includes(".")){let m=o.get(l);if(m&&m.length>1&&!m.some(h=>h.startsWith("(local:"))){let h=m.filter(g=>!g.startsWith("(local:"));h.length>1&&i.push(this.createAmbiguityError(e,l,`Property '${l}'`,h,n,a,!0,l))}}this.validatePropertyValue(e,l,p,o,n,r,a,i)}}validatePropertyValue(e,t,o,n,r,a,i,s){if(o==null)return;let p=t&&t.includes(".")?t.substring(t.lastIndexOf(".")+1):t,l=!!p&&a.has(p);if(typeof o=="string"&&!o.includes(".")&&!l){let m=n.get(o);if(m&&m.length>1&&!m.some(h=>h.startsWith("(local:"))){let h=m.filter(g=>!g.startsWith("(local:"));h.length>1&&s.push(this.createAmbiguityError(e,t,`Reference '${o}'`,h,r,i,!1,o))}}else if(Array.isArray(o))for(let m=0;m<o.length;m++){let d=`${e}.${t}[${m}]`;this.validatePropertyValue(d,t,o[m],n,r,a,i,s)}else if(typeof o=="object"&&!Array.isArray(o)){let m=t?`${e}.${t}`:e;this.validateEntityReferences(m,o,n,r,a,i,s)}}createAmbiguityError(e,t,o,n,r,a,i,s){let p=[];for(let U of n){let $=this.findAliasForNamespace(a,U);if($){let B=t?.split(".").pop()??t;p.push(`${$}.${B}`)}}let l=p.length>0?`Use one of: ${p.map(U=>`'${U}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${t}')`,m=n.map(U=>{let $=r.get(U);return!$||$.length===0?` \u2022 ${U}`:$.length===1?` \u2022 ${U} (direct import)`:` \u2022 ${U}
15
+ imported via: ${$.join(" \u2192 ")}`}).join(`
16
+ `),d=e.split(".")[0],h=e.includes(".")?e:t,g=new u;g.ruleType=this.ruleName,g.severity="Error",g.entityName=d,h&&(g.propertyName=h);let _=s??t;return _&&(g.actualValue=_),g.message=`${o} is ambiguous - defined in multiple imported namespaces`,g.suggestion=`${l}
17
+
18
+ Defined in:
19
+ ${m}`,g.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",g}findAliasForNamespace(e,t){if(!e.metadata.imports)return null;for(let[o,n]of Object.entries(e.metadata.imports))for(let r of n)if(`${o}/${r.packageName}@${r.version}`===t&&r.alias)return r.alias;return null}};var Xt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},Rt=c=>c,be=class{ruleName="PropertyRangeReference";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f))continue;let s=W(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let p=s==="ObjectProperty";for(let l of Zt(i,Xt))this.resolvesToClassLike(r,l)||n.push(this.error(i.name,l,p))}return n}resolvesToClassLike(e,t){let o=R(e,t);return o?v.isClassType(Rt(o))||v.isDatatypeType(Rt(o)):!1}error(e,t,o){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="range",r.actualValue=n,r.expectedValue=o?"A defined or imported class":"A datatype or defined class",r.message=`Property '${e}' has range '${t.name}' which is not defined or imported`,r.suggestion=o?`Define '${t.name}' as a Class here, or import the namespace that contains it (alias-qualify it if imported under an alias).`:`Use a datatype (xsd type, rdfs.Literal, or a datatype-derived type), or \u2014 if '${t.name}' is a class \u2014 make this an ObjectProperty.`,r}};function Zt(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of K(c,e))n instanceof I&&o.push(n.subject);return o}var Jt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},Ve="kanonak.org",Qe="core-rdf",et="core-owl",tt=c=>c,Qt=[{uri:{publisher:Ve,package_:Qe,name:"Class"},ok:(c,e)=>v.isClassType(tt(e))||v.isDatatypeType(tt(e))},{uri:{publisher:Ve,package_:Qe,name:"Datatype"},ok:(c,e)=>v.isDatatypeType(tt(e))},{uri:{publisher:Ve,package_:Qe,name:"Property"},ok:(c,e)=>Y(c,e)},{uri:{publisher:Ve,package_:et,name:"ObjectProperty"},ok:(c,e)=>W(c,e)==="ObjectProperty"},{uri:{publisher:Ve,package_:et,name:"DatatypeProperty"},ok:(c,e)=>W(c,e)==="DatatypeProperty"},{uri:{publisher:Ve,package_:et,name:"AnnotationProperty"},ok:(c,e)=>W(c,e)==="AnnotationProperty"}],Ee=class{ruleName="ObjectPropertyValue";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await re(e,t,o);for(let i of a)i instanceof f&&this.walk(r,i,i.name,n);return n}walk(e,t,o,n){for(let r of t.statement)if(r instanceof We)this.check(e,r.predicate?.subject,r.object.subject,o,n);else if(r instanceof Q)this.walk(e,r.object,Kt(o,r.predicate?.subject),n);else if(r instanceof q){let a=r.predicate?.subject;for(let i of r.object)i instanceof I?this.check(e,a,i.subject,o,n):i instanceof D&&this.walk(e,i,Kt(o,a),n)}}check(e,t,o,n,r){if(!t)return;let a=R(e,t);if(!a)return;let i=y(a,Jt);if(!i)return;let s=Qt.find(l=>X(i,l.uri));if(!s)return;let p=R(e,o);p&&(s.ok(e,p)||r.push(this.warn(n,t,i,o)))}warn(e,t,o,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e.split(".")[0],r.propertyName=e,r.actualValue=n.name,r.expectedValue=o.name,r.message=`Property '${t.name}' expects a ${o.name}, but '${n.name}' is not a ${o.name}`,r.suggestion=`Reference a resource that is a ${o.name}, or correct the type of '${n.name}'.`,r}};function Kt(c,e){return`${c}.${e?.name??"<embedded>"}`}var eo={publisher:"kanonak.org",package_:"core-rdf",name:"type"},to={publisher:"kanonak.org",package_:"core-rdf",name:"domain"},oo={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},ve=class{ruleName="PropertyDomain";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await re(e,t,o);for(let i of a)i instanceof f&&this.walk(r,i,i.name,n);return n}walk(e,t,o,n){this.checkNode(e,t,o,n);for(let r of t.statement)if(r instanceof Q)this.walk(e,r.object,Vt(o,r.predicate?.subject),n);else if(r instanceof q)for(let a of r.object)a instanceof D&&this.walk(e,a,Vt(o,r.predicate?.subject),n)}checkNode(e,t,o,n){let r=bt(t,eo);if(r.length===0)return;let a,i=()=>{if(!a){a=new Set([b(oo)]);for(let p of r)for(let l of z(e,p))a.add(b(l))}return a},s=new Set;for(let p of t.statement){let l=no(p);if(!l||Ye(l.name)||s.has(b(l)))continue;s.add(b(l));let m=R(e,l);if(!m)continue;let d=bt(m,to);d.length!==0&&(d.some(h=>i().has(b(h)))||n.push(this.error(o,l,d,r[0])))}}error(e,t,o,n){let r=o.map(i=>i.name).join(" | "),a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e.split(".")[0],a.propertyName=e,a.actualValue=t.name,a.expectedValue=`Property used on ${r} or its subclasses`,a.message=`Property '${t.name}' has domain '${r}' but is used on '${n.name}' at '${e}'`,a.suggestion=`Either:
20
+ 1. Use '${t.name}' only on '${r}' (or a subclass) instances
21
+ 2. Widen the property's domain to include '${n.name}'
22
+ 3. Use a different property for '${n.name}'`,a}};function no(c){return c.predicate?.subject}function bt(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of K(c,e))n instanceof I&&o.push(n.subject);return o}function Vt(c,e){return`${c}.${e?.name??"<embedded>"}`}var ro={publisher:"kanonak.org",package_:"core-rdf",name:"range"},ao={publisher:"kanonak.org",package_:"core-rdf",name:"Literal"},io=c=>c,De=class{ruleName="PropertyKindRangeConsistency";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);for(let i of a){if(!(i instanceof f))continue;let s=W(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let p=s==="ObjectProperty",l=s==="DatatypeProperty",m=y(i,ro);if(!m||!R(r,m))continue;let d=so(r,m);l&&!d?n.push(this.error(i.name,m,"datatype")):p&&d&&n.push(this.error(i.name,m,"object"))}return n}error(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName="range",n.actualValue=t.name,o==="datatype"?(n.expectedValue="A datatype (xsd type, rdfs.Literal, or a datatype-derived class)",n.message=`DatatypeProperty '${e}' has range '${t.name}', which is a class, not a datatype. A datatype property's values are literals.`,n.suggestion=`Use a datatype range (e.g. xsd.string, rdfs.Literal, or a datatype-derived class), or \u2014 if '${t.name}' is the intended target \u2014 declare '${e}' an ObjectProperty.`):(n.expectedValue="A plain class (not datatype-derived)",n.message=`ObjectProperty '${e}' has range '${t.name}', which is a datatype, not a class. An object property's values are references to resources.`,n.suggestion=`Declare '${e}' a DatatypeProperty (its values are literals of '${t.name}'), or change the range to a plain class.`),n}};function so(c,e){for(let t of z(c,e)){if(X(t,ao))return!0;let o=R(c,t);if(o&&v.isDatatypeType(io(o)))return!0}return!1}var Ie=class{ruleName="ReservedNameShadow";async validateAsync(e,t,o){let n=[],r=await C(e,t,o);for(let a of r){if(!(a instanceof f))continue;let i=ct(a.name);if(!i)continue;let s=w(a);s&&(i.publisher===s.publisher&&i.package_===s.package_||n.push(this.info(a.name,s,i)))}return n}info(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Info",n.entityName=e,n.propertyName=e,n.actualValue=`${t.publisher}/${t.package_}/${e}`,n.expectedValue=`${o.publisher}/${o.package_}/${e}`,n.message=`'${e}' is also the reserved built-in '${o.publisher}/${o.package_}/${e}'. This local definition shadows it \u2014 a bare '${e}' reference in this package resolves to the local entity, not the built-in.`,n.suggestion=`If this is intentional, qualify bare references to '${e}' explicitly (this local one vs. the built-in '${o.publisher}/${o.package_}/${e}') so the choice is unambiguous to readers and tools \u2014 e.g. a self-referential 'subClassOf: ${e}' silently resolves to this local entity.`,n}};var co={publisher:"kanonak.org",package_:"core-rdf",name:"type"},Et=c=>c,Ce=class{ruleName="ClassDefinition";async validateAsync(e,t,o){let n=[],r=await E(e,t,o),a=await C(e,t,o);return G(a,({kanonak:i,path:s})=>{for(let p of po(i,co))this.resolvesToClassLike(r,p)||n.push(this.error(s,p))}),n}resolvesToClassLike(e,t){if(Ye(t.name))return!0;let o=R(e,t);return o?v.isClassType(Et(o))||v.isDatatypeType(Et(o)):!1}error(e,t){let o=`${t.publisher}/${t.package_}/${t.name}`,n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName="type",n.actualValue=o,n.expectedValue="Defined or imported class",n.message=`Class '${t.name}' is not defined or imported`,n.suggestion=`Define '${t.name}' as a Class in this document, or import a namespace that contains it`,n}};function po(c,e){let t=y(c,e);if(t)return[t];let o=[];for(let n of K(c,e))n instanceof I&&o.push(n.subject);return o}var Se=class{ruleName="MarkdownLink";async validateAsync(e,t,o){let n=[],r=await C(e,t,o);return G(r,({kanonak:a,path:i})=>{this.checkNode(a,i,n)}),n}checkNode(e,t,o){for(let n of e.statement){if(!(n instanceof st))continue;let r=n.predicate.subject?.name??"(unknown)";for(let a of n.links)a.target||o.push(this.unresolvedLinkError(t,r,a.reference));for(let a of mt(n.object))o.push(this.malformedLinkError(t,r,a.snippet))}}unresolvedLinkError(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=t,n.actualValue=o,n.message=`Embedded link [[${o}]] in '${t}' could not be resolved`,n.expectedValue="A reference resolvable through the document's import closure",n.suggestion=`The reference '${o}' inside a markdown value cannot be found in the current document or any imported namespace.
23
+
24
+ Possible solutions:
25
+ \u2022 Import the package that defines '${o}' so the link can resolve
26
+ \u2022 Check for typos in the reference name
27
+ \u2022 If the name collides across imports, alias-qualify it: [[alias.${o}]]`,n}malformedLinkError(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=t,n.actualValue=o,n.message=`Malformed embedded reference near '${o}' in '${t}'`,n.expectedValue="A single-line [[reference]] with no internal line break",n.suggestion=`A '[[' in '${t}' does not form a complete [[reference]] link.
28
+
29
+ A reference may not span a line break \u2014 the most common cause is wrapping a
30
+ long reference across two lines in a block scalar, e.g.:
31
+ ... read for [[persistent-energy-
32
+ shock]] held ...
33
+ which is parsed as literal text, not a link. Keep each [[reference]] on one
34
+ line (let the line run long), or check for an unterminated [[.`,n}};var vt="kanonak.org",Dt="look",lo={publisher:vt,package_:Dt,name:"displayLabel"},mo={publisher:vt,package_:Dt,name:"displaySummary"},Pe=class{ruleName="DisplayLensScope";async validateAsync(e,t,o){let n=[],r;o?r=await o.getKanonaks():r=await new S().parseKanonaks(new H(e,t));let a=uo(e);if(!a)return n;for(let i of r)i instanceof f&&i.namespace===a&&(this.checkLens(r,i,lo,"displayLabel",n),this.checkLens(r,i,mo,"displaySummary",n));return n}checkLens(e,t,o,n,r){let a=y(t,o);if(!a)return;let i=[],s=w(t);if(s&&i.push(s),i.push(...lt(t)),i.length===0)return;i.some(l=>L(e,l,a).ok)||r.push(this.scopeError(t.name,n,a.name))}scopeError(e,t,o){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=t,n.actualValue=o,n.message=`${t} points at '${o}', which is not a property in scope for '${e}'`,n.expectedValue="A property whose domain is this resource's class, an ancestor, or rdfs.Resource",n.suggestion=`'${o}' resolves, but its domain does not cover '${e}', so the lens would silently fall back to the resource's name at render time.
35
+
36
+ Possible solutions:
37
+ \u2022 Point ${t} at a property declared on this class (or an ancestor / rdfs.Resource)
38
+ \u2022 Set the property's domain to this class if it should apply here
39
+ \u2022 Use rdfs.label / rdfs.comment for the universal default`,n}};function uo(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}function Z(c,e,t){let o=[];return Le(c,t,{input:e},o),o}function Le(c,e,t,o){if(O(e,M.VarRef)){let a=F(e,M.varName);return a?t[a]:void 0}if(O(e,M.PropertyRead)){let a=P(e,M.readSource),i=a?Le(c,a,t,o):void 0,s=y(e,M.readProp);if(!i||!s)return;let p=L(c,i,s);if(!p.ok){o.push({contextClass:i,propertyUri:s,via:"PropertyRead"});return}return p.descriptor?.range}if(O(e,M.Traverse)){let a=P(e,M.traverseSource),i=a?Le(c,a,t,o):void 0,s=y(e,M.through),p;if(i&&s){let m=L(c,i,s);m.ok?p=m.descriptor?.range:o.push({contextClass:i,propertyUri:s,via:"Traverse"})}let l=P(e,M.step);return l?Le(c,l,{...t,input:p},o):void 0}let n=F(e,M.loopVar),r=n?{...t,[n]:void 0}:t;for(let a of fo(e))Le(c,a,r,o)}function fo(c){let e=[];for(let t of c.statement){let o=t.object;if(o instanceof D)e.push(o);else if(Array.isArray(o))for(let n of o)n instanceof D&&e.push(n)}return e}var Me="kanonak.org",Be="look",yo={publisher:Me,package_:Be,name:"semanticSvg"},go={publisher:Me,package_:Be,name:"tierChip"},ko={publisher:Me,package_:Be,name:"tierIcon"},ho={publisher:Me,package_:Be,name:"tierCard"},Ro={publisher:Me,package_:Be,name:"tierFull"},Ko=[go,ko,ho,Ro],je=class{ruleName="LookSemanticSvgPath";async validateAsync(e,t,o){let n=[],r;o?r=await o.getKanonaks():r=await new S().parseKanonaks(new H(e,t));let a=bo(e);if(!a)return n;for(let i of r)i instanceof f&&i.namespace===a&&this.checkSemanticSvg(r,i,n);return n}checkSemanticSvg(e,t,o){let n=P(t,yo);if(!n)return;let r=w(t);if(r)for(let a of Ko){let i=P(n,a);if(i)for(let s of Z(e,r,i))o.push(this.toError(t.name,a.name,s))}}toError(e,t,o){let n=`${o.propertyUri.publisher}/${o.propertyUri.package_}/${o.propertyUri.name}`,r=o.contextClass.name,a=r===e?`'${e}' (the class this SemanticSvg is declared on)`:`'${r}', reached by traversal from '${e}' (the class this SemanticSvg is declared on)`,i=new u;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=`look.semanticSvg.${t}`,i.actualValue=n,i.message=`tx.${o.via} reads property '${o.propertyUri.name}' off the rendered instance, but its domain is not in scope for ${a}. The read would silently return undefined at render time.`,i.expectedValue=`A property whose domain is '${r}', an ancestor, or rdfs.Resource`,i.suggestion=`Property '${n}' is not in scope for '${r}'.
40
+
41
+ Possible solutions:
42
+ \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
43
+ \u2022 If the property should apply to '${r}', adjust its domain
44
+ \u2022 If the value comes from a pre-computed env binding, use tx.VarRef instead of PropertyRead`,i}};function bo(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var Vo="kanonak.org",V=(c,e)=>({publisher:Vo,package_:c,name:e}),Eo=V("derivation","look"),vo=V("look","bands"),Do=V("look","Distribution"),Io=V("look","StatRow"),Co=V("look","VersionDelta"),So=V("look","Timeline"),Po=V("look","VersionDiff"),jo=V("look","TimePlot"),Oo=V("look","ReferenceList"),Uo=V("look","Diagram"),$o=V("look","alphaPath"),wo=V("look","betaPath"),ot=V("look","metricPath"),It=V("look","lowerPath"),Ct=V("look","upperPath"),St=V("look","hueBy"),Ao=V("look","statPath"),xo=V("look","laneBy"),Pt=V("look","labelPath"),No=V("look","badgePath"),_o=V("look","mapPath"),To=V("look","nodeNote"),Lo=V("look","edgeValue"),Mo=V("look","stats"),Bo=V("look","facets"),Fo=V("look","channels"),Ho=V("look","track"),Wo=V("look","source"),Yo=V("look","relation"),Go=V("look","entries"),Oe=class{ruleName="LookBandPath";async validateAsync(e,t,o){let n=[],r;o?r=await o.getKanonaks():r=await new S().parseKanonaks(new H(e,t));let a=zo(e);if(!a)return n;for(let i of r)i instanceof f&&i.namespace===a&&this.checkDeclaration(r,i,n);return n}checkDeclaration(e,t,o){let n=P(t,Eo);if(!n)return;let r=w(t);if(!r)return;let a=K(n,vo).filter(i=>i instanceof D);for(let i of a)for(let s of this.carriersOf(e,i,r))for(let p of Z(e,s.context,s.expr))o.push(this.toError(t.name,s.slot,p))}carriersOf(e,t,o){let n=[],r=(a,i)=>{let s=P(t,a);s&&n.push({slot:`look.${a.name}`,context:i,expr:s})};if(O(t,Do))for(let a of[$o,wo,ot,It,Ct,St])r(a,o);if(O(t,Co)&&r(ot,o),O(t,Io)){let a=K(t,Mo).filter(i=>i instanceof D);for(let i of a){let s=P(i,Ao);s&&n.push({slot:"look.stats[].statPath",context:o,expr:s})}}if(O(t,So)||O(t,Po)){let a=this.rangeOf(e,o,y(t,Ho));if(a)for(let i of[ot,It,Ct,St])r(i,a)}if(O(t,jo)){let a=this.rangeOf(e,o,y(t,Wo));if(a)for(let i of[xo,Pt])r(i,a)}if(O(t,Oo))for(let a of K(t,Go)){let i=a instanceof D?void 0:qo(a),s=this.rangeOf(e,o,i);if(s)for(let p of[Pt,No])r(p,s)}if(O(t,Uo)){let a=K(t,Bo).filter(i=>i instanceof D);for(let i of a){let s=this.rangeOf(e,o,y(i,Yo));if(!s)continue;let p=P(i,To);p&&n.push({slot:"look.facets[].nodeNote",context:s,expr:p});let l=P(i,Lo);l&&n.push({slot:"look.facets[].edgeValue",context:s,expr:l});let m=K(i,Fo).filter(d=>d instanceof D);for(let d of m){let h=P(d,_o);h&&n.push({slot:"look.facets[].channels[].mapPath",context:s,expr:h})}}}return n}rangeOf(e,t,o){if(!o)return;let n=L(e,t,o);return n.ok?n.descriptor?.range:void 0}toError(e,t,o){let n=`${o.propertyUri.publisher}/${o.propertyUri.package_}/${o.propertyUri.name}`,r=o.contextClass.name,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=t,a.actualValue=n,a.message=`tx.${o.via} reads property '${o.propertyUri.name}', but its domain is not in scope for '${r}' (the class this band carrier is evaluated against). The read would silently return undefined at render time and the band would render empty.`,a.expectedValue=`A property whose domain is '${r}', an ancestor, or rdfs.Resource`,a.suggestion=`Property '${n}' is not in scope for '${r}'.
45
+
46
+ Possible solutions:
47
+ \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
48
+ \u2022 If the property should apply to '${r}', adjust its domain
49
+ \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,a}};function qo(c){let e=c.subject;return e&&typeof e.name=="string"?e:void 0}function zo(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var Xo="kanonak.org",nt=(c,e)=>({publisher:Xo,package_:c,name:e}),Zo=nt("derivation","look"),Jo=nt("look","bands"),Qo=nt("core-rdf","type"),Fe=class{ruleName="UnrenderableBand";async validateAsync(e,t,o){let n=[],r=o?await o.getKanonaks():await new S().parseKanonaks(new H(e,t)),a=en(e);if(!a)return n;let i=dt();for(let s of r){if(!(s instanceof f)||s.namespace!==a)continue;let p=P(s,Zo);if(!p)continue;let l=K(p,Jo).filter(m=>m instanceof D);for(let m of l){let d=this.typeOf(m);if(!d)continue;let h=`${d.publisher}/${d.package_}/${d.name}`;if(i.has(h))continue;let g=new u;g.ruleType=this.ruleName,g.severity="Warning",g.entityName=s.name,g.propertyName="derivation.look",g.actualValue=h,g.message=`Band '${d.name}' has no renderer, so this region of the page will be empty. The declaration is valid against the look vocabulary, but the renderer emits only an HTML comment for it \u2014 which a browser does not display, so the loss is silent. Use a band the renderer implements, or remove it until it is supported.`,n.push(g)}}return n}typeOf(e){let t=y(e,Qo);if(t)return{publisher:t.publisher,package_:t.package_,name:t.name}}};function en(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var $e="kanonak.org",we="view",tn={publisher:$e,package_:we,name:"bind"},on={publisher:$e,package_:we,name:"produces"},nn={publisher:$e,package_:we,name:"projections"},rn={publisher:$e,package_:we,name:"where"},an={publisher:$e,package_:we,name:"value"},sn={publisher:$e,package_:we,name:"as"},Ue=class{ruleName="TxExpressionPath";async validateAsync(e,t,o){let n=[],r;o?r=await o.getKanonaks():r=await new S().parseKanonaks(new H(e,t));let a=ln(e);if(!a)return n;for(let i of r)i instanceof f&&i.namespace===a&&this.checkView(r,i,n);return n}checkView(e,t,o){let n=y(t,tn);if(!n)return;let r=y(t,on),a=0;for(let s of pn(e,K(t,nn))){let p=P(s,an);if(p)for(let m of Z(e,n,p))o.push(this.toError(t.name,`view.projections[${a}].value`,n,m));let l=y(s,sn);l&&r&&(L(e,r,l).ok||o.push(this.asError(t.name,a,r,l))),a+=1}let i=0;for(let s of cn(t,rn)){for(let p of Z(e,n,s))o.push(this.toError(t.name,`view.where[${i}]`,n,p));i+=1}}asError(e,t,o,n){let r=`${n.publisher}/${n.package_}/${n.name}`,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=`view.projections[${t}].as`,a.actualValue=r,a.message=`Projection stores its value under property '${n.name}', but that property's domain is not in scope for the view's produces class '${o.name}'. The materialized result instance could not carry this value.`,a.expectedValue=`A property whose domain is '${o.name}', an ancestor, or rdfs.Resource`,a.suggestion=`Property '${r}' is not in scope for produces class '${o.name}'.
50
+
51
+ Possible solutions:
52
+ \u2022 Use an output property whose domain covers '${o.name}'
53
+ \u2022 Define a new property in the ViewPackage with domain '${o.name}' and the right range
54
+ \u2022 If the value belongs on a different output class, adjust the view's produces`,a}toError(e,t,o,n){let r=`${n.propertyUri.publisher}/${n.propertyUri.package_}/${n.propertyUri.name}`,a=n.contextClass.name,i=a===o.name?`the view's bound class '${o.name}'`:`'${a}', reached by traversal from the view's bound class '${o.name}'`,s=new u;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=e,s.propertyName=t,s.actualValue=r,s.message=`tx.${n.via} reads property '${n.propertyUri.name}', but its domain is not in scope for ${i}. The read would silently return undefined when the view materializes.`,s.expectedValue=`A property whose domain is '${a}', an ancestor, or rdfs.Resource`,s.suggestion=`Property '${r}' is not in scope for '${a}'.
55
+
56
+ Possible solutions:
57
+ \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
58
+ \u2022 If the property should apply to '${a}', adjust its domain
59
+ \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,s}};function cn(c,e){let t=P(c,e);return t?[t]:K(c,e).filter(o=>o instanceof D)}function pn(c,e){let t=[];for(let o of e)if(o instanceof D)t.push(o);else if(o instanceof I){let n=R(c,o.subject);n&&t.push(n)}return t}function ln(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var Xe="kanonak.org",mn="core-shacl",A=c=>({publisher:Xe,package_:mn,name:c}),un=A("NodeShape"),dn=A("PropertyShape"),fn=A("targetClass"),yn=A("property"),gn=A("path"),kn=A("minCount"),hn=A("maxCount"),Rn=A("datatype"),Kn=A("class"),jt=A("in"),bn=A("pattern"),Vn=A("flags"),En=A("minLength"),vn=A("maxLength"),Dn=A("minInclusive"),In=A("maxInclusive"),Cn=new Set(["decimal","integer","int","long","short","byte","float","double","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"]),Ot=c=>c,xe=class{ruleName="ShaclShape";async validateAsync(e,t,o){let n=[],r=o?await o.getKanonaks():await new S().parseKanonaks(t),a=Sn(e);if(!a)return n;let i=new Set;for(let s of r){if(!(s instanceof f)||s.namespace!==a||!O(s,un))continue;let p=y(s,fn);p?this.resolvesToClass(r,p)||n.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' sh:targetClass '${p.name}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(p))):n.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' has no sh:targetClass; it constrains nothing.`,"Add sh:targetClass naming the class this shape applies to."));for(let l of K(s,yn)){let m;if(l instanceof D)m=l;else if(l instanceof I){let d=R(r,l.subject);d&&(m=d,i.add(b(l.subject)))}m&&this.checkPropertyShape(r,s.name,m,p??void 0,n)}}for(let s of r){if(!(s instanceof f)||s.namespace!==a||!O(s,dn))continue;let p=w(s);p&&i.has(b(p))||this.checkPropertyShape(r,s.name,s,void 0,n)}return n}checkPropertyShape(e,t,o,n,r){let a=y(o,gn);if(!a){r.push(this.err(t,"property.path","Error",`A PropertyShape on '${t}' has no sh:path; a PropertyShape must name the property it constrains.`,"Add sh:path naming a property."));return}let i=R(e,a),s=i?Y(e,i):!1;s?n&&(L(e,n,a).ok||r.push(this.err(t,"property.path","Warning",`sh:path '${a.name}' is not in scope for sh:targetClass '${n.name}'; the constraint would never bind a value.`,`Constrain a property whose domain is '${n.name}', an ancestor, or rdfs.Resource.`,J(a)))):r.push(this.err(t,"property.path","Error",`sh:path '${a.name}' on '${t}' does not resolve to a property.`,"Reference a defined or imported property.",J(a)));let p=y(o,Rn),l=y(o,Kn);p&&l&&r.push(this.err(t,"property","Error",`A PropertyShape on '${t}' sets both sh:datatype and sh:class; a value is a literal or a node, not both.`,"Keep sh:datatype (literal values) or sh:class (node values), not both.")),p&&!this.resolvesToDatatype(e,p)&&r.push(this.err(t,"datatype","Error",`sh:datatype '${p.name}' on '${t}' does not resolve to a datatype.`,"Reference an xsd datatype or rdfs.Datatype.",J(p))),l&&!this.resolvesToClass(e,l)&&r.push(this.err(t,"class","Error",`sh:class '${l.name}' on '${t}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(l)));let m=Ae(x(o,kn)),d=Ae(x(o,hn));this.checkOrder(t,"minCount",m,"maxCount",d,r);let h=Ae(x(o,En)),g=Ae(x(o,vn));this.checkOrder(t,"minLength",h,"maxLength",g,r);let _=Ae(x(o,Dn)),U=Ae(x(o,In));this.checkOrder(t,"minInclusive",_,"maxInclusive",U,r);let $=F(o,bn);if($!==void 0){let B=F(o,Vn);try{new RegExp($,B)}catch{r.push(this.err(t,"pattern","Error",`sh:pattern on '${t}' is not a valid regular expression`+(B!==void 0?` (with flags '${B}')`:"")+`: ${$}`,"Provide a valid regular expression and flags.",$))}}if(ee(o,jt)&&K(o,jt).length===0&&r.push(this.err(t,"in","Error",`sh:in on '${t}' is empty; an enumeration must list at least one permitted value.`,"List the permitted literal values, or remove sh:in.")),s&&n){let T=L(e,n,a).descriptor;T&&(($!==void 0||h!==void 0||g!==void 0)&&T.kind==="object"&&r.push(this.err(t,"pattern/minLength/maxLength","Warning",`String facets on '${t}' apply to '${a.name}', which is an object property; string facets constrain literal values.`,"Apply string facets to a datatype property, or use sh:class for node values.",J(a))),(_!==void 0||U!==void 0)&&!this.isNumericDatatypeRange(T.range)&&r.push(this.err(t,"minInclusive/maxInclusive","Warning",`Numeric bounds on '${t}' apply to '${a.name}', whose range is not a numeric datatype.`,"Apply numeric bounds to a numeric datatype property.",J(a))))}}checkOrder(e,t,o,n,r,a){o!==void 0&&r!==void 0&&o>r&&a.push(this.err(e,`${t}/${n}`,"Error",`${t} (${o}) exceeds ${n} (${r}) on '${e}'.`,`Set ${t} <= ${n}.`))}resolvesToClass(e,t){let o=R(e,t);return o?v.isClassType(Ot(o)):!1}resolvesToDatatype(e,t){if(t.publisher===Xe&&t.package_==="core-rdf"&&t.name==="Literal")return!0;let o=R(e,t);return o?v.isDatatypeType(Ot(o)):!1}isNumericDatatypeRange(e){return!e||e.publisher===Xe&&e.package_==="core-rdf"&&e.name==="Literal"?!0:e.publisher===Xe&&e.package_==="core-xsd"&&Cn.has(e.name)}err(e,t,o,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=o,i.entityName=e,i.propertyName=t,i.message=n,i.suggestion=r,a!==void 0&&(i.actualValue=a),i}};function Ae(c){return typeof c=="number"?c:void 0}function J(c){return`${c.publisher}/${c.package_}/${c.name}`}function Sn(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var Ut={publisher:"kanonak.org",package_:"core-owl",name:"oneOf"},Pn=c=>c,Ne=class{ruleName="OwlOneOf";async validateAsync(e,t,o){let n=[],r=o?await o.getKanonaks():await new S().parseKanonaks(t),a=jn(e);if(!a)return n;for(let i of r){if(!(i instanceof f)||i.namespace!==a||!ee(i,Ut))continue;let s=K(i,Ut);if(s.length===0){n.push(this.err(i.name,"Warning",`owl:oneOf on '${i.name}' is empty; a closed enumeration must list at least one individual.`,"List the individuals that make up the enumeration, or remove owl:oneOf."));continue}for(let p of s)if(p instanceof He)n.push(this.err(i.name,"Error",`owl:oneOf member '${String(p.value)}' on '${i.name}' is not a named individual; a class enumeration is of individuals (a misspelled or unimported individual reads as a literal). For a closed set of literal VALUES, constrain a property with sh:in instead.`,"Reference a defined or imported individual, or move literal value sets to a property sh:in.",String(p.value)));else if(p instanceof I){let l=R(r,p.subject);l&&v.isSchemaDefinitionType(Pn(l))&&n.push(this.err(i.name,"Error",`owl:oneOf member '${p.subject.name}' on '${i.name}' is a class/property/datatype, not an individual.`,"List named individuals (instances), not schema definitions.",`${p.subject.publisher}/${p.subject.package_}/${p.subject.name}`))}}return n}err(e,t,o,n,r){let a=new u;return a.ruleType=this.ruleName,a.severity=t,a.entityName=e,a.propertyName="oneOf",a.message=o,a.suggestion=n,r!==void 0&&(a.actualValue=r),a}};function jn(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var On="kanonak.org",Un="core-shacl",N=c=>({publisher:On,package_:Un,name:c}),$n=N("NodeShape"),wn=N("targetClass"),An=N("property"),xn=N("path"),Nn=N("minCount"),_n=N("maxCount"),Tn=N("in"),Ln=N("pattern"),Mn=N("flags"),Bn=N("minLength"),Fn=N("maxLength"),Hn=N("minInclusive"),Wn=N("maxInclusive"),Yn=N("message");function _e(c){return typeof c=="number"?c:void 0}function Gn(c){let e={},t=_e(x(c,Nn)),o=_e(x(c,_n));t!==void 0&&(e.minCount=t),o!==void 0&&(e.maxCount=o);let n=_e(x(c,Bn)),r=_e(x(c,Fn));n!==void 0&&(e.minLength=n),r!==void 0&&(e.maxLength=r);let a=_e(x(c,Hn)),i=_e(x(c,Wn));a!==void 0&&(e.minInclusive=a),i!==void 0&&(e.maxInclusive=i);let s=F(c,Ln);if(s!==void 0){let m=F(c,Mn);e.pattern=m!==void 0?{regex:s,flags:m}:{regex:s}}let p=K(c,Tn).filter(m=>m instanceof He).map(m=>m.value);p.length>0&&(e.enumValues=p);let l=F(c,Yn);return l!==void 0&&(e.message=l),e}function qn(c,e){let t=[];for(let o of K(e,An))if(o instanceof D)t.push(o);else if(o instanceof I){let n=R(c,o.subject);n&&t.push(n)}return t}function $t(c){let e=new Map;for(let t of c){if(!(t instanceof f)||!O(t,$n))continue;let o=y(t,wn);if(!o)continue;let n=b(o);for(let r of qn(c,t)){let a=y(r,xn);if(!a)continue;let i={pathKey:b(a),constraints:Gn(r)},s=e.get(n);s?s.push(i):e.set(n,[i])}}return e}function zn(c,e){e.minCount!==void 0&&(c.minCount=e.minCount),e.maxCount!==void 0&&(c.maxCount=e.maxCount),e.minLength!==void 0&&(c.minLength=e.minLength),e.maxLength!==void 0&&(c.maxLength=e.maxLength),e.minInclusive!==void 0&&(c.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(c.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(c.pattern=e.pattern),e.enumValues!==void 0&&(c.enumValues=e.enumValues),e.message!==void 0&&(c.message=e.message)}function wt(c,e,t){let o=b(t),n=!1,r={};for(let a=e.length-1;a>=0;a--){let i=c.get(b(e[a]));if(i)for(let s of i)s.pathKey===o&&(n=!0,zn(r,s.constraints))}if(n)return r.cardinality=r.maxCount===1?"single":"list",r.required=(r.minCount??0)>=1,r}var Xn=c=>c,Zn=new it("kanonak.org","core-rdf","Resource"),Te=class{ruleName="DiamondNameClash";async validateAsync(e,t,o){let n=[],r=o?await o.getKanonaks():await new S().parseKanonaks(t),a=Jn(e);if(!a)return n;let i=$t(r);for(let s of r){if(!(s instanceof f)||s.namespace!==a||!v.isClassType(Xn(s)))continue;let p=w(s);if(!p)continue;let l=z(r,p),m=b(p),d=new Set(l.map(g=>b(g)));d.delete(m),d.delete(b(Zn));let h=new Map;for(let g of pt(r,p)){if(!g.domains.some($=>d.has(b($))))continue;let U=h.get(g.uri.name);U?U.push(g):h.set(g.uri.name,[g])}for(let[g,_]of h){if(_.length<2)continue;let U=T=>wt(i,l,T.uri)?.cardinality,$=new Set(_.map(T=>T.range?b(T.range):void 0).filter(T=>T!==void 0)),B=new Set(_.map(U).filter(T=>T!==void 0));$.size<=1&&B.size<=1||n.push(this.toError(s.name,g,_,U))}}return n}toError(e,t,o,n){let r=s=>{let p=`${s.uri.publisher}/${s.uri.package_}/${s.uri.name}`,l=s.range?`${s.range.publisher}/${s.range.package_}/${s.range.name}`:"no range",m=n(s);return`${p} (range ${l}${m?`, ${m}`:""})`},a=o.map(r).join("; "),i=new u;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=t,i.actualValue=a,i.message=`Class '${e}' inherits ${o.length} distinct properties named '${t}' with incompatible range or cardinality: ${a}. The generated interface would multiply-inherit '${t}' with conflicting types and could not compile.`,i.suggestion=`Disambiguate the diamond name-clash on '${t}':
60
+ \u2022 rename one of the properties, or
61
+ \u2022 re-domain one so it is not inherited by '${e}', or
62
+ \u2022 restructure the hierarchy so '${e}' inherits only one '${t}', or
63
+ \u2022 make the ranges/cardinalities compatible (identical) if they are meant to be the same property.`,i}};function Jn(c){let e=c.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${j(e.version)}`}var rt=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new at,this.documentRules=[new ae,new ie,new se,new ce,new pe],this.repositoryRules=[new le,new me,new ue,new de,new fe,new ye,new ge,new ke,new he,new Re,new Ke,new be,new Ee,new ve,new De,new Ie,new Ce,new Se,new Pe,new je,new Oe,new Fe,new Ue,new xe,new Ne,new Te]}async validateAsync(e,t,o){let n=new te;for(let r of this.documentRules)try{let a=r.validate(e);this.addErrorsToResult(n,a)}catch(a){let i=new u;i.ruleType=r.ruleName,i.severity="Error",i.message=`Validation rule '${r.ruleName}' failed: ${a instanceof Error?a.message:String(a)}`,n.errors.push(i)}if(t){let r=[],a=o??new oe(new ne(e,t)),i=a.repository;for(let s of this.repositoryRules)try{let p=await s.validateAsync(e,i,a);this.addErrorsToResult(n,p)}catch(p){let l=p instanceof Error?p.message:String(p);r.push({ruleName:s.ruleName,cause:l})}if(r.length>0){let s=new Map;for(let{ruleName:p,cause:l}of r){let m=s.get(l);m?m.push(p):s.set(l,[p])}for(let[p,l]of s){let m=new u;m.ruleType=l[0],m.severity="Error",l.length===1?m.message=`Validation rule '${l[0]}' failed: ${p}`:m.message=`${p} (affects ${l.length} rules: ${l.join(", ")})`,n.errors.push(m)}}}return n.isValid=n.errors.length===0,n}async validateDocumentsAsync(e,t){let o=new oe(t),n=[];for(let r of e){let a=await this.validateAsync(r,o.repository,o);n.push({document:r,result:a})}return n}async validateYamlAsync(e,t,o){let n=this.parser.parseWithErrors(e);if(!n.isValid){let r=new te;r.isValid=!1;for(let a of n.errors){let i=new u;i.ruleType="ParseError",i.severity="Error",i.lineNumber=a.line,i.column=a.column,i.message=a.message,a.keyName&&(i.entityName=a.keyName),a.errorType==="DuplicateKey"&&(i.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),r.errors.push(i)}return r}return await this.validateAsync(n.document,t,o)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let t=this.documentRules.findIndex(o=>o instanceof e);t>=0&&this.documentRules.splice(t,1)}removeRepositoryRule(e){let t=this.repositoryRules.findIndex(o=>o instanceof e);t>=0&&this.repositoryRules.splice(t,1)}addErrorsToResult(e,t){for(let o of t)o.severity==="Error"?e.errors.push(o):o.severity==="Info"?this.includeWarnings&&e.infos.push(o):this.includeWarnings&&e.warnings.push(o)}};export{te as a,k as b,u as c,Ze as d,oe as e,ae as f,ie as g,se as h,ce as i,pe as j,le as k,me as l,ue as m,de as n,fe as o,ye as p,ge as q,ke as r,he as s,Re as t,Ke as u,be as v,Ee as w,ve as x,De as y,Ie as z,Ce as A,Se as B,Pe as C,je as D,Oe as E,Ue as F,xe as G,Ne as H,$t as I,wt as J,Te as K,rt as L};
@@ -1,2 +1,2 @@
1
- import{a as v}from"./chunk-SC5M74NM.js";import{a as R}from"./chunk-NJ3AZYQD.js";import{e as F,g as A}from"./chunk-2ACBWC7K.js";var b="@kanonak-protocol/sdk (+https://kanonak.org)",w=b;function q(o){w=o}function G(){return w}function p(o){let t;try{t=typeof o=="string"?new URL(o):o}catch{throw new Error(`Kanonak requires an absolute https:// URL \u2014 got an unparseable or relative URL: ${String(o)}`)}if(t.protocol!=="https:")throw new Error(`Kanonak requires HTTPS \u2014 refusing to fetch ${t.href} (only https:// is supported).`)}var D=new Set([429,502,503,504]),K=4,I=500,C=2e4;function u(o,t){p(o);let e=new Headers(t?.headers);return e.has("User-Agent")||e.set("User-Agent",w),T(o,{...t,headers:e})}var k=K;function V(o){k=Math.max(0,o)}async function T(o,t){let e;for(let n=0;n<=k;n++){let r;try{r=await fetch(o,t)}catch(s){if(e=s,n>=k)throw s;await E(x(n,null));continue}if(!D.has(r.status)||n>=k)return r;await E(x(n,r.headers.get("retry-after")))}throw e??new Error("kanonakFetch: exhausted retries")}function x(o,t){let e=j(t);if(e!=null)return Math.min(e,C);let n=Math.min(C,I*2**o);return Math.floor(n/2+Math.random()*(n/2))}function j(o){if(!o)return null;let t=Number(o);if(Number.isFinite(t))return Math.max(0,t*1e3);let e=Date.parse(o);return Number.isNaN(e)?null:Math.max(0,e-Date.now())}function E(o){return new Promise(t=>setTimeout(t,o))}var M="https://{publisher}/{package}/{version}.kan.yml",L={version:1};function X(){return{version:1}}var y=class{constructor(t){this.fetchFn=t}fetchFn;cache=new Map;getConfig(t){let e=this.cache.get(t);return e||(e=this.fetchConfig(t),this.cache.set(t,e),e.catch(()=>{this.cache.get(t)===e&&this.cache.delete(t)})),e}async fetchConfig(t){let e=`https://${t}/.well-known/kanonak.json`,n;try{n=await(this.fetchFn?this.fetchFn(e,t):u(e))}catch{return L}if(n.status===404)return L;if(!n.ok)throw new Error(`Failed to fetch publisher config: ${e} (${n.status} ${n.statusText})`);let r=await n.json();if(typeof r.version!="number")throw new Error(`Invalid publisher config at ${e}: missing or invalid "version" field`);let s={version:r.version};return typeof r.package_url_template=="string"&&(N(e,"package_url_template",r.package_url_template),s.package_url_template=r.package_url_template),Array.isArray(r.featured_packages)&&r.featured_packages.every(i=>typeof i=="string")&&(s.featured_packages=r.featured_packages),s}resolvePackageUrl(t,e,n,r){let s=r.package_url_template??M,i=S(s,{publisher:t,package:e,version:n});return p(i),i}};function N(o,t,e){if(!e.startsWith("https://"))throw new Error(`Invalid publisher config at ${o}: ${t} must be an absolute https:// URL template (got "${e}").`)}function S(o,t){let e=o;for(let[r,s]of Object.entries(t))e=e.replaceAll(`{${r}}`,s);let n=e.match(/\{[a-z]+\}/);if(n)throw new Error(`Unresolved variable ${n[0]} in URL template: ${o}`);return e}import $ from"js-yaml";var H=`# This file is generated by Kanonak CLI. Do not edit manually.
2
- `,O="sha256:";function _(o){let t=$.load(o);return!t||typeof t!="object"||t.version!=="1"?null:{version:"1",lastUpdated:t.lastUpdated??"",packages:t.packages??{}}}function Q(o){let t={};for(let n of Object.keys(o.packages).sort())t[n]=o.packages[n];let e=$.dump({...o,packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'});return H+e}async function Z(o){let t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(o)),e=Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("");return`${O}${e}`}var m=class{configResolver;fetchFn;lockCache=new Map;constructor(t){this.configResolver=t?.configResolver??new y(t?.fetchFn),this.fetchFn=t?.fetchFn}getConfig(t){return this.configResolver.getConfig(t)}async getPackageUrl(t,e,n){let r=await this.configResolver.getConfig(t);return this.configResolver.resolvePackageUrl(t,e,n,r)}getLock(t){let e=this.lockCache.get(t);return e||(e=this.fetchLock(t),this.lockCache.set(t,e),e.catch(()=>{this.lockCache.get(t)===e&&this.lockCache.delete(t)})),e}async fetchLock(t){let e=`https://${t}/kanonak.lock`,n;try{n=this.fetchFn?await this.fetchFn(e,t):await u(e)}catch{return null}if(n.status===404)return null;if(!n.ok)throw new Error(`Failed to fetch publisher lock: ${e} (${n.status} ${n.statusText})`);return _(await n.text())}};import{VersionOperator as d}from"@kanonak-protocol/types/document/models/enums";function B(o,t){let e=A(o);if(!e)return!1;let n=t.version;switch(t.versionOperator){case d.Any:return!0;case d.Exact:return e.major===n.major&&e.minor===n.minor&&e.patch===n.patch;case d.Compatible:return e.major===n.major&&e.minor===n.minor&&e.patch>=n.patch;case d.Major:return e.major!==n.major?!1:e.minor!==n.minor?e.minor>n.minor:e.patch>=n.patch;default:return!1}}var U=class{parser=new R;publisherIndex;documents=new Map;contentCache=new Map;fetchFn;onFetch;getFromCache;constructor(t){this.onFetch=t?.onFetch,this.getFromCache=t?.getFromCache,this.fetchFn=t?.fetchFn,this.publisherIndex=t?.fetchFn?new m({fetchFn:t.fetchFn}):new m}async getHighestCompatibleVersionAsync(t,e){let r=(await this.publisherIndex.getLock(t))?.packages[`${t}/${e.packageName}`];return r?B(r.version,e)?this.fetchPinned(t,e.packageName,r):null:this.resolveByDirectFetch(t,e)}async fetchPinned(t,e,n){let r=n.version,s=`${t}/${e}@${r}`,i=this.documents.get(s);if(i)return i;let a=g=>{let f=this.parser.parse(g);return v(f,t,e,r),f};if(this.getFromCache){let g=this.getFromCache(t,e,r);if(g){let f=a(g);return this.documents.set(s,f),this.contentCache.set(s,g),f}}let l=n.resolved,c=this.fetchFn?await this.fetchFn(l,t):await u(l);if(!c.ok)throw new Error(`Failed to fetch Kanonak package: ${l} (${c.status} ${c.statusText})`);let h=await c.text(),P=a(h);return this.onFetch&&this.onFetch(t,e,r,h),this.documents.set(s,P),this.contentCache.set(s,h),P}async resolveByDirectFetch(t,e){let n=e.packageName,s=e.versionOperator===d.Exact?await this.publisherIndex.getPackageUrl(t,n,F(e.version)):`https://${t}/${n}.kan.yml`,i=await this.fetchFollowing(s,t);if(!i)return null;let a=this.parser.parse(i.content),l=a.metadata.namespace_;if(!l||!l.version)throw new Error(`Producer origin returned a package with no namespace/version for ${t}/${n}`);let c=F(l.version);v(a,t,n,c);let h=`${t}/${n}@${c}`;return this.onFetch&&this.onFetch(t,n,c,i.content),this.documents.set(h,a),this.contentCache.set(h,i.content),a}async fetchFollowing(t,e,n=4){let r=t;for(let s=0;s<n;s++){p(r);let i=this.fetchFn?await this.fetchFn(r,e):await u(r,{redirect:"manual"});if(i.status===301||i.status===302){let a=i.headers.get("location");if(!a)throw new Error(`Redirect with no Location header from ${r}`);r=new URL(a,r).toString();continue}if(i.status===404)return null;if(!i.ok)throw new Error(`Failed to fetch Kanonak package: ${r} (${i.status} ${i.statusText})`);return{url:r,content:await i.text()}}throw new Error(`Too many redirects resolving ${t}`)}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(t){return this.documents.get(t)??null}async getDocumentsByNamespaceAsync(t,e){return Array.from(this.documents.values()).filter(n=>{let r=n.metadata.namespace_;return r&&r.publisher===t&&r.package_===e})}async saveDocumentAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async deleteDocumentAsync(t){throw new Error("HttpKanonakDocumentRepository is read-only")}async clearNamespaceAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(t){return this.contentCache.get(t)??null}async getDocumentUriAsync(t){let e=t.match(/^(.+?)\/(.+?)@(.+)$/);if(!e)return null;let[,n,r,s]=e;return this.publisherIndex.getPackageUrl(n,r,s)}};export{b as a,q as b,G as c,p as d,u as e,V as f,X as g,y as h,O as i,_ as j,Q as k,Z as l,m,U as n};
1
+ import{a as v}from"./chunk-SC5M74NM.js";import{a as R}from"./chunk-NJ3AZYQD.js";import{e as F,g as A}from"./chunk-2ACBWC7K.js";var b="@kanonak-protocol/sdk (+https://kanonak.org)",w=b;function q(o){w=o}function G(){return w}function m(o){let t;try{t=typeof o=="string"?new URL(o):o}catch{throw new Error(`Kanonak requires an absolute https:// URL \u2014 got an unparseable or relative URL: ${String(o)}`)}if(t.protocol!=="https:")throw new Error(`Kanonak requires HTTPS \u2014 refusing to fetch ${t.href} (only https:// is supported).`)}var D=new Set([429,502,503,504]),K=4,I=500,C=2e4;function u(o,t){m(o);let e=new Headers(t?.headers);return e.has("User-Agent")||e.set("User-Agent",w),T(o,{...t,headers:e})}var k=K;function V(o){k=Math.max(0,o)}async function T(o,t){let e;for(let n=0;n<=k;n++){let r;try{r=await fetch(o,t)}catch(s){if(e=s,n>=k)throw s;await E(x(n,null));continue}if(!D.has(r.status)||n>=k)return r;await E(x(n,r.headers.get("retry-after")))}throw e??new Error("kanonakFetch: exhausted retries")}function x(o,t){let e=j(t);if(e!=null)return Math.min(e,C);let n=Math.min(C,I*2**o);return Math.floor(n/2+Math.random()*(n/2))}function j(o){if(!o)return null;let t=Number(o);if(Number.isFinite(t))return Math.max(0,t*1e3);let e=Date.parse(o);return Number.isNaN(e)?null:Math.max(0,e-Date.now())}function E(o){return new Promise(t=>setTimeout(t,o))}var M="https://{publisher}/{package}/{version}.kan.yml",L={version:1};function X(){return{version:1}}var y=class{constructor(t){this.fetchFn=t}fetchFn;cache=new Map;getConfig(t){let e=this.cache.get(t);return e||(e=this.fetchConfig(t),this.cache.set(t,e),e.catch(()=>{this.cache.get(t)===e&&this.cache.delete(t)})),e}async fetchConfig(t){let e=`https://${t}/.well-known/kanonak.json`,n;try{n=await(this.fetchFn?this.fetchFn(e,t):u(e))}catch{return L}if(n.status===404)return L;if(!n.ok)throw new Error(`Failed to fetch publisher config: ${e} (${n.status} ${n.statusText})`);let r=await n.json();if(typeof r.version!="number")throw new Error(`Invalid publisher config at ${e}: missing or invalid "version" field`);let s={version:r.version};return typeof r.package_url_template=="string"&&(N(e,"package_url_template",r.package_url_template),s.package_url_template=r.package_url_template),Array.isArray(r.featured_packages)&&r.featured_packages.every(i=>typeof i=="string")&&(s.featured_packages=r.featured_packages),s}resolvePackageUrl(t,e,n,r){let s=r.package_url_template??M,i=S(s,{publisher:t,package:e,version:n});return m(i),i}};function N(o,t,e){if(!e.startsWith("https://"))throw new Error(`Invalid publisher config at ${o}: ${t} must be an absolute https:// URL template (got "${e}").`)}function S(o,t){let e=o;for(let[r,s]of Object.entries(t))e=e.replaceAll(`{${r}}`,s);let n=e.match(/\{[a-z]+\}/);if(n)throw new Error(`Unresolved variable ${n[0]} in URL template: ${o}`);return e}import $ from"js-yaml";var H=`# This file is generated by Kanonak CLI. Do not edit manually.
2
+ `,O="sha256:";function _(o){let t=$.load(o);return!t||typeof t!="object"||t.version!=="1"?null:{version:"1",lastUpdated:t.lastUpdated??"",packages:t.packages??{}}}function Q(o){let t={};for(let n of Object.keys(o.packages).sort())t[n]=o.packages[n];let e=$.dump({...o,packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'});return H+e}async function Z(o){let t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(o)),e=Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("");return`${O}${e}`}var d=class{configResolver;fetchFn;lockCache=new Map;constructor(t){this.configResolver=t?.configResolver??new y(t?.fetchFn),this.fetchFn=t?.fetchFn}getConfig(t){return this.configResolver.getConfig(t)}async getPackageUrl(t,e,n){let r=await this.configResolver.getConfig(t);return this.configResolver.resolvePackageUrl(t,e,n,r)}getLock(t){let e=this.lockCache.get(t);return e||(e=this.fetchLock(t),this.lockCache.set(t,e),e.catch(()=>{this.lockCache.get(t)===e&&this.lockCache.delete(t)})),e}async fetchLock(t){let e=`https://${t}/kanonak.lock`,n;try{n=this.fetchFn?await this.fetchFn(e,t):await u(e)}catch{return null}if(n.status===404)return null;if(!n.ok)throw new Error(`Failed to fetch publisher lock: ${e} (${n.status} ${n.statusText})`);return _(await n.text())}};import{VersionOperator as g}from"@kanonak-protocol/types/document/models/enums";function B(o,t){let e=A(o);if(!e)return!1;let n=t.version;switch(t.versionOperator){case g.Any:return!0;case g.Exact:return e.major===n.major&&e.minor===n.minor&&e.patch===n.patch;case g.Compatible:return e.major===n.major&&e.minor===n.minor&&e.patch>=n.patch;case g.Major:return e.major!==n.major?!1:e.minor!==n.minor?e.minor>n.minor:e.patch>=n.patch;default:return!1}}var U=class{parser=new R;publisherIndex;documents=new Map;contentCache=new Map;fetchFn;onFetch;getFromCache;constructor(t){this.onFetch=t?.onFetch,this.getFromCache=t?.getFromCache,this.fetchFn=t?.fetchFn,this.publisherIndex=t?.fetchFn?new d({fetchFn:t.fetchFn}):new d}async getHighestCompatibleVersionAsync(t,e){let r=(await this.publisherIndex.getLock(t))?.packages[`${t}/${e.packageName}`];return r&&B(r.version,e)?this.fetchPinned(t,e.packageName,r):r&&e.versionOperator!==g.Exact?null:this.resolveByDirectFetch(t,e)}async fetchPinned(t,e,n){let r=n.version,s=`${t}/${e}@${r}`,i=this.documents.get(s);if(i)return i;let a=f=>{let p=this.parser.parse(f);return v(p,t,e,r),p};if(this.getFromCache){let f=this.getFromCache(t,e,r);if(f){let p=a(f);return this.documents.set(s,p),this.contentCache.set(s,f),p}}let l=n.resolved,c=this.fetchFn?await this.fetchFn(l,t):await u(l);if(!c.ok)throw new Error(`Failed to fetch Kanonak package: ${l} (${c.status} ${c.statusText})`);let h=await c.text(),P=a(h);return this.onFetch&&this.onFetch(t,e,r,h),this.documents.set(s,P),this.contentCache.set(s,h),P}async resolveByDirectFetch(t,e){let n=e.packageName,s=e.versionOperator===g.Exact?await this.publisherIndex.getPackageUrl(t,n,F(e.version)):`https://${t}/${n}.kan.yml`,i=await this.fetchFollowing(s,t);if(!i)return null;let a=this.parser.parse(i.content),l=a.metadata.namespace_;if(!l||!l.version)throw new Error(`Producer origin returned a package with no namespace/version for ${t}/${n}`);let c=F(l.version);v(a,t,n,c);let h=`${t}/${n}@${c}`;return this.onFetch&&this.onFetch(t,n,c,i.content),this.documents.set(h,a),this.contentCache.set(h,i.content),a}async fetchFollowing(t,e,n=4){let r=t;for(let s=0;s<n;s++){m(r);let i=this.fetchFn?await this.fetchFn(r,e):await u(r,{redirect:"manual"});if(i.status===301||i.status===302){let a=i.headers.get("location");if(!a)throw new Error(`Redirect with no Location header from ${r}`);r=new URL(a,r).toString();continue}if(i.status===404)return null;if(!i.ok)throw new Error(`Failed to fetch Kanonak package: ${r} (${i.status} ${i.statusText})`);return{url:r,content:await i.text()}}throw new Error(`Too many redirects resolving ${t}`)}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(t){return this.documents.get(t)??null}async getDocumentsByNamespaceAsync(t,e){return Array.from(this.documents.values()).filter(n=>{let r=n.metadata.namespace_;return r&&r.publisher===t&&r.package_===e})}async saveDocumentAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async deleteDocumentAsync(t){throw new Error("HttpKanonakDocumentRepository is read-only")}async clearNamespaceAsync(t,e){throw new Error("HttpKanonakDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(t){return this.contentCache.get(t)??null}async getDocumentUriAsync(t){let e=t.match(/^(.+?)\/(.+?)@(.+)$/);if(!e)return null;let[,n,r,s]=e;return this.publisherIndex.getPackageUrl(n,r,s)}};export{b as a,q as b,G as c,m as d,u as e,V as f,X as g,y as h,O as i,_ as j,Q as k,Z as l,d as m,U as n};
@@ -1,2 +1,2 @@
1
- import{e as F}from"./chunk-W35FCNM7.js";import{I as me,J as he}from"./chunk-UYSEO3OT.js";import{a as te,b as $,c as le,i as z,m as D}from"./chunk-V6KIDED2.js";import{k as ue,o as O,p as x,q as ge,r as B,v as ye}from"./chunk-SVUMCLK5.js";import{b as ne,c as T,d as _,f as oe,g as se,h as ae,i as ie,j as ce,k as pe,l as L,m as K,r as G,t as de,v as I,w as fe,y as V}from"./chunk-YW6P24RF.js";import{a as re}from"./chunk-FUUTGGJS.js";import{d as ee}from"./chunk-2ACBWC7K.js";var Ce=(a=>(a.Class="Class",a.DatatypeProperty="DatatypeProperty",a.ObjectProperty="ObjectProperty",a.AnnotationProperty="AnnotationProperty",a.Instance="Instance",a.Datatype="Datatype",a.Unknown="Unknown",a))(Ce||{}),Se=(i=>(i.InstanceOf="instanceOf",i.SubClassOf="subClassOf",i.Domain="domain",i.Range="range",i.ObjectRelationship="objectRelationship",i.SubPropertyOf="subPropertyOf",i.PropertyValue="propertyValue",i.EmbeddedLink="embeddedLink",i))(Se||{}),H=class{static async buildFromRepository(n,t){let o=await new D().parseKanonaks(n),s=await n.getAllDocumentsAsync(),c=[],a=[],i=new Set,d=new Set,f=new Map;for(let g of o){let u=g;if(u.name&&(O.isClassType(u)&&i.add(u.name),g instanceof T)){let l=B(o,g);(l==="ObjectProperty"||l==="Property")&&d.add(u.name)}}for(let g of s)for(let[u,l]of Object.entries(g.body))d.has(u)&&l?.range&&typeof l.range=="string"&&f.set(u,l.range);let p=new Map;for(let g of o){let u=g;u.name&&p.set(u.name,u)}for(let g of s){let u=g.metadata.namespace_,l=u?`${u.publisher}/${u.package_}`:"",m=u?.version?`${u.version.major}.${u.version.minor}.${u.version.patch}`:"",b=ke(g);for(let[h,y]of Object.entries(g.body)){if(!y||typeof y!="object")continue;let C=p.get(h),k="Unknown";if(C){let R=C,j=C instanceof T?B(o,C):void 0;O.isClassType(R)?k="Class":j==="ObjectProperty"?k="ObjectProperty":j==="DatatypeProperty"?k="DatatypeProperty":j==="AnnotationProperty"?k="AnnotationProperty":O.isDatatypeType(R)?k="Datatype":j==="Property"?k="ObjectProperty":O.isInstanceOfKnownClass(R,i)&&(k="Instance")}let S=l&&m?`${l}/${h}@${m}`:h,Z={};for(let[R,j]of Object.entries(y))R!=="type"&&(typeof j!="object"||j===null)&&(Z[R]=j);c.push({id:S,label:y.label??h,type:k,namespace:l,properties:Z}),be(S,y,k,i,d,a,l,m,b,t),q(S,y,d,f,c,a,l,m,b),Le(S,C,a)}}return{nodes:c,edges:a}}static buildFromDocument(n,t){let r=[],o=[],s=n.metadata.namespace_,c=s?.version?`${s.version.major}.${s.version.minor}.${s.version.patch}`:"",a=s?`${s.publisher}/${s.package_}`:"",i=new Set,d=new Set,f=new Map,p=ke(n);for(let[l,m]of Object.entries(n.body)){let b=m?.type;b&&(Me(b,p)&&i.add(l),Ue(b,p)&&(d.add(l),m.range&&typeof m.range=="string"&&f.set(l,m.range)))}for(let[l,m]of Object.entries(n.body)){if(!m||typeof m!="object")continue;let b=m.type,h=Fe(b,l,i,p),y=a&&c?`${a}/${l}@${c}`:l,C={};for(let[k,S]of Object.entries(m))k!=="type"&&(typeof S!="object"||S===null)&&(C[k]=S);r.push({id:y,label:m.label??l,type:h,namespace:a,properties:C}),be(y,m,h,i,d,o,a,c,p,t),q(y,m,d,f,r,o,a,c,p)}let g=new Set(r.map(l=>l.id)),u=o.filter(l=>g.has(l.source)&&g.has(l.target));return{nodes:r,edges:u}}};function ke(e,n){let t=new Map;if(e.metadata?.imports)for(let[r,o]of Object.entries(e.metadata.imports))for(let s of o){let c=s.alias??s.packageName,a=s.version,i=`${a.major}.${a.minor}.${a.patch}`;t.set(c,{publisher:r,package_:s.packageName,version:i})}return t}var Oe={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},De=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function W(e,n){if(e.includes(".")){let t=e.indexOf("."),r=e.substring(0,t),o=e.substring(t+1),s=n.get(r);if(s)return`${s.publisher}/${s.package_}/${o}`}return null}function Me(e,n){let t=W(e,n);return t?Oe[t]==="Class":!1}function Ue(e,n){let t=W(e,n);return t?De.has(t):!1}function Fe(e,n,t,r){if(!e||e==="Package")return"Unknown";let o=W(e,r);if(o){let c=Oe[o];if(c)return c;let a=o.split("/").pop()?.split("@")[0]??"";return t.has(a)?"Instance":"Unknown"}let s=e.split(".").pop()??e;return t.has(s)?"Instance":"Unknown"}var ve=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function be(e,n,t,r,o,s,c,a,i,d){let f=n.type,p=n.subClassOf;if(p){let h=Array.isArray(p)?p:[p];for(let y of h)typeof y=="string"&&s.push({source:e,target:v(y,c,a,i),type:"subClassOf",label:"subClassOf"})}let g=n.subPropertyOf;if(g){let h=Array.isArray(g)?g:[g];for(let y of h)typeof y=="string"&&s.push({source:e,target:v(y,c,a,i),type:"subPropertyOf",label:"subPropertyOf"})}let u=n.domain,l=n.range;if(d?.includePropertyEdges){let h=[[u,"domain","domain"],[l,"range","range"]];for(let[y,C,k]of h)if(y!=null)for(let S of Array.isArray(y)?y:[y])typeof S=="string"&&s.push({source:e,target:v(S,c,a,i),type:C,label:k})}if(t==="Instance"&&f){let h=f.split(".").pop()??f;s.push({source:e,target:v(h,c,a,i),type:"instanceOf",label:"type"})}if(t==="Instance")for(let[h,y]of Object.entries(n)){if(ve.has(h)||!o.has(h))continue;let C=Array.isArray(y)?y:[y];for(let k of C)typeof k=="string"&&Ge(k)&&s.push({source:e,target:v(k,c,a,i),type:"propertyValue",label:h,propertyId:v(h,c,a,i)})}if((t==="ObjectProperty"||t==="DatatypeProperty"||u&&l)&&u&&l){let h=typeof u=="string"?u:null,y=typeof l=="string"?l:null;h&&y&&s.push({source:v(h,c,a,i),target:v(y,c,a,i),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function q(e,n,t,r,o,s,c,a,i){for(let[d,f]of Object.entries(n)){if(ve.has(d)||typeof f!="object"||f===null||Array.isArray(f))continue;let p=f,g=`${e}/${d}`,u=r.get(d),l=u?u.split(".").pop()??u:"Unknown",m={};for(let[h,y]of Object.entries(p))(typeof y!="object"||y===null)&&(m[h]=y);o.push({id:g,label:`${l} (embedded)`,type:"Instance",namespace:c,properties:m});let b=c&&a?`${c}/${d}@${a}`:d;s.push({source:e,target:g,type:"propertyValue",label:d,propertyId:t.has(d)?b:void 0}),u&&s.push({source:g,target:v(l,c,a,i),type:"instanceOf",label:"type (inferred)"}),q(g,p,t,r,o,s,c,a,i)}}function Le(e,n,t){let r=n?.statement;if(Array.isArray(r))for(let o of r){if(!(o instanceof le))continue;let s=o.predicate?.subject?.name??"";for(let c of o.links){let a=c.target?.subject;if(!a)continue;let i=a.version,d=i&&typeof i.major=="number"?`@${i.major}.${i.minor}.${i.patch}`:"";t.push({source:e,target:`${a.publisher}/${a.package_}/${a.name}${d}`,type:"embeddedLink",label:s})}}}function Ge(e){return!(!e||e.includes(" ")||e.includes(`
1
+ import{e as F}from"./chunk-CCVH7TCQ.js";import{I as me,J as he}from"./chunk-AB42RUYY.js";import{a as te,b as $,c as le,i as z,m as D}from"./chunk-V6KIDED2.js";import{k as ue,o as O,p as x,q as ge,r as B,v as ye}from"./chunk-SVUMCLK5.js";import{b as ne,c as T,d as _,f as oe,g as se,h as ae,i as ie,j as ce,k as pe,l as L,m as K,r as G,t as de,v as I,w as fe,y as V}from"./chunk-YW6P24RF.js";import{a as re}from"./chunk-FUUTGGJS.js";import{d as ee}from"./chunk-2ACBWC7K.js";var Ce=(a=>(a.Class="Class",a.DatatypeProperty="DatatypeProperty",a.ObjectProperty="ObjectProperty",a.AnnotationProperty="AnnotationProperty",a.Instance="Instance",a.Datatype="Datatype",a.Unknown="Unknown",a))(Ce||{}),Se=(i=>(i.InstanceOf="instanceOf",i.SubClassOf="subClassOf",i.Domain="domain",i.Range="range",i.ObjectRelationship="objectRelationship",i.SubPropertyOf="subPropertyOf",i.PropertyValue="propertyValue",i.EmbeddedLink="embeddedLink",i))(Se||{}),H=class{static async buildFromRepository(n,t){let o=await new D().parseKanonaks(n),s=await n.getAllDocumentsAsync(),c=[],a=[],i=new Set,d=new Set,f=new Map;for(let g of o){let u=g;if(u.name&&(O.isClassType(u)&&i.add(u.name),g instanceof T)){let l=B(o,g);(l==="ObjectProperty"||l==="Property")&&d.add(u.name)}}for(let g of s)for(let[u,l]of Object.entries(g.body))d.has(u)&&l?.range&&typeof l.range=="string"&&f.set(u,l.range);let p=new Map;for(let g of o){let u=g;u.name&&p.set(u.name,u)}for(let g of s){let u=g.metadata.namespace_,l=u?`${u.publisher}/${u.package_}`:"",m=u?.version?`${u.version.major}.${u.version.minor}.${u.version.patch}`:"",b=ke(g);for(let[h,y]of Object.entries(g.body)){if(!y||typeof y!="object")continue;let C=p.get(h),k="Unknown";if(C){let R=C,j=C instanceof T?B(o,C):void 0;O.isClassType(R)?k="Class":j==="ObjectProperty"?k="ObjectProperty":j==="DatatypeProperty"?k="DatatypeProperty":j==="AnnotationProperty"?k="AnnotationProperty":O.isDatatypeType(R)?k="Datatype":j==="Property"?k="ObjectProperty":O.isInstanceOfKnownClass(R,i)&&(k="Instance")}let S=l&&m?`${l}/${h}@${m}`:h,Z={};for(let[R,j]of Object.entries(y))R!=="type"&&(typeof j!="object"||j===null)&&(Z[R]=j);c.push({id:S,label:y.label??h,type:k,namespace:l,properties:Z}),be(S,y,k,i,d,a,l,m,b,t),q(S,y,d,f,c,a,l,m,b),Le(S,C,a)}}return{nodes:c,edges:a}}static buildFromDocument(n,t){let r=[],o=[],s=n.metadata.namespace_,c=s?.version?`${s.version.major}.${s.version.minor}.${s.version.patch}`:"",a=s?`${s.publisher}/${s.package_}`:"",i=new Set,d=new Set,f=new Map,p=ke(n);for(let[l,m]of Object.entries(n.body)){let b=m?.type;b&&(Me(b,p)&&i.add(l),Ue(b,p)&&(d.add(l),m.range&&typeof m.range=="string"&&f.set(l,m.range)))}for(let[l,m]of Object.entries(n.body)){if(!m||typeof m!="object")continue;let b=m.type,h=Fe(b,l,i,p),y=a&&c?`${a}/${l}@${c}`:l,C={};for(let[k,S]of Object.entries(m))k!=="type"&&(typeof S!="object"||S===null)&&(C[k]=S);r.push({id:y,label:m.label??l,type:h,namespace:a,properties:C}),be(y,m,h,i,d,o,a,c,p,t),q(y,m,d,f,r,o,a,c,p)}let g=new Set(r.map(l=>l.id)),u=o.filter(l=>g.has(l.source)&&g.has(l.target));return{nodes:r,edges:u}}};function ke(e,n){let t=new Map;if(e.metadata?.imports)for(let[r,o]of Object.entries(e.metadata.imports))for(let s of o){let c=s.alias??s.packageName,a=s.version,i=`${a.major}.${a.minor}.${a.patch}`;t.set(c,{publisher:r,package_:s.packageName,version:i})}return t}var Oe={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},De=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function W(e,n){if(e.includes(".")){let t=e.indexOf("."),r=e.substring(0,t),o=e.substring(t+1),s=n.get(r);if(s)return`${s.publisher}/${s.package_}/${o}`}return null}function Me(e,n){let t=W(e,n);return t?Oe[t]==="Class":!1}function Ue(e,n){let t=W(e,n);return t?De.has(t):!1}function Fe(e,n,t,r){if(!e||e==="Package")return"Unknown";let o=W(e,r);if(o){let c=Oe[o];if(c)return c;let a=o.split("/").pop()?.split("@")[0]??"";return t.has(a)?"Instance":"Unknown"}let s=e.split(".").pop()??e;return t.has(s)?"Instance":"Unknown"}var ve=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function be(e,n,t,r,o,s,c,a,i,d){let f=n.type,p=n.subClassOf;if(p){let h=Array.isArray(p)?p:[p];for(let y of h)typeof y=="string"&&s.push({source:e,target:v(y,c,a,i),type:"subClassOf",label:"subClassOf"})}let g=n.subPropertyOf;if(g){let h=Array.isArray(g)?g:[g];for(let y of h)typeof y=="string"&&s.push({source:e,target:v(y,c,a,i),type:"subPropertyOf",label:"subPropertyOf"})}let u=n.domain,l=n.range;if(d?.includePropertyEdges){let h=[[u,"domain","domain"],[l,"range","range"]];for(let[y,C,k]of h)if(y!=null)for(let S of Array.isArray(y)?y:[y])typeof S=="string"&&s.push({source:e,target:v(S,c,a,i),type:C,label:k})}if(t==="Instance"&&f){let h=f.split(".").pop()??f;s.push({source:e,target:v(h,c,a,i),type:"instanceOf",label:"type"})}if(t==="Instance")for(let[h,y]of Object.entries(n)){if(ve.has(h)||!o.has(h))continue;let C=Array.isArray(y)?y:[y];for(let k of C)typeof k=="string"&&Ge(k)&&s.push({source:e,target:v(k,c,a,i),type:"propertyValue",label:h,propertyId:v(h,c,a,i)})}if((t==="ObjectProperty"||t==="DatatypeProperty"||u&&l)&&u&&l){let h=typeof u=="string"?u:null,y=typeof l=="string"?l:null;h&&y&&s.push({source:v(h,c,a,i),target:v(y,c,a,i),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function q(e,n,t,r,o,s,c,a,i){for(let[d,f]of Object.entries(n)){if(ve.has(d)||typeof f!="object"||f===null||Array.isArray(f))continue;let p=f,g=`${e}/${d}`,u=r.get(d),l=u?u.split(".").pop()??u:"Unknown",m={};for(let[h,y]of Object.entries(p))(typeof y!="object"||y===null)&&(m[h]=y);o.push({id:g,label:`${l} (embedded)`,type:"Instance",namespace:c,properties:m});let b=c&&a?`${c}/${d}@${a}`:d;s.push({source:e,target:g,type:"propertyValue",label:d,propertyId:t.has(d)?b:void 0}),u&&s.push({source:g,target:v(l,c,a,i),type:"instanceOf",label:"type (inferred)"}),q(g,p,t,r,o,s,c,a,i)}}function Le(e,n,t){let r=n?.statement;if(Array.isArray(r))for(let o of r){if(!(o instanceof le))continue;let s=o.predicate?.subject?.name??"";for(let c of o.links){let a=c.target?.subject;if(!a)continue;let i=a.version,d=i&&typeof i.major=="number"?`@${i.major}.${i.minor}.${i.patch}`:"";t.push({source:e,target:`${a.publisher}/${a.package_}/${a.name}${d}`,type:"embeddedLink",label:s})}}}function Ge(e){return!(!e||e.includes(" ")||e.includes(`
2
2
  `)||e.startsWith("http://")||e.startsWith("https://")||/^\d{4}-\d{2}/.test(e)||/^\d+(\.\d+)?$/.test(e))}function v(e,n,t,r){if(e.includes("@")&&e.includes("/"))return e;if(e.includes(".")){let o=e.indexOf("."),s=e.substring(0,o),c=e.substring(o+1);if(r){let a=r.get(s);if(a)return`${a.publisher}/${a.package_}/${c}@${a.version}`}return n&&t?`${n}/${c}@${t}`:c}return n&&t?`${n}/${e}@${t}`:e}import{canonicalForm as Ve,canonicalHash as Be}from"@kanonak-protocol/canonical";function X(e){return typeof e=="object"&&e!==null&&Array.isArray(e.subjects)}import{CANONICAL_FORM_VERSION as en}from"@kanonak-protocol/canonical";function ze(e){return Ve(X(e)?e:Pe(e))}function He(e){return Be(X(e)?e:Pe(e))}function Pe(e){let n=[];for(let t of e)t instanceof T&&n.push({uri:Ze(t),statements:Y(t.statement)});return{subjects:n}}function Y(e){let n=[];for(let t of e){let r=Qe(t);if(!r)continue;if(t instanceof L&&qe(t.predicate.subject)){n.push(...Xe(t,r));continue}let o=Ye(t);o&&n.push({predicate:r,value:o})}return n}function qe(e){let n=ue("type");return n!==void 0&&e.name==="type"&&e.publisher===n.publisher&&e.package_===n.package_}var we=new TextEncoder;function We(e,n){let t=we.encode(e),r=we.encode(n),o=Math.min(t.length,r.length);for(let s=0;s<o;s++)if(t[s]!==r[s])return t[s]-r[s];return t.length-r.length}function Xe(e,n){let t=[];for(let r of e.object){if(!(r instanceof _))throw new Error(`canonicalForm: a multi-valued type statement must contain only entity references, got ${r.constructor?.name??typeof r}`);t.push(J(r))}t.sort(We);for(let r=1;r<t.length;r++)if(t[r-1]===t[r])throw new Error(`canonicalForm: duplicate type ${t[r]} in a multi-valued type statement`);return t.map(r=>({predicate:n,value:{ref:r}}))}function Ye(e){if(e instanceof oe&&e.carrier)return{lit:e.lexical??String(e.object),datatype:Te(e.carrier)};if(e instanceof se)return{raw:e.object};if(e instanceof ae)return{raw:e.lexical??String(e.object)};if(e instanceof ie)return{raw:e.lexical??String(e.object)};if(e instanceof ce)return{ref:J(e.object)};if(e instanceof pe)return je(e.object);if(e instanceof L)return{list:e.object.map(Je)}}function je(e){let n=Y(e.statement);return e.name&&e.name.length>0?{embed:{name:e.name,statements:n}}:{embed:{statements:n}}}function Je(e){if(e instanceof _)return{ref:J(e)};if(e instanceof te)return je(e);if(e instanceof $){if(e.carrier)return{lit:e.lexical??String(e.value),datatype:Te(e.carrier)};let n=e.value;if(typeof n=="string")return{raw:n};if(typeof n=="number")return{raw:String(n)};if(typeof n=="boolean")return{raw:String(n)}}if(e instanceof ne)return{embed:{statements:Y(e.statement)}};throw new Error(`canonicalForm: list item of unrecognized kind (${e.constructor?.name??typeof e}); add canonicalization support before hashing data that contains it`)}function Te(e){return e===z.LangString?"kanonak.org/core-rdf/langString":`kanonak.org/core-xsd/${e}`}function Qe(e){let n=e.predicate;if(n)return Ee(n.subject)}function Ze(e){let n=e.namespace??"",t=e.name??"";return`${n}/${t}`}function J(e){return Ee(e.subject)}function Ee(e){let n=e.version;return n&&typeof n.major=="number"?`${e.publisher}/${e.package_}@${n.major}.${n.minor}.${n.patch}/${e.name}`:`${e.publisher}/${e.package_}/${e.name}`}function A(e){let n=e.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!n)throw new Error("Publisher host cannot be empty");return n}var nn="key_thumbprint",N=class{cache=new Map;prCache=new Map;async discoverProtectedResource(n){let t=A(n);if(this.prCache.has(t))return this.prCache.get(t);let r=`https://${t}/.well-known/oauth-protected-resource`,o=await tn(r),s=o&&Array.isArray(o.authorization_servers)?o.authorization_servers.filter(a=>typeof a=="string"):[],c=s.length>0?s:null;return this.prCache.set(t,c),c}async discover(n){let t=A(n);if(this.cache.has(t))return this.cache.get(t);let r=`https://${t}/.well-known/oauth-authorization-server`,o=await this.tryEndpoint(r);if(!o){let s=`https://${t}/.well-known/openid-configuration`;o=await this.tryEndpoint(s)}return this.cache.set(t,o),o}async supportsOAuth(n){return await this.discover(n)!==null}static supportsPkceS256(n){return n.codeChallengeMethodsSupported?.some(t=>t.toUpperCase()==="S256")??!1}static supportsDynamicRegistration(n){return!!n.registrationEndpoint}static supportsAuthorizationCode(n){return n.responseTypesSupported?.some(t=>t.toLowerCase()==="code")??!1}static supportsEnrollment(n){return!!n.enrollmentEndpoint}static supportsSession(n){return!!n.sessionEndpoint}async tryEndpoint(n){let t;try{t=await fetch(n)}catch(o){let s=o instanceof Error?o.message:String(o);return s.includes("ENOTFOUND")||s.includes("ECONNREFUSED")?(console.error(` OAuth discovery: ${n} \u2014 host unreachable (${s})`),console.error(" If the server is behind a VPN, ensure you are connected.")):s.includes("CERT")||s.includes("SSL")||s.includes("TLS")?(console.error(` OAuth discovery: ${n} \u2014 TLS error (${s})`),console.error(" If using a custom CA certificate, set NODE_EXTRA_CA_CERTS=/path/to/ca.pem")):console.error(` OAuth discovery: ${n} \u2014 network error: ${s}`),null}if(!t.ok)return t.status===404||(t.status===403?(console.error(` OAuth discovery: ${n} \u2014 HTTP 403 Forbidden`),console.error(" Access may be blocked by a firewall, proxy, or WAF.")):t.status>=500&&(console.error(` OAuth discovery: ${n} \u2014 HTTP ${t.status} server error`),console.error(" The authorization server returned an internal error. Contact your IDP administrator."))),null;let r;try{r=await t.json()}catch{return console.error(` OAuth discovery: ${n} \u2014 response is not valid JSON`),console.error(" The endpoint may be returning HTML instead of JSON. Check IDP configuration."),null}return{issuer:w(r.issuer),authorizationEndpoint:w(r.authorization_endpoint),tokenEndpoint:w(r.token_endpoint),registrationEndpoint:w(r.registration_endpoint),revocationEndpoint:w(r.revocation_endpoint),scopesSupported:P(r.scopes_supported),responseTypesSupported:P(r.response_types_supported),grantTypesSupported:P(r.grant_types_supported),codeChallengeMethodsSupported:P(r.code_challenge_methods_supported),tokenEndpointAuthMethodsSupported:P(r.token_endpoint_auth_methods_supported),dpopSigningAlgValuesSupported:P(r.dpop_signing_alg_values_supported),enrollmentEndpoint:w(r.enrollment_endpoint),enrollmentIssuanceProtocols:P(r.enrollment_issuance_protocols),enrollmentKeyTypes:P(r.enrollment_key_types),enrollmentScopesSupported:P(r.enrollment_scopes_supported),enrollmentConsentBindingParam:w(r.enrollment_consent_binding_param),sessionEndpoint:w(r.session_endpoint),sessionEndpointAuthMethod:w(r.session_endpoint_auth_method)}}};async function tn(e){try{let n=await fetch(e);return n.ok?await n.json():null}catch{return null}}function w(e){return typeof e=="string"?e:null}function P(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):null}function Re(e){let n=e.headers.get("WWW-Authenticate")??void 0,t=e.headers.get("DPoP-Nonce")??void 0;if(!n&&!t)return;let r={wwwAuthenticate:n??""};if(t&&(r.nonce=t),n){let o=n.match(/acr_values\s*=\s*"([^"]*)"/i);o&&(r.acrValues=o[1])}return r}function rn(e){try{return new URL(e).host}catch{return null}}function on(e,n={}){let t=n.discovery??new N,r=new Map,o=new Map,s=async i=>{let d=r.get(i);if(d!==void 0)return d;let f=null,p=await t.discoverProtectedResource(i).catch(()=>null);return p&&p.length>0&&(f=rn(p[0])),r.set(i,f),f},c=async(i,d)=>{if(!e)return null;if(!(d.forceRefresh||d.challenge)&&o.has(i))return o.get(i);let p=await e.resolve(i,d).catch(()=>null);return o.set(i,p),p},a=async(i,d,f,p)=>{let g=await s(d);if(!g)return{res:await F(i,{method:f,redirect:"manual"}),authed:!1};let u=await c(g,{method:f,url:i,...p}),l=u?.headers??{};return{res:await F(i,{method:f,redirect:"manual",headers:l}),authed:!!u}};return async(i,d,f="GET")=>{let p=await a(i,d,f,{});if((p.res.status===401||p.res.status===403)&&p.authed){let g=Re(p.res),u={forceRefresh:g===void 0};return g&&(u.challenge=g),(await a(i,d,f,u)).res}return p.res}}var _e="KANONAK_TOKEN";function sn(){return typeof process<"u"&&process.env?process.env:{}}function an(e){return`${_e}_${e.toUpperCase().replace(/[^A-Z0-9]+/g,"_")}`}var Q=class{tokens;env;constructor(n={}){this.tokens=n.tokens??{},this.env=n.env??sn()}async resolve(n,t){let r=A(n),o=this.tokens[r]??this.env[an(r)]??this.env[_e];return o?{headers:{Authorization:`Bearer ${o}`}}:null}};var E="kanonak.org",U="core-rdf",Ie="core-xsd",Ae={publisher:E,package_:U,name:"subClassOf"},Ne={publisher:E,package_:U,name:"label"},$e={publisher:E,package_:U,name:"comment"},Ke={publisher:E,package_:"core-owl",name:"oneOf"},xe=e=>e;function cn(e){let n=fe(e,Ae);if(n)return[n];let t=[];for(let r of V(e,Ae))r instanceof _&&t.push(r.subject);return t}function pn(e,n,t){if(n.publisher===E&&n.package_===U&&n.name==="Literal")return{kind:"datatype",uri:n};let o=G(e,n);if(o){let s=xe(o);if(O.isDatatypeType(s))return{kind:"datatype",uri:n};if(O.isClassType(s))return{kind:"class",uri:x(o)??n,localName:o.name}}return n.publisher===E&&n.package_===Ie?{kind:"datatype",uri:n}:t==="datatype"?{kind:"datatype",uri:n}:{kind:"class",uri:n,localName:n.name}}function ln(e,n,t){if(!n.range)throw new Error(`Property ${n.uri.publisher}/${n.uri.package_}/${n.uri.name} has no rdfs.range; every property must declare a range. Validate the ontology before introspecting it.`);let r=pn(e,n.range,n.kind),o=n.kind==="object"?"object":n.kind==="datatype"?"datatype":r.kind==="class"?"object":"datatype";return{uri:n.uri,localName:n.uri.name,kind:o,range:r,...n.label!==void 0?{label:n.label}:{},...n.comment!==void 0?{comment:n.comment}:{},...t??{}}}var M=e=>new re(E,Ie,e);function un(e){return typeof e=="boolean"?M("boolean"):typeof e=="number"?Number.isInteger(e)?M("integer"):M("decimal"):M("string")}function dn(e,n){let t=[];for(let r of V(n,Ke))if(r instanceof _){let o=G(e,r.subject),s=(o?x(o):void 0)??r.subject,c=o?I(o,Ne):void 0,a=o?I(o,$e):void 0;t.push({kind:"individual",uri:s,localName:s.name,...c!==void 0?{label:c}:{},...a!==void 0?{comment:a}:{}})}else r instanceof $&&t.push({kind:"literal",value:r.value,datatype:un(r.value)});return t}function fn(e,n,t,r){let o=ge(e,n),s=K(n);return ye(e,n).filter(a=>t?!0:a.domains.some(i=>K(i)===s)).map(a=>ln(e,a,he(r,o,a.uri)))}async function gn(e,n,t){let r=e.metadata?.namespace_;if(!r)throw new Error("buildOntologyModel: document has no namespace (publisher/package/version).");let o=t?.includeInherited??!1,s=await new D().parseKanonaks(n),c=me(s),a=[],i=[],d=new Set;for(let f of s){if(!(f instanceof T)||!O.isClassType(xe(f)))continue;let p=x(f);if(!p||p.publisher!==r.publisher||p.package_!==r.package_||p.version&&r.version&&!ee(p.version,r.version))continue;let g=K(p);if(d.has(g))continue;d.add(g);let u=cn(f).map(b=>({uri:b,localName:b.name})),l=I(f,Ne),m=I(f,$e);a.push({uri:p,localName:p.name,superClasses:u,properties:fn(s,p,o,c),...l!==void 0?{label:l}:{},...m!==void 0?{comment:m}:{}}),de(f,Ke)&&i.push({uri:p,localName:p.name,members:dn(s,f),...l!==void 0?{label:l}:{},...m!==void 0?{comment:m}:{}})}return{classes:a,enums:i}}export{Ce as a,Se as b,H as c,ze as d,He as e,en as f,A as g,nn as h,N as i,Re as j,on as k,Q as l,gn as m};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-FUUTGGJS.js";var i=class{resourceResolver;constructor(e){this.resourceResolver=e}async buildFromNameAsync(e,r){return(await this.resourceResolver.resolveEntityAsync(e,r))?.uri??null}buildFromName(e,r,t){if(e.includes(".")){let o=e.split("."),l=o[0],u=o[1],p=this.findPackageNameForAlias(t,l);if(p){for(let n of r.values())if(n.entityName===u&&n.uri.package_===p)return n.uri}return null}let s=r.get(e);return s?s.uri:null}create(e,r,t,s){return new a(e,r,t,s)}findPackageNameForAlias(e,r){if(!e.metadata.imports)return null;for(let[t,s]of Object.entries(e.metadata.imports))for(let o of s)if(o.alias===r||!o.alias&&o.packageName===r)return o.packageName;return null}};export{i as a};