@kanonak-protocol/sdk 5.35.0 → 5.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +3 -1
- package/dist/browser.js +1 -1
- package/dist/{chunk-O35Y6QUW.js → chunk-2WUZKSLB.js} +1 -1
- package/dist/chunk-3353RWDC.js +1 -0
- package/dist/{chunk-2Y6R3K5A.js → chunk-4CXAZH3C.js} +1 -1
- package/dist/chunk-7JBKOJB4.js +1 -0
- package/dist/chunk-D2X6J77P.js +1 -0
- package/dist/chunk-D4QGPMRW.js +1 -0
- package/dist/chunk-DONOB6RA.js +1 -0
- package/dist/{chunk-ZYDJUGIA.js → chunk-ED35OFGD.js} +1 -1
- package/dist/chunk-EG47OOJC.js +155 -0
- package/dist/chunk-HKX27KBZ.js +1 -0
- package/dist/{chunk-26SO3A4B.js → chunk-LE26SEJU.js} +1 -1
- package/dist/chunk-NUTHBBDZ.js +1 -0
- package/dist/{chunk-BZ3YTI3C.js → chunk-OOYGILH4.js} +2 -2
- package/dist/chunk-R4QCVB5M.js +68 -0
- package/dist/chunk-VORVR5BZ.js +1 -0
- package/dist/chunk-W5AOJ5SJ.js +3 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.js +1 -1
- package/dist/kanonaks/DefinedKanonak.d.ts +11 -0
- package/dist/kanonaks/LiteralKanonak.d.ts +12 -0
- package/dist/kanonaks/ReferenceKanonak.d.ts +2 -0
- package/dist/kanonaks/walkDefinedKanonaks.d.ts +23 -18
- 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/KanonakObjectParser.d.ts +8 -0
- 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/TransformationLoaderV3.d.ts +8 -2
- package/dist/uri-helpers/PropertyValues.d.ts +34 -3
- package/dist/uri-helpers/UriHelpers.d.ts +3 -0
- package/dist/uri-helpers/index.d.ts +1 -1
- package/dist/uri-helpers/index.js +1 -1
- package/dist/validation/KanonakObjectValidator.d.ts +7 -1
- package/dist/validation/index.js +1 -1
- package/dist/validation/rules/repository/MarkdownLinkRule.d.ts +1 -0
- package/package.json +2 -2
- package/dist/chunk-54D47DLS.js +0 -1
- package/dist/chunk-AVVLDZAZ.js +0 -68
- package/dist/chunk-D7QLWVPK.js +0 -155
- package/dist/chunk-HF5FJBS2.js +0 -1
- package/dist/chunk-IS3AQKB4.js +0 -1
- package/dist/chunk-JHQPXEMA.js +0 -1
- package/dist/chunk-KIBR3HAT.js +0 -1
- package/dist/chunk-MQBWSCNY.js +0 -1
- package/dist/chunk-V3DH67P3.js +0 -1
- package/dist/chunk-VEGFYZXG.js +0 -2
- package/dist/chunk-XK24CN3C.js +0 -1
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-D7QLWVPK.js";import"../chunk-QHABFCRC.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{k as oe}from"../chunk-JHQPXEMA.js";import{a as O}from"../chunk-HF5FJBS2.js";import{a as xe}from"../chunk-PEJALHXK.js";import{c as Re}from"../chunk-MQBWSCNY.js";import{c as we,x as re}from"../chunk-54D47DLS.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-EG47OOJC.js";import"../chunk-QHABFCRC.js";import{a as ye}from"../chunk-6VIUXP4N.js";import{j as te}from"../chunk-3353RWDC.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-W5AOJ5SJ.js";import{a as ve,b as M,c as Un,n as X,o as Vn,p as Rn,q as le,r as q,t as G}from"../chunk-EG47OOJC.js";import"../chunk-QHABFCRC.js";import"../chunk-6VIUXP4N.js";import{b as $n,c as Tn,d as Bn,e as xn,j as fe}from"../chunk-3353RWDC.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,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};
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Throws `TransformationLoadErrorV3` with a breadcrumb path on the
|
|
9
9
|
* first shape violation.
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import { DefinedKanonak, SubjectKanonak, type Kanonak } from '../../kanonaks/index.js';
|
|
12
12
|
import type { CompiledTransformationV3, CompiledExpressionV3 } from './CompiledTransformationV3.js';
|
|
13
13
|
export declare class TransformationLoadErrorV3 extends Error {
|
|
14
14
|
readonly path: string;
|
|
@@ -17,6 +17,12 @@ export declare class TransformationLoadErrorV3 extends Error {
|
|
|
17
17
|
export interface CompileContext {
|
|
18
18
|
readonly catalog: Kanonak[];
|
|
19
19
|
readonly depth: number;
|
|
20
|
+
/**
|
|
21
|
+
* The named expressions being compiled on the current path, by canonical
|
|
22
|
+
* key — how a cycle through references (A uses B uses A) is reported
|
|
23
|
+
* instead of recursing forever. Callers leave it unset.
|
|
24
|
+
*/
|
|
25
|
+
readonly visiting?: ReadonlySet<string> | undefined;
|
|
20
26
|
}
|
|
21
27
|
/**
|
|
22
28
|
* Top-level entry point. Determines whether the SubjectKanonak is an
|
|
@@ -36,4 +42,4 @@ export declare function compileTransformationV3(transformation: SubjectKanonak,
|
|
|
36
42
|
* must contain every class/property the Expression references so the
|
|
37
43
|
* loader can resolve URI references.
|
|
38
44
|
*/
|
|
39
|
-
export declare function compileExpression(
|
|
45
|
+
export declare function compileExpression(node: DefinedKanonak, path: string, ctx: CompileContext): CompiledExpressionV3;
|
|
@@ -3,7 +3,8 @@ import { SubjectKanonak } from '../kanonaks/SubjectKanonak.js';
|
|
|
3
3
|
import { EmbeddedKanonak } from '../kanonaks/EmbeddedKanonak.js';
|
|
4
4
|
import type { DefinedKanonak } from '../kanonaks/DefinedKanonak.js';
|
|
5
5
|
import type { KanonakUri } from '../resolution/KanonakUri.js';
|
|
6
|
-
import {
|
|
6
|
+
import type { MarkdownLink } from '../statements/MarkdownStatement.js';
|
|
7
|
+
import { type EntityUri, type RawPropertyValue } from './UriHelpers.js';
|
|
7
8
|
/**
|
|
8
9
|
* One value of a property, whatever form it was authored in (typescript#123).
|
|
9
10
|
*
|
|
@@ -19,22 +20,28 @@ import { type EntityUri } from './UriHelpers.js';
|
|
|
19
20
|
* the validator reports — returned all the same, so a consumer that wants
|
|
20
21
|
* only resources filters by kind in its own code.
|
|
21
22
|
*
|
|
22
|
-
* Every value carries its ADDRESS
|
|
23
|
-
* fragment path for this value (see {@link valuesOf})
|
|
23
|
+
* Every value carries its ADDRESS — the node's address plus the protocol's
|
|
24
|
+
* fragment path for this value (see {@link valuesOf}) — and `fromList`:
|
|
25
|
+
* whether it was authored as an item of a list rather than as the property's
|
|
26
|
+
* single value. An editor writing a value back needs the second (editing a
|
|
27
|
+
* list item vs setting a single value); the address already reflects it.
|
|
24
28
|
*/
|
|
25
29
|
export type PropertyValue = {
|
|
26
30
|
kind: 'subject';
|
|
27
31
|
node: SubjectKanonak;
|
|
28
32
|
uri: KanonakUri;
|
|
29
33
|
address: string;
|
|
34
|
+
fromList: boolean;
|
|
30
35
|
} | {
|
|
31
36
|
kind: 'embedded';
|
|
32
37
|
node: EmbeddedKanonak;
|
|
33
38
|
address: string;
|
|
39
|
+
fromList: boolean;
|
|
34
40
|
} | {
|
|
35
41
|
kind: 'unresolved';
|
|
36
42
|
uri: KanonakUri;
|
|
37
43
|
address: string;
|
|
44
|
+
fromList: boolean;
|
|
38
45
|
} | {
|
|
39
46
|
kind: 'literal';
|
|
40
47
|
value: string | number | boolean;
|
|
@@ -42,7 +49,15 @@ export type PropertyValue = {
|
|
|
42
49
|
carrier?: string | undefined;
|
|
43
50
|
/** The raw lexical token as authored. */
|
|
44
51
|
lexical?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* A prose value's `[[reference]]` placeholders, resolved through the
|
|
54
|
+
* import closure by the parser (single values and list items alike).
|
|
55
|
+
* Present exactly when the value is prose (core-prose Markdown /
|
|
56
|
+
* SubstitutableString).
|
|
57
|
+
*/
|
|
58
|
+
links?: readonly MarkdownLink[] | undefined;
|
|
45
59
|
address: string;
|
|
60
|
+
fromList: boolean;
|
|
46
61
|
};
|
|
47
62
|
/**
|
|
48
63
|
* Every value of a property on a node, in authored order, each resolved and
|
|
@@ -72,3 +87,19 @@ export type PropertyValue = {
|
|
|
72
87
|
* (`alice#address`).
|
|
73
88
|
*/
|
|
74
89
|
export declare function valuesOf(node: DefinedKanonak, property: EntityUri, catalog: Kanonak[], nodeAddress: string): PropertyValue[];
|
|
90
|
+
/**
|
|
91
|
+
* A subject's own address — its canonical key `publisher/package/name` —
|
|
92
|
+
* the root that every value address under it extends (`valuesOf`,
|
|
93
|
+
* `walkDefinedKanonaks`, and a conformance finding's focus node).
|
|
94
|
+
*/
|
|
95
|
+
export declare function subjectAddress(subject: SubjectKanonak): string;
|
|
96
|
+
/**
|
|
97
|
+
* THE address computation: every raw value of a property with its fragment
|
|
98
|
+
* address under `nodeAddress`, per the protocol's uri-fragments convention
|
|
99
|
+
* (see {@link valuesOf}). Shared by `valuesOf` and `walkDefinedKanonaks`, so
|
|
100
|
+
* one node has one address whichever way it is reached.
|
|
101
|
+
*/
|
|
102
|
+
export declare function addressedValuesOf(node: DefinedKanonak, property: EntityUri, nodeAddress: string): {
|
|
103
|
+
value: RawPropertyValue;
|
|
104
|
+
address: string;
|
|
105
|
+
}[];
|
|
@@ -4,6 +4,7 @@ import { DefinedKanonak } from '../kanonaks/DefinedKanonak.js';
|
|
|
4
4
|
import { ReferenceKanonak } from '../kanonaks/ReferenceKanonak.js';
|
|
5
5
|
import { Kanonak } from '../kanonaks/Kanonak.js';
|
|
6
6
|
import { KanonakUri } from '../resolution/KanonakUri.js';
|
|
7
|
+
import { type MarkdownLink } from '../statements/MarkdownStatement.js';
|
|
7
8
|
import type { IStatement } from '../statements/IStatement.js';
|
|
8
9
|
/**
|
|
9
10
|
* Canonical URI identity for an ontology entity.
|
|
@@ -93,6 +94,8 @@ export interface RawLiteral {
|
|
|
93
94
|
value: string | number | boolean;
|
|
94
95
|
carrier?: string | undefined;
|
|
95
96
|
lexical?: string | undefined;
|
|
97
|
+
/** A prose value's resolved `[[links]]` — present exactly when the value is prose. */
|
|
98
|
+
links?: readonly MarkdownLink[] | undefined;
|
|
96
99
|
}
|
|
97
100
|
/**
|
|
98
101
|
* Every value of a property on a defined kanonak, in statement order — THE
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { typeReferenceUris, referenceUris, rawValuesOf, uriKey, uriMatches, toCanonicalUrl, hasType, hasProperty, findSubjectsByType, findSubjectByUri, findAllResourcesByCanonicalUri, getDatatypeValue, getStringValue, getReferenceUri, getEmbeddedValue, getListValues, findStatement, } from './UriHelpers.js';
|
|
2
2
|
export type { EntityUri, CanonicalUriParts, RawPropertyValue, RawLiteral } from './UriHelpers.js';
|
|
3
|
-
export { valuesOf } from './PropertyValues.js';
|
|
3
|
+
export { valuesOf, subjectAddress } from './PropertyValues.js';
|
|
4
4
|
export type { PropertyValue } from './PropertyValues.js';
|
|
5
5
|
export { SingleDocumentRepository } from './SingleDocumentRepository.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as
|
|
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-R4QCVB5M.js";import"../chunk-VORVR5BZ.js";import"../chunk-EG47OOJC.js";import"../chunk-QHABFCRC.js";import"../chunk-6VIUXP4N.js";import"../chunk-3353RWDC.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};
|
|
@@ -24,6 +24,7 @@ export declare class MarkdownLinkRule implements IRepositoryValidationRule {
|
|
|
24
24
|
* handles recursion into embeddeds, so this inspects a single level.
|
|
25
25
|
*/
|
|
26
26
|
private checkNode;
|
|
27
|
+
private checkProse;
|
|
27
28
|
private unresolvedLinkError;
|
|
28
29
|
private malformedLinkError;
|
|
29
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.37.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,7 +134,7 @@
|
|
|
134
134
|
],
|
|
135
135
|
"dependencies": {
|
|
136
136
|
"@kanonak-protocol/canonical": "^0.1.3",
|
|
137
|
-
"@kanonak-protocol/types": "^5.
|
|
137
|
+
"@kanonak-protocol/types": "^5.37.0",
|
|
138
138
|
"ignore": "^7.0.5",
|
|
139
139
|
"js-yaml": "^4.1.0",
|
|
140
140
|
"yaml": "^2.7.0",
|
package/dist/chunk-54D47DLS.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as V}from"./chunk-FUUTGGJS.js";import{c as P,g as R}from"./chunk-QILEJIFU.js";var u=class{};var m=class extends u{statement=[];unresolvedPredicates=[];sourceDoc=""};var p=class extends m{namespace;name;icon};var d=class extends m{name;rangeType};var s=class n extends u{subject;static parse(e){let t=new n;return t.subject=V.parse(e),t}};var S=class extends u{value;carrier;lexical};var c=class{predicate;object};var l=class extends c{carrier;lexical};var y=class n extends l{static parse(e,t){let r=new n;return r.predicate=s.parse(e),r.object=t,r}};var g=class n extends l{static parse(e,t){let r=new n;return r.predicate=s.parse(e),r.object=t,r}};var K=class extends l{};var k=class n extends c{static parse(e,t){let r=new n;return r.predicate=s.parse(e),r.object=s.parse(t),r}};var x=class extends c{};var j=class extends c{};function C(n){return`${n.publisher}/${n.package_}/${n.name}`}function $(n,e){return n.publisher===e.publisher&&n.package_===e.package_&&n.name===e.name}function O(n){let e=n.version;return e&&typeof e.major=="number"?`https://${n.publisher}/${n.package_}/${e.major}.${e.minor}.${e.patch}/${n.name}`:`https://${n.publisher}/${n.package_}/${n.name}`}function T(n){return v(n,B)}var B={publisher:"kanonak.org",package_:"core-rdf",name:"type"};function v(n,e){let t=[];for(let r of D(n,e))r.item instanceof s&&t.push(r.item.subject);return t}function D(n,e){if(!(n instanceof m))return[];let t=[];for(let r of n.statement){let a=r.predicate;if(!(!a?.subject||!$(a.subject,e)))if(r instanceof k)t.push({item:r.object,fromList:!1});else if(r instanceof x)t.push({item:r.object,fromList:!1});else if(r instanceof y||r instanceof g||r instanceof K)t.push({item:{literal:!0,value:r.object,carrier:r.carrier,lexical:r.lexical},fromList:!1});else if(r instanceof j)for(let o of r.object??[])if(o instanceof s||o instanceof d)t.push({item:o,fromList:!0});else if(o instanceof S)t.push({item:{literal:!0,value:o.value,carrier:o.carrier,lexical:o.lexical},fromList:!0});else throw new Error(`rawValuesOf: a list value of '${e.name}' is a ${o?.constructor?.name??typeof o}; list items are references, embedded values or literals.`);else throw new Error(`rawValuesOf: '${e.name}' has a statement of unknown kind ${r?.constructor?.name??typeof r}.`)}return t}function I(n,e){if(!(n instanceof m))return!1;for(let t of n.statement)if(t.predicate?.subject?.name==="type"&&t instanceof k){let a=t.object;if($(a.subject,e))return!0}return!1}function M(n,e){let t=[];for(let r of n)r instanceof p&&I(r,e)&&t.push(r);return t}function N(n,e){let t=e.version,r=t&&typeof t.major=="number"?`${e.publisher}/${e.package_}@${t.major}.${t.minor}.${t.patch}`:void 0;for(let a of n){if(!(a instanceof p)||a.name!==e.name)continue;let o=a.namespace||"";if(r!==void 0){if(o===r)return a}else if(o.startsWith(`${e.publisher}/${e.package_}@`))return a}}function H(n,e){let t=[];for(let r of n){if(!(r instanceof p)||r.name!==e.name)continue;(r.namespace||"").startsWith(`${e.publisher}/${e.package_}@`)&&t.push(r)}return t.sort((r,a)=>{let o=R((r.namespace||"").split("@")[1]??""),f=R((a.namespace||"").split("@")[1]??"");return o?f?P(f,o):-1:f?1:0}),t}function b(n,e){for(let t of n.statement){let r=t.predicate;if(r?.subject&&$(r.subject,e))return t}}function W(n,e){return b(n,e)!==void 0}function A(n,e){let t=b(n,e);if(t&&(t instanceof y||t instanceof g||t instanceof K))return t.object}function F(n,e){let t=A(n,e);return typeof t=="string"?t:void 0}function Y(n,e){let t=b(n,e);if(t instanceof k)return t.object.subject}function q(n,e){let t=b(n,e);if(t instanceof x)return t.object}function z(n,e){let t=b(n,e);return t instanceof j?t.object??[]:[]}function G(n,e,t,r){let a=D(n,e);if(a.length===0)return[];let o=r.includes("#")?`${r}.${e.name}`:`${r}#${e.name}`,f=a.length>1||a.some(i=>i.fromList),U=J(t);return a.map((i,_)=>{let h=i.item instanceof d&&i.item.name?`${o}.${i.item.name}`:f?`${o}[${_}]`:o;if(i.item instanceof s){let w=U.resolve(i.item.subject);return w?{kind:"subject",node:w,uri:i.item.subject,address:h}:{kind:"unresolved",uri:i.item.subject,address:h}}return i.item instanceof d?{kind:"embedded",node:i.item,address:h}:{kind:"literal",value:i.item.value,carrier:i.item.carrier,lexical:i.item.lexical,address:h}})}var L=new WeakMap;function J(n){let e=L.get(n);if(e)return e;let t=new Map,r=new Map;for(let a of n){if(!(a instanceof p))continue;let o=a.namespace||"",f=`${o}\0${a.name}`;t.has(f)||t.set(f,a);let U=o.indexOf("@");if(U>=0){let i=`${o.slice(0,U)}\0${a.name}`;r.has(i)||r.set(i,a)}}return e={resolve(a){let o=a.version;return o&&typeof o.major=="number"?t.get(`${a.publisher}/${a.package_}@${o.major}.${o.minor}.${o.patch}\0${a.name}`):r.get(`${a.publisher}/${a.package_}\0${a.name}`)}},L.set(n,e),e}var E=class{constructor(e,t){this.doc=e;this.broader=t}doc;broader;async getAllDocumentsAsync(){return[this.doc]}async getDocumentAsync(e){return this.broader.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){return this.broader.getDocumentsByNamespaceAsync(e,t)}async getHighestCompatibleVersionAsync(e,t){return this.broader.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async deleteDocumentAsync(){throw new Error("SingleDocumentRepository is read-only")}async clearNamespaceAsync(){throw new Error("SingleDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return this.broader.getDocumentContentAsync(e)}async getDocumentUriAsync(e){return this.broader.getDocumentUriAsync(e)}};export{u as a,m as b,p as c,d,s as e,S as f,c as g,l as h,y as i,g as j,K as k,k as l,x as m,j as n,C as o,$ as p,O as q,T as r,v as s,D as t,I as u,M as v,N as w,H as x,b as y,W as z,A,F as B,Y as C,q as D,z as E,G as F,E as G};
|