@kanonak-protocol/sdk 1.9.0 → 2.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.
@@ -1,2 +1,2 @@
1
- var b=class{documents=new Map;documentContents=new Map;parser;constructor(e){this.parser=e}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(e){return this.documents.get(e)??null}async getDocumentsByNamespaceAsync(e,t){let r=[];for(let n of this.documents.values())n.metadata?.namespace_?.publisher===e&&n.metadata?.namespace_?.package_===t&&r.push(n);return r}async getHighestCompatibleVersionAsync(e,t){let r=[];for(let s of this.documents.values())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===t.packageName&&s.metadata?.namespace_?.version!==void 0&&r.push(s);if(r.length===0)return null;let n=r.filter(s=>{let a=s.metadata.namespace_.version;if(!a)return!1;switch(t.versionOperator){case 0:return this.versionsEqual(a,t.version);case 1:return this.isCompatibleVersion(a,t.version);case 2:return this.isMajorCompatible(a,t.version);case 3:return this.compareVersions(a,t.minVersion)>=0;default:return!1}});return n.length===0?null:(n.sort((s,a)=>{let i=s.metadata.namespace_.version,o=a.metadata.namespace_.version;return!i&&!o?0:i?o?this.compareVersions(o,i):-1:1}),n[0])}async saveDocumentAsync(e,t){this.documents.set(t,e);let r=this.parser.save(e);this.documentContents.set(t,r)}async deleteDocumentAsync(e){this.documents.delete(e),this.documentContents.delete(e)}async clearNamespaceAsync(e,t){let r=[];for(let[n,s]of this.documents.entries())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===t&&r.push(n);for(let n of r)this.documents.delete(n),this.documentContents.delete(n)}async getAllDocumentReferencesAsync(){let e=[];for(let t of this.documents.values())t.metadata?.namespace_&&e.push({identifier:t.metadata.namespace_.toString(),uri:`kanonak://${t.metadata.namespace_}`,hasParseError:!1});return e}async getDocumentContentAsync(e){let t=this.documentContents.get(e);if(t!==void 0)return t;let r=this.documents.get(e);return r!==void 0?this.parser.save(r):null}async getDocumentUriAsync(e){let t=this.documents.get(e);return t?t.metadata?.namespace_?`kanonak://${t.metadata.namespace_}`:`kanonak://${e}`:null}versionsEqual(e,t){return e.major===t.major&&e.minor===t.minor&&e.patch===t.patch}compareVersions(e,t){return e.major!==t.major?e.major-t.major:e.minor!==t.minor?e.minor-t.minor:e.patch-t.patch}isCompatibleVersion(e,t){return this.compareVersions(e,t)>=0&&e.major===t.major&&e.minor===t.minor}isMajorCompatible(e,t){return t.major===0?this.compareVersions(e,t)>=0&&e.major===0&&e.minor===t.minor:this.compareVersions(e,t)>=0&&e.major===t.major}};import*as y from"js-yaml";var d=class{parse(e){let t=this.parseWithErrors(e);if(!t.isValid){let r=t.errors[0];throw new Error(`YAML parse error at line ${r.line}, column ${r.column}: ${r.message}`)}return t.document}parseWithErrors(e){let t=[],r;try{e=e.replace(/^\uFEFF/,"");let n=y.load(e);if(!n||typeof n!="object")return r={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:r,errors:t,isValid:!0};let s=this.extractMetadata(n),a=this.extractBody(n,s);return r={metadata:s,body:a,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:r,errors:t,isValid:!0}}catch(n){let s=n,a={message:s.message||"Unknown parse error",line:s.mark?.line??0,column:s.mark?.column??0,errorType:s.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${s.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${s.mark?.line??0}: ${s.message||"Unknown parse error"}`};return t.push(a),{document:void 0,errors:t,isValid:!1}}}save(e){let t={};if(e.metadata.namespace_){let r=e.metadata.namespace_,n={type:"Package",publisher:r.publisher};r.version&&(n.version=`${r.version.major}.${r.version.minor}.${r.version.patch}`),e.metadata.imports&&(n.imports=this.serializeImports(e.metadata.imports)),t[r.package_]=n}return Object.assign(t,e.body),y.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let t=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!t)return[];let r=[];for(let n of Object.values(t))r.push(...n);return r},enumerable:!0,configurable:!0}),e}createVersion(e,t,r){return{major:e,minor:t,patch:r,toString:()=>`${e}.${t}.${r}`,equals:s=>!s||typeof s!="object"?!1:s.major===e&&s.minor===t&&s.patch===r,getHashCode:()=>e<<20|t<<10|r,compareTo:s=>e!==s.major?e-s.major:t!==s.minor?t-s.minor:r-s.patch}}extractMetadata(e){let t=this.createEmptyMetadata();for(let[r,n]of Object.entries(e))if(n&&typeof n=="object"&&n.type==="Package"){t.type_="Package";let s=r,a=n.publisher,i=n.version?this.parseVersion(n.version):void 0;return a&&s&&(t.namespace_={publisher:a,package_:s,version:i,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:o=>!o||typeof o!="object"?!1:o.publisher===a&&o.package_===s&&(!i||!o.version||i.equals(o.version)),getHashCode:()=>{let o=0;for(let c=0;c<a.length;c++)o=(o<<5)-o+a.charCodeAt(c);for(let c=0;c<s.length;c++)o=(o<<5)-o+s.charCodeAt(c);return o|0}}),n.imports&&Array.isArray(n.imports)&&(t.imports=this.parseImportsV3(n.imports)),this.addAllImportsGetter(t)}if(e.kanonak&&typeof e.kanonak=="object"){let r=e.kanonak;return(r.publisher||r.package||r.version)&&(t.namespace_=this.parseNamespace(r)),r.imports&&typeof r.imports=="object"&&(t.imports=this.parseImportsLegacy(r.imports)),this.addAllImportsGetter(t)}return t}extractBody(e,t){let r={},n;for(let[s,a]of Object.entries(e))if(a&&typeof a=="object"&&a.type==="Package"){n=s;break}for(let[s,a]of Object.entries(e))s!==n&&s!=="kanonak"&&s!=="namespace"&&s!=="imports"&&(r[s]=a);return r}parseNamespace(e){if(typeof e=="string"){let s=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(s){let a=s[3]?this.parseVersion(s[3]):this.createVersion(1,0,0);return{publisher:s[1],package_:s[2],version:a,toString:()=>e,equals:i=>!i||typeof i!="object"?!1:i.publisher===s[1]&&i.package_===s[2]&&(!a||!i.version||a.equals(i.version)),getHashCode:()=>{let i=0;for(let o=0;o<s[1].length;o++)i=(i<<5)-i+s[1].charCodeAt(o);for(let o=0;o<s[2].length;o++)i=(i<<5)-i+s[2].charCodeAt(o);return i|0}}}}let t=e.publisher||"",r=e.package||"",n=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:t,package_:r,version:n,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:s=>!s||typeof s!="object"?!1:s.publisher===t&&s.package_===r&&(!n||!s.version||n.equals(s.version)),getHashCode:()=>{let s=0;for(let a=0;a<t.length;a++)s=(s<<5)-s+t.charCodeAt(a);for(let a=0;a<r.length;a++)s=(s<<5)-s+r.charCodeAt(a);return s|0}}}parseVersion(e){if(typeof e=="string"){let t=e.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let t={};for(let r of e)if(!(!r||typeof r!="object"))if(r.packages&&Array.isArray(r.packages)){let n=r.publisher;if(!n)throw new Error("PublisherImport requires 'publisher' property");t[n]||(t[n]=[]);for(let s of r.packages){if(!s||typeof s!="object")continue;let a=this.parseImportFromEmbeddedObject(s,n);t[n].push(a)}}else{let n=this.parseImportFromEmbeddedObject(r,r.publisher),s=n.publisher||"";t[s]||(t[s]=[]),t[s].push(n)}return t}parseImportsLegacy(e){let t={};for(let[r,n]of Object.entries(e))Array.isArray(n)&&(t[r]=n.map(s=>this.parseImport(s,r)));return t}parseImportFromEmbeddedObject(e,t){let r=e.package;if(!r)throw new Error("Import requires 'package' property");let n=e.match;if(!n)throw new Error("Import requires 'match' property");let s=e.version;if(!s)throw new Error("Import requires 'version' property");let a=this.parseVersion(s),i=this.parseVersionOperator(n),o=this.calculateMaxVersion(n,a),c=e.alias;return{package_:`${r} ${n} ${a.toString()}`,publisher:t,packageName:r,versionOperator:i,version:a,alias:c,minVersion:a,maxVersion:o,toEmbeddedObject:()=>{let p={package:r,match:n,version:a.toString()};return c&&(p.alias=c),p},toString:()=>c?`${r} ${n} ${a.toString()} as ${c}`:`${r} ${n} ${a.toString()}`}}parseImport(e,t){if(typeof e=="string"){let o=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(o){let p=o[1].trim(),m=o[2],l=this.parseVersion(o[3].trim()),h=o[4].trim(),v=this.parseVersionOperator(m),x=this.calculateMaxVersion(m,l);return{package_:e,publisher:t,packageName:p,versionOperator:v,version:l,alias:h,minVersion:l,maxVersion:x,toEmbeddedObject:()=>{let $={package:p,match:m,version:l.toString()};return h&&($.alias=h),$},toString:()=>`${p} ${m} ${l.toString()} as ${h}`}}let c=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let p=c[1].trim(),m=c[2],l=this.parseVersion(c[3].trim()),h=this.parseVersionOperator(m),v=this.calculateMaxVersion(m,l);return{package_:e,publisher:t,packageName:p,versionOperator:h,version:l,alias:void 0,minVersion:l,maxVersion:v,toEmbeddedObject:()=>({package:p,match:m,version:l.toString()}),toString:()=>`${p} ${m} ${l.toString()}`}}}let r=this.parseVersionOperator(e.operator||"~"),n=this.parseVersion(e.version||"1.0.0"),s=e.packageName||e.package||"",a=["=","~","^","*"][r],i=this.calculateMaxVersion(e.operator||"~",n);return{package_:e.package||"",publisher:t,packageName:s,versionOperator:r,version:n,alias:e.alias,minVersion:n,maxVersion:i,toEmbeddedObject:()=>{let o={package:s,match:a,version:n.toString()};return e.alias&&(o.alias=e.alias),o},toString:()=>`${s} ${a} ${n.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,t){switch(e){case"~":return this.createVersion(t.major,t.minor+1,0);case"^":return t.major===0?this.createVersion(0,t.minor+1,0):this.createVersion(t.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let t=[];for(let[r,n]of Object.entries(e)){let s={publisher:r,packages:n.map(a=>{let i=["=","~","^","*"][a.versionOperator],o={package:a.packageName,match:i,version:`${a.version.major}.${a.version.minor}.${a.version.patch}`};return a.alias&&(o.alias=a.alias),o})};t.push(s)}return t}};import{VersionOperator as k}from"@kanonak-protocol/types/document/models/enums";var C="https://{publisher}/index.txt",w="https://{publisher}/{package}/{version}.kan.yml",V={version:1},f=class{cache=new Map;async getConfig(e){let t=this.cache.get(e);if(t)return t;let r=await this.fetchConfig(e);return this.cache.set(e,r),r}async fetchConfig(e){let t=`https://${e}/.well-known/kanonak.json`,r;try{r=await fetch(t)}catch{return V}if(r.status===404)return V;if(!r.ok)throw new Error(`Failed to fetch publisher config: ${t} (${r.status} ${r.statusText})`);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.index=="string"&&(s.index=n.index),typeof n.package=="string"&&(s.package=n.package),(n.auth==="none"||n.auth==="oauth"||n.auth==="bearer")&&(s.auth=n.auth),s}resolveIndexUrl(e,t){let r=t.index??C;return I(r,{publisher:e})}resolvePackageUrl(e,t,r,n){let s=n.package??w;return I(s,{publisher:e,package:t,version:r})}};function I(u,e){let t=u;for(let[n,s]of Object.entries(e))t=t.replaceAll(`{${n}}`,s);let r=t.match(/\{[a-z]+\}/);if(r)throw new Error(`Unresolved variable ${r[0]} in URL template: ${u}`);return t}var g=class u{indexCache=new Map;configResolver;fetchFn;constructor(e){this.configResolver=e?.configResolver??new f,this.fetchFn=e?.fetchFn}async resolveVersion(e,t){let r=await this.getPackageVersions(e,t.packageName);if(r.length===0)return null;let n=r.filter(s=>this.isVersionCompatible(s,t.version,t.versionOperator));return n.length===0?null:(n.sort((s,a)=>this.compareVersionStrings(a,s)),n[0])}async getHighestVersion(e,t){let r=await this.getPackageVersions(e,t);return r.length===0?null:[...r].sort((s,a)=>this.compareVersionStrings(a,s))[0]}async getPackageUrl(e,t,r){let n=await this.configResolver.getConfig(e);return this.configResolver.resolvePackageUrl(e,t,r,n)}async getPackageVersions(e,t){let r=this.indexCache.get(e);return r||(r=await this.fetchIndex(e),this.indexCache.set(e,r)),r.get(t)??[]}async fetchIndex(e){let t=await this.configResolver.getConfig(e),r=this.configResolver.resolveIndexUrl(e,t),n=this.fetchFn?await this.fetchFn(r,e):await fetch(r);if(!n.ok)throw new Error(`Failed to fetch publisher index: ${r} (${n.status} ${n.statusText})`);let s=await n.text();return u.parseIndex(s)}static parseIndex(e){let t=new Map;for(let r of e.split(`
2
- `)){let n=r.trim();if(!n||n.startsWith("#"))continue;let s=n.indexOf("/");if(s===-1)continue;let a=n.substring(0,s),i=n.substring(s+1);if(!a||!i)continue;let o=t.get(a);o?o.push(i):t.set(a,[i])}return t}isVersionCompatible(e,t,r){let n=u.parseVersion(e);if(!n)return!1;switch(r){case k.Any:return!0;case k.Exact:return n.major===t.major&&n.minor===t.minor&&n.patch===t.patch;case k.Compatible:return n.major===t.major&&n.minor===t.minor&&n.patch>=t.patch;case k.Major:return n.major!==t.major?!1:n.minor>t.minor?!0:n.minor===t.minor?n.patch>=t.patch:!1;default:return!1}}static parseVersion(e){let t=e.split(".");if(t.length<2)return null;let r=parseInt(t[0],10),n=parseInt(t[1],10),s=t.length>=3?parseInt(t[2],10):0;return isNaN(r)||isNaN(n)||isNaN(s)?null:{major:r,minor:n,patch:s}}compareVersionStrings(e,t){let r=u.parseVersion(e),n=u.parseVersion(t);return!r&&!n?0:r?n?r.major!==n.major?r.major-n.major:r.minor!==n.minor?r.minor-n.minor:r.patch-n.patch:1:-1}};var P=class{parser=new d;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=e?.fetchFn?new g({fetchFn:e.fetchFn}):new g}async getHighestCompatibleVersionAsync(e,t){let r=await this.publisherIndex.resolveVersion(e,t);if(!r)return null;let n=`${e}/${t.packageName}@${r}`,s=this.documents.get(n);if(s)return s;if(this.getFromCache){let p=this.getFromCache(e,t.packageName,r);if(p){let m=this.parser.parse(p);return this.documents.set(n,m),this.contentCache.set(n,p),m}}let a=await this.publisherIndex.getPackageUrl(e,t.packageName,r),i=this.fetchFn?await this.fetchFn(a,e):await fetch(a);if(!i.ok)throw new Error(`Failed to fetch Kanonak package: ${a} (${i.status} ${i.statusText})`);let o=await i.text();this.onFetch&&this.onFetch(e,t.packageName,r,o);let c=this.parser.parse(o);return this.documents.set(n,c),this.contentCache.set(n,o),c}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{P as HttpKanonakDocumentRepository,b as InMemoryKanonakDocumentRepository,f as PublisherConfigResolver,g as PublisherIndex};
1
+ var b=class{documents=new Map;documentContents=new Map;parser;constructor(e){this.parser=e}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(e){return this.documents.get(e)??null}async getDocumentsByNamespaceAsync(e,t){let r=[];for(let n of this.documents.values())n.metadata?.namespace_?.publisher===e&&n.metadata?.namespace_?.package_===t&&r.push(n);return r}async getHighestCompatibleVersionAsync(e,t){let r=[];for(let s of this.documents.values())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===t.packageName&&s.metadata?.namespace_?.version!==void 0&&r.push(s);if(r.length===0)return null;let n=r.filter(s=>{let a=s.metadata.namespace_.version;if(!a)return!1;switch(t.versionOperator){case 0:return this.versionsEqual(a,t.version);case 1:return this.isCompatibleVersion(a,t.version);case 2:return this.isMajorCompatible(a,t.version);case 3:return this.compareVersions(a,t.minVersion)>=0;default:return!1}});return n.length===0?null:(n.sort((s,a)=>{let i=s.metadata.namespace_.version,o=a.metadata.namespace_.version;return!i&&!o?0:i?o?this.compareVersions(o,i):-1:1}),n[0])}async saveDocumentAsync(e,t){this.documents.set(t,e);let r=this.parser.save(e);this.documentContents.set(t,r)}async deleteDocumentAsync(e){this.documents.delete(e),this.documentContents.delete(e)}async clearNamespaceAsync(e,t){let r=[];for(let[n,s]of this.documents.entries())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===t&&r.push(n);for(let n of r)this.documents.delete(n),this.documentContents.delete(n)}async getAllDocumentReferencesAsync(){let e=[];for(let t of this.documents.values())t.metadata?.namespace_&&e.push({identifier:t.metadata.namespace_.toString(),uri:`kanonak://${t.metadata.namespace_}`,hasParseError:!1});return e}async getDocumentContentAsync(e){let t=this.documentContents.get(e);if(t!==void 0)return t;let r=this.documents.get(e);return r!==void 0?this.parser.save(r):null}async getDocumentUriAsync(e){let t=this.documents.get(e);return t?t.metadata?.namespace_?`kanonak://${t.metadata.namespace_}`:`kanonak://${e}`:null}versionsEqual(e,t){return e.major===t.major&&e.minor===t.minor&&e.patch===t.patch}compareVersions(e,t){return e.major!==t.major?e.major-t.major:e.minor!==t.minor?e.minor-t.minor:e.patch-t.patch}isCompatibleVersion(e,t){return this.compareVersions(e,t)>=0&&e.major===t.major&&e.minor===t.minor}isMajorCompatible(e,t){return t.major===0?this.compareVersions(e,t)>=0&&e.major===0&&e.minor===t.minor:this.compareVersions(e,t)>=0&&e.major===t.major}};import*as y from"js-yaml";var d=class{parse(e){let t=this.parseWithErrors(e);if(!t.isValid){let r=t.errors[0];throw new Error(`YAML parse error at line ${r.line}, column ${r.column}: ${r.message}`)}return t.document}parseWithErrors(e){let t=[],r;try{e=e.replace(/^\uFEFF/,"");let n=y.load(e);if(!n||typeof n!="object")return r={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:r,errors:t,isValid:!0};let s=this.extractMetadata(n),a=this.extractBody(n,s);return r={metadata:s,body:a,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:r,errors:t,isValid:!0}}catch(n){let s=n,a={message:s.message||"Unknown parse error",line:s.mark?.line??0,column:s.mark?.column??0,errorType:s.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${s.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${s.mark?.line??0}: ${s.message||"Unknown parse error"}`};return t.push(a),{document:void 0,errors:t,isValid:!1}}}save(e){let t={};if(e.metadata.namespace_){let r=e.metadata.namespace_,n={type:"Package",publisher:r.publisher};r.version&&(n.version=`${r.version.major}.${r.version.minor}.${r.version.patch}`),e.metadata.imports&&(n.imports=this.serializeImports(e.metadata.imports)),t[r.package_]=n}return Object.assign(t,e.body),y.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let t=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!t)return[];let r=[];for(let n of Object.values(t))r.push(...n);return r},enumerable:!0,configurable:!0}),e}createVersion(e,t,r){return{major:e,minor:t,patch:r,toString:()=>`${e}.${t}.${r}`,equals:s=>!s||typeof s!="object"?!1:s.major===e&&s.minor===t&&s.patch===r,getHashCode:()=>e<<20|t<<10|r,compareTo:s=>e!==s.major?e-s.major:t!==s.minor?t-s.minor:r-s.patch}}extractMetadata(e){let t=this.createEmptyMetadata();for(let[r,n]of Object.entries(e))if(n&&typeof n=="object"&&n.type==="Package"){t.type_="Package";let s=r,a=n.publisher,i=n.version?this.parseVersion(n.version):void 0;return a&&s&&(t.namespace_={publisher:a,package_:s,version:i,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:o=>!o||typeof o!="object"?!1:o.publisher===a&&o.package_===s&&(!i||!o.version||i.equals(o.version)),getHashCode:()=>{let o=0;for(let c=0;c<a.length;c++)o=(o<<5)-o+a.charCodeAt(c);for(let c=0;c<s.length;c++)o=(o<<5)-o+s.charCodeAt(c);return o|0}}),n.imports&&Array.isArray(n.imports)&&(t.imports=this.parseImportsV3(n.imports)),this.addAllImportsGetter(t)}if(e.kanonak&&typeof e.kanonak=="object"){let r=e.kanonak;return(r.publisher||r.package||r.version)&&(t.namespace_=this.parseNamespace(r)),r.imports&&typeof r.imports=="object"&&(t.imports=this.parseImportsLegacy(r.imports)),this.addAllImportsGetter(t)}return t}extractBody(e,t){let r={},n;for(let[s,a]of Object.entries(e))if(a&&typeof a=="object"&&a.type==="Package"){n=s;break}for(let[s,a]of Object.entries(e))s!==n&&s!=="kanonak"&&s!=="namespace"&&s!=="imports"&&(r[s]=a);return r}parseNamespace(e){if(typeof e=="string"){let s=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(s){let a=s[3]?this.parseVersion(s[3]):this.createVersion(1,0,0);return{publisher:s[1],package_:s[2],version:a,toString:()=>e,equals:i=>!i||typeof i!="object"?!1:i.publisher===s[1]&&i.package_===s[2]&&(!a||!i.version||a.equals(i.version)),getHashCode:()=>{let i=0;for(let o=0;o<s[1].length;o++)i=(i<<5)-i+s[1].charCodeAt(o);for(let o=0;o<s[2].length;o++)i=(i<<5)-i+s[2].charCodeAt(o);return i|0}}}}let t=e.publisher||"",r=e.package||"",n=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:t,package_:r,version:n,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:s=>!s||typeof s!="object"?!1:s.publisher===t&&s.package_===r&&(!n||!s.version||n.equals(s.version)),getHashCode:()=>{let s=0;for(let a=0;a<t.length;a++)s=(s<<5)-s+t.charCodeAt(a);for(let a=0;a<r.length;a++)s=(s<<5)-s+r.charCodeAt(a);return s|0}}}parseVersion(e){if(typeof e=="string"){let t=e.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let t={};for(let r of e)if(!(!r||typeof r!="object"))if(r.packages&&Array.isArray(r.packages)){let n=r.publisher;if(!n)throw new Error("PublisherImport requires 'publisher' property");t[n]||(t[n]=[]);for(let s of r.packages){if(!s||typeof s!="object")continue;let a=this.parseImportFromEmbeddedObject(s,n);t[n].push(a)}}else{let n=this.parseImportFromEmbeddedObject(r,r.publisher),s=n.publisher||"";t[s]||(t[s]=[]),t[s].push(n)}return t}parseImportsLegacy(e){let t={};for(let[r,n]of Object.entries(e))Array.isArray(n)&&(t[r]=n.map(s=>this.parseImport(s,r)));return t}parseImportFromEmbeddedObject(e,t){let r=e.package;if(!r)throw new Error("Import requires 'package' property");let n=e.match;if(!n)throw new Error("Import requires 'match' property");let s=e.version;if(!s)throw new Error("Import requires 'version' property");let a=this.parseVersion(s),i=this.parseVersionOperator(n),o=this.calculateMaxVersion(n,a),c=e.alias;return{package_:`${r} ${n} ${a.toString()}`,publisher:t,packageName:r,versionOperator:i,version:a,alias:c,minVersion:a,maxVersion:o,toEmbeddedObject:()=>{let m={package:r,match:n,version:a.toString()};return c&&(m.alias=c),m},toString:()=>c?`${r} ${n} ${a.toString()} as ${c}`:`${r} ${n} ${a.toString()}`}}parseImport(e,t){if(typeof e=="string"){let o=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(o){let m=o[1].trim(),p=o[2],l=this.parseVersion(o[3].trim()),h=o[4].trim(),v=this.parseVersionOperator(p),x=this.calculateMaxVersion(p,l);return{package_:e,publisher:t,packageName:m,versionOperator:v,version:l,alias:h,minVersion:l,maxVersion:x,toEmbeddedObject:()=>{let V={package:m,match:p,version:l.toString()};return h&&(V.alias=h),V},toString:()=>`${m} ${p} ${l.toString()} as ${h}`}}let c=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let m=c[1].trim(),p=c[2],l=this.parseVersion(c[3].trim()),h=this.parseVersionOperator(p),v=this.calculateMaxVersion(p,l);return{package_:e,publisher:t,packageName:m,versionOperator:h,version:l,alias:void 0,minVersion:l,maxVersion:v,toEmbeddedObject:()=>({package:m,match:p,version:l.toString()}),toString:()=>`${m} ${p} ${l.toString()}`}}}let r=this.parseVersionOperator(e.operator||"~"),n=this.parseVersion(e.version||"1.0.0"),s=e.packageName||e.package||"",a=["=","~","^","*"][r],i=this.calculateMaxVersion(e.operator||"~",n);return{package_:e.package||"",publisher:t,packageName:s,versionOperator:r,version:n,alias:e.alias,minVersion:n,maxVersion:i,toEmbeddedObject:()=>{let o={package:s,match:a,version:n.toString()};return e.alias&&(o.alias=e.alias),o},toString:()=>`${s} ${a} ${n.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,t){switch(e){case"~":return this.createVersion(t.major,t.minor+1,0);case"^":return t.major===0?this.createVersion(0,t.minor+1,0):this.createVersion(t.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let t=[];for(let[r,n]of Object.entries(e)){let s={publisher:r,packages:n.map(a=>{let i=["=","~","^","*"][a.versionOperator],o={package:a.packageName,match:i,version:`${a.version.major}.${a.version.minor}.${a.version.patch}`};return a.alias&&(o.alias=a.alias),o})};t.push(s)}return t}};import{VersionOperator as k}from"@kanonak-protocol/types/document/models/enums";var C="https://{publisher}/index.txt",w="https://{publisher}/{package}/{version}.kan.yml",$={version:1},f=class{cache=new Map;async getConfig(e){let t=this.cache.get(e);if(t)return t;let r=await this.fetchConfig(e);return this.cache.set(e,r),r}async fetchConfig(e){let t=`https://${e}/.well-known/kanonak.json`,r;try{r=await fetch(t)}catch{return $}if(r.status===404)return $;if(!r.ok)throw new Error(`Failed to fetch publisher config: ${t} (${r.status} ${r.statusText})`);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.index=="string"&&(s.index=n.index),typeof n.package=="string"&&(s.package=n.package),(n.auth==="none"||n.auth==="oauth"||n.auth==="bearer")&&(s.auth=n.auth),s}resolveIndexUrl(e,t){let r=t.index??C;return I(r,{publisher:e})}resolvePackageUrl(e,t,r,n){let s=n.package??w;return I(s,{publisher:e,package:t,version:r})}};function I(u,e){let t=u;for(let[n,s]of Object.entries(e))t=t.replaceAll(`{${n}}`,s);let r=t.match(/\{[a-z]+\}/);if(r)throw new Error(`Unresolved variable ${r[0]} in URL template: ${u}`);return t}var g=class u{indexCache=new Map;configResolver;fetchFn;constructor(e){this.configResolver=e?.configResolver??new f,this.fetchFn=e?.fetchFn}async resolveVersion(e,t){let r=await this.getPackageVersions(e,t.packageName);if(r.length===0)return null;let n=r.filter(s=>this.isVersionCompatible(s,t.version,t.versionOperator));return n.length===0?null:(n.sort((s,a)=>this.compareVersionStrings(a,s)),n[0])}async getHighestVersion(e,t){let r=await this.getPackageVersions(e,t);return r.length===0?null:[...r].sort((s,a)=>this.compareVersionStrings(a,s))[0]}async listLatestPackages(e){let t=this.indexCache.get(e);t||(t=await this.fetchIndex(e),this.indexCache.set(e,t));let r=[];for(let[n,s]of t){if(s.length===0)continue;let a=[...s].sort((i,o)=>this.compareVersionStrings(o,i));r.push({packageName:n,version:a[0]})}return r.sort((n,s)=>n.packageName.localeCompare(s.packageName)),r}async getPackageUrl(e,t,r){let n=await this.configResolver.getConfig(e);return this.configResolver.resolvePackageUrl(e,t,r,n)}async getPackageVersions(e,t){let r=this.indexCache.get(e);return r||(r=await this.fetchIndex(e),this.indexCache.set(e,r)),r.get(t)??[]}async fetchIndex(e){let t=await this.configResolver.getConfig(e),r=this.configResolver.resolveIndexUrl(e,t),n=this.fetchFn?await this.fetchFn(r,e):await fetch(r);if(!n.ok)throw new Error(`Failed to fetch publisher index: ${r} (${n.status} ${n.statusText})`);let s=await n.text();return u.parseIndex(s)}static parseIndex(e){let t=new Map;for(let r of e.split(`
2
+ `)){let n=r.trim();if(!n||n.startsWith("#"))continue;let s=n.indexOf("/");if(s===-1)continue;let a=n.substring(0,s),i=n.substring(s+1);if(!a||!i)continue;let o=t.get(a);o?o.push(i):t.set(a,[i])}return t}isVersionCompatible(e,t,r){let n=u.parseVersion(e);if(!n)return!1;switch(r){case k.Any:return!0;case k.Exact:return n.major===t.major&&n.minor===t.minor&&n.patch===t.patch;case k.Compatible:return n.major===t.major&&n.minor===t.minor&&n.patch>=t.patch;case k.Major:return n.major!==t.major?!1:n.minor>t.minor?!0:n.minor===t.minor?n.patch>=t.patch:!1;default:return!1}}static parseVersion(e){let t=e.split(".");if(t.length<2)return null;let r=parseInt(t[0],10),n=parseInt(t[1],10),s=t.length>=3?parseInt(t[2],10):0;return isNaN(r)||isNaN(n)||isNaN(s)?null:{major:r,minor:n,patch:s}}compareVersionStrings(e,t){let r=u.parseVersion(e),n=u.parseVersion(t);return!r&&!n?0:r?n?r.major!==n.major?r.major-n.major:r.minor!==n.minor?r.minor-n.minor:r.patch-n.patch:1:-1}};var P=class{parser=new d;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=e?.fetchFn?new g({fetchFn:e.fetchFn}):new g}async getHighestCompatibleVersionAsync(e,t){let r=await this.publisherIndex.resolveVersion(e,t);if(!r)return null;let n=`${e}/${t.packageName}@${r}`,s=this.documents.get(n);if(s)return s;if(this.getFromCache){let m=this.getFromCache(e,t.packageName,r);if(m){let p=this.parser.parse(m);return this.documents.set(n,p),this.contentCache.set(n,m),p}}let a=await this.publisherIndex.getPackageUrl(e,t.packageName,r),i=this.fetchFn?await this.fetchFn(a,e):await fetch(a);if(!i.ok)throw new Error(`Failed to fetch Kanonak package: ${a} (${i.status} ${i.statusText})`);let o=await i.text();this.onFetch&&this.onFetch(e,t.packageName,r,o);let c=this.parser.parse(o);return this.documents.set(n,c),this.contentCache.set(n,o),c}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{P as HttpKanonakDocumentRepository,b as InMemoryKanonakDocumentRepository,f as PublisherConfigResolver,g as PublisherIndex};
@@ -1,2 +1,2 @@
1
- var b=class{documents=new Map;documentContents=new Map;parser;constructor(e){this.parser=e}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(e){return this.documents.get(e)??null}async getDocumentsByNamespaceAsync(e,t){let n=[];for(let r of this.documents.values())r.metadata?.namespace_?.publisher===e&&r.metadata?.namespace_?.package_===t&&n.push(r);return n}async getHighestCompatibleVersionAsync(e,t){let n=[];for(let s of this.documents.values())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===t.packageName&&s.metadata?.namespace_?.version!==void 0&&n.push(s);if(n.length===0)return null;let r=n.filter(s=>{let a=s.metadata.namespace_.version;if(!a)return!1;switch(t.versionOperator){case 0:return this.versionsEqual(a,t.version);case 1:return this.isCompatibleVersion(a,t.version);case 2:return this.isMajorCompatible(a,t.version);case 3:return this.compareVersions(a,t.minVersion)>=0;default:return!1}});return r.length===0?null:(r.sort((s,a)=>{let o=s.metadata.namespace_.version,i=a.metadata.namespace_.version;return!o&&!i?0:o?i?this.compareVersions(i,o):-1:1}),r[0])}async saveDocumentAsync(e,t){this.documents.set(t,e);let n=this.parser.save(e);this.documentContents.set(t,n)}async deleteDocumentAsync(e){this.documents.delete(e),this.documentContents.delete(e)}async clearNamespaceAsync(e,t){let n=[];for(let[r,s]of this.documents.entries())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===t&&n.push(r);for(let r of n)this.documents.delete(r),this.documentContents.delete(r)}async getAllDocumentReferencesAsync(){let e=[];for(let t of this.documents.values())t.metadata?.namespace_&&e.push({identifier:t.metadata.namespace_.toString(),uri:`kanonak://${t.metadata.namespace_}`,hasParseError:!1});return e}async getDocumentContentAsync(e){let t=this.documentContents.get(e);if(t!==void 0)return t;let n=this.documents.get(e);return n!==void 0?this.parser.save(n):null}async getDocumentUriAsync(e){let t=this.documents.get(e);return t?t.metadata?.namespace_?`kanonak://${t.metadata.namespace_}`:`kanonak://${e}`:null}versionsEqual(e,t){return e.major===t.major&&e.minor===t.minor&&e.patch===t.patch}compareVersions(e,t){return e.major!==t.major?e.major-t.major:e.minor!==t.minor?e.minor-t.minor:e.patch-t.patch}isCompatibleVersion(e,t){return this.compareVersions(e,t)>=0&&e.major===t.major&&e.minor===t.minor}isMajorCompatible(e,t){return t.major===0?this.compareVersions(e,t)>=0&&e.major===0&&e.minor===t.minor:this.compareVersions(e,t)>=0&&e.major===t.major}};import*as u from"fs/promises";import*as m from"path";import*as D from"js-yaml";var g=class{parse(e){let t=this.parseWithErrors(e);if(!t.isValid){let n=t.errors[0];throw new Error(`YAML parse error at line ${n.line}, column ${n.column}: ${n.message}`)}return t.document}parseWithErrors(e){let t=[],n;try{e=e.replace(/^\uFEFF/,"");let r=D.load(e);if(!r||typeof r!="object")return n={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:n,errors:t,isValid:!0};let s=this.extractMetadata(r),a=this.extractBody(r,s);return n={metadata:s,body:a,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:n,errors:t,isValid:!0}}catch(r){let s=r,a={message:s.message||"Unknown parse error",line:s.mark?.line??0,column:s.mark?.column??0,errorType:s.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${s.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${s.mark?.line??0}: ${s.message||"Unknown parse error"}`};return t.push(a),{document:void 0,errors:t,isValid:!1}}}save(e){let t={};if(e.metadata.namespace_){let n=e.metadata.namespace_,r={type:"Package",publisher:n.publisher};n.version&&(r.version=`${n.version.major}.${n.version.minor}.${n.version.patch}`),e.metadata.imports&&(r.imports=this.serializeImports(e.metadata.imports)),t[n.package_]=r}return Object.assign(t,e.body),D.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let t=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!t)return[];let n=[];for(let r of Object.values(t))n.push(...r);return n},enumerable:!0,configurable:!0}),e}createVersion(e,t,n){return{major:e,minor:t,patch:n,toString:()=>`${e}.${t}.${n}`,equals:s=>!s||typeof s!="object"?!1:s.major===e&&s.minor===t&&s.patch===n,getHashCode:()=>e<<20|t<<10|n,compareTo:s=>e!==s.major?e-s.major:t!==s.minor?t-s.minor:n-s.patch}}extractMetadata(e){let t=this.createEmptyMetadata();for(let[n,r]of Object.entries(e))if(r&&typeof r=="object"&&r.type==="Package"){t.type_="Package";let s=n,a=r.publisher,o=r.version?this.parseVersion(r.version):void 0;return a&&s&&(t.namespace_={publisher:a,package_:s,version:o,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:i=>!i||typeof i!="object"?!1:i.publisher===a&&i.package_===s&&(!o||!i.version||o.equals(i.version)),getHashCode:()=>{let i=0;for(let c=0;c<a.length;c++)i=(i<<5)-i+a.charCodeAt(c);for(let c=0;c<s.length;c++)i=(i<<5)-i+s.charCodeAt(c);return i|0}}),r.imports&&Array.isArray(r.imports)&&(t.imports=this.parseImportsV3(r.imports)),this.addAllImportsGetter(t)}if(e.kanonak&&typeof e.kanonak=="object"){let n=e.kanonak;return(n.publisher||n.package||n.version)&&(t.namespace_=this.parseNamespace(n)),n.imports&&typeof n.imports=="object"&&(t.imports=this.parseImportsLegacy(n.imports)),this.addAllImportsGetter(t)}return t}extractBody(e,t){let n={},r;for(let[s,a]of Object.entries(e))if(a&&typeof a=="object"&&a.type==="Package"){r=s;break}for(let[s,a]of Object.entries(e))s!==r&&s!=="kanonak"&&s!=="namespace"&&s!=="imports"&&(n[s]=a);return n}parseNamespace(e){if(typeof e=="string"){let s=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(s){let a=s[3]?this.parseVersion(s[3]):this.createVersion(1,0,0);return{publisher:s[1],package_:s[2],version:a,toString:()=>e,equals:o=>!o||typeof o!="object"?!1:o.publisher===s[1]&&o.package_===s[2]&&(!a||!o.version||a.equals(o.version)),getHashCode:()=>{let o=0;for(let i=0;i<s[1].length;i++)o=(o<<5)-o+s[1].charCodeAt(i);for(let i=0;i<s[2].length;i++)o=(o<<5)-o+s[2].charCodeAt(i);return o|0}}}}let t=e.publisher||"",n=e.package||"",r=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:t,package_:n,version:r,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:s=>!s||typeof s!="object"?!1:s.publisher===t&&s.package_===n&&(!r||!s.version||r.equals(s.version)),getHashCode:()=>{let s=0;for(let a=0;a<t.length;a++)s=(s<<5)-s+t.charCodeAt(a);for(let a=0;a<n.length;a++)s=(s<<5)-s+n.charCodeAt(a);return s|0}}}parseVersion(e){if(typeof e=="string"){let t=e.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let t={};for(let n of e)if(!(!n||typeof n!="object"))if(n.packages&&Array.isArray(n.packages)){let r=n.publisher;if(!r)throw new Error("PublisherImport requires 'publisher' property");t[r]||(t[r]=[]);for(let s of n.packages){if(!s||typeof s!="object")continue;let a=this.parseImportFromEmbeddedObject(s,r);t[r].push(a)}}else{let r=this.parseImportFromEmbeddedObject(n,n.publisher),s=r.publisher||"";t[s]||(t[s]=[]),t[s].push(r)}return t}parseImportsLegacy(e){let t={};for(let[n,r]of Object.entries(e))Array.isArray(r)&&(t[n]=r.map(s=>this.parseImport(s,n)));return t}parseImportFromEmbeddedObject(e,t){let n=e.package;if(!n)throw new Error("Import requires 'package' property");let r=e.match;if(!r)throw new Error("Import requires 'match' property");let s=e.version;if(!s)throw new Error("Import requires 'version' property");let a=this.parseVersion(s),o=this.parseVersionOperator(r),i=this.calculateMaxVersion(r,a),c=e.alias;return{package_:`${n} ${r} ${a.toString()}`,publisher:t,packageName:n,versionOperator:o,version:a,alias:c,minVersion:a,maxVersion:i,toEmbeddedObject:()=>{let l={package:n,match:r,version:a.toString()};return c&&(l.alias=c),l},toString:()=>c?`${n} ${r} ${a.toString()} as ${c}`:`${n} ${r} ${a.toString()}`}}parseImport(e,t){if(typeof e=="string"){let i=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(i){let l=i[1].trim(),h=i[2],f=this.parseVersion(i[3].trim()),d=i[4].trim(),I=this.parseVersionOperator(h),j=this.calculateMaxVersion(h,f);return{package_:e,publisher:t,packageName:l,versionOperator:I,version:f,alias:d,minVersion:f,maxVersion:j,toEmbeddedObject:()=>{let V={package:l,match:h,version:f.toString()};return d&&(V.alias=d),V},toString:()=>`${l} ${h} ${f.toString()} as ${d}`}}let c=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let l=c[1].trim(),h=c[2],f=this.parseVersion(c[3].trim()),d=this.parseVersionOperator(h),I=this.calculateMaxVersion(h,f);return{package_:e,publisher:t,packageName:l,versionOperator:d,version:f,alias:void 0,minVersion:f,maxVersion:I,toEmbeddedObject:()=>({package:l,match:h,version:f.toString()}),toString:()=>`${l} ${h} ${f.toString()}`}}}let n=this.parseVersionOperator(e.operator||"~"),r=this.parseVersion(e.version||"1.0.0"),s=e.packageName||e.package||"",a=["=","~","^","*"][n],o=this.calculateMaxVersion(e.operator||"~",r);return{package_:e.package||"",publisher:t,packageName:s,versionOperator:n,version:r,alias:e.alias,minVersion:r,maxVersion:o,toEmbeddedObject:()=>{let i={package:s,match:a,version:r.toString()};return e.alias&&(i.alias=e.alias),i},toString:()=>`${s} ${a} ${r.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,t){switch(e){case"~":return this.createVersion(t.major,t.minor+1,0);case"^":return t.major===0?this.createVersion(0,t.minor+1,0):this.createVersion(t.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let t=[];for(let[n,r]of Object.entries(e)){let s={publisher:n,packages:r.map(a=>{let o=["=","~","^","*"][a.versionOperator],i={package:a.packageName,match:o,version:`${a.version.major}.${a.version.minor}.${a.version.patch}`};return a.alias&&(i.alias=a.alias),i})};t.push(s)}return t}};var y=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(e,t=!0,n){if(!e||e.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=m.resolve(e),this.recursive=t,this.parser=n??new g,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let e=new Set(this.documentCache.values());return Array.from(e)}async getDocumentAsync(e){await this.ensureCacheInitialized();let t=this.documentCache.get(e);if(t)return t;let n=m.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let r of[".kan.yml",".yml",".yaml"])if(!e.endsWith(r)){let s=e+r;if(t=this.documentCache.get(s),t)return t;let a=m.join(this.rootPath,s);if(t=this.documentCache.get(a),t)return t}return null}async getDocumentsByNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(r=>r.metadata.namespace_?.publisher===e&&r.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),r=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(r.length===0)return null;let s=r.filter(a=>{let o=a.metadata.namespace_.version;switch(t.versionOperator){case 0:return this.versionsEqual(o,t.version);case 1:return this.isCompatibleVersion(o,t.version);case 2:return this.isMajorCompatible(o,t.version);case 3:return this.compareVersions(o,t.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((a,o)=>{let i=a.metadata.namespace_.version,c=o.metadata.namespace_.version;return this.compareVersions(c,i)}),s[0])}async saveDocumentAsync(e,t){let n,r=e.metadata.namespace_?.toString();if(r&&r.includes("@")&&r.includes("/")){let i=r.split("/"),c=i[0],h=i[1].replace("@","@")+".kan.yml";n=m.join(this.rootPath,c,h)}else n=m.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=m.dirname(n);await u.mkdir(s,{recursive:!0});let a=this.parser.save(e);await u.writeFile(n,a,"utf8"),r&&this.documentCache.set(r,e),this.documentCache.set(n,e);let o=m.relative(this.rootPath,n);this.documentCache.set(o,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await u.unlink(n)}catch{}let r=t.metadata.namespace_?.toString();r&&this.documentCache.delete(r),this.documentCache.delete(e),this.documentCache.delete(n);let s=m.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=[];for(let[s,a]of this.documentCache.entries()){let o=a.metadata.namespace_?.toString()||"";o.includes(e)&&o.includes(t)&&n.push([s,a])}let r=m.join(this.rootPath,e);try{let s=await u.readdir(r);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await u.unlink(m.join(r,a))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let e=new Set(this.filePathsByIdentifier.values()),t=[];for(let n of e){let r=`file://${n}`,s;for(let[i,c]of this.documentCache.entries())if(this.filePathsByIdentifier.get(i)===n&&c.metadata.namespace_){s=c.metadata.namespace_.toString();break}let a=s??m.relative(this.rootPath,n),o=this.parsingErrors.has(n);t.push({identifier:a,uri:r,hasParseError:o})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await u.access(e),t=e}catch{let n=m.join(this.rootPath,e);try{await u.access(n),t=n}catch{return null}}try{return await u.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await u.access(e),t=e}catch{let n=m.join(this.rootPath,e);try{await u.access(n),t=n}catch{return null}}return`file://${t}`}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await u.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async r=>{try{let s=await u.readFile(r,"utf8"),a=this.parser.parse(s);return{filePath:r,document:a,error:null}}catch(s){return{filePath:r,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:r,document:s,error:a}of n){let o=m.relative(this.rootPath,r);if(s&&s.metadata.namespace_){let i=s.metadata.namespace_.toString();this.documentCache.set(i,s),this.documentCache.set(r,s),this.documentCache.set(o,s),this.filePathsByIdentifier.set(i,r),this.filePathsByIdentifier.set(r,r),this.filePathsByIdentifier.set(o,r)}else this.filePathsByIdentifier.set(r,r),this.filePathsByIdentifier.set(o,r);a&&this.parsingErrors.set(r,a)}}versionsEqual(e,t){return e.major===t.major&&e.minor===t.minor&&e.patch===t.patch}compareVersions(e,t){return e.major!==t.major?e.major-t.major:e.minor!==t.minor?e.minor-t.minor:e.patch-t.patch}isCompatibleVersion(e,t){return this.compareVersions(e,t)>=0&&e.major===t.major&&e.minor===t.minor}isMajorCompatible(e,t){return t.major===0?this.compareVersions(e,t)>=0&&e.major===0&&e.minor===t.minor:this.compareVersions(e,t)>=0&&e.major===t.major}async findYamlFiles(e,t){let n=[];try{let r=await u.readdir(e,{withFileTypes:!0});for(let s of r){let a=m.join(e,s.name);if(s.isDirectory()&&t){let o=await this.findYamlFiles(a,t);n.push(...o)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as k from"fs";var x=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(x||{}),P=class{cache;workspace;constructor(e,t,n){let r=n??new g;k.existsSync(e)||k.mkdirSync(e,{recursive:!0}),k.existsSync(t)||k.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,r),this.workspace=new y(t,!0,r)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let r of t)if(r.metadata.namespace_){let s=r.metadata.namespace_.toString();n.set(s,r)}for(let r of e)if(r.metadata.namespace_){let s=r.metadata.namespace_.toString();n.set(s,r)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),r=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of r)if(a.metadata.namespace_?.version){let o=a.metadata.namespace_.version.toString();s.set(o,a)}for(let a of n)if(a.metadata.namespace_?.version){let o=a.metadata.namespace_.version.toString();s.set(o,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as E}from"os";import{join as _}from"path";function A(){let p=process.env.KANONAK_PACKAGE_CACHE;return p||_(E(),".kanonak","packages")}var K=class p{static createComposite(e,t,n){let r=e??A(),s=t??".";return new P(r,s,n)}static createFromEnvironment(e){let t=A(),n=process.env.KANONAK_WORKSPACE_PATH??".";return p.createComposite(t,n,e)}};import{VersionOperator as C}from"@kanonak-protocol/types/document/models/enums";var S="https://{publisher}/index.txt",N="https://{publisher}/{package}/{version}.kan.yml",$={version:1},w=class{cache=new Map;async getConfig(e){let t=this.cache.get(e);if(t)return t;let n=await this.fetchConfig(e);return this.cache.set(e,n),n}async fetchConfig(e){let t=`https://${e}/.well-known/kanonak.json`,n;try{n=await fetch(t)}catch{return $}if(n.status===404)return $;if(!n.ok)throw new Error(`Failed to fetch publisher config: ${t} (${n.status} ${n.statusText})`);let r=await n.json();if(typeof r.version!="number")throw new Error(`Invalid publisher config at ${t}: missing or invalid "version" field`);let s={version:r.version};return typeof r.index=="string"&&(s.index=r.index),typeof r.package=="string"&&(s.package=r.package),(r.auth==="none"||r.auth==="oauth"||r.auth==="bearer")&&(s.auth=r.auth),s}resolveIndexUrl(e,t){let n=t.index??S;return F(n,{publisher:e})}resolvePackageUrl(e,t,n,r){let s=r.package??N;return F(s,{publisher:e,package:t,version:n})}};function F(p,e){let t=p;for(let[r,s]of Object.entries(e))t=t.replaceAll(`{${r}}`,s);let n=t.match(/\{[a-z]+\}/);if(n)throw new Error(`Unresolved variable ${n[0]} in URL template: ${p}`);return t}var v=class p{indexCache=new Map;configResolver;fetchFn;constructor(e){this.configResolver=e?.configResolver??new w,this.fetchFn=e?.fetchFn}async resolveVersion(e,t){let n=await this.getPackageVersions(e,t.packageName);if(n.length===0)return null;let r=n.filter(s=>this.isVersionCompatible(s,t.version,t.versionOperator));return r.length===0?null:(r.sort((s,a)=>this.compareVersionStrings(a,s)),r[0])}async getHighestVersion(e,t){let n=await this.getPackageVersions(e,t);return n.length===0?null:[...n].sort((s,a)=>this.compareVersionStrings(a,s))[0]}async getPackageUrl(e,t,n){let r=await this.configResolver.getConfig(e);return this.configResolver.resolvePackageUrl(e,t,n,r)}async getPackageVersions(e,t){let n=this.indexCache.get(e);return n||(n=await this.fetchIndex(e),this.indexCache.set(e,n)),n.get(t)??[]}async fetchIndex(e){let t=await this.configResolver.getConfig(e),n=this.configResolver.resolveIndexUrl(e,t),r=this.fetchFn?await this.fetchFn(n,e):await fetch(n);if(!r.ok)throw new Error(`Failed to fetch publisher index: ${n} (${r.status} ${r.statusText})`);let s=await r.text();return p.parseIndex(s)}static parseIndex(e){let t=new Map;for(let n of e.split(`
2
- `)){let r=n.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("/");if(s===-1)continue;let a=r.substring(0,s),o=r.substring(s+1);if(!a||!o)continue;let i=t.get(a);i?i.push(o):t.set(a,[o])}return t}isVersionCompatible(e,t,n){let r=p.parseVersion(e);if(!r)return!1;switch(n){case C.Any:return!0;case C.Exact:return r.major===t.major&&r.minor===t.minor&&r.patch===t.patch;case C.Compatible:return r.major===t.major&&r.minor===t.minor&&r.patch>=t.patch;case C.Major:return r.major!==t.major?!1:r.minor>t.minor?!0:r.minor===t.minor?r.patch>=t.patch:!1;default:return!1}}static parseVersion(e){let t=e.split(".");if(t.length<2)return null;let n=parseInt(t[0],10),r=parseInt(t[1],10),s=t.length>=3?parseInt(t[2],10):0;return isNaN(n)||isNaN(r)||isNaN(s)?null:{major:n,minor:r,patch:s}}compareVersionStrings(e,t){let n=p.parseVersion(e),r=p.parseVersion(t);return!n&&!r?0:n?r?n.major!==r.major?n.major-r.major:n.minor!==r.minor?n.minor-r.minor:n.patch-r.patch:1:-1}};var R=class{parser=new g;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=e?.fetchFn?new v({fetchFn:e.fetchFn}):new v}async getHighestCompatibleVersionAsync(e,t){let n=await this.publisherIndex.resolveVersion(e,t);if(!n)return null;let r=`${e}/${t.packageName}@${n}`,s=this.documents.get(r);if(s)return s;if(this.getFromCache){let l=this.getFromCache(e,t.packageName,n);if(l){let h=this.parser.parse(l);return this.documents.set(r,h),this.contentCache.set(r,l),h}}let a=await this.publisherIndex.getPackageUrl(e,t.packageName,n),o=this.fetchFn?await this.fetchFn(a,e):await fetch(a);if(!o.ok)throw new Error(`Failed to fetch Kanonak package: ${a} (${o.status} ${o.statusText})`);let i=await o.text();this.onFetch&&this.onFetch(e,t.packageName,n,i);let c=this.parser.parse(i);return this.documents.set(r,c),this.contentCache.set(r,i),c}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(n=>{let r=n.metadata.namespace_;return r&&r.publisher===e&&r.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[,n,r,s]=t;return this.publisherIndex.getPackageUrl(n,r,s)}};export{P as CompositeKanonakDocumentRepository,x as DocumentLocation,y as FileSystemKanonakDocumentRepository,R as HttpKanonakDocumentRepository,b as InMemoryKanonakDocumentRepository,w as PublisherConfigResolver,v as PublisherIndex,K as RepositoryFactory,A as getGlobalCachePath};
1
+ var b=class{documents=new Map;documentContents=new Map;parser;constructor(e){this.parser=e}async getAllDocumentsAsync(){return Array.from(this.documents.values())}async getDocumentAsync(e){return this.documents.get(e)??null}async getDocumentsByNamespaceAsync(e,t){let n=[];for(let r of this.documents.values())r.metadata?.namespace_?.publisher===e&&r.metadata?.namespace_?.package_===t&&n.push(r);return n}async getHighestCompatibleVersionAsync(e,t){let n=[];for(let s of this.documents.values())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===t.packageName&&s.metadata?.namespace_?.version!==void 0&&n.push(s);if(n.length===0)return null;let r=n.filter(s=>{let a=s.metadata.namespace_.version;if(!a)return!1;switch(t.versionOperator){case 0:return this.versionsEqual(a,t.version);case 1:return this.isCompatibleVersion(a,t.version);case 2:return this.isMajorCompatible(a,t.version);case 3:return this.compareVersions(a,t.minVersion)>=0;default:return!1}});return r.length===0?null:(r.sort((s,a)=>{let o=s.metadata.namespace_.version,i=a.metadata.namespace_.version;return!o&&!i?0:o?i?this.compareVersions(i,o):-1:1}),r[0])}async saveDocumentAsync(e,t){this.documents.set(t,e);let n=this.parser.save(e);this.documentContents.set(t,n)}async deleteDocumentAsync(e){this.documents.delete(e),this.documentContents.delete(e)}async clearNamespaceAsync(e,t){let n=[];for(let[r,s]of this.documents.entries())s.metadata?.namespace_?.publisher===e&&s.metadata?.namespace_?.package_===t&&n.push(r);for(let r of n)this.documents.delete(r),this.documentContents.delete(r)}async getAllDocumentReferencesAsync(){let e=[];for(let t of this.documents.values())t.metadata?.namespace_&&e.push({identifier:t.metadata.namespace_.toString(),uri:`kanonak://${t.metadata.namespace_}`,hasParseError:!1});return e}async getDocumentContentAsync(e){let t=this.documentContents.get(e);if(t!==void 0)return t;let n=this.documents.get(e);return n!==void 0?this.parser.save(n):null}async getDocumentUriAsync(e){let t=this.documents.get(e);return t?t.metadata?.namespace_?`kanonak://${t.metadata.namespace_}`:`kanonak://${e}`:null}versionsEqual(e,t){return e.major===t.major&&e.minor===t.minor&&e.patch===t.patch}compareVersions(e,t){return e.major!==t.major?e.major-t.major:e.minor!==t.minor?e.minor-t.minor:e.patch-t.patch}isCompatibleVersion(e,t){return this.compareVersions(e,t)>=0&&e.major===t.major&&e.minor===t.minor}isMajorCompatible(e,t){return t.major===0?this.compareVersions(e,t)>=0&&e.major===0&&e.minor===t.minor:this.compareVersions(e,t)>=0&&e.major===t.major}};import*as p from"fs/promises";import*as m from"path";import*as D from"js-yaml";var g=class{parse(e){let t=this.parseWithErrors(e);if(!t.isValid){let n=t.errors[0];throw new Error(`YAML parse error at line ${n.line}, column ${n.column}: ${n.message}`)}return t.document}parseWithErrors(e){let t=[],n;try{e=e.replace(/^\uFEFF/,"");let r=D.load(e);if(!r||typeof r!="object")return n={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:n,errors:t,isValid:!0};let s=this.extractMetadata(r),a=this.extractBody(r,s);return n={metadata:s,body:a,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:n,errors:t,isValid:!0}}catch(r){let s=r,a={message:s.message||"Unknown parse error",line:s.mark?.line??0,column:s.mark?.column??0,errorType:s.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${s.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${s.mark?.line??0}: ${s.message||"Unknown parse error"}`};return t.push(a),{document:void 0,errors:t,isValid:!1}}}save(e){let t={};if(e.metadata.namespace_){let n=e.metadata.namespace_,r={type:"Package",publisher:n.publisher};n.version&&(r.version=`${n.version.major}.${n.version.minor}.${n.version.patch}`),e.metadata.imports&&(r.imports=this.serializeImports(e.metadata.imports)),t[n.package_]=r}return Object.assign(t,e.body),D.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(e){let t=e.imports;return Object.defineProperty(e,"allImports",{get:function(){if(!t)return[];let n=[];for(let r of Object.values(t))n.push(...r);return n},enumerable:!0,configurable:!0}),e}createVersion(e,t,n){return{major:e,minor:t,patch:n,toString:()=>`${e}.${t}.${n}`,equals:s=>!s||typeof s!="object"?!1:s.major===e&&s.minor===t&&s.patch===n,getHashCode:()=>e<<20|t<<10|n,compareTo:s=>e!==s.major?e-s.major:t!==s.minor?t-s.minor:n-s.patch}}extractMetadata(e){let t=this.createEmptyMetadata();for(let[n,r]of Object.entries(e))if(r&&typeof r=="object"&&r.type==="Package"){t.type_="Package";let s=n,a=r.publisher,o=r.version?this.parseVersion(r.version):void 0;return a&&s&&(t.namespace_={publisher:a,package_:s,version:o,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:i=>!i||typeof i!="object"?!1:i.publisher===a&&i.package_===s&&(!o||!i.version||o.equals(i.version)),getHashCode:()=>{let i=0;for(let c=0;c<a.length;c++)i=(i<<5)-i+a.charCodeAt(c);for(let c=0;c<s.length;c++)i=(i<<5)-i+s.charCodeAt(c);return i|0}}),r.imports&&Array.isArray(r.imports)&&(t.imports=this.parseImportsV3(r.imports)),this.addAllImportsGetter(t)}if(e.kanonak&&typeof e.kanonak=="object"){let n=e.kanonak;return(n.publisher||n.package||n.version)&&(t.namespace_=this.parseNamespace(n)),n.imports&&typeof n.imports=="object"&&(t.imports=this.parseImportsLegacy(n.imports)),this.addAllImportsGetter(t)}return t}extractBody(e,t){let n={},r;for(let[s,a]of Object.entries(e))if(a&&typeof a=="object"&&a.type==="Package"){r=s;break}for(let[s,a]of Object.entries(e))s!==r&&s!=="kanonak"&&s!=="namespace"&&s!=="imports"&&(n[s]=a);return n}parseNamespace(e){if(typeof e=="string"){let s=e.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(s){let a=s[3]?this.parseVersion(s[3]):this.createVersion(1,0,0);return{publisher:s[1],package_:s[2],version:a,toString:()=>e,equals:o=>!o||typeof o!="object"?!1:o.publisher===s[1]&&o.package_===s[2]&&(!a||!o.version||a.equals(o.version)),getHashCode:()=>{let o=0;for(let i=0;i<s[1].length;i++)o=(o<<5)-o+s[1].charCodeAt(i);for(let i=0;i<s[2].length;i++)o=(o<<5)-o+s[2].charCodeAt(i);return o|0}}}}let t=e.publisher||"",n=e.package||"",r=e.version?this.parseVersion(e.version):this.createVersion(1,0,0);return{publisher:t,package_:n,version:r,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:s=>!s||typeof s!="object"?!1:s.publisher===t&&s.package_===n&&(!r||!s.version||r.equals(s.version)),getHashCode:()=>{let s=0;for(let a=0;a<t.length;a++)s=(s<<5)-s+t.charCodeAt(a);for(let a=0;a<n.length;a++)s=(s<<5)-s+n.charCodeAt(a);return s|0}}}parseVersion(e){if(typeof e=="string"){let t=e.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(e.major||0,e.minor||0,e.patch||0)}parseImportsV3(e){let t={};for(let n of e)if(!(!n||typeof n!="object"))if(n.packages&&Array.isArray(n.packages)){let r=n.publisher;if(!r)throw new Error("PublisherImport requires 'publisher' property");t[r]||(t[r]=[]);for(let s of n.packages){if(!s||typeof s!="object")continue;let a=this.parseImportFromEmbeddedObject(s,r);t[r].push(a)}}else{let r=this.parseImportFromEmbeddedObject(n,n.publisher),s=r.publisher||"";t[s]||(t[s]=[]),t[s].push(r)}return t}parseImportsLegacy(e){let t={};for(let[n,r]of Object.entries(e))Array.isArray(r)&&(t[n]=r.map(s=>this.parseImport(s,n)));return t}parseImportFromEmbeddedObject(e,t){let n=e.package;if(!n)throw new Error("Import requires 'package' property");let r=e.match;if(!r)throw new Error("Import requires 'match' property");let s=e.version;if(!s)throw new Error("Import requires 'version' property");let a=this.parseVersion(s),o=this.parseVersionOperator(r),i=this.calculateMaxVersion(r,a),c=e.alias;return{package_:`${n} ${r} ${a.toString()}`,publisher:t,packageName:n,versionOperator:o,version:a,alias:c,minVersion:a,maxVersion:i,toEmbeddedObject:()=>{let l={package:n,match:r,version:a.toString()};return c&&(l.alias=c),l},toString:()=>c?`${n} ${r} ${a.toString()} as ${c}`:`${n} ${r} ${a.toString()}`}}parseImport(e,t){if(typeof e=="string"){let i=e.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(i){let l=i[1].trim(),h=i[2],f=this.parseVersion(i[3].trim()),d=i[4].trim(),I=this.parseVersionOperator(h),j=this.calculateMaxVersion(h,f);return{package_:e,publisher:t,packageName:l,versionOperator:I,version:f,alias:d,minVersion:f,maxVersion:j,toEmbeddedObject:()=>{let R={package:l,match:h,version:f.toString()};return d&&(R.alias=d),R},toString:()=>`${l} ${h} ${f.toString()} as ${d}`}}let c=e.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let l=c[1].trim(),h=c[2],f=this.parseVersion(c[3].trim()),d=this.parseVersionOperator(h),I=this.calculateMaxVersion(h,f);return{package_:e,publisher:t,packageName:l,versionOperator:d,version:f,alias:void 0,minVersion:f,maxVersion:I,toEmbeddedObject:()=>({package:l,match:h,version:f.toString()}),toString:()=>`${l} ${h} ${f.toString()}`}}}let n=this.parseVersionOperator(e.operator||"~"),r=this.parseVersion(e.version||"1.0.0"),s=e.packageName||e.package||"",a=["=","~","^","*"][n],o=this.calculateMaxVersion(e.operator||"~",r);return{package_:e.package||"",publisher:t,packageName:s,versionOperator:n,version:r,alias:e.alias,minVersion:r,maxVersion:o,toEmbeddedObject:()=>{let i={package:s,match:a,version:r.toString()};return e.alias&&(i.alias=e.alias),i},toString:()=>`${s} ${a} ${r.toString()}`}}parseVersionOperator(e){switch(e){case"=":return 0;case"~":return 1;case"^":return 2;case"*":return 3;default:return 1}}calculateMaxVersion(e,t){switch(e){case"~":return this.createVersion(t.major,t.minor+1,0);case"^":return t.major===0?this.createVersion(0,t.minor+1,0):this.createVersion(t.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(e){let t=[];for(let[n,r]of Object.entries(e)){let s={publisher:n,packages:r.map(a=>{let o=["=","~","^","*"][a.versionOperator],i={package:a.packageName,match:o,version:`${a.version.major}.${a.version.minor}.${a.version.patch}`};return a.alias&&(i.alias=a.alias),i})};t.push(s)}return t}};var y=class{rootPath;recursive;parser;documentCache;filePathsByIdentifier;cacheInitialized=!1;cacheInitPromise=null;parsingErrors=new Map;constructor(e,t=!0,n){if(!e||e.trim().length===0)throw new Error("Root path cannot be null or empty");this.rootPath=m.resolve(e),this.recursive=t,this.parser=n??new g,this.documentCache=new Map,this.filePathsByIdentifier=new Map}async getAllDocumentsAsync(){await this.ensureCacheInitialized();let e=new Set(this.documentCache.values());return Array.from(e)}async getDocumentAsync(e){await this.ensureCacheInitialized();let t=this.documentCache.get(e);if(t)return t;let n=m.join(this.rootPath,e);if(t=this.documentCache.get(n),t)return t;for(let r of[".kan.yml",".yml",".yaml"])if(!e.endsWith(r)){let s=e+r;if(t=this.documentCache.get(s),t)return t;let a=m.join(this.rootPath,s);if(t=this.documentCache.get(a),t)return t}return null}async getDocumentsByNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values());return Array.from(n).filter(r=>r.metadata.namespace_?.publisher===e&&r.metadata.namespace_?.package_===t)}async getHighestCompatibleVersionAsync(e,t){await this.ensureCacheInitialized();let n=new Set(this.documentCache.values()),r=Array.from(n).filter(a=>a.metadata?.namespace_?.publisher===e&&a.metadata?.namespace_?.package_===t.packageName&&a.metadata?.namespace_?.version!==void 0);if(r.length===0)return null;let s=r.filter(a=>{let o=a.metadata.namespace_.version;switch(t.versionOperator){case 0:return this.versionsEqual(o,t.version);case 1:return this.isCompatibleVersion(o,t.version);case 2:return this.isMajorCompatible(o,t.version);case 3:return this.compareVersions(o,t.minVersion)>=0;default:return!1}});return s.length===0?null:(s.sort((a,o)=>{let i=a.metadata.namespace_.version,c=o.metadata.namespace_.version;return this.compareVersions(c,i)}),s[0])}async saveDocumentAsync(e,t){let n,r=e.metadata.namespace_?.toString();if(r&&r.includes("@")&&r.includes("/")){let i=r.split("/"),c=i[0],h=i[1].replace("@","@")+".kan.yml";n=m.join(this.rootPath,c,h)}else n=m.join(this.rootPath,t),!n.endsWith(".yml")&&!n.endsWith(".yaml")&&!n.endsWith(".kan.yml")&&(n+=".kan.yml");let s=m.dirname(n);await p.mkdir(s,{recursive:!0});let a=this.parser.save(e);await p.writeFile(n,a,"utf8"),r&&this.documentCache.set(r,e),this.documentCache.set(n,e);let o=m.relative(this.rootPath,n);this.documentCache.set(o,e)}async deleteDocumentAsync(e){let t=await this.getDocumentAsync(e);if(!t)return;let n=this.filePathsByIdentifier.get(e);if(!n)return;try{await p.unlink(n)}catch{}let r=t.metadata.namespace_?.toString();r&&this.documentCache.delete(r),this.documentCache.delete(e),this.documentCache.delete(n);let s=m.relative(this.rootPath,n);this.documentCache.delete(s)}async clearNamespaceAsync(e,t){await this.ensureCacheInitialized();let n=[];for(let[s,a]of this.documentCache.entries()){let o=a.metadata.namespace_?.toString()||"";o.includes(e)&&o.includes(t)&&n.push([s,a])}let r=m.join(this.rootPath,e);try{let s=await p.readdir(r);for(let a of s)a.includes(t)&&a.endsWith(".kan.yml")&&await p.unlink(m.join(r,a))}catch{}for(let[s]of n)this.documentCache.delete(s)}async getAllDocumentReferencesAsync(){await this.ensureCacheInitialized();let e=new Set(this.filePathsByIdentifier.values()),t=[];for(let n of e){let r=`file://${n}`,s;for(let[i,c]of this.documentCache.entries())if(this.filePathsByIdentifier.get(i)===n&&c.metadata.namespace_){s=c.metadata.namespace_.toString();break}let a=s??m.relative(this.rootPath,n),o=this.parsingErrors.has(n);t.push({identifier:a,uri:r,hasParseError:o})}return t}async getDocumentContentAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await p.access(e),t=e}catch{let n=m.join(this.rootPath,e);try{await p.access(n),t=n}catch{return null}}try{return await p.readFile(t,"utf8")}catch{return null}}async getDocumentUriAsync(e){await this.ensureCacheInitialized();let t=this.filePathsByIdentifier.get(e);if(!t)try{await p.access(e),t=e}catch{let n=m.join(this.rootPath,e);try{await p.access(n),t=n}catch{return null}}return`file://${t}`}async refreshAsync(){this.documentCache.clear(),this.filePathsByIdentifier.clear(),this.parsingErrors.clear(),this.cacheInitialized=!1,this.cacheInitPromise=null,await this.ensureCacheInitialized()}async ensureCacheInitialized(){if(!this.cacheInitialized){if(this.cacheInitPromise){await this.cacheInitPromise;return}this.cacheInitPromise=this.loadDocuments(),await this.cacheInitPromise,this.cacheInitialized=!0}}async loadDocuments(){try{await p.mkdir(this.rootPath,{recursive:!0})}catch{}let t=(await this.findYamlFiles(this.rootPath,this.recursive)).map(async r=>{try{let s=await p.readFile(r,"utf8"),a=this.parser.parse(s);return{filePath:r,document:a,error:null}}catch(s){return{filePath:r,document:null,error:s instanceof Error?s.message:String(s)}}}),n=await Promise.all(t);for(let{filePath:r,document:s,error:a}of n){let o=m.relative(this.rootPath,r);if(s&&s.metadata.namespace_){let i=s.metadata.namespace_.toString();this.documentCache.set(i,s),this.documentCache.set(r,s),this.documentCache.set(o,s),this.filePathsByIdentifier.set(i,r),this.filePathsByIdentifier.set(r,r),this.filePathsByIdentifier.set(o,r)}else this.filePathsByIdentifier.set(r,r),this.filePathsByIdentifier.set(o,r);a&&this.parsingErrors.set(r,a)}}versionsEqual(e,t){return e.major===t.major&&e.minor===t.minor&&e.patch===t.patch}compareVersions(e,t){return e.major!==t.major?e.major-t.major:e.minor!==t.minor?e.minor-t.minor:e.patch-t.patch}isCompatibleVersion(e,t){return this.compareVersions(e,t)>=0&&e.major===t.major&&e.minor===t.minor}isMajorCompatible(e,t){return t.major===0?this.compareVersions(e,t)>=0&&e.major===0&&e.minor===t.minor:this.compareVersions(e,t)>=0&&e.major===t.major}async findYamlFiles(e,t){let n=[];try{let r=await p.readdir(e,{withFileTypes:!0});for(let s of r){let a=m.join(e,s.name);if(s.isDirectory()&&t){let o=await this.findYamlFiles(a,t);n.push(...o)}else s.isFile()&&s.name.endsWith(".kan.yml")&&n.push(a)}}catch{}return n}};import*as k from"fs";var V=(n=>(n.NotFound="NotFound",n.Workspace="Workspace",n.Cache="Cache",n))(V||{}),P=class{cache;workspace;constructor(e,t,n){let r=n??new g;k.existsSync(e)||k.mkdirSync(e,{recursive:!0}),k.existsSync(t)||k.mkdirSync(t,{recursive:!0}),this.cache=new y(e,!0,r),this.workspace=new y(t,!0,r)}getCache(){return this.cache}getWorkspace(){return this.workspace}async getAllDocumentsAsync(){let e=await this.workspace.getAllDocumentsAsync(),t=await this.cache.getAllDocumentsAsync(),n=new Map;for(let r of t)if(r.metadata.namespace_){let s=r.metadata.namespace_.toString();n.set(s,r)}for(let r of e)if(r.metadata.namespace_){let s=r.metadata.namespace_.toString();n.set(s,r)}return Array.from(n.values())}async getDocumentAsync(e){let t=await this.workspace.getDocumentAsync(e);return t||await this.cache.getDocumentAsync(e)}async getDocumentsByNamespaceAsync(e,t){let n=await this.workspace.getDocumentsByNamespaceAsync(e,t),r=await this.cache.getDocumentsByNamespaceAsync(e,t),s=new Map;for(let a of r)if(a.metadata.namespace_?.version){let o=a.metadata.namespace_.version.toString();s.set(o,a)}for(let a of n)if(a.metadata.namespace_?.version){let o=a.metadata.namespace_.version.toString();s.set(o,a)}return Array.from(s.values())}async getHighestCompatibleVersionAsync(e,t){let n=await this.workspace.getHighestCompatibleVersionAsync(e,t);return n||await this.cache.getHighestCompatibleVersionAsync(e,t)}async saveDocumentAsync(e,t){await this.workspace.saveDocumentAsync(e,t)}async saveToCacheAsync(e,t){await this.cache.saveDocumentAsync(e,t)}async deleteDocumentAsync(e){await this.workspace.deleteDocumentAsync(e)}async clearNamespaceAsync(e,t){await this.workspace.clearNamespaceAsync(e,t)}async getAllDocumentReferencesAsync(){let e=await this.workspace.getAllDocumentReferencesAsync(),t=await this.cache.getAllDocumentReferencesAsync(),n=[];return n.push(...e),n.push(...t),n}async getDocumentContentAsync(e){let t=await this.workspace.getDocumentContentAsync(e);return t||await this.cache.getDocumentContentAsync(e)}async getDocumentUriAsync(e){let t=await this.workspace.getDocumentUriAsync(e);return t||await this.cache.getDocumentUriAsync(e)}async getDocumentLocationAsync(e){return await this.workspace.getDocumentAsync(e)?"Workspace":await this.cache.getDocumentAsync(e)?"Cache":"NotFound"}};import{homedir as E}from"os";import{join as _}from"path";function A(){let u=process.env.KANONAK_PACKAGE_CACHE;return u||_(E(),".kanonak","packages")}var K=class u{static createComposite(e,t,n){let r=e??A(),s=t??".";return new P(r,s,n)}static createFromEnvironment(e){let t=A(),n=process.env.KANONAK_WORKSPACE_PATH??".";return u.createComposite(t,n,e)}};import{VersionOperator as C}from"@kanonak-protocol/types/document/models/enums";var S="https://{publisher}/index.txt",N="https://{publisher}/{package}/{version}.kan.yml",$={version:1},w=class{cache=new Map;async getConfig(e){let t=this.cache.get(e);if(t)return t;let n=await this.fetchConfig(e);return this.cache.set(e,n),n}async fetchConfig(e){let t=`https://${e}/.well-known/kanonak.json`,n;try{n=await fetch(t)}catch{return $}if(n.status===404)return $;if(!n.ok)throw new Error(`Failed to fetch publisher config: ${t} (${n.status} ${n.statusText})`);let r=await n.json();if(typeof r.version!="number")throw new Error(`Invalid publisher config at ${t}: missing or invalid "version" field`);let s={version:r.version};return typeof r.index=="string"&&(s.index=r.index),typeof r.package=="string"&&(s.package=r.package),(r.auth==="none"||r.auth==="oauth"||r.auth==="bearer")&&(s.auth=r.auth),s}resolveIndexUrl(e,t){let n=t.index??S;return F(n,{publisher:e})}resolvePackageUrl(e,t,n,r){let s=r.package??N;return F(s,{publisher:e,package:t,version:n})}};function F(u,e){let t=u;for(let[r,s]of Object.entries(e))t=t.replaceAll(`{${r}}`,s);let n=t.match(/\{[a-z]+\}/);if(n)throw new Error(`Unresolved variable ${n[0]} in URL template: ${u}`);return t}var v=class u{indexCache=new Map;configResolver;fetchFn;constructor(e){this.configResolver=e?.configResolver??new w,this.fetchFn=e?.fetchFn}async resolveVersion(e,t){let n=await this.getPackageVersions(e,t.packageName);if(n.length===0)return null;let r=n.filter(s=>this.isVersionCompatible(s,t.version,t.versionOperator));return r.length===0?null:(r.sort((s,a)=>this.compareVersionStrings(a,s)),r[0])}async getHighestVersion(e,t){let n=await this.getPackageVersions(e,t);return n.length===0?null:[...n].sort((s,a)=>this.compareVersionStrings(a,s))[0]}async listLatestPackages(e){let t=this.indexCache.get(e);t||(t=await this.fetchIndex(e),this.indexCache.set(e,t));let n=[];for(let[r,s]of t){if(s.length===0)continue;let a=[...s].sort((o,i)=>this.compareVersionStrings(i,o));n.push({packageName:r,version:a[0]})}return n.sort((r,s)=>r.packageName.localeCompare(s.packageName)),n}async getPackageUrl(e,t,n){let r=await this.configResolver.getConfig(e);return this.configResolver.resolvePackageUrl(e,t,n,r)}async getPackageVersions(e,t){let n=this.indexCache.get(e);return n||(n=await this.fetchIndex(e),this.indexCache.set(e,n)),n.get(t)??[]}async fetchIndex(e){let t=await this.configResolver.getConfig(e),n=this.configResolver.resolveIndexUrl(e,t),r=this.fetchFn?await this.fetchFn(n,e):await fetch(n);if(!r.ok)throw new Error(`Failed to fetch publisher index: ${n} (${r.status} ${r.statusText})`);let s=await r.text();return u.parseIndex(s)}static parseIndex(e){let t=new Map;for(let n of e.split(`
2
+ `)){let r=n.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("/");if(s===-1)continue;let a=r.substring(0,s),o=r.substring(s+1);if(!a||!o)continue;let i=t.get(a);i?i.push(o):t.set(a,[o])}return t}isVersionCompatible(e,t,n){let r=u.parseVersion(e);if(!r)return!1;switch(n){case C.Any:return!0;case C.Exact:return r.major===t.major&&r.minor===t.minor&&r.patch===t.patch;case C.Compatible:return r.major===t.major&&r.minor===t.minor&&r.patch>=t.patch;case C.Major:return r.major!==t.major?!1:r.minor>t.minor?!0:r.minor===t.minor?r.patch>=t.patch:!1;default:return!1}}static parseVersion(e){let t=e.split(".");if(t.length<2)return null;let n=parseInt(t[0],10),r=parseInt(t[1],10),s=t.length>=3?parseInt(t[2],10):0;return isNaN(n)||isNaN(r)||isNaN(s)?null:{major:n,minor:r,patch:s}}compareVersionStrings(e,t){let n=u.parseVersion(e),r=u.parseVersion(t);return!n&&!r?0:n?r?n.major!==r.major?n.major-r.major:n.minor!==r.minor?n.minor-r.minor:n.patch-r.patch:1:-1}};var x=class{parser=new g;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=e?.fetchFn?new v({fetchFn:e.fetchFn}):new v}async getHighestCompatibleVersionAsync(e,t){let n=await this.publisherIndex.resolveVersion(e,t);if(!n)return null;let r=`${e}/${t.packageName}@${n}`,s=this.documents.get(r);if(s)return s;if(this.getFromCache){let l=this.getFromCache(e,t.packageName,n);if(l){let h=this.parser.parse(l);return this.documents.set(r,h),this.contentCache.set(r,l),h}}let a=await this.publisherIndex.getPackageUrl(e,t.packageName,n),o=this.fetchFn?await this.fetchFn(a,e):await fetch(a);if(!o.ok)throw new Error(`Failed to fetch Kanonak package: ${a} (${o.status} ${o.statusText})`);let i=await o.text();this.onFetch&&this.onFetch(e,t.packageName,n,i);let c=this.parser.parse(i);return this.documents.set(r,c),this.contentCache.set(r,i),c}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(n=>{let r=n.metadata.namespace_;return r&&r.publisher===e&&r.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[,n,r,s]=t;return this.publisherIndex.getPackageUrl(n,r,s)}};export{P as CompositeKanonakDocumentRepository,V as DocumentLocation,y as FileSystemKanonakDocumentRepository,x as HttpKanonakDocumentRepository,b as InMemoryKanonakDocumentRepository,w as PublisherConfigResolver,v as PublisherIndex,K as RepositoryFactory,A as getGlobalCachePath};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "1.9.0",
3
+ "version": "2.0.0",
4
4
  "description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -62,6 +62,14 @@
62
62
  "types": "./dist/ctl/index.d.ts",
63
63
  "default": "./dist/ctl/index.js"
64
64
  },
65
+ "./reasoning": {
66
+ "browser": {
67
+ "types": "./dist/reasoning/index.d.ts",
68
+ "default": "./dist/reasoning/index.js"
69
+ },
70
+ "types": "./dist/reasoning/index.d.ts",
71
+ "default": "./dist/reasoning/index.js"
72
+ },
65
73
  "./browser": {
66
74
  "types": "./dist/browser.d.ts",
67
75
  "default": "./dist/browser.js"
@@ -98,7 +106,7 @@
98
106
  "yaml-parser"
99
107
  ],
100
108
  "dependencies": {
101
- "@kanonak-protocol/types": "^1.9.0",
109
+ "@kanonak-protocol/types": "^2.0.0",
102
110
  "ignore": "^7.0.5",
103
111
  "js-yaml": "^4.1.0"
104
112
  },