@kanonak-protocol/sdk 5.36.0 → 5.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +1 -1
- package/dist/chunk-22DSABP6.js +1 -0
- package/dist/chunk-7JBKOJB4.js +1 -0
- package/dist/{chunk-4QXD6HKI.js → chunk-A3HRXFVX.js} +1 -1
- package/dist/{chunk-VENZTHCC.js → chunk-ADSDFJUO.js} +1 -1
- package/dist/chunk-D2X6J77P.js +1 -0
- package/dist/chunk-D4QGPMRW.js +1 -0
- package/dist/chunk-DONOB6RA.js +1 -0
- package/dist/{chunk-IN5VVPYH.js → chunk-ED35OFGD.js} +1 -1
- package/dist/chunk-GKIX3OD6.js +3 -0
- package/dist/chunk-HKX27KBZ.js +1 -0
- package/dist/{chunk-H7SX57L7.js → chunk-LBVHWFFL.js} +1 -1
- package/dist/chunk-NUTHBBDZ.js +1 -0
- package/dist/{chunk-6TEJENCD.js → chunk-O6SOU5Y2.js} +10 -10
- package/dist/{chunk-BZ3YTI3C.js → chunk-OOYGILH4.js} +2 -2
- package/dist/chunk-TYVZXABI.js +155 -0
- package/dist/chunk-VORVR5BZ.js +1 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -1
- package/dist/kanonaks/DefinedKanonak.d.ts +11 -0
- package/dist/kanonaks/LiteralKanonak.d.ts +2 -0
- package/dist/kanonaks/ReferenceKanonak.d.ts +2 -0
- package/dist/lock/LockFile.d.ts +6 -0
- package/dist/lock/index.d.ts +1 -1
- package/dist/look/displayValue.d.ts +3 -0
- package/dist/look/index.d.ts +1 -1
- package/dist/parsing/findMarkdownLinkAt.d.ts +8 -0
- package/dist/parsing/index.d.ts +2 -0
- package/dist/parsing/index.js +1 -1
- package/dist/parsing/sourceSymbols.d.ts +54 -0
- package/dist/producer/index.js +1 -1
- package/dist/reasoning/KanonakVocabulary.d.ts +21 -0
- package/dist/reasoning/index.d.ts +1 -1
- package/dist/reasoning/index.js +1 -1
- package/dist/repositories/LockAwareRepository.d.ts +1 -1
- package/dist/repositories/browser.js +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/resolution/ResourceTypeClassifier.d.ts +8 -1
- package/dist/resolution/index.d.ts +1 -0
- package/dist/resolution/index.js +1 -1
- package/dist/resolution/referenceSpelling.d.ts +14 -0
- package/dist/search/index.js +1 -1
- package/dist/server/closure.d.ts +8 -0
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +16 -16
- package/dist/server/requestRouter.d.ts +16 -0
- package/dist/statements/Statement.d.ts +9 -0
- package/dist/transformations/index.js +2 -2
- package/dist/transformations/v3/CompiledTransformationV3.d.ts +28 -27
- package/dist/transformations/v3/TransformationUriConstantsV3.d.ts +27 -0
- package/dist/uri-helpers/index.js +1 -1
- package/dist/validation/KanonakObjectValidator.d.ts +7 -1
- package/dist/validation/index.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-7TU55KLO.js +0 -1
- package/dist/chunk-HF5FJBS2.js +0 -1
- package/dist/chunk-IS3AQKB4.js +0 -1
- package/dist/chunk-KIBR3HAT.js +0 -1
- package/dist/chunk-Q2FG7DME.js +0 -1
- package/dist/chunk-ROKDCCJN.js +0 -155
- package/dist/chunk-V3DH67P3.js +0 -1
- package/dist/chunk-XK24CN3C.js +0 -1
- package/dist/chunk-XNEWQEB6.js +0 -1
- package/dist/chunk-YBHIELES.js +0 -2
package/dist/server/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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-ROKDCCJN.js";import"../chunk-QHABFCRC.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{j as oe}from"../chunk-Q2FG7DME.js";import{a as O}from"../chunk-HF5FJBS2.js";import{a as xe}from"../chunk-PEJALHXK.js";import"../chunk-7TU55KLO.js";import{A as re,c as we,p as Re}from"../chunk-XNEWQEB6.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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}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
|
-
`),t=
|
|
3
|
-
`),a=
|
|
4
|
-
`),u=
|
|
5
|
-
`),y=
|
|
1
|
+
import{c as Pe}from"../chunk-DONOB6RA.js";import{a as be,d as Z,f as Se,h as re}from"../chunk-HKX27KBZ.js";import{e as ve,g as $e,n as U,o as ee}from"../chunk-OOYGILH4.js";import"../chunk-D2X6J77P.js";import"../chunk-SC5M74NM.js";import{a as H,b as q}from"../chunk-VORVR5BZ.js";import{t as ne}from"../chunk-TYVZXABI.js";import"../chunk-QHABFCRC.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{k as te}from"../chunk-22DSABP6.js";import{a as O}from"../chunk-7JBKOJB4.js";import{a as _e}from"../chunk-PEJALHXK.js";import"../chunk-NUTHBBDZ.js";import{A as oe,c as we,p as xe}from"../chunk-D4QGPMRW.js";import{a as Re}from"../chunk-FUUTGGJS.js";import"../chunk-F67UH4FD.js";import{c as V,e as j,f as W,g as Q}from"../chunk-QILEJIFU.js";import{readFileSync as pe,writeFileSync as Me,mkdirSync as Ee}from"fs";import{join as ae}from"path";import De from"js-yaml";var je=[{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 G(r){return je}function N(r){return`${r.publisher}/${r.package_}`}function z(r,e=[]){let i={"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"},o=[];for(let t of r)if(t.origin==="missing"){let a=N(t),u=i[a]??"whatever this package contributes to rendering is lost";o.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&&o.push(`Render-stack package ${N(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)o.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 o}function se(r){let{publisher:e,availablePublishers:i,catalog:o,lookRenderer:t,localNamespaces:a,rawByNsKey:u,renderStack:d,producers:k,lockSource:y,configSource:s}=r,l=new Map,f=new Map,p=new Map,m=new Set;for(let S of o){if(!(S instanceof we))continue;let w=S.namespace||"";if(!a.has(w))continue;l.set(`${w}/${S.name}`,S);let _=w.split("/")[1]??"",[P,E]=_.split("@");if(!P||!E)continue;let D=Q(E);D&&(m.has(_)||(m.add(_),f.has(P)||f.set(P,[]),f.get(P).push({verStr:E,version:D})),S.name===P&&p.set(_,S))}for(let S of f.values())S.sort((w,_)=>V(_.version,w.version));return{publisher:e,availablePublishers:i,catalog:o,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 ue(r,e={}){let i=new O,o=new ye(i),t=[],a=[];for(let c of re(r)){let h;try{h=pe(c,"utf-8")}catch{continue}let n;try{n=i.parse(h).metadata?.namespace_}catch{continue}if(!n?.version)continue;let g=n.version;a.push({publisher:n.publisher,package_:n.package_,verStr:j(g),version:g,source:h})}a.sort((c,h)=>V(h.version,c.version));for(let c of a)await o.saveDocumentAsync(i.parse(c.source),`${c.publisher}/${c.package_}@${c.verStr}`),t.push({publisher:c.publisher,package_:c.package_,verStr:c.verStr,source:c.source});let u=[...new Set(t.map(c=>c.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 ${r}`):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 c of t)c.publisher===d&&(k.add(`${c.publisher}/${c.package_}@${c.verStr}`),y.set(`${c.package_}@${c.verStr}`,c.source));let s=Z(),l=new be(s,!0,i),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(o,l,new ee(f)),m=e.log??(()=>{}),S=G(void 0),w=[],_=c=>c.map(h=>h.metadata.namespace_?.version).filter(h=>h!==void 0).sort((h,n)=>V(n,h)).map(j);if(!e.repository){m(`[render-stack] resolving ${S.length} ambient look-stack package(s); cache: ${s}`);let c=e.fetchFn?new U({fetchFn:e.fetchFn}):new U;for(let h of S){let n=N(h),g=await o.getDocumentsByNamespaceAsync(h.publisher,h.package_);if(g.length>0){let v=_(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=_(b);w.push({...h,origin:"cache",versions:v}),m(`[render-stack] ${n} \u2014 cache (${v.join(", ")})`);continue}try{let $=(await c.getLock(h.publisher))?.packages[`${h.publisher}/${h.package_}`];if(!$){let C=`publisher ${h.publisher} reachable but its lock does not pin ${h.package_}`;w.push({...h,origin:"missing",reason:C}),m(`[render-stack] ${n} \u2014 MISSING: ${C}`);continue}let F=$.version,T=$.resolved,X=await(e.fetchFn?e.fetchFn(T,h.publisher):ve(T));if(!X.ok){let C=`fetch ${T} failed: HTTP ${X.status} ${X.statusText}`;w.push({...h,origin:"missing",reason:C}),m(`[render-stack] ${n} \u2014 MISSING: ${C}`);continue}let ke=await X.text();await o.saveDocumentAsync(i.parse(ke),`${h.publisher}/${h.package_}@${F}`);try{let C=ae(s,h.publisher);Ee(C,{recursive:!0}),Me(ae(C,`${h.package_}@${F}.kan.yml`),ke,"utf-8"),w.push({...h,origin:"fetched",versions:[F]}),m(`[render-stack] ${n}@${F} \u2014 fetched from ${T}, installed to cache`)}catch(C){w.push({...h,origin:"fetched",versions:[F]}),m(`[render-stack] ${n}@${F} \u2014 fetched from ${T}, but cache ${s} is NOT WRITABLE (${C.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 P=(await o.getAllDocumentsAsync()).filter(c=>c.metadata.namespace_?.publisher===d);for(let c of S)P.push(...await p.getDocumentsByNamespaceAsync(c.publisher,c.package_));let E=[],D=await H(P,p,{onUnresolvedEdge:c=>E.push(c)}),A=p;if(!e.repository){for(let c of S)D.add(N(c));A=new q(p,D)}let B=await new te(i).parseKanonaks(A),le=new ne(B),de=(c,h)=>oe(B,{publisher:c,package_:h,name:h}).length>0,I;if(e.repository){I=[];for(let c of S){let h=await p.getDocumentsByNamespaceAsync(c.publisher,c.package_);I.push(h.length>0?{...c,origin:"repository",versions:_(h)}:{...c,origin:"missing",reason:"not present in the caller-supplied repository"})}}else I=w.map(c=>c.origin==="missing"||de(c.publisher,c.package_)?c:{...c,resolvedButNotInCatalog:!0});let Y=z(I,E);for(let c of Y)m(`[render-stack] WARNING: ${c}`);let J={contractSource:"universal-default",cachePath:s,packages:I,warnings:Y},K;try{K=pe(ae(r,"kanonak.lock"),"utf-8")}catch{K=Ke(d,t,i)}let L;try{L=pe(ae(r,".well-known","kanonak.json"),"utf-8")}catch{L=void 0}return se({publisher:d,availablePublishers:u,catalog:B,lookRenderer:le,localNamespaces:k,rawByNsKey:y,renderStack:J,...K?{lockSource:K}:{},...L?{configSource:L}:{}})}function Ke(r,e,i){let o=new Map;for(let a of e)a.publisher===r&&(o.has(a.package_)||o.set(a.package_,{verStr:a.verStr,source:a.source}));if(o.size===0)return;let t={};for(let a of[...o.keys()].sort()){let{verStr:u,source:d}=o.get(a),k={},y;try{y=i.parse(d).metadata?.imports}catch{y=void 0}for(let l of y?.[r]??[]){let f=o.get(l.packageName);f&&(k[`${r}/${l.packageName}`]=f.verStr)}let s={};for(let l of Object.keys(k).sort())s[l]=k[l];t[`${r}/${a}`]={version:u,resolved:`https://${r}/${a}/${u}.kan.yml`,integrity:Pe(d),dependencies:s}}return De.dump({version:"1",lastUpdated:"",packages:t},{lineWidth:-1,sortKeys:!1,quotingType:'"'})}import{existsSync as Ve,readFileSync as Ae,writeFileSync as Be,mkdirSync as Le}from"fs";import{join as Ce}from"path";async function ge(r,e={}){let i=new O,o=xe(r),t=o.kind==="resource"?o.uri.publisher:o.publisher,a=e.log??(()=>{}),u=e.cacheRoot??Z(),d=(n,g,b)=>Ce(u,n,`${g}@${b}.kan.yml`),k=new Set,y=new Set,s=new Map,l=new ee({getFromCache:(n,g,b)=>{let v=d(n,g,b),$=Ve(v)?Ae(v,"utf-8"):null;return $!==null&&k.add(`${n}/${g}`),$},onFetch:(n,g,b,v)=>{y.add(`${n}/${g}`);try{let $=Ce(u,n);Le($,{recursive:!0}),Be(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(o.kind==="resource"){let n=o.uri.version;p=[n?{package_:o.uri.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:o.uri.package_}]}else if(o.kind==="package"){let n=o.version;p=[n?{package_:o.package_,version:`${n.major}.${n.minor}.${n.patch}`}:{package_:o.package_}]}else p=((await f.getConfig(t)).featured_packages??[]).map(g=>({package_:g}));let m=async(n,g,b)=>{try{let v=b?i.buildImport(g,"=",b,n):i.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 "${r}" from publisher "${t}".`+(w.length>0?` Reasons: ${w.join("; ")}`:""));let _=G(),P="universal-default",E=n=>n.map(g=>g.metadata.namespace_?.version).filter(g=>g!==void 0).sort((g,b)=>V(b,g)).map(j);a(`[render-stack] resolving ${_.length} ambient look-stack package(s) (contract: ${P}); cache: ${u}`);let D=[],A=[];for(let n of _){let g=N(n),{doc:b,error:v}=await m(n.publisher,n.package_,void 0);if(b){D.push(b);let $=E([b]),F=y.has(g)?"fetched":k.has(g)?"cache":"fetched";A.push({...n,origin:F,versions:$}),a(`[render-stack] ${g} \u2014 ${F} (${$.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=[],le=await H([...S,...D],l,{onUnresolvedEdge:n=>B.push(n)}),de=new q(l,le),I=await new te(i).parseKanonaks(de),Y=new ne(I),J=A.map(n=>n.origin==="missing"||oe(I,{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:P,cachePath:u,packages:J,warnings:K},c=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=j(g.version),v=`${g.publisher}/${g.package_}@${b}`;c.add(v);let $=await l.getDocumentContentAsync(v);$!==null&&h.set(`${g.package_}@${b}`,$)}return se({publisher:t,availablePublishers:[t],catalog:I,lookRenderer:Y,localNamespaces:c,rawByNsKey:h,renderStack:L})}import{VersionOperator as ce}from"@kanonak-protocol/types/document/models/enums";function ie(r){let{lookRenderer:e,publisher:i,renderStack:o,catalog:t}=r,a=e.explainStylesheet(e.publisherSubject(i)),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:i,renderStack:{contractSource:o.contractSource,cachePath:o.cachePath,packages:o.packages.map(p=>({package_:N(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:[...o.warnings,...a.warnings.filter(p=>!o.warnings.includes(p)),...f]}}function Oe(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function he(r){let e=Oe,i=r.warnings.length===0,o=r.expressionCarriers.map(s=>`<tr><td><code>${e(s.carrier)}</code></td><td>${e(s.reason)}</td></tr>`).join(`
|
|
2
|
+
`),t=r.warnings.length===0?'<p class="ok">\u2713 No problems detected \u2014 the render stack is fully resolved and pages should be styled.</p>':r.warnings.map(s=>`<div class="warn">\u26A0 ${e(s)}</div>`).join(`
|
|
3
|
+
`),a=r.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
|
+
`),u=r.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=r.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(`
|
|
5
|
+
`),y=r.catalog.map(s=>`<tr><td><code>${e(s.namespace)}</code></td><td>${s.resources}</td></tr>`).join(`
|
|
6
6
|
`);return`<!doctype html>
|
|
7
7
|
<html lang="en">
|
|
8
8
|
<head>
|
|
9
9
|
<meta charset="utf-8">
|
|
10
10
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
11
|
-
<title>Render diagnostics \u2014 ${e(
|
|
11
|
+
<title>Render diagnostics \u2014 ${e(r.publisher)}</title>
|
|
12
12
|
<style>
|
|
13
13
|
body { font-family: system-ui, sans-serif; max-width: 64rem; margin: 2rem auto; padding: 0 1rem; line-height: 1.5; color: #1a1a1a; background: #fff; }
|
|
14
14
|
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; margin-top: 2rem; border-bottom: 1px solid #ddd; padding-bottom: .25rem; }
|
|
@@ -22,12 +22,12 @@ import{c as Pe}from"../chunk-V3DH67P3.js";import{a as be,d as X,f as Se,h as ee}
|
|
|
22
22
|
.row-bad td { background: #fff5f5; }
|
|
23
23
|
.meta { color: #666; font-size: .85rem; }
|
|
24
24
|
.status-banner { font-size: 1.1rem; padding: .5rem 1rem; border-radius: 6px; display: inline-block; margin-bottom: 1rem;
|
|
25
|
-
background: ${
|
|
25
|
+
background: ${i?"#ecfdf3":"#fef2f2"}; border: 1px solid ${i?"#0a7d33":"#b91c1c"}; }
|
|
26
26
|
</style>
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
|
29
|
-
<h1>Render diagnostics \u2014 ${e(
|
|
30
|
-
<p class="status-banner">${
|
|
29
|
+
<h1>Render diagnostics \u2014 ${e(r.publisher)}</h1>
|
|
30
|
+
<p class="status-banner">${i?"\u2713 Healthy":`\u2717 ${r.warnings.length} problem(s) found`}</p>
|
|
31
31
|
<p class="meta">Machine-readable version: <a href="/.well-known/kanonak-render.json"><code>/.well-known/kanonak-render.json</code></a></p>
|
|
32
32
|
|
|
33
33
|
<h2>Problems</h2>
|
|
@@ -35,7 +35,7 @@ ${t}
|
|
|
35
35
|
|
|
36
36
|
<h2>Ambient render stack</h2>
|
|
37
37
|
<p class="meta">The look stack is discovered, not imported \u2014 these packages must be resolvable for any publisher's pages to render styled.
|
|
38
|
-
Contract: <code>${e(
|
|
38
|
+
Contract: <code>${e(r.renderStack.contractSource)}</code> \xB7 Package cache: <code>${e(r.renderStack.cachePath)}</code></p>
|
|
39
39
|
<table>
|
|
40
40
|
<tr><th>Package</th><th>Origin</th><th>Versions / reason</th></tr>
|
|
41
41
|
${a}
|
|
@@ -47,26 +47,26 @@ ${d}
|
|
|
47
47
|
|
|
48
48
|
<h2>Design tokens (:root)</h2>
|
|
49
49
|
<p class="meta">Resolved for the publisher landing page. Each token shows which resource in the cascade supplied it.</p>
|
|
50
|
-
${
|
|
50
|
+
${r.stylesheet.tokens.length===0?'<p><span class="bad">\u2717 No tokens resolved</span></p>':`<table>
|
|
51
51
|
<tr><th>Token</th><th>Value</th><th>Declared by</th><th>Cascade level</th></tr>
|
|
52
52
|
${k}
|
|
53
53
|
</table>`}
|
|
54
54
|
|
|
55
55
|
<h2>Look (page body)</h2>
|
|
56
|
-
${
|
|
56
|
+
${r.stylesheet.look?`<p><span class="good">\u2713</span> Bands resolve from <code>${e(r.stylesheet.look.sourceClass)}</code></p>`:'<p><span class="bad">\u2717 No look resolved</span> \u2014 the page body renders as an empty comment.</p>'}
|
|
57
57
|
|
|
58
58
|
<h2>Expression carriers</h2>
|
|
59
59
|
<p class="meta">Authored <code>tx.Expression</code> carriers (band paths, <code>semanticSvg</code> tiers) that failed to compile while rendering this page. A carrier that does not compile contributes nothing to the output.</p>
|
|
60
|
-
${
|
|
60
|
+
${r.expressionCarriers.length===0?'<p><span class="good">\u2713</span> Every expression carrier on this page compiled.</p>':`<table>
|
|
61
61
|
<tr><th>Carrier</th><th>Reason</th></tr>
|
|
62
|
-
${
|
|
62
|
+
${o}
|
|
63
63
|
</table>`}
|
|
64
64
|
|
|
65
|
-
<h2>Render catalog (${
|
|
65
|
+
<h2>Render catalog (${r.catalog.length} package version(s))</h2>
|
|
66
66
|
<p class="meta">Everything the renderer can see for this publisher \u2014 the served packages, their import closure, and the ambient render stack.</p>
|
|
67
67
|
<table>
|
|
68
68
|
<tr><th>Package version</th><th>Resources</th></tr>
|
|
69
69
|
${y}
|
|
70
70
|
</table>
|
|
71
71
|
</body>
|
|
72
|
-
</html>`}var R={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},x=(
|
|
72
|
+
</html>`}var R={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},x=(r,e,i,o)=>({status:r,headers:{"Content-Type":e,...o||{}},body:i}),M=r=>x(404,R[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${r}</p>`),Te=r=>({status:301,headers:{Location:r},body:""}),We=r=>({status:302,headers:{Location:r},body:""});function Ue(r){switch(r.kind){case"exact":return{operator:ce.Exact,version:W(r.major,r.minor,r.patch)};case"minor-pin":return{operator:ce.Compatible,version:W(r.major,r.minor,0)};case"major-pin":return{operator:ce.Major,version:W(r.major,0,0)};default:return{operator:ce.Any,version:W(0,0,0)}}}async function He(r,e,i,o){if(!o)return null;let t=r.producers?.find(k=>k.canProduce(r.publisher,e));if(!t)return null;let a=await t.resolveVersion(r.publisher,e,Ue(i));if(!a)return null;let u=j(a);if(i.kind!=="exact")return We(`/${e}/${u}.kan.yml`);let{source:d}=await t.produce(r.publisher,e,a);return x(200,R[".kan.yml"],d)}function Ne(r,e,i){let o=r.pkgVersions.get(e);if(!o||o.length===0)return null;switch(i.kind){case"any":return o[0].verStr;case"major-pin":return o.find(t=>t.version.major===i.major)?.verStr??null;case"minor-pin":return o.find(t=>t.version.major===i.major&&t.version.minor===i.minor)?.verStr??null;case"exact":return o.find(t=>t.version.major===i.major&&t.version.minor===i.minor&&t.version.patch===i.patch)?.verStr??null;default:return null}}async function me(r,e,i=""){let{lookRenderer:o,publisher:t}=r;if(e==="/.well-known/kanonak.json")return r.configSource?x(200,R[".json"],r.configSource):x(200,R[".json"],JSON.stringify($e(),null,2));if(e==="/kanonak.lock")return r.lockSource?x(200,R[".kan.yml"],r.lockSource):M(e);if(e==="/.well-known/kanonak-render.json")return x(200,R[".json"],JSON.stringify(ie(r),null,2));if(e==="/.well-known/kanonak-render")return x(200,R[".html"],he(ie(r)));if(e==="/"||e==="/index.html"||e==="/index.css"){let l=o.publisherSubject(t);return e==="/index.css"?x(200,R[".css"],o.renderStylesheet(l)):x(200,R[".html"],await o.renderDocument(l,{rootIndex:!0}))}let a=".html",u=!1,d=e;for(let l of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(l)){a=l,u=!0,d=e.slice(0,-l.length);break}let k=!u&&/application\/yaml|text\/yaml/i.test(i),y=d.endsWith("/");y&&d!=="/"&&(d=d.slice(0,-1));let s=_e.parse(d,t);if(!s)return M(e);if(s.kind==="package"){let l=Ne(r,s.package_,s.versionSpec);if(!l)return await He(r,s.package_,s.versionSpec,a===".kan.yml"||k)??M(e);if(a===".kan.yml"||k){let m=r.rawByNsKey.get(`${s.package_}@${l}`);return m!==void 0?x(200,R[".kan.yml"],m):M(e)}let f=r.pkgSelfByVer.get(`${s.package_}@${l}`);if(!f)return M(e);if(a===".css")return x(200,R[".css"],o.renderStylesheet(f));if(!y)return Te(d+"/");let p=s.versionSpec.kind==="any";if(p&&!o.hasDeclaredView(f)){let m=(r.pkgVersions.get(s.package_)||[]).map(S=>S.verStr);return x(200,R[".html"],o.renderPackageVersionList(s.package_,m,f))}return x(200,R[".html"],await o.renderDocument(f,p?{bareOverview:!0}:void 0))}if(s.kind==="resource"){let l=Ne(r,s.package_,s.versionSpec);if(!l)return M(e);let f=r.bySubject.get(`${t}/${s.package_}@${l}/${s.name}`);if(!f)return M(e);switch(a){case".css":return x(200,R[".css"],o.renderStylesheet(f));case".svg":return x(200,R[".svg"],await o.renderSvg(f));case".md":{let p=o.renderRawMarkdown(f);return p===void 0?M(e):x(200,R[".md"],p)}default:return x(200,R[".html"],await o.renderDocument(f))}}return M(e)}import{readFileSync as qe}from"fs";var Ie=/^\d+\.\d+\.\d+$/,fe=class{constructor(e={}){this.options=e}options;models=new Map;workspaceIndex;clearCache(){this.models.clear(),this.workspaceIndex=void 0}getWorkspaceIndex(){if(this.workspaceIndex)return this.workspaceIndex;let e=new Set,i=new Set;if(this.options.root!==void 0){let o=new O;for(let t of re(this.options.root))try{let a=o.parse(qe(t,"utf-8")).metadata?.namespace_;if(!a?.version)continue;let u=a.version;e.add(`${a.publisher}/${a.package_}@${u.major}.${u.minor}.${u.patch}`),i.add(`${a.publisher}/${a.package_}`)}catch{}}return this.workspaceIndex={exact:e,pkgs:i},this.workspaceIndex}async modelFor(e,i,o){let t=this.getWorkspaceIndex(),a={...this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},...this.options.log?{log:this.options.log}:{}},u=i?o?t.exact.has(`${e}/${i}@${o}`):t.pkgs.has(`${e}/${i}`):[...t.pkgs].some(l=>l.startsWith(`${e}/`)),d,k;if(u&&this.options.root!==void 0){let l=this.options.root;d=`ws:${e}`,k=()=>ue(l,{publisher:e,...this.options.log?{log:this.options.log}:{}})}else{let l=i?o?`${e}/${i}@${o}`:`${e}/${i}`:e;d=`rm:${l}`,k=()=>ge(l,a)}let y=this.models.get(d);if(y)return y;let s=await k();return s.lookRenderer.setLinkMode("open-world"),this.models.set(d,s),s}async handle(e,i=""){let o=e.split("/").filter(Boolean);if(o.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:Fe()};let t=o[0];if(!t.includes("."))return{status:404,headers:{"Content-Type":"text/html; charset=utf-8"},body:"<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Expected a publisher domain as the first path segment: <code>/{publisher}/{package}/{version}/{resource}</code></p>"};let a=o.length>=2&&(o[1]==="index.html"||o[1]==="index.css"||o[1]==="kanonak.lock"||o[1]===".well-known"),u=!a&&o.length>=2?o[1]:void 0,d=!a&&o.length>=3&&Ie.test(o[2])?o[2]:void 0,k=await this.modelFor(t,u,d),y=e.endsWith("/")&&o.length>1?"/":"",s="/"+o.slice(1).join("/")+y,l=await me(k,s,i);return l.headers.Location?{...l,headers:{...l.headers,Location:`/${t}${l.headers.Location}`}}:l}};function Ge(r){switch(r.kind){case"publisher":return`/${r.publisher}/`;case"package":return r.version?`/${r.publisher}/${r.package_}/${j(r.version)}/`:`/${r.publisher}/${r.package_}/`;case"resource":{let e=r.uri;return e.version?`/${e.publisher}/${e.package_}/${j(e.version)}/${e.name}`:`/${e.publisher}/${e.package_}/${e.name}`}}}function ze(r){let e=r.split("/").filter(Boolean),i=e[0];if(!i||!i.includes("."))return;let o=e[1];if(!o)return{kind:"publisher",publisher:i};let t=e[2]&&Ie.test(e[2])?Q(e[2])??void 0:void 0,a=t?e[3]:e[2];return a?{kind:"resource",uri:new Re(i,o,a,t)}:t?{kind:"package",publisher:i,package_:o,version:t}:{kind:"package",publisher:i,package_:o}}function Fe(){return'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Kanonak origin</title></head><body style="font-family:system-ui;max-width:40rem;margin:4rem auto;padding:0 1rem"><h1>Kanonak request-driven origin</h1><p>Open a resource by its address:</p><p><code>/{publisher}/{package}/{version}/{resource}</code></p><p>e.g. <code>/kanonak.org/capabilities/2.0.0/Capability</code></p></body></html>'}export{q as ClosureScopedRepository,fe as RequestRouter,je as UNIVERSAL_RENDER_BASE,ze as addressForRequestPath,ie as buildRenderDiagnostics,z as buildRenderStackWarnings,H as deriveImportClosure,Fe as landingPage,ge as loadResourceModel,ue as loadServerModel,he as renderDiagnosticsHtml,N as renderRefKey,Ge as requestPathFor,G as resolveRenderContract,me as route};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ServerModel, RouteResponse } from './types.js';
|
|
2
2
|
import type { AuthenticatedFetchFn } from '../auth/index.js';
|
|
3
|
+
import type { KanonakAddress } from '../resolution/KanonakAddress.js';
|
|
3
4
|
export interface RequestRouterOptions {
|
|
4
5
|
/**
|
|
5
6
|
* Workspace root, for publishers that are LOCAL (served from disk with live
|
|
@@ -65,5 +66,20 @@ export declare class RequestRouter {
|
|
|
65
66
|
*/
|
|
66
67
|
handle(pathname: string, accept?: string): Promise<RouteResponse>;
|
|
67
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* The path the router serves for a Kanonak address. Publisher-first, so the
|
|
71
|
+
* router derives the publisher from the path: `/{publisher}/`,
|
|
72
|
+
* `/{publisher}/{package}/[{version}/]`, `/{publisher}/{package}/[{version}/]{name}`.
|
|
73
|
+
* A resource's other renderings append their extension (`.svg`, `.md`). THE
|
|
74
|
+
* one mapping for every client of the router; {@link addressForRequestPath}
|
|
75
|
+
* is its inverse.
|
|
76
|
+
*/
|
|
77
|
+
export declare function requestPathFor(address: KanonakAddress): string;
|
|
78
|
+
/**
|
|
79
|
+
* The Kanonak address a router path names — the inverse of
|
|
80
|
+
* {@link requestPathFor}. Undefined for a path that names no address: the
|
|
81
|
+
* root, or a first segment that is not a publisher domain.
|
|
82
|
+
*/
|
|
83
|
+
export declare function addressForRequestPath(pathname: string): KanonakAddress | undefined;
|
|
68
84
|
/** Minimal landing for the request-driven root, which has no single publisher. */
|
|
69
85
|
export declare function landingPage(): string;
|
|
@@ -3,4 +3,13 @@ import type { ReferenceKanonak } from '../kanonaks/ReferenceKanonak.js';
|
|
|
3
3
|
export declare abstract class Statement<TObject> implements IStatement {
|
|
4
4
|
predicate: ReferenceKanonak;
|
|
5
5
|
object: TObject;
|
|
6
|
+
/**
|
|
7
|
+
* The property key exactly as the document authored it (`subClassOf`,
|
|
8
|
+
* `rdfs.subClassOf`, `look.nav`) — the segment of the authored YAML path at
|
|
9
|
+
* which this statement sits. Set by the parser on every statement it builds
|
|
10
|
+
* from source; absent on a statement it synthesized. A parse-time fact, not
|
|
11
|
+
* part of the graph: it changes no content hash or serialization. Read by
|
|
12
|
+
* `sourceSymbols` to tie the object model back to source positions.
|
|
13
|
+
*/
|
|
14
|
+
sourceKey?: string;
|
|
6
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as pe}from"../chunk-
|
|
1
|
+
import{a as pe}from"../chunk-ED35OFGD.js";import"../chunk-GKIX3OD6.js";import{a as ve,b as M,c as Vn,n as X,o as Rn,p as vn,q as le,r as q,t as G}from"../chunk-TYVZXABI.js";import"../chunk-QHABFCRC.js";import"../chunk-6VIUXP4N.js";import{b as $n,c as Tn,d as Bn,e as xn,f as Un,k as fe}from"../chunk-22DSABP6.js";import{a as se}from"../chunk-7JBKOJB4.js";import"../chunk-PEJALHXK.js";import{c as U}from"../chunk-NUTHBBDZ.js";import{b as Y,c as D,d as ce,e as E,f as ue,i as $,j as T,k as B,l as w,m as me,n as x,o as de,s as N,t as S,z as A}from"../chunk-D4QGPMRW.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(`
|
|
@@ -88,4 +88,4 @@ ${e.rawContent}
|
|
|
88
88
|
`)&&(o+=`
|
|
89
89
|
`),o}};function C(e,n){return e.publisher===n.publisher&&e.package_===n.package_&&e.name===n.name}var K=class{backendUri="kanonak.org/transformations/dynamodb-json";render(n,t){if(!n.metadata)throw new Error("dynamodb-json backend: Document has no `metadata` channel. This backend serializes Document.metadata into DynamoDB attribute-value JSON \u2014 the transformation must populate that channel. (No silent empty artifact.)");let r=Ae(n.metadata,t),o=JSON.stringify(r,null,2);return t?.trailingNewline&&!o.endsWith(`
|
|
90
90
|
`)&&(o+=`
|
|
91
|
-
`),o}};function Ae(e,n){let t=new Map;for(let a of e.entries)t.set(a.key,a);let r=n?.metadataKeys??e.entries.map(a=>a.key),o={};for(let a of r){let s=t.get(a);if(!s)continue;let c=n?.metadataRenames.get(a)??a;o[c]=je(s.value,s.escapeHint)}return{M:o}}function je(e,n){switch(e.kind){case"StructuredMap":return Ae(e);case"StructuredList":return{L:e.items.map(t=>je(t,void 0))};case"StringScalar":return dn(e.stringValue,n??e.escapeHint);case"IntegerScalar":return fn(e.integerValue,n??e.escapeHint)}}function dn(e,n){if(n&&C(n,m.ESC_DYNAMODB_BOOL)){if(e==="true")return{BOOL:!0};if(e==="false")return{BOOL:!1};throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-bool must have the value "true" or "false"; got ${JSON.stringify(e)}.`)}if(n&&C(n,m.ESC_DYNAMODB_NULL))return{NULL:!0};if(n&&C(n,m.ESC_DYNAMODB_NUMBER)){if(e.trim()===""||Number.isNaN(Number(e)))throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-number must hold a numeric literal; got ${JSON.stringify(e)}.`);return{N:e}}return{S:e}}function fn(e,n){if(n&&C(n,m.ESC_DYNAMODB_BOOL))throw new Error(`dynamodb-json backend: esc-dynamodb-bool cannot apply to an IntegerScalar (value ${e}). Use a StringScalar "true"/"false".`);if(n&&C(n,m.ESC_DYNAMODB_NULL))throw new Error(`dynamodb-json backend: esc-dynamodb-null cannot apply to an IntegerScalar (value ${e}). Use a StringScalar hinted esc-dynamodb-null.`);return{N:String(e)}}var ln={"markdown-with-frontmatter":{formatUri:"kanonak.org/transformations/markdown-with-frontmatter",extension:".md"},"plain-markdown":{formatUri:"kanonak.org/transformations/plain-markdown",extension:".md"},toml:{formatUri:"kanonak.org/transformations/toml",extension:".toml"},json:{formatUri:"kanonak.org/transformations/json",extension:".json"},html:{formatUri:"kanonak.org/transformations/html",extension:".html"},svg:{formatUri:"kanonak.org/transformations/svg",extension:".svg"},stylesheet:{formatUri:"kanonak.org/transformations/stylesheet",extension:".css"},yaml:{formatUri:"kanonak.org/transformations/yaml",extension:".yaml"},"dynamodb-json":{formatUri:"kanonak.org/transformations/dynamodb-json",extension:".json"}},h=class extends Error{},H=class{backends=new Map;constructor(){this.register(new V),this.register(new R),this.register(new v),this.register(new L),this.register(new O),this.register(new I),this.register(new _),this.register(new K)}register(n){this.backends.set(n.backendUri,n)}async run(n){let t=n.transformationKanonaks??n.allKanonaks,r=M(n.transformation,t);if(!r.outputs.has(n.outputFormat))throw new h(`Transformation "${r.name}" does not declare output format "${n.outputFormat}". Declared: ${Array.from(r.outputs).join(", ")}`);let o=this.findBackend(n.outputFormat);if(!o)throw new h(`No backend registered for OutputFormat "${n.outputFormat}".`);let a=new q(n.repository,n.parser,n.objectParser),s=new le(a,n.allKanonaks,r.fragments);return r.kind==="instance"?this.runInstance(r,n,o,s):this.runSet(r,n,o,s)}async runInstance(n,t,r,o){let a=Ee(t.instances,n.inputPattern.requires),s=$e(a,n.inputPattern.sortBy),c=[];for(let u of s){let f=new Map;f.set("input",u);let l=await o.evaluate(n.rule,f);ee(l,n.name,`input "${u.name}"`);let d=ne(await o.evaluate(n.artifactName,f),n.name,`input "${u.name}"`),g=te(n.overrides.get(t.outputFormat),t.runtimeOverride),k=r.render(l,g);c.push({fileName:d,format:t.outputFormat,content:k,source:{kind:"instance",sourceName:u.name}})}return c}async runSet(n,t,r,o){let a=Ee(t.instances,n.inputPattern.requires),s=$e(a,n.inputPattern.sortBy);return n.partitionBy?this.runSetWithPartition(n,s,t,r,o):this.runSetSingle(n,s,t,r,o)}async runSetSingle(n,t,r,o,a){let s=new Map;s.set("inputs",t);let c=await a.evaluate(n.rule,s);ee(c,n.name,"set");let u=ne(await a.evaluate(n.artifactName,s),n.name,"set"),f=te(n.overrides.get(r.outputFormat),r.runtimeOverride),l=o.render(c,f);return[{fileName:u,format:r.outputFormat,content:l,source:{kind:"set",memberCount:t.length}}]}async runSetWithPartition(n,t,r,o,a){let s=n.partitionBy,c=new Map,u=[];for(let l of t){let d=yn(l,s);if(d==null)continue;let g=kn(d),k=c.get(g);k||(k={keyValue:d,keyDisplay:bn(d),members:[]},c.set(g,k),u.push(g)),k.members.push(l)}let f=[];for(let l of u){let d=c.get(l),g=new Map;g.set("inputs",d.members),g.set("key",d.keyValue);let k=await a.evaluate(n.rule,g);ee(k,n.name,`partition "${d.keyDisplay}"`);let Ue=ne(await a.evaluate(n.artifactName,g),n.name,`partition "${d.keyDisplay}"`),Ve=te(n.overrides.get(r.outputFormat),r.runtimeOverride),Re=o.render(k,Ve);f.push({fileName:Ue,format:r.outputFormat,content:Re,source:{kind:"set",memberCount:d.members.length,partitionKey:d.keyDisplay}})}return f}findBackend(n){let t=ln[n];if(t)return this.backends.get(t.formatUri)}};function Ee(e,n){return n.length===0?e:e.filter(t=>{for(let r of n)if(!gn(t,r))return!1;return!0})}function $e(e,n){if(n.length===0)return e;let t=[...e];return t.sort((r,o)=>{for(let a of n){let s=Te(r,a.byProperty),c=Te(o,a.byProperty),u=pn(s,c,a.order);if(u!==0)return u}return 0}),t}function Te(e,n){for(let t of e.statement){let r=re(t);if(!(!r||!N(r,n))){if(t instanceof $||t instanceof T||t instanceof B)return t.object;if(t instanceof x)throw new h(`Sort property "${n.name}" on instance "${e.name??"?"}" resolves to a list \u2014 list-typed properties are not sortable. Use a scalar property.`);if(t instanceof w)throw new h(`Sort property "${n.name}" on instance "${e.name??"?"}" resolves to a reference \u2014 reference-typed properties don't have a natural total order. Use a scalar property.`)}}}function pn(e,n,t){if(e===void 0&&n===void 0)return 0;if(e===void 0)return t==="ascending"?1:-1;if(n===void 0)return t==="ascending"?-1:1;let r;return typeof e=="number"&&typeof n=="number"?r=e-n:r=String(e).localeCompare(String(n)),t==="ascending"?r:-r}function gn(e,n){for(let t of e.statement){let r=re(t);if(!r||!N(r,n))continue;let o=t.object;if(o!=null&&!(typeof o=="string"&&o.length===0)&&!(Array.isArray(o)&&o.length===0))return!0}return!1}function yn(e,n){for(let t of e.statement){let r=re(t);if(!(!r||!N(r,n))&&(t instanceof $||t instanceof T||t instanceof B||t instanceof w||t instanceof x))return t.object}}function re(e){return e.predicate?.subject}function kn(e){if(e===void 0)return" undef";if(e===null)return" null";if(typeof e=="string")return`s:${e}`;if(typeof e=="number")return`n:${e}`;if(typeof e=="boolean")return`b:${e}`;if(e instanceof E){let n=e.subject;return`r:${n.publisher}/${n.package_}/${n.name}`}if(e instanceof Y){let n=e.name??"";return`k:${e.namespace??""}/${n}`}if(typeof e=="object"&&e!==null&&typeof e.name=="string"&&typeof e.publisher=="string"){let n=e;return`u:${n.publisher}/${n.package_}/${n.name}`}return`o:${JSON.stringify(e)}`}function bn(e){return e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):e instanceof E?e.subject.name:e instanceof Y?e.name??"":typeof e=="object"&&e!==null&&typeof e.name=="string"?e.name:""}function ee(e,n,t){if(typeof e!="object"||e===null||e.kind!=="Document")throw new h(`Transformation "${n}" rule did not yield a Document for ${t}. Got: ${Be(e)}`)}function ne(e,n,t){if(typeof e=="string")return e;if(Array.isArray(e)&&e.every(hn))return e.map(r=>String(r)).join("");throw new h(`Transformation "${n}" artifactName did not yield a string for ${t}. Got: ${Be(e)}`)}function hn(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Be(e){if(e===void 0)return"undefined";if(e===null)return"null";if(Array.isArray(e))return`array(${e.length})`;if(typeof e=="object"){let n=e.kind;return n?`object(kind=${n})`:"object"}return typeof e}function te(e,n){if(!e&&!n)return;let t={metadataRenames:n?.metadataRenames??e?.metadataRenames??new Map},r=n?.metadataKeys??e?.metadataKeys;r!==void 0&&(t.metadataKeys=r);let o=n?.trailingNewline??e?.trailingNewline;o!==void 0&&(t.trailingNewline=o);let a=n?.omitWrapper??e?.omitWrapper;return a!==void 0&&(t.omitWrapper=a),t}var p=class extends Error{constructor(t,r){super(t);this.cause=r;this.name="RenderError"}cause},xe={publisher:"kanonak.org",package_:"derivation",name:"default"},oe=class{constructor(n,t=new se,r=new fe){this.repository=n;this.parser=t;this.objectParser=r}repository;parser;objectParser;runner=new H;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async renderViaLook(n){let t=await this.getCatalog(),r=A(t,n.resource);if(!(r instanceof D))throw new p(`Resource not found: ${b(n.resource)}`);let o=new G(t),a;if(n.format.name==="html")a=await o.renderHtml(r);else if(n.format.name==="stylesheet")a=o.renderStylesheet(r);else throw new p(`LookRenderer does not support format ${b(n.format)} \u2014 only formats.html and formats.stylesheet are implemented in v0.1.`);return{content:a,format:n.format,filename:r.name}}async findDerivation(n){let t=await this.getCatalog(),r=A(t,n.resource);if(!(r instanceof D))return;let o=n.variant??xe;return pe(r,n.format,o,t)}async render(n){if(n.format.name==="html"||n.format.name==="stylesheet"){let a=await this.getCatalog(),s=A(a,n.resource);if(s instanceof D){let u=new G(a).findCascadedLook(s);if(u&&!wn(u.sourceClass)){let f=await this.findDerivation(n);if(!f||Dn(f))return this.renderViaLook({resource:n.resource,format:n.format})}}}let t=await this.findDerivation(n);if(!t)throw new p(`No derivation found for ${b(n.resource)} \u2192 format ${b(n.format)}`+(n.variant?` variant ${b(n.variant)}`:""));let r=ie(t.transformation.version),o={transformation:{publisher:t.transformation.publisher,package_:t.transformation.package_,name:t.transformation.name,...r?{version:r}:{}},input:n.resource,format:n.format};return n.omitWrapper!==void 0&&(o.omitWrapper=n.omitWrapper),this.runTransformation(o)}async runTransformation(n){let t=await this.getCatalog(),r=A(t,n.transformation);if(!(r instanceof D))throw new p(`Transformation not found: ${b(n.transformation)}`);let o=A(t,n.input);if(!(o instanceof D))throw new p(`Input resource not found: ${b(n.input)}`);let a=M(r,t),s=Sn(a.outputs,n.format);if(!s)throw new p(`Transformation ${b(n.transformation)} declares outputs [${[...a.outputs].join(", ")}], none of which corresponds to format ${b(n.format)}`);let c;try{c=await this.runner.run({transformation:r,instances:[o],allKanonaks:t,repository:this.repository,parser:this.parser,objectParser:this.objectParser,outputFormat:s,...n.omitWrapper!==void 0?{runtimeOverride:{metadataRenames:new Map,omitWrapper:n.omitWrapper}}:{}})}catch(u){throw new p(`Transformation execution failed: ${u.message}`,u)}if(c.length===0)throw new p("Transformation produced no artifacts");return{content:c[0].content,format:n.format,filename:c[0].fileName}}async getCatalog(){return this.cachedCatalog||(this.cachedCatalog=await this.objectParser.parseKanonaks(this.repository)),this.cachedCatalog}};function b(e){return`${e.publisher}/${e.package_}/${e.name}`}function Dn(e){return typeof e.source=="string"?!1:e.source.publisher==="kanonak.org"&&e.source.package_==="core-rdf"&&e.source.name==="Resource"}function wn(e){return e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Resource"}function Sn(e,n){let t=n.name;if(e.has(t))return t;for(let r of e)if(r.startsWith(t+"-")||r===t)return r}var An="kanonak.org/core-rdf/type";function ae(e){let n=En(e),t,r={type:""};for(let o of e.statement){let a=o.predicate?.subject;if(!a)throw new Error(`Expression node ${n} has a statement with no resolved predicate`);if(U(a)===An){if(!(o instanceof w))throw new Error(`Expression node ${n} has a non-reference 'type' statement`);if(t!==void 0)throw new Error(`Expression node ${n} declares more than one type \u2014 a runtime tree node is exactly one operator/literal/leaf class`);t=U(o.object.subject);continue}let s=a.name;if(s in r)throw new Error(`Expression node ${n} declares operand '${s}' more than once`);r[s]=jn(o,n,s)}if(t===void 0)throw new Error(`Expression node ${n} declares no type \u2014 the runtime dispatches on it`);return r.type=t,r}function jn(e,n,t){if(e instanceof $||e instanceof de||e instanceof T||e instanceof B)return e.object;if(e instanceof w)return U(e.object.subject);if(e instanceof me)return ae(e.object);if(e instanceof x)return(e.object??[]).map((r,o)=>{if(r instanceof E)return U(r.subject);if(r instanceof ce)return ae(r);if(r instanceof ue)return r.value;throw new Error(`Expression node ${n}: '${t}'[${o}] is not a serializable list item`)});throw new Error(`Expression node ${n}: operand '${t}' has an unserializable statement kind`)}function En(e){let n=e;return n.name?`'${n.name}'`:"(embedded)"}export{I as CssBackend,xe as DEFAULT_VARIANT,m as DOCAST,Oe as DOCAST_PKG,Le as DOCAST_PUB,K as DynamoDbBackend,le as ExpressionEngineV3,Rn as ExpressionEvalErrorV3,L as HtmlBackend,v as JsonBackend,V as MarkdownFrontmatterBackend,q as ReferenceResolver,p as RenderError,ln as SUPPORTED_FORMATS_V3,O as SvgBackend,xn as TX_V3,Tn as TX_V3_PKG,$n as TX_V3_PUB,Bn as TX_V3_VERSION_MAJOR,R as TomlBackend,oe as TransformationEngine,ve as TransformationLoadErrorV3,h as TransformationRunnerErrorV3,H as TransformationRunnerV3,_ as YamlBackend,Un as compileExpression,M as compileTransformationV3,Vn as isRawStringV3,X as renderMarkdownToHtml,ae as toExpressionRuntimeTree};
|
|
91
|
+
`),o}};function Ae(e,n){let t=new Map;for(let a of e.entries)t.set(a.key,a);let r=n?.metadataKeys??e.entries.map(a=>a.key),o={};for(let a of r){let s=t.get(a);if(!s)continue;let c=n?.metadataRenames.get(a)??a;o[c]=je(s.value,s.escapeHint)}return{M:o}}function je(e,n){switch(e.kind){case"StructuredMap":return Ae(e);case"StructuredList":return{L:e.items.map(t=>je(t,void 0))};case"StringScalar":return dn(e.stringValue,n??e.escapeHint);case"IntegerScalar":return fn(e.integerValue,n??e.escapeHint)}}function dn(e,n){if(n&&C(n,m.ESC_DYNAMODB_BOOL)){if(e==="true")return{BOOL:!0};if(e==="false")return{BOOL:!1};throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-bool must have the value "true" or "false"; got ${JSON.stringify(e)}.`)}if(n&&C(n,m.ESC_DYNAMODB_NULL))return{NULL:!0};if(n&&C(n,m.ESC_DYNAMODB_NUMBER)){if(e.trim()===""||Number.isNaN(Number(e)))throw new Error(`dynamodb-json backend: a StringScalar hinted esc-dynamodb-number must hold a numeric literal; got ${JSON.stringify(e)}.`);return{N:e}}return{S:e}}function fn(e,n){if(n&&C(n,m.ESC_DYNAMODB_BOOL))throw new Error(`dynamodb-json backend: esc-dynamodb-bool cannot apply to an IntegerScalar (value ${e}). Use a StringScalar "true"/"false".`);if(n&&C(n,m.ESC_DYNAMODB_NULL))throw new Error(`dynamodb-json backend: esc-dynamodb-null cannot apply to an IntegerScalar (value ${e}). Use a StringScalar hinted esc-dynamodb-null.`);return{N:String(e)}}var ln={"markdown-with-frontmatter":{formatUri:"kanonak.org/transformations/markdown-with-frontmatter",extension:".md"},"plain-markdown":{formatUri:"kanonak.org/transformations/plain-markdown",extension:".md"},toml:{formatUri:"kanonak.org/transformations/toml",extension:".toml"},json:{formatUri:"kanonak.org/transformations/json",extension:".json"},html:{formatUri:"kanonak.org/transformations/html",extension:".html"},svg:{formatUri:"kanonak.org/transformations/svg",extension:".svg"},stylesheet:{formatUri:"kanonak.org/transformations/stylesheet",extension:".css"},yaml:{formatUri:"kanonak.org/transformations/yaml",extension:".yaml"},"dynamodb-json":{formatUri:"kanonak.org/transformations/dynamodb-json",extension:".json"}},h=class extends Error{},H=class{backends=new Map;constructor(){this.register(new V),this.register(new R),this.register(new v),this.register(new L),this.register(new O),this.register(new I),this.register(new _),this.register(new K)}register(n){this.backends.set(n.backendUri,n)}async run(n){let t=n.transformationKanonaks??n.allKanonaks,r=M(n.transformation,t);if(!r.outputs.has(n.outputFormat))throw new h(`Transformation "${r.name}" does not declare output format "${n.outputFormat}". Declared: ${Array.from(r.outputs).join(", ")}`);let o=this.findBackend(n.outputFormat);if(!o)throw new h(`No backend registered for OutputFormat "${n.outputFormat}".`);let a=new q(n.repository,n.parser,n.objectParser),s=new le(a,n.allKanonaks,r.fragments);return r.kind==="instance"?this.runInstance(r,n,o,s):this.runSet(r,n,o,s)}async runInstance(n,t,r,o){let a=Ee(t.instances,n.inputPattern.requires),s=$e(a,n.inputPattern.sortBy),c=[];for(let u of s){let f=new Map;f.set("input",u);let l=await o.evaluate(n.rule,f);ee(l,n.name,`input "${u.name}"`);let d=ne(await o.evaluate(n.artifactName,f),n.name,`input "${u.name}"`),g=te(n.overrides.get(t.outputFormat),t.runtimeOverride),k=r.render(l,g);c.push({fileName:d,format:t.outputFormat,content:k,source:{kind:"instance",sourceName:u.name}})}return c}async runSet(n,t,r,o){let a=Ee(t.instances,n.inputPattern.requires),s=$e(a,n.inputPattern.sortBy);return n.partitionBy?this.runSetWithPartition(n,s,t,r,o):this.runSetSingle(n,s,t,r,o)}async runSetSingle(n,t,r,o,a){let s=new Map;s.set("inputs",t);let c=await a.evaluate(n.rule,s);ee(c,n.name,"set");let u=ne(await a.evaluate(n.artifactName,s),n.name,"set"),f=te(n.overrides.get(r.outputFormat),r.runtimeOverride),l=o.render(c,f);return[{fileName:u,format:r.outputFormat,content:l,source:{kind:"set",memberCount:t.length}}]}async runSetWithPartition(n,t,r,o,a){let s=n.partitionBy,c=new Map,u=[];for(let l of t){let d=yn(l,s);if(d==null)continue;let g=kn(d),k=c.get(g);k||(k={keyValue:d,keyDisplay:bn(d),members:[]},c.set(g,k),u.push(g)),k.members.push(l)}let f=[];for(let l of u){let d=c.get(l),g=new Map;g.set("inputs",d.members),g.set("key",d.keyValue);let k=await a.evaluate(n.rule,g);ee(k,n.name,`partition "${d.keyDisplay}"`);let Ue=ne(await a.evaluate(n.artifactName,g),n.name,`partition "${d.keyDisplay}"`),Ve=te(n.overrides.get(r.outputFormat),r.runtimeOverride),Re=o.render(k,Ve);f.push({fileName:Ue,format:r.outputFormat,content:Re,source:{kind:"set",memberCount:d.members.length,partitionKey:d.keyDisplay}})}return f}findBackend(n){let t=ln[n];if(t)return this.backends.get(t.formatUri)}};function Ee(e,n){return n.length===0?e:e.filter(t=>{for(let r of n)if(!gn(t,r))return!1;return!0})}function $e(e,n){if(n.length===0)return e;let t=[...e];return t.sort((r,o)=>{for(let a of n){let s=Te(r,a.byProperty),c=Te(o,a.byProperty),u=pn(s,c,a.order);if(u!==0)return u}return 0}),t}function Te(e,n){for(let t of e.statement){let r=re(t);if(!(!r||!N(r,n))){if(t instanceof $||t instanceof T||t instanceof B)return t.object;if(t instanceof x)throw new h(`Sort property "${n.name}" on instance "${e.name??"?"}" resolves to a list \u2014 list-typed properties are not sortable. Use a scalar property.`);if(t instanceof w)throw new h(`Sort property "${n.name}" on instance "${e.name??"?"}" resolves to a reference \u2014 reference-typed properties don't have a natural total order. Use a scalar property.`)}}}function pn(e,n,t){if(e===void 0&&n===void 0)return 0;if(e===void 0)return t==="ascending"?1:-1;if(n===void 0)return t==="ascending"?-1:1;let r;return typeof e=="number"&&typeof n=="number"?r=e-n:r=String(e).localeCompare(String(n)),t==="ascending"?r:-r}function gn(e,n){for(let t of e.statement){let r=re(t);if(!r||!N(r,n))continue;let o=t.object;if(o!=null&&!(typeof o=="string"&&o.length===0)&&!(Array.isArray(o)&&o.length===0))return!0}return!1}function yn(e,n){for(let t of e.statement){let r=re(t);if(!(!r||!N(r,n))&&(t instanceof $||t instanceof T||t instanceof B||t instanceof w||t instanceof x))return t.object}}function re(e){return e.predicate?.subject}function kn(e){if(e===void 0)return" undef";if(e===null)return" null";if(typeof e=="string")return`s:${e}`;if(typeof e=="number")return`n:${e}`;if(typeof e=="boolean")return`b:${e}`;if(e instanceof E){let n=e.subject;return`r:${n.publisher}/${n.package_}/${n.name}`}if(e instanceof Y){let n=e.name??"";return`k:${e.namespace??""}/${n}`}if(typeof e=="object"&&e!==null&&typeof e.name=="string"&&typeof e.publisher=="string"){let n=e;return`u:${n.publisher}/${n.package_}/${n.name}`}return`o:${JSON.stringify(e,(n,t)=>n==="sourceKey"?void 0:t)}`}function bn(e){return e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):e instanceof E?e.subject.name:e instanceof Y?e.name??"":typeof e=="object"&&e!==null&&typeof e.name=="string"?e.name:""}function ee(e,n,t){if(typeof e!="object"||e===null||e.kind!=="Document")throw new h(`Transformation "${n}" rule did not yield a Document for ${t}. Got: ${Be(e)}`)}function ne(e,n,t){if(typeof e=="string")return e;if(Array.isArray(e)&&e.every(hn))return e.map(r=>String(r)).join("");throw new h(`Transformation "${n}" artifactName did not yield a string for ${t}. Got: ${Be(e)}`)}function hn(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Be(e){if(e===void 0)return"undefined";if(e===null)return"null";if(Array.isArray(e))return`array(${e.length})`;if(typeof e=="object"){let n=e.kind;return n?`object(kind=${n})`:"object"}return typeof e}function te(e,n){if(!e&&!n)return;let t={metadataRenames:n?.metadataRenames??e?.metadataRenames??new Map},r=n?.metadataKeys??e?.metadataKeys;r!==void 0&&(t.metadataKeys=r);let o=n?.trailingNewline??e?.trailingNewline;o!==void 0&&(t.trailingNewline=o);let a=n?.omitWrapper??e?.omitWrapper;return a!==void 0&&(t.omitWrapper=a),t}var p=class extends Error{constructor(t,r){super(t);this.cause=r;this.name="RenderError"}cause},xe={publisher:"kanonak.org",package_:"derivation",name:"default"},oe=class{constructor(n,t=new se,r=new fe){this.repository=n;this.parser=t;this.objectParser=r}repository;parser;objectParser;runner=new H;cachedCatalog=void 0;invalidate(){this.cachedCatalog=void 0}async renderViaLook(n){let t=await this.getCatalog(),r=A(t,n.resource);if(!(r instanceof D))throw new p(`Resource not found: ${b(n.resource)}`);let o=new G(t),a;if(n.format.name==="html")a=await o.renderHtml(r);else if(n.format.name==="stylesheet")a=o.renderStylesheet(r);else throw new p(`LookRenderer does not support format ${b(n.format)} \u2014 only formats.html and formats.stylesheet are implemented in v0.1.`);return{content:a,format:n.format,filename:r.name}}async findDerivation(n){let t=await this.getCatalog(),r=A(t,n.resource);if(!(r instanceof D))return;let o=n.variant??xe;return pe(r,n.format,o,t)}async render(n){if(n.format.name==="html"||n.format.name==="stylesheet"){let a=await this.getCatalog(),s=A(a,n.resource);if(s instanceof D){let u=new G(a).findCascadedLook(s);if(u&&!wn(u.sourceClass)){let f=await this.findDerivation(n);if(!f||Dn(f))return this.renderViaLook({resource:n.resource,format:n.format})}}}let t=await this.findDerivation(n);if(!t)throw new p(`No derivation found for ${b(n.resource)} \u2192 format ${b(n.format)}`+(n.variant?` variant ${b(n.variant)}`:""));let r=ie(t.transformation.version),o={transformation:{publisher:t.transformation.publisher,package_:t.transformation.package_,name:t.transformation.name,...r?{version:r}:{}},input:n.resource,format:n.format};return n.omitWrapper!==void 0&&(o.omitWrapper=n.omitWrapper),this.runTransformation(o)}async runTransformation(n){let t=await this.getCatalog(),r=A(t,n.transformation);if(!(r instanceof D))throw new p(`Transformation not found: ${b(n.transformation)}`);let o=A(t,n.input);if(!(o instanceof D))throw new p(`Input resource not found: ${b(n.input)}`);let a=M(r,t),s=Sn(a.outputs,n.format);if(!s)throw new p(`Transformation ${b(n.transformation)} declares outputs [${[...a.outputs].join(", ")}], none of which corresponds to format ${b(n.format)}`);let c;try{c=await this.runner.run({transformation:r,instances:[o],allKanonaks:t,repository:this.repository,parser:this.parser,objectParser:this.objectParser,outputFormat:s,...n.omitWrapper!==void 0?{runtimeOverride:{metadataRenames:new Map,omitWrapper:n.omitWrapper}}:{}})}catch(u){throw new p(`Transformation execution failed: ${u.message}`,u)}if(c.length===0)throw new p("Transformation produced no artifacts");return{content:c[0].content,format:n.format,filename:c[0].fileName}}async getCatalog(){return this.cachedCatalog||(this.cachedCatalog=await this.objectParser.parseKanonaks(this.repository)),this.cachedCatalog}};function b(e){return`${e.publisher}/${e.package_}/${e.name}`}function Dn(e){return typeof e.source=="string"?!1:e.source.publisher==="kanonak.org"&&e.source.package_==="core-rdf"&&e.source.name==="Resource"}function wn(e){return e.publisher==="kanonak.org"&&e.package_==="core-rdf"&&e.name==="Resource"}function Sn(e,n){let t=n.name;if(e.has(t))return t;for(let r of e)if(r.startsWith(t+"-")||r===t)return r}var An="kanonak.org/core-rdf/type";function ae(e){let n=En(e),t,r={type:""};for(let o of e.statement){let a=o.predicate?.subject;if(!a)throw new Error(`Expression node ${n} has a statement with no resolved predicate`);if(U(a)===An){if(!(o instanceof w))throw new Error(`Expression node ${n} has a non-reference 'type' statement`);if(t!==void 0)throw new Error(`Expression node ${n} declares more than one type \u2014 a runtime tree node is exactly one operator/literal/leaf class`);t=U(o.object.subject);continue}let s=a.name;if(s in r)throw new Error(`Expression node ${n} declares operand '${s}' more than once`);r[s]=jn(o,n,s)}if(t===void 0)throw new Error(`Expression node ${n} declares no type \u2014 the runtime dispatches on it`);return r.type=t,r}function jn(e,n,t){if(e instanceof $||e instanceof de||e instanceof T||e instanceof B)return e.object;if(e instanceof w)return U(e.object.subject);if(e instanceof me)return ae(e.object);if(e instanceof x)return(e.object??[]).map((r,o)=>{if(r instanceof E)return U(r.subject);if(r instanceof ce)return ae(r);if(r instanceof ue)return r.value;throw new Error(`Expression node ${n}: '${t}'[${o}] is not a serializable list item`)});throw new Error(`Expression node ${n}: operand '${t}' has an unserializable statement kind`)}function En(e){let n=e;return n.name?`'${n.name}'`:"(embedded)"}export{I as CssBackend,xe as DEFAULT_VARIANT,m as DOCAST,Oe as DOCAST_PKG,Le as DOCAST_PUB,K as DynamoDbBackend,le as ExpressionEngineV3,vn as ExpressionEvalErrorV3,L as HtmlBackend,v as JsonBackend,xn as MATH_V1,V as MarkdownFrontmatterBackend,q as ReferenceResolver,p as RenderError,ln as SUPPORTED_FORMATS_V3,O as SvgBackend,Un as TX_V3,Tn as TX_V3_PKG,$n as TX_V3_PUB,Bn as TX_V3_VERSION_MAJOR,R as TomlBackend,oe as TransformationEngine,ve as TransformationLoadErrorV3,h as TransformationRunnerErrorV3,H as TransformationRunnerV3,_ as YamlBackend,Vn as compileExpression,M as compileTransformationV3,Rn as isRawStringV3,X as renderMarkdownToHtml,ae as toExpressionRuntimeTree};
|
|
@@ -90,7 +90,7 @@ export interface CompiledFormatOverrideV3 {
|
|
|
90
90
|
* doctype + style + metadata <dl>; analogous in other backends). */
|
|
91
91
|
omitWrapper?: boolean | undefined;
|
|
92
92
|
}
|
|
93
|
-
export type CompiledExpressionV3 = CompiledStringLiteralV3 | CompiledIntegerLiteralV3 | CompiledDecimalLiteralV3 | CompiledBooleanLiteralV3 | CompiledVarRefV3 | CompiledPropertyReadV3 | CompiledTraverseV3 | CompiledBuildAstNodeV3 | CompiledWhenV3 | CompiledConcatV3 | CompiledFallbackV3 | CompiledUriNameV3 | CompiledUriPublisherV3 | CompiledUriPackageV3 | CompiledUriVersionV3 | CompiledSubjectUriV3 | CompiledUriLiteralV3 | CompiledDisplayLabelV3 | CompiledResolveRefV3 | CompiledNormalizeV3 | CompiledUnescapedStringV3 | CompiledIsSetV3 | CompiledCallFragmentV3 | CompiledJoinV3 | CompiledCountV3 | CompiledSumV3 | CompiledMinV3 | CompiledMaxV3 | CompiledAverageV3 | CompiledForEachV3 | CompiledListMapV3 | CompiledFilterV3 | CompiledPartitionByV3 | CompiledDistinctByV3 | CompiledAllStatementsV3 | CompiledStatementPredicateV3 | CompiledStatementValueV3 | CompiledDateFormatV3 | CompiledNumberFormatV3 |
|
|
93
|
+
export type CompiledExpressionV3 = CompiledStringLiteralV3 | CompiledIntegerLiteralV3 | CompiledDecimalLiteralV3 | CompiledBooleanLiteralV3 | CompiledVarRefV3 | CompiledPropertyReadV3 | CompiledTraverseV3 | CompiledBuildAstNodeV3 | CompiledWhenV3 | CompiledConcatV3 | CompiledFallbackV3 | CompiledUriNameV3 | CompiledUriPublisherV3 | CompiledUriPackageV3 | CompiledUriVersionV3 | CompiledSubjectUriV3 | CompiledUriLiteralV3 | CompiledDisplayLabelV3 | CompiledResolveRefV3 | CompiledNormalizeV3 | CompiledUnescapedStringV3 | CompiledIsSetV3 | CompiledCallFragmentV3 | CompiledJoinV3 | CompiledCountV3 | CompiledSumV3 | CompiledMinV3 | CompiledMaxV3 | CompiledAverageV3 | CompiledForEachV3 | CompiledListMapV3 | CompiledFilterV3 | CompiledPartitionByV3 | CompiledDistinctByV3 | CompiledAllStatementsV3 | CompiledStatementPredicateV3 | CompiledStatementValueV3 | CompiledDateFormatV3 | CompiledNumberFormatV3 | CompiledNumericOpV3 | CompiledReverseV3 | CompiledWindowedMapV3 | CompiledPairwiseMapV3 | CompiledScanV3 | CompiledListItemAtV3 | CompiledEqualsV3 | CompiledGreaterThanV3 | CompiledLessThanV3 | CompiledGreaterThanOrEqualV3 | CompiledLessThanOrEqualV3 | CompiledNotV3 | CompiledAndV3 | CompiledOrV3 | CompiledContainsV3 | CompiledMatchesV3 | CompiledIsReferenceV3 | CompiledIsEmbeddedV3 | CompiledIsListV3 | CompiledStatementObjectV3 | CompiledIsStringV3 | CompiledIsNumberV3 | CompiledIsBooleanV3 | CompiledLetV3 | CompiledGetStatementByNameV3 | CompiledRenderMarkdownV3;
|
|
94
94
|
export interface CompiledStringLiteralV3 {
|
|
95
95
|
kind: 'string-literal';
|
|
96
96
|
value: string;
|
|
@@ -228,25 +228,23 @@ export interface CompiledNumberFormatV3 {
|
|
|
228
228
|
/** ISO 4217; only meaningful for the `currency` style. Defaults to USD. */
|
|
229
229
|
currencyCode?: string;
|
|
230
230
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
left: CompiledExpressionV3;
|
|
249
|
-
right: CompiledExpressionV3;
|
|
231
|
+
/**
|
|
232
|
+
* A numeric operator — tx arithmetic (Add … Divide, Abs, Negate) and the
|
|
233
|
+
* `kanonak.org/math` family (Power … Sign, Clip). Computed by the expression runtime (`@kanonak-protocol/expression`
|
|
234
|
+
* `evaluate`), so its determinism-bearing primitives — Round half away from
|
|
235
|
+
* zero, floored Modulo, Sign(0), the domain errors — are defined once, there.
|
|
236
|
+
*/
|
|
237
|
+
export interface CompiledNumericOpV3 {
|
|
238
|
+
kind: 'numeric-op';
|
|
239
|
+
/** The operator's canonical versionless URI — the runtime's node `type`. */
|
|
240
|
+
type: string;
|
|
241
|
+
/** Its local name, for messages. */
|
|
242
|
+
name: string;
|
|
243
|
+
/** Operands in evaluation order, each under the runtime's operand key. */
|
|
244
|
+
operands: {
|
|
245
|
+
name: string;
|
|
246
|
+
expr: CompiledExpressionV3;
|
|
247
|
+
}[];
|
|
250
248
|
}
|
|
251
249
|
export interface CompiledReverseV3 {
|
|
252
250
|
kind: 'reverse';
|
|
@@ -321,13 +319,16 @@ export interface CompiledContainsV3 {
|
|
|
321
319
|
haystack: CompiledExpressionV3;
|
|
322
320
|
needle: CompiledExpressionV3;
|
|
323
321
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
322
|
+
/**
|
|
323
|
+
* `tx.Matches` (transformations@3.16.0): the string value of `source` tested
|
|
324
|
+
* against `pattern` — a fixed, authored pattern, validated when compiled — by
|
|
325
|
+
* the expression runtime's own matcher (`@kanonak-protocol/expression`
|
|
326
|
+
* `matches`), so the pinned regex subset is defined once.
|
|
327
|
+
*/
|
|
328
|
+
export interface CompiledMatchesV3 {
|
|
329
|
+
kind: 'matches';
|
|
330
|
+
source: CompiledExpressionV3;
|
|
331
|
+
pattern: string;
|
|
331
332
|
}
|
|
332
333
|
export interface CompiledIsReferenceV3 {
|
|
333
334
|
kind: 'is-reference';
|
|
@@ -14,6 +14,30 @@ import type { EntityUri } from '../../uri-helpers/UriHelpers.js';
|
|
|
14
14
|
export declare const TX_V3_PUB = "kanonak.org";
|
|
15
15
|
export declare const TX_V3_PKG = "transformations";
|
|
16
16
|
export declare const TX_V3_VERSION_MAJOR = 3;
|
|
17
|
+
/**
|
|
18
|
+
* `kanonak.org/math` (1.0.0) — the numeric operators beyond tx arithmetic.
|
|
19
|
+
* The binary ones take `tx.arithLeft`/`tx.arithRight` and the unary ones
|
|
20
|
+
* `tx.value` (they subclass `tx.BinaryArithmetic` / `tx.UnaryNumericOp`);
|
|
21
|
+
* `Clip` is the one ternary, over its own three operands.
|
|
22
|
+
*/
|
|
23
|
+
export declare const MATH_V1: {
|
|
24
|
+
readonly Power: EntityUri;
|
|
25
|
+
readonly Modulo: EntityUri;
|
|
26
|
+
readonly Minimum: EntityUri;
|
|
27
|
+
readonly Maximum: EntityUri;
|
|
28
|
+
readonly Exp: EntityUri;
|
|
29
|
+
readonly Ln: EntityUri;
|
|
30
|
+
readonly Log10: EntityUri;
|
|
31
|
+
readonly Sqrt: EntityUri;
|
|
32
|
+
readonly Floor: EntityUri;
|
|
33
|
+
readonly Ceil: EntityUri;
|
|
34
|
+
readonly Round: EntityUri;
|
|
35
|
+
readonly Sign: EntityUri;
|
|
36
|
+
readonly Clip: EntityUri;
|
|
37
|
+
readonly clipValue: EntityUri;
|
|
38
|
+
readonly clipLower: EntityUri;
|
|
39
|
+
readonly clipUpper: EntityUri;
|
|
40
|
+
};
|
|
17
41
|
export declare const TX_V3: {
|
|
18
42
|
readonly Transformation: EntityUri;
|
|
19
43
|
readonly InstanceTransformation: EntityUri;
|
|
@@ -196,6 +220,9 @@ export declare const TX_V3: {
|
|
|
196
220
|
readonly Contains: EntityUri;
|
|
197
221
|
readonly haystack: EntityUri;
|
|
198
222
|
readonly needle: EntityUri;
|
|
223
|
+
readonly Matches: EntityUri;
|
|
224
|
+
readonly matchSource: EntityUri;
|
|
225
|
+
readonly pattern: EntityUri;
|
|
199
226
|
readonly UnaryNumericOp: EntityUri;
|
|
200
227
|
readonly value: EntityUri;
|
|
201
228
|
readonly Abs: EntityUri;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as j,B as k,C as l,D as m,E as n,F as o,G as p,H as q,I as r,J as s,L as t,r as a,s as b,t as c,u as d,v as e,w as f,x as g,y as h,z as i}from"../chunk-
|
|
1
|
+
import{A as j,B as k,C as l,D as m,E as n,F as o,G as p,H as q,I as r,J as s,L as t,r as a,s as b,t as c,u as d,v as e,w as f,x as g,y as h,z as i}from"../chunk-D4QGPMRW.js";import"../chunk-FUUTGGJS.js";import"../chunk-QILEJIFU.js";export{t as SingleDocumentRepository,j as findAllResourcesByCanonicalUri,k as findStatement,i as findSubjectByUri,h as findSubjectsByType,m as getDatatypeValue,p as getEmbeddedValue,q as getListValues,o as getReferenceUri,n as getStringValue,l as hasProperty,g as hasType,f as rawValuesOf,e as referenceUris,s as subjectAddress,c as toCanonicalUrl,d as typeReferenceUris,a as uriKey,b as uriMatches,r as valuesOf};
|
|
@@ -33,8 +33,14 @@ export declare class KanonakObjectValidator implements IKanonakObjectValidator {
|
|
|
33
33
|
* Per-document `validateAsync(doc, repo, cache)` remains the low-level
|
|
34
34
|
* primitive; clients that validate more than one document MUST come
|
|
35
35
|
* through here rather than re-deriving the cache + loop themselves.
|
|
36
|
+
*
|
|
37
|
+
* `source` is the repository — a cache is built over it for this pass — or
|
|
38
|
+
* a `ValidationCache` the caller already holds over that repository, so a
|
|
39
|
+
* client that also reads the catalog (an editor's navigation and tree,
|
|
40
|
+
* from `cache.getKanonaks()` / `getAuthoredKanonaks()`) shares this pass's
|
|
41
|
+
* single parse instead of parsing the repository a second time.
|
|
36
42
|
*/
|
|
37
|
-
validateDocumentsAsync(documents: KanonakDocument[],
|
|
43
|
+
validateDocumentsAsync(documents: KanonakDocument[], source: IKanonakDocumentRepository | ValidationCache): Promise<DocumentValidationResult[]>;
|
|
38
44
|
validateYamlAsync(yamlText: string, repository?: IKanonakDocumentRepository | null, cache?: ValidationCache): Promise<OntologyValidationResult>;
|
|
39
45
|
addDocumentRule(rule: IDocumentValidationRule): void;
|
|
40
46
|
addRepositoryRule(rule: IRepositoryValidationRule): void;
|
package/dist/validation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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-
|
|
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-O6SOU5Y2.js";import"../chunk-VORVR5BZ.js";import"../chunk-TYVZXABI.js";import"../chunk-QHABFCRC.js";import"../chunk-6VIUXP4N.js";import"../chunk-22DSABP6.js";import"../chunk-7JBKOJB4.js";import"../chunk-PEJALHXK.js";import"../chunk-NUTHBBDZ.js";import"../chunk-D4QGPMRW.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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.38.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",
|
|
@@ -134,11 +134,11 @@
|
|
|
134
134
|
],
|
|
135
135
|
"dependencies": {
|
|
136
136
|
"@kanonak-protocol/canonical": "^0.1.3",
|
|
137
|
-
"@kanonak-protocol/types": "^5.
|
|
137
|
+
"@kanonak-protocol/types": "^5.38.0",
|
|
138
138
|
"ignore": "^7.0.5",
|
|
139
139
|
"js-yaml": "^4.1.0",
|
|
140
140
|
"yaml": "^2.7.0",
|
|
141
|
-
"@kanonak-protocol/expression": "^
|
|
141
|
+
"@kanonak-protocol/expression": "^1.1.0"
|
|
142
142
|
},
|
|
143
143
|
"optionalDependencies": {
|
|
144
144
|
"@huggingface/transformers": "^3.8.1"
|
package/dist/chunk-7TU55KLO.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A as M,E as v,F as Q,c as B,d as G,p as X,r as S,s as Y,u as q,v as I,z as W}from"./chunk-XNEWQEB6.js";import{a as x}from"./chunk-FUUTGGJS.js";import{b as H}from"./chunk-F67UH4FD.js";var z=class{cache=new Map;repository;logger;constructor(e,n){this.repository=e,this.logger=n}async resolveEntityAsync(e,n){let o=n.metadata?.namespace_?.toString()??"unknown",s=this.cache.get(o);if(s){let i=s.get(e);if(i)return i}let a=await this.buildEntityIndexAsyncInternal(n,new Set,"",new Map);return this.cache.set(o,a),a.get(e)??null}async resolveAllEntitiesAsync(e,n){let o=await this.buildAllEntitiesIndexAsync(n,new Set,"");if(e.includes(".")){let s=e.split("."),a=s[0],i=s[1],y=await this.findDocumentForAlias(n,a);return y?await this.resolveAllEntitiesAsync(i,y):[]}return o.filter(s=>s.entityName===e)}async buildAllEntitiesIndexAsync(e,n,o){let s=[],a=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building ALL entities index for namespace: ${a}`),n.has(a))return this.logger?.debug?.(`Skipping ${a} - already visited (circular import prevention)`),s;n.add(a);let i=o.length===0?a:`${o} \u2192 ${a}`;for(let[y,l]of Object.entries(e.body))if(!y.includes(".")&&l&&typeof l=="object"&&!Array.isArray(l)){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};s.push({entityName:y,uri:new x(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,y,g),entity:l,definedInNamespace:a,isImported:o.length>0,importPath:i})}if(this.logger?.debug?.(`Collected ${s.length} entities from ${a}`),e.metadata?.imports){let y=Object.values(e.metadata.imports).reduce((l,g)=>l+g.length,0);this.logger?.debug?.(`Processing ${y} import(s) for ${a}`);for(let[l,g]of Object.entries(e.metadata.imports))for(let d of g)if(!H(d))try{this.logger?.debug?.(`Resolving import: ${l}/${d.packageName}`);let m=await this.repository.getHighestCompatibleVersionAsync(l,d);if(m){this.logger?.debug?.(`Successfully loaded import: ${m.metadata?.namespace_?.toString()}`);let k=await this.buildAllEntitiesIndexAsync(m,n,i);s.push(...k),this.logger?.debug?.(`Added ${k.length} entities from import ${m.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${l}/${d.packageName}`)}catch(m){let k=m;throw this.logger?.error?.(`Failed to process import ${l}/${d.packageName} for namespace ${a}. Error: ${k.message}`,k),new Error(`Failed to process import ${l}/${d.packageName} for namespace ${a}. See inner exception for details.`,{cause:m})}}return s}async buildEntityIndexAsync(e){return await this.buildEntityIndexAsyncInternal(e,new Set,"",new Map)}async buildEntityIndexAsyncInternal(e,n,o,s){let a=new Map,i=e.metadata?.namespace_?.toString()??"unknown";if(this.logger?.debug?.(`Building entity index for namespace: ${i}`),n.has(i))return this.logger?.debug?.(`Skipping ${i} - circular import in progress`),a;let y=s.get(i);if(y)return y;n.add(i);let l=o.length===0?i:`${o} \u2192 ${i}`,g=0;for(let[d,m]of Object.entries(e.body))if(!d.includes(".")&&m&&typeof m=="object"&&!Array.isArray(m)){if(!e.metadata.namespace_)continue;if(!a.has(d)){let k=e.metadata.namespace_.version??{major:1,minor:0,patch:0,toString:()=>"1.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};a.set(d,{entityName:d,uri:new x(e.metadata.namespace_.publisher,e.metadata.namespace_.package_,d,k),entity:m,definedInNamespace:i,isImported:o.length>0,importPath:l}),g++}}if(this.logger?.debug?.(`Indexed ${g} entities from ${i}`),e.metadata?.imports){let d=Object.values(e.metadata.imports).reduce((m,k)=>m+k.length,0);this.logger?.debug?.(`Processing ${d} import(s) for ${i}`);for(let[m,k]of Object.entries(e.metadata.imports))for(let b of k)if(!H(b))try{this.logger?.debug?.(`Resolving import: ${m}/${b.packageName}`);let h=await this.repository.getHighestCompatibleVersionAsync(m,b);if(h){this.logger?.debug?.(`Successfully loaded import: ${h.metadata?.namespace_?.toString()}`);let U=await this.buildEntityIndexAsyncInternal(h,n,l,s),$=0;for(let[K,P]of U.entries()){let _=a.get(K);if(!_)a.set(K,P),$++;else if(_.isImported&&P.isImported&&(_.uri.publisher!==P.uri.publisher||_.uri.package_!==P.uri.package_)){let C=_.isAmbiguous?_:{..._,isAmbiguous:!0,ambiguousNamespaces:[_.definedInNamespace]};C.ambiguousNamespaces.includes(P.definedInNamespace)||C.ambiguousNamespaces.push(P.definedInNamespace),a.set(K,C),this.logger?.warn?.(`Ambiguous reference '${K}': defined in ${C.ambiguousNamespaces.join(", ")}`)}if(b.alias&&!K.includes(".")){let C=`${b.alias}.${K}`;a.has(C)||(a.set(C,P),$++)}}this.logger?.debug?.(`Merged ${$} entities from import ${h.metadata?.namespace_?.toString()}`)}else this.logger?.warn?.(`Failed to load import: ${m}/${b.packageName}`)}catch(h){let U=h;throw this.logger?.error?.(`Failed to process import ${m}/${b.packageName} for namespace ${i}. Error: ${U.message}`,U),new Error(`Failed to process import ${m}/${b.packageName} for namespace ${i}. See inner exception for details.`,{cause:h})}}return n.delete(i),s.set(i,a),a}async findDocumentForAlias(e,n){if(!e.metadata?.imports)return null;for(let[o,s]of Object.entries(e.metadata.imports))for(let a of s)if(!H(a)){if(a.alias===n)return await this.repository.getHighestCompatibleVersionAsync(o,a);if(!a.alias&&a.packageName===n)return await this.repository.getHighestCompatibleVersionAsync(o,a)}return null}clearCache(){this.cache.clear()}clearCacheForDocument(e){this.cache.delete(e)}};var J=class t{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"&&t.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 t.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 n=e.includes(".")?e.split(".")[1]:e;return t.KNOWN_XSD_DATATYPES.has(n.toLowerCase())}async isClassTypeAsync(e,n){if(this.isKnownXsdDatatypeName(e))return!1;let o=await this.resourceResolver.resolveEntityAsync(e,n);if(o){let s=o.entity.type;if(s){let a=String(s);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,n){return!!(e==="DatatypeProperty"||e==="Property"&&this.isXsdDatatype(n)||e==="Property"&&this.isLiteralType(n))}isEffectiveObjectProperty(e,n){return!!(e==="ObjectProperty"||e==="Property"&&n&&!this.isXsdDatatype(n)&&!this.isLiteralType(n))}};function Oe(t){return`${t.publisher}/${t.package_}/${t.name}`}function u(t,e,n){return`${t}/${e}/${n}`}function Ue(t){return`${t.s}|${t.p}|${ae(t.o)}`}function ae(t){switch(t.kind){case"uri":return`u:${t.key}`;case"literal":return`l:${t.datatype}:${t.lexical}`;case"blank":return`b:${t.id}`}}function He(t,e,n){return{s:t,p:e,o:{kind:"uri",key:n}}}var se="kanonak.org",ie="core-shacl",r=t=>({publisher:se,package_:ie,name:t}),D=r("Shape"),N=r("NodeShape"),T=r("PropertyShape"),De=r("targetClass"),Ne=r("property"),Te=r("path"),je=r("minCount"),$e=r("maxCount"),Me=r("datatype"),ve=r("class"),Le=r("in"),we=r("pattern"),Ve=r("flags"),Fe=r("minLength"),Be=r("maxLength"),Ge=r("minInclusive"),Xe=r("maxInclusive"),Ye=r("message"),qe=r("targetNode"),We=r("targetSubjectsOf"),Qe=r("targetObjectsOf"),ze=r("closed"),Je=r("ignoredProperties"),Ze=r("nodeKind"),et=r("IRI"),tt=r("BlankNode"),nt=r("Literal"),rt=r("severity"),ot=r("Violation"),at=r("Warning"),st=r("Info"),it=r("ValidationReport"),pt=r("conforms"),ct=r("result"),lt=r("ValidationResult"),ut=r("focusNode"),yt=r("resultPath"),mt=r("resultMessage"),dt=r("resultSeverity"),gt=r("sourceShape"),ft=r("value"),kt=r("sourceConstraintComponent"),St=r("MinCountConstraintComponent"),bt=r("MaxCountConstraintComponent"),_t=r("DatatypeConstraintComponent"),ht=r("ClassConstraintComponent"),Pt=r("InConstraintComponent"),Ct=r("PatternConstraintComponent"),Et=r("MinLengthConstraintComponent"),At=r("MaxLengthConstraintComponent"),Kt=r("MinInclusiveConstraintComponent"),xt=r("MaxInclusiveConstraintComponent"),Rt=r("NodeKindConstraintComponent"),Ot=r("ClosedConstraintComponent"),Ut=r("hasValue"),Ht=r("qualifiedValueShape"),It=r("qualifiedMinCount"),Dt=r("qualifiedMaxCount"),Nt=r("HasValueConstraintComponent"),Tt=r("QualifiedMinCountConstraintComponent"),jt=r("QualifiedMaxCountConstraintComponent");var c="kanonak.org",p="core-rdf",f="core-owl",ee="core-kanonak",w=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",ee]]),pe=new Set(["type","subClassOf","subPropertyOf","domain","range"]);function Lt(t){return w.has(t)}function wt(t){let e=w.get(t);return e?{publisher:c,package_:e}:void 0}function V(t,e,n){if(!t||!t.name)return;let o=w.get(t.name);if(!o)return;let s=()=>{t.publisher=c,t.package_=o,n&&(t.version=n.get(o))};if(pe.has(t.name)){let a=t.publisher===c&&t.package_===o;t.publisher=c,t.package_=o,!a&&n&&(t.version=n.get(o));return}t.publisher===c&&t.package_===o||t.publisher&&t.publisher.length>0&&(!e||e(t))||s()}var Z=class{type=u(c,p,"type");subClassOf=u(c,p,"subClassOf");subPropertyOf=u(c,p,"subPropertyOf");domain=u(c,p,"domain");range=u(c,p,"range");label=u(c,p,"label");comment=u(c,p,"comment");resource=u(c,p,"Resource");class_=u(c,p,"Class");datatype=u(c,p,"Datatype");literal=u(c,p,"Literal");equivalentClass=u(c,f,"equivalentClass");equivalentProperty=u(c,f,"equivalentProperty");inverseOf=u(c,f,"inverseOf");sameAs=u(c,f,"sameAs");transitiveProperty=u(c,f,"TransitiveProperty");symmetricProperty=u(c,f,"SymmetricProperty");objectProperty=u(c,f,"ObjectProperty");datatypeProperty=u(c,f,"DatatypeProperty");annotationProperty=u(c,f,"AnnotationProperty");package_=u(c,ee,"Package");shape=L(D);nodeShape=L(N);propertyShape=L(T)};function L(t){return u(t.publisher,t.package_,t.name)}var ce=new Set(["kanonak.org/core-rdf","kanonak.org/core-owl","kanonak.org/core-xsd","kanonak.org/core-kanonak"]);function R(t){let e=t;if(e.entity&&typeof e.entity=="object"){let n=e.entity.type;if(typeof n=="string"){let s={publisher:"",package_:"",name:n.includes(".")?n.substring(n.lastIndexOf(".")+1):n};return V(s),{publisher:s.publisher,package_:s.package_,name:s.name}}}return ne(t)[0]??null}function ne(t){let e=t;if(e.entity&&typeof e.entity=="object"){let n=R(t);return n?[n]:[]}return Array.isArray(e.statement)?q(t).map(n=>{let o={publisher:n.publisher??"",package_:n.package_??"",name:n.name};return V(o),{publisher:o.publisher,package_:o.package_,name:o.name}}):[]}var le=[D,N,T];function O(t,e){return ce.has(`${t}/${e}`)}var ue=new Set(["Property","ObjectProperty","DatatypeProperty","AnnotationProperty"]);function F(t){if(O(t.publisher,t.package_))return ue.has(t.name)?t.name:void 0}var te=class t{static getTypeUri(e){return R(e)}static isCoreOntologyType(e){return O(e.publisher,e.package_)}static hasCoreType(e,n){return ne(e).some(o=>O(o.publisher,o.package_)&&o.name===n)}static isClassType(e){return t.hasCoreType(e,"Class")}static isDatatypeType(e){return t.hasCoreType(e,"Datatype")}static isDatatypePropertyType(e){return t.hasCoreType(e,"DatatypeProperty")}static isObjectPropertyType(e){return t.hasCoreType(e,"ObjectProperty")}static isAnnotationPropertyType(e){return t.hasCoreType(e,"AnnotationProperty")}static isGenericPropertyType(e){return t.hasCoreType(e,"Property")}static isAnyPropertyType(e){let n=R(e);return!n||!O(n.publisher,n.package_)?!1:n.name==="Property"||n.name==="DatatypeProperty"||n.name==="ObjectProperty"||n.name==="AnnotationProperty"}static isShapeType(e){let n=R(e);return n?le.some(o=>Y(n,o)):!1}static isSchemaDefinitionType(e){if(t.isShapeType(e))return!0;let n=R(e);return!n||!O(n.publisher,n.package_)?!1:n.name==="Class"||n.name==="Property"||n.name==="DatatypeProperty"||n.name==="ObjectProperty"||n.name==="AnnotationProperty"||n.name==="Datatype"}static isInstanceOfKnownClass(e,n){if(t.isSchemaDefinitionType(e))return!1;let o=R(e);return o?n.has(o.name):!1}};var E="kanonak.org",A="core-rdf",ye={publisher:E,package_:A,name:"domain"},me={publisher:E,package_:A,name:"range"},de={publisher:E,package_:A,name:"subClassOf"},ge={publisher:E,package_:A,name:"type"},fe={publisher:E,package_:A,name:"label"},ke={publisher:E,package_:A,name:"comment"},Se=new x(E,A,"Resource");function be(t){try{let e=X(`${t.namespace}/${t.name}`);return e.kind==="resource"?e.uri:void 0}catch{return}}function oe(t,e){let n=[],o=new Set,s="version"in e?e.version:void 0,a=[new x(e.publisher,e.package_,e.name,s??void 0)];for(;a.length>0;){let i=a.shift(),y=S(i);if(o.has(y))continue;o.add(y),n.push(i);let l=_e(t,i);l&&a.push(...I(l,de))}return n}function _e(t,e){return e.version&&typeof e.version.major=="number"?W(t,e)??M(t,e)[0]:M(t,e)[0]}function j(t,e){let n;for(let o of Ee(e)){let s=he(t,o);if(s){if(s!=="Property")return s;n??=s}}return n}function he(t,e){let n=F(e);if(n)return n;let o=re.get(t);o||(o=new Map,re.set(t,o));let s=e.version,a=s&&typeof s.major=="number"?`${S(e)}@${s.major}.${s.minor}.${s.patch}`:S(e),i=o.get(a);if(i!==void 0)return i??void 0;let y;for(let l of oe(t,e)){let g=F(l);if(g){if(g!=="Property"){y=g;break}y??="Property"}}return o.set(a,y??null),y}var re=new WeakMap;function en(t,e){return j(t,e)!==void 0}function tn(t,e){return j(t,e)==="ObjectProperty"}function nn(t,e){return j(t,e)==="DatatypeProperty"}function Pe(t,e){let n=new Set([S(Se)]);for(let o of oe(t,e))n.add(S(o));return n}function Ce(t,e){let n=Pe(t,e),o=[],s=new Set;for(let a of t){if(!(a instanceof B))continue;let i=j(t,a);if(!i)continue;let y=I(a,ye);if(!y.some(d=>n.has(S(d))))continue;let l=be(a);if(!l)continue;let g=S(l);s.has(g)||(s.add(g),o.push({uri:l,label:v(a,fe),comment:v(a,ke),kind:i==="ObjectProperty"?"object":i==="DatatypeProperty"?"datatype":"other",range:Q(a,me),domains:y}))}return o}function rn(t,e,n){let o=Ce(t,e).find(s=>S(s.uri)===S(n));return o?{ok:!0,descriptor:o}:{ok:!1,message:`Property ${n.publisher}/${n.package_}/${n.name} is not in scope for ${e.publisher}/${e.package_}/${e.name}.`}}function Ee(t){let e=I(t,ge);return e.length>0?e:t instanceof G&&t.rangeType?[t.rangeType]:[]}export{z as a,J as b,Oe as c,u as d,Ue as e,ae as f,He as g,se as h,ie as i,D as j,N as k,T as l,De as m,Ne as n,Te as o,je as p,$e as q,Me as r,ve as s,Le as t,we 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,Qe as D,ze as E,Je 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,St as O,bt as P,_t as Q,ht as R,Pt as S,Ct as T,Et as U,At as V,Kt as W,xt as X,Rt as Y,Ot as Z,Ut as _,Ht as $,It as aa,Dt as ba,Nt as ca,Tt as da,jt as ea,Lt as fa,wt as ga,V as ha,Z as ia,F as ja,te as ka,be as la,oe as ma,j as na,en as oa,tn as pa,nn as qa,Ce as ra,rn as sa,Ee as ta};
|
package/dist/chunk-HF5FJBS2.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as d}from"./chunk-F67UH4FD.js";import{a as l,b as h}from"./chunk-QILEJIFU.js";import*as c from"js-yaml";var y=new Set(["Package","EphemeralPackage"]);function f(m){return typeof m=="string"&&y.has(m)}var g=class{parse(e){let r=this.parseWithErrors(e);if(!r.isValid){let n=r.errors[0];throw new Error(`YAML parse error at line ${n.line}, column ${n.column}: ${n.message}`)}return r.document}parseWithErrors(e){let r=[],n;try{e=e.replace(/^\uFEFF/,"");let a=c.load(e,{schema:c.FAILSAFE_SCHEMA});if(!a||typeof a!="object")return n={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:n,errors:r,isValid:!0};let t=this.extractMetadata(a),o=this.extractBody(a,t);return n={metadata:t,body:o,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:n,errors:r,isValid:!0}}catch(a){let t=a,o={message:t.message||"Unknown parse error",line:t.mark?.line??0,column:t.mark?.column??0,errorType:t.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${t.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${t.mark?.line??0}: ${t.message||"Unknown parse error"}`};return r.push(o),{document:void 0,errors:r,isValid:!1}}}save(e){let r={};if(e.metadata.namespace_){let n=e.metadata.namespace_,a={type:"Package",publisher:n.publisher};n.version&&(a.version=`${n.version.major}.${n.version.minor}.${n.version.patch}`),e.metadata.imports&&(a.imports=this.serializeImports(e.metadata.imports)),r[n.package_]=a}return Object.assign(r,e.body),c.dump(r,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let r=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!r)return[];let n=[];for(let a of Object.values(r))n.push(...a);return n},enumerable:!0,configurable:!0}),e}createVersion(e,r,n){return{major:e,minor:r,patch:n,toString:()=>`${e}.${r}.${n}`,equals:t=>!t||typeof t!="object"?!1:t.major===e&&t.minor===r&&t.patch===n,getHashCode:()=>e<<20|r<<10|n,compareTo:t=>e!==t.major?e-t.major:r!==t.minor?r-t.minor:n-t.patch}}extractMetadata(e){let r=this.createEmptyMetadata();for(let[n,a]of Object.entries(e))if(a&&typeof a=="object"&&f(a.type)){r.type_=a.type;let t=n,o=a.publisher,i=a.version?this.parseVersion(a.version):void 0;return o&&t&&(r.namespace_={publisher:o,package_:t,version:i,toString:function(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}`:`${this.publisher}/${this.package_}`},equals:s=>!s||typeof s!="object"?!1:s.publisher===o&&s.package_===t&&(!i||!s.version||i.equals(s.version)),getHashCode:()=>{let s=0;for(let p=0;p<o.length;p++)s=(s<<5)-s+o.charCodeAt(p);for(let p=0;p<t.length;p++)s=(s<<5)-s+t.charCodeAt(p);return s|0}}),a.imports&&Array.isArray(a.imports)&&(r.imports=this.parseImportsV3(a.imports)),this.addAllImportsGetter(r)}return r}extractBody(e,r){let n={};for(let[a,t]of Object.entries(e))if(t&&typeof t=="object"&&f(t.type)){let o={};for(let[i,s]of Object.entries(t))i==="publisher"||i==="version"||i==="imports"||(o[i]=s);n[a]=o}else n[a]=t;return n}parseVersion(e){if(typeof e=="string"){let r=e.split(".").map(Number);return this.createVersion(r[0]||0,r[1]||0,r[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let r={};for(let n of e)if(!(!n||typeof n!="object"))if(n.packages&&Array.isArray(n.packages)){let a=n.publisher;if(!a)throw new Error("PublisherImport requires 'publisher' property");r[a]||(r[a]=[]);for(let t of n.packages){if(!t||typeof t!="object")continue;let o=this.parseImportFromEmbeddedObject(t,a);r[a].push(o)}}else{let a=this.parseImportFromEmbeddedObject(n,n.publisher),t=a.publisher||"";r[t]||(r[t]=[]),r[t].push(a)}return r}parseImportFromEmbeddedObject(e,r){let n=e.package;if(!n)throw new Error("Import requires 'package' property");let a=e.match;if(!a)throw new Error("Import requires 'match' property");let t=e.version;if(!t)throw new Error("Import requires 'version' property");let o;if(e.mode!==void 0&&e.mode!==null){if(!d.includes(e.mode))throw new Error(`Import '${n}' has an unknown mode '${e.mode}'; expected one of: ${d.join(", ")}`);o=e.mode}return this.makeImport(n,a,t,r,e.alias,o)}makeImport(e,r,n,a,t,o){let i=this.parseVersion(n),s=this.parseVersionOperator(r),p=this.calculateMaxVersion(r,i);return{package_:`${e} ${r} ${i.toString()}`,publisher:a,packageName:e,versionOperator:s,version:i,alias:t,...o?{mode:o}:{},minVersion:i,maxVersion:p,toEmbeddedObject:()=>{let u={package:e,match:r,version:i.toString()};return t&&(u.alias=t),o&&(u.mode=o),u},toString:()=>t?`${e} ${r} ${i.toString()} as ${t}`:`${e} ${r} ${i.toString()}`}}buildImport(e,r,n,a){return this.makeImport(e,r,n,a)}parseVersionOperator(e){return l(e)}calculateMaxVersion(e,r){switch(e){case"~":return this.createVersion(r.major,r.minor+1,0);case"^":return r.major===0?this.createVersion(0,r.minor+1,0):this.createVersion(r.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let r=[];for(let[n,a]of Object.entries(e)){let t={publisher:n,packages:a.map(o=>{let i=h(o.versionOperator),s={package:o.packageName,match:i,version:`${o.version.major}.${o.version.minor}.${o.version.patch}`};return o.alias&&(s.alias=o.alias),s})};r.push(t)}return r}};export{g as a};
|