@kanonak-protocol/sdk 3.51.0 → 3.52.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-XWKCX5ZS.js → chunk-B7QSKW7E.js} +1 -1
- package/dist/{chunk-GQQAXZDK.js → chunk-DGR77PRS.js} +1 -1
- package/dist/{chunk-MOFATNEC.js → chunk-H673KOGN.js} +1 -1
- package/dist/{chunk-KDJYZ2YM.js → chunk-HMDTGNEA.js} +1 -1
- package/dist/{chunk-PPORQS4M.js → chunk-XHCSTAUK.js} +1 -1
- package/dist/chunk-YYFIJNSP.js +1 -0
- package/dist/index.js +1 -1
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/transformations/index.js +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-IO5RBK3J.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-B7QSKW7E.js";import{a as Qe}from"./chunk-IIODYDKS.js";import"./chunk-3NEUHF7E.js";import{a as H,b as L,c as W,d as F}from"./chunk-VHUJSHH7.js";import{a as Pe,b as we,c as he}from"./chunk-HMDTGNEA.js";import{a as ke,b as be}from"./chunk-DC774EQL.js";import"./chunk-NIGFQYVA.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-XHCSTAUK.js";import{c as pe}from"./chunk-YYFIJNSP.js";import{a as Y,c as le}from"./chunk-H2LEQLVD.js";import{a as q}from"./chunk-7CUTGGH3.js";import{a as ye}from"./chunk-N224PFBI.js";import"./chunk-Q4DKP5DO.js";import{a as O,b as V,c as $,d as U,e as z,f as M,g as N,h as J}from"./chunk-FQHALFRR.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";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};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as R}from"./chunk-
|
|
1
|
+
import{c as R}from"./chunk-YYFIJNSP.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 +1 @@
|
|
|
1
|
-
import{c as _}from"./chunk-
|
|
1
|
+
import{c as _}from"./chunk-YYFIJNSP.js";import{a as j,b as x}from"./chunk-H2LEQLVD.js";import{d as l,e as u,f as b,g as $,h as s,j as h}from"./chunk-64TVBQFR.js";import{c as S,d as O,g as I,h as T,i as g,j as v,k as L,l as q}from"./chunk-W6T7MOKY.js";var d=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let t=b(e);return this.all.has(t)?!1:(this.all.add(t),this.tripleList.push(e),P(this.byPIdx,e.p,e),P(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&P(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(b(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let t=this.byPIdx.get(e);return t?t.slice():[]}bySubjectPredicate(e,t){let r=this.bySPIdx.get(`${e}|${t}`);return r?r.slice():[]}byPredicateObject(e,t){let r=this.byPOIdx.get(`${e}|${t}`);return r?r.slice():[]}subjectsWithPredicateObject(e,t){let r=this.byPOIdx.get(`${e}|${t}`);if(!r)return[];let n=new Set;for(let a of r)n.add(a.s);return Array.from(n)}uriObjectsOf(e,t){let r=this.bySPIdx.get(`${e}|${t}`);if(!r)return[];let n=new Set;for(let a of r)a.o.kind==="uri"&&n.add(a.o.key);return Array.from(n)}hasUri(e,t,r){return this.all.has(`${e}|${t}|u:${r}`)}hasTriple(e,t,r){return this.all.has(`${e}|${t}|${$(r)}`)}};function P(o,e,t){let r=o.get(e);r?r.push(t):o.set(e,[t])}var w={name:"rdfs2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.domain)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},C={name:"rdfs3",apply(o,e){let t=!1;for(let r of o.byPredicate(e.range)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(s(i.o.key,e.type,a))&&(t=!0)}return t}},A={name:"rdfs5",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subPropertyOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.bySubjectPredicate(a,e.subPropertyOf))i.o.kind==="uri"&&o.add(s(n,e.subPropertyOf,i.o.key))&&(t=!0)}return t}},V={name:"rdfs7",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subPropertyOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(n)){let f={s:i.s,p:a,o:i.o};o.add(f)&&(t=!0)}}return t}},W={name:"rdfs9",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subClassOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},F={name:"rdfs11",apply(o,e){let t=!1;for(let r of o.byPredicate(e.subClassOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.bySubjectPredicate(a,e.subClassOf))i.o.kind==="uri"&&o.add(s(n,e.subClassOf,i.o.key))&&(t=!0)}return t}},k=[w,C,A,V,W,F];var N={name:"prp-trp",apply(o,e){let t=!1,r=o.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let n of r){let a=o.byPredicate(n);for(let i of a){if(i.o.kind!=="uri")continue;let f=i.o.key;for(let c of o.bySubjectPredicate(f,n))c.o.kind==="uri"&&i.s!==c.o.key&&o.add(s(i.s,n,c.o.key))&&(t=!0)}}return t}},D={name:"prp-symp",apply(o,e){let t=!1,r=o.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let n of r)for(let a of o.byPredicate(n))a.o.kind==="uri"&&o.add(s(a.o.key,n,a.s))&&(t=!0);return t}},z={name:"prp-inv1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.inverseOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(n))i.o.kind==="uri"&&o.add(s(i.o.key,a,i.s))&&(t=!0)}return t}},B={name:"prp-inv2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.inverseOf)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;for(let i of o.byPredicate(a))i.o.kind==="uri"&&o.add(s(i.o.key,n,i.s))&&(t=!0)}return t}},M={name:"prp-eqp1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentProperty)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(n))o.add({s:i.s,p:a,o:i.o})&&(t=!0)}return t}},G={name:"prp-eqp2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentProperty)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicate(a))o.add({s:i.s,p:n,o:i.o})&&(t=!0)}return t}},H={name:"cax-eqc1",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentClass)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,n))o.add(s(i.s,e.type,a))&&(t=!0)}return t}},J={name:"cax-eqc2",apply(o,e){let t=!1;for(let r of o.byPredicate(e.equivalentClass)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.byPredicateObject(e.type,a))o.add(s(i.s,e.type,n))&&(t=!0)}return t}},Q={name:"eq-rep-s",apply(o,e){let t=!1;for(let r of o.byPredicate(e.sameAs)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a){for(let i of o.snapshot())i.s===n&&o.add({s:a,p:i.p,o:i.o})&&(t=!0);for(let i of o.snapshot())i.s===a&&o.add({s:n,p:i.p,o:i.o})&&(t=!0)}}return t}},X={name:"eq-rep-o",apply(o,e){let t=!1;for(let r of o.byPredicate(e.sameAs)){if(r.o.kind!=="uri")continue;let n=r.s,a=r.o.key;if(n!==a)for(let i of o.snapshot())i.o.kind==="uri"&&(i.o.key===n?o.add(s(i.s,i.p,a))&&(t=!0):i.o.key===a&&o.add(s(i.s,i.p,n))&&(t=!0))}return t}},K=[N,D,z,B,M,G,H,J,Q,X];var y=class{constructor(e,t){this.store=e;this.vocabulary=t}store;vocabulary;getInstancesOfClass(e){let t=p(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,t)}getSubclasses(e){let t=p(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,t).filter(n=>n!==t)}getSuperclasses(e){let t=p(e);return this.store.uriObjectsOf(t,this.vocabulary.subClassOf).filter(r=>r!==t)}getTypesOfIndividual(e){return this.store.uriObjectsOf(p(e),this.vocabulary.type)}isInstanceOf(e,t){return this.store.hasUri(p(e),this.vocabulary.type,p(t))}triples(){return this.store.snapshot()}size(){return this.store.size()}};function p(o){return typeof o=="string"?o:u(o.publisher,o.package_,o.name)}var R=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new h,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let t=new d,n=await new _().parseKanonaks(e),a=new U;for(let c of n)if(c instanceof S){let m=Y(c);if(!m)continue;for(let E of c.statement)this.emitStatement(m,E,t,a)}let i=[...k];this.profile==="owl-rl-classification"&&i.push(...K);let f=0;for(;f<this.maxIterations;){let c=!1;for(let m of i)m.apply(t,this.vocabulary)&&(c=!0);if(!c)break;f++}return new y(t,this.vocabulary)}emitStatement(e,t,r,n){let a=Z(t);if(a){if(t instanceof I){r.add({s:e,p:a,o:{kind:"literal",lexical:t.object,datatype:"string"}});return}if(t instanceof T){r.add({s:e,p:a,o:{kind:"literal",lexical:String(t.object),datatype:"number"}});return}if(t instanceof g){r.add({s:e,p:a,o:{kind:"literal",lexical:String(t.object),datatype:"boolean"}});return}if(t instanceof v){let i=l(t.object.subject);r.add(s(e,a,i));return}if(t instanceof L){let i=n.next();r.add({s:e,p:a,o:{kind:"blank",id:i}}),this.emitEmbedded(i,t.object,r,n);return}if(t instanceof q){for(let i of t.object??[])this.emitListItem(e,a,i,r,n);return}}}emitListItem(e,t,r,n,a){if(r instanceof O)n.add(s(e,t,l(r.subject)));else if(r instanceof j){let i=a.next();n.add({s:e,p:t,o:{kind:"blank",id:i}}),this.emitEmbedded(i,r,n,a)}else if(r instanceof x){let i=typeof r.value=="number"?"number":typeof r.value=="boolean"?"boolean":"string";n.add({s:e,p:t,o:{kind:"literal",lexical:String(r.value),datatype:i}})}}emitEmbedded(e,t,r,n){let a=`_:${e}`;for(let i of t.statement)this.emitStatement(a,i,r,n)}},U=class{counter=0;next(){return`b${this.counter++}`}};function Y(o){let e=o.namespace??"",t=e.indexOf("@"),r=t===-1?e:e.substring(0,t),n=r.indexOf("/");if(n===-1)return null;let a=r.substring(0,n),i=r.substring(n+1);return!a||!i||!o.name?null:u(a,i,o.name)}function Z(o){let e=o.predicate;return e?.subject?l(e.subject):null}export{d as a,k as b,K as c,y as d,R as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as w,d as A}from"./chunk-VHUJSHH7.js";import{a as f}from"./chunk-7CUTGGH3.js";import{a as P,b as K,f as I,g as R}from"./chunk-FQHALFRR.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as F}from"url";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 0:return K(r,t.version);case 1:return I(r,t.version);case 2:return R(r,t.version);case 3:return P(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 P(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=F(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 F(t).toString()}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await i.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async o=>{try{let s=await i.readFile(o,"utf8"),a=this.parser.parse(s);return{filePath:o,document:a,error:null}}catch(s){return{filePath:o,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:o,document:s,error:a}of n){let r=c.relative(this.rootPath,o);if(s&&s.metadata.namespace_){let m=s.metadata.namespace_.toString();this.documentCache.set(m,s),this.documentCache.set(o,s),this.documentCache.set(r,s),this.filePathsByIdentifier.set(m,o),this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o)}else this.filePathsByIdentifier.set(o,o),this.filePathsByIdentifier.set(r,o);a&&this.parsingErrors.set(o,a)}}async findYamlFiles(e,t){let n=[];try{let o=await i.readdir(e,{withFileTypes:!0});for(let s of o){let a=c.join(e,s.name);if(s.isDirectory()&&t){let r=await this.findYamlFiles(a,t);n.push(...r)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as g from"fs";var b=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(b||{}),k=class{cache;workspace;constructor(e,t,n){let o=n??new f;g.existsSync(e)||g.mkdirSync(e,{recursive:!0}),g.existsSync(t)||g.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,o),this.workspace=new y(t,!0,o)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let o of t)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}for(let o of e)if(o.metadata.namespace_){let s=o.metadata.namespace_.toString();n.set(s,o)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),o=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of o)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}for(let a of n)if(a.metadata.namespace_?.version){let r=a.metadata.namespace_.version.toString();s.set(r,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as x}from"os";import{join as _}from"path";function d(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||_(x(),".kanonak","packages")}var v=class u{static createComposite(e,t,n){let o=e??d(),s=t??".";return new k(o,s,n)}static createFromEnvironment(e){let t=d(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};var D=class{repos;constructor(...e){this.repos=e}async getHighestCompatibleVersionAsync(e,t){for(let n of this.repos)try{let o=await n.getHighestCompatibleVersionAsync(e,t);if(o)return o}catch{}return null}async getAllDocumentsAsync(){let e=[];for(let t of this.repos)try{e.push(...await t.getAllDocumentsAsync())}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 N,readdirSync as B}from"fs";import{join as S}from"path";var H=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(u,e=[]){for(let t of B(u,{withFileTypes:!0}))t.isDirectory()?H.has(t.name)||C(S(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(S(u,t.name));return e}async function j(u,e=new f,t={}){let n=new w(e);for(let m of C(u))try{let l=e.parse(N(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(d(),!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 A({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,b,k as c,d,v as e,D as f,C as g,j as h};
|
|
1
|
+
import{a as w,d as A}from"./chunk-VHUJSHH7.js";import{a as f}from"./chunk-7CUTGGH3.js";import{a as P,b as K,f as I,g as R}from"./chunk-FQHALFRR.js";import*as i from"fs/promises";import*as c from"path";import{pathToFileURL as F}from"url";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 0:return K(r,t.version);case 1:return I(r,t.version);case 2:return R(r,t.version);case 3:return P(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 P(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=F(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 F(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 b=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(b||{}),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 x}from"path";function g(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||x(_(),".kanonak","packages")}var v=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 N,readdirSync as B}from"fs";import{join as S}from"path";var H=new Set(["node_modules",".kanonak",".git","_site","build",".stage"]);function C(u,e=[]){for(let t of B(u,{withFileTypes:!0}))t.isDirectory()?H.has(t.name)||C(S(u,t.name),e):t.name.endsWith(".kan.yml")&&e.push(S(u,t.name));return e}async function $(u,e=new f,t={}){let n=new w(e);for(let m of C(u))try{let l=e.parse(N(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 A({getFromCache:a.getFromCache,onFetch:a.onFetch});return new D(n,o,r)}export{y as a,b,k as c,g as d,v as e,D as f,C as g,$ as h};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as V}from"./chunk-
|
|
1
|
+
import{b as V}from"./chunk-YYFIJNSP.js";import{a as E}from"./chunk-7CUTGGH3.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};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as me,c as v}from"./chunk-IO5RBK3J.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 me,c as v}from"./chunk-YYFIJNSP.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:
|
|
2
2
|
type: Scene
|
|
3
3
|
|
|
4
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 0:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case 1:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case 2:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case 3: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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as j,b as P,c as M}from"./chunk-H2LEQLVD.js";import{a as v}from"./chunk-7CUTGGH3.js";import{b as x,c as L,i as D}from"./chunk-64TVBQFR.js";import{c as h,d as b,g as K,h as I,i as O,j as R,k as S,l as w}from"./chunk-W6T7MOKY.js";var N=/\[\[([^\[\]\n]+)\]\]/g,V=/\[\[/g,$=/```[\s\S]*?```|`[^`\n]*`/g;function C(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=C(p),t=o=>e.some(([n,s])=>o>=n&&o<s),r=new Set(T(p).map(o=>o.startOffset)),a=[];for(let o of p.matchAll(V)){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 T(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(N)){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 x(e),o=new L(a);for(let i of r){let u=i.metadata.namespace_?.toString()??"";for(let[d,l]of Object.entries(i.body)){let y=new h,k=this.resolveCanonicalEntity(d,i,u);y.namespace=k.namespace,y.name=k.name,y.statement=[];let g=await this.parseStatements(l,i,a,o,e);y.statement.push(...g),t.push(y)}}let n=new Map,s=new Map,c=[];for(let i of t)if(i instanceof h){let u=`${i.namespace}/${i.name}`,d=n.get(u);if(d){let l=s.get(u);for(let y of i.statement){let k=A(y);l.has(k)||(l.add(k),d.statement.push(y))}}else{let l=new Set,y=[];for(let k of i.statement){let g=A(k);l.has(g)||(l.add(g),y.push(k))}i.statement=y,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||"",d=u.indexOf("/"),l=d>=0?u.slice(0,d):"",y=d>=0?u.slice(d+1):"",k=y.indexOf("@"),g=k>=0?y.slice(0,k):y;m.add(`${l}/${g}/${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(D(a,t),r instanceof R)r.object instanceof b&&D(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 b?D(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(),d;if(i==="ObjectProperty")d="ObjectProperty";else if(i==="DatatypeProperty")d="DatatypeProperty";else{let k=u&&u.includes(".")?u.substring(u.lastIndexOf(".")+1):u??"";(u?o.isKnownXsdDatatypeName(u):!1)||k==="Literal"?d="DatatypeProperty":d="ObjectProperty"}let l;return u&&(l=(await r.resolveEntityAsync(u,t))?.uri),{propertyUri:n.uri.toString(),propertyType:d,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 O;return s.predicate=b.parse(e),s.object=t,s}}async parseSubstitutableValue(e,t,r,a){let o=new M;o.predicate=b.parse(e),o.object=t;for(let n of T(t)){let s=await a.resolveEntityAsync(n.reference,r),c;s&&(c=new b,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=b.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=b.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=b.parse(e),f.object=c,f}let m=new S;return m.predicate=b.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=b.parse(e),m.object=s,m}async resolveReference(e,t,r){let a=await r.resolveEntityAsync(e,t);if(a){let n=new b;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,d]of Object.entries(t.metadata.imports))for(let l of d)if((l.alias??l.packageName)===f){let k=new b;return k.subject=new n(u,l.packageName,i,l.version),k}}}let c=new b;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 v().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 O)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 b?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 A(p){let e=p.predicate?.subject;return(e?`${e.publisher}/${e.package_}/${e.name}`:"?")+"="+B(p)}function B(p){return p instanceof M?"m:"+String(p.object):p instanceof K?"s:"+String(p.object):p instanceof I?"n:"+String(p.object):p instanceof O?"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 b){let e=p.subject;return"R("+(e?`${e.publisher}/${e.package_}/${e.name}`:"")+")"}return p instanceof j?"E("+(p.statement??[]).map(A).join(";")+")":p instanceof P?"L("+String(p.value)+")":"N"}export{U as a,T as b,_ as c};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as ct,b as lt,c as dt,d as ut,e as pt}from"./chunk-
|
|
1
|
+
import{a as ct,b as lt,c as dt,d as ut,e as pt}from"./chunk-DGR77PRS.js";import{a as or,c as ar}from"./chunk-2WQR7OHH.js";import{a as at,b as it,c as st,d as b,e as S,f as i}from"./chunk-B7QSKW7E.js";import{a as nr}from"./chunk-IIODYDKS.js";import"./chunk-3NEUHF7E.js";import{a as Te,b as je,c as Le,d as Fe,e as De,f as Ue,g as Ve,h as He}from"./chunk-H673KOGN.js";import{a as Ie,b as Ne,c as Oe,d as Ae}from"./chunk-VHUJSHH7.js";import{a as ft,b as yt,c as gt,d as ht}from"./chunk-HMDTGNEA.js";import{a as kt,b as $t}from"./chunk-DC774EQL.js";import{a as Ct}from"./chunk-NIGFQYVA.js";import{A as Qt,B as er,C as tr,E as rr,a as vt,b as Et,c as Kt,d as It,e as Bt,f as Tt,g as jt,h as Lt,i as Ft,j as Dt,k as Nt,l as Ot,m as At,n as Ut,o as Vt,p as Ht,q as Mt,r as _t,s as zt,t as Gt,u as Wt,v as Jt,w as qt,x as Yt,y as Xt,z as Zt}from"./chunk-XHCSTAUK.js";import{a as tt,b as rt,c as nt}from"./chunk-YYFIJNSP.js";import{a as F,b as N,c as We}from"./chunk-H2LEQLVD.js";import{a as Be}from"./chunk-7CUTGGH3.js";import{a as ot,b as bt,c as St,d as Pt,e as Rt,f as wt,g as xt}from"./chunk-N224PFBI.js";import"./chunk-Q4DKP5DO.js";import{a as Pe,b as Re,c as we,d as xe,e as $e,f as ve,g as Ee,h as Ke}from"./chunk-FQHALFRR.js";import{b as Je,c as qe,d as Ye,e as Xe,f as Ze,h as Qe,j as et}from"./chunk-64TVBQFR.js";import{a as Me,b as j,c as L,d as D,e as ze,f as Ge,g as O,h as A,i as U,j as V,k as H,l as M}from"./chunk-W6T7MOKY.js";import{a as _e}from"./chunk-FUUTGGJS.js";import{a as mt}from"./chunk-ODIECDN7.js";import{VersionOperator as yo}from"@kanonak-protocol/types/document/models/enums";import{existsSync as Rr,readFileSync as wr}from"fs";import{homedir as xr}from"os";import{join as $r}from"path";import{execFile as ir}from"child_process";import{promisify as sr}from"util";var C=sr(ir),P="kanonak",R="/usr/bin/security",p=class{async get(e){let r=i(e);try{let{stdout:n}=await C(R,["find-generic-password","-s",P,"-a",r,"-w"],{timeout:1e4});try{return JSON.parse(n.trim())}catch{throw new Error(`Stored credential for '${r}' is corrupted (not valid JSON).
|
|
2
2
|
Run 'kanonak logout ${r}' then 'kanonak login ${r}' to fix.`)}}catch(n){if(X(n,44))return null;throw new Error(`macOS Keychain read failed for '${r}': ${w(n)}
|
|
3
3
|
The Keychain may be locked or inaccessible.
|
|
4
4
|
Try unlocking it via Keychain Access.app or running 'security unlock-keychain'.`)}}async store(e,r){let n=i(e),o=JSON.stringify(r);try{await C(R,["add-generic-password","-s",P,"-a",n,"-U","-w",o],{timeout:1e4})}catch(a){throw new Error(`macOS Keychain write failed for '${n}': ${w(a)}
|
package/dist/parsing/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as c,b as d,c as e,d as f}from"../chunk-
|
|
1
|
+
import{a as c,b as d,c as e,d as f}from"../chunk-HMDTGNEA.js";import{c as b}from"../chunk-YYFIJNSP.js";import"../chunk-H2LEQLVD.js";import{a}from"../chunk-7CUTGGH3.js";import"../chunk-64TVBQFR.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";export{d as KanonakDocumentPositions,b as KanonakObjectParser,a as KanonakParser,c as PropertyMetadata,f as findMarkdownLinkAt,e as parseWithPositions};
|
package/dist/reasoning/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as g,b as h,c as i,d as j,e as k}from"../chunk-
|
|
1
|
+
import{a as g,b as h,c as i,d as j,e as k}from"../chunk-DGR77PRS.js";import"../chunk-YYFIJNSP.js";import"../chunk-H2LEQLVD.js";import"../chunk-7CUTGGH3.js";import{d as a,e as b,f as c,h as d,i as e,j as f}from"../chunk-64TVBQFR.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";export{f as KanonakVocabulary,i as OWL_RL_CLASSIFICATION_RULES,h as RDFS_RULES,k as Reasoner,j as ReasoningResult,g as TripleStore,e as canonicalizeBuiltinUri,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b,b as c,c as d,d as e,e as f,f as j,g as k,h as l}from"../chunk-
|
|
1
|
+
import{a as b,b as c,c as d,d as e,e as f,f as j,g as k,h as l}from"../chunk-H673KOGN.js";import{a,b as g,c as h,d as i}from"../chunk-VHUJSHH7.js";import"../chunk-7CUTGGH3.js";import"../chunk-FQHALFRR.js";export{d as CompositeKanonakDocumentRepository,c as DocumentLocation,b as FileSystemKanonakDocumentRepository,i as HttpKanonakDocumentRepository,a as InMemoryKanonakDocumentRepository,j as LocalFirstRepository,g as PublisherConfigResolver,h as PublisherIndex,f as RepositoryFactory,l as buildLocalFirstRepository,k as collectKanonakFiles,e as getGlobalCachePath};
|
package/dist/server/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{c as O}from"../chunk-2WQR7OHH.js";import"../chunk-3NEUHF7E.js";import{a as P,d as _,f as F,g as N}from"../chunk-
|
|
1
|
+
import{c as O}from"../chunk-2WQR7OHH.js";import"../chunk-3NEUHF7E.js";import{a as P,d as _,f as F,g as N}from"../chunk-H673KOGN.js";import{a as V,d as K}from"../chunk-VHUJSHH7.js";import{a as L}from"../chunk-NIGFQYVA.js";import{c as D}from"../chunk-YYFIJNSP.js";import"../chunk-H2LEQLVD.js";import{a as M}from"../chunk-7CUTGGH3.js";import"../chunk-Q4DKP5DO.js";import{a as x,e as R}from"../chunk-FQHALFRR.js";import"../chunk-64TVBQFR.js";import{c as C}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{readFileSync as B}from"fs";async function A(n,e={}){let a=new M,r=new V(a),c=[];for(let o of N(n)){let h;try{h=B(o,"utf-8")}catch{continue}let u;try{u=a.parse(h).metadata?.namespace_}catch{continue}if(!u?.version)continue;let v=u.version,w=`${v.major}.${v.minor}.${v.patch}`;await r.saveDocumentAsync(a.parse(h),`${u.publisher}/${u.package_}@${w}`),c.push({publisher:u.publisher,package_:u.package_,verStr:w,source:h})}let g=[...new Set(c.map(o=>o.publisher))].sort(),m=e.publisher;if(m){if(!g.includes(m))throw new Error(`Publisher "${m}" not found in workspace. Available: ${g.join(", ")||"(none)"}`)}else if(g.length===1)m=g[0];else throw g.length===0?new Error(`No Kanonak packages found under ${n}`):new Error(`Workspace has multiple publishers (${g.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let d=new Set,b=new Map;for(let o of c)o.publisher===m&&(d.add(`${o.publisher}/${o.package_}@${o.verStr}`),b.set(`${o.package_}@${o.verStr}`,o.source));let $=e.repository??new F(r,new P(_(),!0,a),new K(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),i=await new D(a).parseKanonaks($),s=new O(i),t=new Map,l=new Map,k=new Map,y=new Set;for(let o of i){if(!(o instanceof C))continue;let h=o.namespace||"";if(!d.has(h))continue;t.set(`${h}/${o.name}`,o);let u=h.split("/")[1]??"",[v,w]=u.split("@");if(!v||!w)continue;let j=R(w);j&&(y.has(u)||(y.add(u),l.has(v)||l.set(v,[]),l.get(v).push({verStr:w,version:j})),o.name===v&&k.set(u,o))}for(let o of l.values())o.sort((h,u)=>x(u.version,h.version));return{publisher:m,availablePublishers:g,catalog:i,lookRenderer:s,localNamespaces:d,rawByNsKey:b,bySubject:t,pkgVersions:l,pkgSelfByVer:k}}var p={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},f=(n,e,a,r)=>({status:n,headers:{"Content-Type":e,...r||{}},body:a}),S=n=>f(404,p[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${n}</p>`),I=n=>({status:301,headers:{Location:n},body:""});function E(n,e,a){let r=n.pkgVersions.get(e);if(!r||r.length===0)return null;switch(a.kind){case"any":return r[0].verStr;case"major-pin":return r.find(c=>c.version.major===a.major)?.verStr??null;case"minor-pin":return r.find(c=>c.version.major===a.major&&c.version.minor===a.minor)?.verStr??null;case"exact":return r.find(c=>c.version.major===a.major&&c.version.minor===a.minor&&c.version.patch===a.patch)?.verStr??null;default:return null}}function T(n,e,a=""){let{lookRenderer:r,publisher:c}=n;if(e==="/.well-known/kanonak.json")return f(200,p[".json"],JSON.stringify({version:1,auth:"none"},null,2));if(e==="/index.txt"){let s=[...n.localNamespaces].map(t=>t.split("/")[1].replace("@","/")).sort();return f(200,p[".txt"],s.join(`
|
|
2
2
|
`)+`
|
|
3
3
|
`)}if(e==="/"||e==="/index.html"||e==="/index.css"){let s=r.findPublisherRootView(c),t=[...n.pkgVersions.keys()].sort(),l=s??(t.length?n.pkgSelfByVer.get(`${t[0]}@${n.pkgVersions.get(t[0])[0].verStr}`):void 0);if(e==="/index.css")return f(200,p[".css"],s?r.renderStylesheet(s):r.renderPublisherIndexStylesheet(l));if(s)return f(200,p[".html"],r.renderDocument(s,{rootIndex:!0}));let k=t.map(y=>({label:y,href:`/${y}`}));return f(200,p[".html"],r.renderPublisherIndex(c,k,l))}let g=".html",m=!1,d=e;for(let s of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(s)){g=s,m=!0,d=e.slice(0,-s.length);break}let b=!m&&/application\/yaml|text\/yaml/i.test(a),$=d.endsWith("/");$&&d!=="/"&&(d=d.slice(0,-1));let i=L.parse(d,c);if(!i)return S(e);if(i.kind==="package"){let s=E(n,i.package_,i.versionSpec);if(!s)return S(e);if(g===".kan.yml"||b){let k=n.rawByNsKey.get(`${i.package_}@${s}`);return k!==void 0?f(200,p[".kan.yml"],k):S(e)}let t=n.pkgSelfByVer.get(`${i.package_}@${s}`);if(!t)return S(e);if(g===".css")return f(200,p[".css"],r.renderStylesheet(t));if(!$)return I(d+"/");let l=i.versionSpec.kind==="any";if(l&&!r.hasDeclaredView(t)){let k=(n.pkgVersions.get(i.package_)||[]).map(y=>y.verStr);return f(200,p[".html"],r.renderPackageVersionList(i.package_,k,t))}return f(200,p[".html"],r.renderDocument(t,l?{bareOverview:!0}:void 0))}if(i.kind==="resource"){let s=E(n,i.package_,i.versionSpec);if(!s)return S(e);let t=n.bySubject.get(`${c}/${i.package_}@${s}/${i.name}`);if(!t)return S(e);switch(g){case".css":return f(200,p[".css"],r.renderStylesheet(t));case".svg":return f(200,p[".svg"],r.renderSvg(t));case".md":{let l=r.renderRawMarkdown(t);return l===void 0?S(e):f(200,p[".md"],l)}default:return f(200,p[".html"],r.renderDocument(t))}}return S(e)}export{A as loadServerModel,T as route};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as X,c as ye}from"../chunk-2WQR7OHH.js";import{a as Ne}from"../chunk-IIODYDKS.js";import"../chunk-3NEUHF7E.js";import"../chunk-
|
|
1
|
+
import{b as X,c as ye}from"../chunk-2WQR7OHH.js";import{a as Ne}from"../chunk-IIODYDKS.js";import"../chunk-3NEUHF7E.js";import"../chunk-HMDTGNEA.js";import"../chunk-NIGFQYVA.js";import{c as Ue}from"../chunk-YYFIJNSP.js";import{a as C,c as Ce}from"../chunk-H2LEQLVD.js";import{a as Re}from"../chunk-7CUTGGH3.js";import{b as E,c as F,d as f,f as M,l as Oe}from"../chunk-Q4DKP5DO.js";import{e as Le}from"../chunk-FQHALFRR.js";import"../chunk-64TVBQFR.js";import{b as K,c as w,d as b,g as L,h as U,i as O,j,k as T,l as S}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";var yt="kanonak.org",kt="document-ast",m=t=>({publisher:yt,package_:kt,name:t}),k={Document:m("Document"),Block:m("Block"),Inline:m("Inline"),StructuredValue:m("StructuredValue"),Heading:m("Heading"),Paragraph:m("Paragraph"),RawBlock:m("RawBlock"),Text:m("Text"),StructuredMap:m("StructuredMap"),StructuredEntry:m("StructuredEntry"),StructuredList:m("StructuredList"),StringScalar:m("StringScalar"),IntegerScalar:m("IntegerScalar"),EscapeHint:m("EscapeHint"),MediaType:m("MediaType"),metadata:m("metadata"),children:m("children"),level:m("level"),inlines:m("inlines"),text:m("text"),entries:m("entries"),key:m("key"),value:m("value"),escapeHint:m("escapeHint"),items:m("items"),stringValue:m("stringValue"),integerValue:m("integerValue"),rawContent:m("rawContent"),mediaType:m("mediaType"),mimeType:m("mimeType"),ESC_RAW:m("esc-raw"),ESC_YAML_SAFE:m("esc-yaml-safe"),ESC_TOML_STRING:m("esc-toml-string"),ESC_TOML_MULTILINE:m("esc-toml-multiline"),ESC_JSON:m("esc-json"),ESC_DYNAMODB_BOOL:m("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:m("esc-dynamodb-number"),ESC_DYNAMODB_NULL:m("esc-dynamodb-null"),TEXT_PLAIN:m("text-plain"),TEXT_MARKDOWN:m("text-markdown"),TEXT_HTML:m("text-html"),TEXT_CSS:m("text-css"),APPLICATION_JSON:m("application-json"),TEXT_YAML:m("text-yaml"),IMAGE_SVG_XML:m("image-svg-xml"),ResourceLink:m("ResourceLink"),target:m("target"),linkLabel:m("linkLabel"),PropertyList:m("PropertyList"),propertyEntries:m("propertyEntries"),PropertyEntry:m("PropertyEntry"),propertyKey:m("propertyKey"),propertyValue:m("propertyValue"),Table:m("Table"),tableColumnLabels:m("tableColumnLabels"),tableRows:m("tableRows"),TableRow:m("TableRow"),tableCells:m("tableCells")};function Ie(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=ht(e.metadata,n),a=St(e.children),u=["---",...r,"---","",a].join(`
|
|
2
2
|
`);return n?.trailingNewline&&(u.endsWith(`
|
|
3
3
|
`)||(u+=`
|
|
4
4
|
`)),u}};function ht(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ue(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ue(c),l);let i=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ue),u=[];for(let c of i){let l=n.get(c);if(!l)continue;let p=r.get(c),y=ue(p??c),h=Me(l.value,l.escapeHint);h!==void 0&&u.push(`${y}: ${h}`)}return u}function ue(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Me(t,e){switch(t.kind){case"StringScalar":return bt(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=Me(r,e);a!==void 0&&n.push(a)}return n.join(", ")}case"StructuredMap":return;default:return}}function bt(t,e){return!e||Ie(e,k.ESC_RAW)?t:Ie(e,k.ESC_YAML_SAFE)?wt(t):t}function wt(t){return t.includes(`
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,E,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-
|
|
1
|
+
import{A,B,C,D,E,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-XHCSTAUK.js";import"../chunk-YYFIJNSP.js";import"../chunk-H2LEQLVD.js";import"../chunk-7CUTGGH3.js";import"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import"../chunk-FQHALFRR.js";import"../chunk-64TVBQFR.js";import"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,m as ClassHierarchyCycleRule,t as DefinitionPropertyReferenceRule,D as DisplayLensScopeRule,j as EmbeddedKanonakTypeRule,k as ImportExistenceRule,s as InstancePropertyReferenceRule,E as KanonakObjectValidator,C as MarkdownLinkRule,r as NamespaceImportCycleRule,f as NamespacePrefixRule,x as ObjectPropertyImportRule,y as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,z as PropertyDomainRule,n as PropertyHierarchyCycleRule,w as PropertyRangeReferenceRule,o as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,A as PropertyValueTypeRule,g as ResourceNamingRule,p as SubClassOfReferenceRule,q as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,l as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity,u as XsdImportRule};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.52.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"yaml-parser"
|
|
122
122
|
],
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"@kanonak-protocol/types": "^3.
|
|
124
|
+
"@kanonak-protocol/types": "^3.52.0",
|
|
125
125
|
"ignore": "^7.0.5",
|
|
126
126
|
"js-yaml": "^4.1.0",
|
|
127
127
|
"yaml": "^2.7.0"
|
package/dist/chunk-IO5RBK3J.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as h,b as R,c as T}from"./chunk-H2LEQLVD.js";import{a as M}from"./chunk-7CUTGGH3.js";import{b as A,c as E,i as P}from"./chunk-64TVBQFR.js";import{c as g,d as l,g as j,h as I,i as O,j as S,k as w,l as K}from"./chunk-W6T7MOKY.js";var L=/\[\[([^\[\]\n]+)\]\]/g,N=/\[\[/g,v=/```[\s\S]*?```|`[^`\n]*`/g;function V(d){let e=[];for(let t of d.matchAll(v))e.push([t.index,t.index+t[0].length]);return e}function C(d){if(!d||!d.includes("[["))return[];let e=V(d),t=r=>e.some(([n,i])=>r>=n&&r<i),s=new Set(D(d).map(r=>r.startOffset)),a=[];for(let r of d.matchAll(N)){let n=r.index;if(t(n)||s.has(n))continue;let i=d.slice(n,n+48).replace(/\s+/g," ").trim();a.push({startOffset:n,snippet:i})}return a}function D(d){if(!d||!d.includes("[["))return[];let e=[];for(let a of d.matchAll(v))e.push([a.index,a.index+a[0].length]);let t=a=>e.some(([r,n])=>a>=r&&a<n),s=[];for(let a of d.matchAll(L)){let r=a.index;if(t(r))continue;let n=a[1],i=n.indexOf("|"),c=(i===-1?n:n.slice(0,i)).trim();if(c.length===0)continue;let m=i===-1?"":n.slice(i+1).trim(),o={reference:c,startOffset:r,endOffset:r+a[0].length};m.length>0&&(o.displayText=m),s.push(o)}return s}var x=class{constructor(e){}async parseKanonaks(e){let t=[],s=await e.getAllDocumentsAsync(),a=new A(e),r=new E(a);for(let o of s){let p=o.metadata.namespace_?.toString()??"";for(let[f,y]of Object.entries(o.body)){let u=new g,b=this.resolveCanonicalEntity(f,o,p);u.namespace=b.namespace,u.name=b.name,u.statement=[];let k=await this.parseStatements(y,o,a,r,e);u.statement.push(...k),t.push(u)}}let n=new Map,i=[];for(let o of t)if(o instanceof g){let p=`${o.namespace}/${o.name}`,f=n.get(p);f?f.statement.push(...o.statement):(n.set(p,o),i.push(o))}else i.push(o);let c=new Set;for(let o of i)if(o instanceof g){let p=o.namespace||"",f=p.indexOf("/"),y=f>=0?p.slice(0,f):"",u=f>=0?p.slice(f+1):"",b=u.indexOf("@"),k=b>=0?u.slice(0,b):u;c.add(`${y}/${k}/${o.name}`)}let m=o=>c.has(`${o.publisher}/${o.package_}/${o.name}`);for(let o of i)o instanceof g&&this.canonicalizeStatementBuiltins(o.statement,m);return i}canonicalizeStatementBuiltins(e,t){for(let s of e){let a=s.predicate?.subject;if(P(a,t),s instanceof S)s.object instanceof l&&P(s.object.subject,t);else if(s instanceof w)s.object&&this.canonicalizeStatementBuiltins(s.object.statement,t);else if(s instanceof K)for(let r of s.object??[])r instanceof l?P(r.subject,t):r instanceof h&&this.canonicalizeStatementBuiltins(r.statement,t)}}resolveCanonicalEntity(e,t,s){if(!e.includes(".")||!t.metadata?.imports)return{namespace:s,name:e};let a=e.indexOf("."),r=e.substring(0,a),n=e.substring(a+1);for(let[i,c]of Object.entries(t.metadata.imports))for(let m of c)if((m.alias??m.packageName)===r){let p=m.version;return{namespace:`${i}/${m.packageName}@${p.major}.${p.minor}.${p.patch}`,name:n}}return{namespace:s,name:e}}async parseStatements(e,t,s,a,r){let n=[];if(typeof e!="object"||e===null||Array.isArray(e))return n;for(let[i,c]of Object.entries(e))try{let m=await this.getPropertyMetadata(i,t,s,r,a);if(!m)continue;let o=await this.parsePropertyValue(i,c,m,t,s,a);o&&n.push(o)}catch(m){console.error(`Error parsing property ${i}:`,m)}return n}async getPropertyMetadata(e,t,s,a,r){let n=await s.resolveEntityAsync(e,t);if(!n)return;let i=n.entity,c=i.type?.toString()??"",m=c.includes(".")?c.substring(c.lastIndexOf(".")+1):c;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(m))return;let p=r.getPropertyTypeClassification(c),f=i.range?.toString(),y;if(p==="ObjectProperty")y="ObjectProperty";else if(p==="DatatypeProperty")y="DatatypeProperty";else{let k=f&&f.includes(".")?f.substring(f.lastIndexOf(".")+1):f??"";(f?r.isKnownXsdDatatypeName(f):!1)||k==="Literal"?y="DatatypeProperty":y="ObjectProperty"}let u;return f&&(u=(await s.resolveEntityAsync(f,t))?.uri),{propertyUri:n.uri.toString(),propertyType:y,range:f,rangeUri:u,isImported:n.isImported,definedInNamespace:n.definedInNamespace}}async parsePropertyValue(e,t,s,a,r,n){let i=s.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(i,t,s,a,r,n);if(s.propertyType==="DatatypeProperty")return this.parseDatatypeValue(i,t,s,a,r,n);if(s.propertyType==="ObjectProperty")return this.parseObjectValue(i,t,s,a,r,n)}}async parseDatatypeValue(e,t,s,a,r,n){if(t instanceof Date)return j.parse(e,t.toISOString());if(typeof t=="string")return n.isSubstitutableDatatype(s.rangeUri)?await this.parseSubstitutableValue(e,t,a,r):j.parse(e,t);if(typeof t=="number")return I.parse(e,t);if(typeof t=="boolean"){let i=new O;return i.predicate=l.parse(e),i.object=t,i}}async parseSubstitutableValue(e,t,s,a){let r=new T;r.predicate=l.parse(e),r.object=t;for(let n of D(t)){let i=await a.resolveEntityAsync(n.reference,s),c;i&&(c=new l,c.subject=i.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),r.links.push(m)}return r}async parseObjectValue(e,t,s,a,r,n){if(typeof t=="string"){let i=await this.resolveReference(t,a,r);if(!i)return;let c=new S;return c.predicate=l.parse(e),c.object=i,c}if(typeof t=="object"&&!Array.isArray(t)){let i=new h;if(i.statement=await this.parseStatements(t,a,r,n,{}),i.statement.length>0){let o=new w;return o.predicate=l.parse(e),o.object=i,o}let c=[];for(let[o,p]of Object.entries(t))if(typeof p=="object"&&p!==null&&!Array.isArray(p)){let f=new h;f.name=o,f.statement=await this.parseStatements(p,a,r,n,{}),c.push(f)}else if(typeof p=="string"){let f=await this.resolveReference(p,a,r);f&&c.push(f)}if(c.length>0){let o=new K;return o.predicate=l.parse(e),o.object=c,o}let m=new w;return m.predicate=l.parse(e),m.object=i,m}}async parseListValue(e,t,s,a,r,n){let i=[],c=s.propertyType==="DatatypeProperty";for(let o of t){if(c&&(typeof o=="string"||typeof o=="number"||typeof o=="boolean")){let p=new R;p.value=o,i.push(p);continue}if(c&&o instanceof Date){let p=new R;p.value=o.toISOString(),i.push(p);continue}if(typeof o=="string"){let p=await this.resolveReference(o,a,r);p&&i.push(p)}else if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let p=new h;p.statement=await this.parseStatements(o,a,r,n,{}),i.push(p)}}let m=new K;return m.predicate=l.parse(e),m.object=i,m}async resolveReference(e,t,s){let a=await s.resolveEntityAsync(e,t);if(a){let n=new l;return n.subject=a.uri,n}let r=t.metadata?.namespace_;if(r){let{KanonakUri:n}=await import("./KanonakUri-4VJGV3FN.js"),i=r.version??{major:0,minor:0,patch:0,toString:()=>"0.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};if(e.includes(".")){let m=e.indexOf("."),o=e.substring(0,m),p=e.substring(m+1);if(t.metadata?.imports){for(let[f,y]of Object.entries(t.metadata.imports))for(let u of y)if((u.alias??u.packageName)===o){let k=new l;return k.subject=new n(f,u.packageName,p,u.version),k}}}let c=new l;return c.subject=new n(r.publisher,r.package_,e,i),c}return null}async saveKanonaks(e,t){let s=new Map;for(let a of e)a instanceof g&&a.namespace&&(s.has(a.namespace)||s.set(a.namespace,[]),s.get(a.namespace).push(a));for(let[a,r]of s){let n=await this.convertKanonaksToDocument(a,r),i=`${a.split("@")[0]}.yml`;await t.saveDocumentAsync(n,i)}}async serializeToYaml(e,t){let s=e.filter(n=>n instanceof g&&n.namespace===t);if(s.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let a=await this.convertKanonaksToDocument(t,s);return new M().save(a)}async convertKanonaksToDocument(e,t){let a={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let n=[];for(let i of Object.values(this.imports))n.push(...i);return n}},body:{}},r=new Map;for(let n of t){let i={};for(let c of n.statement){let[m,o]=this.convertStatementToProperty(c);m&&o!==null&&o!==void 0&&(i[m]=o),this.collectImportsFromStatement(c,e,r)}a.body[n.name]=i}return a}convertStatementToProperty(e){if(e instanceof j)return[e.predicate.subject.name,e.object];if(e instanceof I)return[e.predicate.subject.name,e.object];if(e instanceof O)return[e.predicate.subject.name,e.object];if(e instanceof S)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof K){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof w){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let s of e)s instanceof l?t.push(s.subject.name):s instanceof h&&t.push(this.convertEmbeddedKanonakToValue(s));return t}convertEmbeddedKanonakToValue(e){let t={};for(let s of e.statement){let[a,r]=this.convertStatementToProperty(s);a&&r!==null&&r!==void 0&&(t[a]=r)}return t}collectImportsFromStatement(e,t,s){}};export{C as a,D as b,x as c};
|