@kanonak-protocol/sdk 3.21.0 → 3.23.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-63NJ25ZX.js +2 -0
- package/dist/{chunk-BQIWYLBU.js → chunk-GD4SYMXW.js} +1 -1
- package/dist/{chunk-L4HXBHJ4.js → chunk-LPUWDJMI.js} +3 -3
- package/dist/{chunk-2SSUPRX3.js → chunk-NYXIGTTH.js} +1 -1
- package/dist/{chunk-Z72IKY6C.js → chunk-R2V7IXWN.js} +1 -1
- package/dist/{chunk-C2WWLKWE.js → chunk-ROCCA4BY.js} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -12
- package/dist/parsing/findMarkdownLinkAt.d.ts +29 -0
- package/dist/parsing/index.d.ts +1 -0
- package/dist/parsing/index.js +1 -1
- package/dist/reasoning/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-CQLO62JP.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-GD4SYMXW.js";import{a as Ye}from"./chunk-ROCCA4BY.js";import{a as H,b as L,c as W,d as F}from"./chunk-CNM3SY5S.js";import{a as Pe,b as we,c as he}from"./chunk-63NJ25ZX.js";import{a as ye,b as ke,e as be}from"./chunk-VRZUCZEF.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{A as Fe,B as Ge,C as Xe,D as Qe,a as Ke,b as xe,c as Se,d as Re,e as De,f as Be,g as Ce,h as Ee,i as je,j as ve,k as _e,l as Ae,m as Ie,n as Te,o as Oe,p as Ve,q as $e,r as Ue,s as ze,t as Me,u as Ne,v as Je,w as He,x as qe,y as Le,z as We}from"./chunk-LPUWDJMI.js";import"./chunk-FJ35VIV6.js";import{a as Y,c as le,e as pe}from"./chunk-R2V7IXWN.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 q}from"./chunk-MYITGTGJ.js";import{b as ue,c as de}from"./chunk-IXE5THUW.js";import{a as Z}from"./chunk-FUUTGGJS.js";var j="kanonak-credentials",u="credentials",Ze=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,Ze);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 rr(t)),o&&(s.nonce=o),await er(a,s,n.signingKey)}function x(n){return!n||n.length===0?!1:n.some(r=>r.toUpperCase()==="ES256")}async function er(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 rr(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 tr=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=nr(),p=await or(m),R=sr(),I=ir(t.authorizationEndpoint,i,this.callbackUrl,R,p),y=await this.openAuthPopup(I,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:A(o.dpop_signing_alg_values_supported),codeChallengeMethodsSupported:A(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)},tr),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 nr(){let n=new Uint8Array(32);return crypto.getRandomValues(n),B(n.buffer)}async function or(n){let r=new TextEncoder().encode(n),e=await crypto.subtle.digest("SHA-256",r);return B(e)}function sr(){let n=new Uint8Array(16);return crypto.getRandomValues(n),B(n.buffer)}function ir(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 A(n){return Array.isArray(n)?n.filter(r=>typeof r=="string"):null}export{Je as AmbiguousReferenceRule,se as BooleanStatement,f as BrowserCredentialBackend,S as BrowserOAuthFlow,Ge as ClassDefinitionRule,Ie as ClassHierarchyCycleRule,X as DefinedKanonak,Me 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,ze as InstancePropertyReferenceRule,G as Kanonak,we as KanonakDocumentPositions,pe as KanonakObjectParser,Qe as KanonakObjectValidator,q as KanonakParser,Z as KanonakUri,ke as KanonakUriBuilder,ce as ListStatement,Xe as MarkdownLinkRule,le as MarkdownStatement,Ue as NamespaceImportCycleRule,De as NamespacePrefixRule,ge as NodeType,oe as NumberStatement,qe as ObjectPropertyImportRule,Le as ObjectPropertyValueValidationRule,Se as OntologyValidationError,Ke as OntologyValidationResult,We as PropertyDomainRule,Te as PropertyHierarchyCycleRule,Pe as PropertyMetadata,He as PropertyRangeReferenceRule,Oe as PropertyRangeRequiredRule,Ce as PropertyTypeSpecificityRule,Fe 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,Ve as SubClassOfReferenceRule,$e as SubPropertyOfReferenceRule,Q as SubjectKanonak,Ee as SubjectKanonakTypeRequiredRule,Ae as TypeAmbiguityRule,de as TypeResolver,_e as UnresolvedReferenceRule,Re as ValidationContext,xe as ValidationSeverity,Ne as XsdImportRule,x as browserServerSupportsDPoP,O as compareVersions,K as createBrowserDPoPProof,U as createVersion,Ye as findDerivation,be as findInstancesByType,$ as formatVersion,k as generateBrowserDPoPKeyPair,_ as generateBrowserDPoPKeys,E as hasValidToken,b as importDPoPKeys,M as isCompatibleVersion,C as isExpired,N as isMajorCompatible,d as normalizeHost,z as parseVersionString,he as parseWithPositions,J as pickHighestDocument,V as versionsEqual};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{d as V}from"./chunk-R2V7IXWN.js";import{a as E}from"./chunk-MYITGTGJ.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
|
+
`&&(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,2 +1,2 @@
|
|
|
1
|
-
import{a as h}from"./chunk-VRZUCZEF.js";import{c as S,
|
|
1
|
+
import{a as h}from"./chunk-VRZUCZEF.js";import{c as S,e as R}from"./chunk-R2V7IXWN.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,4 +1,4 @@
|
|
|
1
|
-
import{a as le}from"./chunk-FJ35VIV6.js";import{a as re,c as ie,
|
|
1
|
+
import{a as le}from"./chunk-FJ35VIV6.js";import{a as re,c as ie,e as ae}from"./chunk-R2V7IXWN.js";import{c as te,k as oe,l as ne}from"./chunk-W6T7MOKY.js";import{a as ee}from"./chunk-MYITGTGJ.js";import{a as k,b as A,c as se}from"./chunk-IXE5THUW.js";var v=class{isValid=!1;errors=[];warnings=[];get totalIssues(){return this.errors.length+this.warnings.length}};var R=(i=>(i.Warning="Warning",i.Error="Error",i))(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 G=class h{resolvedDocuments=[];currentEntityPath;withPath(e){let i=new h;return i.resolvedDocuments=this.resolvedDocuments,i.currentEntityPath=e,i}};var D=class h{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 i=[];for(let[t,s]of Object.entries(e.body))s&&typeof s=="object"&&!Array.isArray(s)&&this.validateEntity(t,s,i);return i}validateEntity(e,i,t){for(let[s,a]of Object.entries(i)){let r=a?.toString()??"";if(r&&h.NAMESPACE_PREFIX_PATTERN.test(r)){let n=this.getSuggestionForPrefixedValue(r),l=e.split(".")[0],o=new g;o.ruleType=this.ruleName,o.severity="Error",o.entityName=l,o.propertyName=e,o.actualValue=s,o.expectedValue=n,o.message=`Invalid namespace prefix '${r}'. Use '${n}' without prefix.`,o.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(o)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validateEntity(`${e}.${s}`,a,t)}}getSuggestionForPrefixedValue(e){let i=e.toLowerCase();if(i==="rdfs:class"||i==="owl:class")return"Class";if(i==="rdfs:property"||i==="rdf:property")return"DatatypeProperty or ObjectProperty";if(i.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var I=class h{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 i=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[s,a]of Object.entries(e.body)){let r=h.VALID_AUGMENTATION_PATTERN.test(s);if(!r&&!t&&h.RESERVED_WORDS.has(s.toLowerCase())){let n=new g;n.ruleType=this.ruleName,n.severity="Error",n.entityName=s,n.message=`Entity name '${s}' is a reserved word and cannot be used.`,n.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",i.push(n);continue}if(!r&&!h.VALID_NAME_PATTERN.test(s)){let n;/^\d/.test(s)?n="Entity names must start with a letter, not a number.":s.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=s,l.message=`Invalid entity name '${s}'. ${n}`,l.suggestion=n,i.push(l)}a&&typeof a=="object"&&!Array.isArray(a)&&this.validatePropertyNames(s,a,i)}return i}validatePropertyNames(e,i,t){for(let s of Object.keys(i))if(!h.VALID_PROPERTIES.has(s)&&!h.VALID_PROPERTY_NAME_PATTERN.test(s)){let a=new g;a.ruleType=this.ruleName,a.severity="Warning",a.entityName=e,a.propertyName=s,a.message=`Property name '${s}' in entity '${e}' doesn't follow naming conventions.`,a.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(a)}}};var O=class h{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 i=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return i;let t=this.isPropertyDefinedAsClass(e);for(let[s,a]of Object.entries(e.body))if(a&&typeof a=="object"&&!Array.isArray(a)){let r=a,n=r.type;if(n){let l=[];if(Array.isArray(n))for(let o of n){let p=o?.toString();p&&p==="Property"&&!t&&l.push(p)}else{let o=n?.toString();o&&o==="Property"&&!t&&l.push(o)}for(let o of l){let p=this.getPropertyValue(r,"range"),c=this.determinePropertyType(p),m=new g;m.ruleType=this.ruleName,m.severity="Error",m.entityName=s,m.propertyName="type",m.actualValue=o,m.expectedValue=c,m.message=`Invalid property type '${o}'. Use '${c}' instead.`,m.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",i.push(m)}}}return i}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":h.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,i){let t=e[i];return t?t.toString():null}isPropertyDefinedAsClass(e){let i=e.body.Property;if(i&&typeof i=="object"&&!Array.isArray(i)){let s=i.type;if(s){let a=s.toString();return a==="Class"||a.endsWith(".Class")}}return!1}};var j=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let i=[];for(let[t,s]of Object.entries(e.body)){if(typeof s!="object"||s===null||Array.isArray(s)||t.includes("."))continue;let a=s,r="type"in a,n=a.type?.toString().trim();if(!r||!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.)",i.push(l)}}return i}};var w=class{get ruleName(){return"EmbeddedKanonakType"}async validateAsync(e,i){let t=[],s=new A(i),a=await this.buildPropertyRangeMap(e,s);for(let[r,n]of Object.entries(e.body))typeof n=="object"&&n!==null&&!Array.isArray(n)&&await this.checkEmbeddedTypes(r,n,void 0,a,s,e,t,0);return t}pickRange(e,i,t){if(e.length===0)return;if(e.length===1)return e[0].range;let s=i.indexOf(".");if(s>0){let a=i.substring(0,s),r=e.find(n=>n.declaringAlias===a);if(r)return r.range}if(t){let a=this.localName(t),r=e.find(n=>this.localName(n.domain)===a);if(r)return r.range}return e[0].range}async checkEmbeddedTypes(e,i,t,s,a,r,n,l){if(l>0){let p=i.type;if(p!=null){let c=await this.validateEmbeddedType(e,String(p),t,a,r);c&&n.push(c)}}let o=i.type!==void 0&&i.type!==null?String(i.type):void 0;for(let[p,c]of Object.entries(i)){let m=this.localName(p),y=s.get(m),f=(y!==void 0?this.pickRange(y,p,o):void 0)??t;if(typeof c=="object"&&c!==null)if(Array.isArray(c))for(let d=0;d<c.length;d++){let b=c[d];typeof b=="object"&&b!==null&&!Array.isArray(b)&&await this.checkEmbeddedTypes(`${e}.${p}[${d}]`,b,f,s,a,r,n,l+1)}else await this.checkEmbeddedTypes(`${e}.${p}`,c,f,s,a,r,n,l+1)}}async validateEmbeddedType(e,i,t,s,a){if(i.length===0||!t)return null;let r=this.localName(i),n=this.localName(t);if(n==="Resource"||n==="Class")return null;let l=e.split(".")[0];if(r===n){let p=new g;return p.ruleType=this.ruleName,p.severity="Warning",p.entityName=l,p.propertyName=e,p.actualValue=i,p.expectedValue=t,p.message=`Embedded object at '${e}' declares 'type: ${i}', which equals the parent property's range '${t}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,p.suggestion=`Remove the 'type: ${i}' line, or keep it if explicitness is preferred over concision.`,p}if(await s.isSubclassOfAsync(i,t,a)||(r!==i||n!==t)&&await s.isSubclassOfAsync(r,n,a))return null;let o=new g;return o.ruleType=this.ruleName,o.severity="Error",o.entityName=l,o.propertyName=e,o.actualValue=i,o.expectedValue=t,o.message=`Embedded object at '${e}' has 'type: ${i}', which is not a subclass of the parent property's range '${t}'.`,o.suggestion=`Either remove the 'type: ${i}' line (so the type is inferred from the property's range '${t}'), or add 'subClassOf: ${t}' to the '${i}' class definition so the relationship holds.`,o}localName(e){let i=e.lastIndexOf(".");return i<0||i===e.length-1?e:e.substring(i+1)}async buildPropertyRangeMap(e,i){let t=new Map,s=await i.buildEntityIndexAsync(e),a=new Map;for(let[r,n]of s){let l=n.entity.type;if(l==null)continue;let o=String(l),p=this.localName(o);if(!(p==="Property"||p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"))continue;let m=n.entity.range;if(m==null)continue;let y=String(m);if(y.length===0)continue;let u=n.entity.domain,f=u!=null?String(u):"",d=n.uri.toString(),b=a.get(d),V=r.includes(".");(!b||V&&!b.entityName.includes("."))&&a.set(d,{entityName:r,domain:f,range:y})}for(let r of a.values()){let n=this.localName(r.entityName),l=r.entityName.indexOf("."),o=l>0?r.entityName.substring(0,l):void 0,p=t.get(n)??[];p.push({domain:r.domain,range:r.range,declaringAlias:o}),t.set(n,p)}return t}};var E=class{ruleName="ImportExistence";async validateAsync(e,i){let t=[];if(!e.metadata?.imports)return t;let s=await i.getAllDocumentsAsync();for(let[a,r]of Object.entries(e.metadata.imports))for(let n of r)if(!await i.getHighestCompatibleVersionAsync(a,n)){let o=await this.determineImportErrorAsync(i,a,n,s),p=new g;p.ruleType=this.ruleName,p.severity="Error",p.message=o.message,p.suggestion=o.suggestion,p.entityName=`Import: ${a}/${n.packageName}`,p.actualValue=n.toString(),p.expectedValue=o.expectedValue,t.push(p)}return t}async determineImportErrorAsync(e,i,t,s){let a=await e.getDocumentsByNamespaceAsync(i,t.packageName);if(a.length===0){let o=s.filter(y=>y.metadata.namespace_?.publisher===i).map(y=>y.metadata.namespace_.package_).filter((y,u,f)=>f.indexOf(y)===u),p=this.findSimilarPackages(t.packageName,o),c=`Import '${i}/${t.package_}' not found - package does not exist`,m=p.length>0?`Did you mean: ${p.slice(0,3).join(", ")}?`:o.length>0?`Available packages in ${i}: ${o.slice(0,5).join(", ")}`:`No packages found for publisher '${i}'. Verify the publisher name is correct.`;return{message:c,suggestion:m,expectedValue:"Existing package"}}let n=a.filter(o=>o.metadata.namespace_?.version).map(o=>o.metadata.namespace_.version.toString()).sort().join(", "),l=this.getAcceptableVersionRange(t);return{message:`Import '${i}/${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,i){if(i.length===0)return[];let t=i.filter(r=>r.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(r.toLowerCase()));if(t.length>0)return t.sort((r,n)=>r.length-n.length);let s=i.map(r=>({package:r,distance:this.levenshteinDistance(e.toLowerCase(),r.toLowerCase())})).sort((r,n)=>r.distance-n.distance),a=Math.max(3,Math.floor(e.length*.4));return s.filter(r=>r.distance<=a).map(r=>r.package)}levenshteinDistance(e,i){if(!e||e.length===0)return i?.length??0;if(!i||i.length===0)return e.length;let t=e.length,s=i.length,a=Array(t+1).fill(null).map(()=>Array(s+1).fill(0));for(let r=0;r<=t;r++)a[r][0]=r;for(let r=0;r<=s;r++)a[0][r]=r;for(let r=1;r<=t;r++)for(let n=1;n<=s;n++){let l=e[r-1]===i[n-1]?0:1;a[r][n]=Math.min(Math.min(a[r-1][n]+1,a[r][n-1]+1),a[r-1][n-1]+l)}return a[t][s]}};var N=class{ruleName="UnresolvedReference";async validateAsync(e,i){let t=[],s=new A(i),a=await s.buildEntityIndexAsync(e),r=new Set;for(let[n,l]of a.entries()){let o=l.entity.type;if(o){let p=o.toString();(p==="ObjectProperty"||p.endsWith(".ObjectProperty"))&&r.add(n)}}for(let[n,l]of Object.entries(e.body)){if(!l||typeof l!="object"||Array.isArray(l))continue;let o=l,p=this.getPropertyValue(o,"type");if(!(!p||p==="Class"||p.endsWith("Property")||p==="AnnotationProperty"))for(let[c,m]of Object.entries(o))c==="type"||c==="label"||c==="comment"||!(r.has(c)||Array.from(r).some(u=>u.endsWith(`.${c}`)))||await this.validateReferenceValue(n,c,m,e,s,t)}return t}async validateReferenceValue(e,i,t,s,a,r){if(t!=null){if(typeof t=="string")await a.resolveEntityAsync(t,s)||r.push(this.createUnresolvedReferenceError(e,i,t));else if(Array.isArray(t))for(let n=0;n<t.length;n++){let l=t[n];typeof l=="string"&&(await a.resolveEntityAsync(l,s)||r.push(this.createUnresolvedReferenceError(e,`${i}[${n}]`,l)))}}}createUnresolvedReferenceError(e,i,t){let s=`The entity '${t}' cannot be found in the current document or any imported namespaces.
|
|
@@ -8,7 +8,7 @@ Possible solutions:
|
|
|
8
8
|
kanonak namespace add-import <publisher>/<package>@<version>
|
|
9
9
|
\u2022 Check for typos in the reference name '${t}'
|
|
10
10
|
\u2022 Define '${t}' in the current namespace or an appropriate namespace
|
|
11
|
-
\u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,a=new g;return a.ruleType=this.ruleName,a.severity="Warning",a.entityName=e,a.propertyName=i,a.actualValue=t,a.message=`Reference to '${t}' could not be resolved`,a.suggestion=s,a.expectedValue="A valid entity reference that exists in the current document or imported namespaces",a}getPropertyValue(e,i){let t=e[i];return t?t.toString():null}};var S=class{ruleName="TypeAmbiguity";async validateAsync(e,i){let t=[],s=new Map,a=[];if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){a.push({doc:o,import:l,publisher:r});let p=await this.getTransitiveImportsAsync(i,o,new Set);a.push(...p.map(c=>({doc:c,import:null,publisher:r})))}}for(let{doc:r,import:n}of a){let l=r.metadata?.namespace_?.toString()??"unknown";for(let o of Object.keys(r.body))s.has(o)||s.set(o,[]),s.get(o).push({namespace:l,import:n})}for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n;this.checkAmbiguousReference(l,"type",s,r,t),this.checkAmbiguousReference(l,"subClassOf",s,r,t),this.checkAmbiguousReference(l,"subPropertyOf",s,r,t),this.checkAmbiguousReference(l,"domain",s,r,t),this.checkAmbiguousReference(l,"range",s,r,t)}return t}checkAmbiguousReference(e,i,t,s,a){let r=e[i];if(!r)return;let n=k(r);for(let l of n){if(l.includes("."))continue;let o=t.get(l);if(o&&o.length>1){let p=o.map(u=>u.namespace).join(", "),c=[];for(let{namespace:u,import:f}of o)if(f?.alias)c.push(`${f.alias}.${l}`);else{let d=u.split("/"),V=d[d.length-1]?.split("@")[0]??"alias";c.push(`${V}.${l}`)}let m=c.length>0?`Use one of: ${c.join(", ")}`:"Consider adding namespace aliases to your imports",y=new g;y.ruleType=this.ruleName,y.severity="Warning",y.entityName=s,y.propertyName=i,y.actualValue=l,y.message=`Type '${l}' is ambiguous. It's defined in: ${p}`,y.suggestion=m,a.push(y)}}}async getTransitiveImportsAsync(e,i,t){let s=[],a=i.metadata?.namespace_?.toString()??"";if(t.has(a))return s;if(t.add(a),i.metadata?.imports)for(let[r,n]of Object.entries(i.metadata.imports))for(let l of n){let o=await e.getHighestCompatibleVersionAsync(r,l);if(o){s.push(o);let p=await this.getTransitiveImportsAsync(e,o,t);s.push(...p)}}return s}};var $=class{ruleName="ClassHierarchyCycle";async validateAsync(e,i){let t=[],s=new Map,a=new Set;await this.buildClassHierarchy(e,i,s,a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type,p=l.subClassOf;if(o?.toString()==="Class"&&p){let c=r,m=this.detectCycle(c,s);if(m){let y=m.join(" \u2192 "),u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular class hierarchy detected: ${y}`,u.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",u.entityName=c,u.propertyName="subClassOf",u.actualValue=y,t.push(u);break}}}return t}async buildClassHierarchy(e,i,t,s){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&s.has(a))){a&&s.add(a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type,p=l.subClassOf;if(o?.toString()==="Class"&&p){let c=k(p);c.length>0&&t.set(r,c)}}if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);o&&await this.buildClassHierarchy(o,i,t,s)}}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){if(t.includes(e)){let r=t.indexOf(e),n=t.slice(r);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let a=i.get(e);if(a)for(let r of a){let n=this.detectCycleRecursive(r,i,t,s);if(n)return n}return t.pop(),null}};var T=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,i){let t=[],s=new Map,a=new Set;await this.buildPropertyHierarchy(e,i,s,a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.subPropertyOf){let p=r,c=this.detectCycle(p,s);if(c){let m=c.join(" \u2192 "),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Circular property hierarchy detected: ${m}`,y.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",y.entityName=p,y.propertyName="subPropertyOf",y.actualValue=m,t.push(y);break}}return t}async buildPropertyHierarchy(e,i,t,s){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&s.has(a))){a&&s.add(a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type;if(o){let p=o.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"){let c=l.subPropertyOf;if(c){let m=k(c);m.length>0&&t.set(r,m)}}}}if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);o&&await this.buildPropertyHierarchy(o,i,t,s)}}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){if(t.includes(e)){let r=t.indexOf(e),n=t.slice(r);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let a=i.get(e);if(a)for(let r of a){let n=this.detectCycleRecursive(r,i,t,s);if(n)return n}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,i){let t=[];for(let[s,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let r=a,n=r.type?.toString();if(n==="DatatypeProperty"||n==="ObjectProperty"||n?.endsWith(".DatatypeProperty")||n?.endsWith(".ObjectProperty")){let l="range"in r,o=r.range?.toString().trim();if(!l||!o){let p=new g;p.ruleType=this.ruleName,p.severity="Error",p.entityName=s,p.propertyName="range",p.message=`Property '${s}' must have a 'range' defined.`,p.suggestion=n==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",p.expectedValue=n==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(p)}}}return t}};var K=class{builtInClasses=new Set(["Resource","Class","Datatype","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}isClassLikeType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isClassLikeType(l)&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=k(r.subClassOf);for(let o=0;o<l.length;o++){let p=l[o];if(this.builtInClasses.has(p)||s.has(p))continue;if(!await this.isClassAvailableInImports(e,i,p)){let m=l.length>1?`[${o}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Class '${p}' referenced in subClassOf${m} is not defined or imported`,y.suggestion=`Define '${p}' as a Class, or import a namespace that contains it`,y.entityName=a,y.propertyName="subClassOf",y.actualValue=p,y.expectedValue="Defined or imported class",t.push(y)}}}return t}async isClassAvailableInImports(e,i,t){if(!e.metadata.imports)return!1;let s=null,a=t;if(t.includes(".")){let r=t.split(".",2);s=r[0],a=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(s!==null&&l.alias!==s)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=s!==null?a:t,c=o.body[p];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(this.isClassLikeType(u))return!0}let m=new Set;if(await this.isClassAvailableInImportsRecursive(o,i,p,m))return!0}}return!1}async isClassAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isClassLikeType(m))return!0}if(await this.isClassAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}};var x=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();(l==="DatatypeProperty"||l==="ObjectProperty"||l==="AnnotationProperty")&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=k(r.subPropertyOf);for(let o=0;o<l.length;o++){let p=l[o];if(this.builtInProperties.has(p)||s.has(p))continue;if(!await this.isPropertyAvailableInImports(e,i,p)){let m=l.length>1?`[${o}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Property '${p}' referenced in subPropertyOf${m} is not defined or imported`,y.suggestion=`Define '${p}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,y.entityName=a,y.propertyName="subPropertyOf",y.actualValue=p,y.expectedValue="Defined or imported property",t.push(y)}}}return t}async isPropertyAvailableInImports(e,i,t){if(!e.metadata.imports)return!1;let s=null,a=t;if(t.includes(".")){let r=t.split(".",2);s=r[0],a=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(s!==null&&l.alias!==s)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=s!==null?a:t,c=o.body[p];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}let m=new Set;if(await this.isPropertyAvailableInImportsRecursive(o,i,p,m))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}};var W=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,i){let t=[],s=e.metadata.namespace_?.toString();if(!s)return t;let a=new Map,r=new Set;await this.buildImportGraph(e,i,a,r);let n=this.detectCycle(s,a);if(n){let l=n.join(" \u2192 "),o=new g;o.ruleType=this.ruleName,o.severity="Error",o.message=`Circular namespace import detected: ${l}`,o.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",o.entityName="imports",o.propertyName="imports",o.actualValue=l,t.push(o)}return t}async buildImportGraph(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(!(!a||s.has(a))&&(s.add(a),e.metadata.imports)){let r=[];for(let[n,l]of Object.entries(e.metadata.imports))for(let o of l){let p=`${n}/${o.packageName}@${o.version}`;r.push(p);let c=await i.getHighestCompatibleVersionAsync(n,o);c&&await this.buildImportGraph(c,i,t,s)}r.length>0&&t.set(a,r)}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){let a=t.indexOf(e);if(a>=0){let n=t.slice(a);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let r=i.get(e);if(r)for(let n of r){let l=this.detectCycleRecursive(n,i,t,s);if(l)return l}return t.pop(),null}};var M=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isPropertyType(l)&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let n=r,l=n.type?.toString();if(this.isPropertyType(l)||this.isClassType(l))continue;for(let[o,p]of Object.entries(n)){if(!o||this.metadataKeys.has(o))continue;let c=o,m=null;if(o.includes(".")){let u=o.lastIndexOf(".");m=o.substring(0,u),c=o.substring(u+1)}if(s.has(c))continue;if(!await this.isPropertyAvailableInImports(e,i,c,m)){let u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${o}' is not defined or imported`,u.suggestion=m?`The property '${c}' is not found in the imported namespace with alias '${m}'.
|
|
11
|
+
\u2022 Use 'kanonak search type ${t} --include-imports' to locate the entity`,a=new g;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=i,a.actualValue=t,a.message=`Reference to '${t}' could not be resolved`,a.suggestion=s,a.expectedValue="A valid entity reference that exists in the current document or imported namespaces",a}getPropertyValue(e,i){let t=e[i];return t?t.toString():null}};var S=class{ruleName="TypeAmbiguity";async validateAsync(e,i){let t=[],s=new Map,a=[];if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){a.push({doc:o,import:l,publisher:r});let p=await this.getTransitiveImportsAsync(i,o,new Set);a.push(...p.map(c=>({doc:c,import:null,publisher:r})))}}for(let{doc:r,import:n}of a){let l=r.metadata?.namespace_?.toString()??"unknown";for(let o of Object.keys(r.body))s.has(o)||s.set(o,[]),s.get(o).push({namespace:l,import:n})}for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n;this.checkAmbiguousReference(l,"type",s,r,t),this.checkAmbiguousReference(l,"subClassOf",s,r,t),this.checkAmbiguousReference(l,"subPropertyOf",s,r,t),this.checkAmbiguousReference(l,"domain",s,r,t),this.checkAmbiguousReference(l,"range",s,r,t)}return t}checkAmbiguousReference(e,i,t,s,a){let r=e[i];if(!r)return;let n=k(r);for(let l of n){if(l.includes("."))continue;let o=t.get(l);if(o&&o.length>1){let p=o.map(u=>u.namespace).join(", "),c=[];for(let{namespace:u,import:f}of o)if(f?.alias)c.push(`${f.alias}.${l}`);else{let d=u.split("/"),V=d[d.length-1]?.split("@")[0]??"alias";c.push(`${V}.${l}`)}let m=c.length>0?`Use one of: ${c.join(", ")}`:"Consider adding namespace aliases to your imports",y=new g;y.ruleType=this.ruleName,y.severity="Warning",y.entityName=s,y.propertyName=i,y.actualValue=l,y.message=`Type '${l}' is ambiguous. It's defined in: ${p}`,y.suggestion=m,a.push(y)}}}async getTransitiveImportsAsync(e,i,t){let s=[],a=i.metadata?.namespace_?.toString()??"";if(t.has(a))return s;if(t.add(a),i.metadata?.imports)for(let[r,n]of Object.entries(i.metadata.imports))for(let l of n){let o=await e.getHighestCompatibleVersionAsync(r,l);if(o){s.push(o);let p=await this.getTransitiveImportsAsync(e,o,t);s.push(...p)}}return s}};var $=class{ruleName="ClassHierarchyCycle";async validateAsync(e,i){let t=[],s=new Map,a=new Set;await this.buildClassHierarchy(e,i,s,a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type,p=l.subClassOf;if(o?.toString()==="Class"&&p){let c=r,m=this.detectCycle(c,s);if(m){let y=m.join(" \u2192 "),u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Circular class hierarchy detected: ${y}`,u.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",u.entityName=c,u.propertyName="subClassOf",u.actualValue=y,t.push(u);break}}}return t}async buildClassHierarchy(e,i,t,s){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&s.has(a))){a&&s.add(a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type,p=l.subClassOf;if(o?.toString()==="Class"&&p){let c=k(p);c.length>0&&t.set(r,c)}}if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);o&&await this.buildClassHierarchy(o,i,t,s)}}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){if(t.includes(e)){let r=t.indexOf(e),n=t.slice(r);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let a=i.get(e);if(a)for(let r of a){let n=this.detectCycleRecursive(r,i,t,s);if(n)return n}return t.pop(),null}};var T=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,i){let t=[],s=new Map,a=new Set;await this.buildPropertyHierarchy(e,i,s,a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.subPropertyOf){let p=r,c=this.detectCycle(p,s);if(c){let m=c.join(" \u2192 "),y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Circular property hierarchy detected: ${m}`,y.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",y.entityName=p,y.propertyName="subPropertyOf",y.actualValue=m,t.push(y);break}}return t}async buildPropertyHierarchy(e,i,t,s){let a=e.metadata?.namespace_?.toString()??"";if(!(a&&s.has(a))){a&&s.add(a);for(let[r,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)){let l=n,o=l.type;if(o){let p=o.toString();if(p==="DatatypeProperty"||p==="ObjectProperty"||p==="AnnotationProperty"){let c=l.subPropertyOf;if(c){let m=k(c);m.length>0&&t.set(r,m)}}}}if(e.metadata?.imports)for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);o&&await this.buildPropertyHierarchy(o,i,t,s)}}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){if(t.includes(e)){let r=t.indexOf(e),n=t.slice(r);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let a=i.get(e);if(a)for(let r of a){let n=this.detectCycleRecursive(r,i,t,s);if(n)return n}return t.pop(),null}};var C=class{get ruleName(){return"PropertyRangeRequired"}async validateAsync(e,i){let t=[];for(let[s,a]of Object.entries(e.body)){if(typeof a!="object"||a===null||Array.isArray(a))continue;let r=a,n=r.type?.toString();if(n==="DatatypeProperty"||n==="ObjectProperty"||n?.endsWith(".DatatypeProperty")||n?.endsWith(".ObjectProperty")){let l="range"in r,o=r.range?.toString().trim();if(!l||!o){let p=new g;p.ruleType=this.ruleName,p.severity="Error",p.entityName=s,p.propertyName="range",p.message=`Property '${s}' must have a 'range' defined.`,p.suggestion=n==="DatatypeProperty"?"Add a range like: range: string (or integer, boolean, etc.)":"Add a range like: range: ClassName (the class this property expects)",p.expectedValue=n==="DatatypeProperty"?"A datatype (string, integer, boolean, decimal, etc.)":"A class name (Character, Scene, Story, etc.)",t.push(p)}}}return t}};var K=class{builtInClasses=new Set(["Resource","Class","Datatype","Literal","Thing","Nothing","Property","DatatypeProperty","ObjectProperty","AnnotationProperty","FunctionalProperty","InverseFunctionalProperty","TransitiveProperty","SymmetricProperty"]);get ruleName(){return"SubClassOfReference"}isClassLikeType(e){return e?e==="Class"||e.endsWith(".Class")||e==="Datatype"||e.endsWith(".Datatype"):!1}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isClassLikeType(l)&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=k(r.subClassOf);for(let o=0;o<l.length;o++){let p=l[o];if(this.builtInClasses.has(p)||s.has(p))continue;if(!await this.isClassAvailableInImports(e,i,p)){let m=l.length>1?`[${o}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Class '${p}' referenced in subClassOf${m} is not defined or imported`,y.suggestion=`Define '${p}' as a Class, or import a namespace that contains it`,y.entityName=a,y.propertyName="subClassOf",y.actualValue=p,y.expectedValue="Defined or imported class",t.push(y)}}}return t}async isClassAvailableInImports(e,i,t){if(!e.metadata.imports)return!1;let s=null,a=t;if(t.includes(".")){let r=t.split(".",2);s=r[0],a=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(s!==null&&l.alias!==s)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=s!==null?a:t,c=o.body[p];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(this.isClassLikeType(u))return!0}let m=new Set;if(await this.isClassAvailableInImportsRecursive(o,i,p,m))return!0}}return!1}async isClassAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(this.isClassLikeType(m))return!0}if(await this.isClassAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}};var x=class{builtInProperties=new Set(["type","label","comment","domain","range","subPropertyOf","subClassOf","inverseOf","sameAs","seeAlso","isDefinedBy","functional","required"]);get ruleName(){return"SubPropertyOfReference"}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();(l==="DatatypeProperty"||l==="ObjectProperty"||l==="AnnotationProperty")&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=k(r.subPropertyOf);for(let o=0;o<l.length;o++){let p=l[o];if(this.builtInProperties.has(p)||s.has(p))continue;if(!await this.isPropertyAvailableInImports(e,i,p)){let m=l.length>1?`[${o}]`:"",y=new g;y.ruleType=this.ruleName,y.severity="Error",y.message=`Property '${p}' referenced in subPropertyOf${m} is not defined or imported`,y.suggestion=`Define '${p}' as a DatatypeProperty or ObjectProperty, or import a namespace that contains it`,y.entityName=a,y.propertyName="subPropertyOf",y.actualValue=p,y.expectedValue="Defined or imported property",t.push(y)}}}return t}async isPropertyAvailableInImports(e,i,t){if(!e.metadata.imports)return!1;let s=null,a=t;if(t.includes(".")){let r=t.split(".",2);s=r[0],a=r[1]}for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){if(s!==null&&l.alias!==s)continue;let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=s!==null?a:t,c=o.body[p];if(c&&typeof c=="object"&&!Array.isArray(c)){let u=c.type?.toString();if(u==="DatatypeProperty"||u==="ObjectProperty"||u==="AnnotationProperty")return!0}let m=new Set;if(await this.isPropertyAvailableInImportsRecursive(o,i,p,m))return!0}}return!1}async isPropertyAvailableInImportsRecursive(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(a&&s.has(a)||(a&&s.add(a),!e.metadata.imports))return!1;for(let[r,n]of Object.entries(e.metadata.imports))for(let l of n){let o=await i.getHighestCompatibleVersionAsync(r,l);if(o){let p=o.body[t];if(p&&typeof p=="object"&&!Array.isArray(p)){let m=p.type?.toString();if(m==="DatatypeProperty"||m==="ObjectProperty"||m==="AnnotationProperty")return!0}if(await this.isPropertyAvailableInImportsRecursive(o,i,t,s))return!0}}return!1}};var M=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,i){let t=[],s=e.metadata.namespace_?.toString();if(!s)return t;let a=new Map,r=new Set;await this.buildImportGraph(e,i,a,r);let n=this.detectCycle(s,a);if(n){let l=n.join(" \u2192 "),o=new g;o.ruleType=this.ruleName,o.severity="Error",o.message=`Circular namespace import detected: ${l}`,o.suggestion="Remove one of the imports to break the circular dependency. Circular dependencies prevent proper package resolution.",o.entityName="imports",o.propertyName="imports",o.actualValue=l,t.push(o)}return t}async buildImportGraph(e,i,t,s){let a=e.metadata.namespace_?.toString()??"";if(!(!a||s.has(a))&&(s.add(a),e.metadata.imports)){let r=[];for(let[n,l]of Object.entries(e.metadata.imports))for(let o of l){let p=`${n}/${o.packageName}@${o.version}`;r.push(p);let c=await i.getHighestCompatibleVersionAsync(n,o);c&&await this.buildImportGraph(c,i,t,s)}r.length>0&&t.set(a,r)}}detectCycle(e,i){let t=[],s=new Set;return this.detectCycleRecursive(e,i,t,s)}detectCycleRecursive(e,i,t,s){let a=t.indexOf(e);if(a>=0){let n=t.slice(a);return n.push(e),n}if(s.has(e))return null;t.push(e),s.add(e);let r=i.get(e);if(r)for(let n of r){let l=this.detectCycleRecursive(n,i,t,s);if(l)return l}return t.pop(),null}};var W=class{metadataKeys=new Set(["type","label","comment","subClassOf","subPropertyOf","domain","range","inverseOf","transitive","symmetric","functional","inverseFunctional"]);get ruleName(){return"InstancePropertyReference"}async validateAsync(e,i){let t=[],s=new Set;for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let l=r.type?.toString();this.isPropertyType(l)&&s.add(a)}for(let[a,r]of Object.entries(e.body))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let n=r,l=n.type?.toString();if(this.isPropertyType(l)||this.isClassType(l))continue;for(let[o,p]of Object.entries(n)){if(!o||this.metadataKeys.has(o))continue;let c=o,m=null;if(o.includes(".")){let u=o.lastIndexOf(".");m=o.substring(0,u),c=o.substring(u+1)}if(s.has(c))continue;if(!await this.isPropertyAvailableInImports(e,i,c,m)){let u=new g;u.ruleType=this.ruleName,u.severity="Error",u.message=`Property '${o}' is not defined or imported`,u.suggestion=m?`The property '${c}' is not found in the imported namespace with alias '${m}'.
|
|
12
12
|
1. Verify the namespace is imported with the correct alias
|
|
13
13
|
2. Check if the property name is spelled correctly
|
|
14
14
|
3. Ensure the imported namespace version contains this property`:`The property '${o}' is not defined in this namespace or any imported namespace.
|
|
@@ -44,4 +44,4 @@ ${V.slice(1).map(P=>` - ${P}`).join(`
|
|
|
44
44
|
Possible solutions:
|
|
45
45
|
\u2022 Import the package that defines '${t}' so the link can resolve
|
|
46
46
|
\u2022 Check for typos in the reference name
|
|
47
|
-
\u2022 If the name collides across imports, alias-qualify it: [[alias.${t}]]`,s}};var J=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new ee,this.documentRules=[new D,new I,new O,new j],this.repositoryRules=[new w,new E,new N,new S,new $,new T,new C,new K,new x,new
|
|
47
|
+
\u2022 If the name collides across imports, alias-qualify it: [[alias.${t}]]`,s}};var J=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new ee,this.documentRules=[new D,new I,new O,new j],this.repositoryRules=[new w,new E,new N,new S,new $,new T,new C,new K,new x,new M,new W,new L,new _,new H,new U,new F,new q,new X,new z,new B,new Y]}async validateAsync(e,i){let t=new v;for(let s of this.documentRules)try{let a=s.validate(e);this.addErrorsToResult(t,a)}catch(a){let r=new g;r.ruleType=s.ruleName,r.severity="Error",r.message=`Validation rule '${s.ruleName}' failed: ${a instanceof Error?a.message:String(a)}`,t.errors.push(r)}if(i){let s=[];for(let a of this.repositoryRules)try{let r=await a.validateAsync(e,i);this.addErrorsToResult(t,r)}catch(r){let n=r instanceof Error?r.message:String(r);s.push({ruleName:a.ruleName,cause:n})}if(s.length>0){let a=new Map;for(let{ruleName:r,cause:n}of s){let l=a.get(n);l?l.push(r):a.set(n,[r])}for(let[r,n]of a){let l=new g;l.ruleType=n[0],l.severity="Error",n.length===1?l.message=`Validation rule '${n[0]}' failed: ${r}`:l.message=`${r} (affects ${n.length} rules: ${n.join(", ")})`,t.errors.push(l)}}}return t.isValid=t.errors.length===0,t}async validateYamlAsync(e,i){let t=this.parser.parseWithErrors(e);if(!t.isValid){let s=new v;s.isValid=!1;for(let a of t.errors){let r=new g;r.ruleType="ParseError",r.severity="Error",r.lineNumber=a.line,r.column=a.column,r.message=a.message,a.keyName&&(r.entityName=a.keyName),a.errorType==="DuplicateKey"&&(r.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),s.errors.push(r)}return s}return await this.validateAsync(t.document,i)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let i=this.documentRules.findIndex(t=>t instanceof e);i>=0&&this.documentRules.splice(i,1)}removeRepositoryRule(e){let i=this.repositoryRules.findIndex(t=>t instanceof e);i>=0&&this.repositoryRules.splice(i,1)}addErrorsToResult(e,i){for(let t of i)t.severity==="Error"?e.errors.push(t):this.includeWarnings&&e.warnings.push(t)}};export{v as a,R as b,g as c,G as d,D as e,I as f,O as g,j as h,w as i,E as j,N as k,S as l,$ as m,T as n,C as o,K as p,x as q,M as r,W as s,L as t,_ as u,H as v,U as w,F as x,q as y,X as z,z as A,B,Y as C,J as D};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as S,b as j,
|
|
1
|
+
import{a as S,b as j,e as w}from"./chunk-R2V7IXWN.js";import{c as x,d as g,g as T,h as I,i as v,j as $,k as q,l as L}from"./chunk-W6T7MOKY.js";function u(t){return`${t.publisher}/${t.package_}/${t.name}`}function c(t,e,r){return`${t}/${e}/${r}`}function k(t){return`${t.s}|${t.p}|${P(t.o)}`}function P(t){switch(t.kind){case"uri":return`u:${t.key}`;case"literal":return`l:${t.datatype}:${t.lexical}`;case"blank":return`b:${t.id}`}}function s(t,e,r){return{s:t,p:e,o:{kind:"uri",key:r}}}var y=class{all=new Set;byPIdx=new Map;bySPIdx=new Map;byPOIdx=new Map;tripleList=[];add(e){let r=k(e);return this.all.has(r)?!1:(this.all.add(r),this.tripleList.push(e),h(this.byPIdx,e.p,e),h(this.bySPIdx,`${e.s}|${e.p}`,e),e.o.kind==="uri"&&h(this.byPOIdx,`${e.p}|${e.o.key}`,e),!0)}has(e){return this.all.has(k(e))}size(){return this.tripleList.length}snapshot(){return this.tripleList.slice()}byPredicate(e){let r=this.byPIdx.get(e);return r?r.slice():[]}bySubjectPredicate(e,r){let o=this.bySPIdx.get(`${e}|${r}`);return o?o.slice():[]}byPredicateObject(e,r){let o=this.byPOIdx.get(`${e}|${r}`);return o?o.slice():[]}subjectsWithPredicateObject(e,r){let o=this.byPOIdx.get(`${e}|${r}`);if(!o)return[];let i=new Set;for(let a of o)i.add(a.s);return Array.from(i)}uriObjectsOf(e,r){let o=this.bySPIdx.get(`${e}|${r}`);if(!o)return[];let i=new Set;for(let a of o)a.o.kind==="uri"&&i.add(a.o.key);return Array.from(i)}hasUri(e,r,o){return this.all.has(`${e}|${r}|u:${o}`)}hasTriple(e,r,o){return this.all.has(`${e}|${r}|${P(o)}`)}};function h(t,e,r){let o=t.get(e);o?o.push(r):t.set(e,[r])}var d=class{type=c("kanonak.org","core-rdf","type");subClassOf=c("kanonak.org","core-rdf","subClassOf");subPropertyOf=c("kanonak.org","core-rdf","subPropertyOf");domain=c("kanonak.org","core-rdf","domain");range=c("kanonak.org","core-rdf","range");equivalentClass=c("kanonak.org","core-owl","equivalentClass");equivalentProperty=c("kanonak.org","core-owl","equivalentProperty");inverseOf=c("kanonak.org","core-owl","inverseOf");sameAs=c("kanonak.org","core-owl","sameAs");transitiveProperty=c("kanonak.org","core-owl","TransitiveProperty");symmetricProperty=c("kanonak.org","core-owl","SymmetricProperty")};var _={name:"rdfs2",apply(t,e){let r=!1;for(let o of t.byPredicate(e.domain)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.byPredicate(i))t.add(s(n.s,e.type,a))&&(r=!0)}return r}},E={name:"rdfs3",apply(t,e){let r=!1;for(let o of t.byPredicate(e.range)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.byPredicate(i))n.o.kind==="uri"&&t.add(s(n.o.key,e.type,a))&&(r=!0)}return r}},A={name:"rdfs5",apply(t,e){let r=!1;for(let o of t.byPredicate(e.subPropertyOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.bySubjectPredicate(a,e.subPropertyOf))n.o.kind==="uri"&&t.add(s(i,e.subPropertyOf,n.o.key))&&(r=!0)}return r}},V={name:"rdfs7",apply(t,e){let r=!1;for(let o of t.byPredicate(e.subPropertyOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicate(i)){let p={s:n.s,p:a,o:n.o};t.add(p)&&(r=!0)}}return r}},W={name:"rdfs9",apply(t,e){let r=!1;for(let o of t.byPredicate(e.subClassOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicateObject(e.type,i))t.add(s(n.s,e.type,a))&&(r=!0)}return r}},F={name:"rdfs11",apply(t,e){let r=!1;for(let o of t.byPredicate(e.subClassOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.bySubjectPredicate(a,e.subClassOf))n.o.kind==="uri"&&t.add(s(i,e.subClassOf,n.o.key))&&(r=!0)}return r}},K=[_,E,A,V,W,F];var N={name:"prp-trp",apply(t,e){let r=!1,o=t.subjectsWithPredicateObject(e.type,e.transitiveProperty);for(let i of o){let a=t.byPredicate(i);for(let n of a){if(n.o.kind!=="uri")continue;let p=n.o.key;for(let l of t.bySubjectPredicate(p,i))l.o.kind==="uri"&&n.s!==l.o.key&&t.add(s(n.s,i,l.o.key))&&(r=!0)}}return r}},D={name:"prp-symp",apply(t,e){let r=!1,o=t.subjectsWithPredicateObject(e.type,e.symmetricProperty);for(let i of o)for(let a of t.byPredicate(i))a.o.kind==="uri"&&t.add(s(a.o.key,i,a.s))&&(r=!0);return r}},M={name:"prp-inv1",apply(t,e){let r=!1;for(let o of t.byPredicate(e.inverseOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.byPredicate(i))n.o.kind==="uri"&&t.add(s(n.o.key,a,n.s))&&(r=!0)}return r}},z={name:"prp-inv2",apply(t,e){let r=!1;for(let o of t.byPredicate(e.inverseOf)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;for(let n of t.byPredicate(a))n.o.kind==="uri"&&t.add(s(n.o.key,i,n.s))&&(r=!0)}return r}},B={name:"prp-eqp1",apply(t,e){let r=!1;for(let o of t.byPredicate(e.equivalentProperty)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicate(i))t.add({s:n.s,p:a,o:n.o})&&(r=!0)}return r}},G={name:"prp-eqp2",apply(t,e){let r=!1;for(let o of t.byPredicate(e.equivalentProperty)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicate(a))t.add({s:n.s,p:i,o:n.o})&&(r=!0)}return r}},H={name:"cax-eqc1",apply(t,e){let r=!1;for(let o of t.byPredicate(e.equivalentClass)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicateObject(e.type,i))t.add(s(n.s,e.type,a))&&(r=!0)}return r}},J={name:"cax-eqc2",apply(t,e){let r=!1;for(let o of t.byPredicate(e.equivalentClass)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.byPredicateObject(e.type,a))t.add(s(n.s,e.type,i))&&(r=!0)}return r}},Q={name:"eq-rep-s",apply(t,e){let r=!1;for(let o of t.byPredicate(e.sameAs)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a){for(let n of t.snapshot())n.s===i&&t.add({s:a,p:n.p,o:n.o})&&(r=!0);for(let n of t.snapshot())n.s===a&&t.add({s:i,p:n.p,o:n.o})&&(r=!0)}}return r}},X={name:"eq-rep-o",apply(t,e){let r=!1;for(let o of t.byPredicate(e.sameAs)){if(o.o.kind!=="uri")continue;let i=o.s,a=o.o.key;if(i!==a)for(let n of t.snapshot())n.o.kind==="uri"&&(n.o.key===i?t.add(s(n.s,n.p,a))&&(r=!0):n.o.key===a&&t.add(s(n.s,n.p,i))&&(r=!0))}return r}},U=[N,D,M,z,B,G,H,J,Q,X];var m=class{constructor(e,r){this.store=e;this.vocabulary=r}store;vocabulary;getInstancesOfClass(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.type,r)}getSubclasses(e){let r=f(e);return this.store.subjectsWithPredicateObject(this.vocabulary.subClassOf,r).filter(i=>i!==r)}getSuperclasses(e){let r=f(e);return this.store.uriObjectsOf(r,this.vocabulary.subClassOf).filter(o=>o!==r)}getTypesOfIndividual(e){return this.store.uriObjectsOf(f(e),this.vocabulary.type)}isInstanceOf(e,r){return this.store.hasUri(f(e),this.vocabulary.type,f(r))}triples(){return this.store.snapshot()}size(){return this.store.size()}};function f(t){return typeof t=="string"?t:c(t.publisher,t.package_,t.name)}var R=class{vocabulary;profile;maxIterations;constructor(e={}){this.vocabulary=e.vocabulary??new d,this.profile=e.profile??"owl-rl-classification",this.maxIterations=e.maxIterations??100}async reason(e){let r=new y,i=await new w().parseKanonaks(e),a=new O;for(let l of i)if(l instanceof x){let b=Y(l);if(!b)continue;for(let C of l.statement)this.emitStatement(b,C,r,a)}let n=[...K];this.profile==="owl-rl-classification"&&n.push(...U);let p=0;for(;p<this.maxIterations;){let l=!1;for(let b of n)b.apply(r,this.vocabulary)&&(l=!0);if(!l)break;p++}return new m(r,this.vocabulary)}emitStatement(e,r,o,i){let a=Z(r);if(a){if(r instanceof T){o.add({s:e,p:a,o:{kind:"literal",lexical:r.object,datatype:"string"}});return}if(r instanceof I){o.add({s:e,p:a,o:{kind:"literal",lexical:String(r.object),datatype:"number"}});return}if(r instanceof v){o.add({s:e,p:a,o:{kind:"literal",lexical:String(r.object),datatype:"boolean"}});return}if(r instanceof $){let n=u(r.object.subject);o.add(s(e,a,n));return}if(r instanceof q){let n=i.next();o.add({s:e,p:a,o:{kind:"blank",id:n}}),this.emitEmbedded(n,r.object,o,i);return}if(r instanceof L){for(let n of r.object??[])this.emitListItem(e,a,n,o,i);return}}}emitListItem(e,r,o,i,a){if(o instanceof g)i.add(s(e,r,u(o.subject)));else if(o instanceof S){let n=a.next();i.add({s:e,p:r,o:{kind:"blank",id:n}}),this.emitEmbedded(n,o,i,a)}else if(o instanceof j){let n=typeof o.value=="number"?"number":typeof o.value=="boolean"?"boolean":"string";i.add({s:e,p:r,o:{kind:"literal",lexical:String(o.value),datatype:n}})}}emitEmbedded(e,r,o,i){let a=`_:${e}`;for(let n of r.statement)this.emitStatement(a,n,o,i)}},O=class{counter=0;next(){return`b${this.counter++}`}};function Y(t){let e=t.namespace??"",r=e.indexOf("@"),o=r===-1?e:e.substring(0,r),i=o.indexOf("/");if(i===-1)return null;let a=o.substring(0,i),n=o.substring(i+1);return!a||!n||!t.name?null:c(a,n,t.name)}function Z(t){let e=t.predicate;return e?.subject?u(e.subject):null}export{u as a,c as b,k as c,s as d,y as e,d as f,K as g,U as h,m as i,R as j};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as T,b as O,c as K,d as u,g,h as R,i as S,j as D,k as h,l as j}from"./chunk-W6T7MOKY.js";import{a as I}from"./chunk-MYITGTGJ.js";import{b as v,c as M}from"./chunk-IXE5THUW.js";var k=class extends O{name};var w=class extends T{value};var P=class extends g{links=[]};var L=/\[\[([^\[\]\n]+)\]\]/g,V=/```[\s\S]*?```|`[^`\n]*`/g;function x(d){if(!d||!d.includes("[["))return[];let e=[];for(let n of d.matchAll(V))e.push([n.index,n.index+n[0].length]);let t=n=>e.some(([s,a])=>n>=s&&n<a),i=[];for(let n of d.matchAll(L)){let s=n.index;if(t(s))continue;let a=n[1],r=a.indexOf("|"),o=(r===-1?a:a.slice(0,r)).trim();if(o.length===0)continue;let p=r===-1?"":a.slice(r+1).trim(),c={reference:o,startOffset:s,endOffset:s+n[0].length};p.length>0&&(c.displayText=p),i.push(c)}return i}var A=class{constructor(e){}async parseKanonaks(e){let t=[],i=await e.getAllDocumentsAsync(),n=new v(e),s=new M(n);for(let o of i){let p=o.metadata.namespace_?.toString()??"";for(let[c,m]of Object.entries(o.body)){let f=new K,y=this.resolveCanonicalEntity(c,o,p);f.namespace=y.namespace,f.name=y.name,f.statement=[];let l=await this.parseStatements(m,o,n,s,e);f.statement.push(...l),t.push(f)}}let a=new Map,r=[];for(let o of t)if(o instanceof K){let p=`${o.namespace}/${o.name}`,c=a.get(p);c?c.statement.push(...o.statement):(a.set(p,o),r.push(o))}else r.push(o);return r}resolveCanonicalEntity(e,t,i){if(!e.includes(".")||!t.metadata?.imports)return{namespace:i,name:e};let n=e.indexOf("."),s=e.substring(0,n),a=e.substring(n+1);for(let[r,o]of Object.entries(t.metadata.imports))for(let p of o)if((p.alias??p.packageName)===s){let m=p.version;return{namespace:`${r}/${p.packageName}@${m.major}.${m.minor}.${m.patch}`,name:a}}return{namespace:i,name:e}}async parseStatements(e,t,i,n,s){let a=[];if(typeof e!="object"||e===null||Array.isArray(e))return a;for(let[r,o]of Object.entries(e))try{let p=await this.getPropertyMetadata(r,t,i,s,n);if(!p)continue;let c=await this.parsePropertyValue(r,o,p,t,i,n);c&&a.push(c)}catch(p){console.error(`Error parsing property ${r}:`,p)}return a}async getPropertyMetadata(e,t,i,n,s){let a=await i.resolveEntityAsync(e,t);if(!a)return;let r=a.entity,o=r.type?.toString()??"",p=o.includes(".")?o.substring(o.lastIndexOf(".")+1):o;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(p))return;let m=s.getPropertyTypeClassification(o),f=r.range?.toString(),y;if(m==="ObjectProperty")y="ObjectProperty";else if(m==="DatatypeProperty")y="DatatypeProperty";else{let b=f&&f.includes(".")?f.substring(f.lastIndexOf(".")+1):f??"";(f?s.isKnownXsdDatatypeName(f):!1)||b==="Literal"?y="DatatypeProperty":y="ObjectProperty"}let l;return f&&(l=(await i.resolveEntityAsync(f,t))?.uri),{propertyUri:a.uri.toString(),propertyType:y,range:f,rangeUri:l,isImported:a.isImported,definedInNamespace:a.definedInNamespace}}async parsePropertyValue(e,t,i,n,s,a){let r=i.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(r,t,i,n,s,a);if(i.propertyType==="DatatypeProperty")return this.parseDatatypeValue(r,t,i,n,s,a);if(i.propertyType==="ObjectProperty")return this.parseObjectValue(r,t,i,n,s,a)}}async parseDatatypeValue(e,t,i,n,s,a){if(t instanceof Date)return g.parse(e,t.toISOString());if(typeof t=="string")return a.isSubstitutableDatatype(i.rangeUri)?await this.parseSubstitutableValue(e,t,n,s):g.parse(e,t);if(typeof t=="number")return R.parse(e,t);if(typeof t=="boolean"){let r=new S;return r.predicate=u.parse(e),r.object=t,r}}async parseSubstitutableValue(e,t,i,n){let s=new P;s.predicate=u.parse(e),s.object=t;for(let a of x(t)){let r=await n.resolveEntityAsync(a.reference,i),o;r&&(o=new u,o.subject=r.uri);let p={reference:a.reference,startOffset:a.startOffset,endOffset:a.endOffset};a.displayText!==void 0&&(p.displayText=a.displayText),o!==void 0&&(p.target=o),s.links.push(p)}return s}async parseObjectValue(e,t,i,n,s,a){if(typeof t=="string"){let r=await this.resolveReference(t,n,s);if(!r)return;let o=new D;return o.predicate=u.parse(e),o.object=r,o}if(typeof t=="object"&&!Array.isArray(t)){let r=new k;if(r.statement=await this.parseStatements(t,n,s,a,{}),r.statement.length>0){let c=new h;return c.predicate=u.parse(e),c.object=r,c}let o=[];for(let[c,m]of Object.entries(t))if(typeof m=="object"&&m!==null&&!Array.isArray(m)){let f=new k;f.name=c,f.statement=await this.parseStatements(m,n,s,a,{}),o.push(f)}else if(typeof m=="string"){let f=await this.resolveReference(m,n,s);f&&o.push(f)}if(o.length>0){let c=new j;return c.predicate=u.parse(e),c.object=o,c}let p=new h;return p.predicate=u.parse(e),p.object=r,p}}async parseListValue(e,t,i,n,s,a){let r=[],o=i.propertyType==="DatatypeProperty";for(let c of t){if(o&&(typeof c=="string"||typeof c=="number"||typeof c=="boolean")){let m=new w;m.value=c,r.push(m);continue}if(o&&c instanceof Date){let m=new w;m.value=c.toISOString(),r.push(m);continue}if(typeof c=="string"){let m=await this.resolveReference(c,n,s);m&&r.push(m)}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let m=new k;m.statement=await this.parseStatements(c,n,s,a,{}),r.push(m)}}let p=new j;return p.predicate=u.parse(e),p.object=r,p}async resolveReference(e,t,i){let n=await i.resolveEntityAsync(e,t);if(n){let a=new u;return a.subject=n.uri,a}let s=t.metadata?.namespace_;if(s){let{KanonakUri:a}=await import("./KanonakUri-4VJGV3FN.js"),r=s.version??{major:0,minor:0,patch:0,toString:()=>"0.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};if(e.includes(".")){let p=e.indexOf("."),c=e.substring(0,p),m=e.substring(p+1);if(t.metadata?.imports){for(let[f,y]of Object.entries(t.metadata.imports))for(let l of y)if((l.alias??l.packageName)===c){let b=new u;return b.subject=new a(f,l.packageName,m,l.version),b}}}let o=new u;return o.subject=new a(s.publisher,s.package_,e,r),o}return null}async saveKanonaks(e,t){let i=new Map;for(let n of e)n instanceof K&&n.namespace&&(i.has(n.namespace)||i.set(n.namespace,[]),i.get(n.namespace).push(n));for(let[n,s]of i){let a=await this.convertKanonaksToDocument(n,s),r=`${n.split("@")[0]}.yml`;await t.saveDocumentAsync(a,r)}}async serializeToYaml(e,t){let i=e.filter(a=>a instanceof K&&a.namespace===t);if(i.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let n=await this.convertKanonaksToDocument(t,i);return new I().save(n)}async convertKanonaksToDocument(e,t){let n={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let a=[];for(let r of Object.values(this.imports))a.push(...r);return a}},body:{}},s=new Map;for(let a of t){let r={};for(let o of a.statement){let[p,c]=this.convertStatementToProperty(o);p&&c!==null&&c!==void 0&&(r[p]=c),this.collectImportsFromStatement(o,e,s)}n.body[a.name]=r}return n}convertStatementToProperty(e){if(e instanceof g)return[e.predicate.subject.name,e.object];if(e instanceof R)return[e.predicate.subject.name,e.object];if(e instanceof S)return[e.predicate.subject.name,e.object];if(e instanceof D)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof j){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof h){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let i of e)i instanceof u?t.push(i.subject.name):i instanceof k&&t.push(this.convertEmbeddedKanonakToValue(i));return t}convertEmbeddedKanonakToValue(e){let t={};for(let i of e.statement){let[n,s]=this.convertStatementToProperty(i);n&&s!==null&&s!==void 0&&(t[n]=s)}return t}collectImportsFromStatement(e,t,i){}};export{k as a,w as b,P as c,A as
|
|
1
|
+
import{a as T,b as O,c as K,d as u,g,h as R,i as S,j as D,k as h,l as j}from"./chunk-W6T7MOKY.js";import{a as I}from"./chunk-MYITGTGJ.js";import{b as v,c as M}from"./chunk-IXE5THUW.js";var k=class extends O{name};var w=class extends T{value};var P=class extends g{links=[]};var L=/\[\[([^\[\]\n]+)\]\]/g,V=/```[\s\S]*?```|`[^`\n]*`/g;function x(d){if(!d||!d.includes("[["))return[];let e=[];for(let n of d.matchAll(V))e.push([n.index,n.index+n[0].length]);let t=n=>e.some(([s,a])=>n>=s&&n<a),i=[];for(let n of d.matchAll(L)){let s=n.index;if(t(s))continue;let a=n[1],r=a.indexOf("|"),o=(r===-1?a:a.slice(0,r)).trim();if(o.length===0)continue;let p=r===-1?"":a.slice(r+1).trim(),c={reference:o,startOffset:s,endOffset:s+n[0].length};p.length>0&&(c.displayText=p),i.push(c)}return i}var A=class{constructor(e){}async parseKanonaks(e){let t=[],i=await e.getAllDocumentsAsync(),n=new v(e),s=new M(n);for(let o of i){let p=o.metadata.namespace_?.toString()??"";for(let[c,m]of Object.entries(o.body)){let f=new K,y=this.resolveCanonicalEntity(c,o,p);f.namespace=y.namespace,f.name=y.name,f.statement=[];let l=await this.parseStatements(m,o,n,s,e);f.statement.push(...l),t.push(f)}}let a=new Map,r=[];for(let o of t)if(o instanceof K){let p=`${o.namespace}/${o.name}`,c=a.get(p);c?c.statement.push(...o.statement):(a.set(p,o),r.push(o))}else r.push(o);return r}resolveCanonicalEntity(e,t,i){if(!e.includes(".")||!t.metadata?.imports)return{namespace:i,name:e};let n=e.indexOf("."),s=e.substring(0,n),a=e.substring(n+1);for(let[r,o]of Object.entries(t.metadata.imports))for(let p of o)if((p.alias??p.packageName)===s){let m=p.version;return{namespace:`${r}/${p.packageName}@${m.major}.${m.minor}.${m.patch}`,name:a}}return{namespace:i,name:e}}async parseStatements(e,t,i,n,s){let a=[];if(typeof e!="object"||e===null||Array.isArray(e))return a;for(let[r,o]of Object.entries(e))try{let p=await this.getPropertyMetadata(r,t,i,s,n);if(!p)continue;let c=await this.parsePropertyValue(r,o,p,t,i,n);c&&a.push(c)}catch(p){console.error(`Error parsing property ${r}:`,p)}return a}async getPropertyMetadata(e,t,i,n,s){let a=await i.resolveEntityAsync(e,t);if(!a)return;let r=a.entity,o=r.type?.toString()??"",p=o.includes(".")?o.substring(o.lastIndexOf(".")+1):o;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(p))return;let m=s.getPropertyTypeClassification(o),f=r.range?.toString(),y;if(m==="ObjectProperty")y="ObjectProperty";else if(m==="DatatypeProperty")y="DatatypeProperty";else{let b=f&&f.includes(".")?f.substring(f.lastIndexOf(".")+1):f??"";(f?s.isKnownXsdDatatypeName(f):!1)||b==="Literal"?y="DatatypeProperty":y="ObjectProperty"}let l;return f&&(l=(await i.resolveEntityAsync(f,t))?.uri),{propertyUri:a.uri.toString(),propertyType:y,range:f,rangeUri:l,isImported:a.isImported,definedInNamespace:a.definedInNamespace}}async parsePropertyValue(e,t,i,n,s,a){let r=i.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(r,t,i,n,s,a);if(i.propertyType==="DatatypeProperty")return this.parseDatatypeValue(r,t,i,n,s,a);if(i.propertyType==="ObjectProperty")return this.parseObjectValue(r,t,i,n,s,a)}}async parseDatatypeValue(e,t,i,n,s,a){if(t instanceof Date)return g.parse(e,t.toISOString());if(typeof t=="string")return a.isSubstitutableDatatype(i.rangeUri)?await this.parseSubstitutableValue(e,t,n,s):g.parse(e,t);if(typeof t=="number")return R.parse(e,t);if(typeof t=="boolean"){let r=new S;return r.predicate=u.parse(e),r.object=t,r}}async parseSubstitutableValue(e,t,i,n){let s=new P;s.predicate=u.parse(e),s.object=t;for(let a of x(t)){let r=await n.resolveEntityAsync(a.reference,i),o;r&&(o=new u,o.subject=r.uri);let p={reference:a.reference,startOffset:a.startOffset,endOffset:a.endOffset};a.displayText!==void 0&&(p.displayText=a.displayText),o!==void 0&&(p.target=o),s.links.push(p)}return s}async parseObjectValue(e,t,i,n,s,a){if(typeof t=="string"){let r=await this.resolveReference(t,n,s);if(!r)return;let o=new D;return o.predicate=u.parse(e),o.object=r,o}if(typeof t=="object"&&!Array.isArray(t)){let r=new k;if(r.statement=await this.parseStatements(t,n,s,a,{}),r.statement.length>0){let c=new h;return c.predicate=u.parse(e),c.object=r,c}let o=[];for(let[c,m]of Object.entries(t))if(typeof m=="object"&&m!==null&&!Array.isArray(m)){let f=new k;f.name=c,f.statement=await this.parseStatements(m,n,s,a,{}),o.push(f)}else if(typeof m=="string"){let f=await this.resolveReference(m,n,s);f&&o.push(f)}if(o.length>0){let c=new j;return c.predicate=u.parse(e),c.object=o,c}let p=new h;return p.predicate=u.parse(e),p.object=r,p}}async parseListValue(e,t,i,n,s,a){let r=[],o=i.propertyType==="DatatypeProperty";for(let c of t){if(o&&(typeof c=="string"||typeof c=="number"||typeof c=="boolean")){let m=new w;m.value=c,r.push(m);continue}if(o&&c instanceof Date){let m=new w;m.value=c.toISOString(),r.push(m);continue}if(typeof c=="string"){let m=await this.resolveReference(c,n,s);m&&r.push(m)}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let m=new k;m.statement=await this.parseStatements(c,n,s,a,{}),r.push(m)}}let p=new j;return p.predicate=u.parse(e),p.object=r,p}async resolveReference(e,t,i){let n=await i.resolveEntityAsync(e,t);if(n){let a=new u;return a.subject=n.uri,a}let s=t.metadata?.namespace_;if(s){let{KanonakUri:a}=await import("./KanonakUri-4VJGV3FN.js"),r=s.version??{major:0,minor:0,patch:0,toString:()=>"0.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};if(e.includes(".")){let p=e.indexOf("."),c=e.substring(0,p),m=e.substring(p+1);if(t.metadata?.imports){for(let[f,y]of Object.entries(t.metadata.imports))for(let l of y)if((l.alias??l.packageName)===c){let b=new u;return b.subject=new a(f,l.packageName,m,l.version),b}}}let o=new u;return o.subject=new a(s.publisher,s.package_,e,r),o}return null}async saveKanonaks(e,t){let i=new Map;for(let n of e)n instanceof K&&n.namespace&&(i.has(n.namespace)||i.set(n.namespace,[]),i.get(n.namespace).push(n));for(let[n,s]of i){let a=await this.convertKanonaksToDocument(n,s),r=`${n.split("@")[0]}.yml`;await t.saveDocumentAsync(a,r)}}async serializeToYaml(e,t){let i=e.filter(a=>a instanceof K&&a.namespace===t);if(i.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let n=await this.convertKanonaksToDocument(t,i);return new I().save(n)}async convertKanonaksToDocument(e,t){let n={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let a=[];for(let r of Object.values(this.imports))a.push(...r);return a}},body:{}},s=new Map;for(let a of t){let r={};for(let o of a.statement){let[p,c]=this.convertStatementToProperty(o);p&&c!==null&&c!==void 0&&(r[p]=c),this.collectImportsFromStatement(o,e,s)}n.body[a.name]=r}return n}convertStatementToProperty(e){if(e instanceof g)return[e.predicate.subject.name,e.object];if(e instanceof R)return[e.predicate.subject.name,e.object];if(e instanceof S)return[e.predicate.subject.name,e.object];if(e instanceof D)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof j){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof h){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let i of e)i instanceof u?t.push(i.subject.name):i instanceof k&&t.push(this.convertEmbeddedKanonakToValue(i));return t}convertEmbeddedKanonakToValue(e){let t={};for(let i of e.statement){let[n,s]=this.convertStatementToProperty(i);n&&s!==null&&s!==void 0&&(t[n]=s)}return t}collectImportsFromStatement(e,t,i){}};export{k as a,w as b,P as c,x as d,A as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as S}from"./chunk-
|
|
1
|
+
import{a as S}from"./chunk-R2V7IXWN.js";import{c as v,d as u,g as j,j as p,k as h,l as k}from"./chunk-W6T7MOKY.js";function fe(t,n,e,a){let r=D(t);if(r.length>0){let i=r.find(f=>m(f.format,n)&&m(f.variant,e));return i?{transformation:i.transformation,source:"instance"}:void 0}let o=new Set,s=U(t);for(;s.length>0;){let i=s.shift(),f=y(i.subject);if(o.has(f))continue;o.add(f);let c=R(a,i.subject);if(!c)continue;let K=D(c).find(d=>m(d.format,n)&&m(d.variant,e));if(K)return{transformation:K.transformation,source:{publisher:i.subject.publisher,package_:i.subject.package_,name:i.subject.name}};for(let d of T(c))s.push(d)}let l={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"};if(!o.has(y(l))){let i=R(a,l);if(i){let c=D(i).find(g=>m(g.format,n)&&m(g.variant,e));if(c)return{transformation:c.transformation,source:l}}}}function D(t){let n=[];for(let e of t.statement)if(e instanceof k&&b(e,"kanonak.org","derivation","derivations"))for(let a of e.object??[]){if(!(a instanceof S))continue;let r=E(a);r&&n.push(r)}return n}function E(t){let n,e,a;for(let r of t.statement)r instanceof p?b(r,"kanonak.org","derivation","format")?n=x(r):b(r,"kanonak.org","derivation","variant")&&(e=x(r)):r instanceof h&&b(r,"kanonak.org","derivation","transformation")&&(a=_(r.object));if(!(!n||!a))return e||(e={publisher:"kanonak.org",package_:"derivation",name:"default"}),{format:n,variant:e,transformation:a}}function _(t){let n,e,a,r;for(let o of t.statement){if(!(o instanceof j))continue;let s=o.predicate?.subject?.name;s==="publisher"?n=o.object:s==="package"?e=o.object:s==="version"?a=o.object:s==="name"&&(r=o.object)}if(!(!n||!e||!a||!r))return{publisher:n,package_:e,version:a,name:r}}function U(t){let n=[];for(let e of t.statement)e instanceof p&&e.predicate?.subject?.name==="type"&&e.object instanceof u&&n.push(e.object);return n}function T(t){let n=[];for(let e of t.statement)if(e instanceof p){if(e.predicate?.subject?.name!=="subClassOf")continue;e.object instanceof u&&n.push(e.object)}else if(e instanceof k){if(e.predicate?.subject?.name!=="subClassOf")continue;for(let a of e.object??[])a instanceof u&&n.push(a)}return n}function R(t,n){for(let e of t){if(!(e instanceof v)||e.name!==n.name)continue;if((e.namespace||"").startsWith(`${n.publisher}/${n.package_}@`))return e}}function b(t,n,e,a){let r=t.predicate?.subject;return r?r.publisher===n&&r.package_===e&&r.name===a:!1}function x(t){let n=t.object.subject;return{publisher:n.publisher,package_:n.package_,name:n.name}}function m(t,n){return t.publisher===n.publisher&&t.package_===n.package_&&t.name===n.name}function y(t){return`${t.publisher}/${t.package_}/${t.name}`}export{fe as a};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { Reasoner, ReasoningResult, TripleStore, KanonakVocabulary, uriKey, make
|
|
|
6
6
|
export type { ReasonerOptions, ReasoningProfile, Vocabulary, Triple, TripleObject, UriKey, Rule, } from './reasoning/index.js';
|
|
7
7
|
export { GitIgnoreFilter } from './filtering/index.js';
|
|
8
8
|
export type { IGitIgnoreFilter } from './filtering/index.js';
|
|
9
|
-
export { KanonakParser, KanonakObjectParser, PropertyMetadata, KanonakDocumentPositions, parseWithPositions, } from './parsing/index.js';
|
|
9
|
+
export { KanonakParser, KanonakObjectParser, PropertyMetadata, KanonakDocumentPositions, parseWithPositions, findMarkdownLinkAt, } from './parsing/index.js';
|
|
10
10
|
export type { IKanonakObjectParser, SourcePosition, ImportPackageEntry, ParsedDocumentWithPositions, } from './parsing/index.js';
|
|
11
11
|
export { ResourceResolver, KanonakUri, KanonakUriBuilder, parseKanonakAddress, formatKanonakAddress, TypeResolver, ResourceTypeClassifier, findInstancesByType, compareVersions, versionsEqual, formatVersion, parseVersionString, createVersion, isCompatibleVersion, isMajorCompatible, pickHighestDocument, } from './resolution/index.js';
|
|
12
12
|
export type { ResourceResolutionResult, ILogger, InstanceSearchResult, DocumentVersionPick, KanonakAddress, } from './resolution/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{a as Ze,b as Qe,c as et,d as tt,e as rt,f as nt,g as ot,h as at,i as it,j as st}from"./chunk-
|
|
1
|
+
import{a as Ze,b as Qe,c as et,d as tt,e as rt,f as nt,g as ot,h as at,i as it,j as st}from"./chunk-NYXIGTTH.js";import{a as qe,b as Ye,c as Xe,d as b,e as S,f as i}from"./chunk-GD4SYMXW.js";import{a as Wt}from"./chunk-ROCCA4BY.js";import{a as Te,b as je,c as Le,d as Ne,e as Fe}from"./chunk-3JRHG2JH.js";import{a as Be,b as De,c as Oe,d as Ae}from"./chunk-CNM3SY5S.js";import{a as lt,b as dt,c as ut,d as pt}from"./chunk-63NJ25ZX.js";import{a as Je,b as mt,c as ft,d as yt,e as gt}from"./chunk-VRZUCZEF.js";import{a as Pe,b as Re,c as we,d as $e,e as xe,f as ve,g as Ee,h as Ke}from"./chunk-FQHALFRR.js";import{A as _t,B as Mt,C as zt,D as Gt,a as ht,b as kt,c as bt,d as St,e as Ct,f as Pt,g as Rt,h as wt,i as $t,j as xt,k as vt,l as Et,m as Kt,n as Bt,o as It,p as Tt,q as jt,r as Lt,s as Nt,t as Ft,u as Dt,v as Ot,w as At,x as Ht,y as Vt,z as Ut}from"./chunk-LPUWDJMI.js";import"./chunk-FJ35VIV6.js";import{a as N,b as D,c as Me,e as We}from"./chunk-R2V7IXWN.js";import{a as He,b as j,c as L,d as F,e as Ue,f as _e,g as O,h as A,i as H,j as V,k as U,l as _}from"./chunk-W6T7MOKY.js";import{a as Ie}from"./chunk-MYITGTGJ.js";import{b as ze,c as Ge}from"./chunk-IXE5THUW.js";import{a as Ve}from"./chunk-FUUTGGJS.js";import{a as ct}from"./chunk-ODIECDN7.js";import{VersionOperator as to}from"@kanonak-protocol/types/document/models/enums";import{existsSync as ur,readFileSync as pr}from"fs";import{homedir as mr}from"os";import{join as fr}from"path";import{execFile as Jt}from"child_process";import{promisify as qt}from"util";var C=qt(Jt),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)}
|
|
5
5
|
Ensure the Keychain is unlocked and the CLI has write permission.
|
|
6
6
|
On managed devices, your IT policy may block credential storage.`)}}async remove(e){let r=i(e);try{await C(R,["delete-generic-password","-s",P,"-a",r],{timeout:1e4})}catch(n){if(X(n,44))return;console.warn(` Warning: macOS Keychain delete failed for '${r}': ${w(n)}
|
|
7
7
|
The credential may not have been fully removed.`)}}async list(){try{let{stdout:e}=await C(R,["dump-keychain"],{timeout:1e4}),r=[],n=!1;for(let o of e.split(`
|
|
8
|
-
`))if(o.includes(`"svce"<blob>="${P}"`)&&(n=!0),n&&o.includes('"acct"<blob>=')){let a=o.match(/"acct"<blob>="([^"]+)"/);a&&r.push(a[1]),n=!1}return r}catch(e){return console.warn(` Warning: Could not enumerate Keychain entries: ${w(e)}`),[]}}};function X(t,e){return typeof t=="object"&&t!==null&&"code"in t&&t.code===e}function w(t){return t instanceof Error?t.message:String(t)}import{execFile as
|
|
8
|
+
`))if(o.includes(`"svce"<blob>="${P}"`)&&(n=!0),n&&o.includes('"acct"<blob>=')){let a=o.match(/"acct"<blob>="([^"]+)"/);a&&r.push(a[1]),n=!1}return r}catch(e){return console.warn(` Warning: Could not enumerate Keychain entries: ${w(e)}`),[]}}};function X(t,e){return typeof t=="object"&&t!==null&&"code"in t&&t.code===e}function w(t){return t instanceof Error?t.message:String(t)}import{execFile as Yt}from"child_process";import{promisify as Xt}from"util";var Zt=Xt(Yt),$="kanonak:",m=class{async get(e){let r=$+i(e),n=`
|
|
9
9
|
${v}
|
|
10
10
|
$target = [Console]::In.ReadLine()
|
|
11
11
|
$ptr = [IntPtr]::Zero
|
|
@@ -41,7 +41,7 @@ ${v}
|
|
|
41
41
|
$target = [Console]::In.ReadLine()
|
|
42
42
|
[CredMan]::CredDelete($target, 1, 0) | Out-Null`;try{await x(n,r)}catch{}}async list(){let e=`
|
|
43
43
|
${v}
|
|
44
|
-
${
|
|
44
|
+
${Qt}
|
|
45
45
|
$prefix = [Console]::In.ReadLine()
|
|
46
46
|
$count = 0
|
|
47
47
|
$pCreds = [IntPtr]::Zero
|
|
@@ -56,7 +56,7 @@ if ([CredMan]::CredEnumerate($null, 0, [ref]$count, [ref]$pCreds)) {
|
|
|
56
56
|
}
|
|
57
57
|
[CredMan]::CredFree($pCreds)
|
|
58
58
|
}`;try{let{stdout:r}=await x(e,$);return r.trim().split(`
|
|
59
|
-
`).map(n=>n.trim()).filter(Boolean)}catch{return[]}}};async function x(t,e){for(let r of["pwsh","powershell"])try{return await
|
|
59
|
+
`).map(n=>n.trim()).filter(Boolean)}catch{return[]}}};async function x(t,e){for(let r of["pwsh","powershell"])try{return await Zt(r,["-NoProfile","-NonInteractive","-Command",t],{timeout:15e3,...e!==void 0&&{input:e}})}catch(n){if(r==="powershell")throw n}throw new Error("Neither pwsh nor powershell found")}var v=`
|
|
60
60
|
Add-Type -TypeDefinition @"
|
|
61
61
|
using System;
|
|
62
62
|
using System.Runtime.InteropServices;
|
|
@@ -87,13 +87,13 @@ public class CredMan {
|
|
|
87
87
|
[DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
88
88
|
public static extern bool CredEnumerate(string filter, int flags, out int count, out IntPtr credentials);
|
|
89
89
|
}
|
|
90
|
-
"@`,
|
|
91
|
-
`)){let o=n.match(/attribute\.publisher\s*=\s*(.+)/);o&&r.push(o[1].trim())}return r}catch{return[]}}};async function M(){try{return await K("sh",["-c","command -v secret-tool"],{timeout:5e3}),!0}catch{return!1}}import{existsSync as Z,mkdirSync as Q,readFileSync as ee,writeFileSync as te}from"fs";import{createCipheriv as
|
|
90
|
+
"@`,Qt="";import{execFile as er,spawn as tr}from"child_process";import{promisify as rr}from"util";var K=rr(er),E="kanonak",f=class{async get(e){let r=i(e);try{let{stdout:n}=await K("secret-tool",["lookup","service",E,"publisher",r],{timeout:1e4}),o=n.trim();return o?JSON.parse(o):null}catch{return null}}async store(e,r){let n=i(e),o=JSON.stringify(r);await new Promise((a,s)=>{let c=tr("secret-tool",["store","--label",`Kanonak: ${n}`,"service",E,"publisher",n],{stdio:["pipe","ignore","ignore"],timeout:1e4});c.stdin.write(o),c.stdin.end(),c.on("close",l=>{l===0?a():s(new Error(`secret-tool store exited with code ${l}`))}),c.on("error",s)})}async remove(e){let r=i(e);try{await K("secret-tool",["clear","service",E,"publisher",r],{timeout:1e4})}catch{}}async list(){try{let{stdout:e}=await K("secret-tool",["search","service",E],{timeout:1e4}),r=[];for(let n of e.split(`
|
|
91
|
+
`)){let o=n.match(/attribute\.publisher\s*=\s*(.+)/);o&&r.push(o[1].trim())}return r}catch{return[]}}};async function M(){try{return await K("sh",["-c","command -v secret-tool"],{timeout:5e3}),!0}catch{return!1}}import{existsSync as Z,mkdirSync as Q,readFileSync as ee,writeFileSync as te}from"fs";import{createCipheriv as nr,createDecipheriv as or,randomBytes as re}from"crypto";import{homedir as ar}from"os";import{join as W,dirname as ne}from"path";var ae=W(ar(),".config","kanonak"),y=W(ae,"keyring.key"),B=W(ae,"credentials.enc"),oe="aes-256-gcm",z=32,u=12,G=16,g=class{async get(e){let r=this.loadStore(),n=i(e);return r[n]??null}async store(e,r){let n=this.loadStore(),o=i(e);n[o]=r,this.saveStore(n)}async remove(e){let r=this.loadStore(),n=i(e);delete r[n],this.saveStore(r)}async list(){let e=this.loadStore();return Object.keys(e)}loadStore(){if(!Z(B))return{};try{let e=this.getOrCreateKey(),r=ee(B);if(r.length<u+G)return{};let n=r.subarray(0,u),o=r.subarray(u,u+G),a=r.subarray(u+G),s=or(oe,e,n);s.setAuthTag(o);let c=Buffer.concat([s.update(a),s.final()]);return JSON.parse(c.toString("utf-8"))}catch{return{}}}saveStore(e){let r=this.getOrCreateKey(),n=re(u),o=nr(oe,r,n),a=Buffer.from(JSON.stringify(e),"utf-8"),s=Buffer.concat([o.update(a),o.final()]),c=o.getAuthTag(),l=Buffer.concat([n,c,s]);Q(ne(B),{recursive:!0}),te(B,l,{mode:384})}getOrCreateKey(){if(Z(y)){let r=ee(y);if(r.length!==z)throw new Error(`Credential keyring key is corrupted (expected ${z} bytes, got ${r.length}). Delete ${y} and re-authenticate.`);return r}let e=re(z);return Q(ne(y),{recursive:!0}),te(y,e,{mode:384}),e}};import{execFile as ir}from"child_process";import{promisify as sr}from"util";var cr=sr(ir),ie=3e4,h=class{constructor(e){this.helperPath=e}helperPath;async get(e){let r=i(e);try{let o=(await this.runHelper("get",{publisher:r})).trim();return o?JSON.parse(o):null}catch(n){throw new Error(`Credential helper '${this.helperPath}' failed to read credential for '${r}': ${I(n)}
|
|
92
92
|
Verify the helper binary exists, is executable, and implements the Kanonak credential helper protocol.
|
|
93
93
|
Check the 'credentialHelper' path in ~/.kanonak/config.json.`)}}async store(e,r){let n=i(e);try{await this.runHelper("store",{publisher:n,credential:r})}catch(o){throw new Error(`Credential helper '${this.helperPath}' failed to store credential for '${n}': ${I(o)}
|
|
94
|
-
Verify the helper binary supports the 'store' action.`)}}async remove(e){let r=i(e);try{await this.runHelper("erase",{publisher:r})}catch(n){console.warn(` Warning: Credential helper '${this.helperPath}' failed to erase credential for '${r}': ${I(n)}`)}}async list(){try{let e=await this.runHelper("list",void 0);return JSON.parse(e.trim())}catch(e){return console.warn(` Warning: Credential helper '${this.helperPath}' failed to list credentials: ${I(e)}`),[]}}async runHelper(e,r){try{let{stdout:n}=await
|
|
95
|
-
Check the 'credentialHelper' path in ~/.kanonak/config.json.`):
|
|
96
|
-
The helper may be waiting for authentication to an external vault.`):n}}};function I(t){return t instanceof Error?t.message:String(t)}function
|
|
97
|
-
Using default credential backend. Fix the JSON syntax or delete the file.`),{}}}import{createHash as
|
|
98
|
-
The stored key pair may be corrupted. Run 'kanonak login ${n}' to re-authenticate.`),s.Authorization=`Bearer ${a.accessToken}`}}else s.Authorization=`Bearer ${a.accessToken}`;let c=await fetch(r,{method:o,headers:s});if(c.status===401&&a.dpopKeyPair){let l=c.headers.get("DPoP-Nonce");if(l){e.set(n,l);try{let d=k(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,r,a.accessToken,l);s.DPoP=d,c=await fetch(r,{method:o,headers:s})}catch{}}}return c}}import{readFileSync as
|
|
99
|
-
`;function me(t=pe){if(
|
|
94
|
+
Verify the helper binary supports the 'store' action.`)}}async remove(e){let r=i(e);try{await this.runHelper("erase",{publisher:r})}catch(n){console.warn(` Warning: Credential helper '${this.helperPath}' failed to erase credential for '${r}': ${I(n)}`)}}async list(){try{let e=await this.runHelper("list",void 0);return JSON.parse(e.trim())}catch(e){return console.warn(` Warning: Credential helper '${this.helperPath}' failed to list credentials: ${I(e)}`),[]}}async runHelper(e,r){try{let{stdout:n}=await cr(this.helperPath,[e],{...r&&{input:JSON.stringify(r)},timeout:ie});return n}catch(n){throw lr(n)?new Error(`Credential helper not found at '${this.helperPath}'.
|
|
95
|
+
Check the 'credentialHelper' path in ~/.kanonak/config.json.`):dr(n)?new Error(`Credential helper '${this.helperPath}' timed out after ${ie/1e3}s on '${e}'.
|
|
96
|
+
The helper may be waiting for authentication to an external vault.`):n}}};function I(t){return t instanceof Error?t.message:String(t)}function lr(t){return t instanceof Error&&"code"in t&&t.code==="ENOENT"}function dr(t){return t instanceof Error&&"killed"in t&&t.killed}var J=fr(mr(),".kanonak","config.json"),T=class{backend=null;backendReady=null;async getBackend(){if(this.backend)return this.backend;if(this.backendReady)return this.backendReady;this.backendReady=this.resolveBackend();try{return this.backend=await this.backendReady,this.backend}catch(e){throw this.backendReady=null,e}}async getToken(e){let r=yr(e);if(r)return r;let o=await(await this.getBackend()).get(e);return!o||!S(o)?null:o.accessToken??null}async getCredential(e){return(await this.getBackend()).get(e)}async store(e,r){return(await this.getBackend()).store(e,r)}async remove(e){return(await this.getBackend()).remove(e)}async list(){return(await this.getBackend()).list()}async resolveBackend(){let e=gr();return e.credentialHelper?new h(e.credentialHelper):process.platform==="darwin"?new p:process.platform==="win32"?new m:await M()?new f:new g}};function yr(t){let r="KANONAK_TOKEN_"+i(t).replace(/[.\-]/g,"_").toUpperCase();return process.env[r]??null}function gr(){if(!ur(J))return{};try{return JSON.parse(pr(J,"utf-8"))}catch(t){let e=t instanceof Error?t.message:String(t);return console.warn(` Warning: Failed to parse ${J}: ${e}
|
|
97
|
+
Using default credential backend. Fix the JSON syntax or delete the file.`),{}}}import{createHash as hr,createPrivateKey as kr,generateKeyPairSync as br,randomUUID as Sr,sign as Cr}from"crypto";function ce(){let{publicKey:t,privateKey:e}=br("ec",{namedCurve:"P-256"});return{publicKey:t.export({format:"jwk"}),privateKey:e.export({format:"jwk"})}}function k(t,e,r,n,o,a){let s={alg:"ES256",typ:"dpop+jwt",jwk:{kty:e.kty,crv:e.crv,x:e.x,y:e.y}},c={jti:Sr(),htm:r.toUpperCase(),htu:n,iat:Math.floor(Date.now()/1e3)};return o&&(c.ath=hr("sha256").update(o).digest("base64url")),a&&(c.nonce=a),Pr(s,c,t)}function le(t){return!t||t.length===0?!1:t.some(e=>e.toUpperCase()==="ES256")}function Pr(t,e,r){let n=se(JSON.stringify(t)),o=se(JSON.stringify(e)),a=`${n}.${o}`,s=kr({key:r,format:"jwk"}),l=Cr("SHA256",Buffer.from(a),{key:s,dsaEncoding:"ieee-p1363"}).toString("base64url");return`${a}.${l}`}function se(t){return Buffer.from(t,"utf-8").toString("base64url")}function de(t){let e=new Map;return async(r,n,o="GET")=>{if(!t)return fetch(r,{method:o});let a=await t.getCredential(n);if(!a?.accessToken)return fetch(r,{method:o});b(a)&&console.warn(` Warning: Access token for '${n}' is expired. Run 'kanonak login ${n}' to re-authenticate.`);let s={};if(a.dpopKeyPair){let l=e.get(n);try{let d=k(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,r,a.accessToken,l);s.Authorization=`DPoP ${a.accessToken}`,s.DPoP=d}catch(d){let Ce=d instanceof Error?d.message:String(d);console.error(` Error: Failed to create DPoP proof for '${n}': ${Ce}
|
|
98
|
+
The stored key pair may be corrupted. Run 'kanonak login ${n}' to re-authenticate.`),s.Authorization=`Bearer ${a.accessToken}`}}else s.Authorization=`Bearer ${a.accessToken}`;let c=await fetch(r,{method:o,headers:s});if(c.status===401&&a.dpopKeyPair){let l=c.headers.get("DPoP-Nonce");if(l){e.set(n,l);try{let d=k(a.dpopKeyPair.privateKey,a.dpopKeyPair.publicKey,o,r,a.accessToken,l);s.DPoP=d,c=await fetch(r,{method:o,headers:s})}catch{}}}return c}}import{readFileSync as Rr,writeFileSync as wr,existsSync as $r}from"fs";import{createHash as xr}from"crypto";import ue from"js-yaml";var pe="kanonak.lock",vr=`# This file is generated by Kanonak CLI. Do not edit manually.
|
|
99
|
+
`;function me(t=pe){if(!$r(t))return null;let e=Rr(t,"utf-8"),r=ue.load(e);return!r||typeof r!="object"||r.version!=="1"?null:{version:"1",lastUpdated:r.lastUpdated??new Date().toISOString(),packages:r.packages??{}}}function fe(t,e=pe){t.lastUpdated=new Date().toISOString();let r={};for(let o of Object.keys(t.packages).sort())r[o]=t.packages[o];t.packages=r;let n=ue.dump(t,{lineWidth:-1,sortKeys:!1,quotingType:'"'});wr(e,vr+n,"utf-8")}function ye(t){return`sha256:${xr("sha256").update(t).digest("hex")}`}import{createHash as Er}from"crypto";function q(t){let e=[];for(let n of t)n instanceof L&&e.push(Kr(n));return e.sort((n,o)=>n.uri<o.uri?-1:n.uri>o.uri?1:0),JSON.stringify({subjects:e})}function ge(t){let e=q(t);return`sha256:${Er("sha256").update(e,"utf8").digest("hex")}`}function Kr(t){let e=Nr(t),r=Y(t.statement);return{uri:e,statements:r}}function Y(t){let e=[];for(let r of t){let n=Br(r);n&&e.push(n)}return e.sort((r,n)=>r.predicate<n.predicate?-1:r.predicate>n.predicate?1:0),e}function Br(t){let e=Lr(t);if(!e)return;let r=Ir(t);if(r)return jr(e,r)}function Ir(t){if(t instanceof O)return{type:"string",value:t.object};if(t instanceof A)return{type:"number",value:Se(t.object)};if(t instanceof H)return{type:"boolean",value:t.object};if(t instanceof V)return{type:"ref",value:ke(t.object)};if(t instanceof U){let e=t.object;return he(e)}if(t instanceof _)return{type:"list",items:t.object.map(Tr)}}function he(t){let e=Y(t.statement);return t.name&&t.name.length>0?{type:"embedded",name:t.name,statements:e}:{type:"embedded",statements:e}}function Tr(t){if(t instanceof F)return{type:"ref",value:ke(t)};if(t instanceof N)return he(t);if(t instanceof D){let e=t.value;if(typeof e=="string")return{type:"string",value:e};if(typeof e=="number")return{type:"number",value:Se(e)};if(typeof e=="boolean")return{type:"boolean",value:e}}if(t instanceof j)return{type:"embedded",statements:Y(t.statement)};throw new Error(`canonicalForm: list item of unrecognized kind (${t.constructor?.name??typeof t}); add canonicalization support before hashing data that contains it`)}function jr(t,e){switch(e.type){case"string":return{predicate:t,type:"string",value:e.value};case"number":return{predicate:t,type:"number",value:e.value};case"boolean":return{predicate:t,type:"boolean",value:e.value};case"ref":return{predicate:t,type:"ref",value:e.value};case"embedded":return e.name!==void 0?{predicate:t,type:"embedded",name:e.name,statements:e.statements}:{predicate:t,type:"embedded",statements:e.statements};case"list":return{predicate:t,type:"list",items:e.items}}}function Lr(t){let e=t.predicate;if(e)return be(e.subject)}function Nr(t){let e=t.namespace??"",r=t.name??"";return`${e}/${r}`}function ke(t){return be(t.subject)}function be(t){let e=t.version;return e&&typeof e.major=="number"?`${t.publisher}/${t.package_}@${e.major}.${e.minor}.${e.patch}/${t.name}`:`${t.publisher}/${t.package_}/${t.name}`}function Se(t){if(Number.isNaN(t))throw new Error("canonicalForm: NaN cannot be canonicalized");if(!Number.isFinite(t))throw new Error("canonicalForm: \xB1Infinity cannot be canonicalized");return Object.is(t,-0)?"0":String(t)}export{Ot as AmbiguousReferenceRule,H as BooleanStatement,Mt as ClassDefinitionRule,Kt as ClassHierarchyCycleRule,Le as CompositeKanonakDocumentRepository,T as CredentialStore,j as DefinedKanonak,Ft as DefinitionPropertyReferenceRule,je as DocumentLocation,Ye as EdgeType,N as EmbeddedKanonak,$t as EmbeddedKanonakTypeRule,U as EmbeddedStatement,Te as FileSystemKanonakDocumentRepository,ct as GitIgnoreFilter,Xe as GraphBuilder,Ae as HttpKanonakDocumentRepository,xt as ImportExistenceRule,Be as InMemoryKanonakDocumentRepository,Nt as InstancePropertyReferenceRule,He as Kanonak,dt as KanonakDocumentPositions,We as KanonakObjectParser,Gt as KanonakObjectValidator,Ie as KanonakParser,Ve as KanonakUri,mt as KanonakUriBuilder,nt as KanonakVocabulary,_ as ListStatement,D as LiteralKanonak,zt as MarkdownLinkRule,Me as MarkdownStatement,Lt as NamespaceImportCycleRule,Ct as NamespacePrefixRule,qe as NodeType,A as NumberStatement,at as OWL_RL_CLASSIFICATION_RULES,Ht as ObjectPropertyImportRule,Vt as ObjectPropertyValueValidationRule,bt as OntologyValidationError,ht as OntologyValidationResult,Ut as PropertyDomainRule,Bt as PropertyHierarchyCycleRule,lt as PropertyMetadata,At as PropertyRangeReferenceRule,It as PropertyRangeRequiredRule,Rt as PropertyTypeSpecificityRule,_t as PropertyValueTypeRule,De as PublisherConfigResolver,Oe as PublisherIndex,ot as RDFS_RULES,st as Reasoner,it as ReasoningResult,F as ReferenceKanonak,V as ReferenceStatement,Fe as RepositoryFactory,Pt as ResourceNamingRule,ze as ResourceResolver,Je as ResourceTypeClassifier,_e as ScalarStatement,Ue as Statement,O as StringStatement,Tt as SubClassOfReferenceRule,jt as SubPropertyOfReferenceRule,L as SubjectKanonak,wt as SubjectKanonakTypeRequiredRule,rt as TripleStore,Et as TypeAmbiguityRule,Ge as TypeResolver,vt as UnresolvedReferenceRule,St as ValidationContext,kt as ValidationSeverity,to as VersionOperator,Dt as XsdImportRule,q as canonicalForm,ge as canonicalHash,Pe as compareVersions,ye as computeIntegrity,de as createAuthenticatedFetch,k as createDPoPProof,$e as createVersion,Wt as findDerivation,gt as findInstancesByType,pt as findMarkdownLinkAt,yt as formatKanonakAddress,we as formatVersion,ce as generateDPoPKeyPair,Ne as getGlobalCachePath,S as hasValidToken,ve as isCompatibleVersion,b as isExpired,Ee as isMajorCompatible,me as loadLockFile,Qe as makeUriKey,i as normalizeHost,ft as parseKanonakAddress,xe as parseVersionString,ut as parseWithPositions,Ke as pickHighestDocument,fe as saveLockFile,le as serverSupportsDPoP,et as tripleKey,Ze as uriKey,tt as uriTriple,Re as versionsEqual};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map a document cursor position back to a `MarkdownLink` from a
|
|
3
|
+
* `MarkdownStatement`.
|
|
4
|
+
*
|
|
5
|
+
* `MarkdownLink.startOffset` and `endOffset` are character offsets
|
|
6
|
+
* within the *decoded* value string (`stmt.object`). Editor consumers
|
|
7
|
+
* receive cursor positions as `(line, column)` in the *source* YAML.
|
|
8
|
+
* Bridging those two domains for an arbitrary YAML scalar form
|
|
9
|
+
* (plain, literal `|`, folded `>`, quoted with escapes) is annoying
|
|
10
|
+
* in the general case.
|
|
11
|
+
*
|
|
12
|
+
* The trick: `[[reference]]` markers are preserved character-for-
|
|
13
|
+
* character through every YAML scalar form — none of them escape
|
|
14
|
+
* `[` or otherwise transform the markers. So running the same link-
|
|
15
|
+
* extraction regex over the source slice covering the value's range
|
|
16
|
+
* produces matches in the same order as the decoded-value pass, with
|
|
17
|
+
* positions directly comparable to the editor cursor. No YAML-form-
|
|
18
|
+
* specific decoding required.
|
|
19
|
+
*
|
|
20
|
+
* Returns `undefined` when the cursor isn't inside any link's source
|
|
21
|
+
* span (including the trivial case "cursor is outside the value's
|
|
22
|
+
* range entirely") or when the source-side and value-side link counts
|
|
23
|
+
* disagree (a defensive case that shouldn't happen for plain or
|
|
24
|
+
* literal `|` scalars — the only forms in real Kanonak Markdown
|
|
25
|
+
* content — but we'd rather fail safe than guess at a wrong link).
|
|
26
|
+
*/
|
|
27
|
+
import type { MarkdownLink, MarkdownStatement } from '../statements/MarkdownStatement.js';
|
|
28
|
+
import type { SourcePosition } from './KanonakDocumentPositions.js';
|
|
29
|
+
export declare function findMarkdownLinkAt(stmt: MarkdownStatement, cursorLine: number, cursorColumn: number, valuePosition: SourcePosition, sourceText: string): MarkdownLink | undefined;
|
package/dist/parsing/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export { KanonakDocumentPositions } from './KanonakDocumentPositions.js';
|
|
|
6
6
|
export type { SourcePosition, ImportPackageEntry } from './KanonakDocumentPositions.js';
|
|
7
7
|
export { parseWithPositions } from './parseWithPositions.js';
|
|
8
8
|
export type { ParsedDocumentWithPositions } from './parseWithPositions.js';
|
|
9
|
+
export { findMarkdownLinkAt } from './findMarkdownLinkAt.js';
|
|
9
10
|
export type { IKanonakParser } from '@kanonak-protocol/types/document/parsing';
|
|
10
11
|
export type { KanonakDocument, KanonakMetadata, Namespace, Import, Version, ParseResult, ParseError } from '@kanonak-protocol/types/document/models/types';
|
package/dist/parsing/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as c,b as d,c as e}from"../chunk-
|
|
1
|
+
import{a as c,b as d,c as e,d as f}from"../chunk-63NJ25ZX.js";import{e as b}from"../chunk-R2V7IXWN.js";import"../chunk-W6T7MOKY.js";import{a}from"../chunk-MYITGTGJ.js";import"../chunk-IXE5THUW.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,b,c,d,e,f,g,h,i,j}from"../chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j}from"../chunk-NYXIGTTH.js";import"../chunk-R2V7IXWN.js";import"../chunk-W6T7MOKY.js";import"../chunk-MYITGTGJ.js";import"../chunk-IXE5THUW.js";import"../chunk-FUUTGGJS.js";export{f as KanonakVocabulary,h as OWL_RL_CLASSIFICATION_RULES,g as RDFS_RULES,j as Reasoner,i as ReasoningResult,e as TripleStore,b as makeUriKey,c as tripleKey,a as uriKey,d as uriTriple};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as S,c as I,d as f,f as q}from"../chunk-2JQMUZWN.js";import{a as Ne}from"../chunk-
|
|
1
|
+
import{b as S,c as I,d as f,f as q}from"../chunk-2JQMUZWN.js";import{a as Ne}from"../chunk-ROCCA4BY.js";import"../chunk-63NJ25ZX.js";import{a as Oe}from"../chunk-FJ35VIV6.js";import{a as R,c as Ce,e as Ue}from"../chunk-R2V7IXWN.js";import{b as K,c as E,d as b,g as L,h as C,i as U,j as V,k as T,l as w}from"../chunk-W6T7MOKY.js";import{a as Re}from"../chunk-MYITGTGJ.js";import"../chunk-IXE5THUW.js";import"../chunk-FUUTGGJS.js";var bt="kanonak.org",wt="document-ast",p=t=>({publisher:bt,package_:wt,name:t}),h={Document:p("Document"),Block:p("Block"),Inline:p("Inline"),StructuredValue:p("StructuredValue"),Heading:p("Heading"),Paragraph:p("Paragraph"),RawBlock:p("RawBlock"),Text:p("Text"),StructuredMap:p("StructuredMap"),StructuredEntry:p("StructuredEntry"),StructuredList:p("StructuredList"),StringScalar:p("StringScalar"),IntegerScalar:p("IntegerScalar"),EscapeHint:p("EscapeHint"),MediaType:p("MediaType"),metadata:p("metadata"),children:p("children"),level:p("level"),inlines:p("inlines"),text:p("text"),entries:p("entries"),key:p("key"),value:p("value"),escapeHint:p("escapeHint"),items:p("items"),stringValue:p("stringValue"),integerValue:p("integerValue"),rawContent:p("rawContent"),mediaType:p("mediaType"),mimeType:p("mimeType"),ESC_RAW:p("esc-raw"),ESC_YAML_SAFE:p("esc-yaml-safe"),ESC_TOML_STRING:p("esc-toml-string"),ESC_TOML_MULTILINE:p("esc-toml-multiline"),ESC_JSON:p("esc-json"),ESC_DYNAMODB_BOOL:p("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:p("esc-dynamodb-number"),ESC_DYNAMODB_NULL:p("esc-dynamodb-null"),TEXT_PLAIN:p("text-plain"),TEXT_MARKDOWN:p("text-markdown"),TEXT_HTML:p("text-html"),TEXT_CSS:p("text-css"),APPLICATION_JSON:p("application-json"),TEXT_YAML:p("text-yaml"),IMAGE_SVG_XML:p("image-svg-xml"),ResourceLink:p("ResourceLink"),target:p("target"),linkLabel:p("linkLabel"),PropertyList:p("PropertyList"),propertyEntries:p("propertyEntries"),PropertyEntry:p("PropertyEntry"),propertyKey:p("propertyKey"),propertyValue:p("propertyValue"),Table:p("Table"),tableColumnLabels:p("tableColumnLabels"),tableRows:p("tableRows"),TableRow:p("TableRow"),tableCells:p("tableCells")};function _e(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=St(e.metadata,n),i=vt(e.children),u=["---",...r,"---","",i].join(`
|
|
2
2
|
`);return n?.trailingNewline&&(u.endsWith(`
|
|
3
3
|
`)||(u+=`
|
|
4
4
|
`)),u}};function St(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ce(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ce(c),l);let a=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ce),u=[];for(let c of a){let l=n.get(c);if(!l)continue;let m=r.get(c),g=ce(m??c),k=Me(l.value,l.escapeHint);k!==void 0&&u.push(`${g}: ${k}`)}return u}function ce(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Me(t,e){switch(t.kind){case"StringScalar":return Et(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let i=Me(r,e);i!==void 0&&n.push(i)}return n.join(", ")}case"StructuredMap":return;default:return}}function Et(t,e){return!e||_e(e,h.ESC_RAW)?t:_e(e,h.ESC_YAML_SAFE)?$t(t):t}function $t(t){return t.includes(`
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,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,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-LPUWDJMI.js";import"../chunk-FJ35VIV6.js";import"../chunk-R2V7IXWN.js";import"../chunk-W6T7MOKY.js";import"../chunk-MYITGTGJ.js";import"../chunk-IXE5THUW.js";import"../chunk-FUUTGGJS.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,m as ClassHierarchyCycleRule,t as DefinitionPropertyReferenceRule,i as EmbeddedKanonakTypeRule,j as ImportExistenceRule,s as InstancePropertyReferenceRule,D as KanonakObjectValidator,C as MarkdownLinkRule,r as NamespaceImportCycleRule,e 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,g as PropertyTypeSpecificityRule,A as PropertyValueTypeRule,f as ResourceNamingRule,p as SubClassOfReferenceRule,q as SubPropertyOfReferenceRule,h as SubjectKanonakTypeRequiredRule,l as TypeAmbiguityRule,k as UnresolvedReferenceRule,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.23.0",
|
|
4
4
|
"description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"yaml-parser"
|
|
114
114
|
],
|
|
115
115
|
"dependencies": {
|
|
116
|
-
"@kanonak-protocol/types": "^3.
|
|
116
|
+
"@kanonak-protocol/types": "^3.23.0",
|
|
117
117
|
"ignore": "^7.0.5",
|
|
118
118
|
"js-yaml": "^4.1.0",
|
|
119
119
|
"yaml": "^2.7.0"
|
package/dist/chunk-CQLO62JP.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as M}from"./chunk-MYITGTGJ.js";var N=class{propertyUri;propertyType;range;rangeUri;isImported;definedInNamespace};import{parseDocument as R,LineCounter as x,isMap as S,isPair as p,isScalar as g,isSeq as E}from"yaml";var I=class o{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 n=new o,t=new x,i=R(e,{lineCounter:t});if(i.errors.length>0||!S(i.contents))return n;A(i.contents,[],t,n);for(let r of i.contents.items){if(!p(r)||!g(r.key))continue;let a=String(r.key.value),u=r.key.range;if(!u)continue;n.entities.set(a,l(u,t));let s=r.value,c=s&&typeof s=="object"&&"range"in s?s.range:void 0;if(c?n.entityBlocks.set(a,l([u[0],u[1],c[2]],t)):n.entityBlocks.set(a,l(u,t)),S(r.value)){let k=new Map,m=new Map,v=new Map;for(let y of r.value.items){if(!p(y)||!g(y.key))continue;let h=String(y.key.value),f=y.key.range;f&&k.set(h,l(f,t));let P=y.value;if(P&&typeof P=="object"&&"range"in P&&Array.isArray(P.range)){let b=P.range;m.set(h,l(b,t))}if(E(P)){let b=[];for(let K of P.items)K&&typeof K=="object"&&"range"in K&&Array.isArray(K.range)&&b.push(l(K.range,t));b.length>0&&v.set(h,b)}}k.size>0&&n.properties.set(a,k),m.size>0&&n.propertyValues.set(a,m),v.size>0&&n.valueListItems.set(a,v);let d=C(r.value,t);d.length>0&&n.importPackages.set(a,d)}}return n}getEntityPosition(e){return this.entities.get(e)}getEntityBlockPosition(e){return this.entityBlocks.get(e)}findEntityAtPosition(e,n){for(let[t,i]of this.entityBlocks)if(L(i,e,n))return t}findPropertyAtPosition(e,n){let t=this.findEntityAtPosition(e,n);if(!t)return;let i=this.properties.get(t),r=this.propertyValues.get(t);if(!i&&!r)return{entityName:t};let a,u;if(r)for(let[s,c]of r)L(c,e,n)&&(!u||V(c,u))&&(a=s,u=c);if(i)for(let[s,c]of i)L(c,e,n)&&(!u||V(c,u))&&(a=s,u=c);return a?{entityName:t,propertyName:a}:{entityName:t}}getPropertyPosition(e,n){return this.properties.get(e)?.get(n)}getPropertyValuePosition(e,n){return this.propertyValues.get(e)?.get(n)}getImportPackages(e){return this.importPackages.get(e)??[]}getAllImportPackages(){let e=[];for(let[n,t]of this.importPackages)for(let i of t)e.push({entityName:n,entry:i});return e}findPropertySourceName(e,n){let t=this.properties.get(e);if(t){if(t.has(n))return n;for(let i of t.keys()){let r=i.lastIndexOf(".");if((r===-1?i:i.substring(r+1))===n)return i}}}getListItemPosition(e,n,t){let i=this.valueListItems.get(e)?.get(n);if(!(!i||t<0||t>=i.length))return i[t]}getNodeKeyPosition(e){return this.nestedKeys.get(JSON.stringify(e))}getNodeValuePosition(e){return this.nestedValues.get(JSON.stringify(e))}setNestedKeyPosition(e,n){this.nestedKeys.set(e,n)}setNestedValuePosition(e,n){this.nestedValues.set(e,n)}getMostSpecificPosition(e,n,t){if(e){if(n!==void 0){if(t!==void 0){let a=this.getListItemPosition(e,n,t);if(a)return a}let i=this.getPropertyValuePosition(e,n);if(i)return i;let r=this.getPropertyPosition(e,n);if(r)return r}return this.getEntityPosition(e)}}};function C(o,e){let n=[];if(!S(o))return n;let t=o.items.find(i=>p(i)&&g(i.key)&&String(i.key.value)==="imports");if(!t||!p(t)||!E(t.value))return n;for(let i of t.value.items){if(!S(i))continue;let r=i.items.find(s=>p(s)&&g(s.key)&&String(s.key.value)==="publisher");if(!r||!p(r)||!g(r.value))continue;let a=String(r.value.value),u=i.items.find(s=>p(s)&&g(s.key)&&String(s.key.value)==="packages");if(!(!u||!p(u)||!E(u.value)))for(let s of u.value.items){if(!S(s))continue;let c=s.items.find(f=>p(f)&&g(f.key)&&String(f.key.value)==="package");if(!c||!p(c)||!g(c.value)||!c.value.range)continue;let k=String(c.value.value),m=s.items.find(f=>p(f)&&g(f.key)&&String(f.key.value)==="version"),v=m&&p(m)&&g(m.value)?String(m.value.value):"",d=s.items.find(f=>p(f)&&g(f.key)&&String(f.key.value)==="alias"),y=d&&p(d)&&g(d.value)?String(d.value.value):void 0,h=y!==void 0?{publisher:a,package_:k,version:v,alias:y,position:l(c.value.range,e)}:{publisher:a,package_:k,version:v,position:l(c.value.range,e)};n.push(h)}}return n}function L(o,e,n){return!(e<o.line||e>o.endLine||e===o.line&&n<o.column||e===o.endLine&&n>o.endColumn)}function V(o,e){let n=o.endLine-o.line,t=e.endLine-e.line;if(n!==t)return n<t;let i=o.endLine===o.line?o.endColumn-o.column:Number.MAX_SAFE_INTEGER,r=e.endLine===e.line?e.endColumn-e.column:Number.MAX_SAFE_INTEGER;return i<r}function A(o,e,n,t){if(S(o)){for(let i of o.items){if(!p(i)||!g(i.key))continue;let r=String(i.key.value),a=[...e,r],u=JSON.stringify(a);i.key.range&&t.setNestedKeyPosition(u,l(i.key.range,n));let s=i.value,c=w(s);c&&t.setNestedValuePosition(u,l(c,n)),A(s,a,n,t)}return}if(E(o)){for(let i=0;i<o.items.length;i++){let r=o.items[i],a=[...e,i],u=JSON.stringify(a),s=w(r);s&&t.setNestedValuePosition(u,l(s,n)),A(r,a,n,t)}return}}function w(o){if(!o||typeof o!="object"||!("range"in o))return;let e=o.range;return Array.isArray(e)&&e.length>=3?e:void 0}function l(o,e){let n=e.linePos(o[0]),t=e.linePos(o[2]);return{line:n.line-1,column:n.col-1,endLine:t.line-1,endColumn:t.col-1}}function D(o,e){let t=(e??new M).parse(o),i=I.fromContent(o);return{document:t,positions:i}}export{N as a,I as b,D as c};
|