@kanonak-protocol/sdk 6.8.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/browser.d.ts +2 -0
  2. package/dist/browser.js +1 -1
  3. package/dist/{chunk-IT37WOHT.js → chunk-4NTZY2KP.js} +1 -1
  4. package/dist/chunk-7PTZF5LK.js +1 -0
  5. package/dist/{chunk-AZFLKLPB.js → chunk-A4OVTNMT.js} +1 -1
  6. package/dist/{chunk-Q2ZUKZEU.js → chunk-A5EAI5ZU.js} +1 -1
  7. package/dist/chunk-AEH3NZLH.js +3 -0
  8. package/dist/chunk-BA5J2DKJ.js +0 -0
  9. package/dist/{chunk-2GV6GXRF.js → chunk-C5HHCD6P.js} +1 -1
  10. package/dist/{chunk-FKLZDYWF.js → chunk-IXCD4K3K.js} +1 -1
  11. package/dist/{chunk-FCRP7KXR.js → chunk-IZBZDLCX.js} +1 -1
  12. package/dist/chunk-PC3DHZGV.js +1 -0
  13. package/dist/{chunk-PXUSA72Q.js → chunk-RFSARH5S.js} +1 -1
  14. package/dist/chunk-RXIKK3KZ.js +1 -0
  15. package/dist/chunk-VAZY57HJ.js +1 -0
  16. package/dist/chunk-YEUSFSC7.js +1 -0
  17. package/dist/filtering/GitIgnoreFilter.d.ts +25 -1
  18. package/dist/filtering/IGitIgnoreFilter.d.ts +3 -0
  19. package/dist/filtering/index.js +1 -1
  20. package/dist/index.d.ts +3 -3
  21. package/dist/index.js +3 -3
  22. package/dist/lock/VersionIndex.d.ts +97 -0
  23. package/dist/lock/VersionIndexIO.d.ts +4 -0
  24. package/dist/lock/index.d.ts +3 -0
  25. package/dist/parsing/index.js +1 -1
  26. package/dist/producer/index.js +1 -1
  27. package/dist/reasoning/index.js +1 -1
  28. package/dist/repositories/InMemoryKanonakDocumentRepository.d.ts +8 -1
  29. package/dist/repositories/PublisherIndex.d.ts +17 -10
  30. package/dist/repositories/browser.js +1 -1
  31. package/dist/repositories/buildLocalFirstRepository.d.ts +25 -3
  32. package/dist/repositories/index.d.ts +1 -1
  33. package/dist/repositories/index.js +1 -1
  34. package/dist/search/index.js +1 -1
  35. package/dist/server/assembleModel.d.ts +1 -0
  36. package/dist/server/index.d.ts +4 -0
  37. package/dist/server/index.js +19 -19
  38. package/dist/server/route.d.ts +1 -1
  39. package/dist/server/types.d.ts +6 -0
  40. package/dist/server/workspacePackages.d.ts +26 -0
  41. package/dist/server/workspaceVersionIndex.d.ts +23 -0
  42. package/dist/transformations/index.js +1 -1
  43. package/dist/validation/index.js +1 -1
  44. package/package.json +2 -2
  45. package/dist/chunk-3ABGZHKM.js +0 -1
  46. package/dist/chunk-6CI3HTKF.js +0 -1
  47. package/dist/chunk-F4UHQVGA.js +0 -1
  48. package/dist/chunk-NYCGUDVW.js +0 -1
  49. package/dist/chunk-ODIECDN7.js +0 -1
  50. package/dist/chunk-X2URIXH7.js +0 -2
@@ -1,2 +0,0 @@
1
- import{a as m}from"./chunk-SC5M74NM.js";import{b as l,d as A,e as p}from"./chunk-5FVUBF7N.js";import{a as E}from"./chunk-6CI3HTKF.js";import{e as f,g as R,j as C,m as x}from"./chunk-7IMLHHSA.js";var j="@kanonak-protocol/sdk (+https://kanonak.org)",F=j;function ee(o){F=o}function te(){return F}function g(o){let e;try{e=typeof o=="string"?new URL(o):o}catch{throw new Error(`Kanonak requires an absolute https:// URL \u2014 got an unparseable or relative URL: ${String(o)}`)}if(e.protocol!=="https:")throw new Error(`Kanonak requires HTTPS \u2014 refusing to fetch ${e.href} (only https:// is supported).`)}var M=new Set([429,502,503,504]),B=4,q=500,_=2e4;function h(o,e){g(o);let t=new Headers(e?.headers);return t.has("User-Agent")||t.set("User-Agent",F),W(o,{...e,headers:t})}var d=B;function ne(o){d=Math.max(0,o)}async function W(o,e){let t;for(let r=0;r<=d;r++){let n;try{n=await fetch(o,e)}catch(a){if(t=a,r>=d)throw a;await b(T(r,void 0));continue}if(!M.has(n.status)||r>=d)return n;let s=A(n.headers.get("retry-after"));if(s!==void 0&&s*1e3>_)return n;await b(T(r,s))}throw t??new Error("kanonakFetch: exhausted retries")}function T(o,e){if(e!==void 0)return e*1e3;let t=Math.min(_,q*2**o);return Math.floor(t/2+Math.random()*(t/2))}function b(o){return new Promise(e=>setTimeout(e,o))}var k="*",P=["publisher","package","version"];function D(o,e,t){let r=t?` in ${t}`:"";if(typeof o!="object"||o===null||Array.isArray(o))throw new Error(`${e}${r} must be an object mapping a publisher, or "${k}", to a package URL template`);let n={};for(let[s,a]of Object.entries(o)){let i=s===k;if(!i&&!V(s))throw new Error(`${e}${r} names "${s}", which is not a publisher (a publisher is a bare domain, e.g. example.org)`);n[s]=N(a,`${e}["${s}"]${r}`,i)}return Object.freeze(n)}function N(o,e,t){if(typeof o!="string"||o.trim()==="")throw new Error(`${e} must be a package URL template string`);if(!o.startsWith("https://"))throw new Error(`${e} must be an absolute https:// URL template (got "${o}")`);let r=(o.match(/\{[^{}]*\}/g)??[]).filter(a=>!P.includes(a.slice(1,-1)));if(r.length>0)throw new Error(`${e} has the unknown placeholder ${r[0]}; a package URL template takes {publisher}, {package} and {version}`);let s=(t?P:P.filter(a=>a!=="publisher")).filter(a=>!o.includes(`{${a}}`)).map(a=>`{${a}}`);if(s.length>0)throw new Error(`${e} must contain ${s.join(", ")}`+(t?", so that one template addresses every publisher's packages":"")+` (got "${o}")`);return o}function U(o,e){if(o)return Object.hasOwn(o,e)?o[e]:Object.hasOwn(o,k)?o[k]:void 0}function u(o,e,t,r){let n={publisher:e,package:t,version:r},s=o;for(let[i,c]of Object.entries(n))s=s.replaceAll(`{${i}}`,c);let a=s.match(/\{[a-z]+\}/);if(a)throw new Error(`Unresolved variable ${a[0]} in URL template: ${o}`);return g(s),s}function V(o){if(o.trim()!==o)return!1;try{let e=x(o);return e.kind==="publisher"&&e.publisher===o}catch{return!1}}var G="https://{publisher}/{package}/{version}.kan.yml",I={version:1};function he(){return{version:1}}var y=class{constructor(e){this.fetchFn=e}fetchFn;cache=new Map;getConfig(e){let t=this.cache.get(e);return t||(t=this.fetchConfig(e),this.cache.set(e,t),t.catch(()=>{this.cache.get(e)===t&&this.cache.delete(e)})),t}async fetchConfig(e){let t=`https://${e}/.well-known/kanonak.json`,r;try{r=await(this.fetchFn?this.fetchFn(t,e):h(t))}catch(a){if(a instanceof p)throw a;return I}if(r.status===404)return I;if(!r.ok)throw await l("publisher config",t,r);let n=await r.json();if(typeof n.version!="number")throw new Error(`Invalid publisher config at ${t}: missing or invalid "version" field`);let s={version:n.version};return typeof n.package_url_template=="string"&&(z(t,"package_url_template",n.package_url_template),s.package_url_template=n.package_url_template),Array.isArray(n.featured_packages)&&n.featured_packages.every(a=>typeof a=="string")&&(s.featured_packages=n.featured_packages),s}resolvePackageUrl(e,t,r,n){let s=n.package_url_template??G;return u(s,e,t,r)}};function z(o,e,t){if(!t.startsWith("https://"))throw new Error(`Invalid publisher config at ${o}: ${e} must be an absolute https:// URL template (got "${t}").`)}import K from"js-yaml";function pe(o,e,t){return o.packages[`${e}/${t}`]?.version}var Y=`# This file is generated by Kanonak CLI. Do not edit manually.
2
- `,X="sha256:";function O(o){let e=K.load(o);return!e||typeof e!="object"||e.version!=="1"?null:{version:"1",lastUpdated:e.lastUpdated??"",packages:e.packages??{}}}function me(o){let e={};for(let r of Object.keys(o.packages).sort())e[r]=o.packages[r];let t=K.dump({...o,packages:e},{lineWidth:-1,sortKeys:!1,quotingType:'"'});return Y+t}async function J(o){let e=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(o)),t=Array.from(new Uint8Array(e),r=>r.toString(16).padStart(2,"0")).join("");return`${X}${t}`}async function S(o,e,t,r){let n=await J(e);if(n!==t)throw new Error(`Integrity mismatch for ${o}: the lock declares ${t||"(no integrity)"} but the bytes from ${r} hash to ${n}.`)}var w=class{configResolver;fetchFn;packageUrlTemplates;lockCache=new Map;packageLockCache=new Map;constructor(e){this.configResolver=e?.configResolver??new y(e?.fetchFn),this.fetchFn=e?.fetchFn,this.packageUrlTemplates=e?.packageUrlTemplates?D(e.packageUrlTemplates,"packageUrlTemplates"):void 0}getConfig(e){return this.configResolver.getConfig(e)}async getPackageUrl(e,t,r){let n=U(this.packageUrlTemplates,e);if(n)return u(n,e,t,r);let s=await this.configResolver.getConfig(e);return this.configResolver.resolvePackageUrl(e,t,r,s)}lockedSourceUrl(e,t,r){let n=U(this.packageUrlTemplates,e);return n?u(n,e,t,r.version):r.resolved}async fetchLockedSource(e,t,r){let n=`${e}/${t}@${r.version}`,s=this.lockedSourceUrl(e,t,r);g(s);let a=this.fetchFn?await this.fetchFn(s,e):await h(s);if(!a.ok)throw await l(n,s,a);let i=await a.text();return await S(n,i,r.integrity,s),{url:s,content:i}}getLock(e){let t=this.lockCache.get(e);return t||(t=this.fetchLock(e),this.lockCache.set(e,t),t.catch(()=>{this.lockCache.get(e)===t&&this.lockCache.delete(e)})),t}async getPackageLockEntry(e,t){let r=`${e}/${t}`,n=this.packageLockCache.get(r);return n||(n=this.fetchLock(e,t),this.packageLockCache.set(r,n),n.catch(()=>{this.packageLockCache.get(r)===n&&this.packageLockCache.delete(r)})),(await n)?.packages[r]??null}async fetchLock(e,t){let r=t?`https://${e}/${t}/kanonak.lock`:`https://${e}/kanonak.lock`,n;try{n=this.fetchFn?await this.fetchFn(r,e):await h(r)}catch(s){if(s instanceof p)throw s;return null}if(n.status===404)return null;if(!n.ok)throw await l("publisher lock",r,n);return O(await n.text())}};import{VersionOperator as $}from"@kanonak-protocol/types/document/models/enums";function Q(o,e){let t=R(o);return t?C(t,e):!1}var H=class{parser=new E;publisherIndex;documents=new Map;contentCache=new Map;fetchFn;onFetch;getFromCache;constructor(e){this.onFetch=e?.onFetch,this.getFromCache=e?.getFromCache,this.fetchFn=e?.fetchFn,this.publisherIndex=new w({...e?.fetchFn?{fetchFn:e.fetchFn}:{},...e?.packageUrlTemplates?{packageUrlTemplates:e.packageUrlTemplates}:{}})}async getHighestCompatibleVersionAsync(e,t){if(t.versionOperator===$.Exact){let s=await this.fromMemoOrCache(e,t.packageName,f(t.version));if(s)return s}let n=(await this.publisherIndex.getLock(e))?.packages[`${e}/${t.packageName}`]??await this.publisherIndex.getPackageLockEntry(e,t.packageName)??void 0;return n&&Q(n.version,t)?this.fetchPinned(e,t.packageName,n):n&&t.versionOperator!==$.Exact?null:this.resolveByDirectFetch(e,t)}async fetchPinned(e,t,r){let n=r.version,s=`${e}/${t}@${n}`,a=await this.fromMemoOrCache(e,t,n);if(a)return a;let{content:i}=await this.publisherIndex.fetchLockedSource(e,t,r),c=this.parser.parse(i);return m(c,e,t,n),this.onFetch&&await this.onFetch(e,t,n,i),this.documents.set(s,c),this.contentCache.set(s,i),c}async fromMemoOrCache(e,t,r){let n=`${e}/${t}@${r}`,s=this.documents.get(n);if(s)return s;if(!this.getFromCache)return null;let a=await this.getFromCache(e,t,r);if(a==null)return null;let i;try{i=this.parser.parse(a),m(i,e,t,r)}catch(c){throw new Error(`Cached content for ${n} is not a usable copy of that package \u2014 refusing to fall through to a fetch that would hide it. ${c.message}`,{cause:c})}return this.documents.set(n,i),this.contentCache.set(n,a),i}async resolveByDirectFetch(e,t){let r=t.packageName,s=t.versionOperator===$.Exact?await this.publisherIndex.getPackageUrl(e,r,f(t.version)):`https://${e}/${r}.kan.yml`,a=await this.fetchFollowing(s,e);if(!a)return null;let i=this.parser.parse(a.content),c=i.metadata.namespace_;if(!c||!c.version)throw new Error(`Producer origin returned a package with no namespace/version for ${e}/${r}`);let v=f(c.version);m(i,e,r,v);let L=`${e}/${r}@${v}`;return this.onFetch&&await this.onFetch(e,r,v,a.content),this.documents.set(L,i),this.contentCache.set(L,a.content),i}async fetchFollowing(e,t,r=4){let n=e;for(let s=0;s<r;s++){g(n);let a=this.fetchFn?await this.fetchFn(n,t):await h(n,{redirect:"manual"});if(a.status===301||a.status===302){let i=a.headers.get("location");if(!i)throw new Error(`Redirect with no Location header from ${n}`);n=new URL(i,n).toString();continue}if(a.status===404)return null;if(!a.ok)throw await l("Kanonak package",n,a);return{url:n,content:await a.text()}}throw new Error(`Too many redirects resolving ${e}`)}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(e){return this.documents.get(e)??null}async getDocumentsByNamespaceAsync(e,t){return Array.from(this.documents.values()).filter(r=>{let n=r.metadata.namespace_;return n&&n.publisher===e&&n.package_===t})}async saveDocumentAsync(e,t){throw new Error("HttpKanonakDocumentRepository is read-only")}async deleteDocumentAsync(e){throw new Error("HttpKanonakDocumentRepository is read-only")}async clearNamespaceAsync(e,t){throw new Error("HttpKanonakDocumentRepository is read-only")}async getAllDocumentReferencesAsync(){return[]}async getDocumentContentAsync(e){return this.contentCache.get(e)??null}async getDocumentUriAsync(e){let t=e.match(/^(.+?)\/(.+?)@(.+)$/);if(!t)return null;let[,r,n,s]=t;return this.publisherIndex.getPackageUrl(r,n,s)}};export{j as a,ee as b,te as c,g as d,h as e,ne as f,k as g,D as h,N as i,U as j,u as k,he as l,y as m,pe as n,X as o,O as p,me as q,J as r,S as s,w as t,H as u};