@kanonak-protocol/sdk 3.58.0 → 3.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +1 -1
- package/dist/chunk-2ACBWC7K.js +1 -0
- package/dist/{chunk-CYDDQF6S.js → chunk-7JZUJ2K4.js} +1 -1
- package/dist/chunk-CA2EATJR.js +1 -0
- package/dist/{chunk-IIODYDKS.js → chunk-IUCHSPLQ.js} +1 -1
- package/dist/{chunk-ESYVKB25.js → chunk-JYUZT2JU.js} +1 -1
- package/dist/{chunk-WDQONH3P.js → chunk-KSTGTV35.js} +1 -1
- package/dist/{chunk-BSJ6PEKE.js → chunk-OIVACCMQ.js} +9 -9
- package/dist/chunk-ORFSMEMM.js +1 -0
- package/dist/{chunk-DC774EQL.js → chunk-PEUTCG3B.js} +1 -1
- package/dist/{chunk-VJT6YUWK.js → chunk-Q6QTQWR2.js} +1 -1
- package/dist/{chunk-SD5QKNBC.js → chunk-QHJ6EY3Y.js} +1 -1
- package/dist/chunk-RSIZQAFL.js +2 -0
- package/dist/chunk-SC5M74NM.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -20
- package/dist/parsing/KanonakParser.d.ts +10 -1
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/PublisherConfig.d.ts +11 -0
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/VersionUtils.d.ts +12 -0
- package/dist/resolution/assertPackageIdentity.d.ts +10 -0
- package/dist/resolution/index.d.ts +2 -1
- package/dist/resolution/index.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/server/assembleModel.d.ts +21 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +2 -2
- package/dist/server/loadResourceModel.d.ts +26 -0
- package/dist/server/renderStack.d.ts +42 -0
- package/dist/transformations/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-6SGRDFL5.js +0 -2
- package/dist/chunk-7CUTGGH3.js +0 -1
- package/dist/chunk-FQHALFRR.js +0 -1
- package/dist/chunk-MYPKSBTP.js +0 -1
package/dist/browser.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as ge,b as fe,c as me,d as C,e as E,f as d}from"./chunk-
|
|
1
|
+
import{a as ge,b as fe,c as me,d as C,e as E,f as d}from"./chunk-KSTGTV35.js";import{a as Qe}from"./chunk-IUCHSPLQ.js";import"./chunk-3NEUHF7E.js";import{a as H,c as L,d as W,e as F}from"./chunk-RSIZQAFL.js";import{a as Pe,b as we,c as he}from"./chunk-7JZUJ2K4.js";import{a as ke,b as be}from"./chunk-PEUTCG3B.js";import"./chunk-NIGFQYVA.js";import"./chunk-SC5M74NM.js";import{A as We,B as Fe,C as Ge,E as Xe,a as Ke,b as xe,c as Se,d as Re,f as De,g as Be,h as Ce,i as Ee,j as je,k as ve,l as _e,m as Ie,n as Ae,o as Te,p as Oe,q as Ve,r as $e,s as Ue,t as ze,u as Me,v as Ne,w as Je,x as He,y as qe,z as Le}from"./chunk-OIVACCMQ.js";import{c as pe}from"./chunk-Q6QTQWR2.js";import{a as Y,c as le}from"./chunk-H2LEQLVD.js";import{a as q}from"./chunk-ORFSMEMM.js";import{a as ye}from"./chunk-N224PFBI.js";import"./chunk-Q4DKP5DO.js";import{b as ue,c as de}from"./chunk-64TVBQFR.js";import{a as G,b as X,c as Q,d as ee,e as re,f as te,g as ne,h as oe,i as se,j as ie,k as ae,l as ce}from"./chunk-W6T7MOKY.js";import{a as Z}from"./chunk-FUUTGGJS.js";import{c as O,d as V,e as $,f as U,g as z,h as M,i as N,j as J}from"./chunk-2ACBWC7K.js";var j="kanonak-credentials",u="credentials",Ye=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,Ye);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
2
|
Credential storage requires IndexedDB support in your browser.`))})}async function _(){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 K(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 er(t)),o&&(s.nonce=o),await Ze(a,s,n.signingKey)}function x(n){return!n||n.length===0?!1:n.some(r=>r.toUpperCase()==="ES256")}async function Ze(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=D(s);return`${t}.${o}.${l}`}async function er(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return D(e)}function v(n){let r=new TextEncoder().encode(n);return D(r.buffer)}function D(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 rr=300*1e3,S=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=x(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=tr(),p=await nr(m),R=or(),A=sr(t.authorizationEndpoint,i,this.callbackUrl,R,p),y=await this.openAuthPopup(A,R);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!==R)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 T={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,T),{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 fetch(e);if(!t.ok)continue;let o=await t.json();return{issuer:w(o.issuer),authorizationEndpoint:w(o.authorization_endpoint),tokenEndpoint:w(o.token_endpoint),registrationEndpoint:w(o.registration_endpoint),revocationEndpoint:w(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 fetch(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)},rr),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 K(l,"POST",r));try{let m=await fetch(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 tr(){let n=new Uint8Array(32);return crypto.getRandomValues(n),B(n.buffer)}async function nr(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return B(e)}function or(){let n=new Uint8Array(16);return crypto.getRandomValues(n),B(n.buffer)}function sr(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 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(/=+$/,"")}function w(n){return typeof n=="string"?n:null}function I(n){return Array.isArray(n)?n.filter(r=>typeof r=="string"):null}export{Ne as AmbiguousReferenceRule,se as BooleanStatement,f as BrowserCredentialBackend,S as BrowserOAuthFlow,Fe as ClassDefinitionRule,Ie as ClassHierarchyCycleRule,X as DefinedKanonak,ze as DefinitionPropertyReferenceRule,fe as EdgeType,Y as EmbeddedKanonak,je as EmbeddedKanonakTypeRule,ae as EmbeddedStatement,me as GraphBuilder,F as HttpKanonakDocumentRepository,ve as ImportExistenceRule,H as InMemoryKanonakDocumentRepository,Ue as InstancePropertyReferenceRule,G as Kanonak,we as KanonakDocumentPositions,pe as KanonakObjectParser,Xe as KanonakObjectValidator,q as KanonakParser,Z as KanonakUri,ke as KanonakUriBuilder,ce as ListStatement,Ge as MarkdownLinkRule,le as MarkdownStatement,$e as NamespaceImportCycleRule,De as NamespacePrefixRule,ge as NodeType,oe as NumberStatement,He as ObjectPropertyImportRule,qe as ObjectPropertyValueValidationRule,Se as OntologyValidationError,Ke as OntologyValidationResult,Le as PropertyDomainRule,Ae as PropertyHierarchyCycleRule,Pe as PropertyMetadata,Je as PropertyRangeReferenceRule,Te as PropertyRangeRequiredRule,Ce as PropertyTypeSpecificityRule,We as PropertyValueTypeRule,L as PublisherConfigResolver,W as PublisherIndex,ee as ReferenceKanonak,ie as ReferenceStatement,Be as ResourceNamingRule,ue as ResourceResolver,ye as ResourceTypeClassifier,te as ScalarStatement,re as Statement,ne as StringStatement,Oe as SubClassOfReferenceRule,Ve as SubPropertyOfReferenceRule,Q as SubjectKanonak,Ee as SubjectKanonakTypeRequiredRule,de as TypeResolver,_e as UnresolvedReferenceRule,Re as ValidationContext,xe as ValidationSeverity,Me as XsdImportRule,x as browserServerSupportsDPoP,O as compareVersions,K as createBrowserDPoPProof,U as createVersion,Qe as findDerivation,be as findInstancesByType,$ as formatVersion,k as generateBrowserDPoPKeyPair,_ as generateBrowserDPoPKeys,E as hasValidToken,b as importDPoPKeys,M as isCompatibleVersion,C as isExpired,N as isMajorCompatible,d as normalizeHost,z as parseVersionString,he as parseWithPositions,J as pickHighestDocument,V as versionsEqual};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VersionOperator as o}from"@kanonak-protocol/types/document/models/enums";function f(e){switch(e){case"=":return o.Exact;case"~":return o.Compatible;case"^":return o.Major;case"*":return o.Any;default:return o.Compatible}}function V(e){switch(e){case o.Exact:return"=";case o.Compatible:return"~";case o.Major:return"^";case o.Any:return"*";default:return"~"}}function u(e,n){return e.major!==n.major?e.major-n.major:e.minor!==n.minor?e.minor-n.minor:e.patch-n.patch}function x(e,n){return e.major===n.major&&e.minor===n.minor&&e.patch===n.patch}function l(e){return`${e.major}.${e.minor}.${e.patch}`}function c(e,n,t){let a=`${e}.${n}.${t}`;return{major:e,minor:n,patch:t,toString:()=>a,equals:r=>r?.major===e&&r?.minor===n&&r?.patch===t,getHashCode:()=>e<<20|n<<10|t,compareTo:r=>e!==r.major?e-r.major:n!==r.minor?n-r.minor:t-r.patch}}function g(e){let n=/^(\d+)\.(\d+)\.(\d+)$/.exec(e);return n?c(Number(n[1]),Number(n[2]),Number(n[3])):null}function h(e,n){return u(e,n)>=0&&e.major===n.major&&e.minor===n.minor}function v(e,n){return n.major===0?u(e,n)>=0&&e.major===0&&e.minor===n.minor:u(e,n)>=0&&e.major===n.major}function j(e,n={}){let{requestedVersion:t}=n;if(e.length===0)return{chosen:null,alternatives:[],multipleVersionsPresent:!1,exactRequestedVersionMissing:!!t};if(t){let r=e.find(i=>{let s=i.metadata.namespace_?.version;return!!s&&l(s)===t});return r?{chosen:r,alternatives:e.filter(i=>i!==r),multipleVersionsPresent:e.length>1,exactRequestedVersionMissing:!1}:{chosen:null,alternatives:e,multipleVersionsPresent:e.length>1,exactRequestedVersionMissing:!0}}if(e.length===1)return{chosen:e[0],alternatives:[],multipleVersionsPresent:!1,exactRequestedVersionMissing:!1};let a=[...e].sort((r,i)=>{let s=r.metadata.namespace_?.version,m=i.metadata.namespace_?.version;return!s&&!m?0:s?m?u(m,s):-1:1});return{chosen:a[0],alternatives:a.slice(1),multipleVersionsPresent:!0,exactRequestedVersionMissing:!1}}export{f as a,V as b,u as c,x as d,l as e,c as f,g,h,v as i,j};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as V}from"./chunk-
|
|
1
|
+
import{b as V}from"./chunk-Q6QTQWR2.js";import{a as E}from"./chunk-ORFSMEMM.js";var L=class{propertyUri;propertyType;range;rangeUri;isImported;definedInNamespace};import{parseDocument as O,LineCounter as R,isMap as h,isPair as f,isScalar as g,isSeq as I}from"yaml";var K=class i{entities=new Map;entityBlocks=new Map;properties=new Map;propertyValues=new Map;valueListItems=new Map;importPackages=new Map;nestedKeys=new Map;nestedValues=new Map;static fromContent(e){let t=new i,n=new R,r=O(e,{lineCounter:n});if(r.errors.length>0||!h(r.contents))return t;N(r.contents,[],n,t);for(let o of r.contents.items){if(!f(o)||!g(o.key))continue;let a=String(o.key.value),u=o.key.range;if(!u)continue;t.entities.set(a,d(u,n));let s=o.value,c=s&&typeof s=="object"&&"range"in s?s.range:void 0;if(c?t.entityBlocks.set(a,d([u[0],u[1],c[2]],n)):t.entityBlocks.set(a,d(u,n)),h(o.value)){let k=new Map,m=new Map,l=new Map;for(let P of o.value.items){if(!f(P)||!g(P.key))continue;let b=String(P.key.value),p=P.key.range;p&&k.set(b,d(p,n));let S=P.value;if(S&&typeof S=="object"&&"range"in S&&Array.isArray(S.range)){let v=S.range;m.set(b,d(v,n))}if(I(S)){let v=[];for(let M of S.items)M&&typeof M=="object"&&"range"in M&&Array.isArray(M.range)&&v.push(d(M.range,n));v.length>0&&l.set(b,v)}}k.size>0&&t.properties.set(a,k),m.size>0&&t.propertyValues.set(a,m),l.size>0&&t.valueListItems.set(a,l);let y=j(o.value,n);y.length>0&&t.importPackages.set(a,y)}}return t}getEntityPosition(e){return this.entities.get(e)}getEntityBlockPosition(e){return this.entityBlocks.get(e)}findEntityAtPosition(e,t){for(let[n,r]of this.entityBlocks)if(w(r,e,t))return n}findPropertyAtPosition(e,t){let n=this.findEntityAtPosition(e,t);if(!n)return;let r=this.properties.get(n),o=this.propertyValues.get(n);if(!r&&!o)return{entityName:n};let a,u;if(o)for(let[s,c]of o)w(c,e,t)&&(!u||C(c,u))&&(a=s,u=c);if(r)for(let[s,c]of r)w(c,e,t)&&(!u||C(c,u))&&(a=s,u=c);return a?{entityName:n,propertyName:a}:{entityName:n}}getPropertyPosition(e,t){return this.properties.get(e)?.get(t)}getPropertyValuePosition(e,t){return this.propertyValues.get(e)?.get(t)}getImportPackages(e){return this.importPackages.get(e)??[]}getAllImportPackages(){let e=[];for(let[t,n]of this.importPackages)for(let r of n)e.push({entityName:t,entry:r});return e}findPropertySourceName(e,t){let n=this.properties.get(e);if(n){if(n.has(t))return t;for(let r of n.keys()){let o=r.lastIndexOf(".");if((o===-1?r:r.substring(o+1))===t)return r}}}getListItemPosition(e,t,n){let r=this.valueListItems.get(e)?.get(t);if(!(!r||n<0||n>=r.length))return r[n]}getNodeKeyPosition(e){return this.nestedKeys.get(JSON.stringify(e))}getNodeValuePosition(e){return this.nestedValues.get(JSON.stringify(e))}setNestedKeyPosition(e,t){this.nestedKeys.set(e,t)}setNestedValuePosition(e,t){this.nestedValues.set(e,t)}getMostSpecificPosition(e,t,n){if(e){if(t!==void 0){if(n!==void 0){let a=this.getListItemPosition(e,t,n);if(a)return a}let r=this.getPropertyValuePosition(e,t);if(r)return r;let o=this.getPropertyPosition(e,t);if(o)return o}return this.getEntityPosition(e)}}};function j(i,e){let t=[];if(!h(i))return t;let n=i.items.find(r=>f(r)&&g(r.key)&&String(r.key.value)==="imports");if(!n||!f(n)||!I(n.value))return t;for(let r of n.value.items){if(!h(r))continue;let o=r.items.find(s=>f(s)&&g(s.key)&&String(s.key.value)==="publisher");if(!o||!f(o)||!g(o.value))continue;let a=String(o.value.value),u=r.items.find(s=>f(s)&&g(s.key)&&String(s.key.value)==="packages");if(!(!u||!f(u)||!I(u.value)))for(let s of u.value.items){if(!h(s))continue;let c=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="package");if(!c||!f(c)||!g(c.value)||!c.value.range)continue;let k=String(c.value.value),m=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="version"),l=m&&f(m)&&g(m.value)?String(m.value.value):"",y=s.items.find(p=>f(p)&&g(p.key)&&String(p.key.value)==="alias"),P=y&&f(y)&&g(y.value)?String(y.value.value):void 0,b=P!==void 0?{publisher:a,package_:k,version:l,alias:P,position:d(c.value.range,e)}:{publisher:a,package_:k,version:l,position:d(c.value.range,e)};t.push(b)}}return t}function w(i,e,t){return!(e<i.line||e>i.endLine||e===i.line&&t<i.column||e===i.endLine&&t>i.endColumn)}function C(i,e){let t=i.endLine-i.line,n=e.endLine-e.line;if(t!==n)return t<n;let r=i.endLine===i.line?i.endColumn-i.column:Number.MAX_SAFE_INTEGER,o=e.endLine===e.line?e.endColumn-e.column:Number.MAX_SAFE_INTEGER;return r<o}function N(i,e,t,n){if(h(i)){for(let r of i.items){if(!f(r)||!g(r.key))continue;let o=String(r.key.value),a=[...e,o],u=JSON.stringify(a);r.key.range&&n.setNestedKeyPosition(u,d(r.key.range,t));let s=r.value,c=D(s);c&&n.setNestedValuePosition(u,d(c,t)),N(s,a,t,n)}return}if(I(i)){for(let r=0;r<i.items.length;r++){let o=i.items[r],a=[...e,r],u=JSON.stringify(a),s=D(o);s&&n.setNestedValuePosition(u,d(s,t)),N(o,a,t,n)}return}}function D(i){if(!i||typeof i!="object"||!("range"in i))return;let e=i.range;return Array.isArray(e)&&e.length>=3?e:void 0}function d(i,e){let t=e.linePos(i[0]),n=e.linePos(i[2]);return{line:t.line-1,column:t.col-1,endLine:n.line-1,endColumn:n.col-1}}function x(i,e){let n=(e??new E).parse(i),r=K.fromContent(i);return{document:n,positions:r}}function W(i,e,t,n,r){if(e<n.line||e>n.endLine||e===n.line&&t<n.column||e===n.endLine&&t>=n.endColumn)return;let o=A(r,n.line,n.column),a=A(r,n.endLine,n.endColumn);if(o<0||a<0)return;let u=r.substring(o,a),s=V(u);if(s.length!==i.links.length)return;let c=e-n.line,k=e===n.line?t-n.column:t,m=A(u,c,k);if(!(m<0))for(let l=0;l<s.length;l++){let y=s[l];if(m>=y.startOffset&&m<y.endOffset)return i.links[l]}}function A(i,e,t){let n=0,r=0;for(let o=0;o<i.length;o++){if(n===e)return Math.min(r+t,i.length);i[o]===`
|
|
2
2
|
`&&(n++,r=o+1)}return n===e?Math.min(r+t,i.length):-1}export{L as a,K as b,x as c,W as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as A,e as v}from"./chunk-RSIZQAFL.js";import{a as f}from"./chunk-ORFSMEMM.js";import{c as w,d as I,h as R,i as F}from"./chunk-2ACBWC7K.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as b}from"url";import{VersionOperator as P}from"@kanonak-protocol/types/document/models/enums";var y=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(e,t=!0,n){if(!e||e.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=c.resolve(e),this.recursive=t,this.parser=n??new f,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let e=new Set(this.documentCache.values());return Array.from(e)}async getDocumentAsync(e){await this.ensureCacheInitialized();let t=this.documentCache.get(e);if(t)return t;let n=c.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let o of[".kan.yml",".yml",".yaml"])if(!e.endsWith(o)){let s=e+o;if(t=this.documentCache.get(s),t)return t;let a=c.join(this.rootPath,s);if(t=this.documentCache.get(a),t)return t}return null}async getDocumentsByNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(o=>o.metadata.namespace_?.publisher===e&&o.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),o=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(o.length===0)return null;let s=o.filter(a=>{let r=a.metadata.namespace_.version;switch(t.versionOperator){case P.Exact:return I(r,t.version);case P.Compatible:return R(r,t.version);case P.Major:return F(r,t.version);case P.Any:return w(r,t.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((a,r)=>{let m=a.metadata.namespace_.version,l=r.metadata.namespace_.version;return w(l,m)}),s[0])}async saveDocumentAsync(e,t){let n,o=e.metadata.namespace_?.toString();if(o&&o.includes("@")&&o.includes("/")){let m=o.split("/"),l=m[0],p=m[1].replace("@","@")+".kan.yml";n=c.join(this.rootPath,l,p)}else n=c.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=c.dirname(n);await i.mkdir(s,{recursive:!0});let a=this.parser.save(e);await i.writeFile(n,a,"utf8"),o&&this.documentCache.set(o,e),this.documentCache.set(n,e);let r=c.relative(this.rootPath,n);this.documentCache.set(r,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await i.unlink(n)}catch{}let o=t.metadata.namespace_?.toString();o&&this.documentCache.delete(o),this.documentCache.delete(e),this.documentCache.delete(n);let s=c.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=[];for(let[s,a]of this.documentCache.entries()){let r=a.metadata.namespace_?.toString()||"";r.includes(e)&&r.includes(t)&&n.push([s,a])}let o=c.join(this.rootPath,e);try{let s=await i.readdir(o);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await i.unlink(c.join(o,a))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let e=new Set(this.filePathsByIdentifier.values()),t=[];for(let n of e){let o=b(n).toString(),s;for(let[m,l]of this.documentCache.entries())if(this.filePathsByIdentifier.get(m)===n&&l.metadata.namespace_){s=l.metadata.namespace_.toString();break}let a=s??c.relative(this.rootPath,n),r=this.parsingErrors.has(n);t.push({identifier:a,uri:o,hasParseError:r})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}try{return await i.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await i.access(e),t=e}catch{let n=c.join(this.rootPath,e);try{await i.access(n),t=n}catch{return null}}return b(t).toString()}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as d from"fs";var S=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(S||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;d.existsSync(e)||d.mkdirSync(e,{recursive:!0}),d.existsSync(t)||d.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as _}from"os";import{join as N}from"path";function g(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||N(_(),".kanonak","packages")}var C=class u{static createComposite(e,t,n){let o=e??g(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=g(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[],t=new Set;for(let n of this.repos)try{for(let o of await n.getAllDocumentsAsync()){let s=o.metadata?.namespace_,a=s?s.version?`${s.publisher}/${s.package_}@${s.version.major}.${s.version.minor}.${s.version.patch}`:`${s.publisher}/${s.package_}`:void 0;if(a!==void 0){if(t.has(a))continue;t.add(a)}e.push(o)}}catch{}return e}async getDocumentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentAsync(e);if(n)return n}catch{}return null}async getDocumentsByNamespaceAsync(e,t){for(let n of this.repos)try{let o=await n.getDocumentsByNamespaceAsync(e,t);if(o.length>0)return o}catch{}return[]}async saveDocumentAsync(e,t){await this.repos[0].saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.repos[0].deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.repos[0].clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){return this.repos[0].getAllDocumentReferencesAsync()}async getDocumentContentAsync(e){for(let t of this.repos)try{let n=await t.getDocumentContentAsync(e);if(n)return n}catch{}return null}async getDocumentUriAsync(e){for(let t of this.repos)try{let n=await t.getDocumentUriAsync(e);if(n)return n}catch{}return null}};import{readFileSync as B,readdirSync as H}from"fs";import{join as x}from"path";var $=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function K(u,e=[]){for(let t of H(u,{withFileTypes:!0}))t.isDirectory()?$.has(t.name)||K(x(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(x(u,t.name));return e}async function j(u,e=new f,t={}){let n=new A(e);for(let m of K(u))try{let l=e.parse(B(m,"utf-8")),h=l.metadata?.namespace_,p=h?.version;h&&p&&await n.saveDocumentAsync(l,`${h.publisher}/${h.package_}@${p.major}.${p.minor}.${p.patch}`)}catch{}let o=new y(g(),!0,e),s=new Map,a=t.httpCache??{getFromCache:(m,l,h)=>s.get(`${m}|${l}|${h}`)??null,onFetch:(m,l,h,p)=>{s.set(`${m}|${l}|${h}`,p)}},r=new v({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,S as b,k as c,g as d,C as e,D as f,K as g,j as h};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as R}from"./chunk-H2LEQLVD.js";import{
|
|
1
|
+
import{a as R}from"./chunk-H2LEQLVD.js";import{c as D,d as p,g as l,j as m,k as g,l as d}from"./chunk-W6T7MOKY.js";import{c as j,g as b}from"./chunk-2ACBWC7K.js";function te(t,n,e,r){let i=v(t);if(i.length>0){let s=h(i,n,e);return s?{transformation:s.transformation,source:"instance"}:void 0}let a=new Set,o=I(t);for(;o.length>0;){let s=o.shift(),c=_(s.subject);if(a.has(c))continue;a.add(c);let u=y(r,s.subject);if(!u)continue;let U=v(u),S=h(U,n,e);if(S)return{transformation:S.transformation,source:{publisher:s.subject.publisher,package_:s.subject.package_,name:s.subject.name}};for(let x of w(u))o.push(x)}let f={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!a.has(_(f))){let s=y(r,f);if(s){let c=v(s),u=h(c,n,e);if(u)return{transformation:u.transformation,source:f}}}}function v(t){let n=[];for(let e of t.statement)if(e instanceof d&&k(e,"kanonak.org","derivation","derivations"))for(let r of e.object??[]){if(!(r instanceof R))continue;let i=T(r);i&&n.push(i)}return n}function h(t,n,e){let r=t.filter(o=>K(o.format,n)&&K(o.variant,e));if(r.length<=1)return r[0];let i=r[0].transformation,a=r[0];for(let o of r){let f=o.transformation;if(f.publisher!==i.publisher||f.package_!==i.package_||f.name!==i.name)continue;let s=b(a.transformation.version),c=b(f.version);s&&c&&j(c,s)>0&&(a=o)}return a}function T(t){let n,e,r;for(let i of t.statement)i instanceof m?k(i,"kanonak.org","derivation","format")?n=E(i):k(i,"kanonak.org","derivation","variant")&&(e=E(i)):i instanceof g&&k(i,"kanonak.org","derivation","transformation")&&(r=P(i.object));if(!(!n||!r))return e||(e={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:n,variant:e,transformation:r}}function P(t){let n,e,r,i;for(let a of t.statement){if(!(a instanceof l))continue;let o=a.predicate?.subject?.name;o==="publisher"?n=a.object:o==="package"?e=a.object:o==="version"?r=a.object:o==="name"&&(i=a.object)}if(!(!n||!e||!r||!i))return{publisher:n,package_:e,version:r,name:i}}function I(t){let n=[];for(let e of t.statement)e instanceof m&&e.predicate?.subject?.name==="type"&&e.object instanceof p&&n.push(e.object);return n}function w(t){let n=[];for(let e of t.statement)if(e instanceof m){if(e.predicate?.subject?.name!=="subClassOf")continue;e.object instanceof p&&n.push(e.object)}else if(e instanceof d){if(e.predicate?.subject?.name!=="subClassOf")continue;for(let r of e.object??[])r instanceof p&&n.push(r)}return n}function y(t,n){for(let e of t){if(!(e instanceof D)||e.name!==n.name)continue;if((e.namespace||"").startsWith(`${n.publisher}/${n.package_}@`))return e}}function k(t,n,e,r){let i=t.predicate?.subject;return i?i.publisher===n&&i.package_===e&&i.name===r:!1}function E(t){let n=t.object.subject;return{publisher:n.publisher,package_:n.package_,name:n.name}}function K(t,n){return t.publisher===n.publisher&&t.package_===n.package_&&t.name===n.name}function _(t){return`${t.publisher}/${t.package_}/${t.name}`}export{te as a};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as _e}from"./chunk-NIGFQYVA.js";import{a as q,c as Ue}from"./chunk-H2LEQLVD.js";import{a as Pe,f as Ve,h as Be,i as we,k as on}from"./chunk-Q4DKP5DO.js";import{
|
|
1
|
+
import{a as _e}from"./chunk-NIGFQYVA.js";import{a as q,c as Ue}from"./chunk-H2LEQLVD.js";import{a as Pe,f as Ve,h as Be,i as we,k as on}from"./chunk-Q4DKP5DO.js";import{c as ie,d as O,g as Q,h as ve,i as ue,j as N,k as oe,l as W}from"./chunk-W6T7MOKY.js";import{a as sn}from"./chunk-FUUTGGJS.js";import{c as Le,g as re}from"./chunk-2ACBWC7K.js";var je="kanonak.org",un="look",Oe="core-rdf",wn={publisher:je,package_:un,name:"displayLabel"},On={publisher:je,package_:un,name:"displaySummary"},En={publisher:je,package_:Oe,name:"type"},In={publisher:je,package_:Oe,name:"subClassOf"},Un={publisher:je,package_:Oe,name:"label"},Fn={publisher:je,package_:Oe,name:"comment"},rn=new sn(je,Oe,"Resource");function A(h,e){let n=cn(h,e,wn)??Un,a=cn(h,e,On)??Fn,t=Be(e,n)??e.name,o=Be(e,a);return{label:t,summary:o}}function cn(h,e,n){let a=we(e,n);if(a)return a;let t=new Set,o=ln(e,En);for(;o.length>0;){let s=o.shift(),r=Pe(s);if(t.has(r))continue;t.add(r);let i=Ve(h,s);if(!i)continue;let c=we(i,n);if(c)return c;o.push(...ln(i,In))}if(!t.has(Pe(rn))){let s=Ve(h,rn);if(s){let r=we(s,n);if(r)return r}}}function ln(h,e){let n=we(h,e);if(n)return[n];let a=[];for(let t of on(h,e))t instanceof O&&a.push(t.subject);return a}function Ge(h,e={}){let n=h.replace(/\r\n/g,`
|
|
2
2
|
`).split(`
|
|
3
3
|
`),a=[],t=0;for(;t<n.length;){let o=n[t];if(o.trim()===""){t++;continue}let s=/^(\s*)```(\S*)\s*$/.exec(o);if(s){let c=s[2],l=[];for(t++;t<n.length&&!/^(\s*)```\s*$/.test(n[t]);)l.push(n[t]),t++;t++;let d=l.join(`
|
|
4
4
|
`),u=c&&e.highlight?e.highlight(c,d):ye(d),g=c?` class="language-${pn(c)}"`:"";a.push(`<pre class="kan-code"><code${g}>${u}</code></pre>`);continue}let r=/^(#{1,6})\s+(.*)$/.exec(o);if(r){let c=r[1].length,l=Re(r[2].trim());a.push(`<h${c}>${l}</h${c}>`),t++;continue}if(o.includes("|")&&t+1<n.length&&dn(n[t+1])){let c=He(o),l=Tn(n[t+1]);t+=2;let d=[];for(;t<n.length&&n[t].trim()!==""&&n[t].includes("|");)d.push(He(n[t])),t++;a.push(Cn(c,l,d));continue}if(/^\s*[-*]\s+/.test(o)){let c=[];for(;t<n.length&&/^\s*[-*]\s+/.test(n[t]);){let l=[n[t].replace(/^\s*[-*]\s+/,"")];for(t++;t<n.length&&n[t].trim()!==""&&!/^\s*[-*]\s+/.test(n[t])&&!/^\s*\d+\.\s+/.test(n[t]);)l.push(n[t]),t++;t<n.length&&n[t].trim()===""&&t++,c.push(`<li>${Re(l.join(" ").trim())}</li>`)}a.push(`<ul>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as R}from"./chunk-
|
|
1
|
+
import{c as R}from"./chunk-Q6QTQWR2.js";import{c as S}from"./chunk-H2LEQLVD.js";import{a as h}from"./chunk-N224PFBI.js";var E=(t=>(t.Class="Class",t.DatatypeProperty="DatatypeProperty",t.ObjectProperty="ObjectProperty",t.AnnotationProperty="AnnotationProperty",t.Instance="Instance",t.Datatype="Datatype",t.Unknown="Unknown",t))(E||{}),A=(o=>(o.InstanceOf="instanceOf",o.SubClassOf="subClassOf",o.Domain="domain",o.Range="range",o.ObjectRelationship="objectRelationship",o.SubPropertyOf="subPropertyOf",o.PropertyValue="propertyValue",o.EmbeddedLink="embeddedLink",o))(A||{}),$=class{static async buildFromRepository(n){let l=await new R().parseKanonaks(n),p=await n.getAllDocumentsAsync(),a=[],s=[],t=new Set,o=new Set,d=new Map;for(let y of l){let c=y;c.name&&(h.isClassType(c)&&t.add(c.name),(h.isObjectPropertyType(c)||h.isGenericPropertyType(c))&&o.add(c.name))}for(let y of p)for(let[c,g]of Object.entries(y.body))o.has(c)&&g?.range&&typeof g.range=="string"&&d.set(c,g.range);let u=new Map;for(let y of l){let c=y;c.name&&u.set(c.name,c)}for(let y of p){let c=y.metadata.namespace_,g=c?`${c.publisher}/${c.package_}`:"",i=c?.version?`${c.version.major}.${c.version.minor}.${c.version.patch}`:"",f=x(y);for(let[m,b]of Object.entries(y.body)){if(!b||typeof b!="object")continue;let P=u.get(m),k="Unknown";if(P){let T=P;h.isClassType(T)?k="Class":h.isObjectPropertyType(T)?k="ObjectProperty":h.isDatatypePropertyType(T)?k="DatatypeProperty":h.isAnnotationPropertyType(T)?k="AnnotationProperty":h.isDatatypeType(T)?k="Datatype":h.isGenericPropertyType(T)?k="ObjectProperty":h.isInstanceOfKnownClass(T,t)&&(k="Instance")}let j=g&&i?`${g}/${m}@${i}`:m,C={};for(let[T,O]of Object.entries(b))T!=="type"&&(typeof O!="object"||O===null)&&(C[T]=O);a.push({id:j,label:b.label??m,type:k,namespace:g,properties:C}),v(j,b,k,t,o,s,g,i,f),N(j,b,o,d,a,s,g,i,f),L(j,P,s)}}return{nodes:a,edges:s}}static buildFromDocument(n){let r=[],l=[],p=n.metadata.namespace_,a=p?.version?`${p.version.major}.${p.version.minor}.${p.version.patch}`:"",s=p?`${p.publisher}/${p.package_}`:"",t=new Set,o=new Set,d=new Map,u=x(n);for(let[g,i]of Object.entries(n.body)){let f=i?.type;f&&(K(f,u)&&t.add(g),M(f,u)&&(o.add(g),i.range&&typeof i.range=="string"&&d.set(g,i.range)))}for(let[g,i]of Object.entries(n.body)){if(!i||typeof i!="object")continue;let f=i.type,m=U(f,g,t,u),b=s&&a?`${s}/${g}@${a}`:g,P={};for(let[k,j]of Object.entries(i))k!=="type"&&(typeof j!="object"||j===null)&&(P[k]=j);r.push({id:b,label:i.label??g,type:m,namespace:s,properties:P}),v(b,i,m,t,o,l,s,a,u),N(b,i,o,d,r,l,s,a,u)}let y=new Set(r.map(g=>g.id)),c=l.filter(g=>y.has(g.source)&&y.has(g.target));return{nodes:r,edges:c}}};function x(e,n){let r=new Map;if(e.metadata?.imports)for(let[l,p]of Object.entries(e.metadata.imports))for(let a of p){let s=a.alias??a.packageName,t=a.version,o=`${t.major}.${t.minor}.${t.patch}`;r.set(s,{publisher:l,package_:a.packageName,version:o})}return r}var _={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},G=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function D(e,n){if(e.includes(".")){let r=e.indexOf("."),l=e.substring(0,r),p=e.substring(r+1),a=n.get(l);if(a)return`${a.publisher}/${a.package_}/${p}`}return null}function K(e,n){let r=D(e,n);return r?_[r]==="Class":!1}function M(e,n){let r=D(e,n);return r?G.has(r):!1}function U(e,n,r,l){if(!e||e==="Package")return"Unknown";let p=D(e,l);if(p){let s=_[p];if(s)return s;let t=p.split("/").pop()?.split("@")[0]??"";return r.has(t)?"Instance":"Unknown"}let a=e.split(".").pop()??e;return r.has(a)?"Instance":"Unknown"}var I=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function v(e,n,r,l,p,a,s,t,o){let d=n.type,u=n.subClassOf;if(u){let i=Array.isArray(u)?u:[u];for(let f of i)typeof f=="string"&&a.push({source:e,target:w(f,s,t,o),type:"subClassOf",label:"subClassOf"})}let y=n.subPropertyOf;if(y){let i=Array.isArray(y)?y:[y];for(let f of i)typeof f=="string"&&a.push({source:e,target:w(f,s,t,o),type:"subPropertyOf",label:"subPropertyOf"})}if(r==="Instance"&&d){let i=d.split(".").pop()??d;a.push({source:e,target:w(i,s,t,o),type:"instanceOf",label:"type"})}if(r==="Instance")for(let[i,f]of Object.entries(n)){if(I.has(i)||!p.has(i))continue;let m=Array.isArray(f)?f:[f];for(let b of m)typeof b=="string"&&V(b)&&a.push({source:e,target:w(b,s,t,o),type:"propertyValue",label:i,propertyId:w(i,s,t,o)})}let c=r==="ObjectProperty"||r==="DatatypeProperty",g=n.domain&&n.range;if((c||g)&&n.domain&&n.range){let i=typeof n.domain=="string"?n.domain:null,f=typeof n.range=="string"?n.range:null;i&&f&&a.push({source:w(i,s,t,o),target:w(f,s,t,o),type:"objectRelationship",label:n.label??e.split("/").pop()??"",propertyId:e})}}function N(e,n,r,l,p,a,s,t,o){for(let[d,u]of Object.entries(n)){if(I.has(d)||typeof u!="object"||u===null||Array.isArray(u))continue;let y=u,c=`${e}/${d}`,g=l.get(d),i=g?g.split(".").pop()??g:"Unknown",f={};for(let[b,P]of Object.entries(y))(typeof P!="object"||P===null)&&(f[b]=P);p.push({id:c,label:`${i} (embedded)`,type:"Instance",namespace:s,properties:f});let m=s&&t?`${s}/${d}@${t}`:d;a.push({source:e,target:c,type:"propertyValue",label:d,propertyId:r.has(d)?m:void 0}),g&&a.push({source:c,target:w(i,s,t,o),type:"instanceOf",label:"type (inferred)"}),N(c,y,r,l,p,a,s,t,o)}}function L(e,n,r){let l=n?.statement;if(Array.isArray(l))for(let p of l){if(!(p instanceof S))continue;let a=p.predicate?.subject?.name??"";for(let s of p.links){let t=s.target?.subject;if(!t)continue;let o=t.version,d=o&&typeof o.major=="number"?`@${o.major}.${o.minor}.${o.patch}`:"";r.push({source:e,target:`${t.publisher}/${t.package_}/${t.name}${d}`,type:"embeddedLink",label:a})}}}function V(e){return!(!e||e.includes(" ")||e.includes(`
|
|
2
2
|
`)||e.startsWith("http://")||e.startsWith("https://")||/^\d{4}-\d{2}/.test(e)||/^\d+(\.\d+)?$/.test(e))}function w(e,n,r,l){if(e.includes("@")&&e.includes("/"))return e;if(e.includes(".")){let p=e.indexOf("."),a=e.substring(0,p),s=e.substring(p+1);if(l){let t=l.get(a);if(t)return`${t.publisher}/${t.package_}/${s}@${t.version}`}return n&&r?`${n}/${s}@${r}`:s}return n&&r?`${n}/${e}@${r}`:e}function Y(e){if(!e.expiresAt)return!1;let n=new Date(e.expiresAt),r=300*1e3;return n.getTime()<=Date.now()+r}function Q(e){return!!e.accessToken&&!Y(e)}function X(e){let n=e.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!n)throw new Error("Publisher host cannot be empty");return n}export{E as a,A as b,$ as c,Y as d,Q as e,X as f};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{a as me,c as v}from"./chunk-VJT6YUWK.js";import{a as ae,c as pe}from"./chunk-H2LEQLVD.js";import{a as se}from"./chunk-7CUTGGH3.js";import{d as fe,f as de,g as ge}from"./chunk-N224PFBI.js";import{i as ue,l as J}from"./chunk-Q4DKP5DO.js";import{c as V}from"./chunk-FQHALFRR.js";import{a as P,b as D,c as ye}from"./chunk-64TVBQFR.js";import{c as G,k as le,l as ce}from"./chunk-W6T7MOKY.js";var A=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var R=(r=>(r.Warning="Warning",r.Error="Error",r))(R||{});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 ee=class d{resolvedDocuments=[];currentEntityPath;withPath(e){let r=new d;return r.resolvedDocuments=this.resolvedDocuments,r.currentEntityPath=e,r}};var re=class{constructor(e){this.underlying=e;this.repository=new oe(e)}underlying;repository;kanonaksPromise=null;importClosureCache=new Map;classDeclarationsCache=new Map;propertyNamesCache=new Map;allDocumentsPromise=null;getKanonaks(){return this.kanonaksPromise||(this.kanonaksPromise=new v().parseKanonaks(this.underlying)),this.kanonaksPromise}async getImportClosure(e){let r=this.importClosureCache.get(e);return r||(r=this.computeImportClosure(e),this.importClosureCache.set(e,r),r)}async getClassDeclarations(e){let r=this.classDeclarationsCache.get(e);return r||(r=this.computeClassDeclarations(e),this.classDeclarationsCache.set(e,r),r)}async getPropertyNames(e){let r=this.propertyNamesCache.get(e);return r||(r=this.computePropertyNames(e),this.propertyNamesCache.set(e,r),r)}getAllDocuments(){return this.allDocumentsPromise||(this.allDocumentsPromise=this.underlying.getAllDocumentsAsync()),this.allDocumentsPromise}async computeImportClosure(e){let r=new Set([e]),t=[e],o=await this.buildDocsByIdIndex();for(;t.length>0;){let s=t.shift(),i=o.get(s);if(i?.metadata.imports)for(let[n,l]of Object.entries(i.metadata.imports))for(let a of l){let c=await this.repository.getHighestCompatibleVersionAsync(n,a);if(!c)continue;let p=te(c);!p||r.has(p)||(r.add(p),t.push(p))}}return r}async buildDocsByIdIndex(){let e=await this.getAllDocuments(),r=new Map;for(let t of e){let o=te(t);o&&r.set(o,t)}return r}async computeClassDeclarations(e){let r=await this.findDocById(e),t=new Map;if(!r)return t;for(let[o,s]of Object.entries(r.body)){if(!he(s))continue;let i=s,n=be(i,"type");if(n==="Class"||n?.endsWith(".Class")){let l=De(i);t.set(o,l)}}return t}async computePropertyNames(e){let r=await this.findDocById(e),t=new Set;if(!r)return t;for(let[o,s]of Object.entries(r.body)){if(!he(s))continue;let n=be(s,"type");(n==="ObjectProperty"||n?.endsWith(".ObjectProperty")||n==="DatatypeProperty"||n?.endsWith(".DatatypeProperty")||n==="AnnotationProperty"||n?.endsWith(".AnnotationProperty")||n==="Property"||n?.endsWith(".Property"))&&t.add(o)}return t}async findDocById(e){let r=await this.getAllDocuments();for(let t of r)if(te(t)===e)return t}};function te(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}function he(d){return typeof d=="object"&&d!==null&&!Array.isArray(d)}function be(d,e){if(e in d)return Re(d[e]);for(let r of Object.keys(d))if(r.endsWith(`.${e}`))return Re(d[r])}function Re(d){return Array.isArray(d)?d.length>0?String(d[0]):void 0:d==null?void 0:String(d)}function De(d){let e=d.subClassOf;if(e===void 0){for(let r of Object.keys(d))if(r.endsWith(".subClassOf")){e=d[r];break}}return P(e)}var oe=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,r){let t=`${e}/${r}`,o=this.byNamespaceCache.get(t);return o||(o=this.inner.getDocumentsByNamespaceAsync(e,r),this.byNamespaceCache.set(t,o),o)}getHighestCompatibleVersionAsync(e,r){let t=r.version,o=t?`${t.major}.${t.minor}.${t.patch}`:"",s=`${e}/${r.packageName}@${r.versionOperator}:${o}`,i=this.highestVersionCache.get(s);return i||(i=this.inner.getHighestCompatibleVersionAsync(e,r),this.highestVersionCache.set(s,i),i)}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 I=class d{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 r=[];for(let[t,o]of Object.entries(e.body))o&&typeof o=="object"&&!Array.isArray(o)&&this.validateEntity(t,o,r);return r}validateEntity(e,r,t){for(let[o,s]of Object.entries(r)){let i=s?.toString()??"";if(i&&d.NAMESPACE_PREFIX_PATTERN.test(i)){let n=this.getSuggestionForPrefixedValue(i),l=e.split(".")[0],a=new g;a.ruleType=this.ruleName,a.severity="Error",a.entityName=l,a.propertyName=e,a.actualValue=o,a.expectedValue=n,a.message=`Invalid namespace prefix '${i}'. Use '${n}' without prefix.`,a.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(a)}s&&typeof s=="object"&&!Array.isArray(s)&&this.validateEntity(`${e}.${o}`,s,t)}}getSuggestionForPrefixedValue(e){let r=e.toLowerCase();if(r==="rdfs:class"||r==="owl:class")return"Class";if(r==="rdfs:property"||r==="rdf:property")return"DatatypeProperty or ObjectProperty";if(r.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var O=class d{static RESERVED_WORDS=new Set(["kanonak","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 r=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[o,s]of Object.entries(e.body)){let i=d.VALID_AUGMENTATION_PATTERN.test(o);if(!i&&!t&&d.RESERVED_WORDS.has(o.toLowerCase())){let n=new g;n.ruleType=this.ruleName,n.severity="Error",n.entityName=o,n.message=`Entity name '${o}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",r.push(n);continue}if(!i&&!d.VALID_NAME_PATTERN.test(o)){let n;/^\d/.test(o)?n="Entity names must start with a letter, not a number.":o.includes(" ")?n="Entity names cannot contain spaces. Use camelCase or underscores instead.":n="Entity names must start with a letter and contain only letters, numbers, and underscores.";let l=new g;l.ruleType=this.ruleName,l.severity="Error",l.entityName=o,l.message=`Invalid entity name '${o}'. ${n}`,l.suggestion=n,r.push(l)}s&&typeof s=="object"&&!Array.isArray(s)&&this.validatePropertyNames(o,s,r)}return r}validatePropertyNames(e,r,t){for(let o of Object.keys(r))if(!d.VALID_PROPERTIES.has(o)&&!d.VALID_PROPERTY_NAME_PATTERN.test(o)){let s=new g;s.ruleType=this.ruleName,s.severity="Warning",s.entityName=e,s.propertyName=o,s.message=`Property name '${o}' in entity '${e}' doesn't follow naming conventions.`,s.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(s)}}};var w=class d{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 r=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return r;let t=this.isPropertyDefinedAsClass(e);for(let[o,s]of Object.entries(e.body))if(s&&typeof s=="object"&&!Array.isArray(s)){let i=s,n=i.type;if(n){let l=[];if(Array.isArray(n))for(let a of n){let c=a?.toString();c&&c==="Property"&&!t&&l.push(c)}else{let a=n?.toString();a&&a==="Property"&&!t&&l.push(a)}for(let a of l){let c=this.getPropertyValue(i,"range"),p=this.determinePropertyType(c),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.entityName=o,y.propertyName="type",y.actualValue=a,y.expectedValue=p,y.message=`Invalid property type '${a}'. Use '${p}' instead.`,y.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",r.push(y)}}}return r}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":d.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,r){let t=e[r];return t?t.toString():null}isPropertyDefinedAsClass(e){let r=e.body.Property;if(r&&typeof r=="object"&&!Array.isArray(r)){let o=r.type;if(o){let s=o.toString();return s==="Class"||s.endsWith(".Class")}}return!1}};var j=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let r=[];for(let[t,o]of Object.entries(e.body)){if(typeof o!="object"||o===null||Array.isArray(o)||t.includes("."))continue;let s=o,i="type"in s,n=s.type?.toString().trim();if(!i||!n){let l=new g;l.ruleType=this.ruleName,l.severity="Error",l.entityName=t,l.propertyName="type",l.message=`Subject Kanonak '${t}' must have a 'type' property.`,l.suggestion=`Add a type statement like:
|
|
1
|
+
import{a as ue,c as v}from"./chunk-Q6QTQWR2.js";import{a as le,c as ye}from"./chunk-H2LEQLVD.js";import{a as ae}from"./chunk-ORFSMEMM.js";import{d as de,f as ge,g as he}from"./chunk-N224PFBI.js";import{i as fe,l as J}from"./chunk-Q4DKP5DO.js";import{a as P,b as D,c as me}from"./chunk-64TVBQFR.js";import{c as G,k as ce,l as pe}from"./chunk-W6T7MOKY.js";import{e as V}from"./chunk-2ACBWC7K.js";var A=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var R=(r=>(r.Warning="Warning",r.Error="Error",r))(R||{});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 te=class d{resolvedDocuments=[];currentEntityPath;withPath(e){let r=new d;return r.resolvedDocuments=this.resolvedDocuments,r.currentEntityPath=e,r}};var oe=class{constructor(e){this.underlying=e;this.repository=new ne(e)}underlying;repository;kanonaksPromise=null;importClosureCache=new Map;classDeclarationsCache=new Map;propertyNamesCache=new Map;allDocumentsPromise=null;getKanonaks(){return this.kanonaksPromise||(this.kanonaksPromise=new v().parseKanonaks(this.underlying)),this.kanonaksPromise}async getImportClosure(e){let r=this.importClosureCache.get(e);return r||(r=this.computeImportClosure(e),this.importClosureCache.set(e,r),r)}async getClassDeclarations(e){let r=this.classDeclarationsCache.get(e);return r||(r=this.computeClassDeclarations(e),this.classDeclarationsCache.set(e,r),r)}async getPropertyNames(e){let r=this.propertyNamesCache.get(e);return r||(r=this.computePropertyNames(e),this.propertyNamesCache.set(e,r),r)}getAllDocuments(){return this.allDocumentsPromise||(this.allDocumentsPromise=this.underlying.getAllDocumentsAsync()),this.allDocumentsPromise}async computeImportClosure(e){let r=new Set([e]),t=[e],o=await this.buildDocsByIdIndex();for(;t.length>0;){let s=t.shift(),i=o.get(s);if(i?.metadata.imports)for(let[n,l]of Object.entries(i.metadata.imports))for(let a of l){let c=await this.repository.getHighestCompatibleVersionAsync(n,a);if(!c)continue;let p=re(c);!p||r.has(p)||(r.add(p),t.push(p))}}return r}async buildDocsByIdIndex(){let e=await this.getAllDocuments(),r=new Map;for(let t of e){let o=re(t);o&&r.set(o,t)}return r}async computeClassDeclarations(e){let r=await this.findDocById(e),t=new Map;if(!r)return t;for(let[o,s]of Object.entries(r.body)){if(!be(s))continue;let i=s,n=Re(i,"type");if(n==="Class"||n?.endsWith(".Class")){let l=ve(i);t.set(o,l)}}return t}async computePropertyNames(e){let r=await this.findDocById(e),t=new Set;if(!r)return t;for(let[o,s]of Object.entries(r.body)){if(!be(s))continue;let n=Re(s,"type");(n==="ObjectProperty"||n?.endsWith(".ObjectProperty")||n==="DatatypeProperty"||n?.endsWith(".DatatypeProperty")||n==="AnnotationProperty"||n?.endsWith(".AnnotationProperty")||n==="Property"||n?.endsWith(".Property"))&&t.add(o)}return t}async findDocById(e){let r=await this.getAllDocuments();for(let t of r)if(re(t)===e)return t}};function re(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}function be(d){return typeof d=="object"&&d!==null&&!Array.isArray(d)}function Re(d,e){if(e in d)return ke(d[e]);for(let r of Object.keys(d))if(r.endsWith(`.${e}`))return ke(d[r])}function ke(d){return Array.isArray(d)?d.length>0?String(d[0]):void 0:d==null?void 0:String(d)}function ve(d){let e=d.subClassOf;if(e===void 0){for(let r of Object.keys(d))if(r.endsWith(".subClassOf")){e=d[r];break}}return P(e)}var ne=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,r){let t=`${e}/${r}`,o=this.byNamespaceCache.get(t);return o||(o=this.inner.getDocumentsByNamespaceAsync(e,r),this.byNamespaceCache.set(t,o),o)}getHighestCompatibleVersionAsync(e,r){let t=r.version,o=t?`${t.major}.${t.minor}.${t.patch}`:"",s=`${e}/${r.packageName}@${r.versionOperator}:${o}`,i=this.highestVersionCache.get(s);return i||(i=this.inner.getHighestCompatibleVersionAsync(e,r),this.highestVersionCache.set(s,i),i)}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 I=class d{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 r=[];for(let[t,o]of Object.entries(e.body))o&&typeof o=="object"&&!Array.isArray(o)&&this.validateEntity(t,o,r);return r}validateEntity(e,r,t){for(let[o,s]of Object.entries(r)){let i=s?.toString()??"";if(i&&d.NAMESPACE_PREFIX_PATTERN.test(i)){let n=this.getSuggestionForPrefixedValue(i),l=e.split(".")[0],a=new g;a.ruleType=this.ruleName,a.severity="Error",a.entityName=l,a.propertyName=e,a.actualValue=o,a.expectedValue=n,a.message=`Invalid namespace prefix '${i}'. Use '${n}' without prefix.`,a.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(a)}s&&typeof s=="object"&&!Array.isArray(s)&&this.validateEntity(`${e}.${o}`,s,t)}}getSuggestionForPrefixedValue(e){let r=e.toLowerCase();if(r==="rdfs:class"||r==="owl:class")return"Class";if(r==="rdfs:property"||r==="rdf:property")return"DatatypeProperty or ObjectProperty";if(r.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var O=class d{static RESERVED_WORDS=new Set(["kanonak","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 r=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[o,s]of Object.entries(e.body)){let i=d.VALID_AUGMENTATION_PATTERN.test(o);if(!i&&!t&&d.RESERVED_WORDS.has(o.toLowerCase())){let n=new g;n.ruleType=this.ruleName,n.severity="Error",n.entityName=o,n.message=`Entity name '${o}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",r.push(n);continue}if(!i&&!d.VALID_NAME_PATTERN.test(o)){let n;/^\d/.test(o)?n="Entity names must start with a letter, not a number.":o.includes(" ")?n="Entity names cannot contain spaces. Use camelCase or underscores instead.":n="Entity names must start with a letter and contain only letters, numbers, and underscores.";let l=new g;l.ruleType=this.ruleName,l.severity="Error",l.entityName=o,l.message=`Invalid entity name '${o}'. ${n}`,l.suggestion=n,r.push(l)}s&&typeof s=="object"&&!Array.isArray(s)&&this.validatePropertyNames(o,s,r)}return r}validatePropertyNames(e,r,t){for(let o of Object.keys(r))if(!d.VALID_PROPERTIES.has(o)&&!d.VALID_PROPERTY_NAME_PATTERN.test(o)){let s=new g;s.ruleType=this.ruleName,s.severity="Warning",s.entityName=e,s.propertyName=o,s.message=`Property name '${o}' in entity '${e}' doesn't follow naming conventions.`,s.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(s)}}};var w=class d{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 r=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return r;let t=this.isPropertyDefinedAsClass(e);for(let[o,s]of Object.entries(e.body))if(s&&typeof s=="object"&&!Array.isArray(s)){let i=s,n=i.type;if(n){let l=[];if(Array.isArray(n))for(let a of n){let c=a?.toString();c&&c==="Property"&&!t&&l.push(c)}else{let a=n?.toString();a&&a==="Property"&&!t&&l.push(a)}for(let a of l){let c=this.getPropertyValue(i,"range"),p=this.determinePropertyType(c),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.entityName=o,y.propertyName="type",y.actualValue=a,y.expectedValue=p,y.message=`Invalid property type '${a}'. Use '${p}' instead.`,y.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",r.push(y)}}}return r}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":d.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,r){let t=e[r];return t?t.toString():null}isPropertyDefinedAsClass(e){let r=e.body.Property;if(r&&typeof r=="object"&&!Array.isArray(r)){let o=r.type;if(o){let s=o.toString();return s==="Class"||s.endsWith(".Class")}}return!1}};var j=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let r=[];for(let[t,o]of Object.entries(e.body)){if(typeof o!="object"||o===null||Array.isArray(o)||t.includes("."))continue;let s=o,i="type"in s,n=s.type?.toString().trim();if(!i||!n){let l=new g;l.ruleType=this.ruleName,l.severity="Error",l.entityName=t,l.propertyName="type",l.message=`Subject Kanonak '${t}' must have a 'type' property.`,l.suggestion=`Add a type statement like:
|
|
2
2
|
type: Scene
|
|
3
3
|
|
|
4
|
-
Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,l.expectedValue="A valid class name (Scene, Character, Story, etc.)",r.push(l)}}return r}};var E=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,r){let t=[],o=new D(r),s=await this.buildPropertyRangeMap(e,o);for(let[i,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&await this.checkEmbeddedTypes(i,n,void 0,s,o,e,t,0);return t}pickRange(e,r,t){if(e.length===0)return;if(e.length===1)return e[0].range;let o=r.indexOf(".");if(o>0){let s=r.substring(0,o),i=e.find(n=>n.declaringAlias===s);if(i)return i.range}if(t){let s=this.localName(t),i=e.find(n=>this.localName(n.domain)===s);if(i)return i.range}return e[0].range}async checkEmbeddedTypes(e,r,t,o,s,i,n,l){if(l>0){let c=r.type;if(c!=null){let p=await this.validateEmbeddedType(e,String(c),t,s,i);p&&n.push(p)}}let a=r.type!==void 0&&r.type!==null?String(r.type):void 0;for(let[c,p]of Object.entries(r)){let y=this.localName(c),m=o.get(y),f=(m!==void 0?this.pickRange(m,c,a):void 0)??t;if(typeof p=="object"&&p!==null)if(Array.isArray(p))for(let b=0;b<p.length;b++){let h=p[b];typeof h=="object"&&h!==null&&!Array.isArray(h)&&await this.checkEmbeddedTypes(`${e}.${c}[${b}]`,h,f,o,s,i,n,l+1)}else await this.checkEmbeddedTypes(`${e}.${c}`,p,f,o,s,i,n,l+1)}}async validateEmbeddedType(e,r,t,o,s){if(r.length===0||!t)return null;let i=this.localName(r),n=this.localName(t);if(n==="Resource"||n==="Class")return null;let l=e.split(".")[0];if(i===n){let c=new g;return c.ruleType=this.ruleName,c.severity="Warning",c.entityName=l,c.propertyName=e,c.actualValue=r,c.expectedValue=t,c.message=`Embedded object at '${e}' declares 'type: ${r}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,c.suggestion=`Remove the 'type: ${r}' line, or keep it if explicitness is preferred over concision.`,c}if(await o.isSubclassOfAsync(r,t,s)||(i!==r||n!==t)&&await o.isSubclassOfAsync(i,n,s))return null;let a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=l,a.propertyName=e,a.actualValue=r,a.expectedValue=t,a.message=`Embedded object at '${e}' has 'type: ${r}', which is not a subclass of the parent property's range '${t}'.`,a.suggestion=`Either remove the 'type: ${r}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${r}' class definition so the relationship holds.`,a}localName(e){let r=e.lastIndexOf(".");return r<0||r===e.length-1?e:e.substring(r+1)}async buildPropertyRangeMap(e,r){let t=new Map,o=await r.buildEntityIndexAsync(e),s=new Map;for(let[i,n]of o){let l=n.entity.type;if(l==null)continue;let a=String(l),c=this.localName(a);if(!(c==="Property"||c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"))continue;let y=n.entity.range;if(y==null)continue;let m=String(y);if(m.length===0)continue;let u=n.entity.domain,f=u!=null?String(u):"",b=n.uri.toString(),h=s.get(b),k=i.includes(".");(!h||k&&!h.entityName.includes("."))&&s.set(b,{entityName:i,domain:f,range:m})}for(let i of s.values()){let n=this.localName(i.entityName),l=i.entityName.indexOf("."),a=l>0?i.entityName.substring(0,l):void 0,c=t.get(n)??[];c.push({domain:i.domain,range:i.range,declaringAlias:a}),t.set(n,c)}return t}};var $=class{ruleName="ImportExistence";async validateAsync(e,r){let t=[];if(!e.metadata?.imports)return t;let o=await r.getAllDocumentsAsync();for(let[s,i]of Object.entries(e.metadata.imports))for(let n of i)if(!await r.getHighestCompatibleVersionAsync(s,n)){let a=await this.determineImportErrorAsync(r,s,n,o),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=a.message,c.suggestion=a.suggestion,c.entityName=`Import: ${s}/${n.packageName}`,c.actualValue=n.toString(),c.expectedValue=a.expectedValue,t.push(c)}return t}async determineImportErrorAsync(e,r,t,o){let s=await e.getDocumentsByNamespaceAsync(r,t.packageName);if(s.length===0){let a=o.filter(m=>m.metadata.namespace_?.publisher===r).map(m=>m.metadata.namespace_.package_).filter((m,u,f)=>f.indexOf(m)===u),c=this.findSimilarPackages(t.packageName,a),p=`Import '${r}/${t.package_}' not found - package does not exist`,y=c.length>0?`Did you mean: ${c.slice(0,3).join(", ")}?`:a.length>0?`Available packages in ${r}: ${a.slice(0,5).join(", ")}`:`No packages found for publisher '${r}'. Verify the publisher name is correct.`;return{message:p,suggestion:y,expectedValue:"Existing package"}}let n=s.filter(a=>a.metadata.namespace_?.version).map(a=>a.metadata.namespace_.version.toString()).sort().join(", "),l=this.getAcceptableVersionRange(t);return{message:`Import '${r}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${n}. Required: ${l}`,expectedValue:l}}getAcceptableVersionRange(e){switch(e.versionOperator){case
|
|
4
|
+
Only embedded objects can infer type from their parent property's range. Subject Kanonaks (top-level entities) must explicitly declare their type.`,l.expectedValue="A valid class name (Scene, Character, Story, etc.)",r.push(l)}}return r}};var E=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,r){let t=[],o=new D(r),s=await this.buildPropertyRangeMap(e,o);for(let[i,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&await this.checkEmbeddedTypes(i,n,void 0,s,o,e,t,0);return t}pickRange(e,r,t){if(e.length===0)return;if(e.length===1)return e[0].range;let o=r.indexOf(".");if(o>0){let s=r.substring(0,o),i=e.find(n=>n.declaringAlias===s);if(i)return i.range}if(t){let s=this.localName(t),i=e.find(n=>this.localName(n.domain)===s);if(i)return i.range}return e[0].range}async checkEmbeddedTypes(e,r,t,o,s,i,n,l){if(l>0){let c=r.type;if(c!=null){let p=await this.validateEmbeddedType(e,String(c),t,s,i);p&&n.push(p)}}let a=r.type!==void 0&&r.type!==null?String(r.type):void 0;for(let[c,p]of Object.entries(r)){let y=this.localName(c),m=o.get(y),f=(m!==void 0?this.pickRange(m,c,a):void 0)??t;if(typeof p=="object"&&p!==null)if(Array.isArray(p))for(let b=0;b<p.length;b++){let h=p[b];typeof h=="object"&&h!==null&&!Array.isArray(h)&&await this.checkEmbeddedTypes(`${e}.${c}[${b}]`,h,f,o,s,i,n,l+1)}else await this.checkEmbeddedTypes(`${e}.${c}`,p,f,o,s,i,n,l+1)}}async validateEmbeddedType(e,r,t,o,s){if(r.length===0||!t)return null;let i=this.localName(r),n=this.localName(t);if(n==="Resource"||n==="Class")return null;let l=e.split(".")[0];if(i===n){let c=new g;return c.ruleType=this.ruleName,c.severity="Warning",c.entityName=l,c.propertyName=e,c.actualValue=r,c.expectedValue=t,c.message=`Embedded object at '${e}' declares 'type: ${r}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,c.suggestion=`Remove the 'type: ${r}' line, or keep it if explicitness is preferred over concision.`,c}if(await o.isSubclassOfAsync(r,t,s)||(i!==r||n!==t)&&await o.isSubclassOfAsync(i,n,s))return null;let a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=l,a.propertyName=e,a.actualValue=r,a.expectedValue=t,a.message=`Embedded object at '${e}' has 'type: ${r}', which is not a subclass of the parent property's range '${t}'.`,a.suggestion=`Either remove the 'type: ${r}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${r}' class definition so the relationship holds.`,a}localName(e){let r=e.lastIndexOf(".");return r<0||r===e.length-1?e:e.substring(r+1)}async buildPropertyRangeMap(e,r){let t=new Map,o=await r.buildEntityIndexAsync(e),s=new Map;for(let[i,n]of o){let l=n.entity.type;if(l==null)continue;let a=String(l),c=this.localName(a);if(!(c==="Property"||c==="DatatypeProperty"||c==="ObjectProperty"||c==="AnnotationProperty"))continue;let y=n.entity.range;if(y==null)continue;let m=String(y);if(m.length===0)continue;let u=n.entity.domain,f=u!=null?String(u):"",b=n.uri.toString(),h=s.get(b),k=i.includes(".");(!h||k&&!h.entityName.includes("."))&&s.set(b,{entityName:i,domain:f,range:m})}for(let i of s.values()){let n=this.localName(i.entityName),l=i.entityName.indexOf("."),a=l>0?i.entityName.substring(0,l):void 0,c=t.get(n)??[];c.push({domain:i.domain,range:i.range,declaringAlias:a}),t.set(n,c)}return t}};import{VersionOperator as Q}from"@kanonak-protocol/types/document/models/enums";var $=class{ruleName="ImportExistence";async validateAsync(e,r){let t=[];if(!e.metadata?.imports)return t;let o=await r.getAllDocumentsAsync();for(let[s,i]of Object.entries(e.metadata.imports))for(let n of i)if(!await r.getHighestCompatibleVersionAsync(s,n)){let a=await this.determineImportErrorAsync(r,s,n,o),c=new g;c.ruleType=this.ruleName,c.severity="Error",c.message=a.message,c.suggestion=a.suggestion,c.entityName=`Import: ${s}/${n.packageName}`,c.actualValue=n.toString(),c.expectedValue=a.expectedValue,t.push(c)}return t}async determineImportErrorAsync(e,r,t,o){let s=await e.getDocumentsByNamespaceAsync(r,t.packageName);if(s.length===0){let a=o.filter(m=>m.metadata.namespace_?.publisher===r).map(m=>m.metadata.namespace_.package_).filter((m,u,f)=>f.indexOf(m)===u),c=this.findSimilarPackages(t.packageName,a),p=`Import '${r}/${t.package_}' not found - package does not exist`,y=c.length>0?`Did you mean: ${c.slice(0,3).join(", ")}?`:a.length>0?`Available packages in ${r}: ${a.slice(0,5).join(", ")}`:`No packages found for publisher '${r}'. Verify the publisher name is correct.`;return{message:p,suggestion:y,expectedValue:"Existing package"}}let n=s.filter(a=>a.metadata.namespace_?.version).map(a=>a.metadata.namespace_.version.toString()).sort().join(", "),l=this.getAcceptableVersionRange(t);return{message:`Import '${r}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${n}. Required: ${l}`,expectedValue:l}}getAcceptableVersionRange(e){switch(e.versionOperator){case Q.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Q.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Q.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Q.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,r){if(r.length===0)return[];let t=r.filter(i=>i.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(i.toLowerCase()));if(t.length>0)return t.sort((i,n)=>i.length-n.length);let o=r.map(i=>({package:i,distance:this.levenshteinDistance(e.toLowerCase(),i.toLowerCase())})).sort((i,n)=>i.distance-n.distance),s=Math.max(3,Math.floor(e.length*.4));return o.filter(i=>i.distance<=s).map(i=>i.package)}levenshteinDistance(e,r){if(!e||e.length===0)return r?.length??0;if(!r||r.length===0)return e.length;let t=e.length,o=r.length,s=Array(t+1).fill(null).map(()=>Array(o+1).fill(0));for(let i=0;i<=t;i++)s[i][0]=i;for(let i=0;i<=o;i++)s[0][i]=i;for(let i=1;i<=t;i++)for(let n=1;n<=o;n++){let l=e[i-1]===r[n-1]?0:1;s[i][n]=Math.min(Math.min(s[i-1][n]+1,s[i][n-1]+1),s[i-1][n-1]+l)}return s[t][o]}};var S=class{ruleName="UnresolvedReference";async validateAsync(e,r){let t=[],o=new D(r),s=await o.buildEntityIndexAsync(e),i=new Set;for(let[n,l]of s.entries()){let a=l.entity.type;if(a){let c=a.toString();(c==="ObjectProperty"||c.endsWith(".ObjectProperty"))&&i.add(n)}}for(let[n,l]of Object.entries(e.body)){if(!l||typeof l!="object"||Array.isArray(l))continue;let a=l,c=this.getPropertyValue(a,"type");if(!(!c||c==="Class"||c.endsWith("Property")||c==="AnnotationProperty"))for(let[p,y]of Object.entries(a))p==="type"||p==="label"||p==="comment"||!(i.has(p)||Array.from(i).some(u=>u.endsWith(`.${p}`)))||await this.validateReferenceValue(n,p,y,e,o,t)}return t}async validateReferenceValue(e,r,t,o,s,i){if(t!=null){if(typeof t=="string")await s.resolveEntityAsync(t,o)||i.push(this.createUnresolvedReferenceError(e,r,t));else if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=t[n];typeof l=="string"&&(await s.resolveEntityAsync(l,o)||i.push(this.createUnresolvedReferenceError(e,`${r}[${n}]`,l)))}}}createUnresolvedReferenceError(e,r,t){let o=`The entity '${t}' cannot be found in the current document or any imported namespaces.
|
|
5
5
|
|
|
6
6
|
Possible solutions:
|
|
7
7
|
\u2022 Add import if the entity is defined in another namespace:
|
|
@@ -14,7 +14,7 @@ Possible solutions:
|
|
|
14
14
|
3. Ensure the imported namespace version contains this property`:`The property '${y}' is not defined in this namespace or any imported namespace.
|
|
15
15
|
1. Define '${y}' as an ObjectProperty or DatatypeProperty in this namespace, OR
|
|
16
16
|
2. Import the namespace that contains '${y}', OR
|
|
17
|
-
3. Use a qualified reference like 'alias.${y}' if already imported with an alias`,h.entityName=l,h.propertyName=y,h.actualValue=m?.toString(),h.expectedValue="A defined or imported property",o.push(h)}}}return o}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 isPropertyAvailable(e,r,t,o,s,i){if(s!==void 0&&i!==void 0){if(o===null)return s.has(t);let n=i.get(o);return n?n.has(t):!1}return await this.isPropertyAvailableInImports(e,r,t,o)}async closurePropertyNamesViaCache(e,r){let t=new Set,o=
|
|
17
|
+
3. Use a qualified reference like 'alias.${y}' if already imported with an alias`,h.entityName=l,h.propertyName=y,h.actualValue=m?.toString(),h.expectedValue="A defined or imported property",o.push(h)}}}return o}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 isPropertyAvailable(e,r,t,o,s,i){if(s!==void 0&&i!==void 0){if(o===null)return s.has(t);let n=i.get(o);return n?n.has(t):!1}return await this.isPropertyAvailableInImports(e,r,t,o)}async closurePropertyNamesViaCache(e,r){let t=new Set,o=Pe(e);if(!o)return t;let s=await r.getImportClosure(o);for(let i of s)if(i!==o)for(let n of await r.getPropertyNames(i))t.add(n);return t}async aliasClosurePropertyNamesViaCache(e,r){let t=new Map;if(!e.metadata.imports)return t;for(let[o,s]of Object.entries(e.metadata.imports))for(let i of s){if(!i.alias)continue;let n=await r.repository.getHighestCompatibleVersionAsync(o,i);if(!n)continue;let l=Pe(n);if(!l)continue;let a=await r.getImportClosure(l),c=t.get(i.alias)??new Set;for(let p of a)for(let y of await r.getPropertyNames(p))c.add(y);t.set(i.alias,c)}return t}async isPropertyAvailableInImports(e,r,t,o){if(!e.metadata.imports)return!1;for(let[s,i]of Object.entries(e.metadata.imports))for(let n of i){if(o!==null&&n.alias!==o)continue;let l=await r.getHighestCompatibleVersionAsync(s,n);if(l){let a=l.body[t];if(a&&typeof a=="object"&&!Array.isArray(a)){let y=a.type?.toString();if(this.isPropertyType(y))return!0}let c=new Set;if(await this.isPropertyAvailableInImportsRecursive(l,r,t,c))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(s&&o.has(s)||(s&&o.add(s),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=a.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isPropertyType(y))return!0}if(await this.isPropertyAvailableInImportsRecursive(a,r,t,o))return!0}}return!1}};function Pe(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}var W=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"DefinitionPropertyReference"}async validateAsync(e,r){let t=[],o=new Set;for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let l=i.type?.toString();this.isPropertyType(l)&&o.add(s)}for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let n=i,l=n.type?.toString();if(!this.isPropertyType(l)&&!this.isClassType(l))continue;for(let[a,c]of Object.entries(n)){if(!a||this.metadataKeys.has(a))continue;let p=a,y=null;if(a.includes(".")){let u=a.lastIndexOf(".");y=a.substring(0,u),p=a.substring(u+1)}if(o.has(p))continue;if(!await this.isPropertyAvailableInImports(e,r,p,y)){let u=this.isClassType(l)?"class":"property",f=new g;f.ruleType=this.ruleName,f.severity="Error",f.message=`Property '${a}' used on ${u} '${s}' is not defined or imported`,f.suggestion=y?`The property '${p}' is not found in the imported namespace with alias '${y}'.
|
|
18
18
|
1. Verify the namespace is imported with the correct alias
|
|
19
19
|
2. Check if the property name is spelled correctly
|
|
20
20
|
3. Ensure the imported namespace version contains this property`:`The property '${a}' is not defined in this namespace or any imported namespace.
|
|
@@ -29,17 +29,17 @@ ${c}`,m.expectedValue="Unambiguous reference (use namespace alias to disambiguat
|
|
|
29
29
|
2. Import the namespace that contains '${p}', OR
|
|
30
30
|
3. Use a qualified reference like 'alias.${p}' if already imported with an alias`:`For DatatypeProperty:
|
|
31
31
|
1. Use a primitive type (string, integer, boolean, dateTime, etc.), OR
|
|
32
|
-
2. If '${p}' should be a class, change property type to ObjectProperty`,u.entityName=s,u.propertyName="range",u.actualValue=p,u.expectedValue=m==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(u)}}}return t}async isTypeAvailableInImports(e,r,t){if(!e.metadata.imports)return!1;let o=null,s=t;if(t.includes(".")){let i=t.split(".",2);o=i[0],s=i[1]}for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){if(o!==null&&l.alias!==o)continue;let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=o!==null?s:t,p=a.body[c];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isValidRangeTargetType(u))return!0}let y=new Set;if(await this.isTypeAvailableInImportsRecursive(a,r,c,y))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(s&&o.has(s)||(s&&o.add(s),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=a.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isValidRangeTargetType(y))return!0}if(await this.isTypeAvailableInImportsRecursive(a,r,t,o))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var F=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,r){let t=[],o=new Map,s=new D(r);await s.buildEntityIndexAsync(e);for(let[i,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,a=!1,c=l.type;if(Array.isArray(c)){for(let p of c)if(p?.toString()==="ObjectProperty"){a=!0;break}}else c?.toString()==="ObjectProperty"&&(a=!0);if(a){let p=l.range,y=[];if(Array.isArray(p))for(let m of p){let u=m?.toString();u&&y.push(u)}else{let m=p?.toString();m&&y.push(m)}for(let m of y)this.xsdTypes.has(m)||(o.has(m)||o.set(m,[]),o.get(m).push(i))}}for(let[i,n]of o)if(!await s.resolveEntityAsync(i,e))for(let a of n){let c=new g;c.ruleType=this.ruleName,c.severity="Warning",c.message=`ObjectProperty references class '${i}' which may not be imported`,c.suggestion=`Ensure the namespace containing '${i}' is imported, or define '${i}' in this document`,c.entityName=a,c.propertyName="range",c.actualValue=i,t.push(c)}return t}};var B=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,r){let t=[],o=new D(r),s=new
|
|
32
|
+
2. If '${p}' should be a class, change property type to ObjectProperty`,u.entityName=s,u.propertyName="range",u.actualValue=p,u.expectedValue=m==="ObjectProperty"?"A defined or imported class name":"A primitive type or defined class",t.push(u)}}}return t}async isTypeAvailableInImports(e,r,t){if(!e.metadata.imports)return!1;let o=null,s=t;if(t.includes(".")){let i=t.split(".",2);o=i[0],s=i[1]}for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){if(o!==null&&l.alias!==o)continue;let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=o!==null?s:t,p=a.body[c];if(p&&typeof p=="object"&&!Array.isArray(p)){let u=p.type?.toString();if(this.isValidRangeTargetType(u))return!0}let y=new Set;if(await this.isTypeAvailableInImportsRecursive(a,r,c,y))return!0}}return!1}async isTypeAvailableInImportsRecursive(e,r,t,o){let s=e.metadata.namespace_?.toString()??"";if(s&&o.has(s)||(s&&o.add(s),!e.metadata.imports))return!1;for(let[i,n]of Object.entries(e.metadata.imports))for(let l of n){let a=await r.getHighestCompatibleVersionAsync(i,l);if(a){let c=a.body[t];if(c&&typeof c=="object"&&!Array.isArray(c)){let y=c.type?.toString();if(this.isValidRangeTargetType(y))return!0}if(await this.isTypeAvailableInImportsRecursive(a,r,t,o))return!0}}return!1}isValidRangeTargetType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}};var F=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,r){let t=[],o=new Map,s=new D(r);await s.buildEntityIndexAsync(e);for(let[i,n]of Object.entries(e.body))if(typeof n=="object"&&n!==null&&!Array.isArray(n)){let l=n,a=!1,c=l.type;if(Array.isArray(c)){for(let p of c)if(p?.toString()==="ObjectProperty"){a=!0;break}}else c?.toString()==="ObjectProperty"&&(a=!0);if(a){let p=l.range,y=[];if(Array.isArray(p))for(let m of p){let u=m?.toString();u&&y.push(u)}else{let m=p?.toString();m&&y.push(m)}for(let m of y)this.xsdTypes.has(m)||(o.has(m)||o.set(m,[]),o.get(m).push(i))}}for(let[i,n]of o)if(!await s.resolveEntityAsync(i,e))for(let a of n){let c=new g;c.ruleType=this.ruleName,c.severity="Warning",c.message=`ObjectProperty references class '${i}' which may not be imported`,c.suggestion=`Ensure the namespace containing '${i}' is imported, or define '${i}' in this document`,c.entityName=a,c.propertyName="range",c.actualValue=i,t.push(c)}return t}};var B=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"ObjectPropertyValue"}async validateAsync(e,r){let t=[],o=new D(r),s=new me(o),i=await o.buildEntityIndexAsync(e),n=await this.buildPropertyMetadataAsync(e,r,o,i);for(let[l,a]of Object.entries(e.body))typeof a=="object"&&a!==null&&!Array.isArray(a)&&await this.scanEntityForObjectProperties(a,l,"",n,o,s,e,t);return t}async scanEntityForObjectProperties(e,r,t,o,s,i,n,l){for(let[a,c]of Object.entries(e)){if(this.standardProperties.has(a))continue;let p,y=await s.resolveEntityAsync(a,n);if(y?.uri){let m=`${y.uri.publisher}/${y.uri.package_}/${y.uri.name}`;p=o.get(m)}if(!p){let m=a,u=a.lastIndexOf(".");u>0&&u<a.length-1&&(m=a.substring(u+1)),p=o.get(m)}if(p&&i.isEffectiveObjectProperty(p.propertyType,p.rangeUri)){let u=t?`${t}.${a}`:a;if(typeof c=="string"&&c.trim().length>0){let f=c.trim();if(f.includes(",")){let h=f.split(",").map(k=>k.trim()).filter(k=>k.length>0);l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${a}' has a comma-separated string value, but ObjectProperty expects a list of references`,suggestion:`Use YAML list format:
|
|
33
33
|
${a}:
|
|
34
34
|
- ${h[0]}
|
|
35
35
|
${h.slice(1).map(k=>` - ${k}`).join(`
|
|
36
|
-
`)}`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:`A single reference to ${p.range??"an entity"} OR a YAML list`});continue}let b=await s.resolveEntityAsync(f,n);if(b)p.range&&(await this.validateRangeType(b,p.range,s,n)||l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${a}' expects a ${p.range}, but '${f}' may not be a ${p.range}`,suggestion:`Ensure '${f}' is defined with appropriate type`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:p.range}));else{let h=p.range??"entity";l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${a}' references '${f}' which is not defined or imported`,suggestion:`Define '${f}' or import a namespace that contains it. Expected range: ${h}`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:"Defined or imported entity"})}}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let f=t?`${t}.${a}`:a;await this.scanEntityForObjectProperties(c,r,f,o,s,i,n,l)}else if(Array.isArray(c))for(let f=0;f<c.length;f++){let b=c[f];if(typeof b=="string"&&b.trim().length>0){let h=b.trim(),k=await s.resolveEntityAsync(h,n);if(k){if(p.range&&!await this.validateRangeType(k,p.range,s,n)){let
|
|
36
|
+
`)}`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:`A single reference to ${p.range??"an entity"} OR a YAML list`});continue}let b=await s.resolveEntityAsync(f,n);if(b)p.range&&(await this.validateRangeType(b,p.range,s,n)||l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${a}' expects a ${p.range}, but '${f}' may not be a ${p.range}`,suggestion:`Ensure '${f}' is defined with appropriate type`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:p.range}));else{let h=p.range??"entity";l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${a}' references '${f}' which is not defined or imported`,suggestion:`Define '${f}' or import a namespace that contains it. Expected range: ${h}`,entityName:r,propertyName:a,propertyPath:u,actualValue:f,expectedValue:"Defined or imported entity"})}}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let f=t?`${t}.${a}`:a;await this.scanEntityForObjectProperties(c,r,f,o,s,i,n,l)}else if(Array.isArray(c))for(let f=0;f<c.length;f++){let b=c[f];if(typeof b=="string"&&b.trim().length>0){let h=b.trim(),k=await s.resolveEntityAsync(h,n);if(k){if(p.range&&!await this.validateRangeType(k,p.range,s,n)){let ee=t?`${t}.${a}[${f}]`:`${a}[${f}]`;l.push({ruleType:this.ruleName,severity:"Warning",message:`Property '${a}' expects a ${p.range}, but '${h}' may not be a ${p.range}`,suggestion:`Ensure '${h}' is defined with appropriate type`,entityName:r,propertyName:`${a}[${f}]`,propertyPath:ee,actualValue:h,expectedValue:p.range})}}else{let se=p.range??"entity",ee=t?`${t}.${a}[${f}]`:`${a}[${f}]`;l.push({ruleType:this.ruleName,severity:"Error",message:`Property '${a}' references '${h}' which is not defined or imported`,suggestion:`Define '${h}' or import a namespace that contains it. Expected range: ${se}`,entityName:r,propertyName:`${a}[${f}]`,propertyPath:ee,actualValue:h,expectedValue:"Defined or imported entity"})}}else if(typeof b=="object"&&b!==null&&!Array.isArray(b)){let h=t?`${t}.${a}[${f}]`:`${a}[${f}]`;await this.scanEntityForObjectProperties(b,r,h,o,s,i,n,l)}}}if(typeof c=="object"&&c!==null&&!Array.isArray(c)&&!o.has(a)){let m=t?`${t}.${a}`:a;await this.scanEntityForObjectProperties(c,r,m,o,s,i,n,l)}else if(Array.isArray(c))for(let m=0;m<c.length;m++){let u=c[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=t?`${t}.${a}[${m}]`:`${a}[${m}]`;await this.scanEntityForObjectProperties(u,r,f,o,s,i,n,l)}}}}async validateRangeType(e,r,t,o){if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty","Class","Resource"]).has(r))return!0;let i=e.entity.type;if(i){let n=[];if(Array.isArray(i))for(let l of i){let a=l?.toString();a&&a.trim().length>0&&n.push(a)}else{let l=i?.toString();l&&l.trim().length>0&&n.push(l)}for(let l of n){let a=l.includes(".")?l.split(".")[1]:l;if(a===r||r==="Property"&&(a==="DatatypeProperty"||a==="ObjectProperty"||a==="AnnotationProperty")||r==="Class"&&a==="Class"||await t.isSubclassOfAsync(l,r,o))return!0}}return!1}async buildPropertyMetadataAsync(e,r,t,o){let s=new Map;for(let[i,n]of o){let l=n.entity.type;if(l){let a=[];if(Array.isArray(l))for(let y of l){let m=y?.toString();m&&m.trim().length>0&&a.push(m)}else{let y=l?.toString();y&&y.trim().length>0&&a.push(y)}let c=!1,p="Property";for(let y of a){let m=y.includes(".")?y.split(".")[1]:y;if(m==="Property"||m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty"){c=!0,p=y;break}}if(c){let y={propertyType:p},m=n.entity.range;if(m){let u=m?.toString();if(u&&u.trim().length>0){y.range=u;let f=await t.resolveEntityAsync(u,e);f&&(y.rangeUri=f.uri)}}if(s.set(i,y),n.uri){let u=`${n.uri.publisher}/${n.uri.package_}/${n.uri.name}`;s.set(u,y)}}}}return s}};var q=class{standardProperties=new Set(["type","label","comment","subClassOf","domain","range","subPropertyOf","inverseOf","sameAs","seeAlso","isDefinedBy"]);get ruleName(){return"PropertyDomain"}async validateAsync(e,r,t){let o=[],s=new Map;for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let a=l,c=this.getPropertyValue(a,"type");(c==="DatatypeProperty"||c?.endsWith(".DatatypeProperty")||c==="ObjectProperty"||c?.endsWith(".ObjectProperty")||c==="AnnotationProperty"||c?.endsWith(".AnnotationProperty"))&&s.set(n,a)}let i=t?await this.buildClassHierarchyViaCache(e,t):await this.buildCompleteClassHierarchyAsync(e,r);for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let a=l,c=this.getPropertyValue(a,"type");if(!c||c==="Class"||c.endsWith(".Class")||c.endsWith("Property")||c==="AnnotationProperty")continue;this.validateEntityProperties(a,n,c,s,i,o)}return o}async buildClassHierarchyViaCache(e,r){let t=new Map,o=Ae(e);if(!o)return t;let s=await r.getImportClosure(o);for(let i of s){let n=await r.getClassDeclarations(i);for(let[l,a]of n)a.length>0&&t.set(l,a)}return t}async buildCompleteClassHierarchyAsync(e,r){let t=new Map,o=new Set,s=async(n,l)=>{if(!o.has(l)){o.add(l);for(let[a,c]of Object.entries(n.body))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let p=c,y=this.getPropertyValue(p,"type");if(y==="Class"||y?.endsWith(".Class")){let m=p.subClassOf;if(m===void 0){for(let f of Object.keys(p))if(f.endsWith(".subClassOf")){m=p[f];break}}let u=P(m);u.length>0&&t.set(a,u)}}if(n.metadata.imports)for(let[a,c]of Object.entries(n.metadata.imports))for(let p of c)try{let y=await r.getHighestCompatibleVersionAsync(a,p);if(y){let m=`${a}/${p.packageName}@${p.version}`;await s(y,m)}}catch{}}},i=e.metadata.namespace_?.toString()??"unknown";return await s(e,i),t}validateEntityProperties(e,r,t,o,s,i){for(let[n,l]of Object.entries(e)){if(this.standardProperties.has(n))continue;let a=n,c=n.lastIndexOf(".");c>0&&c<n.length-1&&(a=n.substring(c+1));let p=o.get(a);if(!p)continue;let y=this.getPropertyValue(p,"domain");if(y){if(!this.isTypeCompatibleWithDomain(t,y,s)){let m=r.split(".")[0];i.push({ruleType:this.ruleName,severity:"Error",entityName:m,propertyName:r,actualValue:n,message:`Property '${n}' has domain '${y}' but is used on '${t}' at '${r}'`,suggestion:`Either:
|
|
37
37
|
1. Use this property only on '${y}' instances
|
|
38
38
|
2. Change the property domain to include '${t}'
|
|
39
|
-
3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let m=l,u=this.getPropertyValue(m,"type");if(u){let f=`${r}.${n}`;this.validateEntityProperties(m,f,u,o,s,i)}else{let f=this.getPropertyValue(p,"range");if(f){let b=`${r}.${n}`;this.validateEntityProperties(m,b,f,o,s,i)}}}else if(Array.isArray(l))for(let m=0;m<l.length;m++){let u=l[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=u,b=this.getPropertyValue(f,"type");if(b){let h=`${r}.${n}[${m}]`;this.validateEntityProperties(f,h,b,o,s,i)}else{let h=this.getPropertyValue(p,"range");if(h){let k=`${r}.${n}[${m}]`;this.validateEntityProperties(f,k,h,o,s,i)}}}}}}}isTypeCompatibleWithDomain(e,r,t){if(e===r)return!0;let o=new Set,s=[e];for(;s.length>0;){let i=s.shift();if(o.has(i))continue;o.add(i);let n=t.get(i);if(n)for(let l of n){if(l===r)return!0;s.push(l)}}return!1}getPropertyValue(e,r){if(r in e){let t=e[r];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${r}`)){let o=e[t];return this.extractFirstValue(o)}}extractFirstValue(e){if(Array.isArray(e)){let r=[];for(let t of e)r.push(t?.toString()??"");return r.length>0?r[0]:void 0}return e?.toString()}};function
|
|
39
|
+
3. Create a different property for '${t}'`,expectedValue:`Property used on ${y} or its subclasses`})}if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let m=l,u=this.getPropertyValue(m,"type");if(u){let f=`${r}.${n}`;this.validateEntityProperties(m,f,u,o,s,i)}else{let f=this.getPropertyValue(p,"range");if(f){let b=`${r}.${n}`;this.validateEntityProperties(m,b,f,o,s,i)}}}else if(Array.isArray(l))for(let m=0;m<l.length;m++){let u=l[m];if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let f=u,b=this.getPropertyValue(f,"type");if(b){let h=`${r}.${n}[${m}]`;this.validateEntityProperties(f,h,b,o,s,i)}else{let h=this.getPropertyValue(p,"range");if(h){let k=`${r}.${n}[${m}]`;this.validateEntityProperties(f,k,h,o,s,i)}}}}}}}isTypeCompatibleWithDomain(e,r,t){if(e===r)return!0;let o=new Set,s=[e];for(;s.length>0;){let i=s.shift();if(o.has(i))continue;o.add(i);let n=t.get(i);if(n)for(let l of n){if(l===r)return!0;s.push(l)}}return!1}getPropertyValue(e,r){if(r in e){let t=e[r];return this.extractFirstValue(t)}for(let t of Object.keys(e))if(t.endsWith(`.${r}`)){let o=e[t];return this.extractFirstValue(o)}}extractFirstValue(e){if(Array.isArray(e)){let r=[];for(let t of e)r.push(t?.toString()??"");return r.length>0?r[0]:void 0}return e?.toString()}};function Ae(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}var X=class{get ruleName(){return"PropertyValueType"}async validateAsync(e,r){let t=[],o=new Map;for(let[s,i]of Object.entries(e.body))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let n=i,l=this.getPropertyValue(n,"type");(l==="DatatypeProperty"||l==="ObjectProperty")&&o.set(s,n)}for(let[s,i]of Object.entries(e.body)){if(typeof i!="object"||i===null||Array.isArray(i))continue;let n=i,l=this.getPropertyValue(n,"type");if(!(!l||l==="Class"||l.endsWith("Property")||l==="AnnotationProperty"))for(let[a,c]of Object.entries(n)){if(a==="type"||a==="label"||a==="comment")continue;let p=a,y=a.lastIndexOf(".");y>0&&y<a.length-1&&(p=a.substring(y+1));let m=o.get(p);if(!m)continue;let u=this.getPropertyValue(m,"type"),f=this.getPropertyValue(m,"range");if(u==="DatatypeProperty"){if(typeof c=="object"&&c!==null&&!Array.isArray(c)||Array.isArray(c))t.push({ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:a,message:`Property '${a}' is a DatatypeProperty with range '${f}' but instance '${s}' has a complex object value`,suggestion:`Either:
|
|
40
40
|
1. Create a class for this data and change '${a}' to an ObjectProperty
|
|
41
41
|
2. Store as a JSON string to keep it as DatatypeProperty
|
|
42
|
-
3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,c)){let b={ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:a,message:`Property '${a}' expects type '${f}' but instance '${s}' has value of type '${this.getValueTypeName(c)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(b.expectedValue=f),t.push(b)}}else if(u==="ObjectProperty")if(Array.isArray(c))for(let b=0;b<c.length;b++){let h=c[b];typeof h!="string"&&(typeof h!="object"||h===null||Array.isArray(h))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:`${a}[${b}]`,message:`ObjectProperty '${a}' array item ${b} in instance '${s}' has invalid type '${this.getValueTypeName(h)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof c!="string"&&(typeof c!="object"||c===null||Array.isArray(c))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:a,message:`ObjectProperty '${a}' in instance '${s}' has invalid value type '${this.getValueTypeName(c)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,r){switch(e?.toLowerCase()){case"string":return typeof r=="string";case"integer":case"int":return typeof r=="number"&&Number.isInteger(r);case"decimal":return typeof r=="number";case"boolean":return typeof r=="boolean";case"float":case"double":return typeof r=="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,r){if(r in e){let t=e[r];if(Array.isArray(t)){let o=[];for(let s of t)o.push(s?.toString()??"");return o.length>0?o[0]:void 0}return t?.toString()}}};var z=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,r){let t=[],o=new Map,s=new Set;for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let c=l.type;if(c)if(Array.isArray(c))for(let p of c){let y=p?.toString();if(y==="Class"||y&&y.endsWith(".Class")){s.add(n);break}}else{let p=c?.toString();(p==="Class"||p&&p.endsWith(".Class"))&&s.add(n)}}for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let a=l,c=a.type;if(c)if(Array.isArray(c)){let p=!1;for(let y of c){let m=y?.toString();if(m&&this.isDefinitionType(m)){p=!0;break}}if(!p)for(let y of c){let m=y?.toString();m&&m.trim().length>0&&(o.has(m)||o.set(m,[]),o.get(m).push(n))}}else{let p=c?.toString();p&&p.trim().length>0&&(this.isDefinitionType(p)||(o.has(p)||o.set(p,[]),o.get(p).push(n)))}this.checkNestedTypes(a,n,o,n)}let i=new D(r);for(let[n,l]of o){if(this.builtInClasses.has(n)||s.has(n))continue;let a=await i.resolveEntityAsync(n,e);if(!(a&&this.isClassEntity(a.entity))){let p=Array.from(new Set(l)).sort();for(let y of p)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${n}' is not defined or imported`,suggestion:`Define '${n}' as a Class in this document, or import a namespace that contains it`,entityName:y,propertyName:"type",actualValue:n,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,r,t,o){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let s=e,i=s.type;if(i){let n=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(i))for(let l of i){let a=l?.toString();a&&a.trim().length>0&&!n.has(a)&&(t.has(a)||t.set(a,[]),t.get(a).push(o))}else{let l=i?.toString();l&&l.trim().length>0&&!n.has(l)&&(t.has(l)||t.set(l,[]),t.get(l).push(o))}}for(let[n,l]of Object.entries(s))if(n!=="type"){let a=`${o}.${n}`;this.checkNestedTypes(l,r,t,a)}}else if(Array.isArray(e))for(let s=0;s<e.length;s++){let i=`${o}[${s}]`;this.checkNestedTypes(e[s],r,t,i)}}isClassEntity(e){if(!e)return!1;let r=e.type;if(!r)return!1;if(Array.isArray(r))for(let t of r){let o=t?.toString();if(o==="Class"||o&&o.endsWith(".Class"))return!0}else{let t=r?.toString();if(t==="Class"||t&&t.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 Y=class{ruleName="MarkdownLink";async validateAsync(e,r,t){let o=[],s;if(t){let i=await t.getKanonaks(),n=
|
|
42
|
+
3. Use separate properties instead of nesting`,expectedValue:`A simple value of type '${f}'`});else if(!this.validateDatatypeValue(f,c)){let b={ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:a,message:`Property '${a}' expects type '${f}' but instance '${s}' has value of type '${this.getValueTypeName(c)}'`,suggestion:`Provide a value of type '${f}'`,toString:()=>""};f&&(b.expectedValue=f),t.push(b)}}else if(u==="ObjectProperty")if(Array.isArray(c))for(let b=0;b<c.length;b++){let h=c[b];typeof h!="string"&&(typeof h!="object"||h===null||Array.isArray(h))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:`${a}[${b}]`,message:`ObjectProperty '${a}' array item ${b} in instance '${s}' has invalid type '${this.getValueTypeName(h)}'`,suggestion:"Array items must be references (strings) or embedded objects (dictionaries)",expectedValue:"string or object"})}else typeof c!="string"&&(typeof c!="object"||c===null||Array.isArray(c))&&t.push({ruleType:this.ruleName,severity:"Error",entityName:s,propertyName:a,message:`ObjectProperty '${a}' in instance '${s}' has invalid value type '${this.getValueTypeName(c)}'`,suggestion:"Value must be a reference (string), embedded object (dictionary), or array of these",expectedValue:`Reference to ${f} or embedded ${f} object`})}}return t}validateDatatypeValue(e,r){switch(e?.toLowerCase()){case"string":return typeof r=="string";case"integer":case"int":return typeof r=="number"&&Number.isInteger(r);case"decimal":return typeof r=="number";case"boolean":return typeof r=="boolean";case"float":case"double":return typeof r=="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,r){if(r in e){let t=e[r];if(Array.isArray(t)){let o=[];for(let s of t)o.push(s?.toString()??"");return o.length>0?o[0]:void 0}return t?.toString()}}};var z=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,r){let t=[],o=new Map,s=new Set;for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let c=l.type;if(c)if(Array.isArray(c))for(let p of c){let y=p?.toString();if(y==="Class"||y&&y.endsWith(".Class")){s.add(n);break}}else{let p=c?.toString();(p==="Class"||p&&p.endsWith(".Class"))&&s.add(n)}}for(let[n,l]of Object.entries(e.body))if(typeof l=="object"&&l!==null&&!Array.isArray(l)){let a=l,c=a.type;if(c)if(Array.isArray(c)){let p=!1;for(let y of c){let m=y?.toString();if(m&&this.isDefinitionType(m)){p=!0;break}}if(!p)for(let y of c){let m=y?.toString();m&&m.trim().length>0&&(o.has(m)||o.set(m,[]),o.get(m).push(n))}}else{let p=c?.toString();p&&p.trim().length>0&&(this.isDefinitionType(p)||(o.has(p)||o.set(p,[]),o.get(p).push(n)))}this.checkNestedTypes(a,n,o,n)}let i=new D(r);for(let[n,l]of o){if(this.builtInClasses.has(n)||s.has(n))continue;let a=await i.resolveEntityAsync(n,e);if(!(a&&this.isClassEntity(a.entity))){let p=Array.from(new Set(l)).sort();for(let y of p)t.push({ruleType:this.ruleName,severity:"Error",message:`Class '${n}' is not defined or imported`,suggestion:`Define '${n}' as a Class in this document, or import a namespace that contains it`,entityName:y,propertyName:"type",actualValue:n,expectedValue:"Defined or imported class"})}}return t}checkNestedTypes(e,r,t,o){if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let s=e,i=s.type;if(i){let n=new Set(["Class","DatatypeProperty","ObjectProperty","AnnotationProperty"]);if(Array.isArray(i))for(let l of i){let a=l?.toString();a&&a.trim().length>0&&!n.has(a)&&(t.has(a)||t.set(a,[]),t.get(a).push(o))}else{let l=i?.toString();l&&l.trim().length>0&&!n.has(l)&&(t.has(l)||t.set(l,[]),t.get(l).push(o))}}for(let[n,l]of Object.entries(s))if(n!=="type"){let a=`${o}.${n}`;this.checkNestedTypes(l,r,t,a)}}else if(Array.isArray(e))for(let s=0;s<e.length;s++){let i=`${o}[${s}]`;this.checkNestedTypes(e[s],r,t,i)}}isClassEntity(e){if(!e)return!1;let r=e.type;if(!r)return!1;if(Array.isArray(r))for(let t of r){let o=t?.toString();if(o==="Class"||o&&o.endsWith(".Class"))return!0}else{let t=r?.toString();if(t==="Class"||t&&t.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 Y=class{ruleName="MarkdownLink";async validateAsync(e,r,t){let o=[],s;if(t){let i=await t.getKanonaks(),n=Ie(e);s=n?i.filter(l=>l instanceof G&&l.namespace===n):[]}else{let i=new J(e,r);s=await new v().parseKanonaks(i)}for(let i of s)i instanceof G&&this.checkDefined(i,i.name,o);return o}checkDefined(e,r,t){for(let o of e.statement)if(o instanceof ye){let s=o.predicate.subject?.name??"(unknown)";for(let i of o.links)i.target||t.push(this.unresolvedLinkError(r,s,i.reference));for(let i of ue(o.object))t.push(this.malformedLinkError(r,s,i.snippet))}else if(o instanceof ce)this.checkDefined(o.object,r,t);else if(o instanceof pe)for(let s of o.object)s instanceof le&&this.checkDefined(s,r,t)}unresolvedLinkError(e,r,t){let o=new g;return o.ruleType=this.ruleName,o.severity="Warning",o.entityName=e,o.propertyName=r,o.actualValue=t,o.message=`Embedded link [[${t}]] in '${r}' could not be resolved`,o.expectedValue="A reference resolvable through the document's import closure",o.suggestion=`The reference '${t}' inside a markdown value cannot be found in the current document or any imported namespace.
|
|
43
43
|
|
|
44
44
|
Possible solutions:
|
|
45
45
|
\u2022 Import the package that defines '${t}' so the link can resolve
|
|
@@ -51,9 +51,9 @@ long reference across two lines in a block scalar, e.g.:
|
|
|
51
51
|
... read for [[persistent-energy-
|
|
52
52
|
shock]] held ...
|
|
53
53
|
which is parsed as literal text, not a link. Keep each [[reference]] on one
|
|
54
|
-
line (let the line run long), or check for an unterminated [[.`,o}};function
|
|
54
|
+
line (let the line run long), or check for an unterminated [[.`,o}};function Ie(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}var Ve="kanonak.org",De="look",Oe={publisher:Ve,package_:De,name:"displayLabel"},we={publisher:Ve,package_:De,name:"displaySummary"},Z=class{ruleName="DisplayLensScope";async validateAsync(e,r,t){let o=[],s;t?s=await t.getKanonaks():s=await new v().parseKanonaks(new J(e,r));let i=je(e);if(!i)return o;for(let n of s)n instanceof G&&n.namespace===i&&(this.checkLens(s,n,Oe,"displayLabel",o),this.checkLens(s,n,we,"displaySummary",o));return o}checkLens(e,r,t,o,s){let i=fe(r,t);if(!i)return;let n=[],l=de(r);if(l&&n.push(l),n.push(...he(r)),n.length===0)return;n.some(c=>ge(e,c,i).ok)||s.push(this.scopeError(r.name,o,i.name))}scopeError(e,r,t){let o=new g;return o.ruleType=this.ruleName,o.severity="Warning",o.entityName=e,o.propertyName=r,o.actualValue=t,o.message=`${r} points at '${t}', 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=`'${t}' resolves, but its domain does not cover '${e}', so the lens would silently fall back to the resource's name at render time.
|
|
55
55
|
|
|
56
56
|
Possible solutions:
|
|
57
57
|
\u2022 Point ${r} at a property declared on this class (or an ancestor / rdfs.Resource)
|
|
58
58
|
\u2022 Set the property's domain to this class if it should apply here
|
|
59
|
-
\u2022 Use rdfs.label / rdfs.comment for the universal default`,o}};function
|
|
59
|
+
\u2022 Use rdfs.label / rdfs.comment for the universal default`,o}};function je(d){let e=d.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${V(e.version)}`}var ie=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new ae,this.documentRules=[new I,new O,new w,new j],this.repositoryRules=[new E,new $,new S,new N,new C,new K,new T,new x,new M,new L,new W,new _,new U,new H,new F,new B,new q,new X,new z,new Y,new Z]}async validateAsync(e,r,t){let o=new A;for(let s of this.documentRules)try{let i=s.validate(e);this.addErrorsToResult(o,i)}catch(i){let n=new g;n.ruleType=s.ruleName,n.severity="Error",n.message=`Validation rule '${s.ruleName}' failed: ${i instanceof Error?i.message:String(i)}`,o.errors.push(n)}if(r){let s=[],i=t?.repository??r;for(let n of this.repositoryRules)try{let l=await n.validateAsync(e,i,t);this.addErrorsToResult(o,l)}catch(l){let a=l instanceof Error?l.message:String(l);s.push({ruleName:n.ruleName,cause:a})}if(s.length>0){let n=new Map;for(let{ruleName:l,cause:a}of s){let c=n.get(a);c?c.push(l):n.set(a,[l])}for(let[l,a]of n){let c=new g;c.ruleType=a[0],c.severity="Error",a.length===1?c.message=`Validation rule '${a[0]}' failed: ${l}`:c.message=`${l} (affects ${a.length} rules: ${a.join(", ")})`,o.errors.push(c)}}}return o.isValid=o.errors.length===0,o}async validateYamlAsync(e,r,t){let o=this.parser.parseWithErrors(e);if(!o.isValid){let s=new A;s.isValid=!1;for(let i of o.errors){let n=new g;n.ruleType="ParseError",n.severity="Error",n.lineNumber=i.line,n.column=i.column,n.message=i.message,i.keyName&&(n.entityName=i.keyName),i.errorType==="DuplicateKey"&&(n.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),s.errors.push(n)}return s}return await this.validateAsync(o.document,r,t)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let r=this.documentRules.findIndex(t=>t instanceof e);r>=0&&this.documentRules.splice(r,1)}removeRepositoryRule(e){let r=this.repositoryRules.findIndex(t=>t instanceof e);r>=0&&this.repositoryRules.splice(r,1)}addErrorsToResult(e,r){for(let t of r)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{A as a,R as b,g as c,te as d,oe as e,I as f,O as g,w as h,j as i,E as j,$ as k,S as l,N as m,C as n,K as o,T as p,x as q,M as r,L as s,W as t,_ as u,U as v,H as w,F as x,B as y,q as z,X as A,z as B,Y as C,Z as D,ie as E};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as y,b as g}from"./chunk-2ACBWC7K.js";import*as h from"js-yaml";var k=class{parse(e){let t=this.parseWithErrors(e);if(!t.isValid){let a=t.errors[0];throw new Error(`YAML parse error at line ${a.line}, column ${a.column}: ${a.message}`)}return t.document}parseWithErrors(e){let t=[],a;try{e=e.replace(/^\uFEFF/,"");let s=h.load(e);if(!s||typeof s!="object")return a={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:a,errors:t,isValid:!0};let r=this.extractMetadata(s),n=this.extractBody(s,r);return a={metadata:r,body:n,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:a,errors:t,isValid:!0}}catch(s){let r=s,n={message:r.message||"Unknown parse error",line:r.mark?.line??0,column:r.mark?.column??0,errorType:r.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${r.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${r.mark?.line??0}: ${r.message||"Unknown parse error"}`};return t.push(n),{document:void 0,errors:t,isValid:!1}}}save(e){let t={};if(e.metadata.namespace_){let a=e.metadata.namespace_,s={type:"Package",publisher:a.publisher};a.version&&(s.version=`${a.version.major}.${a.version.minor}.${a.version.patch}`),e.metadata.imports&&(s.imports=this.serializeImports(e.metadata.imports)),t[a.package_]=s}return Object.assign(t,e.body),h.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let t=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!t)return[];let a=[];for(let s of Object.values(t))a.push(...s);return a},enumerable:!0,configurable:!0}),e}createVersion(e,t,a){return{major:e,minor:t,patch:a,toString:()=>`${e}.${t}.${a}`,equals:r=>!r||typeof r!="object"?!1:r.major===e&&r.minor===t&&r.patch===a,getHashCode:()=>e<<20|t<<10|a,compareTo:r=>e!==r.major?e-r.major:t!==r.minor?t-r.minor:a-r.patch}}extractMetadata(e){let t=this.createEmptyMetadata();for(let[a,s]of Object.entries(e))if(s&&typeof s=="object"&&s.type==="Package"){t.type_="Package";let r=a,n=s.publisher,i=s.version?this.parseVersion(s.version):void 0;return n&&r&&(t.namespace_={publisher:n,package_:r,version:i,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:o=>!o||typeof o!="object"?!1:o.publisher===n&&o.package_===r&&(!i||!o.version||i.equals(o.version)),getHashCode:()=>{let o=0;for(let c=0;c<n.length;c++)o=(o<<5)-o+n.charCodeAt(c);for(let c=0;c<r.length;c++)o=(o<<5)-o+r.charCodeAt(c);return o|0}}),s.imports&&Array.isArray(s.imports)&&(t.imports=this.parseImportsV3(s.imports)),this.addAllImportsGetter(t)}if(e.kanonak&&typeof e.kanonak=="object"){let a=e.kanonak;return(a.publisher||a.package||a.version)&&(t.namespace_=this.parseNamespace(a)),a.imports&&typeof a.imports=="object"&&(t.imports=this.parseImportsLegacy(a.imports)),this.addAllImportsGetter(t)}return t}extractBody(e,t){let a={};for(let[s,r]of Object.entries(e))if(!(s==="kanonak"||s==="namespace"||s==="imports"))if(r&&typeof r=="object"&&r.type==="Package"){let n={};for(let[i,o]of Object.entries(r))i==="publisher"||i==="version"||i==="imports"||(n[i]=o);a[s]=n}else a[s]=r;return a}parseNamespace(e){if(typeof e=="string"){let r=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(r){let n=r[3]?this.parseVersion(r[3]):this.createVersion(1,0,0);return{publisher:r[1],package_:r[2],version:n,toString:()=>e,equals:i=>!i||typeof i!="object"?!1:i.publisher===r[1]&&i.package_===r[2]&&(!n||!i.version||n.equals(i.version)),getHashCode:()=>{let i=0;for(let o=0;o<r[1].length;o++)i=(i<<5)-i+r[1].charCodeAt(o);for(let o=0;o<r[2].length;o++)i=(i<<5)-i+r[2].charCodeAt(o);return i|0}}}}let t=e.publisher||"",a=e.package||"",s=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:t,package_:a,version:s,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:r=>!r||typeof r!="object"?!1:r.publisher===t&&r.package_===a&&(!s||!r.version||s.equals(r.version)),getHashCode:()=>{let r=0;for(let n=0;n<t.length;n++)r=(r<<5)-r+t.charCodeAt(n);for(let n=0;n<a.length;n++)r=(r<<5)-r+a.charCodeAt(n);return r|0}}}parseVersion(e){if(typeof e=="string"){let t=e.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let t={};for(let a of e)if(!(!a||typeof a!="object"))if(a.packages&&Array.isArray(a.packages)){let s=a.publisher;if(!s)throw new Error("PublisherImport requires 'publisher' property");t[s]||(t[s]=[]);for(let r of a.packages){if(!r||typeof r!="object")continue;let n=this.parseImportFromEmbeddedObject(r,s);t[s].push(n)}}else{let s=this.parseImportFromEmbeddedObject(a,a.publisher),r=s.publisher||"";t[r]||(t[r]=[]),t[r].push(s)}return t}parseImportsLegacy(e){let t={};for(let[a,s]of Object.entries(e))Array.isArray(s)&&(t[a]=s.map(r=>this.parseImport(r,a)));return t}parseImportFromEmbeddedObject(e,t){let a=e.package;if(!a)throw new Error("Import requires 'package' property");let s=e.match;if(!s)throw new Error("Import requires 'match' property");let r=e.version;if(!r)throw new Error("Import requires 'version' property");let n=this.parseVersion(r),i=this.parseVersionOperator(s),o=this.calculateMaxVersion(s,n),c=e.alias;return{package_:`${a} ${s} ${n.toString()}`,publisher:t,packageName:a,versionOperator:i,version:n,alias:c,minVersion:n,maxVersion:o,toEmbeddedObject:()=>{let m={package:a,match:s,version:n.toString()};return c&&(m.alias=c),m},toString:()=>c?`${a} ${s} ${n.toString()} as ${c}`:`${a} ${s} ${n.toString()}`}}buildImport(e,t,a,s){return this.parseImport({packageName:e,operator:t,version:a},s)}parseImport(e,t){if(typeof e=="string"){let o=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(o){let m=o[1].trim(),u=o[2],p=this.parseVersion(o[3].trim()),l=o[4].trim(),d=this.parseVersionOperator(u),v=this.calculateMaxVersion(u,p);return{package_:e,publisher:t,packageName:m,versionOperator:d,version:p,alias:l,minVersion:p,maxVersion:v,toEmbeddedObject:()=>{let f={package:m,match:u,version:p.toString()};return l&&(f.alias=l),f},toString:()=>`${m} ${u} ${p.toString()} as ${l}`}}let c=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let m=c[1].trim(),u=c[2],p=this.parseVersion(c[3].trim()),l=this.parseVersionOperator(u),d=this.calculateMaxVersion(u,p);return{package_:e,publisher:t,packageName:m,versionOperator:l,version:p,alias:void 0,minVersion:p,maxVersion:d,toEmbeddedObject:()=>({package:m,match:u,version:p.toString()}),toString:()=>`${m} ${u} ${p.toString()}`}}}let a=this.parseVersionOperator(e.operator||"~"),s=this.parseVersion(e.version||"1.0.0"),r=e.packageName||e.package||"",n=g(a),i=this.calculateMaxVersion(e.operator||"~",s);return{package_:e.package||"",publisher:t,packageName:r,versionOperator:a,version:s,alias:e.alias,minVersion:s,maxVersion:i,toEmbeddedObject:()=>{let o={package:r,match:n,version:s.toString()};return e.alias&&(o.alias=e.alias),o},toString:()=>`${r} ${n} ${s.toString()}`}}parseVersionOperator(e){return y(e)}calculateMaxVersion(e,t){switch(e){case"~":return this.createVersion(t.major,t.minor+1,0);case"^":return t.major===0?this.createVersion(0,t.minor+1,0):this.createVersion(t.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let t=[];for(let[a,s]of Object.entries(e)){let r={publisher:a,packages:s.map(n=>{let i=g(n.versionOperator),o={package:n.packageName,match:i,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(o.alias=n.alias),o})};t.push(r)}return t}};export{k as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as m}from"./chunk-FUUTGGJS.js";var f=class{resourceResolver;constructor(e){this.resourceResolver=e}async buildFromNameAsync(e,r){return(await this.resourceResolver.resolveEntityAsync(e,r))?.uri??null}buildFromName(e,r,s){if(e.includes(".")){let o=e.split("."),c=o[0],
|
|
1
|
+
import{a as m}from"./chunk-FUUTGGJS.js";var f=class{resourceResolver;constructor(e){this.resourceResolver=e}async buildFromNameAsync(e,r){return(await this.resourceResolver.resolveEntityAsync(e,r))?.uri??null}buildFromName(e,r,s){if(e.includes(".")){let o=e.split("."),c=o[0],p=o[1],a=this.findPackageNameForAlias(s,c);if(a){for(let i of r.values())if(i.entityName===p&&i.uri.package_===a)return i.uri}return null}let n=r.get(e);return n?n.uri:null}create(e,r,s,n){return new m(e,r,s,n)}findPackageNameForAlias(e,r){if(!e.metadata.imports)return null;for(let[s,n]of Object.entries(e.metadata.imports))for(let o of n)if(o.alias===r||!o.alias&&o.packageName===r)return o.packageName;return null}};async function R(t,e){let r=[],s=await t.getAllDocumentsAsync();for(let n of s){let o=n.metadata.namespace_;if(!o)continue;let c=o.publisher,p=o.package_,a=o.version?`${o.version.major}.${o.version.minor}.${o.version.patch}`:"0.0.0";for(let[i,u]of Object.entries(n.body)){if(!u||typeof u!="object")continue;let l=u.type;!l||typeof l!="string"||l!=="Package"&&d(l,e)&&r.push({entityName:i,entity:u,documentNamespace:`${c}/${p}@${a}`,publisher:c,package_:p,version:a})}}return r}function d(t,e){let r=y(t),s=y(e);return r===s}function y(t){let e=t.lastIndexOf(".");if(e!==-1)return t.substring(e+1);let r=t.lastIndexOf("/");return r!==-1?t.substring(r+1):t}export{f as a,R as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as j,b as P,c as T}from"./chunk-H2LEQLVD.js";import{a as x}from"./chunk-
|
|
1
|
+
import{a as j,b as P,c as T}from"./chunk-H2LEQLVD.js";import{a as x}from"./chunk-ORFSMEMM.js";import{b as L,c as N,i as O}from"./chunk-64TVBQFR.js";import{c as h,d as g,g as K,h as I,i as D,j as R,k as S,l as w}from"./chunk-W6T7MOKY.js";var V=/\[\[([^\[\]\n]+)\]\]/g,C=/\[\[/g,$=/```[\s\S]*?```|`[^`\n]*`/g;function B(p){let e=[];for(let t of p.matchAll($))e.push([t.index,t.index+t[0].length]);return e}function U(p){if(!p||!p.includes("[["))return[];let e=B(p),t=o=>e.some(([n,s])=>o>=n&&o<s),r=new Set(A(p).map(o=>o.startOffset)),a=[];for(let o of p.matchAll(C)){let n=o.index;if(t(n)||r.has(n))continue;let s=p.slice(n,n+48).replace(/\s+/g," ").trim();a.push({startOffset:n,snippet:s})}return a}function A(p){if(!p||!p.includes("[["))return[];let e=[];for(let a of p.matchAll($))e.push([a.index,a.index+a[0].length]);let t=a=>e.some(([o,n])=>a>=o&&a<n),r=[];for(let a of p.matchAll(V)){let o=a.index;if(t(o))continue;let n=a[1],s=n.indexOf("|"),c=(s===-1?n:n.slice(0,s)).trim();if(c.length===0)continue;let m=s===-1?"":n.slice(s+1).trim(),f={reference:c,startOffset:o,endOffset:o+a[0].length};m.length>0&&(f.displayText=m),r.push(f)}return r}var _=class{constructor(e){}async parseKanonaks(e){let t=[],r=await e.getAllDocumentsAsync(),a=new L(e),o=new N(a);for(let i of r){let u=i.metadata.namespace_?.toString()??"";for(let[y,l]of Object.entries(i.body)){let k=new h,d=this.resolveCanonicalEntity(y,i,u);k.namespace=d.namespace,k.name=d.name,k.statement=[];let b=await this.parseStatements(l,i,a,o,e);k.statement.push(...b),t.push(k)}}let n=new Map,s=new Map,c=[];for(let i of t)if(i instanceof h){let u=`${i.namespace}/${i.name}`,y=n.get(u);if(y){let l=s.get(u);for(let k of i.statement){let d=v(k);l.has(d)||(l.add(d),y.statement.push(k))}}else{let l=new Set,k=[];for(let d of i.statement){let b=v(d);l.has(b)||(l.add(b),k.push(d))}i.statement=k,s.set(u,l),n.set(u,i),c.push(i)}}else c.push(i);let m=new Set;for(let i of c)if(i instanceof h){let u=i.namespace||"",y=u.indexOf("/"),l=y>=0?u.slice(0,y):"",k=y>=0?u.slice(y+1):"",d=k.indexOf("@"),b=d>=0?k.slice(0,d):k;m.add(`${l}/${b}/${i.name}`)}let f=i=>m.has(`${i.publisher}/${i.package_}/${i.name}`);for(let i of c)i instanceof h&&this.canonicalizeStatementBuiltins(i.statement,f);return c}canonicalizeStatementBuiltins(e,t){for(let r of e){let a=r.predicate?.subject;if(O(a,t),r instanceof R)r.object instanceof g&&O(r.object.subject,t);else if(r instanceof S)r.object&&this.canonicalizeStatementBuiltins(r.object.statement,t);else if(r instanceof w)for(let o of r.object??[])o instanceof g?O(o.subject,t):o instanceof j&&this.canonicalizeStatementBuiltins(o.statement,t)}}resolveCanonicalEntity(e,t,r){if(!e.includes(".")||!t.metadata?.imports)return{namespace:r,name:e};let a=e.indexOf("."),o=e.substring(0,a),n=e.substring(a+1);for(let[s,c]of Object.entries(t.metadata.imports))for(let m of c)if((m.alias??m.packageName)===o){let i=m.version;return{namespace:`${s}/${m.packageName}@${i.major}.${i.minor}.${i.patch}`,name:n}}return{namespace:r,name:e}}async parseStatements(e,t,r,a,o){let n=[];if(typeof e!="object"||e===null||Array.isArray(e))return n;for(let[s,c]of Object.entries(e))try{let m=await this.getPropertyMetadata(s,t,r,o,a);if(!m)continue;let f=await this.parsePropertyValue(s,c,m,t,r,a);f&&n.push(f)}catch(m){console.error(`Error parsing property ${s}:`,m)}return n}async getPropertyMetadata(e,t,r,a,o){let n=await r.resolveEntityAsync(e,t);if(!n)return;let s=n.entity,c=s.type?.toString()??"",m=c.includes(".")?c.substring(c.lastIndexOf(".")+1):c;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(m))return;let i=o.getPropertyTypeClassification(c),u=s.range?.toString(),y;if(i==="ObjectProperty")y="ObjectProperty";else if(i==="DatatypeProperty")y="DatatypeProperty";else{let d=u&&u.includes(".")?u.substring(u.lastIndexOf(".")+1):u??"";(u?o.isKnownXsdDatatypeName(u):!1)||d==="Literal"?y="DatatypeProperty":y="ObjectProperty"}let l;if(u){let d=t;if(n.isImported&&n.definedInNamespace&&typeof a.getDocumentAsync=="function"){let M=await a.getDocumentAsync(n.definedInNamespace);M&&(d=M)}l=(await r.resolveEntityAsync(u,d))?.uri}return{propertyUri:n.uri.toString(),propertyType:y,range:u,rangeUri:l,isImported:n.isImported,definedInNamespace:n.definedInNamespace}}async parsePropertyValue(e,t,r,a,o,n){let s=r.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(s,t,r,a,o,n);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(s,t,r,a,o,n);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(s,t,r,a,o,n)}}async parseDatatypeValue(e,t,r,a,o,n){if(t instanceof Date)return K.parse(e,t.toISOString());if(typeof t=="string")return n.isSubstitutableDatatype(r.rangeUri)?await this.parseSubstitutableValue(e,t,a,o):K.parse(e,t);if(typeof t=="number")return I.parse(e,t);if(typeof t=="boolean"){let s=new D;return s.predicate=g.parse(e),s.object=t,s}}async parseSubstitutableValue(e,t,r,a){let o=new T;o.predicate=g.parse(e),o.object=t;for(let n of A(t)){let s=await a.resolveEntityAsync(n.reference,r),c;s&&(c=new g,c.subject=s.uri);let m={reference:n.reference,startOffset:n.startOffset,endOffset:n.endOffset};n.displayText!==void 0&&(m.displayText=n.displayText),c!==void 0&&(m.target=c),o.links.push(m)}return o}async parseObjectValue(e,t,r,a,o,n){if(typeof t=="string"){let s=await this.resolveReference(t,a,o);if(!s)return;let c=new R;return c.predicate=g.parse(e),c.object=s,c}if(typeof t=="object"&&!Array.isArray(t)){let s=new j;if(s.statement=await this.parseStatements(t,a,o,n,{}),s.statement.length>0){let f=new S;return f.predicate=g.parse(e),f.object=s,f}let c=[];for(let[f,i]of Object.entries(t))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){let u=new j;u.name=f,u.statement=await this.parseStatements(i,a,o,n,{}),c.push(u)}else if(typeof i=="string"){let u=await this.resolveReference(i,a,o);u&&c.push(u)}if(c.length>0){let f=new w;return f.predicate=g.parse(e),f.object=c,f}let m=new S;return m.predicate=g.parse(e),m.object=s,m}}async parseListValue(e,t,r,a,o,n){let s=[],c=r.propertyType==="DatatypeProperty";for(let f of t){if(c&&(typeof f=="string"||typeof f=="number"||typeof f=="boolean")){let i=new P;i.value=f,s.push(i);continue}if(c&&f instanceof Date){let i=new P;i.value=f.toISOString(),s.push(i);continue}if(typeof f=="string"){let i=await this.resolveReference(f,a,o);i&&s.push(i)}else if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let i=new j;i.statement=await this.parseStatements(f,a,o,n,{}),s.push(i)}}let m=new w;return m.predicate=g.parse(e),m.object=s,m}async resolveReference(e,t,r){let a=await r.resolveEntityAsync(e,t);if(a){let n=new g;return n.subject=a.uri,n}let o=t.metadata?.namespace_;if(o){let{KanonakUri:n}=await import("./KanonakUri-4VJGV3FN.js"),s=o.version??{major:0,minor:0,patch:0,toString:()=>"0.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};if(e.includes(".")){let m=e.indexOf("."),f=e.substring(0,m),i=e.substring(m+1);if(t.metadata?.imports){for(let[u,y]of Object.entries(t.metadata.imports))for(let l of y)if((l.alias??l.packageName)===f){let d=new g;return d.subject=new n(u,l.packageName,i,l.version),d}}}let c=new g;return c.subject=new n(o.publisher,o.package_,e,s),c}return null}async saveKanonaks(e,t){let r=new Map;for(let a of e)a instanceof h&&a.namespace&&(r.has(a.namespace)||r.set(a.namespace,[]),r.get(a.namespace).push(a));for(let[a,o]of r){let n=await this.convertKanonaksToDocument(a,o),s=`${a.split("@")[0]}.yml`;await t.saveDocumentAsync(n,s)}}async serializeToYaml(e,t){let r=e.filter(n=>n instanceof h&&n.namespace===t);if(r.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let a=await this.convertKanonaksToDocument(t,r);return new x().save(a)}async convertKanonaksToDocument(e,t){let a={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let n=[];for(let s of Object.values(this.imports))n.push(...s);return n}},body:{}},o=new Map;for(let n of t){let s={};for(let c of n.statement){let[m,f]=this.convertStatementToProperty(c);m&&f!==null&&f!==void 0&&(s[m]=f),this.collectImportsFromStatement(c,e,o)}a.body[n.name]=s}return a}convertStatementToProperty(e){if(e instanceof K)return[e.predicate.subject.name,e.object];if(e instanceof I)return[e.predicate.subject.name,e.object];if(e instanceof D)return[e.predicate.subject.name,e.object];if(e instanceof R)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof w){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof S){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let r of e)r instanceof g?t.push(r.subject.name):r instanceof j&&t.push(this.convertEmbeddedKanonakToValue(r));return t}convertEmbeddedKanonakToValue(e){let t={};for(let r of e.statement){let[a,o]=this.convertStatementToProperty(r);a&&o!==null&&o!==void 0&&(t[a]=o)}return t}collectImportsFromStatement(e,t,r){}};function v(p){let e=p.predicate?.subject;return(e?`${e.publisher}/${e.package_}/${e.name}`:"?")+"="+z(p)}function z(p){return p instanceof T?"m:"+String(p.object):p instanceof K?"s:"+String(p.object):p instanceof I?"n:"+String(p.object):p instanceof D?"b:"+String(p.object):p instanceof R?"r:"+E(p.object):p instanceof S?"e:"+E(p.object):p instanceof w?"l:["+(p.object??[]).map(E).join("|")+"]":"x"}function E(p){if(!p)return"";if(p instanceof g){let e=p.subject;return"R("+(e?`${e.publisher}/${e.package_}/${e.name}`:"")+")"}return p instanceof j?"E("+(p.statement??[]).map(v).join(";")+")":p instanceof P?"L("+String(p.value)+")":"N"}export{U as a,A as b,_ as c};
|