@kanonak-protocol/sdk 3.63.0 → 3.64.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.
@@ -1,3 +1,3 @@
1
- import{c as L}from"../chunk-IL6VHYRU.js";import"../chunk-3NEUHF7E.js";import{a as J,d as K,f as X,g as Z}from"../chunk-CA2EATJR.js";import{a as Y,b as z,c as Q,d as F,e as V}from"../chunk-RSIZQAFL.js";import"../chunk-PEUTCG3B.js";import{a as re}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import{c as N}from"../chunk-Q6QTQWR2.js";import"../chunk-H2LEQLVD.js";import{a as C}from"../chunk-ORFSMEMM.js";import{b as I}from"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{c as ee}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as M,g as G}from"../chunk-2ACBWC7K.js";import{readFileSync as ce,existsSync as le,readdirSync as pe,writeFileSync as ue,mkdirSync as de}from"fs";import{join as H}from"path";function te(s){let e=s.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function j(s,e){let n=new Set,r=[...s];for(;r.length>0;){let t=r.shift(),d=te(t);if(!d||n.has(d))continue;n.add(d);let m=t.metadata?.imports;if(m)for(let[l,g]of Object.entries(m))for(let y of g)try{let p=await e.getHighestCompatibleVersionAsync(l,y);p&&r.push(p)}catch{}}return n}var $=class{constructor(e,n){this.inner=e;this.scope=n}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(n=>{let r=te(n);return r!==void 0&&this.scope.has(r)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,n){return this.inner.getDocumentsByNamespaceAsync(e,n)}getHighestCompatibleVersionAsync(e,n){return this.inner.getHighestCompatibleVersionAsync(e,n)}saveDocumentAsync(e,n){return this.inner.saveDocumentAsync(e,n)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,n){return this.inner.clearNamespaceAsync(e,n)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var ne=[{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 A(s){let e=s?.render;if(e&&e.length>0){let n=[];for(let r of e)try{let t=I(r);t.kind==="package"?n.push({publisher:t.publisher,package_:t.package_}):t.kind==="resource"&&n.push({publisher:t.uri.publisher,package_:t.uri.package_})}catch{}if(n.length>0)return n}return ne}function B(s){return`${s.publisher}/${s.package_}`}function E(s){let{publisher:e,availablePublishers:n,catalog:r,lookRenderer:t,localNamespaces:d,rawByNsKey:m}=s,l=new Map,g=new Map,y=new Map,p=new Set;for(let c of r){if(!(c instanceof ee))continue;let u=c.namespace||"";if(!d.has(u))continue;l.set(`${u}/${c.name}`,c);let h=u.split("/")[1]??"",[v,x]=h.split("@");if(!v||!x)continue;let a=G(x);a&&(p.has(h)||(p.add(h),g.has(v)||g.set(v,[]),g.get(v).push({verStr:x,version:a})),c.name===v&&y.set(h,c))}for(let c of g.values())c.sort((u,h)=>M(h.version,u.version));return{publisher:e,availablePublishers:n,catalog:r,lookRenderer:t,localNamespaces:d,rawByNsKey:m,bySubject:l,pkgVersions:g,pkgSelfByVer:y}}async function q(s,e={}){let n=new C,r=new Y(n),t=[],d=[];for(let a of Z(s)){let w;try{w=ce(a,"utf-8")}catch{continue}let b;try{b=n.parse(w).metadata?.namespace_}catch{continue}if(!b?.version)continue;let _=b.version;d.push({publisher:b.publisher,package_:b.package_,verStr:`${_.major}.${_.minor}.${_.patch}`,version:_,source:w})}d.sort((a,w)=>M(w.version,a.version));for(let a of d)await r.saveDocumentAsync(n.parse(a.source),`${a.publisher}/${a.package_}@${a.verStr}`),t.push({publisher:a.publisher,package_:a.package_,verStr:a.verStr,source:a.source});let m=[...new Set(t.map(a=>a.publisher))].sort(),l=e.publisher;if(l){if(!m.includes(l))throw new Error(`Publisher "${l}" not found in workspace. Available: ${m.join(", ")||"(none)"}`)}else if(m.length===1)l=m[0];else throw m.length===0?new Error(`No Kanonak packages found under ${s}`):new Error(`Workspace has multiple publishers (${m.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let g=new Set,y=new Map;for(let a of t)a.publisher===l&&(g.add(`${a.publisher}/${a.package_}@${a.verStr}`),y.set(`${a.package_}@${a.verStr}`,a.source));let p=new J(K(),!0,n),c=e.repository??new X(r,p,new V(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),u=A(void 0);if(!e.repository){let a=K(),w=o=>{let f=H(a,o);return le(f)?new Set(pe(f).filter(k=>k.endsWith(".kan.yml")).map(k=>k.split("@")[0])):new Set},b=(o,f)=>t.some(k=>k.publisher===o&&k.package_===f),_=new F,i=new Map;for(let o of u)if(i.has(o.publisher)||i.set(o.publisher,w(o.publisher)),!(i.get(o.publisher).has(o.package_)||b(o.publisher,o.package_)))try{let f=await _.getHighestVersion(o.publisher,o.package_);if(!f)continue;let k=await _.getPackageUrl(o.publisher,o.package_,f),D=await fetch(k);if(!D.ok)continue;let ie=await D.text(),W=H(a,o.publisher);de(W,{recursive:!0}),ue(H(W,`${o.package_}@${f}.kan.yml`),ie,"utf-8")}catch{}}let h=c;if(!e.repository){let a=(await r.getAllDocumentsAsync()).filter(b=>b.metadata.namespace_?.publisher===l),w=await j(a,c);for(let b of u)w.add(B(b));h=new $(c,w)}let v=await new N(n).parseKanonaks(h),x=new L(v);return E({publisher:l,availablePublishers:m,catalog:v,lookRenderer:x,localNamespaces:g,rawByNsKey:y})}import{existsSync as me,readFileSync as ge,writeFileSync as fe,mkdirSync as he}from"fs";import{join as oe}from"path";async function O(s,e={}){let n=new C,r=I(s),t=r.kind==="resource"?r.uri.publisher:r.publisher,d=e.cacheRoot??K(),m=(i,o,f)=>oe(d,i,`${o}@${f}.kan.yml`),l=new V({getFromCache:(i,o,f)=>{let k=m(i,o,f);return me(k)?ge(k,"utf-8"):null},onFetch:(i,o,f,k)=>{let D=oe(d,i);he(D,{recursive:!0}),fe(m(i,o,f),k,"utf-8")},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new F(e.fetchFn?{fetchFn:e.fetchFn}:void 0),y;if(r.kind==="resource"){let i=r.uri.version;y=[i?{package_:r.uri.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let i=r.version;y=[i?{package_:r.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.package_}]}else y=(await g.listLatestPackages(t)).map(o=>({package_:o.packageName}));let p=async(i,o,f)=>{try{let k=f?n.buildImport(o,"=",f,i):n.buildImport(o,"*","0.0.0",i);return await l.getHighestCompatibleVersionAsync(i,k)}catch{return null}},c=[];for(let i of y){let o=await p(t,i.package_,i.version);o&&c.push(o)}if(c.length===0)throw new Error(`Could not fetch any package for address "${s}" from publisher "${t}".`);let u=await new Q().getConfig(t).catch(()=>{}),h=[];for(let i of A(u)){let o=await p(i.publisher,i.package_,void 0);o&&h.push(o)}let v=await j([...c,...h],l),x=new $(l,v),a=await new N(n).parseKanonaks(x),w=new L(a),b=new Set,_=new Map;for(let i of await l.getAllDocumentsAsync()){let o=i.metadata.namespace_;if(!o||o.publisher!==t)continue;let f=`${o.version.major}.${o.version.minor}.${o.version.patch}`,k=`${o.publisher}/${o.package_}@${f}`;b.add(k);let D=await l.getDocumentContentAsync(k);D!==null&&_.set(`${o.package_}@${f}`,D)}return E({publisher:t,availablePublishers:[t],catalog:a,lookRenderer:w,localNamespaces:b,rawByNsKey:_})}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"},S=(s,e,n,r)=>({status:s,headers:{"Content-Type":e,...r||{}},body:n}),P=s=>S(404,R[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${s}</p>`),ke=s=>({status:301,headers:{Location:s},body:""});function se(s,e,n){let r=s.pkgVersions.get(e);if(!r||r.length===0)return null;switch(n.kind){case"any":return r[0].verStr;case"major-pin":return r.find(t=>t.version.major===n.major)?.verStr??null;case"minor-pin":return r.find(t=>t.version.major===n.major&&t.version.minor===n.minor)?.verStr??null;case"exact":return r.find(t=>t.version.major===n.major&&t.version.minor===n.minor&&t.version.patch===n.patch)?.verStr??null;default:return null}}function T(s,e,n=""){let{lookRenderer:r,publisher:t}=s;if(e==="/.well-known/kanonak.json")return S(200,R[".json"],JSON.stringify(z(t),null,2));if(e==="/index.txt"){let c=[...s.localNamespaces].map(u=>u.split("/")[1].replace("@","/")).sort();return S(200,R[".txt"],c.join(`
1
+ import{c as O}from"../chunk-IL6VHYRU.js";import"../chunk-3NEUHF7E.js";import{a as z,d as j,f as Z,g as V}from"../chunk-CA2EATJR.js";import{a as J,b as Q,c as X,d as F,e as I}from"../chunk-RSIZQAFL.js";import"../chunk-PEUTCG3B.js";import{a as te}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import{c as N}from"../chunk-Q6QTQWR2.js";import"../chunk-H2LEQLVD.js";import{a as K}from"../chunk-ORFSMEMM.js";import{b as L}from"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{c as ee}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as C,g as Y}from"../chunk-2ACBWC7K.js";import{readFileSync as ce,existsSync as pe,readdirSync as le,writeFileSync as ue,mkdirSync as de}from"fs";import{join as W}from"path";function re(a){let e=a.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function A(a,e){let r=new Set,t=[...a];for(;t.length>0;){let n=t.shift(),u=re(n);if(!u||r.has(u))continue;r.add(u);let d=n.metadata?.imports;if(d)for(let[c,g]of Object.entries(d))for(let f of g)try{let i=await e.getHighestCompatibleVersionAsync(c,f);i&&t.push(i)}catch{}}return r}var D=class{constructor(e,r){this.inner=e;this.scope=r}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(r=>{let t=re(r);return t!==void 0&&this.scope.has(t)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,r){return this.inner.getDocumentsByNamespaceAsync(e,r)}getHighestCompatibleVersionAsync(e,r){return this.inner.getHighestCompatibleVersionAsync(e,r)}saveDocumentAsync(e,r){return this.inner.saveDocumentAsync(e,r)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,r){return this.inner.clearNamespaceAsync(e,r)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var ne=[{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 M(a){let e=a?.render;if(e&&e.length>0){let r=[];for(let t of e)try{let n=L(t);n.kind==="package"?r.push({publisher:n.publisher,package_:n.package_}):n.kind==="resource"&&r.push({publisher:n.uri.publisher,package_:n.uri.package_})}catch{}if(r.length>0)return r}return ne}function B(a){return`${a.publisher}/${a.package_}`}function E(a){let{publisher:e,availablePublishers:r,catalog:t,lookRenderer:n,localNamespaces:u,rawByNsKey:d}=a,c=new Map,g=new Map,f=new Map,i=new Set;for(let s of t){if(!(s instanceof ee))continue;let m=s.namespace||"";if(!u.has(m))continue;c.set(`${m}/${s.name}`,s);let k=m.split("/")[1]??"",[v,x]=k.split("@");if(!v||!x)continue;let p=Y(x);p&&(i.has(k)||(i.add(k),g.has(v)||g.set(v,[]),g.get(v).push({verStr:x,version:p})),s.name===v&&f.set(k,s))}for(let s of g.values())s.sort((m,k)=>C(k.version,m.version));return{publisher:e,availablePublishers:r,catalog:t,lookRenderer:n,localNamespaces:u,rawByNsKey:d,bySubject:c,pkgVersions:g,pkgSelfByVer:f}}async function H(a,e={}){let r=new K,t=new J(r),n=[],u=[];for(let p of V(a)){let R;try{R=ce(p,"utf-8")}catch{continue}let b;try{b=r.parse(R).metadata?.namespace_}catch{continue}if(!b?.version)continue;let $=b.version;u.push({publisher:b.publisher,package_:b.package_,verStr:`${$.major}.${$.minor}.${$.patch}`,version:$,source:R})}u.sort((p,R)=>C(R.version,p.version));for(let p of u)await t.saveDocumentAsync(r.parse(p.source),`${p.publisher}/${p.package_}@${p.verStr}`),n.push({publisher:p.publisher,package_:p.package_,verStr:p.verStr,source:p.source});let d=[...new Set(n.map(p=>p.publisher))].sort(),c=e.publisher;if(c){if(!d.includes(c))throw new Error(`Publisher "${c}" not found in workspace. Available: ${d.join(", ")||"(none)"}`)}else if(d.length===1)c=d[0];else throw d.length===0?new Error(`No Kanonak packages found under ${a}`):new Error(`Workspace has multiple publishers (${d.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let g=new Set,f=new Map;for(let p of n)p.publisher===c&&(g.add(`${p.publisher}/${p.package_}@${p.verStr}`),f.set(`${p.package_}@${p.verStr}`,p.source));let i=new z(j(),!0,r),s=e.repository??new Z(t,i,new I(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),m=M(void 0);if(!e.repository){let p=j(),R=o=>{let h=W(p,o);return pe(h)?new Set(le(h).filter(y=>y.endsWith(".kan.yml")).map(y=>y.split("@")[0])):new Set},b=(o,h)=>n.some(y=>y.publisher===o&&y.package_===h),$=new F,l=new Map;for(let o of m)if(l.has(o.publisher)||l.set(o.publisher,R(o.publisher)),!(l.get(o.publisher).has(o.package_)||b(o.publisher,o.package_)))try{let h=await $.getHighestVersion(o.publisher,o.package_);if(!h)continue;let y=await $.getPackageUrl(o.publisher,o.package_,h),P=await fetch(y);if(!P.ok)continue;let ie=await P.text(),G=W(p,o.publisher);de(G,{recursive:!0}),ue(W(G,`${o.package_}@${h}.kan.yml`),ie,"utf-8")}catch{}}let k=s;if(!e.repository){let p=(await t.getAllDocumentsAsync()).filter(b=>b.metadata.namespace_?.publisher===c),R=await A(p,s);for(let b of m)R.add(B(b));k=new D(s,R)}let v=await new N(r).parseKanonaks(k),x=new O(v);return E({publisher:c,availablePublishers:d,catalog:v,lookRenderer:x,localNamespaces:g,rawByNsKey:f})}import{existsSync as me,readFileSync as ge,writeFileSync as fe,mkdirSync as he}from"fs";import{join as oe}from"path";async function q(a,e={}){let r=new K,t=L(a),n=t.kind==="resource"?t.uri.publisher:t.publisher,u=e.cacheRoot??j(),d=(l,o,h)=>oe(u,l,`${o}@${h}.kan.yml`),c=new I({getFromCache:(l,o,h)=>{let y=d(l,o,h);return me(y)?ge(y,"utf-8"):null},onFetch:(l,o,h,y)=>{let P=oe(u,l);he(P,{recursive:!0}),fe(d(l,o,h),y,"utf-8")},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new F(e.fetchFn?{fetchFn:e.fetchFn}:void 0),f;if(t.kind==="resource"){let l=t.uri.version;f=[l?{package_:t.uri.package_,version:`${l.major}.${l.minor}.${l.patch}`}:{package_:t.uri.package_}]}else if(t.kind==="package"){let l=t.version;f=[l?{package_:t.package_,version:`${l.major}.${l.minor}.${l.patch}`}:{package_:t.package_}]}else f=(await g.listLatestPackages(n)).map(o=>({package_:o.packageName}));let i=async(l,o,h)=>{try{let y=h?r.buildImport(o,"=",h,l):r.buildImport(o,"*","0.0.0",l);return await c.getHighestCompatibleVersionAsync(l,y)}catch{return null}},s=[];for(let l of f){let o=await i(n,l.package_,l.version);o&&s.push(o)}if(s.length===0)throw new Error(`Could not fetch any package for address "${a}" from publisher "${n}".`);let m=await new X().getConfig(n).catch(()=>{}),k=[];for(let l of M(m)){let o=await i(l.publisher,l.package_,void 0);o&&k.push(o)}let v=await A([...s,...k],c),x=new D(c,v),p=await new N(r).parseKanonaks(x),R=new O(p),b=new Set,$=new Map;for(let l of await c.getAllDocumentsAsync()){let o=l.metadata.namespace_;if(!o||o.publisher!==n)continue;let h=`${o.version.major}.${o.version.minor}.${o.version.patch}`,y=`${o.publisher}/${o.package_}@${h}`;b.add(y);let P=await c.getDocumentContentAsync(y);P!==null&&$.set(`${o.package_}@${h}`,P)}return E({publisher:n,availablePublishers:[n],catalog:p,lookRenderer:R,localNamespaces:b,rawByNsKey:$})}var S={".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"},w=(a,e,r,t)=>({status:a,headers:{"Content-Type":e,...t||{}},body:r}),_=a=>w(404,S[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${a}</p>`),ke=a=>({status:301,headers:{Location:a},body:""});function se(a,e,r){let t=a.pkgVersions.get(e);if(!t||t.length===0)return null;switch(r.kind){case"any":return t[0].verStr;case"major-pin":return t.find(n=>n.version.major===r.major)?.verStr??null;case"minor-pin":return t.find(n=>n.version.major===r.major&&n.version.minor===r.minor)?.verStr??null;case"exact":return t.find(n=>n.version.major===r.major&&n.version.minor===r.minor&&n.version.patch===r.patch)?.verStr??null;default:return null}}function T(a,e,r=""){let{lookRenderer:t,publisher:n}=a;if(e==="/.well-known/kanonak.json")return w(200,S[".json"],JSON.stringify(Q(n),null,2));if(e==="/index.txt"){let s=[...a.localNamespaces].map(m=>m.split("/")[1].replace("@","/")).sort();return w(200,S[".txt"],s.join(`
2
2
  `)+`
3
- `)}if(e==="/"||e==="/index.html"||e==="/index.css"){let c=r.publisherSubject(t);return e==="/index.css"?S(200,R[".css"],r.renderStylesheet(c)):S(200,R[".html"],r.renderDocument(c,{rootIndex:!0}))}let d=".html",m=!1,l=e;for(let c of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(c)){d=c,m=!0,l=e.slice(0,-c.length);break}let g=!m&&/application\/yaml|text\/yaml/i.test(n),y=l.endsWith("/");y&&l!=="/"&&(l=l.slice(0,-1));let p=re.parse(l,t);if(!p)return P(e);if(p.kind==="package"){let c=se(s,p.package_,p.versionSpec);if(!c)return P(e);if(d===".kan.yml"||g){let v=s.rawByNsKey.get(`${p.package_}@${c}`);return v!==void 0?S(200,R[".kan.yml"],v):P(e)}let u=s.pkgSelfByVer.get(`${p.package_}@${c}`);if(!u)return P(e);if(d===".css")return S(200,R[".css"],r.renderStylesheet(u));if(!y)return ke(l+"/");let h=p.versionSpec.kind==="any";if(h&&!r.hasDeclaredView(u)){let v=(s.pkgVersions.get(p.package_)||[]).map(x=>x.verStr);return S(200,R[".html"],r.renderPackageVersionList(p.package_,v,u))}return S(200,R[".html"],r.renderDocument(u,h?{bareOverview:!0}:void 0))}if(p.kind==="resource"){let c=se(s,p.package_,p.versionSpec);if(!c)return P(e);let u=s.bySubject.get(`${t}/${p.package_}@${c}/${p.name}`);if(!u)return P(e);switch(d){case".css":return S(200,R[".css"],r.renderStylesheet(u));case".svg":return S(200,R[".svg"],r.renderSvg(u));case".md":{let h=r.renderRawMarkdown(u);return h===void 0?P(e):S(200,R[".md"],h)}default:return S(200,R[".html"],r.renderDocument(u))}}return P(e)}var U=class{constructor(e={}){this.options=e}options;models=new Map;clearCache(){this.models.clear()}async modelFor(e){let n=this.models.get(e);if(n)return n;let r=this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},t;if(this.options.root!==void 0)try{t=await q(this.options.root,{publisher:e})}catch(d){if(!/not found in workspace/i.test(d.message))throw d;t=await O(e,r)}else t=await O(e,r);return t.lookRenderer.setLinkMode("open-world"),this.models.set(e,t),t}async handle(e,n=""){let r=e.split("/").filter(Boolean);if(r.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:ae()};let t=r[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 d=await this.modelFor(t),m=e.endsWith("/")&&r.length>1?"/":"",l="/"+r.slice(1).join("/")+m,g=T(d,l,n);return g.headers.Location?{...g,headers:{...g.headers,Location:`/${t}${g.headers.Location}`}}:g}};function ae(){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{$ as ClosureScopedRepository,U as RequestRouter,ne as UNIVERSAL_RENDER_BASE,j as deriveImportClosure,ae as landingPage,O as loadResourceModel,q as loadServerModel,B as renderRefKey,A as resolveRenderContract,T as route};
3
+ `)}if(e==="/"||e==="/index.html"||e==="/index.css"){let s=t.publisherSubject(n);return e==="/index.css"?w(200,S[".css"],t.renderStylesheet(s)):w(200,S[".html"],t.renderDocument(s,{rootIndex:!0}))}let u=".html",d=!1,c=e;for(let s of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(s)){u=s,d=!0,c=e.slice(0,-s.length);break}let g=!d&&/application\/yaml|text\/yaml/i.test(r),f=c.endsWith("/");f&&c!=="/"&&(c=c.slice(0,-1));let i=te.parse(c,n);if(!i)return _(e);if(i.kind==="package"){let s=se(a,i.package_,i.versionSpec);if(!s)return _(e);if(u===".kan.yml"||g){let v=a.rawByNsKey.get(`${i.package_}@${s}`);return v!==void 0?w(200,S[".kan.yml"],v):_(e)}let m=a.pkgSelfByVer.get(`${i.package_}@${s}`);if(!m)return _(e);if(u===".css")return w(200,S[".css"],t.renderStylesheet(m));if(!f)return ke(c+"/");let k=i.versionSpec.kind==="any";if(k&&!t.hasDeclaredView(m)){let v=(a.pkgVersions.get(i.package_)||[]).map(x=>x.verStr);return w(200,S[".html"],t.renderPackageVersionList(i.package_,v,m))}return w(200,S[".html"],t.renderDocument(m,k?{bareOverview:!0}:void 0))}if(i.kind==="resource"){let s=se(a,i.package_,i.versionSpec);if(!s)return _(e);let m=a.bySubject.get(`${n}/${i.package_}@${s}/${i.name}`);if(!m)return _(e);switch(u){case".css":return w(200,S[".css"],t.renderStylesheet(m));case".svg":return w(200,S[".svg"],t.renderSvg(m));case".md":{let k=t.renderRawMarkdown(m);return k===void 0?_(e):w(200,S[".md"],k)}default:return w(200,S[".html"],t.renderDocument(m))}}return _(e)}import{readFileSync as ye}from"fs";var U=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,r=new Set;if(this.options.root!==void 0){let t=new K;for(let n of V(this.options.root))try{let u=t.parse(ye(n,"utf-8")).metadata?.namespace_;if(!u?.version)continue;let d=u.version;e.add(`${u.publisher}/${u.package_}@${d.major}.${d.minor}.${d.patch}`),r.add(`${u.publisher}/${u.package_}`)}catch{}}return this.workspaceIndex={exact:e,pkgs:r},this.workspaceIndex}async modelFor(e,r,t){let n=this.getWorkspaceIndex(),u=this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},d=r?t?n.exact.has(`${e}/${r}@${t}`):n.pkgs.has(`${e}/${r}`):[...n.pkgs].some(s=>s.startsWith(`${e}/`)),c,g;if(d&&this.options.root!==void 0){let s=this.options.root;c=`ws:${e}`,g=()=>H(s,{publisher:e})}else{let s=r?t?`${e}/${r}@${t}`:`${e}/${r}`:e;c=`rm:${s}`,g=()=>q(s,u)}let f=this.models.get(c);if(f)return f;let i=await g();return i.lookRenderer.setLinkMode("open-world"),this.models.set(c,i),i}async handle(e,r=""){let t=e.split("/").filter(Boolean);if(t.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:ae()};let n=t[0];if(!n.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 u=t.length>=2?t[1]:void 0,d=t.length>=3&&/^\d+\.\d+\.\d+$/.test(t[2])?t[2]:void 0,c=await this.modelFor(n,u,d),g=e.endsWith("/")&&t.length>1?"/":"",f="/"+t.slice(1).join("/")+g,i=T(c,f,r);return i.headers.Location?{...i,headers:{...i.headers,Location:`/${n}${i.headers.Location}`}}:i}};function ae(){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{D as ClosureScopedRepository,U as RequestRouter,ne as UNIVERSAL_RENDER_BASE,A as deriveImportClosure,ae as landingPage,q as loadResourceModel,H as loadServerModel,B as renderRefKey,M as resolveRenderContract,T as route};
@@ -12,11 +12,13 @@ export interface RequestRouterOptions {
12
12
  }
13
13
  /**
14
14
  * The request-driven routing engine: maps a publisher-FIRST path
15
- * (`/{publisher}/{package}/{version}/{resource}`) to a response by deriving the
16
- * publisher from the first path segment and building a per-publisher
17
- * {@link ServerModel} on demand — from the workspace if that publisher is local
18
- * (when `root` is set), else fetched over HTTP via {@link loadResourceModel}.
19
- * One model is cached per publisher.
15
+ * (`/{publisher}/{package}/{version}/{resource}`) to a response. The local↔remote
16
+ * decision is made PER PACKAGE, not per publisher: if the requested
17
+ * `publisher/package@version` is in the workspace it's served from disk (live
18
+ * edits); otherwise just that package + its import closure is fetched over HTTP
19
+ * via {@link loadResourceModel}. So a "partially local" publisher — some packages
20
+ * authored locally, the rest published — works: your local packages render from
21
+ * the workspace while the others resolve from the server on demand.
20
22
  *
21
23
  * This is the canonical request-driven engine shared by `kanonak serve`
22
24
  * (request-driven mode) and the VS Code extension's `EmbeddedServer`: both are
@@ -26,16 +28,24 @@ export interface RequestRouterOptions {
26
28
  */
27
29
  export declare class RequestRouter {
28
30
  private readonly options;
31
+ /** Built models, keyed `ws:<publisher>` (workspace) or `rm:<seed-address>` (fetched). */
29
32
  private readonly models;
33
+ /** Workspace package presence, scanned once from `root`. */
34
+ private workspaceIndex;
30
35
  constructor(options?: RequestRouterOptions);
31
- /** Drop cached models — e.g. after a workspace `.kan.yml` change. */
36
+ /** Drop cached models + the workspace scan — e.g. after a `.kan.yml` change. */
32
37
  clearCache(): void;
38
+ /** Which `publisher/package@version` (and `publisher/package`) the workspace defines. */
39
+ private getWorkspaceIndex;
33
40
  /**
34
- * The model for one publisher, built on first use and cached. A local
35
- * workspace publisher is served from disk; any other publisher is fetched
36
- * over HTTP (its latest catalogue). Throws if neither resolves.
41
+ * The model to route a request against, built on first use and cached. The
42
+ * requested `(publisher, package, version)` decides local vs remote: a package
43
+ * present in the workspace is served from disk (`loadServerModel`); anything
44
+ * else is fetched as just that package + closure (`loadResourceModel`). A bare
45
+ * publisher (root page) uses the workspace if it has ANY of that publisher's
46
+ * packages, else the publisher's fetched catalogue.
37
47
  */
38
- modelFor(publisher: string): Promise<ServerModel>;
48
+ modelFor(publisher: string, pkg?: string, version?: string): Promise<ServerModel>;
39
49
  /**
40
50
  * Route one publisher-first path:
41
51
  * - `/` → a landing page (no single publisher to show);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "3.63.0",
3
+ "version": "3.64.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",
@@ -122,7 +122,7 @@
122
122
  "yaml-parser"
123
123
  ],
124
124
  "dependencies": {
125
- "@kanonak-protocol/types": "^3.63.0",
125
+ "@kanonak-protocol/types": "^3.64.0",
126
126
  "ignore": "^7.0.5",
127
127
  "js-yaml": "^4.1.0",
128
128
  "yaml": "^2.7.0"