@kanonak-protocol/sdk 5.29.0 → 5.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/browser.js +1 -1
  2. package/dist/chunk-7UYXTYXC.js +1 -0
  3. package/dist/chunk-AXQ4DBJD.js +68 -0
  4. package/dist/{chunk-HBG6SC5L.js → chunk-BS7RRG7D.js} +1 -1
  5. package/dist/chunk-BZ3YTI3C.js +2 -0
  6. package/dist/{chunk-4SMQ7G23.js → chunk-EVMSO7HJ.js} +1 -1
  7. package/dist/chunk-F67UH4FD.js +1 -0
  8. package/dist/chunk-HF5FJBS2.js +1 -0
  9. package/dist/{chunk-JFBPQN6T.js → chunk-IS3AQKB4.js} +1 -1
  10. package/dist/{chunk-ZRCJGTEV.js → chunk-J4ZD6IF6.js} +1 -1
  11. package/dist/chunk-KIBR3HAT.js +1 -0
  12. package/dist/{chunk-GMK4YL3X.js → chunk-L2J7WD7E.js} +1 -1
  13. package/dist/chunk-PVUBHIU2.js +1 -0
  14. package/dist/{chunk-D66LUZDB.js → chunk-V3DH67P3.js} +1 -1
  15. package/dist/{chunk-ANJAHB4N.js → chunk-Z5Y4MCW5.js} +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/parsing/KanonakObjectParser.d.ts +9 -0
  19. package/dist/parsing/index.js +1 -1
  20. package/dist/reasoning/index.js +1 -1
  21. package/dist/repositories/PublisherIndex.d.ts +13 -1
  22. package/dist/repositories/browser.js +1 -1
  23. package/dist/repositories/buildLocalFirstRepository.d.ts +1 -0
  24. package/dist/repositories/index.js +1 -1
  25. package/dist/resolution/ResourceTypeClassifier.d.ts +9 -0
  26. package/dist/resolution/importMode.d.ts +26 -0
  27. package/dist/resolution/index.d.ts +1 -0
  28. package/dist/resolution/index.js +1 -1
  29. package/dist/search/index.js +1 -1
  30. package/dist/server/index.js +1 -1
  31. package/dist/transformations/index.js +1 -1
  32. package/dist/validation/KanonakObjectValidator.d.ts +5 -1
  33. package/dist/validation/index.d.ts +1 -1
  34. package/dist/validation/index.js +1 -1
  35. package/dist/validation/rules/document/NamespacePrefixRule.d.ts +8 -0
  36. package/dist/validation/rules/repository/LinkTargetRule.d.ts +42 -0
  37. package/dist/validation/rules/repository/index.d.ts +1 -0
  38. package/package.json +2 -2
  39. package/dist/chunk-3DWEBQSD.js +0 -68
  40. package/dist/chunk-BRCVOR7A.js +0 -1
  41. package/dist/chunk-F3SGXIDP.js +0 -1
  42. package/dist/chunk-G3GKOJ5E.js +0 -1
  43. package/dist/chunk-KOWDHKBN.js +0 -1
  44. package/dist/chunk-P5VQEDBS.js +0 -2
  45. /package/dist/{chunk-PEB52US5.js → chunk-XK24CN3C.js} +0 -0
@@ -1,4 +1,4 @@
1
- import{c as Pe}from"../chunk-D66LUZDB.js";import{a as be,d as X,f as Se,h as ee}from"../chunk-JFBPQN6T.js";import{e as ve,g as $e,m as U,n as Z}from"../chunk-P5VQEDBS.js";import"../chunk-PEB52US5.js";import"../chunk-SC5M74NM.js";import{a as H,b as G}from"../chunk-BRCVOR7A.js";import{r as te}from"../chunk-ANJAHB4N.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{m as oe}from"../chunk-F3SGXIDP.js";import{a as O}from"../chunk-KOWDHKBN.js";import{a as xe}from"../chunk-PEJALHXK.js";import{c as Re}from"../chunk-G3GKOJ5E.js";import{c as we,u as re}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import{c as V,e as E,f as W,g as ke}from"../chunk-QILEJIFU.js";import{readFileSync as de,writeFileSync as Ie,mkdirSync as Me}from"fs";import{join as se}from"path";import Fe from"js-yaml";var _e=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function q(o){return _e}function C(o){return`${o.publisher}/${o.package_}`}function z(o,e=[]){let c={"kanonak.org/look-styles":"pages render UNSTYLED \u2014 generated CSS stops at the :root token block","kanonak.org/look-tokens":"the :root block loses the universal design-token floor (colors, fonts, spacing)","kanonak.org/universal-look":"resources without their own look render as an empty HTML comment","kanonak.org/look":"band vocabulary (Hero, PropertyList, \u2026) is unresolvable \u2014 declared looks cannot render","kanonak.org/site":"the site vocabulary (content, navigation) is unresolvable \u2014 the base stylesheet cannot bind","kanonak.org/core-kanonak":"the Package/Publisher classes are unresolvable \u2014 package and publisher pages degrade","kanonak.org/link":"link vocabulary is unresolvable \u2014 cross-reference styling degrades"},r=[];for(let t of o)if(t.origin==="missing"){let a=C(t),u=c[a]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${a} is MISSING (${t.reason??"unknown reason"}) \u2014 ${u}. Fix: kanonak install ${a} (as the user running the render), or restore network access to ${t.publisher}.`)}else t.resolvedButNotInCatalog&&r.push(`Render-stack package ${C(t)} resolved (${t.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let t of e)r.push(`Import edge ${t.fromNamespace} \u2192 ${t.publisher}/${t.packageName} ${t.constraint} did NOT resolve (${t.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${t.fromNamespace} authors against ${t.publisher}/${t.packageName} entities is dropped from the parse as an unresolved predicate (a look declaration loses its bands and pages render empty; see typescript#91). Fix: add a ${t.constraint}-compatible version of ${t.publisher}/${t.packageName} to the workspace or cache (kanonak install ${t.publisher}/${t.packageName}), or bump the import in ${t.fromNamespace}.`);return r}function ne(o){let{publisher:e,availablePublishers:c,catalog:r,lookRenderer:t,localNamespaces:a,rawByNsKey:u,renderStack:d,producers:k,lockSource:y,configSource:s}=o,l=new Map,f=new Map,p=new Map,m=new Set;for(let S of r){if(!(S instanceof we))continue;let w=S.namespace||"";if(!a.has(w))continue;l.set(`${w}/${S.name}`,S);let P=w.split("/")[1]??"",[_,F]=P.split("@");if(!_||!F)continue;let D=ke(F);D&&(m.has(P)||(m.add(P),f.has(_)||f.set(_,[]),f.get(_).push({verStr:F,version:D})),S.name===_&&p.set(P,S))}for(let S of f.values())S.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:c,catalog:r,lookRenderer:t,localNamespaces:a,rawByNsKey:u,bySubject:l,pkgVersions:f,pkgSelfByVer:p,renderStack:d,...k?{producers:k}:{},...y?{lockSource:y}:{},...s?{configSource:s}:{}}}async function pe(o,e={}){let c=new O,r=new ye(c),t=[],a=[];for(let i of ee(o)){let h;try{h=de(i,"utf-8")}catch{continue}let n;try{n=c.parse(h).metadata?.namespace_}catch{continue}if(!n?.version)continue;let g=n.version;a.push({publisher:n.publisher,package_:n.package_,verStr:E(g),version:g,source:h})}a.sort((i,h)=>V(h.version,i.version));for(let i of a)await r.saveDocumentAsync(c.parse(i.source),`${i.publisher}/${i.package_}@${i.verStr}`),t.push({publisher:i.publisher,package_:i.package_,verStr:i.verStr,source:i.source});let u=[...new Set(t.map(i=>i.publisher))].sort(),d=e.publisher;if(d){if(!u.includes(d))throw new Error(`Publisher "${d}" not found in workspace. Available: ${u.join(", ")||"(none)"}`)}else if(u.length===1)d=u[0];else throw u.length===0?new Error(`No Kanonak packages found under ${o}`):new Error(`Workspace has multiple publishers (${u.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let k=new Set,y=new Map;for(let i of t)i.publisher===d&&(k.add(`${i.publisher}/${i.package_}@${i.verStr}`),y.set(`${i.package_}@${i.verStr}`,i.source));let s=X(),l=new be(s,!0,c),f={};e.httpCache&&(f.getFromCache=e.httpCache.getFromCache,f.onFetch=e.httpCache.onFetch),e.fetchFn&&(f.fetchFn=e.fetchFn);let p=e.repository??new Se(r,l,new Z(f)),m=e.log??(()=>{}),S=q(void 0),w=[],P=i=>i.map(h=>h.metadata.namespace_?.version).filter(h=>h!==void 0).sort((h,n)=>V(n,h)).map(E);if(!e.repository){m(`[render-stack] resolving ${S.length} ambient look-stack package(s); cache: ${s}`);let i=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let h of S){let n=C(h),g=await r.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(g.length>0){let v=P(g);w.push({...h,origin:"workspace",versions:v}),m(`[render-stack] ${n} \u2014 workspace (${v.join(", ")})`);continue}let b=await l.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(b.length>0){let v=P(b);w.push({...h,origin:"cache",versions:v}),m(`[render-stack] ${n} \u2014 cache (${v.join(", ")})`);continue}try{let $=(await i.getLock(h.publisher))?.packages[`${h.publisher}/${h.package_}`];if(!$){let j=`publisher ${h.publisher} reachable but its lock does not pin ${h.package_}`;w.push({...h,origin:"missing",reason:j}),m(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let I=$.version,T=$.resolved,Q=await(e.fetchFn?e.fetchFn(T,h.publisher):ve(T));if(!Q.ok){let j=`fetch ${T} failed: HTTP ${Q.status} ${Q.statusText}`;w.push({...h,origin:"missing",reason:j}),m(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let fe=await Q.text();await r.saveDocumentAsync(c.parse(fe),`${h.publisher}/${h.package_}@${I}`);try{let j=se(s,h.publisher);Me(j,{recursive:!0}),Ie(se(j,`${h.package_}@${I}.kan.yml`),fe,"utf-8"),w.push({...h,origin:"fetched",versions:[I]}),m(`[render-stack] ${n}@${I} \u2014 fetched from ${T}, installed to cache`)}catch(j){w.push({...h,origin:"fetched",versions:[I]}),m(`[render-stack] ${n}@${I} \u2014 fetched from ${T}, but cache ${s} is NOT WRITABLE (${j.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(v){let $=`fetch failed: ${v.message}`;w.push({...h,origin:"missing",reason:$}),m(`[render-stack] ${n} \u2014 MISSING: ${$}`)}}}let _=(await r.getAllDocumentsAsync()).filter(i=>i.metadata.namespace_?.publisher===d);for(let i of S)_.push(...await p.getDocumentsByNamespaceAsync(i.publisher,i.package_));let F=[],D=await H(_,p,{onUnresolvedEdge:i=>F.push(i)}),A=p;if(!e.repository){for(let i of S)D.add(C(i));A=new G(p,D)}let B=await new oe(c).parseKanonaks(A),ce=new te(B),le=(i,h)=>re(B,{publisher:i,package_:h,name:h}).length>0,N;if(e.repository){N=[];for(let i of S){let h=await p.getDocumentsByNamespaceAsync(i.publisher,i.package_);N.push(h.length>0?{...i,origin:"repository",versions:P(h)}:{...i,origin:"missing",reason:"not present in the caller-supplied repository"})}}else N=w.map(i=>i.origin==="missing"||le(i.publisher,i.package_)?i:{...i,resolvedButNotInCatalog:!0});let Y=z(N,F);for(let i of Y)m(`[render-stack] WARNING: ${i}`);let J={contractSource:"universal-default",cachePath:s,packages:N,warnings:Y},K;try{K=de(se(o,"kanonak.lock"),"utf-8")}catch{K=De(d,t,c)}let L;try{L=de(se(o,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return ne({publisher:d,availablePublishers:u,catalog:B,lookRenderer:ce,localNamespaces:k,rawByNsKey:y,renderStack:J,...K?{lockSource:K}:{},...L?{configSource:L}:{}})}function De(o,e,c){let r=new Map;for(let a of e)a.publisher===o&&(r.has(a.package_)||r.set(a.package_,{verStr:a.verStr,source:a.source}));if(r.size===0)return;let t={};for(let a of[...r.keys()].sort()){let{verStr:u,source:d}=r.get(a),k={},y;try{y=c.parse(d).metadata?.imports}catch{y=void 0}for(let l of y?.[o]??[]){let f=r.get(l.packageName);f&&(k[`${o}/${l.packageName}`]=f.verStr)}let s={};for(let l of Object.keys(k).sort())s[l]=k[l];t[`${o}/${a}`]={version:u,resolved:`https://${o}/${a}/${u}.kan.yml`,integrity:Pe(d),dependencies:s}}return Fe.dump({version:"1",lastUpdated:"",packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ee,readFileSync as Ke,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as je}from"path";async function ue(o,e={}){let c=new O,r=Re(o),t=r.kind==="resource"?r.uri.publisher:r.publisher,a=e.log??(()=>{}),u=e.cacheRoot??X(),d=(n,g,b)=>je(u,n,`${g}@${b}.kan.yml`),k=new Set,y=new Set,s=new Map,l=new Z({getFromCache:(n,g,b)=>{let v=d(n,g,b),$=Ee(v)?Ke(v,"utf-8"):null;return $!==null&&k.add(`${n}/${g}`),$},onFetch:(n,g,b,v)=>{y.add(`${n}/${g}`);try{let $=je(u,n);Ae($,{recursive:!0}),Ve(d(n,g,b),v,"utf-8")}catch($){s.set(`${n}/${g}`,$.message),a(`[render] fetched ${n}/${g}@${b} but cache ${u} is NOT WRITABLE (${$.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),f=new U(e.fetchFn?{fetchFn:e.fetchFn}:void 0),p;if(r.kind==="resource"){let n=r.uri.version;p=[n?{package_:r.uri.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let n=r.version;p=[n?{package_:r.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.package_}]}else p=((await f.getConfig(t)).featured_packages??[]).map(g=>({package_:g}));let m=async(n,g,b)=>{try{let v=b?c.buildImport(g,"=",b,n):c.buildImport(g,"*","0.0.0",n),$=await l.getHighestCompatibleVersionAsync(n,v);return $?{doc:$}:{doc:null,error:`${n} did not resolve ${g}${b?`@${b}`:""} (not in its index, or unreachable)`}}catch(v){return{doc:null,error:v.message}}},S=[],w=[];for(let n of p){let{doc:g,error:b}=await m(t,n.package_,n.version);g?S.push(g):b&&w.push(b)}if(S.length===0)throw new Error(`Could not fetch any package for address "${o}" from publisher "${t}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",F=n=>n.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,b)=>V(b,g)).map(E);a(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${u}`);let D=[],A=[];for(let n of P){let g=C(n),{doc:b,error:v}=await m(n.publisher,n.package_,void 0);if(b){D.push(b);let $=F([b]),I=y.has(g)?"fetched":k.has(g)?"cache":"fetched";A.push({...n,origin:I,versions:$}),a(`[render-stack] ${g} \u2014 ${I} (${$.join(", ")})`+(s.has(g)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:v??"unresolved"}),a(`[render-stack] ${g} \u2014 MISSING: ${v??"unresolved"}`)}let B=[],ce=await H([...S,...D],l,{onUnresolvedEdge:n=>B.push(n)}),le=new G(l,ce),N=await new oe(c).parseKanonaks(le),Y=new te(N),J=A.map(n=>n.origin==="missing"||re(N,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),K=z(J,B);for(let n of K)a(`[render-stack] WARNING: ${n}`);let L={contractSource:_,cachePath:u,packages:J,warnings:K},i=new Set,h=new Map;for(let n of await l.getAllDocumentsAsync()){let g=n.metadata.namespace_;if(!g?.version||g.publisher!==t)continue;let b=E(g.version),v=`${g.publisher}/${g.package_}@${b}`;i.add(v);let $=await l.getDocumentContentAsync(v);$!==null&&h.set(`${g.package_}@${b}`,$)}return ne({publisher:t,availablePublishers:[t],catalog:N,lookRenderer:Y,localNamespaces:i,rawByNsKey:h,renderStack:L})}import{VersionOperator as ie}from"@kanonak-protocol/types/document/models/enums";function ae(o){let{lookRenderer:e,publisher:c,renderStack:r,catalog:t}=o,a=e.explainStylesheet(e.publisherSubject(c)),u=[...a.tokens.entries()].map(([p,m])=>({name:p,value:m.value,source:`${m.sourceNamespace}/${m.sourceName}`,level:m.level})),d=a.baseStylesheet,k={present:d.css!==void 0,...d.sourceNamespace!==void 0?{source:d.sourceNamespace}:{},...d.scope!==void 0?{scope:d.scope}:{},...d.css!==void 0?{bytes:d.css.length}:{},...d.problem!==void 0?{problem:d.problem}:{},candidates:d.candidates},y=new Map;for(let p of t){let m=p.namespace;m&&y.set(m,(y.get(m)??0)+1)}let s=[...y.entries()].map(([p,m])=>({namespace:p,resources:m})).sort((p,m)=>p.namespace.localeCompare(m.namespace)),l=e.expressionFailures().map(p=>({carrier:p.carrier,reason:p.reason})),f=l.map(p=>`Expression carrier "${p.carrier}" did not compile: ${p.reason} Consequence: that value renders as nothing (and a parent operation consuming it may drop its whole tier). Fix: use a tx.Expression node class the runner implements, or remove the carrier.`);return{publisher:c,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(p=>({package_:C(p),origin:p.origin,...p.versions!==void 0?{versions:p.versions}:{},...p.reason!==void 0?{reason:p.reason}:{},...p.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:p.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:u,baseStylesheet:k,...a.look?{look:{sourceClass:`${a.look.sourceClass.publisher}/${a.look.sourceClass.package_}/${a.look.sourceClass.name}`}}:{}},expressionCarriers:l,catalog:s,warnings:[...r.warnings,...a.warnings.filter(p=>!r.warnings.includes(p)),...f]}}function Be(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function ge(o){let e=Be,c=o.warnings.length===0,r=o.expressionCarriers.map(s=>`<tr><td><code>${e(s.carrier)}</code></td><td>${e(s.reason)}</td></tr>`).join(`
1
+ import{c as Pe}from"../chunk-V3DH67P3.js";import{a as be,d as X,f as Se,h as ee}from"../chunk-IS3AQKB4.js";import{e as ve,g as $e,m as U,n as Z}from"../chunk-BZ3YTI3C.js";import"../chunk-XK24CN3C.js";import"../chunk-SC5M74NM.js";import{a as H,b as G}from"../chunk-KIBR3HAT.js";import{r as te}from"../chunk-Z5Y4MCW5.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{m as oe}from"../chunk-PVUBHIU2.js";import{a as O}from"../chunk-HF5FJBS2.js";import{a as xe}from"../chunk-PEJALHXK.js";import{c as Re}from"../chunk-7UYXTYXC.js";import{c as we,u as re}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{c as V,e as E,f as W,g as ke}from"../chunk-QILEJIFU.js";import{readFileSync as de,writeFileSync as Ie,mkdirSync as Me}from"fs";import{join as se}from"path";import Fe from"js-yaml";var _e=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function q(o){return _e}function C(o){return`${o.publisher}/${o.package_}`}function z(o,e=[]){let c={"kanonak.org/look-styles":"pages render UNSTYLED \u2014 generated CSS stops at the :root token block","kanonak.org/look-tokens":"the :root block loses the universal design-token floor (colors, fonts, spacing)","kanonak.org/universal-look":"resources without their own look render as an empty HTML comment","kanonak.org/look":"band vocabulary (Hero, PropertyList, \u2026) is unresolvable \u2014 declared looks cannot render","kanonak.org/site":"the site vocabulary (content, navigation) is unresolvable \u2014 the base stylesheet cannot bind","kanonak.org/core-kanonak":"the Package/Publisher classes are unresolvable \u2014 package and publisher pages degrade","kanonak.org/link":"link vocabulary is unresolvable \u2014 cross-reference styling degrades"},r=[];for(let t of o)if(t.origin==="missing"){let a=C(t),u=c[a]??"whatever this package contributes to rendering is lost";r.push(`Render-stack package ${a} is MISSING (${t.reason??"unknown reason"}) \u2014 ${u}. Fix: kanonak install ${a} (as the user running the render), or restore network access to ${t.publisher}.`)}else t.resolvedButNotInCatalog&&r.push(`Render-stack package ${C(t)} resolved (${t.origin}) but is NOT in the parsed catalog \u2014 this is a closure-scoping bug; please report it.`);for(let t of e)r.push(`Import edge ${t.fromNamespace} \u2192 ${t.publisher}/${t.packageName} ${t.constraint} did NOT resolve (${t.reason==="no-compatible-version"?"no compatible version in the repository":"resolution threw"}) \u2014 every statement ${t.fromNamespace} authors against ${t.publisher}/${t.packageName} entities is dropped from the parse as an unresolved predicate (a look declaration loses its bands and pages render empty; see typescript#91). Fix: add a ${t.constraint}-compatible version of ${t.publisher}/${t.packageName} to the workspace or cache (kanonak install ${t.publisher}/${t.packageName}), or bump the import in ${t.fromNamespace}.`);return r}function ne(o){let{publisher:e,availablePublishers:c,catalog:r,lookRenderer:t,localNamespaces:a,rawByNsKey:u,renderStack:d,producers:k,lockSource:y,configSource:s}=o,l=new Map,f=new Map,p=new Map,m=new Set;for(let S of r){if(!(S instanceof we))continue;let w=S.namespace||"";if(!a.has(w))continue;l.set(`${w}/${S.name}`,S);let P=w.split("/")[1]??"",[_,F]=P.split("@");if(!_||!F)continue;let D=ke(F);D&&(m.has(P)||(m.add(P),f.has(_)||f.set(_,[]),f.get(_).push({verStr:F,version:D})),S.name===_&&p.set(P,S))}for(let S of f.values())S.sort((w,P)=>V(P.version,w.version));return{publisher:e,availablePublishers:c,catalog:r,lookRenderer:t,localNamespaces:a,rawByNsKey:u,bySubject:l,pkgVersions:f,pkgSelfByVer:p,renderStack:d,...k?{producers:k}:{},...y?{lockSource:y}:{},...s?{configSource:s}:{}}}async function pe(o,e={}){let c=new O,r=new ye(c),t=[],a=[];for(let i of ee(o)){let h;try{h=de(i,"utf-8")}catch{continue}let n;try{n=c.parse(h).metadata?.namespace_}catch{continue}if(!n?.version)continue;let g=n.version;a.push({publisher:n.publisher,package_:n.package_,verStr:E(g),version:g,source:h})}a.sort((i,h)=>V(h.version,i.version));for(let i of a)await r.saveDocumentAsync(c.parse(i.source),`${i.publisher}/${i.package_}@${i.verStr}`),t.push({publisher:i.publisher,package_:i.package_,verStr:i.verStr,source:i.source});let u=[...new Set(t.map(i=>i.publisher))].sort(),d=e.publisher;if(d){if(!u.includes(d))throw new Error(`Publisher "${d}" not found in workspace. Available: ${u.join(", ")||"(none)"}`)}else if(u.length===1)d=u[0];else throw u.length===0?new Error(`No Kanonak packages found under ${o}`):new Error(`Workspace has multiple publishers (${u.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let k=new Set,y=new Map;for(let i of t)i.publisher===d&&(k.add(`${i.publisher}/${i.package_}@${i.verStr}`),y.set(`${i.package_}@${i.verStr}`,i.source));let s=X(),l=new be(s,!0,c),f={};e.httpCache&&(f.getFromCache=e.httpCache.getFromCache,f.onFetch=e.httpCache.onFetch),e.fetchFn&&(f.fetchFn=e.fetchFn);let p=e.repository??new Se(r,l,new Z(f)),m=e.log??(()=>{}),S=q(void 0),w=[],P=i=>i.map(h=>h.metadata.namespace_?.version).filter(h=>h!==void 0).sort((h,n)=>V(n,h)).map(E);if(!e.repository){m(`[render-stack] resolving ${S.length} ambient look-stack package(s); cache: ${s}`);let i=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let h of S){let n=C(h),g=await r.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(g.length>0){let v=P(g);w.push({...h,origin:"workspace",versions:v}),m(`[render-stack] ${n} \u2014 workspace (${v.join(", ")})`);continue}let b=await l.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(b.length>0){let v=P(b);w.push({...h,origin:"cache",versions:v}),m(`[render-stack] ${n} \u2014 cache (${v.join(", ")})`);continue}try{let $=(await i.getLock(h.publisher))?.packages[`${h.publisher}/${h.package_}`];if(!$){let j=`publisher ${h.publisher} reachable but its lock does not pin ${h.package_}`;w.push({...h,origin:"missing",reason:j}),m(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let I=$.version,T=$.resolved,Q=await(e.fetchFn?e.fetchFn(T,h.publisher):ve(T));if(!Q.ok){let j=`fetch ${T} failed: HTTP ${Q.status} ${Q.statusText}`;w.push({...h,origin:"missing",reason:j}),m(`[render-stack] ${n} \u2014 MISSING: ${j}`);continue}let fe=await Q.text();await r.saveDocumentAsync(c.parse(fe),`${h.publisher}/${h.package_}@${I}`);try{let j=se(s,h.publisher);Me(j,{recursive:!0}),Ie(se(j,`${h.package_}@${I}.kan.yml`),fe,"utf-8"),w.push({...h,origin:"fetched",versions:[I]}),m(`[render-stack] ${n}@${I} \u2014 fetched from ${T}, installed to cache`)}catch(j){w.push({...h,origin:"fetched",versions:[I]}),m(`[render-stack] ${n}@${I} \u2014 fetched from ${T}, but cache ${s} is NOT WRITABLE (${j.message}); usable for this load only \u2014 every load will re-fetch it`)}}catch(v){let $=`fetch failed: ${v.message}`;w.push({...h,origin:"missing",reason:$}),m(`[render-stack] ${n} \u2014 MISSING: ${$}`)}}}let _=(await r.getAllDocumentsAsync()).filter(i=>i.metadata.namespace_?.publisher===d);for(let i of S)_.push(...await p.getDocumentsByNamespaceAsync(i.publisher,i.package_));let F=[],D=await H(_,p,{onUnresolvedEdge:i=>F.push(i)}),A=p;if(!e.repository){for(let i of S)D.add(C(i));A=new G(p,D)}let B=await new oe(c).parseKanonaks(A),ce=new te(B),le=(i,h)=>re(B,{publisher:i,package_:h,name:h}).length>0,N;if(e.repository){N=[];for(let i of S){let h=await p.getDocumentsByNamespaceAsync(i.publisher,i.package_);N.push(h.length>0?{...i,origin:"repository",versions:P(h)}:{...i,origin:"missing",reason:"not present in the caller-supplied repository"})}}else N=w.map(i=>i.origin==="missing"||le(i.publisher,i.package_)?i:{...i,resolvedButNotInCatalog:!0});let Y=z(N,F);for(let i of Y)m(`[render-stack] WARNING: ${i}`);let J={contractSource:"universal-default",cachePath:s,packages:N,warnings:Y},K;try{K=de(se(o,"kanonak.lock"),"utf-8")}catch{K=De(d,t,c)}let L;try{L=de(se(o,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return ne({publisher:d,availablePublishers:u,catalog:B,lookRenderer:ce,localNamespaces:k,rawByNsKey:y,renderStack:J,...K?{lockSource:K}:{},...L?{configSource:L}:{}})}function De(o,e,c){let r=new Map;for(let a of e)a.publisher===o&&(r.has(a.package_)||r.set(a.package_,{verStr:a.verStr,source:a.source}));if(r.size===0)return;let t={};for(let a of[...r.keys()].sort()){let{verStr:u,source:d}=r.get(a),k={},y;try{y=c.parse(d).metadata?.imports}catch{y=void 0}for(let l of y?.[o]??[]){let f=r.get(l.packageName);f&&(k[`${o}/${l.packageName}`]=f.verStr)}let s={};for(let l of Object.keys(k).sort())s[l]=k[l];t[`${o}/${a}`]={version:u,resolved:`https://${o}/${a}/${u}.kan.yml`,integrity:Pe(d),dependencies:s}}return Fe.dump({version:"1",lastUpdated:"",packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ee,readFileSync as Ke,writeFileSync as Ve,mkdirSync as Ae}from"fs";import{join as je}from"path";async function ue(o,e={}){let c=new O,r=Re(o),t=r.kind==="resource"?r.uri.publisher:r.publisher,a=e.log??(()=>{}),u=e.cacheRoot??X(),d=(n,g,b)=>je(u,n,`${g}@${b}.kan.yml`),k=new Set,y=new Set,s=new Map,l=new Z({getFromCache:(n,g,b)=>{let v=d(n,g,b),$=Ee(v)?Ke(v,"utf-8"):null;return $!==null&&k.add(`${n}/${g}`),$},onFetch:(n,g,b,v)=>{y.add(`${n}/${g}`);try{let $=je(u,n);Ae($,{recursive:!0}),Ve(d(n,g,b),v,"utf-8")}catch($){s.set(`${n}/${g}`,$.message),a(`[render] fetched ${n}/${g}@${b} but cache ${u} is NOT WRITABLE (${$.message}); usable for this load only \u2014 every load will re-fetch it`)}},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),f=new U(e.fetchFn?{fetchFn:e.fetchFn}:void 0),p;if(r.kind==="resource"){let n=r.uri.version;p=[n?{package_:r.uri.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let n=r.version;p=[n?{package_:r.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:r.package_}]}else p=((await f.getConfig(t)).featured_packages??[]).map(g=>({package_:g}));let m=async(n,g,b)=>{try{let v=b?c.buildImport(g,"=",b,n):c.buildImport(g,"*","0.0.0",n),$=await l.getHighestCompatibleVersionAsync(n,v);return $?{doc:$}:{doc:null,error:`${n} did not resolve ${g}${b?`@${b}`:""} (not in its index, or unreachable)`}}catch(v){return{doc:null,error:v.message}}},S=[],w=[];for(let n of p){let{doc:g,error:b}=await m(t,n.package_,n.version);g?S.push(g):b&&w.push(b)}if(S.length===0)throw new Error(`Could not fetch any package for address "${o}" from publisher "${t}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let P=q(),_="universal-default",F=n=>n.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,b)=>V(b,g)).map(E);a(`[render-stack] resolving ${P.length} ambient look-stack package(s) (contract: ${_}); cache: ${u}`);let D=[],A=[];for(let n of P){let g=C(n),{doc:b,error:v}=await m(n.publisher,n.package_,void 0);if(b){D.push(b);let $=F([b]),I=y.has(g)?"fetched":k.has(g)?"cache":"fetched";A.push({...n,origin:I,versions:$}),a(`[render-stack] ${g} \u2014 ${I} (${$.join(", ")})`+(s.has(g)?" [cache write FAILED \u2014 will re-fetch next load]":""))}else A.push({...n,origin:"missing",reason:v??"unresolved"}),a(`[render-stack] ${g} \u2014 MISSING: ${v??"unresolved"}`)}let B=[],ce=await H([...S,...D],l,{onUnresolvedEdge:n=>B.push(n)}),le=new G(l,ce),N=await new oe(c).parseKanonaks(le),Y=new te(N),J=A.map(n=>n.origin==="missing"||re(N,{publisher:n.publisher,package_:n.package_,name:n.package_}).length>0?n:{...n,resolvedButNotInCatalog:!0}),K=z(J,B);for(let n of K)a(`[render-stack] WARNING: ${n}`);let L={contractSource:_,cachePath:u,packages:J,warnings:K},i=new Set,h=new Map;for(let n of await l.getAllDocumentsAsync()){let g=n.metadata.namespace_;if(!g?.version||g.publisher!==t)continue;let b=E(g.version),v=`${g.publisher}/${g.package_}@${b}`;i.add(v);let $=await l.getDocumentContentAsync(v);$!==null&&h.set(`${g.package_}@${b}`,$)}return ne({publisher:t,availablePublishers:[t],catalog:N,lookRenderer:Y,localNamespaces:i,rawByNsKey:h,renderStack:L})}import{VersionOperator as ie}from"@kanonak-protocol/types/document/models/enums";function ae(o){let{lookRenderer:e,publisher:c,renderStack:r,catalog:t}=o,a=e.explainStylesheet(e.publisherSubject(c)),u=[...a.tokens.entries()].map(([p,m])=>({name:p,value:m.value,source:`${m.sourceNamespace}/${m.sourceName}`,level:m.level})),d=a.baseStylesheet,k={present:d.css!==void 0,...d.sourceNamespace!==void 0?{source:d.sourceNamespace}:{},...d.scope!==void 0?{scope:d.scope}:{},...d.css!==void 0?{bytes:d.css.length}:{},...d.problem!==void 0?{problem:d.problem}:{},candidates:d.candidates},y=new Map;for(let p of t){let m=p.namespace;m&&y.set(m,(y.get(m)??0)+1)}let s=[...y.entries()].map(([p,m])=>({namespace:p,resources:m})).sort((p,m)=>p.namespace.localeCompare(m.namespace)),l=e.expressionFailures().map(p=>({carrier:p.carrier,reason:p.reason})),f=l.map(p=>`Expression carrier "${p.carrier}" did not compile: ${p.reason} Consequence: that value renders as nothing (and a parent operation consuming it may drop its whole tier). Fix: use a tx.Expression node class the runner implements, or remove the carrier.`);return{publisher:c,renderStack:{contractSource:r.contractSource,cachePath:r.cachePath,packages:r.packages.map(p=>({package_:C(p),origin:p.origin,...p.versions!==void 0?{versions:p.versions}:{},...p.reason!==void 0?{reason:p.reason}:{},...p.resolvedButNotInCatalog!==void 0?{resolvedButNotInCatalog:p.resolvedButNotInCatalog}:{}}))},stylesheet:{tokens:u,baseStylesheet:k,...a.look?{look:{sourceClass:`${a.look.sourceClass.publisher}/${a.look.sourceClass.package_}/${a.look.sourceClass.name}`}}:{}},expressionCarriers:l,catalog:s,warnings:[...r.warnings,...a.warnings.filter(p=>!r.warnings.includes(p)),...f]}}function Be(o){return o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function ge(o){let e=Be,c=o.warnings.length===0,r=o.expressionCarriers.map(s=>`<tr><td><code>${e(s.carrier)}</code></td><td>${e(s.reason)}</td></tr>`).join(`
2
2
  `),t=o.warnings.length===0?'<p class="ok">\u2713 No problems detected \u2014 the render stack is fully resolved and pages should be styled.</p>':o.warnings.map(s=>`<div class="warn">\u26A0 ${e(s)}</div>`).join(`
3
3
  `),a=o.renderStack.packages.map(s=>{let l=s.origin!=="missing"&&!s.resolvedButNotInCatalog,f=s.origin==="missing"?'<span class="bad">MISSING</span>':s.resolvedButNotInCatalog?`<span class="bad">${e(s.origin)} (not in catalog)</span>`:`<span class="good">${e(s.origin)}</span>`,p=s.reason?e(s.reason):e((s.versions??[]).join(", "));return`<tr class="${l?"":"row-bad"}"><td><code>${e(s.package_)}</code></td><td>${f}</td><td>${p}</td></tr>`}).join(`
4
4
  `),u=o.stylesheet.baseStylesheet,d=u.present?`<p><span class="good">\u2713 present</span> \u2014 <code>${e(u.source??"")}</code> (${u.bytes} bytes, ${e(u.scope??"")})</p>`:`<p><span class="bad">\u2717 MISSING</span>${u.problem?` \u2014 ${e(u.problem)}`:""}${u.candidates.length>0?`<br>candidates considered: ${u.candidates.map(s=>`<code>${e(s)}</code>`).join(", ")}`:""}</p><p>Without the base stylesheet, generated CSS stops at the <code>:root</code> token block and pages appear unstyled.</p>`,k=o.stylesheet.tokens.map(s=>`<tr><td><code>--kan-${e(s.name)}</code></td><td><code>${e(s.value)}</code></td><td><code>${e(s.source)}</code></td><td>${e(s.level)}</td></tr>`).join(`
@@ -1,4 +1,4 @@
1
- import{a as pe}from"../chunk-GMK4YL3X.js";import"../chunk-HBG6SC5L.js";import{a as ve,b as M,c as Un,l as X,m as Vn,n as Rn,o as le,p as q,r as G}from"../chunk-ANJAHB4N.js";import"../chunk-6VIUXP4N.js";import{a as ce,b as ue,c as de,e as $n,f as Tn,g as Bn,h as xn,m as fe}from"../chunk-F3SGXIDP.js";import{a as se}from"../chunk-KOWDHKBN.js";import"../chunk-PEJALHXK.js";import{e as U}from"../chunk-G3GKOJ5E.js";import{b as Y,c as D,d as E,g as $,h as T,i as B,j as w,k as me,l as x,n as N,o as S,t as A}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import{g as ie}from"../chunk-QILEJIFU.js";var Le="kanonak.org",Oe="document-ast",i=e=>({publisher:Le,package_:Oe,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ge(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var V=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=Ie(n.metadata,t),o=Ke(n.children),s=["---",...r,"---","",o].join(`
1
+ import{a as pe}from"../chunk-L2J7WD7E.js";import"../chunk-BS7RRG7D.js";import{a as ve,b as M,c as Un,l as X,m as Vn,n as Rn,o as le,p as q,r as G}from"../chunk-Z5Y4MCW5.js";import"../chunk-6VIUXP4N.js";import{a as ce,b as ue,c as de,e as $n,f as Tn,g as Bn,h as xn,m as fe}from"../chunk-PVUBHIU2.js";import{a as se}from"../chunk-HF5FJBS2.js";import"../chunk-PEJALHXK.js";import{e as U}from"../chunk-7UYXTYXC.js";import{b as Y,c as D,d as E,g as $,h as T,i as B,j as w,k as me,l as x,n as N,o as S,t as A}from"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{g as ie}from"../chunk-QILEJIFU.js";var Le="kanonak.org",Oe="document-ast",i=e=>({publisher:Le,package_:Oe,name:e}),m={Document:i("Document"),Block:i("Block"),Inline:i("Inline"),StructuredValue:i("StructuredValue"),Heading:i("Heading"),Paragraph:i("Paragraph"),RawBlock:i("RawBlock"),Text:i("Text"),StructuredMap:i("StructuredMap"),StructuredEntry:i("StructuredEntry"),StructuredList:i("StructuredList"),StringScalar:i("StringScalar"),IntegerScalar:i("IntegerScalar"),EscapeHint:i("EscapeHint"),MediaType:i("MediaType"),metadata:i("metadata"),children:i("children"),level:i("level"),inlines:i("inlines"),text:i("text"),entries:i("entries"),key:i("key"),value:i("value"),escapeHint:i("escapeHint"),items:i("items"),stringValue:i("stringValue"),integerValue:i("integerValue"),rawContent:i("rawContent"),mediaType:i("mediaType"),mimeType:i("mimeType"),ESC_RAW:i("esc-raw"),ESC_YAML_SAFE:i("esc-yaml-safe"),ESC_TOML_STRING:i("esc-toml-string"),ESC_TOML_MULTILINE:i("esc-toml-multiline"),ESC_JSON:i("esc-json"),ESC_DYNAMODB_BOOL:i("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:i("esc-dynamodb-number"),ESC_DYNAMODB_NULL:i("esc-dynamodb-null"),TEXT_PLAIN:i("text-plain"),TEXT_MARKDOWN:i("text-markdown"),TEXT_HTML:i("text-html"),TEXT_CSS:i("text-css"),APPLICATION_JSON:i("application-json"),TEXT_YAML:i("text-yaml"),IMAGE_SVG_XML:i("image-svg-xml"),ResourceLink:i("ResourceLink"),target:i("target"),linkLabel:i("linkLabel"),PropertyList:i("PropertyList"),propertyEntries:i("propertyEntries"),PropertyEntry:i("PropertyEntry"),propertyKey:i("propertyKey"),propertyValue:i("propertyValue"),Table:i("Table"),tableColumnLabels:i("tableColumnLabels"),tableRows:i("tableRows"),TableRow:i("TableRow"),tableCells:i("tableCells")};function ge(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var V=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(n,t){let r=Ie(n.metadata,t),o=Ke(n.children),s=["---",...r,"---","",o].join(`
2
2
  `);return t?.trailingNewline&&(s.endsWith(`
3
3
  `)||(s+=`
4
4
  `)),s}};function Ie(e,n){if(!e)return[];let t=new Map;for(let c of e.entries)t.set(P(c.key),c);let r=new Map;if(n?.metadataRenames)for(let[c,u]of n.metadataRenames)r.set(P(c),u);let a=(n?.metadataKeys??e.entries.map(c=>c.key)).map(P),s=[];for(let c of a){let u=t.get(c);if(!u)continue;let f=r.get(c),l=P(f??c),d=ye(u.value,u.escapeHint);d!==void 0&&s.push(`${l}: ${d}`)}return s}function P(e){let n=e.lastIndexOf(".");return n===-1?e:e.substring(n+1)||e}function ye(e,n){switch(e.kind){case"StringScalar":return _e(e.stringValue,n);case"IntegerScalar":return String(e.integerValue);case"StructuredList":{let t=[];for(let r of e.items){let o=ye(r,n);o!==void 0&&t.push(o)}return t.join(", ")}case"StructuredMap":return;default:return}}function _e(e,n){return!n||ge(n,m.ESC_RAW)?e:ge(n,m.ESC_YAML_SAFE)?Ce(e):e}function Ce(e){return e.includes(`
@@ -6,12 +6,16 @@ import type { IDocumentValidationRule } from './rules/document/IDocumentValidati
6
6
  import type { IRepositoryValidationRule } from './rules/repository/IRepositoryValidationRule.js';
7
7
  import { OntologyValidationResult } from './OntologyValidationResult.js';
8
8
  import { ValidationCache } from './ValidationCache.js';
9
+ export interface KanonakObjectValidatorOptions {
10
+ /** No network: a link whose package only HTTP could answer is reported as unverified, not broken. */
11
+ offline?: boolean | undefined;
12
+ }
9
13
  export declare class KanonakObjectValidator implements IKanonakObjectValidator {
10
14
  private readonly parser;
11
15
  private readonly documentRules;
12
16
  private readonly repositoryRules;
13
17
  includeWarnings: boolean;
14
- constructor(parser?: IKanonakParser);
18
+ constructor(parser?: IKanonakParser, options?: KanonakObjectValidatorOptions);
15
19
  validateAsync(document: KanonakDocument, repository?: IKanonakDocumentRepository | null, cache?: ValidationCache): Promise<OntologyValidationResult>;
16
20
  /**
17
21
  * Validate a SET of documents that share one repository — the single
@@ -8,4 +8,4 @@ export { KanonakObjectValidator } from './KanonakObjectValidator.js';
8
8
  export type { IDocumentValidationRule } from './rules/document/IDocumentValidationRule.js';
9
9
  export type { IRepositoryValidationRule } from './rules/repository/IRepositoryValidationRule.js';
10
10
  export { NamespacePrefixRule, ResourceNamingRule, PropertyTypeSpecificityRule, SubjectKanonakTypeRequiredRule, PackageHeaderRule } from './rules/document/index.js';
11
- export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyKindRangeConsistencyRule, ReservedNameShadowRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, TxExpressionCompilesRule, SequenceNarrativeRule, LookBandPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './rules/repository/index.js';
11
+ export { ImportExistenceRule, UnresolvedReferenceRule, ClassHierarchyCycleRule, PropertyHierarchyCycleRule, PropertyRangeRequiredRule, SubClassOfReferenceRule, SubPropertyOfReferenceRule, NamespaceImportCycleRule, UnresolvedPredicateRule, AmbiguousReferenceRule, PropertyRangeReferenceRule, ObjectPropertyValueValidationRule, PropertyDomainRule, PropertyKindRangeConsistencyRule, ReservedNameShadowRule, ClassDefinitionRule, EmbeddedKanonakTypeRule, MarkdownLinkRule, DisplayLensScopeRule, LookSemanticSvgPathRule, TxExpressionCompilesRule, SequenceNarrativeRule, LinkTargetRule, LookBandPathRule, TxExpressionPathRule, ShaclShapeRule, OwlOneOfRule, DiamondNameClashRule } from './rules/repository/index.js';
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,I,J,K,L,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-3DWEBQSD.js";import"../chunk-BRCVOR7A.js";import"../chunk-ANJAHB4N.js";import"../chunk-6VIUXP4N.js";import"../chunk-F3SGXIDP.js";import"../chunk-KOWDHKBN.js";import"../chunk-PEJALHXK.js";import"../chunk-G3GKOJ5E.js";import"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-QILEJIFU.js";export{u as AmbiguousReferenceRule,A as ClassDefinitionRule,n as ClassHierarchyCycleRule,K as DiamondNameClashRule,C as DisplayLensScopeRule,k as EmbeddedKanonakTypeRule,l as ImportExistenceRule,L as KanonakObjectValidator,G as LookBandPathRule,D as LookSemanticSvgPathRule,B as MarkdownLinkRule,s as NamespaceImportCycleRule,f as NamespacePrefixRule,w as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,J as OwlOneOfRule,j as PackageHeaderRule,x as PropertyDomainRule,o as PropertyHierarchyCycleRule,y as PropertyKindRangeConsistencyRule,v as PropertyRangeReferenceRule,p as PropertyRangeRequiredRule,h as PropertyTypeSpecificityRule,z as ReservedNameShadowRule,g as ResourceNamingRule,F as SequenceNarrativeRule,I as ShaclShapeRule,q as SubClassOfReferenceRule,r as SubPropertyOfReferenceRule,i as SubjectKanonakTypeRequiredRule,E as TxExpressionCompilesRule,H as TxExpressionPathRule,t as UnresolvedPredicateRule,m as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity};
1
+ import{A,B,C,D,E,F,G,H,I,J,K,L,M,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunk-AXQ4DBJD.js";import"../chunk-KIBR3HAT.js";import"../chunk-Z5Y4MCW5.js";import"../chunk-6VIUXP4N.js";import"../chunk-PVUBHIU2.js";import"../chunk-HF5FJBS2.js";import"../chunk-PEJALHXK.js";import"../chunk-7UYXTYXC.js";import"../chunk-CJMVIOZX.js";import"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import"../chunk-QILEJIFU.js";export{v as AmbiguousReferenceRule,B as ClassDefinitionRule,o as ClassHierarchyCycleRule,L as DiamondNameClashRule,D as DisplayLensScopeRule,l as EmbeddedKanonakTypeRule,m as ImportExistenceRule,M as KanonakObjectValidator,f as LinkTargetRule,H as LookBandPathRule,E as LookSemanticSvgPathRule,C as MarkdownLinkRule,t as NamespaceImportCycleRule,g as NamespacePrefixRule,x as ObjectPropertyValueValidationRule,c as OntologyValidationError,a as OntologyValidationResult,K as OwlOneOfRule,k as PackageHeaderRule,y as PropertyDomainRule,p as PropertyHierarchyCycleRule,z as PropertyKindRangeConsistencyRule,w as PropertyRangeReferenceRule,q as PropertyRangeRequiredRule,i as PropertyTypeSpecificityRule,A as ReservedNameShadowRule,h as ResourceNamingRule,G as SequenceNarrativeRule,J as ShaclShapeRule,r as SubClassOfReferenceRule,s as SubPropertyOfReferenceRule,j as SubjectKanonakTypeRequiredRule,F as TxExpressionCompilesRule,I as TxExpressionPathRule,u as UnresolvedPredicateRule,n as UnresolvedReferenceRule,e as ValidationCache,d as ValidationContext,b as ValidationSeverity};
@@ -2,6 +2,14 @@ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/ty
2
2
  import { OntologyValidationError } from '../../OntologyValidationError.js';
3
3
  import type { IDocumentValidationRule } from './IDocumentValidationRule.js';
4
4
  export declare class NamespacePrefixRule implements IDocumentValidationRule {
5
+ /**
6
+ * A Turtle/SPARQL-style prefixed name used where Kanonak expects a bare or
7
+ * alias-dotted name: the WHOLE value is `prefix:LocalName` — one well-known
8
+ * prefix, one colon, one name token. Prose that merely starts with one of
9
+ * these words followed by a colon (a label such as `Time::ParseDate License`,
10
+ * a comment beginning `Schema: ...`) is not a prefixed name and must not
11
+ * fire; the earlier prefix-only match did.
12
+ */
5
13
  private static readonly NAMESPACE_PREFIX_PATTERN;
6
14
  readonly ruleName = "NamespacePrefix";
7
15
  validate(document: KanonakDocument): OntologyValidationError[];
@@ -0,0 +1,42 @@
1
+ import type { IKanonakDocumentRepository } from '@kanonak-protocol/types/document/models';
2
+ import type { KanonakDocument } from '@kanonak-protocol/types/document/models/types';
3
+ import { OntologyValidationError } from '../../OntologyValidationError.js';
4
+ import type { IRepositoryValidationRule } from './IRepositoryValidationRule.js';
5
+ import type { ValidationCache } from '../../ValidationCache.js';
6
+ export interface LinkTargetRuleOptions {
7
+ /**
8
+ * No network: a link whose package only HTTP could answer is reported as
9
+ * UNVERIFIED (a warning), not as broken. A package the workspace or cache
10
+ * answers is still verified fully — offline changes what an absence means,
11
+ * never what a presence proves.
12
+ */
13
+ offline?: boolean | undefined;
14
+ }
15
+ /**
16
+ * Every reference through a `mode: link` import must dereference — ONE HOP
17
+ * out, never the closure (typescript#111).
18
+ *
19
+ * A link's target is addressed, not loaded: it is not in this document's
20
+ * catalog by design, so `UnresolvedReferenceRule` cannot (and does not) judge
21
+ * it. This rule does, with the bound the whole design exists for: the target
22
+ * PACKAGE is resolved through the repository — workspace first, then the
23
+ * cache, then HTTP, exactly the tiering `LocalFirstRepository` already
24
+ * provides — and the referenced resource must be one the package defines.
25
+ * The target's own imports are never followed. Q937 costs its 262 links, not
26
+ * its 1,208-package connected component.
27
+ *
28
+ * Findings:
29
+ * - the link package cannot be resolved: Error — or, offline, a Warning
30
+ * that says the link is unverified;
31
+ * - the package resolves but defines no such resource: Error (a typo, a
32
+ * renamed entity, or a stale link — the reporter's "moved entity" case).
33
+ * A link import no reference uses is not a finding: declaring a link you do
34
+ * not follow is harmless, and a generator may declare its neighbourhood.
35
+ */
36
+ export declare class LinkTargetRule implements IRepositoryValidationRule {
37
+ private readonly options;
38
+ readonly ruleName = "LinkTarget";
39
+ constructor(options?: LinkTargetRuleOptions);
40
+ validateAsync(document: KanonakDocument, repository: IKanonakDocumentRepository, cache?: ValidationCache): Promise<OntologyValidationError[]>;
41
+ private finding;
42
+ }
@@ -23,6 +23,7 @@ export { TxExpressionCompilesRule } from './TxExpressionCompilesRule.js';
23
23
  export { SequenceNarrativeRule } from './SequenceNarrativeRule.js';
24
24
  export { LookBandPathRule } from './LookBandPathRule.js';
25
25
  export { UnrenderableBandRule } from './UnrenderableBandRule.js';
26
+ export { LinkTargetRule, type LinkTargetRuleOptions } from './LinkTargetRule.js';
26
27
  export { TxExpressionPathRule } from './TxExpressionPathRule.js';
27
28
  export { ShaclShapeRule } from './ShaclShapeRule.js';
28
29
  export { OwlOneOfRule } from './OwlOneOfRule.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "5.29.0",
3
+ "version": "5.31.0",
4
4
  "description": "TypeScript SDK for the Kanonak Protocol — parse, resolve, validate, reason over, and render .kan.yml packages.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -126,7 +126,7 @@
126
126
  ],
127
127
  "dependencies": {
128
128
  "@kanonak-protocol/canonical": "^0.1.3",
129
- "@kanonak-protocol/types": "^5.29.0",
129
+ "@kanonak-protocol/types": "^5.31.0",
130
130
  "ignore": "^7.0.5",
131
131
  "js-yaml": "^4.1.0",
132
132
  "yaml": "^2.7.0",
@@ -1,68 +0,0 @@
1
- import{a as Eo}from"./chunk-BRCVOR7A.js";import{c as Vo,e as vo,f as Je,g as Qe,h as Do,i as So,j as Io,q as eo,r as $o,s as jo}from"./chunk-ANJAHB4N.js";import{a as v,b as mo,c as uo,d as M,h as W,k as Ko,m as j}from"./chunk-F3SGXIDP.js";import{a as po}from"./chunk-KOWDHKBN.js";import{aa as He,b as fo,ba as yo,fa as $,ga as x,ha as H,ia as L,ja as Y,ma as Ro,na as B,oa as bo}from"./chunk-G3GKOJ5E.js";import{A as w,B as K,C as _,c as y,d as C,j as qe,k as G,l as F,m as R,n as q,p as go,q as ko,r as A,t as b,u as ho,w as Q,x as X,y as z,z as g}from"./chunk-CJMVIOZX.js";import{a as lo}from"./chunk-FUUTGGJS.js";import{e as O}from"./chunk-QILEJIFU.js";var ee=class{isValid=!1;errors=[];warnings=[];infos=[];get totalIssues(){return this.errors.length+this.warnings.length+this.infos.length}get allDiagnostics(){return[...this.errors,...this.warnings,...this.infos]}};var k=(t=>(t.Info="Info",t.Warning="Warning",t.Error="Error",t))(k||{});var u=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 oo=class p{resolvedDocuments=[];currentEntityPath;withPath(e){let o=new p;return o.resolvedDocuments=this.resolvedDocuments,o.currentEntityPath=e,o}};var oe=class{constructor(e){this.underlying=e;this.repository=new to(e)}underlying;repository;parsePromise=null;getKanonaks(){return this.parseOnce().then(e=>e.merged)}getAuthoredKanonaks(){return this.parseOnce().then(e=>e.authored)}parseOnce(){return this.parsePromise||(this.parsePromise=(async()=>{let e=await this.underlying.getAllDocumentsAsync();await Eo(e,this.repository);let o={};return{merged:await new j().parseKanonaks(this.underlying,o),authored:o.authored??[]}})()),this.parsePromise}},to=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,o){let t=`${e}/${o}`,n=this.byNamespaceCache.get(t);return n||(n=this.inner.getDocumentsByNamespaceAsync(e,o),this.byNamespaceCache.set(t,n),n)}getHighestCompatibleVersionAsync(e,o){let t=o.version,n=t?`${t.major}.${t.minor}.${t.patch}`:"",r=`${e}/${o.packageName}@${o.versionOperator}:${n}`,a=this.highestVersionCache.get(r);return a||(a=this.inner.getHighestCompatibleVersionAsync(e,o),this.highestVersionCache.set(r,a),a)}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)}};async function D(p,e,o){return o?o.getKanonaks():new j().parseKanonaks(new te(p,e))}async function P(p,e,o){let t=await D(p,e,o),n=Ye(p);return n?t.filter(r=>r instanceof y&&r.namespace===n):[]}async function ne(p,e,o){let t=Ye(p);if(!t)return[];let n;if(o)n=await o.getAuthoredKanonaks();else{let r={};await new j().parseKanonaks(new te(p,e),r),n=r.authored??[]}return n.filter(r=>r instanceof y&&r.sourceDoc===t)}function Ye(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var te=class{constructor(e,o){this.document=e;this.broader=o}document;broader;async getAllDocumentsAsync(){let e=this.document.metadata.namespace_?.toString(),o=(await this.broader.getAllDocumentsAsync()).filter(t=>t.metadata.namespace_?.toString()!==e);return[this.document,...o]}getDocumentAsync(e){return this.broader.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,o){return this.broader.getDocumentsByNamespaceAsync(e,o)}getHighestCompatibleVersionAsync(e,o){return this.broader.getHighestCompatibleVersionAsync(e,o)}getAllDocumentReferencesAsync(){return this.broader.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}saveDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}deleteDocumentAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}clearNamespaceAsync(){throw new Error("DocumentWithRepositoryCatalog is read-only")}};var re=class p{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 o=[];for(let[t,n]of Object.entries(e.body))n&&typeof n=="object"&&!Array.isArray(n)&&this.validateEntity(t,n,o);return o}validateEntity(e,o,t){for(let[n,r]of Object.entries(o)){let a=r?.toString()??"";if(a&&p.NAMESPACE_PREFIX_PATTERN.test(a)){let i=this.getSuggestionForPrefixedValue(a),s=e.split(".")[0],c=new u;c.ruleType=this.ruleName,c.severity="Error",c.entityName=s,c.propertyName=e,c.actualValue=n,c.expectedValue=i,c.message=`Invalid namespace prefix '${a}'. Use '${i}' without prefix.`,c.suggestion="Kanonak YAML uses simple type names. Namespace resolution is handled through imports.",t.push(c)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validateEntity(`${e}.${n}`,r,t)}}getSuggestionForPrefixedValue(e){let o=e.toLowerCase();if(o==="rdfs:class"||o==="owl:class")return"Class";if(o==="rdfs:property"||o==="rdf:property")return"DatatypeProperty or ObjectProperty";if(o.startsWith("xsd:"))return e.substring(4);let t=e.indexOf(":");return t>=0?e.substring(t+1):e}};var ae=class p{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 o=[],t=e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-");for(let[n,r]of Object.entries(e.body)){let a=p.VALID_AUGMENTATION_PATTERN.test(n);if(!a&&!t&&p.RESERVED_WORDS.has(n.toLowerCase())){let i=new u;i.ruleType=this.ruleName,i.severity="Error",i.entityName=n,i.message=`Entity name '${n}' is a reserved word and cannot be used.`,i.suggestion="Choose a different name that doesn't conflict with Kanonak reserved words.",o.push(i);continue}if(!a&&!p.VALID_NAME_PATTERN.test(n)){let i;/^\d/.test(n)?i="Entity names must start with a letter, not a number.":n.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 u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=n,s.message=`Invalid entity name '${n}'. ${i}`,s.suggestion=i,o.push(s)}r&&typeof r=="object"&&!Array.isArray(r)&&this.validatePropertyNames(n,r,o)}return o}validatePropertyNames(e,o,t){for(let n of Object.keys(o))if(!p.VALID_PROPERTIES.has(n)&&!p.VALID_PROPERTY_NAME_PATTERN.test(n)){let r=new u;r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=n,r.message=`Property name '${n}' in entity '${e}' doesn't follow naming conventions.`,r.suggestion="Property names should start with a letter and contain only letters, numbers, and underscores.",t.push(r)}}};var ie=class p{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 o=[];if(e.metadata?.namespace_?.publisher==="kanonak.org"&&e.metadata?.namespace_?.package_?.startsWith("core-"))return o;let t=this.isPropertyDefinedAsClass(e);for(let[n,r]of Object.entries(e.body))if(r&&typeof r=="object"&&!Array.isArray(r)){let a=r,i=a.type;if(i){let s=[];if(Array.isArray(i))for(let c of i){let l=c?.toString();l&&l==="Property"&&!t&&s.push(l)}else{let c=i?.toString();c&&c==="Property"&&!t&&s.push(c)}for(let c of s){let l=this.getPropertyValue(a,"range"),m=this.determinePropertyType(l),d=new u;d.ruleType=this.ruleName,d.severity="Error",d.entityName=n,d.propertyName="type",d.actualValue=c,d.expectedValue=m,d.message=`Invalid property type '${c}'. Use '${m}' instead.`,d.suggestion="Properties should specify their type: DatatypeProperty for data values, ObjectProperty for relationships.",o.push(d)}}}return o}determinePropertyType(e){return!e||e.trim().length===0?"DatatypeProperty or ObjectProperty":p.XSD_TYPES.has(e.toLowerCase())?"DatatypeProperty":/^[A-Z]/.test(e)?"ObjectProperty":"DatatypeProperty or ObjectProperty"}getPropertyValue(e,o){let t=e[o];return t?t.toString():null}isPropertyDefinedAsClass(e){let o=e.body.Property;if(o&&typeof o=="object"&&!Array.isArray(o)){let n=o.type;if(n){let r=n.toString();return r==="Class"||r.endsWith(".Class")}}return!1}};var se=class{get ruleName(){return"SubjectKanonakTypeRequired"}validate(e){let o=[];for(let[t,n]of Object.entries(e.body)){if(typeof n!="object"||n===null||Array.isArray(n)||t.includes("."))continue;let r=n,a="type"in r,i=r.type?.toString().trim();if(!a||!i){let s=new u;s.ruleType=this.ruleName,s.severity="Error",s.entityName=t,s.propertyName="type",s.message=`Subject Kanonak '${t}' 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.)",o.push(s)}}return o}};var Jo=new Set(["EphemeralPackage"]),ce=class{get ruleName(){return"PackageHeader"}validate(e){let o=e.metadata;if(!o.type_)return[];let t=[],n=this.packageKey(e,o.type_);return o.namespace_?(!Jo.has(o.type_)&&!o.namespace_.version&&t.push(this.error(n,"version",`Package resource '${n}' requires a 'version' property \u2014 packages are addressed by name@version.`,`Add a version, e.g.:
5
- version: 1.0.0`)),t):(t.push(this.error(n,"publisher",`Package resource '${n}' requires a 'publisher' property.`,`Add a publisher, e.g.:
6
- publisher: example.org`)),t)}packageKey(e,o){for(let[t,n]of Object.entries(e.body))if(n&&typeof n=="object"&&!Array.isArray(n)&&n.type===o)return t;return o}error(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.message=t,r.suggestion=n,r}};var Qo={publisher:"kanonak.org",package_:"core-rdf",name:"type"},et={publisher:"kanonak.org",package_:"core-rdf",name:"range"},ot={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},tt={publisher:"kanonak.org",package_:"core-rdf",name:"Class"},pe=class{ruleName="EmbeddedKanonakType";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await ne(e,o,t);for(let i of a)i instanceof y&&this.walk(r,i,i.name,n);return n}walk(e,o,t,n){for(let r of o.statement)if(r instanceof G){let a=r.predicate?.subject,i=`${t}.${a?.name??"<embedded>"}`;this.check(e,a,r.object,t,i,n),this.walk(e,r.object,i,n)}else if(r instanceof F){let a=r.predicate?.subject,i=0;for(let s of r.object){if(s instanceof v){let c=`${t}.${a?.name??"<embedded>"}[${i}]`;this.check(e,a,s,t,c,n),this.walk(e,s,c,n)}i++}}}check(e,o,t,n,r,a){if(!o)return;let i=g(t,Qo);if(!i)return;let s=b(e,o);if(!s)return;let c=g(s,et);if(c&&!(q(c,ot)||q(c,tt))){if(R(i)===R(c)){a.push(this.redundant(n,r,i,c));return}H(e,i).some(l=>R(l)===R(c))||a.push(this.notSubclass(n,r,i,c))}}redundant(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e,r.propertyName=o,r.actualValue=t.name,r.expectedValue=n.name,r.message=`Embedded object at '${o}' declares 'type: ${t.name}', which equals the parent property's range '${n.name}'. The declaration is redundant \u2014 the type is already inferred from the property's range.`,r.suggestion=`Remove the 'type: ${t.name}' line, or keep it if explicitness is preferred over concision.`,r}notSubclass(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.actualValue=t.name,r.expectedValue=n.name,r.message=`Embedded object at '${o}' has 'type: ${t.name}', which is not a subclass of the parent property's range '${n.name}'.`,r.suggestion=`Either remove the 'type: ${t.name}' line (so the type is inferred from the property's range '${n.name}'), or add 'subClassOf: ${n.name}' to the '${t.name}' class definition so the relationship holds.`,r}};import{VersionOperator as Ge}from"@kanonak-protocol/types/document/models/enums";var le=class{ruleName="ImportExistence";async validateAsync(e,o){let t=[];if(!e.metadata?.imports)return t;let n=await o.getAllDocumentsAsync();for(let[r,a]of Object.entries(e.metadata.imports))for(let i of a)if(!await o.getHighestCompatibleVersionAsync(r,i)){let c=await this.determineImportErrorAsync(o,r,i,n),l=new u;l.ruleType=this.ruleName,l.severity="Error",l.message=c.message,l.suggestion=c.suggestion,l.entityName=`Import: ${r}/${i.packageName}`,l.actualValue=i.toString(),l.expectedValue=c.expectedValue,t.push(l)}return t}async determineImportErrorAsync(e,o,t,n){let r=await e.getDocumentsByNamespaceAsync(o,t.packageName);if(r.length===0){let c=n.filter(h=>h.metadata.namespace_?.publisher===o).map(h=>h.metadata.namespace_.package_).filter((h,f,S)=>S.indexOf(h)===f),l=this.findSimilarPackages(t.packageName,c),m=`Import '${o}/${t.package_}' not found - package does not exist`,d=l.length>0?`Did you mean: ${l.slice(0,3).join(", ")}?`:c.length>0?`Available packages in ${o}: ${c.slice(0,5).join(", ")}`:`No packages found for publisher '${o}'. Verify the publisher name is correct.`;return{message:m,suggestion:d,expectedValue:"Existing package"}}let i=r.filter(c=>c.metadata.namespace_?.version).map(c=>c.metadata.namespace_.version.toString()).sort().join(", "),s=this.getAcceptableVersionRange(t);return{message:`Import '${o}/${t.toString()}' version mismatch - no compatible version found`,suggestion:`Available versions: ${i}. Required: ${s}`,expectedValue:s}}getAcceptableVersionRange(e){switch(e.versionOperator){case Ge.Exact:return`exactly ${e.version.major}.${e.version.minor}.${e.version.patch}`;case Ge.Compatible:return`${e.version.major}.${e.version.minor}.${e.version.patch} to ${e.version.major}.${e.version.minor}.x`;case Ge.Major:return e.version.major===0?`0.${e.version.minor}.x`:`${e.version.major}.x.x`;case Ge.Any:return`any version >= ${e.version.major}.${e.version.minor}.${e.version.patch}`;default:return e.toString()}}findSimilarPackages(e,o){if(o.length===0)return[];let t=o.filter(a=>a.toLowerCase().includes(e.toLowerCase())||e.toLowerCase().includes(a.toLowerCase()));if(t.length>0)return t.sort((a,i)=>a.length-i.length);let n=o.map(a=>({package:a,distance:this.levenshteinDistance(e.toLowerCase(),a.toLowerCase())})).sort((a,i)=>a.distance-i.distance),r=Math.max(3,Math.floor(e.length*.4));return n.filter(a=>a.distance<=r).map(a=>a.package)}levenshteinDistance(e,o){if(!e||e.length===0)return o?.length??0;if(!o||o.length===0)return e.length;let t=e.length,n=o.length,r=Array(t+1).fill(null).map(()=>Array(n+1).fill(0));for(let a=0;a<=t;a++)r[a][0]=a;for(let a=0;a<=n;a++)r[0][a]=a;for(let a=1;a<=t;a++)for(let i=1;i<=n;i++){let s=e[a-1]===o[i-1]?0:1;r[a][i]=Math.min(Math.min(r[a-1][i]+1,r[a][i-1]+1),r[a-1][i-1]+s)}return r[t][n]}};var nt="kanonak.org",rt="core-rdf",at=new Set(["type","subClassOf","subPropertyOf","domain","range"].map(p=>R({publisher:nt,package_:rt,name:p}))),me=class{ruleName="UnresolvedReference";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);return M(a,({kanonak:i,path:s})=>{for(let c of i.statement){let l=it(c);if(!(!l||at.has(R(l)))){if(c instanceof qe)this.check(r,s,l,c.object,n);else if(c instanceof F)for(let m of c.object)m instanceof C&&this.check(r,s,l,m,n)}}}),n}check(e,o,t,n,r){b(e,n.subject)||r.push(this.unresolvedError(o,t.name,n.subject))}unresolvedError(e,o,t){let n=`${t.publisher}/${t.package_}/${t.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.actualValue=n,r.expectedValue="A reference that resolves to a defined or imported resource",r.message=`Reference to '${t.name}' in '${o}' could not be resolved`,r.suggestion=`The entity '${n}' is not defined in this namespace or any imported namespace.
7
- \u2022 Import the package that defines it, or check for a typo in '${t.name}'
8
- \u2022 If it lives in an imported namespace, alias-qualify the reference`,r}};function it(p){return p.predicate?.subject}var Oo={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},Co={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"};function st(p,e){let o=g(p,e);if(o)return[o];let t=[];for(let n of K(p,e))n instanceof C&&t.push(n.subject);return t}function ze(p,e,o){let t=[],n=new Set,r=new Set,a=i=>{let s=b(p,i),c=s?`${s.namespace}/${s.name}`:R(i);if(n.has(c)){let l=t.findIndex(d=>d.key===c),m=t.slice(l);return m.length<=1?null:[...m.map(d=>d.uri),i]}if(r.has(c))return null;if(n.add(c),t.push({key:c,uri:i}),s)for(let l of st(s,o)){let m=a(l);if(m)return m}return t.pop(),n.delete(c),r.add(c),null};return a(e)}var Po=p=>p,ue=class{ruleName="ClassHierarchyCycle";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);for(let i of a){if(!(i instanceof y)||!($.isClassType(Po(i))||$.isDatatypeType(Po(i))))continue;let s=x(i);if(!s)continue;let c=ze(r,s,Oo);if(c){let l=c.map(d=>d.name).join(" \u2192 "),m=new u;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular class hierarchy detected: ${l}`,m.suggestion="Remove the circular dependency by breaking one of the subClassOf relationships",m.entityName=i.name,m.propertyName="subClassOf",m.actualValue=l,n.push(m);break}}return n}};var de=class{ruleName="PropertyHierarchyCycle";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);for(let i of a){if(!(i instanceof y)||!Y(r,i))continue;let s=x(i);if(!s)continue;let c=ze(r,s,Co);if(c){let l=c.map(d=>d.name).join(" \u2192 "),m=new u;m.ruleType=this.ruleName,m.severity="Error",m.message=`Circular property hierarchy detected: ${l}`,m.suggestion="Remove the circular dependency by breaking one of the subPropertyOf relationships",m.entityName=i.name,m.propertyName="subPropertyOf",m.actualValue=l,n.push(m);break}}return n}};var ct={publisher:"kanonak.org",package_:"core-rdf",name:"range"},fe=class{ruleName="PropertyRangeRequired";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);for(let i of a){if(!(i instanceof y))continue;let s=L(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let c=s==="ObjectProperty";Q(i,ct)||n.push(this.error(i.name,c))}return n}error(e,o){let t=new u;return t.ruleType=this.ruleName,t.severity="Error",t.entityName=e,t.propertyName="range",t.message=`Property '${e}' must have a 'range' defined.`,t.suggestion=o?"Add a range like: range: ClassName (the class this property expects)":"Add a range like: range: string (or integer, boolean, etc.)",t.expectedValue=o?"A class name (Character, Scene, Story, etc.)":"A datatype (string, integer, boolean, decimal, etc.)",t}};var pt={publisher:"kanonak.org",package_:"core-rdf",name:"subClassOf"},wo=p=>p,ye=class{ruleName="SubClassOfReference";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);for(let i of a){if(!(i instanceof y)||!Uo(wo(i)))continue;let s=lt(i,pt);for(let c=0;c<s.length;c++)this.resolvesToClassLike(r,s[c])||n.push(this.error(i.name,s[c],s.length>1?`[${c}]`:""))}return n}resolvesToClassLike(e,o){let t=b(e,o);return t?Uo(wo(t)):!1}error(e,o,t){let n=`${o.publisher}/${o.package_}/${o.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="subClassOf",r.actualValue=n,r.expectedValue="Defined or imported class",r.message=`Class '${o.name}' referenced in subClassOf${t} is not defined or imported`,r.suggestion=`Define '${o.name}' as a Class, or import a namespace that contains it`,r}};function Uo(p){return $.isClassType(p)||$.isDatatypeType(p)}function lt(p,e){let o=g(p,e);if(o)return[o];let t=[];for(let n of K(p,e))n instanceof C&&t.push(n.subject);return t}var mt={publisher:"kanonak.org",package_:"core-rdf",name:"subPropertyOf"},ge=class{ruleName="SubPropertyOfReference";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);for(let i of a){if(!(i instanceof y)||!Y(r,i))continue;let s=ut(i,mt);for(let c=0;c<s.length;c++)this.resolvesToProperty(r,s[c])||n.push(this.error(i.name,s[c],s.length>1?`[${c}]`:""))}return n}resolvesToProperty(e,o){let t=b(e,o);return t?Y(e,t):!1}error(e,o,t){let n=`${o.publisher}/${o.package_}/${o.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="subPropertyOf",r.actualValue=n,r.expectedValue="Defined or imported property",r.message=`Property '${o.name}' referenced in subPropertyOf${t} is not defined or imported`,r.suggestion=`Define '${o.name}' as a property, or import a namespace that contains it`,r}};function ut(p,e){let o=g(p,e);if(o)return[o];let t=[];for(let n of K(p,e))n instanceof C&&t.push(n.subject);return t}var ke=class{get ruleName(){return"NamespaceImportCycle"}async validateAsync(e,o){let t=[],n=e.metadata.namespace_?.toString();if(!n)return t;let r=new Map,a=new Set;await this.buildImportGraph(e,o,r,a);let i=this.detectCycle(n,r);if(i){let s=i.join(" \u2192 "),c=new u;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,t.push(c)}return t}async buildImportGraph(e,o,t,n){let r=e.metadata.namespace_?.toString()??"";if(!(!r||n.has(r))&&(n.add(r),e.metadata.imports)){let a=[];for(let[i,s]of Object.entries(e.metadata.imports))for(let c of s){let l=`${i}/${c.packageName}@${c.version}`;a.push(l);let m=await o.getHighestCompatibleVersionAsync(i,c);m&&await this.buildImportGraph(m,o,t,n)}a.length>0&&t.set(r,a)}}detectCycle(e,o){let t=[],n=new Set;return this.detectCycleRecursive(e,o,t,n)}detectCycleRecursive(e,o,t,n){let r=t.indexOf(e);if(r>=0){let i=t.slice(r);return i.push(e),i}if(n.has(e))return null;t.push(e),n.add(e);let a=o.get(e);if(a)for(let i of a){let s=this.detectCycleRecursive(i,o,t,n);if(s)return s}return t.pop(),null}};var he=class{ruleName="UnresolvedPredicate";async validateAsync(e,o,t){let n=[],r=Ye(e);if(!r)return n;let a=await D(e,o,t);return M(a,({kanonak:i,path:s})=>{for(let c of i.unresolvedPredicates)c.sourceDoc===r&&n.push(this.unresolvedPredicateError(s,c.key))}),n}unresolvedPredicateError(e,o){let t=o.lastIndexOf("."),n=t>0?o.slice(0,t):null,r=t>0?o.slice(t+1):o,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=o,a.actualValue=o,a.expectedValue="A defined or imported property",a.message=`Property '${o}' is not defined or imported`,a.suggestion=n?`The property '${r}' was not found in the namespace imported as '${n}'.
9
- 1. Check '${r}' is spelled correctly
10
- 2. Verify '${n}' is imported with the right alias and version
11
- 3. Ensure that namespace version actually defines '${r}'`:`The property '${o}' is not defined in this namespace or any imported namespace.
12
- 1. Define '${o}' as an ObjectProperty or DatatypeProperty here, OR
13
- 2. Import the namespace that defines it, OR
14
- 3. Alias-qualify it if it lives in an imported namespace ('alias.${o}')`,a}};var Re=class{get ruleName(){return"AmbiguousReference"}async validateAsync(e,o){let t=[],{entitySources:n,importPaths:r}=await this.buildEntitySourceMapAsync(e,o),a=await this.buildDatatypePropertyNamesAsync(e,o);for(let[i,s]of Object.entries(e.body))typeof s=="object"&&s!==null&&!Array.isArray(s)&&this.validateEntityReferences(i,s,n,r,a,e,t);return t}async buildEntitySourceMapAsync(e,o){let t=new Map,n=new Set,r=new Map;for(let a of Object.keys(e.body)){let i=e.metadata.namespace_?.toString()??"";t.has(a)||t.set(a,[]),t.get(a).push(`(local:${i})`)}if(e.metadata.imports)for(let[a,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await o.getHighestCompatibleVersionAsync(a,s);if(c){let l=c.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(c,t,n,r,[l],o)}}return{entitySources:t,importPaths:r}}async collectEntitiesRecursivelyAsync(e,o,t,n,r,a){let i=e.metadata.namespace_?.toString()??"";if(!t.has(i)){t.add(i),n.has(i)||n.set(i,r);for(let s of Object.keys(e.body)){o.has(s)||o.set(s,[]);let c=o.get(s);c.includes(i)||c.push(i)}if(e.metadata.imports)for(let[s,c]of Object.entries(e.metadata.imports))for(let l of c){let m=await a.getHighestCompatibleVersionAsync(s,l);if(m){let d=m.metadata.namespace_?.toString()??"";await this.collectEntitiesRecursivelyAsync(m,o,t,n,[...r,d],a)}}}}async buildDatatypePropertyNamesAsync(e,o){let t=new Set,n=new Set;if(await this.collectDatatypePropertiesAsync(e,t,n,o),e.metadata.imports)for(let[r,a]of Object.entries(e.metadata.imports))for(let i of a){let s=await o.getHighestCompatibleVersionAsync(r,i);s&&await this.collectDatatypePropertiesAsync(s,t,n,o)}return t}async collectDatatypePropertiesAsync(e,o,t,n){let r=e.metadata.namespace_?.toString()??"";if(!t.has(r)){t.add(r);for(let[a,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"&&o.add(a)}if(e.metadata.imports)for(let[a,i]of Object.entries(e.metadata.imports))for(let s of i){let c=await n.getHighestCompatibleVersionAsync(a,s);c&&await this.collectDatatypePropertiesAsync(c,o,t,n)}}}validateEntityReferences(e,o,t,n,r,a,i){for(let[s,c]of Object.entries(o)){let l=s;if(l&&!l.includes(".")){let m=t.get(l);if(m&&m.length>1&&!m.some(h=>h.startsWith("(local:"))){let h=m.filter(f=>!f.startsWith("(local:"));h.length>1&&i.push(this.createAmbiguityError(e,l,`Property '${l}'`,h,n,a,!0,l))}}this.validatePropertyValue(e,l,c,t,n,r,a,i)}}validatePropertyValue(e,o,t,n,r,a,i,s){if(t==null)return;let c=o&&o.includes(".")?o.substring(o.lastIndexOf(".")+1):o,l=!!c&&a.has(c);if(typeof t=="string"&&!t.includes(".")&&!l){let m=n.get(t);if(m&&m.length>1&&!m.some(h=>h.startsWith("(local:"))){let h=m.filter(f=>!f.startsWith("(local:"));h.length>1&&s.push(this.createAmbiguityError(e,o,`Reference '${t}'`,h,r,i,!1,t))}}else if(Array.isArray(t))for(let m=0;m<t.length;m++){let d=`${e}.${o}[${m}]`;this.validatePropertyValue(d,o,t[m],n,r,a,i,s)}else if(typeof t=="object"&&!Array.isArray(t)){let m=o?`${e}.${o}`:e;this.validateEntityReferences(m,t,n,r,a,i,s)}}createAmbiguityError(e,o,t,n,r,a,i,s){let c=[];for(let I of n){let V=this.findAliasForNamespace(a,I);if(V){let U=o?.split(".").pop()??o;c.push(`${V}.${U}`)}}let l=c.length>0?`Use one of: ${c.map(I=>`'${I}'`).join(", ")}`:`Add aliases to imports and use qualified names (e.g., 'alias.${o}')`,m=n.map(I=>{let V=r.get(I);return!V||V.length===0?` \u2022 ${I}`:V.length===1?` \u2022 ${I} (direct import)`:` \u2022 ${I}
15
- imported via: ${V.join(" \u2192 ")}`}).join(`
16
- `),d=e.split(".")[0],h=e.includes(".")?e:o,f=new u;f.ruleType=this.ruleName,f.severity="Error",f.entityName=d,h&&(f.propertyName=h);let S=s??o;return S&&(f.actualValue=S),f.message=`${t} is ambiguous - defined in multiple imported namespaces`,f.suggestion=`${l}
17
-
18
- Defined in:
19
- ${m}`,f.expectedValue="Unambiguous reference (use namespace alias to disambiguate)",f}findAliasForNamespace(e,o){if(!e.metadata.imports)return null;for(let[t,n]of Object.entries(e.metadata.imports))for(let r of n)if(`${t}/${r.packageName}@${r.version}`===o&&r.alias)return r.alias;return null}};var dt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},Ao=p=>p,be=class{ruleName="PropertyRangeReference";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);for(let i of a){if(!(i instanceof y))continue;let s=L(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let c=s==="ObjectProperty";for(let l of ft(i,dt))this.resolvesToClassLike(r,l)||n.push(this.error(i.name,l,c))}return n}resolvesToClassLike(e,o){let t=b(e,o);return t?$.isClassType(Ao(t))||$.isDatatypeType(Ao(t)):!1}error(e,o,t){let n=`${o.publisher}/${o.package_}/${o.name}`,r=new u;return r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName="range",r.actualValue=n,r.expectedValue=t?"A defined or imported class":"A datatype or defined class",r.message=`Property '${e}' has range '${o.name}' which is not defined or imported`,r.suggestion=t?`Define '${o.name}' as a Class here, or import the namespace that contains it (alias-qualify it if imported under an alias).`:`Use a datatype (xsd type, rdfs.Literal, or a datatype-derived type), or \u2014 if '${o.name}' is a class \u2014 make this an ObjectProperty.`,r}};function ft(p,e){let o=g(p,e);if(o)return[o];let t=[];for(let n of K(p,e))n instanceof C&&t.push(n.subject);return t}var yt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},Ke="kanonak.org",no="core-rdf",ro="core-owl",ao=p=>p,gt=[{uri:{publisher:Ke,package_:no,name:"Class"},ok:(p,e)=>$.isClassType(ao(e))||$.isDatatypeType(ao(e))},{uri:{publisher:Ke,package_:no,name:"Datatype"},ok:(p,e)=>$.isDatatypeType(ao(e))},{uri:{publisher:Ke,package_:no,name:"Property"},ok:(p,e)=>Y(p,e)},{uri:{publisher:Ke,package_:ro,name:"ObjectProperty"},ok:(p,e)=>L(p,e)==="ObjectProperty"},{uri:{publisher:Ke,package_:ro,name:"DatatypeProperty"},ok:(p,e)=>L(p,e)==="DatatypeProperty"},{uri:{publisher:Ke,package_:ro,name:"AnnotationProperty"},ok:(p,e)=>L(p,e)==="AnnotationProperty"}],Ee=class{ruleName="ObjectPropertyValue";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await ne(e,o,t);for(let i of a)i instanceof y&&this.walk(r,i,i.name,n);return n}walk(e,o,t,n){for(let r of o.statement)if(r instanceof qe)this.check(e,r.predicate?.subject,r.object.subject,t,n);else if(r instanceof G)this.walk(e,r.object,No(t,r.predicate?.subject),n);else if(r instanceof F){let a=r.predicate?.subject;for(let i of r.object)i instanceof C?this.check(e,a,i.subject,t,n):i instanceof v&&this.walk(e,i,No(t,a),n)}}check(e,o,t,n,r){if(!o)return;let a=b(e,o);if(!a)return;let i=g(a,yt);if(!i)return;let s=gt.find(l=>q(i,l.uri));if(!s)return;let c=b(e,t);c&&(s.ok(e,c)||r.push(this.warn(n,o,i,t)))}warn(e,o,t,n){let r=new u;return r.ruleType=this.ruleName,r.severity="Warning",r.entityName=e.split(".")[0],r.propertyName=e,r.actualValue=n.name,r.expectedValue=t.name,r.message=`Property '${o.name}' expects a ${t.name}, but '${n.name}' is not a ${t.name}`,r.suggestion=`Reference a resource that is a ${t.name}, or correct the type of '${n.name}'.`,r}};function No(p,e){return`${p}.${e?.name??"<embedded>"}`}var kt={publisher:"kanonak.org",package_:"core-rdf",name:"type"},ht={publisher:"kanonak.org",package_:"core-rdf",name:"domain"},Rt={publisher:"kanonak.org",package_:"core-rdf",name:"Resource"},Ve=class{ruleName="PropertyDomain";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await ne(e,o,t);for(let i of a)i instanceof y&&this.walk(r,i,i.name,n);return n}walk(e,o,t,n){this.checkNode(e,o,t,n);for(let r of o.statement)if(r instanceof G)this.walk(e,r.object,To(t,r.predicate?.subject),n);else if(r instanceof F)for(let a of r.object)a instanceof v&&this.walk(e,a,To(t,r.predicate?.subject),n)}checkNode(e,o,t,n){let r=xo(o,kt);if(r.length===0)return;let a,i=()=>{if(!a){a=new Set([R(Rt)]);for(let c of r)for(let l of H(e,c))a.add(R(l))}return a},s=new Set;for(let c of o.statement){let l=bt(c);if(!l||He(l.name)||s.has(R(l)))continue;s.add(R(l));let m=b(e,l);if(!m)continue;let d=xo(m,ht);d.length!==0&&(d.some(h=>i().has(R(h)))||n.push(this.error(t,l,d,r[0])))}}error(e,o,t,n){let r=t.map(i=>i.name).join(" | "),a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e.split(".")[0],a.propertyName=e,a.actualValue=o.name,a.expectedValue=`Property used on ${r} or its subclasses`,a.message=`Property '${o.name}' has domain '${r}' but is used on '${n.name}' at '${e}'`,a.suggestion=`Either:
20
- 1. Use '${o.name}' only on '${r}' (or a subclass) instances
21
- 2. Widen the property's domain to include '${n.name}'
22
- 3. Use a different property for '${n.name}'`,a}};function bt(p){return p.predicate?.subject}function xo(p,e){let o=g(p,e);if(o)return[o];let t=[];for(let n of K(p,e))n instanceof C&&t.push(n.subject);return t}function To(p,e){return`${p}.${e?.name??"<embedded>"}`}var Kt={publisher:"kanonak.org",package_:"core-rdf",name:"range"},Et={publisher:"kanonak.org",package_:"core-rdf",name:"Literal"},Vt=p=>p,ve=class{ruleName="PropertyKindRangeConsistency";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);for(let i of a){if(!(i instanceof y))continue;let s=L(r,i);if(s!=="ObjectProperty"&&s!=="DatatypeProperty")continue;let c=s==="ObjectProperty",l=s==="DatatypeProperty",m=g(i,Kt);if(!m||!b(r,m))continue;let d=vt(r,m);l&&!d?n.push(this.error(i.name,m,"datatype")):c&&d&&n.push(this.error(i.name,m,"object"))}return n}error(e,o,t){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName="range",n.actualValue=o.name,t==="datatype"?(n.expectedValue="A datatype (xsd type, rdfs.Literal, or a datatype-derived class)",n.message=`DatatypeProperty '${e}' has range '${o.name}', which is a class, not a datatype. A datatype property's values are literals.`,n.suggestion=`Use a datatype range (e.g. xsd.string, rdfs.Literal, or a datatype-derived class), or \u2014 if '${o.name}' is the intended target \u2014 declare '${e}' an ObjectProperty.`):(n.expectedValue="A plain class (not datatype-derived)",n.message=`ObjectProperty '${e}' has range '${o.name}', which is a datatype, not a class. An object property's values are references to resources.`,n.suggestion=`Declare '${e}' a DatatypeProperty (its values are literals of '${o.name}'), or change the range to a plain class.`),n}};function vt(p,e){for(let o of H(p,e)){if(q(o,Et))return!0;let t=b(p,o);if(t&&$.isDatatypeType(Vt(t)))return!0}return!1}var De=class{ruleName="ReservedNameShadow";async validateAsync(e,o,t){let n=[],r=await P(e,o,t);for(let a of r){if(!(a instanceof y))continue;let i=yo(a.name);if(!i)continue;let s=x(a);s&&(i.publisher===s.publisher&&i.package_===s.package_||n.push(this.info(a.name,s,i)))}return n}info(e,o,t){let n=new u;return n.ruleType=this.ruleName,n.severity="Info",n.entityName=e,n.propertyName=e,n.actualValue=`${o.publisher}/${o.package_}/${e}`,n.expectedValue=`${t.publisher}/${t.package_}/${e}`,n.message=`'${e}' is also the reserved built-in '${t.publisher}/${t.package_}/${e}'. This local definition shadows it \u2014 a bare '${e}' reference in this package resolves to the local entity, not the built-in.`,n.suggestion=`If this is intentional, qualify bare references to '${e}' explicitly (this local one vs. the built-in '${t.publisher}/${t.package_}/${e}') so the choice is unambiguous to readers and tools \u2014 e.g. a self-referential 'subClassOf: ${e}' silently resolves to this local entity.`,n}};var Dt={publisher:"kanonak.org",package_:"core-rdf",name:"type"},_o=p=>p,Se=class{ruleName="ClassDefinition";async validateAsync(e,o,t){let n=[],r=await D(e,o,t),a=await P(e,o,t);return M(a,({kanonak:i,path:s})=>{for(let c of St(i,Dt))this.resolvesToClassLike(r,c)||n.push(this.error(s,c))}),n}resolvesToClassLike(e,o){if(He(o.name))return!0;let t=b(e,o);return t?$.isClassType(_o(t))||$.isDatatypeType(_o(t)):!1}error(e,o){let t=`${o.publisher}/${o.package_}/${o.name}`,n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName="type",n.actualValue=t,n.expectedValue="Defined or imported class",n.message=`Class '${o.name}' is not defined or imported`,n.suggestion=`Define '${o.name}' as a Class in this document, or import a namespace that contains it`,n}};function St(p,e){let o=g(p,e);if(o)return[o];let t=[];for(let n of K(p,e))n instanceof C&&t.push(n.subject);return t}var Ie=class{ruleName="MarkdownLink";async validateAsync(e,o,t){let n=[],r=await P(e,o,t);return M(r,({kanonak:a,path:i})=>{this.checkNode(a,i,n)}),n}checkNode(e,o,t){for(let n of e.statement){if(!(n instanceof uo))continue;let r=n.predicate.subject?.name??"(unknown)";for(let a of n.links)a.target||t.push(this.unresolvedLinkError(o,r,a.reference));for(let a of Ko(n.object))t.push(this.malformedLinkError(o,r,a.snippet))}}unresolvedLinkError(e,o,t){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=o,n.actualValue=t,n.message=`Embedded link [[${t}]] in '${o}' could not be resolved`,n.expectedValue="A reference resolvable through the document's import closure",n.suggestion=`The reference '${t}' inside a markdown value cannot be found in the current document or any imported namespace.
23
-
24
- Possible solutions:
25
- \u2022 Import the package that defines '${t}' so the link can resolve
26
- \u2022 Check for typos in the reference name
27
- \u2022 If the name collides across imports, alias-qualify it: [[alias.${t}]]`,n}malformedLinkError(e,o,t){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=o,n.actualValue=t,n.message=`Malformed embedded reference near '${t}' in '${o}'`,n.expectedValue="A single-line [[reference]] with no internal line break",n.suggestion=`A '[[' in '${o}' does not form a complete [[reference]] link.
28
-
29
- A reference may not span a line break \u2014 the most common cause is wrapping a
30
- long reference across two lines in a block scalar, e.g.:
31
- ... read for [[persistent-energy-
32
- shock]] held ...
33
- which is parsed as literal text, not a link. Keep each [[reference]] on one
34
- line (let the line run long), or check for an unterminated [[.`,n}};var Lo="kanonak.org",Bo="look",It={publisher:Lo,package_:Bo,name:"displayLabel"},$t={publisher:Lo,package_:Bo,name:"displaySummary"},$e=class{ruleName="DisplayLensScope";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=jt(e);if(!a)return n;for(let i of r)i instanceof y&&i.namespace===a&&(this.checkLens(r,i,It,"displayLabel",n),this.checkLens(r,i,$t,"displaySummary",n));return n}checkLens(e,o,t,n,r){let a=g(o,t);if(!a)return;let i=[],s=x(o);if(s&&i.push(s),i.push(...bo(o)),i.length===0)return;i.some(l=>B(e,l,a).ok)||r.push(this.scopeError(o.name,n,a.name))}scopeError(e,o,t){let n=new u;return n.ruleType=this.ruleName,n.severity="Error",n.entityName=e,n.propertyName=o,n.actualValue=t,n.message=`${o} points at '${t}', which is not a property in scope for '${e}'`,n.expectedValue="A property whose domain is this resource's class, an ancestor, or rdfs.Resource",n.suggestion=`'${t}' resolves, but its domain does not cover '${e}', so the lens would silently fall back to the resource's name at render time.
35
-
36
- Possible solutions:
37
- \u2022 Point ${o} at a property declared on this class (or an ancestor / rdfs.Resource)
38
- \u2022 Set the property's domain to this class if it should apply here
39
- \u2022 Use rdfs.label / rdfs.comment for the universal default`,n}};function jt(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}function Z(p,e,o){let t=[];return Le(p,o,{input:e},t),t}function Le(p,e,o,t){if(A(e,W.VarRef)){let a=z(e,W.varName);return a?o[a]:void 0}if(A(e,W.PropertyRead)){let a=w(e,W.readSource),i=a?Le(p,a,o,t):void 0,s=g(e,W.readProp);if(!i||!s)return;let c=B(p,i,s);if(!c.ok){t.push({contextClass:i,propertyUri:s,via:"PropertyRead"});return}return c.descriptor?.range}if(A(e,W.Traverse)){let a=w(e,W.traverseSource),i=a?Le(p,a,o,t):void 0,s=g(e,W.through),c;if(i&&s){let m=B(p,i,s);m.ok?c=m.descriptor?.range:t.push({contextClass:i,propertyUri:s,via:"Traverse"})}let l=w(e,W.step);return l?Le(p,l,{...o,input:c},t):void 0}let n=z(e,W.loopVar),r=n?{...o,[n]:void 0}:o;for(let a of Ot(e))Le(p,a,r,t)}function Ot(p){let e=[];for(let o of p.statement){let t=o.object;if(t instanceof v)e.push(t);else if(Array.isArray(t))for(let n of t)n instanceof v&&e.push(n)}return e}var Be="kanonak.org",Me="look",Ct={publisher:Be,package_:Me,name:"semanticSvg"},Pt={publisher:Be,package_:Me,name:"tierChip"},wt={publisher:Be,package_:Me,name:"tierIcon"},Ut={publisher:Be,package_:Me,name:"tierCard"},At={publisher:Be,package_:Me,name:"tierFull"},Nt=[Pt,wt,Ut,At],je=class{ruleName="LookSemanticSvgPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=xt(e);if(!a)return n;for(let i of r)i instanceof y&&i.namespace===a&&this.checkSemanticSvg(r,i,n);return n}checkSemanticSvg(e,o,t){let n=w(o,Ct);if(!n)return;let r=x(o);if(r)for(let a of Nt){let i=w(n,a);if(i)for(let s of Z(e,r,i))t.push(this.toError(o.name,a.name,s))}}toError(e,o,t){let n=`${t.propertyUri.publisher}/${t.propertyUri.package_}/${t.propertyUri.name}`,r=t.contextClass.name,a=r===e?`'${e}' (the class this SemanticSvg is declared on)`:`'${r}', reached by traversal from '${e}' (the class this SemanticSvg is declared on)`,i=new u;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=`look.semanticSvg.${o}`,i.actualValue=n,i.message=`tx.${t.via} reads property '${t.propertyUri.name}' off the rendered instance, but its domain is not in scope for ${a}. The read would silently return undefined at render time.`,i.expectedValue=`A property whose domain is '${r}', an ancestor, or rdfs.Resource`,i.suggestion=`Property '${n}' is not in scope for '${r}'.
40
-
41
- Possible solutions:
42
- \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
43
- \u2022 If the property should apply to '${r}', adjust its domain
44
- \u2022 If the value comes from a pre-computed env binding, use tx.VarRef instead of PropertyRead`,i}};function xt(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var Mo={publisher:"kanonak.org",package_:"transformations",name:"Expression"},Tt=new Map([["look","the look renderer"],["view","the view materializer"],["transformations","the transformation runner"]]);function _t(p){if(!(!p||p.publisher!=="kanonak.org"))return Tt.get(p.package_)}var Oe=class{ruleName="TxExpressionCompiles";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(new _(e,o)),a=Bt(e);if(!a)return n;let i=r.filter(f=>f instanceof y&&f.namespace===a);if(i.length===0)return n;let s=new Map,c=f=>{for(let S of go(f)){let I=R(S),V=s.get(I);if(V===void 0&&(V=q(S,Mo)||H(r,S).some(U=>q(U,Mo)),s.set(I,V)),V)return!0}return!1},l=[],m=new Map,d=new Set;for(let f of i)M([f],({kanonak:S,path:I})=>{let V=S instanceof v&&c(S);V&&l.push({node:S,path:I,subject:f.name});for(let{child:U,predicate:N}of Lt(S))c(U)&&(N&&m.set(U,N),V&&d.add(U))});let h=new Set;for(let{node:f,path:S,subject:I}of l){if(d.has(f))continue;let V=_t(m.get(f));if(V)try{Vo(f,S,{catalog:r,depth:0})}catch(U){let N=U instanceof Error?U.message:String(U),Ze=`${I} ${S} ${N}`;if(h.has(Ze))continue;h.add(Ze),n.push(this.toError(I,S,N,V))}}return n}toError(e,o,t,n){let r=new u;r.ruleType=this.ruleName,r.severity="Error",r.entityName=e,r.propertyName=o,r.actualValue=t;let a=/[.!?]$/.test(t)?t:`${t}.`;return r.message=`A tx.Expression at '${o}' is in a slot ${n} evaluates, but it cannot be compiled: ${a} The value would be silently absent wherever this slot is used.`,r.expectedValue=`A tx.Expression built from node classes ${n} implements`,r.suggestion=`This slot is evaluated by ${n}, which is part of this SDK, so its node classes are the ones available here. (An Expression subclass meant for a DIFFERENT runner is fine in that runner's own slots \u2014 this rule does not look at those.)
45
-
46
- Possible solutions:
47
- \u2022 Rebuild the expression from tx primitives this SDK supports
48
- \u2022 For numeric presentation (rounding, percentages, fixed precision), use tx.NumberFormat \u2014 it scales internally, so no arithmetic is needed
49
- \u2022 If the node class should be supported, implement it in the runner first`,r}};function Lt(p){let e=[];for(let o of p.statement){let t=o.predicate?.subject;if(o instanceof G)e.push({child:o.object,predicate:t});else if(o instanceof F)for(let n of o.object)n instanceof v&&e.push({child:n,predicate:t})}return e}function Bt(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var Mt="kanonak.org",We=(p,e)=>({publisher:Mt,package_:p,name:e}),Wt=We("derivation","look"),Wo=We("look","bands"),Fo=We("look","Sequence"),Ft=We("core-rdf","range"),qt=We("look","nodeTier"),Ce=class{ruleName="SequenceNarrative";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(new _(e,o)),a=Ht(e);if(!a)return n;let i=r.filter(c=>c instanceof y&&c.namespace===a);if(i.length===0)return n;for(let c of i){let l=w(c,Wt);l&&K(l,Wo).forEach((m,d)=>{!(m instanceof v)||!A(m,Fo)||n.push(...this.checkBand(r,c,m,`${c.name}.look.bands[${d}]`))})}let s=new $o(r);for(let c of i){let l=s.findCascadedLook(c);if(l)for(let m of K(l.declaration,Wo))!(m instanceof v)||!A(m,Fo)||this.checkBand(r,c,m,"").length>0||n.push(...this.checkInstance(r,c,m,Do(r,c,m)))}return n}checkBand(e,o,t,n){let r=[],a=(l,m,d)=>r.push(this.toError("Error",o.name,n,l,m,d)),i=Je(t);if(!i)a("A look.Sequence band declares no look.source. The order of a sequence comes from the [[references]] in a prose property, so without one nothing can be sequenced.","Set look.source to a property of this class whose rdfs.range is prose.Markdown (or prose.SubstitutableString), and render the same property with a look.Markdown band so the narrative and the diagram cannot drift.");else{let l=ho(e,i)[0],m=l?ko(l,Ft):[];l&&!m.some(d=>fo.isSubstitutableDatatypeUri(d))&&a(`look.source names '${i.name}', whose rdfs.range is ${m.map(d=>R(d)).join(", ")||"undeclared"} \u2014 not prose.Markdown. A Sequence orders its participants by the [[references]] in prose, so a value of this property carries no order.`,"Point look.source at a prose.Markdown-ranged property, or give this property that range if its values are narrative.",R(i))}let s=Qe(e,t);s.length===0&&a("A look.Sequence band declares no look.connectors, so no property counts as a message and every narrative renders empty.","List the object properties that constitute messages: look.connectors: [{ look.relation: calls }, ...]. The domain ontology declares nothing about sequences; the look layer says which of its relations are interactions.");for(let l of s)(!l.subject||L(e,l.subject)===void 0)&&a(`look.connectors names '${l.relation.name}' as a relation, but it is not a property${l.subject?"":" in the closure"}. A message is a triple, so its relation must be an object property whose values are the participants.`,"Use an owl.ObjectProperty (or a subclass such as owl.SymmetricProperty) for look.relation.",R(l.relation)),l.invalidStyle!==void 0&&a(`look.lineStyle '${l.invalidStyle}' on connector '${l.relation.name}' is not a supported value. Supported: ${[...vo].join(", ")}.`,"Use one of the supported values, or omit look.lineStyle: a reply is derived from owl.inverseOf and an undirected edge from owl.SymmetricProperty, so the overlay is only needed for what the ontology cannot say.",l.invalidStyle);let c=z(t,qt);return c!==void 0&&eo[c]===void 0&&a(`look.nodeTier '${c}' is not a tier. Supported: ${Object.keys(eo).join(", ")}.`,"Use one of the semantic-zoom tiers \u2014 chip (56), icon (120, the default), card (240), full (420) \u2014 or omit look.nodeTier to take the participants' class-level look.diagramTier.",c),r}checkInstance(e,o,t,n){let r=[],a=Je(t),i=`${o.name}.${a.name}`,s=Qe(e,t).map(c=>c.relation.name).join(", ");if(n.problem)return r.push(this.toError("Error",o.name,i,`The look.Sequence band cannot walk this instance: ${n.problem}.`,"Check the value authored for the source property.")),r;if(n.sourceAbsent)return r.push(this.toError("Warning",o.name,i,`'${o.name}' carries no value for '${a.name}', so its look.Sequence band renders nothing.`,`Author the narrative in '${a.name}' with [[references]] to the participants, or leave it if the band is meant to be empty here.`)),r;for(let c of n.strayPropertyRefs)r.push(this.toError("Error",o.name,i,`The narrative references property '${c.name}', which is not a declared connector of the look.Sequence band (declared: ${s}). A property reference between two participants selects the edge for that pair; one the band does not declare selects nothing, and the sentence draws no message.`,`Add { look.relation: ${c.name} } to look.connectors on the band, or reference one of the declared connectors instead.`,R(c)));if(n.mentions>=2&&n.messages.length===0)return r.push(this.toError("Error",o.name,i,`The narrative mentions ${n.mentions} participant references but joins nothing: no declared connector (${s}) holds between any consecutive pair, so the look.Sequence band renders no message.`,"Either the graph is missing the triples the prose describes (declare them on the participants), the band is missing the relation the prose relies on (add it to look.connectors), or the prose orders participants no relation joins (reorder it).")),r;for(let c of n.gaps){let l=c.selected?`'${c.selected.name}' does not hold`:`no declared connector (${s}) holds`;r.push(this.toError("Warning",o.name,i,`The narrative orders '${c.prev.name}' then '${c.next.name}', but ${l} between them in the graph, so no message is drawn for that pair.`,`If the prose is right, declare the relation on '${c.prev.name}' or '${c.next.name}' (or add it to look.connectors); if the graph is right, reorder the prose so consecutive references are joined. A mention that is meant to connect to nothing is fine \u2014 it simply gets no lifeline.`,`${c.prev.name} \u2192 ${c.next.name}`))}return r}toError(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=e,i.entityName=o,i.propertyName=t,i.message=n,i.suggestion=r,a!==void 0&&(i.actualValue=a),i}};function Ht(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var Yt="kanonak.org",E=(p,e)=>({publisher:Yt,package_:p,name:e}),Gt=E("derivation","look"),zt=E("look","bands"),Xt=E("look","Distribution"),Zt=E("look","StatRow"),Jt=E("look","VersionDelta"),Qt=E("look","Timeline"),en=E("look","VersionDiff"),on=E("look","TimePlot"),tn=E("look","ReferenceList"),nn=E("look","Diagram"),rn=E("look","alphaPath"),an=E("look","betaPath"),io=E("look","metricPath"),qo=E("look","lowerPath"),Ho=E("look","upperPath"),Yo=E("look","hueBy"),sn=E("look","statPath"),cn=E("look","laneBy"),Go=E("look","labelPath"),pn=E("look","badgePath"),ln=E("look","mapPath"),mn=E("look","nodeNote"),un=E("look","edgeValue"),dn=E("look","stats"),fn=E("look","facets"),yn=E("look","channels"),gn=E("look","track"),kn=E("look","source"),hn=E("look","relation"),Rn=E("look","entries"),Pe=class{ruleName="LookBandPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=Kn(e);if(!a)return n;for(let i of r)i instanceof y&&i.namespace===a&&this.checkDeclaration(r,i,n);return n}checkDeclaration(e,o,t){let n=w(o,Gt);if(!n)return;let r=x(o);if(!r)return;let a=K(n,zt).filter(i=>i instanceof v);for(let i of a)for(let s of this.carriersOf(e,i,r))for(let c of Z(e,s.context,s.expr))t.push(this.toError(o.name,s.slot,c))}carriersOf(e,o,t){let n=[],r=(a,i)=>{let s=w(o,a);s&&n.push({slot:`look.${a.name}`,context:i,expr:s})};if(A(o,Xt))for(let a of[rn,an,io,qo,Ho,Yo])r(a,t);if(A(o,Jt)&&r(io,t),A(o,Zt)){let a=K(o,dn).filter(i=>i instanceof v);for(let i of a){let s=w(i,sn);s&&n.push({slot:"look.stats[].statPath",context:t,expr:s})}}if(A(o,Qt)||A(o,en)){let a=this.rangeOf(e,t,g(o,gn));if(a)for(let i of[io,qo,Ho,Yo])r(i,a)}if(A(o,on)){let a=this.rangeOf(e,t,g(o,kn));if(a)for(let i of[cn,Go])r(i,a)}if(A(o,tn))for(let a of K(o,Rn)){let i=a instanceof v?void 0:bn(a),s=this.rangeOf(e,t,i);if(s)for(let c of[Go,pn])r(c,s)}if(A(o,nn)){let a=K(o,fn).filter(i=>i instanceof v);for(let i of a){let s=this.rangeOf(e,t,g(i,hn));if(!s)continue;let c=w(i,mn);c&&n.push({slot:"look.facets[].nodeNote",context:s,expr:c});let l=w(i,un);l&&n.push({slot:"look.facets[].edgeValue",context:s,expr:l});let m=K(i,yn).filter(d=>d instanceof v);for(let d of m){let h=w(d,ln);h&&n.push({slot:"look.facets[].channels[].mapPath",context:s,expr:h})}}}return n}rangeOf(e,o,t){if(!t)return;let n=B(e,o,t);return n.ok?n.descriptor?.range:void 0}toError(e,o,t){let n=`${t.propertyUri.publisher}/${t.propertyUri.package_}/${t.propertyUri.name}`,r=t.contextClass.name,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=o,a.actualValue=n,a.message=`tx.${t.via} reads property '${t.propertyUri.name}', but its domain is not in scope for '${r}' (the class this band carrier is evaluated against). The read would silently return undefined at render time and the band would render empty.`,a.expectedValue=`A property whose domain is '${r}', an ancestor, or rdfs.Resource`,a.suggestion=`Property '${n}' is not in scope for '${r}'.
50
-
51
- Possible solutions:
52
- \u2022 Read a property declared on '${r}' (or an ancestor / rdfs.Resource)
53
- \u2022 If the property should apply to '${r}', adjust its domain
54
- \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,a}};function bn(p){let e=p.subject;return e&&typeof e.name=="string"?e:void 0}function Kn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var En="kanonak.org",so=(p,e)=>({publisher:En,package_:p,name:e}),Vn=so("derivation","look"),vn=so("look","bands"),Dn=so("core-rdf","type"),Fe=class{ruleName="UnrenderableBand";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(new _(e,o)),a=Sn(e);if(!a)return n;let i=jo();for(let s of r){if(!(s instanceof y)||s.namespace!==a)continue;let c=w(s,Vn);if(!c)continue;let l=K(c,vn).filter(m=>m instanceof v);for(let m of l){let d=this.typeOf(m);if(!d)continue;let h=`${d.publisher}/${d.package_}/${d.name}`;if(i.has(h))continue;let f=new u;f.ruleType=this.ruleName,f.severity="Warning",f.entityName=s.name,f.propertyName="derivation.look",f.actualValue=h,f.message=`Band '${d.name}' has no renderer, so this region of the page will be empty. The declaration is valid against the look vocabulary, but the renderer emits only an HTML comment for it \u2014 which a browser does not display, so the loss is silent. Use a band the renderer implements, or remove it until it is supported.`,n.push(f)}}return n}typeOf(e){let o=g(e,Dn);if(o)return{publisher:o.publisher,package_:o.package_,name:o.name}}};function Sn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var Ue="kanonak.org",Ae="view",In={publisher:Ue,package_:Ae,name:"bind"},$n={publisher:Ue,package_:Ae,name:"produces"},jn={publisher:Ue,package_:Ae,name:"projections"},On={publisher:Ue,package_:Ae,name:"where"},Cn={publisher:Ue,package_:Ae,name:"value"},Pn={publisher:Ue,package_:Ae,name:"as"},we=class{ruleName="TxExpressionPath";async validateAsync(e,o,t){let n=[],r;t?r=await t.getKanonaks():r=await new j().parseKanonaks(new _(e,o));let a=An(e);if(!a)return n;for(let i of r)i instanceof y&&i.namespace===a&&this.checkView(r,i,n);return n}checkView(e,o,t){let n=g(o,In);if(!n)return;let r=g(o,$n),a=0;for(let s of Un(e,K(o,jn))){let c=w(s,Cn);if(c)for(let m of Z(e,n,c))t.push(this.toError(o.name,`view.projections[${a}].value`,n,m));let l=g(s,Pn);l&&r&&(B(e,r,l).ok||t.push(this.asError(o.name,a,r,l))),a+=1}let i=0;for(let s of wn(o,On)){for(let c of Z(e,n,s))t.push(this.toError(o.name,`view.where[${i}]`,n,c));i+=1}}asError(e,o,t,n){let r=`${n.publisher}/${n.package_}/${n.name}`,a=new u;return a.ruleType=this.ruleName,a.severity="Error",a.entityName=e,a.propertyName=`view.projections[${o}].as`,a.actualValue=r,a.message=`Projection stores its value under property '${n.name}', but that property's domain is not in scope for the view's produces class '${t.name}'. The materialized result instance could not carry this value.`,a.expectedValue=`A property whose domain is '${t.name}', an ancestor, or rdfs.Resource`,a.suggestion=`Property '${r}' is not in scope for produces class '${t.name}'.
55
-
56
- Possible solutions:
57
- \u2022 Use an output property whose domain covers '${t.name}'
58
- \u2022 Define a new property in the ViewPackage with domain '${t.name}' and the right range
59
- \u2022 If the value belongs on a different output class, adjust the view's produces`,a}toError(e,o,t,n){let r=`${n.propertyUri.publisher}/${n.propertyUri.package_}/${n.propertyUri.name}`,a=n.contextClass.name,i=a===t.name?`the view's bound class '${t.name}'`:`'${a}', reached by traversal from the view's bound class '${t.name}'`,s=new u;return s.ruleType=this.ruleName,s.severity="Error",s.entityName=e,s.propertyName=o,s.actualValue=r,s.message=`tx.${n.via} reads property '${n.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 '${a}', an ancestor, or rdfs.Resource`,s.suggestion=`Property '${r}' is not in scope for '${a}'.
60
-
61
- Possible solutions:
62
- \u2022 Read a property declared on '${a}' (or an ancestor / rdfs.Resource)
63
- \u2022 If the property should apply to '${a}', adjust its domain
64
- \u2022 If the path is wrong, correct the tx.PropertyRead/tx.Traverse chain`,s}};function wn(p,e){let o=w(p,e);return o?[o]:K(p,e).filter(t=>t instanceof v)}function Un(p,e){let o=[];for(let t of e)if(t instanceof v)o.push(t);else if(t instanceof C){let n=b(p,t.subject);n&&o.push(n)}return o}function An(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var Xe="kanonak.org",Nn="core-shacl",T=p=>({publisher:Xe,package_:Nn,name:p}),xn=T("NodeShape"),Tn=T("PropertyShape"),_n=T("targetClass"),Ln=T("property"),Bn=T("path"),Mn=T("minCount"),Wn=T("maxCount"),Fn=T("datatype"),qn=T("class"),zo=T("in"),Hn=T("pattern"),Yn=T("flags"),Gn=T("minLength"),zn=T("maxLength"),Xn=T("minInclusive"),Zn=T("maxInclusive"),Jn=new Set(["decimal","integer","int","long","short","byte","float","double","nonNegativeInteger","positiveInteger","negativeInteger","nonPositiveInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"]),Xo=p=>p,xe=class{ruleName="ShaclShape";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=Qn(e);if(!a)return n;let i=new Set;for(let s of r){if(!(s instanceof y)||s.namespace!==a||!A(s,xn))continue;let c=g(s,_n);c?this.resolvesToClass(r,c)||n.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.",J(c))):n.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 l of K(s,Ln)){let m;if(l instanceof v)m=l;else if(l instanceof C){let d=b(r,l.subject);d&&(m=d,i.add(R(l.subject)))}m&&this.checkPropertyShape(r,s.name,m,c??void 0,n)}}for(let s of r){if(!(s instanceof y)||s.namespace!==a||!A(s,Tn))continue;let c=x(s);c&&i.has(R(c))||this.checkPropertyShape(r,s.name,s,void 0,n)}return n}checkPropertyShape(e,o,t,n,r){let a=g(t,Bn);if(!a){r.push(this.err(o,"property.path","Error",`A PropertyShape on '${o}' has no sh:path; a PropertyShape must name the property it constrains.`,"Add sh:path naming a property."));return}let i=b(e,a),s=i?Y(e,i):!1;s?n&&(B(e,n,a).ok||r.push(this.err(o,"property.path","Warning",`sh:path '${a.name}' is not in scope for sh:targetClass '${n.name}'; the constraint would never bind a value.`,`Constrain a property whose domain is '${n.name}', an ancestor, or rdfs.Resource.`,J(a)))):r.push(this.err(o,"property.path","Error",`sh:path '${a.name}' on '${o}' does not resolve to a property.`,"Reference a defined or imported property.",J(a)));let c=g(t,Fn),l=g(t,qn);c&&l&&r.push(this.err(o,"property","Error",`A PropertyShape on '${o}' 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)&&r.push(this.err(o,"datatype","Error",`sh:datatype '${c.name}' on '${o}' does not resolve to a datatype.`,"Reference an xsd datatype or rdfs.Datatype.",J(c))),l&&!this.resolvesToClass(e,l)&&r.push(this.err(o,"class","Error",`sh:class '${l.name}' on '${o}' does not resolve to a class.`,"Reference a defined or imported rdfs.Class.",J(l)));let m=Ne(X(t,Mn)),d=Ne(X(t,Wn));this.checkOrder(o,"minCount",m,"maxCount",d,r);let h=Ne(X(t,Gn)),f=Ne(X(t,zn));this.checkOrder(o,"minLength",h,"maxLength",f,r);let S=Ne(X(t,Xn)),I=Ne(X(t,Zn));this.checkOrder(o,"minInclusive",S,"maxInclusive",I,r);let V=z(t,Hn);if(V!==void 0){let U=z(t,Yn);try{new RegExp(V,U)}catch{r.push(this.err(o,"pattern","Error",`sh:pattern on '${o}' is not a valid regular expression`+(U!==void 0?` (with flags '${U}')`:"")+`: ${V}`,"Provide a valid regular expression and flags.",V))}}if(Q(t,zo)&&K(t,zo).length===0&&r.push(this.err(o,"in","Error",`sh:in on '${o}' is empty; an enumeration must list at least one permitted value.`,"List the permitted literal values, or remove sh:in.")),s&&n){let N=B(e,n,a).descriptor;N&&((V!==void 0||h!==void 0||f!==void 0)&&N.kind==="object"&&r.push(this.err(o,"pattern/minLength/maxLength","Warning",`String facets on '${o}' apply to '${a.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.",J(a))),(S!==void 0||I!==void 0)&&!this.isNumericDatatypeRange(N.range)&&r.push(this.err(o,"minInclusive/maxInclusive","Warning",`Numeric bounds on '${o}' apply to '${a.name}', whose range is not a numeric datatype.`,"Apply numeric bounds to a numeric datatype property.",J(a))))}}checkOrder(e,o,t,n,r,a){t!==void 0&&r!==void 0&&t>r&&a.push(this.err(e,`${o}/${n}`,"Error",`${o} (${t}) exceeds ${n} (${r}) on '${e}'.`,`Set ${o} <= ${n}.`))}resolvesToClass(e,o){let t=b(e,o);return t?$.isClassType(Xo(t)):!1}resolvesToDatatype(e,o){if(o.publisher===Xe&&o.package_==="core-rdf"&&o.name==="Literal")return!0;let t=b(e,o);return t?$.isDatatypeType(Xo(t)):!1}isNumericDatatypeRange(e){return!e||e.publisher===Xe&&e.package_==="core-rdf"&&e.name==="Literal"?!0:e.publisher===Xe&&e.package_==="core-xsd"&&Jn.has(e.name)}err(e,o,t,n,r,a){let i=new u;return i.ruleType=this.ruleName,i.severity=t,i.entityName=e,i.propertyName=o,i.message=n,i.suggestion=r,a!==void 0&&(i.actualValue=a),i}};function Ne(p){return typeof p=="number"?p:void 0}function J(p){return`${p.publisher}/${p.package_}/${p.name}`}function Qn(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var Zo={publisher:"kanonak.org",package_:"core-owl",name:"oneOf"},er=p=>p,Te=class{ruleName="OwlOneOf";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=or(e);if(!a)return n;for(let i of r){if(!(i instanceof y)||i.namespace!==a||!Q(i,Zo))continue;let s=K(i,Zo);if(s.length===0){n.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 mo)n.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 C){let l=b(r,c.subject);l&&$.isSchemaDefinitionType(er(l))&&n.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 n}err(e,o,t,n,r){let a=new u;return a.ruleType=this.ruleName,a.severity=o,a.entityName=e,a.propertyName="oneOf",a.message=t,a.suggestion=n,r!==void 0&&(a.actualValue=r),a}};function or(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var tr=p=>p,nr=new lo("kanonak.org","core-rdf","Resource"),_e=class{ruleName="DiamondNameClash";async validateAsync(e,o,t){let n=[],r=t?await t.getKanonaks():await new j().parseKanonaks(o),a=rr(e);if(!a)return n;let i=So(r);for(let s of r){if(!(s instanceof y)||s.namespace!==a||!$.isClassType(tr(s)))continue;let c=x(s);if(!c)continue;let l=H(r,c),m=R(c),d=new Set(l.map(f=>R(f)));d.delete(m),d.delete(R(nr));let h=new Map;for(let f of Ro(r,c)){if(!f.domains.some(V=>d.has(R(V))))continue;let I=h.get(f.uri.name);I?I.push(f):h.set(f.uri.name,[f])}for(let[f,S]of h){if(S.length<2)continue;let I=N=>Io(i,l,N.uri)?.cardinality,V=new Set(S.map(N=>N.range?R(N.range):void 0).filter(N=>N!==void 0)),U=new Set(S.map(I).filter(N=>N!==void 0));V.size<=1&&U.size<=1||n.push(this.toError(s.name,f,S,I))}}return n}toError(e,o,t,n){let r=s=>{let c=`${s.uri.publisher}/${s.uri.package_}/${s.uri.name}`,l=s.range?`${s.range.publisher}/${s.range.package_}/${s.range.name}`:"no range",m=n(s);return`${c} (range ${l}${m?`, ${m}`:""})`},a=t.map(r).join("; "),i=new u;return i.ruleType=this.ruleName,i.severity="Error",i.entityName=e,i.propertyName=o,i.actualValue=a,i.message=`Class '${e}' inherits ${t.length} distinct properties named '${o}' with incompatible range or cardinality: ${a}. The generated interface would multiply-inherit '${o}' with conflicting types and could not compile.`,i.suggestion=`Disambiguate the diamond name-clash on '${o}':
65
- \u2022 rename one of the properties, or
66
- \u2022 re-domain one so it is not inherited by '${e}', or
67
- \u2022 restructure the hierarchy so '${e}' inherits only one '${o}', or
68
- \u2022 make the ranges/cardinalities compatible (identical) if they are meant to be the same property.`,i}};function rr(p){let e=p.metadata.namespace_;if(!(!e||!e.version))return`${e.publisher}/${e.package_}@${O(e.version)}`}var co=class{parser;documentRules;repositoryRules;includeWarnings=!0;constructor(e){this.parser=e??new po,this.documentRules=[new re,new ae,new ie,new se,new ce],this.repositoryRules=[new pe,new le,new me,new ue,new de,new fe,new ye,new ge,new ke,new he,new Re,new be,new Ee,new Ve,new ve,new De,new Se,new Ie,new $e,new je,new Pe,new Fe,new Ce,new Oe,new we,new xe,new Te,new _e]}async validateAsync(e,o,t){let n=new ee;for(let r of this.documentRules)try{let a=r.validate(e);this.addErrorsToResult(n,a)}catch(a){let i=new u;i.ruleType=r.ruleName,i.severity="Error",i.message=`Validation rule '${r.ruleName}' failed: ${a instanceof Error?a.message:String(a)}`,n.errors.push(i)}if(o){let r=[],a=t??new oe(new te(e,o)),i=a.repository;for(let s of this.repositoryRules)try{let c=await s.validateAsync(e,i,a);this.addErrorsToResult(n,c)}catch(c){let l=c instanceof Error?c.message:String(c);r.push({ruleName:s.ruleName,cause:l})}if(r.length>0){let s=new Map;for(let{ruleName:c,cause:l}of r){let m=s.get(l);m?m.push(c):s.set(l,[c])}for(let[c,l]of s){let m=new u;m.ruleType=l[0],m.severity="Error",l.length===1?m.message=`Validation rule '${l[0]}' failed: ${c}`:m.message=`${c} (affects ${l.length} rules: ${l.join(", ")})`,n.errors.push(m)}}}return n.isValid=n.errors.length===0,n}async validateDocumentsAsync(e,o){let t=new oe(o),n=[];for(let r of e){let a=await this.validateAsync(r,t.repository,t);n.push({document:r,result:a})}return n}async validateYamlAsync(e,o,t){let n=this.parser.parseWithErrors(e);if(!n.isValid){let r=new ee;r.isValid=!1;for(let a of n.errors){let i=new u;i.ruleType="ParseError",i.severity="Error",i.lineNumber=a.line,i.column=a.column,i.message=a.message,a.keyName&&(i.entityName=a.keyName),a.errorType==="DuplicateKey"&&(i.suggestion="All property names must be unique across the entire document. Rename one of the duplicate properties to make them unique."),r.errors.push(i)}return r}return await this.validateAsync(n.document,o,t)}addDocumentRule(e){this.documentRules.push(e)}addRepositoryRule(e){this.repositoryRules.push(e)}removeDocumentRule(e){let o=this.documentRules.findIndex(t=>t instanceof e);o>=0&&this.documentRules.splice(o,1)}removeRepositoryRule(e){let o=this.repositoryRules.findIndex(t=>t instanceof e);o>=0&&this.repositoryRules.splice(o,1)}addErrorsToResult(e,o){for(let t of o)t.severity==="Error"?e.errors.push(t):t.severity==="Info"?this.includeWarnings&&e.infos.push(t):this.includeWarnings&&e.warnings.push(t)}};export{ee as a,k as b,u as c,oo as d,oe as e,re as f,ae as g,ie as h,se as i,ce as j,pe as k,le as l,me as m,ue as n,de as o,fe as p,ye as q,ge as r,ke as s,he as t,Re as u,be as v,Ee as w,Ve as x,ve as y,De as z,Se as A,Ie as B,$e as C,je as D,Oe as E,Ce as F,Pe as G,we as H,xe as I,Te as J,_e as K,co as L};
@@ -1 +0,0 @@
1
- import{b as y,e as m}from"./chunk-QILEJIFU.js";function f(t){let e=t.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}function k(t){let e=t.metadata?.namespace_;if(e)return e.version?`${e.publisher}/${e.package_}@${m(e.version)}`:`${e.publisher}/${e.package_}`}async function A(t,e,n={}){let o=new Set,u=new Set,i=[...t];for(;i.length>0;){let a=i.shift(),l=f(a),r=k(a);if(!l||!r||u.has(r))continue;u.add(r),o.add(l);let p=a.metadata?.imports;if(p)for(let[g,h]of Object.entries(p))for(let s of h){let c=null,d="no-compatible-version";try{c=await e.getHighestCompatibleVersionAsync(g,s)}catch{d="resolution-error"}c?i.push(c):n.onUnresolvedEdge?.({fromNamespace:r,publisher:g,packageName:s.packageName,constraint:`${y(s.versionOperator)}${m(s.version)}`,reason:d})}}return o}var D=class{constructor(e,n){this.inner=e;this.scope=n}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(n=>{let o=f(n);return o!==void 0&&this.scope.has(o)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,n){return this.inner.getDocumentsByNamespaceAsync(e,n)}getHighestCompatibleVersionAsync(e,n){return this.inner.getHighestCompatibleVersionAsync(e,n)}saveDocumentAsync(e,n){return this.inner.saveDocumentAsync(e,n)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,n){return this.inner.clearNamespaceAsync(e,n)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};export{A as a,D as b};
@@ -1 +0,0 @@
1
- import{a as G}from"./chunk-KOWDHKBN.js";import{a as H,aa as Y,b as J,ba as N,ca as A,ia as Z}from"./chunk-G3GKOJ5E.js";import{a as X,b as q,c as w,d as g,g as R,h as T,i as M,j as D,k as K,l as P,m as x,n as _,t as Q}from"./chunk-CJMVIOZX.js";import{a as L}from"./chunk-FUUTGGJS.js";import{k as W}from"./chunk-QILEJIFU.js";var b=class extends q{name};var j=class extends X{value;carrier;lexical};var I=class extends R{links=[]};var ae="kanonak.org",oe="transformations",Ke=3,e=p=>({publisher:ae,package_:oe,name:p}),E={Transformation:e("Transformation"),InstanceTransformation:e("InstanceTransformation"),SetTransformation:e("SetTransformation"),inputPattern:e("inputPattern"),rule:e("rule"),artifactName:e("artifactName"),outputs:e("outputs"),formatOverrides:e("formatOverrides"),partitionBy:e("partitionBy"),InputPattern:e("InputPattern"),matchesClass:e("matchesClass"),requires:e("requires"),sortBy:e("sortBy"),SortKey:e("SortKey"),byProperty:e("byProperty"),order:e("order"),SortOrder:e("SortOrder"),ascending:e("ascending"),descending:e("descending"),OutputFormat:e("OutputFormat"),backendUri:e("backendUri"),FormatOverride:e("FormatOverride"),formatTarget:e("formatTarget"),metadataKeys:e("metadataKeys"),metadataRenames:e("metadataRenames"),trailingNewline:e("trailingNewline"),omitWrapper:e("omitWrapper"),RenameEntry:e("RenameEntry"),fromKey:e("fromKey"),toKey:e("toKey"),FMT_MARKDOWN_FRONTMATTER:e("markdown-with-frontmatter"),FMT_PLAIN_MARKDOWN:e("plain-markdown"),FMT_TOML:e("toml"),FMT_JSON:e("json"),FMT_HTML:e("html"),FMT_SVG:e("svg"),Expression:e("Expression"),ListSourcedExpression:e("ListSourcedExpression"),ListAggregate:e("ListAggregate"),IteratingExpression:e("IteratingExpression"),BuildAstNode:e("BuildAstNode"),astClass:e("astClass"),set:e("set"),AstFieldBinding:e("AstFieldBinding"),field:e("field"),bindValue:e("bindValue"),When:e("When"),condition:e("condition"),thenBuild:e("thenBuild"),elseBuild:e("elseBuild"),Concat:e("Concat"),parts:e("parts"),Fallback:e("Fallback"),primary:e("primary"),alternate:e("alternate"),StringLiteral:e("StringLiteral"),stringLiteral:e("stringLiteral"),IntegerLiteral:e("IntegerLiteral"),integerLiteral:e("integerLiteral"),DecimalLiteral:e("DecimalLiteral"),decimalLiteral:e("decimalLiteral"),BooleanLiteral:e("BooleanLiteral"),booleanLiteral:e("booleanLiteral"),VarRef:e("VarRef"),varName:e("varName"),PropertyRead:e("PropertyRead"),readSource:e("readSource"),readProp:e("readProp"),Traverse:e("Traverse"),traverseSource:e("traverseSource"),through:e("through"),step:e("step"),UriName:e("UriName"),uriNameOf:e("uriNameOf"),UriPublisher:e("UriPublisher"),uriPublisherOf:e("uriPublisherOf"),UriPackage:e("UriPackage"),uriPackageOf:e("uriPackageOf"),UriVersion:e("UriVersion"),uriVersionOf:e("uriVersionOf"),SubjectUri:e("SubjectUri"),subjectOf:e("subjectOf"),UriLiteral:e("UriLiteral"),refTo:e("refTo"),DisplayLabel:e("DisplayLabel"),labelTarget:e("labelTarget"),labelSource:e("labelSource"),ResolveRef:e("ResolveRef"),resolveSource:e("resolveSource"),Normalize:e("Normalize"),normSource:e("normSource"),normKind:e("normKind"),NormalizeKind:e("NormalizeKind"),NORM_TRIM_END:e("trim-end"),NORM_TO_UPPER:e("to-upper"),NORM_TO_LOWER:e("to-lower"),NORM_FIRST_CHAR:e("first-char"),UnescapedString:e("UnescapedString"),unescapedSource:e("unescapedSource"),IsSet:e("IsSet"),checkExpr:e("checkExpr"),ExpressionFragment:e("ExpressionFragment"),body:e("body"),CallFragment:e("CallFragment"),fragmentRef:e("fragmentRef"),source:e("source"),Join:e("Join"),separator:e("separator"),Count:e("Count"),Sum:e("Sum"),Min:e("Min"),Max:e("Max"),Average:e("Average"),loopVar:e("loopVar"),ForEach:e("ForEach"),emit:e("emit"),ListMap:e("ListMap"),mapBody:e("mapBody"),Filter:e("Filter"),predicate:e("predicate"),PartitionBy:e("PartitionBy"),partitionKey:e("partitionKey"),DistinctBy:e("DistinctBy"),distinctKey:e("distinctKey"),Partition:e("Partition"),key:e("key"),members:e("members"),AllStatements:e("AllStatements"),statementsOf:e("statementsOf"),StatementPredicate:e("StatementPredicate"),predicateOf:e("predicateOf"),StatementValue:e("StatementValue"),valueOf:e("valueOf"),DateFormat:e("DateFormat"),dateSource:e("dateSource"),dateFormat:e("dateFormat"),NumberFormat:e("NumberFormat"),numberSource:e("numberSource"),numberStyle:e("numberStyle"),fractionDigits:e("fractionDigits"),currencyCode:e("currencyCode"),BinaryArithmetic:e("BinaryArithmetic"),arithLeft:e("arithLeft"),arithRight:e("arithRight"),Add:e("Add"),Subtract:e("Subtract"),Multiply:e("Multiply"),Divide:e("Divide"),Reverse:e("Reverse"),WindowedMap:e("WindowedMap"),windowSize:e("windowSize"),windowVar:e("windowVar"),windowBody:e("windowBody"),PairwiseMap:e("PairwiseMap"),firstVar:e("firstVar"),secondVar:e("secondVar"),pairBody:e("pairBody"),Scan:e("Scan"),initialState:e("initialState"),stateVar:e("stateVar"),elementVar:e("elementVar"),accumulate:e("accumulate"),ListItemAt:e("ListItemAt"),itemIndex:e("itemIndex"),BinaryComparison:e("BinaryComparison"),compareLeft:e("compareLeft"),compareRight:e("compareRight"),Equals:e("Equals"),GreaterThan:e("GreaterThan"),LessThan:e("LessThan"),GreaterThanOrEqual:e("GreaterThanOrEqual"),LessThanOrEqual:e("LessThanOrEqual"),Not:e("Not"),operand:e("operand"),BooleanLogic:e("BooleanLogic"),operands:e("operands"),And:e("And"),Or:e("Or"),Contains:e("Contains"),haystack:e("haystack"),needle:e("needle"),UnaryNumericOp:e("UnaryNumericOp"),value:e("value"),Abs:e("Abs"),Negate:e("Negate"),KindPredicate:e("KindPredicate"),IsReference:e("IsReference"),IsEmbedded:e("IsEmbedded"),IsList:e("IsList"),kindCheck:e("kindCheck"),IsString:e("IsString"),IsNumber:e("IsNumber"),IsBoolean:e("IsBoolean"),StatementObject:e("StatementObject"),statementSource:e("statementSource"),Let:e("Let"),letName:e("letName"),letValue:e("letValue"),letBody:e("letBody"),GetStatementByName:e("GetStatementByName"),inSubject:e("inSubject"),byName:e("byName"),RenderMarkdown:e("RenderMarkdown"),renderSource:e("renderSource"),renderProp:e("renderProp"),renderFormat:e("renderFormat"),RenderFormat:e("RenderFormat"),RENDER_HTML:e("render-html"),RENDER_MARKDOWN:e("render-markdown")};import{Carrier as h,carrierOf as se}from"@kanonak-protocol/canonical";function B(p){return se(`${p.publisher}/${p.package_}/${p.name}`)}var ie=/\[\[([^\[\]\n]+)\]\]/g,ce=/\[\[/g,ee=/```[\s\S]*?```|`[^`\n]*`/g;function pe(p){let t=[];for(let n of p.matchAll(ee))t.push([n.index,n.index+n[0].length]);return t}function ve(p){if(!p||!p.includes("[["))return[];let t=pe(p),n=s=>t.some(([o,c])=>s>=o&&s<c),r=new Set(V(p).map(s=>s.startOffset)),a=[];for(let s of p.matchAll(ce)){let o=s.index;if(n(o)||r.has(o))continue;let c=p.slice(o,o+48).replace(/\s+/g," ").trim();a.push({startOffset:o,snippet:c})}return a}function V(p){if(!p||!p.includes("[["))return[];let t=[];for(let a of p.matchAll(ee))t.push([a.index,a.index+a[0].length]);let n=a=>t.some(([s,o])=>a>=s&&a<o),r=[];for(let a of p.matchAll(ie)){let s=a.index;if(n(s))continue;let o=a[1],c=o.indexOf("|"),m=(c===-1?o:o.slice(0,c)).trim();if(m.length===0)continue;let i=c===-1?"":o.slice(c+1).trim(),u={reference:m,startOffset:s,endOffset:s+a[0].length};i.length>0&&(u.displayText=i),r.push(u)}return r}function ne(p,t){for(let n of p)n instanceof w&&U(n,n.name,t)}function U(p,t,n){n({kanonak:p,path:t});for(let r of p.statement){let a=r.predicate?.subject?.name;if(r instanceof K)U(r.object,te(t,a,r.object),n);else if(r instanceof P)for(let s=0;s<r.object.length;s++){let o=r.object[s];o instanceof b&&U(o,te(t,a,o,s),n)}}}function te(p,t,n,r){let a=`${p}.${t??"<embedded>"}`,s=n instanceof b?n.name:void 0;return s?`${a}.${s}`:r===void 0?a:`${a}[${r}]`}var me={...N("range"),name:"range"};function fe(p){let t=p.lastIndexOf(".");return t===-1?p:p.slice(t+1)}var re=class{constructor(t){}async parseKanonaks(t,n){let r=await t.getAllDocumentsAsync(),a=new H(t),s=new J(a);this.knownPropertyClasses.clear();let o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t);return await this.learnPropertyClassesAsync(c,r,a)&&(o=await this.parseAllDocumentsAsync(r,a,s,t),c=await this.mergeAndCanonicalizeAsync(o,t)),n&&(n.authored=o),c}knownPropertyClasses=new Map;async learnPropertyClassesAsync(t,n,r){let a=new Map;for(let m of n){let i=m.metadata.namespace_?.toString();i&&a.set(i,m)}let s=[],o=new Set;ne(t,({kanonak:m})=>{for(let i of m.unresolvedPredicates){let u=`${i.sourceDoc}::${i.key}`;o.has(u)||(o.add(u),s.push(i))}});let c=!1;for(let m of s){let i=a.get(m.sourceDoc);if(!i)continue;let u=await r.resolveEntityAsync(m.key,i);if(!u)continue;let d=x(u.uri);if(this.knownPropertyClasses.has(d))continue;let f=Q(t,u.uri);if(!f)continue;let l=Z(t,f);l&&(this.knownPropertyClasses.set(d,l),c=!0)}return c}async parseAllDocumentsAsync(t,n,r,a){let s=[];for(let o of t){let c=o.metadata.namespace_?.toString()??"";for(let[m,i]of Object.entries(o.body)){let u=new w,d=this.resolveCanonicalEntity(m,o,c);u.namespace=d.namespace,u.name=d.name,u.statement=[];let f=await this.parseStatements(i,o,n,r,a);u.statement.push(...f.statements),u.unresolvedPredicates=f.unresolved,F(u,c),s.push(u)}}return s}async mergeAndCanonicalizeAsync(t,n){let r=new Map,a=new Map,s=[];for(let i of t)if(i instanceof w){let u=`${i.namespace}/${i.name}`,d=r.get(u);if(d){let f=a.get(u);for(let l of i.statement){let y=$(l);f.has(y)||(f.add(y),d.statement.push(l))}for(let l of i.unresolvedPredicates)d.unresolvedPredicates.some(y=>y.key===l.key&&y.sourceDoc===l.sourceDoc)||d.unresolvedPredicates.push(l)}else{let f=new w;f.namespace=i.namespace,f.name=i.name,f.sourceDoc=i.sourceDoc;let l=new Set;for(let y of i.statement){let k=$(y);l.has(k)||(l.add(k),f.statement.push(y))}f.unresolvedPredicates=[...i.unresolvedPredicates],a.set(u,l),r.set(u,f),s.push(f)}}else s.push(i);let o=new Set;for(let i of s)if(i instanceof w){let u=i.namespace||"",d=u.indexOf("/"),f=d>=0?u.slice(0,d):"",l=d>=0?u.slice(d+1):"",y=l.indexOf("@"),k=y>=0?l.slice(0,y):l;o.add(`${f}/${k}/${i.name}`)}let c=i=>o.has(`${i.publisher}/${i.package_}/${i.name}`),m=new Map;for(let i of["core-rdf","core-owl","core-kanonak"]){let u=await n.getDocumentsByNamespaceAsync("kanonak.org",i);m.set(i,W(u).chosen?.metadata.namespace_?.version??void 0)}for(let i of t)i instanceof w&&this.canonicalizeStatementBuiltins(i.statement,c,m);return s}canonicalizeStatementBuiltins(t,n,r){for(let a of t){let s=a.predicate?.subject;if(A(s,n,r),a instanceof D)a.object instanceof g&&A(a.object.subject,n,r);else if(a instanceof K)a.object&&this.canonicalizeStatementBuiltins(a.object.statement,n,r);else if(a instanceof P)for(let o of a.object??[])o instanceof g?A(o.subject,n,r):o instanceof b&&this.canonicalizeStatementBuiltins(o.statement,n,r)}}resolveCanonicalEntity(t,n,r){if(!t.includes(".")||!n.metadata?.imports)return{namespace:r,name:t};let a=t.indexOf("."),s=t.substring(0,a),o=t.substring(a+1);for(let[c,m]of Object.entries(n.metadata.imports))for(let i of m)if((i.alias??i.packageName)===s){let d=i.version;return{namespace:`${c}/${i.packageName}@${d.major}.${d.minor}.${d.patch}`,name:o}}return{namespace:r,name:t}}async parseStatements(t,n,r,a,s){let o=[],c=[];if(typeof t!="object"||t===null||Array.isArray(t))return{statements:o,unresolved:c};let m=n.metadata.namespace_?.toString()??"";for(let[i,u]of Object.entries(t))try{let d=await this.getPropertyMetadata(i,n,r,s,a);if(!d){let l=i.includes(".")?i.slice(i.lastIndexOf(".")+1):i;Y(l)||c.push({key:i,sourceDoc:m});continue}let f=await this.parsePropertyValue(i,u,d,n,r,a,s);f&&o.push(f)}catch(d){throw new Error(`Failed to parse property '${i}': ${d.message}`,{cause:d})}return{statements:o,unresolved:c}}async getPropertyMetadata(t,n,r,a,s){let o=await r.resolveEntityAsync(t,n);if(!o)return;let c=o.entity,m=c.type?.toString()??"",i=m.includes(".")?m.substring(m.lastIndexOf(".")+1):m,u=new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]),d=this.knownPropertyClasses.get(x(o.uri));if(!u.has(i)&&!d)return;let f=d??s.getPropertyTypeClassification(m),l,y=async()=>{if(l)return l;if(!(o.isImported&&o.definedInNamespace))return l=n,n;if(typeof a.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${t}': the parse repository cannot fetch defining document '${o.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let v=await a.getDocumentAsync(o.definedInNamespace);if(!v)throw new Error(`Cannot resolve the range of imported property '${t}': defining document '${o.definedInNamespace}' was not found in the repository.`);return l=v,v},k=await this.readDefinitionSlot(c,me,y,r),S=k==null?void 0:String(k),O;if(f==="ObjectProperty")O="ObjectProperty";else if(f==="DatatypeProperty")O="DatatypeProperty";else{let v=S&&S.includes(".")?S.substring(S.lastIndexOf(".")+1):S??"";(S?s.isKnownXsdDatatypeName(S):!1)||v==="Literal"?O="DatatypeProperty":O="ObjectProperty"}let z;return S&&(z=(await r.resolveEntityAsync(S,await y()))?.uri),{propertyUri:o.uri.toString(),propertyType:O,range:S,rangeUri:z,isImported:o.isImported,definedInNamespace:o.definedInNamespace}}async readDefinitionSlot(t,n,r,a){let s=Object.keys(t).filter(i=>fe(i)===n.name);if(s.length===0)return;let o=await r(),c=N(n.name),m=c!==void 0&&c.publisher===n.publisher&&c.package_===n.package_;for(let i of s){let u=await a.resolveEntityAsync(i,o);if(u){if(_(u.uri,n))return t[i];continue}if(!i.includes(".")&&m)return t[i]}}async parsePropertyValue(t,n,r,a,s,o,c){let m=r.propertyUri;if(n!=null){if(Array.isArray(n))return this.parseListValue(m,n,r,a,s,o,c);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(m,n,r,a,s,o);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(m,n,r,a,s,o,c)}}async parseDatatypeValue(t,n,r,a,s,o){let c;if(typeof n=="string"){if(o.isSubstitutableDatatype(r.rangeUri))return await this.parseSubstitutableValue(t,n,a,s);c=n}else if(typeof n=="number"||typeof n=="boolean")c=String(n);else return;return this.typedScalarStatement(t,c,r)}typedScalarStatement(t,n,r){let a=g.parse(t),s=r.rangeUri?B(r.rangeUri):void 0;if(s===h.Boolean){let c=new M;return c.predicate=a,c.object=n==="true"||n==="1",c.carrier=s,c.lexical=n,c}if(s===h.Integer||s===h.Decimal||s===h.Double||s===h.Float){let c=new T;return c.predicate=a,c.object=Number(n),c.carrier=s,c.lexical=n,c}let o=R.parse(t,n);return s&&(o.carrier=s,o.lexical=n),o}typedListLiteral(t,n){let r=new j,a=n.rangeUri?B(n.rangeUri):void 0;return a===h.Boolean?r.value=t==="true"||t==="1":a===h.Integer||a===h.Decimal||a===h.Double||a===h.Float?r.value=Number(t):r.value=t,a&&(r.carrier=a,r.lexical=t),r}async parseSubstitutableValue(t,n,r,a){let s=new I;s.predicate=g.parse(t),s.object=n;for(let o of V(n)){let c=await a.resolveEntityAsync(o.reference,r),m;c&&(m=new g,m.subject=c.uri);let i={reference:o.reference,startOffset:o.startOffset,endOffset:o.endOffset};o.displayText!==void 0&&(i.displayText=o.displayText),m!==void 0&&(i.target=m),s.links.push(i)}return s}async parseObjectValue(t,n,r,a,s,o,c){if(typeof n=="string"){if(r.rangeUri&&_(r.rangeUri,E.Expression))return this.coerceExpressionLiteral(t,n,r.rangeUri);let m=await this.resolveReference(n,a,s);if(!m)return;let i=new D;return i.predicate=g.parse(t),i.object=m,i}if(typeof n=="object"&&!Array.isArray(n)){let m=await this.parseStatements(n,a,s,o,c);if(m.statements.length>0){let d=new b;d.statement=m.statements,d.unresolvedPredicates=m.unresolved;let f=new K;return f.predicate=g.parse(t),f.object=d,f}let i=[];for(let[d,f]of Object.entries(n))if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let l=new b;l.name=d;let y=await this.parseStatements(f,a,s,o,c);l.statement=y.statements,l.unresolvedPredicates=y.unresolved,i.push(l)}else if(typeof f=="string"){let l=await this.resolveReference(f,a,s);l&&i.push(l)}if(i.length>0){let d=new P;return d.predicate=g.parse(t),d.object=i,d}let u=new K;return u.predicate=g.parse(t),u.object=new b,u}}coerceExpressionLiteral(t,n,r){let a=new b,s=new D,o=new g;o.subject=new L("kanonak.org","core-rdf","type"),s.predicate=o;let c=new g;c.subject=new L(r.publisher,r.package_,E.StringLiteral.name,r.version),s.object=c;let m=new R,i=new g;i.subject=new L(r.publisher,r.package_,E.stringLiteral.name,r.version),m.predicate=i,m.object=n,a.statement=[s,m];let u=new K;return u.predicate=g.parse(t),u.object=a,u}async parseListValue(t,n,r,a,s,o,c){let m=[],i=r.propertyType==="DatatypeProperty",u=r.rangeUri?.publisher==="kanonak.org"&&r.rangeUri?.package_==="core-rdf"&&r.rangeUri?.name==="List"||!r.rangeUri&&(r.range?.includes(".")?r.range.substring(r.range.lastIndexOf(".")+1):r.range)==="List";for(let f of n){let l=typeof f=="string"||typeof f=="number"||typeof f=="boolean";if(i&&l){let y=typeof f=="string"?f:String(f);m.push(this.typedListLiteral(y,r));continue}if(u&&l){if(typeof f=="string"){let y=await s.resolveEntityAsync(f,a);if(y){let k=new g;k.subject=y.uri,m.push(k)}else{let k=new j;k.value=f,m.push(k)}}else{let y=new j;y.value=f,m.push(y)}continue}if(typeof f=="string"){let y=await this.resolveReference(f,a,s);y&&m.push(y)}else if(typeof f=="object"&&f!==null&&!Array.isArray(f)){let y=new b,k=await this.parseStatements(f,a,s,o,c);y.statement=k.statements,y.unresolvedPredicates=k.unresolved,m.push(y)}}let d=new P;return d.predicate=g.parse(t),d.object=m,d}async resolveReference(t,n,r){let a=await r.resolveEntityAsync(t,n);if(a){let o=new g;return o.subject=a.uri,o}let s=n.metadata?.namespace_;if(s){let{KanonakUri:o}=await import("./KanonakUri-4VJGV3FN.js");if(t.includes(".")){let m=t.indexOf("."),i=t.substring(0,m),u=t.substring(m+1);if(n.metadata?.imports){for(let[d,f]of Object.entries(n.metadata.imports))for(let l of f)if((l.alias??l.packageName)===i){let k=new g;return k.subject=new o(d,l.packageName,u,l.version),k}}}let c=new g;return c.subject=new o(s.publisher,s.package_,t,s.version??void 0),c}return null}async saveKanonaks(t,n){let r=new Map;for(let a of t)a instanceof w&&a.namespace&&(r.has(a.namespace)||r.set(a.namespace,[]),r.get(a.namespace).push(a));for(let[a,s]of r){let o=await this.convertKanonaksToDocument(a,s),c=`${a.split("@")[0]}.yml`;await n.saveDocumentAsync(o,c)}}async serializeToYaml(t,n){let r=t.filter(o=>o instanceof w&&o.namespace===n);if(r.length===0)throw new Error(`No kanonaks found with namespace '${n}'`);let a=await this.convertKanonaksToDocument(n,r);return new G().save(a)}async convertKanonaksToDocument(t,n){let a={metadata:{namespace_:t,get allImports(){if(!this.imports)return[];let o=[];for(let c of Object.values(this.imports))o.push(...c);return o}},body:{}},s=new Map;for(let o of n){let c={};for(let m of o.statement){let[i,u]=this.convertStatementToProperty(m);i&&u!==null&&u!==void 0&&(c[i]=u),this.collectImportsFromStatement(m,t,s)}a.body[o.name]=c}return a}convertStatementToProperty(t){if(t instanceof R)return[t.predicate.subject.name,t.object];if(t instanceof T)return[t.predicate.subject.name,t.object];if(t instanceof M)return[t.predicate.subject.name,t.object];if(t instanceof D)return[t.predicate.subject.name,t.object.subject.name];if(t instanceof P){let n=this.convertKanonakListToValue(t.object);return[t.predicate.subject.name,n]}else if(t instanceof K){let n=this.convertEmbeddedKanonakToValue(t.object);return[t.predicate.subject.name,n]}return[null,null]}convertKanonakListToValue(t){let n=[];for(let r of t)r instanceof g?n.push(r.subject.name):r instanceof b&&n.push(this.convertEmbeddedKanonakToValue(r));return n}convertEmbeddedKanonakToValue(t){let n={};for(let r of t.statement){let[a,s]=this.convertStatementToProperty(r);a&&s!==null&&s!==void 0&&(n[a]=s)}return n}collectImportsFromStatement(t,n,r){}};function F(p,t){p.sourceDoc=t;for(let n of p.statement)if(n instanceof K)F(n.object,t);else if(n instanceof P)for(let r of n.object)r instanceof b&&F(r,t)}function $(p){let t=p.predicate?.subject;return(t?`${t.publisher}/${t.package_}/${t.name}`:"?")+"="+ue(p)}function ue(p){return p instanceof I?"m:"+String(p.object):p instanceof R?"s:"+String(p.object):p instanceof T?"n:"+String(p.object):p instanceof M?"b:"+String(p.object):p instanceof D?"r:"+C(p.object):p instanceof K?"e:"+C(p.object):p instanceof P?"l:["+(p.object??[]).map(C).join("|")+"]":"x"}function C(p){if(!p)return"";if(p instanceof g){let t=p.subject;return"R("+(t?`${t.publisher}/${t.package_}/${t.name}`:"")+")"}return p instanceof b?"E("+(p.statement??[]).map($).join(";")+")":p instanceof j?"L("+String(p.value)+")":"N"}export{b as a,j as b,I as c,ne as d,ae as e,oe as f,Ke as g,E as h,h as i,B as j,ve as k,V as l,re as m};
@@ -1 +0,0 @@
1
- import{B as q,c as B,d as G,m as S,n as X,t as Y,u as T,y as v,z as j}from"./chunk-CJMVIOZX.js";import{a as P}from"./chunk-FUUTGGJS.js";var W=class{cache=new Map;repository;logger;constructor(e,t){this.repository=e,this.logger=t}async resolveEntityAsync(e,t){let r=t.metadata?.namespace_?.toString()??"unknown",o=this.cache.get(r);if(o){let i=o.get(e);if(i)return i}let a=await this.buildEntityIndexAsyncInternal(t,new Set,"",new Map);return this.cache.set(r,a),a.get(e)??null}async resolveAllEntitiesAsync(e,t){let r=await this.buildAllEntitiesIndexAsync(t,new Set,"");if(e.includes(".")){let o=e.split("."),a=o[0],i=o[1],u=await this.findDocumentForAlias(t,a);return u?await this.resolveAllEntitiesAsync(i,u):[]}return r.filter(o=>o.entityName===e)}async buildAllEntitiesIndexAsync(e,t,r){let o=[],a=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${a}`),t.has(a))return this.logger?.debug?.(`Skipping ${a} - already visited (circular import prevention)`),o;t.add(a);let i=r.length===0?a:`${r} \u2192 ${a}`;for(let[u,c]of Object.entries(e.body))if(!u.includes(".")&&c&&typeof c=="object"&&!Array.isArray(c)){if(!e.metadata.namespace_)continue;let g=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};o.push({entityName:u,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,u,g),entity:c,definedInNamespace:a,isImported:r.length>0,importPath:i})}if(this.logger?.debug?.(`Collected ${o.length} entities from ${a}`),e.metadata?.imports){let u=Object.values(e.metadata.imports).reduce((c,g)=>c+g.length,0);this.logger?.debug?.(`Processing ${u} import(s) for ${a}`);for(let[c,g]of Object.entries(e.metadata.imports))for(let m of g)try{this.logger?.debug?.(`Resolving import: ${c}/${m.packageName}`);let d=await this.repository.getHighestCompatibleVersionAsync(c,m);if(d){this.logger?.debug?.(`Successfully loaded import: ${d.metadata?.namespace_?.toString()}`);let k=await this.buildAllEntitiesIndexAsync(d,t,i);o.push(...k),this.logger?.debug?.(`Added ${k.length} entities from import ${d.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${c}/${m.packageName}`)}catch(d){let k=d;throw this.logger?.error?.(`Failed to process import ${c}/${m.packageName} for namespace ${a}. Error: ${k.message}`,k),new Error(`Failed to process import ${c}/${m.packageName} for namespace ${a}. See inner exception for details.`,{cause:d})}}return o}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,t,r,o){let a=new Map,i=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${i}`),t.has(i))return this.logger?.debug?.(`Skipping ${i} - circular import in progress`),a;let u=o.get(i);if(u)return u;t.add(i);let c=r.length===0?i:`${r} \u2192 ${i}`,g=0;for(let[m,d]of Object.entries(e.body))if(!m.includes(".")&&d&&typeof d=="object"&&!Array.isArray(d)){if(!e.metadata.namespace_)continue;if(!a.has(m)){let k=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};a.set(m,{entityName:m,uri:new P(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,m,k),entity:d,definedInNamespace:i,isImported:r.length>0,importPath:c}),g++}}if(this.logger?.debug?.(`Indexed ${g} entities from ${i}`),e.metadata?.imports){let m=Object.values(e.metadata.imports).reduce((d,k)=>d+k.length,0);this.logger?.debug?.(`Processing ${m} import(s) for ${i}`);for(let[d,k]of Object.entries(e.metadata.imports))for(let K of k)try{this.logger?.debug?.(`Resolving import: ${d}/${K.packageName}`);let E=await this.repository.getHighestCompatibleVersionAsync(d,K);if(E){this.logger?.debug?.(`Successfully loaded import: ${E.metadata?.namespace_?.toString()}`);let U=await this.buildEntityIndexAsyncInternal(E,t,c,o),$=0;for(let[O,C]of U.entries()){let _=a.get(O);if(!_)a.set(O,C),$++;else if(_.isImported&&C.isImported&&(_.uri.publisher!==C.uri.publisher||_.uri.package_!==C.uri.package_)){let A=_.isAmbiguous?_:{..._,isAmbiguous:!0,ambiguousNamespaces:[_.definedInNamespace]};A.ambiguousNamespaces.includes(C.definedInNamespace)||A.ambiguousNamespaces.push(C.definedInNamespace),a.set(O,A),this.logger?.warn?.(`Ambiguous reference '${O}': defined in ${A.ambiguousNamespaces.join(", ")}`)}if(K.alias&&!O.includes(".")){let A=`${K.alias}.${O}`;a.has(A)||(a.set(A,C),$++)}}this.logger?.debug?.(`Merged ${$} entities from import ${E.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${d}/${K.packageName}`)}catch(E){let U=E;throw this.logger?.error?.(`Failed to process import ${d}/${K.packageName} for namespace ${i}. Error: ${U.message}`,U),new Error(`Failed to process import ${d}/${K.packageName} for namespace ${i}. See inner exception for details.`,{cause:E})}}return t.delete(i),o.set(i,a),a}async findDocumentForAlias(e,t){if(!e.metadata?.imports)return null;for(let[r,o]of Object.entries(e.metadata.imports))for(let a of o){if(a.alias===t)return await this.repository.getHighestCompatibleVersionAsync(r,a);if(!a.alias&&a.packageName===t)return await this.repository.getHighestCompatibleVersionAsync(r,a)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}};var z=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 n.isSubstitutableDatatypeUri(e)}static isSubstitutableDatatypeUri(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 r=await this.resourceResolver.resolveEntityAsync(e,t);if(r){let o=r.entity.type;if(o){let a=String(o);return a==="Class"||a==="rdfs.Class"||a.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 J(n){if(!n||n.trim().length===0)throw new Error("Kanonak address string cannot be null or empty");let e=n.trim(),t=e.split("/");if(t.length===1){let r=t[0];if(!r)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher, publisher/package[@version], or publisher/package[@version]/name.`);if(r.includes("@"))throw new Error(`Invalid Kanonak address: "${n}". A bare publisher cannot carry an @version qualifier \u2014 versions belong to packages.`);return{kind:"publisher",publisher:r}}if(t.length===2){let[r,o]=t;if(!r||!o)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher/package[@version].`);let a=o.indexOf("@");if(a===-1)return{kind:"package",publisher:r,package_:o};let i=o.substring(0,a),u=o.substring(a+1);if(!i||!u)throw new Error(`Invalid Kanonak address: "${n}". Expected publisher/package[@version].`);let c=re(u);return{kind:"package",publisher:r,package_:i,version:c}}return{kind:"resource",uri:P.parse(e)}}function Oe(n){switch(n.kind){case"publisher":return n.publisher;case"package":return n.version?`${n.publisher}/${n.package_}@${n.version.major}.${n.version.minor}.${n.version.patch}`:`${n.publisher}/${n.package_}`;case"resource":return n.uri.toString()}}function re(n){let e=n.split(".").map(Number);return oe(e[0]||0,e[1]||0,e[2]||0)}function oe(n,e,t){return{major:n,minor:e,patch:t,toString:()=>`${n}.${e}.${t}`,equals:r=>!r||typeof r!="object"?!1:r.major===n&&r.minor===e&&r.patch===t,getHashCode:()=>n<<20|e<<10|t,compareTo:r=>n!==r.major?n-r.major:e!==r.minor?e-r.minor:t-r.patch}}function Ne(n){return`${n.publisher}/${n.package_}/${n.name}`}function y(n,e,t){return`${n}/${e}/${t}`}function He(n){return`${n.s}|${n.p}|${ae(n.o)}`}function ae(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 Ie(n,e,t){return{s:n,p:e,o:{kind:"uri",key:t}}}var se="kanonak.org",ie="core-shacl",s=n=>({publisher:se,package_:ie,name:n}),N=s("Shape"),H=s("NodeShape"),I=s("PropertyShape"),$e=s("targetClass"),Te=s("property"),ve=s("path"),je=s("minCount"),we=s("maxCount"),Me=s("datatype"),Le=s("class"),Ve=s("in"),Fe=s("pattern"),Be=s("flags"),Ge=s("minLength"),Xe=s("maxLength"),Ye=s("minInclusive"),qe=s("maxInclusive"),We=s("message"),ze=s("targetNode"),Je=s("targetSubjectsOf"),Qe=s("targetObjectsOf"),Ze=s("closed"),et=s("ignoredProperties"),tt=s("nodeKind"),nt=s("IRI"),rt=s("BlankNode"),ot=s("Literal"),at=s("severity"),st=s("Violation"),it=s("Warning"),pt=s("Info"),ct=s("ValidationReport"),lt=s("conforms"),ut=s("result"),yt=s("ValidationResult"),dt=s("focusNode"),gt=s("resultPath"),mt=s("resultMessage"),ft=s("resultSeverity"),kt=s("sourceShape"),bt=s("value"),St=s("sourceConstraintComponent"),ht=s("MinCountConstraintComponent"),_t=s("MaxCountConstraintComponent"),Pt=s("DatatypeConstraintComponent"),Kt=s("ClassConstraintComponent"),Et=s("InConstraintComponent"),Ct=s("PatternConstraintComponent"),At=s("MinLengthConstraintComponent"),xt=s("MaxLengthConstraintComponent"),Rt=s("MinInclusiveConstraintComponent"),Ot=s("MaxInclusiveConstraintComponent"),Ut=s("NodeKindConstraintComponent"),Nt=s("ClosedConstraintComponent");var l="kanonak.org",p="core-rdf",f="core-owl",Z="core-kanonak",M=new Map([["type",p],["subClassOf",p],["subPropertyOf",p],["domain",p],["range",p],["label",p],["comment",p],["seeAlso",p],["isDefinedBy",p],["member",p],["Resource",p],["Class",p],["Property",p],["Datatype",p],["Literal",p],["List",p],["ObjectProperty",f],["DatatypeProperty",f],["AnnotationProperty",f],["Thing",f],["Nothing",f],["Package",Z]]),pe=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function $t(n){return M.has(n)}function Tt(n){let e=M.get(n);return e?{publisher:l,package_:e}:void 0}function L(n,e,t){if(!n||!n.name)return;let r=M.get(n.name);if(!r)return;let o=()=>{n.publisher=l,n.package_=r,t&&(n.version=t.get(r))};if(pe.has(n.name)){let a=n.publisher===l&&n.package_===r;n.publisher=l,n.package_=r,!a&&t&&(n.version=t.get(r));return}n.publisher===l&&n.package_===r||n.publisher&&n.publisher.length>0&&(!e||e(n))||o()}var Q=class{type=y(l,p,"type");subClassOf=y(l,p,"subClassOf");subPropertyOf=y(l,p,"subPropertyOf");domain=y(l,p,"domain");range=y(l,p,"range");label=y(l,p,"label");comment=y(l,p,"comment");resource=y(l,p,"Resource");class_=y(l,p,"Class");datatype=y(l,p,"Datatype");literal=y(l,p,"Literal");equivalentClass=y(l,f,"equivalentClass");equivalentProperty=y(l,f,"equivalentProperty");inverseOf=y(l,f,"inverseOf");sameAs=y(l,f,"sameAs");transitiveProperty=y(l,f,"TransitiveProperty");symmetricProperty=y(l,f,"SymmetricProperty");objectProperty=y(l,f,"ObjectProperty");datatypeProperty=y(l,f,"DatatypeProperty");annotationProperty=y(l,f,"AnnotationProperty");package_=y(l,Z,"Package");shape=w(N);nodeShape=w(H);propertyShape=w(I)};function w(n){return y(n.publisher,n.package_,n.name)}var ce=new Set(["kanonak.org/core-rdf","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);function b(n){let e=n;if(e.entity&&typeof e.entity=="object"){let t=e.entity.type;if(typeof t=="string"){let o={publisher:"",package_:"",name:t.includes(".")?t.substring(t.lastIndexOf(".")+1):t};return L(o),{publisher:o.publisher,package_:o.package_,name:o.name}}}if(e.statement&&Array.isArray(e.statement)){for(let t of e.statement)if(t.predicate?.subject?.name==="type"&&t.object?.subject){let r=t.object.subject,o={publisher:r.publisher??"",package_:r.package_??"",name:r.name};return L(o),{publisher:o.publisher,package_:o.package_,name:o.name}}}return null}var le=[N,H,I];function h(n,e){return ce.has(`${n}/${e}`)}var ue=new Set(["Property","ObjectProperty","DatatypeProperty","AnnotationProperty"]);function V(n){if(h(n.publisher,n.package_))return ue.has(n.name)?n.name:void 0}var ee=class n{static getTypeUri(e){return b(e)}static isCoreOntologyType(e){return h(e.publisher,e.package_)}static isClassType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="Class":!1}static isDatatypeType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="Datatype":!1}static isDatatypePropertyType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="DatatypeProperty":!1}static isObjectPropertyType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="ObjectProperty":!1}static isAnnotationPropertyType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="AnnotationProperty":!1}static isGenericPropertyType(e){let t=b(e);return t?h(t.publisher,t.package_)&&t.name==="Property":!1}static isAnyPropertyType(e){let t=b(e);return!t||!h(t.publisher,t.package_)?!1:t.name==="Property"||t.name==="DatatypeProperty"||t.name==="ObjectProperty"||t.name==="AnnotationProperty"}static isShapeType(e){let t=b(e);return t?le.some(r=>X(t,r)):!1}static isSchemaDefinitionType(e){if(n.isShapeType(e))return!0;let t=b(e);return!t||!h(t.publisher,t.package_)?!1:t.name==="Class"||t.name==="Property"||t.name==="DatatypeProperty"||t.name==="ObjectProperty"||t.name==="AnnotationProperty"||t.name==="Datatype"}static isInstanceOfKnownClass(e,t){if(n.isSchemaDefinitionType(e))return!1;let r=b(e);return r?t.has(r.name):!1}};var x="kanonak.org",R="core-rdf",ye={publisher:x,package_:R,name:"domain"},de={publisher:x,package_:R,name:"range"},ge={publisher:x,package_:R,name:"subClassOf"},me={publisher:x,package_:R,name:"type"},fe={publisher:x,package_:R,name:"label"},ke={publisher:x,package_:R,name:"comment"},be=new P(x,R,"Resource");function Se(n){try{let e=J(`${n.namespace}/${n.name}`);return e.kind==="resource"?e.uri:void 0}catch{return}}function F(n,e){let t=j(n,e);if(t)return[t];let r=[];for(let o of q(n,e))o instanceof G&&r.push(o.subject);return r}function ne(n,e){let t=[],r=new Set,o="version"in e?e.version:void 0,a=[new P(e.publisher,e.package_,e.name,o??void 0)];for(;a.length>0;){let i=a.shift(),u=S(i);if(r.has(u))continue;r.add(u),t.push(i);let c=he(n,i);c&&a.push(...F(c,ge))}return t}function he(n,e){return e.version&&typeof e.version.major=="number"?Y(n,e)??T(n,e)[0]:T(n,e)[0]}function D(n,e){let t;for(let r of Ee(e)){let o=_e(n,r);if(o){if(o!=="Property")return o;t??=o}}return t}function _e(n,e){let t=V(e);if(t)return t;let r=te.get(n);r||(r=new Map,te.set(n,r));let o=e.version,a=o&&typeof o.major=="number"?`${S(e)}@${o.major}.${o.minor}.${o.patch}`:S(e),i=r.get(a);if(i!==void 0)return i??void 0;let u;for(let c of ne(n,e)){let g=V(c);if(g){if(g!=="Property"){u=g;break}u??="Property"}}return r.set(a,u??null),u}var te=new WeakMap;function qt(n,e){return D(n,e)!==void 0}function Wt(n,e){return D(n,e)==="ObjectProperty"}function zt(n,e){return D(n,e)==="DatatypeProperty"}function Pe(n,e){let t=new Set([S(be)]);for(let r of ne(n,e))t.add(S(r));return t}function Ke(n,e){let t=Pe(n,e),r=[],o=new Set;for(let a of n){if(!(a instanceof B))continue;let i=D(n,a);if(!i)continue;let u=F(a,ye);if(!u.some(m=>t.has(S(m))))continue;let c=Se(a);if(!c)continue;let g=S(c);o.has(g)||(o.add(g),r.push({uri:c,label:v(a,fe),comment:v(a,ke),kind:i==="ObjectProperty"?"object":i==="DatatypeProperty"?"datatype":"other",range:j(a,de),domains:u}))}return r}function Jt(n,e,t){let r=Ke(n,e).find(o=>S(o.uri)===S(t));return r?{ok:!0,descriptor:r}:{ok:!1,message:`Property ${t.publisher}/${t.package_}/${t.name} is not in scope for ${e.publisher}/${e.package_}/${e.name}.`}}function Ee(n){return F(n,me)}export{W as a,z as b,J as c,Oe as d,Ne as e,y as f,He as g,ae as h,Ie as i,se as j,ie as k,N as l,H as m,I as n,$e as o,Te as p,ve as q,je as r,we as s,Me as t,Le as u,Ve as v,Fe as w,Be as x,Ge as y,Xe as z,Ye as A,qe as B,We as C,ze as D,Je as E,Qe as F,Ze as G,et as H,tt as I,nt as J,rt as K,ot as L,at as M,st as N,it as O,pt as P,ht as Q,_t as R,Pt as S,Kt as T,Et as U,Ct as V,At as W,xt as X,Rt as Y,Ot as Z,Ut as _,Nt as $,$t as aa,Tt as ba,L as ca,Q as da,V as ea,ee as fa,Se as ga,ne as ha,D as ia,qt as ja,Wt as ka,zt as la,Ke as ma,Jt as na,Ee as oa};