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