@kanonak-protocol/sdk 4.10.0 → 4.11.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.
Files changed (35) hide show
  1. package/dist/browser.d.ts +1 -1
  2. package/dist/browser.js +2 -2
  3. package/dist/{chunk-NV63IOB7.js → chunk-47RLRYV2.js} +1 -1
  4. package/dist/chunk-4UT2CLAT.js +1 -0
  5. package/dist/chunk-55DXTCGV.js +86 -0
  6. package/dist/{chunk-VKTFLHCW.js → chunk-7HRKWTBB.js} +1 -1
  7. package/dist/{chunk-PBNVHBS3.js → chunk-7TKJHKC2.js} +1 -1
  8. package/dist/{chunk-OOR5SVNQ.js → chunk-E2FCKRB4.js} +1 -1
  9. package/dist/{chunk-UK2OIPAB.js → chunk-IEOSSSB5.js} +1 -1
  10. package/dist/chunk-MFNVQSBW.js +1 -0
  11. package/dist/{chunk-RYOZTXI7.js → chunk-MMJ7GO7J.js} +1 -1
  12. package/dist/{chunk-RWEGPZ23.js → chunk-QIMJSVIM.js} +1 -1
  13. package/dist/{chunk-KGWDV7FW.js → chunk-WED776KZ.js} +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +3 -3
  16. package/dist/kanonaks/DefinedKanonak.d.ts +25 -0
  17. package/dist/parsing/index.js +1 -1
  18. package/dist/reasoning/KanonakVocabulary.d.ts +8 -0
  19. package/dist/reasoning/index.js +1 -1
  20. package/dist/resolution/index.js +1 -1
  21. package/dist/search/index.js +1 -1
  22. package/dist/server/index.js +1 -1
  23. package/dist/transformations/index.js +1 -1
  24. package/dist/uri-helpers/index.js +1 -1
  25. package/dist/validation/documentModel.d.ts +48 -0
  26. package/dist/validation/index.d.ts +1 -1
  27. package/dist/validation/index.js +1 -1
  28. package/dist/validation/rules/repository/MarkdownLinkRule.d.ts +3 -4
  29. package/dist/validation/rules/repository/UnresolvedPredicateRule.d.ts +25 -0
  30. package/dist/validation/rules/repository/index.d.ts +1 -1
  31. package/package.json +2 -2
  32. package/dist/chunk-DSHPAWJQ.js +0 -1
  33. package/dist/chunk-IZRPJCQW.js +0 -86
  34. package/dist/chunk-T3JR2SV6.js +0 -1
  35. package/dist/validation/rules/repository/InstancePropertyReferenceRule.d.ts +0 -35
package/dist/browser.d.ts CHANGED
@@ -12,7 +12,7 @@ export { KanonakParser, KanonakObjectParser, PropertyMetadata, KanonakDocumentPo
12
12
  export type { IKanonakObjectParser, SourcePosition, ImportPackageEntry, ParsedDocumentWithPositions, } from './parsing/index.js';
13
13
  export { GraphBuilder, NodeType, EdgeType } from './graph/index.js';
14
14
  export type { GraphNode, GraphEdge, GraphData } from './graph/index.js';
15
- export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, InstancePropertyReferenceRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, MarkdownLinkRule } from './validation/index.js';
15
+ export { OntologyValidationResult, OntologyValidationError, ValidationSeverity, ValidationContext, KanonakObjectValidator, NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, EmbeddedKanonakTypeRule, ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, DefinitionPropertyReferenceRule, XsdImportRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyImportRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyValueTypeRule, ClassDefinitionRule, MarkdownLinkRule } from './validation/index.js';
16
16
  export type { IKanonakObjectValidator, IDocumentValidationRule, IRepositoryValidationRule } from './validation/index.js';
17
17
  export { Kanonak, DefinedKanonak, SubjectKanonak, EmbeddedKanonak, ReferenceKanonak } from './kanonaks/index.js';
18
18
  export type { IStatement } from './statements/index.js';
package/dist/browser.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as we,b as ke,c as he,d as E,e as _,f as d,g as tr}from"./chunk-KGWDV7FW.js";import{a as rr}from"./chunk-NV63IOB7.js";import"./chunk-QHABFCRC.js";import{a as F,b as W,c as G,d as w,f as X,g as Q,h as Y}from"./chunk-JYBKSBB5.js";import{a as q}from"./chunk-4NO7MHS7.js";import{a as Ke,b as be,c as xe}from"./chunk-RYOZTXI7.js";import{a as Se,b as Re}from"./chunk-PEUTCG3B.js";import"./chunk-PEJALHXK.js";import"./chunk-SC5M74NM.js";import{A as Xe,B as Qe,C as Ye,D as Ze,M as er,a as De,b as Be,c as Ce,d as Ee,f as _e,g as je,h as Ae,i as ve,k as Ie,l as Te,m as Oe,n as Ve,o as Ue,p as $e,q as Me,r as Ne,s as ze,t as Je,u as He,v as qe,w as Le,x as Fe,y as We,z as Ge}from"./chunk-IZRPJCQW.js";import"./chunk-SHDHMKMJ.js";import{a as te,c as ye,i as me}from"./chunk-DSHPAWJQ.js";import{a as L}from"./chunk-NJ3AZYQD.js";import{a as Pe}from"./chunk-UK2OIPAB.js";import"./chunk-PBNVHBS3.js";import{b as ge,c as fe}from"./chunk-VKTFLHCW.js";import{a as Z,b as ee,c as re,d as oe,e as se,f as ie,g as ae,h as ce,i as le,j as ue,k as de,l as pe}from"./chunk-T3JR2SV6.js";import{a as ne}from"./chunk-FUUTGGJS.js";import{c as V,d as U,e as $,f as M,g as N,h as z,i as J,j as H}from"./chunk-2ACBWC7K.js";var j="kanonak-credentials",u="credentials",nr=1,f=class{async get(r){let e=d(r),t=await h();return new Promise((o,a)=>{let s=t.transaction(u,"readonly"),i=s.objectStore(u).get(e);i.onsuccess=()=>o(i.result??null),i.onerror=()=>a(new Error(`IndexedDB read failed for '${e}': ${i.error?.message}`)),s.oncomplete=()=>t.close()})}async store(r,e){let t=d(r),o=await h();return new Promise((a,s)=>{let l=o.transaction(u,"readwrite"),c=l.objectStore(u).put(e,t);c.onsuccess=()=>a(),c.onerror=()=>s(new Error(`IndexedDB write failed for '${t}': ${c.error?.message}`)),l.oncomplete=()=>o.close()})}async remove(r){let e=d(r),t=await h();return new Promise((o,a)=>{let s=t.transaction(u,"readwrite"),i=s.objectStore(u).delete(e);i.onsuccess=()=>o(),i.onerror=()=>a(new Error(`IndexedDB delete failed for '${e}': ${i.error?.message}`)),s.oncomplete=()=>t.close()})}async list(){let r=await h();return new Promise((e,t)=>{let o=r.transaction(u,"readonly"),s=o.objectStore(u).getAllKeys();s.onsuccess=()=>e(s.result??[]),s.onerror=()=>t(new Error(`IndexedDB list failed: ${s.error?.message}`)),o.oncomplete=()=>r.close()})}};function h(){return new Promise((n,r)=>{let e=indexedDB.open(j,nr);e.onupgradeneeded=()=>{let t=e.result;t.objectStoreNames.contains(u)||t.createObjectStore(u)},e.onsuccess=()=>n(e.result),e.onerror=()=>r(new Error(`Failed to open IndexedDB '${j}': ${e.error?.message}
2
- Credential storage requires IndexedDB support in your browser.`))})}async function v(){let n=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),r=await crypto.subtle.exportKey("jwk",n.publicKey);return{signingKey:n.privateKey,publicKeyJwk:r}}async function K(){let n=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign"]),r=await crypto.subtle.exportKey("jwk",n.publicKey),e=await crypto.subtle.exportKey("jwk",n.privateKey);return{keys:{signingKey:n.privateKey,publicKeyJwk:r},dpopKeyPair:{publicKey:r,privateKey:e}}}async function b(n){return{signingKey:await crypto.subtle.importKey("jwk",n.privateKey,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),publicKeyJwk:n.publicKey}}async function x(n,r,e,t,o){let a={alg:"ES256",typ:"dpop+jwt",jwk:{kty:n.publicKeyJwk.kty,crv:n.publicKeyJwk.crv,x:n.publicKeyJwk.x,y:n.publicKeyJwk.y}},s={jti:crypto.randomUUID(),htm:r.toUpperCase(),htu:e,iat:Math.floor(Date.now()/1e3)};return t&&(s.ath=await sr(t)),o&&(s.nonce=o),await or(a,s,n.signingKey)}function S(n){return!n||n.length===0?!1:n.some(r=>r.toUpperCase()==="ES256")}async function or(n,r,e){let t=A(JSON.stringify(n)),o=A(JSON.stringify(r)),a=new TextEncoder().encode(`${t}.${o}`),s=await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,a),l=B(s);return`${t}.${o}.${l}`}async function sr(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return B(e)}function A(n){let r=new TextEncoder().encode(n);return B(r.buffer)}function B(n){let r=new Uint8Array(n),e="";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var ir=300*1e3,R=class{credentialBackend;callbackUrl;constructor(r){this.credentialBackend=new f,this.callbackUrl=r??`${window.location.origin}/browser/callback.html`}async authorize(r){let e=d(r),t=await this.discover(e);if(!t)return{success:!1,error:`No OAuth discovery endpoint found for '${e}'.`};if(!t.authorizationEndpoint||!t.tokenEndpoint)return{success:!1,error:`OAuth metadata incomplete for '${e}'.`};let o=S(t.dpopSigningAlgValuesSupported),a=null,s=null;if(o){let g=await K();a=g.keys,s=g.dpopKeyPair}let l=await this.credentialBackend.get(e),i=l?.clientId??null,c=l?.clientSecret??null;if(!i&&t.registrationEndpoint){let g=await this.registerClient(t.registrationEndpoint);if(!g)return{success:!1,error:`Dynamic client registration failed for '${e}'.`};i=g.clientId,c=g.clientSecret??null}if(!i)return{success:!1,error:`No OAuth client credentials for '${e}'.`};let m=ar(),p=await cr(m),D=lr(),T=ur(t.authorizationEndpoint,i,this.callbackUrl,D,p),y=await this.openAuthPopup(T,D);if(!y)return{success:!1,error:"Authorization timed out or was cancelled."};if(y.error)return{success:!1,error:`Authorization failed: ${y.error}`};if(!y.code)return{success:!1,error:"No authorization code received."};if(y.state!==D)return{success:!1,error:"State mismatch \u2014 possible CSRF attack."};let P=await this.exchangeCode(t.tokenEndpoint,i,c,y.code,this.callbackUrl,m,a);if(!P)return{success:!1,error:"Token exchange failed."};let O={clientId:i,clientSecret:c,accessToken:P.accessToken??null,refreshToken:P.refreshToken??null,expiresAt:P.expiresIn?new Date(Date.now()+P.expiresIn*1e3).toISOString():null,tokenEndpoint:t.tokenEndpoint,dpopKeyPair:s};return await this.credentialBackend.store(e,O),{success:!0,host:e}}async getCredentialWithKeys(r){let e=await this.credentialBackend.get(r);if(!e)return null;let t=null;return e.dpopKeyPair&&(t=await b(e.dpopKeyPair)),{credential:e,dpopKeys:t}}async logout(r){let e=d(r);return await this.credentialBackend.remove(e),{success:!0,host:e}}async listAuthenticated(){return this.credentialBackend.list()}async discover(r){for(let e of[`https://${r}/.well-known/oauth-authorization-server`,`https://${r}/.well-known/openid-configuration`])try{let t=await w(e);if(!t.ok)continue;let o=await t.json();return{issuer:k(o.issuer),authorizationEndpoint:k(o.authorization_endpoint),tokenEndpoint:k(o.token_endpoint),registrationEndpoint:k(o.registration_endpoint),revocationEndpoint:k(o.revocation_endpoint),dpopSigningAlgValuesSupported:I(o.dpop_signing_alg_values_supported),codeChallengeMethodsSupported:I(o.code_challenge_methods_supported)}}catch{continue}return null}async registerClient(r){try{let e=await w(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_name:"Kanonak Browser",redirect_uris:[this.callbackUrl],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"none"})});if(!e.ok)return null;let t=await e.json(),o=t.client_id;return o?{clientId:o,clientSecret:t.client_secret}:null}catch{return null}}openAuthPopup(r,e){return new Promise(t=>{let o=window.open(r,"kanonak-auth","width=500,height=700,menubar=no,toolbar=no,location=yes,status=no");if(!o){t(null);return}let a=setTimeout(()=>{i(),t(null)},ir),s=c=>{c.origin===window.location.origin&&(!c.data||c.data.type!=="kanonak-auth-callback"||(i(),t({code:c.data.code??void 0,state:c.data.state??void 0,error:c.data.error??void 0})))},l=setInterval(()=>{o.closed&&(i(),t(null))},500),i=()=>{clearTimeout(a),clearInterval(l),window.removeEventListener("message",s);try{o.close()}catch{}};window.addEventListener("message",s)})}async exchangeCode(r,e,t,o,a,s,l){let i=new URLSearchParams({grant_type:"authorization_code",client_id:e,code:o,redirect_uri:a,code_verifier:s});t&&i.set("client_secret",t);let c={"Content-Type":"application/x-www-form-urlencoded"};l&&(c.DPoP=await x(l,"POST",r));try{let m=await w(r,{method:"POST",headers:c,body:i.toString()});if(!m.ok)return null;let p=await m.json();return{accessToken:p.access_token,refreshToken:p.refresh_token,expiresIn:typeof p.expires_in=="number"?p.expires_in:void 0}}catch{return null}}};function ar(){let n=new Uint8Array(32);return crypto.getRandomValues(n),C(n.buffer)}async function cr(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return C(e)}function lr(){let n=new Uint8Array(16);return crypto.getRandomValues(n),C(n.buffer)}function ur(n,r,e,t,o){let a=new URLSearchParams({client_id:r,response_type:"code",redirect_uri:e,state:t,code_challenge:o,code_challenge_method:"S256"});return`${n}?${a}`}function C(n){let r=new Uint8Array(n),e="";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function k(n){return typeof n=="string"?n:null}function I(n){return Array.isArray(n)?n.filter(r=>typeof r=="string"):null}export{Le as AmbiguousReferenceRule,le as BooleanStatement,f as BrowserCredentialBackend,R as BrowserOAuthFlow,Ye as ClassDefinitionRule,Ve as ClassHierarchyCycleRule,ee as DefinedKanonak,He as DefinitionPropertyReferenceRule,ke as EdgeType,te as EmbeddedKanonak,Ie as EmbeddedKanonakTypeRule,de as EmbeddedStatement,he as GraphBuilder,Y as HttpKanonakDocumentRepository,Te as ImportExistenceRule,q as InMemoryKanonakDocumentRepository,Je as InstancePropertyReferenceRule,F as KANONAK_USER_AGENT,Z as Kanonak,be as KanonakDocumentPositions,me as KanonakObjectParser,er as KanonakObjectValidator,L as KanonakParser,ne as KanonakUri,Se as KanonakUriBuilder,pe as ListStatement,Ze as MarkdownLinkRule,ye as MarkdownStatement,ze as NamespaceImportCycleRule,_e as NamespacePrefixRule,we as NodeType,ce as NumberStatement,We as ObjectPropertyImportRule,Ge as ObjectPropertyValueValidationRule,Ce as OntologyValidationError,De as OntologyValidationResult,Xe as PropertyDomainRule,Ue as PropertyHierarchyCycleRule,Ke as PropertyMetadata,Fe as PropertyRangeReferenceRule,$e as PropertyRangeRequiredRule,Ae as PropertyTypeSpecificityRule,Qe as PropertyValueTypeRule,X as PublisherConfigResolver,Q as PublisherIndex,oe as ReferenceKanonak,ue as ReferenceStatement,je as ResourceNamingRule,ge as ResourceResolver,Pe as ResourceTypeClassifier,ie as ScalarStatement,se as Statement,ae as StringStatement,Me as SubClassOfReferenceRule,Ne as SubPropertyOfReferenceRule,re as SubjectKanonak,ve as SubjectKanonakTypeRequiredRule,fe as TypeResolver,Oe as UnresolvedReferenceRule,Ee as ValidationContext,Be as ValidationSeverity,qe as XsdImportRule,S as browserServerSupportsDPoP,tr as buildOntologyModel,V as compareVersions,x as createBrowserDPoPProof,M as createVersion,rr as findDerivation,Re as findInstancesByType,$ as formatVersion,K as generateBrowserDPoPKeyPair,v as generateBrowserDPoPKeys,G as getKanonakUserAgent,_ as hasValidToken,b as importDPoPKeys,z as isCompatibleVersion,E as isExpired,J as isMajorCompatible,w as kanonakFetch,d as normalizeHost,N as parseVersionString,xe as parseWithPositions,H as pickHighestDocument,W as setKanonakUserAgent,U as versionsEqual};
1
+ import{a as we,b as ke,c as he,d as E,e as _,f as d,g as tr}from"./chunk-WED776KZ.js";import{a as rr}from"./chunk-47RLRYV2.js";import"./chunk-QHABFCRC.js";import{a as F,b as W,c as G,d as w,f as X,g as Q,h as Y}from"./chunk-JYBKSBB5.js";import{a as q}from"./chunk-4NO7MHS7.js";import{a as Ke,b as be,c as xe}from"./chunk-MMJ7GO7J.js";import{a as Se,b as Re}from"./chunk-PEUTCG3B.js";import"./chunk-PEJALHXK.js";import"./chunk-SC5M74NM.js";import{A as Xe,B as Qe,C as Ye,D as Ze,M as er,a as De,b as Be,c as Ce,d as Ee,f as _e,g as je,h as ve,i as Ae,k as Te,l as Ie,m as Oe,n as Ue,o as Ve,p as $e,q as Me,r as Ne,s as ze,t as Je,u as He,v as qe,w as Le,x as Fe,y as We,z as Ge}from"./chunk-55DXTCGV.js";import"./chunk-SHDHMKMJ.js";import{a as te,c as ye,i as me}from"./chunk-MFNVQSBW.js";import{a as L}from"./chunk-NJ3AZYQD.js";import{a as Pe}from"./chunk-IEOSSSB5.js";import"./chunk-7TKJHKC2.js";import{b as ge,c as fe}from"./chunk-7HRKWTBB.js";import{a as Z,b as ee,c as re,d as oe,e as se,f as ie,g as ae,h as ce,i as le,j as ue,k as de,l as pe}from"./chunk-4UT2CLAT.js";import{a as ne}from"./chunk-FUUTGGJS.js";import{c as U,d as V,e as $,f as M,g as N,h as z,i as J,j as H}from"./chunk-2ACBWC7K.js";var j="kanonak-credentials",u="credentials",nr=1,f=class{async get(r){let e=d(r),t=await h();return new Promise((o,a)=>{let s=t.transaction(u,"readonly"),i=s.objectStore(u).get(e);i.onsuccess=()=>o(i.result??null),i.onerror=()=>a(new Error(`IndexedDB read failed for '${e}': ${i.error?.message}`)),s.oncomplete=()=>t.close()})}async store(r,e){let t=d(r),o=await h();return new Promise((a,s)=>{let l=o.transaction(u,"readwrite"),c=l.objectStore(u).put(e,t);c.onsuccess=()=>a(),c.onerror=()=>s(new Error(`IndexedDB write failed for '${t}': ${c.error?.message}`)),l.oncomplete=()=>o.close()})}async remove(r){let e=d(r),t=await h();return new Promise((o,a)=>{let s=t.transaction(u,"readwrite"),i=s.objectStore(u).delete(e);i.onsuccess=()=>o(),i.onerror=()=>a(new Error(`IndexedDB delete failed for '${e}': ${i.error?.message}`)),s.oncomplete=()=>t.close()})}async list(){let r=await h();return new Promise((e,t)=>{let o=r.transaction(u,"readonly"),s=o.objectStore(u).getAllKeys();s.onsuccess=()=>e(s.result??[]),s.onerror=()=>t(new Error(`IndexedDB list failed: ${s.error?.message}`)),o.oncomplete=()=>r.close()})}};function h(){return new Promise((n,r)=>{let e=indexedDB.open(j,nr);e.onupgradeneeded=()=>{let t=e.result;t.objectStoreNames.contains(u)||t.createObjectStore(u)},e.onsuccess=()=>n(e.result),e.onerror=()=>r(new Error(`Failed to open IndexedDB '${j}': ${e.error?.message}
2
+ Credential storage requires IndexedDB support in your browser.`))})}async function A(){let n=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),r=await crypto.subtle.exportKey("jwk",n.publicKey);return{signingKey:n.privateKey,publicKeyJwk:r}}async function K(){let n=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign"]),r=await crypto.subtle.exportKey("jwk",n.publicKey),e=await crypto.subtle.exportKey("jwk",n.privateKey);return{keys:{signingKey:n.privateKey,publicKeyJwk:r},dpopKeyPair:{publicKey:r,privateKey:e}}}async function b(n){return{signingKey:await crypto.subtle.importKey("jwk",n.privateKey,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),publicKeyJwk:n.publicKey}}async function x(n,r,e,t,o){let a={alg:"ES256",typ:"dpop+jwt",jwk:{kty:n.publicKeyJwk.kty,crv:n.publicKeyJwk.crv,x:n.publicKeyJwk.x,y:n.publicKeyJwk.y}},s={jti:crypto.randomUUID(),htm:r.toUpperCase(),htu:e,iat:Math.floor(Date.now()/1e3)};return t&&(s.ath=await sr(t)),o&&(s.nonce=o),await or(a,s,n.signingKey)}function S(n){return!n||n.length===0?!1:n.some(r=>r.toUpperCase()==="ES256")}async function or(n,r,e){let t=v(JSON.stringify(n)),o=v(JSON.stringify(r)),a=new TextEncoder().encode(`${t}.${o}`),s=await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,a),l=B(s);return`${t}.${o}.${l}`}async function sr(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return B(e)}function v(n){let r=new TextEncoder().encode(n);return B(r.buffer)}function B(n){let r=new Uint8Array(n),e="";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var ir=300*1e3,R=class{credentialBackend;callbackUrl;constructor(r){this.credentialBackend=new f,this.callbackUrl=r??`${window.location.origin}/browser/callback.html`}async authorize(r){let e=d(r),t=await this.discover(e);if(!t)return{success:!1,error:`No OAuth discovery endpoint found for '${e}'.`};if(!t.authorizationEndpoint||!t.tokenEndpoint)return{success:!1,error:`OAuth metadata incomplete for '${e}'.`};let o=S(t.dpopSigningAlgValuesSupported),a=null,s=null;if(o){let g=await K();a=g.keys,s=g.dpopKeyPair}let l=await this.credentialBackend.get(e),i=l?.clientId??null,c=l?.clientSecret??null;if(!i&&t.registrationEndpoint){let g=await this.registerClient(t.registrationEndpoint);if(!g)return{success:!1,error:`Dynamic client registration failed for '${e}'.`};i=g.clientId,c=g.clientSecret??null}if(!i)return{success:!1,error:`No OAuth client credentials for '${e}'.`};let m=ar(),p=await cr(m),D=lr(),I=ur(t.authorizationEndpoint,i,this.callbackUrl,D,p),y=await this.openAuthPopup(I,D);if(!y)return{success:!1,error:"Authorization timed out or was cancelled."};if(y.error)return{success:!1,error:`Authorization failed: ${y.error}`};if(!y.code)return{success:!1,error:"No authorization code received."};if(y.state!==D)return{success:!1,error:"State mismatch \u2014 possible CSRF attack."};let P=await this.exchangeCode(t.tokenEndpoint,i,c,y.code,this.callbackUrl,m,a);if(!P)return{success:!1,error:"Token exchange failed."};let O={clientId:i,clientSecret:c,accessToken:P.accessToken??null,refreshToken:P.refreshToken??null,expiresAt:P.expiresIn?new Date(Date.now()+P.expiresIn*1e3).toISOString():null,tokenEndpoint:t.tokenEndpoint,dpopKeyPair:s};return await this.credentialBackend.store(e,O),{success:!0,host:e}}async getCredentialWithKeys(r){let e=await this.credentialBackend.get(r);if(!e)return null;let t=null;return e.dpopKeyPair&&(t=await b(e.dpopKeyPair)),{credential:e,dpopKeys:t}}async logout(r){let e=d(r);return await this.credentialBackend.remove(e),{success:!0,host:e}}async listAuthenticated(){return this.credentialBackend.list()}async discover(r){for(let e of[`https://${r}/.well-known/oauth-authorization-server`,`https://${r}/.well-known/openid-configuration`])try{let t=await w(e);if(!t.ok)continue;let o=await t.json();return{issuer:k(o.issuer),authorizationEndpoint:k(o.authorization_endpoint),tokenEndpoint:k(o.token_endpoint),registrationEndpoint:k(o.registration_endpoint),revocationEndpoint:k(o.revocation_endpoint),dpopSigningAlgValuesSupported:T(o.dpop_signing_alg_values_supported),codeChallengeMethodsSupported:T(o.code_challenge_methods_supported)}}catch{continue}return null}async registerClient(r){try{let e=await w(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_name:"Kanonak Browser",redirect_uris:[this.callbackUrl],grant_types:["authorization_code","refresh_token"],response_types:["code"],token_endpoint_auth_method:"none"})});if(!e.ok)return null;let t=await e.json(),o=t.client_id;return o?{clientId:o,clientSecret:t.client_secret}:null}catch{return null}}openAuthPopup(r,e){return new Promise(t=>{let o=window.open(r,"kanonak-auth","width=500,height=700,menubar=no,toolbar=no,location=yes,status=no");if(!o){t(null);return}let a=setTimeout(()=>{i(),t(null)},ir),s=c=>{c.origin===window.location.origin&&(!c.data||c.data.type!=="kanonak-auth-callback"||(i(),t({code:c.data.code??void 0,state:c.data.state??void 0,error:c.data.error??void 0})))},l=setInterval(()=>{o.closed&&(i(),t(null))},500),i=()=>{clearTimeout(a),clearInterval(l),window.removeEventListener("message",s);try{o.close()}catch{}};window.addEventListener("message",s)})}async exchangeCode(r,e,t,o,a,s,l){let i=new URLSearchParams({grant_type:"authorization_code",client_id:e,code:o,redirect_uri:a,code_verifier:s});t&&i.set("client_secret",t);let c={"Content-Type":"application/x-www-form-urlencoded"};l&&(c.DPoP=await x(l,"POST",r));try{let m=await w(r,{method:"POST",headers:c,body:i.toString()});if(!m.ok)return null;let p=await m.json();return{accessToken:p.access_token,refreshToken:p.refresh_token,expiresIn:typeof p.expires_in=="number"?p.expires_in:void 0}}catch{return null}}};function ar(){let n=new Uint8Array(32);return crypto.getRandomValues(n),C(n.buffer)}async function cr(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return C(e)}function lr(){let n=new Uint8Array(16);return crypto.getRandomValues(n),C(n.buffer)}function ur(n,r,e,t,o){let a=new URLSearchParams({client_id:r,response_type:"code",redirect_uri:e,state:t,code_challenge:o,code_challenge_method:"S256"});return`${n}?${a}`}function C(n){let r=new Uint8Array(n),e="";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function k(n){return typeof n=="string"?n:null}function T(n){return Array.isArray(n)?n.filter(r=>typeof r=="string"):null}export{Le as AmbiguousReferenceRule,le as BooleanStatement,f as BrowserCredentialBackend,R as BrowserOAuthFlow,Ye as ClassDefinitionRule,Ue as ClassHierarchyCycleRule,ee as DefinedKanonak,He as DefinitionPropertyReferenceRule,ke as EdgeType,te as EmbeddedKanonak,Te as EmbeddedKanonakTypeRule,de as EmbeddedStatement,he as GraphBuilder,Y as HttpKanonakDocumentRepository,Ie as ImportExistenceRule,q as InMemoryKanonakDocumentRepository,F as KANONAK_USER_AGENT,Z as Kanonak,be as KanonakDocumentPositions,me as KanonakObjectParser,er as KanonakObjectValidator,L as KanonakParser,ne as KanonakUri,Se as KanonakUriBuilder,pe as ListStatement,Ze as MarkdownLinkRule,ye as MarkdownStatement,ze as NamespaceImportCycleRule,_e as NamespacePrefixRule,we as NodeType,ce as NumberStatement,We as ObjectPropertyImportRule,Ge as ObjectPropertyValueValidationRule,Ce as OntologyValidationError,De as OntologyValidationResult,Xe as PropertyDomainRule,Ve as PropertyHierarchyCycleRule,Ke as PropertyMetadata,Fe as PropertyRangeReferenceRule,$e as PropertyRangeRequiredRule,ve as PropertyTypeSpecificityRule,Qe as PropertyValueTypeRule,X as PublisherConfigResolver,Q as PublisherIndex,oe as ReferenceKanonak,ue as ReferenceStatement,je as ResourceNamingRule,ge as ResourceResolver,Pe as ResourceTypeClassifier,ie as ScalarStatement,se as Statement,ae as StringStatement,Me as SubClassOfReferenceRule,Ne as SubPropertyOfReferenceRule,re as SubjectKanonak,Ae as SubjectKanonakTypeRequiredRule,fe as TypeResolver,Je as UnresolvedPredicateRule,Oe as UnresolvedReferenceRule,Ee as ValidationContext,Be as ValidationSeverity,qe as XsdImportRule,S as browserServerSupportsDPoP,tr as buildOntologyModel,U as compareVersions,x as createBrowserDPoPProof,M as createVersion,rr as findDerivation,Re as findInstancesByType,$ as formatVersion,K as generateBrowserDPoPKeyPair,A as generateBrowserDPoPKeys,G as getKanonakUserAgent,_ as hasValidToken,b as importDPoPKeys,z as isCompatibleVersion,E as isExpired,J as isMajorCompatible,w as kanonakFetch,d as normalizeHost,N as parseVersionString,xe as parseWithPositions,H as pickHighestDocument,W as setKanonakUserAgent,V as versionsEqual};
@@ -1 +1 @@
1
- import{a as D}from"./chunk-DSHPAWJQ.js";import{c as j,d as m,g as R,j as p,k as K,l as k}from"./chunk-T3JR2SV6.js";import{c as b,g as u}from"./chunk-2ACBWC7K.js";function F(a,e,n,t){let i=g(a);if(i.length>0){let s=v(i,e,n);return s?{transformation:s.transformation,source:"instance"}:void 0}let r=new Set,o=O(a);for(;o.length>0;){let s=o.shift(),f=_(s.subject);if(r.has(f))continue;r.add(f);let l=S(t,s.subject);if(l.length===0)continue;let U=l.flatMap(g),h=v(U,e,n);if(h)return{transformation:h.transformation,source:{publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name}};for(let T of l)for(let P of $(T))o.push(P)}let c={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!r.has(_(c))){let s=S(t,c).flatMap(g),f=v(s,e,n);if(f)return{transformation:f.transformation,source:c}}}function g(a){let e=[];for(let n of a.statement)if(n instanceof k&&d(n,"kanonak.org","derivation","derivations"))for(let t of n.object??[]){if(!(t instanceof D))continue;let i=x(t);i&&e.push(i)}return e}function v(a,e,n){let t=a.filter(o=>E(o.format,e)&&E(o.variant,n));if(t.length<=1)return t[0];let i=t[0].transformation,r=t[0];for(let o of t){let c=o.transformation;if(c.publisher!==i.publisher||c.package_!==i.package_||c.name!==i.name)continue;let s=u(r.transformation.version),f=u(c.version);s&&f&&b(f,s)>0&&(r=o)}return r}function x(a){let e,n,t;for(let i of a.statement)i instanceof p?d(i,"kanonak.org","derivation","format")?e=y(i):d(i,"kanonak.org","derivation","variant")&&(n=y(i)):i instanceof K&&d(i,"kanonak.org","derivation","transformation")&&(t=C(i.object));if(!(!e||!t))return n||(n={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:e,variant:n,transformation:t}}function C(a){let e,n,t,i;for(let r of a.statement){if(!(r instanceof R))continue;let o=r.predicate?.subject?.name;o==="publisher"?e=r.object:o==="package"?n=r.object:o==="version"?t=r.object:o==="name"&&(i=r.object)}if(!(!e||!n||!t||!i))return{publisher:e,package_:n,version:t,name:i}}function O(a){let e=[];for(let n of a.statement)n instanceof p&&n.predicate?.subject?.name==="type"&&n.object instanceof m&&e.push(n.object);return e}function $(a){let e=[];for(let n of a.statement)if(n instanceof p){if(n.predicate?.subject?.name!=="subClassOf")continue;n.object instanceof m&&e.push(n.object)}else if(n instanceof k){if(n.predicate?.subject?.name!=="subClassOf")continue;for(let t of n.object??[])t instanceof m&&e.push(t)}return e}function S(a,e){let n=[];for(let t of a){if(!(t instanceof j)||t.name!==e.name)continue;(t.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&n.push(t)}return n.sort((t,i)=>{let r=u((t.namespace||"").split("@")[1]??""),o=u((i.namespace||"").split("@")[1]??"");return!r||!o?0:b(o,r)}),n}function d(a,e,n,t){let i=a.predicate?.subject;return i?i.publisher===e&&i.package_===n&&i.name===t:!1}function y(a){let e=a.object.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}function E(a,e){return a.publisher===e.publisher&&a.package_===e.package_&&a.name===e.name}function _(a){return`${a.publisher}/${a.package_}/${a.name}`}export{F as a};
1
+ import{a as D}from"./chunk-MFNVQSBW.js";import{c as j,d as m,g as R,j as p,k as K,l as k}from"./chunk-4UT2CLAT.js";import{c as b,g as u}from"./chunk-2ACBWC7K.js";function F(a,e,n,t){let i=g(a);if(i.length>0){let s=v(i,e,n);return s?{transformation:s.transformation,source:"instance"}:void 0}let r=new Set,o=O(a);for(;o.length>0;){let s=o.shift(),f=_(s.subject);if(r.has(f))continue;r.add(f);let l=S(t,s.subject);if(l.length===0)continue;let U=l.flatMap(g),h=v(U,e,n);if(h)return{transformation:h.transformation,source:{publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name}};for(let T of l)for(let P of $(T))o.push(P)}let c={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!r.has(_(c))){let s=S(t,c).flatMap(g),f=v(s,e,n);if(f)return{transformation:f.transformation,source:c}}}function g(a){let e=[];for(let n of a.statement)if(n instanceof k&&d(n,"kanonak.org","derivation","derivations"))for(let t of n.object??[]){if(!(t instanceof D))continue;let i=x(t);i&&e.push(i)}return e}function v(a,e,n){let t=a.filter(o=>E(o.format,e)&&E(o.variant,n));if(t.length<=1)return t[0];let i=t[0].transformation,r=t[0];for(let o of t){let c=o.transformation;if(c.publisher!==i.publisher||c.package_!==i.package_||c.name!==i.name)continue;let s=u(r.transformation.version),f=u(c.version);s&&f&&b(f,s)>0&&(r=o)}return r}function x(a){let e,n,t;for(let i of a.statement)i instanceof p?d(i,"kanonak.org","derivation","format")?e=y(i):d(i,"kanonak.org","derivation","variant")&&(n=y(i)):i instanceof K&&d(i,"kanonak.org","derivation","transformation")&&(t=C(i.object));if(!(!e||!t))return n||(n={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:e,variant:n,transformation:t}}function C(a){let e,n,t,i;for(let r of a.statement){if(!(r instanceof R))continue;let o=r.predicate?.subject?.name;o==="publisher"?e=r.object:o==="package"?n=r.object:o==="version"?t=r.object:o==="name"&&(i=r.object)}if(!(!e||!n||!t||!i))return{publisher:e,package_:n,version:t,name:i}}function O(a){let e=[];for(let n of a.statement)n instanceof p&&n.predicate?.subject?.name==="type"&&n.object instanceof m&&e.push(n.object);return e}function $(a){let e=[];for(let n of a.statement)if(n instanceof p){if(n.predicate?.subject?.name!=="subClassOf")continue;n.object instanceof m&&e.push(n.object)}else if(n instanceof k){if(n.predicate?.subject?.name!=="subClassOf")continue;for(let t of n.object??[])t instanceof m&&e.push(t)}return e}function S(a,e){let n=[];for(let t of a){if(!(t instanceof j)||t.name!==e.name)continue;(t.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&n.push(t)}return n.sort((t,i)=>{let r=u((t.namespace||"").split("@")[1]??""),o=u((i.namespace||"").split("@")[1]??"");return!r||!o?0:b(o,r)}),n}function d(a,e,n,t){let i=a.predicate?.subject;return i?i.publisher===e&&i.package_===n&&i.name===t:!1}function y(a){let e=a.object.subject;return{publisher:e.publisher,package_:e.package_,name:e.name}}function E(a,e){return a.publisher===e.publisher&&a.package_===e.package_&&a.name===e.name}function _(a){return`${a.publisher}/${a.package_}/${a.name}`}export{F as a};
@@ -0,0 +1 @@
1
+ import{a as p}from"./chunk-FUUTGGJS.js";var m=class{};var c=class extends m{statement=[];unresolvedPredicates=[]};var i=class extends c{namespace;name;icon};var a=class e extends m{subject;static parse(o){let n=new e;return n.subject=p.parse(o),n}};var r=class{predicate;object};var s=class extends r{carrier;lexical};var d=class e extends s{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=n,t}};var f=class e extends s{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=n,t}};var k=class extends s{};var l=class e extends r{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=a.parse(n),t}};var x=class extends r{};var b=class extends r{};export{m as a,c as b,i as c,a as d,r as e,s as f,d as g,f as h,k as i,l as j,x as k,b as l};
@@ -0,0 +1,86 @@
1
+ import{d as _}from"./chunk-SHDHMKMJ.js";import{a as I,b as Ne,c as Qe,g as tt,i as E}from"./chunk-MFNVQSBW.js";import{a as Ye}from"./chunk-NJ3AZYQD.js";import{a as B,d as W,e as nt,f as ot,g as x,h as rt}from"./chunk-IEOSSSB5.js";import{a as C,d as A,f as T,h as xe,i as w,j as L,k as V,l as O,m as S,n as M}from"./chunk-7TKJHKC2.js";import{a as N,b as U,c as et}from"./chunk-7HRKWTBB.js";import{c as D,d as H,k as Ze,l as Je}from"./chunk-4UT2CLAT.js";import{a as Ge}from"./chunk-FUUTGGJS.js";import{e as P}from"./chunk-2ACBWC7K.js";var q=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var b=(t=>(t.Warning="Warning",t.Error="Error",t))(b||{});var g=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 Le=class m{resolvedDocuments=[];currentEntityPath;withPath(e){let t=new m;return t.resolvedDocuments=this.resolvedDocuments,t.currentEntityPath=e,t}};var Se=class{constructor(e){this.underlying=e;this.repository=new We(e)}underlying;repository;kanonaksPromise=null;importClosureCache=new Map;classDeclarationsCache=new Map;propertyNamesCache=new Map;allDocumentsPromise=null;getKanonaks(){return this.kanonaksPromise||(this.kanonaksPromise=new E().parseKanonaks(this.underlying)),this.kanonaksPromise}async getImportClosure(e){let t=this.importClosureCache.get(e);return t||(t=this.computeImportClosure(e),this.importClosureCache.set(e,t),t)}async getClassDeclarations(e){let t=this.classDeclarationsCache.get(e);return t||(t=this.computeClassDeclarations(e),this.classDeclarationsCache.set(e,t),t)}async getPropertyNames(e){let t=this.propertyNamesCache.get(e);return t||(t=this.computePropertyNames(e),this.propertyNamesCache.set(e,t),t)}getAllDocuments(){return this.allDocumentsPromise||(this.allDocumentsPromise=this.underlying.getAllDocumentsAsync()),this.allDocumentsPromise}async computeImportClosure(e){let t=new Set([e]),n=[e],o=await this.buildDocsByIdIndex();for(;n.length>0;){let a=n.shift(),r=o.get(a);if(r?.metadata.imports)for(let[i,s]of Object.entries(r.metadata.imports))for(let c of s){let p=await this.repository.getHighestCompatibleVersionAsync(i,c);if(!p)continue;let l=Me(p);!l||t.has(l)||(t.add(l),n.push(l))}}return t}async buildDocsByIdIndex(){let e=await this.getAllDocuments(),t=new Map;for(let n of e){let o=Me(n);o&&t.set(o,n)}return t}async computeClassDeclarations(e){let t=await this.findDocById(e),n=new Map;if(!t)return n;for(let[o,a]of Object.entries(t.body)){if(!it(a))continue;let r=a,i=at(r,"type");if(i==="Class"||i?.endsWith(".Class")){let s=Rt(r);n.set(o,s)}}return n}async computePropertyNames(e){let t=await this.findDocById(e),n=new Set;if(!t)return n;for(let[o,a]of Object.entries(t.body)){if(!it(a))continue;let i=at(a,"type");(i==="ObjectProperty"||i?.endsWith(".ObjectProperty")||i==="DatatypeProperty"||i?.endsWith(".DatatypeProperty")||i==="AnnotationProperty"||i?.endsWith(".AnnotationProperty")||i==="Property"||i?.endsWith(".Property"))&&n.add(o)}return n}async findDocById(e){let t=await this.getAllDocuments();for(let n of t)if(Me(n)===e)return n}};function Me(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}function it(m){return typeof m=="object"&&m!==null&&!Array.isArray(m)}function at(m,e){if(e in m)return st(m[e]);for(let t of Object.keys(m))if(t.endsWith(`.${e}`))return st(m[t])}function st(m){return Array.isArray(m)?m.length>0?String(m[0]):void 0:m==null?void 0:String(m)}function Rt(m){let e=m.subClassOf;if(e===void 0){for(let t of Object.keys(m))if(t.endsWith(".subClassOf")){e=m[t];break}}return N(e)}var We=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 n=`${e}/${t}`,o=this.byNamespaceCache.get(n);return o||(o=this.inner.getDocumentsByNamespaceAsync(e,t),this.byNamespaceCache.set(n,o),o)}getHighestCompatibleVersionAsync(e,t){let n=t.version,o=n?`${n.major}.${n.minor}.${n.patch}`:"",a=`${e}/${t.packageName}@${t.versionOperator}:${o}`,r=this.highestVersionCache.get(a);return r||(r=this.inner.getHighestCompatibleVersionAsync(e,t),this.highestVersionCache.set(a,r),r)}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)}};var z=class m{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[n,o]of Object.entries(e.body))o&&typeof o=="object"&&!Array.isArray(o)&&this.validateEntity(n,o,t);return t}validateEntity(e,t,n){for(let[o,a]of Object.entries(t)){let r=a?.toString()??"";if(r&&m.NAMESPACE_PREFIX_PATTERN.test(r)){let i=this.getSuggestionForPrefixedValue(r),s=e.split(".")[0],c=new g;c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue=o,c.expectedValue=i,c.message=`Invalid namespace prefix '${r}'. Use '${i}' without prefix.`,c.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",n.push(c)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validateEntity(`${e}.${o}`,a,n)}}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 n=e.indexOf(":");return n>=0?e.substring(n+1):e}};var Y=class m{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=[],n=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[o,a]of Object.entries(e.body)){let r=m.VALID_AUGMENTATION_PATTERN.test(o);if(!r&&!n&&m.RESERVED_WORDS.has(o.toLowerCase())){let i=new g;i.ruleType=this.ruleName,i.severity="Error",i.entityName=o,i.message=`Entity name '${o}' 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(!r&&!m.VALID_NAME_PATTERN.test(o)){let i;/^\d/.test(o)?i="Entity names must start with a letter, not a number.":o.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 g;s.ruleType=this.ruleName,s.severity="Error",s.entityName=o,s.message=`Invalid entity name '${o}'. ${i}`,s.suggestion=i,t.push(s)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validatePropertyNames(o,a,t)}return t}validatePropertyNames(e,t,n){for(let o of Object.keys(t))if(!m.VALID_PROPERTIES.has(o)&&!m.VALID_PROPERTY_NAME_PATTERN.test(o)){let a=new g;a.ruleType=this.ruleName,a.severity="Warning",a.entityName=e,a.propertyName=o,a.message=`Property name '${o}' in entity '${e}' doesn't follow naming conventions.`,a.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",n.push(a)}}};var G=class m{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 n=this.isPropertyDefinedAsClass(e);for(let[o,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let r=a,i=r.type;if(i){let s=[];if(Array.isArray(i))for(let c of i){let p=c?.toString();p&&p==="Property"&&!n&&s.push(p)}else{let c=i?.toString();c&&c==="Property"&&!n&&s.push(c)}for(let c of s){let p=this.getPropertyValue(r,"range"),l=this.determinePropertyType(p),u=new g;u.ruleType=this.ruleName,u.severity="Error",u.entityName=o,u.propertyName="type",u.actualValue=c,u.expectedValue=l,u.message=`Invalid property type '${c}'. Use '${l}' instead.`,u.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",t.push(u)}}}return t}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":m.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,t){let n=e[t];return n?n.toString():null}isPropertyDefinedAsClass(e){let t=e.body.Property;if(t&&typeof t=="object"&&!Array.isArray(t)){let o=t.type;if(o){let a=o.toString();return a==="Class"||a.endsWith(".Class")}}return!1}};var Z=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let t=[];for(let[n,o]of Object.entries(e.body)){if(typeof o!="object"||o===null||Array.isArray(o)||n.includes("."))continue;let a=o,r="type"in a,i=a.type?.toString().trim();if(!r||!i){let s=new g;s.ruleType=this.ruleName,s.severity="Error",s.entityName=n,s.propertyName="type",s.message=`Subject Kanonak '${n}' 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 vt=new Set(["EphemeralPackage"]),J=class{get ruleName(){return"PackageHeader"}validate(e){let t=e.metadata;if(!t.type_)return[];let n=[],o=this.packageKey(e,t.type_);return t.namespace_?(!vt.has(t.type_)&&!t.namespace_.version&&n.push(this.error(o,"version",`Package resource '${o}' requires a 'version' property \u2014 packages are addressed by name@version.`,`Add a version, e.g.:
5
+ version: 1.0.0`)),n):(n.push(this.error(o,"publisher",`Package resource '${o}' requires a 'publisher' property.`,`Add a publisher, e.g.:
6
+ publisher: example.org`)),n)}packageKey(e,t){for(let[n,o]of Object.entries(e.body))if(o&&typeof o=="object"&&!Array.isArray(o)&&o.type===t)return n;return t}error(e,t,n,o){let a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=t,a.message=n,a.suggestion=o,a}};var Q=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,t){let n=[],o=new U(t),a=await this.buildPropertyRangeMap(e,o);for(let[r,i]of Object.entries(e.body))typeof i=="object"&&i!==null&&!Array.isArray(i)&&await this.checkEmbeddedTypes(r,i,void 0,a,o,e,n,0);return n}pickRange(e,t,n){if(e.length===0)return;if(e.length===1)return e[0].range;let o=t.indexOf(".");if(o>0){let a=t.substring(0,o),r=e.find(i=>i.declaringAlias===a);if(r)return r.range}if(n){let a=this.localName(n),r=e.find(i=>this.localName(i.domain)===a);if(r)return r.range}return e[0].range}async checkEmbeddedTypes(e,t,n,o,a,r,i,s){if(s>0){let p=t.type;if(p!=null){let l=await this.validateEmbeddedType(e,String(p),n,a,r);l&&i.push(l)}}let c=t.type!==void 0&&t.type!==null?String(t.type):void 0;for(let[p,l]of Object.entries(t)){let u=this.localName(p),y=o.get(u),d=(y!==void 0?this.pickRange(y,p,c):void 0)??n;if(typeof l=="object"&&l!==null)if(Array.isArray(l))for(let k=0;k<l.length;k++){let h=l[k];typeof h=="object"&&h!==null&&!Array.isArray(h)&&await this.checkEmbeddedTypes(`${e}.${p}[${k}]`,h,d,o,a,r,i,s+1)}else await this.checkEmbeddedTypes(`${e}.${p}`,l,d,o,a,r,i,s+1)}}async validateEmbeddedType(e,t,n,o,a){if(t.length===0||!n)return null;let r=this.localName(t),i=this.localName(n);if(i==="Resource"||i==="Class")return null;let s=e.split(".")[0];if(r===i){let p=new g;return p.ruleType=this.ruleName,p.severity="Warning",p.entityName=s,p.propertyName=e,p.actualValue=t,p.expectedValue=n,p.message=`Embedded object at '${e}' declares 'type: ${t}', which equals the parent property's range '${n}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,p.suggestion=`Remove the 'type: ${t}' line, or keep it if explicitness is preferred over concision.`,p}if(await o.isSubclassOfAsync(t,n,a)||(r!==t||i!==n)&&await o.isSubclassOfAsync(r,i,a))return null;let c=new g;return c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue=t,c.expectedValue=n,c.message=`Embedded object at '${e}' has 'type: ${t}', which is not a subclass of the parent property's range '${n}'.`,c.suggestion=`Either remove the 'type: ${t}' line (so the type is inferred from the property's range '${n}'), or add 'subClassOf: ${n}' to the '${t}' class definition so the relationship holds.`,c}localName(e){let t=e.lastIndexOf(".");return t<0||t===e.length-1?e:e.substring(t+1)}async buildPropertyRangeMap(e,t){let n=new Map,o=await t.buildEntityIndexAsync(e),a=new Map;for(let[r,i]of o){let s=i.entity.type;if(s==null)continue;let c=String(s),p=this.localName(c);if(!(p==="Property"||p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"))continue;let u=i.entity.range;if(u==null)continue;let y=String(u);if(y.length===0)continue;let f=i.entity.domain,d=f!=null?String(f):"",k=i.uri.toString(),h=a.get(k),v=r.includes(".");(!h||v&&!h.entityName.includes("."))&&a.set(k,{entityName:r,domain:d,range:y})}for(let r of a.values()){let i=this.localName(r.entityName),s=r.entityName.indexOf("."),c=s>0?r.entityName.substring(0,s):void 0,p=n.get(i)??[];p.push({domain:r.domain,range:r.range,declaringAlias:c}),n.set(i,p)}return n}};import{VersionOperator as Te}from"@kanonak-protocol/types/document/models/enums";var ee=class{ruleName="ImportExistence";async validateAsync(e,t){let n=[];if(!e.metadata?.imports)return n;let o=await t.getAllDocumentsAsync();for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r)if(!await t.getHighestCompatibleVersionAsync(a,i)){let c=await this.determineImportErrorAsync(t,a,i,o),p=new g;p.ruleType=this.ruleName,p.severity="Error",p.message=c.message,p.suggestion=c.suggestion,p.entityName=`Import: ${a}/${i.packageName}`,p.actualValue=i.toString(),p.expectedValue=c.expectedValue,n.push(p)}return n}async determineImportErrorAsync(e,t,n,o){let a=await e.getDocumentsByNamespaceAsync(t,n.packageName);if(a.length===0){let c=o.filter(y=>y.metadata.namespace_?.publisher===t).map(y=>y.metadata.namespace_.package_).filter((y,f,d)=>d.indexOf(y)===f),p=this.findSimilarPackages(n.packageName,c),l=`Import '${t}/${n.package_}' not found - package does not exist`,u=p.length>0?`Did you mean: ${p.slice(0,3).join(", ")}?`:c.length>0?`Available packages in ${t}: ${c.slice(0,5).join(", ")}`:`No packages found for publisher '${t}'. Verify the publisher name is correct.`;return{message:l,suggestion:u,expectedValue:"Existing package"}}let i=a.filter(c=>c.metadata.namespace_?.version).map(c=>c.metadata.namespace_.version.toString()).sort().join(", "),s=this.getAcceptableVersionRange(n);return{message:`Import '${t}/${n.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${i}. Required: ${s}`,expectedValue:s}}getAcceptableVersionRange(e){switch(e.versionOperator){case Te.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Te.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Te.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Te.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 n=t.filter(r=>r.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(r.toLowerCase()));if(n.length>0)return n.sort((r,i)=>r.length-i.length);let o=t.map(r=>({package:r,distance:this.levenshteinDistance(e.toLowerCase(),r.toLowerCase())})).sort((r,i)=>r.distance-i.distance),a=Math.max(3,Math.floor(e.length*.4));return o.filter(r=>r.distance<=a).map(r=>r.package)}levenshteinDistance(e,t){if(!e||e.length===0)return t?.length??0;if(!t||t.length===0)return e.length;let n=e.length,o=t.length,a=Array(n+1).fill(null).map(()=>Array(o+1).fill(0));for(let r=0;r<=n;r++)a[r][0]=r;for(let r=0;r<=o;r++)a[0][r]=r;for(let r=1;r<=n;r++)for(let i=1;i<=o;i++){let s=e[r-1]===t[i-1]?0:1;a[r][i]=Math.min(Math.min(a[r-1][i]+1,a[r][i-1]+1),a[r-1][i-1]+s)}return a[n][o]}};var te=class{ruleName="UnresolvedReference";async validateAsync(e,t){let n=[],o=new U(t),a=await o.buildEntityIndexAsync(e),r=new Set;for(let[i,s]of a.entries()){let c=s.entity.type;if(c){let p=c.toString();(p==="ObjectProperty"||p.endsWith(".ObjectProperty"))&&r.add(i)}}for(let[i,s]of Object.entries(e.body)){if(!s||typeof s!="object"||Array.isArray(s))continue;let c=s,p=this.getPropertyValue(c,"type");if(!(!p||p==="Class"||p.endsWith("Property")||p==="AnnotationProperty"))for(let[l,u]of Object.entries(c))l==="type"||l==="label"||l==="comment"||!(r.has(l)||Array.from(r).some(f=>f.endsWith(`.${l}`)))||await this.validateReferenceValue(i,l,u,e,o,n)}return n}async validateReferenceValue(e,t,n,o,a,r){if(n!=null){if(typeof n=="string")await a.resolveEntityAsync(n,o)||r.push(this.createUnresolvedReferenceError(e,t,n));else if(Array.isArray(n))for(let i=0;i<n.length;i++){let s=n[i];typeof s=="string"&&(await a.resolveEntityAsync(s,o)||r.push(this.createUnresolvedReferenceError(e,`${t}[${i}]`,s)))}}}createUnresolvedReferenceError(e,t,n){let o=`The entity '${n}' cannot be found in the current document or any imported namespaces.
7
+
8
+ Possible solutions:
9
+ \u2022 Add import if the entity is defined in another namespace:
10
+ kanonak namespace add-import <publisher>/<package>@<version>
11
+ \u2022 Check for typos in the reference name '${n}'
12
+ \u2022 Define '${n}' in the current namespace or an appropriate namespace
13
+ \u2022 Use 'kanonak search type ${n} --include-imports' to locate the entity`,a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=t,a.actualValue=n,a.message=`Reference to '${n}' could not be resolved`,a.suggestion=o,a.expectedValue="A valid entity reference that exists in the current document or imported namespaces",a}getPropertyValue(e,t){let n=e[t];return n?n.toString():null}};var ne=class{ruleName="ClassHierarchyCycle";async validateAsync(e,t){let n=[],o=new Map,a=new Set;await this.buildClassHierarchy(e,t,o,a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type,p=s.subClassOf;if(c?.toString()==="Class"&&p){let l=r,u=this.detectCycle(l,o);if(u){let y=u.join(" \u2192 "),f=new g;f.ruleType=this.ruleName,f.severity="Error",f.message=`Circular class hierarchy detected: ${y}`,f.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",f.entityName=l,f.propertyName="subClassOf",f.actualValue=y,n.push(f);break}}}return n}async buildClassHierarchy(e,t,n,o){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&o.has(a))){a&&o.add(a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type,p=s.subClassOf;if(c?.toString()==="Class"&&p){let l=N(p);l.length>0&&n.set(r,l)}}if(e.metadata?.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);c&&await this.buildClassHierarchy(c,t,n,o)}}}detectCycle(e,t){let n=[],o=new Set;return this.detectCycleRecursive(e,t,n,o)}detectCycleRecursive(e,t,n,o){if(n.includes(e)){let r=n.indexOf(e),i=n.slice(r);return i.push(e),i}if(o.has(e))return null;n.push(e),o.add(e);let a=t.get(e);if(a)for(let r of a){let i=this.detectCycleRecursive(r,t,n,o);if(i)return i}return n.pop(),null}};var oe=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,t){let n=[],o=new Map,a=new Set;await this.buildPropertyHierarchy(e,t,o,a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)&&i.subPropertyOf){let p=r,l=this.detectCycle(p,o);if(l){let u=l.join(" \u2192 "),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Circular property hierarchy detected: ${u}`,y.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",y.entityName=p,y.propertyName="subPropertyOf",y.actualValue=u,n.push(y);break}}return n}async buildPropertyHierarchy(e,t,n,o){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&o.has(a))){a&&o.add(a);for(let[r,i]of Object.entries(e.body))if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i,c=s.type;if(c){let p=c.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"){let l=s.subPropertyOf;if(l){let u=N(l);u.length>0&&n.set(r,u)}}}}if(e.metadata?.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);c&&await this.buildPropertyHierarchy(c,t,n,o)}}}detectCycle(e,t){let n=[],o=new Set;return this.detectCycleRecursive(e,t,n,o)}detectCycleRecursive(e,t,n,o){if(n.includes(e)){let r=n.indexOf(e),i=n.slice(r);return i.push(e),i}if(o.has(e))return null;n.push(e),o.add(e);let a=t.get(e);if(a)for(let r of a){let i=this.detectCycleRecursive(r,t,n,o);if(i)return i}return n.pop(),null}};var re=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,t){let n=[];for(let[o,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let r=a,i=r.type?.toString();if(i==="DatatypeProperty"||i==="ObjectProperty"||i?.endsWith(".DatatypeProperty")||i?.endsWith(".ObjectProperty")){let s="range"in r,c=r.range?.toString().trim();if(!s||!c){let p=new g;p.ruleType=this.ruleName,p.severity="Error",p.entityName=o,p.propertyName="range",p.message=`Property '${o}' must have a 'range' defined.`,p.suggestion=i==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",p.expectedValue=i==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",n.push(p)}}}return n}};var ie=class{builtInClasses=new Set(["Resource","Class","Datatype","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}isClassLikeType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}async validateAsync(e,t){let n=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isClassLikeType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=N(r.subClassOf);for(let c=0;c<s.length;c++){let p=s[c];if(this.builtInClasses.has(p)||o.has(p))continue;if(!await this.isClassAvailableInImports(e,t,p)){let u=s.length>1?`[${c}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Class '${p}' referenced in subClassOf${u} is not defined or imported`,y.suggestion=`Define '${p}' as a Class, or import a namespace that contains it`,y.entityName=a,y.propertyName="subClassOf",y.actualValue=p,y.expectedValue="Defined or imported class",n.push(y)}}}return n}async isClassAvailableInImports(e,t,n){if(!e.metadata.imports)return!1;let o=null,a=n;if(n.includes(".")){let r=n.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:n,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(this.isClassLikeType(f))return!0}let u=new Set;if(await this.isClassAvailableInImportsRecursive(c,t,p,u))return!0}}return!1}async isClassAvailableInImportsRecursive(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[n];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isClassLikeType(u))return!0}if(await this.isClassAvailableInImportsRecursive(c,t,n,o))return!0}}return!1}};var ae=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,t){let n=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();(s==="DatatypeProperty"||s==="ObjectProperty"||s==="AnnotationProperty")&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=N(r.subPropertyOf);for(let c=0;c<s.length;c++){let p=s[c];if(this.builtInProperties.has(p)||o.has(p))continue;if(!await this.isPropertyAvailableInImports(e,t,p)){let u=s.length>1?`[${c}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Property '${p}' referenced in subPropertyOf${u} is not defined or imported`,y.suggestion=`Define '${p}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,y.entityName=a,y.propertyName="subPropertyOf",y.actualValue=p,y.expectedValue="Defined or imported property",n.push(y)}}}return n}async isPropertyAvailableInImports(e,t,n){if(!e.metadata.imports)return!1;let o=null,a=n;if(n.includes(".")){let r=n.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:n,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(f==="DatatypeProperty"||f==="ObjectProperty"||f==="AnnotationProperty")return!0}let u=new Set;if(await this.isPropertyAvailableInImportsRecursive(c,t,p,u))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[n];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(c,t,n,o))return!0}}return!1}};var se=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,t){let n=[],o=e.metadata.namespace_?.toString();if(!o)return n;let a=new Map,r=new Set;await this.buildImportGraph(e,t,a,r);let i=this.detectCycle(o,a);if(i){let s=i.join(" \u2192 "),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=`Circular namespace import detected: ${s}`,c.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",c.entityName="imports",c.propertyName="imports",c.actualValue=s,n.push(c)}return n}async buildImportGraph(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(!(!a||o.has(a))&&(o.add(a),e.metadata.imports)){let r=[];for(let[i,s]of Object.entries(e.metadata.imports))for(let c of s){let p=`${i}/${c.packageName}@${c.version}`;r.push(p);let l=await t.getHighestCompatibleVersionAsync(i,c);l&&await this.buildImportGraph(l,t,n,o)}r.length>0&&n.set(a,r)}}detectCycle(e,t){let n=[],o=new Set;return this.detectCycleRecursive(e,t,n,o)}detectCycleRecursive(e,t,n,o){let a=n.indexOf(e);if(a>=0){let i=n.slice(a);return i.push(e),i}if(o.has(e))return null;n.push(e),o.add(e);let r=t.get(e);if(r)for(let i of r){let s=this.detectCycleRecursive(i,t,n,o);if(s)return s}return n.pop(),null}};async function Be(m,e,t){return t?t.getKanonaks():new E().parseKanonaks(new M(m,e))}async function pt(m,e,t){let n=await Be(m,e,t),o=Fe(m);return o?n.filter(a=>a instanceof D&&a.namespace===o):[]}function _e(m,e){for(let t of m)t instanceof D&&He(t,t.name,e)}function He(m,e,t){t({kanonak:m,path:e});for(let n of m.statement)if(n instanceof Ze)He(n.object,ct(e,n.object),t);else if(n instanceof Je)for(let o of n.object)o instanceof I&&He(o,ct(e,o),t)}function ct(m,e){let t=e instanceof I&&e.name?e.name:"<embedded>";return`${m}/${t}`}function Fe(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var ce=class{ruleName="UnresolvedPredicate";async validateAsync(e,t,n){let o=[],a=Fe(e);if(!a)return o;let r=await Be(e,t,n);return _e(r,({kanonak:i,path:s})=>{for(let c of i.unresolvedPredicates)c.sourceDoc===a&&o.push(this.unresolvedPredicateError(s,c.key))}),o}unresolvedPredicateError(e,t){let n=t.lastIndexOf("."),o=n>0?t.slice(0,n):null,a=n>0?t.slice(n+1):t,r=new g;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.actualValue=t,r.expectedValue="A defined or imported property",r.message=`Property '${t}' is not defined or imported`,r.suggestion=o?`The property '${a}' was not found in the namespace imported as '${o}'.
14
+ 1. Check '${a}' is spelled correctly
15
+ 2. Verify '${o}' is imported with the right alias and version
16
+ 3. Ensure that namespace version actually defines '${a}'`:`The property '${t}' is not defined in this namespace or any imported namespace.
17
+ 1. Define '${t}' as an ObjectProperty or DatatypeProperty here, OR
18
+ 2. Import the namespace that defines it, OR
19
+ 3. Alias-qualify it if it lives in an imported namespace ('alias.${t}')`,r}};var pe=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,t){let n=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isPropertyType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=i.type?.toString();if(!this.isPropertyType(s)&&!this.isClassType(s))continue;for(let[c,p]of Object.entries(i)){if(!c||this.metadataKeys.has(c))continue;let l=c,u=null;if(c.includes(".")){let f=c.lastIndexOf(".");u=c.substring(0,f),l=c.substring(f+1)}if(o.has(l))continue;if(!await this.isPropertyAvailableInImports(e,t,l,u)){let f=this.isClassType(s)?"class":"property",d=new g;d.ruleType=this.ruleName,d.severity="Error",d.message=`Property '${c}' used on ${f} '${a}' is not defined or imported`,d.suggestion=u?`The property '${l}' is not found in the imported namespace with alias '${u}'.
20
+ 1. Verify the namespace is imported with the correct alias
21
+ 2. Check if the property name is spelled correctly
22
+ 3. Ensure the imported namespace version contains this property`:`The property '${c}' is not defined in this namespace or any imported namespace.
23
+ 1. Define '${c}' as an ObjectProperty or DatatypeProperty in this namespace, OR
24
+ 2. Import the namespace that contains '${c}', OR
25
+ 3. Use a qualified reference like 'alias.${c}' if already imported with an alias`,d.entityName=a,d.propertyName=c,d.actualValue=p?.toString(),d.expectedValue="A defined or imported property",n.push(d)}}}return n}isPropertyType(e){return e?e==="ObjectProperty"||e==="DatatypeProperty"||e==="AnnotationProperty"||e==="Property"||e.endsWith(".ObjectProperty")||e.endsWith(".DatatypeProperty")||e.endsWith(".AnnotationProperty")||e.endsWith(".Property"):!1}isClassType(e){return e?e==="Class"||e.endsWith(".Class"):!1}async isPropertyAvailableInImports(e,t,n,o){if(!e.metadata.imports)return!1;for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r){if(o!==null&&i.alias!==o)continue;let s=await t.getHighestCompatibleVersionAsync(a,i);if(s){let c=s.body[n];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(this.isPropertyType(u))return!0}let p=new Set;if(await this.isPropertyAvailableInImportsRecursive(s,t,n,p))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[n];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isPropertyType(u))return!0}if(await this.isPropertyAvailableInImportsRecursive(c,t,n,o))return!0}}return!1}};var le=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"XsdImport"}async validateAsync(e,t){let n=[],o=new Set,a=[];for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let s=i,c=!1,p=s.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="DatatypeProperty"){c=!0;break}}else p?.toString()==="DatatypeProperty"&&(c=!0);if(c){a.push(r);let l=this.getPropertyValue(s,"range");l&&this.xsdTypes.has(l)&&o.add(l)}}if(o.size>0&&!await this.checkXsdImportAsync(e.metadata,t)){let i=Array.from(o).sort().join(", "),s=a.sort().join(", "),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=`XSD namespace not imported but XSD types are used: ${i}`,c.suggestion=`Add an XSD import to the imports section. The core XSD types package is 'core-xsd' from publisher 'kanonak.org'. Used by properties: ${s}`,c.entityName="imports",n.push(c)}return n}async checkXsdImportAsync(e,t,n=new Set){if(!e?.imports)return!1;let o=e.namespace_?.toString()??"";if(o&&n.has(o))return!1;o&&n.add(o);for(let[,a]of Object.entries(e.imports))for(let r of a)if(r.packageName==="xsd"||r.packageName.toLowerCase().endsWith("-xsd"))return!0;for(let[a,r]of Object.entries(e.imports))for(let i of r){let s=await t.getHighestCompatibleVersionAsync(a,i);if(s?.metadata&&await this.checkXsdImportAsync(s.metadata,t,n))return!0}return!1}getPropertyValue(e,t){return e[t]?.toString()}};var me=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,t){let n=[],{entitySources:o,importPaths:a}=await this.buildEntitySourceMapAsync(e,t),r=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,o,a,r,e,n);return n}async buildEntitySourceMapAsync(e,t){let n=new Map,o=new Set,a=new Map;for(let r of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";n.has(r)||n.set(r,[]),n.get(r).push(`(local:${i})`)}if(e.metadata.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(c,n,o,a,[p],t)}}return{entitySources:n,importPaths:a}}async collectEntitiesRecursivelyAsync(e,t,n,o,a,r){let i=e.metadata.namespace_?.toString()??"";if(!n.has(i)){n.add(i),o.has(i)||o.set(i,a);for(let s of Object.keys(e.body)){t.has(s)||t.set(s,[]);let c=t.get(s);c.includes(i)||c.push(i)}if(e.metadata.imports)for(let[s,c]of Object.entries(e.metadata.imports))for(let p of c){let l=await r.getHighestCompatibleVersionAsync(s,p);if(l){let u=l.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(l,t,n,o,[...a,u],r)}}}}async buildDatatypePropertyNamesAsync(e,t){let n=new Set,o=new Set;if(await this.collectDatatypePropertiesAsync(e,n,o,t),e.metadata.imports)for(let[a,r]of Object.entries(e.metadata.imports))for(let i of r){let s=await t.getHighestCompatibleVersionAsync(a,i);s&&await this.collectDatatypePropertiesAsync(s,n,o,t)}return n}async collectDatatypePropertiesAsync(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(!n.has(a)){n.add(a);for(let[r,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(r)}if(e.metadata.imports)for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await o.getHighestCompatibleVersionAsync(r,s);c&&await this.collectDatatypePropertiesAsync(c,t,n,o)}}}validateEntityReferences(e,t,n,o,a,r,i){for(let[s,c]of Object.entries(t)){let p=s;if(p&&!p.includes(".")){let l=n.get(p);if(l&&l.length>1&&!l.some(y=>y.startsWith("(local:"))){let y=l.filter(f=>!f.startsWith("(local:"));y.length>1&&i.push(this.createAmbiguityError(e,p,`Property '${p}'`,y,o,r,!0,p))}}this.validatePropertyValue(e,p,c,n,o,a,r,i)}}validatePropertyValue(e,t,n,o,a,r,i,s){if(n==null)return;let c=t&&t.includes(".")?t.substring(t.lastIndexOf(".")+1):t,p=!!c&&r.has(c);if(typeof n=="string"&&!n.includes(".")&&!p){let l=o.get(n);if(l&&l.length>1&&!l.some(y=>y.startsWith("(local:"))){let y=l.filter(f=>!f.startsWith("(local:"));y.length>1&&s.push(this.createAmbiguityError(e,t,`Reference '${n}'`,y,a,i,!1,n))}}else if(Array.isArray(n))for(let l=0;l<n.length;l++){let u=`${e}.${t}[${l}]`;this.validatePropertyValue(u,t,n[l],o,a,r,i,s)}else if(typeof n=="object"&&!Array.isArray(n)){let l=t?`${e}.${t}`:e;this.validateEntityReferences(l,n,o,a,r,i,s)}}createAmbiguityError(e,t,n,o,a,r,i,s){let c=[];for(let k of o){let h=this.findAliasForNamespace(r,k);if(h){let v=t?.split(".").pop()??t;c.push(`${h}.${v}`)}}let p=c.length>0?`Use one of: ${c.map(k=>`'${k}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${t}')`,l=o.map(k=>{let h=a.get(k);return!h||h.length===0?` \u2022 ${k}`:h.length===1?` \u2022 ${k} (direct import)`:` \u2022 ${k}
26
+ imported via: ${h.join(" \u2192 ")}`}).join(`
27
+ `),u=e.split(".")[0],y=e.includes(".")?e:t,f=new g;f.ruleType=this.ruleName,f.severity="Error",f.entityName=u,y&&(f.propertyName=y);let d=s??t;return d&&(f.actualValue=d),f.message=`${n} is ambiguous - defined in multiple imported namespaces`,f.suggestion=`${p}
28
+
29
+ Defined in:
30
+ ${l}`,f.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",f}findAliasForNamespace(e,t){if(!e.metadata.imports)return null;for(let[n,o]of Object.entries(e.metadata.imports))for(let a of o)if(`${n}/${a.packageName}@${a.version}`===t&&a.alias)return a.alias;return null}};var ye=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]);primitiveTypes=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","Literal","Resource"]);get ruleName(){return"PropertyRangeReference"}async validateAsync(e,t){let n=[],o=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=r.type?.toString();this.isValidRangeTargetType(s)&&o.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=i.type?.toString();if(s!=="DatatypeProperty"&&s!=="ObjectProperty"&&!s?.endsWith(".DatatypeProperty")&&!s?.endsWith(".ObjectProperty"))continue;let c=i.range;if(!c)continue;let p=[];if(Array.isArray(c))for(let l of c){let u=l?.toString();u&&p.push(u)}else{let l=c?.toString();l&&p.push(l)}if(p.length===0)continue;for(let l of p){if(this.primitiveTypes.has(l)||this.builtInClasses.has(l)||o.has(l))continue;if(!await this.isTypeAvailableInImports(e,t,l)){let y=s?.includes("ObjectProperty")?"ObjectProperty":"DatatypeProperty",f=new g;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${a}' has range '${l}' which is not defined or imported`,f.suggestion=y==="ObjectProperty"?`For ObjectProperty:
31
+ 1. Define '${l}' as a Class in this namespace, OR
32
+ 2. Import the namespace that contains '${l}', OR
33
+ 3. Use a qualified reference like 'alias.${l}' if already imported with an alias`:`For DatatypeProperty:
34
+ 1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
35
+ 2. If '${l}' should be a class, change property type to ObjectProperty`,f.entityName=a,f.propertyName="range",f.actualValue=l,f.expectedValue=y==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",n.push(f)}}}return n}async isTypeAvailableInImports(e,t,n){if(!e.metadata.imports)return!1;let o=null,a=n;if(n.includes(".")){let r=n.split(".",2);o=r[0],a=r[1]}for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){if(o!==null&&s.alias!==o)continue;let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=o!==null?a:n,l=c.body[p];if(l&&typeof l=="object"&&!Array.isArray(l)){let f=l.type?.toString();if(this.isValidRangeTargetType(f))return!0}let u=new Set;if(await this.isTypeAvailableInImportsRecursive(c,t,p,u))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,t,n,o){let a=e.metadata.namespace_?.toString()??"";if(a&&o.has(a)||(a&&o.add(a),!e.metadata.imports))return!1;for(let[r,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await t.getHighestCompatibleVersionAsync(r,s);if(c){let p=c.body[n];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isValidRangeTargetType(u))return!0}if(await this.isTypeAvailableInImportsRecursive(c,t,n,o))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var ue=class{xsdTypes=new Set(["string","integer","boolean","decimal","float","double","date","dateTime","time","duration","anyURI","base64Binary","hexBinary","long","int","short","byte","unsignedLong","unsignedInt","unsignedShort","unsignedByte","positiveInteger","nonPositiveInteger","negativeInteger","nonNegativeInteger","normalizedString","token","language","Name","NCName","ENTITY","ENTITIES","IDREF","IDREFS","NMTOKEN","NMTOKENS"]);get ruleName(){return"ObjectPropertyImport"}async validateAsync(e,t){let n=[],o=new Map,a=new U(t);await a.buildEntityIndexAsync(e);for(let[r,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let s=i,c=!1,p=s.type;if(Array.isArray(p)){for(let l of p)if(l?.toString()==="ObjectProperty"){c=!0;break}}else p?.toString()==="ObjectProperty"&&(c=!0);if(c){let l=s.range,u=[];if(Array.isArray(l))for(let y of l){let f=y?.toString();f&&u.push(f)}else{let y=l?.toString();y&&u.push(y)}for(let y of u)this.xsdTypes.has(y)||(o.has(y)||o.set(y,[]),o.get(y).push(r))}}for(let[r,i]of o)if(!await a.resolveEntityAsync(r,e))for(let c of i){let p=new g;p.ruleType=this.ruleName,p.severity="Warning",p.message=`ObjectProperty references class '${r}' which may not be imported`,p.suggestion=`Ensure the namespace containing '${r}' is imported, or define '${r}' in this document`,p.entityName=c,p.propertyName="range",p.actualValue=r,n.push(p)}return n}};var fe=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,t){let n=[],o=new U(t),a=new et(o),r=await o.buildEntityIndexAsync(e),i=await this.buildPropertyMetadataAsync(e,t,o,r);for(let[s,c]of Object.entries(e.body))typeof c=="object"&&c!==null&&!Array.isArray(c)&&await this.scanEntityForObjectProperties(c,s,"",i,o,a,e,n);return n}async scanEntityForObjectProperties(e,t,n,o,a,r,i,s){for(let[c,p]of Object.entries(e)){if(this.standardProperties.has(c))continue;let l,u=await a.resolveEntityAsync(c,i);if(u?.uri){let y=`${u.uri.publisher}/${u.uri.package_}/${u.uri.name}`;l=o.get(y)}if(!l){let y=c,f=c.lastIndexOf(".");f>0&&f<c.length-1&&(y=c.substring(f+1)),l=o.get(y)}if(l&&r.isEffectiveObjectProperty(l.propertyType,l.rangeUri)){let f=n?`${n}.${c}`:c;if(typeof p=="string"&&p.trim().length>0){let d=p.trim();if(d.includes(",")){let h=d.split(",").map(v=>v.trim()).filter(v=>v.length>0);s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
36
+ ${c}:
37
+ - ${h[0]}
38
+ ${h.slice(1).map(v=>` - ${v}`).join(`
39
+ `)}`,entityName:t,propertyName:c,propertyPath:f,actualValue:d,expectedValue:`A single reference to ${l.range??"an entity"} OR a YAML list`});continue}let k=await a.resolveEntityAsync(d,i);if(k)l.range&&(await this.validateRangeType(k,l.range,a,i)||s.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${c}' expects a ${l.range}, but '${d}' may not be a ${l.range}`,suggestion:`Ensure '${d}' is defined with appropriate type`,entityName:t,propertyName:c,propertyPath:f,actualValue:d,expectedValue:l.range}));else{let h=l.range??"entity";s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' references '${d}' which is not defined or imported`,suggestion:`Define '${d}' or import a namespace that contains it. Expected range: ${h}`,entityName:t,propertyName:c,propertyPath:f,actualValue:d,expectedValue:"Defined or imported entity"})}}else if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let d=n?`${n}.${c}`:c;await this.scanEntityForObjectProperties(p,t,d,o,a,r,i,s)}else if(Array.isArray(p))for(let d=0;d<p.length;d++){let k=p[d];if(typeof k=="string"&&k.trim().length>0){let h=k.trim(),v=await a.resolveEntityAsync(h,i);if(v){if(l.range&&!await this.validateRangeType(v,l.range,a,i)){let je=n?`${n}.${c}[${d}]`:`${c}[${d}]`;s.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${c}' expects a ${l.range}, but '${h}' may not be a ${l.range}`,suggestion:`Ensure '${h}' is defined with appropriate type`,entityName:t,propertyName:`${c}[${d}]`,propertyPath:je,actualValue:h,expectedValue:l.range})}}else{let $=l.range??"entity",je=n?`${n}.${c}[${d}]`:`${c}[${d}]`;s.push({ruleType:this.ruleName,severity:"Error",message:`Property '${c}' references '${h}' which is not defined or imported`,suggestion:`Define '${h}' or import a namespace that contains it. Expected range: ${$}`,entityName:t,propertyName:`${c}[${d}]`,propertyPath:je,actualValue:h,expectedValue:"Defined or imported entity"})}}else if(typeof k=="object"&&k!==null&&!Array.isArray(k)){let h=n?`${n}.${c}[${d}]`:`${c}[${d}]`;await this.scanEntityForObjectProperties(k,t,h,o,a,r,i,s)}}}if(typeof p=="object"&&p!==null&&!Array.isArray(p)&&!o.has(c)){let y=n?`${n}.${c}`:c;await this.scanEntityForObjectProperties(p,t,y,o,a,r,i,s)}else if(Array.isArray(p))for(let y=0;y<p.length;y++){let f=p[y];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=n?`${n}.${c}[${y}]`:`${c}[${y}]`;await this.scanEntityForObjectProperties(f,t,d,o,a,r,i,s)}}}}async validateRangeType(e,t,n,o){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(t))return!0;let r=e.entity.type;if(r){let i=[];if(Array.isArray(r))for(let s of r){let c=s?.toString();c&&c.trim().length>0&&i.push(c)}else{let s=r?.toString();s&&s.trim().length>0&&i.push(s)}for(let s of i){let c=s.includes(".")?s.split(".")[1]:s;if(c===t||t==="Property"&&(c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty")||t==="Class"&&c==="Class"||await n.isSubclassOfAsync(s,t,o))return!0}}return!1}async buildPropertyMetadataAsync(e,t,n,o){let a=new Map;for(let[r,i]of o){let s=i.entity.type;if(s){let c=[];if(Array.isArray(s))for(let u of s){let y=u?.toString();y&&y.trim().length>0&&c.push(y)}else{let u=s?.toString();u&&u.trim().length>0&&c.push(u)}let p=!1,l="Property";for(let u of c){let y=u.includes(".")?u.split(".")[1]:u;if(y==="Property"||y==="DatatypeProperty"||y==="ObjectProperty"||y==="AnnotationProperty"){p=!0,l=u;break}}if(p){let u={propertyType:l},y=i.entity.range;if(y){let f=y?.toString();if(f&&f.trim().length>0){u.range=f;let d=await n.resolveEntityAsync(f,e);d&&(u.rangeUri=d.uri)}}if(a.set(r,u),i.uri){let f=`${i.uri.publisher}/${i.uri.package_}/${i.uri.name}`;a.set(f,u)}}}}return a}};var de=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,t,n){let o=[],a=new Map;for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=this.getPropertyValue(c,"type");(p==="DatatypeProperty"||p?.endsWith(".DatatypeProperty")||p==="ObjectProperty"||p?.endsWith(".ObjectProperty")||p==="AnnotationProperty"||p?.endsWith(".AnnotationProperty"))&&a.set(i,c)}let r=n?await this.buildClassHierarchyViaCache(e,n):await this.buildCompleteClassHierarchyAsync(e,t);for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=this.getPropertyValue(c,"type");if(!p||p==="Class"||p.endsWith(".Class")||p.endsWith("Property")||p==="AnnotationProperty")continue;this.validateEntityProperties(c,i,p,a,r,o)}return o}async buildClassHierarchyViaCache(e,t){let n=new Map,o=Vt(e);if(!o)return n;let a=await t.getImportClosure(o);for(let r of a){let i=await t.getClassDeclarations(r);for(let[s,c]of i)c.length>0&&n.set(s,c)}return n}async buildCompleteClassHierarchyAsync(e,t){let n=new Map,o=new Set,a=async(i,s)=>{if(!o.has(s)){o.add(s);for(let[c,p]of Object.entries(i.body))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let l=p,u=this.getPropertyValue(l,"type");if(u==="Class"||u?.endsWith(".Class")){let y=l.subClassOf;if(y===void 0){for(let d of Object.keys(l))if(d.endsWith(".subClassOf")){y=l[d];break}}let f=N(y);f.length>0&&n.set(c,f)}}if(i.metadata.imports)for(let[c,p]of Object.entries(i.metadata.imports))for(let l of p)try{let u=await t.getHighestCompatibleVersionAsync(c,l);if(u){let y=`${c}/${l.packageName}@${l.version}`;await a(u,y)}}catch{}}},r=e.metadata.namespace_?.toString()??"unknown";return await a(e,r),n}validateEntityProperties(e,t,n,o,a,r){for(let[i,s]of Object.entries(e)){if(this.standardProperties.has(i))continue;let c=i,p=i.lastIndexOf(".");p>0&&p<i.length-1&&(c=i.substring(p+1));let l=o.get(c);if(!l)continue;let u=this.getPropertyValue(l,"domain");if(u){if(!this.isTypeCompatibleWithDomain(n,u,a)){let y=t.split(".")[0];r.push({ruleType:this.ruleName,severity:"Error",entityName:y,propertyName:t,actualValue:i,message:`Property '${i}' has domain '${u}' but is used on '${n}' at '${t}'`,suggestion:`Either:
40
+ 1. Use this property only on '${u}' instances
41
+ 2. Change the property domain to include '${n}'
42
+ 3. Create a different property for '${n}'`,expectedValue:`Property used on ${u} or its subclasses`})}if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let y=s,f=this.getPropertyValue(y,"type");if(f){let d=`${t}.${i}`;this.validateEntityProperties(y,d,f,o,a,r)}else{let d=this.getPropertyValue(l,"range");if(d){let k=`${t}.${i}`;this.validateEntityProperties(y,k,d,o,a,r)}}}else if(Array.isArray(s))for(let y=0;y<s.length;y++){let f=s[y];if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let d=f,k=this.getPropertyValue(d,"type");if(k){let h=`${t}.${i}[${y}]`;this.validateEntityProperties(d,h,k,o,a,r)}else{let h=this.getPropertyValue(l,"range");if(h){let v=`${t}.${i}[${y}]`;this.validateEntityProperties(d,v,h,o,a,r)}}}}}}}isTypeCompatibleWithDomain(e,t,n){if(e===t)return!0;let o=new Set,a=[e];for(;a.length>0;){let r=a.shift();if(o.has(r))continue;o.add(r);let i=n.get(r);if(i)for(let s of i){if(s===t)return!0;a.push(s)}}return!1}getPropertyValue(e,t){if(t in e){let n=e[t];return this.extractFirstValue(n)}for(let n of Object.keys(e))if(n.endsWith(`.${t}`)){let o=e[n];return this.extractFirstValue(o)}}extractFirstValue(e){if(Array.isArray(e)){let t=[];for(let n of e)t.push(n?.toString()??"");return t.length>0?t[0]:void 0}return e?.toString()}};function Vt(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var ge=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,t){let n=[],o=new Map;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let i=r,s=this.getPropertyValue(i,"type");(s==="DatatypeProperty"||s==="ObjectProperty")&&o.set(a,i)}for(let[a,r]of Object.entries(e.body)){if(typeof r!="object"||r===null||Array.isArray(r))continue;let i=r,s=this.getPropertyValue(i,"type");if(!(!s||s==="Class"||s.endsWith("Property")||s==="AnnotationProperty"))for(let[c,p]of Object.entries(i)){if(c==="type"||c==="label"||c==="comment")continue;let l=c,u=c.lastIndexOf(".");u>0&&u<c.length-1&&(l=c.substring(u+1));let y=o.get(l);if(!y)continue;let f=this.getPropertyValue(y,"type"),d=this.getPropertyValue(y,"range");if(f==="DatatypeProperty"){if(typeof p=="object"&&p!==null&&!Array.isArray(p)||Array.isArray(p))n.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`Property '${c}' is a DatatypeProperty with range '${d}' but instance '${a}' has a complex object value`,suggestion:`Either:
43
+ 1. Create a class for this data and change '${c}' to an ObjectProperty
44
+ 2. Store as a JSON string to keep it as DatatypeProperty
45
+ 3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${d}'`});else if(!this.validateDatatypeValue(d,p)){let k={ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`Property '${c}' expects type '${d}' but instance '${a}' has value of type '${this.getValueTypeName(p)}'`,suggestion:`Provide a value of type '${d}'`,toString:()=>""};d&&(k.expectedValue=d),n.push(k)}}else if(f==="ObjectProperty")if(Array.isArray(p))for(let k=0;k<p.length;k++){let h=p[k];typeof h!="string"&&(typeof h!="object"||h===null||Array.isArray(h))&&n.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:`${c}[${k}]`,message:`ObjectProperty '${c}' array item ${k} in instance '${a}' has invalid type '${this.getValueTypeName(h)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof p!="string"&&(typeof p!="object"||p===null||Array.isArray(p))&&n.push({ruleType:this.ruleName,severity:"Error",entityName:a,propertyName:c,message:`ObjectProperty '${c}' in instance '${a}' has invalid value type '${this.getValueTypeName(p)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${d} or embedded ${d} object`})}}return n}validateDatatypeValue(e,t){switch(e?.toLowerCase()){case"string":return typeof t=="string";case"integer":case"int":return typeof t=="number"&&Number.isInteger(t);case"decimal":return typeof t=="number";case"boolean":return typeof t=="boolean";case"float":case"double":return typeof t=="number";default:return!0}}getValueTypeName(e){return typeof e=="string"?"string":typeof e=="number"?Number.isInteger(e)?"integer":"decimal":typeof e=="boolean"?"boolean":Array.isArray(e)?"array":typeof e=="object"&&e!==null?"object":e===null?"null":e===void 0?"undefined":typeof e}getPropertyValue(e,t){if(t in e){let n=e[t];if(Array.isArray(n)){let o=[];for(let a of n)o.push(a?.toString()??"");return o.length>0?o[0]:void 0}return n?.toString()}}};var he=class{builtInClasses=new Set(["Resource","Class","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty","Package"]);get ruleName(){return"ClassDefinition"}async validateAsync(e,t){let n=[],o=new Map,a=new Set;for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let p=s.type;if(p)if(Array.isArray(p))for(let l of p){let u=l?.toString();if(u==="Class"||u&&u.endsWith(".Class")){a.add(i);break}}else{let l=p?.toString();(l==="Class"||l&&l.endsWith(".Class"))&&a.add(i)}}for(let[i,s]of Object.entries(e.body))if(typeof s=="object"&&s!==null&&!Array.isArray(s)){let c=s,p=c.type;if(p)if(Array.isArray(p)){let l=!1;for(let u of p){let y=u?.toString();if(y&&this.isDefinitionType(y)){l=!0;break}}if(!l)for(let u of p){let y=u?.toString();y&&y.trim().length>0&&(o.has(y)||o.set(y,[]),o.get(y).push(i))}}else{let l=p?.toString();l&&l.trim().length>0&&(this.isDefinitionType(l)||(o.has(l)||o.set(l,[]),o.get(l).push(i)))}this.checkNestedTypes(c,i,o,i)}let r=new U(t);for(let[i,s]of o){if(this.builtInClasses.has(i)||a.has(i))continue;let c=await r.resolveEntityAsync(i,e);if(!(c&&this.isClassEntity(c.entity))){let l=Array.from(new Set(s)).sort();for(let u of l)n.push({ruleType:this.ruleName,severity:"Error",message:`Class '${i}' is not defined or imported`,suggestion:`Define '${i}' as a Class in this document, or import a namespace that contains it`,entityName:u,propertyName:"type",actualValue:i,expectedValue:"Defined or imported class"})}}return n}checkNestedTypes(e,t,n,o){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let a=e,r=a.type;if(r){let i=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(r))for(let s of r){let c=s?.toString();c&&c.trim().length>0&&!i.has(c)&&(n.has(c)||n.set(c,[]),n.get(c).push(o))}else{let s=r?.toString();s&&s.trim().length>0&&!i.has(s)&&(n.has(s)||n.set(s,[]),n.get(s).push(o))}}for(let[i,s]of Object.entries(a))if(i!=="type"){let c=`${o}.${i}`;this.checkNestedTypes(s,t,n,c)}}else if(Array.isArray(e))for(let a=0;a<e.length;a++){let r=`${o}[${a}]`;this.checkNestedTypes(e[a],t,n,r)}}isClassEntity(e){if(!e)return!1;let t=e.type;if(!t)return!1;if(Array.isArray(t))for(let n of t){let o=n?.toString();if(o==="Class"||o&&o.endsWith(".Class"))return!0}else{let n=t?.toString();if(n==="Class"||n&&n.endsWith(".Class"))return!0}return!1}isDefinitionType(e){return!e||e.trim().length===0?!1:new Set(["Class","Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(e)?!0:e.endsWith(".Class")||e.endsWith(".Property")||e.endsWith(".DatatypeProperty")||e.endsWith(".ObjectProperty")||e.endsWith(".AnnotationProperty")}};var ke=class{ruleName="MarkdownLink";async validateAsync(e,t,n){let o=[],a=await pt(e,t,n);return _e(a,({kanonak:r,path:i})=>{this.checkNode(r,i,o)}),o}checkNode(e,t,n){for(let o of e.statement){if(!(o instanceof Qe))continue;let a=o.predicate.subject?.name??"(unknown)";for(let r of o.links)r.target||n.push(this.unresolvedLinkError(t,a,r.reference));for(let r of tt(o.object))n.push(this.malformedLinkError(t,a,r.snippet))}}unresolvedLinkError(e,t,n){let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=t,o.actualValue=n,o.message=`Embedded link [[${n}]] in '${t}' could not be resolved`,o.expectedValue="A reference resolvable through the document's import closure",o.suggestion=`The reference '${n}' inside a markdown value cannot be found in the current document or any imported namespace.
46
+
47
+ Possible solutions:
48
+ \u2022 Import the package that defines '${n}' so the link can resolve
49
+ \u2022 Check for typos in the reference name
50
+ \u2022 If the name collides across imports, alias-qualify it: [[alias.${n}]]`,o}malformedLinkError(e,t,n){let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=t,o.actualValue=n,o.message=`Malformed embedded reference near '${n}' in '${t}'`,o.expectedValue="A single-line [[reference]] with no internal line break",o.suggestion=`A '[[' in '${t}' does not form a complete [[reference]] link.
51
+
52
+ A reference may not span a line break \u2014 the most common cause is wrapping a
53
+ long reference across two lines in a block scalar, e.g.:
54
+ ... read for [[persistent-energy-
55
+ shock]] held ...
56
+ which is parsed as literal text, not a link. Keep each [[reference]] on one
57
+ line (let the line run long), or check for an unterminated [[.`,o}};var lt="kanonak.org",mt="look",Pt={publisher:lt,package_:mt,name:"displayLabel"},Dt={publisher:lt,package_:mt,name:"displaySummary"},be=class{ruleName="DisplayLensScope";async validateAsync(e,t,n){let o=[],a;n?a=await n.getKanonaks():a=await new E().parseKanonaks(new M(e,t));let r=It(e);if(!r)return o;for(let i of a)i instanceof D&&i.namespace===r&&(this.checkLens(a,i,Pt,"displayLabel",o),this.checkLens(a,i,Dt,"displaySummary",o));return o}checkLens(e,t,n,o,a){let r=V(t,n);if(!r)return;let i=[],s=W(t);if(s&&i.push(s),i.push(...rt(t)),i.length===0)return;i.some(p=>x(e,p,r).ok)||a.push(this.scopeError(t.name,o,r.name))}scopeError(e,t,n){let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=e,o.propertyName=t,o.actualValue=n,o.message=`${t} points at '${n}', which is not a property in scope for '${e}'`,o.expectedValue="A property whose domain is this resource's class, an ancestor, or rdfs.Resource",o.suggestion=`'${n}' resolves, but its domain does not cover '${e}', so the lens would silently fall back to the resource's name at render time.
58
+
59
+ Possible solutions:
60
+ \u2022 Point ${t} at a property declared on this class (or an ancestor / rdfs.Resource)
61
+ \u2022 Set the property's domain to this class if it should apply here
62
+ \u2022 Use rdfs.label / rdfs.comment for the universal default`,o}};function It(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}function F(m,e,t){let n=[];return Ke(m,t,{input:e},n),n}function Ke(m,e,t,n){if(A(e,_.VarRef)){let r=L(e,_.varName);return r?t[r]:void 0}if(A(e,_.PropertyRead)){let r=O(e,_.readSource),i=r?Ke(m,r,t,n):void 0,s=V(e,_.readProp);if(!i||!s)return;let c=x(m,i,s);if(!c.ok){n.push({contextClass:i,propertyUri:s,via:"PropertyRead"});return}return c.descriptor?.range}if(A(e,_.Traverse)){let r=O(e,_.traverseSource),i=r?Ke(m,r,t,n):void 0,s=V(e,_.through),c;if(i&&s){let l=x(m,i,s);l.ok?c=l.descriptor?.range:n.push({contextClass:i,propertyUri:s,via:"Traverse"})}let p=O(e,_.step);return p?Ke(m,p,{...t,input:c},n):void 0}let o=L(e,_.loopVar),a=o?{...t,[o]:void 0}:t;for(let r of Et(e))Ke(m,r,a,n)}function Et(m){let e=[];for(let t of m.statement){let n=t.object;if(n instanceof I)e.push(n);else if(Array.isArray(n))for(let o of n)o instanceof I&&e.push(o)}return e}var $e="kanonak.org",Ce="look",At={publisher:$e,package_:Ce,name:"semanticSvg"},Ot={publisher:$e,package_:Ce,name:"tierChip"},St={publisher:$e,package_:Ce,name:"tierIcon"},Kt={publisher:$e,package_:Ce,name:"tierCard"},$t={publisher:$e,package_:Ce,name:"tierFull"},Ct=[Ot,St,Kt,$t],Re=class{ruleName="LookSemanticSvgPath";async validateAsync(e,t,n){let o=[],a;n?a=await n.getKanonaks():a=await new E().parseKanonaks(new M(e,t));let r=wt(e);if(!r)return o;for(let i of a)i instanceof D&&i.namespace===r&&this.checkSemanticSvg(a,i,o);return o}checkSemanticSvg(e,t,n){let o=O(t,At);if(!o)return;let a=W(t);if(a)for(let r of Ct){let i=O(o,r);if(i)for(let s of F(e,a,i))n.push(this.toError(t.name,r.name,s))}}toError(e,t,n){let o=`${n.propertyUri.publisher}/${n.propertyUri.package_}/${n.propertyUri.name}`,a=n.contextClass.name,r=a===e?`'${e}' (the class this SemanticSvg is declared on)`:`'${a}', reached by traversal from '${e}' (the class this SemanticSvg is declared on)`,i=new g;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=`look.semanticSvg.${t}`,i.actualValue=o,i.message=`tx.${n.via} reads property '${n.propertyUri.name}' off the rendered instance, but its domain is not in scope for ${r}. The read would silently return undefined at render time.`,i.expectedValue=`A property whose domain is '${a}', an ancestor, or rdfs.Resource`,i.suggestion=`Property '${o}' is not in scope for '${a}'.
63
+
64
+ Possible solutions:
65
+ \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
66
+ \u2022 If the property should apply to '${a}', adjust its domain
67
+ \u2022 If the value comes from a pre-computed env binding, use tx.VarRef instead of PropertyRead`,i}};function wt(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var jt="kanonak.org",R=(m,e)=>({publisher:jt,package_:m,name:e}),Nt=R("derivation","look"),xt=R("look","bands"),Tt=R("look","Distribution"),_t=R("look","StatRow"),Ut=R("look","VersionDelta"),Lt=R("look","Timeline"),Mt=R("look","VersionDiff"),Wt=R("look","TimePlot"),Ht=R("look","ReferenceList"),Bt=R("look","Diagram"),Ft=R("look","alphaPath"),Xt=R("look","betaPath"),Xe=R("look","metricPath"),yt=R("look","lowerPath"),ut=R("look","upperPath"),ft=R("look","hueBy"),qt=R("look","statPath"),zt=R("look","laneBy"),dt=R("look","labelPath"),Yt=R("look","badgePath"),Gt=R("look","mapPath"),Zt=R("look","nodeNote"),Jt=R("look","edgeValue"),Qt=R("look","stats"),en=R("look","facets"),tn=R("look","channels"),nn=R("look","track"),on=R("look","source"),rn=R("look","relation"),an=R("look","entries"),we=class{ruleName="LookBandPath";async validateAsync(e,t,n){let o=[],a;n?a=await n.getKanonaks():a=await new E().parseKanonaks(new M(e,t));let r=cn(e);if(!r)return o;for(let i of a)i instanceof D&&i.namespace===r&&this.checkDeclaration(a,i,o);return o}checkDeclaration(e,t,n){let o=O(t,Nt);if(!o)return;let a=W(t);if(!a)return;let r=S(o,xt).filter(i=>i instanceof I);for(let i of r)for(let s of this.carriersOf(e,i,a))for(let c of F(e,s.context,s.expr))n.push(this.toError(t.name,s.slot,c))}carriersOf(e,t,n){let o=[],a=(r,i)=>{let s=O(t,r);s&&o.push({slot:`look.${r.name}`,context:i,expr:s})};if(A(t,Tt))for(let r of[Ft,Xt,Xe,yt,ut,ft])a(r,n);if(A(t,Ut)&&a(Xe,n),A(t,_t)){let r=S(t,Qt).filter(i=>i instanceof I);for(let i of r){let s=O(i,qt);s&&o.push({slot:"look.stats[].statPath",context:n,expr:s})}}if(A(t,Lt)||A(t,Mt)){let r=this.rangeOf(e,n,V(t,nn));if(r)for(let i of[Xe,yt,ut,ft])a(i,r)}if(A(t,Wt)){let r=this.rangeOf(e,n,V(t,on));if(r)for(let i of[zt,dt])a(i,r)}if(A(t,Ht))for(let r of S(t,an)){let i=r instanceof I?void 0:sn(r),s=this.rangeOf(e,n,i);if(s)for(let c of[dt,Yt])a(c,s)}if(A(t,Bt)){let r=S(t,en).filter(i=>i instanceof I);for(let i of r){let s=this.rangeOf(e,n,V(i,rn));if(!s)continue;let c=O(i,Zt);c&&o.push({slot:"look.facets[].nodeNote",context:s,expr:c});let p=O(i,Jt);p&&o.push({slot:"look.facets[].edgeValue",context:s,expr:p});let l=S(i,tn).filter(u=>u instanceof I);for(let u of l){let y=O(u,Gt);y&&o.push({slot:"look.facets[].channels[].mapPath",context:s,expr:y})}}}return o}rangeOf(e,t,n){if(!n)return;let o=x(e,t,n);return o.ok?o.descriptor?.range:void 0}toError(e,t,n){let o=`${n.propertyUri.publisher}/${n.propertyUri.package_}/${n.propertyUri.name}`,a=n.contextClass.name,r=new g;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=t,r.actualValue=o,r.message=`tx.${n.via} reads property '${n.propertyUri.name}', but its domain is not in scope for '${a}' (the class this band carrier is evaluated against). The read would silently return undefined at render time and the band would render empty.`,r.expectedValue=`A property whose domain is '${a}', an ancestor, or rdfs.Resource`,r.suggestion=`Property '${o}' is not in scope for '${a}'.
68
+
69
+ Possible solutions:
70
+ \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
71
+ \u2022 If the property should apply to '${a}', adjust its domain
72
+ \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,r}};function sn(m){let e=m.subject;return e&&typeof e.name=="string"?e:void 0}function cn(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var Ve="kanonak.org",Pe="view",pn={publisher:Ve,package_:Pe,name:"bind"},ln={publisher:Ve,package_:Pe,name:"produces"},mn={publisher:Ve,package_:Pe,name:"projections"},yn={publisher:Ve,package_:Pe,name:"where"},un={publisher:Ve,package_:Pe,name:"value"},fn={publisher:Ve,package_:Pe,name:"as"},ve=class{ruleName="TxExpressionPath";async validateAsync(e,t,n){let o=[],a;n?a=await n.getKanonaks():a=await new E().parseKanonaks(new M(e,t));let r=hn(e);if(!r)return o;for(let i of a)i instanceof D&&i.namespace===r&&this.checkView(a,i,o);return o}checkView(e,t,n){let o=V(t,pn);if(!o)return;let a=V(t,ln),r=0;for(let s of gn(e,S(t,mn))){let c=O(s,un);if(c)for(let l of F(e,o,c))n.push(this.toError(t.name,`view.projections[${r}].value`,o,l));let p=V(s,fn);p&&a&&(x(e,a,p).ok||n.push(this.asError(t.name,r,a,p))),r+=1}let i=0;for(let s of dn(t,yn)){for(let c of F(e,o,s))n.push(this.toError(t.name,`view.where[${i}]`,o,c));i+=1}}asError(e,t,n,o){let a=`${o.publisher}/${o.package_}/${o.name}`,r=new g;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=`view.projections[${t}].as`,r.actualValue=a,r.message=`Projection stores its value under property '${o.name}', but that property's domain is not in scope for the view's produces class '${n.name}'. The materialized result instance could not carry this value.`,r.expectedValue=`A property whose domain is '${n.name}', an ancestor, or rdfs.Resource`,r.suggestion=`Property '${a}' is not in scope for produces class '${n.name}'.
73
+
74
+ Possible solutions:
75
+ \u2022 Use an output property whose domain covers '${n.name}'
76
+ \u2022 Define a new property in the ViewPackage with domain '${n.name}' and the right range
77
+ \u2022 If the value belongs on a different output class, adjust the view's produces`,r}toError(e,t,n,o){let a=`${o.propertyUri.publisher}/${o.propertyUri.package_}/${o.propertyUri.name}`,r=o.contextClass.name,i=r===n.name?`the view's bound class '${n.name}'`:`'${r}', reached by traversal from the view's bound class '${n.name}'`,s=new g;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=e,s.propertyName=t,s.actualValue=a,s.message=`tx.${o.via} reads property '${o.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 '${r}', an ancestor, or rdfs.Resource`,s.suggestion=`Property '${a}' is not in scope for '${r}'.
78
+
79
+ Possible solutions:
80
+ \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
81
+ \u2022 If the property should apply to '${r}', adjust its domain
82
+ \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,s}};function dn(m,e){let t=O(m,e);return t?[t]:S(m,e).filter(n=>n instanceof I)}function gn(m,e){let t=[];for(let n of e)if(n instanceof I)t.push(n);else if(n instanceof H){let o=T(m,n.subject);o&&t.push(o)}return t}function hn(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var Ue="kanonak.org",kn="core-shacl",K=m=>({publisher:Ue,package_:kn,name:m}),bn=K("NodeShape"),Rn=K("PropertyShape"),vn=K("targetClass"),Vn=K("property"),Pn=K("path"),Dn=K("minCount"),In=K("maxCount"),En=K("datatype"),An=K("class"),gt=K("in"),On=K("pattern"),Sn=K("flags"),Kn=K("minLength"),$n=K("maxLength"),Cn=K("minInclusive"),wn=K("maxInclusive"),jn=new Set(["decimal","integer","int","long","short","byte","float","double","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"]),qe=m=>m,Ie=class{ruleName="ShaclShape";async validateAsync(e,t,n){let o=[],a=n?await n.getKanonaks():await new E().parseKanonaks(t),r=Nn(e);if(!r)return o;let i=new Set;for(let s of a){if(!(s instanceof D)||s.namespace!==r||!A(s,bn))continue;let c=V(s,vn);c?this.resolvesToClass(a,c)||o.push(this.err(s.name,"targetClass","Error",`NodeShape '${s.name}' sh:targetClass '${c.name}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",X(c))):o.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 p of S(s,Vn)){let l;if(p instanceof I)l=p;else if(p instanceof H){let u=T(a,p.subject);u&&(l=u,i.add(C(p.subject)))}l&&this.checkPropertyShape(a,s.name,l,c??void 0,o)}}for(let s of a){if(!(s instanceof D)||s.namespace!==r||!A(s,Rn))continue;let c=W(s);c&&i.has(C(c))||this.checkPropertyShape(a,s.name,s,void 0,o)}return o}checkPropertyShape(e,t,n,o,a){let r=V(n,Pn);if(!r){a.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=T(e,r),s=i?B.isAnyPropertyType(qe(i)):!1;s?o&&(x(e,o,r).ok||a.push(this.err(t,"property.path","Warning",`sh:path '${r.name}' is not in scope for sh:targetClass '${o.name}'; the constraint would never bind a value.`,`Constrain a property whose domain is '${o.name}', an ancestor, or rdfs.Resource.`,X(r)))):a.push(this.err(t,"property.path","Error",`sh:path '${r.name}' on '${t}' does not resolve to a property.`,"Reference a defined or imported property.",X(r)));let c=V(n,En),p=V(n,An);c&&p&&a.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.")),c&&!this.resolvesToDatatype(e,c)&&a.push(this.err(t,"datatype","Error",`sh:datatype '${c.name}' on '${t}' does not resolve to a datatype.`,"Reference an xsd datatype or rdfs.Datatype.",X(c))),p&&!this.resolvesToClass(e,p)&&a.push(this.err(t,"class","Error",`sh:class '${p.name}' on '${t}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",X(p)));let l=De(w(n,Dn)),u=De(w(n,In));this.checkOrder(t,"minCount",l,"maxCount",u,a);let y=De(w(n,Kn)),f=De(w(n,$n));this.checkOrder(t,"minLength",y,"maxLength",f,a);let d=De(w(n,Cn)),k=De(w(n,wn));this.checkOrder(t,"minInclusive",d,"maxInclusive",k,a);let h=L(n,On);if(h!==void 0){let v=L(n,Sn);try{new RegExp(h,v)}catch{a.push(this.err(t,"pattern","Error",`sh:pattern on '${t}' is not a valid regular expression`+(v!==void 0?` (with flags '${v}')`:"")+`: ${h}`,"Provide a valid regular expression and flags.",h))}}if(xe(n,gt)&&S(n,gt).length===0&&a.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&&o){let $=x(e,o,r).descriptor;$&&((h!==void 0||y!==void 0||f!==void 0)&&$.kind==="object"&&a.push(this.err(t,"pattern/minLength/maxLength","Warning",`String facets on '${t}' apply to '${r.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.",X(r))),(d!==void 0||k!==void 0)&&!this.isNumericDatatypeRange($.range)&&a.push(this.err(t,"minInclusive/maxInclusive","Warning",`Numeric bounds on '${t}' apply to '${r.name}', whose range is not a numeric datatype.`,"Apply numeric bounds to a numeric datatype property.",X(r))))}}checkOrder(e,t,n,o,a,r){n!==void 0&&a!==void 0&&n>a&&r.push(this.err(e,`${t}/${o}`,"Error",`${t} (${n}) exceeds ${o} (${a}) on '${e}'.`,`Set ${t} <= ${o}.`))}resolvesToClass(e,t){let n=T(e,t);return n?B.isClassType(qe(n)):!1}resolvesToDatatype(e,t){if(t.publisher===Ue&&t.package_==="core-rdf"&&t.name==="Literal")return!0;let n=T(e,t);return n?B.isDatatypeType(qe(n)):!1}isNumericDatatypeRange(e){return!e||e.publisher===Ue&&e.package_==="core-rdf"&&e.name==="Literal"?!0:e.publisher===Ue&&e.package_==="core-xsd"&&jn.has(e.name)}err(e,t,n,o,a,r){let i=new g;return i.ruleType=this.ruleName,i.severity=n,i.entityName=e,i.propertyName=t,i.message=o,i.suggestion=a,r!==void 0&&(i.actualValue=r),i}};function De(m){return typeof m=="number"?m:void 0}function X(m){return`${m.publisher}/${m.package_}/${m.name}`}function Nn(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var ht={publisher:"kanonak.org",package_:"core-owl",name:"oneOf"},xn=m=>m,Ee=class{ruleName="OwlOneOf";async validateAsync(e,t,n){let o=[],a=n?await n.getKanonaks():await new E().parseKanonaks(t),r=Tn(e);if(!r)return o;for(let i of a){if(!(i instanceof D)||i.namespace!==r||!xe(i,ht))continue;let s=S(i,ht);if(s.length===0){o.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 c of s)if(c instanceof Ne)o.push(this.err(i.name,"Error",`owl:oneOf member '${String(c.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(c.value)));else if(c instanceof H){let p=T(a,c.subject);p&&B.isSchemaDefinitionType(xn(p))&&o.push(this.err(i.name,"Error",`owl:oneOf member '${c.subject.name}' on '${i.name}' is a class/property/datatype, not an individual.`,"List named individuals (instances), not schema definitions.",`${c.subject.publisher}/${c.subject.package_}/${c.subject.name}`))}}return o}err(e,t,n,o,a){let r=new g;return r.ruleType=this.ruleName,r.severity=t,r.entityName=e,r.propertyName="oneOf",r.message=n,r.suggestion=o,a!==void 0&&(r.actualValue=a),r}};function Tn(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var _n="kanonak.org",Un="core-shacl",j=m=>({publisher:_n,package_:Un,name:m}),Ln=j("NodeShape"),Mn=j("targetClass"),Wn=j("property"),Hn=j("path"),Bn=j("minCount"),Fn=j("maxCount"),Xn=j("in"),qn=j("pattern"),zn=j("flags"),Yn=j("minLength"),Gn=j("maxLength"),Zn=j("minInclusive"),Jn=j("maxInclusive"),Qn=j("message");function Ae(m){return typeof m=="number"?m:void 0}function eo(m){let e={},t=Ae(w(m,Bn)),n=Ae(w(m,Fn));t!==void 0&&(e.minCount=t),n!==void 0&&(e.maxCount=n);let o=Ae(w(m,Yn)),a=Ae(w(m,Gn));o!==void 0&&(e.minLength=o),a!==void 0&&(e.maxLength=a);let r=Ae(w(m,Zn)),i=Ae(w(m,Jn));r!==void 0&&(e.minInclusive=r),i!==void 0&&(e.maxInclusive=i);let s=L(m,qn);if(s!==void 0){let l=L(m,zn);e.pattern=l!==void 0?{regex:s,flags:l}:{regex:s}}let c=S(m,Xn).filter(l=>l instanceof Ne).map(l=>l.value);c.length>0&&(e.enumValues=c);let p=L(m,Qn);return p!==void 0&&(e.message=p),e}function to(m,e){let t=[];for(let n of S(e,Wn))if(n instanceof I)t.push(n);else if(n instanceof H){let o=T(m,n.subject);o&&t.push(o)}return t}function kt(m){let e=new Map;for(let t of m){if(!(t instanceof D)||!A(t,Ln))continue;let n=V(t,Mn);if(!n)continue;let o=C(n);for(let a of to(m,t)){let r=V(a,Hn);if(!r)continue;let i={pathKey:C(r),constraints:eo(a)},s=e.get(o);s?s.push(i):e.set(o,[i])}}return e}function no(m,e){e.minCount!==void 0&&(m.minCount=e.minCount),e.maxCount!==void 0&&(m.maxCount=e.maxCount),e.minLength!==void 0&&(m.minLength=e.minLength),e.maxLength!==void 0&&(m.maxLength=e.maxLength),e.minInclusive!==void 0&&(m.minInclusive=e.minInclusive),e.maxInclusive!==void 0&&(m.maxInclusive=e.maxInclusive),e.pattern!==void 0&&(m.pattern=e.pattern),e.enumValues!==void 0&&(m.enumValues=e.enumValues),e.message!==void 0&&(m.message=e.message)}function bt(m,e,t){let n=C(t),o=!1,a={};for(let r=e.length-1;r>=0;r--){let i=m.get(C(e[r]));if(i)for(let s of i)s.pathKey===n&&(o=!0,no(a,s.constraints))}if(o)return a.cardinality=a.maxCount===1?"single":"list",a.required=(a.minCount??0)>=1,a}var oo=m=>m,ro=new Ge("kanonak.org","core-rdf","Resource"),Oe=class{ruleName="DiamondNameClash";async validateAsync(e,t,n){let o=[],a=n?await n.getKanonaks():await new E().parseKanonaks(t),r=io(e);if(!r)return o;let i=kt(a);for(let s of a){if(!(s instanceof D)||s.namespace!==r||!B.isClassType(oo(s)))continue;let c=W(s);if(!c)continue;let p=nt(a,c),l=C(c),u=new Set(p.map(f=>C(f)));u.delete(l),u.delete(C(ro));let y=new Map;for(let f of ot(a,c)){if(!f.domains.some(h=>u.has(C(h))))continue;let k=y.get(f.uri.name);k?k.push(f):y.set(f.uri.name,[f])}for(let[f,d]of y){if(d.length<2)continue;let k=$=>bt(i,p,$.uri)?.cardinality,h=new Set(d.map($=>$.range?C($.range):void 0).filter($=>$!==void 0)),v=new Set(d.map(k).filter($=>$!==void 0));h.size<=1&&v.size<=1||o.push(this.toError(s.name,f,d,k))}}return o}toError(e,t,n,o){let a=s=>{let c=`${s.uri.publisher}/${s.uri.package_}/${s.uri.name}`,p=s.range?`${s.range.publisher}/${s.range.package_}/${s.range.name}`:"no range",l=o(s);return`${c} (range ${p}${l?`, ${l}`:""})`},r=n.map(a).join("; "),i=new g;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=t,i.actualValue=r,i.message=`Class '${e}' inherits ${n.length} distinct properties named '${t}' with incompatible range or cardinality: ${r}. The generated interface would multiply-inherit '${t}' with conflicting types and could not compile.`,i.suggestion=`Disambiguate the diamond name-clash on '${t}':
83
+ \u2022 rename one of the properties, or
84
+ \u2022 re-domain one so it is not inherited by '${e}', or
85
+ \u2022 restructure the hierarchy so '${e}' inherits only one '${t}', or
86
+ \u2022 make the ranges/cardinalities compatible (identical) if they are meant to be the same property.`,i}};function io(m){let e=m.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${P(e.version)}`}var ze=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new Ye,this.documentRules=[new z,new Y,new G,new Z,new J],this.repositoryRules=[new Q,new ee,new te,new ne,new oe,new re,new ie,new ae,new se,new ce,new pe,new le,new me,new ye,new ue,new fe,new de,new ge,new he,new ke,new be,new Re,new we,new ve,new Ie,new Ee,new Oe]}async validateAsync(e,t,n){let o=new q;for(let a of this.documentRules)try{let r=a.validate(e);this.addErrorsToResult(o,r)}catch(r){let i=new g;i.ruleType=a.ruleName,i.severity="Error",i.message=`Validation rule '${a.ruleName}' failed: ${r instanceof Error?r.message:String(r)}`,o.errors.push(i)}if(t){let a=[],r=n?.repository??t;for(let i of this.repositoryRules)try{let s=await i.validateAsync(e,r,n);this.addErrorsToResult(o,s)}catch(s){let c=s instanceof Error?s.message:String(s);a.push({ruleName:i.ruleName,cause:c})}if(a.length>0){let i=new Map;for(let{ruleName:s,cause:c}of a){let p=i.get(c);p?p.push(s):i.set(c,[s])}for(let[s,c]of i){let p=new g;p.ruleType=c[0],p.severity="Error",c.length===1?p.message=`Validation rule '${c[0]}' failed: ${s}`:p.message=`${s} (affects ${c.length} rules: ${c.join(", ")})`,o.errors.push(p)}}}return o.isValid=o.errors.length===0,o}async validateDocumentsAsync(e,t){let n=new Se(t),o=[];for(let a of e){let r=await this.validateAsync(a,n.repository,n);o.push({document:a,result:r})}return o}async validateYamlAsync(e,t,n){let o=this.parser.parseWithErrors(e);if(!o.isValid){let a=new q;a.isValid=!1;for(let r of o.errors){let i=new g;i.ruleType="ParseError",i.severity="Error",i.lineNumber=r.line,i.column=r.column,i.message=r.message,r.keyName&&(i.entityName=r.keyName),r.errorType==="DuplicateKey"&&(i.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),a.errors.push(i)}return a}return await this.validateAsync(o.document,t,n)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let t=this.documentRules.findIndex(n=>n instanceof e);t>=0&&this.documentRules.splice(t,1)}removeRepositoryRule(e){let t=this.repositoryRules.findIndex(n=>n instanceof e);t>=0&&this.repositoryRules.splice(t,1)}addErrorsToResult(e,t){for(let n of t)n.severity==="Error"?e.errors.push(n):this.includeWarnings&&e.warnings.push(n)}};export{q as a,b,g as c,Le as d,Se as e,z as f,Y as g,G as h,Z as i,J as j,Q as k,ee as l,te as m,ne as n,oe as o,re as p,ie as q,ae as r,se as s,ce as t,pe as u,le as v,me as w,ye as x,ue as y,fe as z,de as A,ge as B,he as C,ke as D,be as E,Re as F,ve as G,Ie as H,Ee as I,kt as J,bt as K,Oe as L,ze as M};
@@ -1 +1 @@
1
- import{a as w}from"./chunk-FUUTGGJS.js";function K(n){if(Array.isArray(n))return n.map(t=>t?.toString()??"").filter(t=>t.length>0);let e=n?.toString();return e?[e]:[]}var S=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let a=t.metadata?.namespace_?.toString()??"unknown",s=this.cache.get(a);if(s){let o=s.get(e);if(o)return o}let r=await this.buildEntityIndexAsyncInternal(t,new Set,"",new Map);return this.cache.set(a,r),r.get(e)??null}async resolveAllEntitiesAsync(e,t){let a=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let s=e.split("."),r=s[0],o=s[1],g=await this.findDocumentForAlias(t,r);return g?await this.resolveAllEntitiesAsync(o,g):[]}return a.filter(s=>s.entityName===e)}async buildAllEntitiesIndexAsync(e,t,a){let s=[],r=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${r}`),t.has(r))return this.logger?.debug?.(`Skipping ${r} - already visited (circular import prevention)`),s;t.add(r);let o=a.length===0?r:`${a} \u2192 ${r}`;for(let[g,u]of Object.entries(e.body))if(!g.includes(".")&&u&&typeof u=="object"&&!Array.isArray(u)){if(!e.metadata.namespace_)continue;let f=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};s.push({entityName:g,uri:new w(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,g,f),entity:u,definedInNamespace:r,isImported:a.length>0,importPath:o})}if(this.logger?.debug?.(`Collected ${s.length} entities from ${r}`),e.metadata?.imports){let g=Object.values(e.metadata.imports).reduce((u,f)=>u+f.length,0);this.logger?.debug?.(`Processing ${g} import(s) for ${r}`);for(let[u,f]of Object.entries(e.metadata.imports))for(let d of f)try{this.logger?.debug?.(`Resolving import: ${u}/${d.packageName}`);let p=await this.repository.getHighestCompatibleVersionAsync(u,d);if(p){this.logger?.debug?.(`Successfully loaded import: ${p.metadata?.namespace_?.toString()}`);let m=await this.buildAllEntitiesIndexAsync(p,t,o);s.push(...m),this.logger?.debug?.(`Added ${m.length} entities from import ${p.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${u}/${d.packageName}`)}catch(p){let m=p;throw this.logger?.error?.(`Failed to process import ${u}/${d.packageName} for namespace ${r}. Error: ${m.message}`,m),new Error(`Failed to process import ${u}/${d.packageName} for namespace ${r}. See inner exception for details.`,{cause:p})}}return s}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,t,a,s){let r=new Map,o=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${o}`),t.has(o))return this.logger?.debug?.(`Skipping ${o} - circular import in progress`),r;let g=s.get(o);if(g)return g;t.add(o);let u=a.length===0?o:`${a} \u2192 ${o}`,f=0;for(let[d,p]of Object.entries(e.body))if(!d.includes(".")&&p&&typeof p=="object"&&!Array.isArray(p)){if(!e.metadata.namespace_)continue;if(!r.has(d)){let m=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};r.set(d,{entityName:d,uri:new w(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,d,m),entity:p,definedInNamespace:o,isImported:a.length>0,importPath:u}),f++}}if(this.logger?.debug?.(`Indexed ${f} entities from ${o}`),e.metadata?.imports){let d=Object.values(e.metadata.imports).reduce((p,m)=>p+m.length,0);this.logger?.debug?.(`Processing ${d} import(s) for ${o}`);for(let[p,m]of Object.entries(e.metadata.imports))for(let h of m)try{this.logger?.debug?.(`Resolving import: ${p}/${h.packageName}`);let k=await this.repository.getHighestCompatibleVersionAsync(p,h);if(k){this.logger?.debug?.(`Successfully loaded import: ${k.metadata?.namespace_?.toString()}`);let P=await this.buildEntityIndexAsyncInternal(k,t,u,s),v=0;for(let[$,R]of P.entries()){let b=r.get($);if(!b)r.set($,R),v++;else if(b.isImported&&R.isImported&&(b.uri.publisher!==R.uri.publisher||b.uri.package_!==R.uri.package_)){let A=b.isAmbiguous?b:{...b,isAmbiguous:!0,ambiguousNamespaces:[b.definedInNamespace]};A.ambiguousNamespaces.includes(R.definedInNamespace)||A.ambiguousNamespaces.push(R.definedInNamespace),r.set($,A),this.logger?.warn?.(`Ambiguous reference '${$}': defined in ${A.ambiguousNamespaces.join(", ")}`)}if(h.alias&&!$.includes(".")){let A=`${h.alias}.${$}`;r.has(A)||(r.set(A,R),v++)}}this.logger?.debug?.(`Merged ${v} entities from import ${k.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${p}/${h.packageName}`)}catch(k){let P=k;throw this.logger?.error?.(`Failed to process import ${p}/${h.packageName} for namespace ${o}. Error: ${P.message}`,P),new Error(`Failed to process import ${p}/${h.packageName} for namespace ${o}. See inner exception for details.`,{cause:k})}}return t.delete(o),s.set(o,r),r}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[a,s]of Object.entries(e.metadata.imports))for(let r of s){if(r.alias===t)return await this.repository.getHighestCompatibleVersionAsync(a,r);if(!r.alias&&r.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(a,r)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubclassOfRecursiveAsync(e,t,a,s)}async isSubclassOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let r=await this.resolveEntityAsync(e,a);if(!r?.entity)return!1;let o=r.entity.subClassOf;if(o){let g=K(o);for(let u of g)if(u===t||await this.isSubclassOfRecursiveAsync(u,t,a,s))return!0}return!1}async isSubpropertyOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubpropertyOfRecursiveAsync(e,t,a,s)}async isSubpropertyOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let r=await this.resolveEntityAsync(e,a);if(!r?.entity)return!1;let o=r.entity.subPropertyOf;if(o){let g=K(o);for(let u of g)if(u===t||await this.isSubpropertyOfRecursiveAsync(u,t,a,s))return!0}return!1}};var D=class n{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-xsd"&&n.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Literal":!1}isMarkdownDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&e.name==="Markdown":!1}isSubstitutableDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&(e.name==="SubstitutableString"||e.name==="Markdown"):!1}isKnownXsdDatatypeName(e){let t=e.includes(".")?e.split(".")[1]:e;return n.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let a=await this.resourceResolver.resolveEntityAsync(e,t);if(a){let s=a.entity.type;if(s){let r=String(s);return r==="Class"||r==="rdfs.Class"||r.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,t){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(t)||e==="Property"&&this.isLiteralType(t))}isEffectiveObjectProperty(e,t){return!!(e==="ObjectProperty"||e==="Property"&&t&&!this.isXsdDatatype(t)&&!this.isLiteralType(t))}};function L(n){return`${n.publisher}/${n.package_}/${n.name}`}function c(n,e,t){return`${n}/${e}/${t}`}function M(n){return`${n.s}|${n.p}|${x(n.o)}`}function x(n){switch(n.kind){case"uri":return`u:${n.key}`;case"literal":return`l:${n.datatype}:${n.lexical}`;case"blank":return`b:${n.id}`}}function F(n,e,t){return{s:n,p:e,o:{kind:"uri",key:t}}}var l="kanonak.org",i="core-rdf",y="core-owl",_="core-kanonak",I=new Map([["type",i],["subClassOf",i],["subPropertyOf",i],["domain",i],["range",i],["label",i],["comment",i],["seeAlso",i],["isDefinedBy",i],["member",i],["Resource",i],["Class",i],["Property",i],["Datatype",i],["Literal",i],["List",i],["ObjectProperty",y],["DatatypeProperty",y],["AnnotationProperty",y],["Thing",y],["Nothing",y],["Package",_]]),E=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function X(n,e,t){if(!n||!n.name)return;let a=I.get(n.name);if(!a)return;let s=()=>{n.publisher=l,n.package_=a,t&&(n.version=t.get(a))};if(E.has(n.name)){let r=n.publisher===l&&n.package_===a;n.publisher=l,n.package_=a,!r&&t&&(n.version=t.get(a));return}n.publisher===l&&n.package_===a||n.publisher&&n.publisher.length>0&&(!e||e(n))||s()}var O=class{type=c(l,i,"type");subClassOf=c(l,i,"subClassOf");subPropertyOf=c(l,i,"subPropertyOf");domain=c(l,i,"domain");range=c(l,i,"range");label=c(l,i,"label");comment=c(l,i,"comment");resource=c(l,i,"Resource");class_=c(l,i,"Class");datatype=c(l,i,"Datatype");literal=c(l,i,"Literal");equivalentClass=c(l,y,"equivalentClass");equivalentProperty=c(l,y,"equivalentProperty");inverseOf=c(l,y,"inverseOf");sameAs=c(l,y,"sameAs");transitiveProperty=c(l,y,"TransitiveProperty");symmetricProperty=c(l,y,"SymmetricProperty");objectProperty=c(l,y,"ObjectProperty");datatypeProperty=c(l,y,"DatatypeProperty");annotationProperty=c(l,y,"AnnotationProperty");package_=c(l,_,"Package")};export{K as a,S as b,D as c,L as d,c as e,M as f,x as g,F as h,X as i,O as j};
1
+ import{a as w}from"./chunk-FUUTGGJS.js";function K(r){if(Array.isArray(r))return r.map(t=>t?.toString()??"").filter(t=>t.length>0);let e=r?.toString();return e?[e]:[]}var S=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let a=t.metadata?.namespace_?.toString()??"unknown",s=this.cache.get(a);if(s){let o=s.get(e);if(o)return o}let n=await this.buildEntityIndexAsyncInternal(t,new Set,"",new Map);return this.cache.set(a,n),n.get(e)??null}async resolveAllEntitiesAsync(e,t){let a=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let s=e.split("."),n=s[0],o=s[1],g=await this.findDocumentForAlias(t,n);return g?await this.resolveAllEntitiesAsync(o,g):[]}return a.filter(s=>s.entityName===e)}async buildAllEntitiesIndexAsync(e,t,a){let s=[],n=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${n}`),t.has(n))return this.logger?.debug?.(`Skipping ${n} - already visited (circular import prevention)`),s;t.add(n);let o=a.length===0?n:`${a} \u2192 ${n}`;for(let[g,u]of Object.entries(e.body))if(!g.includes(".")&&u&&typeof u=="object"&&!Array.isArray(u)){if(!e.metadata.namespace_)continue;let f=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};s.push({entityName:g,uri:new w(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,g,f),entity:u,definedInNamespace:n,isImported:a.length>0,importPath:o})}if(this.logger?.debug?.(`Collected ${s.length} entities from ${n}`),e.metadata?.imports){let g=Object.values(e.metadata.imports).reduce((u,f)=>u+f.length,0);this.logger?.debug?.(`Processing ${g} import(s) for ${n}`);for(let[u,f]of Object.entries(e.metadata.imports))for(let d of f)try{this.logger?.debug?.(`Resolving import: ${u}/${d.packageName}`);let p=await this.repository.getHighestCompatibleVersionAsync(u,d);if(p){this.logger?.debug?.(`Successfully loaded import: ${p.metadata?.namespace_?.toString()}`);let m=await this.buildAllEntitiesIndexAsync(p,t,o);s.push(...m),this.logger?.debug?.(`Added ${m.length} entities from import ${p.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${u}/${d.packageName}`)}catch(p){let m=p;throw this.logger?.error?.(`Failed to process import ${u}/${d.packageName} for namespace ${n}. Error: ${m.message}`,m),new Error(`Failed to process import ${u}/${d.packageName} for namespace ${n}. See inner exception for details.`,{cause:p})}}return s}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,t,a,s){let n=new Map,o=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${o}`),t.has(o))return this.logger?.debug?.(`Skipping ${o} - circular import in progress`),n;let g=s.get(o);if(g)return g;t.add(o);let u=a.length===0?o:`${a} \u2192 ${o}`,f=0;for(let[d,p]of Object.entries(e.body))if(!d.includes(".")&&p&&typeof p=="object"&&!Array.isArray(p)){if(!e.metadata.namespace_)continue;if(!n.has(d)){let m=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};n.set(d,{entityName:d,uri:new w(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,d,m),entity:p,definedInNamespace:o,isImported:a.length>0,importPath:u}),f++}}if(this.logger?.debug?.(`Indexed ${f} entities from ${o}`),e.metadata?.imports){let d=Object.values(e.metadata.imports).reduce((p,m)=>p+m.length,0);this.logger?.debug?.(`Processing ${d} import(s) for ${o}`);for(let[p,m]of Object.entries(e.metadata.imports))for(let h of m)try{this.logger?.debug?.(`Resolving import: ${p}/${h.packageName}`);let k=await this.repository.getHighestCompatibleVersionAsync(p,h);if(k){this.logger?.debug?.(`Successfully loaded import: ${k.metadata?.namespace_?.toString()}`);let P=await this.buildEntityIndexAsyncInternal(k,t,u,s),v=0;for(let[$,R]of P.entries()){let b=n.get($);if(!b)n.set($,R),v++;else if(b.isImported&&R.isImported&&(b.uri.publisher!==R.uri.publisher||b.uri.package_!==R.uri.package_)){let A=b.isAmbiguous?b:{...b,isAmbiguous:!0,ambiguousNamespaces:[b.definedInNamespace]};A.ambiguousNamespaces.includes(R.definedInNamespace)||A.ambiguousNamespaces.push(R.definedInNamespace),n.set($,A),this.logger?.warn?.(`Ambiguous reference '${$}': defined in ${A.ambiguousNamespaces.join(", ")}`)}if(h.alias&&!$.includes(".")){let A=`${h.alias}.${$}`;n.has(A)||(n.set(A,R),v++)}}this.logger?.debug?.(`Merged ${v} entities from import ${k.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${p}/${h.packageName}`)}catch(k){let P=k;throw this.logger?.error?.(`Failed to process import ${p}/${h.packageName} for namespace ${o}. Error: ${P.message}`,P),new Error(`Failed to process import ${p}/${h.packageName} for namespace ${o}. See inner exception for details.`,{cause:k})}}return t.delete(o),s.set(o,n),n}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[a,s]of Object.entries(e.metadata.imports))for(let n of s){if(n.alias===t)return await this.repository.getHighestCompatibleVersionAsync(a,n);if(!n.alias&&n.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(a,n)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}async isSubclassOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubclassOfRecursiveAsync(e,t,a,s)}async isSubclassOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let n=await this.resolveEntityAsync(e,a);if(!n?.entity)return!1;let o=n.entity.subClassOf;if(o){let g=K(o);for(let u of g)if(u===t||await this.isSubclassOfRecursiveAsync(u,t,a,s))return!0}return!1}async isSubpropertyOfAsync(e,t,a){if(e===t)return!0;let s=new Set;return await this.isSubpropertyOfRecursiveAsync(e,t,a,s)}async isSubpropertyOfRecursiveAsync(e,t,a,s){if(s.has(e))return!1;s.add(e);let n=await this.resolveEntityAsync(e,a);if(!n?.entity)return!1;let o=n.entity.subPropertyOf;if(o){let g=K(o);for(let u of g)if(u===t||await this.isSubpropertyOfRecursiveAsync(u,t,a,s))return!0}return!1}};var D=class r{static KNOWN_XSD_DATATYPES=new Set(["string","integer","int","boolean","decimal","float","double","date","datetime","time","duration","anyuri","base64binary","hexbinary","long","short","byte","nonnegativeinteger","positiveinteger","negativeinteger","nonpositiveinteger","unsignedint","unsignedlong","unsignedshort","unsignedbyte"]);resourceResolver;constructor(e){this.resourceResolver=e}isXsdDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-xsd"&&r.KNOWN_XSD_DATATYPES.has(e.name.toLowerCase()):!1}isLiteralType(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Literal":!1}isMarkdownDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&e.name==="Markdown":!1}isSubstitutableDatatype(e){return e?e.publisher==="kanonak.org"&&e.package_==="core-prose"&&(e.name==="SubstitutableString"||e.name==="Markdown"):!1}isKnownXsdDatatypeName(e){let t=e.includes(".")?e.split(".")[1]:e;return r.KNOWN_XSD_DATATYPES.has(t.toLowerCase())}async isClassTypeAsync(e,t){if(this.isKnownXsdDatatypeName(e))return!1;let a=await this.resourceResolver.resolveEntityAsync(e,t);if(a){let s=a.entity.type;if(s){let n=String(s);return n==="Class"||n==="rdfs.Class"||n.endsWith(".Class")}}return!0}getPropertyTypeClassification(e){if(!e||e.trim().length===0)return"Property";switch(e.includes(".")?e.split(".")[1]:e){case"DatatypeProperty":return"DatatypeProperty";case"ObjectProperty":return"ObjectProperty";case"AnnotationProperty":return"AnnotationProperty";case"Property":return"Property";default:return"Property"}}isEffectiveDatatypeProperty(e,t){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(t)||e==="Property"&&this.isLiteralType(t))}isEffectiveObjectProperty(e,t){return!!(e==="ObjectProperty"||e==="Property"&&t&&!this.isXsdDatatype(t)&&!this.isLiteralType(t))}};function L(r){return`${r.publisher}/${r.package_}/${r.name}`}function c(r,e,t){return`${r}/${e}/${t}`}function M(r){return`${r.s}|${r.p}|${I(r.o)}`}function I(r){switch(r.kind){case"uri":return`u:${r.key}`;case"literal":return`l:${r.datatype}:${r.lexical}`;case"blank":return`b:${r.id}`}}function F(r,e,t){return{s:r,p:e,o:{kind:"uri",key:t}}}var l="kanonak.org",i="core-rdf",y="core-owl",_="core-kanonak",x=new Map([["type",i],["subClassOf",i],["subPropertyOf",i],["domain",i],["range",i],["label",i],["comment",i],["seeAlso",i],["isDefinedBy",i],["member",i],["Resource",i],["Class",i],["Property",i],["Datatype",i],["Literal",i],["List",i],["ObjectProperty",y],["DatatypeProperty",y],["AnnotationProperty",y],["Thing",y],["Nothing",y],["Package",_]]),E=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function X(r){return x.has(r)}function B(r,e,t){if(!r||!r.name)return;let a=x.get(r.name);if(!a)return;let s=()=>{r.publisher=l,r.package_=a,t&&(r.version=t.get(a))};if(E.has(r.name)){let n=r.publisher===l&&r.package_===a;r.publisher=l,r.package_=a,!n&&t&&(r.version=t.get(a));return}r.publisher===l&&r.package_===a||r.publisher&&r.publisher.length>0&&(!e||e(r))||s()}var O=class{type=c(l,i,"type");subClassOf=c(l,i,"subClassOf");subPropertyOf=c(l,i,"subPropertyOf");domain=c(l,i,"domain");range=c(l,i,"range");label=c(l,i,"label");comment=c(l,i,"comment");resource=c(l,i,"Resource");class_=c(l,i,"Class");datatype=c(l,i,"Datatype");literal=c(l,i,"Literal");equivalentClass=c(l,y,"equivalentClass");equivalentProperty=c(l,y,"equivalentProperty");inverseOf=c(l,y,"inverseOf");sameAs=c(l,y,"sameAs");transitiveProperty=c(l,y,"TransitiveProperty");symmetricProperty=c(l,y,"SymmetricProperty");objectProperty=c(l,y,"ObjectProperty");datatypeProperty=c(l,y,"DatatypeProperty");annotationProperty=c(l,y,"AnnotationProperty");package_=c(l,_,"Package")};export{K as a,S as b,D as c,L as d,c as e,M as f,I as g,F as h,X as i,B as j,O as k};
@@ -1 +1 @@
1
- import{b as y,c as s,g as l,h as g,i as b,j as u,k,l as K}from"./chunk-T3JR2SV6.js";import{c as d,g as m}from"./chunk-2ACBWC7K.js";function S(t){return`${t.publisher}/${t.package_}/${t.name}`}function f(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}function U(t){let e=t.version;return e&&typeof e.major=="number"?`https://${t.publisher}/${t.package_}/${e.major}.${e.minor}.${e.patch}/${t.name}`:`https://${t.publisher}/${t.package_}/${t.name}`}function h(t,e){if(!(t instanceof y))return!1;for(let n of t.statement)if(n.predicate?.subject?.name==="type"&&n instanceof u){let r=n.object;if(f(r.subject,e))return!0}return!1}function j(t,e){let n=[];for(let o of t)o instanceof s&&h(o,e)&&n.push(o);return n}function E(t,e){let n=e.version,o=n&&typeof n.major=="number"?`${e.publisher}/${e.package_}@${n.major}.${n.minor}.${n.patch}`:void 0;for(let r of t){if(!(r instanceof s)||r.name!==e.name)continue;let a=r.namespace||"";if(o!==void 0){if(a===o)return r}else if(a.startsWith(`${e.publisher}/${e.package_}@`))return r}}function $(t,e){let n=[];for(let o of t){if(!(o instanceof s)||o.name!==e.name)continue;(o.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&n.push(o)}return n.sort((o,r)=>{let a=m((o.namespace||"").split("@")[1]??""),c=m((r.namespace||"").split("@")[1]??"");return a?c?d(c,a):-1:c?1:0}),n}function i(t,e){for(let n of t.statement){let o=n.predicate;if(o?.subject&&f(o.subject,e))return n}}function x(t,e){return i(t,e)!==void 0}function D(t,e){let n=i(t,e);if(n&&(n instanceof l||n instanceof g||n instanceof b))return n.object}function A(t,e){let n=D(t,e);return typeof n=="string"?n:void 0}function R(t,e){let n=i(t,e);if(n instanceof u)return n.object.subject}function P(t,e){let n=i(t,e);if(n instanceof k)return n.object}function v(t,e){let n=i(t,e);return n instanceof K?n.object??[]:[]}var p=class{constructor(e,n){this.doc=e;this.broader=n}doc;broader;async getAllDocumentsAsync(){return[this.doc]}async getDocumentAsync(e){return this.broader.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,n){return this.broader.getDocumentsByNamespaceAsync(e,n)}async getHighestCompatibleVersionAsync(e,n){return this.broader.getHighestCompatibleVersionAsync(e,n)}async saveDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async deleteDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async clearNamespaceAsync(){throw new Error("SingleDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}async getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}};export{S as a,f as b,U as c,h as d,j as e,E as f,$ as g,x as h,D as i,A as j,R as k,P as l,v as m,p as n};
1
+ import{b as y,c as s,g as l,h as g,i as b,j as u,k,l as K}from"./chunk-4UT2CLAT.js";import{c as d,g as m}from"./chunk-2ACBWC7K.js";function S(t){return`${t.publisher}/${t.package_}/${t.name}`}function f(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}function U(t){let e=t.version;return e&&typeof e.major=="number"?`https://${t.publisher}/${t.package_}/${e.major}.${e.minor}.${e.patch}/${t.name}`:`https://${t.publisher}/${t.package_}/${t.name}`}function h(t,e){if(!(t instanceof y))return!1;for(let n of t.statement)if(n.predicate?.subject?.name==="type"&&n instanceof u){let r=n.object;if(f(r.subject,e))return!0}return!1}function j(t,e){let n=[];for(let o of t)o instanceof s&&h(o,e)&&n.push(o);return n}function E(t,e){let n=e.version,o=n&&typeof n.major=="number"?`${e.publisher}/${e.package_}@${n.major}.${n.minor}.${n.patch}`:void 0;for(let r of t){if(!(r instanceof s)||r.name!==e.name)continue;let a=r.namespace||"";if(o!==void 0){if(a===o)return r}else if(a.startsWith(`${e.publisher}/${e.package_}@`))return r}}function $(t,e){let n=[];for(let o of t){if(!(o instanceof s)||o.name!==e.name)continue;(o.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&n.push(o)}return n.sort((o,r)=>{let a=m((o.namespace||"").split("@")[1]??""),c=m((r.namespace||"").split("@")[1]??"");return a?c?d(c,a):-1:c?1:0}),n}function i(t,e){for(let n of t.statement){let o=n.predicate;if(o?.subject&&f(o.subject,e))return n}}function x(t,e){return i(t,e)!==void 0}function D(t,e){let n=i(t,e);if(n&&(n instanceof l||n instanceof g||n instanceof b))return n.object}function A(t,e){let n=D(t,e);return typeof n=="string"?n:void 0}function R(t,e){let n=i(t,e);if(n instanceof u)return n.object.subject}function P(t,e){let n=i(t,e);if(n instanceof k)return n.object}function v(t,e){let n=i(t,e);return n instanceof K?n.object??[]:[]}var p=class{constructor(e,n){this.doc=e;this.broader=n}doc;broader;async getAllDocumentsAsync(){return[this.doc]}async getDocumentAsync(e){return this.broader.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,n){return this.broader.getDocumentsByNamespaceAsync(e,n)}async getHighestCompatibleVersionAsync(e,n){return this.broader.getHighestCompatibleVersionAsync(e,n)}async saveDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async deleteDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async clearNamespaceAsync(){throw new Error("SingleDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}async getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}};export{S as a,f as b,U as c,h as d,j as e,E as f,$ as g,x as h,D as i,A as j,R as k,P as l,v as m,p as n};
@@ -1,4 +1,4 @@
1
- import{a as Cn}from"./chunk-4NO7MHS7.js";import{a as An}from"./chunk-PEJALHXK.js";import{d as u}from"./chunk-SHDHMKMJ.js";import{a as M,c as Me,i as Vn}from"./chunk-DSHPAWJQ.js";import{a as Fn}from"./chunk-NJ3AZYQD.js";import{a as pn,b as ue,c as xn,d as w,f as Ne,g as ke,j as gn,k as qe,m as Mn,n as Nn}from"./chunk-PBNVHBS3.js";import{b as Oe,c as G,d as E,g as X,h as me,i as re,j as V,k as H,l as T}from"./chunk-T3JR2SV6.js";import{a as Tn}from"./chunk-FUUTGGJS.js";import{c as en,g as ye}from"./chunk-2ACBWC7K.js";var Te="kanonak.org",Hn="look",We="core-rdf",Et={publisher:Te,package_:Hn,name:"displayLabel"},Kt={publisher:Te,package_:Hn,name:"displaySummary"},Rt={publisher:Te,package_:We,name:"type"},Lt={publisher:Te,package_:We,name:"subClassOf"},Ot={publisher:Te,package_:We,name:"label"},Ut={publisher:Te,package_:We,name:"comment"},Pn=new Tn(Te,We,"Resource");function D(r,e){let n=Dn(r,e,Et)??Ot,t=Dn(r,e,Kt)??Ut,a=gn(e,n)??e.name,s=gn(e,t);return{label:a,summary:s}}function Dn(r,e,n){let t=qe(e,n);if(t)return t;let a=new Set,s=Bn(e,Rt);for(;s.length>0;){let o=s.shift(),i=pn(o);if(a.has(i))continue;a.add(i);let c=Ne(r,o);if(!c)continue;let l=qe(c,n);if(l)return l;s.push(...Bn(c,Lt))}if(!a.has(pn(Pn))){let o=Ne(r,Pn);if(o){let i=qe(o,n);if(i)return i}}}function Bn(r,e){let n=qe(r,e);if(n)return[n];let t=[];for(let a of Mn(r,e))a instanceof E&&t.push(a.subject);return t}function Ye(r,e={}){let n=r.replace(/\r\n/g,`
1
+ import{a as Cn}from"./chunk-4NO7MHS7.js";import{a as An}from"./chunk-PEJALHXK.js";import{d as u}from"./chunk-SHDHMKMJ.js";import{a as M,c as Me,i as Vn}from"./chunk-MFNVQSBW.js";import{a as Fn}from"./chunk-NJ3AZYQD.js";import{a as pn,b as ue,c as xn,d as w,f as Ne,g as ke,j as gn,k as qe,m as Mn,n as Nn}from"./chunk-7TKJHKC2.js";import{b as Oe,c as G,d as E,g as X,h as me,i as re,j as V,k as H,l as T}from"./chunk-4UT2CLAT.js";import{a as Tn}from"./chunk-FUUTGGJS.js";import{c as en,g as ye}from"./chunk-2ACBWC7K.js";var Te="kanonak.org",Hn="look",We="core-rdf",Et={publisher:Te,package_:Hn,name:"displayLabel"},Kt={publisher:Te,package_:Hn,name:"displaySummary"},Rt={publisher:Te,package_:We,name:"type"},Lt={publisher:Te,package_:We,name:"subClassOf"},Ot={publisher:Te,package_:We,name:"label"},Ut={publisher:Te,package_:We,name:"comment"},Pn=new Tn(Te,We,"Resource");function D(r,e){let n=Dn(r,e,Et)??Ot,t=Dn(r,e,Kt)??Ut,a=gn(e,n)??e.name,s=gn(e,t);return{label:a,summary:s}}function Dn(r,e,n){let t=qe(e,n);if(t)return t;let a=new Set,s=Bn(e,Rt);for(;s.length>0;){let o=s.shift(),i=pn(o);if(a.has(i))continue;a.add(i);let c=Ne(r,o);if(!c)continue;let l=qe(c,n);if(l)return l;s.push(...Bn(c,Lt))}if(!a.has(pn(Pn))){let o=Ne(r,Pn);if(o){let i=qe(o,n);if(i)return i}}}function Bn(r,e){let n=qe(r,e);if(n)return[n];let t=[];for(let a of Mn(r,e))a instanceof E&&t.push(a.subject);return t}function Ye(r,e={}){let n=r.replace(/\r\n/g,`
2
2
  `).split(`
3
3
  `),t=[],a=0;for(;a<n.length;){let s=n[a];if(s.trim()===""){a++;continue}let o=/^(\s*)```(\S*)\s*$/.exec(s);if(o){let l=o[2],d=[];for(a++;a<n.length&&!/^(\s*)```\s*$/.test(n[a]);)d.push(n[a]),a++;a++;let f=d.join(`
4
4
  `),g=l&&e.highlight?e.highlight(l,f):De(f),m=l?` class="language-${Gn(l)}"`:"";t.push(`<pre class="kan-code"><code${m}>${g}</code></pre>`);continue}let i=/^(#{1,6})\s+(.*)$/.exec(s);if(i){let l=i[1].length,d=Pe(i[2].trim());t.push(`<h${l}>${d}</h${l}>`),a++;continue}if(s.includes("|")&&a+1<n.length&&zn(n[a+1])){let l=mn(s),d=It(n[a+1]);a+=2;let f=[];for(;a<n.length&&n[a].trim()!==""&&n[a].includes("|");)f.push(mn(n[a])),a++;t.push(Ct(l,d,f));continue}if(/^\s*[-*]\s+/.test(s)){let l=[];for(;a<n.length&&/^\s*[-*]\s+/.test(n[a]);){let d=[n[a].replace(/^\s*[-*]\s+/,"")];for(a++;a<n.length&&n[a].trim()!==""&&!/^\s*[-*]\s+/.test(n[a])&&!/^\s*\d+\.\s+/.test(n[a]);)d.push(n[a]),a++;a<n.length&&n[a].trim()===""&&a++,l.push(`<li>${Pe(d.join(" ").trim())}</li>`)}t.push(`<ul>
@@ -1 +1 @@
1
- import{a as u,f as _,j as g,k as d,m as j}from"./chunk-PBNVHBS3.js";import{i as m}from"./chunk-VKTFLHCW.js";import{c as U,d as S}from"./chunk-T3JR2SV6.js";import{a as b}from"./chunk-FUUTGGJS.js";var $=new Set(["kanonak.org/core-rdf","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);function i(r){let n=r;if(n.entity&&typeof n.entity=="object"){let e=n.entity.type;if(typeof e=="string"){let a={publisher:"",package_:"",name:e.includes(".")?e.substring(e.lastIndexOf(".")+1):e};return m(a),{publisher:a.publisher,package_:a.package_,name:a.name}}}if(n.statement&&Array.isArray(n.statement)){for(let e of n.statement)if(e.predicate?.subject?.name==="type"&&e.object?.subject){let t=e.object.subject,a={publisher:t.publisher??"",package_:t.package_??"",name:t.name};return m(a),{publisher:a.publisher,package_:a.package_,name:a.name}}}return null}function c(r,n){return $.has(`${r}/${n}`)}var y=class r{static getTypeUri(n){return i(n)}static isCoreOntologyType(n){return c(n.publisher,n.package_)}static isClassType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Class":!1}static isDatatypeType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Datatype":!1}static isDatatypePropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="DatatypeProperty":!1}static isObjectPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="ObjectProperty":!1}static isAnnotationPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="AnnotationProperty":!1}static isGenericPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Property":!1}static isAnyPropertyType(n){let e=i(n);return!e||!c(e.publisher,e.package_)?!1:e.name==="Property"||e.name==="DatatypeProperty"||e.name==="ObjectProperty"||e.name==="AnnotationProperty"}static isSchemaDefinitionType(n){let e=i(n);return!e||!c(e.publisher,e.package_)?!1:e.name==="Class"||e.name==="Property"||e.name==="DatatypeProperty"||e.name==="ObjectProperty"||e.name==="AnnotationProperty"||e.name==="Datatype"}static isInstanceOfKnownClass(n,e){if(r.isSchemaDefinitionType(n))return!1;let t=i(n);return t?e.has(t.name):!1}};function P(r){if(!r||r.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let n=r.trim(),e=n.split("/");if(e.length===1){let t=e[0];if(!t)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(t.includes("@"))throw new Error(`Invalid Kanonak address: "${r}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:t}}if(e.length===2){let[t,a]=e;if(!t||!a)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher/package[@version].`);let o=a.indexOf("@");if(o===-1)return{kind:"package",publisher:t,package_:a};let s=a.substring(0,o),p=a.substring(o+1);if(!s||!p)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher/package[@version].`);let f=A(p);return{kind:"package",publisher:t,package_:s,version:f}}return{kind:"resource",uri:b.parse(n)}}function G(r){switch(r.kind){case"publisher":return r.publisher;case"package":return r.version?`${r.publisher}/${r.package_}@${r.version.major}.${r.version.minor}.${r.version.patch}`:`${r.publisher}/${r.package_}`;case"resource":return r.uri.toString()}}function A(r){let n=r.split(".").map(Number);return w(n[0]||0,n[1]||0,n[2]||0)}function w(r,n,e){return{major:r,minor:n,patch:e,toString:()=>`${r}.${n}.${e}`,equals:t=>!t||typeof t!="object"?!1:t.major===r&&t.minor===n&&t.patch===e,getHashCode:()=>r<<20|n<<10|e,compareTo:t=>r!==t.major?r-t.major:n!==t.minor?n-t.minor:e-t.patch}}var k="kanonak.org",l="core-rdf",T={publisher:k,package_:l,name:"domain"},C={publisher:k,package_:l,name:"range"},R={publisher:k,package_:l,name:"subClassOf"},v={publisher:k,package_:l,name:"type"},x={publisher:k,package_:l,name:"label"},D={publisher:k,package_:l,name:"comment"},O=new b(k,l,"Resource"),I=r=>r;function V(r){try{let n=P(`${r.namespace}/${r.name}`);return n.kind==="resource"?n.uri:void 0}catch{return}}function h(r,n){let e=d(r,n);if(e)return[e];let t=[];for(let a of j(r,n))a instanceof S&&t.push(a.subject);return t}function N(r,n){let e=[],t=new Set,a=[new b(n.publisher,n.package_,n.name)];for(;a.length>0;){let o=a.shift(),s=u(o);if(t.has(s))continue;t.add(s),e.push(o);let p=_(r,o);p&&a.push(...h(p,R))}return e}function B(r,n){let e=new Set([u(O)]);for(let t of N(r,n))e.add(u(t));return e}function F(r,n){let e=B(r,n),t=[],a=new Set;for(let o of r){if(!(o instanceof U))continue;let s=I(o);if(!y.isAnyPropertyType(s))continue;let p=h(o,T);if(!p.some(E=>e.has(u(E))))continue;let f=V(o);if(!f)continue;let K=u(f);a.has(K)||(a.add(K),t.push({uri:f,label:g(o,x),comment:g(o,D),kind:y.isObjectPropertyType(s)?"object":y.isDatatypePropertyType(s)?"datatype":"other",range:d(o,C),domains:p}))}return t}function Z(r,n,e){let t=F(r,n).find(a=>u(a.uri)===u(e));return t?{ok:!0,descriptor:t}:{ok:!1,message:`Property ${e.publisher}/${e.package_}/${e.name} is not in scope for ${n.publisher}/${n.package_}/${n.name}.`}}function ee(r){return h(r,v)}export{y as a,P as b,G as c,V as d,N as e,F as f,Z as g,ee as h};
1
+ import{a as u,f as _,j as g,k as d,m as j}from"./chunk-7TKJHKC2.js";import{j as m}from"./chunk-7HRKWTBB.js";import{c as U,d as S}from"./chunk-4UT2CLAT.js";import{a as b}from"./chunk-FUUTGGJS.js";var $=new Set(["kanonak.org/core-rdf","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);function i(r){let n=r;if(n.entity&&typeof n.entity=="object"){let e=n.entity.type;if(typeof e=="string"){let a={publisher:"",package_:"",name:e.includes(".")?e.substring(e.lastIndexOf(".")+1):e};return m(a),{publisher:a.publisher,package_:a.package_,name:a.name}}}if(n.statement&&Array.isArray(n.statement)){for(let e of n.statement)if(e.predicate?.subject?.name==="type"&&e.object?.subject){let t=e.object.subject,a={publisher:t.publisher??"",package_:t.package_??"",name:t.name};return m(a),{publisher:a.publisher,package_:a.package_,name:a.name}}}return null}function c(r,n){return $.has(`${r}/${n}`)}var y=class r{static getTypeUri(n){return i(n)}static isCoreOntologyType(n){return c(n.publisher,n.package_)}static isClassType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Class":!1}static isDatatypeType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Datatype":!1}static isDatatypePropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="DatatypeProperty":!1}static isObjectPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="ObjectProperty":!1}static isAnnotationPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="AnnotationProperty":!1}static isGenericPropertyType(n){let e=i(n);return e?c(e.publisher,e.package_)&&e.name==="Property":!1}static isAnyPropertyType(n){let e=i(n);return!e||!c(e.publisher,e.package_)?!1:e.name==="Property"||e.name==="DatatypeProperty"||e.name==="ObjectProperty"||e.name==="AnnotationProperty"}static isSchemaDefinitionType(n){let e=i(n);return!e||!c(e.publisher,e.package_)?!1:e.name==="Class"||e.name==="Property"||e.name==="DatatypeProperty"||e.name==="ObjectProperty"||e.name==="AnnotationProperty"||e.name==="Datatype"}static isInstanceOfKnownClass(n,e){if(r.isSchemaDefinitionType(n))return!1;let t=i(n);return t?e.has(t.name):!1}};function P(r){if(!r||r.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let n=r.trim(),e=n.split("/");if(e.length===1){let t=e[0];if(!t)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(t.includes("@"))throw new Error(`Invalid Kanonak address: "${r}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:t}}if(e.length===2){let[t,a]=e;if(!t||!a)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher/package[@version].`);let o=a.indexOf("@");if(o===-1)return{kind:"package",publisher:t,package_:a};let s=a.substring(0,o),p=a.substring(o+1);if(!s||!p)throw new Error(`Invalid Kanonak address: "${r}". Expected publisher/package[@version].`);let f=A(p);return{kind:"package",publisher:t,package_:s,version:f}}return{kind:"resource",uri:b.parse(n)}}function G(r){switch(r.kind){case"publisher":return r.publisher;case"package":return r.version?`${r.publisher}/${r.package_}@${r.version.major}.${r.version.minor}.${r.version.patch}`:`${r.publisher}/${r.package_}`;case"resource":return r.uri.toString()}}function A(r){let n=r.split(".").map(Number);return w(n[0]||0,n[1]||0,n[2]||0)}function w(r,n,e){return{major:r,minor:n,patch:e,toString:()=>`${r}.${n}.${e}`,equals:t=>!t||typeof t!="object"?!1:t.major===r&&t.minor===n&&t.patch===e,getHashCode:()=>r<<20|n<<10|e,compareTo:t=>r!==t.major?r-t.major:n!==t.minor?n-t.minor:e-t.patch}}var k="kanonak.org",l="core-rdf",T={publisher:k,package_:l,name:"domain"},C={publisher:k,package_:l,name:"range"},R={publisher:k,package_:l,name:"subClassOf"},v={publisher:k,package_:l,name:"type"},x={publisher:k,package_:l,name:"label"},D={publisher:k,package_:l,name:"comment"},O=new b(k,l,"Resource"),I=r=>r;function V(r){try{let n=P(`${r.namespace}/${r.name}`);return n.kind==="resource"?n.uri:void 0}catch{return}}function h(r,n){let e=d(r,n);if(e)return[e];let t=[];for(let a of j(r,n))a instanceof S&&t.push(a.subject);return t}function N(r,n){let e=[],t=new Set,a=[new b(n.publisher,n.package_,n.name)];for(;a.length>0;){let o=a.shift(),s=u(o);if(t.has(s))continue;t.add(s),e.push(o);let p=_(r,o);p&&a.push(...h(p,R))}return e}function B(r,n){let e=new Set([u(O)]);for(let t of N(r,n))e.add(u(t));return e}function F(r,n){let e=B(r,n),t=[],a=new Set;for(let o of r){if(!(o instanceof U))continue;let s=I(o);if(!y.isAnyPropertyType(s))continue;let p=h(o,T);if(!p.some(E=>e.has(u(E))))continue;let f=V(o);if(!f)continue;let K=u(f);a.has(K)||(a.add(K),t.push({uri:f,label:g(o,x),comment:g(o,D),kind:y.isObjectPropertyType(s)?"object":y.isDatatypePropertyType(s)?"datatype":"other",range:d(o,C),domains:p}))}return t}function Z(r,n,e){let t=F(r,n).find(a=>u(a.uri)===u(e));return t?{ok:!0,descriptor:t}:{ok:!1,message:`Property ${e.publisher}/${e.package_}/${e.name} is not in scope for ${n.publisher}/${n.package_}/${n.name}.`}}function ee(r){return h(r,v)}export{y as a,P as b,G as c,V as d,N as e,F as f,Z as g,ee as h};
@@ -0,0 +1 @@
1
+ import{a as U}from"./chunk-NJ3AZYQD.js";import{b as F,c as V,i as z,j as T}from"./chunk-7HRKWTBB.js";import{a as B,b as _,c as x,d as k,g as w,h as R,i as v,j as D,k as $,l as j}from"./chunk-4UT2CLAT.js";import{j as L}from"./chunk-2ACBWC7K.js";var S=class extends _{name};var I=class extends B{value;carrier;lexical};var K=class extends w{links=[]};var J=n=>({publisher:"kanonak.org",package_:"core-xsd",name:n}),Q=n=>({publisher:"kanonak.org",package_:"core-rdf",name:n}),Z=(p=>(p.Integer="integer",p.Decimal="decimal",p.Double="double",p.Float="float",p.Boolean="boolean",p.String="string",p.AnyUri="anyURI",p.LangString="langString",p.DateTime="dateTime",p.Date="date",p.Time="time",p.HexBinary="hexBinary",p.Base64Binary="base64Binary",p))(Z||{});function C(n){return`${n.publisher}/${n.package_}/${n.name}`}var ee=[["integer","integer"],["long","integer"],["int","integer"],["short","integer"],["byte","integer"],["unsignedLong","integer"],["unsignedInt","integer"],["unsignedShort","integer"],["unsignedByte","integer"],["nonNegativeInteger","integer"],["positiveInteger","integer"],["nonPositiveInteger","integer"],["negativeInteger","integer"],["decimal","decimal"],["double","double"],["float","float"],["boolean","boolean"],["string","string"],["normalizedString","string"],["token","string"],["anyURI","anyURI"],["dateTime","dateTime"],["date","date"],["time","time"],["hexBinary","hexBinary"],["base64Binary","base64Binary"]],ne=new Map(ee.map(([n,e])=>[C(J(n)),e])),te=C(Q("langString"));function M(n){let e=C(n);return e===te?"langString":ne.get(e)}function re(n){let e=n.trim();if(!/^[+-]?\d+$/.test(e))throw new Error(`canonicalInteger: '${n}' is not a valid xsd:integer lexical`);return BigInt(e.replace(/^\+/,"")).toString()}function ae(n){let e=n.trim(),t=/^([+-]?)(\d*)(?:\.(\d*))?$/.exec(e);if(!t||t[2]===""&&(t[3]??"")==="")throw new Error(`canonicalDecimal: '${n}' is not a valid xsd:decimal lexical`);let a=t[1]==="-"?"-":"",r=(t[2]??"").replace(/^0+/,"")||"0",s=(t[3]??"").replace(/0+$/,""),o=s.length>0?`${r}.${s}`:r;return o==="0"?"0":`${a}${o}`}function H(n,e,t){let a=n.trim();if(a==="NaN")return"NaN";if(a==="INF")return"INF";if(a==="-INF")return"-INF";if(!/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(a))throw new Error(`canonical${t}: '${n}' is not a valid xsd:${t.toLowerCase()} lexical`);let r=e(Number(a));if(!Number.isFinite(r))throw new Error(`canonical${t}: '${n}' is out of the finite range`);return Object.is(r,-0)?"0":String(r)}function oe(n){return H(n,e=>e,"Double")}function ie(n){return H(n,e=>Math.fround(e),"Float")}function se(n){let e=n.trim();if(e==="true"||e==="1")return"true";if(e==="false"||e==="0")return"false";throw new Error(`canonicalBoolean: '${n}' is not a valid xsd:boolean lexical`)}function Y(n){return n.normalize("NFC")}function ce(n){return n.normalize("NFC")}function fe(n){let e=n.trim();if(!/^([0-9A-Fa-f]{2})*$/.test(e))throw new Error(`canonicalHexBinary: '${n}' is not a valid xsd:hexBinary lexical`);return e.toUpperCase()}function pe(n){let e=n.replace(/\s+/g,"");if(!/^[A-Za-z0-9+/]*={0,2}$/.test(e)||e.length%4!==0)throw new Error(`canonicalBase64: '${n}' is not a valid xsd:base64Binary lexical`);return Buffer.from(e,"base64").toString("base64")}var P=n=>n<10?`0${n}`:`${n}`;function E(n){let e=n.startsWith("-"),t=(e?n.slice(1):n).replace(/^0+/,"")||"0",a=t.length<4?t.padStart(4,"0"):t;return`${e?"-":""}${a}`}function X(n){if(!n)return"";let e=n.replace(/^\./,"").replace(/0+$/,"");return e.length>0?`.${e}`:""}function G(n){return n?n==="Z"||n==="+00:00"||n==="-00:00"?"Z":n:""}function ue(n){return n==="Z"?0:(n[0]==="-"?-1:1)*(Number(n.slice(1,3))*60+Number(n.slice(4,6)))}var le=/^(-?\d{4,})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/,me=/^(-?\d{4,})-(\d{2})-(\d{2})(Z|[+-]\d{2}:\d{2})?$/,de=/^(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-]\d{2}:\d{2})?$/;function ge(n){let e=le.exec(n.trim());if(!e)throw new Error(`canonicalDateTime: '${n}' is not a valid xsd:dateTime lexical`);let[,t,a,r,s,o,c,f,u]=e,g=X(f);if(!u)return`${E(t)}-${a}-${r}T${s}:${o}:${c}${g}`;let l=new Date(0);l.setUTCFullYear(Number(t),Number(a)-1,Number(r)),l.setUTCHours(Number(s),Number(o),Number(c),0);let i=new Date(l.getTime()-ue(u)*6e4);return`${E(String(i.getUTCFullYear()))}-${P(i.getUTCMonth()+1)}-${P(i.getUTCDate())}T${P(i.getUTCHours())}:${P(i.getUTCMinutes())}:${P(i.getUTCSeconds())}${g}Z`}function ye(n){let e=me.exec(n.trim());if(!e)throw new Error(`canonicalDate: '${n}' is not a valid xsd:date lexical`);let[,t,a,r,s]=e;return`${E(t)}-${a}-${r}${G(s)}`}function ke(n){let e=de.exec(n.trim());if(!e)throw new Error(`canonicalTime: '${n}' is not a valid xsd:time lexical`);let[,t,a,r,s,o]=e,c=X(s),f=t;return t==="24"&&a==="00"&&r==="00"&&c===""&&(f="00"),`${f}:${a}:${r}${c}${G(o)}`}function Pe(n,e){switch(n){case"integer":return re(e);case"decimal":return ae(e);case"double":return oe(e);case"float":return ie(e);case"boolean":return se(e);case"string":return Y(e);case"anyURI":return ce(e);case"langString":return Y(e);case"dateTime":return ge(e);case"date":return ye(e);case"time":return ke(e);case"hexBinary":return fe(e);case"base64Binary":return pe(e)}}var be=/\[\[([^\[\]\n]+)\]\]/g,he=/\[\[/g,q=/```[\s\S]*?```|`[^`\n]*`/g;function Se(n){let e=[];for(let t of n.matchAll(q))e.push([t.index,t.index+t[0].length]);return e}function ve(n){if(!n||!n.includes("[["))return[];let e=Se(n),t=s=>e.some(([o,c])=>s>=o&&s<c),a=new Set(N(n).map(s=>s.startOffset)),r=[];for(let s of n.matchAll(he)){let o=s.index;if(t(o)||a.has(o))continue;let c=n.slice(o,o+48).replace(/\s+/g," ").trim();r.push({startOffset:o,snippet:c})}return r}function N(n){if(!n||!n.includes("[["))return[];let e=[];for(let r of n.matchAll(q))e.push([r.index,r.index+r[0].length]);let t=r=>e.some(([s,o])=>r>=s&&r<o),a=[];for(let r of n.matchAll(be)){let s=r.index;if(t(s))continue;let o=r[1],c=o.indexOf("|"),f=(c===-1?o:o.slice(0,c)).trim();if(f.length===0)continue;let u=c===-1?"":o.slice(c+1).trim(),g={reference:f,startOffset:s,endOffset:s+r[0].length};u.length>0&&(g.displayText=u),a.push(g)}return a}var W=class{constructor(e){}async parseKanonaks(e){let t=[],a=await e.getAllDocumentsAsync(),r=new F(e),s=new V(r);for(let i of a){let p=i.metadata.namespace_?.toString()??"";for(let[m,y]of Object.entries(i.body)){let d=new x,b=this.resolveCanonicalEntity(m,i,p);d.namespace=b.namespace,d.name=b.name,d.statement=[];let h=await this.parseStatements(y,i,r,s,e);d.statement.push(...h.statements),d.unresolvedPredicates=h.unresolved,t.push(d)}}let o=new Map,c=new Map,f=[];for(let i of t)if(i instanceof x){let p=`${i.namespace}/${i.name}`,m=o.get(p);if(m){let y=c.get(p);for(let d of i.statement){let b=O(d);y.has(b)||(y.add(b),m.statement.push(d))}for(let d of i.unresolvedPredicates)m.unresolvedPredicates.some(b=>b.key===d.key&&b.sourceDoc===d.sourceDoc)||m.unresolvedPredicates.push(d)}else{let y=new Set,d=[];for(let b of i.statement){let h=O(b);y.has(h)||(y.add(h),d.push(b))}i.statement=d,c.set(p,y),o.set(p,i),f.push(i)}}else f.push(i);let u=new Set;for(let i of f)if(i instanceof x){let p=i.namespace||"",m=p.indexOf("/"),y=m>=0?p.slice(0,m):"",d=m>=0?p.slice(m+1):"",b=d.indexOf("@"),h=b>=0?d.slice(0,b):d;u.add(`${y}/${h}/${i.name}`)}let g=i=>u.has(`${i.publisher}/${i.package_}/${i.name}`),l=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let p=await e.getDocumentsByNamespaceAsync("kanonak.org",i);l.set(i,L(p).chosen?.metadata.namespace_?.version??void 0)}for(let i of f)i instanceof x&&this.canonicalizeStatementBuiltins(i.statement,g,l);return f}canonicalizeStatementBuiltins(e,t,a){for(let r of e){let s=r.predicate?.subject;if(T(s,t,a),r instanceof D)r.object instanceof k&&T(r.object.subject,t,a);else if(r instanceof $)r.object&&this.canonicalizeStatementBuiltins(r.object.statement,t,a);else if(r instanceof j)for(let o of r.object??[])o instanceof k?T(o.subject,t,a):o instanceof S&&this.canonicalizeStatementBuiltins(o.statement,t,a)}}resolveCanonicalEntity(e,t,a){if(!e.includes(".")||!t.metadata?.imports)return{namespace:a,name:e};let r=e.indexOf("."),s=e.substring(0,r),o=e.substring(r+1);for(let[c,f]of Object.entries(t.metadata.imports))for(let u of f)if((u.alias??u.packageName)===s){let l=u.version;return{namespace:`${c}/${u.packageName}@${l.major}.${l.minor}.${l.patch}`,name:o}}return{namespace:a,name:e}}async parseStatements(e,t,a,r,s){let o=[],c=[];if(typeof e!="object"||e===null||Array.isArray(e))return{statements:o,unresolved:c};let f=t.metadata.namespace_?.toString()??"";for(let[u,g]of Object.entries(e))try{let l=await this.getPropertyMetadata(u,t,a,s,r);if(!l){let p=u.includes(".")?u.slice(u.lastIndexOf(".")+1):u;z(p)||c.push({key:u,sourceDoc:f});continue}let i=await this.parsePropertyValue(u,g,l,t,a,r,s);i&&o.push(i)}catch(l){throw new Error(`Failed to parse property '${u}': ${l.message}`,{cause:l})}return{statements:o,unresolved:c}}async getPropertyMetadata(e,t,a,r,s){let o=await a.resolveEntityAsync(e,t);if(!o)return;let c=o.entity,f=c.type?.toString()??"",u=f.includes(".")?f.substring(f.lastIndexOf(".")+1):f;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(u))return;let l=s.getPropertyTypeClassification(f),i=c.range?.toString(),p;if(l==="ObjectProperty")p="ObjectProperty";else if(l==="DatatypeProperty")p="DatatypeProperty";else{let d=i&&i.includes(".")?i.substring(i.lastIndexOf(".")+1):i??"";(i?s.isKnownXsdDatatypeName(i):!1)||d==="Literal"?p="DatatypeProperty":p="ObjectProperty"}let m;if(i){let d=t;if(o.isImported&&o.definedInNamespace){if(typeof r.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${e}': the parse repository cannot fetch defining document '${o.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let h=await r.getDocumentAsync(o.definedInNamespace);if(!h)throw new Error(`Cannot resolve the range of imported property '${e}': defining document '${o.definedInNamespace}' was not found in the repository.`);d=h}m=(await a.resolveEntityAsync(i,d))?.uri}return{propertyUri:o.uri.toString(),propertyType:p,range:i,rangeUri:m,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async parsePropertyValue(e,t,a,r,s,o,c){let f=a.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(f,t,a,r,s,o,c);if(a.propertyType==="DatatypeProperty")return this.parseDatatypeValue(f,t,a,r,s,o);if(a.propertyType==="ObjectProperty")return this.parseObjectValue(f,t,a,r,s,o,c)}}async parseDatatypeValue(e,t,a,r,s,o){let c;if(typeof t=="string"){if(o.isSubstitutableDatatype(a.rangeUri))return await this.parseSubstitutableValue(e,t,r,s);c=t}else if(typeof t=="number"||typeof t=="boolean")c=String(t);else return;return this.typedScalarStatement(e,c,a)}typedScalarStatement(e,t,a){let r=k.parse(e),s=a.rangeUri?M(a.rangeUri):void 0;if(s==="boolean"){let c=new v;return c.predicate=r,c.object=t==="true"||t==="1",c.carrier=s,c.lexical=t,c}if(s==="integer"||s==="decimal"||s==="double"||s==="float"){let c=new R;return c.predicate=r,c.object=Number(t),c.carrier=s,c.lexical=t,c}let o=w.parse(e,t);return s&&(o.carrier=s,o.lexical=t),o}typedListLiteral(e,t){let a=new I,r=t.rangeUri?M(t.rangeUri):void 0;return r==="boolean"?a.value=e==="true"||e==="1":r==="integer"||r==="decimal"||r==="double"||r==="float"?a.value=Number(e):a.value=e,r&&(a.carrier=r,a.lexical=e),a}async parseSubstitutableValue(e,t,a,r){let s=new K;s.predicate=k.parse(e),s.object=t;for(let o of N(t)){let c=await r.resolveEntityAsync(o.reference,a),f;c&&(f=new k,f.subject=c.uri);let u={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(u.displayText=o.displayText),f!==void 0&&(u.target=f),s.links.push(u)}return s}async parseObjectValue(e,t,a,r,s,o,c){if(typeof t=="string"){let f=await this.resolveReference(t,r,s);if(!f)return;let u=new D;return u.predicate=k.parse(e),u.object=f,u}if(typeof t=="object"&&!Array.isArray(t)){let f=await this.parseStatements(t,r,s,o,c);if(f.statements.length>0){let l=new S;l.statement=f.statements,l.unresolvedPredicates=f.unresolved;let i=new $;return i.predicate=k.parse(e),i.object=l,i}let u=[];for(let[l,i]of Object.entries(t))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let p=new S;p.name=l;let m=await this.parseStatements(i,r,s,o,c);p.statement=m.statements,p.unresolvedPredicates=m.unresolved,u.push(p)}else if(typeof i=="string"){let p=await this.resolveReference(i,r,s);p&&u.push(p)}if(u.length>0){let l=new j;return l.predicate=k.parse(e),l.object=u,l}let g=new $;return g.predicate=k.parse(e),g.object=new S,g}}async parseListValue(e,t,a,r,s,o,c){let f=[],u=a.propertyType==="DatatypeProperty",g=a.rangeUri?.publisher==="kanonak.org"&&a.rangeUri?.package_==="core-rdf"&&a.rangeUri?.name==="List"||!a.rangeUri&&(a.range?.includes(".")?a.range.substring(a.range.lastIndexOf(".")+1):a.range)==="List";for(let i of t){let p=typeof i=="string"||typeof i=="number"||typeof i=="boolean";if(u&&p){let m=typeof i=="string"?i:String(i);f.push(this.typedListLiteral(m,a));continue}if(g&&p){if(typeof i=="string"){let m=await s.resolveEntityAsync(i,r);if(m){let y=new k;y.subject=m.uri,f.push(y)}else{let y=new I;y.value=i,f.push(y)}}else{let m=new I;m.value=i,f.push(m)}continue}if(typeof i=="string"){let m=await this.resolveReference(i,r,s);m&&f.push(m)}else if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let m=new S,y=await this.parseStatements(i,r,s,o,c);m.statement=y.statements,m.unresolvedPredicates=y.unresolved,f.push(m)}}let l=new j;return l.predicate=k.parse(e),l.object=f,l}async resolveReference(e,t,a){let r=await a.resolveEntityAsync(e,t);if(r){let o=new k;return o.subject=r.uri,o}let s=t.metadata?.namespace_;if(s){let{KanonakUri:o}=await import("./KanonakUri-4VJGV3FN.js");if(e.includes(".")){let f=e.indexOf("."),u=e.substring(0,f),g=e.substring(f+1);if(t.metadata?.imports){for(let[l,i]of Object.entries(t.metadata.imports))for(let p of i)if((p.alias??p.packageName)===u){let y=new k;return y.subject=new o(l,p.packageName,g,p.version),y}}}let c=new k;return c.subject=new o(s.publisher,s.package_,e,s.version??void 0),c}return null}async saveKanonaks(e,t){let a=new Map;for(let r of e)r instanceof x&&r.namespace&&(a.has(r.namespace)||a.set(r.namespace,[]),a.get(r.namespace).push(r));for(let[r,s]of a){let o=await this.convertKanonaksToDocument(r,s),c=`${r.split("@")[0]}.yml`;await t.saveDocumentAsync(o,c)}}async serializeToYaml(e,t){let a=e.filter(o=>o instanceof x&&o.namespace===t);if(a.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let r=await this.convertKanonaksToDocument(t,a);return new U().save(r)}async convertKanonaksToDocument(e,t){let r={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},s=new Map;for(let o of t){let c={};for(let f of o.statement){let[u,g]=this.convertStatementToProperty(f);u&&g!==null&&g!==void 0&&(c[u]=g),this.collectImportsFromStatement(f,e,s)}r.body[o.name]=c}return r}convertStatementToProperty(e){if(e instanceof w)return[e.predicate.subject.name,e.object];if(e instanceof R)return[e.predicate.subject.name,e.object];if(e instanceof v)return[e.predicate.subject.name,e.object];if(e instanceof D)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof j){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof $){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let a of e)a instanceof k?t.push(a.subject.name):a instanceof S&&t.push(this.convertEmbeddedKanonakToValue(a));return t}convertEmbeddedKanonakToValue(e){let t={};for(let a of e.statement){let[r,s]=this.convertStatementToProperty(a);r&&s!==null&&s!==void 0&&(t[r]=s)}return t}collectImportsFromStatement(e,t,a){}};function O(n){let e=n.predicate?.subject;return(e?`${e.publisher}/${e.package_}/${e.name}`:"?")+"="+xe(n)}function xe(n){return n instanceof K?"m:"+String(n.object):n instanceof w?"s:"+String(n.object):n instanceof R?"n:"+String(n.object):n instanceof v?"b:"+String(n.object):n instanceof D?"r:"+A(n.object):n instanceof $?"e:"+A(n.object):n instanceof j?"l:["+(n.object??[]).map(A).join("|")+"]":"x"}function A(n){if(!n)return"";if(n instanceof k){let e=n.subject;return"R("+(e?`${e.publisher}/${e.package_}/${e.name}`:"")+")"}return n instanceof S?"E("+(n.statement??[]).map(O).join(";")+")":n instanceof I?"L("+String(n.value)+")":"N"}export{S as a,I as b,K as c,Z as d,M as e,Pe as f,ve as g,N as h,W as i};